Skip to content

[DXIL][Analysis] Make alignment on StructuredBuffer optional #100697

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
12 changes: 6 additions & 6 deletions llvm/include/llvm/Analysis/DXILResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -138,7 +138,7 @@ class ResourceInfo {
CBufferSize = Size;
}
void setSampler(dxil::SamplerType Ty) { SamplerTy = Ty; }
void setStruct(uint32_t Stride, Align Alignment) {
void setStruct(uint32_t Stride, MaybeAlign Alignment) {
assert(isStruct() && "Not a Struct");
Struct.Stride = Stride;
Struct.Alignment = Alignment;
Expand All @@ -164,7 +164,7 @@ class ResourceInfo {
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);
Expand All @@ -180,9 +180,9 @@ class ResourceInfo {
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,
Expand Down
9 changes: 6 additions & 3 deletions llvm/lib/Analysis/DXILResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ 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.setStruct(Stride, Alignment);
Expand Down Expand Up @@ -127,7 +128,8 @@ ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
}

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,
Expand Down Expand Up @@ -284,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;
Expand Down
13 changes: 13 additions & 0 deletions llvm/unittests/Analysis/DXILResourceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> >"));
Expand Down
Loading