Skip to content

Commit 754f83c

Browse files
committed
[HLSL] Add the DXC matrix orientation flags
fixes #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 7062cd6 commit 754f83c

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-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
@@ -9587,6 +9587,8 @@ class DXCJoinedOrSeparate<string name> : Option<["/", "-"], name,
95879587
KIND_JOINED_OR_SEPARATE>, Group<dxc_Group>,
95889588
Visibility<[DXCOption]>;
95899589

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

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,10 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
37233723
if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
37243724
!Args.hasArg(options::OPT_nostdinc))
37253725
CmdArgs.push_back("-finclude-default-header");
3726+
if (Args.hasArg(options::OPT_dxc_col_major))
3727+
CmdArgs.push_back("-fmatrix-memory-layout=column-major");
3728+
if (Args.hasArg(options::OPT_dxc_row_major))
3729+
CmdArgs.push_back("-fmatrix-memory-layout=row-major");
37263730
}
37273731

37283732
static void RenderOpenACCOptions(const Driver &D, const ArgList &Args,

clang/lib/Driver/ToolChains/HLSL.cpp

Lines changed: 4 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();
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)