aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2024-07-25 22:46:02 -0700
committerJustin Bogner <mail@justinbogner.com>2024-07-25 22:46:02 -0700
commite55ce060323508a91b6d3c3583c634269ace9e6f (patch)
treecfce9b1aa99d2f223a2bf4b0939cbfee9342ff1b
parent70a9535f714e2fdb84af243a1a316012c8019049 (diff)
downloadllvm-users/bogner/sprmain.directx-remove-new-pm-versions-of-dxilresource-passes-nfc.zip
llvm-users/bogner/sprmain.directx-remove-new-pm-versions-of-dxilresource-passes-nfc.tar.gz
llvm-users/bogner/sprmain.directx-remove-new-pm-versions-of-dxilresource-passes-nfc.tar.bz2
[𝘀𝗽𝗿] changes to main this commit is based onusers/bogner/sprmain.directx-remove-new-pm-versions-of-dxilresource-passes-nfc
Created using spr 1.3.5-bogner [skip ci]
-rw-r--r--llvm/include/llvm/Analysis/DXILResource.h69
-rw-r--r--llvm/lib/Analysis/DXILResource.cpp77
-rw-r--r--llvm/unittests/Analysis/DXILResourceTest.cpp13
3 files changed, 92 insertions, 67 deletions
diff --git a/llvm/include/llvm/Analysis/DXILResource.h b/llvm/include/llvm/Analysis/DXILResource.h
index d4006ae..0fad598 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -47,7 +47,7 @@ class ResourceInfo {
struct StructInfo {
uint32_t Stride;
- Align Alignment;
+ MaybeAlign Alignment;
bool operator==(const StructInfo &RHS) const {
return std::tie(Stride, Alignment) == std::tie(RHS.Stride, RHS.Alignment);
@@ -106,6 +106,11 @@ class ResourceInfo {
MSInfo MultiSample;
+public:
+ ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
+ StringRef Name)
+ : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
+
// Conditions to check before accessing union members.
bool isUAV() const;
bool isCBuffer() const;
@@ -115,17 +120,53 @@ class ResourceInfo {
bool isFeedback() const;
bool isMultiSample() const;
- ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
- StringRef Name)
- : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
+ 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;
+ }
+ void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV) {
+ assert(isUAV() && "Not a UAV");
+ UAVFlags.GloballyCoherent = GloballyCoherent;
+ UAVFlags.HasCounter = HasCounter;
+ UAVFlags.IsROV = IsROV;
+ }
+ void setCBuffer(uint32_t Size) {
+ assert(isCBuffer() && "Not a CBuffer");
+ CBufferSize = Size;
+ }
+ void setSampler(dxil::SamplerType Ty) {
+ SamplerTy = Ty;
+ }
+ void setStruct(uint32_t Stride, MaybeAlign Alignment) {
+ assert(isStruct() && "Not a Struct");
+ Struct.Stride = Stride;
+ Struct.Alignment = Alignment;
+ }
+ void setTyped(dxil::ElementType ElementTy, uint32_t ElementCount) {
+ assert(isTyped() && "Not Typed");
+ Typed.ElementTy = ElementTy;
+ Typed.ElementCount = ElementCount;
+ }
+ void setFeedback(dxil::SamplerFeedbackType Type) {
+ assert(isFeedback() && "Not Feedback");
+ Feedback.Type = Type;
+ }
+ void setMultiSample(uint32_t Count) {
+ assert(isMultiSample() && "Not MultiSampled");
+ MultiSample.Count = Count;
+ }
+
+ bool operator==(const ResourceInfo &RHS) const;
-public:
static ResourceInfo SRV(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy, uint32_t ElementCount,
dxil::ResourceKind Kind);
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
- uint32_t Stride, Align Alignment);
+ uint32_t Stride, MaybeAlign Alignment);
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount);
@@ -141,9 +182,9 @@ public:
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
bool GloballyCoherent, bool IsROV);
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
- uint32_t Stride,
- Align Alignment, bool GloballyCoherent,
- bool IsROV, bool HasCounter);
+ uint32_t Stride, MaybeAlign Alignment,
+ bool GloballyCoherent, bool IsROV,
+ bool HasCounter);
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount,
@@ -164,16 +205,6 @@ public:
static ResourceInfo Sampler(Value *Symbol, StringRef Name,
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;
ResourceBinding getBinding() const { return Binding; }
diff --git a/llvm/lib/Analysis/DXILResource.cpp b/llvm/lib/Analysis/DXILResource.cpp
index 72cba9d..d49fed7 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -69,8 +69,7 @@ ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
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;
+ RI.setTyped(ElementTy, ElementCount);
return RI;
}
@@ -80,11 +79,11 @@ ResourceInfo ResourceInfo::RawBuffer(Value *Symbol, StringRef Name) {
}
ResourceInfo ResourceInfo::StructuredBuffer(Value *Symbol, StringRef Name,
- uint32_t Stride, Align Alignment) {
+ uint32_t Stride,
+ MaybeAlign Alignment) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::StructuredBuffer, Symbol,
Name);
- RI.Struct.Stride = Stride;
- RI.Struct.Alignment = Alignment;
+ RI.setStruct(Stride, Alignment);
return RI;
}
@@ -93,9 +92,8 @@ ResourceInfo ResourceInfo::Texture2DMS(Value *Symbol, StringRef Name,
uint32_t ElementCount,
uint32_t SampleCount) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -105,9 +103,8 @@ ResourceInfo ResourceInfo::Texture2DMSArray(Value *Symbol, StringRef Name,
uint32_t SampleCount) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMSArray, Symbol,
Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -118,34 +115,27 @@ ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name);
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
"Invalid ResourceKind for UAV constructor.");
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = IsROV;
- RI.UAVFlags.HasCounter = false;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
return RI;
}
ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
bool GloballyCoherent, bool IsROV) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name);
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = IsROV;
- RI.UAVFlags.HasCounter = false;
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
return RI;
}
ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
- uint32_t Stride, Align Alignment,
+ uint32_t Stride,
+ MaybeAlign Alignment,
bool GloballyCoherent, bool IsROV,
bool HasCounter) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::StructuredBuffer, Symbol,
Name);
- RI.Struct.Stride = Stride;
- RI.Struct.Alignment = Alignment;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = IsROV;
- RI.UAVFlags.HasCounter = HasCounter;
+ RI.setStruct(Stride, Alignment);
+ RI.setUAV(GloballyCoherent, HasCounter, IsROV);
return RI;
}
@@ -155,12 +145,9 @@ ResourceInfo ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
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;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -171,12 +158,9 @@ ResourceInfo ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
bool GloballyCoherent) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMSArray, Symbol,
Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -184,10 +168,8 @@ ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,
SamplerFeedbackType FeedbackTy) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2D, Symbol,
Name);
- RI.UAVFlags.GloballyCoherent = false;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.Feedback.Type = FeedbackTy;
+ RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setFeedback(FeedbackTy);
return RI;
}
@@ -196,24 +178,22 @@ ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
SamplerFeedbackType FeedbackTy) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2DArray,
Symbol, Name);
- RI.UAVFlags.GloballyCoherent = false;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.Feedback.Type = FeedbackTy;
+ RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setFeedback(FeedbackTy);
return RI;
}
ResourceInfo ResourceInfo::CBuffer(Value *Symbol, StringRef Name,
uint32_t Size) {
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name);
- RI.CBufferSize = Size;
+ RI.setCBuffer(Size);
return RI;
}
ResourceInfo ResourceInfo::Sampler(Value *Symbol, StringRef Name,
SamplerType SamplerTy) {
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name);
- RI.SamplerTy = SamplerTy;
+ RI.setSampler(SamplerTy);
return RI;
}
@@ -306,7 +286,8 @@ MDTuple *ResourceInfo::getAsMetadata(LLVMContext &Ctx) const {
std::pair<uint32_t, uint32_t> ResourceInfo::getAnnotateProps() const {
uint32_t ResourceKind = llvm::to_underlying(Kind);
- uint32_t AlignLog2 = isStruct() ? Log2(Struct.Alignment) : 0;
+ uint32_t AlignLog2 =
+ isStruct() && Struct.Alignment ? Log2(*Struct.Alignment) : 0;
bool IsUAV = isUAV();
bool IsROV = IsUAV && UAVFlags.IsROV;
bool IsGloballyCoherent = IsUAV && UAVFlags.GloballyCoherent;
diff --git a/llvm/unittests/Analysis/DXILResourceTest.cpp b/llvm/unittests/Analysis/DXILResourceTest.cpp
index 554cbd0..7bbb417 100644
--- a/llvm/unittests/Analysis/DXILResourceTest.cpp
+++ b/llvm/unittests/Analysis/DXILResourceTest.cpp
@@ -151,6 +151,19 @@ TEST(DXILResource, AnnotationsAndMetadata) {
EXPECT_MDEQ(
MD, TestMD.get(0, Symbol, "Buffer0", 0, 0, 1, 12, 0, TestMD.get(1, 16)));
+ // StructuredBuffer<float3> Buffer1 : register(t1);
+ Symbol = UndefValue::get(StructType::create(
+ Context, {Floatx3Ty}, "class.StructuredBuffer<vector<float, 3> >"));
+ Resource = ResourceInfo::StructuredBuffer(Symbol, "Buffer1",
+ /*Stride=*/12, {});
+ Resource.bind(1, 0, 1, 1);
+ Props = Resource.getAnnotateProps();
+ EXPECT_EQ(Props.first, 0x0000000cU);
+ EXPECT_EQ(Props.second, 0x0000000cU);
+ MD = Resource.getAsMetadata(Context);
+ EXPECT_MDEQ(
+ MD, TestMD.get(1, Symbol, "Buffer1", 0, 1, 1, 12, 0, TestMD.get(1, 12)));
+
// Texture2D<float4> ColorMapTexture : register(t2);
Symbol = UndefValue::get(StructType::create(
Context, {Floatx4Ty}, "class.Texture2D<vector<float, 4> >"));