Skip to content

Commit 1d60d91

Browse files
authored
[HLSL][SPIRV] Add option to add all KHR extensions (#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 #137650.
1 parent 0a2b6f6 commit 1d60d91

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Driver/ToolChains/HLSL.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ std::string getSpirvExtArg(ArrayRef<std::string> SpvExtensionArgs) {
182182
(Twine("-spirv-ext=+") + SpvExtensionArgs.front()).str();
183183
SpvExtensionArgs = SpvExtensionArgs.slice(1);
184184
for (auto Extension : SpvExtensionArgs) {
185-
LlvmOption = (Twine(LlvmOption) + ",+" + Extension).str();
185+
if (Extension != "KHR")
186+
Extension = (Twine("+") + Extension).str();
187+
LlvmOption = (Twine(LlvmOption) + "," + Extension).str();
186188
}
187189
return LlvmOption;
188190
}
189191

190192
bool isValidSPIRVExtensionName(const std::string &str) {
191-
std::regex pattern("SPV_[a-zA-Z0-9_]+");
193+
std::regex pattern("KHR|SPV_[a-zA-Z0-9_]+");
192194
return std::regex_match(str, pattern);
193195
}
194196

clang/test/Driver/dxc_fspv_extension.hlsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=SPV_TEST1 -fspv-extension=SPV_TEST2 2>&1 | FileCheck %s -check-prefix=TEST2
1111
// TEST2: "-spirv-ext=+SPV_TEST1,+SPV_TEST2"
1212

13+
// Merge KHR with other extensions.
14+
// 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
15+
// TEST3: "-spirv-ext=+SPV_TEST1,KHR,+SPV_TEST2"
16+
1317
// Check for the error message if the extension name is not properly formed.
14-
// 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
18+
// 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
19+
// FAIL: invalid value 'KHR_BAD' in '-fspv-extension'
1520
// FAIL: invalid value 'TEST1' in '-fspv-extension'
1621
// FAIL: invalid value 'TEST2' in '-fspv-extension'
1722

0 commit comments

Comments
 (0)