Refactor Wddm map gpu address method

Change-Id: I9d3d8675bf80af4079e25b84ba6e09b7883c9e28
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-03-18 10:06:01 +01:00
committed by sys_ocldev
parent 62ae7adf1a
commit 5367440fab
18 changed files with 105 additions and 163 deletions

View File

@@ -18,7 +18,7 @@ void testGfxPartition(uint64_t gpuAddressSpace) {
gfxPartition.init(gpuAddressSpace);
uint64_t gfxTop = gpuAddressSpace + 1;
uint64_t gfxBase = is64bit ? MemoryConstants::max64BitAppAddress + 1 : MemoryConstants::max32BitAddress + 1;
uint64_t gfxBase = MemoryConstants::maxSvmAddress + 1;
const uint64_t sizeHeap32 = 4 * MemoryConstants::gigaByte;
const uint64_t gfxGranularity = 2 * MemoryConstants::megaByte;
@@ -27,6 +27,7 @@ void testGfxPartition(uint64_t gpuAddressSpace) {
EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM));
EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), gfxGranularity);
EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), gfxBase - gfxGranularity);
EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), MemoryConstants::maxSvmAddress);
} else {
// Limited range
EXPECT_FALSE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM));

View File

@@ -1656,35 +1656,29 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenAllocationWasNotUnlockedThenItIsUn
TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
allocation.set32BitAllocation(true);
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, false, false));
}
TEST(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
allocation.set32BitAllocation(false);
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, false, false));
}
TEST(HeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) {
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
allocation.set32BitAllocation(true);
EXPECT_EQ(HeapIndex::HEAP_EXTERNAL, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
EXPECT_EQ(HeapIndex::HEAP_EXTERNAL, MemoryManager::selectHeap(&allocation, false, false));
}
TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenStandardHeapIsUsed) {
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
if (platformDevices[0]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) {
return;
}
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, true, false));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) {
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) {
return;
}
EXPECT_EQ(HeapIndex::HEAP_SVM, MemoryManager::selectHeap(&allocation, &allocation, *platformDevices[0]));
EXPECT_EQ(HeapIndex::HEAP_SVM, MemoryManager::selectHeap(&allocation, true, true));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) {
@@ -1693,10 +1687,7 @@ TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocati
auto resourceInfo = static_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
resourceInfo->is64KBPageSuitableValue = true;
allocation.setDefaultGmm(gmm.get());
if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) {
return;
}
EXPECT_EQ(HeapIndex::HEAP_STANDARD64KB, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
EXPECT_EQ(HeapIndex::HEAP_STANDARD64KB, MemoryManager::selectHeap(&allocation, false, true));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) {
@@ -1705,23 +1696,15 @@ TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocati
auto resourceInfo = static_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
resourceInfo->is64KBPageSuitableValue = false;
allocation.setDefaultGmm(gmm.get());
if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) {
return;
}
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, false, true));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) {
return;
}
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, nullptr, *platformDevices[0]));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, false, true));
}
TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
auto hwInfo = *platformDevices[0];
hwInfo.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress;
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, nullptr, hwInfo));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, false, false));
}
TEST(MemoryAllocationTest, givenAllocationTypeWhenPassedToMemoryAllocationConstructorThenAllocationTypeIsStored) {

View File

@@ -19,7 +19,6 @@ uint64_t gGpuAddressSpace = 0ull;
#ifdef __cplusplus // If used by C++ code,
extern "C" { // we need to export the C interface
#endif
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle,
IN DWORD nReason,
IN LPVOID Reserved) {
@@ -194,7 +193,6 @@ NTSTATUS __stdcall D3DKMTDestroyAllocation2(IN CONST D3DKMT_DESTROYALLOCATION2 *
}
NTSTATUS __stdcall D3DKMTMapGpuVirtualAddress(IN OUT D3DDDI_MAPGPUVIRTUALADDRESS *mapGpuVA) {
uint64_t maxSvmAddress = sizeof(size_t) == 8 ? 0x7fffffffffff : 0xffffffff;
if (mapGpuVA == nullptr) {
memset(&gLastCallMapGpuVaArg, 0, sizeof(gLastCallMapGpuVaArg));
return STATUS_INVALID_PARAMETER;
@@ -225,7 +223,7 @@ NTSTATUS __stdcall D3DKMTMapGpuVirtualAddress(IN OUT D3DDDI_MAPGPUVIRTUALADDRESS
mapGpuVA->VirtualAddress = MemoryConstants::pageSize64k;
}
} else {
if (maxSvmAddress != mapGpuVA->MaximumAddress) {
if (MemoryConstants::maxSvmAddress != mapGpuVA->MaximumAddress) {
return STATUS_INVALID_PARAMETER;
}
mapGpuVA->VirtualAddress = mapGpuVA->BaseAddress;

View File

@@ -5,6 +5,8 @@
*
*/
#include "runtime/memory_manager/memory_constants.h"
#include "mock_gdi.h"
extern ADAPTER_INFO gAdapterInfo;
@@ -15,7 +17,7 @@ void InitGfxPartition() {
gAdapterInfo.GfxPartition.Standard64KB.Base = 0x0000b80200000000;
gAdapterInfo.GfxPartition.Standard64KB.Limit = 0x0000efffffffffff;
gAdapterInfo.GfxPartition.SVM.Base = 0;
gAdapterInfo.GfxPartition.SVM.Limit = 0x00007fffffffffff;
gAdapterInfo.GfxPartition.SVM.Limit = MemoryConstants::maxSvmAddress;
gAdapterInfo.GfxPartition.Heap32[0].Base = 0x0000800000000000;
gAdapterInfo.GfxPartition.Heap32[0].Limit = 0x00008000ffffefff;
gAdapterInfo.GfxPartition.Heap32[1].Base = 0x0000800100000000;

View File

@@ -34,14 +34,23 @@ bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeT
makeNonResidentResult.called++;
return makeNonResidentResult.success = Wddm::evict(handles, num, sizeToTrim);
}
bool WddmMock::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, HeapIndex heapIndex) {
bool WddmMock::mapGpuVirtualAddress(WddmAllocation *allocation) {
D3DGPU_VIRTUAL_ADDRESS minimumAddress = gfxPartition.Standard.Base;
D3DGPU_VIRTUAL_ADDRESS maximumAddress = gfxPartition.Standard.Limit;
if (allocation->getAlignedCpuPtr()) {
minimumAddress = 0u;
maximumAddress = MemoryConstants::maxSvmAddress;
}
return mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), minimumAddress, maximumAddress,
reinterpret_cast<D3DGPU_VIRTUAL_ADDRESS>(allocation->getAlignedCpuPtr()), allocation->getGpuAddressToModify());
}
bool WddmMock::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) {
mapGpuVirtualAddressResult.called++;
mapGpuVirtualAddressResult.cpuPtrPassed = cpuPtr;
mapGpuVirtualAddressResult.cpuPtrPassed = reinterpret_cast<void *>(preferredAddress);
if (callBaseMapGpuVa) {
return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, gpuPtr, heapIndex);
return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddress(gmm, handle, minimumAddress, maximumAddress, preferredAddress, gpuPtr);
} else {
gpuPtr = reinterpret_cast<D3DGPU_VIRTUAL_ADDRESS>(cpuPtr);
gpuPtr = preferredAddress;
return mapGpuVaStatus;
}
}
@@ -186,7 +195,7 @@ bool WddmMock::openAdapter() {
void WddmMock::setHeap32(uint64_t base, uint64_t size) {
gfxPartition.Heap32[3].Base = base;
gfxPartition.Heap32[3].Limit = size;
gfxPartition.Heap32[3].Limit = base + size;
}
GMM_GFX_PARTITIONING *WddmMock::getGfxPartitionPtr() {

View File

@@ -52,6 +52,7 @@ class WddmMock : public Wddm {
using Wddm::gdi;
using Wddm::getSystemInfo;
using Wddm::gmmMemory;
using Wddm::mapGpuVirtualAddress;
using Wddm::pagingFenceAddress;
using Wddm::pagingQueue;
using Wddm::temporaryResources;
@@ -63,7 +64,8 @@ class WddmMock : public Wddm {
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override;
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override;
bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, HeapIndex heapIndex) override;
bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) override;
bool mapGpuVirtualAddress(WddmAllocation *allocation);
bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override;
NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle) override;
bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override;

View File

@@ -82,7 +82,7 @@ TEST_F(Wddm20Tests, givenNullPageTableManagerAndRenderCompressedResourceWhenMapp
allocation.setDefaultGmm(gmm.get());
allocation.getHandleToModify(0u) = ALLOCATION_HANDLE;
EXPECT_TRUE(wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()));
EXPECT_TRUE(wddm->mapGpuVirtualAddress(&allocation));
}
TEST(Wddm20EnumAdaptersTest, expectTrue) {
@@ -205,7 +205,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz
EXPECT_EQ(STATUS_SUCCESS, status);
EXPECT_NE(0, allocation.getDefaultHandle());
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
bool ret = wddm->mapGpuVirtualAddress(&allocation);
EXPECT_TRUE(ret);
EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages);
@@ -247,59 +247,27 @@ TEST_F(Wddm20WithMockGdiDllTests, givenWddmAllocationWhenMappingGpuVaThenUseGmmS
auto mockResourceInfo = static_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
mockResourceInfo->overrideReturnedSize(allocation.getAlignedSize() + (2 * MemoryConstants::pageSize));
wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
wddm->mapGpuVirtualAddress(&allocation);
uint64_t expectedSizeInPages = static_cast<uint64_t>(mockResourceInfo->getSizeAllocation() / MemoryConstants::pageSize);
EXPECT_EQ(expectedSizeInPages, getLastCallMapGpuVaArgFcn()->SizeInPages);
}
TEST_F(Wddm20Tests, createAllocation32bit) {
uint64_t heap32baseAddress = 0x40000;
uint64_t heap32Size = 0x40000;
wddm->setHeap32(heap32baseAddress, heap32Size);
MockWddmAllocation allocation;
Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
allocation.setDefaultGmm(gmm);
allocation.set32BitAllocation(true); // mark 32 bit allocation
auto status = wddm->createAllocation(&allocation);
EXPECT_EQ(STATUS_SUCCESS, status);
EXPECT_TRUE(allocation.handle != 0);
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
EXPECT_TRUE(ret);
EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called);
EXPECT_LE(heap32baseAddress, allocation.getGpuAddress());
EXPECT_GT(heap32baseAddress + heap32Size, allocation.getGpuAddress());
auto success = wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_TRUE(success);
delete gmm;
}
TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap0ThenItHasGpuAddressWithinHeapInternalLimits) {
void *alignedPtr = (void *)0x12000;
size_t alignedSize = 0x2000;
WddmAllocation allocation(GraphicsAllocation::AllocationType::KERNEL_ISA, alignedPtr, alignedSize, nullptr, MemoryPool::MemoryNull, false);
std::unique_ptr<Gmm> gmm(GmmHelperFunctions::getGmm(alignedPtr, alignedSize));
uint64_t gpuAddress = 0u;
auto heapBase = wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base;
auto heapLimit = wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit;
allocation.getHandleToModify(0u) = ALLOCATION_HANDLE;
allocation.setDefaultGmm(GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()));
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, allocation.getAlignedCpuPtr(), *hardwareInfoTable[wddm->getGfxPlatform()->eProductFamily]));
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
bool ret = wddm->mapGpuVirtualAddress(gmm.get(), ALLOCATION_HANDLE, heapBase, heapLimit, 0u, gpuAddress);
EXPECT_TRUE(ret);
auto cannonizedHeapBase = GmmHelper::canonize(heapBase);
auto cannonizedHeapEnd = GmmHelper::canonize(heapLimit);
auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base);
auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit);
EXPECT_GE(allocation.getGpuAddress(), cannonizedHeapBase);
EXPECT_LE(allocation.getGpuAddress(), cannonizedHeapEnd);
delete allocation.getDefaultGmm();
EXPECT_GE(gpuAddress, cannonizedHeapBase);
EXPECT_LE(gpuAddress, cannonizedHeapEnd);
}
TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarkedAllocationsAreDestroyed) {
@@ -345,7 +313,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) {
EXPECT_EQ(STATUS_SUCCESS, status);
EXPECT_TRUE(allocation.getDefaultHandle() != 0);
auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
auto error = wddm->mapGpuVirtualAddress(&allocation);
EXPECT_TRUE(error);
EXPECT_TRUE(allocation.getGpuAddress() != 0);
@@ -369,7 +337,7 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) {
auto status = wddm->createAllocation(&allocation);
EXPECT_EQ(STATUS_SUCCESS, status);
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
bool ret = wddm->mapGpuVirtualAddress(&allocation);
EXPECT_TRUE(ret);
EXPECT_NE(0u, allocation.getGpuAddress());
@@ -390,7 +358,7 @@ TEST_F(Wddm20Tests, makeResidentNonResident) {
EXPECT_EQ(STATUS_SUCCESS, status);
EXPECT_TRUE(allocation.getDefaultHandle() != 0);
auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
auto error = wddm->mapGpuVirtualAddress(&allocation);
EXPECT_TRUE(error);
EXPECT_TRUE(allocation.getGpuAddress() != 0);
@@ -461,7 +429,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
ASSERT_NE(nullptr, wddmAllocation);
if (is32bit) {
if (is32bit && executionEnvironment->isFullRangeSvm()) {
EXPECT_NE(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr);
} else {
EXPECT_EQ(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr);

View File

@@ -24,7 +24,7 @@ class WddmWithKmDafMock : public Wddm {
public:
using Wddm::featureTable;
using Wddm::gdi;
using Wddm::mapGpuVirtualAddressImpl;
using Wddm::mapGpuVirtualAddress;
WddmWithKmDafMock() : Wddm() {
kmDafListener.reset(new KmDafListenerMock);
@@ -79,8 +79,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenMapGpuVirtualAddressIsCalledThenKmDaf
auto gmm = std::unique_ptr<Gmm>(new Gmm(nullptr, 1, false));
allocation.setDefaultGmm(gmm.get());
auto heapIndex = MemoryManager::selectHeap(&allocation, allocation.getUnderlyingBuffer(), *platformDevices[0]);
wddmWithKmDafMock->mapGpuVirtualAddressImpl(allocation.getDefaultGmm(), allocation.getDefaultHandle(), allocation.getUnderlyingBuffer(), allocation.getGpuAddressToModify(), heapIndex);
wddmWithKmDafMock->mapGpuVirtualAddress(allocation.getDefaultGmm(), allocation.getDefaultHandle(), wddmWithKmDafMock->getGfxPartition().Standard.Base, wddmWithKmDafMock->getGfxPartition().Standard.Limit, 0u, allocation.getGpuAddressToModify());
EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyMapGpuVAParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyMapGpuVAParametrization.hAdapter);

View File

@@ -819,6 +819,8 @@ TEST_F(WddmMemoryManagerTest, given32BitAllocationWhenItIsCreatedThenItHasNonZer
ASSERT_NE(nullptr, gpuAllocation);
EXPECT_NE(0llu, gpuAllocation->getGpuAddressToPatch());
EXPECT_LE(GmmHelper::canonize(wddm->getExternalHeapBase()), gpuAllocation->getGpuAddress());
EXPECT_GT(GmmHelper::canonize(wddm->getExternalHeapBase()) + wddm->getExternalHeapSize() - 1, gpuAllocation->getGpuAddress());
memoryManager->freeGraphicsMemory(gpuAllocation);
}
@@ -1173,18 +1175,19 @@ TEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocati
struct WddmMemoryManagerWithAsyncDeleterTest : ::testing::Test {
void SetUp() {
executionEnvironment = platform()->peekExecutionEnvironment();
wddm = std::make_unique<WddmMock>();
wddm->gdi.reset(new MockGdi());
wddm->callBaseDestroyAllocations = false;
wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
deleter = new MockDeferredDeleter;
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm.get(), executionEnvironment);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm.get(), *executionEnvironment);
memoryManager->setDeferredDeleter(deleter);
}
MockDeferredDeleter *deleter = nullptr;
std::unique_ptr<WddmMock> wddm;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
ExecutionEnvironment executionEnvironment;
ExecutionEnvironment *executionEnvironment;
};
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) {
@@ -1254,19 +1257,19 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele
}
TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalBaseIsReturned) {
ExecutionEnvironment executionEnvironment;
auto executionEnvironment = platform()->peekExecutionEnvironment();
auto wddm = std::make_unique<WddmMock>();
wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
MockWddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
auto heapBase = wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base;
EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress());
}
TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) {
ExecutionEnvironment executionEnvironment;
auto executionEnvironment = platform()->peekExecutionEnvironment();
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
MockWddmMemoryManager memoryManager(wddm.get(), *executionEnvironment);
auto wddmAlloc = static_cast<WddmAllocation *>(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, reinterpret_cast<void *>(0x1000)));
@@ -1313,12 +1316,12 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation
}
TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLockResultAndmapGpuVirtualAddressIsCalled) {
ExecutionEnvironment executionEnvironment;
auto executionEnvironment = platform()->peekExecutionEnvironment();
DebugManagerStateRestore dbgRestore;
DebugManager.flags.Enable64kbpages.set(true);
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
MockWddmMemoryManager memoryManager64k(wddm.get(), executionEnvironment);
MockWddmMemoryManager memoryManager64k(wddm.get(), *executionEnvironment);
uint32_t lockCount = wddm->lockResult.called;
uint32_t mapGpuVirtualAddressResult = wddm->mapGpuVirtualAddressResult.called;
AllocationData allocationData;
@@ -1326,7 +1329,11 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLoc
GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemory64kb(allocationData);
EXPECT_EQ(lockCount + 1, wddm->lockResult.called);
EXPECT_EQ(mapGpuVirtualAddressResult + 1, wddm->mapGpuVirtualAddressResult.called);
EXPECT_NE(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr);
if (executionEnvironment->isFullRangeSvm()) {
EXPECT_NE(nullptr, wddm->mapGpuVirtualAddressResult.cpuPtrPassed);
} else {
EXPECT_EQ(nullptr, wddm->mapGpuVirtualAddressResult.cpuPtrPassed);
}
memoryManager64k.freeGraphicsMemory(galloc);
}
@@ -1423,7 +1430,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa
auto hwInfo = hardwareInfoTable[wddm.getGfxPlatform()->eProductFamily];
ASSERT_NE(nullptr, hwInfo);
auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, gpuVa, MemoryManager::selectHeap(nullptr, nullptr, *hwInfo));
auto result = wddm.mapGpuVirtualAddress(gmm.get(), ALLOCATION_HANDLE, wddm.getGfxPartition().Standard.Base, wddm.getGfxPartition().Standard.Limit, 0u, gpuVa);
ASSERT_TRUE(result);
EXPECT_EQ(GmmHelper::canonize(wddm.getGfxPartition().Standard.Base), gpuVa);
@@ -1484,8 +1491,7 @@ TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenMappedGp
EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0);
auto heapIndex = MemoryManager::selectHeap(nullptr, nullptr, *hardwareInfoTable[wddm.getGfxPlatform()->eProductFamily]);
auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, gpuVa, heapIndex);
auto result = wddm.mapGpuVirtualAddress(gmm.get(), ALLOCATION_HANDLE, wddm.getGfxPartition().Standard.Base, wddm.getGfxPartition().Standard.Limit, 0u, gpuVa);
ASSERT_TRUE(result);
}
@@ -1496,8 +1502,7 @@ TEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenRetur
WddmMock wddm;
EXPECT_TRUE(wddm.init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
auto heapIndex = MemoryManager::selectHeap(nullptr, nullptr, *hardwareInfoTable[wddm.getGfxPlatform()->eProductFamily]);
auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), 0, nullptr, gpuVa, heapIndex);
auto result = wddm.mapGpuVirtualAddress(gmm.get(), 0, 0, 0, 0, gpuVa);
ASSERT_FALSE(result);
}
@@ -1520,8 +1525,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse
EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0);
auto heapIndex = MemoryManager::selectHeap(nullptr, nullptr, *hardwareInfoTable[wddm->getGfxPlatform()->eProductFamily]);
auto result = wddm->mapGpuVirtualAddressImpl(myGmm, ALLOCATION_HANDLE, nullptr, gpuVa, heapIndex);
auto result = wddm->mapGpuVirtualAddress(myGmm, ALLOCATION_HANDLE, wddm->getGfxPartition().Standard.Base, wddm->getGfxPartition().Standard.Limit, 0u, gpuVa);
EXPECT_TRUE(result);
memoryManager.freeGraphicsMemory(wddmAlloc);
}
@@ -1568,7 +1572,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC
}
TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhenCleanupMemoryManagerThenDontAccessCsr) {
ExecutionEnvironment executionEnvironment;
ExecutionEnvironment &executionEnvironment = *platform()->peekExecutionEnvironment();
auto csr = createCommandStream(*platformDevices, executionEnvironment);
auto wddm = new WddmMock();
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);

View File

@@ -118,7 +118,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test {
gdi = new MockGdi();
wddm->gdi.reset(gdi);
executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
@@ -135,7 +135,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test {
osContext->decRefInternal();
}
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
ExecutionEnvironment *executionEnvironment;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;