clc: force linking of spirvs with mismatching pointer types in signatures

With LLVM-17 and opaque pointers, sometimes the compiled spirvs lose all
their information in regards to what specific pointer type a function
parameter has.

To workaround this, we can tell the spirv linker to insert casts to handle
those cases.

See https://github.com/KhronosGroup/SPIRV-Tools/pull/5534

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30029>
This commit is contained in:
Karol Herbst
2024-07-03 20:43:06 +02:00
committed by Marge Bot
parent ec46d2a8f2
commit f283c38f9c
2 changed files with 20 additions and 0 deletions

View File

@@ -1228,10 +1228,17 @@ clc_link_spirv_binaries(const struct clc_linker_args *args,
context.SetMessageConsumer(msgconsumer);
spvtools::LinkerOptions options;
options.SetAllowPartialLinkage(args->create_library);
#if defined(HAS_SPIRV_LINK_LLVM_WORKAROUND) && LLVM_VERSION_MAJOR >= 17
options.SetAllowPtrTypeMismatch(true);
#endif
options.SetCreateLibrary(args->create_library);
std::vector<uint32_t> linkingResult;
spv_result_t status = spvtools::Link(context, binaries, &linkingResult, options);
if (status != SPV_SUCCESS) {
#if !defined(HAS_SPIRV_LINK_LLVM_WORKAROUND) && LLVM_VERSION_MAJOR >= 17
clc_warning(logger, "SPIRV-Tools doesn't contain https://github.com/KhronosGroup/SPIRV-Tools/pull/5534\n");
clc_warning(logger, "Please update in order to prevent spurious linking failures\n");
#endif
return -1;
}

View File

@@ -82,6 +82,19 @@ else
endif
endif
has_spirv_link_workaround = cpp.has_member(
'spvtools::LinkerOptions',
'SetAllowPtrTypeMismatch(true)',
prefix : [
'#include <spirv-tools/linker.hpp>',
],
dependencies : dep_spirv_tools,
)
if has_spirv_link_workaround
_libmesaclc_c_args += ['-DHAS_SPIRV_LINK_LLVM_WORKAROUND=1']
endif
_libmesaclc = static_library(
'libmesaclc',
files_libmesaclc,