Mesa (master): radv: handle different Vulkan API versions correctly

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue May 12 09:01:48 UTC 2020


Module: Mesa
Branch: master
Commit: 021270cb3170ef38244d21cf3fe8780a3ef5fb3e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=021270cb3170ef38244d21cf3fe8780a3ef5fb3e

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Mon May 11 11:58:26 2020 +0200

radv: handle different Vulkan API versions correctly

Loosely based on ANV.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Acked-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4985>

---

 src/amd/vulkan/radv_extensions.py | 55 ++++++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 12 deletions(-)

diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py
index 4ea75a10d57..684f30f12de 100644
--- a/src/amd/vulkan/radv_extensions.py
+++ b/src/amd/vulkan/radv_extensions.py
@@ -31,7 +31,12 @@ import xml.etree.cElementTree as et
 
 from mako.template import Template
 
-MAX_API_VERSION = '1.2.128'
+def _bool_to_c_expr(b):
+    if b is True:
+        return 'true'
+    if b is False:
+        return 'false'
+    return b
 
 class Extension:
     def __init__(self, name, ext_version, enable):
@@ -44,6 +49,24 @@ class Extension:
         else:
             self.enable = enable;
 
+class ApiVersion:
+    def __init__(self, version, enable):
+        self.version = version
+        self.enable = _bool_to_c_expr(enable)
+
+# Supported API versions.  Each one is the maximum patch version for the given
+# version.  Version come in increasing order and each version is available if
+# it's provided "enable" condition is true and all previous versions are
+# available.
+# TODO: The patch version should be unified!
+API_VERSIONS = [
+    ApiVersion('1.0.68',  True),
+    ApiVersion('1.1.107', True),
+    ApiVersion('1.2.131', '!ANDROID'),
+]
+
+MAX_API_VERSION = None # Computed later
+
 # On Android, we disable all surface and swapchain extensions. Android's Vulkan
 # loader implements VK_KHR_surface and VK_KHR_swapchain, and applications
 # cannot access the driver's implementation. Moreoever, if the driver exposes
@@ -218,7 +241,11 @@ class VkVersion:
         return self.__int_ver() > other.__int_ver()
 
 
-MAX_API_VERSION = VkVersion(MAX_API_VERSION)
+MAX_API_VERSION = VkVersion('0.0.0')
+for version in API_VERSIONS:
+    version.version = VkVersion(version.version)
+    assert version.version > MAX_API_VERSION
+    MAX_API_VERSION = version.version
 
 def _init_exts_from_xml(xml):
     """ Walk the Vulkan XML and fill out extra extension information. """
@@ -412,6 +439,7 @@ _TEMPLATE_C = Template(COPYRIGHT + """
                          VK_USE_PLATFORM_XLIB_KHR || \\
                          VK_USE_PLATFORM_DISPLAY_KHR)
 
+static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
 
 const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT] = {
 %for ext in instance_extensions:
@@ -443,24 +471,26 @@ void radv_fill_device_extension_table(const struct radv_physical_device *device,
 VkResult radv_EnumerateInstanceVersion(
     uint32_t*                                   pApiVersion)
 {
-    *pApiVersion = ${MAX_API_VERSION.c_vk_version()};
+    *pApiVersion = MAX_API_VERSION;
     return VK_SUCCESS;
 }
 
 uint32_t
 radv_physical_device_api_version(struct radv_physical_device *dev)
 {
+    uint32_t version = 0;
+
     uint32_t override = vk_get_version_override();
-    uint32_t version = VK_MAKE_VERSION(1, 0, 68);
-    if (dev->rad_info.has_syncobj_wait_for_submit) {
-        if (ANDROID) {
-            version = VK_MAKE_VERSION(1, 1, 107);
-        } else {
-            version = ${MAX_API_VERSION.c_vk_version()};
-        }
-    }
+    if (override)
+        return MIN2(override, MAX_API_VERSION);
+
+%for version in API_VERSIONS:
+    if (!(${version.enable}))
+        return version;
+    version = ${version.version.c_vk_version()};
 
-    return override ? MIN2(override, version) : version;
+%endfor
+    return version;
 }
 """)
 
@@ -482,6 +512,7 @@ if __name__ == '__main__':
         assert ext.type == 'instance' or ext.type == 'device'
 
     template_env = {
+        'API_VERSIONS': API_VERSIONS,
         'MAX_API_VERSION': MAX_API_VERSION,
         'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'],
         'device_extensions': [e for e in EXTENSIONS if e.type == 'device'],



More information about the mesa-commit mailing list