Skip to content

Commit 44bd13a

Browse files
author
joaosaffran
committed
making read work
1 parent f804a23 commit 44bd13a

File tree

8 files changed

+326
-12
lines changed

8 files changed

+326
-12
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,25 @@ enum class RootDescriptorFlag : uint32_t {
163163
#include "DXContainerConstants.def"
164164
};
165165

166+
#define DESCRIPTOR_RANGE_FLAG(Num, Val) Val = 1ull << Num,
167+
enum class DescriptorRangeFlag : uint32_t {
168+
#include "DXContainerConstants.def"
169+
};
170+
166171
#define ROOT_PARAMETER(Val, Enum) Enum = Val,
167172
enum class RootParameterType : uint32_t {
168173
#include "DXContainerConstants.def"
169174
};
170175

171176
ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();
172177

178+
#define DESCRIPTOR_RANGE(Val, Enum) Enum = Val,
179+
enum class DescriptorRangeType : uint32_t {
180+
#include "DXContainerConstants.def"
181+
};
182+
183+
ArrayRef<EnumEntry<DescriptorRangeType>> getDescriptorRangeTypes();
184+
173185
#define ROOT_PARAMETER(Val, Enum) \
174186
case Val: \
175187
return true;
@@ -595,6 +607,21 @@ struct RootDescriptor {
595607
sys::swapByteOrder(RegisterSpace);
596608
}
597609
};
610+
611+
struct DescriptorRange {
612+
uint32_t RangeType;
613+
uint32_t NumDescriptors;
614+
uint32_t BaseShaderRegister;
615+
uint32_t RegisterSpace;
616+
int32_t OffsetInDescriptorsFromTableStart;
617+
void swapBytes() {
618+
sys::swapByteOrder(RangeType);
619+
sys::swapByteOrder(NumDescriptors);
620+
sys::swapByteOrder(BaseShaderRegister);
621+
sys::swapByteOrder(RegisterSpace);
622+
sys::swapByteOrder(OffsetInDescriptorsFromTableStart);
623+
}
624+
};
598625
} // namespace v0
599626

600627
namespace v1 {
@@ -605,6 +632,14 @@ struct RootDescriptor : public v0::RootDescriptor {
605632
sys::swapByteOrder(Flags);
606633
}
607634
};
635+
636+
struct DescriptorRange : public v0::DescriptorRange {
637+
uint32_t Flags;
638+
void swapBytes() {
639+
v0::DescriptorRange::swapBytes();
640+
sys::swapByteOrder(Flags);
641+
}
642+
};
608643
} // namespace v1
609644
} // namespace RST0
610645
// following dx12 naming

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
7373
#endif // ROOT_ELEMENT_FLAG
7474

7575

76-
// ROOT_ELEMENT_FLAG(bit offset for the flag, name).
76+
// ROOT_DESCRIPTOR_FLAG(bit offset for the flag, name).
7777
#ifdef ROOT_DESCRIPTOR_FLAG
7878

7979
ROOT_DESCRIPTOR_FLAG(0, NONE)
@@ -84,15 +84,38 @@ ROOT_DESCRIPTOR_FLAG(3, DATA_STATIC)
8484
#endif // ROOT_DESCRIPTOR_FLAG
8585

8686

87+
// DESCRIPTOR_RANGE_FLAG(bit offset for the flag, name).
88+
#ifdef DESCRIPTOR_RANGE_FLAG
89+
90+
DESCRIPTOR_RANGE_FLAG(0, NONE)
91+
DESCRIPTOR_RANGE_FLAG(1, DESCRIPTORS_VOLATILE)
92+
DESCRIPTOR_RANGE_FLAG(2, DATA_VOLATILE)
93+
DESCRIPTOR_RANGE_FLAG(3, DATA_STATIC_WHILE_SET_AT_EXECUTE)
94+
DESCRIPTOR_RANGE_FLAG(4, DATA_STATIC)
95+
DESCRIPTOR_RANGE_FLAG(16, DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
96+
#undef DESCRIPTOR_RANGE_FLAG
97+
#endif // DESCRIPTOR_RANGE_FLAG
98+
8799
#ifdef ROOT_PARAMETER
88100

101+
ROOT_PARAMETER(0, DescriptorTable)
89102
ROOT_PARAMETER(1, Constants32Bit)
90103
ROOT_PARAMETER(2, CBV)
91104
ROOT_PARAMETER(3, SRV)
92105
ROOT_PARAMETER(4, UAV)
93106
#undef ROOT_PARAMETER
94107
#endif // ROOT_PARAMETER
95108

109+
110+
#ifdef DESCRIPTOR_RANGE
111+
112+
DESCRIPTOR_RANGE(0, SRV)
113+
DESCRIPTOR_RANGE(1, UAV)
114+
DESCRIPTOR_RANGE(2, CBV)
115+
DESCRIPTOR_RANGE(3, Sampler)
116+
#undef DESCRIPTOR_RANGE
117+
#endif // DESCRIPTOR_RANGE
118+
96119
#ifdef SHADER_VISIBILITY
97120

98121
SHADER_VISIBILITY(0, All)

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/ADT/STLForwardCompat.h"
10+
#include "llvm/ADT/SmallVector.h"
1011
#include "llvm/BinaryFormat/DXContainer.h"
1112
#include <cstddef>
1213
#include <cstdint>
@@ -28,17 +29,30 @@ struct RootParameterInfo {
2829
RootParameterInfo(dxbc::RootParameterHeader H, size_t L)
2930
: Header(H), Location(L) {}
3031
};
32+
using DescriptorRanges = std::variant<dxbc::RST0::v0::DescriptorRange,
33+
dxbc::RST0::v1::DescriptorRange>;
34+
struct DescriptorTable {
35+
SmallVector<DescriptorRanges> Ranges;
36+
37+
SmallVector<DescriptorRanges>::const_iterator begin() const {
38+
return Ranges.begin();
39+
}
40+
SmallVector<DescriptorRanges>::const_iterator end() const {
41+
return Ranges.end();
42+
}
43+
};
3144

3245
using RootDescriptor = std::variant<dxbc::RST0::v0::RootDescriptor,
3346
dxbc::RST0::v1::RootDescriptor>;
34-
using ParametersView = std::variant<const dxbc::RootConstants *,
35-
const dxbc::RST0::v0::RootDescriptor *,
36-
const dxbc::RST0::v1::RootDescriptor *>;
47+
48+
using ParametersView = std::variant<
49+
const dxbc::RootConstants *, const dxbc::RST0::v0::RootDescriptor *,
50+
const dxbc::RST0::v1::RootDescriptor *, const DescriptorTable *>;
3751
struct RootParametersContainer {
3852
SmallVector<RootParameterInfo> ParametersInfo;
39-
4053
SmallVector<dxbc::RootConstants> Constants;
4154
SmallVector<RootDescriptor> Descriptors;
55+
SmallVector<DescriptorTable> Tables;
4256

4357
void addInfo(dxbc::RootParameterHeader H, size_t L) {
4458
ParametersInfo.push_back(RootParameterInfo(H, L));
@@ -61,20 +75,28 @@ struct RootParametersContainer {
6175
Descriptors.push_back(D);
6276
}
6377

78+
void addParameter(dxbc::RootParameterHeader H, DescriptorTable D) {
79+
addInfo(H, Tables.size());
80+
Tables.push_back(D);
81+
}
82+
6483
std::optional<ParametersView> getParameter(const RootParameterInfo *H) const {
6584
switch (H->Header.ParameterType) {
6685
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
6786
return &Constants[H->Location];
6887
case llvm::to_underlying(dxbc::RootParameterType::CBV):
6988
case llvm::to_underlying(dxbc::RootParameterType::SRV):
70-
case llvm::to_underlying(dxbc::RootParameterType::UAV):
89+
case llvm::to_underlying(dxbc::RootParameterType::UAV): {
7190
const RootDescriptor &VersionedParam = Descriptors[H->Location];
7291
if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor>(
7392
VersionedParam)) {
7493
return &std::get<dxbc::RST0::v0::RootDescriptor>(VersionedParam);
7594
}
7695
return &std::get<dxbc::RST0::v1::RootDescriptor>(VersionedParam);
7796
}
97+
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
98+
return &Tables[H->Location];
99+
}
78100

79101
return std::nullopt;
80102
}

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

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

18+
#include "llvm/ADT/STLForwardCompat.h"
19+
#include "llvm/ADT/SmallVector.h"
1820
#include "llvm/ADT/StringRef.h"
1921
#include "llvm/BinaryFormat/DXContainer.h"
2022
#include "llvm/Object/DXContainer.h"
@@ -91,6 +93,25 @@ struct RootDescriptorYaml {
9193
#include "llvm/BinaryFormat/DXContainerConstants.def"
9294
};
9395

96+
struct DescriptorRangeYaml {
97+
uint32_t RangeType;
98+
uint32_t NumDescriptors;
99+
uint32_t BaseShaderRegister;
100+
uint32_t RegisterSpace;
101+
int32_t OffsetInDescriptorsFromTableStart;
102+
103+
uint32_t getEncodedFlags() const;
104+
105+
#define DESCRIPTOR_RANGE_FLAG(Num, Val) bool Val = false;
106+
#include "llvm/BinaryFormat/DXContainerConstants.def"
107+
};
108+
109+
struct DescriptorTableYaml {
110+
uint32_t NumRanges;
111+
uint32_t RangesOffset;
112+
SmallVector<DescriptorRangeYaml> Ranges;
113+
};
114+
94115
struct RootParameterYamlDesc {
95116
uint32_t Type;
96117
uint32_t Visibility;
@@ -107,12 +128,80 @@ struct RootParameterYamlDesc {
107128
case llvm::to_underlying(dxbc::RootParameterType::UAV):
108129
Descriptor = RootDescriptorYaml();
109130
break;
131+
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
132+
Table = DescriptorTableYaml();
133+
break;
134+
}
135+
}
136+
137+
~RootParameterYamlDesc() {
138+
switch (Type) {
139+
140+
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
141+
Constants.~RootConstantsYaml();
142+
break;
143+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
144+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
145+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
146+
Descriptor.~RootDescriptorYaml();
147+
break;
148+
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
149+
Table.~DescriptorTableYaml();
150+
break;
110151
}
111152
}
112153

154+
RootParameterYamlDesc(const RootParameterYamlDesc &Other)
155+
: Type(Other.Type), Visibility(Other.Visibility), Offset(Other.Offset) {
156+
// Initialize the appropriate union member based on Type
157+
switch (Type) {
158+
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
159+
// Placement new to construct the union member
160+
new (&Constants) RootConstantsYaml(Other.Constants);
161+
break;
162+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
163+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
164+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
165+
new (&Descriptor) RootDescriptorYaml(Other.Descriptor);
166+
break;
167+
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
168+
new (&Table) DescriptorTableYaml(Other.Table);
169+
break;
170+
}
171+
}
172+
173+
RootParameterYamlDesc &operator=(const RootParameterYamlDesc &other) {
174+
if (this != &other) {
175+
// First, destroy the current union member
176+
this->~RootParameterYamlDesc();
177+
178+
// Copy the basic members
179+
Type = other.Type;
180+
Visibility = other.Visibility;
181+
Offset = other.Offset;
182+
183+
// Initialize the new union member based on the Type from 'other'
184+
switch (Type) {
185+
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
186+
new (&Constants) RootConstantsYaml(other.Constants);
187+
break;
188+
case llvm::to_underlying(dxbc::RootParameterType::CBV):
189+
case llvm::to_underlying(dxbc::RootParameterType::SRV):
190+
case llvm::to_underlying(dxbc::RootParameterType::UAV):
191+
new (&Descriptor) RootDescriptorYaml(other.Descriptor);
192+
break;
193+
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):
194+
new (&Table) DescriptorTableYaml(other.Table);
195+
break;
196+
}
197+
}
198+
return *this;
199+
}
200+
113201
union {
114202
RootConstantsYaml Constants;
115203
RootDescriptorYaml Descriptor;
204+
DescriptorTableYaml Table;
116205
};
117206
};
118207

@@ -244,6 +333,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureElement)
244333
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::PSVInfo::MaskVector)
245334
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureParameter)
246335
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::RootParameterYamlDesc)
336+
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::DescriptorRangeYaml)
247337
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::SemanticKind)
248338
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ComponentType)
249339
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::InterpolationMode)
@@ -328,6 +418,14 @@ template <> struct MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml> {
328418
static void mapping(IO &IO, llvm::DXContainerYAML::RootDescriptorYaml &D);
329419
};
330420

421+
template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorTableYaml> {
422+
static void mapping(IO &IO, llvm::DXContainerYAML::DescriptorTableYaml &D);
423+
};
424+
425+
template <> struct MappingTraits<llvm::DXContainerYAML::DescriptorRangeYaml> {
426+
static void mapping(IO &IO, llvm::DXContainerYAML::DescriptorRangeYaml &D);
427+
};
428+
331429
} // namespace yaml
332430

333431
} // namespace llvm

0 commit comments

Comments
 (0)