@@ -44,22 +44,20 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size,
4444 MemoryAllocation *memoryAllocation = nullptr ;
4545
4646 if (fakeBigAllocations && size > bigAllocation) {
47- memoryAllocation = new MemoryAllocation (true , 1 , (void *)dummyAddress, static_cast <uint64_t >(dummyAddress), size, counter);
47+ memoryAllocation = new MemoryAllocation (true , (void *)dummyAddress, static_cast <uint64_t >(dummyAddress), size, counter);
4848 counter++;
4949 memoryAllocation->dummyAllocation = true ;
5050 memoryAllocation->uncacheable = uncacheable;
5151 return memoryAllocation;
5252 }
5353 auto ptr = allocateSystemMemory (sizeAligned, alignment ? alignUp (alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
54- DEBUG_BREAK_IF (allocationMap.find (ptr) != allocationMap.end ());
5554 if (ptr != nullptr ) {
56- memoryAllocation = new MemoryAllocation (true , 1 , ptr, reinterpret_cast <uint64_t >(ptr), size, counter);
55+ memoryAllocation = new MemoryAllocation (true , ptr, reinterpret_cast <uint64_t >(ptr), size, counter);
5756 if (!memoryAllocation) {
5857 alignedFreeWrapper (ptr);
5958 return nullptr ;
6059 }
6160 memoryAllocation->uncacheable = uncacheable;
62- allocationMap.emplace (ptr, memoryAllocation);
6361 }
6462 counter++;
6563 return memoryAllocation;
@@ -77,12 +75,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
7775 return nullptr ;
7876 }
7977 uint64_t offset = static_cast <uint64_t >(reinterpret_cast <uintptr_t >(ptr) & MemoryConstants::pageMask);
80- MemoryAllocation *memAlloc = new MemoryAllocation (false , 1 , reinterpret_cast <void *>(ptr), Gmm::canonize (reinterpret_cast <uint64_t >(gpuVirtualAddress) + offset), size, counter);
78+ MemoryAllocation *memAlloc = new MemoryAllocation (false , reinterpret_cast <void *>(ptr), Gmm::canonize (reinterpret_cast <uint64_t >(gpuVirtualAddress) + offset), size, counter);
8179 memAlloc->is32BitAllocation = true ;
8280 memAlloc->gpuBaseAddress = Gmm::canonize (allocator32Bit->getBase ());
8381 memAlloc->sizeToFree = allocationSize;
8482
85- allocationMap.emplace (const_cast <void *>(ptr), memAlloc);
8683 counter++;
8784 return memAlloc;
8885 }
@@ -94,22 +91,20 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
9491 ptrAlloc = alignedMallocWrapper (allocationSize, MemoryConstants::allocationAlignment);
9592 void *gpuPointer = allocator32Bit->allocate (allocationSize);
9693
97- DEBUG_BREAK_IF (allocationMap.find (ptrAlloc) != allocationMap.end ());
9894 MemoryAllocation *memoryAllocation = nullptr ;
9995 if (ptrAlloc != nullptr ) {
100- memoryAllocation = new MemoryAllocation (true , 1 , ptrAlloc, Gmm::canonize (reinterpret_cast <uint64_t >(gpuPointer)), size, counter);
96+ memoryAllocation = new MemoryAllocation (true , ptrAlloc, Gmm::canonize (reinterpret_cast <uint64_t >(gpuPointer)), size, counter);
10197 memoryAllocation->is32BitAllocation = true ;
10298 memoryAllocation->gpuBaseAddress = Gmm::canonize (allocator32Bit->getBase ());
10399 memoryAllocation->sizeToFree = allocationSize;
104100 memoryAllocation->cpuPtrAllocated = true ;
105- allocationMap.emplace (ptrAlloc, memoryAllocation);
106101 }
107102 counter++;
108103 return memoryAllocation;
109104}
110105
111106GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle (osHandle handle, bool requireSpecificBitness, bool reuseBO) {
112- auto graphicsAllocation = new MemoryAllocation (false , 1 , reinterpret_cast <void *>(1 ), 1 , 4096u , static_cast <uint64_t >(handle));
107+ auto graphicsAllocation = new MemoryAllocation (false , reinterpret_cast <void *>(1 ), 1 , 4096u , static_cast <uint64_t >(handle));
113108 graphicsAllocation->setSharedHandle (handle);
114109 graphicsAllocation->is32BitAllocation = requireSpecificBitness;
115110 return graphicsAllocation;
@@ -131,29 +126,13 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo
131126 return ;
132127 }
133128
134- bool freeMemory = false ;
135- bool is32BitAllocation = false ;
136129 void *ptr = gfxAllocation->getUnderlyingBuffer ();
137- void *gpuPtrToFree = nullptr ;
138- size_t sizeToFree = 0 ;
139- auto it = allocationMap.find (ptr);
140-
141- if (it != allocationMap.end ()) {
142- it->second ->refCount --;
143- if (it->second ->refCount == 0 ) {
144- freeMemory = it->second ->cpuPtrAllocated ;
145- is32BitAllocation = it->second ->is32BitAllocation ;
146- gpuPtrToFree = reinterpret_cast <void *>(it->second ->getGpuAddress () & ~MemoryConstants::pageMask);
147- sizeToFree = it->second ->sizeToFree ;
148- allocationMap.erase (it);
149- }
130+
131+ if (gfxAllocation->is32BitAllocation ) {
132+ void *gpuPtrToFree = reinterpret_cast <void *>(gfxAllocation->getGpuAddress () & ~MemoryConstants::pageMask);
133+ allocator32Bit->free (gpuPtrToFree, static_cast <MemoryAllocation *>(gfxAllocation)->sizeToFree );
150134 }
151- if (is32BitAllocation) {
152- allocator32Bit->free (gpuPtrToFree, sizeToFree);
153- if (freeMemory) {
154- alignedFreeWrapper (ptr);
155- }
156- } else if (freeMemory) {
135+ if (gfxAllocation->cpuPtrAllocated ) {
157136 alignedFreeWrapper (ptr);
158137 }
159138 delete gfxAllocation;
@@ -172,7 +151,7 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() {
172151}
173152
174153GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation (OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
175- auto allocation = new MemoryAllocation (false , 0 , const_cast <void *>(hostPtr), reinterpret_cast <uint64_t >(hostPtr), hostPtrSize, counter++);
154+ auto allocation = new MemoryAllocation (false , const_cast <void *>(hostPtr), reinterpret_cast <uint64_t >(hostPtr), hostPtrSize, counter++);
176155 allocation->fragmentsStorage = handleStorage;
177156 return allocation;
178157}
0 commit comments