Skip to content

Conversation

inbelic
Copy link
Contributor

@inbelic inbelic commented Sep 9, 2025

This pr adds Frs as a DXC driver option.

It is done by invoking llvm-objcopy with the extract-section=RTS0
argument specified to output the separate DXContainer.

Option behaviour as a reference is found here.

This resolves: #150277.

This pr adds the `Frs` as a DXC driver option.

It is done by invoking `llvm-objcopy` with the `extract-section=RTS0`
argument specified to output the separate `DXContainer`.

This resolves: .
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' HLSL HLSL Language Support labels Sep 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Finn Plummer (inbelic)

Changes

This pr adds the Frs as a DXC driver option.

It is done by invoking llvm-objcopy with the extract-section=RTS0
argument specified to output the separate DXContainer.

This resolves: #150277.


Full diff: https://github.com/llvm/llvm-project/pull/157690.diff

3 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+2)
  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+9-2)
  • (added) clang/test/Driver/dxc_frs.hlsl (+10)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ea5a94f840470..123caa9d35520 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -9418,6 +9418,8 @@ def dxc_Fo : DXCJoinedOrSeparate<"Fo">,
   HelpText<"Output object file">;
 def dxc_Fc : DXCJoinedOrSeparate<"Fc">,
   HelpText<"Output assembly listing file">;
+def dxc_Frs : DXCJoinedOrSeparate<"Frs">,
+  HelpText<"Output additional root signature object file">;
 def dxil_validator_version : Option<["/", "-"], "validator-version", KIND_SEPARATE>,
   Group<dxc_Group>, Flags<[HelpHidden]>,
   Visibility<[DXCOption, ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 559af32dc3808..1bb7aa02188f9 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -313,7 +313,13 @@ void tools::hlsl::LLVMObjcopy::ConstructJob(Compilation &C, const JobAction &JA,
   CmdArgs.push_back(Output.getFilename());
 
   if (Args.hasArg(options::OPT_dxc_strip_rootsignature)) {
-    const char *Frs = Args.MakeArgString("--remove-section=RTS0");
+    const char *StripRS = Args.MakeArgString("--remove-section=RTS0");
+    CmdArgs.push_back(StripRS);
+  }
+
+  if (Arg *Arg = Args.getLastArg(options::OPT_dxc_Frs)) {
+    const char *Frs =
+        Args.MakeArgString("--extract-section=RTS0=" + Twine(Arg->getValue()));
     CmdArgs.push_back(Frs);
   }
 
@@ -493,7 +499,8 @@ bool HLSLToolChain::requiresBinaryTranslation(DerivedArgList &Args) const {
 
 bool HLSLToolChain::requiresObjcopy(DerivedArgList &Args) const {
   return Args.hasArg(options::OPT_dxc_Fo) &&
-         Args.hasArg(options::OPT_dxc_strip_rootsignature);
+         (Args.hasArg(options::OPT_dxc_strip_rootsignature) ||
+          Args.hasArg(options::OPT_dxc_Frs));
 }
 
 bool HLSLToolChain::isLastJob(DerivedArgList &Args,
diff --git a/clang/test/Driver/dxc_frs.hlsl b/clang/test/Driver/dxc_frs.hlsl
new file mode 100644
index 0000000000000..7f7034f6fef89
--- /dev/null
+++ b/clang/test/Driver/dxc_frs.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang_dxc -T cs_6_0 /Fo %t.dxo /Frs %t.rs.dxo -### %s 2>&1 | FileCheck %s
+
+// Test to demonstrate that extracting the root signature to the specified
+// output file with /Frs.
+
+// CHECK: "{{.*}}llvm-objcopy{{(.exe)?}}" "{{.*}}.obj" "{{.*}}.dxo" "--extract-section=RTS0={{.*}}.rs.dxo"
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void EmptyEntry() {}

Copy link

github-actions bot commented Sep 9, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@inbelic inbelic merged commit d3c72d6 into llvm:main Sep 9, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL][RootSignature] Add support for the /Frs compiler flag
4 participants