Skip to content

Commit 787c776

Browse files
committed
adding yaml representation and updating write logic
1 parent 53a18eb commit 787c776

File tree

10 files changed

+134
-2
lines changed

10 files changed

+134
-2
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ enum class DescriptorRangeFlags : uint32_t {
185185

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

188+
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) Enum = Num,
189+
enum class StaticSamplerFlags : uint32_t {
190+
#include "DXContainerConstants.def"
191+
192+
LLVM_MARK_AS_BITMASK_ENUM(NonNormalizedCoordinates)
193+
};
194+
195+
LLVM_ABI ArrayRef<EnumEntry<StaticSamplerFlags>> getStaticSamplerFlags();
196+
188197
#define ROOT_PARAMETER(Val, Enum) Enum = Val,
189198
enum class RootParameterType : uint32_t {
190199
#include "DXContainerConstants.def"
@@ -813,6 +822,21 @@ struct DescriptorRange {
813822
}
814823
};
815824
} // namespace v2
825+
namespace v3 {
826+
struct StaticSampler : public v1::StaticSampler {
827+
uint32_t Flags;
828+
829+
StaticSampler() = default;
830+
explicit StaticSampler(v1::StaticSampler &Base)
831+
: v1::StaticSampler(Base), Flags(0U) {}
832+
833+
void swapBytes() {
834+
v1::StaticSampler::swapBytes();
835+
sys::swapByteOrder(Flags);
836+
}
837+
};
838+
839+
} // namespace v3
816840
} // namespace RTS0
817841

818842
// D3D_ROOT_SIGNATURE_VERSION

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ DESCRIPTOR_RANGE_FLAG(0x10000, DescriptorsStaticKeepingBufferBoundsChecks, DESCR
104104
#undef DESCRIPTOR_RANGE_FLAG
105105
#endif // DESCRIPTOR_RANGE_FLAG
106106

107+
// STATIC_SAMPLER_FLAG(flag value, name, flag).
108+
#ifdef STATIC_SAMPLER_FLAG
109+
110+
STATIC_SAMPLER_FLAG(0x0, None, SAMPLER_FLAG_NONE)
111+
STATIC_SAMPLER_FLAG(0x1, UintBorderColor, SAMPLER_FLAG_UINT_BORDER_COLOR)
112+
STATIC_SAMPLER_FLAG(0x2, NonNormalizedCoordinates, SAMPLER_FLAG_NON_NORMALIZED_COORDINATES)
113+
114+
#undef STATIC_SAMPLER_FLAG
115+
#endif // STATIC_SAMPLER_FLAG
116+
107117
#ifdef ROOT_PARAMETER
108118

109119
ROOT_PARAMETER(0, DescriptorTable)

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct StaticSampler {
7474
uint32_t ShaderRegister;
7575
uint32_t RegisterSpace;
7676
dxbc::ShaderVisibility ShaderVisibility;
77+
uint32_t Flags;
7778
};
7879

7980
struct RootParametersContainer {

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ struct StaticSamplerYamlDesc {
178178
uint32_t ShaderRegister;
179179
uint32_t RegisterSpace;
180180
dxbc::ShaderVisibility ShaderVisibility;
181+
182+
LLVM_ABI uint32_t getEncodedFlags() const;
183+
184+
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) bool Enum = false;
185+
#include "llvm/BinaryFormat/DXContainerConstants.def"
181186
};
182187

183188
struct RootSignatureYamlDesc {

llvm/lib/BinaryFormat/DXContainer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ ArrayRef<EnumEntry<DescriptorRangeFlags>> dxbc::getDescriptorRangeFlags() {
8989
return ArrayRef(DescriptorRangeFlagNames);
9090
}
9191

92+
static const EnumEntry<StaticSamplerFlags> StaticSamplerFlagNames[] = {
93+
#define STATIC_SAMPLER_FLAG(Val, Enum, Flag) {#Enum, StaticSamplerFlags::Enum},
94+
#include "llvm/BinaryFormat/DXContainerConstants.def"
95+
};
96+
97+
ArrayRef<EnumEntry<StaticSamplerFlags>> dxbc::getStaticSamplerFlags() {
98+
return ArrayRef(StaticSamplerFlagNames);
99+
}
100+
92101
#define SHADER_VISIBILITY(Val, Enum) {#Enum, ShaderVisibility::Enum},
93102

94103
static const EnumEntry<ShaderVisibility> ShaderVisibilityValues[] = {

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ namespace rootsig {
2020

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

23-
bool verifyVersion(uint32_t Version) { return (Version == 1 || Version == 2); }
23+
bool verifyVersion(uint32_t Version) {
24+
return (Version == 1 || Version == 2 || Version == 3);
25+
}
2426

2527
bool verifyRegisterValue(uint32_t RegisterValue) {
2628
return RegisterValue != ~0U;

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ static uint32_t rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
3333
size_t RootSignatureDesc::getSize() const {
3434
uint32_t StaticSamplersOffset = computeStaticSamplersOffset();
3535
size_t StaticSamplersSize =
36-
StaticSamplers.size() * sizeof(dxbc::RTS0::v1::StaticSampler);
36+
(Version > 2 ? sizeof(dxbc::RTS0::v3::StaticSampler)
37+
: sizeof(dxbc::RTS0::v1::StaticSampler)) *
38+
StaticSamplers.size();
3739

3840
return size_t(StaticSamplersOffset) + StaticSamplersSize;
3941
}
@@ -171,6 +173,9 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
171173
support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
172174
support::endian::write(BOS, S.RegisterSpace, llvm::endianness::little);
173175
support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
176+
177+
if (Version > 2)
178+
support::endian::write(BOS, S.Flags, llvm::endianness::little);
174179
}
175180
assert(Storage.size() == getSize());
176181
OS.write(Storage.data(), Storage.size());

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
343343
NewSampler.RegisterSpace = Param.RegisterSpace;
344344
NewSampler.ShaderVisibility = Param.ShaderVisibility;
345345

346+
if (RS.Version > 2)
347+
NewSampler.Flags = Param.getEncodedFlags();
348+
346349
RS.StaticSamplers.push_back(NewSampler);
347350
}
348351

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ uint32_t DXContainerYAML::DescriptorRangeYaml::getEncodedFlags() const {
245245
return Flags;
246246
}
247247

248+
uint32_t DXContainerYAML::StaticSamplerYamlDesc::getEncodedFlags() const {
249+
uint64_t Flags = 0;
250+
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
251+
if (Enum) \
252+
Flags |= (uint32_t)dxbc::StaticSamplerFlags::Enum;
253+
#include "llvm/BinaryFormat/DXContainerConstants.def"
254+
return Flags;
255+
}
256+
248257
uint64_t DXContainerYAML::ShaderFeatureFlags::getEncodedFlags() {
249258
uint64_t Flag = 0;
250259
#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) \
@@ -512,6 +521,9 @@ void MappingTraits<llvm::DXContainerYAML::StaticSamplerYamlDesc>::mapping(
512521
IO.mapRequired("ShaderRegister", S.ShaderRegister);
513522
IO.mapRequired("RegisterSpace", S.RegisterSpace);
514523
IO.mapRequired("ShaderVisibility", S.ShaderVisibility);
524+
525+
#define STATIC_SAMPLER_FLAG_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false);
526+
#include "llvm/BinaryFormat/DXContainerConstants.def"
515527
}
516528

517529
void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,

llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,64 @@ TEST(RootSignature, ParseStaticSamplers) {
526526
EXPECT_EQ(Storage.size(), 144u);
527527
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 144u) == 0);
528528
}
529+
530+
TEST(RootSignature, ParseStaticSamplersV13) {
531+
SmallString<128> Storage;
532+
533+
// First read a fully explicit yaml with all sizes and offsets provided
534+
ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
535+
Header:
536+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
537+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
538+
Version:
539+
Major: 1
540+
Minor: 0
541+
PartCount: 1
542+
PartOffsets: [ 60 ]
543+
Parts:
544+
- Name: RTS0
545+
Size: 76
546+
RootSignature:
547+
Version: 3
548+
NumRootParameters: 0
549+
RootParametersOffset: 24
550+
NumStaticSamplers: 1
551+
StaticSamplersOffset: 24
552+
Parameters: []
553+
Samplers:
554+
- Filter: MinLinearMagMipPoint
555+
AddressU: Wrap
556+
AddressV: Mirror
557+
AddressW: MirrorOnce
558+
MipLODBias: 1.23
559+
MaxAnisotropy: 20
560+
ComparisonFunc: LessEqual
561+
BorderColor: TransparentBlack
562+
MinLOD: 4.56
563+
MaxLOD: 8.90
564+
ShaderRegister: 31
565+
RegisterSpace: 32
566+
ShaderVisibility: Mesh
567+
SAMPLER_FLAG_UINT_BORDER_COLOR: true
568+
AllowInputAssemblerInputLayout: true
569+
DenyGeometryShaderRootAccess: true
570+
)"));
571+
572+
uint8_t Buffer[] = {
573+
0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
574+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
575+
0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
576+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578+
0x52, 0x54, 0x53, 0x30, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
579+
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
580+
0x18, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
581+
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
582+
0xa4, 0x70, 0x9d, 0x3f, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
583+
0x00, 0x00, 0x00, 0x00, 0x85, 0xeb, 0x91, 0x40, 0x66, 0x66, 0x0e, 0x41,
584+
0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
585+
0x01};
586+
587+
EXPECT_EQ(Storage.size(), 148U);
588+
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 148U) == 0);
589+
}

0 commit comments

Comments
 (0)