diff --git a/runtime/dll/CMakeLists.txt b/runtime/dll/CMakeLists.txt index 89ddc82fea..03a03a1c3a 100644 --- a/runtime/dll/CMakeLists.txt +++ b/runtime/dll/CMakeLists.txt @@ -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}) diff --git a/runtime/gen8/windows/wddm.cpp b/runtime/gen8/windows/wddm.cpp index cb662747f9..512b796c31 100644 --- a/runtime/gen8/windows/wddm.cpp +++ b/runtime/gen8/windows/wddm.cpp @@ -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 { diff --git a/runtime/gen9/windows/wddm.cpp b/runtime/gen9/windows/wddm.cpp index ea1d3f2ed5..a39fcca385 100644 --- a/runtime/gen9/windows/wddm.cpp +++ b/runtime/gen9/windows/wddm.cpp @@ -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 { diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index 7188ed79c4..ee66b8942b 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -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) diff --git a/runtime/os_interface/windows/deferrable_deletion_win.cpp b/runtime/os_interface/windows/deferrable_deletion_win.cpp index 4f617c7789..ca28eff919 100644 --- a/runtime/os_interface/windows/deferrable_deletion_win.cpp +++ b/runtime/os_interface/windows/deferrable_deletion_win.cpp @@ -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 { diff --git a/runtime/os_interface/windows/device_factory.cpp b/runtime/os_interface/windows/device_factory.cpp index 05caad038c..ca7bfad648 100644 --- a/runtime/os_interface/windows/device_factory.cpp +++ b/runtime/os_interface/windows/device_factory.cpp @@ -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 { diff --git a/runtime/os_interface/windows/driver_info.cpp b/runtime/os_interface/windows/driver_info.cpp index 21f05a5e7a..463903629b 100644 --- a/runtime/os_interface/windows/driver_info.cpp +++ b/runtime/os_interface/windows/driver_info.cpp @@ -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" diff --git a/runtime/os_interface/windows/os_interface.cpp b/runtime/os_interface/windows/os_interface.cpp index bef34892ce..10fbda0099 100644 --- a/runtime/os_interface/windows/os_interface.cpp +++ b/runtime/os_interface/windows/os_interface.cpp @@ -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 { diff --git a/runtime/os_interface/windows/os_time.cpp b/runtime/os_interface/windows/os_time.cpp index 6436bf4c44..c9a92b765b 100644 --- a/runtime/os_interface/windows/os_time.cpp +++ b/runtime/os_interface/windows/os_time.cpp @@ -21,7 +21,7 @@ */ #include -#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" diff --git a/runtime/os_interface/windows/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp similarity index 98% rename from runtime/os_interface/windows/wddm.cpp rename to runtime/os_interface/windows/wddm/wddm.cpp index 046b3faa3e..77eca1c68c 100644 --- a/runtime/os_interface/windows/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -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,18 +53,16 @@ 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), - adapter(0), - context(0), - device(0), - pagingQueue(0), - pagingQueueSyncObject(0), - pagingFenceAddress(nullptr), - currentPagingFenceValue(0), - hwContextId(0), - trimCallbackHandle(nullptr) { +Wddm::Wddm() : initialized(false), + adapter(0), + context(0), + device(0), + pagingQueue(0), + pagingQueueSyncObject(0), + pagingFenceAddress(nullptr), + currentPagingFenceValue(0), + hwContextId(0), + trimCallbackHandle(nullptr) { featureTable.reset(new FeatureTable()); waTable.reset(new WorkaroundTable()); gtSystemInfo.reset(new GT_SYSTEM_INFO); @@ -81,10 +79,7 @@ Wddm::Wddm(Gdi *gdi) : initialized(false), gmmMemory = std::unique_ptr(GmmMemory::create()); minAddress = 0; kmDafListener = std::unique_ptr(new KmDafListener); -} - -Wddm::Wddm() : Wddm(new Gdi()) { - gdiAllocated = true; + gdi = std::unique_ptr(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) { diff --git a/runtime/os_interface/windows/wddm.h b/runtime/os_interface/windows/wddm/wddm.h similarity index 95% rename from runtime/os_interface/windows/wddm.h rename to runtime/os_interface/windows/wddm/wddm.h index 7713b6eaf0..2935ab6556 100644 --- a/runtime/os_interface/windows/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -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; D3DKMT_HANDLE adapter; D3DKMT_HANDLE context; D3DKMT_HANDLE device; @@ -208,6 +194,7 @@ class Wddm { std::unique_ptr 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(); diff --git a/runtime/os_interface/windows/wddm.inl b/runtime/os_interface/windows/wddm/wddm.inl similarity index 97% rename from runtime/os_interface/windows/wddm.inl rename to runtime/os_interface/windows/wddm/wddm.inl index d8f5c7342e..04c82e65d6 100644 --- a/runtime/os_interface/windows/wddm.inl +++ b/runtime/os_interface/windows/wddm/wddm.inl @@ -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 { diff --git a/runtime/os_interface/windows/wddm_create.cpp b/runtime/os_interface/windows/wddm/wddm_create.cpp similarity index 95% rename from runtime/os_interface/windows/wddm_create.cpp rename to runtime/os_interface/windows/wddm/wddm_create.cpp index fc78587115..7298438c79 100644 --- a/runtime/os_interface/windows/wddm_create.cpp +++ b/runtime/os_interface/windows/wddm/wddm_create.cpp @@ -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 namespace OCLRT { -Wddm *Wddm::createWddm(Gdi *gdi) { +Wddm *Wddm::createWddm() { return new Wddm(); } diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index f1d865be8b..60d5911d4c 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -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" diff --git a/runtime/os_interface/windows/wddm_engine_mapper.h b/runtime/os_interface/windows/wddm_engine_mapper.h index eb8ef71a7f..474ea8bb78 100644 --- a/runtime/os_interface/windows/wddm_engine_mapper.h +++ b/runtime/os_interface/windows/wddm_engine_mapper.h @@ -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 diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 0cd54ec13e..29f1646357 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -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 namespace OCLRT { diff --git a/runtime/os_interface/windows/windows_defs.h b/runtime/os_interface/windows/windows_defs.h index d94d5730af..27b6144b73 100644 --- a/runtime/os_interface/windows/windows_defs.h +++ b/runtime/os_interface/windows/windows_defs.h @@ -22,8 +22,19 @@ #pragma once +#include +#include + 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 diff --git a/unit_tests/mocks/mock_wddm.h b/unit_tests/mocks/mock_wddm.h index 86f824a880..8a477db3b6 100644 --- a/unit_tests/mocks/mock_wddm.h +++ b/unit_tests/mocks/mock_wddm.h @@ -22,7 +22,7 @@ #pragma once -#include "runtime/os_interface/windows/wddm.h" +#include "runtime/os_interface/windows/wddm/wddm.h" #include #include @@ -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; diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index b059fc627e..2d487552c4 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -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(Wddm::createWddm(&gdi)); + wddm = static_cast(Wddm::createWddm()); + gdi = new MockGdi(); + wddm->gdi.reset(gdi); ASSERT_NE(wddm, nullptr); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); csr = new WddmCommandStreamReceiver(*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); } diff --git a/unit_tests/os_interface/windows/hw_info_config_tests.cpp b/unit_tests/os_interface/windows/hw_info_config_tests.cpp index 32001c4204..4c7fbe0dd1 100644 --- a/unit_tests/os_interface/windows/hw_info_config_tests.cpp +++ b/unit_tests/os_interface/windows/hw_info_config_tests.cpp @@ -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" diff --git a/unit_tests/os_interface/windows/os_interface_tests.h b/unit_tests/os_interface/windows/os_interface_tests.h index eaf9f88fc6..0efee1c7de 100644 --- a/unit_tests/os_interface/windows/os_interface_tests.h +++ b/unit_tests/os_interface/windows/os_interface_tests.h @@ -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" diff --git a/unit_tests/os_interface/windows/wddm_address_space_tests.cpp b/unit_tests/os_interface/windows/wddm_address_space_tests.cpp index bb529e55d7..63642f4646 100644 --- a/unit_tests/os_interface/windows/wddm_address_space_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_address_space_tests.cpp @@ -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) { diff --git a/unit_tests/os_interface/windows/wddm_create.cpp b/unit_tests/os_interface/windows/wddm_create.cpp index 203b0fdc20..807b67e319 100644 --- a/unit_tests/os_interface/windows/wddm_create.cpp +++ b/unit_tests/os_interface/windows/wddm_create.cpp @@ -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) - return new WddmMock(); - return new WddmMock(gdi); +Wddm *Wddm::createWddm() { + return new WddmMock(); } Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() { diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index ed4905487f..1ca18d4328 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -32,13 +32,15 @@ namespace OCLRT { struct WddmFixture { virtual void SetUp() { - wddm.reset(static_cast(Wddm::createWddm(&gdi))); + wddm.reset(static_cast(Wddm::createWddm())); + gdi = new MockGdi(); + wddm->gdi.reset(gdi); } virtual void TearDown(){}; std::unique_ptr wddm; - MockGdi gdi; + MockGdi *gdi = nullptr; }; struct WddmFixtureWithMockGdiDll : public GdiDllFixture { diff --git a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp index fc2c060819..f40aca37ff 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -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(); wddmWithKmDafMock->getFeatureTable()->ftrKmdDaf = true; } - void TearDown() { - delete wddmWithKmDafMock; - } - WddmWithKmDafMock *wddmWithKmDafMock; - MockGdi gdi; + std::unique_ptr wddmWithKmDafMock; }; HWTEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) { diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index 7d2359f3a5..1804ad26f8 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -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(); - EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)memoryManager->trimCallback, gdi.getRegisterTrimNotificationArg().Callback); - EXPECT_EQ(reinterpret_cast(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(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(); - 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(); - gdi.setNonZeroNumBytesToTrimInEvict(); + gdi->setNonZeroNumBytesToTrimInEvict(); WddmAllocation allocation1; allocation1.getResidencyData().resident = true; @@ -1250,7 +1250,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonResident) { SetUpMm(); - 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(); - 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(); - gdi.setNonZeroNumBytesToTrimInEvict(); + gdi->setNonZeroNumBytesToTrimInEvict(); void *ptr = reinterpret_cast(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(); - gdi.setNonZeroNumBytesToTrimInEvict(); + gdi->setNonZeroNumBytesToTrimInEvict(); size_t underlyingSize = 0xF00; size_t alignedSize = 0x1000; size_t budget = 2 * alignedSize; diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 2c1f458cba..6b525d509f 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -62,7 +62,9 @@ typedef ::Test WddmMemoryManagerTest; class MockWddmMemoryManagerFixture { public: void SetUp() { - wddm = static_cast(Wddm::createWddm(&gdi)); + wddm = static_cast(Wddm::createWddm()); + gdi = new MockGdi(); + wddm->gdi.reset(gdi); } template @@ -81,7 +83,7 @@ class MockWddmMemoryManagerFixture { virtual void TearDown() {} std::unique_ptr memoryManager; WddmMock *wddm = nullptr; - MockGdi gdi; + MockGdi *gdi = nullptr; }; typedef ::Test WddmMemoryManagerResidencyTest; diff --git a/unit_tests/os_interface/windows/wddm_tests.cpp b/unit_tests/os_interface/windows/wddm_tests.cpp index 21b70bda84..e1fac4e6a1 100644 --- a/unit_tests/os_interface/windows/wddm_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_tests.cpp @@ -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(); - 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(queryResourceInfoMock); + gdi->queryResourceInfo = reinterpret_cast(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(); OsHandleStorage handleStorage;