Skip to content

Commit 1b3e10a

Browse files
author
joaosaffran
committed
addressing comments
1 parent 15eb6f5 commit 1b3e10a

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ struct ProgramSignatureElement {
585585

586586
static_assert(sizeof(ProgramSignatureElement) == 32,
587587
"ProgramSignatureElement is misaligned");
588-
namespace RST0 {
589-
namespace v0 {
588+
namespace RTS0 {
589+
namespace v1 {
590590
struct RootDescriptor {
591591
uint32_t ShaderRegister;
592592
uint32_t RegisterSpace;
@@ -595,18 +595,23 @@ struct RootDescriptor {
595595
sys::swapByteOrder(RegisterSpace);
596596
}
597597
};
598-
} // namespace v0
598+
} // namespace v1
599599

600-
namespace v1 {
601-
struct RootDescriptor : public v0::RootDescriptor {
600+
namespace v2 {
601+
struct RootDescriptor : public v1::RootDescriptor {
602602
uint32_t Flags;
603+
604+
RootDescriptor() = default;
605+
RootDescriptor(v1::RootDescriptor &Base)
606+
: v1::RootDescriptor(Base), Flags(0u) {}
607+
603608
void swapBytes() {
604-
v0::RootDescriptor::swapBytes();
609+
v1::RootDescriptor::swapBytes();
605610
sys::swapByteOrder(Flags);
606611
}
607612
};
608-
} // namespace v1
609-
} // namespace RST0
613+
} // namespace v2
614+
} // namespace RTS0
610615
// following dx12 naming
611616
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
612617
struct RootConstants {

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct RootParameter {
1919
dxbc::RootParameterHeader Header;
2020
union {
2121
dxbc::RootConstants Constants;
22-
dxbc::RST0::v1::RootDescriptor Descriptor;
22+
dxbc::RTS0::v2::RootDescriptor Descriptor;
2323
};
2424
};
2525
struct RootSignatureDesc {

llvm/include/llvm/Object/DXContainer.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/ADT/SmallVector.h"
1919
#include "llvm/ADT/StringRef.h"
20+
#include "llvm/ADT/Twine.h"
2021
#include "llvm/BinaryFormat/DXContainer.h"
2122
#include "llvm/Object/Error.h"
2223
#include "llvm/Support/Error.h"
@@ -124,16 +125,13 @@ struct RootParameterView {
124125
RootParameterView(uint32_t V, const dxbc::RootParameterHeader &H, StringRef P)
125126
: Header(H), ParamData(P) {}
126127

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())
128+
template <typename T> Expected<T> readParameter() {
129+
if (sizeof(T) != ParamData.size())
132130
return make_error<GenericBinaryError>(
133131
"Reading structure out of file bounds", object_error::parse_failed);
134132

135133
T Struct;
136-
memcpy(&Struct, ParamData.data(), sizeof(VersionT));
134+
memcpy(&Struct, ParamData.data(), sizeof(T));
137135
// DXContainer is always little endian
138136
if (sys::IsBigEndianHost)
139137
Struct.swapBytes();
@@ -162,11 +160,18 @@ struct RootDescriptorView : RootParameterView {
162160
llvm::to_underlying(dxbc::RootParameterType::UAV));
163161
}
164162

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>();
169-
return readParameter<dxbc::RST0::v1::RootDescriptor>();
163+
llvm::Expected<dxbc::RTS0::v2::RootDescriptor> read(uint32_t Version) {
164+
if (Version == 1) {
165+
auto Descriptor = readParameter<dxbc::RTS0::v1::RootDescriptor>();
166+
if (Error E = Descriptor.takeError())
167+
return E;
168+
return dxbc::RTS0::v2::RootDescriptor(*Descriptor);
169+
}
170+
if (Version != 2)
171+
return make_error<GenericBinaryError>("Invalid Root Signature version: " +
172+
Twine(Version),
173+
object_error::parse_failed);
174+
return readParameter<dxbc::RTS0::v2::RootDescriptor>();
170175
}
171176
};
172177

@@ -217,9 +222,9 @@ class RootSignature {
217222
case dxbc::RootParameterType::SRV:
218223
case dxbc::RootParameterType::UAV:
219224
if (Version == 1)
220-
DataSize = sizeof(dxbc::RST0::v0::RootDescriptor);
225+
DataSize = sizeof(dxbc::RTS0::v1::RootDescriptor);
221226
else
222-
DataSize = sizeof(dxbc::RST0::v1::RootDescriptor);
227+
DataSize = sizeof(dxbc::RTS0::v2::RootDescriptor);
223228
break;
224229
}
225230
size_t EndOfSectionByte = getNumStaticSamplers() == 0

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ 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

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ size_t RootSignatureDesc::getSize() const {
4141
case llvm::to_underlying(dxbc::RootParameterType::SRV):
4242
case llvm::to_underlying(dxbc::RootParameterType::UAV):
4343
if (Version == 1)
44-
Size += sizeof(dxbc::RST0::v0::RootDescriptor);
44+
Size += sizeof(dxbc::RTS0::v1::RootDescriptor);
4545
else
46-
Size += sizeof(dxbc::RST0::v1::RootDescriptor);
46+
Size += sizeof(dxbc::RTS0::v2::RootDescriptor);
4747

4848
break;
4949
}

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
8282
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
8383
} else if (auto *RDV =
8484
dyn_cast<object::DirectX::RootDescriptorView>(&ParamView)) {
85-
llvm::Expected<dxbc::RST0::v1::RootDescriptor> DescriptorOrErr =
85+
llvm::Expected<dxbc::RTS0::v2::RootDescriptor> DescriptorOrErr =
8686
RDV->read(Version);
8787
if (Error E = DescriptorOrErr.takeError())
8888
return std::move(E);

0 commit comments

Comments
 (0)