Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 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
5 changes: 2 additions & 3 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,9 +1283,8 @@ bool SemaHLSL::handleRootSignatureElements(
ReportError(Loc, 1, 0xfffffffe);
}

if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
Version, llvm::to_underlying(Clause->Type),
llvm::to_underlying(Clause->Flags)))
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(Version, Clause->Type,
Clause->Flags))
ReportFlagError(Loc);
}
}
Expand Down
47 changes: 47 additions & 0 deletions llvm/include/llvm/BinaryFormat/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ inline bool isValidParameterType(uint32_t V) {
return false;
}

inline bool isValidRangeType(uint32_t V) {
static_assert(llvm::to_underlying(dxil::ResourceClass::Sampler) == 3,
"dxil::ResourceClass numeric values must match the Root "
"Signature values associated to each class.");
return V <= llvm::to_underlying(dxil::ResourceClass::Sampler);
}

#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
enum class ShaderVisibility : uint32_t {
#include "DXContainerConstants.def"
Expand All @@ -231,6 +238,16 @@ enum class SamplerFilter : uint32_t {
#include "DXContainerConstants.def"
};

#define FILTER(Val, Enum) \
case Val: \
return true;
inline bool isValidSamplerFilter(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

LLVM_ABI ArrayRef<EnumEntry<SamplerFilter>> getSamplerFilters();

#define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val,
Expand All @@ -240,18 +257,48 @@ enum class TextureAddressMode : uint32_t {

LLVM_ABI ArrayRef<EnumEntry<TextureAddressMode>> getTextureAddressModes();

#define TEXTURE_ADDRESS_MODE(Val, Enum) \
case Val: \
return true;
inline bool isValidAddress(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

#define COMPARISON_FUNC(Val, Enum) Enum = Val,
enum class ComparisonFunc : uint32_t {
#include "DXContainerConstants.def"
};

LLVM_ABI ArrayRef<EnumEntry<ComparisonFunc>> getComparisonFuncs();

#define COMPARISON_FUNC(Val, Enum) \
case Val: \
return true;
inline bool isValidComparisonFunc(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

#define STATIC_BORDER_COLOR(Val, Enum) Enum = Val,
enum class StaticBorderColor : uint32_t {
#include "DXContainerConstants.def"
};

#define STATIC_BORDER_COLOR(Val, Enum) \
case Val: \
return true;
inline bool isValidBorderColor(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

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

LLVM_ABI PartType parsePartType(StringRef S);
Expand Down
10 changes: 0 additions & 10 deletions llvm/include/llvm/BinaryFormat/DXContainerConstants.def
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ DESCRIPTOR_RANGE_FLAG(0x10000, DescriptorsStaticKeepingBufferBoundsChecks, DESCR
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG

// DESCRIPTOR_RANGE(value, name).
#ifdef DESCRIPTOR_RANGE

DESCRIPTOR_RANGE(0, SRV)
DESCRIPTOR_RANGE(1, UAV)
DESCRIPTOR_RANGE(2, CBV)
DESCRIPTOR_RANGE(3, Sampler)
#undef DESCRIPTOR_RANGE
#endif // DESCRIPTOR_RANGE

#ifdef ROOT_PARAMETER

ROOT_PARAMETER(0, DescriptorTable)
Expand Down
9 changes: 3 additions & 6 deletions llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ LLVM_ABI bool verifyRegisterValue(uint32_t RegisterValue);
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace);
LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
LLVM_ABI bool verifyRangeType(uint32_t Type);
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
uint32_t FlagsVal);
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
dxil::ResourceClass Type,
dxbc::DescriptorRangeFlags FlagsVal);
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
LLVM_ABI bool verifySamplerFilter(uint32_t Value);
LLVM_ABI bool verifyAddress(uint32_t Address);
LLVM_ABI bool verifyMipLODBias(float MipLODBias);
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy);
LLVM_ABI bool verifyComparisonFunc(uint32_t ComparisonFunc);
LLVM_ABI bool verifyBorderColor(uint32_t BorderColor);
LLVM_ABI bool verifyLOD(float LOD);

} // namespace rootsig
Expand Down
33 changes: 29 additions & 4 deletions llvm/include/llvm/MC/DXContainerRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ struct RootDescriptor {
uint32_t Flags;
};

struct DescriptorRange {
dxil::ResourceClass RangeType;
uint32_t NumDescriptors;
uint32_t BaseShaderRegister;
uint32_t RegisterSpace;
uint32_t Flags;
uint32_t OffsetInDescriptorsFromTableStart;
};

struct RootParameterInfo {
dxbc::RootParameterType Type;
dxbc::ShaderVisibility Visibility;
Expand All @@ -42,15 +51,31 @@ struct RootParameterInfo {
};

struct DescriptorTable {
SmallVector<dxbc::RTS0::v2::DescriptorRange> Ranges;
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator begin() const {
SmallVector<DescriptorRange> Ranges;
SmallVector<DescriptorRange>::const_iterator begin() const {
return Ranges.begin();
}
SmallVector<dxbc::RTS0::v2::DescriptorRange>::const_iterator end() const {
SmallVector<DescriptorRange>::const_iterator end() const {
return Ranges.end();
}
};

struct StaticSampler {
dxbc::SamplerFilter Filter;
dxbc::TextureAddressMode AddressU;
dxbc::TextureAddressMode AddressV;
dxbc::TextureAddressMode AddressW;
float MipLODBias;
uint32_t MaxAnisotropy;
dxbc::ComparisonFunc ComparisonFunc;
dxbc::StaticBorderColor BorderColor;
float MinLOD;
float MaxLOD;
uint32_t ShaderRegister;
uint32_t RegisterSpace;
dxbc::ShaderVisibility ShaderVisibility;
};

struct RootParametersContainer {
SmallVector<RootParameterInfo> ParametersInfo;

Expand Down Expand Up @@ -116,7 +141,7 @@ struct RootSignatureDesc {
uint32_t StaticSamplersOffset = 0u;
uint32_t NumStaticSamplers = 0u;
mcdxbc::RootParametersContainer ParametersContainer;
SmallVector<dxbc::RTS0::v1::StaticSampler> StaticSamplers;
SmallVector<StaticSampler> StaticSamplers;

LLVM_ABI void write(raw_ostream &OS) const;

Expand Down
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;
dxbc::DescriptorRangeType 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(llvm::dxbc::DescriptorRangeType)
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
Loading
Loading