Skip to content

Commit 5f26016

Browse files
Joao SaffranJoao Saffran
authored andcommitted
finish changing
1 parent 3924438 commit 5f26016

File tree

16 files changed

+282
-197
lines changed

16 files changed

+282
-197
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/ADT/StringExtras.h"
4040
#include "llvm/ADT/StringRef.h"
4141
#include "llvm/ADT/Twine.h"
42+
#include "llvm/BinaryFormat/DXContainer.h"
4243
#include "llvm/Frontend/HLSL/HLSLBinding.h"
4344
#include "llvm/Frontend/HLSL/RootSignatureValidations.h"
4445
#include "llvm/Support/Casting.h"
@@ -1218,9 +1219,9 @@ bool SemaHLSL::handleRootSignatureElements(
12181219
ReportError(Loc, 0, 0xffffffef);
12191220
};
12201221

1221-
const uint32_t Version =
1222-
llvm::to_underlying(SemaRef.getLangOpts().HLSLRootSigVer);
1223-
const uint32_t VersionEnum = Version - 1;
1222+
const llvm::dxbc::RootSignatureVersion Version =
1223+
SemaRef.getLangOpts().HLSLRootSigVer;
1224+
const uint32_t VersionEnum = static_cast<uint32_t>(Version) - 1;
12241225
auto ReportFlagError = [this, &HadError, VersionEnum](SourceLocation Loc) {
12251226
HadError = true;
12261227
this->Diag(Loc, diag::err_hlsl_invalid_rootsig_flag)
@@ -1270,7 +1271,9 @@ bool SemaHLSL::handleRootSignatureElements(
12701271
}
12711272

12721273
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
1273-
Version, llvm::to_underlying(Clause->Type),
1274+
Version,
1275+
llvm::dxbc::DescriptorRangeType(
1276+
llvm::to_underlying(Clause->Type)),
12741277
llvm::to_underlying(Clause->Flags)))
12751278
ReportFlagError(Loc);
12761279
}

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ enum class DescriptorRangeType : uint32_t {
200200
LLVM_ABI ArrayRef<EnumEntry<DescriptorRangeType>> getDescriptorRangeTypes();
201201

202202
#define ROOT_PARAMETER(Val, Enum) \
203-
case Val: \
203+
case dxbc::RootParameterType::Enum: \
204204
return true;
205-
inline bool isValidParameterType(uint32_t V) {
205+
inline bool isValidParameterType(dxbc::RootParameterType V) {
206206
switch (V) {
207207
#include "DXContainerConstants.def"
208208
}
@@ -217,9 +217,9 @@ enum class ShaderVisibility : uint32_t {
217217
LLVM_ABI ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();
218218

219219
#define SHADER_VISIBILITY(Val, Enum) \
220-
case Val: \
220+
case dxbc::ShaderVisibility::Enum: \
221221
return true;
222-
inline bool isValidShaderVisibility(uint32_t V) {
222+
inline bool isValidShaderVisibility(dxbc::ShaderVisibility V) {
223223
switch (V) {
224224
#include "DXContainerConstants.def"
225225
}
@@ -254,6 +254,14 @@ enum class StaticBorderColor : uint32_t {
254254

255255
LLVM_ABI ArrayRef<EnumEntry<StaticBorderColor>> getStaticBorderColors();
256256

257+
// D3D_ROOT_SIGNATURE_VERSION
258+
enum class RootSignatureVersion {
259+
V1_0 = 0x1,
260+
V1_1 = 0x2,
261+
};
262+
263+
LLVM_ABI ArrayRef<EnumEntry<RootSignatureVersion>> getRootSignatureVersions();
264+
257265
LLVM_ABI PartType parsePartType(StringRef S);
258266

259267
struct VertexPSVInfo {
@@ -646,19 +654,19 @@ static_assert(sizeof(ProgramSignatureElement) == 32,
646654
namespace RTS0 {
647655
namespace v1 {
648656
struct StaticSampler {
649-
uint32_t Filter;
650-
uint32_t AddressU;
651-
uint32_t AddressV;
652-
uint32_t AddressW;
657+
dxbc::SamplerFilter Filter;
658+
dxbc::TextureAddressMode AddressU;
659+
dxbc::TextureAddressMode AddressV;
660+
dxbc::TextureAddressMode AddressW;
653661
float MipLODBias;
654662
uint32_t MaxAnisotropy;
655-
uint32_t ComparisonFunc;
656-
uint32_t BorderColor;
663+
dxbc::ComparisonFunc ComparisonFunc;
664+
dxbc::StaticBorderColor BorderColor;
657665
float MinLOD;
658666
float MaxLOD;
659667
uint32_t ShaderRegister;
660668
uint32_t RegisterSpace;
661-
uint32_t ShaderVisibility;
669+
dxbc::ShaderVisibility ShaderVisibility;
662670
void swapBytes() {
663671
sys::swapByteOrder(Filter);
664672
sys::swapByteOrder(AddressU);
@@ -677,7 +685,7 @@ struct StaticSampler {
677685
};
678686

679687
struct DescriptorRange {
680-
uint32_t RangeType;
688+
dxbc::DescriptorRangeType RangeType;
681689
uint32_t NumDescriptors;
682690
uint32_t BaseShaderRegister;
683691
uint32_t RegisterSpace;
@@ -715,8 +723,8 @@ struct RootConstants {
715723
};
716724

717725
struct RootParameterHeader {
718-
uint32_t ParameterType;
719-
uint32_t ShaderVisibility;
726+
dxbc::RootParameterType ParameterType;
727+
dxbc::ShaderVisibility ShaderVisibility;
720728
uint32_t ParameterOffset;
721729

722730
void swapBytes() {
@@ -760,7 +768,7 @@ struct RootDescriptor : public v1::RootDescriptor {
760768
};
761769

762770
struct DescriptorRange {
763-
uint32_t RangeType;
771+
dxbc::DescriptorRangeType RangeType;
764772
uint32_t NumDescriptors;
765773
uint32_t BaseShaderRegister;
766774
uint32_t RegisterSpace;
@@ -778,12 +786,6 @@ struct DescriptorRange {
778786
} // namespace v2
779787
} // namespace RTS0
780788

781-
// D3D_ROOT_SIGNATURE_VERSION
782-
enum class RootSignatureVersion {
783-
V1_0 = 0x1,
784-
V1_1 = 0x2,
785-
};
786-
787789
} // namespace dxbc
788790
} // namespace llvm
789791

llvm/include/llvm/Frontend/HLSL/RootSignatureMetadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class MetadataParser {
143143
MetadataParser(MDNode *Root) : Root(Root) {}
144144

145145
LLVM_ABI llvm::Expected<llvm::mcdxbc::RootSignatureDesc>
146-
ParseRootSignature(uint32_t Version);
146+
ParseRootSignature(dxbc::RootSignatureVersion Version);
147147

148148
private:
149149
llvm::Error parseRootFlags(mcdxbc::RootSignatureDesc &RSD,

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H
1616

1717
#include "llvm/ADT/IntervalMap.h"
18+
#include "llvm/BinaryFormat/DXContainer.h"
1819
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
1920
#include "llvm/Support/Compiler.h"
2021

@@ -25,20 +26,22 @@ namespace rootsig {
2526
// Basic verification of RootElements
2627

2728
LLVM_ABI bool verifyRootFlag(uint32_t Flags);
28-
LLVM_ABI bool verifyVersion(uint32_t Version);
29+
LLVM_ABI bool verifyVersion(dxbc::RootSignatureVersion Version);
2930
LLVM_ABI bool verifyRegisterValue(uint32_t RegisterValue);
3031
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace);
31-
LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
32-
LLVM_ABI bool verifyRangeType(uint32_t Type);
33-
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
32+
LLVM_ABI bool verifyRootDescriptorFlag(dxbc::RootSignatureVersion Version,
33+
uint32_t FlagsVal);
34+
LLVM_ABI bool verifyRangeType(dxbc::DescriptorRangeType Type);
35+
LLVM_ABI bool verifyDescriptorRangeFlag(dxbc::RootSignatureVersion Version,
36+
dxbc::DescriptorRangeType Type,
3437
uint32_t FlagsVal);
3538
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
36-
LLVM_ABI bool verifySamplerFilter(uint32_t Value);
37-
LLVM_ABI bool verifyAddress(uint32_t Address);
39+
LLVM_ABI bool verifySamplerFilter(dxbc::SamplerFilter Value);
40+
LLVM_ABI bool verifyAddress(dxbc::TextureAddressMode Address);
3841
LLVM_ABI bool verifyMipLODBias(float MipLODBias);
3942
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy);
40-
LLVM_ABI bool verifyComparisonFunc(uint32_t ComparisonFunc);
41-
LLVM_ABI bool verifyBorderColor(uint32_t BorderColor);
43+
LLVM_ABI bool verifyComparisonFunc(dxbc::ComparisonFunc ComparisonFunc);
44+
LLVM_ABI bool verifyBorderColor(dxbc::StaticBorderColor BorderColor);
4245
LLVM_ABI bool verifyLOD(float LOD);
4346

4447
} // namespace rootsig

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct RootParametersContainer {
7272
Tables.push_back(Table);
7373
}
7474

75-
std::pair<uint32_t, uint32_t>
75+
std::pair<dxbc::RootParameterType, uint32_t>
7676
getTypeAndLocForParameter(uint32_t Location) const {
7777
const RootParameterInfo &Info = ParametersInfo[Location];
7878
return {Info.Header.ParameterType, Info.Location};
@@ -106,7 +106,7 @@ struct RootParametersContainer {
106106
};
107107
struct RootSignatureDesc {
108108

109-
uint32_t Version = 2U;
109+
dxbc::RootSignatureVersion Version = dxbc::RootSignatureVersion::V1_1;
110110
uint32_t Flags = 0U;
111111
uint32_t RootParameterOffset = 0U;
112112
uint32_t StaticSamplersOffset = 0u;

llvm/include/llvm/Object/DXContainer.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ struct RootParameterView {
146146

147147
struct RootConstantView : RootParameterView {
148148
static bool classof(const RootParameterView *V) {
149-
return V->Header.ParameterType ==
150-
(uint32_t)dxbc::RootParameterType::Constants32Bit;
149+
return V->Header.ParameterType == dxbc::RootParameterType::Constants32Bit;
151150
}
152151

153152
llvm::Expected<dxbc::RTS0::v1::RootConstants> read() {
@@ -157,25 +156,24 @@ struct RootConstantView : RootParameterView {
157156

158157
struct RootDescriptorView : RootParameterView {
159158
static bool classof(const RootParameterView *V) {
160-
return (V->Header.ParameterType ==
161-
llvm::to_underlying(dxbc::RootParameterType::CBV) ||
162-
V->Header.ParameterType ==
163-
llvm::to_underlying(dxbc::RootParameterType::SRV) ||
164-
V->Header.ParameterType ==
165-
llvm::to_underlying(dxbc::RootParameterType::UAV));
159+
return (V->Header.ParameterType == dxbc::RootParameterType::CBV ||
160+
V->Header.ParameterType == dxbc::RootParameterType::SRV ||
161+
V->Header.ParameterType == dxbc::RootParameterType::UAV);
166162
}
167163

168-
llvm::Expected<dxbc::RTS0::v2::RootDescriptor> read(uint32_t Version) {
169-
if (Version == 1) {
164+
llvm::Expected<dxbc::RTS0::v2::RootDescriptor>
165+
read(dxbc::RootSignatureVersion Version) {
166+
if (Version == dxbc::RootSignatureVersion::V1_0) {
170167
auto Descriptor = readParameter<dxbc::RTS0::v1::RootDescriptor>();
171168
if (Error E = Descriptor.takeError())
172169
return E;
173170
return dxbc::RTS0::v2::RootDescriptor(*Descriptor);
174171
}
175-
if (Version != 2)
176-
return make_error<GenericBinaryError>("Invalid Root Signature version: " +
177-
Twine(Version),
178-
object_error::parse_failed);
172+
if (Version != dxbc::RootSignatureVersion::V1_1)
173+
return make_error<GenericBinaryError>(
174+
"Invalid Root Signature version: " +
175+
Twine(static_cast<uint32_t>(Version)),
176+
object_error::parse_failed);
179177
return readParameter<dxbc::RTS0::v2::RootDescriptor>();
180178
}
181179
};
@@ -192,7 +190,7 @@ template <typename T> struct DescriptorTable {
192190
struct DescriptorTableView : RootParameterView {
193191
static bool classof(const RootParameterView *V) {
194192
return (V->Header.ParameterType ==
195-
llvm::to_underlying(dxbc::RootParameterType::DescriptorTable));
193+
dxbc::RootParameterType::DescriptorTable);
196194
}
197195

198196
// Define a type alias to access the template parameter from inside classof
@@ -220,7 +218,7 @@ static Error parseFailed(const Twine &Msg) {
220218

221219
class RootSignature {
222220
private:
223-
uint32_t Version;
221+
dxbc::RootSignatureVersion Version;
224222
uint32_t NumParameters;
225223
uint32_t RootParametersOffset;
226224
uint32_t NumStaticSamplers;
@@ -238,7 +236,7 @@ class RootSignature {
238236
RootSignature(StringRef PD) : PartData(PD) {}
239237

240238
LLVM_ABI Error parse();
241-
uint32_t getVersion() const { return Version; }
239+
dxbc::RootSignatureVersion getVersion() const { return Version; }
242240
uint32_t getNumParameters() const { return NumParameters; }
243241
uint32_t getRootParametersOffset() const { return RootParametersOffset; }
244242
uint32_t getNumStaticSamplers() const { return NumStaticSamplers; }
@@ -269,7 +267,7 @@ class RootSignature {
269267
case dxbc::RootParameterType::CBV:
270268
case dxbc::RootParameterType::SRV:
271269
case dxbc::RootParameterType::UAV:
272-
if (Version == 1)
270+
if (Version == dxbc::RootSignatureVersion::V1_0)
273271
DataSize = sizeof(dxbc::RTS0::v1::RootDescriptor);
274272
else
275273
DataSize = sizeof(dxbc::RTS0::v2::RootDescriptor);
@@ -281,7 +279,7 @@ class RootSignature {
281279
uint32_t NumRanges =
282280
support::endian::read<uint32_t, llvm::endianness::little>(
283281
PartData.begin() + Header.ParameterOffset);
284-
if (Version == 1)
282+
if (Version == dxbc::RootSignatureVersion::V1_0)
285283
DataSize = sizeof(dxbc::RTS0::v1::DescriptorRange) * NumRanges;
286284
else
287285
DataSize = sizeof(dxbc::RTS0::v2::DescriptorRange) * NumRanges;

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct RootDescriptorYaml {
9292
};
9393

9494
struct DescriptorRangeYaml {
95-
uint32_t RangeType;
95+
dxbc::DescriptorRangeType RangeType;
9696
uint32_t NumDescriptors;
9797
uint32_t BaseShaderRegister;
9898
uint32_t RegisterSpace;
@@ -111,12 +111,12 @@ struct DescriptorTableYaml {
111111
};
112112

113113
struct RootParameterHeaderYaml {
114-
uint32_t Type;
115-
uint32_t Visibility;
114+
dxbc::RootParameterType Type;
115+
dxbc::ShaderVisibility Visibility;
116116
uint32_t Offset;
117117

118118
RootParameterHeaderYaml(){};
119-
RootParameterHeaderYaml(uint32_t T) : Type(T) {}
119+
RootParameterHeaderYaml(dxbc::RootParameterType T) : Type(T) {}
120120
};
121121

122122
struct RootParameterLocationYaml {
@@ -165,27 +165,25 @@ struct RootParameterYamlDesc {
165165
};
166166

167167
struct StaticSamplerYamlDesc {
168-
uint32_t Filter = llvm::to_underlying(dxbc::SamplerFilter::Anisotropic);
169-
uint32_t AddressU = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
170-
uint32_t AddressV = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
171-
uint32_t AddressW = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
168+
dxbc::SamplerFilter Filter = dxbc::SamplerFilter::Anisotropic;
169+
dxbc::TextureAddressMode AddressU = dxbc::TextureAddressMode::Wrap;
170+
dxbc::TextureAddressMode AddressV = dxbc::TextureAddressMode::Wrap;
171+
dxbc::TextureAddressMode AddressW = dxbc::TextureAddressMode::Wrap;
172172
float MipLODBias = 0.f;
173173
uint32_t MaxAnisotropy = 16u;
174-
uint32_t ComparisonFunc =
175-
llvm::to_underlying(dxbc::ComparisonFunc::LessEqual);
176-
uint32_t BorderColor =
177-
llvm::to_underlying(dxbc::StaticBorderColor::OpaqueWhite);
174+
dxbc::ComparisonFunc ComparisonFunc = dxbc::ComparisonFunc::LessEqual;
175+
dxbc::StaticBorderColor BorderColor = dxbc::StaticBorderColor::OpaqueWhite;
178176
float MinLOD = 0.f;
179177
float MaxLOD = std::numeric_limits<float>::max();
180178
uint32_t ShaderRegister;
181179
uint32_t RegisterSpace;
182-
uint32_t ShaderVisibility;
180+
dxbc::ShaderVisibility ShaderVisibility;
183181
};
184182

185183
struct RootSignatureYamlDesc {
186184
RootSignatureYamlDesc() = default;
187185

188-
uint32_t Version;
186+
dxbc::RootSignatureVersion Version;
189187
uint32_t NumRootParameters;
190188
uint32_t RootParametersOffset;
191189
uint32_t NumStaticSamplers;
@@ -321,6 +319,14 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ResourceKind)
321319
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::D3DSystemValue)
322320
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigComponentType)
323321
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigMinPrecision)
322+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::ShaderVisibility)
323+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::RootParameterType)
324+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::DescriptorRangeType)
325+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SamplerFilter)
326+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::TextureAddressMode)
327+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::StaticBorderColor)
328+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::ComparisonFunc)
329+
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::RootSignatureVersion)
324330

325331
namespace llvm {
326332

llvm/lib/BinaryFormat/DXContainer.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ ArrayRef<EnumEntry<StaticBorderColor>> dxbc::getStaticBorderColors() {
139139
return ArrayRef(StaticBorderColorValues);
140140
}
141141

142+
#define DESCRIPTOR_RANGE(Val, Enum) {#Enum, DescriptorRangeType::Enum},
143+
static const EnumEntry<DescriptorRangeType> DescriptorRangeTypeValues[] = {
144+
#include "llvm/BinaryFormat/DXContainerConstants.def"
145+
};
146+
147+
ArrayRef<EnumEntry<DescriptorRangeType>> dxbc::getDescriptorRangeTypes() {
148+
return ArrayRef(DescriptorRangeTypeValues);
149+
}
150+
151+
static const EnumEntry<RootSignatureVersion> RootSignatureVersionsValues[] = {
152+
{"V1_0", RootSignatureVersion::V1_0},
153+
{"V1_1", RootSignatureVersion::V1_1},
154+
};
155+
156+
ArrayRef<EnumEntry<RootSignatureVersion>> dxbc::getRootSignatureVersions() {
157+
return ArrayRef(RootSignatureVersionsValues);
158+
}
159+
142160
#define ROOT_PARAMETER(Val, Enum) {#Enum, RootParameterType::Enum},
143161

144162
static const EnumEntry<RootParameterType> RootParameterTypes[] = {

0 commit comments

Comments
 (0)