Skip to content

[HLSL] Add option for VK layouts #145327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">,
Expand Down
21 changes: 20 additions & 1 deletion clang/lib/Driver/ToolChains/HLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions clang/test/Driver/HLSL/dxc_fvk_layout.hlsl
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 2 additions & 2 deletions clang/test/Driver/dxc_fspv_extension.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down