Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 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
a4d77d7
Revert "removing binary format descriptor range dependency"
joaosaffran Aug 20, 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
4074ceb
removing unused code
joaosaffran Sep 9, 2025
36afa22
removing assert and adding lastEntry
joaosaffran Sep 10, 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: 27 additions & 4 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,34 @@ bool SemaHLSL::handleRootSignatureElements(
// value
ReportError(Loc, 1, 0xfffffffe);
}
switch (Clause->Type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be simpler with a toDescriptorRangeType() helper (whether as a static function or even just a lambda). Also, the flags argument to verifyDescriptorRangeFlag looks like it's just immediately cast back to a dxbc::DescriptorRangeFlags - we should just update the signature to take the enum in the first place.

      if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
              Version, toDescriptorRangeType(Clause->Type), Clause->Flags))
        ReportFlagError(Loc);


if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
Version, llvm::to_underlying(Clause->Type),
llvm::to_underlying(Clause->Flags)))
ReportFlagError(Loc);
case llvm::dxil::ResourceClass::SRV:
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
Version, llvm::dxbc::DescriptorRangeType::SRV,
llvm::to_underlying(Clause->Flags)))
ReportFlagError(Loc);
break;
case llvm::dxil::ResourceClass::UAV:
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
Version, llvm::dxbc::DescriptorRangeType::UAV,
llvm::to_underlying(Clause->Flags)))
ReportFlagError(Loc);
break;
case llvm::dxil::ResourceClass::CBuffer:
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
Version, llvm::dxbc::DescriptorRangeType::CBV,
llvm::to_underlying(Clause->Flags)))
ReportFlagError(Loc);
break;
case llvm::dxil::ResourceClass::Sampler:
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
Version, llvm::dxbc::DescriptorRangeType::Sampler,
llvm::to_underlying(Clause->Flags)))
ReportFlagError(Loc);
break;
break;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/BinaryFormat/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ inline bool isValidParameterType(uint32_t V) {
return false;
}

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

#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
enum class ShaderVisibility : uint32_t {
#include "DXContainerConstants.def"
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ 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,
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version,
dxbc::DescriptorRangeType Type,
uint32_t FlagsVal);
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
LLVM_ABI bool verifySamplerFilter(uint32_t Value);
Expand Down
83 changes: 48 additions & 35 deletions llvm/include/llvm/MC/DXContainerRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,75 +19,88 @@ namespace llvm {
class raw_ostream;
namespace mcdxbc {

struct RootConstants {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
uint32_t Num32BitValues;
};

struct RootDescriptor {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
uint32_t Flags;
};

struct DescriptorRange {
dxbc::DescriptorRangeType RangeType;
uint32_t NumDescriptors;
uint32_t BaseShaderRegister;
uint32_t RegisterSpace;
uint32_t Flags;
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 decided to keep the flags as uint32_t, since the flags are not mutually exclusive.

uint32_t OffsetInDescriptorsFromTableStart;
};

struct RootParameterInfo {
dxbc::RTS0::v1::RootParameterHeader Header;
dxbc::RootParameterType Type;
dxbc::ShaderVisibility Visibility;
size_t Location;

RootParameterInfo() = default;

RootParameterInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location)
: Header(Header), Location(Location) {}
RootParameterInfo(dxbc::RootParameterType Type,
dxbc::ShaderVisibility Visibility, size_t Location)
: Type(Type), Visibility(Visibility), Location(Location) {}
};

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 RootParametersContainer {
SmallVector<RootParameterInfo> ParametersInfo;

SmallVector<dxbc::RTS0::v1::RootConstants> Constants;
SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;
SmallVector<RootConstants> Constants;
SmallVector<RootDescriptor> Descriptors;
SmallVector<DescriptorTable> Tables;

void addInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) {
ParametersInfo.push_back(RootParameterInfo(Header, Location));
void addInfo(dxbc::RootParameterType Type, dxbc::ShaderVisibility Visibility,
size_t Location) {
ParametersInfo.emplace_back(Type, Visibility, Location);
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
dxbc::RTS0::v1::RootConstants Constant) {
addInfo(Header, Constants.size());
void addParameter(dxbc::RootParameterType Type,
dxbc::ShaderVisibility Visibility, RootConstants Constant) {
addInfo(Type, Visibility, Constants.size());
Constants.push_back(Constant);
}

void addInvalidParameter(dxbc::RTS0::v1::RootParameterHeader Header) {
addInfo(Header, -1);
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
dxbc::RTS0::v2::RootDescriptor Descriptor) {
addInfo(Header, Descriptors.size());
void addParameter(dxbc::RootParameterType Type,
dxbc::ShaderVisibility Visibility,
RootDescriptor Descriptor) {
addInfo(Type, Visibility, Descriptors.size());
Descriptors.push_back(Descriptor);
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader Header,
DescriptorTable Table) {
addInfo(Header, Tables.size());
void addParameter(dxbc::RootParameterType Type,
dxbc::ShaderVisibility Visibility, DescriptorTable Table) {
addInfo(Type, Visibility, Tables.size());
Tables.push_back(Table);
}

std::pair<uint32_t, uint32_t>
getTypeAndLocForParameter(uint32_t Location) const {
const RootParameterInfo &Info = ParametersInfo[Location];
return {Info.Header.ParameterType, Info.Location};
}

const dxbc::RTS0::v1::RootParameterHeader &getHeader(size_t Location) const {
const RootParameterInfo &getInfo(uint32_t Location) const {
const RootParameterInfo &Info = ParametersInfo[Location];
return Info.Header;
return Info;
}

const dxbc::RTS0::v1::RootConstants &getConstant(size_t Index) const {
const RootConstants &getConstant(size_t Index) const {
return Constants[Index];
}

const dxbc::RTS0::v2::RootDescriptor &getRootDescriptor(size_t Index) const {
const RootDescriptor &getRootDescriptor(size_t Index) const {
return Descriptors[Index];
}

Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/BinaryFormat/DXContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ ArrayRef<EnumEntry<RootParameterType>> dxbc::getRootParameterTypes() {
return ArrayRef(RootParameterTypes);
}

#define DESCRIPTOR_RANGE(Val, Enum) {#Enum, DescriptorRangeType::Enum},

static const EnumEntry<DescriptorRangeType> DescriptorRangeTypes[] = {
#include "llvm/BinaryFormat/DXContainerConstants.def"
};

ArrayRef<EnumEntry<DescriptorRangeType>> dxbc::getDescriptorRangeTypes() {
Copy link
Contributor Author

@joaosaffran joaosaffran Aug 30, 2025

Choose a reason for hiding this comment

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

Replicating the pattern to use with enumToStringRef

return ArrayRef(DescriptorRangeTypes);
}

#define SEMANTIC_KIND(Val, Enum) {#Enum, PSV::SemanticKind::Enum},

static const EnumEntry<PSV::SemanticKind> SemanticKindNames[] = {
Expand Down
Loading