[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Apr 24 14:29:35 PDT 2025
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/136732
>From 578faea764d630b8782ba53b5153fdbeda2c45f8 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 24 Apr 2025 19:33:05 +0000
Subject: [PATCH 1/8] addressing pr comments
---
.../llvm/MC/DXContainerRootSignature.h | 2 +-
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 105 +++++++-----------
.../RootSignature-MultipleEntryFunctions.ll | 4 +-
.../ContainerData/RootSignature-Parameters.ll | 24 ++--
4 files changed, 57 insertions(+), 78 deletions(-)
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 6d3329a2c6ce9..fee799249b255 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -25,7 +25,7 @@ struct RootSignatureDesc {
uint32_t Version = 2U;
uint32_t Flags = 0U;
- uint32_t RootParameterOffset = 24U;
+ uint32_t RootParameterOffset = 0U;
uint32_t StaticSamplersOffset = 0u;
uint32_t NumStaticSamplers = 0u;
SmallVector<mcdxbc::RootParameter> Parameters;
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 5e615461df4f3..fe30793aa9853 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -40,21 +40,19 @@ static bool reportError(LLVMContext *Ctx, Twine Message,
return true;
}
-static bool reportValueError(LLVMContext *Ctx, Twine ParamName, uint32_t Value,
- DiagnosticSeverity Severity = DS_Error) {
+static bool reportValueError(LLVMContext *Ctx, Twine ParamName,
+ uint32_t Value) {
Ctx->diagnose(DiagnosticInfoGeneric(
- "Invalid value for " + ParamName + ": " + Twine(Value), Severity));
+ "Invalid value for " + ParamName + ": " + Twine(Value), DS_Error));
return true;
}
-static bool extractMdIntValue(uint32_t &Value, MDNode *Node,
- unsigned int OpId) {
- auto *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(OpId).get());
- if (CI == nullptr)
- return true;
-
- Value = CI->getZExtValue();
- return false;
+static std::optional<uint32_t> extractMdIntValue(MDNode *Node,
+ unsigned int OpId) {
+ if (auto *CI =
+ mdconst::dyn_extract<ConstantInt>(Node->getOperand(OpId).get()))
+ return CI->getZExtValue();
+ return std::nullopt;
}
static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
@@ -63,7 +61,9 @@ static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
if (RootFlagNode->getNumOperands() != 2)
return reportError(Ctx, "Invalid format for RootFlag Element");
- if (extractMdIntValue(RSD.Flags, RootFlagNode, 1))
+ if (std::optional<uint32_t> Val = extractMdIntValue(RootFlagNode, 1))
+ RSD.Flags = *Val;
+ else
return reportError(Ctx, "Invalid value for RootFlag");
return false;
@@ -79,22 +79,24 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
NewParameter.Header.ParameterType =
llvm::to_underlying(dxbc::RootParameterType::Constants32Bit);
- uint32_t SV;
- if (extractMdIntValue(SV, RootConstantNode, 1))
+ if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 1))
+ NewParameter.Header.ShaderVisibility = *Val;
+ else
return reportError(Ctx, "Invalid value for ShaderVisibility");
- NewParameter.Header.ShaderVisibility = SV;
-
- if (extractMdIntValue(NewParameter.Constants.ShaderRegister, RootConstantNode,
- 2))
+ if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 2))
+ NewParameter.Constants.ShaderRegister = *Val;
+ else
return reportError(Ctx, "Invalid value for ShaderRegister");
- if (extractMdIntValue(NewParameter.Constants.RegisterSpace, RootConstantNode,
- 3))
+ if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 3))
+ NewParameter.Constants.RegisterSpace = *Val;
+ else
return reportError(Ctx, "Invalid value for RegisterSpace");
- if (extractMdIntValue(NewParameter.Constants.Num32BitValues, RootConstantNode,
- 4))
+ if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 4))
+ NewParameter.Constants.Num32BitValues = *Val;
+ else
return reportError(Ctx, "Invalid value for Num32BitValues");
RSD.Parameters.push_back(NewParameter);
@@ -148,32 +150,6 @@ static bool parse(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
static bool verifyRootFlag(uint32_t Flags) { return (Flags & ~0xfff) == 0; }
-static bool verifyShaderVisibility(uint32_t Flags) {
- switch (Flags) {
-
- case llvm::to_underlying(dxbc::ShaderVisibility::All):
- case llvm::to_underlying(dxbc::ShaderVisibility::Vertex):
- case llvm::to_underlying(dxbc::ShaderVisibility::Hull):
- case llvm::to_underlying(dxbc::ShaderVisibility::Domain):
- case llvm::to_underlying(dxbc::ShaderVisibility::Geometry):
- case llvm::to_underlying(dxbc::ShaderVisibility::Pixel):
- case llvm::to_underlying(dxbc::ShaderVisibility::Amplification):
- case llvm::to_underlying(dxbc::ShaderVisibility::Mesh):
- return true;
- }
-
- return false;
-}
-
-static bool verifyParameterType(uint32_t Type) {
- switch (Type) {
- case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
- return true;
- }
-
- return false;
-}
-
static bool verifyVersion(uint32_t Version) {
return (Version == 1 || Version == 2);
}
@@ -189,11 +165,11 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
}
for (const auto &P : RSD.Parameters) {
- if (!verifyShaderVisibility(P.Header.ShaderVisibility))
+ if (!dxbc::isValidShaderVisibility(P.Header.ShaderVisibility))
return reportValueError(Ctx, "ShaderVisibility",
- (uint32_t)P.Header.ShaderVisibility);
+ P.Header.ShaderVisibility);
- assert(verifyParameterType(P.Header.ParameterType) &&
+ assert(dxbc::isValidParameterType(P.Header.ParameterType) &&
"Invalid value for ParameterType");
}
@@ -265,6 +241,10 @@ analyzeModule(Module &M) {
}
mcdxbc::RootSignatureDesc RSD;
+ // Clang emits the root signature data in dxcontainer following a specific
+ // sequence. First the header, then the root parameters. The header is
+ // always 24 bytes long, this is why we have 24 here.
+ RSD.RootParameterOffset = 24U;
if (parse(Ctx, RSD, RootElementListNode) || validate(Ctx, RSD)) {
return RSDMap;
@@ -307,26 +287,25 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
OS << indent(Space) << "Flags: " << format_hex(RS.Flags, 8) << "\n";
OS << indent(Space) << "Version: " << RS.Version << "\n";
OS << indent(Space) << "NumParameters: " << RS.Parameters.size() << "\n";
- OS << indent(Space) << "RootParametersOffset: " << RSHSize << "\n";
+ OS << indent(Space) << "RootParametersOffset: " << RS.RootParameterOffset
+ << "\n";
OS << indent(Space) << "NumStaticSamplers: " << 0 << "\n";
- OS << indent(Space)
- << "StaticSamplersOffset: " << RSHSize + RS.Parameters.size_in_bytes()
+ OS << indent(Space) << "StaticSamplersOffset: " << RS.StaticSamplersOffset
<< "\n";
Space++;
for (auto const &P : RS.Parameters) {
- OS << indent(Space)
- << "Parameter Type: " << (uint32_t)P.Header.ParameterType << "\n";
- OS << indent(Space)
- << "Shader Visibility: " << (uint32_t)P.Header.ShaderVisibility
+ OS << indent(Space) << "- Parameter Type: " << P.Header.ParameterType
<< "\n";
+ OS << indent(Space + 2)
+ << "Shader Visibility: " << P.Header.ShaderVisibility << "\n";
switch (P.Header.ParameterType) {
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
- OS << indent(Space) << "Register Space: " << P.Constants.RegisterSpace
- << "\n";
- OS << indent(Space) << "Shader Register: " << P.Constants.ShaderRegister
- << "\n";
- OS << indent(Space)
+ OS << indent(Space + 2)
+ << "Register Space: " << P.Constants.RegisterSpace << "\n";
+ OS << indent(Space + 2)
+ << "Shader Register: " << P.Constants.ShaderRegister << "\n";
+ OS << indent(Space + 2)
<< "Num 32 Bit Values: " << P.Constants.Num32BitValues << "\n";
break;
}
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll
index 581ac9aaec110..666cc731cff51 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll
@@ -29,7 +29,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; CHECK-NEXT: NumParameters: 0
; CHECK-NEXT: RootParametersOffset: 24
; CHECK-NEXT: NumStaticSamplers: 0
-; CHECK-NEXT: StaticSamplersOffset: 24
+; CHECK-NEXT: StaticSamplersOffset: 0
; CHECK-LABEL: Definition for 'anotherMain':
; CHECK-NEXT: Flags: 0x000002
@@ -37,4 +37,4 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; CHECK-NEXT: NumParameters: 0
; CHECK-NEXT: RootParametersOffset: 24
; CHECK-NEXT: NumStaticSamplers: 0
-; CHECK-NEXT: StaticSamplersOffset: 24
+; CHECK-NEXT: StaticSamplersOffset: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll
index 9a2f7d840a236..047422f1d64a1 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll
@@ -16,15 +16,15 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
!5 = !{ !"RootConstants", i32 0, i32 1, i32 2, i32 3 }
-; CHECK-LABEL: Definition for 'main':
-; CHECK-NEXT: Flags: 0x000001
-; CHECK-NEXT: Version: 2
-; CHECK-NEXT: NumParameters: 1
-; CHECK-NEXT: RootParametersOffset: 24
-; CHECK-NEXT: NumStaticSamplers: 0
-; CHECK-NEXT: StaticSamplersOffset: 48
-; CHECK-NEXT: Parameter Type: 1
-; CHECK-NEXT: Shader Visibility: 0
-; CHECK-NEXT: Register Space: 2
-; CHECK-NEXT: Shader Register: 1
-; CHECK-NEXT: Num 32 Bit Values: 3
+;CHECK-LABEL: Definition for 'main':
+;CHECK-NEXT: Flags: 0x000001
+;CHECK-NEXT: Version: 2
+;CHECK-NEXT: NumParameters: 1
+;CHECK-NEXT: RootParametersOffset: 24
+;CHECK-NEXT: NumStaticSamplers: 0
+;CHECK-NEXT: StaticSamplersOffset: 0
+;CHECK-NEXT: - Parameter Type: 1
+;CHECK-NEXT: Shader Visibility: 0
+;CHECK-NEXT: Register Space: 2
+;CHECK-NEXT: Shader Register: 1
+;CHECK-NEXT: Num 32 Bit Values: 3
>From 860fddd10ec0401f3319b48e10fe5f77100a5e5d Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 24 Apr 2025 20:04:53 +0000
Subject: [PATCH 2/8] addressing comments
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 18 ++++++++----------
.../RootSignature-MultipleEntryFunctions.ll | 4 ++--
.../ContainerData/RootSignature-Parameters.ll | 6 +++---
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index fe30793aa9853..ef299c17baf76 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -164,7 +164,7 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
return reportValueError(Ctx, "RootFlags", RSD.Flags);
}
- for (const auto &P : RSD.Parameters) {
+ for (const mcdxbc::RootParameter &P : RSD.Parameters) {
if (!dxbc::isValidShaderVisibility(P.Header.ShaderVisibility))
return reportValueError(Ctx, "ShaderVisibility",
P.Header.ShaderVisibility);
@@ -242,9 +242,9 @@ analyzeModule(Module &M) {
mcdxbc::RootSignatureDesc RSD;
// Clang emits the root signature data in dxcontainer following a specific
- // sequence. First the header, then the root parameters. The header is
- // always 24 bytes long, this is why we have 24 here.
- RSD.RootParameterOffset = 24U;
+ // sequence. First the header, then the root parameters. So the header
+ // offset will always equal to the header size.
+ RSD.RootParameterOffset = sizeof(dxbc::RootSignatureHeader);
if (parse(Ctx, RSD, RootElementListNode) || validate(Ctx, RSD)) {
return RSDMap;
@@ -271,7 +271,6 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
SmallDenseMap<const Function *, mcdxbc::RootSignatureDesc> &RSDMap =
AM.getResult<RootSignatureAnalysis>(M);
- const size_t RSHSize = sizeof(dxbc::RootSignatureHeader);
OS << "Root Signature Definitions"
<< "\n";
uint8_t Space = 0;
@@ -286,13 +285,9 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
Space++;
OS << indent(Space) << "Flags: " << format_hex(RS.Flags, 8) << "\n";
OS << indent(Space) << "Version: " << RS.Version << "\n";
- OS << indent(Space) << "NumParameters: " << RS.Parameters.size() << "\n";
OS << indent(Space) << "RootParametersOffset: " << RS.RootParameterOffset
<< "\n";
- OS << indent(Space) << "NumStaticSamplers: " << 0 << "\n";
- OS << indent(Space) << "StaticSamplersOffset: " << RS.StaticSamplersOffset
- << "\n";
-
+ OS << indent(Space) << "NumParameters: " << RS.Parameters.size() << "\n";
Space++;
for (auto const &P : RS.Parameters) {
OS << indent(Space) << "- Parameter Type: " << P.Header.ParameterType
@@ -311,6 +306,9 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
}
}
Space--;
+ OS << indent(Space) << "NumStaticSamplers: " << 0 << "\n";
+ OS << indent(Space) << "StaticSamplersOffset: " << RS.StaticSamplersOffset
+ << "\n";
Space--;
// end root signature header
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll
index 666cc731cff51..d23e1c71d2fc0 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-MultipleEntryFunctions.ll
@@ -26,15 +26,15 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; CHECK-LABEL: Definition for 'main':
; CHECK-NEXT: Flags: 0x000001
; CHECK-NEXT: Version: 2
-; CHECK-NEXT: NumParameters: 0
; CHECK-NEXT: RootParametersOffset: 24
+; CHECK-NEXT: NumParameters: 0
; CHECK-NEXT: NumStaticSamplers: 0
; CHECK-NEXT: StaticSamplersOffset: 0
; CHECK-LABEL: Definition for 'anotherMain':
; CHECK-NEXT: Flags: 0x000002
; CHECK-NEXT: Version: 2
-; CHECK-NEXT: NumParameters: 0
; CHECK-NEXT: RootParametersOffset: 24
+; CHECK-NEXT: NumParameters: 0
; CHECK-NEXT: NumStaticSamplers: 0
; CHECK-NEXT: StaticSamplersOffset: 0
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll
index 047422f1d64a1..b55d1283df0c9 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll
@@ -19,12 +19,12 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
;CHECK-LABEL: Definition for 'main':
;CHECK-NEXT: Flags: 0x000001
;CHECK-NEXT: Version: 2
-;CHECK-NEXT: NumParameters: 1
;CHECK-NEXT: RootParametersOffset: 24
-;CHECK-NEXT: NumStaticSamplers: 0
-;CHECK-NEXT: StaticSamplersOffset: 0
+;CHECK-NEXT: NumParameters: 1
;CHECK-NEXT: - Parameter Type: 1
;CHECK-NEXT: Shader Visibility: 0
;CHECK-NEXT: Register Space: 2
;CHECK-NEXT: Shader Register: 1
;CHECK-NEXT: Num 32 Bit Values: 3
+;CHECK-NEXT: NumStaticSamplers: 0
+;CHECK-NEXT: StaticSamplersOffset: 0
>From 3ce683e96c169131d5d6a1fb9a143b0dcb63c01a Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 18 Apr 2025 00:41:37 +0000
Subject: [PATCH 3/8] adding support for root descriptor
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 25 ++++++++
.../BinaryFormat/DXContainerConstants.def | 15 +++++
.../llvm/MC/DXContainerRootSignature.h | 2 +
llvm/include/llvm/Object/DXContainer.h | 39 ++++++++++++
.../include/llvm/ObjectYAML/DXContainerYAML.h | 36 ++++++++++-
llvm/lib/MC/DXContainerRootSignature.cpp | 26 ++++++++
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 19 +++++-
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 63 +++++++++++++++++--
.../RootSignature-MultipleParameters.yaml | 20 ++++--
9 files changed, 233 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 455657980bf40..d6e585c94fed1 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -18,6 +18,7 @@
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/TargetParser/Triple.h"
+#include <cstdint>
#include <stdint.h>
namespace llvm {
@@ -158,6 +159,11 @@ enum class RootElementFlag : uint32_t {
#include "DXContainerConstants.def"
};
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) Val = 1ull << Num,
+enum class RootDescriptorFlag : uint32_t {
+#include "DXContainerConstants.def"
+};
+
#define ROOT_PARAMETER(Val, Enum) Enum = Val,
enum class RootParameterType : uint32_t {
#include "DXContainerConstants.def"
@@ -594,6 +600,25 @@ struct RootConstants {
sys::swapByteOrder(Num32BitValues);
}
};
+struct RootDescriptor_V1_0 {
+ uint32_t ShaderRegister;
+ uint32_t RegisterSpace;
+ void swapBytes() {
+ sys::swapByteOrder(ShaderRegister);
+ sys::swapByteOrder(RegisterSpace);
+ }
+};
+
+struct RootDescriptor_V1_1 {
+ uint32_t ShaderRegister;
+ uint32_t RegisterSpace;
+ uint32_t Flags;
+ void swapBytes() {
+ sys::swapByteOrder(ShaderRegister);
+ sys::swapByteOrder(RegisterSpace);
+ sys::swapByteOrder(Flags);
+ }
+};
struct RootParameterHeader {
uint32_t ParameterType;
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 590ded5e8c899..6840901460ced 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -72,9 +72,24 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
#undef ROOT_ELEMENT_FLAG
#endif // ROOT_ELEMENT_FLAG
+
+// ROOT_ELEMENT_FLAG(bit offset for the flag, name).
+#ifdef ROOT_DESCRIPTOR_FLAG
+
+ROOT_DESCRIPTOR_FLAG(0, NONE)
+ROOT_DESCRIPTOR_FLAG(2, DATA_VOLATILE)
+ROOT_DESCRIPTOR_FLAG(4, DATA_STATIC_WHILE_SET_AT_EXECUTE)
+ROOT_DESCRIPTOR_FLAG(8, DATA_STATIC)
+#undef ROOT_DESCRIPTOR_FLAG
+#endif // ROOT_DESCRIPTOR_FLAG
+
+
#ifdef ROOT_PARAMETER
ROOT_PARAMETER(1, Constants32Bit)
+ROOT_PARAMETER(2, CBV)
+ROOT_PARAMETER(3, SRV)
+ROOT_PARAMETER(4, UAV)
#undef ROOT_PARAMETER
#endif // ROOT_PARAMETER
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index fee799249b255..cfa63db55c1c6 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -19,6 +19,8 @@ struct RootParameter {
dxbc::RootParameterHeader Header;
union {
dxbc::RootConstants Constants;
+ dxbc::RootDescriptor_V1_0 Descriptor_V10;
+ dxbc::RootDescriptor_V1_1 Descriptor_V11;
};
};
struct RootSignatureDesc {
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index e8287ce078365..7812906700fe3 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -15,6 +15,7 @@
#ifndef LLVM_OBJECT_DXCONTAINER_H
#define LLVM_OBJECT_DXCONTAINER_H
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
@@ -149,6 +150,36 @@ struct RootConstantView : RootParameterView {
}
};
+struct RootDescriptorView_V1_0 : RootParameterView {
+ static bool classof(const RootParameterView *V) {
+ return (V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::CBV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::SRV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::UAV));
+ }
+
+ llvm::Expected<dxbc::RootDescriptor_V1_0> read() {
+ return readParameter<dxbc::RootDescriptor_V1_0>();
+ }
+};
+
+struct RootDescriptorView_V1_1 : RootParameterView {
+ static bool classof(const RootParameterView *V) {
+ return (V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::CBV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::SRV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::UAV));
+ }
+
+ llvm::Expected<dxbc::RootDescriptor_V1_1> read() {
+ return readParameter<dxbc::RootDescriptor_V1_1>();
+ }
+};
+
static Error parseFailed(const Twine &Msg) {
return make_error<GenericBinaryError>(Msg.str(), object_error::parse_failed);
}
@@ -192,6 +223,14 @@ class RootSignature {
case dxbc::RootParameterType::Constants32Bit:
DataSize = sizeof(dxbc::RootConstants);
break;
+ case dxbc::RootParameterType::CBV:
+ case dxbc::RootParameterType::SRV:
+ case dxbc::RootParameterType::UAV:
+ if (Version == 1)
+ DataSize = sizeof(dxbc::RootDescriptor_V1_0);
+ else
+ DataSize = sizeof(dxbc::RootDescriptor_V1_1);
+ break;
}
size_t EndOfSectionByte = getNumStaticSamplers() == 0
? PartData.size()
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 393bba9c79bf8..2026a2c08d472 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -15,6 +15,7 @@
#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
@@ -24,6 +25,7 @@
#include <cstdint>
#include <optional>
#include <string>
+#include <variant>
#include <vector>
namespace llvm {
@@ -73,24 +75,50 @@ struct ShaderHash {
std::vector<llvm::yaml::Hex8> Digest;
};
-#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
-
struct RootConstantsYaml {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
uint32_t Num32BitValues;
};
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false;
+struct RootDescriptorYaml {
+ RootDescriptorYaml() = default;
+
+ uint32_t ShaderRegister;
+ uint32_t RegisterSpace;
+
+ uint32_t getEncodedFlags();
+
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+};
+
struct RootParameterYamlDesc {
uint32_t Type;
uint32_t Visibility;
uint32_t Offset;
+ RootParameterYamlDesc(){};
+ RootParameterYamlDesc(uint32_t T) : Type(T) {
+ switch (T) {
+
+ case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
+ Constants = RootConstantsYaml();
+ break;
+ case llvm::to_underlying(dxbc::RootParameterType::CBV):
+ case llvm::to_underlying(dxbc::RootParameterType::SRV):
+ case llvm::to_underlying(dxbc::RootParameterType::UAV):
+ Descriptor = RootDescriptorYaml();
+ break;
+ }
+ }
union {
RootConstantsYaml Constants;
+ RootDescriptorYaml Descriptor;
};
};
+#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
struct RootSignatureYamlDesc {
RootSignatureYamlDesc() = default;
@@ -298,6 +326,10 @@ template <> struct MappingTraits<llvm::DXContainerYAML::RootConstantsYaml> {
static void mapping(IO &IO, llvm::DXContainerYAML::RootConstantsYaml &C);
};
+template <> struct MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml> {
+ static void mapping(IO &IO, llvm::DXContainerYAML::RootDescriptorYaml &D);
+};
+
} // namespace yaml
} // namespace llvm
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index c2731d95c955e..f3f5a6993bf38 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -8,6 +8,7 @@
#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Support/EndianStream.h"
using namespace llvm;
@@ -37,6 +38,15 @@ size_t RootSignatureDesc::getSize() const {
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
Size += sizeof(dxbc::RootConstants);
break;
+ case llvm::to_underlying(dxbc::RootParameterType::CBV):
+ case llvm::to_underlying(dxbc::RootParameterType::SRV):
+ case llvm::to_underlying(dxbc::RootParameterType::UAV):
+ if (Version == 1)
+ Size += sizeof(dxbc::RootDescriptor_V1_0);
+ else
+ Size += sizeof(dxbc::RootDescriptor_V1_1);
+
+ break;
}
}
return Size;
@@ -80,6 +90,22 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
support::endian::write(BOS, P.Constants.Num32BitValues,
llvm::endianness::little);
break;
+ case llvm::to_underlying(dxbc::RootParameterType::CBV):
+ case llvm::to_underlying(dxbc::RootParameterType::SRV):
+ case llvm::to_underlying(dxbc::RootParameterType::UAV):
+ if (Version == 1) {
+ support::endian::write(BOS, P.Descriptor_V10.RegisterSpace,
+ llvm::endianness::little);
+ support::endian::write(BOS, P.Descriptor_V10.ShaderRegister,
+ llvm::endianness::little);
+ } else {
+ support::endian::write(BOS, P.Descriptor_V11.RegisterSpace,
+ llvm::endianness::little);
+ support::endian::write(BOS, P.Descriptor_V11.ShaderRegister,
+ llvm::endianness::little);
+ support::endian::write(BOS, P.Descriptor_V11.Flags,
+ llvm::endianness::little);
+ }
}
}
assert(Storage.size() == getSize());
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 86e24eae4abc6..a931084e50d34 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -273,7 +273,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
- for (const auto &Param : P.RootSignature->Parameters) {
+ for (auto &Param : P.RootSignature->Parameters) {
mcdxbc::RootParameter NewParam;
NewParam.Header = dxbc::RootParameterHeader{
Param.Type, Param.Visibility, Param.Offset};
@@ -283,6 +283,23 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
NewParam.Constants.Num32BitValues = Param.Constants.Num32BitValues;
NewParam.Constants.RegisterSpace = Param.Constants.RegisterSpace;
NewParam.Constants.ShaderRegister = Param.Constants.ShaderRegister;
+ break;
+ case llvm::to_underlying(dxbc::RootParameterType::SRV):
+ case llvm::to_underlying(dxbc::RootParameterType::UAV):
+ case llvm::to_underlying(dxbc::RootParameterType::CBV):
+ if (RS.Version == 1) {
+ NewParam.Descriptor_V10.RegisterSpace =
+ Param.Descriptor.RegisterSpace;
+ NewParam.Descriptor_V10.ShaderRegister =
+ Param.Descriptor.ShaderRegister;
+ } else {
+ NewParam.Descriptor_V11.RegisterSpace =
+ Param.Descriptor.RegisterSpace;
+ NewParam.Descriptor_V11.ShaderRegister =
+ Param.Descriptor.ShaderRegister;
+ NewParam.Descriptor_V11.Flags = Param.Descriptor.getEncodedFlags();
+ }
+
break;
}
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 59914fe30082d..af5bc7388ae22 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/Object/DXContainer.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ScopedPrinter.h"
#include <cstdint>
@@ -38,8 +39,9 @@ DXContainerYAML::RootSignatureYamlDesc::create(
const object::DirectX::RootSignature &Data) {
RootSignatureYamlDesc RootSigDesc;
+ uint32_t V = Data.getVersion();
- RootSigDesc.Version = Data.getVersion();
+ RootSigDesc.Version = V;
RootSigDesc.NumStaticSamplers = Data.getNumStaticSamplers();
RootSigDesc.StaticSamplersOffset = Data.getStaticSamplersOffset();
RootSigDesc.NumRootParameters = Data.getNumRootParameters();
@@ -47,14 +49,12 @@ DXContainerYAML::RootSignatureYamlDesc::create(
uint32_t Flags = Data.getFlags();
for (const dxbc::RootParameterHeader &PH : Data.param_headers()) {
-
- RootParameterYamlDesc NewP;
- NewP.Offset = PH.ParameterOffset;
-
if (!dxbc::isValidParameterType(PH.ParameterType))
return createStringError(std::errc::invalid_argument,
"Invalid value for parameter type");
+ RootParameterYamlDesc NewP(PH.ParameterType);
+ NewP.Offset = PH.ParameterOffset;
NewP.Type = PH.ParameterType;
if (!dxbc::isValidShaderVisibility(PH.ShaderVisibility))
@@ -80,6 +80,37 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Constants.ShaderRegister = Constants.ShaderRegister;
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
}
+
+ if (V == 1) {
+ if (auto *RDV =
+ dyn_cast<object::DirectX::RootDescriptorView_V1_0>(&ParamView)) {
+ llvm::Expected<dxbc::RootDescriptor_V1_0> DescriptorOrErr = RDV->read();
+ if (Error E = DescriptorOrErr.takeError())
+ return std::move(E);
+ auto Descriptor = *DescriptorOrErr;
+
+ NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
+ NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
+ }
+ }
+
+ if (V == 2) {
+ if (auto *RDV =
+ dyn_cast<object::DirectX::RootDescriptorView_V1_1>(&ParamView)) {
+ llvm::Expected<dxbc::RootDescriptor_V1_1> DescriptorOrErr = RDV->read();
+ if (Error E = DescriptorOrErr.takeError())
+ return std::move(E);
+ auto Descriptor = *DescriptorOrErr;
+ NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
+ NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) \
+ NewP.Descriptor.Val = \
+ (Descriptor.Flags & \
+ llvm::to_underlying(dxbc::RootDescriptorFlag::Val)) > 0;
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+ }
+ }
+
RootSigDesc.Parameters.push_back(NewP);
}
#define ROOT_ELEMENT_FLAG(Num, Val) \
@@ -89,6 +120,15 @@ DXContainerYAML::RootSignatureYamlDesc::create(
return RootSigDesc;
}
+uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() {
+ uint64_t Flag = 0;
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) \
+ if (Val) \
+ Flag |= (uint32_t)dxbc::RootDescriptorFlag::Val;
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+ return Flag;
+}
+
uint32_t DXContainerYAML::RootSignatureYamlDesc::getEncodedFlags() {
uint64_t Flag = 0;
#define ROOT_ELEMENT_FLAG(Num, Val) \
@@ -276,6 +316,14 @@ void MappingTraits<llvm::DXContainerYAML::RootConstantsYaml>::mapping(
IO.mapRequired("ShaderRegister", C.ShaderRegister);
}
+void MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml>::mapping(
+ IO &IO, llvm::DXContainerYAML::RootDescriptorYaml &D) {
+ IO.mapRequired("RegisterSpace", D.RegisterSpace);
+ IO.mapRequired("ShaderRegister", D.ShaderRegister);
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) IO.mapOptional(#Val, D.Val, false);
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+}
+
void MappingTraits<llvm::DXContainerYAML::RootParameterYamlDesc>::mapping(
IO &IO, llvm::DXContainerYAML::RootParameterYamlDesc &P) {
IO.mapRequired("ParameterType", P.Type);
@@ -285,6 +333,11 @@ void MappingTraits<llvm::DXContainerYAML::RootParameterYamlDesc>::mapping(
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
IO.mapRequired("Constants", P.Constants);
break;
+ case llvm::to_underlying(dxbc::RootParameterType::CBV):
+ case llvm::to_underlying(dxbc::RootParameterType::SRV):
+ case llvm::to_underlying(dxbc::RootParameterType::UAV):
+ IO.mapRequired("Descriptor", P.Descriptor);
+ break;
}
}
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
index f366d71714359..ed7d6ed4542ad 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
@@ -11,10 +11,10 @@ Header:
PartOffsets: [ 60 ]
Parts:
- Name: RTS0
- Size: 80
+ Size: 96
RootSignature:
Version: 2
- NumRootParameters: 2
+ NumRootParameters: 3
RootParametersOffset: 24
NumStaticSamplers: 0
StaticSamplersOffset: 60
@@ -31,14 +31,20 @@ Parts:
Num32BitValues: 21
ShaderRegister: 22
RegisterSpace: 23
+ - ParameterType: 2 # SRV
+ ShaderVisibility: 3 # Domain
+ Descriptor:
+ ShaderRegister: 31
+ RegisterSpace: 32
+ DATA_STATIC_WHILE_SET_AT_EXECUTE: true
AllowInputAssemblerInputLayout: true
DenyGeometryShaderRootAccess: true
# CHECK: - Name: RTS0
-# CHECK-NEXT: Size: 80
+# CHECK-NEXT: Size: 96
# CHECK-NEXT: RootSignature:
# CHECK-NEXT: Version: 2
-# CHECK-NEXT: NumRootParameters: 2
+# CHECK-NEXT: NumRootParameters: 3
# CHECK-NEXT: RootParametersOffset: 24
# CHECK-NEXT: NumStaticSamplers: 0
# CHECK-NEXT: StaticSamplersOffset: 60
@@ -55,5 +61,11 @@ Parts:
# CHECK-NEXT: Num32BitValues: 21
# CHECK-NEXT: RegisterSpace: 23
# CHECK-NEXT: ShaderRegister: 22
+# CHECK-NEXT: - ParameterType: 2
+# CHECK-NEXT: ShaderVisibility: 3
+# CHECK-NEXT: Descriptor:
+# CHECK-NEXT: RegisterSpace: 31
+# CHECK-NEXT: ShaderRegister: 32
+# CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
# CHECK-NEXT: DenyGeometryShaderRootAccess: true
>From 13d704599b67fa0d5ca2223b0e3acf915456f4ff Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 18 Apr 2025 02:36:57 +0000
Subject: [PATCH 4/8] adding test
---
.../BinaryFormat/DXContainerConstants.def | 6 +-
llvm/lib/MC/DXContainerRootSignature.cpp | 8 +-
.../RootSignature-Descriptor1.0.yaml | 46 ++++++++
.../RootSignature-Descriptor1.1.yaml | 47 ++++++++
.../RootSignature-MultipleParameters.yaml | 4 +-
llvm/unittests/Object/DXContainerTest.cpp | 91 ++++++++++++++++
.../ObjectYAML/DXContainerYAMLTest.cpp | 103 ++++++++++++++++++
7 files changed, 296 insertions(+), 9 deletions(-)
create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 6840901460ced..bd9bd760547dc 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -77,9 +77,9 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
#ifdef ROOT_DESCRIPTOR_FLAG
ROOT_DESCRIPTOR_FLAG(0, NONE)
-ROOT_DESCRIPTOR_FLAG(2, DATA_VOLATILE)
-ROOT_DESCRIPTOR_FLAG(4, DATA_STATIC_WHILE_SET_AT_EXECUTE)
-ROOT_DESCRIPTOR_FLAG(8, DATA_STATIC)
+ROOT_DESCRIPTOR_FLAG(1, DATA_VOLATILE)
+ROOT_DESCRIPTOR_FLAG(2, DATA_STATIC_WHILE_SET_AT_EXECUTE)
+ROOT_DESCRIPTOR_FLAG(3, DATA_STATIC)
#undef ROOT_DESCRIPTOR_FLAG
#endif // ROOT_DESCRIPTOR_FLAG
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index f3f5a6993bf38..91b158ba22d2c 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -94,15 +94,15 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
case llvm::to_underlying(dxbc::RootParameterType::SRV):
case llvm::to_underlying(dxbc::RootParameterType::UAV):
if (Version == 1) {
- support::endian::write(BOS, P.Descriptor_V10.RegisterSpace,
- llvm::endianness::little);
support::endian::write(BOS, P.Descriptor_V10.ShaderRegister,
llvm::endianness::little);
- } else {
- support::endian::write(BOS, P.Descriptor_V11.RegisterSpace,
+ support::endian::write(BOS, P.Descriptor_V10.RegisterSpace,
llvm::endianness::little);
+ } else {
support::endian::write(BOS, P.Descriptor_V11.ShaderRegister,
llvm::endianness::little);
+ support::endian::write(BOS, P.Descriptor_V11.RegisterSpace,
+ llvm::endianness::little);
support::endian::write(BOS, P.Descriptor_V11.Flags,
llvm::endianness::little);
}
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
new file mode 100644
index 0000000000000..e19f3de894c07
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
@@ -0,0 +1,46 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+ Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+ Version:
+ Major: 1
+ Minor: 0
+ PartCount: 1
+ PartOffsets: [ 60 ]
+Parts:
+ - Name: RTS0
+ Size: 96
+ RootSignature:
+ Version: 1
+ NumRootParameters: 1
+ RootParametersOffset: 24
+ NumStaticSamplers: 0
+ StaticSamplersOffset: 60
+ Parameters:
+ - ParameterType: 2 # SRV
+ ShaderVisibility: 3 # Domain
+ Descriptor:
+ ShaderRegister: 31
+ RegisterSpace: 32
+ DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+ AllowInputAssemblerInputLayout: true
+ DenyGeometryShaderRootAccess: true
+
+# CHECK: - Name: RTS0
+# CHECK-NEXT: Size: 96
+# CHECK-NEXT: RootSignature:
+# CHECK-NEXT: Version: 1
+# CHECK-NEXT: NumRootParameters: 1
+# CHECK-NEXT: RootParametersOffset: 24
+# CHECK-NEXT: NumStaticSamplers: 0
+# CHECK-NEXT: StaticSamplersOffset: 60
+# CHECK-NEXT: Parameters:
+# CHECK-NEXT: - ParameterType: 2
+# CHECK-NEXT: ShaderVisibility: 3
+# CHECK-NEXT: Descriptor:
+# CHECK-NEXT: RegisterSpace: 32
+# CHECK-NEXT: ShaderRegister: 31
+# CHECK-NEXT: AllowInputAssemblerInputLayout: true
+# CHECK-NEXT: DenyGeometryShaderRootAccess: true
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
new file mode 100644
index 0000000000000..64e01c6836e32
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
@@ -0,0 +1,47 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+--- !dxcontainer
+Header:
+ Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+ Version:
+ Major: 1
+ Minor: 0
+ PartCount: 1
+ PartOffsets: [ 60 ]
+Parts:
+ - Name: RTS0
+ Size: 89
+ RootSignature:
+ Version: 2
+ NumRootParameters: 1
+ RootParametersOffset: 24
+ NumStaticSamplers: 0
+ StaticSamplersOffset: 60
+ Parameters:
+ - ParameterType: 2 # SRV
+ ShaderVisibility: 3 # Domain
+ Descriptor:
+ ShaderRegister: 31
+ RegisterSpace: 32
+ DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+ AllowInputAssemblerInputLayout: true
+ DenyGeometryShaderRootAccess: true
+
+# CHECK: - Name: RTS0
+# CHECK-NEXT: Size: 89
+# CHECK-NEXT: RootSignature:
+# CHECK-NEXT: Version: 2
+# CHECK-NEXT: NumRootParameters: 1
+# CHECK-NEXT: RootParametersOffset: 24
+# CHECK-NEXT: NumStaticSamplers: 0
+# CHECK-NEXT: StaticSamplersOffset: 60
+# CHECK-NEXT: Parameters:
+# CHECK-NEXT: - ParameterType: 2
+# CHECK-NEXT: ShaderVisibility: 3
+# CHECK-NEXT: Descriptor:
+# CHECK-NEXT: RegisterSpace: 32
+# CHECK-NEXT: ShaderRegister: 31
+# CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+# CHECK-NEXT: AllowInputAssemblerInputLayout: true
+# CHECK-NEXT: DenyGeometryShaderRootAccess: true
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
index ed7d6ed4542ad..debb459c3944e 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
@@ -64,8 +64,8 @@ Parts:
# CHECK-NEXT: - ParameterType: 2
# CHECK-NEXT: ShaderVisibility: 3
# CHECK-NEXT: Descriptor:
-# CHECK-NEXT: RegisterSpace: 31
-# CHECK-NEXT: ShaderRegister: 32
+# CHECK-NEXT: RegisterSpace: 32
+# CHECK-NEXT: ShaderRegister: 31
# CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
# CHECK-NEXT: DenyGeometryShaderRootAccess: true
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 62ef8e385373f..ed43f6deaa951 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -959,3 +959,94 @@ TEST(RootSignature, ParseRootConstant) {
ASSERT_EQ(Constants->Num32BitValues, 16u);
}
}
+
+TEST(RootSignature, ParseRootDescriptor) {
+ {
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
+ 0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
+ 0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00};
+ DXContainer C =
+ llvm::cantFail(DXContainer::create(getMemoryBuffer<133>(Buffer)));
+
+ auto MaybeRS = C.getRootSignature();
+ ASSERT_TRUE(MaybeRS.has_value());
+ const auto &RS = MaybeRS.value();
+ ASSERT_EQ(RS.getVersion(), 1u);
+ ASSERT_EQ(RS.getNumParameters(), 1u);
+ ASSERT_EQ(RS.getRootParametersOffset(), 24u);
+ ASSERT_EQ(RS.getNumStaticSamplers(), 0u);
+ ASSERT_EQ(RS.getStaticSamplersOffset(), 60u);
+ ASSERT_EQ(RS.getFlags(), 17u);
+
+ auto RootParam = *RS.param_headers().begin();
+ ASSERT_EQ((unsigned)RootParam.ParameterType, 2u);
+ ASSERT_EQ((unsigned)RootParam.ShaderVisibility, 3u);
+ auto ParamView = RS.getParameter(RootParam);
+ ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
+
+ DirectX::RootDescriptorView_V1_0 *RootDescriptorView =
+ dyn_cast<DirectX::RootDescriptorView_V1_0>(&*ParamView);
+ ASSERT_TRUE(RootDescriptorView != nullptr);
+ auto Descriptor = RootDescriptorView->read();
+
+ ASSERT_THAT_ERROR(Descriptor.takeError(), Succeeded());
+
+ ASSERT_EQ(Descriptor->ShaderRegister, 31u);
+ ASSERT_EQ(Descriptor->RegisterSpace, 32u);
+ }
+
+ {
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
+ 0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
+ 0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00};
+ DXContainer C =
+ llvm::cantFail(DXContainer::create(getMemoryBuffer<133>(Buffer)));
+
+ auto MaybeRS = C.getRootSignature();
+ ASSERT_TRUE(MaybeRS.has_value());
+ const auto &RS = MaybeRS.value();
+ ASSERT_EQ(RS.getVersion(), 2u);
+ ASSERT_EQ(RS.getNumParameters(), 1u);
+ ASSERT_EQ(RS.getRootParametersOffset(), 24u);
+ ASSERT_EQ(RS.getNumStaticSamplers(), 0u);
+ ASSERT_EQ(RS.getStaticSamplersOffset(), 60u);
+ ASSERT_EQ(RS.getFlags(), 17u);
+
+ auto RootParam = *RS.param_headers().begin();
+ ASSERT_EQ((unsigned)RootParam.ParameterType, 2u);
+ ASSERT_EQ((unsigned)RootParam.ShaderVisibility, 3u);
+ auto ParamView = RS.getParameter(RootParam);
+ ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
+
+ DirectX::RootDescriptorView_V1_1 *RootDescriptorView =
+ dyn_cast<DirectX::RootDescriptorView_V1_1>(&*ParamView);
+ ASSERT_TRUE(RootDescriptorView != nullptr);
+ auto Descriptor = RootDescriptorView->read();
+
+ ASSERT_THAT_ERROR(Descriptor.takeError(), Succeeded());
+
+ ASSERT_EQ(Descriptor->ShaderRegister, 31u);
+ ASSERT_EQ(Descriptor->RegisterSpace, 32u);
+ ASSERT_EQ(Descriptor->Flags, 4u);
+ }
+}
diff --git a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
index 61390049bc0df..b6a5cee24b29d 100644
--- a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
+++ b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
@@ -251,3 +251,106 @@ TEST(RootSignature, ParseRootConstants) {
EXPECT_EQ(Storage.size(), 133u);
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 133u) == 0);
}
+
+TEST(RootSignature, ParseRootDescriptorsV10) {
+ SmallString<128> Storage;
+
+ // First read a fully explicit yaml with all sizes and offsets provided
+ ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
+ Header:
+ Hash: [ 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F, 0x5,
+ 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1 ]
+ Version:
+ Major: 1
+ Minor: 0
+ FileSize: 133
+ PartCount: 1
+ PartOffsets: [ 36 ]
+ Parts:
+ - Name: RTS0
+ Size: 89
+ RootSignature:
+ Version: 1
+ NumRootParameters: 1
+ RootParametersOffset: 24
+ NumStaticSamplers: 0
+ StaticSamplersOffset: 60
+ Parameters:
+ - ParameterType: 2 # SRV
+ ShaderVisibility: 3 # Domain
+ Descriptor:
+ ShaderRegister: 31
+ RegisterSpace: 32
+ AllowInputAssemblerInputLayout: true
+ DenyGeometryShaderRootAccess: true
+ )"));
+
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
+ 0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
+ 0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00};
+
+ EXPECT_EQ(Storage.size(), 133u);
+ EXPECT_TRUE(memcmp(Buffer, Storage.data(), 133u) == 0);
+}
+
+TEST(RootSignature, ParseRootDescriptorsV11) {
+ SmallString<128> Storage;
+
+ // First read a fully explicit yaml with all sizes and offsets provided
+ ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
+ Header:
+ Hash: [ 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F, 0x5,
+ 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1 ]
+ Version:
+ Major: 1
+ Minor: 0
+ FileSize: 133
+ PartCount: 1
+ PartOffsets: [ 36 ]
+ Parts:
+ - Name: RTS0
+ Size: 89
+ RootSignature:
+ Version: 2
+ NumRootParameters: 1
+ RootParametersOffset: 24
+ NumStaticSamplers: 0
+ StaticSamplersOffset: 60
+ Parameters:
+ - ParameterType: 2 # SRV
+ ShaderVisibility: 3 # Domain
+ Descriptor:
+ ShaderRegister: 31
+ RegisterSpace: 32
+ DATA_STATIC_WHILE_SET_AT_EXECUTE: true
+ AllowInputAssemblerInputLayout: true
+ DenyGeometryShaderRootAccess: true
+ )"));
+
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
+ 0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
+ 0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00};
+
+ EXPECT_EQ(Storage.size(), 133u);
+ EXPECT_TRUE(memcmp(Buffer, Storage.data(), 133u) == 0);
+}
>From fdc12e1d9a6d7559c2cab25c1e16b30acee169e2 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 18 Apr 2025 02:36:57 +0000
Subject: [PATCH 5/8] adding test
---
llvm/include/llvm/Object/DXContainer.h | 34 ++++++++++++++-----------
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 4 ---
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 7812906700fe3..d6c9315842289 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -25,6 +25,7 @@
#include "llvm/TargetParser/Triple.h"
#include <array>
#include <cstddef>
+#include <cstdint>
#include <variant>
namespace llvm {
@@ -121,9 +122,10 @@ template <typename T> struct ViewArray {
namespace DirectX {
struct RootParameterView {
const dxbc::RootParameterHeader &Header;
+ uint32_t Version;
StringRef ParamData;
- RootParameterView(const dxbc::RootParameterHeader &H, StringRef P)
- : Header(H), ParamData(P) {}
+ RootParameterView(uint32_t V, const dxbc::RootParameterHeader &H, StringRef P)
+ : Header(H), Version(V), ParamData(P) {}
template <typename T> Expected<T> readParameter() {
T Struct;
@@ -152,12 +154,13 @@ struct RootConstantView : RootParameterView {
struct RootDescriptorView_V1_0 : RootParameterView {
static bool classof(const RootParameterView *V) {
- return (V->Header.ParameterType ==
- llvm::to_underlying(dxbc::RootParameterType::CBV) ||
- V->Header.ParameterType ==
- llvm::to_underlying(dxbc::RootParameterType::SRV) ||
- V->Header.ParameterType ==
- llvm::to_underlying(dxbc::RootParameterType::UAV));
+ return (V->Version == 1 &&
+ (V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::CBV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::SRV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::UAV)));
}
llvm::Expected<dxbc::RootDescriptor_V1_0> read() {
@@ -167,12 +170,13 @@ struct RootDescriptorView_V1_0 : RootParameterView {
struct RootDescriptorView_V1_1 : RootParameterView {
static bool classof(const RootParameterView *V) {
- return (V->Header.ParameterType ==
- llvm::to_underlying(dxbc::RootParameterType::CBV) ||
- V->Header.ParameterType ==
- llvm::to_underlying(dxbc::RootParameterType::SRV) ||
- V->Header.ParameterType ==
- llvm::to_underlying(dxbc::RootParameterType::UAV));
+ return (V->Version == 2 &&
+ (V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::CBV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::SRV) ||
+ V->Header.ParameterType ==
+ llvm::to_underlying(dxbc::RootParameterType::UAV)));
}
llvm::Expected<dxbc::RootDescriptor_V1_1> read() {
@@ -240,7 +244,7 @@ class RootSignature {
return parseFailed("Reading structure out of file bounds");
StringRef Buff = PartData.substr(Header.ParameterOffset, DataSize);
- RootParameterView View = RootParameterView(Header, Buff);
+ RootParameterView View = RootParameterView(Version, Header, Buff);
return View;
}
};
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index af5bc7388ae22..f1bc2a49fe3ba 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -81,7 +81,6 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
}
- if (V == 1) {
if (auto *RDV =
dyn_cast<object::DirectX::RootDescriptorView_V1_0>(&ParamView)) {
llvm::Expected<dxbc::RootDescriptor_V1_0> DescriptorOrErr = RDV->read();
@@ -92,9 +91,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
}
- }
- if (V == 2) {
if (auto *RDV =
dyn_cast<object::DirectX::RootDescriptorView_V1_1>(&ParamView)) {
llvm::Expected<dxbc::RootDescriptor_V1_1> DescriptorOrErr = RDV->read();
@@ -109,7 +106,6 @@ DXContainerYAML::RootSignatureYamlDesc::create(
llvm::to_underlying(dxbc::RootDescriptorFlag::Val)) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
- }
RootSigDesc.Parameters.push_back(NewP);
}
>From c81ce8aa1899b31179221de6adff7b32f51b28a8 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 22 Apr 2025 18:33:38 +0000
Subject: [PATCH 6/8] clean up
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 1 -
llvm/include/llvm/Object/DXContainer.h | 2 -
.../include/llvm/ObjectYAML/DXContainerYAML.h | 4 +-
llvm/lib/MC/DXContainerRootSignature.cpp | 1 -
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 2 +-
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 47 +++++++++----------
.../RootSignature-Descriptor1.0.yaml | 1 -
7 files changed, 23 insertions(+), 35 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index d6e585c94fed1..2e9b3089a6da5 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -18,7 +18,6 @@
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/TargetParser/Triple.h"
-#include <cstdint>
#include <stdint.h>
namespace llvm {
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index d6c9315842289..7b64c8ee15ae6 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -15,7 +15,6 @@
#ifndef LLVM_OBJECT_DXCONTAINER_H
#define LLVM_OBJECT_DXCONTAINER_H
-#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
@@ -25,7 +24,6 @@
#include "llvm/TargetParser/Triple.h"
#include <array>
#include <cstddef>
-#include <cstdint>
#include <variant>
namespace llvm {
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 2026a2c08d472..e86a869da99bc 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -15,7 +15,6 @@
#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
-#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
@@ -25,7 +24,6 @@
#include <cstdint>
#include <optional>
#include <string>
-#include <variant>
#include <vector>
namespace llvm {
@@ -88,7 +86,7 @@ struct RootDescriptorYaml {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
- uint32_t getEncodedFlags();
+ uint32_t getEncodedFlags() const;
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 91b158ba22d2c..25ea3cc081295 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -8,7 +8,6 @@
#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Support/EndianStream.h"
using namespace llvm;
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index a931084e50d34..be0e52fef04f5 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -273,7 +273,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
- for (auto &Param : P.RootSignature->Parameters) {
+ for (const auto &Param : P.RootSignature->Parameters) {
mcdxbc::RootParameter NewParam;
NewParam.Header = dxbc::RootParameterHeader{
Param.Type, Param.Visibility, Param.Offset};
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index f1bc2a49fe3ba..ecfcd3bb0148e 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -14,7 +14,6 @@
#include "llvm/ObjectYAML/DXContainerYAML.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/ScopeExit.h"
-#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -39,9 +38,8 @@ DXContainerYAML::RootSignatureYamlDesc::create(
const object::DirectX::RootSignature &Data) {
RootSignatureYamlDesc RootSigDesc;
- uint32_t V = Data.getVersion();
- RootSigDesc.Version = V;
+ RootSigDesc.Version = Data.getVersion();
RootSigDesc.NumStaticSamplers = Data.getNumStaticSamplers();
RootSigDesc.StaticSamplersOffset = Data.getStaticSamplersOffset();
RootSigDesc.NumRootParameters = Data.getNumRootParameters();
@@ -49,6 +47,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
uint32_t Flags = Data.getFlags();
for (const dxbc::RootParameterHeader &PH : Data.param_headers()) {
+
if (!dxbc::isValidParameterType(PH.ParameterType))
return createStringError(std::errc::invalid_argument,
"Invalid value for parameter type");
@@ -79,33 +78,29 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Constants.Num32BitValues = Constants.Num32BitValues;
NewP.Constants.ShaderRegister = Constants.ShaderRegister;
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
- }
-
- if (auto *RDV =
- dyn_cast<object::DirectX::RootDescriptorView_V1_0>(&ParamView)) {
- llvm::Expected<dxbc::RootDescriptor_V1_0> DescriptorOrErr = RDV->read();
- if (Error E = DescriptorOrErr.takeError())
- return std::move(E);
- auto Descriptor = *DescriptorOrErr;
-
- NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
- NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
- }
-
- if (auto *RDV =
- dyn_cast<object::DirectX::RootDescriptorView_V1_1>(&ParamView)) {
- llvm::Expected<dxbc::RootDescriptor_V1_1> DescriptorOrErr = RDV->read();
- if (Error E = DescriptorOrErr.takeError())
- return std::move(E);
- auto Descriptor = *DescriptorOrErr;
- NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
- NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
+ } else if (auto *RDV = dyn_cast<object::DirectX::RootDescriptorView_V1_0>(
+ &ParamView)) {
+ llvm::Expected<dxbc::RootDescriptor_V1_0> DescriptorOrErr = RDV->read();
+ if (Error E = DescriptorOrErr.takeError())
+ return std::move(E);
+ auto Descriptor = *DescriptorOrErr;
+
+ NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
+ NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
+ } else if (auto *RDV = dyn_cast<object::DirectX::RootDescriptorView_V1_1>(
+ &ParamView)) {
+ llvm::Expected<dxbc::RootDescriptor_V1_1> DescriptorOrErr = RDV->read();
+ if (Error E = DescriptorOrErr.takeError())
+ return std::move(E);
+ auto Descriptor = *DescriptorOrErr;
+ NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
+ NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
#define ROOT_DESCRIPTOR_FLAG(Num, Val) \
NewP.Descriptor.Val = \
(Descriptor.Flags & \
llvm::to_underlying(dxbc::RootDescriptorFlag::Val)) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
- }
+ }
RootSigDesc.Parameters.push_back(NewP);
}
@@ -116,7 +111,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
return RootSigDesc;
}
-uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() {
+uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() const {
uint64_t Flag = 0;
#define ROOT_DESCRIPTOR_FLAG(Num, Val) \
if (Val) \
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
index e19f3de894c07..46cdf416ffcae 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
@@ -24,7 +24,6 @@ Parts:
Descriptor:
ShaderRegister: 31
RegisterSpace: 32
- DATA_STATIC_WHILE_SET_AT_EXECUTE: true
AllowInputAssemblerInputLayout: true
DenyGeometryShaderRootAccess: true
>From 9e2b122140bd0d9a6beb992b10c767501efc5367 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 22 Apr 2025 18:38:59 +0000
Subject: [PATCH 7/8] try fix clean up
---
llvm/include/llvm/ObjectYAML/DXContainerYAML.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index e86a869da99bc..c54c995acd263 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -95,7 +95,7 @@ struct RootParameterYamlDesc {
uint32_t Type;
uint32_t Visibility;
uint32_t Offset;
- RootParameterYamlDesc(){};
+ RootParameterYamlDesc() {};
RootParameterYamlDesc(uint32_t T) : Type(T) {
switch (T) {
>From d982395ef4d7bf74c74510f042c101ad38122bbb Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 24 Apr 2025 18:23:53 +0000
Subject: [PATCH 8/8] changing version namings
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 36 +++++++++----------
.../llvm/MC/DXContainerRootSignature.h | 4 +--
llvm/include/llvm/Object/DXContainer.h | 12 +++----
.../include/llvm/ObjectYAML/DXContainerYAML.h | 2 +-
llvm/lib/MC/DXContainerRootSignature.cpp | 4 +--
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 7 ++--
6 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 2e9b3089a6da5..439bf7b40f31b 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -427,7 +427,6 @@ struct SignatureElement {
static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
"PSV Signature elements must fit in 16 bytes.");
-
} // namespace v0
namespace v1 {
@@ -468,7 +467,6 @@ struct RuntimeInfo : public v0::RuntimeInfo {
sys::swapByteOrder(GeomData.MaxVertexCount);
}
};
-
} // namespace v1
namespace v2 {
@@ -585,37 +583,39 @@ struct ProgramSignatureElement {
static_assert(sizeof(ProgramSignatureElement) == 32,
"ProgramSignatureElement is misaligned");
-
-// following dx12 naming
-// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
-struct RootConstants {
+namespace RST0 {
+namespace v0 {
+struct RootDescriptor {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
- uint32_t Num32BitValues;
-
void swapBytes() {
sys::swapByteOrder(ShaderRegister);
sys::swapByteOrder(RegisterSpace);
- sys::swapByteOrder(Num32BitValues);
}
};
-struct RootDescriptor_V1_0 {
- uint32_t ShaderRegister;
- uint32_t RegisterSpace;
+} // namespace v0
+
+namespace v1 {
+struct RootDescriptor : public v0::RootDescriptor {
+ uint32_t Flags;
void swapBytes() {
- sys::swapByteOrder(ShaderRegister);
- sys::swapByteOrder(RegisterSpace);
+ v0::RootDescriptor::swapBytes();
+ sys::swapByteOrder(Flags);
}
};
-
-struct RootDescriptor_V1_1 {
+} // namespace v1
+} // namespace RST0
+// following dx12 naming
+// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
+struct RootConstants {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
- uint32_t Flags;
+ uint32_t Num32BitValues;
+
void swapBytes() {
sys::swapByteOrder(ShaderRegister);
sys::swapByteOrder(RegisterSpace);
- sys::swapByteOrder(Flags);
+ sys::swapByteOrder(Num32BitValues);
}
};
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index cfa63db55c1c6..1f421d726bf38 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -19,8 +19,8 @@ struct RootParameter {
dxbc::RootParameterHeader Header;
union {
dxbc::RootConstants Constants;
- dxbc::RootDescriptor_V1_0 Descriptor_V10;
- dxbc::RootDescriptor_V1_1 Descriptor_V11;
+ dxbc::RST0::v0::RootDescriptor Descriptor_V10;
+ dxbc::RST0::v1::RootDescriptor Descriptor_V11;
};
};
struct RootSignatureDesc {
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 7b64c8ee15ae6..ba261a9e42aea 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -161,8 +161,8 @@ struct RootDescriptorView_V1_0 : RootParameterView {
llvm::to_underlying(dxbc::RootParameterType::UAV)));
}
- llvm::Expected<dxbc::RootDescriptor_V1_0> read() {
- return readParameter<dxbc::RootDescriptor_V1_0>();
+ llvm::Expected<dxbc::RST0::v0::RootDescriptor> read() {
+ return readParameter<dxbc::RST0::v0::RootDescriptor>();
}
};
@@ -177,8 +177,8 @@ struct RootDescriptorView_V1_1 : RootParameterView {
llvm::to_underlying(dxbc::RootParameterType::UAV)));
}
- llvm::Expected<dxbc::RootDescriptor_V1_1> read() {
- return readParameter<dxbc::RootDescriptor_V1_1>();
+ llvm::Expected<dxbc::RST0::v1::RootDescriptor> read() {
+ return readParameter<dxbc::RST0::v1::RootDescriptor>();
}
};
@@ -229,9 +229,9 @@ class RootSignature {
case dxbc::RootParameterType::SRV:
case dxbc::RootParameterType::UAV:
if (Version == 1)
- DataSize = sizeof(dxbc::RootDescriptor_V1_0);
+ DataSize = sizeof(dxbc::RST0::v0::RootDescriptor);
else
- DataSize = sizeof(dxbc::RootDescriptor_V1_1);
+ DataSize = sizeof(dxbc::RST0::v1::RootDescriptor);
break;
}
size_t EndOfSectionByte = getNumStaticSamplers() == 0
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index c54c995acd263..e86a869da99bc 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -95,7 +95,7 @@ struct RootParameterYamlDesc {
uint32_t Type;
uint32_t Visibility;
uint32_t Offset;
- RootParameterYamlDesc() {};
+ RootParameterYamlDesc(){};
RootParameterYamlDesc(uint32_t T) : Type(T) {
switch (T) {
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 25ea3cc081295..a5210f4768f16 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -41,9 +41,9 @@ size_t RootSignatureDesc::getSize() const {
case llvm::to_underlying(dxbc::RootParameterType::SRV):
case llvm::to_underlying(dxbc::RootParameterType::UAV):
if (Version == 1)
- Size += sizeof(dxbc::RootDescriptor_V1_0);
+ Size += sizeof(dxbc::RST0::v0::RootDescriptor);
else
- Size += sizeof(dxbc::RootDescriptor_V1_1);
+ Size += sizeof(dxbc::RST0::v1::RootDescriptor);
break;
}
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index ecfcd3bb0148e..ef86da85989e6 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -14,6 +14,7 @@
#include "llvm/ObjectYAML/DXContainerYAML.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/ScopeExit.h"
+#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -80,7 +81,8 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
} else if (auto *RDV = dyn_cast<object::DirectX::RootDescriptorView_V1_0>(
&ParamView)) {
- llvm::Expected<dxbc::RootDescriptor_V1_0> DescriptorOrErr = RDV->read();
+ llvm::Expected<dxbc::RST0::v0::RootDescriptor> DescriptorOrErr =
+ RDV->read();
if (Error E = DescriptorOrErr.takeError())
return std::move(E);
auto Descriptor = *DescriptorOrErr;
@@ -89,7 +91,8 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
} else if (auto *RDV = dyn_cast<object::DirectX::RootDescriptorView_V1_1>(
&ParamView)) {
- llvm::Expected<dxbc::RootDescriptor_V1_1> DescriptorOrErr = RDV->read();
+ llvm::Expected<dxbc::RST0::v1::RootDescriptor> DescriptorOrErr =
+ RDV->read();
if (Error E = DescriptorOrErr.takeError())
return std::move(E);
auto Descriptor = *DescriptorOrErr;
More information about the llvm-branch-commits
mailing list