Skip to content

Commit c0ac522

Browse files
author
joaosaffran
committed
adding tests and changing parameter type
1 parent 6986945 commit c0ac522

File tree

11 files changed

+104
-77
lines changed

11 files changed

+104
-77
lines changed

llvm/include/llvm/Object/DXContainer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,13 @@ class RootSignature {
167167
public:
168168
RootSignature(StringRef PD) : PartData(PD) {}
169169

170-
Error parse(StringRef Data);
170+
Error parse();
171171
uint32_t getVersion() const { return Version; }
172172
uint32_t getNumParameters() const { return NumParameters; }
173173
uint32_t getRootParametersOffset() const { return RootParametersOffset; }
174174
uint32_t getNumStaticSamplers() const { return NumStaticSamplers; }
175175
uint32_t getStaticSamplersOffset() const { return StaticSamplersOffset; }
176+
uint32_t getNumRootParameters() const { return ParametersHeaders.size(); }
176177
llvm::iterator_range<param_header_iterator> param_headers() const {
177178
return llvm::make_range(ParametersHeaders.begin(), ParametersHeaders.end());
178179
}

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ struct RootConstantsYaml {
8282
};
8383

8484
struct RootParameterYamlDesc {
85-
dxbc::RootParameterType Type;
86-
dxbc::ShaderVisibility Visibility;
85+
uint32_t Type;
86+
uint32_t Visibility;
8787
uint32_t Offset;
8888

8989
union {
@@ -95,6 +95,8 @@ struct RootSignatureYamlDesc {
9595
RootSignatureYamlDesc() = default;
9696

9797
uint32_t Version;
98+
uint32_t NumRootParameters;
99+
uint32_t RootParametersOffset;
98100
uint32_t NumStaticSamplers;
99101
uint32_t StaticSamplersOffset;
100102

@@ -224,8 +226,6 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ResourceKind)
224226
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::D3DSystemValue)
225227
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigComponentType)
226228
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigMinPrecision)
227-
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::RootParameterType)
228-
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::ShaderVisibility)
229229

230230
namespace llvm {
231231

llvm/lib/Object/DXContainer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Error DXContainer::parseRootSignature(StringRef Part) {
9797
if (RootSignature)
9898
return parseFailed("More than one RTS0 part is present in the file");
9999
RootSignature = DirectX::RootSignature(Part);
100-
if (Error Err = RootSignature->parse(Part))
100+
if (Error Err = RootSignature->parse())
101101
return Err;
102102
return Error::success();
103103
}
@@ -242,12 +242,11 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
242242
IteratorState.Offset = Offset;
243243
}
244244

245-
Error DirectX::RootSignature::parse(StringRef Data) {
246-
const char *Begin = Data.begin();
247-
const char *Current = Data.begin();
245+
Error DirectX::RootSignature::parse() {
246+
const char *Current = PartData.begin();
248247

249248
// Root Signature headers expects 6 integers to be present.
250-
if (Data.size() < 6 * sizeof(uint32_t))
249+
if (PartData.size() < 6 * sizeof(uint32_t))
251250
return parseFailed(
252251
"Invalid root signature, insufficient space for header.");
253252

@@ -273,9 +272,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
273272
Flags = support::endian::read<uint32_t, llvm::endianness::little>(Current);
274273
Current += sizeof(uint32_t);
275274

276-
assert(Current == Begin + RootParametersOffset);
275+
assert(Current == PartData.begin() + RootParametersOffset);
277276

278-
ParametersHeaders.Data = Data.substr(
277+
ParametersHeaders.Data = PartData.substr(
279278
RootParametersOffset, NumParameters * sizeof(dxbc::RootParameterHeader));
280279

281280
return Error::success();

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ DXContainerYAML::RootSignatureYamlDesc::create(
4040
RootSigDesc.Version = Data.getVersion();
4141
RootSigDesc.NumStaticSamplers = Data.getNumStaticSamplers();
4242
RootSigDesc.StaticSamplersOffset = Data.getStaticSamplersOffset();
43+
RootSigDesc.NumRootParameters = Data.getNumRootParameters();
44+
RootSigDesc.RootParametersOffset = Data.getRootParametersOffset();
4345

4446
uint32_t Flags = Data.getFlags();
4547
for (const auto &PH : Data.param_headers()) {
@@ -51,13 +53,13 @@ DXContainerYAML::RootSignatureYamlDesc::create(
5153
return createStringError(std::errc::invalid_argument,
5254
"Invalid value for parameter type");
5355

54-
NewP.Type = (dxbc::RootParameterType)PH.ParameterType;
56+
NewP.Type = PH.ParameterType;
5557

5658
if (!dxbc::isValidShaderVisibility(PH.ShaderVisibility))
5759
return createStringError(std::errc::invalid_argument,
5860
"Invalid value for shader visibility");
5961

60-
NewP.Visibility = (dxbc::ShaderVisibility)PH.ShaderVisibility;
62+
NewP.Visibility = PH.ShaderVisibility;
6163

6264
llvm::Expected<object::DirectX::RootParameterView> ParamViewOrErr =
6365
Data.getParameter(PH);
@@ -257,6 +259,8 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
257259
void MappingTraits<DXContainerYAML::RootSignatureYamlDesc>::mapping(
258260
IO &IO, DXContainerYAML::RootSignatureYamlDesc &S) {
259261
IO.mapRequired("Version", S.Version);
262+
IO.mapRequired("NumRootParameters", S.NumRootParameters);
263+
IO.mapRequired("RootParametersOffset", S.RootParametersOffset);
260264
IO.mapRequired("NumStaticSamplers", S.NumStaticSamplers);
261265
IO.mapRequired("StaticSamplersOffset", S.StaticSamplersOffset);
262266
IO.mapRequired("Parameters", S.Parameters);
@@ -385,18 +389,6 @@ void ScalarEnumerationTraits<dxbc::SigComponentType>::enumeration(
385389
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
386390
}
387391

388-
void ScalarEnumerationTraits<dxbc::RootParameterType>::enumeration(
389-
IO &IO, dxbc::RootParameterType &Value) {
390-
for (const auto &E : dxbc::getRootParameterTypes())
391-
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
392-
}
393-
394-
void ScalarEnumerationTraits<dxbc::ShaderVisibility>::enumeration(
395-
IO &IO, dxbc::ShaderVisibility &Value) {
396-
for (const auto &E : dxbc::getShaderVisibility())
397-
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
398-
}
399-
400392
} // namespace yaml
401393

402394
void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) {

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
2222
; DXC-NEXT: Size: 24
2323
; DXC-NEXT: RootSignature:
2424
; DXC-NEXT: Version: 2
25+
; DXC-NEXT: NumRootParameters: 0
26+
; DXC-NEXT: RootParametersOffset: 24
2527
; DXC-NEXT: NumStaticSamplers: 0
2628
; DXC-NEXT: StaticSamplersOffset: 0
2729
; DXC-NEXT: Parameters: []

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Parts:
1414
Size: 24
1515
RootSignature:
1616
Version: 2
17+
NumRootParameters: 0
18+
RootParametersOffset: 24
1719
NumStaticSamplers: 4
1820
StaticSamplersOffset: 5
1921
Parameters: []
@@ -24,6 +26,8 @@ Parts:
2426
# CHECK-NEXT: Size: 24
2527
# CHECK-NEXT: RootSignature:
2628
# CHECK-NEXT: Version: 2
29+
# CHECK-NEXT: NumRootParameters: 0
30+
# CHECK-NEXT: RootParametersOffset: 24
2731
# CHECK-NEXT: NumStaticSamplers: 0
2832
# CHECK-NEXT: StaticSamplersOffset: 0
2933
# CHECK-NEXT: Parameters: []
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: not obj2yaml 2>&1 %t | FileCheck %s -DFILE=%t
3+
4+
# CHECK: Error reading file: [[FILE]]: Invalid value for parameter type
5+
6+
7+
--- !dxcontainer
8+
Header:
9+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
10+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
11+
Version:
12+
Major: 1
13+
Minor: 0
14+
PartCount: 1
15+
PartOffsets: [ 60 ]
16+
Parts:
17+
- Name: RTS0
18+
Size: 80
19+
RootSignature:
20+
Version: 2
21+
NumRootParameters: 2
22+
RootParametersOffset: 24
23+
NumStaticSamplers: 0
24+
StaticSamplersOffset: 64
25+
Parameters:
26+
- ParameterType: 255 # INVALID
27+
ShaderVisibility: 2 # Hull
28+
AllowInputAssemblerInputLayout: true
29+
DenyGeometryShaderRootAccess: true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: not obj2yaml 2>&1 %t | FileCheck %s -DFILE=%t
3+
4+
# CHECK: Error reading file: [[FILE]]: Invalid value for shader visibility
5+
6+
7+
--- !dxcontainer
8+
Header:
9+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
10+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
11+
Version:
12+
Major: 1
13+
Minor: 0
14+
PartCount: 1
15+
PartOffsets: [ 60 ]
16+
Parts:
17+
- Name: RTS0
18+
Size: 80
19+
RootSignature:
20+
Version: 2
21+
NumRootParameters: 2
22+
RootParametersOffset: 24
23+
NumStaticSamplers: 0
24+
StaticSamplersOffset: 64
25+
Parameters:
26+
- ParameterType: 1 # Constants32Bit
27+
ShaderVisibility: 255 # INVALID
28+
Constants:
29+
Num32BitValues: 21
30+
ShaderRegister: 22
31+
RegisterSpace: 23
32+
AllowInputAssemblerInputLayout: true
33+
DenyGeometryShaderRootAccess: true

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ Parts:
1414
Size: 80
1515
RootSignature:
1616
Version: 2
17+
NumRootParameters: 2
18+
RootParametersOffset: 24
1719
NumStaticSamplers: 0
1820
StaticSamplersOffset: 64
1921
Parameters:
20-
- ParameterType: Constants32Bit
21-
ShaderVisibility: Hull
22+
- ParameterType: 1 # Constants32Bit
23+
ShaderVisibility: 2 # Hull
2224
Constants:
2325
Num32BitValues: 16
2426
ShaderRegister: 15
2527
RegisterSpace: 14
26-
- ParameterType: Constants32Bit
27-
ShaderVisibility: Geometry
28+
- ParameterType: 1 # Constants32Bit
29+
ShaderVisibility: 4 # Geometry
2830
Constants:
2931
Num32BitValues: 21
3032
ShaderRegister: 22
@@ -36,17 +38,19 @@ Parts:
3638
# CHECK-NEXT: Size: 80
3739
# CHECK-NEXT: RootSignature:
3840
# CHECK-NEXT: Version: 2
41+
# CHECK-NEXT: NumRootParameters: 2
42+
# CHECK-NEXT: RootParametersOffset: 24
3943
# CHECK-NEXT: NumStaticSamplers: 0
4044
# CHECK-NEXT: StaticSamplersOffset: 0
4145
# CHECK-NEXT: Parameters:
42-
# CHECK-NEXT: - ParameterType: Constants32Bit
43-
# CHECK-NEXT: ShaderVisibility: Hull
46+
# CHECK-NEXT: - ParameterType: 1
47+
# CHECK-NEXT: ShaderVisibility: 2
4448
# CHECK-NEXT: Constants:
4549
# CHECK-NEXT: Num32BitValues: 16
4650
# CHECK-NEXT: RegisterSpace: 14
4751
# CHECK-NEXT: ShaderRegister: 15
48-
# CHECK-NEXT: - ParameterType: Constants32Bit
49-
# CHECK-NEXT: ShaderVisibility: Geometry
52+
# CHECK-NEXT: - ParameterType: 1
53+
# CHECK-NEXT: ShaderVisibility: 4
5054
# CHECK-NEXT: Constants:
5155
# CHECK-NEXT: Num32BitValues: 21
5256
# CHECK-NEXT: RegisterSpace: 23

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Object/DXContainer.h"
10-
#include "../../tools/obj2yaml/dxcontainer2yaml.cpp"
1110
#include "llvm/ADT/StringRef.h"
1211
#include "llvm/BinaryFormat/Magic.h"
1312
#include "llvm/ObjectYAML/DXContainerYAML.h"
@@ -908,44 +907,4 @@ TEST(RootSignature, ParseRootConstant) {
908907
ASSERT_EQ(Constants->RegisterSpace, 14u);
909908
ASSERT_EQ(Constants->Num32BitValues, 16u);
910909
}
911-
{
912-
uint8_t Buffer[] = {
913-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
914-
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
915-
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
916-
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
917-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
918-
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
919-
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
920-
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
921-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
922-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
924-
0x00};
925-
926-
SmallString<256> Storage;
927-
raw_svector_ostream OS(Storage);
928-
EXPECT_THAT_ERROR(dxcontainer2yaml(OS, getMemoryBuffer<133>(Buffer)),
929-
FailedWithMessage("Invalid value for parameter type"));
930-
}
931-
{
932-
uint8_t Buffer[] = {
933-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
934-
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
935-
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
936-
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
937-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
938-
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
939-
0xFF, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
940-
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
941-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
942-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
943-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
944-
0x00};
945-
946-
SmallString<256> Storage;
947-
raw_svector_ostream OS(Storage);
948-
EXPECT_THAT_ERROR(dxcontainer2yaml(OS, getMemoryBuffer<133>(Buffer)),
949-
FailedWithMessage("Invalid value for shader visibility"));
950-
}
951910
}

0 commit comments

Comments
 (0)