mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-29 09:03:14 +08:00
WddmMemoryManager: move logic of handling too low host pointer
Check malloc restrictions in method that allocates memory using host ptr Related-To: NEO-2860 Change-Id: If1471c410d9a68e1ebacc6379682bfe98d0d75fe Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
f946cdd288
commit
3abfb7cb3f
@@ -145,7 +145,7 @@ class MemoryManager {
|
||||
return allocateGraphicsMemoryInPreferredPool(properties, GraphicsAllocation::createStorageInfoFromProperties(properties), nullptr);
|
||||
}
|
||||
|
||||
virtual GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) {
|
||||
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) {
|
||||
return allocateGraphicsMemoryInPreferredPool(properties, GraphicsAllocation::createStorageInfoFromProperties(properties), ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -137,25 +137,19 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(co
|
||||
return wddmAllocation.release();
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptrArg) {
|
||||
void *ptr = const_cast<void *>(ptrArg);
|
||||
|
||||
if (ptr == nullptr) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (mallocRestrictions.minAddress > reinterpret_cast<uintptr_t>(ptrArg)) {
|
||||
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) {
|
||||
if (mallocRestrictions.minAddress > reinterpret_cast<uintptr_t>(allocationData.hostPtr)) {
|
||||
auto inputPtr = allocationData.hostPtr;
|
||||
void *reserve = nullptr;
|
||||
void *ptrAligned = alignDown(ptr, MemoryConstants::allocationAlignment);
|
||||
size_t sizeAligned = alignSizeWholePage(ptr, properties.size);
|
||||
size_t offset = ptrDiff(ptr, ptrAligned);
|
||||
auto ptrAligned = alignDown(inputPtr, MemoryConstants::allocationAlignment);
|
||||
size_t sizeAligned = alignSizeWholePage(inputPtr, allocationData.size);
|
||||
size_t offset = ptrDiff(inputPtr, ptrAligned);
|
||||
|
||||
if (!wddm->reserveValidAddressRange(sizeAligned, reserve)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto allocation = new WddmAllocation(properties.allocationType, ptr, properties.size, reserve, MemoryPool::System4KBPages, false);
|
||||
auto allocation = new WddmAllocation(allocationData.type, const_cast<void *>(inputPtr), allocationData.size, reserve, MemoryPool::System4KBPages, false);
|
||||
allocation->setAllocationOffset(offset);
|
||||
|
||||
Gmm *gmm = new Gmm(ptrAligned, sizeAligned, false);
|
||||
@@ -167,10 +161,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithProperties(cons
|
||||
freeGraphicsMemory(allocation);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto allocation = MemoryManager::allocateGraphicsMemoryWithProperties(properties, ptr);
|
||||
DebugManager.logAllocation(allocation);
|
||||
return allocation;
|
||||
return MemoryManager::allocateGraphicsMemoryWithHostPtr(allocationData);
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) {
|
||||
|
||||
@@ -36,7 +36,6 @@ class WddmMemoryManager : public MemoryManager {
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
||||
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
||||
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override;
|
||||
|
||||
@@ -68,6 +67,7 @@ class WddmMemoryManager : public MemoryManager {
|
||||
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user