mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 17:30:12 +01:00
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: 98c622a96e ("vulkan: Update dispatch table gen for Windows")
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13348>
This commit is contained in:
parent
ae99ea6f4d
commit
6d44b21d4f
2 changed files with 16 additions and 5 deletions
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue