mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 06:24:51 +08:00
Clean drm interfaces.
- all driver allocations are using SoftPin - remove unneeded methods. - remove unneeded members. - remove unneeded code paths. Change-Id: I3369c0a4d37727210b5a26271d25537ca5218bd4
This commit is contained in:
committed by
sys_ocldev
parent
c9a8f9b1be
commit
45a0ceecfb
@@ -30,30 +30,17 @@
|
||||
namespace OCLRT {
|
||||
|
||||
BufferObject::BufferObject(Drm *drm, int handle, bool isAllocated) : drm(drm), refCount(1), handle(handle), isReused(false), isAllocated(isAllocated) {
|
||||
this->isSoftpin = false;
|
||||
|
||||
this->tiling_mode = I915_TILING_NONE;
|
||||
this->stride = 0;
|
||||
|
||||
execObjectsStorage = nullptr;
|
||||
|
||||
this->size = 0;
|
||||
this->address = nullptr;
|
||||
this->lockedAddress = nullptr;
|
||||
this->offset64 = 0;
|
||||
}
|
||||
|
||||
uint32_t BufferObject::getRefCount() const {
|
||||
return this->refCount.load();
|
||||
}
|
||||
|
||||
bool BufferObject::softPin(uint64_t offset) {
|
||||
this->isSoftpin = true;
|
||||
this->offset64 = offset;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bool BufferObject::close() {
|
||||
drm_gem_close close = {};
|
||||
close.handle = this->handle;
|
||||
@@ -111,11 +98,11 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_
|
||||
execObject.relocation_count = 0; //No relocations, we are SoftPinning
|
||||
execObject.relocs_ptr = 0ul;
|
||||
execObject.alignment = 0;
|
||||
execObject.offset = this->isSoftpin ? this->offset64 : 0;
|
||||
execObject.flags = this->isSoftpin ? EXEC_OBJECT_PINNED : 0;
|
||||
execObject.offset = this->gpuAddress;
|
||||
execObject.flags = EXEC_OBJECT_PINNED;
|
||||
#ifdef __x86_64__
|
||||
// set EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag if whole object resides in 32BIT address space boundary
|
||||
execObject.flags |= (reinterpret_cast<uint64_t>(this->address) + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0;
|
||||
execObject.flags |= (this->gpuAddress + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0;
|
||||
#endif
|
||||
execObject.rsvd1 = drmContextId;
|
||||
execObject.rsvd2 = 0;
|
||||
@@ -157,8 +144,8 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmC
|
||||
drm_i915_gem_execbuffer2 execbuf = {};
|
||||
StackVec<drm_i915_gem_exec_object2, maxFragmentsCount + 1> execObject;
|
||||
|
||||
reinterpret_cast<uint32_t *>(this->address)[0] = 0x05000000;
|
||||
reinterpret_cast<uint32_t *>(this->address)[1] = 0x00000000;
|
||||
reinterpret_cast<uint32_t *>(this->gpuAddress)[0] = 0x05000000;
|
||||
reinterpret_cast<uint32_t *>(this->gpuAddress)[1] = 0x00000000;
|
||||
|
||||
execObject.resize(numberOfBos + 1);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -40,8 +40,6 @@ class BufferObject {
|
||||
public:
|
||||
MOCKABLE_VIRTUAL ~BufferObject(){};
|
||||
|
||||
bool softPin(uint64_t offset);
|
||||
|
||||
bool setTiling(uint32_t mode, uint32_t stride);
|
||||
|
||||
MOCKABLE_VIRTUAL int pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmContextId);
|
||||
@@ -59,8 +57,8 @@ class BufferObject {
|
||||
bool peekIsAllocated() const { return isAllocated; }
|
||||
size_t peekSize() const { return size; }
|
||||
int peekHandle() const { return handle; }
|
||||
void *peekAddress() const { return address; }
|
||||
void setAddress(void *address) { this->address = address; }
|
||||
uint64_t peekAddress() const { return gpuAddress; }
|
||||
void setAddress(uint64_t address) { this->gpuAddress = address; }
|
||||
void *peekLockedAddress() const { return lockedAddress; }
|
||||
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
|
||||
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
|
||||
@@ -87,7 +85,6 @@ class BufferObject {
|
||||
drm_i915_gem_exec_object2 *execObjectsStorage;
|
||||
|
||||
int handle; // i915 gem object handle
|
||||
bool isSoftpin;
|
||||
bool isReused;
|
||||
|
||||
//Tiling
|
||||
@@ -97,9 +94,9 @@ class BufferObject {
|
||||
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_t drmContextId);
|
||||
void processRelocs(int &idx, uint32_t drmContextId);
|
||||
|
||||
uint64_t offset64; // last-seen GPU offset
|
||||
size_t size;
|
||||
void *address; // GPU side virtual address
|
||||
uint64_t gpuAddress = 0llu;
|
||||
|
||||
uint64_t size;
|
||||
void *lockedAddress; // CPU side virtual address
|
||||
|
||||
bool isAllocated = false;
|
||||
|
||||
@@ -128,7 +128,7 @@ uint32_t DrmMemoryManager::unreference(OCLRT::BufferObject *bo, bool synchronous
|
||||
|
||||
if (r == 1) {
|
||||
auto unmapSize = bo->peekUnmapSize();
|
||||
auto address = bo->isAllocated || unmapSize > 0 ? bo->address : nullptr;
|
||||
auto address = bo->isAllocated || unmapSize > 0 ? reinterpret_cast<void *>(bo->gpuAddress) : nullptr;
|
||||
auto allocatorType = bo->peekAllocationType();
|
||||
|
||||
if (bo->isReused) {
|
||||
@@ -206,8 +206,7 @@ OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t si
|
||||
return nullptr;
|
||||
}
|
||||
res->size = size;
|
||||
res->address = reinterpret_cast<void *>(address);
|
||||
res->softPin(address);
|
||||
res->gpuAddress = address;
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -279,8 +278,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(size_t s
|
||||
|
||||
bo->isAllocated = false;
|
||||
bo->setUnmapSize(alignedSize);
|
||||
bo->address = reinterpret_cast<void *>(gpuVirtualAddress);
|
||||
bo->softPin((uint64_t)bo->address);
|
||||
bo->gpuAddress = gpuVirtualAddress;
|
||||
bo->setAllocationType(allocType);
|
||||
|
||||
auto allocation = new DrmAllocation(bo, alignedPtr, gpuVirtualAddress, size, MemoryPool::System4KBPages, false);
|
||||
@@ -319,8 +317,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
|
||||
return nullptr;
|
||||
}
|
||||
bo->size = allocationData.imgInfo->size;
|
||||
bo->address = reinterpret_cast<void *>(gpuRange);
|
||||
bo->softPin(gpuRange);
|
||||
bo->gpuAddress = gpuRange;
|
||||
|
||||
auto ret2 = bo->setTiling(I915_TILING_Y, static_cast<uint32_t>(allocationData.imgInfo->rowPitch));
|
||||
DEBUG_BREAK_IF(ret2 != true);
|
||||
@@ -358,9 +355,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
|
||||
bo->isAllocated = false;
|
||||
bo->setUnmapSize(realAllocationSize);
|
||||
bo->address = reinterpret_cast<void *>(gpuVirtualAddress);
|
||||
uintptr_t offset = (uintptr_t)bo->address;
|
||||
bo->softPin((uint64_t)offset);
|
||||
bo->gpuAddress = gpuVirtualAddress;
|
||||
bo->setAllocationType(allocatorType);
|
||||
auto drmAllocation = new DrmAllocation(bo, const_cast<void *>(allocationData.hostPtr), static_cast<uint64_t>(ptrOffset(gpuVirtualAddress, inputPointerOffset)),
|
||||
allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
|
||||
@@ -409,8 +404,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
|
||||
DrmAllocation *drmAllocation = nullptr;
|
||||
if (limitedRangeAllocation) {
|
||||
// softpin to the GPU address, res if it uses limitedRangeAllocation
|
||||
bo->address = reinterpret_cast<void *>(res);
|
||||
bo->softPin(res);
|
||||
bo->gpuAddress = res;
|
||||
drmAllocation = new DrmAllocation(bo, ptrAlloc, res, alignedAllocationSize,
|
||||
MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
|
||||
} else {
|
||||
@@ -451,8 +445,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si
|
||||
}
|
||||
|
||||
bo->size = size;
|
||||
bo->address = reinterpret_cast<void *>(gpuRange);
|
||||
bo->softPin(gpuRange);
|
||||
bo->gpuAddress = gpuRange;
|
||||
bo->setUnmapSize(size);
|
||||
bo->setAllocationType(storageType);
|
||||
return bo;
|
||||
@@ -490,7 +483,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
|
||||
|
||||
lock.unlock();
|
||||
|
||||
auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle, MemoryPool::SystemCpuInaccessible, false);
|
||||
auto drmAllocation = new DrmAllocation(bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size, handle, MemoryPool::SystemCpuInaccessible, false);
|
||||
|
||||
if (requireSpecificBitness && this->force32bitAllocations) {
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
@@ -517,8 +510,7 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
|
||||
if (!bo) {
|
||||
return nullptr;
|
||||
}
|
||||
bo->setAddress(reinterpret_cast<void *>(gpuRange));
|
||||
bo->softPin(gpuRange);
|
||||
bo->gpuAddress = gpuRange;
|
||||
bo->setUnmapSize(sizeWithPadding);
|
||||
bo->setAllocationType(storageType);
|
||||
return new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding,
|
||||
|
||||
@@ -102,7 +102,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedCrosses32BitBoundaryW
|
||||
drm_i915_gem_exec_object2 execObject;
|
||||
|
||||
memset(&execObject, 0, sizeof(execObject));
|
||||
bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u));
|
||||
bo->setAddress(((uint64_t)1u << 32) - 0x1000u);
|
||||
bo->setSize(0x1000);
|
||||
bo->fillExecObject(execObject, 1);
|
||||
//base address + size > size of 32bit address space
|
||||
@@ -113,7 +113,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWh
|
||||
drm_i915_gem_exec_object2 execObject;
|
||||
|
||||
memset(&execObject, 0, sizeof(execObject));
|
||||
bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u));
|
||||
bo->setAddress(((uint64_t)1u << 32) - 0x1000u);
|
||||
bo->setSize(0xFFF);
|
||||
bo->fillExecObject(execObject, 1);
|
||||
//base address + size < size of 32bit address space
|
||||
@@ -130,7 +130,7 @@ TEST_F(DrmBufferObjectTest, onPinIoctlFailed) {
|
||||
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(this->mock));
|
||||
ASSERT_NE(nullptr, boToPin.get());
|
||||
|
||||
bo->setAddress(buff.get());
|
||||
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
|
||||
BufferObject *boArray[1] = {boToPin.get()};
|
||||
auto ret = bo->pin(boArray, 1, 1);
|
||||
EXPECT_EQ(EINVAL, ret);
|
||||
@@ -151,7 +151,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
|
||||
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(mock.get()));
|
||||
ASSERT_NE(nullptr, boToPin.get());
|
||||
|
||||
bo->setAddress(buff.get());
|
||||
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
|
||||
mock->errnoValue = EFAULT;
|
||||
|
||||
BufferObject *boArray[1] = {boToPin.get()};
|
||||
@@ -179,7 +179,7 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
|
||||
|
||||
BufferObject *array[3] = {boToPin.get(), boToPin2.get(), boToPin3.get()};
|
||||
|
||||
bo->setAddress(buff.get());
|
||||
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
|
||||
auto ret = bo->pin(array, 3, 1);
|
||||
EXPECT_EQ(mock->ioctl_res, ret);
|
||||
uint32_t bb_end = 0x05000000;
|
||||
@@ -191,5 +191,5 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
|
||||
EXPECT_NE(nullptr, boToPin2->execObjectPointerFilled);
|
||||
EXPECT_NE(nullptr, boToPin3->execObjectPointerFilled);
|
||||
|
||||
bo->setAddress(nullptr);
|
||||
bo->setAddress(0llu);
|
||||
}
|
||||
|
||||
@@ -604,7 +604,6 @@ class DrmCommandStreamEnhancedFixture
|
||||
|
||||
protected:
|
||||
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, false) {
|
||||
this->isSoftpin = true;
|
||||
this->size = alignUp(size, 4096);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -468,7 +468,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr) {
|
||||
auto bo = alloc->getBO();
|
||||
ASSERT_NE(nullptr, bo);
|
||||
EXPECT_FALSE(bo->peekIsAllocated());
|
||||
EXPECT_EQ(ptr, bo->peekAddress());
|
||||
EXPECT_EQ(ptr, reinterpret_cast<void *>(bo->peekAddress()));
|
||||
EXPECT_EQ(Sharing::nonSharedResource, alloc->peekSharedHandle());
|
||||
memoryManager->freeGraphicsMemory(alloc);
|
||||
::alignedFree(ptr);
|
||||
@@ -490,7 +490,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_Nullptr) {
|
||||
auto bo = alloc->getBO();
|
||||
ASSERT_NE(nullptr, bo);
|
||||
EXPECT_FALSE(bo->peekIsAllocated());
|
||||
EXPECT_EQ(ptr, bo->peekAddress());
|
||||
EXPECT_EQ(ptr, reinterpret_cast<void *>(bo->peekAddress()));
|
||||
|
||||
memoryManager->freeGraphicsMemory(alloc);
|
||||
::alignedFree(ptr);
|
||||
@@ -514,7 +514,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_MisAligned) {
|
||||
auto bo = alloc->getBO();
|
||||
ASSERT_NE(nullptr, bo);
|
||||
EXPECT_FALSE(bo->peekIsAllocated());
|
||||
EXPECT_EQ(ptrT, bo->peekAddress());
|
||||
EXPECT_EQ(ptrT, reinterpret_cast<void *>(bo->peekAddress()));
|
||||
|
||||
memoryManager->freeGraphicsMemory(alloc);
|
||||
::alignedFree(ptrT);
|
||||
@@ -747,7 +747,7 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked
|
||||
for (int i = 0; i < maxFragmentsCount; i++) {
|
||||
ASSERT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo);
|
||||
EXPECT_EQ(reqs.AllocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekSize());
|
||||
EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress());
|
||||
EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, reinterpret_cast<void *>(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress()));
|
||||
EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekIsAllocated());
|
||||
}
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
@@ -1561,7 +1561,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT
|
||||
auto bo = drmAllocation->getBO();
|
||||
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);
|
||||
EXPECT_EQ(bo->peekUnmapSize(), size);
|
||||
EXPECT_NE(nullptr, bo->peekAddress());
|
||||
EXPECT_NE(0llu, bo->peekAddress());
|
||||
EXPECT_TRUE(bo->peekIsAllocated());
|
||||
EXPECT_EQ(1u, bo->getRefCount());
|
||||
EXPECT_EQ(size, bo->peekSize());
|
||||
@@ -1625,7 +1625,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea
|
||||
bo = drmAllocation->getBO();
|
||||
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);
|
||||
EXPECT_EQ(bo->peekUnmapSize(), size);
|
||||
EXPECT_NE(nullptr, bo->peekAddress());
|
||||
EXPECT_NE(0llu, bo->peekAddress());
|
||||
EXPECT_TRUE(bo->peekIsAllocated());
|
||||
EXPECT_EQ(expectedRefCount, bo->getRefCount());
|
||||
EXPECT_EQ(size, bo->peekSize());
|
||||
@@ -2041,7 +2041,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre
|
||||
auto bo = drmAllocation->getBO();
|
||||
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);
|
||||
EXPECT_EQ(bo->peekUnmapSize(), realSize);
|
||||
EXPECT_NE(nullptr, bo->peekAddress());
|
||||
EXPECT_NE(0llu, bo->peekAddress());
|
||||
EXPECT_TRUE(bo->peekIsAllocated());
|
||||
EXPECT_EQ(1u, bo->getRefCount());
|
||||
EXPECT_EQ(realSize, bo->peekSize());
|
||||
|
||||
Reference in New Issue
Block a user