Skip to content

Commit 13d7045

Browse files
author
joaosaffran
committed
adding test
1 parent 3ce683e commit 13d7045

File tree

7 files changed

+296
-9
lines changed

7 files changed

+296
-9
lines changed

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
7777
#ifdef ROOT_DESCRIPTOR_FLAG
7878

7979
ROOT_DESCRIPTOR_FLAG(0, NONE)
80-
ROOT_DESCRIPTOR_FLAG(2, DATA_VOLATILE)
81-
ROOT_DESCRIPTOR_FLAG(4, DATA_STATIC_WHILE_SET_AT_EXECUTE)
82-
ROOT_DESCRIPTOR_FLAG(8, DATA_STATIC)
80+
ROOT_DESCRIPTOR_FLAG(1, DATA_VOLATILE)
81+
ROOT_DESCRIPTOR_FLAG(2, DATA_STATIC_WHILE_SET_AT_EXECUTE)
82+
ROOT_DESCRIPTOR_FLAG(3, DATA_STATIC)
8383
#undef ROOT_DESCRIPTOR_FLAG
8484
#endif // ROOT_DESCRIPTOR_FLAG
8585

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
9494
case llvm::to_underlying(dxbc::RootParameterType::SRV):
9595
case llvm::to_underlying(dxbc::RootParameterType::UAV):
9696
if (Version == 1) {
97-
support::endian::write(BOS, P.Descriptor_V10.RegisterSpace,
98-
llvm::endianness::little);
9997
support::endian::write(BOS, P.Descriptor_V10.ShaderRegister,
10098
llvm::endianness::little);
101-
} else {
102-
support::endian::write(BOS, P.Descriptor_V11.RegisterSpace,
99+
support::endian::write(BOS, P.Descriptor_V10.RegisterSpace,
103100
llvm::endianness::little);
101+
} else {
104102
support::endian::write(BOS, P.Descriptor_V11.ShaderRegister,
105103
llvm::endianness::little);
104+
support::endian::write(BOS, P.Descriptor_V11.RegisterSpace,
105+
llvm::endianness::little);
106106
support::endian::write(BOS, P.Descriptor_V11.Flags,
107107
llvm::endianness::little);
108108
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
2+
3+
--- !dxcontainer
4+
Header:
5+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
6+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
7+
Version:
8+
Major: 1
9+
Minor: 0
10+
PartCount: 1
11+
PartOffsets: [ 60 ]
12+
Parts:
13+
- Name: RTS0
14+
Size: 96
15+
RootSignature:
16+
Version: 1
17+
NumRootParameters: 1
18+
RootParametersOffset: 24
19+
NumStaticSamplers: 0
20+
StaticSamplersOffset: 60
21+
Parameters:
22+
- ParameterType: 2 # SRV
23+
ShaderVisibility: 3 # Domain
24+
Descriptor:
25+
ShaderRegister: 31
26+
RegisterSpace: 32
27+
DATA_STATIC_WHILE_SET_AT_EXECUTE: true
28+
AllowInputAssemblerInputLayout: true
29+
DenyGeometryShaderRootAccess: true
30+
31+
# CHECK: - Name: RTS0
32+
# CHECK-NEXT: Size: 96
33+
# CHECK-NEXT: RootSignature:
34+
# CHECK-NEXT: Version: 1
35+
# CHECK-NEXT: NumRootParameters: 1
36+
# CHECK-NEXT: RootParametersOffset: 24
37+
# CHECK-NEXT: NumStaticSamplers: 0
38+
# CHECK-NEXT: StaticSamplersOffset: 60
39+
# CHECK-NEXT: Parameters:
40+
# CHECK-NEXT: - ParameterType: 2
41+
# CHECK-NEXT: ShaderVisibility: 3
42+
# CHECK-NEXT: Descriptor:
43+
# CHECK-NEXT: RegisterSpace: 32
44+
# CHECK-NEXT: ShaderRegister: 31
45+
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
46+
# CHECK-NEXT: DenyGeometryShaderRootAccess: true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
2+
3+
--- !dxcontainer
4+
Header:
5+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
6+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
7+
Version:
8+
Major: 1
9+
Minor: 0
10+
PartCount: 1
11+
PartOffsets: [ 60 ]
12+
Parts:
13+
- Name: RTS0
14+
Size: 89
15+
RootSignature:
16+
Version: 2
17+
NumRootParameters: 1
18+
RootParametersOffset: 24
19+
NumStaticSamplers: 0
20+
StaticSamplersOffset: 60
21+
Parameters:
22+
- ParameterType: 2 # SRV
23+
ShaderVisibility: 3 # Domain
24+
Descriptor:
25+
ShaderRegister: 31
26+
RegisterSpace: 32
27+
DATA_STATIC_WHILE_SET_AT_EXECUTE: true
28+
AllowInputAssemblerInputLayout: true
29+
DenyGeometryShaderRootAccess: true
30+
31+
# CHECK: - Name: RTS0
32+
# CHECK-NEXT: Size: 89
33+
# CHECK-NEXT: RootSignature:
34+
# CHECK-NEXT: Version: 2
35+
# CHECK-NEXT: NumRootParameters: 1
36+
# CHECK-NEXT: RootParametersOffset: 24
37+
# CHECK-NEXT: NumStaticSamplers: 0
38+
# CHECK-NEXT: StaticSamplersOffset: 60
39+
# CHECK-NEXT: Parameters:
40+
# CHECK-NEXT: - ParameterType: 2
41+
# CHECK-NEXT: ShaderVisibility: 3
42+
# CHECK-NEXT: Descriptor:
43+
# CHECK-NEXT: RegisterSpace: 32
44+
# CHECK-NEXT: ShaderRegister: 31
45+
# CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
46+
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
47+
# CHECK-NEXT: DenyGeometryShaderRootAccess: true

llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ Parts:
6464
# CHECK-NEXT: - ParameterType: 2
6565
# CHECK-NEXT: ShaderVisibility: 3
6666
# CHECK-NEXT: Descriptor:
67-
# CHECK-NEXT: RegisterSpace: 31
68-
# CHECK-NEXT: ShaderRegister: 32
67+
# CHECK-NEXT: RegisterSpace: 32
68+
# CHECK-NEXT: ShaderRegister: 31
6969
# CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
7070
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
7171
# CHECK-NEXT: DenyGeometryShaderRootAccess: true

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,3 +959,94 @@ TEST(RootSignature, ParseRootConstant) {
959959
ASSERT_EQ(Constants->Num32BitValues, 16u);
960960
}
961961
}
962+
963+
TEST(RootSignature, ParseRootDescriptor) {
964+
{
965+
uint8_t Buffer[] = {
966+
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
967+
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
968+
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
969+
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
970+
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
971+
0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
972+
0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
973+
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
974+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
975+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
976+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
977+
0x00};
978+
DXContainer C =
979+
llvm::cantFail(DXContainer::create(getMemoryBuffer<133>(Buffer)));
980+
981+
auto MaybeRS = C.getRootSignature();
982+
ASSERT_TRUE(MaybeRS.has_value());
983+
const auto &RS = MaybeRS.value();
984+
ASSERT_EQ(RS.getVersion(), 1u);
985+
ASSERT_EQ(RS.getNumParameters(), 1u);
986+
ASSERT_EQ(RS.getRootParametersOffset(), 24u);
987+
ASSERT_EQ(RS.getNumStaticSamplers(), 0u);
988+
ASSERT_EQ(RS.getStaticSamplersOffset(), 60u);
989+
ASSERT_EQ(RS.getFlags(), 17u);
990+
991+
auto RootParam = *RS.param_headers().begin();
992+
ASSERT_EQ((unsigned)RootParam.ParameterType, 2u);
993+
ASSERT_EQ((unsigned)RootParam.ShaderVisibility, 3u);
994+
auto ParamView = RS.getParameter(RootParam);
995+
ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
996+
997+
DirectX::RootDescriptorView_V1_0 *RootDescriptorView =
998+
dyn_cast<DirectX::RootDescriptorView_V1_0>(&*ParamView);
999+
ASSERT_TRUE(RootDescriptorView != nullptr);
1000+
auto Descriptor = RootDescriptorView->read();
1001+
1002+
ASSERT_THAT_ERROR(Descriptor.takeError(), Succeeded());
1003+
1004+
ASSERT_EQ(Descriptor->ShaderRegister, 31u);
1005+
ASSERT_EQ(Descriptor->RegisterSpace, 32u);
1006+
}
1007+
1008+
{
1009+
uint8_t Buffer[] = {
1010+
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
1011+
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
1012+
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
1013+
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
1014+
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1015+
0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
1016+
0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
1017+
0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1018+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1019+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1020+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1021+
0x00};
1022+
DXContainer C =
1023+
llvm::cantFail(DXContainer::create(getMemoryBuffer<133>(Buffer)));
1024+
1025+
auto MaybeRS = C.getRootSignature();
1026+
ASSERT_TRUE(MaybeRS.has_value());
1027+
const auto &RS = MaybeRS.value();
1028+
ASSERT_EQ(RS.getVersion(), 2u);
1029+
ASSERT_EQ(RS.getNumParameters(), 1u);
1030+
ASSERT_EQ(RS.getRootParametersOffset(), 24u);
1031+
ASSERT_EQ(RS.getNumStaticSamplers(), 0u);
1032+
ASSERT_EQ(RS.getStaticSamplersOffset(), 60u);
1033+
ASSERT_EQ(RS.getFlags(), 17u);
1034+
1035+
auto RootParam = *RS.param_headers().begin();
1036+
ASSERT_EQ((unsigned)RootParam.ParameterType, 2u);
1037+
ASSERT_EQ((unsigned)RootParam.ShaderVisibility, 3u);
1038+
auto ParamView = RS.getParameter(RootParam);
1039+
ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
1040+
1041+
DirectX::RootDescriptorView_V1_1 *RootDescriptorView =
1042+
dyn_cast<DirectX::RootDescriptorView_V1_1>(&*ParamView);
1043+
ASSERT_TRUE(RootDescriptorView != nullptr);
1044+
auto Descriptor = RootDescriptorView->read();
1045+
1046+
ASSERT_THAT_ERROR(Descriptor.takeError(), Succeeded());
1047+
1048+
ASSERT_EQ(Descriptor->ShaderRegister, 31u);
1049+
ASSERT_EQ(Descriptor->RegisterSpace, 32u);
1050+
ASSERT_EQ(Descriptor->Flags, 4u);
1051+
}
1052+
}

llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,106 @@ TEST(RootSignature, ParseRootConstants) {
251251
EXPECT_EQ(Storage.size(), 133u);
252252
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 133u) == 0);
253253
}
254+
255+
TEST(RootSignature, ParseRootDescriptorsV10) {
256+
SmallString<128> Storage;
257+
258+
// First read a fully explicit yaml with all sizes and offsets provided
259+
ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
260+
Header:
261+
Hash: [ 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F, 0x5,
262+
0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1 ]
263+
Version:
264+
Major: 1
265+
Minor: 0
266+
FileSize: 133
267+
PartCount: 1
268+
PartOffsets: [ 36 ]
269+
Parts:
270+
- Name: RTS0
271+
Size: 89
272+
RootSignature:
273+
Version: 1
274+
NumRootParameters: 1
275+
RootParametersOffset: 24
276+
NumStaticSamplers: 0
277+
StaticSamplersOffset: 60
278+
Parameters:
279+
- ParameterType: 2 # SRV
280+
ShaderVisibility: 3 # Domain
281+
Descriptor:
282+
ShaderRegister: 31
283+
RegisterSpace: 32
284+
AllowInputAssemblerInputLayout: true
285+
DenyGeometryShaderRootAccess: true
286+
)"));
287+
288+
uint8_t Buffer[] = {
289+
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
290+
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
291+
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
292+
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
293+
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294+
0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
295+
0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
296+
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300+
0x00};
301+
302+
EXPECT_EQ(Storage.size(), 133u);
303+
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 133u) == 0);
304+
}
305+
306+
TEST(RootSignature, ParseRootDescriptorsV11) {
307+
SmallString<128> Storage;
308+
309+
// First read a fully explicit yaml with all sizes and offsets provided
310+
ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
311+
Header:
312+
Hash: [ 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F, 0x5,
313+
0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1 ]
314+
Version:
315+
Major: 1
316+
Minor: 0
317+
FileSize: 133
318+
PartCount: 1
319+
PartOffsets: [ 36 ]
320+
Parts:
321+
- Name: RTS0
322+
Size: 89
323+
RootSignature:
324+
Version: 2
325+
NumRootParameters: 1
326+
RootParametersOffset: 24
327+
NumStaticSamplers: 0
328+
StaticSamplersOffset: 60
329+
Parameters:
330+
- ParameterType: 2 # SRV
331+
ShaderVisibility: 3 # Domain
332+
Descriptor:
333+
ShaderRegister: 31
334+
RegisterSpace: 32
335+
DATA_STATIC_WHILE_SET_AT_EXECUTE: true
336+
AllowInputAssemblerInputLayout: true
337+
DenyGeometryShaderRootAccess: true
338+
)"));
339+
340+
uint8_t Buffer[] = {
341+
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
342+
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
343+
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
344+
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
345+
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
346+
0x3c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
347+
0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
348+
0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
349+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
351+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352+
0x00};
353+
354+
EXPECT_EQ(Storage.size(), 133u);
355+
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 133u) == 0);
356+
}

0 commit comments

Comments
 (0)