Skip to content

Commit e7b54bb

Browse files
krystian-andrzejewskiigcbot
authored andcommitted
Support bindful reads in ConstantCoalescing
This change is to support new patterns in ConstantCoalescing: indirect read accesses from bindful resources.
1 parent e1ecf7b commit e7b54bb

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

IGC/Compiler/CISACodeGen/ConstantCoalescing.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,6 @@ void ConstantCoalescing::ProcessBlock(
417417
BufferType bufType = DecodeAS4GFXResource(
418418
ldRaw->getResourceValue()->getType()->getPointerAddressSpace(), directIdx, bufId);
419419

420-
if ((bufType != BINDLESS_CONSTANT_BUFFER)
421-
&& (bufType != BINDLESS_TEXTURE)
422-
&& (bufType != SSH_BINDLESS_CONSTANT_BUFFER)
423-
&& (bufType != BINDLESS)
424-
)
425-
{
426-
continue;
427-
}
428420

429421
uint offsetInBytes = 0;
430422
Value* baseOffsetInBytes = nullptr;
@@ -457,12 +449,9 @@ void ConstantCoalescing::ProcessBlock(
457449
Extension,
458450
baseOffsetInBytes ? indcb_owloads : dircb_owloads);
459451
}
460-
else if (bufType == BINDLESS_CONSTANT_BUFFER
461-
|| bufType == SSH_BINDLESS_CONSTANT_BUFFER
462-
|| bufType == BINDLESS
463-
)
452+
else if (IsUntypedBuffer(bufType))
464453
{
465-
if (UsesTypedConstantBuffer(m_ctx, bufType) && (bufType != BINDLESS))
454+
if (UsesTypedConstantBuffer(m_ctx, bufType))
466455
{
467456
ScatterToSampler(
468457
ldRaw,
@@ -474,7 +463,8 @@ void ConstantCoalescing::ProcessBlock(
474463
}
475464
else if (IGC_IS_FLAG_DISABLED(DisableConstantCoalescingOfStatefulNonUniformLoads))
476465
{
477-
if (bufType != BINDLESS)
466+
// TODO: remove this condition
467+
if (!IsWritableBuffer(bufType))
478468
{
479469
MergeScatterLoad(
480470
ldRaw,
@@ -488,7 +478,7 @@ void ConstantCoalescing::ProcessBlock(
488478
}
489479
}
490480
}
491-
else if (bufType == BINDLESS_TEXTURE && IGC_IS_FLAG_ENABLED(EnableTextureLoadCoalescing))
481+
else if (IsTypedBuffer(bufType) && IGC_IS_FLAG_ENABLED(EnableTextureLoadCoalescing))
492482
{
493483
MergeScatterLoad(
494484
ldRaw,

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ namespace IGC
182182
const CodeGenContext* pContext,
183183
const BufferType bufType)
184184
{
185-
IGC_ASSERT(bufType == CONSTANT_BUFFER ||
186-
bufType == BINDLESS_CONSTANT_BUFFER ||
187-
bufType == BINDLESS);
185+
if (!IsUntypedBuffer(bufType) || IsWritableBuffer(bufType))
186+
{
187+
return false;
188+
}
188189

189190
if (pContext->m_DriverInfo.ForceUntypedBindlessConstantBuffers() &&
190191
bufType == BINDLESS_CONSTANT_BUFFER)

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,56 @@ namespace IGC
217217
bool IsDirectIdx(unsigned addrSpace);
218218
bool isNaNCheck(llvm::FCmpInst& FC);
219219

220+
inline bool IsBindfull(BufferType t)
221+
{
222+
return t == UAV ||
223+
t == CONSTANT_BUFFER ||
224+
t == RESOURCE;
225+
}
220226
inline bool IsBindless(BufferType t)
221227
{
222-
return t == BINDLESS || t == BINDLESS_CONSTANT_BUFFER || t == BINDLESS_TEXTURE;
228+
return t == BINDLESS ||
229+
t == BINDLESS_CONSTANT_BUFFER ||
230+
t == BINDLESS_TEXTURE;
223231
}
224232
inline bool IsSSHbindless(BufferType t)
225233
{
226-
return t == SSH_BINDLESS || t == SSH_BINDLESS_CONSTANT_BUFFER || t == SSH_BINDLESS_TEXTURE;
234+
return t == SSH_BINDLESS ||
235+
t == SSH_BINDLESS_CONSTANT_BUFFER ||
236+
t == SSH_BINDLESS_TEXTURE;
237+
}
238+
inline bool IsStatelessBuffer(BufferType t)
239+
{
240+
return t == STATELESS ||
241+
t == STATELESS_READONLY ||
242+
t == STATELESS_A32;
243+
}
244+
inline bool IsTypedBuffer(BufferType t)
245+
{
246+
return t == RESOURCE ||
247+
t == BINDLESS_TEXTURE ||
248+
t == SSH_BINDLESS_TEXTURE;
249+
}
250+
inline bool IsUntypedBuffer(BufferType t)
251+
{
252+
return t == UAV ||
253+
t == CONSTANT_BUFFER ||
254+
t == BINDLESS ||
255+
t == BINDLESS_CONSTANT_BUFFER ||
256+
t == SSH_BINDLESS ||
257+
t == SSH_BINDLESS_CONSTANT_BUFFER;
258+
}
259+
inline bool IsWritableBuffer(BufferType t)
260+
{
261+
BufferAccessType accessType = getDefaultAccessType(t);
262+
return accessType == BufferAccessType::ACCESS_WRITE ||
263+
accessType == BufferAccessType::ACCESS_READWRITE;
264+
}
265+
inline bool IsReadableBuffer(BufferType t)
266+
{
267+
BufferAccessType accessType = getDefaultAccessType(t);
268+
return accessType == BufferAccessType::ACCESS_READ ||
269+
accessType == BufferAccessType::ACCESS_READWRITE;
227270
}
228271

229272
bool IsUnsignedCmp(const llvm::CmpInst::Predicate Pred);

0 commit comments

Comments
 (0)