Skip to content

Commit e655315

Browse files
author
joaosaffran
committed
move to namespace
1 parent aabd424 commit e655315

File tree

8 files changed

+64
-58
lines changed

8 files changed

+64
-58
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -587,31 +587,6 @@ static_assert(sizeof(ProgramSignatureElement) == 32,
587587
"ProgramSignatureElement is misaligned");
588588
namespace RTS0 {
589589
namespace v1 {
590-
struct RootDescriptor {
591-
uint32_t ShaderRegister;
592-
uint32_t RegisterSpace;
593-
void swapBytes() {
594-
sys::swapByteOrder(ShaderRegister);
595-
sys::swapByteOrder(RegisterSpace);
596-
}
597-
};
598-
} // namespace v1
599-
600-
namespace v2 {
601-
struct RootDescriptor : public v1::RootDescriptor {
602-
uint32_t Flags;
603-
604-
RootDescriptor() = default;
605-
explicit RootDescriptor(v1::RootDescriptor &Base)
606-
: v1::RootDescriptor(Base), Flags(0u) {}
607-
608-
void swapBytes() {
609-
v1::RootDescriptor::swapBytes();
610-
sys::swapByteOrder(Flags);
611-
}
612-
};
613-
} // namespace v2
614-
} // namespace RTS0
615590
// following dx12 naming
616591
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants
617592
struct RootConstants {
@@ -655,6 +630,33 @@ struct RootSignatureHeader {
655630
sys::swapByteOrder(Flags);
656631
}
657632
};
633+
634+
struct RootDescriptor {
635+
uint32_t ShaderRegister;
636+
uint32_t RegisterSpace;
637+
void swapBytes() {
638+
sys::swapByteOrder(ShaderRegister);
639+
sys::swapByteOrder(RegisterSpace);
640+
}
641+
};
642+
} // namespace v1
643+
644+
namespace v2 {
645+
struct RootDescriptor : public v1::RootDescriptor {
646+
uint32_t Flags;
647+
648+
RootDescriptor() = default;
649+
explicit RootDescriptor(v1::RootDescriptor &Base)
650+
: v1::RootDescriptor(Base), Flags(0u) {}
651+
652+
void swapBytes() {
653+
v1::RootDescriptor::swapBytes();
654+
sys::swapByteOrder(Flags);
655+
}
656+
};
657+
} // namespace v2
658+
} // namespace RTS0
659+
658660
} // namespace dxbc
659661
} // namespace llvm
660662

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ class raw_ostream;
1616
namespace mcdxbc {
1717

1818
struct RootParameterInfo {
19-
dxbc::RootParameterHeader Header;
19+
dxbc::RTS0::v1::RootParameterHeader Header;
2020
size_t Location;
2121

2222
RootParameterInfo() = default;
2323

24-
RootParameterInfo(dxbc::RootParameterHeader Header, size_t Location)
24+
RootParameterInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location)
2525
: Header(Header), Location(Location) {}
2626
};
2727

2828
struct RootParametersContainer {
2929
SmallVector<RootParameterInfo> ParametersInfo;
3030

31-
SmallVector<dxbc::RootConstants> Constants;
31+
SmallVector<dxbc::RTS0::v1::RootConstants> Constants;
3232
SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;
3333

34-
void addInfo(dxbc::RootParameterHeader Header, size_t Location) {
34+
void addInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) {
3535
ParametersInfo.push_back(RootParameterInfo(Header, Location));
3636
}
3737

38-
void addParameter(dxbc::RootParameterHeader Header,
39-
dxbc::RootConstants Constant) {
38+
void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
39+
dxbc::RTS0::v1::RootConstants Constant) {
4040
addInfo(Header, Constants.size());
4141
Constants.push_back(Constant);
4242
}
4343

44-
void addInvalidParameter(dxbc::RootParameterHeader Header) {
44+
void addInvalidParameter(dxbc::RTS0::v1::RootParameterHeader Header) {
4545
addInfo(Header, -1);
4646
}
4747

48-
void addParameter(dxbc::RootParameterHeader Header,
48+
void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
4949
dxbc::RTS0::v2::RootDescriptor Descriptor) {
5050
addInfo(Header, Descriptors.size());
5151
Descriptors.push_back(Descriptor);
@@ -57,12 +57,12 @@ struct RootParametersContainer {
5757
return {Info.Header.ParameterType, Info.Location};
5858
}
5959

60-
const dxbc::RootParameterHeader &getHeader(size_t Location) const {
60+
const dxbc::RTS0::v1::RootParameterHeader &getHeader(size_t Location) const {
6161
const RootParameterInfo &Info = ParametersInfo[Location];
6262
return Info.Header;
6363
}
6464

65-
const dxbc::RootConstants &getConstant(size_t Index) const {
65+
const dxbc::RTS0::v1::RootConstants &getConstant(size_t Index) const {
6666
return Constants[Index];
6767
}
6868

llvm/include/llvm/Object/DXContainer.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ template <typename T> struct ViewArray {
121121

122122
namespace DirectX {
123123
struct RootParameterView {
124-
const dxbc::RootParameterHeader &Header;
124+
const dxbc::RTS0::v1::RootParameterHeader &Header;
125125
StringRef ParamData;
126126

127-
RootParameterView(const dxbc::RootParameterHeader &H, StringRef P)
127+
RootParameterView(const dxbc::RTS0::v1::RootParameterHeader &H, StringRef P)
128128
: Header(H), ParamData(P) {}
129129

130130
template <typename T> Expected<T> readParameter() {
@@ -147,8 +147,8 @@ struct RootConstantView : RootParameterView {
147147
(uint32_t)dxbc::RootParameterType::Constants32Bit;
148148
}
149149

150-
llvm::Expected<dxbc::RootConstants> read() {
151-
return readParameter<dxbc::RootConstants>();
150+
llvm::Expected<dxbc::RTS0::v1::RootConstants> read() {
151+
return readParameter<dxbc::RTS0::v1::RootConstants>();
152152
}
153153
};
154154

@@ -189,10 +189,11 @@ class RootSignature {
189189
uint32_t NumStaticSamplers;
190190
uint32_t StaticSamplersOffset;
191191
uint32_t Flags;
192-
ViewArray<dxbc::RootParameterHeader> ParametersHeaders;
192+
ViewArray<dxbc::RTS0::v1::RootParameterHeader> ParametersHeaders;
193193
StringRef PartData;
194194

195-
using param_header_iterator = ViewArray<dxbc::RootParameterHeader>::iterator;
195+
using param_header_iterator =
196+
ViewArray<dxbc::RTS0::v1::RootParameterHeader>::iterator;
196197

197198
public:
198199
RootSignature(StringRef PD) : PartData(PD) {}
@@ -210,15 +211,15 @@ class RootSignature {
210211
uint32_t getFlags() const { return Flags; }
211212

212213
llvm::Expected<RootParameterView>
213-
getParameter(const dxbc::RootParameterHeader &Header) const {
214+
getParameter(const dxbc::RTS0::v1::RootParameterHeader &Header) const {
214215
size_t DataSize;
215216

216217
if (!dxbc::isValidParameterType(Header.ParameterType))
217218
return parseFailed("invalid parameter type");
218219

219220
switch (static_cast<dxbc::RootParameterType>(Header.ParameterType)) {
220221
case dxbc::RootParameterType::Constants32Bit:
221-
DataSize = sizeof(dxbc::RootConstants);
222+
DataSize = sizeof(dxbc::RTS0::v1::RootConstants);
222223
break;
223224
case dxbc::RootParameterType::CBV:
224225
case dxbc::RootParameterType::SRV:

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ static void rewriteOffsetToCurrentByte(raw_svector_ostream &Stream,
2929
}
3030

3131
size_t RootSignatureDesc::getSize() const {
32-
size_t Size = sizeof(dxbc::RootSignatureHeader) +
33-
ParametersContainer.size() * sizeof(dxbc::RootParameterHeader);
32+
size_t Size =
33+
sizeof(dxbc::RTS0::v1::RootSignatureHeader) +
34+
ParametersContainer.size() * sizeof(dxbc::RTS0::v1::RootParameterHeader);
3435

3536
for (const RootParameterInfo &I : ParametersContainer) {
3637
switch (I.Header.ParameterType) {
3738
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
38-
Size += sizeof(dxbc::RootConstants);
39+
Size += sizeof(dxbc::RTS0::v1::RootConstants);
3940
break;
4041
case llvm::to_underlying(dxbc::RootParameterType::CBV):
4142
case llvm::to_underlying(dxbc::RootParameterType::SRV):
@@ -81,7 +82,7 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
8182
const auto &[Type, Loc] = ParametersContainer.getTypeAndLocForParameter(I);
8283
switch (Type) {
8384
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
84-
const dxbc::RootConstants &Constants =
85+
const dxbc::RTS0::v1::RootConstants &Constants =
8586
ParametersContainer.getConstant(Loc);
8687
support::endian::write(BOS, Constants.ShaderRegister,
8788
llvm::endianness::little);

llvm/lib/Object/DXContainer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ Error DirectX::RootSignature::parse() {
273273
Current += sizeof(uint32_t);
274274

275275
ParametersHeaders.Data = PartData.substr(
276-
RootParametersOffset, NumParameters * sizeof(dxbc::RootParameterHeader));
276+
RootParametersOffset,
277+
NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader));
277278

278279
return Error::success();
279280
}

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,12 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
274274
RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
275275

276276
for (const auto &Param : P.RootSignature->Parameters) {
277-
auto Header = dxbc::RootParameterHeader{Param.Type, Param.Visibility,
278-
Param.Offset};
277+
auto Header = dxbc::RTS0::v1::RootParameterHeader{
278+
Param.Type, Param.Visibility, Param.Offset};
279279

280280
if (auto *ConstantYaml =
281281
std::get_if<DXContainerYAML::RootConstantsYaml>(&Param.Data)) {
282-
dxbc::RootConstants Constants;
282+
dxbc::RTS0::v1::RootConstants Constants;
283283
Constants.Num32BitValues = ConstantYaml->Num32BitValues;
284284
Constants.RegisterSpace = ConstantYaml->RegisterSpace;
285285
Constants.ShaderRegister = ConstantYaml->ShaderRegister;

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DXContainerYAML::RootSignatureYamlDesc::create(
4747
RootSigDesc.RootParametersOffset = Data.getRootParametersOffset();
4848

4949
uint32_t Flags = Data.getFlags();
50-
for (const dxbc::RootParameterHeader &PH : Data.param_headers()) {
50+
for (const dxbc::RTS0::v1::RootParameterHeader &PH : Data.param_headers()) {
5151

5252
if (!dxbc::isValidParameterType(PH.ParameterType))
5353
return createStringError(std::errc::invalid_argument,
@@ -70,7 +70,8 @@ DXContainerYAML::RootSignatureYamlDesc::create(
7070
object::DirectX::RootParameterView ParamView = ParamViewOrErr.get();
7171

7272
if (auto *RCV = dyn_cast<object::DirectX::RootConstantView>(&ParamView)) {
73-
llvm::Expected<dxbc::RootConstants> ConstantsOrErr = RCV->read();
73+
llvm::Expected<dxbc::RTS0::v1::RootConstants> ConstantsOrErr =
74+
RCV->read();
7475
if (Error E = ConstantsOrErr.takeError())
7576
return std::move(E);
7677

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
7575
if (RootConstantNode->getNumOperands() != 5)
7676
return reportError(Ctx, "Invalid format for RootConstants Element");
7777

78-
dxbc::RootParameterHeader Header;
78+
dxbc::RTS0::v1::RootParameterHeader Header;
7979
// The parameter offset doesn't matter here - we recalculate it during
8080
// serialization Header.ParameterOffset = 0;
8181
Header.ParameterType =
@@ -86,7 +86,7 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
8686
else
8787
return reportError(Ctx, "Invalid value for ShaderVisibility");
8888

89-
dxbc::RootConstants Constants;
89+
dxbc::RTS0::v1::RootConstants Constants;
9090
if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 2))
9191
Constants.ShaderRegister = *Val;
9292
else
@@ -247,7 +247,7 @@ analyzeModule(Module &M) {
247247
// Clang emits the root signature data in dxcontainer following a specific
248248
// sequence. First the header, then the root parameters. So the header
249249
// offset will always equal to the header size.
250-
RSD.RootParameterOffset = sizeof(dxbc::RootSignatureHeader);
250+
RSD.RootParameterOffset = sizeof(dxbc::RTS0::v1::RootSignatureHeader);
251251

252252
if (parse(Ctx, RSD, RootElementListNode) || validate(Ctx, RSD)) {
253253
return RSDMap;
@@ -296,7 +296,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
296296
for (size_t I = 0; I < RS.ParametersContainer.size(); I++) {
297297
const auto &[Type, Loc] =
298298
RS.ParametersContainer.getTypeAndLocForParameter(I);
299-
const dxbc::RootParameterHeader Header =
299+
const dxbc::RTS0::v1::RootParameterHeader Header =
300300
RS.ParametersContainer.getHeader(I);
301301

302302
OS << indent(Space) << "- Parameter Type: " << Type << "\n";
@@ -305,7 +305,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
305305

306306
switch (Type) {
307307
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
308-
const dxbc::RootConstants &Constants =
308+
const dxbc::RTS0::v1::RootConstants &Constants =
309309
RS.ParametersContainer.getConstant(Loc);
310310
OS << indent(Space + 2) << "Register Space: " << Constants.RegisterSpace
311311
<< "\n";

0 commit comments

Comments
 (0)