-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[HLSL] Add the DXC matrix orientation flags #171550
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
[HLSL] Add the DXC matrix orientation flags #171550
Conversation
|
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang-driver Author: Farzon Lotfi (farzonl) Changesfixes #58676
Full diff: https://github.com/llvm/llvm-project/pull/171550.diff 5 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 3e6f7a2a430ff..fca84904326c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -826,6 +826,8 @@ def err_drv_target_variant_invalid : Error<
def err_drv_invalid_directx_shader_module : Error<
"invalid profile : %0">;
+def err_drv_dxc_invalid_matrix_layout : Error<
+ "cannot specify /Zpr and /Zpc together">;
def err_drv_dxc_missing_target_profile : Error<
"target profile option (-T) is missing">;
def err_drv_hlsl_unsupported_target : Error<
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index e55146f0c7823..35fb9d5bd227a 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -9587,6 +9587,8 @@ class DXCJoinedOrSeparate<string name> : Option<["/", "-"], name,
KIND_JOINED_OR_SEPARATE>, Group<dxc_Group>,
Visibility<[DXCOption]>;
+def dxc_col_major : DXCFlag<"Zpc">, HelpText<"Pack matrices in column-major order">;
+def dxc_row_major : DXCFlag<"Zpr">, HelpText<"Pack matrices in row-major order">;
def dxc_no_stdinc : DXCFlag<"hlsl-no-stdinc">,
HelpText<"HLSL only. Disables all standard includes containing non-native compiler types and functions.">;
def dxc_Fo : DXCJoinedOrSeparate<"Fo">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 542b70b3e9d4c..b0d1c994de160 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3723,6 +3723,10 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
!Args.hasArg(options::OPT_nostdinc))
CmdArgs.push_back("-finclude-default-header");
+ if (Args.hasArg(options::OPT_dxc_col_major))
+ CmdArgs.push_back("-fmatrix-memory-layout=column-major");
+ if (Args.hasArg(options::OPT_dxc_row_major))
+ CmdArgs.push_back("-fmatrix-memory-layout=row-major");
}
static void RenderOpenACCOptions(const Driver &D, const ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 5d7221b8718a9..8f58b2f449a9a 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -412,6 +412,10 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
const OptTable &Opts = getDriver().getOpts();
+ if (Args.hasArg(options::OPT_dxc_col_major) &&
+ Args.hasArg(options::OPT_dxc_row_major))
+ getDriver().Diag(diag::err_drv_dxc_invalid_matrix_layout);
+
for (Arg *A : Args) {
if (A->getOption().getID() == options::OPT_dxil_validator_version) {
StringRef ValVerStr = A->getValue();
diff --git a/clang/test/Driver/hlsl_matrix_pack_order.hlsl b/clang/test/Driver/hlsl_matrix_pack_order.hlsl
new file mode 100644
index 0000000000000..f7b6902fd02d8
--- /dev/null
+++ b/clang/test/Driver/hlsl_matrix_pack_order.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_dxc -T lib_6_7 -Zpr -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR
+// CHECK-ROW-MAJOR: -fmatrix-memory-layout=row-major
+
+// RUN: %clang_dxc -T lib_6_7 -Zpc -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR
+// CHECK-COL-MAJOR: -fmatrix-memory-layout=column-major
+
+// RUN: not %clang_dxc -Tlib_6_7 -Zpr -Zpc -fcgl -Fo - %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH-MAJOR
+// CHECK-MISMATCH-MAJOR: cannot specify /Zpr and /Zpc together
|
| if (Args.hasArg(options::OPT_dxc_col_major)) | ||
| CmdArgs.push_back("-fmatrix-memory-layout=column-major"); | ||
| if (Args.hasArg(options::OPT_dxc_row_major)) | ||
| CmdArgs.push_back("-fmatrix-memory-layout=row-major"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try and figure out how to replace this with
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 5d7221b8718a..11597b168f59 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -506,7 +510,18 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
A->claim();
continue;
}
-
+ if (A->getOption().getID() == options::OPT_dxc_col_major) {
+ DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_fmatrix_memory_layout_EQ),
+ "column-major");
+ A->claim();
+ continue;
+ }
+ if (A->getOption().getID() == options::OPT_dxc_row_major) {
+ DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_fmatrix_memory_layout_EQ),
+ "row-major");
+ A->claim();
+ continue;
+ }
DAL->append(A);
}
inbelic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although I think we should use AddJoinedArg instead of AddSeparateArg.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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
…ptions. Then set it via HLSLToolChain::TranslateArgs.
9e5df35 to
e4ad3c3
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/18942 Here is the relevant piece of the build log for the reference |
fixes #58676