https://github.com/dnovillo updated https://github.com/llvm/llvm-project/pull/239374
>From f088f43a5a96dea644ba7b2ed14751897f0a58bf Mon Sep 17 00:00:00 2001 From: Diego Novillo <[email protected]> Date: Thu, 5 Nov 2026 15:51:51 -0500 Subject: [PATCH] [HLSL][Driver][SPIRV] Default -fspv-extension to the DXC extension set --- clang/docs/ReleaseNotes.md | 4 ++++ clang/include/clang/Options/Options.td | 11 +++++++---- clang/lib/Driver/ToolChains/HLSL.cpp | 10 ++++++---- clang/test/Driver/dxc_fspv_extension.hlsl | 12 ++++++++++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index a946932d3ecee..282b26257fb99 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -436,6 +436,10 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and separated from surrounding arguments by whitespace. Quoted arguments can no longer be split across multiple lines using a backslash. +- `clang-dxc -spirv` without `-fspv-extension` now enables the SPIR-V + extensions that DXC implements, as `-fspv-extension=DXC` does, instead of all + extensions. `-fspv-extension=all` restores the previous behavior. + ### Removed Compiler Flags ### Attribute Changes in Clang diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 15c9c188a4316..32e719e839592 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -10193,10 +10193,13 @@ def fspv_extension_EQ Group<dxc_Group>, HelpText< "Specify the available SPIR-V extensions. If this option is not " - "specified, then all extensions are available. If KHR is specified, " - "then all KHR extensions will be available. If DXC is specifided, " - "then all extensions implemented by the DirectX Shader compiler will " - "be available. This option is useful for moving from DXC to Clang.">; + "specified, then all extensions implemented by the DirectX Shader " + "compiler are available. If KHR is specified, then all KHR " + "extensions will be available. If DXC is specified, then all " + "extensions implemented by the DirectX Shader compiler will be " + "available. If all is specified, then all extensions the SPIR-V " + "backend supports will be available. This option is useful for " + "moving from DXC to Clang.">; def fvk_use_dx_layout : DXCFlag<"fvk-use-dx-layout">, HelpText<"Use DirectX memory layout for Vulkan resources.">; diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp index f9efe79628a3b..240351500b182 100644 --- a/clang/lib/Driver/ToolChains/HLSL.cpp +++ b/clang/lib/Driver/ToolChains/HLSL.cpp @@ -243,9 +243,11 @@ void getSpirvExtOperand(StringRef SpvExtensionArg, raw_ostream &out) { } SmallString<1024> getSpirvExtArg(ArrayRef<std::string> SpvExtensionArgs) { - if (SpvExtensionArgs.empty()) { - return StringRef("-spirv-ext=all"); - } + // The backend uses any enabled extension it can, so `all` makes modules + // declare extensions that a Vulkan application may not have enabled. + const std::string DefaultExtension = "DXC"; + if (SpvExtensionArgs.empty()) + SpvExtensionArgs = ArrayRef<std::string>(DefaultExtension); llvm::SmallString<1024> LlvmOption; raw_svector_ostream out(LlvmOption); @@ -262,7 +264,7 @@ SmallString<1024> getSpirvExtArg(ArrayRef<std::string> SpvExtensionArgs) { } bool isValidSPIRVExtensionName(const std::string &str) { - std::regex pattern("dxc|DXC|khr|KHR|SPV_[a-zA-Z0-9_]+"); + std::regex pattern("dxc|DXC|khr|KHR|all|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 aeba9f56463f8..06025856dd51f 100644 --- a/clang/test/Driver/dxc_fspv_extension.hlsl +++ b/clang/test/Driver/dxc_fspv_extension.hlsl @@ -1,7 +1,15 @@ -// If there is no `-fspv-extension`, enable all extensions. -// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s 2>&1 | FileCheck %s -check-prefix=ALL +// If there is no `-fspv-extension`, enable the extensions DXC implements, and +// not SPV_KHR_fma, SPV_KHR_float_controls2 or SPV_EXT_long_vector. +// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s 2>&1 | FileCheck %s -check-prefix=DEFAULT --implicit-check-not=SPV_KHR_fma --implicit-check-not=SPV_KHR_float_controls2 --implicit-check-not=SPV_EXT_long_vector --implicit-check-not=-spirv-ext=all +// DEFAULT: "-spirv-ext={{(\+SPV_[a-zA-Z0-9_]+,?)+}}" + +// `-fspv-extension=all` enables every extension the backend supports. +// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=all 2>&1 | FileCheck %s -check-prefix=ALL // ALL: "-spirv-ext=all" +// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=all -fspv-extension=SPV_TEST1 2>&1 | FileCheck %s -check-prefix=ALL2 +// ALL2: "-spirv-ext=all,+SPV_TEST1" + // Convert the `-fspv-extension` into `spirv-ext`. // RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=SPV_TEST1 2>&1 | FileCheck %s -check-prefix=TEST1 // TEST1: "-spirv-ext=+SPV_TEST1" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
