[clang] [HLSL][Driver][SPIRV] Default -fspv-extension to the DXC extension set (PR #239374)
Diego Novillo via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 13:04:07 PST 2026
https://github.com/dnovillo created https://github.com/llvm/llvm-project/pull/239374
Without `-fspv-extension`, `clang-dxc -spirv` passes `-spirv-ext=all`, which causes Vulkan modules to declare extensions such as `SPV_KHR_fma`, `SPV_KHR_float_controls2` and `SPV_EXT_long_vector`. Applications that did not enable the matching features fail validation. This does not happen to DXC's modules for the same shaders.
This change passes the list that `-fspv-extension=DXC` produces instead. `-fspv-extension=all` restores the old behavior.
`dxc_fspv_extension.hlsl` checks the default list and `-fspv-extension=all`.
Fixes [#237364](https://github.com/llvm/llvm-project/issues/237364).
>From 25b0a7654af68968f4fad602263abc2970b4cfa4 Mon Sep 17 00:00:00 2001
From: Diego Novillo <dnovillo at nvidia.com>
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 6a2201012693e2..2b3e38eb40ad06 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -263,6 +263,10 @@ features cannot lower the translation-unit ABI level;
- All options of the `-fzero-call-used-regs` compiler flag are now allowed on RISC-V.
+- `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 50fc7a75b7695f..391d1f2eba4a4b 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -10052,10 +10052,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 9e7005b8798f20..7bd4ea4a7e0344 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 aeba9f56463f8b..06025856dd51fb 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"
More information about the cfe-commits
mailing list