Skip to content

Commit 4b9991d

Browse files
committed
updating object to yaml to account for enums
1 parent e57236c commit 4b9991d

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 10 additions & 12 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,16 +165,14 @@ 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;

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ readDescriptorRanges(DXContainerYAML::RootParameterHeaderYaml &Header,
6060
NewR.NumDescriptors = R.NumDescriptors;
6161
NewR.BaseShaderRegister = R.BaseShaderRegister;
6262
NewR.RegisterSpace = R.RegisterSpace;
63-
NewR.RangeType = R.RangeType;
63+
if (!dxbc::isValidRangeType(R.RangeType))
64+
return createStringError(std::errc::invalid_argument,
65+
"Invalid value for descriptor range type");
66+
NewR.RangeType = dxbc::DescriptorRangeType(R.RangeType);
6467
if constexpr (std::is_same_v<T, dxbc::RTS0::v2::DescriptorRange>) {
6568
// Set all flag fields for v2
6669
#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \
@@ -94,15 +97,14 @@ DXContainerYAML::RootSignatureYamlDesc::create(
9497
return createStringError(std::errc::invalid_argument,
9598
"Invalid value for parameter type");
9699

97-
RootParameterHeaderYaml Header(PH.ParameterType);
100+
RootParameterHeaderYaml Header(dxbc::RootParameterType(PH.ParameterType));
98101
Header.Offset = PH.ParameterOffset;
99-
Header.Type = PH.ParameterType;
100102

101103
if (!dxbc::isValidShaderVisibility(PH.ShaderVisibility))
102104
return createStringError(std::errc::invalid_argument,
103105
"Invalid value for shader visibility");
104106

105-
Header.Visibility = PH.ShaderVisibility;
107+
Header.Visibility = dxbc::ShaderVisibility(PH.ShaderVisibility);
106108

107109
llvm::Expected<object::DirectX::RootParameterView> ParamViewOrErr =
108110
Data.getParameter(PH);
@@ -162,15 +164,40 @@ DXContainerYAML::RootSignatureYamlDesc::create(
162164
}
163165

164166
for (const auto &S : Data.samplers()) {
167+
if (!dxbc::isValidSamplerFilter(S.Filter))
168+
return createStringError(std::errc::invalid_argument,
169+
"Invalid value for static sampler filter");
170+
171+
if (!dxbc::isValidAddress(S.AddressU))
172+
return createStringError(std::errc::invalid_argument,
173+
"Invalid value for static sampler AddressU");
174+
175+
if (!dxbc::isValidAddress(S.AddressV))
176+
return createStringError(std::errc::invalid_argument,
177+
"Invalid value for static sampler AddressV");
178+
179+
if (!dxbc::isValidAddress(S.AddressW))
180+
return createStringError(std::errc::invalid_argument,
181+
"Invalid value for static sampler AddressW");
182+
183+
if (!dxbc::isValidComparisonFunc(S.ComparisonFunc))
184+
return createStringError(
185+
std::errc::invalid_argument,
186+
"Invalid value for static sampler ComparisonFunc");
187+
188+
if (!dxbc::isValidBorderColor(S.BorderColor))
189+
return createStringError(std::errc::invalid_argument,
190+
"Invalid value for static sampler BorderColor");
191+
165192
StaticSamplerYamlDesc NewS;
166-
NewS.Filter = S.Filter;
167-
NewS.AddressU = S.AddressU;
168-
NewS.AddressV = S.AddressV;
169-
NewS.AddressW = S.AddressW;
193+
NewS.Filter = dxbc::SamplerFilter(S.Filter);
194+
NewS.AddressU = dxbc::TextureAddressMode(S.AddressU);
195+
NewS.AddressV = dxbc::TextureAddressMode(S.AddressV);
196+
NewS.AddressW = dxbc::TextureAddressMode(S.AddressW);
170197
NewS.MipLODBias = S.MipLODBias;
171198
NewS.MaxAnisotropy = S.MaxAnisotropy;
172-
NewS.ComparisonFunc = S.ComparisonFunc;
173-
NewS.BorderColor = S.BorderColor;
199+
NewS.ComparisonFunc = dxbc::ComparisonFunc(S.ComparisonFunc);
200+
NewS.BorderColor = dxbc::StaticBorderColor(S.BorderColor);
174201
NewS.MinLOD = S.MinLOD;
175202
NewS.MaxLOD = S.MaxLOD;
176203
NewS.ShaderRegister = S.ShaderRegister;
@@ -425,21 +452,21 @@ void MappingContextTraits<DXContainerYAML::RootParameterLocationYaml,
425452
IO.mapRequired("ShaderVisibility", L.Header.Visibility);
426453

427454
switch (L.Header.Type) {
428-
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
455+
case dxbc::RootParameterType::Constants32Bit: {
429456
DXContainerYAML::RootConstantsYaml &Constants =
430457
S.Parameters.getOrInsertConstants(L);
431458
IO.mapRequired("Constants", Constants);
432459
break;
433460
}
434-
case llvm::to_underlying(dxbc::RootParameterType::CBV):
435-
case llvm::to_underlying(dxbc::RootParameterType::SRV):
436-
case llvm::to_underlying(dxbc::RootParameterType::UAV): {
461+
case dxbc::RootParameterType::CBV:
462+
case dxbc::RootParameterType::SRV:
463+
case dxbc::RootParameterType::UAV: {
437464
DXContainerYAML::RootDescriptorYaml &Descriptor =
438465
S.Parameters.getOrInsertDescriptor(L);
439466
IO.mapRequired("Descriptor", Descriptor);
440467
break;
441468
}
442-
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): {
469+
case dxbc::RootParameterType::DescriptorTable: {
443470
DXContainerYAML::DescriptorTableYaml &Table =
444471
S.Parameters.getOrInsertTable(L);
445472
IO.mapRequired("Table", Table);

0 commit comments

Comments
 (0)