From cc46cdf46cb37eb7801918cd03c7fd3e06fd4068 Mon Sep 17 00:00:00 2001 From: Andrzej Swierczynski Date: Wed, 6 Nov 2019 18:14:30 +0100 Subject: [PATCH] Move PageTableManager to RootDeviceEnvironment Related-To: NEO-2285 Change-Id: I77699b5f540b6ac5b73cf1830712a5591326b766 Signed-off-by: Andrzej Swierczynski --- Jenkinsfile | 4 +- .../root_device_environment.cpp | 1 + .../root_device_environment.h | 2 + .../windows/wddm_preemption_tests.cpp | 2 +- .../command_stream_receiver_hw.h | 1 - .../command_stream_receiver_hw_base.inl | 6 +- runtime/dll/CMakeLists.txt | 2 +- runtime/gmm_helper/CMakeLists.txt | 4 +- runtime/gmm_helper/page_table_mngr.h | 26 +++--- runtime/gmm_helper/page_table_mngr_impl.cpp | 22 ++++- runtime/memory_manager/memory_manager.cpp | 11 +++ runtime/memory_manager/memory_manager.h | 2 +- runtime/os_interface/linux/CMakeLists.txt | 1 + .../os_interface/linux/drm_command_stream.h | 1 + .../os_interface/linux/drm_command_stream.inl | 10 +++ .../linux/page_table_manager_functions.cpp | 21 +++++ runtime/os_interface/windows/CMakeLists.txt | 1 + .../windows/device_factory_win.cpp | 2 +- .../windows/page_table_manager_functions.cpp | 23 ++++++ runtime/os_interface/windows/wddm/wddm.cpp | 24 ++---- runtime/os_interface/windows/wddm/wddm.h | 13 +-- .../os_interface/windows/wddm/wddm_create.cpp | 4 +- .../windows/wddm_device_command_stream.h | 2 - .../windows/wddm_device_command_stream.inl | 14 +--- .../windows/wddm_memory_manager.cpp | 11 ++- .../windows/wddm_memory_manager.h | 2 - .../create_command_stream_receiver_tests.cpp | 2 +- unit_tests/device/device_win_timers_tests.cpp | 6 +- unit_tests/fixtures/buffer_enqueue_fixture.h | 2 +- .../device_instrumentation_fixture.cpp | 2 +- .../windows/gmm_callbacks_tests_gen12lp.cpp | 2 +- .../helpers/execution_environment_helper.cpp | 3 +- .../helpers/execution_environment_helper.h | 2 +- .../memory_manager/memory_manager_tests.cpp | 18 +++++ unit_tests/mocks/CMakeLists.txt | 6 +- unit_tests/mocks/mock_gmm_page_table_mngr.cpp | 1 - unit_tests/mocks/mock_gmm_page_table_mngr.h | 19 ++++- unit_tests/mocks/mock_wddm.cpp | 7 +- unit_tests/mocks/mock_wddm.h | 10 +-- .../linux/device_command_stream_tests.cpp | 2 +- .../linux/drm_command_stream_tests.cpp | 69 ++++++++++++++++ .../mock_performance_counters.cpp | 17 ++++ .../os_interface/mock_performance_counters.h | 6 ++ .../performance_counters_tests.cpp | 2 + .../windows/deferrable_deletion_win_tests.cpp | 23 ++++-- .../windows/device_command_stream_tests.cpp | 74 ++++++++--------- .../windows/driver_info_tests.cpp | 8 +- .../windows/gl/gl_os_sharing_tests.cpp | 14 ++-- .../windows/hw_info_config_win_tests.cpp | 12 ++- .../windows/hw_info_config_win_tests.h | 8 ++ .../windows/mock_performance_counters_win.cpp | 2 +- .../windows/os_interface_win_tests.cpp | 10 ++- .../windows/os_time_win_tests.cpp | 6 +- .../os_interface/windows/wddm20_tests.cpp | 80 ++++++++++++------- .../os_interface/windows/wddm23_tests.cpp | 3 +- .../windows/wddm_address_space_tests.cpp | 24 ++++-- .../os_interface/windows/wddm_create.cpp | 4 +- .../os_interface/windows/wddm_fixture.h | 6 +- .../windows/wddm_kmdaf_listener_tests.cpp | 5 +- .../windows/wddm_memory_manager_tests.cpp | 66 ++++++++++----- .../windows/wddm_memory_manager_tests.h | 9 ++- .../wddm_residency_controller_tests.cpp | 26 ++++-- ...d_write_buffer_scenarios_windows_tests.cpp | 2 +- .../source_level_debugger_csr_tests.cpp | 2 +- .../source_level_debugger_tests.cpp | 2 +- unit_tests/windows/wddm_create_tests.cpp | 6 +- 66 files changed, 543 insertions(+), 237 deletions(-) create mode 100644 runtime/os_interface/linux/page_table_manager_functions.cpp create mode 100644 runtime/os_interface/windows/page_table_manager_functions.cpp diff --git a/Jenkinsfile b/Jenkinsfile index 73edfaf41b..7a11084221 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy dependenciesRevision='42bc9ab3a399b043aa54824c449d5d7a96b7ea82-1354' strategy='EQUAL' -allowedCD=256 -allowedF=7 +allowedCD=259 +allowedF=11 diff --git a/core/execution_environment/root_device_environment.cpp b/core/execution_environment/root_device_environment.cpp index 81b2f4f53f..d945ffefe5 100644 --- a/core/execution_environment/root_device_environment.cpp +++ b/core/execution_environment/root_device_environment.cpp @@ -9,6 +9,7 @@ #include "runtime/aub/aub_center.h" #include "runtime/execution_environment/execution_environment.h" +#include "runtime/gmm_helper/page_table_mngr.h" namespace NEO { diff --git a/core/execution_environment/root_device_environment.h b/core/execution_environment/root_device_environment.h index 3e9ec41f07..f4fef12e89 100644 --- a/core/execution_environment/root_device_environment.h +++ b/core/execution_environment/root_device_environment.h @@ -16,6 +16,7 @@ namespace NEO { class AubCenter; class ExecutionEnvironment; +class GmmPageTableMngr; struct RootDeviceEnvironment { RootDeviceEnvironment(ExecutionEnvironment &executionEnvironment); @@ -24,6 +25,7 @@ struct RootDeviceEnvironment { MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); + std::unique_ptr pageTableManager; std::unique_ptr aubCenter; ExecutionEnvironment &executionEnvironment; }; diff --git a/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp b/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp index ed2ac663b4..b6004f835d 100644 --- a/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp +++ b/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp @@ -29,7 +29,7 @@ class WddmPreemptionTests : public Test { } void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) { - wddm = static_cast(Wddm::createWddm()); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); diff --git a/runtime/command_stream/command_stream_receiver_hw.h b/runtime/command_stream/command_stream_receiver_hw.h index 2dda35e6a0..74ce02e077 100644 --- a/runtime/command_stream/command_stream_receiver_hw.h +++ b/runtime/command_stream/command_stream_receiver_hw.h @@ -90,7 +90,6 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { void programStateSip(LinearStream &cmdStream, Device &device); void programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t maxFrontEndThreads); void programStallingPipeControlForBarrier(LinearStream &cmdStream, DispatchFlags &dispatchFlags); - virtual void initPageTableManagerRegisters(LinearStream &csr){}; void programEngineModeCommands(LinearStream &csr, const DispatchFlags &dispatchFlags); void programEngineModeEpliogue(LinearStream &csr, const DispatchFlags &dispatchFlags); diff --git a/runtime/command_stream/command_stream_receiver_hw_base.inl b/runtime/command_stream/command_stream_receiver_hw_base.inl index c3576b770b..2ffadaec54 100644 --- a/runtime/command_stream/command_stream_receiver_hw_base.inl +++ b/runtime/command_stream/command_stream_receiver_hw_base.inl @@ -8,6 +8,7 @@ #include "core/command_stream/linear_stream.h" #include "core/command_stream/preemption.h" #include "core/debug_settings/debug_settings_manager.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/cache_policy.h" #include "core/helpers/hw_helper.h" #include "core/helpers/options.h" @@ -21,6 +22,7 @@ #include "runtime/command_stream/scratch_space_controller_base.h" #include "runtime/device/device.h" #include "runtime/event/event.h" +#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/gtpin/gtpin_notify.h" #include "runtime/helpers/blit_commands_helper.h" #include "runtime/helpers/flat_batch_buffer_helper_hw.h" @@ -259,7 +261,9 @@ CompletionStamp CommandStreamReceiverHw::flushTask( } programEngineModeCommands(commandStreamCSR, dispatchFlags); - initPageTableManagerRegisters(commandStreamCSR); + if (executionEnvironment.rootDeviceEnvironments[device.getRootDeviceIndex()]->pageTableManager.get()) { + executionEnvironment.rootDeviceEnvironments[device.getRootDeviceIndex()]->pageTableManager->initPageTableManagerRegisters(); + } programComputeMode(commandStreamCSR, dispatchFlags); programL3(commandStreamCSR, dispatchFlags, newL3Config); programPipelineSelect(commandStreamCSR, dispatchFlags.pipelineSelectArgs); diff --git a/runtime/dll/CMakeLists.txt b/runtime/dll/CMakeLists.txt index 2383d386c5..280b9e0f82 100644 --- a/runtime/dll/CMakeLists.txt +++ b/runtime/dll/CMakeLists.txt @@ -26,6 +26,7 @@ set(RUNTIME_SRCS_DLL_BASE ${NEO_SOURCE_DIR}/core/utilities/clflush.cpp ${NEO_SOURCE_DIR}/core/utilities/debug_settings_reader_creator.cpp ${NEO_SOURCE_DIR}/runtime/api/api.cpp + ${NEO_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp ${NEO_SOURCE_DIR}/runtime/gmm_helper/resource_info.cpp ${NEO_SOURCE_DIR}/runtime/helpers/built_ins_helper.cpp ${NEO_SOURCE_DIR}/runtime/program/evaluate_unhandled_token.cpp @@ -52,7 +53,6 @@ set(RUNTIME_SRCS_DLL_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/windows/os_interface.cpp ${NEO_SOURCE_DIR}/core/os_interface/windows/sys_calls.cpp ${NEO_SOURCE_DIR}/runtime/gmm_helper/gmm_memory.cpp - ${NEO_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr.cpp ${NEO_SOURCE_DIR}/runtime/os_interface/windows/wddm/wddm_calls.cpp ${NEO_SOURCE_DIR}/runtime/os_interface/windows/wddm/wddm_create.cpp ) diff --git a/runtime/gmm_helper/CMakeLists.txt b/runtime/gmm_helper/CMakeLists.txt index 16269ecd55..1261526891 100644 --- a/runtime/gmm_helper/CMakeLists.txt +++ b/runtime/gmm_helper/CMakeLists.txt @@ -18,11 +18,11 @@ set(RUNTIME_SRCS_GMM_HELPER_BASE ${CMAKE_CURRENT_SOURCE_DIR}/resource_info.h ${CMAKE_CURRENT_SOURCE_DIR}/resource_info_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/gmm_utils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/page_table_mngr.h + ${CMAKE_CURRENT_SOURCE_DIR}/page_table_mngr_impl.cpp ) set(RUNTIME_SRCS_GMM_HELPER_WINDOWS - ${CMAKE_CURRENT_SOURCE_DIR}/page_table_mngr.h - ${CMAKE_CURRENT_SOURCE_DIR}/page_table_mngr_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory${BRANCH_DIR_SUFFIX}/gmm_memory.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory_base.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory_base.cpp diff --git a/runtime/gmm_helper/page_table_mngr.h b/runtime/gmm_helper/page_table_mngr.h index 0a751620f6..35e9075233 100644 --- a/runtime/gmm_helper/page_table_mngr.h +++ b/runtime/gmm_helper/page_table_mngr.h @@ -8,33 +8,37 @@ #pragma once #include "core/gmm_helper/gmm_lib.h" +#include "External/Common/GmmPageTableMgr.h" + #include #include namespace NEO { +class Gmm; +class LinearStream; class GmmPageTableMngr { public: MOCKABLE_VIRTUAL ~GmmPageTableMngr(); static GmmPageTableMngr *create(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb); - MOCKABLE_VIRTUAL GMM_STATUS initContextAuxTableRegister(HANDLE initialBBHandle, GMM_ENGINE_TYPE engineType) { - return pageTableManager->InitContextAuxTableRegister(initialBBHandle, engineType); - } + MOCKABLE_VIRTUAL void setCsrHandle(void *csrHandle); - MOCKABLE_VIRTUAL GMM_STATUS initContextTRTableRegister(HANDLE initialBBHandle, GMM_ENGINE_TYPE engineType) { - return pageTableManager->InitContextTRTableRegister(initialBBHandle, engineType); - } + bool updateAuxTable(uint64_t gpuVa, Gmm *gmm, bool map); + void initPageTableManagerRegisters(); + + bool initialized = false; + + protected: + GmmPageTableMngr() = default; MOCKABLE_VIRTUAL GMM_STATUS updateAuxTable(const GMM_DDI_UPDATEAUXTABLE *ddiUpdateAuxTable) { return pageTableManager->UpdateAuxTable(ddiUpdateAuxTable); } - MOCKABLE_VIRTUAL void setCsrHandle(void *csrHandle) { - pageTableManager->GmmSetCsrHandle(csrHandle); - } - protected: - GmmPageTableMngr() = default; + MOCKABLE_VIRTUAL GMM_STATUS initContextAuxTableRegister(HANDLE initialBBHandle, GMM_ENGINE_TYPE engineType) { + return pageTableManager->InitContextAuxTableRegister(initialBBHandle, engineType); + } GmmPageTableMngr(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb); GMM_CLIENT_CONTEXT *clientContext = nullptr; diff --git a/runtime/gmm_helper/page_table_mngr_impl.cpp b/runtime/gmm_helper/page_table_mngr_impl.cpp index 15f2041fae..197308d322 100644 --- a/runtime/gmm_helper/page_table_mngr_impl.cpp +++ b/runtime/gmm_helper/page_table_mngr_impl.cpp @@ -6,8 +6,9 @@ */ #include "core/gmm_helper/gmm_helper.h" +#include "runtime/gmm_helper/gmm.h" #include "runtime/gmm_helper/page_table_mngr.h" -#include "runtime/platform/platform.h" +#include "runtime/gmm_helper/resource_info.h" #include "gmm_client_context.h" @@ -18,9 +19,22 @@ GmmPageTableMngr::~GmmPageTableMngr() { } } -GmmPageTableMngr::GmmPageTableMngr(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) { - clientContext = platform()->peekGmmClientContext()->getHandle(); - pageTableManager = clientContext->CreatePageTblMgrObject(translationTableCb, translationTableFlags); +bool GmmPageTableMngr::updateAuxTable(uint64_t gpuVa, Gmm *gmm, bool map) { + GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; + ddiUpdateAuxTable.BaseGpuVA = gpuVa; + ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); + ddiUpdateAuxTable.DoNotWait = true; + ddiUpdateAuxTable.Map = map ? 1u : 0u; + + return updateAuxTable(&ddiUpdateAuxTable) == GMM_STATUS::GMM_SUCCESS; +} + +void GmmPageTableMngr::initPageTableManagerRegisters() { + if (!initialized) { + initContextAuxTableRegister(this, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS); + + initialized = true; + } } } // namespace NEO diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index b246652bd6..f52422a4a2 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -7,6 +7,8 @@ #include "runtime/memory_manager/memory_manager.h" +#include "core/execution_environment/root_device_environment.h" +#include "core/gmm_helper/gmm_helper.h" #include "core/helpers/aligned_memory.h" #include "core/helpers/basic_math.h" #include "core/helpers/hw_helper.h" @@ -19,6 +21,7 @@ #include "runtime/event/hw_timestamps.h" #include "runtime/event/perf_counter.h" #include "runtime/gmm_helper/gmm.h" +#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/gmm_helper/resource_info.h" #include "runtime/helpers/hardware_commands_helper.h" #include "runtime/mem_obj/image.h" @@ -328,6 +331,14 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A return allocation; } +bool MemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { + auto index = graphicsAllocation->getRootDeviceIndex(); + if (executionEnvironment.rootDeviceEnvironments[index]->pageTableManager.get()) { + return executionEnvironment.rootDeviceEnvironments[index]->pageTableManager->updateAuxTable(graphicsAllocation->getGpuAddress(), graphicsAllocation->getDefaultGmm(), true); + } + return false; +} + GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &allocationData) { if (allocationData.type == GraphicsAllocation::AllocationType::IMAGE || allocationData.type == GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY) { UNRECOVERABLE_IF(allocationData.imgInfo == nullptr); diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 04eac5948d..8a6e4acc69 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -75,7 +75,7 @@ class MemoryManager { virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) = 0; - virtual bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { return false; } + virtual bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation); void *lockResource(GraphicsAllocation *graphicsAllocation); void unlockResource(GraphicsAllocation *graphicsAllocation); diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index c45535b084..673b12433a 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -45,6 +45,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.h + ${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux.h ) diff --git a/runtime/os_interface/linux/drm_command_stream.h b/runtime/os_interface/linux/drm_command_stream.h index 197f535702..d1ded776c3 100644 --- a/runtime/os_interface/linux/drm_command_stream.h +++ b/runtime/os_interface/linux/drm_command_stream.h @@ -43,6 +43,7 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { bool waitForFlushStamp(FlushStamp &flushStampToWait) override; DrmMemoryManager *getMemoryManager() const; + GmmPageTableMngr *createPageTableManager() override; gemCloseWorkerMode peekGemCloseWorkerOperationMode() const { return this->gemCloseWorkerOperationMode; diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 69d6c712a9..4d9a5ef37f 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -6,9 +6,11 @@ */ #include "core/command_stream/linear_stream.h" +#include "core/gmm_helper/gmm_helper.h" #include "core/helpers/aligned_memory.h" #include "core/helpers/preamble.h" #include "runtime/execution_environment/execution_environment.h" +#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/helpers/flush_stamp.h" #include "runtime/mem_obj/buffer.h" #include "runtime/os_interface/linux/drm_allocation.h" @@ -146,6 +148,14 @@ DrmMemoryManager *DrmCommandStreamReceiver::getMemoryManager() const return static_cast(CommandStreamReceiver::getMemoryManager()); } +template +GmmPageTableMngr *DrmCommandStreamReceiver::createPageTableManager() { + GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(TT_TYPE::AUXTT, nullptr); + gmmPageTableMngr->setCsrHandle(this); + this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->pageTableManager.reset(gmmPageTableMngr); + return gmmPageTableMngr; +} + template bool DrmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStamp) { drm_i915_gem_wait wait = {}; diff --git a/runtime/os_interface/linux/page_table_manager_functions.cpp b/runtime/os_interface/linux/page_table_manager_functions.cpp new file mode 100644 index 0000000000..446b34828b --- /dev/null +++ b/runtime/os_interface/linux/page_table_manager_functions.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/gmm_helper/gmm_helper.h" +#include "runtime/gmm_helper/page_table_mngr.h" +#include "runtime/platform/platform.h" + +#include "gmm_client_context.h" + +namespace NEO { +GmmPageTableMngr::GmmPageTableMngr(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) { + clientContext = platform()->peekGmmClientContext()->getHandle(); + pageTableManager = clientContext->CreatePageTblMgrObject(translationTableFlags); +} + +void GmmPageTableMngr::setCsrHandle(void *csrHandle) {} +} // namespace NEO diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index 591a422584..ecb00de0b5 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -31,6 +31,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_win.h ${CMAKE_CURRENT_SOURCE_DIR}/os_time_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_time_win.h + ${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_win.h ${CMAKE_CURRENT_SOURCE_DIR}/thk_wrapper.h diff --git a/runtime/os_interface/windows/device_factory_win.cpp b/runtime/os_interface/windows/device_factory_win.cpp index fac0727613..0e14362804 100644 --- a/runtime/os_interface/windows/device_factory_win.cpp +++ b/runtime/os_interface/windows/device_factory_win.cpp @@ -31,7 +31,7 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi executionEnvironment.prepareRootDeviceEnvironments(static_cast(numRootDevices)); auto hardwareInfo = executionEnvironment.getMutableHardwareInfo(); - std::unique_ptr wddm(Wddm::createWddm()); + std::unique_ptr wddm(Wddm::createWddm(*executionEnvironment.rootDeviceEnvironments[0].get())); if (!wddm->init(*hardwareInfo)) { return false; } diff --git a/runtime/os_interface/windows/page_table_manager_functions.cpp b/runtime/os_interface/windows/page_table_manager_functions.cpp new file mode 100644 index 0000000000..5ecde957c6 --- /dev/null +++ b/runtime/os_interface/windows/page_table_manager_functions.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/gmm_helper/gmm_helper.h" +#include "runtime/gmm_helper/page_table_mngr.h" +#include "runtime/platform/platform.h" + +#include "gmm_client_context.h" + +namespace NEO { +GmmPageTableMngr::GmmPageTableMngr(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) { + clientContext = platform()->peekGmmClientContext()->getHandle(); + pageTableManager = clientContext->CreatePageTblMgrObject(translationTableCb, translationTableFlags); +} + +void GmmPageTableMngr::setCsrHandle(void *csrHandle) { + pageTableManager->GmmSetCsrHandle(csrHandle); +} +} // namespace NEO diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 00695b0b03..134229cd2e 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -8,6 +8,7 @@ #include "runtime/os_interface/windows/wddm/wddm.h" #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "core/gmm_helper/gmm_helper.h" #include "core/helpers/interlocked_max.h" #include "core/os_interface/windows/debug_registry_reader.h" @@ -60,15 +61,14 @@ Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo(); Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc(); Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree(); -Wddm::Wddm() { +Wddm::Wddm(RootDeviceEnvironment &rootDeviceEnvironment) : rootDeviceEnvironment(rootDeviceEnvironment) { featureTable.reset(new FeatureTable()); workaroundTable.reset(new WorkaroundTable()); gtSystemInfo.reset(new GT_SYSTEM_INFO); gfxPlatform.reset(new PLATFORM); memset(gtSystemInfo.get(), 0, sizeof(*gtSystemInfo)); memset(gfxPlatform.get(), 0, sizeof(*gfxPlatform)); - - registryReader.reset(new RegistryReader(false, "System\\CurrentControlSet\\Control\\GraphicsDrivers\\Scheduler")); + this->registryReader.reset(new RegistryReader(false, "System\\CurrentControlSet\\Control\\GraphicsDrivers\\Scheduler")); adapterLuid.HighPart = 0; adapterLuid.LowPart = 0; kmDafListener = std::unique_ptr(new KmDafListener); @@ -78,7 +78,6 @@ Wddm::Wddm() { Wddm::~Wddm() { temporaryResources.reset(); - resetPageTableManager(nullptr); destroyPagingQueue(); destroyDevice(); closeAdapter(); @@ -398,8 +397,8 @@ bool Wddm::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_A kmDafListener->notifyMapGpuVA(featureTable->ftrKmdDaf, adapter, device, handle, MapGPUVA.VirtualAddress, gdi->escape); - if (gmm->isRenderCompressed && pageTableManager.get()) { - return updateAuxTable(gpuPtr, gmm, true); + if (gmm->isRenderCompressed && rootDeviceEnvironment.pageTableManager.get()) { + return rootDeviceEnvironment.pageTableManager->updateAuxTable(gpuPtr, gmm, true); } return true; @@ -906,19 +905,6 @@ void Wddm::releaseReservedAddress(void *reservedAddress) { } } -bool Wddm::updateAuxTable(D3DGPU_VIRTUAL_ADDRESS gpuVa, Gmm *gmm, bool map) { - GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; - ddiUpdateAuxTable.BaseGpuVA = gpuVa; - ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); - ddiUpdateAuxTable.DoNotWait = true; - ddiUpdateAuxTable.Map = map ? 1u : 0u; - return pageTableManager->updateAuxTable(&ddiUpdateAuxTable) == GMM_STATUS::GMM_SUCCESS; -} - -void Wddm::resetPageTableManager(GmmPageTableMngr *newPageTableManager) { - pageTableManager.reset(newPageTableManager); -} - bool Wddm::reserveValidAddressRange(size_t size, void *&reservedMem) { reservedMem = virtualAlloc(nullptr, size, MEM_RESERVE, PAGE_READWRITE); if (reservedMem == nullptr) { diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index fb9f58a020..fe228cc4fa 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -22,7 +22,6 @@ namespace NEO { class Gdi; class Gmm; class GmmMemory; -class GmmPageTableMngr; class OsContextWin; class SettingsReader; class WddmAllocation; @@ -33,6 +32,7 @@ class WddmResidentAllocationsContainer; struct AllocationStorageData; struct HardwareInfo; struct KmDafListener; +struct RootDeviceEnvironment; struct MonitoredFence; struct OsHandleStorage; @@ -58,7 +58,7 @@ class Wddm { virtual ~Wddm(); - static Wddm *createWddm(); + static Wddm *createWddm(RootDeviceEnvironment &rootDeviceEnvironment); bool init(HardwareInfo &outHardwareInfo); MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim); @@ -131,10 +131,6 @@ class Wddm { std::unique_ptr registryReader; - GmmPageTableMngr *getPageTableManager() const { return pageTableManager.get(); } - void resetPageTableManager(GmmPageTableMngr *newPageTableManager); - bool updateAuxTable(D3DGPU_VIRTUAL_ADDRESS gpuVa, Gmm *gmm, bool map); - uintptr_t getWddmMinAddress() const { return this->minAddress; } @@ -181,6 +177,7 @@ class Wddm { uint32_t maxRenderFrequency = 0; bool instrumentationEnabled = false; std::string deviceRegistryPath; + RootDeviceEnvironment &rootDeviceEnvironment; unsigned long hwContextId = 0; LUID adapterLuid; @@ -188,7 +185,7 @@ class Wddm { std::unique_ptr gmmMemory; uintptr_t minAddress = 0; - Wddm(); + Wddm(RootDeviceEnvironment &rootDeviceEnvironment); MOCKABLE_VIRTUAL bool openAdapter(); MOCKABLE_VIRTUAL bool waitOnGPU(D3DKMT_HANDLE context); bool createDevice(PreemptionMode preemptionMode); @@ -205,8 +202,6 @@ class Wddm { static VirtualFreeFcn virtualFreeFnc; static VirtualAllocFcn virtualAllocFnc; - std::unique_ptr pageTableManager; - std::unique_ptr kmDafListener; std::unique_ptr wddmInterface; std::unique_ptr temporaryResources; diff --git a/runtime/os_interface/windows/wddm/wddm_create.cpp b/runtime/os_interface/windows/wddm/wddm_create.cpp index cf3485650c..05011090fe 100644 --- a/runtime/os_interface/windows/wddm/wddm_create.cpp +++ b/runtime/os_interface/windows/wddm/wddm_create.cpp @@ -8,7 +8,7 @@ #include "runtime/os_interface/windows/wddm/wddm.h" namespace NEO { -Wddm *Wddm::createWddm() { - return new Wddm(); +Wddm *Wddm::createWddm(RootDeviceEnvironment &rootDeviceEnvironment) { + return new Wddm(rootDeviceEnvironment); } } // namespace NEO diff --git a/runtime/os_interface/windows/wddm_device_command_stream.h b/runtime/os_interface/windows/wddm_device_command_stream.h index 9d0a1682ba..38f30eaa79 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.h +++ b/runtime/os_interface/windows/wddm_device_command_stream.h @@ -36,11 +36,9 @@ class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver GmmPageTableMngr *createPageTableManager() override; protected: - void initPageTableManagerRegisters(LinearStream &csr) override; void kmDafLockAllocations(ResidencyContainer &allocationsForResidency); Wddm *wddm; COMMAND_BUFFER_HEADER_REC *commandBufferHeader; - bool pageTableManagerInitialized = false; }; } // namespace NEO diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index c7d1a3e08a..409d867e5e 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -134,22 +134,12 @@ GmmPageTableMngr *WddmCommandStreamReceiver::createPageTableManager() GMM_TRANSLATIONTABLE_CALLBACKS ttCallbacks = {}; ttCallbacks.pfWriteL3Adr = TTCallbacks::writeL3Address; - GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(TT_TYPE::TRTT | TT_TYPE::AUXTT, &ttCallbacks); + GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(TT_TYPE::AUXTT, &ttCallbacks); gmmPageTableMngr->setCsrHandle(this); - this->wddm->resetPageTableManager(gmmPageTableMngr); + this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->pageTableManager.reset(gmmPageTableMngr); return gmmPageTableMngr; } -template -void WddmCommandStreamReceiver::initPageTableManagerRegisters(LinearStream &csr) { - if (wddm->getPageTableManager() && !pageTableManagerInitialized) { - wddm->getPageTableManager()->initContextTRTableRegister(this, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS); - wddm->getPageTableManager()->initContextAuxTableRegister(this, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS); - - pageTableManagerInitialized = true; - } -} - template void WddmCommandStreamReceiver::kmDafLockAllocations(ResidencyContainer &allocationsForResidency) { for (auto &graphicsAllocation : allocationsForResidency) { diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index ff579f7392..ef71e750f0 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -7,6 +7,7 @@ #include "runtime/os_interface/windows/wddm_memory_manager.h" +#include "core/execution_environment/root_device_environment.h" #include "core/gmm_helper/gmm_helper.h" #include "core/helpers/aligned_memory.h" #include "core/helpers/deferred_deleter_helper.h" @@ -17,6 +18,7 @@ #include "runtime/device/device.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/gmm_helper/gmm.h" +#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/gmm_helper/resource_info.h" #include "runtime/helpers/surface_formats.h" #include "runtime/memory_manager/deferrable_deletion.h" @@ -333,8 +335,9 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation auto defaultGmm = gfxAllocation->getDefaultGmm(); if (defaultGmm) { - if (defaultGmm->isRenderCompressed && wddm->getPageTableManager()) { - auto status = wddm->updateAuxTable(input->getGpuAddress(), defaultGmm, false); + auto index = gfxAllocation->getRootDeviceIndex(); + if (defaultGmm->isRenderCompressed && executionEnvironment.rootDeviceEnvironments[index]->pageTableManager.get()) { + auto status = executionEnvironment.rootDeviceEnvironments[index]->pageTableManager->updateAuxTable(input->getGpuAddress(), defaultGmm, false); DEBUG_BREAK_IF(!status); } } @@ -493,10 +496,6 @@ uint64_t WddmMemoryManager::getSystemSharedMemory() { return wddm->getSystemSharedMemory(); } -bool WddmMemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { - return wddm->updateAuxTable(graphicsAllocation->getGpuAddress(), graphicsAllocation->getDefaultGmm(), true); -} - AlignedMallocRestrictions *WddmMemoryManager::getAlignedMallocRestrictions() { return &mallocRestrictions; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index e45140cd37..a016ba41f4 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -54,8 +54,6 @@ class WddmMemoryManager : public MemoryManager { bool isMemoryBudgetExhausted() const override; - bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) override; - AlignedMallocRestrictions *getAlignedMallocRestrictions() override; bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override; diff --git a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp index 0059c693bd..aea0530203 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -24,7 +24,7 @@ struct CreateCommandStreamReceiverTest : public ::testing::TestWithParamrootDeviceEnvironments[0]); CommandStreamReceiverType csrType = GetParam(); diff --git a/unit_tests/device/device_win_timers_tests.cpp b/unit_tests/device/device_win_timers_tests.cpp index 933339c524..22ab0e44d1 100644 --- a/unit_tests/device/device_win_timers_tests.cpp +++ b/unit_tests/device/device_win_timers_tests.cpp @@ -5,8 +5,10 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_ostime.h" #include "unit_tests/mocks/mock_ostime_win.h" #include "unit_tests/mocks/mock_wddm.h" @@ -20,7 +22,9 @@ namespace ULT { typedef ::testing::Test MockOSTimeWinTest; TEST_F(MockOSTimeWinTest, DynamicResolution) { - auto wddmMock = std::unique_ptr(new WddmMock()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddmMock = std::unique_ptr(new WddmMock(rootDeviceEnvironment)); auto mDev = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); auto hwInfo = mDev->getHardwareInfo(); diff --git a/unit_tests/fixtures/buffer_enqueue_fixture.h b/unit_tests/fixtures/buffer_enqueue_fixture.h index 794f9f5d01..1f37067930 100644 --- a/unit_tests/fixtures/buffer_enqueue_fixture.h +++ b/unit_tests/fixtures/buffer_enqueue_fixture.h @@ -26,7 +26,7 @@ struct BufferEnqueueFixture : public HardwareParse, } void SetUp() override { - executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); } void TearDown() override { diff --git a/unit_tests/fixtures/device_instrumentation_fixture.cpp b/unit_tests/fixtures/device_instrumentation_fixture.cpp index 293b551f69..786421f127 100644 --- a/unit_tests/fixtures/device_instrumentation_fixture.cpp +++ b/unit_tests/fixtures/device_instrumentation_fixture.cpp @@ -12,7 +12,7 @@ namespace NEO { void DeviceInstrumentationFixture::SetUp(bool instrumentation) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.instrumentationEnabled = instrumentation; device = std::unique_ptr(Device::create(executionEnvironment, 0)); } diff --git a/unit_tests/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp b/unit_tests/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp index 33a7d33b20..544fbafe81 100644 --- a/unit_tests/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp +++ b/unit_tests/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp @@ -31,7 +31,7 @@ struct MockAubCsrToTestNotifyAubCapture : public AUBCommandStreamReceiverHwinitializeMemoryManager(); auto csr = std::make_unique>(*executionEnvironment, 0); uint64_t address = 0xFEDCBA9876543210; diff --git a/unit_tests/helpers/execution_environment_helper.cpp b/unit_tests/helpers/execution_environment_helper.cpp index 78e12fa2e8..281023f2a6 100644 --- a/unit_tests/helpers/execution_environment_helper.cpp +++ b/unit_tests/helpers/execution_environment_helper.cpp @@ -12,8 +12,9 @@ namespace NEO { -ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo) { +ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo, uint32_t rootDeviceEnvironments) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(rootDeviceEnvironments); size_t numDevicesReturned = 0; hwInfo = nullptr; DeviceFactory::getDevices(numDevicesReturned, *executionEnvironment); diff --git a/unit_tests/helpers/execution_environment_helper.h b/unit_tests/helpers/execution_environment_helper.h index 58ac7d97a6..bb32b8e15b 100644 --- a/unit_tests/helpers/execution_environment_helper.h +++ b/unit_tests/helpers/execution_environment_helper.h @@ -13,5 +13,5 @@ #include namespace NEO { -ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo); +ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo, uint32_t rootDeviceEnvironments); } // namespace NEO diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index ffaa5133d2..ee665dc018 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -7,9 +7,11 @@ #include "core/command_stream/preemption.h" #include "core/helpers/cache_policy.h" +#include "core/memory_manager/graphics_allocation.h" #include "core/memory_manager/memory_constants.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "runtime/event/event.h" +#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/helpers/dispatch_info.h" #include "runtime/helpers/hardware_commands_helper.h" #include "runtime/mem_obj/image.h" @@ -2017,3 +2019,19 @@ HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenHostPtrTrackingEnabledThenNo result = memoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::MAP_ALLOCATION); EXPECT_EQ(!executionEnvironment->isFullRangeSvm(), result); } + +using PageTableManagerTest = ::testing::Test; + +HWTEST_F(PageTableManagerTest, givenMemoryManagerThatSupportsPageTableManagerWhenMapAuxGpuVAIsCalledThenItReturnsTrue) { + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(2); + auto memoryManager = new MockMemoryManager(false, false, *executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); + MockGraphicsAllocation allocation(1u, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull); + MockGmm gmm; + allocation.setDefaultGmm(&gmm); + bool mapped = memoryManager->mapAuxGpuVA(&allocation); + auto hwInfo = executionEnvironment->getHardwareInfo(); + + EXPECT_EQ(HwHelper::get(hwInfo->platform.eRenderCoreFamily).isPageTableManagerSupported(*hwInfo), mapped); +} diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 0a5e8d7a12..5c69a81624 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -43,6 +43,8 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_graphics_allocation.h @@ -72,6 +74,7 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_csr.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_timestamp_container.h + ${NEO_SOURCE_DIR}/runtime/gmm_helper/page_table_mngr_impl.cpp ) if(WIN32) @@ -82,8 +85,6 @@ if(WIN32) ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_memory_base.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_memory_base.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory${BRANCH_DIR_SUFFIX}/mock_gmm_memory.h - ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.h - ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_page_table_mngr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm_interface20.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm_interface23.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm.h @@ -97,6 +98,7 @@ else() ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_command_stream_receiver.h + ${NEO_SOURCE_DIR}/runtime/os_interface/linux/page_table_manager_functions.cpp ) endif() diff --git a/unit_tests/mocks/mock_gmm_page_table_mngr.cpp b/unit_tests/mocks/mock_gmm_page_table_mngr.cpp index 40835ba63d..136a7d37b0 100644 --- a/unit_tests/mocks/mock_gmm_page_table_mngr.cpp +++ b/unit_tests/mocks/mock_gmm_page_table_mngr.cpp @@ -13,7 +13,6 @@ using namespace ::testing; GmmPageTableMngr *GmmPageTableMngr::create(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) { auto pageTableMngr = new ::testing::NiceMock(translationTableFlags, translationTableCb); ON_CALL(*pageTableMngr, initContextAuxTableRegister(_, _)).WillByDefault(Return(GMM_SUCCESS)); - ON_CALL(*pageTableMngr, initContextTRTableRegister(_, _)).WillByDefault(Return(GMM_SUCCESS)); ON_CALL(*pageTableMngr, updateAuxTable(_)).WillByDefault(Return(GMM_SUCCESS)); return pageTableMngr; } diff --git a/unit_tests/mocks/mock_gmm_page_table_mngr.h b/unit_tests/mocks/mock_gmm_page_table_mngr.h index bba0bf66d7..45d44658de 100644 --- a/unit_tests/mocks/mock_gmm_page_table_mngr.h +++ b/unit_tests/mocks/mock_gmm_page_table_mngr.h @@ -11,18 +11,25 @@ #include "gmock/gmock.h" +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif + namespace NEO { class MockGmmPageTableMngr : public GmmPageTableMngr { public: MockGmmPageTableMngr() = default; MockGmmPageTableMngr(unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) - : translationTableFlags(translationTableFlags), translationTableCb(*translationTableCb){}; + : translationTableFlags(translationTableFlags) { + if (translationTableCb) { + this->translationTableCb = *translationTableCb; + } + }; MOCK_METHOD2(initContextAuxTableRegister, GMM_STATUS(HANDLE initialBBHandle, GMM_ENGINE_TYPE engineType)); - MOCK_METHOD2(initContextTRTableRegister, GMM_STATUS(HANDLE initialBBHandle, GMM_ENGINE_TYPE engineType)); - MOCK_METHOD1(updateAuxTable, GMM_STATUS(const GMM_DDI_UPDATEAUXTABLE *ddiUpdateAuxTable)); void setCsrHandle(void *csrHandle) override; @@ -30,8 +37,12 @@ class MockGmmPageTableMngr : public GmmPageTableMngr { uint32_t setCsrHanleCalled = 0; void *passedCsrHandle = nullptr; - GMM_TRANSLATIONTABLE_CALLBACKS translationTableCb = {}; unsigned int translationTableFlags = 0; + GMM_TRANSLATIONTABLE_CALLBACKS translationTableCb = {}; }; } // namespace NEO + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/unit_tests/mocks/mock_wddm.cpp b/unit_tests/mocks/mock_wddm.cpp index 2924ee07f4..bc79e151a3 100644 --- a/unit_tests/mocks/mock_wddm.cpp +++ b/unit_tests/mocks/mock_wddm.cpp @@ -7,6 +7,7 @@ #include "unit_tests/mocks/mock_wddm.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/aligned_memory.h" #include "runtime/os_interface/windows/gdi_interface.h" #include "runtime/os_interface/windows/wddm_allocation.h" @@ -17,7 +18,7 @@ using namespace NEO; -WddmMock::WddmMock() : Wddm() { +WddmMock::WddmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) { this->temporaryResources = std::make_unique(this); } @@ -273,3 +274,7 @@ void *GmockWddm::virtualAllocWrapper(void *inPtr, size_t size, uint32_t flags, u virtualAllocAddress += size; return tmp; } + +GmockWddm::GmockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment) { + virtualAllocAddress = NEO::windowsMinAddress; +} diff --git a/unit_tests/mocks/mock_wddm.h b/unit_tests/mocks/mock_wddm.h index eb1138828c..8c941f388d 100644 --- a/unit_tests/mocks/mock_wddm.h +++ b/unit_tests/mocks/mock_wddm.h @@ -41,7 +41,7 @@ class WddmMock : public Wddm { using Wddm::temporaryResources; using Wddm::wddmInterface; - WddmMock(); + WddmMock(RootDeviceEnvironment &rootDeviceEnvironment); ~WddmMock(); bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override; @@ -115,8 +115,8 @@ class WddmMock : public Wddm { WddmMockHelpers::CallResult getPagingFenceAddressResult; WddmMockHelpers::CallResult reserveGpuVirtualAddressResult; - NTSTATUS createAllocationStatus; - bool mapGpuVaStatus; + NTSTATUS createAllocationStatus = STATUS_SUCCESS; + bool mapGpuVaStatus = true; bool callBaseDestroyAllocations = true; bool failOpenSharedHandle = false; bool callBaseMapGpuVa = true; @@ -127,9 +127,7 @@ class WddmMock : public Wddm { }; struct GmockWddm : WddmMock { - GmockWddm() { - virtualAllocAddress = NEO::windowsMinAddress; - } + GmockWddm(RootDeviceEnvironment &rootDeviceEnvironment); ~GmockWddm() = default; bool virtualFreeWrapper(void *ptr, size_t size, uint32_t flags) { return true; diff --git a/unit_tests/os_interface/linux/device_command_stream_tests.cpp b/unit_tests/os_interface/linux/device_command_stream_tests.cpp index b97a768ce6..1127785287 100644 --- a/unit_tests/os_interface/linux/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/device_command_stream_tests.cpp @@ -27,7 +27,7 @@ using namespace NEO; struct DeviceCommandStreamLeaksTest : ::testing::Test { void SetUp() override { HardwareInfo *hwInfo = nullptr; - executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); } diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index e338c3caea..65f84d9ac9 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -6,7 +6,11 @@ */ #include "core/command_stream/preemption.h" +#include "core/gmm_helper/gmm_helper.h" +#include "core/memory_manager/graphics_allocation.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" +#include "runtime/gmm_helper/page_table_mngr.h" +#include "runtime/gmm_helper/resource_info.h" #include "runtime/helpers/flush_stamp.h" #include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/mem_obj/buffer.h" @@ -22,6 +26,8 @@ #include "unit_tests/helpers/execution_environment_helper.h" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/mocks/linux/mock_drm_command_stream_receiver.h" +#include "unit_tests/mocks/mock_gmm.h" +#include "unit_tests/mocks/mock_gmm_page_table_mngr.h" #include "unit_tests/mocks/mock_host_ptr_manager.h" #include "unit_tests/mocks/mock_program.h" #include "unit_tests/mocks/mock_submissions_aggregator.h" @@ -1370,3 +1376,66 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocationWithSingleBuffer mm->freeGraphicsMemory(allocation); } + +template +struct MockDrmCsr : public DrmCommandStreamReceiver { + using DrmCommandStreamReceiver::DrmCommandStreamReceiver; +}; + +HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenDrmCommandStreamReceiverWhenCreatePageTableMngrIsCalledThenCreatePageTableManager) { + executionEnvironment.prepareRootDeviceEnvironments(2); + auto csr = std::make_unique>(executionEnvironment, 1, gemCloseWorkerMode::gemCloseWorkerActive); + auto pageTableManager = csr->createPageTableManager(); + EXPECT_EQ(executionEnvironment.rootDeviceEnvironments[1]->pageTableManager.get(), pageTableManager); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenDrmCommandStreamReceiverWhenInitializePageTableMngrRegistersIsCalledThenInitializePageTableManager) { + executionEnvironment.prepareRootDeviceEnvironments(2); + auto csr = std::make_unique>(executionEnvironment, 1, gemCloseWorkerMode::gemCloseWorkerActive); + csr->createPageTableManager(); + auto &rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[1]; + + MockGmmPageTableMngr *mockMngr = static_cast(rootDeviceEnvironment->pageTableManager.get()); + EXPECT_CALL(*mockMngr, initContextAuxTableRegister(::testing::_, ::testing::_)).Times(1); + + EXPECT_FALSE(rootDeviceEnvironment->pageTableManager->initialized); + LinearStream linearStream = {}; + rootDeviceEnvironment->pageTableManager->initPageTableManagerRegisters(); + EXPECT_TRUE(rootDeviceEnvironment->pageTableManager->initialized); + + rootDeviceEnvironment->pageTableManager->initPageTableManagerRegisters(); + EXPECT_TRUE(rootDeviceEnvironment->pageTableManager->initialized); + + rootDeviceEnvironment->pageTableManager.reset(nullptr); + EXPECT_EQ(rootDeviceEnvironment->pageTableManager, nullptr); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenPageTableManagerAndMapTrueWhenUpdateAuxTableIsCalledThenItReturnsTrue) { + auto mockMngr = new MockGmmPageTableMngr(); + executionEnvironment.rootDeviceEnvironments[0]->pageTableManager.reset(mockMngr); + auto gmm = std::make_unique(); + GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; + EXPECT_CALL(*mockMngr, updateAuxTable(::testing::_)).Times(1).WillOnce(::testing::Invoke([&](const GMM_DDI_UPDATEAUXTABLE *arg) {ddiUpdateAuxTable = *arg; return GMM_SUCCESS; })); + auto result = executionEnvironment.rootDeviceEnvironments[0]->pageTableManager->updateAuxTable(0, gmm.get(), true); + EXPECT_EQ(ddiUpdateAuxTable.BaseGpuVA, 0ull); + EXPECT_EQ(ddiUpdateAuxTable.BaseResInfo, gmm->gmmResourceInfo->peekHandle()); + EXPECT_EQ(ddiUpdateAuxTable.DoNotWait, true); + EXPECT_EQ(ddiUpdateAuxTable.Map, 1u); + + EXPECT_TRUE(result); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenPageTableManagerAndMapFalseWhenUpdateAuxTableIsCalledThenItReturnsTrue) { + auto mockMngr = new MockGmmPageTableMngr(); + executionEnvironment.rootDeviceEnvironments[0]->pageTableManager.reset(mockMngr); + auto gmm = std::make_unique(); + GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; + EXPECT_CALL(*mockMngr, updateAuxTable(::testing::_)).Times(1).WillOnce(::testing::Invoke([&](const GMM_DDI_UPDATEAUXTABLE *arg) {ddiUpdateAuxTable = *arg; return GMM_SUCCESS; })); + auto result = executionEnvironment.rootDeviceEnvironments[0]->pageTableManager->updateAuxTable(0, gmm.get(), false); + EXPECT_EQ(ddiUpdateAuxTable.BaseGpuVA, 0ull); + EXPECT_EQ(ddiUpdateAuxTable.BaseResInfo, gmm->gmmResourceInfo->peekHandle()); + EXPECT_EQ(ddiUpdateAuxTable.DoNotWait, true); + EXPECT_EQ(ddiUpdateAuxTable.Map, 0u); + + EXPECT_TRUE(result); +} diff --git a/unit_tests/os_interface/mock_performance_counters.cpp b/unit_tests/os_interface/mock_performance_counters.cpp index f9798db49f..d2c06d1a9e 100644 --- a/unit_tests/os_interface/mock_performance_counters.cpp +++ b/unit_tests/os_interface/mock_performance_counters.cpp @@ -7,6 +7,9 @@ #include "mock_performance_counters.h" +#include "core/execution_environment/root_device_environment.h" +#include "runtime/os_interface/os_interface.h" +#include "unit_tests/mocks/mock_execution_environment.h" using namespace MetricsLibraryApi; namespace NEO { @@ -340,6 +343,20 @@ void PerformanceCountersMetricsLibraryFixture::TearDown() { PerformanceCountersFixture::TearDown(); } +////////////////////////////////////////////////////// +// PerformanceCountersFixture::PerformanceCountersFixture +////////////////////////////////////////////////////// +PerformanceCountersFixture::PerformanceCountersFixture() { + executionEnvironment = std::make_unique(); + rootDeviceEnvironment = std::make_unique(*executionEnvironment); +} + +////////////////////////////////////////////////////// +// PerformanceCountersFixture::~PerformanceCountersFixture +////////////////////////////////////////////////////// +PerformanceCountersFixture::~PerformanceCountersFixture() { +} + ////////////////////////////////////////////////////// // PerformanceCountersMetricsLibraryFixture::createPerformanceCounters ////////////////////////////////////////////////////// diff --git a/unit_tests/os_interface/mock_performance_counters.h b/unit_tests/os_interface/mock_performance_counters.h index fc207f7d80..e781171a98 100644 --- a/unit_tests/os_interface/mock_performance_counters.h +++ b/unit_tests/os_interface/mock_performance_counters.h @@ -215,10 +215,14 @@ struct PerformanceCountersDeviceFixture { decltype(&PerformanceCounters::create) createFunc; }; +struct MockExecutionEnvironment; +struct RootDeviceEnvironment; ///////////////////////////////////////////////////// // PerformanceCountersFixture ////////////////////////////////////////////////////// struct PerformanceCountersFixture { + PerformanceCountersFixture(); + ~PerformanceCountersFixture(); virtual void SetUp(); virtual void TearDown(); virtual void createPerfCounters(); @@ -228,6 +232,8 @@ struct PerformanceCountersFixture { std::unique_ptr queue; std::unique_ptr osInterface; std::unique_ptr performanceCountersBase; + std::unique_ptr executionEnvironment; + std::unique_ptr rootDeviceEnvironment; }; ////////////////////////////////////////////////////// diff --git a/unit_tests/os_interface/performance_counters_tests.cpp b/unit_tests/os_interface/performance_counters_tests.cpp index f6a409d55b..f84230525f 100644 --- a/unit_tests/os_interface/performance_counters_tests.cpp +++ b/unit_tests/os_interface/performance_counters_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/options.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "runtime/os_interface/os_interface.h" @@ -12,6 +13,7 @@ #include "runtime/utilities/tag_allocator.h" #include "unit_tests/fixtures/device_instrumentation_fixture.h" #include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/os_interface/mock_performance_counters.h" #include "gtest/gtest.h" diff --git a/unit_tests/os_interface/windows/deferrable_deletion_win_tests.cpp b/unit_tests/os_interface/windows/deferrable_deletion_win_tests.cpp index e8756f026e..21db2a66fd 100644 --- a/unit_tests/os_interface/windows/deferrable_deletion_win_tests.cpp +++ b/unit_tests/os_interface/windows/deferrable_deletion_win_tests.cpp @@ -5,7 +5,9 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "runtime/os_interface/windows/deferrable_deletion_win.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_wddm.h" #include "gtest/gtest.h" @@ -35,15 +37,22 @@ class MockDeferrableDeletion : public DeferrableDeletionImpl { class DeferrableDeletionTest : public ::testing::Test { public: - WddmMock wddm; + std::unique_ptr executionEnvironment; + std::unique_ptr wddm; const D3DKMT_HANDLE handle = 0; uint32_t allocationCount = 1; D3DKMT_HANDLE resourceHandle = 0; + + void SetUp() override { + executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + wddm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + } }; TEST_F(DeferrableDeletionTest, givenDeferrableDeletionWhenIsCreatedThenObjectMembersAreSetProperly) { - MockDeferrableDeletion deletion(&wddm, &handle, allocationCount, resourceHandle); - EXPECT_EQ(&wddm, deletion.wddm); + MockDeferrableDeletion deletion(wddm.get(), &handle, allocationCount, resourceHandle); + EXPECT_EQ(wddm.get(), deletion.wddm); EXPECT_NE(nullptr, deletion.handles); EXPECT_EQ(handle, *deletion.handles); EXPECT_NE(&handle, deletion.handles); @@ -52,9 +61,9 @@ TEST_F(DeferrableDeletionTest, givenDeferrableDeletionWhenIsCreatedThenObjectMem } TEST_F(DeferrableDeletionTest, givenDeferrableDeletionWhenApplyIsCalledThenDeletionIsApplied) { - wddm.callBaseDestroyAllocations = false; - std::unique_ptr deletion(DeferrableDeletion::create((Wddm *)&wddm, &handle, allocationCount, resourceHandle)); - EXPECT_EQ(0, wddm.destroyAllocationResult.called); + wddm->callBaseDestroyAllocations = false; + std::unique_ptr deletion(DeferrableDeletion::create((Wddm *)wddm.get(), &handle, allocationCount, resourceHandle)); + EXPECT_EQ(0, wddm->destroyAllocationResult.called); deletion->apply(); - EXPECT_EQ(1, wddm.destroyAllocationResult.called); + EXPECT_EQ(1, wddm->destroyAllocationResult.called); } 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 6296a39738..e9be4eb863 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -60,7 +60,7 @@ class WddmCommandStreamFixture { virtual void SetUp() { HardwareInfo *hwInfo = nullptr; DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); - auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); memoryManager = new MockWddmMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); @@ -82,7 +82,6 @@ struct MockWddmCsr : public WddmCommandStreamReceiver { using CommandStreamReceiver::dispatchMode; using CommandStreamReceiver::getCS; using WddmCommandStreamReceiver::commandBufferHeader; - using WddmCommandStreamReceiver::pageTableManagerInitialized; using WddmCommandStreamReceiver::WddmCommandStreamReceiver; void overrideDispatchPolicy(DispatchMode overrideValue) { @@ -117,7 +116,7 @@ class WddmCommandStreamWithMockGdiFixture { virtual void SetUp() { HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); gdi = new MockGdi(); wddm->gdi.reset(gdi); @@ -144,8 +143,8 @@ using WddmDefaultTest = ::Test; using DeviceCommandStreamTest = ::Test; TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { - auto wddm = Wddm::createWddm(); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto wddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(static_cast(wddm)); executionEnvironment->initializeMemoryManager(); @@ -156,8 +155,8 @@ TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { } TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) { - auto wddm = Wddm::createWddm(); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto wddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(static_cast(wddm)); executionEnvironment->initializeMemoryManager(); @@ -238,7 +237,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFl TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOffWhenWorkloadIsSubmittedThenHeaderDoesntHavePreemptionFieldSet) { HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; executionEnvironment->setHwInfo(hwInfo); auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); @@ -263,7 +262,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOnWhenWorkloadIsSubmittedThenHeaderDoesHavePreemptionFieldSet) { HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; executionEnvironment->setHwInfo(hwInfo); auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); @@ -289,7 +288,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderContainsPreemptionFieldSet) { HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; executionEnvironment->setHwInfo(hwInfo); auto commandStreamReceiver = std::make_unique>(*executionEnvironment, 0); @@ -300,7 +299,7 @@ TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStream TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderPreemptionFieldIsNotSet) { HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; executionEnvironment->setHwInfo(hwInfo); auto commandStreamReceiver = std::make_unique>(*executionEnvironment, 0); @@ -820,7 +819,7 @@ HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedO DebugManager.flags.CsrDispatchMode.set(0); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); std::unique_ptr device(Device::create(executionEnvironment, 0u)); - auto wddm = Wddm::createWddm(); + auto wddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); @@ -829,7 +828,7 @@ HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedO } HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVersionBasingOnFtrFlag) { - auto wddm = Wddm::createWddm(); + auto wddm = Wddm::createWddm(*pDevice->executionEnvironment->rootDeviceEnvironments[0].get()); pDevice->executionEnvironment->osInterface = std::make_unique(); pDevice->executionEnvironment->osInterface->get()->setWddm(wddm); pDevice->executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); @@ -860,22 +859,23 @@ struct WddmCsrCompressionParameterizedTest : WddmCsrCompressionTests, ::testing: }; HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenInitializedThenCreatePagetableMngr) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - std::unique_ptr device(Device::create(executionEnvironment, 0u)); + uint32_t index = 1u; + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); + std::unique_ptr device(Device::create(executionEnvironment, 1u)); setCompressionEnabled(compressionEnabled, !compressionEnabled); myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); + EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[index]->pageTableManager.get()); - MockWddmCsr mockWddmCsr(*executionEnvironment, 0); + MockWddmCsr mockWddmCsr(*executionEnvironment, index); mockWddmCsr.createPageTableManager(); - ASSERT_NE(nullptr, myMockWddm->getPageTableManager()); + ASSERT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[index]->pageTableManager.get()); - auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); + auto mockMngr = reinterpret_cast(executionEnvironment->rootDeviceEnvironments[index]->pageTableManager.get()); EXPECT_EQ(1u, mockMngr->setCsrHanleCalled); EXPECT_EQ(&mockWddmCsr, mockMngr->passedCsrHandle); GMM_TRANSLATIONTABLE_CALLBACKS expectedTTCallbacks = {}; - unsigned int expectedFlags = (TT_TYPE::TRTT | TT_TYPE::AUXTT); + unsigned int expectedFlags = TT_TYPE::AUXTT; expectedTTCallbacks.pfWriteL3Adr = TTCallbacks::writeL3Address; @@ -884,25 +884,24 @@ HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenInitial } HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDontCreatePagetableMngr) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - std::unique_ptr device(Device::create(executionEnvironment, 0u)); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); + std::unique_ptr device(Device::create(executionEnvironment, 1u)); setCompressionEnabled(false, false); myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - MockWddmCsr mockWddmCsr(*executionEnvironment, 0); - EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); + MockWddmCsr mockWddmCsr(*executionEnvironment, 1); + EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.get()); } HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); setCompressionEnabled(compressionEnabled, !compressionEnabled); myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - auto mockWddmCsr = new MockWddmCsr(*executionEnvironment, 0); + auto mockWddmCsr = new MockWddmCsr(*executionEnvironment, 1); mockWddmCsr->createPageTableManager(); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); executionEnvironment->memoryManager.reset(new WddmMemoryManager(*executionEnvironment)); - auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); - std::unique_ptr device(Device::create(executionEnvironment, 0u)); + std::unique_ptr device(Device::create(executionEnvironment, 1u)); device->resetCommandStreamReceiver(mockWddmCsr); auto memoryManager = executionEnvironment->memoryManager.get(); @@ -912,20 +911,13 @@ HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenFlushin auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap cs(graphicsAllocation); - EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); - - EXPECT_CALL(*mockMngr, initContextAuxTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)) - .Times(1) - .WillOnce(Return(GMM_SUCCESS)); - EXPECT_CALL(*mockMngr, initContextTRTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)) - .Times(1) - .WillOnce(Return(GMM_SUCCESS)); + EXPECT_FALSE(executionEnvironment->rootDeviceEnvironments[1]->pageTableManager->initialized); DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); - EXPECT_TRUE(mockWddmCsr->pageTableManagerInitialized); + EXPECT_TRUE(executionEnvironment->rootDeviceEnvironments[1]->pageTableManager->initialized); // flush again to check if PT manager was initialized once mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); @@ -940,31 +932,31 @@ INSTANTIATE_TEST_CASE_P( ::testing::Bool()); HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontInitTranslationTable) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); setCompressionEnabled(false, false); myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - auto mockWddmCsr = new MockWddmCsr(*executionEnvironment, 0); + auto mockWddmCsr = new MockWddmCsr(*executionEnvironment, 1); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); executionEnvironment->memoryManager.reset(new WddmMemoryManager(*executionEnvironment)); - std::unique_ptr device(Device::create(executionEnvironment, 0u)); + std::unique_ptr device(Device::create(executionEnvironment, 1u)); device->resetCommandStreamReceiver(mockWddmCsr); auto memoryManager = executionEnvironment->memoryManager.get(); - EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); + EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.get()); auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap cs(graphicsAllocation); - EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); + EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.get()); DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); - EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); + EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.get()); mockWddmCsr->flushBatchedSubmissions(); memoryManager->freeGraphicsMemory(graphicsAllocation); diff --git a/unit_tests/os_interface/windows/driver_info_tests.cpp b/unit_tests/os_interface/windows/driver_info_tests.cpp index 21e848acc6..b2dc8dc76a 100644 --- a/unit_tests/os_interface/windows/driver_info_tests.cpp +++ b/unit_tests/os_interface/windows/driver_info_tests.cpp @@ -6,6 +6,7 @@ */ #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/options.h" #include "core/os_interface/windows/debug_registry_reader.h" #include "runtime/execution_environment/execution_environment.h" @@ -16,6 +17,7 @@ #include "unit_tests/libult/create_command_stream.h" #include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_wddm.h" #include "unit_tests/os_interface/windows/registry_reader_tests.h" @@ -49,7 +51,7 @@ CommandStreamReceiver *createMockCommandStreamReceiver(bool withAubDump, Executi auto csr = new MockCommandStreamReceiver(executionEnvironment, rootDeviceIndex); if (!executionEnvironment.osInterface) { executionEnvironment.osInterface = std::make_unique(); - auto wddm = new WddmMock(); + auto wddm = new WddmMock(*executionEnvironment.rootDeviceEnvironments[0]); auto hwInfo = *executionEnvironment.getHardwareInfo(); wddm->init(hwInfo); executionEnvironment.osInterface->get()->setWddm(wddm); @@ -121,8 +123,10 @@ TEST(DriverInfo, GivenDriverInfoWhenThenReturnNonNullptr) { TEST(DriverInfo, givenInitializedOsInterfaceWhenCreateDriverInfoThenReturnDriverInfoWindowsNotNullptr) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); std::unique_ptr osInterface(new OSInterface()); - osInterface->get()->setWddm(Wddm::createWddm()); + osInterface->get()->setWddm(Wddm::createWddm(rootDeviceEnvironment)); EXPECT_NE(nullptr, osInterface->get()->getWddm()); std::unique_ptr driverInfo(DriverInfo::create(osInterface.get())); diff --git a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp index 7bcdafae82..2ad30664ac 100644 --- a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp +++ b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "public/cl_gl_private_intel.h" #include "runtime/helpers/timestamp_packet.h" #include "runtime/os_interface/os_interface.h" @@ -15,6 +16,7 @@ #include "runtime/sharings/gl/gl_arb_sync_event.h" #include "runtime/sharings/gl/gl_sharing.h" #include "unit_tests/mocks/gl/mock_gl_sharing.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/os_interface/windows/wddm_fixture.h" #include "gtest/gtest.h" @@ -79,14 +81,16 @@ TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenBackupConte struct GlArbSyncEventOsTest : public ::testing::Test { void SetUp() override { + rootDeviceEnvironment = std::make_unique(executionEnvironment); sharing.GLContextHandle = 0x2cU; sharing.GLDeviceHandle = 0x3cU; - wddm = new WddmMock(); + wddm = new WddmMock(*rootDeviceEnvironment); gdi = new MockGdi(); wddm->gdi.reset(gdi); osInterface.get()->setWddm(wddm); } - + MockExecutionEnvironment executionEnvironment; + std::unique_ptr rootDeviceEnvironment; GlSharingFunctionsMock sharing; MockGdi *gdi = nullptr; WddmMock *wddm = nullptr; @@ -209,7 +213,7 @@ TEST_F(GlArbSyncEventOsTest, GivenNewGlSyncInfoWhenCreateEventFailsThenSetupArbS MockOSInterface mockOsInterface; MockOSInterfaceImpl *mockOsInterfaceImpl = static_cast(mockOsInterface.get()); - auto wddm = new WddmMock(); + auto wddm = new WddmMock(*rootDeviceEnvironment.get()); auto gdi = new MockGdi(); wddm->gdi.reset(gdi); auto hwInfo = *platformDevices[0]; @@ -238,7 +242,7 @@ TEST_F(GlArbSyncEventOsTest, GivenInvalidGlSyncInfoWhenCleanupArbSyncObjectIsCal } }; - auto wddm = new WddmMock(); + auto wddm = new WddmMock(*rootDeviceEnvironment.get()); auto gdi = new MockGdi(); wddm->gdi.reset(gdi); auto hwInfo = *platformDevices[0]; @@ -268,7 +272,7 @@ TEST_F(GlArbSyncEventOsTest, GivenValidGlSyncInfoWhenCleanupArbSyncObjectIsCalle } }; - auto wddm = new WddmMock(); + auto wddm = new WddmMock(*rootDeviceEnvironment.get()); auto gdi = new MockGdi(); wddm->gdi.reset(gdi); auto hwInfo = *platformDevices[0]; diff --git a/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp b/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp index 3245c88a4e..a9fbc16e2e 100644 --- a/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp +++ b/unit_tests/os_interface/windows/hw_info_config_win_tests.cpp @@ -7,12 +7,14 @@ #include "unit_tests/os_interface/windows/hw_info_config_win_tests.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/hw_helper.h" #include "core/helpers/options.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm/wddm.h" #include "test.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "instrumentation.h" @@ -52,12 +54,20 @@ template <> void HwInfoConfigHw::adjustPlatformForProductFamily(HardwareInfo *hwInfo) { } +HwInfoConfigTestWindows::HwInfoConfigTestWindows() { + this->executionEnvironment = std::make_unique(); + this->rootDeviceEnvironment = std::make_unique(*executionEnvironment); +} + +HwInfoConfigTestWindows::~HwInfoConfigTestWindows() { +} + void HwInfoConfigTestWindows::SetUp() { HwInfoConfigTest::SetUp(); osInterface.reset(new OSInterface()); - std::unique_ptr wddm(Wddm::createWddm()); + std::unique_ptr wddm(Wddm::createWddm(*rootDeviceEnvironment)); wddm->init(outHwInfo); } diff --git a/unit_tests/os_interface/windows/hw_info_config_win_tests.h b/unit_tests/os_interface/windows/hw_info_config_win_tests.h index e8cc0cd9db..6f701acea2 100644 --- a/unit_tests/os_interface/windows/hw_info_config_win_tests.h +++ b/unit_tests/os_interface/windows/hw_info_config_win_tests.h @@ -14,15 +14,23 @@ namespace NEO { +struct MockExecutionEnvironment; +struct RootDeviceEnvironment; + struct DummyHwConfig : HwInfoConfigHw { }; struct HwInfoConfigTestWindows : public HwInfoConfigTest { + HwInfoConfigTestWindows(); + ~HwInfoConfigTestWindows(); + void SetUp() override; void TearDown() override; std::unique_ptr osInterface; DummyHwConfig hwConfig; + std::unique_ptr executionEnvironment; + std::unique_ptr rootDeviceEnvironment; }; } // namespace NEO diff --git a/unit_tests/os_interface/windows/mock_performance_counters_win.cpp b/unit_tests/os_interface/windows/mock_performance_counters_win.cpp index 00232fea48..c35e919ac0 100644 --- a/unit_tests/os_interface/windows/mock_performance_counters_win.cpp +++ b/unit_tests/os_interface/windows/mock_performance_counters_win.cpp @@ -52,7 +52,7 @@ void PerformanceCountersFixture::SetUp() { context = std::make_unique(device.get()); queue = std::make_unique(context.get(), device.get(), &queueProperties); osInterface = std::unique_ptr(new OSInterface()); - osInterface->get()->setWddm(new WddmMock()); + osInterface->get()->setWddm(new WddmMock(*rootDeviceEnvironment)); device->setOSTime(new MockOSTimeWin(osInterface.get())); } diff --git a/unit_tests/os_interface/windows/os_interface_win_tests.cpp b/unit_tests/os_interface/windows/os_interface_win_tests.cpp index 09bf118b96..18886e4833 100644 --- a/unit_tests/os_interface/windows/os_interface_win_tests.cpp +++ b/unit_tests/os_interface/windows/os_interface_win_tests.cpp @@ -7,7 +7,9 @@ #include "unit_tests/os_interface/windows/os_interface_win_tests.h" +#include "core/execution_environment/root_device_environment.h" #include "runtime/os_interface/windows/os_context_win.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/os_interface/windows/wddm_fixture.h" TEST_F(OsInterfaceTest, GivenWindowsWhenOsSupportFor64KBpagesIsBeingQueriedThenTrueIsReturned) { @@ -22,7 +24,9 @@ TEST_F(OsInterfaceTest, GivenWindowsWhenCreateEentIsCalledThenValidEventHandleIs } TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitializedTrimCallbackIsRegisteredMemoryOperationsHandlerCreated) { - auto wddm = new WddmMock; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = new WddmMock(rootDeviceEnvironment); OSInterface osInterface; osInterface.get()->setWddm(wddm); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); @@ -36,7 +40,9 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit } TEST_F(OsInterfaceTest, whenOsInterfaceSetupGmmInputArgsThenProperAdapterBDFIsSet) { - auto wddm = new WddmMock; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = new WddmMock(rootDeviceEnvironment); osInterface->get()->setWddm(wddm); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); diff --git a/unit_tests/os_interface/windows/os_time_win_tests.cpp b/unit_tests/os_interface/windows/os_time_win_tests.cpp index 263553ef7a..3be48312c8 100644 --- a/unit_tests/os_interface/windows/os_time_win_tests.cpp +++ b/unit_tests/os_interface/windows/os_time_win_tests.cpp @@ -5,7 +5,9 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "runtime/os_interface/windows/os_interface.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/os_interface/windows/wddm_fixture.h" #include "gtest/gtest.h" @@ -85,7 +87,9 @@ TEST(OSTimeWinTests, givenNoOSInterfaceWhenGetCpuGpuTimeThenReturnsError) { } TEST(OSTimeWinTests, givenOSInterfaceWhenGetCpuGpuTimeThenReturnsSuccess) { - auto wddm = new WddmMock; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = new WddmMock(rootDeviceEnvironment); TimeStampData CPUGPUTime01 = {0}; TimeStampData CPUGPUTime02 = {0}; std::unique_ptr osInterface(new OSInterface()); diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 5cec6d6dc0..e830ab84cb 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "core/gmm_helper/gmm_helper.h" #include "core/helpers/hw_info.h" #include "core/helpers/options.h" @@ -21,6 +22,7 @@ #include "runtime/os_interface/windows/wddm_allocation.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" #include "unit_tests/helpers/variable_backup.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_gfx_partition.h" #include "unit_tests/mocks/mock_gmm_resource_info.h" #include "unit_tests/mocks/mock_memory_manager.h" @@ -78,8 +80,6 @@ TEST_F(Wddm20Tests, doubleCreation) { } TEST_F(Wddm20Tests, givenNullPageTableManagerAndRenderCompressedResourceWhenMappingGpuVaThenDontUpdateAuxTable) { - wddm->resetPageTableManager(nullptr); - auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); mockGmmRes->setUnifiedAuxTranslationCapable(); @@ -100,10 +100,13 @@ TEST(Wddm20EnumAdaptersTest, WhenAdapterDescriptionContainsDCHDAndgdrclPathDoesn struct MockWddm : Wddm { using Wddm::openAdapter; - }; - MockWddm wddm; - bool isOpened = wddm.openAdapter(); + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) {} + }; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = std::make_unique(rootDeviceEnvironment); + bool isOpened = wddm->openAdapter(); EXPECT_FALSE(isOpened); } @@ -116,9 +119,12 @@ TEST(Wddm20EnumAdaptersTest, WhenAdapterDescriptionContainsDCHIAndgdrclPathDoesn struct MockWddm : Wddm { using Wddm::openAdapter; - }; - auto wddm = std::make_unique(); + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) {} + }; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = std::make_unique(rootDeviceEnvironment); bool isOpened = wddm->openAdapter(); EXPECT_FALSE(isOpened); @@ -132,9 +138,12 @@ TEST(Wddm20EnumAdaptersTest, WhenAdapterDescriptionContainsDCHDAndgdrclPathConta struct MockWddm : Wddm { using Wddm::openAdapter; - }; - auto wddm = std::make_unique(); + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) {} + }; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = std::make_unique(rootDeviceEnvironment); bool isOpened = wddm->openAdapter(); EXPECT_TRUE(isOpened); @@ -148,9 +157,12 @@ TEST(Wddm20EnumAdaptersTest, WhenAdapterDescriptionContainsDCHIAndgdrclPathConta struct MockWddm : Wddm { using Wddm::openAdapter; - }; - auto wddm = std::make_unique(); + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) {} + }; + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddm = std::make_unique(rootDeviceEnvironment); bool isOpened = wddm->openAdapter(); EXPECT_TRUE(isOpened); @@ -164,7 +176,9 @@ TEST(Wddm20EnumAdaptersTest, expectTrue) { &hwInfo->gtSystemInfo, hwInfo->capabilityTable.gpuAddressSpace)); - std::unique_ptr wddm(Wddm::createWddm()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(Wddm::createWddm(rootDeviceEnvironment)); bool success = wddm->init(outHwInfo); EXPECT_TRUE(success); @@ -180,7 +194,9 @@ TEST(Wddm20EnumAdaptersTest, givenEmptyHardwareInfoWhenEnumAdapterIsCalledThenCa &hwInfo->gtSystemInfo, hwInfo->capabilityTable.gpuAddressSpace)); - std::unique_ptr wddm(Wddm::createWddm()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(Wddm::createWddm(rootDeviceEnvironment)); bool success = wddm->init(outHwInfo); EXPECT_TRUE(success); @@ -203,7 +219,9 @@ TEST(Wddm20EnumAdaptersTest, givenUnknownPlatformWhenEnumAdapterIsCalledThenFals &hwInfo.gtSystemInfo, hwInfo.capabilityTable.gpuAddressSpace)); - std::unique_ptr wddm(Wddm::createWddm()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(Wddm::createWddm(rootDeviceEnvironment)); auto ret = wddm->init(outHwInfo); EXPECT_FALSE(ret); @@ -875,7 +893,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeReside TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentAndMakeResidentCallFailsThenEvictTemporaryResourcesAndRetry) { MockWddmAllocation allocation; allocation.handle = 0x3; - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillRepeatedly(::testing::Return(false)); gmockWddm.temporaryResources->makeResidentResource(allocation.handle); @@ -884,7 +902,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeReside TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndTemporaryResourcesAreEvictedSuccessfullyThenCallMakeResidentOneMoreTime) { MockWddmAllocation allocation; allocation.handle = 0x3; - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(allocation.handle); EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true)); @@ -895,7 +913,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndTemporaryR TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDontStoreTemporaryResource) { MockWddmAllocation allocation; allocation.handle = 0x2; - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(0x1); EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true)); @@ -907,7 +925,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeReside TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvictThenStoreTemporaryResource) { MockWddmAllocation allocation; allocation.handle = 0x2; - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(0x1); EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true)); @@ -920,7 +938,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeReside TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentPassesThenStoreTemporaryResource) { MockWddmAllocation allocation; allocation.handle = 0x2; - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(0x1); EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); @@ -939,7 +957,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesThenAcqui } TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesAndAllEvictionsSucceedThenReturnSuccess) { MockWddmAllocation allocation; - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(allocation.handle); EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); @@ -948,7 +966,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesAndAllEvi EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictAllResourcesResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCallEvictForEachAllocationAndCleanList) { - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); constexpr uint32_t numAllocations = 3u; for (auto i = 0u; i < numAllocations; i++) { @@ -959,7 +977,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTempor EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty()); } TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesAndOneOfThemFailsThenReturnFail) { - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); constexpr uint32_t numAllocations = 3u; for (auto i = 0u; i < numAllocations; i++) { @@ -986,7 +1004,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingNonExistingTemporaryResourceTh EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictResourceResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) { - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(ALLOCATION_HANDLE); EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false)); @@ -995,7 +1013,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFails EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictResourceResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSuccess) { - GmockWddm gmockWddm; + GmockWddm gmockWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto mockTemporaryResources = reinterpret_cast(gmockWddm.temporaryResources.get()); mockTemporaryResources->resourceHandles.push_back(ALLOCATION_HANDLE); EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); @@ -1053,10 +1071,13 @@ TEST_F(WddmGfxPartitionTest, initGfxPartition) { TEST_F(Wddm20Tests, givenWddmWhenOpenAdapterAndForceDeviceIdIsTheSameAsTheExistingDeviceThenReturnTrue) { DebugManagerStateRestore stateRestore; DebugManager.flags.ForceDeviceId.set("1234"); // Existing device Id - struct MockWddm : Wddm { + struct MockWddm : public Wddm { using Wddm::openAdapter; + + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) {} }; - MockWddm wddm; + + MockWddm wddm(*executionEnvironment->rootDeviceEnvironments[0].get()); bool result = wddm.openAdapter(); EXPECT_TRUE(result); } @@ -1064,10 +1085,13 @@ TEST_F(Wddm20Tests, givenWddmWhenOpenAdapterAndForceDeviceIdIsTheSameAsTheExisti TEST_F(Wddm20Tests, givenWddmWhenOpenAdapterAndForceDeviceIdIsDifferentFromTheExistingDeviceThenReturnFalse) { DebugManagerStateRestore stateRestore; DebugManager.flags.ForceDeviceId.set("1111"); - struct MockWddm : Wddm { + struct MockWddm : public Wddm { using Wddm::openAdapter; + + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) {} }; - MockWddm wddm; + + MockWddm wddm(*executionEnvironment->rootDeviceEnvironments[0].get()); bool result = wddm.openAdapter(); EXPECT_FALSE(result); } diff --git a/unit_tests/os_interface/windows/wddm23_tests.cpp b/unit_tests/os_interface/windows/wddm23_tests.cpp index 910b9932e5..a3615d553c 100644 --- a/unit_tests/os_interface/windows/wddm23_tests.cpp +++ b/unit_tests/os_interface/windows/wddm23_tests.cpp @@ -9,6 +9,7 @@ #include "core/helpers/hw_helper.h" #include "core/memory_manager/memory_constants.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" +#include "runtime/execution_environment/execution_environment.h" #include "runtime/os_interface/windows/gdi_interface.h" #include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/os_interface.h" @@ -25,7 +26,7 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture { GdiDllFixture::SetUp(); executionEnvironment = platformImpl->peekExecutionEnvironment(); - wddm = static_cast(Wddm::createWddm()); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); osInterface = std::make_unique(); osInterface->get()->setWddm(wddm); 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 eae3e511bb..0fc221ec7f 100644 --- a/unit_tests/os_interface/windows/wddm_address_space_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_address_space_tests.cpp @@ -6,15 +6,17 @@ */ #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/options.h" #include "test.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_wddm.h" using namespace NEO; class WddmMockReserveAddress : public WddmMock { public: - WddmMockReserveAddress() : WddmMock() {} + WddmMockReserveAddress(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment) {} void *virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) override { if (returnGood != 0) { @@ -55,7 +57,9 @@ class WddmMockReserveAddress : public WddmMock { }; TEST(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddress) { - std::unique_ptr wddm(new WddmMockReserveAddress()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(new WddmMockReserveAddress(rootDeviceEnvironment)); size_t size = 0x1000; void *reserve = nullptr; @@ -72,7 +76,9 @@ TEST(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddr } TEST(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) { - std::unique_ptr wddm(new WddmMockReserveAddress()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(new WddmMockReserveAddress(rootDeviceEnvironment)); size_t size = 0x1000; void *reserve = nullptr; @@ -85,7 +91,9 @@ TEST(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) { } TEST(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenReturnSecond) { - std::unique_ptr wddm(new WddmMockReserveAddress()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(new WddmMockReserveAddress(rootDeviceEnvironment)); size_t size = 0x1000; void *reserve = nullptr; @@ -102,7 +110,9 @@ TEST(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenRetu } TEST(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenReturnThird) { - std::unique_ptr wddm(new WddmMockReserveAddress()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(new WddmMockReserveAddress(rootDeviceEnvironment)); size_t size = 0x1000; void *reserve = nullptr; @@ -119,7 +129,9 @@ TEST(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenRetu } TEST(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondNullThenReturnSecondNull) { - std::unique_ptr wddm(new WddmMockReserveAddress()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(new WddmMockReserveAddress(rootDeviceEnvironment)); size_t size = 0x1000; void *reserve = nullptr; diff --git a/unit_tests/os_interface/windows/wddm_create.cpp b/unit_tests/os_interface/windows/wddm_create.cpp index 80e97cdf4b..cb42287164 100644 --- a/unit_tests/os_interface/windows/wddm_create.cpp +++ b/unit_tests/os_interface/windows/wddm_create.cpp @@ -8,7 +8,7 @@ #include "unit_tests/mocks/mock_wddm.h" namespace NEO { -Wddm *Wddm::createWddm() { - return new WddmMock(); +Wddm *Wddm::createWddm(RootDeviceEnvironment &rootDeviceEnvironment) { + return new WddmMock(rootDeviceEnvironment); } } // namespace NEO diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index 91ad60a60f..2d520b64b5 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -28,7 +28,7 @@ namespace NEO { struct WddmFixture : ::testing::Test { void SetUp() override { executionEnvironment = platformImpl->peekExecutionEnvironment(); - wddm = static_cast(Wddm::createWddm()); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); @@ -55,7 +55,7 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture { void SetUp() override { executionEnvironment = platformImpl->peekExecutionEnvironment(); GdiDllFixture::SetUp(); - wddm = static_cast(Wddm::createWddm()); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); wddmMockInterface = new WddmMockInterface20(*wddm); wddm->wddmInterface.reset(wddmMockInterface); executionEnvironment->osInterface = std::make_unique(); @@ -87,7 +87,7 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture { struct WddmInstrumentationGmmFixture { void SetUp() { executionEnvironment = platformImpl->peekExecutionEnvironment(); - wddm.reset(static_cast(Wddm::createWddm())); + wddm.reset(static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()))); gmmMem = new ::testing::NiceMock(); wddm->gmmMemory.reset(gmmMem); } 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 cbea94c51d..a8c8909c7c 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -6,6 +6,7 @@ */ #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "core/gmm_helper/gmm_helper.h" #include "runtime/gmm_helper/gmm.h" #include "runtime/memory_manager/memory_manager.h" @@ -26,7 +27,7 @@ class WddmWithKmDafMock : public Wddm { using Wddm::gdi; using Wddm::mapGpuVirtualAddress; - WddmWithKmDafMock() : Wddm() { + WddmWithKmDafMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(rootDeviceEnvironment) { kmDafListener.reset(new KmDafListenerMock); } @@ -39,7 +40,7 @@ class WddmKmDafListenerTest : public ::testing::Test { public: void SetUp() { executionEnvironment = platformImpl->peekExecutionEnvironment(); - wddmWithKmDafMock.reset(new WddmWithKmDafMock()); + wddmWithKmDafMock.reset(new WddmWithKmDafMock(*executionEnvironment->rootDeviceEnvironments[0].get())); wddmWithKmDafMock->gdi.reset(new MockGdi()); auto hwInfo = *platformDevices[0]; wddmWithKmDafMock->init(hwInfo); 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 0845621c7f..7bbdfd4b83 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -36,17 +36,17 @@ using namespace ::testing; void WddmMemoryManagerFixture::SetUp() { GdiDllFixture::SetUp(); - wddm = static_cast(Wddm::createWddm()); + executionEnvironment = platformImpl->peekExecutionEnvironment(); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); if (platformDevices[0]->capabilityTable.ftrRenderCompressedBuffers || platformDevices[0]->capabilityTable.ftrRenderCompressedImages) { GMM_TRANSLATIONTABLE_CALLBACKS dummyTTCallbacks = {}; - wddm->resetPageTableManager(GmmPageTableMngr::create(0, &dummyTTCallbacks)); + executionEnvironment->rootDeviceEnvironments[0]->pageTableManager.reset(GmmPageTableMngr::create(0, &dummyTTCallbacks)); } auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000; wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - executionEnvironment = platformImpl->peekExecutionEnvironment(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); @@ -107,8 +107,8 @@ TEST(WddmAllocationTest, givenMemoryPoolWhenPassedToWddmAllocationConstructorThe TEST(WddmMemoryManagerExternalHeapTest, externalHeapIsCreatedWithCorrectBase) { HardwareInfo *hwInfo; - auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - std::unique_ptr wddm(static_cast(Wddm::createWddm())); + auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + std::unique_ptr wddm(static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()))); uint64_t base = 0x56000; uint64_t size = 0x9000; wddm->setHeap32(base, size); @@ -121,8 +121,8 @@ TEST(WddmMemoryManagerExternalHeapTest, externalHeapIsCreatedWithCorrectBase) { TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) { HardwareInfo *hwInfo; - auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - auto wddm = std::make_unique(); + auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + auto wddm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0].get()); executionEnvironment->osInterface->get()->setWddm(wddm.release()); bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(true); @@ -1302,8 +1302,8 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalBaseIsReturned) { HardwareInfo *hwInfo; - auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - auto wddm = new WddmMock(); + auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + auto wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[0].get()); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); auto hwInfoMock = *platformDevices[0]; @@ -1439,9 +1439,9 @@ TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThen WddmMemoryManager memoryManager(*executionEnvironment); auto mockMngr = new NiceMock(); - wddm->resetPageTableManager(mockMngr); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); - auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(AllocationProperties(1, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY)); GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; @@ -1462,12 +1462,12 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa std::unique_ptr gmm(new Gmm(reinterpret_cast(123), 4096u, false)); gmm->isRenderCompressed = true; D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; - WddmMock wddm; + WddmMock wddm(*executionEnvironment->rootDeviceEnvironments[1].get()); auto hwInfo = *platformDevices[0]; wddm.init(hwInfo); auto mockMngr = new NiceMock(); - wddm.resetPageTableManager(mockMngr); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; @@ -1494,9 +1494,9 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT D3DGPU_VIRTUAL_ADDRESS gpuVa = 123; auto mockMngr = new NiceMock(); - wddm->resetPageTableManager(mockMngr); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); - auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); + auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(AllocationProperties(1, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY))); wddmAlloc->setGpuAddress(gpuVa); wddmAlloc->getDefaultGmm()->isRenderCompressed = true; @@ -1519,7 +1519,7 @@ TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleasei WddmMemoryManager memoryManager(*executionEnvironment); auto mockMngr = new NiceMock(); - wddm->resetPageTableManager(mockMngr); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); wddmAlloc->getDefaultGmm()->isRenderCompressed = false; @@ -1533,12 +1533,12 @@ TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenMappedGp std::unique_ptr gmm(new Gmm(reinterpret_cast(123), 4096u, false)); gmm->isRenderCompressed = false; D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; - WddmMock wddm; + WddmMock wddm(*executionEnvironment->rootDeviceEnvironments[0].get()); auto hwInfo = *platformDevices[0]; wddm.init(hwInfo); auto mockMngr = new NiceMock(); - wddm.resetPageTableManager(mockMngr); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0); @@ -1550,7 +1550,7 @@ TEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenRetur std::unique_ptr gmm(new Gmm(reinterpret_cast(123), 4096u, false)); gmm->isRenderCompressed = false; D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; - WddmMock wddm; + WddmMock wddm(*executionEnvironment->rootDeviceEnvironments[1].get()); auto hwInfo = *platformDevices[0]; wddm.init(hwInfo); @@ -1565,7 +1565,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse WddmMemoryManager memoryManager(*executionEnvironment); auto mockMngr = new NiceMock(); - wddm->resetPageTableManager(mockMngr); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); auto myGmm = new Gmm(reinterpret_cast(123), 4096u, false); myGmm->isRenderCompressed = false; @@ -1582,6 +1582,30 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse memoryManager.freeGraphicsMemory(wddmAlloc); } +TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsSetThenUpdateAuxTable) { + D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; + auto hwInfo = *platformDevices[0]; + wddm->init(hwInfo); + WddmMemoryManager memoryManager(*executionEnvironment); + + auto mockMngr = new NiceMock(); + executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.reset(mockMngr); + + auto myGmm = new Gmm(reinterpret_cast(123), 4096u, false); + myGmm->isRenderCompressed = true; + myGmm->gmmResourceInfo->getResourceFlags()->Info.RenderCompressed = 1; + + auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); + delete wddmAlloc->getDefaultGmm(); + wddmAlloc->setDefaultGmm(myGmm); + + EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(1); + + auto result = wddm->mapGpuVirtualAddress(myGmm, ALLOCATION_HANDLE, wddm->getGfxPartition().Standard.Base, wddm->getGfxPartition().Standard.Limit, 0u, gpuVa); + EXPECT_TRUE(result); + memoryManager.freeGraphicsMemory(wddmAlloc); +} + TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryWhenCreateAllocationFailsThenPopulateOsHandlesReturnsInvalidPointer) { OsHandleStorage handleStorage; handleStorage.fragmentCount = 1; @@ -1626,7 +1650,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhenCleanupMemoryManagerThenDontAccessCsr) { ExecutionEnvironment &executionEnvironment = *platform()->peekExecutionEnvironment(); auto csr = std::unique_ptr(createCommandStream(executionEnvironment, 0)); - auto wddm = new WddmMock(); + auto wddm = new WddmMock(*executionEnvironment.rootDeviceEnvironments[0].get()); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); 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 6b9a3d053c..7f519f53ff 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -48,7 +48,7 @@ class MockWddmMemoryManagerFixture { executionEnvironment = platformImpl->peekExecutionEnvironment(); gdi = new MockGdi(); - wddm = static_cast(Wddm::createWddm()); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); wddm->gdi.reset(gdi); constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000; wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); @@ -96,7 +96,8 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture void SetUp() override { // wddm is deleted by memory manager - wddm = new NiceMock; + + wddm = new NiceMock(*executionEnvironment->rootDeviceEnvironments[0].get()); executionEnvironment->osInterface = std::make_unique(); ASSERT_NE(nullptr, wddm); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); @@ -162,8 +163,8 @@ class WddmMemoryManagerSimpleTest : public MockWddmMemoryManagerFixture, public class MockWddmMemoryManagerTest : public ::testing::Test { public: void SetUp() override { - executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - wddm = new WddmMock(); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); + wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[1].get()); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); } diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index c2eb47a6dd..7133dc33f6 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -6,6 +6,7 @@ */ #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/hw_helper.h" #include "core/memory_manager/memory_operations_handler.h" #include "runtime/execution_environment/execution_environment.h" @@ -19,6 +20,7 @@ #include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/mocks/mock_allocation_properties.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_wddm.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h" #include "unit_tests/os_interface/windows/mock_wddm_allocation.h" @@ -64,7 +66,9 @@ struct WddmResidencyControllerTest : ::testing::Test { const uint32_t osContextId = 0u; void SetUp() { - wddm = std::unique_ptr(static_cast(Wddm::createWddm())); + executionEnvironment = std::make_unique(); + rootDeviceEnvironment = std::make_unique(*executionEnvironment); + wddm = std::unique_ptr(static_cast(Wddm::createWddm(*rootDeviceEnvironment))); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); mockOsContextWin = std::make_unique(*wddm, osContextId, 0, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); @@ -74,6 +78,8 @@ struct WddmResidencyControllerTest : ::testing::Test { std::unique_ptr wddm; std::unique_ptr mockOsContextWin; + std::unique_ptr executionEnvironment; + std::unique_ptr rootDeviceEnvironment; MockWddmResidencyController *residencyController = nullptr; }; @@ -81,7 +87,9 @@ struct WddmResidencyControllerWithGdiTest : ::testing::Test { const uint32_t osContextId = 0u; void SetUp() { - wddm = std::unique_ptr(static_cast(Wddm::createWddm())); + executionEnvironment = std::make_unique(); + rootDeviceEnvironment = std::make_unique(*executionEnvironment); + wddm = std::unique_ptr(static_cast(Wddm::createWddm(*rootDeviceEnvironment))); gdi = new MockGdi(); wddm->gdi.reset(gdi); auto hwInfo = *platformDevices[0]; @@ -95,6 +103,8 @@ struct WddmResidencyControllerWithGdiTest : ::testing::Test { std::unique_ptr wddm; std::unique_ptr mockOsContextWin; + std::unique_ptr executionEnvironment; + std::unique_ptr rootDeviceEnvironment; MockWddmResidencyController *residencyController = nullptr; MockGdi *gdi; }; @@ -103,7 +113,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT void SetUp() { executionEnvironment = platformImpl->peekExecutionEnvironment(); - wddm = new ::testing::NiceMock(); + wddm = new ::testing::NiceMock(*executionEnvironment->rootDeviceEnvironments[0].get()); wddm->gdi = std::make_unique(); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); auto hwInfo = *platformDevices[0]; @@ -135,13 +145,13 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { const uint32_t osContextId = 0u; void SetUp() { - wddm = static_cast(Wddm::createWddm()); + executionEnvironment = platform()->peekExecutionEnvironment(); + wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); gdi = new MockGdi(); wddm->gdi.reset(gdi); - executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); @@ -170,8 +180,9 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { TEST(WddmResidencyController, givenWddmResidencyControllerWhenItIsConstructedThenDoNotRegisterTrimCallback) { ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); auto gdi = new MockGdi(); - auto wddm = std::unique_ptr{static_cast(Wddm::createWddm())}; + auto wddm = std::unique_ptr{static_cast(Wddm::createWddm(*executionEnvironment.rootDeviceEnvironments[0].get()))}; wddm->gdi.reset(gdi); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); @@ -189,8 +200,9 @@ TEST(WddmResidencyController, givenWddmResidencyControllerWhenItIsConstructedThe TEST(WddmResidencyController, givenWddmResidencyControllerWhenRegisterCallbackThenCallbackIsSetUpProperly) { ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); auto gdi = new MockGdi(); - auto wddm = std::unique_ptr{static_cast(Wddm::createWddm())}; + auto wddm = std::unique_ptr{static_cast(Wddm::createWddm(*executionEnvironment.rootDeviceEnvironments[0].get()))}; wddm->gdi.reset(gdi); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); diff --git a/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp b/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp index c87db62244..ecf79fd058 100644 --- a/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp +++ b/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp @@ -27,7 +27,7 @@ struct EnqueueBufferWindowsTest : public HardwareParse, void SetUp() override { DebugManager.flags.EnableBlitterOperationsForReadWriteBuffers.set(0); - executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); } void TearDown() override { diff --git a/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp index 7ac1da6065..332cff3728 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp @@ -27,7 +27,7 @@ class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test { hwInfo = nullptr; EnvironmentWithCsrWrapper environment; environment.setCsrType>(); - executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable = platformDevices[0]->capabilityTable; hwInfo->capabilityTable.sourceLevelDebuggerSupported = true; diff --git a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp index 4bc12dcf2f..eda9887c8b 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp @@ -491,7 +491,7 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreate VariableBackup backup(&overrideCommandStreamReceiverCreation, true); HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.instrumentationEnabled = true; unique_ptr device(Device::create(executionEnvironment, 0)); diff --git a/unit_tests/windows/wddm_create_tests.cpp b/unit_tests/windows/wddm_create_tests.cpp index 634e53d255..fdb0a7ae19 100644 --- a/unit_tests/windows/wddm_create_tests.cpp +++ b/unit_tests/windows/wddm_create_tests.cpp @@ -5,16 +5,20 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/hw_info.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "runtime/os_interface/windows/wddm/wddm.h" #include "test.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include using namespace NEO; TEST(wddmCreateTests, givenInputVersionWhenCreatingThenCreateRequestedObject) { - std::unique_ptr wddm(Wddm::createWddm()); + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + std::unique_ptr wddm(Wddm::createWddm(rootDeviceEnvironment)); EXPECT_EQ(typeid(*wddm.get()), typeid(Wddm)); }