Skip to content

Conversation

joaosaffran
Copy link
Contributor

MC Root Signature Representations currently depend on Object structures. This PR removes that dependency and in order to facilitate removing to_underlying usage in follow up PRs.

@joaosaffran joaosaffran linked an issue Aug 20, 2025 that may be closed by this pull request
@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2025

@llvm/pr-subscribers-mc
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-objectyaml

@llvm/pr-subscribers-hlsl

Author: None (joaosaffran)

Changes

MC Root Signature Representations currently depend on Object structures. This PR removes that dependency and in order to facilitate removing to_underlying usage in follow up PRs.


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

6 Files Affected:

  • (modified) llvm/include/llvm/MC/DXContainerRootSignature.h (+18-7)
  • (modified) llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp (+3-3)
  • (modified) llvm/lib/MC/DXContainerRootSignature.cpp (+2-2)
  • (modified) llvm/lib/ObjectYAML/DXContainerEmitter.cpp (+2-2)
  • (modified) llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp (+2-2)
  • (modified) llvm/lib/Target/DirectX/DXILRootSignature.cpp (+2-2)
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 4db3f3458c808..85b45323cee08 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -19,6 +19,18 @@ namespace llvm {
 class raw_ostream;
 namespace mcdxbc {
 
+struct RootConstants {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t Num32BitValues;
+};
+
+struct RootDescriptor {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t Flags;
+};
+
 struct RootParameterInfo {
   dxbc::RootParameterType Type;
   dxbc::ShaderVisibility Visibility;
@@ -42,8 +54,8 @@ struct DescriptorTable {
 struct RootParametersContainer {
   SmallVector<RootParameterInfo> ParametersInfo;
 
-  SmallVector<dxbc::RTS0::v1::RootConstants> Constants;
-  SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;
+  SmallVector<RootConstants> Constants;
+  SmallVector<RootDescriptor> Descriptors;
   SmallVector<DescriptorTable> Tables;
 
   void addInfo(dxbc::RootParameterType Type, dxbc::ShaderVisibility Visibility,
@@ -52,15 +64,14 @@ struct RootParametersContainer {
   }
 
   void addParameter(dxbc::RootParameterType Type,
-                    dxbc::ShaderVisibility Visibility,
-                    dxbc::RTS0::v1::RootConstants Constant) {
+                    dxbc::ShaderVisibility Visibility, RootConstants Constant) {
     addInfo(Type, Visibility, Constants.size());
     Constants.push_back(Constant);
   }
 
   void addParameter(dxbc::RootParameterType Type,
                     dxbc::ShaderVisibility Visibility,
-                    dxbc::RTS0::v2::RootDescriptor Descriptor) {
+                    RootDescriptor Descriptor) {
     addInfo(Type, Visibility, Descriptors.size());
     Descriptors.push_back(Descriptor);
   }
@@ -76,11 +87,11 @@ struct RootParametersContainer {
     return Info;
   }
 
-  const dxbc::RTS0::v1::RootConstants &getConstant(size_t Index) const {
+  const RootConstants &getConstant(size_t Index) const {
     return Constants[Index];
   }
 
-  const dxbc::RTS0::v2::RootDescriptor &getRootDescriptor(size_t Index) const {
+  const RootDescriptor &getRootDescriptor(size_t Index) const {
     return Descriptors[Index];
   }
 
diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
index 610f889e8d7c6..770a6d1638e3c 100644
--- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
+++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp
@@ -240,7 +240,7 @@ Error MetadataParser::parseRootConstants(mcdxbc::RootSignatureDesc &RSD,
   if (auto E = Visibility.takeError())
     return Error(std::move(E));
 
-  dxbc::RTS0::v1::RootConstants Constants;
+  mcdxbc::RootConstants Constants;
   if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 2))
     Constants.ShaderRegister = *Val;
   else
@@ -294,7 +294,7 @@ Error MetadataParser::parseRootDescriptors(
   if (auto E = Visibility.takeError())
     return Error(std::move(E));
 
-  dxbc::RTS0::v2::RootDescriptor Descriptor;
+  mcdxbc::RootDescriptor Descriptor;
   if (std::optional<uint32_t> Val = extractMdIntValue(RootDescriptorNode, 2))
     Descriptor.ShaderRegister = *Val;
   else
@@ -544,7 +544,7 @@ Error MetadataParser::validateRootSignature(
     case dxbc::RootParameterType::CBV:
     case dxbc::RootParameterType::UAV:
     case dxbc::RootParameterType::SRV: {
-      const dxbc::RTS0::v2::RootDescriptor &Descriptor =
+      const mcdxbc::RootDescriptor &Descriptor =
           RSD.ParametersContainer.getRootDescriptor(Info.Location);
       if (!hlsl::rootsig::verifyRegisterValue(Descriptor.ShaderRegister))
         DeferredErrs =
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 14c9c8866bb24..94119d8e89ec9 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -97,7 +97,7 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
     const auto Info = ParametersContainer.getInfo(I);
     switch (Info.Type) {
     case dxbc::RootParameterType::Constants32Bit: {
-      const dxbc::RTS0::v1::RootConstants &Constants =
+      const mcdxbc::RootConstants &Constants =
           ParametersContainer.getConstant(Info.Location);
       support::endian::write(BOS, Constants.ShaderRegister,
                              llvm::endianness::little);
@@ -110,7 +110,7 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
     case dxbc::RootParameterType::CBV:
     case dxbc::RootParameterType::SRV:
     case dxbc::RootParameterType::UAV: {
-      const dxbc::RTS0::v2::RootDescriptor &Descriptor =
+      const mcdxbc::RootDescriptor &Descriptor =
           ParametersContainer.getRootDescriptor(Info.Location);
 
       support::endian::write(BOS, Descriptor.ShaderRegister,
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index b112c6f21ee5a..a51821e196cb8 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -288,7 +288,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
         case dxbc::RootParameterType::Constants32Bit: {
           const DXContainerYAML::RootConstantsYaml &ConstantYaml =
               P.RootSignature->Parameters.getOrInsertConstants(L);
-          dxbc::RTS0::v1::RootConstants Constants;
+          mcdxbc::RootConstants Constants;
 
           Constants.Num32BitValues = ConstantYaml.Num32BitValues;
           Constants.RegisterSpace = ConstantYaml.RegisterSpace;
@@ -302,7 +302,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
           const DXContainerYAML::RootDescriptorYaml &DescriptorYaml =
               P.RootSignature->Parameters.getOrInsertDescriptor(L);
 
-          dxbc::RTS0::v2::RootDescriptor Descriptor;
+          mcdxbc::RootDescriptor Descriptor;
           Descriptor.RegisterSpace = DescriptorYaml.RegisterSpace;
           Descriptor.ShaderRegister = DescriptorYaml.ShaderRegister;
           if (RS.Version > 1)
diff --git a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
index fc0afb9a0efdf..5557443a3db93 100644
--- a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
+++ b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
@@ -171,7 +171,7 @@ static void validateRootSignature(Module &M,
     dxbc::RootParameterType ParamType = dxbc::RootParameterType(ParamInfo.Type);
     switch (ParamType) {
     case dxbc::RootParameterType::Constants32Bit: {
-      dxbc::RTS0::v1::RootConstants Const =
+      mcdxbc::RootConstants Const =
           RSD.ParametersContainer.getConstant(ParamInfo.Location);
       Builder.trackBinding(dxil::ResourceClass::CBuffer, Const.RegisterSpace,
                            Const.ShaderRegister, Const.ShaderRegister,
@@ -182,7 +182,7 @@ static void validateRootSignature(Module &M,
     case dxbc::RootParameterType::SRV:
     case dxbc::RootParameterType::UAV:
     case dxbc::RootParameterType::CBV: {
-      dxbc::RTS0::v2::RootDescriptor Desc =
+      mcdxbc::RootDescriptor Desc =
           RSD.ParametersContainer.getRootDescriptor(ParamInfo.Location);
       Builder.trackBinding(toResourceClass(ParamInfo.Type), Desc.RegisterSpace,
                            Desc.ShaderRegister, Desc.ShaderRegister,
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 2ca2ecff5a55f..b05b8ee699ef6 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -182,7 +182,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
       const uint32_t &Loc = Info.Location;
       switch (Info.Type) {
       case dxbc::RootParameterType::Constants32Bit: {
-        const dxbc::RTS0::v1::RootConstants &Constants =
+        const mcdxbc::RootConstants &Constants =
             RS.ParametersContainer.getConstant(Loc);
         OS << "  Register Space: " << Constants.RegisterSpace << "\n"
            << "  Shader Register: " << Constants.ShaderRegister << "\n"
@@ -192,7 +192,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
       case dxbc::RootParameterType::CBV:
       case dxbc::RootParameterType::UAV:
       case dxbc::RootParameterType::SRV: {
-        const dxbc::RTS0::v2::RootDescriptor &Descriptor =
+        const mcdxbc::RootDescriptor &Descriptor =
             RS.ParametersContainer.getRootDescriptor(Loc);
         OS << "  Register Space: " << Descriptor.RegisterSpace << "\n"
            << "  Shader Register: " << Descriptor.ShaderRegister << "\n";

Copy link
Contributor

@inbelic inbelic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but the same note about a dependency: #154249 (comment)

@joaosaffran joaosaffran changed the base branch from users/joaosaffran/154249 to main August 25, 2025 20:54
Copy link

github-actions bot commented Aug 25, 2025

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

@joaosaffran joaosaffran merged commit dfc376a into llvm:main Aug 29, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DirectX] Clean up to_underlying in case labels
4 participants