Skip to content

Commit 3ce683e

Browse files
author
joaosaffran
committed
adding support for root descriptor
1 parent 860fddd commit 3ce683e

File tree

9 files changed

+233
-12
lines changed

9 files changed

+233
-12
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/SwapByteOrder.h"
1919
#include "llvm/TargetParser/Triple.h"
2020

21+
#include <cstdint>
2122
#include <stdint.h>
2223

2324
namespace llvm {
@@ -158,6 +159,11 @@ enum class RootElementFlag : uint32_t {
158159
#include "DXContainerConstants.def"
159160
};
160161

162+
#define ROOT_DESCRIPTOR_FLAG(Num, Val) Val = 1ull << Num,
163+
enum class RootDescriptorFlag : uint32_t {
164+
#include "DXContainerConstants.def"
165+
};
166+
161167
#define ROOT_PARAMETER(Val, Enum) Enum = Val,
162168
enum class RootParameterType : uint32_t {
163169
#include "DXContainerConstants.def"
@@ -594,6 +600,25 @@ struct RootConstants {
594600
sys::swapByteOrder(Num32BitValues);
595601
}
596602
};
603+
struct RootDescriptor_V1_0 {
604+
uint32_t ShaderRegister;
605+
uint32_t RegisterSpace;
606+
void swapBytes() {
607+
sys::swapByteOrder(ShaderRegister);
608+
sys::swapByteOrder(RegisterSpace);
609+
}
610+
};
611+
612+
struct RootDescriptor_V1_1 {
613+
uint32_t ShaderRegister;
614+
uint32_t RegisterSpace;
615+
uint32_t Flags;
616+
void swapBytes() {
617+
sys::swapByteOrder(ShaderRegister);
618+
sys::swapByteOrder(RegisterSpace);
619+
sys::swapByteOrder(Flags);
620+
}
621+
};
597622

598623
struct RootParameterHeader {
599624
uint32_t ParameterType;

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,24 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
7272
#undef ROOT_ELEMENT_FLAG
7373
#endif // ROOT_ELEMENT_FLAG
7474

75+
76+
// ROOT_ELEMENT_FLAG(bit offset for the flag, name).
77+
#ifdef ROOT_DESCRIPTOR_FLAG
78+
79+
ROOT_DESCRIPTOR_FLAG(0, NONE)
80+
ROOT_DESCRIPTOR_FLAG(2, DATA_VOLATILE)
81+
ROOT_DESCRIPTOR_FLAG(4, DATA_STATIC_WHILE_SET_AT_EXECUTE)
82+
ROOT_DESCRIPTOR_FLAG(8, DATA_STATIC)
83+
#undef ROOT_DESCRIPTOR_FLAG
84+
#endif // ROOT_DESCRIPTOR_FLAG
85+
86+
7587
#ifdef ROOT_PARAMETER
7688

7789
ROOT_PARAMETER(1, Constants32Bit)
90+
ROOT_PARAMETER(2, CBV)
91+
ROOT_PARAMETER(3, SRV)
92+
ROOT_PARAMETER(4, UAV)
7893
#undef ROOT_PARAMETER
7994
#endif // ROOT_PARAMETER
8095

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct RootParameter {
1919
dxbc::RootParameterHeader Header;
2020
union {
2121
dxbc::RootConstants Constants;
22+
dxbc::RootDescriptor_V1_0 Descriptor_V10;
23+
dxbc::RootDescriptor_V1_1 Descriptor_V11;
2224
};
2325
};
2426
struct RootSignatureDesc {

llvm/include/llvm/Object/DXContainer.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_OBJECT_DXCONTAINER_H
1616
#define LLVM_OBJECT_DXCONTAINER_H
1717

18+
#include "llvm/ADT/STLForwardCompat.h"
1819
#include "llvm/ADT/SmallVector.h"
1920
#include "llvm/ADT/StringRef.h"
2021
#include "llvm/BinaryFormat/DXContainer.h"
@@ -149,6 +150,36 @@ struct RootConstantView : RootParameterView {
149150
}
150151
};
151152

153+
struct RootDescriptorView_V1_0 : RootParameterView {
154+
static bool classof(const RootParameterView *V) {
155+
return (V->Header.ParameterType ==
156+
llvm::to_underlying(dxbc::RootParameterType::CBV) ||
157+
V->Header.ParameterType ==
158+
llvm::to_underlying(dxbc::RootParameterType::SRV) ||
159+
V->Header.ParameterType ==
160+
llvm::to_underlying(dxbc::RootParameterType::UAV));
161+
}
162+
163+
llvm::Expected<dxbc::RootDescriptor_V1_0> read() {
164+
return readParameter<dxbc::RootDescriptor_V1_0>();
165+
}
166+
};
167+
168+
struct RootDescriptorView_V1_1 : RootParameterView {
169+
static bool classof(const RootParameterView *V) {
170+
return (V->Header.ParameterType ==
171+
llvm::to_underlying(dxbc::RootParameterType::CBV) ||
172+
V->Header.ParameterType ==
173+
llvm::to_underlying(dxbc::RootParameterType::SRV) ||
174+
V->Header.ParameterType ==
175+
llvm::to_underlying(dxbc::RootParameterType::UAV));
176+
}
177+
178+
llvm::Expected<dxbc::RootDescriptor_V1_1> read() {
179+
return readParameter<dxbc::RootDescriptor_V1_1>();
180+
}
181+
};
182+
152183
static Error parseFailed(const Twine &Msg) {
153184
return make_error<GenericBinaryError>(Msg.str(), object_error::parse_failed);
154185
}
@@ -192,6 +223,14 @@ class RootSignature {
192223
case dxbc::RootParameterType::Constants32Bit:
193224
DataSize = sizeof(dxbc::RootConstants);
194225
break;
226+
case dxbc::RootParameterType::CBV:
227+
case dxbc::RootParameterType::SRV:
228+
case dxbc::RootParameterType::UAV:
229+
if (Version == 1)
230+
DataSize = sizeof(dxbc::RootDescriptor_V1_0);
231+
else
232+
DataSize = sizeof(dxbc::RootDescriptor_V1_1);
233+
break;
195234
}
196235
size_t EndOfSectionByte = getNumStaticSamplers() == 0
197236
? PartData.size()

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
1616
#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
1717

18+
#include "llvm/ADT/STLForwardCompat.h"
1819
#include "llvm/ADT/StringRef.h"
1920
#include "llvm/BinaryFormat/DXContainer.h"
2021
#include "llvm/Object/DXContainer.h"
@@ -24,6 +25,7 @@
2425
#include <cstdint>
2526
#include <optional>
2627
#include <string>
28+
#include <variant>
2729
#include <vector>
2830

2931
namespace llvm {
@@ -73,24 +75,50 @@ struct ShaderHash {
7375
std::vector<llvm::yaml::Hex8> Digest;
7476
};
7577

76-
#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
77-
7878
struct RootConstantsYaml {
7979
uint32_t ShaderRegister;
8080
uint32_t RegisterSpace;
8181
uint32_t Num32BitValues;
8282
};
8383

84+
#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false;
85+
struct RootDescriptorYaml {
86+
RootDescriptorYaml() = default;
87+
88+
uint32_t ShaderRegister;
89+
uint32_t RegisterSpace;
90+
91+
uint32_t getEncodedFlags();
92+
93+
#include "llvm/BinaryFormat/DXContainerConstants.def"
94+
};
95+
8496
struct RootParameterYamlDesc {
8597
uint32_t Type;
8698
uint32_t Visibility;
8799
uint32_t Offset;
100+
RootParameterYamlDesc(){};
101+
RootParameterYamlDesc(uint32_t T) : Type(T) {
102+
switch (T) {
103+
104+
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
105+
Constants = RootConstantsYaml();
106+
break;
107+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
108+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
109+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
110+
Descriptor = RootDescriptorYaml();
111+
break;
112+
}
113+
}
88114

89115
union {
90116
RootConstantsYaml Constants;
117+
RootDescriptorYaml Descriptor;
91118
};
92119
};
93120

121+
#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
94122
struct RootSignatureYamlDesc {
95123
RootSignatureYamlDesc() = default;
96124

@@ -298,6 +326,10 @@ template <> struct MappingTraits<llvm::DXContainerYAML::RootConstantsYaml> {
298326
static void mapping(IO &IO, llvm::DXContainerYAML::RootConstantsYaml &C);
299327
};
300328

329+
template <> struct MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml> {
330+
static void mapping(IO &IO, llvm::DXContainerYAML::RootDescriptorYaml &D);
331+
};
332+
301333
} // namespace yaml
302334

303335
} // namespace llvm

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/MC/DXContainerRootSignature.h"
1010
#include "llvm/ADT/SmallString.h"
11+
#include "llvm/BinaryFormat/DXContainer.h"
1112
#include "llvm/Support/EndianStream.h"
1213

1314
using namespace llvm;
@@ -37,6 +38,15 @@ size_t RootSignatureDesc::getSize() const {
3738
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
3839
Size += sizeof(dxbc::RootConstants);
3940
break;
41+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
42+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
43+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
44+
if (Version == 1)
45+
Size += sizeof(dxbc::RootDescriptor_V1_0);
46+
else
47+
Size += sizeof(dxbc::RootDescriptor_V1_1);
48+
49+
break;
4050
}
4151
}
4252
return Size;
@@ -80,6 +90,22 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
8090
support::endian::write(BOS, P.Constants.Num32BitValues,
8191
llvm::endianness::little);
8292
break;
93+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
94+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
95+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
96+
if (Version == 1) {
97+
support::endian::write(BOS, P.Descriptor_V10.RegisterSpace,
98+
llvm::endianness::little);
99+
support::endian::write(BOS, P.Descriptor_V10.ShaderRegister,
100+
llvm::endianness::little);
101+
} else {
102+
support::endian::write(BOS, P.Descriptor_V11.RegisterSpace,
103+
llvm::endianness::little);
104+
support::endian::write(BOS, P.Descriptor_V11.ShaderRegister,
105+
llvm::endianness::little);
106+
support::endian::write(BOS, P.Descriptor_V11.Flags,
107+
llvm::endianness::little);
108+
}
83109
}
84110
}
85111
assert(Storage.size() == getSize());

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
273273
RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
274274
RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
275275

276-
for (const auto &Param : P.RootSignature->Parameters) {
276+
for (auto &Param : P.RootSignature->Parameters) {
277277
mcdxbc::RootParameter NewParam;
278278
NewParam.Header = dxbc::RootParameterHeader{
279279
Param.Type, Param.Visibility, Param.Offset};
@@ -283,6 +283,23 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
283283
NewParam.Constants.Num32BitValues = Param.Constants.Num32BitValues;
284284
NewParam.Constants.RegisterSpace = Param.Constants.RegisterSpace;
285285
NewParam.Constants.ShaderRegister = Param.Constants.ShaderRegister;
286+
break;
287+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
288+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
289+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
290+
if (RS.Version == 1) {
291+
NewParam.Descriptor_V10.RegisterSpace =
292+
Param.Descriptor.RegisterSpace;
293+
NewParam.Descriptor_V10.ShaderRegister =
294+
Param.Descriptor.ShaderRegister;
295+
} else {
296+
NewParam.Descriptor_V11.RegisterSpace =
297+
Param.Descriptor.RegisterSpace;
298+
NewParam.Descriptor_V11.ShaderRegister =
299+
Param.Descriptor.ShaderRegister;
300+
NewParam.Descriptor_V11.Flags = Param.Descriptor.getEncodedFlags();
301+
}
302+
286303
break;
287304
}
288305

0 commit comments

Comments
 (0)