mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 13:33:02 +08:00
Improve OsHandle struct
Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
5c15a65b62
commit
f8f8b53d95
@@ -36,7 +36,7 @@ bool DrmAllocation::setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regi
|
||||
|
||||
if (fragmentsStorage.fragmentCount > 0) {
|
||||
for (uint32_t i = 0; i < fragmentsStorage.fragmentCount; i++) {
|
||||
auto bo = fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
|
||||
auto bo = static_cast<OsHandleLinux *>(fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
|
||||
bo->setCacheRegion(regionIndex);
|
||||
}
|
||||
return true;
|
||||
@@ -54,7 +54,7 @@ void DrmAllocation::makeBOsResident(OsContext *osContext, uint32_t vmHandleId, s
|
||||
if (this->fragmentsStorage.fragmentCount) {
|
||||
for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) {
|
||||
if (!this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContext->getContextId()]) {
|
||||
bindBO(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo, osContext, vmHandleId, bufferObjects, bind);
|
||||
bindBO(static_cast<OsHandleLinux *>(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage)->bo, osContext, vmHandleId, bufferObjects, bind);
|
||||
this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContext->getContextId()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class OsContext;
|
||||
class Drm;
|
||||
enum class CacheRegion : uint16_t;
|
||||
|
||||
struct OsHandle {
|
||||
struct OsHandleLinux : OsHandle {
|
||||
BufferObject *bo = nullptr;
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
|
||||
BufferObject *getBO() const {
|
||||
if (fragmentsStorage.fragmentCount) {
|
||||
return fragmentsStorage.fragmentStorageData[0].osHandleStorage->bo;
|
||||
return static_cast<OsHandleLinux *>(fragmentsStorage.fragmentStorageData[0].osHandleStorage)->bo;
|
||||
}
|
||||
return this->bufferObjects[0];
|
||||
}
|
||||
|
||||
@@ -668,9 +668,12 @@ void DrmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllo
|
||||
fragment.driverAllocation = true;
|
||||
fragment.fragmentCpuPointer = gfxAllocation->getUnderlyingBuffer();
|
||||
fragment.fragmentSize = alignUp(gfxAllocation->getUnderlyingBufferSize(), MemoryConstants::pageSize);
|
||||
fragment.osInternalStorage = new OsHandle();
|
||||
|
||||
auto osHandle = new OsHandleLinux();
|
||||
osHandle->bo = drmMemory->getBO();
|
||||
|
||||
fragment.osInternalStorage = osHandle;
|
||||
fragment.residency = new ResidencyData(maxOsContextCount);
|
||||
fragment.osInternalStorage->bo = drmMemory->getBO();
|
||||
hostPtrManager->storeFragment(gfxAllocation->getRootDeviceIndex(), fragment);
|
||||
}
|
||||
|
||||
@@ -783,18 +786,20 @@ MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStor
|
||||
for (unsigned int i = 0; i < maxFragmentsCount; i++) {
|
||||
// If there is no fragment it means it already exists.
|
||||
if (!handleStorage.fragmentStorageData[i].osHandleStorage && handleStorage.fragmentStorageData[i].fragmentSize) {
|
||||
handleStorage.fragmentStorageData[i].osHandleStorage = new OsHandle();
|
||||
auto osHandle = new OsHandleLinux();
|
||||
|
||||
handleStorage.fragmentStorageData[i].osHandleStorage = osHandle;
|
||||
handleStorage.fragmentStorageData[i].residency = new ResidencyData(maxOsContextCount);
|
||||
|
||||
handleStorage.fragmentStorageData[i].osHandleStorage->bo = allocUserptr((uintptr_t)handleStorage.fragmentStorageData[i].cpuPtr,
|
||||
handleStorage.fragmentStorageData[i].fragmentSize,
|
||||
0, rootDeviceIndex);
|
||||
if (!handleStorage.fragmentStorageData[i].osHandleStorage->bo) {
|
||||
osHandle->bo = allocUserptr((uintptr_t)handleStorage.fragmentStorageData[i].cpuPtr,
|
||||
handleStorage.fragmentStorageData[i].fragmentSize,
|
||||
0, rootDeviceIndex);
|
||||
if (!osHandle->bo) {
|
||||
handleStorage.fragmentStorageData[i].freeTheFragment = true;
|
||||
return AllocationStatus::Error;
|
||||
}
|
||||
|
||||
allocatedBos[numberOfBosAllocated] = handleStorage.fragmentStorageData[i].osHandleStorage->bo;
|
||||
allocatedBos[numberOfBosAllocated] = osHandle->bo;
|
||||
indexesOfAllocatedBos[numberOfBosAllocated] = i;
|
||||
numberOfBosAllocated++;
|
||||
}
|
||||
@@ -822,8 +827,9 @@ MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStor
|
||||
void DrmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) {
|
||||
for (unsigned int i = 0; i < maxFragmentsCount; i++) {
|
||||
if (handleStorage.fragmentStorageData[i].freeTheFragment) {
|
||||
if (handleStorage.fragmentStorageData[i].osHandleStorage->bo) {
|
||||
BufferObject *search = handleStorage.fragmentStorageData[i].osHandleStorage->bo;
|
||||
auto osHandle = static_cast<OsHandleLinux *>(handleStorage.fragmentStorageData[i].osHandleStorage);
|
||||
if (osHandle->bo) {
|
||||
BufferObject *search = osHandle->bo;
|
||||
search->wait(-1);
|
||||
auto refCount = unreference(search, true);
|
||||
DEBUG_BREAK_IF(refCount != 1u);
|
||||
|
||||
Reference in New Issue
Block a user