Mesa (staging/21.3): vulkan: Fix weak symbol emulation when compiling with MSVC

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Oct 14 20:48:05 UTC 2021


Module: Mesa
Branch: staging/21.3
Commit: 7a751b63ca40b3bb115c026833d46e99f2da9a68
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a751b63ca40b3bb115c026833d46e99f2da9a68

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Wed Oct 13 21:50:59 2021 +0200

vulkan: Fix weak symbol emulation when compiling with MSVC

Mapping unimplemented entrypoints to a global function pointer variable
initialized to NULL is a bit cumbersome, and actually led to a bug
in the vk_xxx_dispatch_table_from_entrypoints() template: the !override
case didn't have the right check on the source table entries. Instead of
fixing that case, let's simplify the logic by creating a stub function
and making the alternatename pragma point to this stub. This way we get
rid of all those uneeded xxx_Null symbols/variables and simplify the
tests in vk_xxxx_dispatch_table_from_entrypoints().

Cc: mesa-stable
Fixes: 98c622a96e28 ("vulkan: Update dispatch table gen for Windows")
Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13348>
(cherry picked from commit 6d44b21d4fdea89673541de265f69258747c5499)

---

 .pick_status.json                        |  2 +-
 src/vulkan/util/vk_dispatch_table_gen.py | 16 ++++++++++++++--
 src/vulkan/util/vk_entrypoints_gen.py    |  5 ++---
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 43ac7726390..1b6be9711ba 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -85,7 +85,7 @@
         "description": "vulkan: Fix weak symbol emulation when compiling with MSVC",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "98c622a96e28020640517cb5499a1d7bd56553b0"
     },
diff --git a/src/vulkan/util/vk_dispatch_table_gen.py b/src/vulkan/util/vk_dispatch_table_gen.py
index 7eafa8ecb3c..509a246edc2 100644
--- a/src/vulkan/util/vk_dispatch_table_gen.py
+++ b/src/vulkan/util/vk_dispatch_table_gen.py
@@ -464,6 +464,13 @@ vk_device_entrypoint_is_enabled(int index, uint32_t core_version,
    }
 }
 
+#ifdef _MSC_VER
+void vk_entrypoint_stub(void)
+{
+   unreachable(!"Entrypoint not implemented");
+}
+#endif
+
 <%def name="dispatch_table_from_entrypoints(type)">
 void vk_${type}_dispatch_table_from_entrypoints(
     struct vk_${type}_dispatch_table *dispatch_table,
@@ -477,8 +484,8 @@ void vk_${type}_dispatch_table_from_entrypoints(
         memset(dispatch_table, 0, sizeof(*dispatch_table));
         for (unsigned i = 0; i < ARRAY_SIZE(${type}_compaction_table); i++) {
 #ifdef _MSC_VER
-            const uintptr_t zero = 0;
-            if (entry[i] == NULL || memcmp(entry[i], &zero, sizeof(zero)) == 0)
+            assert(entry[i] != NULL);
+            if (entry[i] == vk_entrypoint_stub)
 #else
             if (entry[i] == NULL)
 #endif
@@ -490,7 +497,12 @@ void vk_${type}_dispatch_table_from_entrypoints(
     } else {
         for (unsigned i = 0; i < ARRAY_SIZE(${type}_compaction_table); i++) {
             unsigned disp_index = ${type}_compaction_table[i];
+#ifdef _MSC_VER
+            assert(entry[i] != NULL);
+            if (disp[disp_index] == NULL && entry[i] != vk_entrypoint_stub)
+#else
             if (disp[disp_index] == NULL)
+#endif
                 disp[disp_index] = entry[i];
         }
     }
diff --git a/src/vulkan/util/vk_entrypoints_gen.py b/src/vulkan/util/vk_entrypoints_gen.py
index a8f50c71c24..b4a8985c1a3 100644
--- a/src/vulkan/util/vk_entrypoints_gen.py
+++ b/src/vulkan/util/vk_entrypoints_gen.py
@@ -123,13 +123,12 @@ TEMPLATE_C = Template(COPYRIGHT + """
     % endif
     % for p in prefixes:
 #ifdef _MSC_VER
-    ${e.return_type} (*${p}_${e.name}_Null)(${e.decl_params()}) = 0;
 #ifdef _M_IX86
       % for args_size in [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 60, 104]:
-    #pragma comment(linker, "/alternatename:_${p}_${e.name}@${args_size}=_${p}_${e.name}_Null")
+    #pragma comment(linker, "/alternatename:_${p}_${e.name}@${args_size}=_vk_entrypoint_stub")
       % endfor
 #else
-    #pragma comment(linker, "/alternatename:${p}_${e.name}=${p}_${e.name}_Null")
+    #pragma comment(linker, "/alternatename:${p}_${e.name}=vk_entrypoint_stub")
 #endif
 #else
     VKAPI_ATTR ${e.return_type} VKAPI_CALL ${p}_${e.name}(${e.decl_params()}) __attribute__ ((weak));



More information about the mesa-commit mailing list