Skip to content

[HLSL][SPIRV] Add option to add all KHR extensions #145536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025

Conversation

s-perron
Copy link
Contributor

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 #137650.

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 llvm#137650.
@s-perron s-perron requested a review from Keenuts June 24, 2025 15:47
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' HLSL HLSL Language Support labels Jun 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-clang-driver

Author: Steven Perron (s-perron)

Changes

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 #137650.


Full diff: https://github.com/llvm/llvm-project/pull/145536.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+4-2)
  • (modified) clang/test/Driver/dxc_fspv_extension.hlsl (+6-1)
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'
 

@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-hlsl

Author: Steven Perron (s-perron)

Changes

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 #137650.


Full diff: https://github.com/llvm/llvm-project/pull/145536.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+4-2)
  • (modified) clang/test/Driver/dxc_fspv_extension.hlsl (+6-1)
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'
 

@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-clang

Author: Steven Perron (s-perron)

Changes

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 #137650.


Full diff: https://github.com/llvm/llvm-project/pull/145536.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+4-2)
  • (modified) clang/test/Driver/dxc_fspv_extension.hlsl (+6-1)
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'
 

@s-perron s-perron merged commit 1d60d91 into llvm:main Jun 26, 2025
8 checks passed
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
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 llvm#137650.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants