mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Move Buffer MOCS programming to new method
Change-Id: I317977105bdbf85023100b0b3a5b4fdad9871ac4 Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
2689ec32bd
commit
282b0d49ee
@@ -505,6 +505,30 @@ Buffer *Buffer::createBufferHwFromDevice(const Device *device,
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
uint32_t Buffer::getMocsValue(bool disableL3Cache) const {
|
||||
uint64_t bufferAddress = 0;
|
||||
size_t bufferSize = 0;
|
||||
if (getGraphicsAllocation()) {
|
||||
bufferAddress = getGraphicsAllocation()->getGpuAddress();
|
||||
bufferSize = getGraphicsAllocation()->getUnderlyingBufferSize();
|
||||
} else {
|
||||
bufferAddress = reinterpret_cast<uint64_t>(getHostPtr());
|
||||
bufferSize = getSize();
|
||||
}
|
||||
bufferAddress += this->offset;
|
||||
|
||||
bool readOnlyMemObj = isValueSet(getFlags(), CL_MEM_READ_ONLY);
|
||||
bool alignedMemObj = isAligned<MemoryConstants::cacheLineSize>(bufferAddress) &&
|
||||
isAligned<MemoryConstants::cacheLineSize>(bufferSize);
|
||||
|
||||
auto gmmHelper = executionEnvironment->getGmmHelper();
|
||||
if (!disableL3Cache && !isMemObjUncacheable() && (alignedMemObj || readOnlyMemObj || !isMemObjZeroCopy())) {
|
||||
return gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER);
|
||||
} else {
|
||||
return gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED);
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::setSurfaceState(const Device *device,
|
||||
void *surfaceState,
|
||||
size_t svmSize,
|
||||
|
||||
@@ -120,6 +120,8 @@ class Buffer : public MemObj {
|
||||
|
||||
bool isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitList, void *ptr, size_t size);
|
||||
|
||||
uint32_t getMocsValue(bool disableL3Cache) const;
|
||||
|
||||
protected:
|
||||
Buffer(Context *context,
|
||||
MemoryProperties properties,
|
||||
|
||||
@@ -33,7 +33,6 @@ void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, boo
|
||||
using SURFACE_FORMAT = typename RENDER_SURFACE_STATE::SURFACE_FORMAT;
|
||||
using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
|
||||
|
||||
auto gmmHelper = executionEnvironment->getGmmHelper();
|
||||
auto surfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(memory);
|
||||
|
||||
// The graphics allocation for Host Ptr surface will be created in makeResident call and GPU address is expected to be the same as CPU address
|
||||
@@ -52,8 +51,6 @@ void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, boo
|
||||
surfaceState->setHeight(Length.SurfaceState.Height + 1);
|
||||
surfaceState->setDepth(Length.SurfaceState.Depth + 1);
|
||||
|
||||
auto bufferSize = (getGraphicsAllocation() != nullptr) ? getGraphicsAllocation()->getUnderlyingBufferSize() : getSize();
|
||||
|
||||
if (bufferAddress != 0) {
|
||||
surfaceState->setSurfaceType(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER);
|
||||
} else {
|
||||
@@ -66,14 +63,7 @@ void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, boo
|
||||
surfaceState->setTileMode(RENDER_SURFACE_STATE::TILE_MODE_LINEAR);
|
||||
surfaceState->setVerticalLineStride(0);
|
||||
surfaceState->setVerticalLineStrideOffset(0);
|
||||
const bool readOnlyMemObj = isValueSet(getFlags(), CL_MEM_READ_ONLY);
|
||||
const bool alignedMemObj = isAligned<MemoryConstants::cacheLineSize>(bufferAddress) && isAligned<MemoryConstants::cacheLineSize>(bufferSize);
|
||||
if (!disableL3Cache && !this->isMemObjUncacheable() && (alignedMemObj || readOnlyMemObj || !this->isMemObjZeroCopy())) {
|
||||
surfaceState->setMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER));
|
||||
} else {
|
||||
surfaceState->setMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
|
||||
}
|
||||
|
||||
surfaceState->setMemoryObjectControlState(getMocsValue(disableL3Cache));
|
||||
surfaceState->setSurfaceBaseAddress(bufferAddressAligned);
|
||||
|
||||
Gmm *gmm = graphicsAllocation ? graphicsAllocation->getDefaultGmm() : nullptr;
|
||||
|
||||
@@ -229,7 +229,7 @@ bool MemObj::isMemObjUncacheable() const {
|
||||
return isValueSet(properties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MemObj::getGraphicsAllocation() {
|
||||
GraphicsAllocation *MemObj::getGraphicsAllocation() const {
|
||||
return graphicsAllocation;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
virtual void transferDataToHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) { UNRECOVERABLE_IF(true); };
|
||||
virtual void transferDataFromHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) { UNRECOVERABLE_IF(true); };
|
||||
|
||||
GraphicsAllocation *getGraphicsAllocation();
|
||||
GraphicsAllocation *getGraphicsAllocation() const;
|
||||
void resetGraphicsAllocation(GraphicsAllocation *newGraphicsAllocation);
|
||||
GraphicsAllocation *getMcsAllocation() { return mcsAllocation; }
|
||||
void setMcsAllocation(GraphicsAllocation *alloc) { mcsAllocation = alloc; }
|
||||
|
||||
Reference in New Issue
Block a user