-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[DXIL][Analysis] Make the DXILResource binding optional. NFC #100623
Conversation
Created using spr 1.3.5-bogner [skip ci]
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-llvm-analysis Author: Justin Bogner (bogner) ChangesThis makes the binding structure in a DXILResource default to empty This will put us in a better position when dealing with resource Patch is 27.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/100623.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Analysis/DXILResource.h b/llvm/include/llvm/Analysis/DXILResource.h
index cca5e0f0bd759..d4006ae10837c 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -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;
@@ -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 {
@@ -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;
diff --git a/llvm/lib/Analysis/DXILResource.cpp b/llvm/lib/Analysis/DXILResource.cpp
index d47a73c05a3e5..72cba9d4373bb 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -64,10 +64,9 @@ 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;
@@ -75,43 +74,37 @@ ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
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;
@@ -119,11 +112,10 @@ ResourceInfo ResourceInfo::Texture2DMSArray(
}
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;
@@ -135,11 +127,8 @@ 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;
@@ -147,13 +136,11 @@ ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
}
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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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));
diff --git a/llvm/unittests/Analysis/DXILResourceTest.cpp b/llvm/unittests/Analysis/DXILResourceTest.cpp
index 036ba40f275d0..554cbd0d8ded7 100644
--- a/llvm/unittests/Analysis/DXILResourceTest.cpp
+++ b/llvm/unittests/Analysis/DXILResourceTest.cpp
@@ -113,9 +113,8 @@ TEST(DXILResource, AnnotationsAndMetadata) {
// ByteAddressBuffer Buffer0;
Value *Symbol = UndefValue::get(
StructType::create(Context, {Int32Ty}, "struct.ByteAddressBuffer"));
- ResourceInfo Resource =
- ResourceInfo::RawBuffer(Symbol, "Buffer0", ResourceBinding{0, 0, 1},
- /*UniqueID=*/0);
+ ResourceInfo Resource = ResourceInfo::RawBuffer(Symbol, "Buffer0");
+ Resource.bind(0, 0, 0, 1);
std::pair<uint32_t, uint32_t> Props = Resource.getAnnotateProps();
EXPECT_EQ(Props.first, 0x0000000bU);
EXPECT_EQ(Props.second, 0U);
@@ -125,9 +124,10 @@ TEST(DXILResource, AnnotationsAndMetadata) {
// RWByteAddressBuffer BufferOut : register(u3, space2);
Symbol = UndefValue::get(
StructType::create(Context, {Int32Ty}, "struct.RWByteAddressBuffer"));
- Resource = ResourceInfo::RWRawBuffer(
- Symbol, "BufferOut", ResourceBinding{2, 3, 1}, /*UniqueID=*/1,
- /*GloballyCoherent=*/false, /*IsROV=*/false);
+ Resource =
+ ResourceInfo::RWRawBuffer(Symbol, "BufferOut",
+ /*GloballyCoherent=*/false, /*IsROV=*/false);
+ Resource.bind(1, 2, 3, 1);
Props = Resource.getAnnotateProps();
EXPECT_EQ(Props.first, 0x0000100bU);
EXPECT_EQ(Props.second, 0U);
@@ -141,9 +141,9 @@ TEST(DXILResource, AnnotationsAndMetadata) {
StructType::create(Context, {Int32Ty, FloatTy, DoubleTy}, "BufType0");
Symbol = UndefValue::get(StructType::create(
Context, {BufType0}, "class.StructuredBuffer<BufType>"));
- Resource = ResourceInfo::StructuredBuffer(
- Symbol, "Buffer0", ResourceBinding{0, 0, 1}, /*UniqueID=*/0,
- /*Stride=*/16, Align(8));
+ Resource = ResourceInfo::StructuredBuffer(Symbol, "Buffer0",
+ /*Stride=*/16, Align(8));
+ Resource.bind(0, 0, 0, 1);
Props = Resource.getAnnotateProps();
EXPECT_EQ(Props.first, 0x0000030cU);
EXPECT_EQ(Props.second, 0x00000010U);
@@ -155,9 +155,9 @@ TEST(DXILResource, AnnotationsAndMetadata) {
Symbol = UndefValue::get(StructType::create(
Context, {Floatx4Ty}, "class.Texture2D<vector<float, 4> >"));
Resource =
- ResourceInfo::SRV(Symbol, "ColorMapTexture", ResourceBinding{0, 2, 1},
- /*UniqueID=*/2, dxil::ElementType::F32,
+ ResourceInfo::SRV(Symbol, "ColorMapTexture", dxil::ElementType::F32,
/*ElementCoun...
[truncated]
|
@llvm/pr-subscribers-backend-directx Author: Justin Bogner (bogner) ChangesThis makes the binding structure in a DXILResource default to empty This will put us in a better position when dealing with resource Patch is 27.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/100623.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Analysis/DXILResource.h b/llvm/include/llvm/Analysis/DXILResource.h
index cca5e0f0bd759..d4006ae10837c 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -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;
@@ -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 {
@@ -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;
diff --git a/llvm/lib/Analysis/DXILResource.cpp b/llvm/lib/Analysis/DXILResource.cpp
index d47a73c05a3e5..72cba9d4373bb 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -64,10 +64,9 @@ 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;
@@ -75,43 +74,37 @@ ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
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;
@@ -119,11 +112,10 @@ ResourceInfo ResourceInfo::Texture2DMSArray(
}
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;
@@ -135,11 +127,8 @@ 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;
@@ -147,13 +136,11 @@ ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
}
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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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));
diff --git a/llvm/unittests/Analysis/DXILResourceTest.cpp b/llvm/unittests/Analysis/DXILResourceTest.cpp
index 036ba40f275d0..554cbd0d8ded7 100644
--- a/llvm/unittests/Analysis/DXILResourceTest.cpp
+++ b/llvm/unittests/Analysis/DXILResourceTest.cpp
@@ -113,9 +113,8 @@ TEST(DXILResource, AnnotationsAndMetadata) {
// ByteAddressBuffer Buffer0;
Value *Symbol = UndefValue::get(
StructType::create(Context, {Int32Ty}, "struct.ByteAddressBuffer"));
- ResourceInfo Resource =
- ResourceInfo::RawBuffer(Symbol, "Buffer0", ResourceBinding{0, 0, 1},
- /*UniqueID=*/0);
+ ResourceInfo Resource = ResourceInfo::RawBuffer(Symbol, "Buffer0");
+ Resource.bind(0, 0, 0, 1);
std::pair<uint32_t, uint32_t> Props = Resource.getAnnotateProps();
EXPECT_EQ(Props.first, 0x0000000bU);
EXPECT_EQ(Props.second, 0U);
@@ -125,9 +124,10 @@ TEST(DXILResource, AnnotationsAndMetadata) {
// RWByteAddressBuffer BufferOut : register(u3, space2);
Symbol = UndefValue::get(
StructType::create(Context, {Int32Ty}, "struct.RWByteAddressBuffer"));
- Resource = ResourceInfo::RWRawBuffer(
- Symbol, "BufferOut", ResourceBinding{2, 3, 1}, /*UniqueID=*/1,
- /*GloballyCoherent=*/false, /*IsROV=*/false);
+ Resource =
+ ResourceInfo::RWRawBuffer(Symbol, "BufferOut",
+ /*GloballyCoherent=*/false, /*IsROV=*/false);
+ Resource.bind(1, 2, 3, 1);
Props = Resource.getAnnotateProps();
EXPECT_EQ(Props.first, 0x0000100bU);
EXPECT_EQ(Props.second, 0U);
@@ -141,9 +141,9 @@ TEST(DXILResource, AnnotationsAndMetadata) {
StructType::create(Context, {Int32Ty, FloatTy, DoubleTy}, "BufType0");
Symbol = UndefValue::get(StructType::create(
Context, {BufType0}, "class.StructuredBuffer<BufType>"));
- Resource = ResourceInfo::StructuredBuffer(
- Symbol, "Buffer0", ResourceBinding{0, 0, 1}, /*UniqueID=*/0,
- /*Stride=*/16, Align(8));
+ Resource = ResourceInfo::StructuredBuffer(Symbol, "Buffer0",
+ /*Stride=*/16, Align(8));
+ Resource.bind(0, 0, 0, 1);
Props = Resource.getAnnotateProps();
EXPECT_EQ(Props.first, 0x0000030cU);
EXPECT_EQ(Props.second, 0x00000010U);
@@ -155,9 +155,9 @@ TEST(DXILResource, AnnotationsAndMetadata) {
Symbol = UndefValue::get(StructType::create(
Context, {Floatx4Ty}, "class.Texture2D<vector<float, 4> >"));
Resource =
- ResourceInfo::SRV(Symbol, "ColorMapTexture", ResourceBinding{0, 2, 1},
- /*UniqueID=*/2, dxil::ElementType::F32,
+ ResourceInfo::SRV(Symbol, "ColorMapTexture", dxil::ElementType::F32,
/*ElementCoun...
[truncated]
|
Created using spr 1.3.5-bogner [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, makes sense. Weird how github highlights UniqueID
, maybe it's some sort of special keyword? It might be worth renaming, but very small nit.
This makes the binding structure in a DXILResource default to empty
and need a separate call to set up, and also moves the unique ID into
it since bindings are the only place where those are actually used.
This will put us in a better position when dealing with resource
handles in libraries.