Skip to content

Commit 2b1fa68

Browse files
authored
[HLSL] Add the DXC matrix orientation flags (llvm#171550)
fixes llvm#58676 - Make /Zpr and /Zpc turn on the -fmatrix-memory-layout= row-major and column-major flags - Add the new DXC driver flags to Options.td - Error in the HLSL toolchain when both flags are specified - Add the new error diagnostic to DiagnosticDriverKinds.td - propogate the flag via the Clang toolchain
1 parent e13998f commit 2b1fa68

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ def err_drv_target_variant_invalid : Error<
826826

827827
def err_drv_invalid_directx_shader_module : Error<
828828
"invalid profile : %0">;
829+
def err_drv_dxc_invalid_matrix_layout : Error<
830+
"cannot specify /Zpr and /Zpc together">;
829831
def err_drv_dxc_missing_target_profile : Error<
830832
"target profile option (-T) is missing">;
831833
def err_drv_hlsl_unsupported_target : Error<

clang/include/clang/Options/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9603,6 +9603,8 @@ class DXCJoinedOrSeparate<string name> : Option<["/", "-"], name,
96039603
KIND_JOINED_OR_SEPARATE>, Group<dxc_Group>,
96049604
Visibility<[DXCOption]>;
96059605

9606+
def dxc_col_major : DXCFlag<"Zpc">, HelpText<"Pack matrices in column-major order">;
9607+
def dxc_row_major : DXCFlag<"Zpr">, HelpText<"Pack matrices in row-major order">;
96069608
def dxc_no_stdinc : DXCFlag<"hlsl-no-stdinc">,
96079609
HelpText<"HLSL only. Disables all standard includes containing non-native compiler types and functions.">;
96089610
def dxc_Fo : DXCJoinedOrSeparate<"Fo">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,7 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
37093709
options::OPT_disable_llvm_passes,
37103710
options::OPT_fnative_half_type,
37113711
options::OPT_fnative_int16_type,
3712+
options::OPT_fmatrix_memory_layout_EQ,
37123713
options::OPT_hlsl_entrypoint,
37133714
options::OPT_fdx_rootsignature_define,
37143715
options::OPT_fdx_rootsignature_version,

clang/lib/Driver/ToolChains/HLSL.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
412412

413413
const OptTable &Opts = getDriver().getOpts();
414414

415+
if (Args.hasArg(options::OPT_dxc_col_major) &&
416+
Args.hasArg(options::OPT_dxc_row_major))
417+
getDriver().Diag(diag::err_drv_dxc_invalid_matrix_layout);
418+
415419
for (Arg *A : Args) {
416420
if (A->getOption().getID() == options::OPT_dxil_validator_version) {
417421
StringRef ValVerStr = A->getValue();
@@ -506,6 +510,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
506510
A->claim();
507511
continue;
508512
}
513+
if (A->getOption().getID() == options::OPT_dxc_col_major) {
514+
DAL->AddJoinedArg(nullptr,
515+
Opts.getOption(options::OPT_fmatrix_memory_layout_EQ),
516+
"column-major");
517+
A->claim();
518+
continue;
519+
}
520+
if (A->getOption().getID() == options::OPT_dxc_row_major) {
521+
DAL->AddJoinedArg(nullptr,
522+
Opts.getOption(options::OPT_fmatrix_memory_layout_EQ),
523+
"row-major");
524+
A->claim();
525+
continue;
526+
}
509527

510528
DAL->append(A);
511529
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_dxc -T lib_6_7 -Zpr -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR
2+
// CHECK-ROW-MAJOR: -fmatrix-memory-layout=row-major
3+
4+
// RUN: %clang_dxc -T lib_6_7 -Zpc -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR
5+
// CHECK-COL-MAJOR: -fmatrix-memory-layout=column-major
6+
7+
// RUN: not %clang_dxc -Tlib_6_7 -Zpr -Zpc -fcgl -Fo - %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH-MAJOR
8+
// CHECK-MISMATCH-MAJOR: cannot specify /Zpr and /Zpc together

0 commit comments

Comments
 (0)