diff --git a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp index c794334653..0b021fcfa1 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -734,6 +734,49 @@ TEST_F(GmmTests, givenInvalidFlagsSetWhenAskedForUnifiedAuxTranslationCapability EXPECT_FALSE(gmm->unifiedAuxTranslationCapable()); // RenderCompressed == 0 } +TEST_F(GmmTests, whenLargePagesAreImplicitlyAllowedThenEnableOptimizationPadding) { + size_t allocationSize = 128; + Gmm gmm(getGmmClientContext(), nullptr, allocationSize, 0, false); + EXPECT_FALSE(gmm.resourceParams.Flags.Info.NoOptimizationPadding); +} + +TEST_F(GmmTests, whenLargePagesAreExplicitlyAllowedAndUserPtrIsNullThenAllowOptimizationPadding) { + size_t allocationSize = 128; + bool allowLargePages = true; + Gmm gmm(getGmmClientContext(), nullptr, allocationSize, 0, false, false, false, {}, allowLargePages); + EXPECT_FALSE(gmm.resourceParams.Flags.Info.NoOptimizationPadding); +} + +TEST_F(GmmTests, whenLargePagesAreExplicitlyDisallowedButUserPtrIsNotNullThenAllowOptimizationPadding) { + const void *dummyPtr = reinterpret_cast(0x123); + size_t allocationSize = 128; + bool allowLargePages = false; + Gmm gmm(getGmmClientContext(), dummyPtr, allocationSize, 0, false, false, false, {}, allowLargePages); + EXPECT_FALSE(gmm.resourceParams.Flags.Info.NoOptimizationPadding); +} + +TEST_F(GmmTests, whenLargePagesAreExplicitlyDisallowedAndUserPtrIsNullThenDisableOptimizationPadding) { + size_t allocationSize = 128; + bool allowLargePages = false; + Gmm gmm(getGmmClientContext(), nullptr, allocationSize, 0, false, false, false, {}, allowLargePages); + EXPECT_TRUE(gmm.resourceParams.Flags.Info.NoOptimizationPadding); +} + +TEST_F(GmmTests, givenSizeIsMisallignedTo64kbWhenForceDisablingLargePagesThenSizeIsPreserved) { + const void *dummyPtr = reinterpret_cast(0x123); + size_t allocationSize = 256U; + bool allowLargePages = false; + Gmm gmm(getGmmClientContext(), dummyPtr, allocationSize, 0, false, false, false, {}, allowLargePages); + EXPECT_EQ(allocationSize, gmm.resourceParams.BaseWidth64); +} + +TEST_F(GmmTests, givenSizeIsAllignedTo64kbWhenForceDisablingLargePagesThenSizeIsAlteredToBreak64kbAlignment) { + size_t allocationSize = MemoryConstants::pageSize64k; + bool allowLargePages = false; + Gmm gmm(getGmmClientContext(), nullptr, allocationSize, 0, false, false, false, {}, allowLargePages); + EXPECT_EQ(allocationSize + MemoryConstants::pageSize, gmm.resourceParams.BaseWidth64); +} + TEST(GmmTest, givenHwInfoWhenDeviceIsCreatedThenSetThisHwInfoToGmmHelper) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); EXPECT_EQ(&device->getHardwareInfo(), device->getGmmHelper()->getHardwareInfo()); diff --git a/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h b/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h index 02cb3bbe73..3bbb81126e 100644 --- a/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h +++ b/opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h @@ -44,8 +44,8 @@ class MockWddmMemoryManager : public MemoryManagerCreate { return BaseClass::allocateGraphicsMemoryInDevicePool(allocationData, status); } - size_t hugeGfxMemoryChunkSize = BaseClass::getHugeGfxMemoryChunkSize(); - size_t getHugeGfxMemoryChunkSize() const override { return hugeGfxMemoryChunkSize; } + size_t hugeGfxMemoryChunkSize = BaseClass::getHugeGfxMemoryChunkSize(preferredAllocationMethod); + size_t getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const override { return hugeGfxMemoryChunkSize; } MockWddmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, false, executionEnvironment) { hostPtrManager.reset(new MockHostPtrManager); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 16585ca797..8807b95d5d 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -155,7 +155,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocation64IsCalledThenKmDafLi auto gmm = std::make_unique(rootDeviceEnvironment->getGmmClientContext(), nullptr, 1, 0, false); auto handle = 0u; - wddmWithKmDafMock->createAllocation64k(gmm.get(), handle); + wddmWithKmDafMock->createAllocation(gmm.get(), handle); EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.ftrKmdDaf); EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.hAdapter); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 2535838345..dc53a29a7a 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1548,10 +1548,10 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor if (memoryManager64k.isLimitedGPU(0)) { GTEST_SKIP(); } - EXPECT_EQ(0, wddm->createAllocationResult.called); + EXPECT_EQ(0U, wddm->createAllocationResult.called); GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, mockDeviceBitfield}); - EXPECT_EQ(1, wddm->createAllocationResult.called); + EXPECT_NE(0U, wddm->createAllocationResult.called); EXPECT_NE(nullptr, galloc); EXPECT_EQ(true, galloc->isLocked()); EXPECT_NE(nullptr, galloc->getUnderlyingBuffer()); @@ -1629,7 +1629,8 @@ TEST_F(MockWddmMemoryManagerTest, givenAllocateGraphicsMemoryForBufferAndRequest TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenCorrectHugeGfxMemoryChunkIsSet) { MockWddmMemoryManager memoryManager(*executionEnvironment); - EXPECT_EQ(memoryManager.getHugeGfxMemoryChunkSize(), 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize64k); + EXPECT_EQ(memoryManager.getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::AllocateByKmd), 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize64k); + EXPECT_EQ(memoryManager.getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::UseUmdSystemPtr), 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize64k); } TEST_F(MockWddmMemoryManagerTest, givenAllocateGraphicsMemoryForHostBufferAndRequestedSizeIsHugeThenResultAllocationIsSplitted) { diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index ea24d0a6cd..de44684819 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -20,13 +20,23 @@ namespace NEO { Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable) : Gmm(clientContext, alignedPtr, alignedSize, alignment, uncacheable, false, true, {}) {} -Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferRenderCompressed, bool systemMemoryPool, StorageInfo storageInfo) : clientContext(clientContext) { +Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferRenderCompressed, bool systemMemoryPool, StorageInfo storageInfo) + : Gmm(clientContext, alignedPtr, alignedSize, alignment, uncacheable, preferRenderCompressed, systemMemoryPool, storageInfo, true) { +} + +Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferRenderCompressed, bool systemMemoryPool, StorageInfo storageInfo, bool allowLargePages) : clientContext(clientContext) { resourceParams.Type = RESOURCE_BUFFER; resourceParams.Format = GMM_FORMAT_GENERIC_8BIT; resourceParams.BaseWidth64 = static_cast(alignedSize); resourceParams.BaseHeight = 1; resourceParams.Depth = 1; resourceParams.BaseAlignment = static_cast(alignment); + if ((nullptr == alignedPtr) && (false == allowLargePages)) { + resourceParams.Flags.Info.NoOptimizationPadding = true; + if ((resourceParams.BaseWidth64 & MemoryConstants::page64kMask) == 0) { + resourceParams.BaseWidth64 += MemoryConstants::pageSize; + } + } if (!uncacheable) { resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; } else { diff --git a/shared/source/gmm_helper/gmm.h b/shared/source/gmm_helper/gmm.h index 7590558951..f726bb223f 100644 --- a/shared/source/gmm_helper/gmm.h +++ b/shared/source/gmm_helper/gmm.h @@ -27,6 +27,7 @@ class Gmm { Gmm(GmmClientContext *clientContext, ImageInfo &inputOutputImgInfo, StorageInfo storageInfo); Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable); Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferRenderCompressed, bool systemMemoryPool, StorageInfo storageInfo); + Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferRenderCompressed, bool systemMemoryPool, StorageInfo storageInfo, bool allowLargePages); Gmm(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmm); void queryImageParams(ImageInfo &inputOutputImgInfo); diff --git a/shared/source/os_interface/windows/max_chunk_size_drm_or_wddm.cpp b/shared/source/os_interface/windows/max_chunk_size_drm_or_wddm.cpp index 7270c5a695..67588f7b22 100644 --- a/shared/source/os_interface/windows/max_chunk_size_drm_or_wddm.cpp +++ b/shared/source/os_interface/windows/max_chunk_size_drm_or_wddm.cpp @@ -9,8 +9,14 @@ namespace NEO { -size_t WddmMemoryManager::getHugeGfxMemoryChunkSize() const { - return 31 * MemoryConstants::megaByte; +const GfxMemoryAllocationMethod preferredAllocationMethod = GfxMemoryAllocationMethod::AllocateByKmd; + +size_t WddmMemoryManager::getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const { + if (GfxMemoryAllocationMethod::AllocateByKmd == allocationMethod) { + return 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize64k; + } else { + return 31 * MemoryConstants::megaByte; + } } } // namespace NEO diff --git a/shared/source/os_interface/windows/max_chunk_size_wddm.cpp b/shared/source/os_interface/windows/max_chunk_size_wddm.cpp index 443cde1960..b3f28f159e 100644 --- a/shared/source/os_interface/windows/max_chunk_size_wddm.cpp +++ b/shared/source/os_interface/windows/max_chunk_size_wddm.cpp @@ -9,7 +9,9 @@ namespace NEO { -size_t WddmMemoryManager::getHugeGfxMemoryChunkSize() const { +const GfxMemoryAllocationMethod preferredAllocationMethod = GfxMemoryAllocationMethod::UseUmdSystemPtr; + +size_t WddmMemoryManager::getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const { return 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize64k; } diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index c796706bdc..e418b54198 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -498,18 +498,8 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM AllocationInfo.pSystemMem = alignedCpuPtr; AllocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); AllocationInfo.PrivateDriverDataSize = static_cast(gmm->gmmResourceInfo->peekHandleSize()); - AllocationInfo.Flags.Primary = 0; - - CreateAllocation.hGlobalShare = 0; - CreateAllocation.PrivateRuntimeDataSize = 0; - CreateAllocation.PrivateDriverDataSize = 0; - CreateAllocation.Flags.Reserved = 0; CreateAllocation.NumAllocations = 1; - CreateAllocation.pPrivateRuntimeData = nullptr; - CreateAllocation.pPrivateDriverData = nullptr; - CreateAllocation.Flags.NonSecure = FALSE; CreateAllocation.Flags.CreateShared = outSharedHandle ? TRUE : FALSE; - CreateAllocation.Flags.RestrictSharedAccess = FALSE; CreateAllocation.Flags.CreateResource = outSharedHandle || alignedCpuPtr ? TRUE : FALSE; CreateAllocation.pAllocationInfo2 = &AllocationInfo; CreateAllocation.hDevice = device; @@ -530,6 +520,13 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM return status; } +bool Wddm::createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { + D3DKMT_HANDLE outResourceHandle = NULL_HANDLE; + D3DKMT_HANDLE *outSharedHandle = nullptr; + auto result = this->createAllocation(nullptr, gmm, outHandle, outResourceHandle, outSharedHandle); + return STATUS_SUCCESS == result; +} + bool Wddm::setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocationCount, uint32_t priority) { D3DKMT_SETALLOCATIONPRIORITY setAllocationPriority = {}; @@ -553,36 +550,6 @@ bool Wddm::setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allocati return STATUS_SUCCESS == status; } -bool Wddm::createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { - NTSTATUS status = STATUS_SUCCESS; - D3DDDI_ALLOCATIONINFO2 AllocationInfo = {}; - D3DKMT_CREATEALLOCATION CreateAllocation = {}; - - AllocationInfo.pSystemMem = 0; - AllocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); - AllocationInfo.PrivateDriverDataSize = static_cast(gmm->gmmResourceInfo->peekHandleSize()); - AllocationInfo.Flags.Primary = 0; - - CreateAllocation.NumAllocations = 1; - CreateAllocation.pPrivateRuntimeData = nullptr; - CreateAllocation.pPrivateDriverData = nullptr; - CreateAllocation.Flags.CreateResource = FALSE; - CreateAllocation.pAllocationInfo2 = &AllocationInfo; - CreateAllocation.hDevice = device; - - status = getGdi()->createAllocation2(&CreateAllocation); - - if (status != STATUS_SUCCESS) { - DEBUG_BREAK_IF(true); - return false; - } - - outHandle = AllocationInfo.hAllocation; - kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, getAdapter(), device, outHandle, getGdi()->escape); - - return true; -} - NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) { NTSTATUS status = STATUS_UNSUCCESSFUL; D3DDDI_ALLOCATIONINFO2 AllocationInfo[maxFragmentsCount] = {}; diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 7612981827..8dcc25db30 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -77,7 +77,7 @@ class Wddm : public DriverModel { MOCKABLE_VIRTUAL void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext, const HardwareInfo &hwInfo); MOCKABLE_VIRTUAL bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size); MOCKABLE_VIRTUAL NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, D3DKMT_HANDLE *outSharedHandle); - MOCKABLE_VIRTUAL bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle); + MOCKABLE_VIRTUAL bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle); MOCKABLE_VIRTUAL NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles); MOCKABLE_VIRTUAL bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle); MOCKABLE_VIRTUAL bool verifySharedHandle(D3DKMT_HANDLE osHandle); diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 9f6b5d8502..1310f3e434 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -95,15 +95,19 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImageImpl(const } GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(const AllocationData &allocationData) { - size_t sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize64k); - if (sizeAligned > getHugeGfxMemoryChunkSize()) { + return allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(allocationData, true); +} + +GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(const AllocationData &allocationData, bool allowLargePages) { + size_t sizeAligned = alignUp(allocationData.size, allowLargePages ? MemoryConstants::pageSize64k : MemoryConstants::pageSize); + if (sizeAligned > getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::AllocateByKmd)) { return allocateHugeGraphicsMemory(allocationData, false); } auto wddmAllocation = std::make_unique(allocationData.rootDeviceIndex, 1u, // numGmms allocationData.type, nullptr, - sizeAligned, nullptr, MemoryPool::System64KBPages, + sizeAligned, nullptr, allowLargePages ? MemoryPool::System64KBPages : MemoryPool::System4KBPages, 0u, // shareable maxOsContextCount); @@ -111,12 +115,13 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(const Allocati sizeAligned, 0u, allocationData.flags.uncacheable, allocationData.flags.preferRenderCompressed, true, - allocationData.storageInfo); + allocationData.storageInfo, + allowLargePages); wddmAllocation->setDefaultGmm(gmm); wddmAllocation->setFlushL3Required(allocationData.flags.flushL3); wddmAllocation->storageInfo = allocationData.storageInfo; - if (!getWddm(allocationData.rootDeviceIndex).createAllocation64k(gmm, wddmAllocation->getHandleToModify(0u))) { + if (!getWddm(allocationData.rootDeviceIndex).createAllocation(gmm, wddmAllocation->getHandleToModify(0u))) { delete gmm; return nullptr; } @@ -149,7 +154,7 @@ GraphicsAllocation *WddmMemoryManager::allocateHugeGraphicsMemory(const Allocati } } - auto chunkSize = getHugeGfxMemoryChunkSize(); + auto chunkSize = getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::UseUmdSystemPtr); auto numGmms = (alignedSize + chunkSize - 1) / chunkSize; auto wddmAllocation = std::make_unique(allocationData.rootDeviceIndex, numGmms, allocationData.type, hostPtr, allocationData.size, @@ -191,9 +196,17 @@ GraphicsAllocation *WddmMemoryManager::allocateUSMHostGraphicsMemory(const Alloc } GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { + if (preferredAllocationMethod == GfxMemoryAllocationMethod::UseUmdSystemPtr) { + return allocateSystemMemoryAndCreateGraphicsAllocationFromIt(allocationData); + } else { + return allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(allocationData, NEO::OSInterface::osEnabled64kbPages); + } +} + +GraphicsAllocation *WddmMemoryManager::allocateSystemMemoryAndCreateGraphicsAllocationFromIt(const AllocationData &allocationData) { size_t newAlignment = allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize; size_t sizeAligned = allocationData.size ? alignUp(allocationData.size, MemoryConstants::pageSize) : MemoryConstants::pageSize; - if (sizeAligned > getHugeGfxMemoryChunkSize()) { + if (sizeAligned > getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::UseUmdSystemPtr)) { return allocateHugeGraphicsMemory(allocationData, true); } void *pSysMem = allocateSystemMemory(sizeAligned, newAlignment); @@ -240,7 +253,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) { auto alignedSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size); - if (alignedSize > getHugeGfxMemoryChunkSize()) { + if (alignedSize > getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::UseUmdSystemPtr)) { return allocateHugeGraphicsMemory(allocationData, false); } @@ -268,7 +281,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(co } GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) { - if (allocationData.size > getHugeGfxMemoryChunkSize()) { + if (allocationData.size > getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod::UseUmdSystemPtr)) { return allocateHugeGraphicsMemory(allocationData, false); } diff --git a/shared/source/os_interface/windows/wddm_memory_manager.h b/shared/source/os_interface/windows/wddm_memory_manager.h index b56e19ff26..df4f9ca221 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.h +++ b/shared/source/os_interface/windows/wddm_memory_manager.h @@ -23,6 +23,13 @@ class Gmm; class OsContextWin; class Wddm; +enum class GfxMemoryAllocationMethod : uint32_t { + UseUmdSystemPtr, + AllocateByKmd +}; + +extern const GfxMemoryAllocationMethod preferredAllocationMethod; + class WddmMemoryManager : public MemoryManager { public: using MemoryManager::allocateGraphicsMemoryWithProperties; @@ -68,7 +75,6 @@ class WddmMemoryManager : public MemoryManager { protected: GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override; - GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override; GraphicsAllocation *allocateUSMHostGraphicsMemory(const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override; @@ -76,13 +82,17 @@ class WddmMemoryManager : public MemoryManager { GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr gmm) override; GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override { return nullptr; } + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override; + GraphicsAllocation *allocateSystemMemoryAndCreateGraphicsAllocationFromIt(const AllocationData &allocationData); + GraphicsAllocation *allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(const AllocationData &allocationData, bool allowLargePages); + void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override; void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override; void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) override; GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override; GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; - MOCKABLE_VIRTUAL size_t getHugeGfxMemoryChunkSize() const; + MOCKABLE_VIRTUAL size_t getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const; GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress); GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex); diff --git a/shared/test/common/mocks/mock_wddm.cpp b/shared/test/common/mocks/mock_wddm.cpp index 7dcfaf1b9d..2e10664596 100644 --- a/shared/test/common/mocks/mock_wddm.cpp +++ b/shared/test/common/mocks/mock_wddm.cpp @@ -104,13 +104,13 @@ NTSTATUS WddmMock::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D bool WddmMock::createAllocation64k(WddmAllocation *wddmAllocation) { if (wddmAllocation) { - return createAllocation64k(wddmAllocation->getDefaultGmm(), wddmAllocation->getHandleToModify(0u)); + return createAllocation(wddmAllocation->getDefaultGmm(), wddmAllocation->getHandleToModify(0u)); } return false; } -bool WddmMock::createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { +bool WddmMock::createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { createAllocationResult.called++; - return createAllocationResult.success = Wddm::createAllocation64k(gmm, outHandle); + return createAllocationResult.success = Wddm::createAllocation(gmm, outHandle); } bool WddmMock::destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) { diff --git a/shared/test/common/mocks/mock_wddm.h b/shared/test/common/mocks/mock_wddm.h index ab1079eb86..173939636b 100644 --- a/shared/test/common/mocks/mock_wddm.h +++ b/shared/test/common/mocks/mock_wddm.h @@ -58,7 +58,7 @@ class WddmMock : public Wddm { 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, D3DKMT_HANDLE &outResource, D3DKMT_HANDLE *outSharedHandle) override; - bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override; + bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override; bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) override; NTSTATUS createAllocation(WddmAllocation *wddmAllocation); diff --git a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp index 651833046f..fff9e2dd10 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp @@ -20,7 +20,7 @@ TEST_F(WddmTests, whenCreatingAllocation64kThenDoNotCreateResource) { D3DKMT_HANDLE handle; Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmClientContext(), nullptr, 20, 0, false, true, true, {}); - EXPECT_TRUE(wddm->createAllocation64k(&gmm, handle)); + EXPECT_TRUE(wddm->createAllocation(&gmm, handle)); auto gdiParam = getMockAllocationFcn(); EXPECT_EQ(FALSE, gdiParam->Flags.CreateResource); }