Skip to content

Commit 97fb003

Browse files
author
joaosaffran
committed
test pass locally
1 parent ac51bf6 commit 97fb003

File tree

4 files changed

+86
-52
lines changed

4 files changed

+86
-52
lines changed

llvm/include/llvm/Object/DXContainer.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/BinaryFormat/DXContainer.h"
2121
#include "llvm/Object/Error.h"
22+
#include "llvm/Support/Casting.h"
2223
#include "llvm/Support/Endian.h"
2324
#include "llvm/Support/Error.h"
2425
#include "llvm/Support/MemoryBufferRef.h"
@@ -38,6 +39,12 @@ template <typename T>
3839
std::enable_if_t<std::is_class<T>::value, void> swapBytes(T &value) {
3940
value.swapBytes();
4041
}
42+
43+
struct TypeIdGenerator {
44+
static inline size_t nextId = 0;
45+
46+
static size_t getNextId() { return nextId++; }
47+
};
4148
} // namespace detail
4249

4350
// This class provides a view into the underlying resource array. The Resource
@@ -120,8 +127,10 @@ namespace DirectX {
120127
struct RootParameterView {
121128
const dxbc::RootParameterHeader &Header;
122129
StringRef ParamData;
130+
uint32_t Version;
131+
123132
RootParameterView(uint32_t V, const dxbc::RootParameterHeader &H, StringRef P)
124-
: Header(H), ParamData(P) {}
133+
: Header(H), ParamData(P), Version(V) {}
125134

126135
template <typename T, typename VersionT = T> Expected<T> readParameter() {
127136
assert(sizeof(VersionT) <= sizeof(T) &&
@@ -169,22 +178,34 @@ struct RootDescriptorView : RootParameterView {
169178
}
170179
};
171180
template <typename T> struct DescriptorTable {
172-
uint32_t Version;
173181
uint32_t NumRanges;
174182
uint32_t RangesOffset;
175183
ViewArray<T> Ranges;
176184

177185
typename ViewArray<T>::iterator begin() const { return Ranges.begin(); }
178186

179-
typename ViewArray<T>::iterator end() const { return Ranges.end(); }
187+
typename ViewArray<T>::iterator end() const { return Ranges.end(); }
188+
};
189+
template <typename T> struct TemplateTypeToVersion {
190+
// Default version
191+
static constexpr uint32_t Value = -1;
192+
};
193+
194+
template <> struct TemplateTypeToVersion<dxbc::RST0::v0::DescriptorRange> {
195+
static constexpr uint32_t Value = 1;
196+
};
197+
198+
template <> struct TemplateTypeToVersion<dxbc::RST0::v1::DescriptorRange> {
199+
static constexpr uint32_t Value = 2;
180200
};
181201

182202
template <typename T> struct DescriptorTableView : RootParameterView {
183203
using TemplateType = T;
184204

185205
static bool classof(const RootParameterView *V) {
186206
return (V->Header.ParameterType ==
187-
llvm::to_underlying(dxbc::RootParameterType::DescriptorTable));
207+
llvm::to_underlying(dxbc::RootParameterType::DescriptorTable)) &&
208+
(V->Version == TemplateTypeToVersion<T>::Value);
188209
}
189210

190211
// Define a type alias to access the template parameter from inside classof

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,39 +170,40 @@ struct RootParameterYamlDesc {
170170
}
171171
}
172172

173-
RootParameterYamlDesc &operator=(const RootParameterYamlDesc &other) {
174-
if (this != &other) {
173+
RootParameterYamlDesc &operator=(const RootParameterYamlDesc &Other) {
174+
if (this != &Other) {
175175
// First, destroy the current union member
176176
this->~RootParameterYamlDesc();
177177

178178
// Copy the basic members
179-
Type = other.Type;
180-
Visibility = other.Visibility;
181-
Offset = other.Offset;
179+
Type = Other.Type;
180+
Visibility = Other.Visibility;
181+
Offset = Other.Offset;
182182

183183
// Initialize the new union member based on the Type from 'other'
184184
switch (Type) {
185185
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
186-
new (&Constants) RootConstantsYaml(other.Constants);
186+
new (&Constants) RootConstantsYaml(Other.Constants);
187187
break;
188188
case llvm::to_underlying(dxbc::RootParameterType::CBV):
189189
case llvm::to_underlying(dxbc::RootParameterType::SRV):
190190
case llvm::to_underlying(dxbc::RootParameterType::UAV):
191-
new (&Descriptor) RootDescriptorYaml(other.Descriptor);
191+
new (&Descriptor) RootDescriptorYaml(Other.Descriptor);
192192
break;
193193
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
194-
new (&Table) DescriptorTableYaml(other.Table);
194+
new (&Table) DescriptorTableYaml(Other.Table);
195195
break;
196196
}
197197
}
198198
return *this;
199199
}
200200

201+
// ToDo: Fix this (Already have a follow up PR with it)
201202
union {
202203
RootConstantsYaml Constants;
203204
RootDescriptorYaml Descriptor;
204-
DescriptorTableYaml Table;
205205
};
206+
DescriptorTableYaml Table;
206207
};
207208

208209
struct RootSignatureYamlDesc {

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ DXContainerYAML::RootSignatureYamlDesc::create(
9797
#include "llvm/BinaryFormat/DXContainerConstants.def"
9898
}
9999
} else if (auto *TDV = dyn_cast<object::DirectX::DescriptorTableView<
100-
dxbc::RST0::v0::DescriptorRange>>(&ParamView)) {
100+
dxbc::RST0::v1::DescriptorRange>>(&ParamView)) {
101101
llvm::Expected<
102-
object::DirectX::DescriptorTable<dxbc::RST0::v0::DescriptorRange>>
102+
object::DirectX::DescriptorTable<dxbc::RST0::v1::DescriptorRange>>
103103
TableOrErr = TDV->read();
104104
if (Error E = TableOrErr.takeError())
105105
return std::move(E);
@@ -116,13 +116,16 @@ DXContainerYAML::RootSignatureYamlDesc::create(
116116
NewR.BaseShaderRegister = R.BaseShaderRegister;
117117
NewR.RegisterSpace = R.RegisterSpace;
118118
NewR.RangeType = R.RangeType;
119-
119+
#define DESCRIPTOR_RANGE_FLAG(Num, Val) \
120+
NewR.Val = \
121+
(R.Flags & llvm::to_underlying(dxbc::DescriptorRangeFlag::Val)) > 0;
122+
#include "llvm/BinaryFormat/DXContainerConstants.def"
120123
NewP.Table.Ranges.push_back(NewR);
121124
}
122125
} else if (auto *TDV = dyn_cast<object::DirectX::DescriptorTableView<
123-
dxbc::RST0::v1::DescriptorRange>>(&ParamView)) {
126+
dxbc::RST0::v0::DescriptorRange>>(&ParamView)) {
124127
llvm::Expected<
125-
object::DirectX::DescriptorTable<dxbc::RST0::v1::DescriptorRange>>
128+
object::DirectX::DescriptorTable<dxbc::RST0::v0::DescriptorRange>>
126129
TableOrErr = TDV->read();
127130
if (Error E = TableOrErr.takeError())
128131
return std::move(E);
@@ -139,10 +142,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
139142
NewR.BaseShaderRegister = R.BaseShaderRegister;
140143
NewR.RegisterSpace = R.RegisterSpace;
141144
NewR.RangeType = R.RangeType;
142-
#define DESCRIPTOR_RANGE_FLAG(Num, Val) \
143-
NewR.Val = \
144-
(R.Flags & llvm::to_underlying(dxbc::DescriptorRangeFlag::Val)) > 0;
145-
#include "llvm/BinaryFormat/DXContainerConstants.def"
145+
146146
NewP.Table.Ranges.push_back(NewR);
147147
}
148148
}

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

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Header:
1111
PartOffsets: [ 60 ]
1212
Parts:
1313
- Name: RTS0
14-
Size: 96
14+
Size: 200
1515
RootSignature:
1616
Version: 2
1717
NumRootParameters: 3
@@ -51,32 +51,44 @@ Parts:
5151
AllowInputAssemblerInputLayout: true
5252
DenyGeometryShaderRootAccess: true
5353

54-
# CHECK: - Name: RTS0
55-
# CHECK-NEXT: Size: 96
56-
# CHECK-NEXT: RootSignature:
57-
# CHECK-NEXT: Version: 2
58-
# CHECK-NEXT: NumRootParameters: 3
59-
# CHECK-NEXT: RootParametersOffset: 24
60-
# CHECK-NEXT: NumStaticSamplers: 0
61-
# CHECK-NEXT: StaticSamplersOffset: 60
62-
# CHECK-NEXT: Parameters:
63-
# CHECK-NEXT: - ParameterType: 1
64-
# CHECK-NEXT: ShaderVisibility: 2
65-
# CHECK-NEXT: Constants:
66-
# CHECK-NEXT: Num32BitValues: 16
67-
# CHECK-NEXT: RegisterSpace: 14
68-
# CHECK-NEXT: ShaderRegister: 15
69-
# CHECK-NEXT: - ParameterType: 1
70-
# CHECK-NEXT: ShaderVisibility: 4
71-
# CHECK-NEXT: Constants:
72-
# CHECK-NEXT: Num32BitValues: 21
73-
# CHECK-NEXT: RegisterSpace: 23
74-
# CHECK-NEXT: ShaderRegister: 22
75-
# CHECK-NEXT: - ParameterType: 2
76-
# CHECK-NEXT: ShaderVisibility: 3
77-
# CHECK-NEXT: Descriptor:
78-
# CHECK-NEXT: RegisterSpace: 32
79-
# CHECK-NEXT: ShaderRegister: 31
80-
# CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
81-
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
82-
# CHECK-NEXT: DenyGeometryShaderRootAccess: true
54+
#CHECK: - Name: RTS0
55+
#CHECK-NEXT: Size: 200
56+
#CHECK-NEXT: RootSignature:
57+
#CHECK-NEXT: Version: 2
58+
#CHECK-NEXT: NumRootParameters: 4
59+
#CHECK-NEXT: RootParametersOffset: 24
60+
#CHECK-NEXT: NumStaticSamplers: 0
61+
#CHECK-NEXT: StaticSamplersOffset: 60
62+
#CHECK-NEXT: Parameters:
63+
#CHECK-NEXT: - ParameterType: 1
64+
#CHECK-NEXT: ShaderVisibility: 2
65+
#CHECK-NEXT: Constants:
66+
#CHECK-NEXT: Num32BitValues: 16
67+
#CHECK-NEXT: RegisterSpace: 14
68+
#CHECK-NEXT: ShaderRegister: 15
69+
#CHECK-NEXT: - ParameterType: 1
70+
#CHECK-NEXT: ShaderVisibility: 4
71+
#CHECK-NEXT: Constants:
72+
#CHECK-NEXT: Num32BitValues: 21
73+
#CHECK-NEXT: RegisterSpace: 23
74+
#CHECK-NEXT: ShaderRegister: 22
75+
#CHECK-NEXT: - ParameterType: 2
76+
#CHECK-NEXT: ShaderVisibility: 3
77+
#CHECK-NEXT: Descriptor:
78+
#CHECK-NEXT: RegisterSpace: 32
79+
#CHECK-NEXT: ShaderRegister: 31
80+
#CHECK-NEXT: DATA_STATIC_WHILE_SET_AT_EXECUTE: true
81+
#CHECK-NEXT: - ParameterType: 0
82+
#CHECK-NEXT: ShaderVisibility: 3
83+
#CHECK-NEXT: Table:
84+
#CHECK-NEXT: NumRanges: 1
85+
#CHECK-NEXT: RangesOffset: 116
86+
#CHECK-NEXT: Ranges:
87+
#CHECK-NEXT: - RangeType: 0
88+
#CHECK-NEXT: NumDescriptors: 41
89+
#CHECK-NEXT: BaseShaderRegister: 42
90+
#CHECK-NEXT: RegisterSpace: 43
91+
#CHECK-NEXT: OffsetInDescriptorsFromTableStart: -1
92+
#CHECK-NEXT: DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS: true
93+
#CHECK-NEXT: AllowInputAssemblerInputLayout: true
94+
#CHECK-NEXT: DenyGeometryShaderRootAccess: true

0 commit comments

Comments
 (0)