Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
787c776
adding yaml representation and updating write logic
joaosaffran Sep 18, 2025
57fd710
fix test
joaosaffran Sep 18, 2025
d72adfe
adding missing test
joaosaffran Sep 19, 2025
23803b7
Merge branch 'main' into obj2yaml/root-signature-1.2
joaosaffran Sep 19, 2025
fefd58c
fix test
joaosaffran Sep 19, 2025
13d945d
Merge branch 'main' into obj2yaml/static-sampler-view
joaosaffran Sep 19, 2025
1d0cbd3
adding samplers_iterator
joaosaffran Sep 22, 2025
e530bcc
this was easier than I thought
joaosaffran Sep 22, 2025
79ea587
adding new test
joaosaffran Sep 22, 2025
367ac8c
Merge branch 'main' into obj2yaml/root-signature-1.2
joaosaffran Sep 22, 2025
a08c05e
Merge branch 'obj2yaml/root-signature-1.2' of github.com:joaosaffran/…
joaosaffran Sep 22, 2025
159388d
Merge branch 'obj2yaml/root-signature-1.2' into obj2yaml/static-sampl…
joaosaffran Sep 22, 2025
905d5d3
clean up
joaosaffran Sep 22, 2025
b73bf24
clean up
joaosaffran Sep 22, 2025
ddf9945
changing size and remove untested parameters
joaosaffran Sep 24, 2025
284901c
adding suggested comment
joaosaffran Sep 24, 2025
73e6bb5
addressing inbelic comments
joaosaffran Sep 24, 2025
159cd57
addressing inbelic comments
joaosaffran Sep 24, 2025
b7f07aa
format
joaosaffran Sep 24, 2025
b5ecf7f
Merge branch 'obj2yaml/root-signature-1.2' into obj2yaml/static-sampl…
joaosaffran Sep 25, 2025
efcd873
remove test
joaosaffran Sep 26, 2025
9c2c1d3
Merge branch 'obj2yaml/root-signature-1.2' into obj2yaml/static-sampl…
joaosaffran Sep 26, 2025
74a5956
Merge branch 'main' into obj2yaml/static-sampler-view
joaosaffran Sep 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions llvm/include/llvm/BinaryFormat/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ enum class DescriptorRangeFlags : uint32_t {

LLVM_ABI ArrayRef<EnumEntry<DescriptorRangeFlags>> getDescriptorRangeFlags();

#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) Enum = Num,
enum class StaticSamplerFlags : uint32_t {
#include "DXContainerConstants.def"

LLVM_MARK_AS_BITMASK_ENUM(NonNormalizedCoordinates)
};

LLVM_ABI ArrayRef<EnumEntry<StaticSamplerFlags>> getStaticSamplerFlags();

#define ROOT_PARAMETER(Val, Enum) Enum = Val,
enum class RootParameterType : uint32_t {
#include "DXContainerConstants.def"
Expand Down Expand Up @@ -813,6 +822,21 @@ struct DescriptorRange {
}
};
} // namespace v2
namespace v3 {
struct StaticSampler : public v1::StaticSampler {
uint32_t Flags;

StaticSampler() = default;
explicit StaticSampler(v1::StaticSampler &Base)
: v1::StaticSampler(Base), Flags(0U) {}

void swapBytes() {
v1::StaticSampler::swapBytes();
sys::swapByteOrder(Flags);
}
};

} // namespace v3
} // namespace RTS0

// D3D_ROOT_SIGNATURE_VERSION
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/BinaryFormat/DXContainerConstants.def
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ DESCRIPTOR_RANGE_FLAG(0x10000, DescriptorsStaticKeepingBufferBoundsChecks, DESCR
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG

// STATIC_SAMPLER_FLAG(flag value, name, flag).
#ifdef STATIC_SAMPLER_FLAG

STATIC_SAMPLER_FLAG(0x0, None, SAMPLER_FLAG_NONE)
STATIC_SAMPLER_FLAG(0x1, UintBorderColor, SAMPLER_FLAG_UINT_BORDER_COLOR)
STATIC_SAMPLER_FLAG(0x2, NonNormalizedCoordinates, SAMPLER_FLAG_NON_NORMALIZED_COORDINATES)

#undef STATIC_SAMPLER_FLAG
#endif // STATIC_SAMPLER_FLAG

#ifdef ROOT_PARAMETER

ROOT_PARAMETER(0, DescriptorTable)
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/MC/DXContainerRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct StaticSampler {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
dxbc::ShaderVisibility ShaderVisibility;
uint32_t Flags;
};

struct RootParametersContainer {
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Object/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ class RootSignature {
uint32_t Flags;
ViewArray<dxbc::RTS0::v1::RootParameterHeader> ParametersHeaders;
StringRef PartData;
ViewArray<dxbc::RTS0::v1::StaticSampler> StaticSamplers;
ViewArray<dxbc::RTS0::v3::StaticSampler> StaticSamplers;

using param_header_iterator =
ViewArray<dxbc::RTS0::v1::RootParameterHeader>::iterator;
using samplers_iterator = ViewArray<dxbc::RTS0::v1::StaticSampler>::iterator;
using samplers_iterator = ViewArray<dxbc::RTS0::v3::StaticSampler>::iterator;

public:
RootSignature(StringRef PD) : PartData(PD) {}
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/ObjectYAML/DXContainerYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ struct StaticSamplerYamlDesc {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
dxbc::ShaderVisibility ShaderVisibility;

LLVM_ABI uint32_t getEncodedFlags() const;

#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) bool Enum = false;
#include "llvm/BinaryFormat/DXContainerConstants.def"
};

struct RootSignatureYamlDesc {
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/BinaryFormat/DXContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ ArrayRef<EnumEntry<DescriptorRangeFlags>> dxbc::getDescriptorRangeFlags() {
return ArrayRef(DescriptorRangeFlagNames);
}

static const EnumEntry<StaticSamplerFlags> StaticSamplerFlagNames[] = {
#define STATIC_SAMPLER_FLAG(Val, Enum, Flag) {#Enum, StaticSamplerFlags::Enum},
#include "llvm/BinaryFormat/DXContainerConstants.def"
};

ArrayRef<EnumEntry<StaticSamplerFlags>> dxbc::getStaticSamplerFlags() {
return ArrayRef(StaticSamplerFlagNames);
}

#define SHADER_VISIBILITY(Val, Enum) {#Enum, ShaderVisibility::Enum},

static const EnumEntry<ShaderVisibility> ShaderVisibilityValues[] = {
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace rootsig {

bool verifyRootFlag(uint32_t Flags) { return (Flags & ~0xfff) == 0; }

bool verifyVersion(uint32_t Version) { return (Version == 1 || Version == 2); }
bool verifyVersion(uint32_t Version) {
return (Version == 1 || Version == 2 || Version == 3);
}

bool verifyRegisterValue(uint32_t RegisterValue) {
return RegisterValue != ~0U;
Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/MC/DXContainerRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ static uint32_t rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
size_t RootSignatureDesc::getSize() const {
uint32_t StaticSamplersOffset = computeStaticSamplersOffset();
size_t StaticSamplersSize =
StaticSamplers.size() * sizeof(dxbc::RTS0::v1::StaticSampler);
(Version > 2 ? sizeof(dxbc::RTS0::v3::StaticSampler)
: sizeof(dxbc::RTS0::v1::StaticSampler)) *
StaticSamplers.size();

return size_t(StaticSamplersOffset) + StaticSamplersSize;
}
Expand Down Expand Up @@ -171,6 +173,9 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
support::endian::write(BOS, S.RegisterSpace, llvm::endianness::little);
support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);

if (Version > 2)
support::endian::write(BOS, S.Flags, llvm::endianness::little);
}
assert(Storage.size() == getSize());
OS.write(Storage.data(), Storage.size());
Expand Down
11 changes: 7 additions & 4 deletions llvm/lib/Object/DXContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ Error DirectX::RootSignature::parse() {
RootParametersOffset,
NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader));

StaticSamplers.Stride = sizeof(dxbc::RTS0::v1::StaticSampler);
StaticSamplers.Data = PartData.substr(
StaticSamplersOffset,
NumStaticSamplers * sizeof(dxbc::RTS0::v1::StaticSampler));
StaticSamplers.Stride = (Version <= 2)
? sizeof(dxbc::RTS0::v1::StaticSampler)
: sizeof(dxbc::RTS0::v3::StaticSampler);

StaticSamplers.Data = PartData.substr(StaticSamplersOffset,
static_cast<size_t>(NumStaticSamplers) *
StaticSamplers.Stride);

return Error::success();
}
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/ObjectYAML/DXContainerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
NewSampler.RegisterSpace = Param.RegisterSpace;
NewSampler.ShaderVisibility = Param.ShaderVisibility;

if (RS.Version > 2)
NewSampler.Flags = Param.getEncodedFlags();

RS.StaticSamplers.push_back(NewSampler);
}

Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/ObjectYAML/DXContainerYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ DXContainerYAML::RootSignatureYamlDesc::create(
NewS.RegisterSpace = S.RegisterSpace;
NewS.ShaderVisibility = dxbc::ShaderVisibility(S.ShaderVisibility);

if (Version > 2) {
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
NewS.Enum = \
(S.Flags & llvm::to_underlying(dxbc::StaticSamplerFlags::Enum)) > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think the > 0 comparison is redundant

#include "llvm/BinaryFormat/DXContainerConstants.def"
}
RootSigDesc.StaticSamplers.push_back(NewS);
}

Expand Down Expand Up @@ -245,6 +251,15 @@ uint32_t DXContainerYAML::DescriptorRangeYaml::getEncodedFlags() const {
return Flags;
}

uint32_t DXContainerYAML::StaticSamplerYamlDesc::getEncodedFlags() const {
uint64_t Flags = 0;
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
if (Enum) \
Flags |= (uint32_t)dxbc::StaticSamplerFlags::Enum;
#include "llvm/BinaryFormat/DXContainerConstants.def"
return Flags;
}

uint64_t DXContainerYAML::ShaderFeatureFlags::getEncodedFlags() {
uint64_t Flag = 0;
#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) \
Expand Down Expand Up @@ -512,6 +527,9 @@ void MappingTraits<llvm::DXContainerYAML::StaticSamplerYamlDesc>::mapping(
IO.mapRequired("ShaderRegister", S.ShaderRegister);
IO.mapRequired("RegisterSpace", S.RegisterSpace);
IO.mapRequired("ShaderVisibility", S.ShaderVisibility);
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
IO.mapOptional(#Flag, S.Enum, false);
#include "llvm/BinaryFormat/DXContainerConstants.def"
}

void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s

target triple = "dxil-unknown-shadermodel6.0-compute"


; CHECK: error: Invalid value for Version: 4
; CHECK-NOT: Root Signature Definitions
define void @main() #0 {
entry:
ret void
}
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }


!dx.rootsignatures = !{!2, !3, !4, !5} ; list of function/root signature pairs
!2 = !{ ptr @main, !6, i32 1 } ; function, root signature
!3 = !{ ptr @main, !6, i32 4 } ; function, root signature
!4 = !{ ptr @main, !6, i32 2 } ; function, root signature
!5 = !{ ptr @main, !6, i32 3 } ; function, root signature
!6 = !{ } ; list of root signature elements
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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: 80
RootSignature:
Version: 3
NumRootParameters: 0
RootParametersOffset: 24
NumStaticSamplers: 1
StaticSamplersOffset: 24
Parameters: []
Samplers:
- Filter: MinLinearMagMipPoint
AddressU: Wrap
AddressV: Mirror
AddressW: MirrorOnce
MipLODBias: 1.23
MaxAnisotropy: 20
ComparisonFunc: LessEqual
BorderColor: TransparentBlack
MinLOD: 4.56
MaxLOD: 8.90
ShaderRegister: 31
RegisterSpace: 32
ShaderVisibility: Mesh
SAMPLER_FLAG_UINT_BORDER_COLOR: true
AllowInputAssemblerInputLayout: true
DenyGeometryShaderRootAccess: true

#CHECK: - Name: RTS0
#CHECK-NEXT: Size: 80
#CHECK-NEXT: RootSignature:
#CHECK-NEXT: Version: 3
#CHECK-NEXT: NumRootParameters: 0
#CHECK-NEXT: RootParametersOffset: 24
#CHECK-NEXT: NumStaticSamplers: 1
#CHECK-NEXT: StaticSamplersOffset: 24
#CHECK-NEXT: Parameters: []
#CHECK-NEXT: Samplers:
#CHECK-NEXT: - Filter: MinLinearMagMipPoint
#CHECK-NEXT: AddressU: Wrap
#CHECK-NEXT: AddressV: Mirror
#CHECK-NEXT: AddressW: MirrorOnce
#CHECK-NEXT: MipLODBias: 1.23
#CHECK-NEXT: MaxAnisotropy: 20
#CHECK-NEXT: ComparisonFunc: LessEqual
#CHECK-NEXT: BorderColor: TransparentBlack
#CHECK-NEXT: MinLOD: 4.56
#CHECK-NEXT: MaxLOD: 8.9
#CHECK-NEXT: ShaderRegister: 31
#CHECK-NEXT: RegisterSpace: 32
#CHECK-NEXT: ShaderVisibility: Mesh
#CHECK-NEXT: SAMPLER_FLAG_UINT_BORDER_COLOR: true
#CHECK-NEXT: AllowInputAssemblerInputLayout: true
#CHECK-NEXT: DenyGeometryShaderRootAccess: true
45 changes: 45 additions & 0 deletions llvm/unittests/Object/DXContainerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,4 +1200,49 @@ TEST(RootSignature, ParseStaticSamplers) {
ASSERT_EQ(Sampler.RegisterSpace, 32u);
ASSERT_EQ(Sampler.ShaderVisibility, 7u);
}
{
uint8_t Buffer[] = {
0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 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,
0x52, 0x54, 0x53, 0x30, 0x4c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0xa4, 0x70, 0x9d, 0x3f, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x85, 0xeb, 0x91, 0x40, 0x66, 0x66, 0x0e, 0x41,
0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00};
DXContainer C =
llvm::cantFail(DXContainer::create(getMemoryBuffer<148>(Buffer)));

auto MaybeRS = C.getRootSignature();
ASSERT_TRUE(MaybeRS.has_value());
const auto &RS = MaybeRS.value();
ASSERT_EQ(RS.getVersion(), 3U);
ASSERT_EQ(RS.getNumParameters(), 0U);
ASSERT_EQ(RS.getRootParametersOffset(), 0U);
ASSERT_EQ(RS.getNumStaticSamplers(), 1U);
ASSERT_EQ(RS.getStaticSamplersOffset(), 24U);
ASSERT_EQ(RS.getFlags(), 17U);

auto Sampler = *RS.samplers().begin();

ASSERT_EQ(Sampler.Filter, 10U);
ASSERT_EQ(Sampler.AddressU, 1U);
ASSERT_EQ(Sampler.AddressV, 2U);
ASSERT_EQ(Sampler.AddressW, 5U);
ASSERT_FLOAT_EQ(Sampler.MipLODBias, 1.23F);
ASSERT_EQ(Sampler.MaxAnisotropy, 20U);
ASSERT_EQ(Sampler.ComparisonFunc, 4U);
ASSERT_EQ(Sampler.BorderColor, 0U);
ASSERT_FLOAT_EQ(Sampler.MinLOD, 4.56F);
ASSERT_FLOAT_EQ(Sampler.MaxLOD, 8.9F);
ASSERT_EQ(Sampler.ShaderRegister, 31U);
ASSERT_EQ(Sampler.RegisterSpace, 32U);
ASSERT_EQ(Sampler.ShaderVisibility, 7U);
ASSERT_EQ(Sampler.Flags, 1U);
}
}
Loading