https://github.com/s-perron created https://github.com/llvm/llvm-project/pull/145536
In DXC, there is an option to enable all KHR extension. This is added by passing the KHR option to the SPIR-V backend, which will enable all of the appropriate extensions. Part of https://github.com/llvm/llvm-project/issues/137650. >From af0773cd9677d90d2fe2466fa113d70983fc2c32 Mon Sep 17 00:00:00 2001 From: Steven Perron <stevenper...@google.com> Date: Tue, 24 Jun 2025 11:41:12 -0400 Subject: [PATCH] [HLSL][SPIRV] Add option to add all KHR extensions In DXC, there is an option to enable all KHR extension. This is added by passing the KHR option to the SPIR-V backend, which will enable all of the appropriate extensions. Part of https://github.com/llvm/llvm-project/issues/137650. --- clang/lib/Driver/ToolChains/HLSL.cpp | 6 ++++-- clang/test/Driver/dxc_fspv_extension.hlsl | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp index dcc51e182924c..14bbd61c5178a 100644 --- a/clang/lib/Driver/ToolChains/HLSL.cpp +++ b/clang/lib/Driver/ToolChains/HLSL.cpp @@ -182,13 +182,15 @@ std::string getSpirvExtArg(ArrayRef<std::string> SpvExtensionArgs) { (Twine("-spirv-ext=+") + SpvExtensionArgs.front()).str(); SpvExtensionArgs = SpvExtensionArgs.slice(1); for (auto Extension : SpvExtensionArgs) { - LlvmOption = (Twine(LlvmOption) + ",+" + Extension).str(); + if (Extension != "KHR") + Extension = (Twine("+") + Extension).str(); + LlvmOption = (Twine(LlvmOption) + "," + Extension).str(); } return LlvmOption; } bool isValidSPIRVExtensionName(const std::string &str) { - std::regex pattern("SPV_[a-zA-Z0-9_]+"); + std::regex pattern("KHR|SPV_[a-zA-Z0-9_]+"); return std::regex_match(str, pattern); } diff --git a/clang/test/Driver/dxc_fspv_extension.hlsl b/clang/test/Driver/dxc_fspv_extension.hlsl index 0a9d321b8d95e..7cb7990568d3e 100644 --- a/clang/test/Driver/dxc_fspv_extension.hlsl +++ b/clang/test/Driver/dxc_fspv_extension.hlsl @@ -10,8 +10,13 @@ // RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=SPV_TEST1 -fspv-extension=SPV_TEST2 2>&1 | FileCheck %s -check-prefix=TEST2 // TEST2: "-spirv-ext=+SPV_TEST1,+SPV_TEST2" +// Merge KHR with other extensions. +// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=SPV_TEST1 -fspv-extension=KHR -fspv-extension=SPV_TEST2 2>&1 | FileCheck %s -check-prefix=TEST3 +// TEST3: "-spirv-ext=+SPV_TEST1,KHR,+SPV_TEST2" + // Check for the error message if the extension name is not properly formed. -// RUN: not %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=TEST1 -fspv-extension=SPV_GOOD -fspv-extension=TEST2 2>&1 | FileCheck %s -check-prefix=FAIL +// RUN: not %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=KHR_BAD -fspv-extension=TEST1 -fspv-extension=SPV_GOOD -fspv-extension=TEST2 2>&1 | FileCheck %s -check-prefix=FAIL +// FAIL: invalid value 'KHR_BAD' in '-fspv_extension' // FAIL: invalid value 'TEST1' in '-fspv_extension' // FAIL: invalid value 'TEST2' in '-fspv_extension' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits