From ed6381a66aa221a1bd67f6d3d1867a77f623f082 Mon Sep 17 00:00:00 2001 From: "Jablonski, Mateusz" Date: Mon, 18 Feb 2019 10:49:21 +0100 Subject: [PATCH] Use HEAP_STANDARD64Kb when cpu access is required Change-Id: I3a451b618f1b72836cd640ed510e874cf2d60624 Signed-off-by: Jablonski, Mateusz --- runtime/memory_manager/graphics_allocation.h | 7 +++++++ runtime/memory_manager/memory_manager.cpp | 12 +----------- runtime/os_interface/windows/wddm/wddm.cpp | 3 +++ .../graphics_allocation_tests.cpp | 16 ++++++++++++++++ unit_tests/mock_gdi/mock_gdi.cpp | 6 +++++- .../os_interface/windows/wddm20_tests.cpp | 17 ++++++++++++++++- 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 2a3a1bc19c..5f0bc1b2a6 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -164,6 +164,13 @@ class GraphicsAllocation : public IDNode { virtual std::string getAllocationInfoString() const; + static bool isCpuAccessRequired(AllocationType allocationType) { + return allocationType == AllocationType::LINEAR_STREAM || + allocationType == AllocationType::KERNEL_ISA || + allocationType == AllocationType::INTERNAL_HEAP || + allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER; + } + protected: constexpr static uint32_t objectNotResident = (uint32_t)-1; constexpr static uint32_t objectNotUsed = (uint32_t)-1; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 00de104d93..9b21250491 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -274,17 +274,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo break; } - switch (properties.allocationType) { - case GraphicsAllocation::AllocationType::LINEAR_STREAM: - case GraphicsAllocation::AllocationType::KERNEL_ISA: - case GraphicsAllocation::AllocationType::INTERNAL_HEAP: - case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER: - allocationData.flags.requiresCpuAccess = true; - break; - default: - break; - } - + allocationData.flags.requiresCpuAccess = GraphicsAllocation::isCpuAccessRequired(properties.allocationType); allocationData.flags.mustBeZeroCopy = mustBeZeroCopy; allocationData.flags.allocateMemory = properties.flags.allocateMemory; allocationData.flags.allow32Bit = allow32Bit; diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 51d455d4dc..5e09b4b6f4 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -1006,6 +1006,9 @@ HeapIndex Wddm::selectHeap(const WddmAllocation *allocation, const void *ptr) co if (ptr) { return HeapIndex::HEAP_SVM; } + if (allocation && GraphicsAllocation::isCpuAccessRequired(allocation->getAllocationType())) { + return HeapIndex::HEAP_STANDARD64Kb; + } return HeapIndex::HEAP_STANDARD; } return HeapIndex::HEAP_LIMITED; diff --git a/unit_tests/memory_manager/graphics_allocation_tests.cpp b/unit_tests/memory_manager/graphics_allocation_tests.cpp index 7fdd428019..ee54717694 100644 --- a/unit_tests/memory_manager/graphics_allocation_tests.cpp +++ b/unit_tests/memory_manager/graphics_allocation_tests.cpp @@ -112,3 +112,19 @@ TEST(GraphicsAllocationTest, givenResidentGraphicsAllocationWhenCheckIfResidency EXPECT_TRUE(graphicsAllocation.isResident(0u)); EXPECT_TRUE(graphicsAllocation.isResidencyTaskCountBelow(currentResidencyTaskCount + 1u, 0u)); } + +TEST(GraphicsAllocationTest, whenAllocationTypeIsLinearStreamThenCpuAccessIsRequired) { + EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::LINEAR_STREAM)); +} + +TEST(GraphicsAllocationTest, whenAllocationTypeIsKernelIsaThenCpuAccessIsRequired) { + EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::KERNEL_ISA)); +} + +TEST(GraphicsAllocationTest, whenAllocationTypeIsInternalHeapThenCpuAccessIsRequired) { + EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::INTERNAL_HEAP)); +} + +TEST(GraphicsAllocationTest, whenAllocationTypeIsTimestampPacketThenCpuAccessIsRequired) { + EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER)); +} diff --git a/unit_tests/mock_gdi/mock_gdi.cpp b/unit_tests/mock_gdi/mock_gdi.cpp index 89f89c544a..728f77ac0d 100644 --- a/unit_tests/mock_gdi/mock_gdi.cpp +++ b/unit_tests/mock_gdi/mock_gdi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,6 +27,8 @@ BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, case DLL_PROCESS_ATTACH: gAdapterInfo.GfxPartition.Standard.Base = 0x0000800400000000; gAdapterInfo.GfxPartition.Standard.Limit = 0x0000eeffffffffff; + gAdapterInfo.GfxPartition.Standard64KB.Base = 0x0000b80200000000; + gAdapterInfo.GfxPartition.Standard64KB.Limit = 0x0000efffffffffff; gAdapterInfo.GfxPartition.SVM.Base = 0; gAdapterInfo.GfxPartition.SVM.Limit = 0x00007fffffffffff; gAdapterInfo.GfxPartition.Heap32[0].Base = 0x0000800000000000; @@ -287,6 +289,8 @@ NTSTATUS __stdcall D3DKMTQueryAdapterInfo(IN CONST D3DKMT_QUERYADAPTERINFO *quer adapterInfo->GfxPartition.Standard.Base = gAdapterInfo.GfxPartition.Standard.Base; adapterInfo->GfxPartition.Standard.Limit = gAdapterInfo.GfxPartition.Standard.Limit; + adapterInfo->GfxPartition.Standard64KB.Base = gAdapterInfo.GfxPartition.Standard64KB.Base; + adapterInfo->GfxPartition.Standard64KB.Limit = gAdapterInfo.GfxPartition.Standard64KB.Limit; adapterInfo->GfxPartition.SVM.Base = gAdapterInfo.GfxPartition.SVM.Base; adapterInfo->GfxPartition.SVM.Limit = gAdapterInfo.GfxPartition.SVM.Limit; diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index af8a773ad4..40f77454d5 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -1030,9 +1030,24 @@ TEST_F(WddmHeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAl } EXPECT_EQ(HeapIndex::HEAP_SVM, wddm->selectHeap(&allocation, &allocation)); } -TEST_F(WddmHeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrThenStandardHeapIsUsed) { +TEST_F(WddmHeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndCpuAccessIsRequiredThenStandard64kHeapIsUsed) { WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, false}; EXPECT_EQ(AllocationOrigin::EXTERNAL_ALLOCATION, allocation.origin); + auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM; + allocation.setAllocationType(allocationType); + EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(allocationType)); + if (hardwareInfoTable[wddm->getGfxPlatform()->eProductFamily]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { + return; + } + EXPECT_EQ(HeapIndex::HEAP_STANDARD64Kb, wddm->selectHeap(&allocation, nullptr)); +} + +TEST_F(WddmHeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndCpuAccessIsNotRequiredThenStandardHeapIsUsed) { + WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, false}; + EXPECT_EQ(AllocationOrigin::EXTERNAL_ALLOCATION, allocation.origin); + auto allocationType = GraphicsAllocation::AllocationType::UNDECIDED; + allocation.setAllocationType(allocationType); + EXPECT_FALSE(GraphicsAllocation::isCpuAccessRequired(allocationType)); if (hardwareInfoTable[wddm->getGfxPlatform()->eProductFamily]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { return; }