[clang] 6c320b4 - [SPIRV] Add -spirv option to DXC driver (#65989)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 1 10:41:34 PDT 2023


Author: Natalie Chouinard
Date: 2023-11-01T13:41:30-04:00
New Revision: 6c320b434d249c0d5692cbecc0e67ec22d659b7e

URL: https://github.com/llvm/llvm-project/commit/6c320b434d249c0d5692cbecc0e67ec22d659b7e
DIFF: https://github.com/llvm/llvm-project/commit/6c320b434d249c0d5692cbecc0e67ec22d659b7e.diff

LOG: [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

Added: 
    clang/test/Driver/dxc_spirv.hlsl

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c8b730e0f7ecd84..b1229b2f4562379 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -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">;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index bbbb30ae2201ab8..6f5ff8141032677 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -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);
     }

diff  --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000000000000000..a3c5c30af06e3c8
--- /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"


        


More information about the cfe-commits mailing list