Skip to content

[DXIL][Analysis] Make the DXILResource binding optional. NFC #100623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
88 changes: 41 additions & 47 deletions llvm/include/llvm/Analysis/DXILResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ class MDTuple;

namespace dxil {

struct ResourceBinding {
uint32_t Space;
uint32_t LowerBound;
uint32_t Size;

bool operator==(const ResourceBinding &RHS) const {
return std::tie(Space, LowerBound, Size) ==
std::tie(RHS.Space, RHS.LowerBound, RHS.Size);
}
bool operator!=(const ResourceBinding &RHS) const { return !(*this == RHS); }
};

class ResourceInfo {
struct ResourceBinding {
uint32_t UniqueID;
uint32_t Space;
uint32_t LowerBound;
uint32_t Size;

bool operator==(const ResourceBinding &RHS) const {
return std::tie(UniqueID, Space, LowerBound, Size) ==
std::tie(RHS.UniqueID, RHS.Space, RHS.LowerBound, RHS.Size);
}
bool operator!=(const ResourceBinding &RHS) const {
return !(*this == RHS);
}
};

struct UAVInfo {
bool GloballyCoherent;
bool HasCounter;
Expand Down Expand Up @@ -81,12 +84,11 @@ class ResourceInfo {
Value *Symbol;
StringRef Name;

ResourceBinding Binding;
uint32_t UniqueID;

dxil::ResourceClass RC;
dxil::ResourceKind Kind;

ResourceBinding Binding = {};

// Resource class dependent properties.
// CBuffer, Sampler, and RawBuffer end here.
union {
Expand Down Expand Up @@ -114,70 +116,62 @@ class ResourceInfo {
bool isMultiSample() const;

ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
StringRef Name, ResourceBinding Binding, uint32_t UniqueID)
: Symbol(Symbol), Name(Name), Binding(Binding), UniqueID(UniqueID),
RC(RC), Kind(Kind) {}
StringRef Name)
: Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}

public:
static ResourceInfo SRV(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy, uint32_t ElementCount,
dxil::ResourceKind Kind);
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID);
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, uint32_t Stride,
Align Alignment);
uint32_t Stride, Align Alignment);
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount);
static ResourceInfo
Texture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
uint32_t UniqueID, dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount);
static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount);

static ResourceInfo UAV(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy, uint32_t ElementCount,
bool GloballyCoherent, bool IsROV,
dxil::ResourceKind Kind);
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
bool GloballyCoherent, bool IsROV);
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, uint32_t Stride,
uint32_t Stride,
Align Alignment, bool GloballyCoherent,
bool IsROV, bool HasCounter);
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount,
bool GloballyCoherent);
static ResourceInfo
RWTexture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
uint32_t UniqueID, dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount,
bool GloballyCoherent);
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount,
bool GloballyCoherent);
static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID,
dxil::SamplerFeedbackType FeedbackTy);
static ResourceInfo
FeedbackTexture2DArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
uint32_t UniqueID,
FeedbackTexture2DArray(Value *Symbol, StringRef Name,
dxil::SamplerFeedbackType FeedbackTy);

static ResourceInfo CBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
uint32_t Size);
static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size);

static ResourceInfo Sampler(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::SamplerType SamplerTy);

void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
uint32_t Size) {
Binding.UniqueID = UniqueID;
Binding.Space = Space;
Binding.LowerBound = LowerBound;
Binding.Size = Size;
}

bool operator==(const ResourceInfo &RHS) const;

MDTuple *getAsMetadata(LLVMContext &Ctx) const;
Expand Down
92 changes: 35 additions & 57 deletions llvm/lib/Analysis/DXILResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,66 +64,58 @@ bool ResourceInfo::isMultiSample() const {
}

ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
ElementType ElementTy, uint32_t ElementCount,
ResourceKind Kind) {
ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name, Binding, UniqueID);
ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name);
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
"Invalid ResourceKind for SRV constructor.");
RI.Typed.ElementTy = ElementTy;
RI.Typed.ElementCount = ElementCount;
return RI;
}

ResourceInfo ResourceInfo::RawBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::RawBuffer, Symbol, Name,
Binding, UniqueID);
ResourceInfo ResourceInfo::RawBuffer(Value *Symbol, StringRef Name) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::RawBuffer, Symbol, Name);
return RI;
}

ResourceInfo ResourceInfo::StructuredBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, uint32_t Stride,
Align Alignment) {
uint32_t Stride, Align Alignment) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::StructuredBuffer, Symbol,
Name, Binding, UniqueID);
Name);
RI.Struct.Stride = Stride;
RI.Struct.Alignment = Alignment;
return RI;
}

ResourceInfo ResourceInfo::Texture2DMS(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, ElementType ElementTy,
ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name,
Binding, UniqueID);
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name);
RI.Typed.ElementTy = ElementTy;
RI.Typed.ElementCount = ElementCount;
RI.MultiSample.Count = SampleCount;
return RI;
}

ResourceInfo ResourceInfo::Texture2DMSArray(
Value *Symbol, StringRef Name, ResourceBinding Binding, uint32_t UniqueID,
ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount) {
ResourceInfo ResourceInfo::Texture2DMSArray(Value *Symbol, StringRef Name,
ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMSArray, Symbol,
Name, Binding, UniqueID);
Name);
RI.Typed.ElementTy = ElementTy;
RI.Typed.ElementCount = ElementCount;
RI.MultiSample.Count = SampleCount;
return RI;
}

ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
ElementType ElementTy, uint32_t ElementCount,
bool GloballyCoherent, bool IsROV,
ResourceKind Kind) {
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name, Binding, UniqueID);
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name);
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
"Invalid ResourceKind for UAV constructor.");
RI.Typed.ElementTy = ElementTy;
Expand All @@ -135,25 +127,20 @@ ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
}

ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, bool GloballyCoherent,
bool IsROV) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name,
Binding, UniqueID);
bool GloballyCoherent, bool IsROV) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name);
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
RI.UAVFlags.IsROV = IsROV;
RI.UAVFlags.HasCounter = false;
return RI;
}

ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID,
uint32_t Stride, Align Alignment,
bool GloballyCoherent, bool IsROV,
bool HasCounter) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::StructuredBuffer, Symbol,
Name, Binding, UniqueID);
Name);
RI.Struct.Stride = Stride;
RI.Struct.Alignment = Alignment;
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
Expand All @@ -162,13 +149,12 @@ ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
return RI;
}

ResourceInfo
ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
ElementType ElementTy, uint32_t ElementCount,
uint32_t SampleCount, bool GloballyCoherent) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMS, Symbol, Name,
Binding, UniqueID);
ResourceInfo ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount,
bool GloballyCoherent) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMS, Symbol, Name);
RI.Typed.ElementTy = ElementTy;
RI.Typed.ElementCount = ElementCount;
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
Expand All @@ -178,13 +164,13 @@ ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
return RI;
}

ResourceInfo
ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
ElementType ElementTy, uint32_t ElementCount,
uint32_t SampleCount, bool GloballyCoherent) {
ResourceInfo ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount,
bool GloballyCoherent) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMSArray, Symbol,
Name, Binding, UniqueID);
Name);
RI.Typed.ElementTy = ElementTy;
RI.Typed.ElementCount = ElementCount;
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
Expand All @@ -195,11 +181,9 @@ ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
}

ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID,
SamplerFeedbackType FeedbackTy) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2D, Symbol,
Name, Binding, UniqueID);
Name);
RI.UAVFlags.GloballyCoherent = false;
RI.UAVFlags.IsROV = false;
RI.UAVFlags.HasCounter = false;
Expand All @@ -209,10 +193,9 @@ ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,

ResourceInfo
ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
SamplerFeedbackType FeedbackTy) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2DArray,
Symbol, Name, Binding, UniqueID);
Symbol, Name);
RI.UAVFlags.GloballyCoherent = false;
RI.UAVFlags.IsROV = false;
RI.UAVFlags.HasCounter = false;
Expand All @@ -221,27 +204,22 @@ ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
}

ResourceInfo ResourceInfo::CBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
uint32_t Size) {
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name,
Binding, UniqueID);
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name);
RI.CBufferSize = Size;
return RI;
}

ResourceInfo ResourceInfo::Sampler(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
SamplerType SamplerTy) {
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name,
Binding, UniqueID);
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name);
RI.SamplerTy = SamplerTy;
return RI;
}

bool ResourceInfo::operator==(const ResourceInfo &RHS) const {
if (std::tie(Symbol, Name, Binding, UniqueID, RC, Kind) !=
std::tie(RHS.Symbol, RHS.Name, RHS.Binding, RHS.UniqueID, RHS.RC,
RHS.Kind))
if (std::tie(Symbol, Name, Binding, RC, Kind) !=
std::tie(RHS.Symbol, RHS.Name, RHS.Binding, RHS.RC, RHS.Kind))
return false;
if (isCBuffer())
return CBufferSize == RHS.CBufferSize;
Expand Down Expand Up @@ -278,7 +256,7 @@ MDTuple *ResourceInfo::getAsMetadata(LLVMContext &Ctx) const {
Constant::getIntegerValue(I1Ty, APInt(1, V)));
};

MDVals.push_back(getIntMD(UniqueID));
MDVals.push_back(getIntMD(Binding.UniqueID));
MDVals.push_back(ValueAsMetadata::get(Symbol));
MDVals.push_back(MDString::get(Ctx, Name));
MDVals.push_back(getIntMD(Binding.Space));
Expand Down
Loading
Loading