Skip to content

Commit e095ac8

Browse files
Windows: use HEAP_INTERNAL in 32bit scenarios
Change-Id: I652727303eec45cd3547bd98bec42f276000d9b4 Signed-off-by: Jablonski, Mateusz <[email protected]>
1 parent 4943c10 commit e095ac8

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

runtime/os_interface/windows/wddm/wddm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ std::unique_lock<SpinLock> Wddm::acquireLock(SpinLock &lock) {
999999
HeapIndex Wddm::selectHeap(const WddmAllocation *allocation, const void *ptr) const {
10001000
if (allocation) {
10011001
if (allocation->origin == AllocationOrigin::INTERNAL_ALLOCATION) {
1002-
return HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY;
1002+
return internalHeapIndex;
10031003
} else if (allocation->is32BitAllocation) {
10041004
return HeapIndex::HEAP_EXTERNAL;
10051005
}

runtime/os_interface/windows/wddm/wddm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "runtime/os_interface/os_context.h"
1010
#include "runtime/helpers/debug_helpers.h"
1111
#include "runtime/gmm_helper/gmm_lib.h"
12+
#include "runtime/memory_manager/memory_constants.h"
1213
#include "runtime/utilities/spinlock.h"
1314
#include "sku_info.h"
1415
#include <memory>
@@ -52,6 +53,8 @@ enum class HeapIndex : uint32_t {
5253
HEAP_LIMITED
5354
};
5455

56+
constexpr auto internalHeapIndex = is32bit ? HeapIndex::HEAP_INTERNAL : HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY;
57+
5558
class Wddm {
5659
public:
5760
typedef HRESULT(WINAPI *CreateDXGIFactoryFcn)(REFIID riid, void **ppFactory);

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ uint64_t WddmMemoryManager::getMaxApplicationAddress() {
450450
}
451451

452452
uint64_t WddmMemoryManager::getInternalHeapBaseAddress() {
453-
return this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Base;
453+
return this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base;
454454
}
455455

456456
bool WddmMemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) {

unit_tests/os_interface/windows/wddm20_tests.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,20 @@ TEST_F(Wddm20Tests, createAllocation32bit) {
267267
delete gmm;
268268
}
269269

270-
TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap0ThenItHasGpuAddressWithingHeap0Limits) {
270+
TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap0ThenItHasGpuAddressWithingHeapInternalLimits) {
271271
void *alignedPtr = (void *)0x12000;
272272
size_t alignedSize = 0x2000;
273273
WddmAllocation allocation(alignedPtr, alignedSize, nullptr, MemoryPool::MemoryNull, 1u, false);
274274

275275
allocation.handle = ALLOCATION_HANDLE;
276276
allocation.gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
277277
allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION;
278-
EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, wddm->selectHeap(&allocation, allocation.getAlignedCpuPtr()));
278+
EXPECT_EQ(internalHeapIndex, wddm->selectHeap(&allocation, allocation.getAlignedCpuPtr()));
279279
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr());
280280
EXPECT_TRUE(ret);
281281

282-
uint32_t heapIndex = static_cast<uint32_t>(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY);
283-
auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[heapIndex].Base);
284-
auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[heapIndex].Limit);
282+
auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base);
283+
auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit);
285284

286285
EXPECT_GE(allocation.gpuPtr, cannonizedHeapBase);
287286
EXPECT_LE(allocation.gpuPtr, cannonizedHeapEnd);
@@ -1001,17 +1000,17 @@ TEST_F(Wddm20Tests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheLi
10011000

10021001
using WddmHeapSelectorTest = Wddm20Tests;
10031002

1004-
TEST_F(WddmHeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalDeviceMemoryHeapIsUsed) {
1003+
TEST_F(WddmHeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
10051004
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
10061005
allocation.is32BitAllocation = true;
10071006
allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION;
1008-
EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, wddm->selectHeap(&allocation, nullptr));
1007+
EXPECT_EQ(internalHeapIndex, wddm->selectHeap(&allocation, nullptr));
10091008
}
1010-
TEST_F(WddmHeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalDeviceMemoryHeapIsUsed) {
1009+
TEST_F(WddmHeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
10111010
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
10121011
allocation.is32BitAllocation = false;
10131012
allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION;
1014-
EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, wddm->selectHeap(&allocation, nullptr));
1013+
EXPECT_EQ(internalHeapIndex, wddm->selectHeap(&allocation, nullptr));
10151014
}
10161015
TEST_F(WddmHeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) {
10171016
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,15 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstAnd
865865
EXPECT_FALSE(ret);
866866
}
867867

868-
TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeap1) {
868+
TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeapInternal) {
869869
auto wddmAllocation = static_cast<WddmAllocation *>(memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION));
870870
ASSERT_NE(nullptr, wddmAllocation);
871871
EXPECT_EQ(wddmAllocation->gpuBaseAddress, GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress()));
872872
EXPECT_NE(nullptr, wddmAllocation->getUnderlyingBuffer());
873873
EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize());
874874
EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress());
875875
auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress());
876-
auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Limit);
876+
auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit);
877877

878878
EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase);
879879
EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd);
@@ -892,7 +892,7 @@ TEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationWhe
892892
EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize());
893893
EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress());
894894
auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress());
895-
auto cannonizedHeapEnd = GmmHelper::canonize(wddm->getGfxPartition().Heap32[static_cast<uint32_t>(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Limit);
895+
auto cannonizedHeapEnd = GmmHelper::canonize(wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit);
896896

897897
EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase);
898898
EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd);
@@ -1152,12 +1152,12 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele
11521152
EXPECT_EQ(1u, wddm->createAllocationResult.called);
11531153
}
11541154

1155-
TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalDeviceMemoryBaseIsReturned) {
1155+
TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalBaseIsReturned) {
11561156
ExecutionEnvironment executionEnvironment;
11571157
auto wddm = std::make_unique<WddmMock>();
11581158
wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
11591159
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
1160-
auto heapBase = wddm->getGfxPartition().Heap32[static_cast<uint32_t>(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Base;
1160+
auto heapBase = wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base;
11611161
EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress());
11621162
}
11631163

0 commit comments

Comments
 (0)