From f8ec59dd720414c9b24d68f4fb2e99dfc84da48f Mon Sep 17 00:00:00 2001 From: Mariusz Merecki Date: Wed, 18 Dec 2024 14:03:07 +0000 Subject: [PATCH] Add `BINDLESS_READONLY` and `BINLDESS_WRITEONLY` resource types New resource types allow to specify a read-only and write-only images. --- IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp | 12 ++++++++++-- IGC/Compiler/CISACodeGen/helper.cpp | 4 +++- IGC/Compiler/CISACodeGen/helper.h | 4 ++++ IGC/Compiler/CodeGenPublicEnums.h | 2 ++ .../SynchronizationObjectCoalescing.cpp | 17 +++++++++++------ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp b/IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp index bc8eddbbd44c..4b2736161ce1 100644 --- a/IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp +++ b/IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp @@ -368,7 +368,9 @@ void CheckInstrTypes::visitCallInst(CallInst& C) g_InstrTypes.num1DAccesses++; BufferType bufferType = DecodeBufferType( CI->getArgOperand(0)->getType()->getPointerAddressSpace()); - if (bufferType == UAV || bufferType == BINDLESS) + if (bufferType == UAV || + bufferType == BINDLESS || + bufferType == BINDLESS_READONLY) { g_InstrTypes.hasStorageBufferLoad = true; } @@ -380,7 +382,9 @@ void CheckInstrTypes::visitCallInst(CallInst& C) g_InstrTypes.num1DAccesses++; BufferType bufferType = DecodeBufferType( CI->getArgOperand(0)->getType()->getPointerAddressSpace()); - if (bufferType == UAV || bufferType == BINDLESS) + if (bufferType == UAV || + bufferType == BINDLESS || + bufferType == BINDLESS_WRITEONLY) { g_InstrTypes.hasStorageBufferStore = true; } @@ -564,6 +568,7 @@ void CheckInstrTypes::visitLoadInst(LoadInst& I) g_InstrTypes.num1DAccesses++; break; case IGC::BINDLESS: + case IGC::BINDLESS_READONLY: case IGC::SSH_BINDLESS: g_InstrTypes.hasStorageBufferLoad = true; break; @@ -583,6 +588,7 @@ void CheckInstrTypes::visitLoadInst(LoadInst& I) case IGC::CONSTANT_BUFFER: case IGC::POINTER: case IGC::BINDLESS_CONSTANT_BUFFER: + case IGC::BINDLESS_WRITEONLY: case IGC::BINDLESS_TEXTURE: case IGC::SAMPLER: case IGC::BINDLESS_SAMPLER: @@ -637,6 +643,7 @@ void CheckInstrTypes::visitStoreInst(StoreInst& I) g_InstrTypes.num1DAccesses++; break; case IGC::BINDLESS: + case IGC::BINDLESS_WRITEONLY: case IGC::SSH_BINDLESS: g_InstrTypes.hasStorageBufferStore = true; break; @@ -656,6 +663,7 @@ void CheckInstrTypes::visitStoreInst(StoreInst& I) case IGC::CONSTANT_BUFFER: case IGC::POINTER: case IGC::BINDLESS_CONSTANT_BUFFER: + case IGC::BINDLESS_READONLY: case IGC::BINDLESS_TEXTURE: case IGC::SAMPLER: case IGC::BINDLESS_SAMPLER: diff --git a/IGC/Compiler/CISACodeGen/helper.cpp b/IGC/Compiler/CISACodeGen/helper.cpp index 6e66af164f1e..997be43e2349 100644 --- a/IGC/Compiler/CISACodeGen/helper.cpp +++ b/IGC/Compiler/CISACodeGen/helper.cpp @@ -629,13 +629,14 @@ namespace IGC BufferAccessType getDefaultAccessType(BufferType bufTy) { - static_assert(BufferType::BUFFER_TYPE_UNKNOWN == 17, "Please also update switch() below"); + static_assert(BufferType::BUFFER_TYPE_UNKNOWN == 19, "Please also update switch() below"); switch (bufTy) { case BufferType::CONSTANT_BUFFER: case BufferType::RESOURCE: case BufferType::BINDLESS_TEXTURE: case BufferType::BINDLESS_CONSTANT_BUFFER: + case BufferType::BINDLESS_READONLY: case BufferType::STATELESS_READONLY: case BufferType::SAMPLER: case BufferType::BINDLESS_SAMPLER: @@ -652,6 +653,7 @@ namespace IGC case BufferType::STATELESS_A32: return BufferAccessType::ACCESS_READWRITE; + case BufferType::BINDLESS_WRITEONLY: case BufferType::RENDER_TARGET: return BufferAccessType::ACCESS_WRITE; default: diff --git a/IGC/Compiler/CISACodeGen/helper.h b/IGC/Compiler/CISACodeGen/helper.h index 16d8b4632915..8beb0205c196 100644 --- a/IGC/Compiler/CISACodeGen/helper.h +++ b/IGC/Compiler/CISACodeGen/helper.h @@ -235,6 +235,8 @@ namespace IGC { return t == BINDLESS || t == BINDLESS_CONSTANT_BUFFER || + t == BINDLESS_READONLY || + t == BINDLESS_WRITEONLY || t == BINDLESS_TEXTURE; } inline bool IsSSHbindless(BufferType t) @@ -261,6 +263,8 @@ namespace IGC t == CONSTANT_BUFFER || t == BINDLESS || t == BINDLESS_CONSTANT_BUFFER || + t == BINDLESS_READONLY || + t == BINDLESS_WRITEONLY || t == SSH_BINDLESS || t == SSH_BINDLESS_CONSTANT_BUFFER; } diff --git a/IGC/Compiler/CodeGenPublicEnums.h b/IGC/Compiler/CodeGenPublicEnums.h index 7cb957739b17..7ee964d923c9 100644 --- a/IGC/Compiler/CodeGenPublicEnums.h +++ b/IGC/Compiler/CodeGenPublicEnums.h @@ -96,6 +96,8 @@ namespace IGC SSH_BINDLESS, SSH_BINDLESS_CONSTANT_BUFFER, SSH_BINDLESS_TEXTURE, + BINDLESS_READONLY, + BINDLESS_WRITEONLY, BUFFER_TYPE_UNKNOWN }; diff --git a/IGC/Compiler/Optimizer/SynchronizationObjectCoalescing.cpp b/IGC/Compiler/Optimizer/SynchronizationObjectCoalescing.cpp index 1fa6e57a6fdd..be945b9fe94b 100644 --- a/IGC/Compiler/Optimizer/SynchronizationObjectCoalescing.cpp +++ b/IGC/Compiler/Optimizer/SynchronizationObjectCoalescing.cpp @@ -485,7 +485,7 @@ class SynchronizationObjectCoalescing : public llvm::FunctionPass static bool IsFenceOperation(const llvm::Instruction* pInst); //////////////////////////////////////////////////////////////////////// - static bool IsGlobalResource(llvm::Type* pResourePointerType); + static bool IsGlobalWritableResource(llvm::Type* pResourePointerType); //////////////////////////////////////////////////////////////////////// static bool IsSharedMemoryResource(llvm::Type* pResourePointerType); @@ -1865,7 +1865,7 @@ IGC::InstructionMask SynchronizationObjectCoalescing::GetAtomicInstructionMaskFr else { llvm::Type* pPointerType = pGenIntrinsicInst->getOperand(0)->getType(); - if (IsGlobalResource(pPointerType)) + if (IsGlobalWritableResource(pPointerType)) { result = static_cast(result | InstructionMask::BufferReadOperation); result = static_cast(result | InstructionMask::BufferWriteOperation); @@ -2466,7 +2466,7 @@ bool SynchronizationObjectCoalescing::IsTypedReadOperation(const llvm::Instructi switch (pGenIntrinsicInst->getIntrinsicID()) { case llvm::GenISAIntrinsic::GenISA_typedread: - return true; + return IsGlobalWritableResource(pGenIntrinsicInst->getOperand(0)->getType()); default: break; } @@ -2603,7 +2603,7 @@ bool SynchronizationObjectCoalescing::IsBufferReadOperation(const llvm::Instruct { if (llvm::Type* pPtrType = GetReadOperationPointerType(pInst)) { - return IsGlobalResource(pPtrType); + return IsGlobalWritableResource(pPtrType); } return false; } @@ -2613,7 +2613,7 @@ bool SynchronizationObjectCoalescing::IsBufferWriteOperation(const llvm::Instruc { if (llvm::Type* pPtrType = GetWriteOperationPointerType(pInst)) { - return IsGlobalResource(pPtrType); + return IsGlobalWritableResource(pPtrType); } return false; } @@ -2920,7 +2920,10 @@ bool SynchronizationObjectCoalescing::IsFenceOperation(const llvm::Instruction* } //////////////////////////////////////////////////////////////////////// -bool SynchronizationObjectCoalescing::IsGlobalResource(llvm::Type* pResourePointerType) +/// Returns true for resources in the global memory (storage buffers or +/// storage images) that are not marked as ReadOnly in the shader. +bool SynchronizationObjectCoalescing::IsGlobalWritableResource( + llvm::Type* pResourePointerType) { uint as = pResourePointerType->getPointerAddressSpace(); switch (as) @@ -2937,6 +2940,7 @@ bool SynchronizationObjectCoalescing::IsGlobalResource(llvm::Type* pResourePoint { case IGC::UAV: case IGC::BINDLESS: + case IGC::BINDLESS_WRITEONLY: case IGC::STATELESS: case IGC::SSH_BINDLESS: return true; @@ -2946,6 +2950,7 @@ bool SynchronizationObjectCoalescing::IsGlobalResource(llvm::Type* pResourePoint case IGC::POINTER: case IGC::BINDLESS_CONSTANT_BUFFER: case IGC::BINDLESS_TEXTURE: + case IGC::BINDLESS_READONLY: case IGC::SAMPLER: case IGC::BINDLESS_SAMPLER: case IGC::RENDER_TARGET: