Remove alignedSize from WddmAllocation.

Change-Id: I3b610515e4d5db16ce6a604e7e2f4b85b657bef2
This commit is contained in:
Mrozek, Michal
2018-10-30 13:14:07 +01:00
committed by sys_ocldev
parent 4a8f4aa47b
commit 5b2e16651f
6 changed files with 26 additions and 28 deletions

View File

@@ -7,6 +7,7 @@
#pragma once
#define UMDF_USING_NTSTATUS
#include "runtime/helpers/aligned_memory.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/os_interface/windows/windows_wrapper.h"
#include <d3dkmthk.h>
@@ -30,12 +31,11 @@ class WddmAllocation : public GraphicsAllocation {
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
D3DGPU_VIRTUAL_ADDRESS gpuPtr; // set by mapGpuVA
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, size_t alignedSize, void *reservedAddr, MemoryPool::Type pool, size_t osContextsCount)
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, void *reservedAddr, MemoryPool::Type pool, size_t osContextsCount)
: GraphicsAllocation(cpuPtrIn, sizeIn),
handle(0),
gpuPtr(0),
alignedCpuPtr(alignedCpuPtr),
alignedSize(alignedSize),
trimCandidateListPositions(osContextsCount, trimListUnusedPosition) {
reservedAddressSpace = reservedAddr;
this->memoryPool = pool;
@@ -46,14 +46,13 @@ class WddmAllocation : public GraphicsAllocation {
handle(0),
gpuPtr(0),
alignedCpuPtr(nullptr),
alignedSize(sizeIn),
trimCandidateListPositions(osContextsCount, trimListUnusedPosition) {
reservedAddressSpace = nullptr;
this->memoryPool = pool;
}
WddmAllocation(void *alignedCpuPtr, size_t sizeIn, void *reservedAddress, MemoryPool::Type pool, size_t osContextsCount)
: WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, sizeIn, reservedAddress, pool, osContextsCount) {
: WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, reservedAddress, pool, osContextsCount) {
}
void *getAlignedCpuPtr() const {
@@ -61,7 +60,7 @@ class WddmAllocation : public GraphicsAllocation {
}
size_t getAlignedSize() const {
return this->alignedSize;
return alignSizeWholePage(this->cpuPtr, this->size);
}
ResidencyData &getResidencyData() {
@@ -90,7 +89,6 @@ class WddmAllocation : public GraphicsAllocation {
protected:
void *alignedCpuPtr;
size_t alignedSize;
ResidencyData residency;
std::vector<size_t> trimCandidateListPositions;
void *reservedAddressSpace;

View File

@@ -86,7 +86,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s
size_t sizeAligned = alignUp(size, MemoryConstants::pageSize64k);
Gmm *gmm = nullptr;
auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr, MemoryPool::System64KBPages, getOsContextCount());
auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, nullptr, MemoryPool::System64KBPages, getOsContextCount());
gmm = new Gmm(nullptr, sizeAligned, false, preferRenderCompressed, true);
wddmAllocation->gmm = gmm;
@@ -117,7 +117,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_
return nullptr;
}
auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr, MemoryPool::System4KBPages, getOsContextCount());
auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, nullptr, MemoryPool::System4KBPages, getOsContextCount());
wddmAllocation->cpuPtrAllocated = true;
gmm = new Gmm(pSysMem, sizeAligned, uncacheable);
@@ -138,7 +138,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(si
auto offsetInPage = ptrDiff(cpuPtr, alignedPtr);
auto alignedSize = alignSizeWholePage(cpuPtr, size);
auto wddmAllocation = new WddmAllocation(cpuPtr, size, alignedPtr, alignedSize, nullptr, MemoryPool::System4KBPages, getOsContextCount());
auto wddmAllocation = new WddmAllocation(cpuPtr, size, alignedPtr, nullptr, MemoryPool::System4KBPages, getOsContextCount());
wddmAllocation->allocationOffset = offsetInPage;
auto gmm = new Gmm(alignedPtr, alignedSize, false);
@@ -171,7 +171,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const
return nullptr;
}
auto allocation = new WddmAllocation(ptr, size, ptrAligned, sizeAligned, reserve, MemoryPool::System4KBPages, getOsContextCount());
auto allocation = new WddmAllocation(ptr, size, ptrAligned, reserve, MemoryPool::System4KBPages, getOsContextCount());
allocation->allocationOffset = offset;
Gmm *gmm = new Gmm(ptrAligned, sizeAligned, false);
@@ -208,7 +208,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
cpuPtrAllocated = true;
}
auto wddmAllocation = new WddmAllocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), sizeAligned, nullptr, MemoryPool::System4KBPagesWith32BitGpuAddressing, getOsContextCount());
auto wddmAllocation = new WddmAllocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), nullptr, MemoryPool::System4KBPagesWith32BitGpuAddressing, getOsContextCount());
wddmAllocation->cpuPtrAllocated = cpuPtrAllocated;
wddmAllocation->is32BitAllocation = true;
wddmAllocation->allocationOffset = offset;
@@ -456,7 +456,7 @@ void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation,
}
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
auto allocation = new WddmAllocation(const_cast<void *>(hostPtr), hostPtrSize, const_cast<void *>(hostPtr), hostPtrSize, nullptr, MemoryPool::System4KBPages, getOsContextCount());
auto allocation = new WddmAllocation(const_cast<void *>(hostPtr), hostPtrSize, const_cast<void *>(hostPtr), nullptr, MemoryPool::System4KBPages, getOsContextCount());
allocation->fragmentsStorage = handleStorage;
obtainGpuAddresFromFragments(allocation, handleStorage);
return allocation;

View File

@@ -12,7 +12,7 @@ namespace OCLRT {
class MockWddmAllocation : public WddmAllocation {
public:
MockWddmAllocation() : WddmAllocation(nullptr, 0, nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u) {
MockWddmAllocation() : WddmAllocation(nullptr, 0, nullptr, nullptr, MemoryPool::MemoryNull, 1u) {
}
};

View File

@@ -76,7 +76,7 @@ TEST_F(Wddm20Tests, givenNullPageTableManagerAndRenderCompressedResourceWhenMapp
mockGmmRes->setUnifiedAuxTranslationCapable();
void *fakePtr = reinterpret_cast<void *>(0x100);
WddmAllocation allocation(fakePtr, 0x2100, fakePtr, 0x3000, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation(fakePtr, 0x2100, fakePtr, nullptr, MemoryPool::MemoryNull, 1u);
allocation.gmm = gmm.get();
allocation.handle = ALLOCATION_HANDLE;
@@ -194,7 +194,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz
size_t underlyingPages = underlyingSize / MemoryConstants::pageSize;
size_t alignedPages = alignedSize / MemoryConstants::pageSize;
WddmAllocation allocation(ptr, 0x2100, ptr, 0x3000, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation(ptr, 0x2100, ptr, nullptr, MemoryPool::MemoryNull, 1u);
Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getAlignedCpuPtr(), allocation.getAlignedSize());
allocation.gmm = gmm;
@@ -217,7 +217,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz
TEST_F(Wddm20WithMockGdiDllTests, givenWddmAllocationWhenMappingGpuVaThenUseGmmSize) {
void *fakePtr = reinterpret_cast<void *>(0x123);
WddmAllocation allocation(fakePtr, 100, fakePtr, 200, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation(fakePtr, 100, fakePtr, nullptr, MemoryPool::MemoryNull, 1u);
std::unique_ptr<Gmm> gmm(GmmHelperFunctions::getGmm(allocation.getAlignedCpuPtr(), allocation.getAlignedSize()));
allocation.gmm = gmm.get();
@@ -739,7 +739,7 @@ TEST_F(Wddm20Tests, whenCreateAllocation64kFailsThenReturnFalse) {
void *fakePtr = reinterpret_cast<void *>(0x123);
auto gmm = std::make_unique<Gmm>(fakePtr, 100, false);
WddmAllocation allocation(fakePtr, 100, fakePtr, 200, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation(fakePtr, 100, fakePtr, nullptr, MemoryPool::MemoryNull, 1u);
allocation.gmm = gmm.get();
EXPECT_FALSE(wddm->createAllocation64k(&allocation));

View File

@@ -56,7 +56,7 @@ TEST(WddmMemoryManager, NonAssignable) {
}
TEST(WddmAllocationTest, givenAllocationIsTrimCandidateInOneOsContextWhenGettingTrimCandidatePositionThenReturnItsPositionAndUnusedPositionInOtherContexts) {
WddmAllocation allocation{nullptr, 0, nullptr, 0, nullptr, MemoryPool::MemoryNull, 3u};
WddmAllocation allocation{nullptr, 0, nullptr, nullptr, MemoryPool::MemoryNull, 3u};
OsContext osContext{nullptr, 1u};
allocation.setTrimCandidateListPosition(osContext.getContextId(), 700u);
EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(0u));
@@ -65,7 +65,7 @@ TEST(WddmAllocationTest, givenAllocationIsTrimCandidateInOneOsContextWhenGetting
}
TEST(WddmAllocationTest, givenRequestedContextIdTooLargeWhenGettingTrimCandidateListPositionThenReturnUnusedPosition) {
WddmAllocation allocation{nullptr, 0, nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u};
WddmAllocation allocation{nullptr, 0, nullptr, nullptr, MemoryPool::MemoryNull, 1u};
EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(1u));
EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(1000u));
}
@@ -1213,7 +1213,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR
MockWddmAllocation allocation1;
void *cpuPtr = reinterpret_cast<void *>(wddm->getWddmMinAddress() + 0x1000);
size_t allocationSize = 0x1000;
WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, allocationSize, nullptr, MemoryPool::MemoryNull, memoryManager->getOsContextCount());
WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, nullptr, MemoryPool::MemoryNull, memoryManager->getOsContextCount());
allocationToTrim.getResidencyData().updateCompletionData(osContext->get()->getResidencyController().getMonitoredFence().lastSubmittedFence, osContext->getContextId());

View File

@@ -506,9 +506,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetReturnsFalseWhenNumBytesT
}
TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetStopsEvictingWhenNumBytesToTrimIsZero) {
WddmAllocation allocation1(reinterpret_cast<void *>(0x1000), 0x1000, reinterpret_cast<void *>(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull, 1u),
allocation2(reinterpret_cast<void *>(0x1000), 0x3000, reinterpret_cast<void *>(0x1000), 0x3000, nullptr, MemoryPool::MemoryNull, 1u),
allocation3(reinterpret_cast<void *>(0x1000), 0x1000, reinterpret_cast<void *>(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation1(reinterpret_cast<void *>(0x1000), 0x1000, reinterpret_cast<void *>(0x1000), nullptr, MemoryPool::MemoryNull, 1u),
allocation2(reinterpret_cast<void *>(0x1000), 0x3000, reinterpret_cast<void *>(0x1000), nullptr, MemoryPool::MemoryNull, 1u),
allocation3(reinterpret_cast<void *>(0x1000), 0x1000, reinterpret_cast<void *>(0x1000), nullptr, MemoryPool::MemoryNull, 1u);
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().updateCompletionData(0, osContextId);
@@ -601,8 +601,8 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetWaitsFromCpuWhenLastFence
TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, trimToBudgetEvictsDoneFragmentsOnly) {
gdi->setNonZeroNumBytesToTrimInEvict();
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation1(ptr, 0x1000, ptr, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation2(ptr, 0x1000, ptr, nullptr, MemoryPool::MemoryNull, 1u);
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().updateCompletionData(0, osContextId);
@@ -660,9 +660,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge
void *ptr2 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x3000);
void *ptr3 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x5000);
WddmAllocation allocation1(ptr1, underlyingSize, ptr1, alignedSize, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation2(ptr2, underlyingSize, ptr2, alignedSize, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation3(ptr3, underlyingSize, ptr3, alignedSize, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation1(ptr1, underlyingSize, ptr1, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation2(ptr2, underlyingSize, ptr2, nullptr, MemoryPool::MemoryNull, 1u);
WddmAllocation allocation3(ptr3, underlyingSize, ptr3, nullptr, MemoryPool::MemoryNull, 1u);
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().updateCompletionData(0, osContextId);