Skip to content

Commit 6c320b4

Browse files
authored
[SPIRV] Add -spirv option to DXC driver (#65989)
Add an option to target SPIR-V to the clang-dxc driver, which sets the target triple's architecture to logical SPIR-V. This does not yet address the need for a Vulkan target environment in the triple, tracked in Issue #70051. Depends on #70330
1 parent 370e9b5 commit 6c320b4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8326,3 +8326,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
83268326
def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
83278327
Flags<[Ignored]>, Visibility<[DXCOption]>,
83288328
HelpText<"Embed PDB in shader container (ignored)">;
8329+
def spirv : DXCFlag<"spirv">,
8330+
HelpText<"Generate SPIR-V code">;

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
13031303
Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
13041304

13051305
A->claim();
1306+
1307+
// TODO: Specify Vulkan target environment somewhere in the triple.
1308+
if (Args.hasArg(options::OPT_spirv)) {
1309+
llvm::Triple T(TargetTriple);
1310+
T.setArch(llvm::Triple::spirv);
1311+
TargetTriple = T.str();
1312+
}
13061313
} else {
13071314
Diag(diag::err_drv_dxc_missing_target_profile);
13081315
}

clang/test/Driver/dxc_spirv.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
2+
3+
// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
4+
// CHECK-SAME: "-x" "hlsl"

0 commit comments

Comments
 (0)