Skip to content

Commit

Permalink
[SPIRV] Add -spirv option to DXC driver (#65989)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sudonatalie committed Nov 1, 2023
1 parent 370e9b5 commit 6c320b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8326,3 +8326,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
Flags<[Ignored]>, Visibility<[DXCOption]>,
HelpText<"Embed PDB in shader container (ignored)">;
def spirv : DXCFlag<"spirv">,
HelpText<"Generate SPIR-V code">;
7 changes: 7 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;

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);
TargetTriple = T.str();
}
} else {
Diag(diag::err_drv_dxc_missing_target_profile);
}
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/dxc_spirv.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s

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

0 comments on commit 6c320b4

Please sign in to comment.