Skip to content

[HLSL][SPIR-V] Add support -fspv-target-env opt #78611

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 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8463,3 +8463,6 @@ def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
HelpText<"Embed PDB in shader container (ignored)">;
def spirv : DXCFlag<"spirv">,
HelpText<"Generate SPIR-V code">;
def fspv_target_env_EQ : Joined<["-"], "fspv-target-env=">, Group<dxc_Group>,
HelpText<"Specify the target environment">,
Values<"vulkan1.2, vulkan1.3">;
15 changes: 14 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,10 +1310,23 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {

A->claim();

// TODO: Specify Vulkan target environment somewhere in the triple.
if (Args.hasArg(options::OPT_spirv)) {
llvm::Triple T(TargetTriple);
T.setArch(llvm::Triple::spirv);
T.setOS(llvm::Triple::Vulkan);

// Set specific Vulkan version if applicable.
if (const Arg *A = Args.getLastArg(options::OPT_fspv_target_env_EQ)) {
const llvm::StringSet<> ValidValues = {"vulkan1.2", "vulkan1.3"};
if (ValidValues.contains(A->getValue())) {
T.setOSName(A->getValue());
} else {
Diag(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();
}
A->claim();
}

TargetTriple = T.str();
}
} else {
Expand Down
11 changes: 10 additions & 1 deletion clang/test/Driver/dxc_spirv.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
// RUN: %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.2 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-VULKAN12
// RUN: %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.3 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-VULKAN13
// RUN: not %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.0 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR

// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
// CHECK: "-triple" "spirv-unknown-vulkan-compute"
// CHECK-SAME: "-x" "hlsl"

// CHECK-VULKAN12: "-triple" "spirv-unknown-vulkan1.2-compute"

// CHECK-VULKAN13: "-triple" "spirv-unknown-vulkan1.3-compute"

// CHECK-ERROR: error: invalid value 'vulkan1.0' in '-fspv-target-env=vulkan1.0'