Wddm interface [3/n]: Improve constructing Wddm object

- Only Wddm object owns Gdi
- Dont pass Gdi object to constructor
- Move Wddm related files to new directory

Change-Id: Iadd26634c7692db760d7d3367211c32d2c2c8121
This commit is contained in:
Dunajski, Bartosz
2018-05-10 11:42:41 +02:00
committed by sys_ocldev
parent 06287af541
commit bab9ad6cda
28 changed files with 163 additions and 171 deletions

View File

@ -55,7 +55,7 @@ set(RUNTIME_SRCS_DLL_WINDOWS
${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/gmm_memory.cpp
${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/sys_calls.cpp
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm_create.cpp
${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows/wddm/wddm_create.cpp
)
target_sources(${NEO_DYNAMIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_DLL_BASE})

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -21,8 +21,8 @@
*/
#include "hw_cmds.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm.inl"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.inl"
namespace OCLRT {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -21,8 +21,8 @@
*/
#include "hw_cmds.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm.inl"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.inl"
namespace OCLRT {

View File

@ -56,9 +56,6 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_windows.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h
${CMAKE_CURRENT_SOURCE_DIR}/thk_wrapper.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm.inl
${CMAKE_CURRENT_SOURCE_DIR}/wddm_32bit_memory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm_allocation.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm_device_command_stream.h
@ -71,6 +68,9 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/windows_inc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.inl
)
if(WIN32)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -20,7 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/deferrable_deletion_win.h"
namespace OCLRT {

View File

@ -26,7 +26,7 @@
#include "runtime/os_interface/device_factory.h"
#include "runtime/os_interface/hw_info_config.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
namespace OCLRT {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -20,7 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/device/driver_info.h"
#include "runtime/os_interface/windows/driver_info.h"
#include "runtime/os_interface/windows/os_interface.h"

View File

@ -22,7 +22,7 @@
#include "os_interface.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/sys_calls.h"
namespace OCLRT {

View File

@ -21,7 +21,7 @@
*/
#include <memory>
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/os_time.h"

View File

@ -27,7 +27,7 @@
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/gmm_helper/page_table_mngr.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/hw_info_config.h"
#include "runtime/os_interface/windows/wddm_allocation.h"
#include "runtime/os_interface/windows/registry_reader.h"
@ -53,9 +53,7 @@ Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo();
Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc();
Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree();
Wddm::Wddm(Gdi *gdi) : initialized(false),
gdiAllocated(false),
gdi(gdi),
Wddm::Wddm() : initialized(false),
adapter(0),
context(0),
device(0),
@ -81,10 +79,7 @@ Wddm::Wddm(Gdi *gdi) : initialized(false),
gmmMemory = std::unique_ptr<GmmMemory>(GmmMemory::create());
minAddress = 0;
kmDafListener = std::unique_ptr<KmDafListener>(new KmDafListener);
}
Wddm::Wddm() : Wddm(new Gdi()) {
gdiAllocated = true;
gdi = std::unique_ptr<Gdi>(new Gdi());
}
Wddm::~Wddm() {
@ -95,8 +90,6 @@ Wddm::~Wddm() {
destroyPagingQueue();
destroyDevice();
closeAdapter();
if (gdiAllocated)
delete gdi;
}
bool Wddm::enumAdapters(unsigned int devNum, HardwareInfo &outHardwareInfo) {

View File

@ -50,19 +50,6 @@ struct WorkaroundTable;
struct KmDafListener;
class Wddm {
private:
struct MonitoredFence {
D3DKMT_HANDLE fenceHandle;
D3DGPU_VIRTUAL_ADDRESS gpuAddress;
volatile uint64_t *cpuAddress;
volatile uint64_t currentFenceValue;
uint64_t lastSubmittedFence;
};
protected:
Wddm();
Wddm(Gdi *gdi);
public:
typedef HRESULT(WINAPI *CreateDXGIFactoryFcn)(REFIID riid, void **ppFactory);
typedef void(WINAPI *GetSystemInfoFcn)(SYSTEM_INFO *pSystemInfo);
@ -71,7 +58,7 @@ class Wddm {
virtual ~Wddm();
static Wddm *createWddm(Gdi *gdi = nullptr);
static Wddm *createWddm();
static bool enumAdapters(unsigned int devNum, HardwareInfo &outHardwareInfo);
@ -140,7 +127,7 @@ class Wddm {
D3DKMT_HANDLE getDevice() const { return device; }
D3DKMT_HANDLE getPagingQueue() const { return pagingQueue; }
D3DKMT_HANDLE getPagingQueueSyncObject() const { return pagingQueueSyncObject; }
Gdi *getGdi() const { return gdi; }
Gdi *getGdi() const { return gdi.get(); }
PFND3DKMT_ESCAPE getEscapeHandle() const;
@ -175,8 +162,7 @@ class Wddm {
protected:
bool initialized;
bool gdiAllocated;
Gdi *gdi;
std::unique_ptr<Gdi> gdi;
D3DKMT_HANDLE adapter;
D3DKMT_HANDLE context;
D3DKMT_HANDLE device;
@ -208,6 +194,7 @@ class Wddm {
std::unique_ptr<GmmMemory> gmmMemory;
uintptr_t minAddress;
Wddm();
MOCKABLE_VIRTUAL bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1);
MOCKABLE_VIRTUAL bool openAdapter();
bool createDevice();

View File

@ -21,7 +21,7 @@
*/
#include "runtime/os_interface/windows/gdi_interface.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
namespace OCLRT {

View File

@ -21,11 +21,11 @@
*/
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include <dxgi.h>
namespace OCLRT {
Wddm *Wddm::createWddm(Gdi *gdi) {
Wddm *Wddm::createWddm() {
return new Wddm();
}

View File

@ -29,7 +29,7 @@
#include "runtime/command_stream/preemption.h"
#include "runtime/mem_obj/mem_obj.h"
#include "runtime/device/device.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm_device_command_stream.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/helpers/translationtable_callbacks.h"

View File

@ -24,7 +24,7 @@
#include "runtime/helpers/engine_node.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include <cstdint>

View File

@ -31,7 +31,7 @@
#include "runtime/memory_manager/deferrable_deletion.h"
#include "runtime/os_interface/windows/wddm_memory_manager.h"
#include "runtime/os_interface/windows/wddm_allocation.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include <algorithm>
namespace OCLRT {

View File

@ -22,8 +22,19 @@
#pragma once
#include <d3dkmthk.h>
#include <cstdint>
namespace OCLRT {
constexpr uintptr_t windowsMinAddress = 0x200000;
struct MonitoredFence {
D3DKMT_HANDLE fenceHandle;
D3DGPU_VIRTUAL_ADDRESS gpuAddress;
volatile uint64_t *cpuAddress;
volatile uint64_t currentFenceValue;
uint64_t lastSubmittedFence;
};
} // namespace OCLRT

View File

@ -22,7 +22,7 @@
#pragma once
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include <vector>
#include <set>
@ -57,7 +57,6 @@ class WddmMock : public Wddm {
using Wddm::pagingQueue;
WddmMock() : Wddm(){};
WddmMock(Gdi *gdi) : Wddm(gdi) {}
~WddmMock();
bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override;

View File

@ -96,13 +96,15 @@ class WddmCommandStreamWithMockGdiFixture {
MemoryManager *memManager = nullptr;
MockDevice *device = nullptr;
WddmMock *wddm = nullptr;
MockGdi gdi;
MockGdi *gdi = nullptr;
DebugManagerStateRestore stateRestore;
GraphicsAllocation *tagAllocation;
GraphicsAllocation *preemptionAllocation = nullptr;
virtual void SetUp() {
wddm = static_cast<WddmMock *>(Wddm::createWddm(&gdi));
wddm = static_cast<WddmMock *>(Wddm::createWddm());
gdi = new MockGdi();
wddm->gdi.reset(gdi);
ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm);
@ -605,12 +607,12 @@ TEST_F(WddmCommandStreamMockGdiTest, FlushCallsWddmMakeResidentForResidencyAlloc
EXPECT_EQ(1u, memManager->getResidencyAllocations().size());
gdi.getMakeResidentArg().NumAllocations = 0;
gdi->getMakeResidentArg().NumAllocations = 0;
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
EXPECT_NE(0u, gdi.getMakeResidentArg().NumAllocations);
EXPECT_NE(0u, gdi->getMakeResidentArg().NumAllocations);
memManager->freeGraphicsMemory(commandBuffer);
}

View File

@ -23,7 +23,7 @@
#include "unit_tests/os_interface/windows/hw_info_config_tests.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/libult/mock_gfx_family.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -22,7 +22,7 @@
#pragma once
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h"

View File

@ -28,7 +28,6 @@ using namespace OCLRT;
class WddmMockReserveAddress : public WddmMock {
public:
WddmMockReserveAddress() : WddmMock() {}
WddmMockReserveAddress(Gdi *gdi) : WddmMock(gdi) {}
void *virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) override {
if (returnGood != 0) {

View File

@ -34,10 +34,8 @@ LPVOID WINAPI ULTVirtualAlloc(LPVOID inPtr, SIZE_T size, DWORD flags, DWORD type
return malloc(size);
}
Wddm *Wddm::createWddm(Gdi *gdi) {
if (gdi == nullptr)
Wddm *Wddm::createWddm() {
return new WddmMock();
return new WddmMock(gdi);
}
Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() {

View File

@ -32,13 +32,15 @@
namespace OCLRT {
struct WddmFixture {
virtual void SetUp() {
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(&gdi)));
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
gdi = new MockGdi();
wddm->gdi.reset(gdi);
}
virtual void TearDown(){};
std::unique_ptr<WddmMock> wddm;
MockGdi gdi;
MockGdi *gdi = nullptr;
};
struct WddmFixtureWithMockGdiDll : public GdiDllFixture {

View File

@ -20,7 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm_allocation.h"
#include "unit_tests/os_interface/windows/mock_kmdaf_listener.h"
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
@ -31,7 +31,9 @@ using namespace OCLRT;
class WddmWithKmDafMock : public Wddm {
public:
WddmWithKmDafMock(Gdi *gdi) : Wddm(gdi) {
using Wddm::gdi;
WddmWithKmDafMock() : Wddm() {
kmDafListener.reset(new KmDafListenerMock);
}
@ -51,16 +53,13 @@ class WddmWithKmDafMock : public Wddm {
class WddmKmDafListenerTest : public ::testing::Test {
public:
void SetUp() {
wddmWithKmDafMock = new WddmWithKmDafMock(&gdi);
wddmWithKmDafMock.reset(new WddmWithKmDafMock());
wddmWithKmDafMock->gdi.reset(new MockGdi());
wddmWithKmDafMock->init<DEFAULT_TEST_FAMILY_NAME>();
wddmWithKmDafMock->getFeatureTable()->ftrKmdDaf = true;
}
void TearDown() {
delete wddmWithKmDafMock;
}
WddmWithKmDafMock *wddmWithKmDafMock;
MockGdi gdi;
std::unique_ptr<WddmWithKmDafMock> wddmWithKmDafMock;
};
HWTEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) {

View File

@ -958,7 +958,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTr
EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident);
}
EXPECT_EQ(5u, gdi.getMakeResidentArg().NumAllocations);
EXPECT_EQ(5u, gdi->getMakeResidentArg().NumAllocations);
memoryManager->freeGraphicsMemory(allocationTriple);
}
@ -986,9 +986,9 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLas
HWTEST_F(WddmMemoryManagerResidencyTest, trimCallbackIsRegisteredInWddmMemoryManagerCtor) {
SetUpMm<FamilyType>();
EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)memoryManager->trimCallback, gdi.getRegisterTrimNotificationArg().Callback);
EXPECT_EQ(reinterpret_cast<void *>(memoryManager.get()), gdi.getRegisterTrimNotificationArg().Context);
EXPECT_EQ(wddm->getDevice(), gdi.getRegisterTrimNotificationArg().hDevice);
EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)memoryManager->trimCallback, gdi->getRegisterTrimNotificationArg().Callback);
EXPECT_EQ(reinterpret_cast<void *>(memoryManager.get()), gdi->getRegisterTrimNotificationArg().Context);
EXPECT_EQ(wddm->getDevice(), gdi->getRegisterTrimNotificationArg().hDevice);
}
HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeriodicTrimWhenTrimResidencyPeriodicTrimIsCalledThenAllocationsAreEvictedMarkedAndRemovedFromTrimCandidateList) {
@ -1149,7 +1149,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWithZeroSizeReturnsTrue) {
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
SetUpMm<FamilyType>();
gdi.setNonZeroNumBytesToTrimInEvict();
gdi->setNonZeroNumBytesToTrimInEvict();
WddmAllocation allocation1, allocation2, allocation3;
allocation1.getResidencyData().resident = true;
@ -1188,7 +1188,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToTrimIsNotZero) {
SetUpMm<FamilyType>();
gdi.setNonZeroNumBytesToTrimInEvict();
gdi->setNonZeroNumBytesToTrimInEvict();
WddmAllocation allocation1;
allocation1.getResidencyData().resident = true;
@ -1250,7 +1250,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonResident) {
SetUpMm<FamilyType>();
gdi.setNonZeroNumBytesToTrimInEvict();
gdi->setNonZeroNumBytesToTrimInEvict();
WddmAllocation allocation1, allocation2, allocation3;
allocation1.getResidencyData().resident = true;
@ -1283,7 +1283,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonRe
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIsGreaterThanMonitored) {
SetUpMm<FamilyType>();
gdi.setNonZeroNumBytesToTrimInEvict();
gdi->setNonZeroNumBytesToTrimInEvict();
WddmAllocation allocation1;
allocation1.getResidencyData().resident = true;
@ -1300,19 +1300,19 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs
memoryManager->addToTrimCandidateList(&allocation1);
gdi.getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_FALSE(allocation1.getResidencyData().resident);
EXPECT_EQ(wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(wddm->getDevice(), gdi->getWaitFromCpuArg().hDevice);
}
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) {
SetUpMm<FamilyType>();
gdi.setNonZeroNumBytesToTrimInEvict();
gdi->setNonZeroNumBytesToTrimInEvict();
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr);
WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr);
@ -1387,7 +1387,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, checkTrimCandidateListCompaction) {
HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerThanAllocSizeWhenBudgetEqualTwoAlignedAllocationThenEvictOnlyTwo) {
SetUpMm<FamilyType>();
gdi.setNonZeroNumBytesToTrimInEvict();
gdi->setNonZeroNumBytesToTrimInEvict();
size_t underlyingSize = 0xF00;
size_t alignedSize = 0x1000;
size_t budget = 2 * alignedSize;

View File

@ -62,7 +62,9 @@ typedef ::Test<WddmMemoryManagerFixture> WddmMemoryManagerTest;
class MockWddmMemoryManagerFixture {
public:
void SetUp() {
wddm = static_cast<WddmMock *>(Wddm::createWddm(&gdi));
wddm = static_cast<WddmMock *>(Wddm::createWddm());
gdi = new MockGdi();
wddm->gdi.reset(gdi);
}
template <typename FamiltyType>
@ -81,7 +83,7 @@ class MockWddmMemoryManagerFixture {
virtual void TearDown() {}
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;
MockGdi gdi;
MockGdi *gdi = nullptr;
};
typedef ::Test<MockWddmMemoryManagerFixture> WddmMemoryManagerResidencyTest;

View File

@ -680,14 +680,14 @@ HWTEST_F(WddmTest, makeResidentMultipleHandles) {
handles[0] = allocation.handle;
handles[1] = allocation.handle;
gdi.getMakeResidentArg().NumAllocations = 0;
gdi.getMakeResidentArg().AllocationList = nullptr;
gdi->getMakeResidentArg().NumAllocations = 0;
gdi->getMakeResidentArg().AllocationList = nullptr;
bool error = wddm->makeResident(handles, 2, false, nullptr);
EXPECT_TRUE(error);
EXPECT_EQ(2u, gdi.getMakeResidentArg().NumAllocations);
EXPECT_EQ(handles, gdi.getMakeResidentArg().AllocationList);
EXPECT_EQ(2u, gdi->getMakeResidentArg().NumAllocations);
EXPECT_EQ(handles, gdi->getMakeResidentArg().AllocationList);
mm.freeSystemMemory(allocation.getUnderlyingBuffer());
}
@ -705,15 +705,15 @@ HWTEST_F(WddmTest, makeResidentMultipleHandlesWithReturnBytesToTrim) {
handles[0] = allocation.handle;
handles[1] = allocation.handle;
gdi.getMakeResidentArg().NumAllocations = 0;
gdi.getMakeResidentArg().AllocationList = nullptr;
gdi.getMakeResidentArg().NumBytesToTrim = 30;
gdi->getMakeResidentArg().NumAllocations = 0;
gdi->getMakeResidentArg().AllocationList = nullptr;
gdi->getMakeResidentArg().NumBytesToTrim = 30;
uint64_t bytesToTrim = 0;
bool success = wddm->makeResident(handles, 2, false, &bytesToTrim);
EXPECT_TRUE(success);
EXPECT_EQ(gdi.getMakeResidentArg().NumBytesToTrim, bytesToTrim);
EXPECT_EQ(gdi->getMakeResidentArg().NumBytesToTrim, bytesToTrim);
mm.freeSystemMemory(allocation.getUnderlyingBuffer());
}
@ -723,19 +723,19 @@ HWTEST_F(WddmTest, makeNonResidentCallsEvict) {
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
gdi.getEvictArg().AllocationList = nullptr;
gdi.getEvictArg().Flags.Value = 0;
gdi.getEvictArg().hDevice = 0;
gdi.getEvictArg().NumAllocations = 0;
gdi.getEvictArg().NumBytesToTrim = 20;
gdi->getEvictArg().AllocationList = nullptr;
gdi->getEvictArg().Flags.Value = 0;
gdi->getEvictArg().hDevice = 0;
gdi->getEvictArg().NumAllocations = 0;
gdi->getEvictArg().NumBytesToTrim = 20;
uint64_t sizeToTrim = 10;
wddm->evict(&handle, 1, sizeToTrim);
EXPECT_EQ(1u, gdi.getEvictArg().NumAllocations);
EXPECT_EQ(&handle, gdi.getEvictArg().AllocationList);
EXPECT_EQ(wddm->getDevice(), gdi.getEvictArg().hDevice);
EXPECT_EQ(0u, gdi.getEvictArg().NumBytesToTrim);
EXPECT_EQ(1u, gdi->getEvictArg().NumAllocations);
EXPECT_EQ(&handle, gdi->getEvictArg().AllocationList);
EXPECT_EQ(wddm->getDevice(), gdi->getEvictArg().hDevice);
EXPECT_EQ(0u, gdi->getEvictArg().NumBytesToTrim);
}
HWTEST_F(WddmTest, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCallsWaitFromCpu) {
@ -749,28 +749,28 @@ HWTEST_F(WddmTest, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCal
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
gdi.getWaitFromCpuArg().FenceValueArray = nullptr;
gdi.getWaitFromCpuArg().Flags.Value = 0;
gdi.getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi.getWaitFromCpuArg().ObjectCount = 0;
gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
gdi->getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getWaitFromCpuArg().ObjectCount = 0;
gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr;
gdi.getDestroyArg().AllocationCount = 0;
gdi.getDestroyArg().Flags.Value = 0;
gdi.getDestroyArg().hDevice = (D3DKMT_HANDLE)0;
gdi.getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi.getDestroyArg().phAllocationList = nullptr;
gdi->getDestroyArg().AllocationCount = 0;
gdi->getDestroyArg().Flags.Value = 0;
gdi->getDestroyArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi->getDestroyArg().phAllocationList = nullptr;
wddm->destroyAllocation(&allocation);
EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ(wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(1u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(&wddm->getMonitoredFence().fenceHandle, gdi.getWaitFromCpuArg().ObjectHandleArray);
EXPECT_NE(nullptr, gdi->getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ(wddm->getDevice(), gdi->getWaitFromCpuArg().hDevice);
EXPECT_EQ(1u, gdi->getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(&wddm->getMonitoredFence().fenceHandle, gdi->getWaitFromCpuArg().ObjectHandleArray);
EXPECT_EQ(wddm->getDevice(), gdi.getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi.getDestroyArg().AllocationCount);
EXPECT_NE(nullptr, gdi.getDestroyArg().phAllocationList);
EXPECT_EQ(wddm->getDevice(), gdi->getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi->getDestroyArg().AllocationCount);
EXPECT_NE(nullptr, gdi->getDestroyArg().phAllocationList);
}
HWTEST_F(WddmTest, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDoesNotCallWaitFromCpu) {
@ -784,28 +784,28 @@ HWTEST_F(WddmTest, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDoe
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
gdi.getWaitFromCpuArg().FenceValueArray = nullptr;
gdi.getWaitFromCpuArg().Flags.Value = 0;
gdi.getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi.getWaitFromCpuArg().ObjectCount = 0;
gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
gdi->getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getWaitFromCpuArg().ObjectCount = 0;
gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr;
gdi.getDestroyArg().AllocationCount = 0;
gdi.getDestroyArg().Flags.Value = 0;
gdi.getDestroyArg().hDevice = (D3DKMT_HANDLE)0;
gdi.getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi.getDestroyArg().phAllocationList = nullptr;
gdi->getDestroyArg().AllocationCount = 0;
gdi->getDestroyArg().Flags.Value = 0;
gdi->getDestroyArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi->getDestroyArg().phAllocationList = nullptr;
wddm->destroyAllocation(&allocation);
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)0, gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(0u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray);
EXPECT_EQ(nullptr, gdi->getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)0, gdi->getWaitFromCpuArg().hDevice);
EXPECT_EQ(0u, gdi->getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(nullptr, gdi->getWaitFromCpuArg().ObjectHandleArray);
EXPECT_EQ(wddm->getDevice(), gdi.getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi.getDestroyArg().AllocationCount);
EXPECT_NE(nullptr, gdi.getDestroyArg().phAllocationList);
EXPECT_EQ(wddm->getDevice(), gdi->getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi->getDestroyArg().AllocationCount);
EXPECT_NE(nullptr, gdi->getDestroyArg().phAllocationList);
}
HWTEST_F(WddmTest, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) {
@ -817,20 +817,20 @@ HWTEST_F(WddmTest, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled
*wddm->getMonitoredFence().cpuAddress = 10;
gdi.getWaitFromCpuArg().FenceValueArray = nullptr;
gdi.getWaitFromCpuArg().Flags.Value = 0;
gdi.getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi.getWaitFromCpuArg().ObjectCount = 0;
gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
gdi->getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getWaitFromCpuArg().ObjectCount = 0;
gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr;
auto status = wddm->waitFromCpu(10);
EXPECT_TRUE(status);
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)0, gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(0u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray);
EXPECT_EQ(nullptr, gdi->getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)0, gdi->getWaitFromCpuArg().hDevice);
EXPECT_EQ(0u, gdi->getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(nullptr, gdi->getWaitFromCpuArg().ObjectHandleArray);
}
HWTEST_F(WddmTest, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) {
@ -842,32 +842,32 @@ HWTEST_F(WddmTest, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) {
*wddm->getMonitoredFence().cpuAddress = 10;
gdi.getWaitFromCpuArg().FenceValueArray = nullptr;
gdi.getWaitFromCpuArg().Flags.Value = 0;
gdi.getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi.getWaitFromCpuArg().ObjectCount = 0;
gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
gdi->getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0;
gdi->getWaitFromCpuArg().ObjectCount = 0;
gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr;
auto status = wddm->waitFromCpu(20);
EXPECT_TRUE(status);
EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(1u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray);
EXPECT_NE(nullptr, gdi->getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)wddm->getDevice(), gdi->getWaitFromCpuArg().hDevice);
EXPECT_EQ(1u, gdi->getWaitFromCpuArg().ObjectCount);
EXPECT_NE(nullptr, gdi->getWaitFromCpuArg().ObjectHandleArray);
}
HWTEST_F(WddmTest, createMonitoredFenceIsInitializedWithFenceValueZeroAndCurrentFenceValueIsSetToOne) {
wddm->init<FamilyType>();
gdi.createSynchronizationObject2 = gdi.createSynchronizationObject2Mock;
gdi->createSynchronizationObject2 = gdi->createSynchronizationObject2Mock;
gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300;
gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300;
wddm->createMonitoredFence();
EXPECT_EQ(0u, gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue);
EXPECT_EQ(0u, gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue);
EXPECT_EQ(1u, wddm->getMonitoredFence().currentFenceValue);
}
@ -882,7 +882,7 @@ HWTEST_F(WddmTest, givenOpenSharedHandleWhenZeroAllocationsThenReturnNull) {
D3DKMT_HANDLE handle = 0;
WddmAllocation *alloc = nullptr;
gdi.queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock);
gdi->queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock);
auto ret = wddm->openSharedHandle(handle, alloc);
EXPECT_EQ(false, ret);
@ -895,7 +895,7 @@ HWTEST_F(WddmTest, givenReadOnlyMemoryWhenCreateAllocationFailsWithNoVideoMemory
return STATUS_GRAPHICS_NO_VIDEO_MEMORY;
};
};
gdi.createAllocation = MockCreateAllocation::mockCreateAllocation;
gdi->createAllocation = MockCreateAllocation::mockCreateAllocation;
wddm->init<FamilyType>();
OsHandleStorage handleStorage;