-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[SPIRV][HLSL] Add DXC compatibility option for extension #151554
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
Open
s-perron
wants to merge
8
commits into
llvm:main
Choose a base branch
from
s-perron:dxc_ext
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−12
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
900c99b
[SPIRV][HLSL] Add DXC compatibility option for extension
s-perron 82730ee
Use ostream to build strings.
s-perron 96b944f
Update clang/lib/Driver/ToolChains/HLSL.cpp
s-perron 0049bac
Update clang/lib/Driver/ToolChains/HLSL.cpp
s-perron ea2db60
Update clang/lib/Driver/ToolChains/HLSL.cpp
s-perron 4371f50
Update clang/lib/Driver/ToolChains/HLSL.cpp
s-perron 78e60e6
Update clang/lib/Driver/ToolChains/HLSL.cpp
s-perron 20ab96a
Update clang/lib/Driver/ToolChains/HLSL.cpp
s-perron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -173,24 +173,84 @@ bool isLegalValidatorVersion(StringRef ValVersionStr, const Driver &D) { | |||||
return true; | ||||||
} | ||||||
|
||||||
std::string getSpirvExtArg(ArrayRef<std::string> SpvExtensionArgs) { | ||||||
void getSpirvExtOperand(llvm::StringRef SpvExtensionArg, raw_ostream &out) { | ||||||
// The extensions that are commented out are supported in DXC, but the SPIR-V | ||||||
// backend does not know about them yet. | ||||||
static const std::vector<StringRef> DxcSupportedExtensions = { | ||||||
"SPV_KHR_16bit_storage", | ||||||
"SPV_KHR_device_group", | ||||||
"SPV_KHR_fragment_shading_rate", | ||||||
"SPV_KHR_multiview", | ||||||
"SPV_KHR_post_depth_coverage", | ||||||
"SPV_KHR_non_semantic_info", | ||||||
"SPV_KHR_shader_draw_parameters", | ||||||
"SPV_KHR_ray_tracing", | ||||||
"SPV_KHR_shader_clock", | ||||||
"SPV_EXT_demote_to_helper_invocation", | ||||||
"SPV_EXT_descriptor_indexing", | ||||||
"SPV_EXT_fragment_fully_covered", | ||||||
"SPV_EXT_fragment_invocation_density", | ||||||
"SPV_EXT_fragment_shader_interlock", | ||||||
"SPV_EXT_mesh_shader", | ||||||
"SPV_EXT_shader_stencil_export", | ||||||
"SPV_EXT_shader_viewport_index_layer", | ||||||
// "SPV_AMD_shader_early_and_late_fragment_tests", | ||||||
"SPV_GOOGLE_hlsl_functionality1", | ||||||
"SPV_GOOGLE_user_type", | ||||||
"SPV_KHR_ray_query", | ||||||
"SPV_EXT_shader_image_int64", | ||||||
"SPV_KHR_fragment_shader_barycentric", | ||||||
"SPV_KHR_physical_storage_buffer", | ||||||
"SPV_KHR_vulkan_memory_model", | ||||||
// "SPV_KHR_compute_shader_derivatives", | ||||||
// "SPV_KHR_maximal_reconvergence", | ||||||
"SPV_KHR_float_controls", | ||||||
"SPV_NV_shader_subgroup_partitioned", | ||||||
// "SPV_KHR_quad_control" | ||||||
}; | ||||||
|
||||||
if (SpvExtensionArg.starts_with("SPV_")) { | ||||||
out << "+" << SpvExtensionArg; | ||||||
return; | ||||||
} | ||||||
|
||||||
if (SpvExtensionArg.compare_insensitive("DXC") == 0) { | ||||||
bool first = true; | ||||||
std::string Operand; | ||||||
for (llvm::StringRef E : DxcSupportedExtensions) { | ||||||
s-perron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (!first) | ||||||
out << ","; | ||||||
else | ||||||
first = false; | ||||||
out << "+" << E; | ||||||
} | ||||||
return; | ||||||
} | ||||||
out << SpvExtensionArg; | ||||||
return; | ||||||
} | ||||||
|
||||||
llvm::SmallString<1024> getSpirvExtArg(ArrayRef<std::string> SpvExtensionArgs) { | ||||||
s-perron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (SpvExtensionArgs.empty()) { | ||||||
return "-spirv-ext=all"; | ||||||
return llvm::StringRef("-spirv-ext=all"); | ||||||
s-perron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
std::string LlvmOption = | ||||||
(Twine("-spirv-ext=+") + SpvExtensionArgs.front()).str(); | ||||||
llvm::SmallString<1024> LlvmOption; | ||||||
raw_svector_ostream out(LlvmOption); | ||||||
|
||||||
out << "-spirv-ext="; | ||||||
getSpirvExtOperand(SpvExtensionArgs[0], out); | ||||||
|
||||||
SpvExtensionArgs = SpvExtensionArgs.slice(1); | ||||||
for (auto Extension : SpvExtensionArgs) { | ||||||
if (Extension != "KHR") | ||||||
Extension = (Twine("+") + Extension).str(); | ||||||
LlvmOption = (Twine(LlvmOption) + "," + Extension).str(); | ||||||
for (llvm::StringRef Extension : SpvExtensionArgs) { | ||||||
s-perron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
out << ","; | ||||||
getSpirvExtOperand(Extension, out); | ||||||
} | ||||||
return LlvmOption; | ||||||
} | ||||||
|
||||||
bool isValidSPIRVExtensionName(const std::string &str) { | ||||||
std::regex pattern("KHR|SPV_[a-zA-Z0-9_]+"); | ||||||
std::regex pattern("dxc|DXC|KHR|SPV_[a-zA-Z0-9_]+"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return std::regex_match(str, pattern); | ||||||
} | ||||||
|
||||||
|
@@ -371,7 +431,7 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch, | |||||
std::vector<std::string> SpvExtensionArgs = | ||||||
Args.getAllArgValues(options::OPT_fspv_extension_EQ); | ||||||
if (checkExtensionArgsAreValid(SpvExtensionArgs, getDriver())) { | ||||||
std::string LlvmOption = getSpirvExtArg(SpvExtensionArgs); | ||||||
llvm::SmallString<1024> LlvmOption = getSpirvExtArg(SpvExtensionArgs); | ||||||
s-perron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_mllvm), | ||||||
LlvmOption); | ||||||
} | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,6 +14,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 | ||||
// TEST3: "-spirv-ext=+SPV_TEST1,KHR,+SPV_TEST2" | ||||
|
||||
// Merge KHR with other extensions. | ||||
// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=KHR -fspv-extension=SPV_TEST2 2>&1 | FileCheck %s -check-prefix=TEST4 | ||||
// TEST4: "-spirv-ext=KHR,+SPV_TEST2" | ||||
|
||||
// Merge KHR with other extensions. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment seems wrong
Suggested change
|
||||
// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=DXC 2>&1 | FileCheck %s -check-prefix=TEST5 | ||||
// TEST5: "-spirv-ext={{(\+SPV_[a-zA-Z0-9_]+,?)+}}" | ||||
|
||||
// Check for the error message if the extension name is not properly formed. | ||||
// 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' | ||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.