mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
Remove copy constructor for GraphicsAllocation
Change-Id: If547a004b6f9e5cadb1f6ba0a0f44c3ac0d1ff0d
This commit is contained in:
committed by
sys_ocldev
parent
eea76094a1
commit
d9dd68a8ef
@@ -61,6 +61,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
};
|
||||
|
||||
virtual ~GraphicsAllocation() = default;
|
||||
GraphicsAllocation &operator=(const GraphicsAllocation &) = delete;
|
||||
GraphicsAllocation(const GraphicsAllocation &) = delete;
|
||||
GraphicsAllocation(void *cpuPtrIn, size_t sizeIn) : size(sizeIn),
|
||||
cpuPtr(cpuPtrIn),
|
||||
gpuAddress((uint64_t)cpuPtrIn),
|
||||
|
||||
@@ -59,7 +59,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size,
|
||||
return nullptr;
|
||||
}
|
||||
memoryAllocation->uncacheable = uncacheable;
|
||||
allocationMap.insert(std::pair<void *, MemoryAllocation>(ptr, *memoryAllocation));
|
||||
allocationMap.emplace(ptr, memoryAllocation);
|
||||
}
|
||||
counter++;
|
||||
return memoryAllocation;
|
||||
@@ -82,7 +82,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
memAlloc->gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase());
|
||||
memAlloc->sizeToFree = allocationSize;
|
||||
|
||||
allocationMap.insert(std::pair<void *, MemoryAllocation>(const_cast<void *>(ptr), *memAlloc));
|
||||
allocationMap.emplace(const_cast<void *>(ptr), memAlloc);
|
||||
counter++;
|
||||
return memAlloc;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
memoryAllocation->gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase());
|
||||
memoryAllocation->sizeToFree = allocationSize;
|
||||
memoryAllocation->cpuPtrAllocated = true;
|
||||
allocationMap.insert(std::pair<void *, MemoryAllocation>(ptrAlloc, *memoryAllocation));
|
||||
allocationMap.emplace(ptrAlloc, memoryAllocation);
|
||||
}
|
||||
counter++;
|
||||
return memoryAllocation;
|
||||
@@ -139,12 +139,12 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo
|
||||
auto it = allocationMap.find(ptr);
|
||||
|
||||
if (it != allocationMap.end()) {
|
||||
it->second.refCount--;
|
||||
if (it->second.refCount == 0) {
|
||||
freeMemory = it->second.cpuPtrAllocated;
|
||||
is32BitAllocation = it->second.is32BitAllocation;
|
||||
gpuPtrToFree = reinterpret_cast<void *>(it->second.getGpuAddress() & ~MemoryConstants::pageMask);
|
||||
sizeToFree = it->second.sizeToFree;
|
||||
it->second->refCount--;
|
||||
if (it->second->refCount == 0) {
|
||||
freeMemory = it->second->cpuPtrAllocated;
|
||||
is32BitAllocation = it->second->is32BitAllocation;
|
||||
gpuPtrToFree = reinterpret_cast<void *>(it->second->getGpuAddress() & ~MemoryConstants::pageMask);
|
||||
sizeToFree = it->second->sizeToFree;
|
||||
allocationMap.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class MemoryAllocation : public GraphicsAllocation {
|
||||
id(count) {}
|
||||
};
|
||||
|
||||
typedef std::map<void *, MemoryAllocation> PointerMap;
|
||||
typedef std::map<void *, MemoryAllocation *> PointerMap;
|
||||
|
||||
class OsAgnosticMemoryManager : public MemoryManager {
|
||||
public:
|
||||
|
||||
@@ -70,34 +70,31 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo
|
||||
delete gmm;
|
||||
return allocateGraphicsMemory(imgInfo.size, MemoryConstants::preferredAlignment);
|
||||
}
|
||||
WddmAllocation allocation(nullptr, imgInfo.size, nullptr);
|
||||
allocation.gmm = gmm;
|
||||
auto status = WddmMemoryManager::createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
|
||||
if (status) {
|
||||
auto *wddmAllocation = new WddmAllocation(allocation);
|
||||
return wddmAllocation;
|
||||
} else {
|
||||
auto allocation = new WddmAllocation(nullptr, imgInfo.size, nullptr);
|
||||
allocation->gmm = gmm;
|
||||
|
||||
if (!WddmMemoryManager::createWddmAllocation(allocation, MemoryType::EXTERNAL_ALLOCATION)) {
|
||||
delete allocation;
|
||||
return nullptr;
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin) {
|
||||
size_t sizeAligned = alignUp(size, MemoryConstants::pageSize64k);
|
||||
bool success = true;
|
||||
Gmm *gmm = nullptr;
|
||||
|
||||
WddmAllocation allocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr);
|
||||
auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr);
|
||||
|
||||
gmm = Gmm::create(nullptr, sizeAligned, false);
|
||||
wddmAllocation->gmm = gmm;
|
||||
|
||||
while (success) {
|
||||
allocation.gmm = gmm;
|
||||
success = wddm->createAllocation64k(&allocation);
|
||||
if (!wddm->createAllocation64k(wddmAllocation)) {
|
||||
delete gmm;
|
||||
delete wddmAllocation;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
break;
|
||||
|
||||
auto *wddmAllocation = new WddmAllocation(allocation);
|
||||
auto cpuPtr = lockResource(wddmAllocation);
|
||||
wddmAllocation->setLocked(true);
|
||||
|
||||
@@ -110,42 +107,33 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s
|
||||
return wddmAllocation;
|
||||
}
|
||||
|
||||
delete gmm;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) {
|
||||
size_t newAlignment = alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize;
|
||||
size_t sizeAligned = size ? alignUp(size, MemoryConstants::pageSize) : MemoryConstants::pageSize;
|
||||
void *pSysMem = allocateSystemMemory(sizeAligned, newAlignment);
|
||||
bool success = true;
|
||||
Gmm *gmm = nullptr;
|
||||
|
||||
if (pSysMem == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WddmAllocation allocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr);
|
||||
allocation.cpuPtrAllocated = true;
|
||||
auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr);
|
||||
wddmAllocation->cpuPtrAllocated = true;
|
||||
|
||||
gmm = Gmm::create(pSysMem, sizeAligned, uncacheable);
|
||||
|
||||
while (success) {
|
||||
allocation.gmm = gmm;
|
||||
|
||||
bool success = createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
|
||||
if (!success)
|
||||
break;
|
||||
|
||||
auto *wddmAllocation = new WddmAllocation(allocation);
|
||||
return wddmAllocation;
|
||||
}
|
||||
wddmAllocation->gmm = gmm;
|
||||
|
||||
if (!createWddmAllocation(wddmAllocation, MemoryType::EXTERNAL_ALLOCATION)) {
|
||||
delete gmm;
|
||||
delete wddmAllocation;
|
||||
freeSystemMemory(pSysMem);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return wddmAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const void *ptrArg) {
|
||||
void *ptr = const_cast<void *>(ptrArg);
|
||||
|
||||
@@ -180,8 +168,6 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) {
|
||||
GraphicsAllocation *graphicsAllocation = nullptr;
|
||||
bool success = true;
|
||||
Gmm *gmm = nullptr;
|
||||
const void *ptrAligned = nullptr;
|
||||
size_t sizeAligned = size;
|
||||
@@ -203,66 +189,61 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
|
||||
cpuPtrAllocated = true;
|
||||
}
|
||||
|
||||
WddmAllocation allocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), sizeAligned, nullptr);
|
||||
allocation.cpuPtrAllocated = cpuPtrAllocated;
|
||||
allocation.is32BitAllocation = true;
|
||||
allocation.allocationOffset = offset;
|
||||
auto wddmAllocation = new WddmAllocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), sizeAligned, nullptr);
|
||||
wddmAllocation->cpuPtrAllocated = cpuPtrAllocated;
|
||||
wddmAllocation->is32BitAllocation = true;
|
||||
wddmAllocation->allocationOffset = offset;
|
||||
|
||||
gmm = Gmm::create(ptrAligned, sizeAligned, false);
|
||||
wddmAllocation->gmm = gmm;
|
||||
|
||||
while (success) {
|
||||
allocation.gmm = gmm;
|
||||
|
||||
success = createWddmAllocation(&allocation, memoryType);
|
||||
if (!success)
|
||||
break;
|
||||
|
||||
auto *wddmAllocation = new WddmAllocation(allocation);
|
||||
graphicsAllocation = wddmAllocation;
|
||||
graphicsAllocation->is32BitAllocation = true;
|
||||
auto baseAddress = memoryType == MemoryType::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base;
|
||||
graphicsAllocation->gpuBaseAddress = Gmm::canonize(baseAddress);
|
||||
|
||||
return graphicsAllocation;
|
||||
}
|
||||
|
||||
if (!createWddmAllocation(wddmAllocation, memoryType)) {
|
||||
delete gmm;
|
||||
delete wddmAllocation;
|
||||
freeSystemMemory(pSysMem);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wddmAllocation->is32BitAllocation = true;
|
||||
auto baseAddress = memoryType == MemoryType::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base;
|
||||
wddmAllocation->gpuBaseAddress = Gmm::canonize(baseAddress);
|
||||
|
||||
return wddmAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle) {
|
||||
WddmAllocation allocation(nullptr, 0, handle);
|
||||
auto allocation = new WddmAllocation(nullptr, 0, handle);
|
||||
bool is32BitAllocation = false;
|
||||
|
||||
if (ntHandle) {
|
||||
wddm->openNTHandle((HANDLE)((UINT_PTR)handle), &allocation);
|
||||
} else {
|
||||
if (wddm->openSharedHandle(handle, &allocation) == false) {
|
||||
bool status = ntHandle ? wddm->openNTHandle((HANDLE)((UINT_PTR)handle), allocation)
|
||||
: wddm->openSharedHandle(handle, allocation);
|
||||
|
||||
if (!status) {
|
||||
delete allocation;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Shared objects are passed without size
|
||||
size_t size = allocation.gmm->gmmResourceInfo->getSizeAllocation();
|
||||
allocation.setSize(size);
|
||||
size_t size = allocation->gmm->gmmResourceInfo->getSizeAllocation();
|
||||
allocation->setSize(size);
|
||||
|
||||
void *ptr = nullptr;
|
||||
if (is32bit) {
|
||||
if (!wddm->reserveValidAddressRange(size, ptr)) {
|
||||
delete allocation;
|
||||
return nullptr;
|
||||
}
|
||||
allocation.setReservedAddress(ptr);
|
||||
allocation->setReservedAddress(ptr);
|
||||
} else if (requireSpecificBitness && this->force32bitAllocations) {
|
||||
is32BitAllocation = true;
|
||||
allocation.is32BitAllocation = true;
|
||||
allocation.gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase());
|
||||
allocation->is32BitAllocation = true;
|
||||
allocation->gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase());
|
||||
}
|
||||
auto status = wddm->mapGpuVirtualAddress(&allocation, ptr, size, is32BitAllocation, false, false);
|
||||
status = wddm->mapGpuVirtualAddress(allocation, ptr, size, is32BitAllocation, false, false);
|
||||
DEBUG_BREAK_IF(!status);
|
||||
allocation.setGpuAddress(allocation.gpuPtr);
|
||||
allocation->setGpuAddress(allocation->gpuPtr);
|
||||
|
||||
return new WddmAllocation(allocation);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool /*isReused*/) {
|
||||
|
||||
@@ -279,7 +279,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic
|
||||
|
||||
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphicsAllocationSizeIsZeroThenWriteMemoryIsNotAllowed) {
|
||||
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(*platformDevices[0], true));
|
||||
auto gfxAllocation = GraphicsAllocation((void *)0x1234, 0);
|
||||
GraphicsAllocation gfxAllocation((void *)0x1234, 0);
|
||||
|
||||
EXPECT_FALSE(aubCsr->writeMemory(gfxAllocation));
|
||||
}
|
||||
|
||||
@@ -931,7 +931,7 @@ HWTEST_F(CommandStreamReceiverCQFlushTaskTests, getCSShouldReturnACSWithEnoughSi
|
||||
EXPECT_GE(commandStream.getAvailableSpace(), sizeRequested);
|
||||
commandStream.getSpace(sizeRequested - sizeCQReserves);
|
||||
|
||||
GraphicsAllocation allocation = GraphicsAllocation((void *)0x1234, 1);
|
||||
GraphicsAllocation allocation((void *)0x1234, 1);
|
||||
LinearStream linear(&allocation);
|
||||
|
||||
auto blocking = true;
|
||||
|
||||
@@ -37,11 +37,17 @@
|
||||
#include "unit_tests/mocks/mock_memory_manager.h"
|
||||
|
||||
#include <future>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
typedef Test<MemoryAllocatorFixture> MemoryAllocatorTest;
|
||||
|
||||
TEST(GraphicsAllocationTest, defaultTypeTraits) {
|
||||
EXPECT_FALSE(std::is_copy_constructible<GraphicsAllocation>::value);
|
||||
EXPECT_FALSE(std::is_copy_assignable<GraphicsAllocation>::value);
|
||||
}
|
||||
|
||||
TEST(GraphicsAllocationTest, Ctor) {
|
||||
void *cpuPtr = (void *)0x30000;
|
||||
size_t size = 0x1000;
|
||||
|
||||
@@ -116,7 +116,7 @@ TEST_F(DrmCommandStreamTest, makeResident) {
|
||||
.Times(0);
|
||||
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
|
||||
.Times(0);
|
||||
auto graphicsAllocation = DrmAllocation(nullptr, nullptr, 1024);
|
||||
DrmAllocation graphicsAllocation(nullptr, nullptr, 1024);
|
||||
csr->makeResident(graphicsAllocation);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ TEST_F(DrmCommandStreamTest, makeResidentTwiceTheSame) {
|
||||
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
|
||||
.Times(0);
|
||||
|
||||
auto graphicsAllocation = DrmAllocation(nullptr, nullptr, 1024);
|
||||
DrmAllocation graphicsAllocation(nullptr, nullptr, 1024);
|
||||
|
||||
csr->makeResident(graphicsAllocation);
|
||||
csr->makeResident(graphicsAllocation);
|
||||
@@ -146,7 +146,7 @@ TEST_F(DrmCommandStreamTest, makeResidentSizeZero) {
|
||||
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
|
||||
.Times(0);
|
||||
|
||||
auto graphicsAllocation = DrmAllocation(nullptr, nullptr, 0);
|
||||
DrmAllocation graphicsAllocation(nullptr, nullptr, 0);
|
||||
|
||||
csr->makeResident(graphicsAllocation);
|
||||
}
|
||||
@@ -161,8 +161,8 @@ TEST_F(DrmCommandStreamTest, makeResidentResized) {
|
||||
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
|
||||
.Times(0);
|
||||
|
||||
auto graphicsAllocation = DrmAllocation(nullptr, nullptr, 1024);
|
||||
auto graphicsAllocation2 = DrmAllocation(nullptr, nullptr, 8192);
|
||||
DrmAllocation graphicsAllocation(nullptr, nullptr, 1024);
|
||||
DrmAllocation graphicsAllocation2(nullptr, nullptr, 8192);
|
||||
|
||||
csr->makeResident(graphicsAllocation);
|
||||
csr->makeResident(graphicsAllocation2);
|
||||
@@ -413,8 +413,8 @@ TEST_F(DrmCommandStreamTest, FlushCheckFlags) {
|
||||
.Times(1)
|
||||
.WillRepeatedly(::testing::Return(0));
|
||||
|
||||
auto allocation = DrmAllocation(nullptr, (void *)0x7FFFFFFF, 1024);
|
||||
auto allocation2 = DrmAllocation(nullptr, (void *)0x307FFFFFFF, 1024);
|
||||
DrmAllocation allocation(nullptr, (void *)0x7FFFFFFF, 1024);
|
||||
DrmAllocation allocation2(nullptr, (void *)0x307FFFFFFF, 1024);
|
||||
csr->makeResident(allocation);
|
||||
csr->makeResident(allocation2);
|
||||
csr->addBatchBufferEnd(cs, nullptr);
|
||||
@@ -448,7 +448,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFree) {
|
||||
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
|
||||
.Times(1);
|
||||
|
||||
auto allocation = DrmAllocation(nullptr, nullptr, 1024);
|
||||
DrmAllocation allocation(nullptr, nullptr, 1024);
|
||||
|
||||
csr->makeResident(allocation);
|
||||
csr->addBatchBufferEnd(cs, nullptr);
|
||||
@@ -493,7 +493,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFreeCloseFailed) {
|
||||
.WillOnce(::testing::Return(-1));
|
||||
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
|
||||
.Times(1);
|
||||
auto allocation = DrmAllocation(nullptr, nullptr, 1024);
|
||||
DrmAllocation allocation(nullptr, nullptr, 1024);
|
||||
|
||||
csr->makeResident(allocation);
|
||||
csr->addBatchBufferEnd(cs, nullptr);
|
||||
@@ -1341,7 +1341,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag
|
||||
|
||||
TEST_F(DrmCommandStreamLeaksTest, makeResidentSizeZero) {
|
||||
std::unique_ptr<BufferObject> buffer(this->createBO(0));
|
||||
auto allocation = DrmAllocation(buffer.get(), nullptr, buffer->peekSize());
|
||||
DrmAllocation allocation(buffer.get(), nullptr, buffer->peekSize());
|
||||
EXPECT_EQ(nullptr, allocation.getUnderlyingBuffer());
|
||||
EXPECT_EQ(buffer->peekSize(), allocation.getUnderlyingBufferSize());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user