From 945b3f673343e2057d36f75481c490b0f66b75bd Mon Sep 17 00:00:00 2001 From: "Ossowski, Jacek" Date: Thu, 23 Oct 2025 16:07:56 +0000 Subject: [PATCH] Sampler opaque ptr readiness This change is part of the effort to support opaque pointers in next llvm versions. --- IGC/Compiler/FixResourcePtr.cpp | 5 ++- IGC/LLVM3DBuilder/BuiltinsFrontend.hpp | 4 +- .../BuiltinsFrontendDefinitions.hpp | 40 ++++--------------- 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/IGC/Compiler/FixResourcePtr.cpp b/IGC/Compiler/FixResourcePtr.cpp index 552599830..b7dbaaf6e 100644 --- a/IGC/Compiler/FixResourcePtr.cpp +++ b/IGC/Compiler/FixResourcePtr.cpp @@ -81,7 +81,10 @@ void FixResourcePtr::RemoveGetBufferPtr(GenIntrinsicInst *bufPtr, Value *bufIdx) uint outAS = bufPtr->getType()->getPointerAddressSpace(); uint origAS = outAS; BufferType bufType = (BufferType)(cast(bufPtr->getOperand(1))->getZExtValue()); - uint encodeAS = EncodeAS4GFXResource(*bufIdx, bufType); + // address space contains texture dimension information + // it has to be saved for further use + auto resourceDimType = DecodeAS4GFXResourceType(outAS); + uint encodeAS = EncodeAS4GFXResource(*bufIdx, bufType, 0, false, resourceDimType); if (outAS != encodeAS && (bufType == CONSTANT_BUFFER || bufType == RESOURCE || bufType == UAV)) { // happens to OGL, need to fix if address-space encoding is wrong outAS = encodeAS; diff --git a/IGC/LLVM3DBuilder/BuiltinsFrontend.hpp b/IGC/LLVM3DBuilder/BuiltinsFrontend.hpp index d7c9fe767..bfa028262 100644 --- a/IGC/LLVM3DBuilder/BuiltinsFrontend.hpp +++ b/IGC/LLVM3DBuilder/BuiltinsFrontend.hpp @@ -26,6 +26,7 @@ SPDX-License-Identifier: MIT #include "skuwa/iacm_g10_rev_id.h" #include "skuwa/iacm_g11_rev_id.h" #include "skuwa/iacm_g12_rev_id.h" +#include "IGC/common/ResourceAddrSpace.h" namespace llvm { class GenIntrinsicInst; @@ -172,7 +173,8 @@ public: LLVM3DBuilder(const LLVM3DBuilder &) = delete; LLVM3DBuilder &operator=(const LLVM3DBuilder &) = delete; - static unsigned EncodeASForGFXResource(const llvm::Value &bufIdx, IGC::BufferType bufType, unsigned uniqueIndAS); + static unsigned EncodeASForGFXResource(const llvm::Value &bufIdx, IGC::BufferType bufType, unsigned uniqueIndAS, + IGC::ResourceDimType resourceDimTypeId = std::nullopt); llvm::Value *CreateFAbs(llvm::Value *V); llvm::Value *CreateFSat(llvm::Value *V); diff --git a/IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp b/IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp index 36df20c05..7d397313b 100644 --- a/IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp +++ b/IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp @@ -20,16 +20,7 @@ SPDX-License-Identifier: MIT #include "common/LLVMWarningsPop.hpp" #include "Probe/Assertion.h" #include "visa/include/visa_igc_common_header.h" - -typedef union _gfxResourceAddressSpace { - struct _bits { - unsigned int bufId : 16; - unsigned int bufType : 5; - unsigned int indirect : 1; // bool - unsigned int reserved : 10; - } bits; - unsigned int u32Val; -} GFXResourceAddressSpace; +#include "IGC/common/ResourceAddrSpace.h" enum class ADDRESS_SPACE_TYPE : unsigned int { ADDRESS_SPACE_PRIVATE = 0, @@ -42,29 +33,12 @@ enum class ADDRESS_SPACE_TYPE : unsigned int { template unsigned LLVM3DBuilder::EncodeASForGFXResource(const llvm::Value &bufIdx, - IGC::BufferType bufType, - unsigned uniqueIndAS) { - GFXResourceAddressSpace temp = {}; - - static_assert(sizeof(temp) == 4, "Code below may need and update."); - - temp.u32Val = 0; - IGC_ASSERT((bufType + 1) < IGC::BUFFER_TYPE_UNKNOWN + 1); - temp.bits.bufType = bufType + 1; - if (bufType == IGC::BufferType::SLM) { - return static_cast( - ADDRESS_SPACE_TYPE::ADDRESS_SPACE_LOCAL); // OCL uses addrspace 3 for SLM. We should use the same thing. - } else if (llvm::isa(&bufIdx)) { - const unsigned bufId = (unsigned)(llvm::cast(&bufIdx)->getZExtValue()); - IGC_ASSERT(bufId < (1 << 16)); - temp.bits.bufId = bufId; - return temp.u32Val; - } - - // if it is indirect-buf, it is front-end's job to give a proper(unique) address-space per access - temp.bits.bufId = uniqueIndAS; - temp.bits.indirect = 1; - return temp.u32Val; + IGC::BufferType bufType, + unsigned uniqueIndAS, + IGC::ResourceDimType resourceDimTypeId) { + return IGC::EncodeAS4GFXResource( + bufIdx, bufType, uniqueIndAS, false, + resourceDimTypeId.value_or(IGC::RESOURCE_DIMENSION_TYPE::NUM_RESOURCE_DIMENSION_TYPES)); } template