Skip to content

Commit 6187125

Browse files
committed
Merge branch 'obj2yaml/static-sampler-view' into metadata/rootsignature1.2
2 parents c25fee8 + b5ecf7f commit 6187125

File tree

10 files changed

+63
-26
lines changed

10 files changed

+63
-26
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ struct DescriptorRange {
822822
}
823823
};
824824
} // namespace v2
825+
825826
namespace v3 {
826827
struct StaticSampler : public v1::StaticSampler {
827828
uint32_t Flags;

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ LLVM_ABI bool verifyRangeType(uint32_t Type);
3333
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
3434
dxil::ResourceClass Type,
3535
dxbc::DescriptorRangeFlags FlagsVal);
36+
LLVM_ABI bool verifyStaticSamplerFlags(uint32_t Version,
37+
dxbc::StaticSamplerFlags Flags);
3638
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
3739
LLVM_ABI bool verifyMipLODBias(float MipLODBias);
3840
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy);

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ struct StaticSampler {
7474
uint32_t ShaderRegister;
7575
uint32_t RegisterSpace;
7676
dxbc::ShaderVisibility ShaderVisibility;
77-
uint32_t Flags;
77+
// Version 3 onwards:
78+
uint32_t Flags = 0;
7879
};
7980

8081
struct RootParametersContainer {

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,13 @@ Error MetadataParser::validateRootSignature(
662662
joinErrors(std::move(DeferredErrs),
663663
make_error<RootSignatureValidationError<uint32_t>>(
664664
"RegisterSpace", Sampler.RegisterSpace));
665+
666+
if (!hlsl::rootsig::verifyStaticSamplerFlags(
667+
RSD.Version, dxbc::StaticSamplerFlags(Sampler.Flags)))
668+
DeferredErrs =
669+
joinErrors(std::move(DeferredErrs),
670+
make_error<RootSignatureValidationError<uint32_t>>(
671+
"Static Sampler Flag", Sampler.Flags));
665672
}
666673

667674
return DeferredErrs;

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ bool verifyDescriptorRangeFlag(uint32_t Version, dxil::ResourceClass Type,
113113
return (Flags & ~Mask) == FlagT::None;
114114
}
115115

116+
bool verifyStaticSamplerFlags(uint32_t Version,
117+
dxbc::StaticSamplerFlags Flags) {
118+
119+
if (Version <= 2)
120+
return Flags == dxbc::StaticSamplerFlags::None;
121+
122+
assert(Version == 3 && "Provided invalid root signature version");
123+
124+
dxbc::StaticSamplerFlags Mask =
125+
dxbc::StaticSamplerFlags::NonNormalizedCoordinates |
126+
dxbc::StaticSamplerFlags::UintBorderColor |
127+
dxbc::StaticSamplerFlags::None;
128+
return (Flags | Mask) == Mask;
129+
}
130+
116131
bool verifyNumDescriptors(uint32_t NumDescriptors) {
117132
return NumDescriptors > 0;
118133
}

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ static uint32_t rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
3232

3333
size_t RootSignatureDesc::getSize() const {
3434
uint32_t StaticSamplersOffset = computeStaticSamplersOffset();
35-
size_t StaticSamplersSize =
36-
(Version > 2 ? sizeof(dxbc::RTS0::v3::StaticSampler)
37-
: sizeof(dxbc::RTS0::v1::StaticSampler)) *
38-
StaticSamplers.size();
35+
size_t StaticSamplersSize = sizeof(dxbc::RTS0::v1::StaticSampler);
36+
if (Version > 2)
37+
StaticSamplersSize = sizeof(dxbc::RTS0::v3::StaticSampler);
3938

40-
return size_t(StaticSamplersOffset) + StaticSamplersSize;
39+
return size_t(StaticSamplersOffset) +
40+
(StaticSamplersSize * StaticSamplers.size());
4141
}
4242

4343
uint32_t RootSignatureDesc::computeRootParametersOffset() const {

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
211211

212212
if (Version > 2) {
213213
#define STATIC_SAMPLER_FLAG(Num, Enum, Flag) \
214-
NewS.Enum = \
215-
(S.Flags & llvm::to_underlying(dxbc::StaticSamplerFlags::Enum)) > 0;
214+
NewS.Enum = (S.Flags & llvm::to_underlying(dxbc::StaticSamplerFlags::Enum));
216215
#include "llvm/BinaryFormat/DXContainerConstants.def"
217216
}
218217
RootSigDesc.StaticSamplers.push_back(NewS);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
2+
3+
4+
target triple = "dxil-unknown-shadermodel6.0-compute"
5+
6+
; CHECK: error: Invalid value for ShaderVisibility: 666
7+
; CHECK-NOT: Root Signature Definitions
8+
9+
define void @main() #0 {
10+
entry:
11+
ret void
12+
}
13+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
14+
15+
16+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
17+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
18+
!3 = !{ !5 } ; list of root signature elements
19+
!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 666 }

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,9 @@ TEST(RootSignature, ParseStaticSamplers) {
12011201
ASSERT_EQ(Sampler.ShaderVisibility, 7u);
12021202
}
12031203
{
1204+
// this is testing static sampler parsing for root signature version 1.2,
1205+
// it changes: the version number, the size of root signature being emitted
1206+
// and the values for flag fields.
12041207
uint8_t Buffer[] = {
12051208
0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12061209
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,

llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ TEST(RootSignature, ParseStaticSamplers) {
528528
}
529529

530530
TEST(RootSignature, ParseStaticSamplersV13) {
531-
SmallString<160> Storage;
531+
SmallString<128> Storage;
532532

533533
// First read a fully explicit yaml with all sizes and offsets provided
534534
ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
@@ -551,19 +551,9 @@ TEST(RootSignature, ParseStaticSamplersV13) {
551551
StaticSamplersOffset: 24
552552
Parameters: []
553553
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
554+
- ShaderRegister: 31
565555
RegisterSpace: 32
566-
ShaderVisibility: Mesh
556+
ShaderVisibility: All
567557
SAMPLER_FLAG_UINT_BORDER_COLOR: true
568558
AllowInputAssemblerInputLayout: true
569559
DenyGeometryShaderRootAccess: true
@@ -577,11 +567,11 @@ TEST(RootSignature, ParseStaticSamplersV13) {
577567
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578568
0x52, 0x54, 0x53, 0x30, 0x4c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
579569
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,
570+
0x18, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00,
571+
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
572+
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
573+
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x7f,
574+
0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
585575
0x01, 0x00, 0x00, 0x00};
586576

587577
EXPECT_EQ(Storage.size(), 148U);

0 commit comments

Comments
 (0)