[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)
Natalie Chouinard via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 07:20:23 PDT 2023
https://github.com/sudonatalie updated https://github.com/llvm/llvm-project/pull/65989
>From 331e1a92f2d93dcd5e7e1cae25ce51f33b2c8ffe Mon Sep 17 00:00:00 2001
From: Natalie Chouinard <chouinard at google.com>
Date: Mon, 11 Sep 2023 18:08:17 +0000
Subject: [PATCH 1/3] [SPIRV] Add -spirv option to DXC driver
Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
clang/include/clang/Driver/Options.td | 2 ++
clang/lib/Driver/Driver.cpp | 6 ++++++
clang/test/Driver/dxc_spirv.hlsl | 4 ++++
3 files changed, 12 insertions(+)
create mode 100644 clang/test/Driver/dxc_spirv.hlsl
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..5e0aa80bc64945d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8324,3 +8324,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">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index bbbb30ae2201ab8..92fbdcabe9cfdc9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1303,6 +1303,12 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
A->claim();
+
+ 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);
}
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000000000000000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -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"
\ No newline at end of file
>From d0be295583dd279de25ee65124712aa9e9f694be Mon Sep 17 00:00:00 2001
From: Natalie Chouinard <chouinard at google.com>
Date: Tue, 24 Oct 2023 14:40:36 +0000
Subject: [PATCH 2/3] Add TODO
---
clang/lib/Driver/Driver.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 92fbdcabe9cfdc9..6f5ff8141032677 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1304,6 +1304,7 @@ 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);
>From 96e3a24bf3fafe715054969d859fbe44a0b9dc25 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard <chouinard at google.com>
Date: Tue, 24 Oct 2023 14:51:20 +0000
Subject: [PATCH 3/3] EOF newlines
---
clang/include/clang/Driver/Options.td | 2 +-
clang/test/Driver/dxc_spirv.hlsl | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 5e0aa80bc64945d..474263699c47ee2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8325,4 +8325,4 @@ 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">;
\ No newline at end of file
+ HelpText<"Generate SPIR-V code">;
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
index 387b71ca58ada18..a3c5c30af06e3c8 100644
--- a/clang/test/Driver/dxc_spirv.hlsl
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -1,4 +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"
\ No newline at end of file
+// CHECK-SAME: "-x" "hlsl"
More information about the cfe-commits
mailing list