From f283c38f9ca9691f258a47dd1d19570b78e6eed6 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 3 Jul 2024 20:43:06 +0200 Subject: [PATCH] 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: --- src/compiler/clc/clc_helpers.cpp | 7 +++++++ src/compiler/clc/meson.build | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index dda4a63ac45..c95ed657038 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -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 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; } diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build index 10248ebf5c0..bd558d25566 100644 --- a/src/compiler/clc/meson.build +++ b/src/compiler/clc/meson.build @@ -82,6 +82,19 @@ else endif endif +has_spirv_link_workaround = cpp.has_member( + 'spvtools::LinkerOptions', + 'SetAllowPtrTypeMismatch(true)', + prefix : [ + '#include ', + ], + 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,