Read-only memory allocations handling in Wddm

- return InvalidHostPointer when createallocation
fails with NO_VIDEO_MEMORY

Change-Id: I6946eeb04d3a191550478e1d26a6ce0c32b75c34
This commit is contained in:
Hoppe, Mateusz
2018-03-23 10:07:31 +01:00
committed by sys_ocldev
parent e1a0452c6b
commit ed30f6e55f
6 changed files with 69 additions and 12 deletions

View File

@@ -2047,3 +2047,20 @@ HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUn
EXPECT_TRUE(result);
memoryManager.freeGraphicsMemory(wddmAlloc);
}
HWTEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryWhenCreateAllocationFailsThenPopulateOsHandlesReturnsInvalidPointer) {
SetUpMm<FamilyType>();
OsHandleStorage handleStorage;
handleStorage.fragmentCount = 1;
handleStorage.fragmentStorageData[0].cpuPtr = (void *)0x1000;
handleStorage.fragmentStorageData[0].fragmentSize = 0x1000;
handleStorage.fragmentStorageData[0].freeTheFragment = false;
EXPECT_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillOnce(::testing::Return(STATUS_GRAPHICS_NO_VIDEO_MEMORY));
auto result = memoryManager->populateOsHandles(handleStorage);
EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result);
handleStorage.fragmentStorageData[0].freeTheFragment = true;
memoryManager->cleanOsHandles(handleStorage);
}

View File

@@ -125,8 +125,12 @@ class GmockWddm : public Wddm {
return tmp;
}
uintptr_t virtualAllocAddress;
MOCK_METHOD4(makeResident, bool(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim));
MOCK_METHOD1(createAllocationsAndMapGpuVa, NTSTATUS(OsHandleStorage &osHandles));
NTSTATUS baseCreateAllocationAndMapGpuVa(OsHandleStorage &osHandles) {
return Wddm::createAllocationsAndMapGpuVa(osHandles);
}
};
class WddmMemoryManagerFixtureWithGmockWddm {
@@ -145,6 +149,8 @@ class WddmMemoryManagerFixtureWithGmockWddm {
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm);
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm, &GmockWddm::baseCreateAllocationAndMapGpuVa));
}
void TearDown() {
delete memoryManager;

View File

@@ -1075,3 +1075,33 @@ HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondNullThenReturn
EXPECT_FALSE(ret);
EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve));
}
HWTEST_F(WddmWithMockGdiTest, givenReadOnlyMemoryWhenCreateAllocationFailsWithNoVideoMemoryThenCorrectStatusIsReturned) {
class MockCreateAllocation {
public:
static NTSTATUS APIENTRY mockCreateAllocation(D3DKMT_CREATEALLOCATION *param) {
return STATUS_GRAPHICS_NO_VIDEO_MEMORY;
};
};
Gdi *gdi = wddm->getGdi();
gdi->createAllocation = MockCreateAllocation::mockCreateAllocation;
wddm->init<FamilyType>();
OsHandleStorage handleStorage;
OsHandle handle = {0};
ResidencyData residency;
handleStorage.fragmentCount = 1;
handleStorage.fragmentStorageData[0].cpuPtr = (void *)0x1000;
handleStorage.fragmentStorageData[0].fragmentSize = 0x1000;
handleStorage.fragmentStorageData[0].freeTheFragment = false;
handleStorage.fragmentStorageData[0].osHandleStorage = &handle;
handleStorage.fragmentStorageData[0].residency = &residency;
handleStorage.fragmentStorageData[0].osHandleStorage->gmm = getGmm(nullptr, 0);
NTSTATUS result = wddm->createAllocationsAndMapGpuVa(handleStorage);
EXPECT_EQ(STATUS_GRAPHICS_NO_VIDEO_MEMORY, result);
releaseGmm(handleStorage.fragmentStorageData[0].osHandleStorage->gmm);
}