Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
31ec5e5
making parameter type and shader visibility use enums
joaosaffran Aug 19, 2025
1690a9c
clean up
joaosaffran Aug 19, 2025
f6f2e61
removing root parameter header from MC
joaosaffran Aug 19, 2025
6539364
clean up
joaosaffran Aug 19, 2025
1d29111
fix whitespace in test
joaosaffran Aug 19, 2025
8eb82fd
adding missing import
joaosaffran Aug 19, 2025
d38c00d
remove unused
joaosaffran Aug 19, 2025
3b25b34
save a copy
joaosaffran Aug 19, 2025
567a3d4
remove default constructor
joaosaffran Aug 19, 2025
fb248da
rename visibility
joaosaffran Aug 19, 2025
dc436d5
remove cstdint
joaosaffran Aug 19, 2025
8353fe0
remove Loc
joaosaffran Aug 19, 2025
f3ecd8a
removing dependency of Object
joaosaffran Aug 20, 2025
8c143ba
removing binary format descriptor range dependency
joaosaffran Aug 20, 2025
e57236c
removing binaryformat dependency on mc
joaosaffran Aug 20, 2025
a4d77d7
Revert "removing binary format descriptor range dependency"
joaosaffran Aug 20, 2025
4b9991d
updating object to yaml to account for enums
joaosaffran Aug 21, 2025
04df258
updating tests
joaosaffran Aug 21, 2025
19ec1c3
Merge branch 'main' into refactoring/updating-descriptor-range
joaosaffran Aug 29, 2025
182c817
removing binary format descriptor range dependency
joaosaffran Aug 20, 2025
f9d16d2
creating toDescriptorRange and change verifyDescriptorRangeFlag signa…
joaosaffran Aug 29, 2025
42f8f11
adding test and removing string switch
joaosaffran Aug 29, 2025
7ada31b
removing copy
joaosaffran Aug 29, 2025
fa60959
clean up
joaosaffran Aug 30, 2025
e065a82
removing function I thought I needed
joaosaffran Sep 6, 2025
17dbe9f
refactoring to use dxil::ResourceClass for range type
joaosaffran Sep 8, 2025
5c23b7e
adding assert
joaosaffran Sep 8, 2025
1c539f0
changing casting to use proper llvm-casting
joaosaffran Sep 8, 2025
716acfb
Merge branch 'refactoring/updating-descriptor-range' into refactoring…
joaosaffran Sep 8, 2025
43582d2
Merge branch 'refactoring/updating-static-samplers' into refactoring/…
joaosaffran Sep 8, 2025
44bfe7a
fixing tests
joaosaffran Sep 9, 2025
6757986
Merge branch 'main' into refactoring/using-enums-yaml
joaosaffran Sep 11, 2025
3ebaa29
clean up
joaosaffran Sep 11, 2025
e84f811
Merge branch 'main' into refactoring/using-enums-yaml
joaosaffran Sep 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions llvm/include/llvm/ObjectYAML/DXContainerYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct RootDescriptorYaml {
};

struct DescriptorRangeYaml {
uint32_t RangeType;
dxil::ResourceClass RangeType;
uint32_t NumDescriptors;
uint32_t BaseShaderRegister;
uint32_t RegisterSpace;
Expand All @@ -111,12 +111,12 @@ struct DescriptorTableYaml {
};

struct RootParameterHeaderYaml {
uint32_t Type;
uint32_t Visibility;
dxbc::RootParameterType Type;
dxbc::ShaderVisibility Visibility;
uint32_t Offset;

RootParameterHeaderYaml(){};
RootParameterHeaderYaml(uint32_t T) : Type(T) {}
RootParameterHeaderYaml(dxbc::RootParameterType T) : Type(T) {}
};

struct RootParameterLocationYaml {
Expand Down Expand Up @@ -165,21 +165,19 @@ struct RootParameterYamlDesc {
};

struct StaticSamplerYamlDesc {
uint32_t Filter = llvm::to_underlying(dxbc::SamplerFilter::Anisotropic);
uint32_t AddressU = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
uint32_t AddressV = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
uint32_t AddressW = llvm::to_underlying(dxbc::TextureAddressMode::Wrap);
dxbc::SamplerFilter Filter = dxbc::SamplerFilter::Anisotropic;
dxbc::TextureAddressMode AddressU = dxbc::TextureAddressMode::Wrap;
dxbc::TextureAddressMode AddressV = dxbc::TextureAddressMode::Wrap;
dxbc::TextureAddressMode AddressW = dxbc::TextureAddressMode::Wrap;
float MipLODBias = 0.f;
uint32_t MaxAnisotropy = 16u;
uint32_t ComparisonFunc =
llvm::to_underlying(dxbc::ComparisonFunc::LessEqual);
uint32_t BorderColor =
llvm::to_underlying(dxbc::StaticBorderColor::OpaqueWhite);
dxbc::ComparisonFunc ComparisonFunc = dxbc::ComparisonFunc::LessEqual;
dxbc::StaticBorderColor BorderColor = dxbc::StaticBorderColor::OpaqueWhite;
float MinLOD = 0.f;
float MaxLOD = std::numeric_limits<float>::max();
uint32_t ShaderRegister;
uint32_t RegisterSpace;
uint32_t ShaderVisibility;
dxbc::ShaderVisibility ShaderVisibility;
};

struct RootSignatureYamlDesc {
Expand Down Expand Up @@ -321,6 +319,13 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ResourceKind)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::D3DSystemValue)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigComponentType)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SigMinPrecision)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::RootParameterType)
LLVM_YAML_DECLARE_ENUM_TRAITS(dxil::ResourceClass)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::SamplerFilter)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::StaticBorderColor)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::TextureAddressMode)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::ShaderVisibility)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::ComparisonFunc)

namespace llvm {

Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/Support/DXILABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const unsigned MinWaveSize = 4;
const unsigned MaxWaveSize = 128;

LLVM_ABI StringRef getResourceClassName(ResourceClass RC);

} // namespace dxil
} // namespace llvm

Expand Down
37 changes: 10 additions & 27 deletions llvm/lib/ObjectYAML/DXContainerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,8 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
for (DXContainerYAML::RootParameterLocationYaml &L :
P.RootSignature->Parameters.Locations) {

assert(dxbc::isValidParameterType(L.Header.Type) &&
"invalid DXContainer YAML");
assert(dxbc::isValidShaderVisibility(L.Header.Visibility) &&
"invalid DXContainer YAML");
dxbc::RootParameterType Type = dxbc::RootParameterType(L.Header.Type);
dxbc::ShaderVisibility Visibility =
dxbc::ShaderVisibility(L.Header.Visibility);
const dxbc::RootParameterType Type = L.Header.Type;
const dxbc::ShaderVisibility Visibility = L.Header.Visibility;

switch (Type) {
case dxbc::RootParameterType::Constants32Bit: {
Expand Down Expand Up @@ -313,10 +308,8 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
P.RootSignature->Parameters.getOrInsertTable(L);
mcdxbc::DescriptorTable Table;
for (const auto &R : TableYaml.Ranges) {
assert(dxbc::isValidRangeType(R.RangeType) &&
"Invalid Descriptor Range Type");
mcdxbc::DescriptorRange Range;
Range.RangeType = dxil::ResourceClass(R.RangeType);
Range.RangeType = R.RangeType;
Range.NumDescriptors = R.NumDescriptors;
Range.BaseShaderRegister = R.BaseShaderRegister;
Range.RegisterSpace = R.RegisterSpace;
Expand All @@ -335,30 +328,20 @@ Error DXContainerWriter::writeParts(raw_ostream &OS) {
}

for (const auto &Param : P.RootSignature->samplers()) {
assert(dxbc::isValidSamplerFilter(Param.Filter) &&
dxbc::isValidAddress(Param.AddressU) &&
dxbc::isValidAddress(Param.AddressV) &&
dxbc::isValidAddress(Param.AddressW) &&
dxbc::isValidComparisonFunc(Param.ComparisonFunc) &&
dxbc::isValidBorderColor(Param.BorderColor) &&
dxbc::isValidShaderVisibility(Param.ShaderVisibility) &&
"Invalid enum value in static sampler");

Comment on lines -338 to -346
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since those are now enums, they are validated during enum parsing, therefore, these values don't require validation anymore.

mcdxbc::StaticSampler NewSampler;
NewSampler.Filter = dxbc::SamplerFilter(Param.Filter);
NewSampler.AddressU = dxbc::TextureAddressMode(Param.AddressU);
NewSampler.AddressV = dxbc::TextureAddressMode(Param.AddressV);
NewSampler.AddressW = dxbc::TextureAddressMode(Param.AddressW);
NewSampler.Filter = Param.Filter;
NewSampler.AddressU = Param.AddressU;
NewSampler.AddressV = Param.AddressV;
NewSampler.AddressW = Param.AddressW;
NewSampler.MipLODBias = Param.MipLODBias;
NewSampler.MaxAnisotropy = Param.MaxAnisotropy;
NewSampler.ComparisonFunc = dxbc::ComparisonFunc(Param.ComparisonFunc);
NewSampler.BorderColor = dxbc::StaticBorderColor(Param.BorderColor);
NewSampler.ComparisonFunc = Param.ComparisonFunc;
NewSampler.BorderColor = Param.BorderColor;
NewSampler.MinLOD = Param.MinLOD;
NewSampler.MaxLOD = Param.MaxLOD;
NewSampler.ShaderRegister = Param.ShaderRegister;
NewSampler.RegisterSpace = Param.RegisterSpace;
NewSampler.ShaderVisibility =
dxbc::ShaderVisibility(Param.ShaderVisibility);
NewSampler.ShaderVisibility = Param.ShaderVisibility;

RS.StaticSamplers.push_back(NewSampler);
}
Expand Down
113 changes: 97 additions & 16 deletions llvm/lib/ObjectYAML/DXContainerYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ readDescriptorRanges(DXContainerYAML::RootParameterHeaderYaml &Header,
NewR.NumDescriptors = R.NumDescriptors;
NewR.BaseShaderRegister = R.BaseShaderRegister;
NewR.RegisterSpace = R.RegisterSpace;
NewR.RangeType = R.RangeType;
if (!dxbc::isValidRangeType(R.RangeType))
return createStringError(std::errc::invalid_argument,
"Invalid value for descriptor range type");
NewR.RangeType = dxil::ResourceClass(R.RangeType);
if constexpr (std::is_same_v<T, dxbc::RTS0::v2::DescriptorRange>) {
// Set all flag fields for v2
#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \
Expand Down Expand Up @@ -94,15 +97,14 @@ DXContainerYAML::RootSignatureYamlDesc::create(
return createStringError(std::errc::invalid_argument,
"Invalid value for parameter type");

RootParameterHeaderYaml Header(PH.ParameterType);
RootParameterHeaderYaml Header(dxbc::RootParameterType(PH.ParameterType));
Header.Offset = PH.ParameterOffset;
Header.Type = PH.ParameterType;

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

Header.Visibility = PH.ShaderVisibility;
Header.Visibility = dxbc::ShaderVisibility(PH.ShaderVisibility);

llvm::Expected<object::DirectX::RootParameterView> ParamViewOrErr =
Data.getParameter(PH);
Expand Down Expand Up @@ -162,20 +164,50 @@ DXContainerYAML::RootSignatureYamlDesc::create(
}

for (const auto &S : Data.samplers()) {
if (!dxbc::isValidSamplerFilter(S.Filter))
return createStringError(std::errc::invalid_argument,
"Invalid value for static sampler filter");

if (!dxbc::isValidAddress(S.AddressU))
return createStringError(std::errc::invalid_argument,
"Invalid value for static sampler AddressU");

if (!dxbc::isValidAddress(S.AddressV))
return createStringError(std::errc::invalid_argument,
"Invalid value for static sampler AddressV");

if (!dxbc::isValidAddress(S.AddressW))
return createStringError(std::errc::invalid_argument,
"Invalid value for static sampler AddressW");

if (!dxbc::isValidComparisonFunc(S.ComparisonFunc))
return createStringError(
std::errc::invalid_argument,
"Invalid value for static sampler ComparisonFunc");

if (!dxbc::isValidBorderColor(S.BorderColor))
return createStringError(std::errc::invalid_argument,
"Invalid value for static sampler BorderColor");

if (!dxbc::isValidShaderVisibility(S.ShaderVisibility))
return createStringError(
std::errc::invalid_argument,
"Invalid value for static sampler ShaderVisibility");

StaticSamplerYamlDesc NewS;
NewS.Filter = S.Filter;
NewS.AddressU = S.AddressU;
NewS.AddressV = S.AddressV;
NewS.AddressW = S.AddressW;
NewS.Filter = dxbc::SamplerFilter(S.Filter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed removing these casts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those castings are required here. They are coming from the binary representation, so they are actually uint32_t, the casting are moving the data into the internal representations, which use the enums.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also ran ninja check-all, and the objcopy tests passed.

NewS.AddressU = dxbc::TextureAddressMode(S.AddressU);
NewS.AddressV = dxbc::TextureAddressMode(S.AddressV);
NewS.AddressW = dxbc::TextureAddressMode(S.AddressW);
NewS.MipLODBias = S.MipLODBias;
NewS.MaxAnisotropy = S.MaxAnisotropy;
NewS.ComparisonFunc = S.ComparisonFunc;
NewS.BorderColor = S.BorderColor;
NewS.ComparisonFunc = dxbc::ComparisonFunc(S.ComparisonFunc);
NewS.BorderColor = dxbc::StaticBorderColor(S.BorderColor);
NewS.MinLOD = S.MinLOD;
NewS.MaxLOD = S.MaxLOD;
NewS.ShaderRegister = S.ShaderRegister;
NewS.RegisterSpace = S.RegisterSpace;
NewS.ShaderVisibility = S.ShaderVisibility;
NewS.ShaderVisibility = dxbc::ShaderVisibility(S.ShaderVisibility);

RootSigDesc.StaticSamplers.push_back(NewS);
}
Expand Down Expand Up @@ -425,21 +457,21 @@ void MappingContextTraits<DXContainerYAML::RootParameterLocationYaml,
IO.mapRequired("ShaderVisibility", L.Header.Visibility);

switch (L.Header.Type) {
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
case dxbc::RootParameterType::Constants32Bit: {
DXContainerYAML::RootConstantsYaml &Constants =
S.Parameters.getOrInsertConstants(L);
IO.mapRequired("Constants", Constants);
break;
}
case llvm::to_underlying(dxbc::RootParameterType::CBV):
case llvm::to_underlying(dxbc::RootParameterType::SRV):
case llvm::to_underlying(dxbc::RootParameterType::UAV): {
case dxbc::RootParameterType::CBV:
case dxbc::RootParameterType::SRV:
case dxbc::RootParameterType::UAV: {
DXContainerYAML::RootDescriptorYaml &Descriptor =
S.Parameters.getOrInsertDescriptor(L);
IO.mapRequired("Descriptor", Descriptor);
break;
}
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): {
case dxbc::RootParameterType::DescriptorTable: {
DXContainerYAML::DescriptorTableYaml &Table =
S.Parameters.getOrInsertTable(L);
IO.mapRequired("Table", Table);
Expand Down Expand Up @@ -585,6 +617,55 @@ void ScalarEnumerationTraits<dxbc::SigComponentType>::enumeration(
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxbc::RootParameterType>::enumeration(
IO &IO, dxbc::RootParameterType &Value) {
for (const auto &E : dxbc::getRootParameterTypes())
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxil::ResourceClass>::enumeration(
IO &IO, dxil::ResourceClass &Value) {
const EnumEntry<dxil::ResourceClass> ResourceClasses[] = {
{"CBuffer", dxil::ResourceClass::CBuffer},
{"SRV", dxil::ResourceClass::SRV},
{"UAV", dxil::ResourceClass::UAV},
{"Sampler", dxil::ResourceClass::Sampler},
};

for (const auto &E : ResourceClasses)
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxbc::SamplerFilter>::enumeration(
IO &IO, dxbc::SamplerFilter &Value) {
for (const auto &E : dxbc::getSamplerFilters())
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxbc::StaticBorderColor>::enumeration(
IO &IO, dxbc::StaticBorderColor &Value) {
for (const auto &E : dxbc::getStaticBorderColors())
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxbc::TextureAddressMode>::enumeration(
IO &IO, dxbc::TextureAddressMode &Value) {
for (const auto &E : dxbc::getTextureAddressModes())
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxbc::ShaderVisibility>::enumeration(
IO &IO, dxbc::ShaderVisibility &Value) {
for (const auto &E : dxbc::getShaderVisibility())
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

void ScalarEnumerationTraits<dxbc::ComparisonFunc>::enumeration(
IO &IO, dxbc::ComparisonFunc &Value) {
for (const auto &E : dxbc::getComparisonFuncs())
IO.enumCase(Value, E.Name.str().c_str(), E.Value);
}

} // namespace yaml

void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) {
Expand Down
Loading