Release memory when allocation created from shared handle fails on map call

Change-Id: Ic2745c32f54ea9a0418ebb4d29cc41f84deb247d
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-03-19 14:18:05 +01:00
committed by sys_ocldev
parent cacab6b1bc
commit e5a40502aa
3 changed files with 33 additions and 2 deletions

View File

@@ -41,5 +41,12 @@ class MockWddmMemoryManager : public WddmMemoryManager {
getAllocationData(allocationData, MockAllocationProperties(allocateMemory, size, allocationType), {}, ptr);
return allocate32BitGraphicsMemoryImpl(allocationData);
}
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override {
freeGraphicsMemoryImplCalled++;
BaseClass::freeGraphicsMemoryImpl(gfxAllocation);
}
uint32_t freeGraphicsMemoryImplCalled = 0u;
};
} // namespace OCLRT

View File

@@ -208,7 +208,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa
D3DDDI_OPENALLOCATIONINFO allocationInfo;
allocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle();
allocationInfo.hAllocation = static_cast<D3DKMT_HANDLE>(0x4000);
allocationInfo.hAllocation = ALLOCATION_HANDLE;
allocationInfo.PrivateDriverDataSize = sizeof(GMM_RESOURCE_INFO);
gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo;
@@ -219,6 +219,26 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerSimpleTest, whenCreateAllocationFromHandleAndMapCallFailsThenFreeGraphicsMemoryIsCalled) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));
auto osHandle = 1u;
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
auto gmm = std::make_unique<Gmm>(nullptr, 0, false);
D3DDDI_OPENALLOCATIONINFO allocationInfo;
allocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle();
allocationInfo.hAllocation = ALLOCATION_HANDLE;
allocationInfo.PrivateDriverDataSize = sizeof(GMM_RESOURCE_INFO);
wddm->mapGpuVaStatus = false;
wddm->callBaseMapGpuVa = false;
gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo;
EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryImplCalled);
auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false);
EXPECT_EQ(nullptr, allocation);
EXPECT_EQ(1u, memoryManager->freeGraphicsMemoryImplCalled);
}
TEST_F(WddmMemoryManagerSimpleTest,
givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWhenNotAlignedPtrIsPassedThenAlignedGraphicsAllocationIsCreated) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment));