[llvm] 03d3e6d - [DirectX] Adding support for Root Descriptors in obj2yaml/yaml2obj (#137259)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 23:18:30 PDT 2025
Author: joaosaffran
Date: 2025-05-08T23:18:26-07:00
New Revision: 03d3e6dbe9e7a0c64e6c62b583bb187723421717
URL: https://github.com/llvm/llvm-project/commit/03d3e6dbe9e7a0c64e6c62b583bb187723421717
DIFF: https://github.com/llvm/llvm-project/commit/03d3e6dbe9e7a0c64e6c62b583bb187723421717.diff
LOG: [DirectX] Adding support for Root Descriptors in obj2yaml/yaml2obj (#137259)
closes: [126634](https://github.com/llvm/llvm-project/issues/126634)
---------
Co-authored-by: joaosaffran <joao.saffran at microsoft.com>
Added:
llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.1.yaml
Modified:
llvm/include/llvm/BinaryFormat/DXContainer.h
llvm/include/llvm/BinaryFormat/DXContainerConstants.def
llvm/include/llvm/MC/DXContainerRootSignature.h
llvm/include/llvm/Object/DXContainer.h
llvm/include/llvm/ObjectYAML/DXContainerYAML.h
llvm/lib/MC/DXContainerRootSignature.cpp
llvm/lib/ObjectYAML/DXContainerEmitter.cpp
llvm/lib/ObjectYAML/DXContainerYAML.cpp
llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml
llvm/unittests/Object/DXContainerTest.cpp
llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 455657980bf40..4fbc0cf1e5954 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -158,6 +158,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"
@@ -580,7 +585,33 @@ struct ProgramSignatureElement {
static_assert(sizeof(ProgramSignatureElement) == 32,
"ProgramSignatureElement is misaligned");
+namespace RTS0 {
+namespace v1 {
+struct RootDescriptor {
+ uint32_t ShaderRegister;
+ uint32_t RegisterSpace;
+ void swapBytes() {
+ sys::swapByteOrder(ShaderRegister);
+ sys::swapByteOrder(RegisterSpace);
+ }
+};
+} // namespace v1
+
+namespace v2 {
+struct RootDescriptor : public v1::RootDescriptor {
+ uint32_t Flags;
+
+ RootDescriptor() = default;
+ RootDescriptor(v1::RootDescriptor &Base)
+ : v1::RootDescriptor(Base), Flags(0u) {}
+ void swapBytes() {
+ v1::RootDescriptor::swapBytes();
+ sys::swapByteOrder(Flags);
+ }
+};
+} // namespace v2
+} // namespace RTS0
// following dx12 naming
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
struct RootConstants {
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index a00c13ca1cb5f..1645018aebedb 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -74,9 +74,24 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
#undef ROOT_ELEMENT_FLAG
#endif // ROOT_ELEMENT_FLAG
+
+// ROOT_DESCRIPTOR_FLAG(bit offset for the flag, name).
+#ifdef ROOT_DESCRIPTOR_FLAG
+
+ROOT_DESCRIPTOR_FLAG(0, NONE)
+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
+
+
#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..e3c4900ba175c 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -19,6 +19,7 @@ struct RootParameter {
dxbc::RootParameterHeader Header;
union {
dxbc::RootConstants Constants;
+ dxbc::RTS0::v2::RootDescriptor Descriptor;
};
};
struct RootSignatureDesc {
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index e8287ce078365..61bfa9411cc57 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Error.h"
@@ -24,6 +25,7 @@
#include "llvm/TargetParser/Triple.h"
#include <array>
#include <cstddef>
+#include <cstdint>
#include <variant>
namespace llvm {
@@ -121,6 +123,7 @@ namespace DirectX {
struct RootParameterView {
const dxbc::RootParameterHeader &Header;
StringRef ParamData;
+
RootParameterView(const dxbc::RootParameterHeader &H, StringRef P)
: Header(H), ParamData(P) {}
@@ -149,6 +152,31 @@ struct RootConstantView : RootParameterView {
}
};
+struct RootDescriptorView : 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::RTS0::v2::RootDescriptor> read(uint32_t Version) {
+ if (Version == 1) {
+ auto Descriptor = readParameter<dxbc::RTS0::v1::RootDescriptor>();
+ if (Error E = Descriptor.takeError())
+ return E;
+ return dxbc::RTS0::v2::RootDescriptor(*Descriptor);
+ }
+ if (Version != 2)
+ return make_error<GenericBinaryError>("Invalid Root Signature version: " +
+ Twine(Version),
+ object_error::parse_failed);
+ return readParameter<dxbc::RTS0::v2::RootDescriptor>();
+ }
+};
+
static Error parseFailed(const Twine &Msg) {
return make_error<GenericBinaryError>(Msg.str(), object_error::parse_failed);
}
@@ -192,6 +220,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::RTS0::v1::RootDescriptor);
+ else
+ DataSize = sizeof(dxbc::RTS0::v2::RootDescriptor);
+ 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..73532fa392520 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -21,7 +21,6 @@
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/YAMLTraits.h"
#include <array>
-#include <cstdint>
#include <optional>
#include <string>
#include <vector>
@@ -73,21 +72,46 @@ 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;
};
+struct RootDescriptorYaml {
+ RootDescriptorYaml() = default;
+
+ uint32_t ShaderRegister;
+ uint32_t RegisterSpace;
+
+ uint32_t getEncodedFlags() const;
+
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false;
+#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;
};
};
@@ -111,6 +135,7 @@ struct RootSignatureYamlDesc {
static llvm::Expected<DXContainerYAML::RootSignatureYamlDesc>
create(const object::DirectX::RootSignature &Data);
+#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
@@ -298,6 +323,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..161711a79e467 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -37,6 +37,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::RTS0::v1::RootDescriptor);
+ else
+ Size += sizeof(dxbc::RTS0::v2::RootDescriptor);
+
+ break;
}
}
return Size;
@@ -80,6 +89,16 @@ 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):
+ support::endian::write(BOS, P.Descriptor.ShaderRegister,
+ llvm::endianness::little);
+ support::endian::write(BOS, P.Descriptor.RegisterSpace,
+ llvm::endianness::little);
+ if (Version > 1)
+ support::endian::write(BOS, P.Descriptor.Flags,
+ llvm::endianness::little);
}
}
assert(Storage.size() == getSize());
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 86e24eae4abc6..239ee9e3de9b1 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -284,6 +284,14 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
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):
+ NewParam.Descriptor.RegisterSpace = Param.Descriptor.RegisterSpace;
+ NewParam.Descriptor.ShaderRegister = Param.Descriptor.ShaderRegister;
+ if (P.RootSignature->Version > 1)
+ NewParam.Descriptor.Flags = Param.Descriptor.getEncodedFlags();
+ break;
}
RS.Parameters.push_back(NewParam);
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 59914fe30082d..8964c913946f2 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -38,8 +38,9 @@ DXContainerYAML::RootSignatureYamlDesc::create(
const object::DirectX::RootSignature &Data) {
RootSignatureYamlDesc RootSigDesc;
+ uint32_t Version = Data.getVersion();
- RootSigDesc.Version = Data.getVersion();
+ RootSigDesc.Version = Version;
RootSigDesc.NumStaticSamplers = Data.getNumStaticSamplers();
RootSigDesc.StaticSamplersOffset = Data.getStaticSamplersOffset();
RootSigDesc.NumRootParameters = Data.getNumRootParameters();
@@ -48,13 +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))
@@ -79,7 +79,24 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewP.Constants.Num32BitValues = Constants.Num32BitValues;
NewP.Constants.ShaderRegister = Constants.ShaderRegister;
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
+ } else if (auto *RDV =
+ dyn_cast<object::DirectX::RootDescriptorView>(&ParamView)) {
+ llvm::Expected<dxbc::RTS0::v2::RootDescriptor> DescriptorOrErr =
+ RDV->read(Version);
+ if (Error E = DescriptorOrErr.takeError())
+ return std::move(E);
+ auto Descriptor = *DescriptorOrErr;
+ NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
+ NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
+ if (Version > 1) {
+#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 +106,15 @@ DXContainerYAML::RootSignatureYamlDesc::create(
return RootSigDesc;
}
+uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() const {
+ 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 +302,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 +319,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-Descriptor1.0.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
new file mode 100644
index 0000000000000..889eccf74001f
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Descriptor1.0.yaml
@@ -0,0 +1,45 @@
+# 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
+ 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 f366d71714359..debb459c3944e 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: 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..72f860a5039ff 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 *RootDescriptorView =
+ dyn_cast<DirectX::RootDescriptorView>(&*ParamView);
+ ASSERT_TRUE(RootDescriptorView != nullptr);
+ auto Descriptor = RootDescriptorView->read(RS.getVersion());
+
+ 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 *RootDescriptorView =
+ dyn_cast<DirectX::RootDescriptorView>(&*ParamView);
+ ASSERT_TRUE(RootDescriptorView != nullptr);
+ auto Descriptor = RootDescriptorView->read(RS.getVersion());
+
+ 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);
+}
More information about the llvm-commits
mailing list