[clang] b581f9d - [HLSL] Add option for VK layouts (#145327)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 24 07:51:33 PDT 2025


Author: Steven Perron
Date: 2025-06-24T10:51:22-04:00
New Revision: b581f9d056babadf55098b9d5d100271621b90db

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

LOG: [HLSL] Add option for VK layouts (#145327)

We add the options to the driver, so that the one option that is being
implemented at this time can be used. Issue an error for the other
options.

When we start to implement the other options, we will have to figure out
how to pass which  option is active to clang.

Part of but does not complete:

https://github.com/llvm/llvm-project/issues/136956
https://github.com/llvm/llvm-project/issues/136959
https://github.com/llvm/llvm-project/issues/136958

Added: 
    clang/test/Driver/HLSL/dxc_fvk_layout.hlsl

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/HLSL.cpp
    clang/test/Driver/dxc_fspv_extension.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index e133ac97a4ffc..4f91b82a3bfa6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -9326,6 +9326,16 @@ def fspv_extension_EQ
       Group<dxc_Group>,
       HelpText<"Specify the available SPIR-V extensions. If this option is not "
                "specified, then all extensions are available.">;
+def fvk_use_dx_layout
+    : DXCFlag<"fvk-use-dx-layout">,
+      HelpText<"Use DirectX memory layout for Vulkan resources.">;
+def fvk_use_gl_layout : DXCFlag<"fvk-use-gl-layout">,
+                        HelpText<"Use strict OpenGL std140/std430 memory "
+                                 "layout for Vulkan resources.">;
+def fvk_use_scalar_layout
+    : DXCFlag<"fvk-use-scalar-layout">,
+      HelpText<"Use scalar memory layout for Vulkan resources.">;
+
 def no_wasm_opt : Flag<["--"], "no-wasm-opt">,
   Group<m_Group>,
   HelpText<"Disable the wasm-opt optimizer">,

diff  --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index dcc51e182924c..be59cc895667a 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -200,7 +200,7 @@ bool checkExtensionArgsAreValid(ArrayRef<std::string> SpvExtensionArgs,
   for (auto Extension : SpvExtensionArgs) {
     if (!isValidSPIRVExtensionName(Extension)) {
       Driver.Diag(diag::err_drv_invalid_value)
-          << "-fspv_extension" << Extension;
+          << "-fspv-extension" << Extension;
       AllValid = false;
     }
   }
@@ -330,6 +330,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
       A->claim();
       continue;
     }
+
+    if (A->getOption().getID() == options::OPT_fvk_use_dx_layout) {
+      // This is the only implemented layout so far.
+      A->claim();
+      continue;
+    }
+
+    if (A->getOption().getID() == options::OPT_fvk_use_scalar_layout) {
+      getDriver().Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
+      A->claim();
+      continue;
+    }
+
+    if (A->getOption().getID() == options::OPT_fvk_use_gl_layout) {
+      getDriver().Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
+      A->claim();
+      continue;
+    }
+
     DAL->append(A);
   }
 

diff  --git a/clang/test/Driver/HLSL/dxc_fvk_layout.hlsl b/clang/test/Driver/HLSL/dxc_fvk_layout.hlsl
new file mode 100644
index 0000000000000..a796fbb8e052b
--- /dev/null
+++ b/clang/test/Driver/HLSL/dxc_fvk_layout.hlsl
@@ -0,0 +1,8 @@
+// No errors. Otherwise nothing observable.
+// RUN: %clang_dxc -fvk-use-dx-layout -spirv -Tlib_6_7 -### %s
+
+// RUN: not %clang_dxc -fvk-use-scalar-layout -spirv -Tlib_6_7 -### %s 2>&1 | FileCheck %s -check-prefix=SCALAR
+// SCALAR: error: the clang compiler does not support '-fvk-use-scalar-layout'
+
+// RUN: not %clang_dxc -fvk-use-gl-layout -spirv -Tlib_6_7 -### %s 2>&1 | FileCheck %s -check-prefix=GL
+// GL: error: the clang compiler does not support '-fvk-use-gl-layout' 

diff  --git a/clang/test/Driver/dxc_fspv_extension.hlsl b/clang/test/Driver/dxc_fspv_extension.hlsl
index 0a9d321b8d95e..ff414ab6c0a6e 100644
--- a/clang/test/Driver/dxc_fspv_extension.hlsl
+++ b/clang/test/Driver/dxc_fspv_extension.hlsl
@@ -12,8 +12,8 @@
 
 // Check for the error message if the extension name is not properly formed.
 // RUN: not %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=TEST1 -fspv-extension=SPV_GOOD -fspv-extension=TEST2 2>&1 | FileCheck %s -check-prefix=FAIL
-// FAIL: invalid value 'TEST1' in '-fspv_extension'
-// FAIL: invalid value 'TEST2' in '-fspv_extension'
+// FAIL: invalid value 'TEST1' in '-fspv-extension'
+// FAIL: invalid value 'TEST2' in '-fspv-extension'
 
 // If targeting DXIL, the `-spirv-ext` should not be passed to the backend.
 // RUN: %clang_dxc -Tlib_6_7 -### %s 2>&1 | FileCheck %s -check-prefix=DXIL


        


More information about the cfe-commits mailing list