Skip to content

Commit 7ac9641

Browse files
author
joaosaffran
committed
addressing comments
1 parent 8b8c02a commit 7ac9641

File tree

4 files changed

+32
-53
lines changed

4 files changed

+32
-53
lines changed

llvm/include/llvm/Object/DXContainer.h

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ template <typename T> struct ViewArray {
120120
namespace DirectX {
121121
struct RootParameterView {
122122
const dxbc::RootParameterHeader &Header;
123-
uint32_t Version;
124123
StringRef ParamData;
125124
RootParameterView(uint32_t V, const dxbc::RootParameterHeader &H, StringRef P)
126-
: Header(H), Version(V), ParamData(P) {}
125+
: Header(H), ParamData(P) {}
127126

128-
template <typename T> Expected<T> readParameter() {
129-
T Struct;
130-
if (sizeof(T) != ParamData.size())
127+
template <typename T, typename VersionT = T> Expected<T> readParameter() {
128+
assert(sizeof(VersionT) <= sizeof(T) &&
129+
"Parameter of higher version must inherit all previous version data "
130+
"members");
131+
if (sizeof(VersionT) != ParamData.size())
131132
return make_error<GenericBinaryError>(
132133
"Reading structure out of file bounds", object_error::parse_failed);
133134

134-
memcpy(&Struct, ParamData.data(), sizeof(T));
135+
T Struct;
136+
memcpy(&Struct, ParamData.data(), sizeof(VersionT));
135137
// DXContainer is always little endian
136138
if (sys::IsBigEndianHost)
137139
Struct.swapBytes();
@@ -150,34 +152,20 @@ struct RootConstantView : RootParameterView {
150152
}
151153
};
152154

153-
struct RootDescriptorView_V1_0 : RootParameterView {
154-
static bool classof(const RootParameterView *V) {
155-
return (V->Version == 1 &&
156-
(V->Header.ParameterType ==
157-
llvm::to_underlying(dxbc::RootParameterType::CBV) ||
158-
V->Header.ParameterType ==
159-
llvm::to_underlying(dxbc::RootParameterType::SRV) ||
160-
V->Header.ParameterType ==
161-
llvm::to_underlying(dxbc::RootParameterType::UAV)));
162-
}
163-
164-
llvm::Expected<dxbc::RST0::v0::RootDescriptor> read() {
165-
return readParameter<dxbc::RST0::v0::RootDescriptor>();
166-
}
167-
};
168-
169-
struct RootDescriptorView_V1_1 : RootParameterView {
155+
struct RootDescriptorView : RootParameterView {
170156
static bool classof(const RootParameterView *V) {
171-
return (V->Version == 2 &&
172-
(V->Header.ParameterType ==
173-
llvm::to_underlying(dxbc::RootParameterType::CBV) ||
174-
V->Header.ParameterType ==
175-
llvm::to_underlying(dxbc::RootParameterType::SRV) ||
176-
V->Header.ParameterType ==
177-
llvm::to_underlying(dxbc::RootParameterType::UAV)));
157+
return (V->Header.ParameterType ==
158+
llvm::to_underlying(dxbc::RootParameterType::CBV) ||
159+
V->Header.ParameterType ==
160+
llvm::to_underlying(dxbc::RootParameterType::SRV) ||
161+
V->Header.ParameterType ==
162+
llvm::to_underlying(dxbc::RootParameterType::UAV));
178163
}
179164

180-
llvm::Expected<dxbc::RST0::v1::RootDescriptor> read() {
165+
llvm::Expected<dxbc::RST0::v1::RootDescriptor> read(uint32_t Version) {
166+
if (Version == 1)
167+
return readParameter<dxbc::RST0::v1::RootDescriptor,
168+
dxbc::RST0::v0::RootDescriptor>();
181169
return readParameter<dxbc::RST0::v1::RootDescriptor>();
182170
}
183171
};

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct RootConstantsYaml {
7979
uint32_t Num32BitValues;
8080
};
8181

82-
#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false;
8382
struct RootDescriptorYaml {
8483
RootDescriptorYaml() = default;
8584

@@ -88,14 +87,15 @@ struct RootDescriptorYaml {
8887

8988
uint32_t getEncodedFlags() const;
9089

90+
#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false;
9191
#include "llvm/BinaryFormat/DXContainerConstants.def"
9292
};
9393

9494
struct RootParameterYamlDesc {
9595
uint32_t Type;
9696
uint32_t Visibility;
9797
uint32_t Offset;
98-
RootParameterYamlDesc() {};
98+
RootParameterYamlDesc(){};
9999
RootParameterYamlDesc(uint32_t T) : Type(T) {
100100
switch (T) {
101101

@@ -116,7 +116,6 @@ struct RootParameterYamlDesc {
116116
};
117117
};
118118

119-
#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
120119
struct RootSignatureYamlDesc {
121120
RootSignatureYamlDesc() = default;
122121

@@ -137,6 +136,7 @@ struct RootSignatureYamlDesc {
137136
static llvm::Expected<DXContainerYAML::RootSignatureYamlDesc>
138137
create(const object::DirectX::RootSignature &Data);
139138

139+
#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
140140
#include "llvm/BinaryFormat/DXContainerConstants.def"
141141
};
142142

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/STLForwardCompat.h"
1616
#include "llvm/ADT/ScopeExit.h"
1717
#include "llvm/BinaryFormat/DXContainer.h"
18+
#include "llvm/Object/DXContainer.h"
1819
#include "llvm/Support/Error.h"
1920
#include "llvm/Support/ScopedPrinter.h"
2021
#include <cstdint>
@@ -78,20 +79,10 @@ DXContainerYAML::RootSignatureYamlDesc::create(
7879
NewP.Constants.Num32BitValues = Constants.Num32BitValues;
7980
NewP.Constants.ShaderRegister = Constants.ShaderRegister;
8081
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
81-
} else if (auto *RDV = dyn_cast<object::DirectX::RootDescriptorView_V1_0>(
82-
&ParamView)) {
83-
llvm::Expected<dxbc::RST0::v0::RootDescriptor> DescriptorOrErr =
84-
RDV->read();
85-
if (Error E = DescriptorOrErr.takeError())
86-
return std::move(E);
87-
auto Descriptor = *DescriptorOrErr;
88-
89-
NewP.Descriptor.ShaderRegister = Descriptor.ShaderRegister;
90-
NewP.Descriptor.RegisterSpace = Descriptor.RegisterSpace;
91-
} else if (auto *RDV = dyn_cast<object::DirectX::RootDescriptorView_V1_1>(
92-
&ParamView)) {
82+
} else if (auto *RDV =
83+
dyn_cast<object::DirectX::RootDescriptorView>(&ParamView)) {
9384
llvm::Expected<dxbc::RST0::v1::RootDescriptor> DescriptorOrErr =
94-
RDV->read();
85+
RDV->read(Data.getVersion());
9586
if (Error E = DescriptorOrErr.takeError())
9687
return std::move(E);
9788
auto Descriptor = *DescriptorOrErr;

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,10 @@ TEST(RootSignature, ParseRootDescriptor) {
994994
auto ParamView = RS.getParameter(RootParam);
995995
ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
996996

997-
DirectX::RootDescriptorView_V1_0 *RootDescriptorView =
998-
dyn_cast<DirectX::RootDescriptorView_V1_0>(&*ParamView);
997+
DirectX::RootDescriptorView *RootDescriptorView =
998+
dyn_cast<DirectX::RootDescriptorView>(&*ParamView);
999999
ASSERT_TRUE(RootDescriptorView != nullptr);
1000-
auto Descriptor = RootDescriptorView->read();
1000+
auto Descriptor = RootDescriptorView->read(RS.getVersion());
10011001

10021002
ASSERT_THAT_ERROR(Descriptor.takeError(), Succeeded());
10031003

@@ -1038,10 +1038,10 @@ TEST(RootSignature, ParseRootDescriptor) {
10381038
auto ParamView = RS.getParameter(RootParam);
10391039
ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
10401040

1041-
DirectX::RootDescriptorView_V1_1 *RootDescriptorView =
1042-
dyn_cast<DirectX::RootDescriptorView_V1_1>(&*ParamView);
1041+
DirectX::RootDescriptorView *RootDescriptorView =
1042+
dyn_cast<DirectX::RootDescriptorView>(&*ParamView);
10431043
ASSERT_TRUE(RootDescriptorView != nullptr);
1044-
auto Descriptor = RootDescriptorView->read();
1044+
auto Descriptor = RootDescriptorView->read(RS.getVersion());
10451045

10461046
ASSERT_THAT_ERROR(Descriptor.takeError(), Succeeded());
10471047

0 commit comments

Comments
 (0)