mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 13:33:02 +08:00
break friendship between DrmMM and DrmBO
Related-To: NEO-6364 Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
5a7d14398c
commit
275ec1118e
@@ -29,8 +29,6 @@ class Drm;
|
||||
class OsContext;
|
||||
|
||||
class BufferObject {
|
||||
friend DrmMemoryManager;
|
||||
|
||||
public:
|
||||
BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount);
|
||||
MOCKABLE_VIRTUAL ~BufferObject() = default;
|
||||
@@ -60,10 +58,14 @@ class BufferObject {
|
||||
inline void reference() {
|
||||
this->refCount++;
|
||||
}
|
||||
inline uint32_t unreference() {
|
||||
return this->refCount.fetch_sub(1);
|
||||
}
|
||||
uint32_t getRefCount() const;
|
||||
|
||||
size_t peekSize() const { return size; }
|
||||
int peekHandle() const { return handle; }
|
||||
const Drm *peekDrm() const { return drm; }
|
||||
uint64_t peekAddress() const { return gpuAddress; }
|
||||
void setAddress(uint64_t address) { this->gpuAddress = address; }
|
||||
void *peekLockedAddress() const { return lockedAddress; }
|
||||
@@ -71,6 +73,7 @@ class BufferObject {
|
||||
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
|
||||
uint64_t peekUnmapSize() const { return unmapSize; }
|
||||
bool peekIsReusableAllocation() const { return this->isReused; }
|
||||
void markAsReusableAllocation() { this->isReused = true; }
|
||||
void addBindExtHandle(uint32_t handle);
|
||||
StackVec<uint32_t, 2> &getBindExtHandles() { return bindExtHandles; }
|
||||
void markForCapture() {
|
||||
@@ -111,8 +114,6 @@ class BufferObject {
|
||||
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);
|
||||
void fillExecObjectImpl(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId);
|
||||
|
||||
uint64_t gpuAddress = 0llu;
|
||||
|
||||
void *lockedAddress; // CPU side virtual address
|
||||
|
||||
uint64_t unmapSize = 0;
|
||||
@@ -122,5 +123,8 @@ class BufferObject {
|
||||
|
||||
std::vector<std::array<bool, EngineLimits::maxHandleCount>> bindInfo;
|
||||
StackVec<uint32_t, 2> bindExtHandles;
|
||||
|
||||
private:
|
||||
uint64_t gpuAddress = 0llu;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -101,7 +101,9 @@ BufferObject *DrmMemoryManager::createRootDeviceBufferObject(uint32_t rootDevice
|
||||
bo = allocUserptr(reinterpret_cast<uintptr_t>(memoryForPinBBs[rootDeviceIndex]), MemoryConstants::pageSize, 0, rootDeviceIndex);
|
||||
if (bo) {
|
||||
if (isLimitedRange(rootDeviceIndex)) {
|
||||
bo->gpuAddress = acquireGpuRange(bo->size, rootDeviceIndex, HeapIndex::HEAP_STANDARD);
|
||||
auto boSize = bo->peekSize();
|
||||
bo->setAddress(acquireGpuRange(boSize, rootDeviceIndex, HeapIndex::HEAP_STANDARD));
|
||||
UNRECOVERABLE_IF(boSize < bo->peekSize());
|
||||
}
|
||||
} else {
|
||||
alignedFreeWrapper(memoryForPinBBs[rootDeviceIndex]);
|
||||
@@ -132,7 +134,7 @@ void DrmMemoryManager::releaseDeviceSpecificMemResources(uint32_t rootDeviceInde
|
||||
void DrmMemoryManager::releaseBufferObject(uint32_t rootDeviceIndex) {
|
||||
if (auto bo = pinBBs[rootDeviceIndex]) {
|
||||
if (isLimitedRange(rootDeviceIndex)) {
|
||||
releaseGpuRange(reinterpret_cast<void *>(bo->gpuAddress), bo->size, rootDeviceIndex);
|
||||
releaseGpuRange(reinterpret_cast<void *>(bo->peekAddress()), bo->peekSize(), rootDeviceIndex);
|
||||
}
|
||||
DrmMemoryManager::unreference(bo, true);
|
||||
pinBBs[rootDeviceIndex] = nullptr;
|
||||
@@ -153,12 +155,12 @@ void DrmMemoryManager::commonCleanup() {
|
||||
void DrmMemoryManager::eraseSharedBufferObject(NEO::BufferObject *bo) {
|
||||
auto it = std::find(sharingBufferObjects.begin(), sharingBufferObjects.end(), bo);
|
||||
DEBUG_BREAK_IF(it == sharingBufferObjects.end());
|
||||
releaseGpuRange(reinterpret_cast<void *>((*it)->gpuAddress), (*it)->peekUnmapSize(), this->getRootDeviceIndex(bo->drm));
|
||||
releaseGpuRange(reinterpret_cast<void *>((*it)->peekAddress()), (*it)->peekUnmapSize(), this->getRootDeviceIndex(bo->peekDrm()));
|
||||
sharingBufferObjects.erase(it);
|
||||
}
|
||||
|
||||
void DrmMemoryManager::pushSharedBufferObject(NEO::BufferObject *bo) {
|
||||
bo->isReused = true;
|
||||
bo->markAsReusableAllocation();
|
||||
sharingBufferObjects.push_back(bo);
|
||||
}
|
||||
|
||||
@@ -167,19 +169,19 @@ uint32_t DrmMemoryManager::unreference(NEO::BufferObject *bo, bool synchronousDe
|
||||
return -1;
|
||||
|
||||
if (synchronousDestroy) {
|
||||
while (bo->refCount > 1)
|
||||
while (bo->getRefCount() > 1)
|
||||
;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mtx, std::defer_lock);
|
||||
if (bo->isReused) {
|
||||
if (bo->peekIsReusableAllocation()) {
|
||||
lock.lock();
|
||||
}
|
||||
|
||||
uint32_t r = bo->refCount.fetch_sub(1);
|
||||
uint32_t r = bo->unreference();
|
||||
|
||||
if (r == 1) {
|
||||
if (bo->isReused) {
|
||||
if (bo->peekIsReusableAllocation()) {
|
||||
eraseSharedBufferObject(bo);
|
||||
}
|
||||
|
||||
@@ -242,7 +244,7 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size
|
||||
DEBUG_BREAK_IF(true);
|
||||
return nullptr;
|
||||
}
|
||||
res->gpuAddress = address;
|
||||
res->setAddress(address);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -327,7 +329,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignmentFromUserptr(const Alloc
|
||||
obtainGpuAddress(allocationData, bo.get(), gpuAddress);
|
||||
emitPinningRequest(bo.get(), allocationData);
|
||||
|
||||
auto allocation = std::make_unique<DrmAllocation>(allocationData.rootDeviceIndex, allocationData.type, bo.get(), res, bo->gpuAddress, size, MemoryPool::System4KBPages);
|
||||
auto allocation = std::make_unique<DrmAllocation>(allocationData.rootDeviceIndex, allocationData.type, bo.get(), res, bo->peekAddress(), size, MemoryPool::System4KBPages);
|
||||
allocation->setDriverAllocatedCpuPtr(res);
|
||||
allocation->setReservedAddressRange(reinterpret_cast<void *>(gpuAddress), alignedSVMSize);
|
||||
if (!allocation->setCacheRegion(&this->getDrm(allocationData.rootDeviceIndex), static_cast<CacheRegion>(allocationData.cacheRegion))) {
|
||||
@@ -343,7 +345,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignmentFromUserptr(const Alloc
|
||||
void DrmMemoryManager::obtainGpuAddress(const AllocationData &allocationData, BufferObject *bo, uint64_t gpuAddress) {
|
||||
if ((isLimitedRange(allocationData.rootDeviceIndex) || allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) &&
|
||||
!allocationData.flags.isUSMHostAllocation) {
|
||||
bo->gpuAddress = gpuAddress;
|
||||
bo->setAddress(gpuAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +373,7 @@ DrmAllocation *DrmMemoryManager::allocateUSMHostGraphicsMemory(const AllocationD
|
||||
if (!gpuAddress) {
|
||||
return nullptr;
|
||||
}
|
||||
bo->gpuAddress = gpuAddress;
|
||||
bo->setAddress(gpuAddress);
|
||||
}
|
||||
|
||||
emitPinningRequest(bo.get(), allocationData);
|
||||
@@ -380,7 +382,7 @@ DrmAllocation *DrmMemoryManager::allocateUSMHostGraphicsMemory(const AllocationD
|
||||
allocationData.type,
|
||||
bo.get(),
|
||||
bufferPtr,
|
||||
bo->gpuAddress,
|
||||
bo->peekAddress(),
|
||||
cSize,
|
||||
MemoryPool::System4KBPages);
|
||||
|
||||
@@ -417,14 +419,14 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryWithGpuVa(const Allo
|
||||
}
|
||||
|
||||
UNRECOVERABLE_IF(allocationData.gpuAddress == 0);
|
||||
bo->gpuAddress = allocationData.gpuAddress;
|
||||
bo->setAddress(allocationData.gpuAddress);
|
||||
|
||||
BufferObject *boPtr = bo.get();
|
||||
if (forcePinEnabled && pinBBs.at(allocationData.rootDeviceIndex) != nullptr && alignedSize >= this->pinThreshold) {
|
||||
pinBBs.at(allocationData.rootDeviceIndex)->pin(&boPtr, 1, osContextLinux, 0, osContextLinux->getDrmContextIds()[0]);
|
||||
}
|
||||
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), res, bo->gpuAddress, alignedSize, MemoryPool::System4KBPages);
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), res, bo->peekAddress(), alignedSize, MemoryPool::System4KBPages);
|
||||
allocation->setDriverAllocatedCpuPtr(res);
|
||||
bo.release();
|
||||
|
||||
@@ -452,7 +454,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bo->gpuAddress = gpuVirtualAddress;
|
||||
bo->setAddress(gpuVirtualAddress);
|
||||
|
||||
if (validateHostPtrMemory) {
|
||||
auto boPtr = bo.get();
|
||||
@@ -491,7 +493,7 @@ GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &
|
||||
((void)(ret));
|
||||
|
||||
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, bufferSize, maxOsContextCount));
|
||||
bo->gpuAddress = gpuRange;
|
||||
bo->setAddress(gpuRange);
|
||||
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), nullptr, gpuRange, bufferSize, MemoryPool::SystemCpuInaccessible);
|
||||
allocation->setDefaultGmm(gmm.release());
|
||||
@@ -523,7 +525,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
|
||||
if (!bo) {
|
||||
return nullptr;
|
||||
}
|
||||
bo->gpuAddress = gpuRange;
|
||||
bo->setAddress(gpuRange);
|
||||
|
||||
auto ret2 = bo->setTiling(I915_TILING_Y, static_cast<uint32_t>(allocationData.imgInfo->rowPitch));
|
||||
DEBUG_BREAK_IF(ret2 != true);
|
||||
@@ -559,7 +561,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bo->gpuAddress = GmmHelper::canonize(gpuVirtualAddress);
|
||||
bo->setAddress(GmmHelper::canonize(gpuVirtualAddress));
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), const_cast<void *>(allocationData.hostPtr), GmmHelper::canonize(ptrOffset(gpuVirtualAddress, inputPointerOffset)),
|
||||
allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing);
|
||||
allocation->set32BitAllocation(true);
|
||||
@@ -593,7 +595,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bo->gpuAddress = GmmHelper::canonize(gpuVA);
|
||||
bo->setAddress(GmmHelper::canonize(gpuVA));
|
||||
|
||||
// softpin to the GPU address, res if it uses limitedRange Allocation
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), ptrAlloc, GmmHelper::canonize(gpuVA), alignedAllocationSize,
|
||||
@@ -610,7 +612,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle) {
|
||||
BufferObject *bo = nullptr;
|
||||
for (const auto &i : sharingBufferObjects) {
|
||||
if (i->handle == boHandle) {
|
||||
if (i->peekHandle() == boHandle) {
|
||||
bo = i;
|
||||
bo->reference();
|
||||
break;
|
||||
@@ -666,7 +668,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
|
||||
|
||||
lock.unlock();
|
||||
|
||||
auto drmAllocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size,
|
||||
auto drmAllocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->peekAddress()), bo->peekSize(),
|
||||
handle, MemoryPool::SystemCpuInaccessible);
|
||||
|
||||
if (requireSpecificBitness && this->force32bitAllocations) {
|
||||
@@ -715,7 +717,7 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
|
||||
if (!bo) {
|
||||
return nullptr;
|
||||
}
|
||||
bo->gpuAddress = gpuRange;
|
||||
bo->setAddress(gpuRange);
|
||||
auto allocation = new DrmAllocation(rootDeviceIndex, inputGraphicsAllocation->getAllocationType(), bo.get(), srcPtr, GmmHelper::canonize(ptrOffset(gpuRange, offset)), sizeWithPadding,
|
||||
inputGraphicsAllocation->getMemoryPool());
|
||||
|
||||
@@ -778,7 +780,7 @@ void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation)
|
||||
} else {
|
||||
auto &bos = static_cast<DrmAllocation *>(gfxAllocation)->getBOs();
|
||||
for (auto bo : bos) {
|
||||
unreference(bo, bo && bo->isReused ? false : true);
|
||||
unreference(bo, bo && bo->peekIsReusableAllocation() ? false : true);
|
||||
}
|
||||
closeSharedHandle(gfxAllocation);
|
||||
}
|
||||
@@ -1128,7 +1130,7 @@ void DrmMemoryManager::unlockResourceInLocalMemoryImpl(BufferObject *bo) {
|
||||
if (bo == nullptr)
|
||||
return;
|
||||
|
||||
releaseReservedCpuAddressRange(bo->peekLockedAddress(), bo->peekSize(), this->getRootDeviceIndex(bo->drm));
|
||||
releaseReservedCpuAddressRange(bo->peekLockedAddress(), bo->peekSize(), this->getRootDeviceIndex(bo->peekDrm()));
|
||||
|
||||
[[maybe_unused]] auto ret = munmapFunction(bo->peekLockedAddress(), bo->peekSize());
|
||||
DEBUG_BREAK_IF(ret != 0);
|
||||
|
||||
@@ -26,7 +26,7 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl
|
||||
auto bo = new BufferObject(&getDrm(properties.rootDeviceIndex), openFd.handle, properties.size, maxOsContextCount);
|
||||
bo->setAddress(properties.gpuAddress);
|
||||
|
||||
return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size,
|
||||
return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->peekAddress()), bo->peekSize(),
|
||||
handle, MemoryPool::SystemCpuInaccessible);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl
|
||||
auto bo = new BufferObject(&getDrm(properties.rootDeviceIndex), openFd.handle, properties.size, maxOsContextCount);
|
||||
bo->setAddress(properties.gpuAddress);
|
||||
|
||||
return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size,
|
||||
return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->peekAddress()), bo->peekSize(),
|
||||
handle, MemoryPool::SystemCpuInaccessible);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &
|
||||
obtainGpuAddress(allocationData, bo.get(), gpuAddress);
|
||||
emitPinningRequest(bo.get(), allocationData);
|
||||
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), cpuPointer, bo->gpuAddress, alignedSize, MemoryPool::System4KBPages);
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), cpuPointer, bo->peekAddress(), alignedSize, MemoryPool::System4KBPages);
|
||||
allocation->setMmapPtr(cpuPointer);
|
||||
allocation->setMmapSize(alignedSize);
|
||||
if (pointerDiff != 0) {
|
||||
@@ -122,7 +122,7 @@ void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) {
|
||||
if (bo == nullptr)
|
||||
return nullptr;
|
||||
|
||||
auto rootDeviceIndex = this->getRootDeviceIndex(bo->drm);
|
||||
auto rootDeviceIndex = this->getRootDeviceIndex(bo->peekDrm());
|
||||
|
||||
uint64_t offset = 0;
|
||||
if (!retrieveMmapOffsetForBufferObject(this->getDrm(rootDeviceIndex), *bo, I915_MMAP_OFFSET_WC, offset)) {
|
||||
|
||||
Reference in New Issue
Block a user