fix: Allow free of zero sized allocation

Related-To: NEO-9236

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk 2024-02-07 14:13:36 +00:00 committed by Compute-Runtime-Automation
parent d514c675df
commit 5717a726ff
2 changed files with 12 additions and 2 deletions

View File

@ -811,11 +811,10 @@ bool WddmMemoryManager::isMemoryBudgetExhausted() const {
bool WddmMemoryManager::validateAllocation(WddmAllocation *alloc) {
if (alloc == nullptr)
return false;
auto size = alloc->getUnderlyingBufferSize();
if (alloc->physicalMemoryReservation && !alloc->mappedPhysicalMemoryReservation) {
return true;
}
if (alloc->getGpuAddress() == 0u || size == 0 || (alloc->getDefaultHandle() == 0 && alloc->fragmentsStorage.fragmentCount == 0))
if (alloc->getGpuAddress() == 0u || (alloc->getDefaultHandle() == 0 && alloc->fragmentsStorage.fragmentCount == 0))
return false;
return true;
}

View File

@ -3372,6 +3372,17 @@ TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledW
memoryManager.freeGraphicsMemory(wddmAlloc);
}
TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithZeroSizedAllocationThenSuccessIsReturned) {
wddm->init();
MockWddmMemoryManager memoryManager(executionEnvironment);
auto ptr = reinterpret_cast<void *>(0x1234);
WddmAllocation allocation{0, AllocationType::commandBuffer, ptr, castToUint64(ptr), 0, nullptr, MemoryPool::system64KBPages, 0u, 1u};
allocation.getHandleToModify(0u) = 1;
EXPECT_TRUE(memoryManager.validateAllocationMock(&allocation));
}
TEST_F(MockWddmMemoryManagerTest, givenCreateOrReleaseDeviceSpecificMemResourcesWhenCreatingMemoryManagerObjectThenTheseMethodsAreEmpty) {
wddm->init();
MockWddmMemoryManager memoryManager(executionEnvironment);