From 92bfd2e3d209c58f083986263fac8db14f4fd253 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 27 Aug 2018 15:48:29 +0200 Subject: [PATCH] Move OsContext to Device Change-Id: I030b65372fbdc075423d22720e9da34ac65b8e68 Signed-off-by: Mateusz Jablonski --- runtime/command_queue/command_queue.cpp | 2 +- .../aub_command_stream_receiver_hw.h | 4 +- .../aub_command_stream_receiver_hw.inl | 6 +- .../command_stream/command_stream_receiver.h | 9 +- .../command_stream_receiver_hw.h | 4 +- .../command_stream_receiver_hw.inl | 10 +- .../command_stream_receiver_with_aub_dump.h | 4 +- .../command_stream_receiver_with_aub_dump.inl | 12 +- .../tbx_command_stream_receiver_hw.h | 4 +- .../tbx_command_stream_receiver_hw.inl | 6 +- runtime/device/device.cpp | 10 +- runtime/device/device.h | 12 +- runtime/memory_manager/host_ptr_defines.h | 17 ++- .../os_interface/linux/drm_command_stream.h | 6 +- .../os_interface/linux/drm_command_stream.inl | 8 +- .../os_interface/linux/os_context_linux.cpp | 2 +- runtime/os_interface/os_context.h | 8 +- .../windows/deferrable_deletion_win.cpp | 6 +- .../windows/deferrable_deletion_win.h | 6 +- .../os_interface/windows/os_context_win.cpp | 14 +- runtime/os_interface/windows/os_context_win.h | 1 + runtime/os_interface/windows/wddm/wddm.cpp | 43 +++--- runtime/os_interface/windows/wddm/wddm.h | 12 +- .../windows/wddm/wddm_interface.cpp | 4 +- .../windows/wddm_device_command_stream.h | 6 +- .../windows/wddm_device_command_stream.inl | 18 ++- .../windows/wddm_memory_manager.cpp | 69 ++++++--- .../windows/wddm_memory_manager.h | 7 +- .../aub_command_stream_tests.cpp | 12 +- .../command_queue/drm_requirements_tests.cpp | 2 +- .../command_queue/enqueue_thread_tests.cpp | 2 +- .../aub_command_stream_receiver_tests.cpp | 54 +++---- ...mmand_stream_receiver_flush_task_tests.cpp | 2 +- .../command_stream_receiver_tests.cpp | 2 +- ...nd_stream_receiver_with_aub_dump_tests.cpp | 11 +- .../tbx_command_stream_tests.cpp | 16 +- unit_tests/device/device_win_timers_tests.cpp | 2 - unit_tests/helpers/kmd_notify_tests.cpp | 28 ++-- unit_tests/kernel/kernel_tests.cpp | 4 +- .../mem_obj/mem_obj_destruction_tests.cpp | 1 - .../memory_manager/memory_manager_tests.cpp | 23 +++ unit_tests/mocks/mock_csr.cpp | 2 +- unit_tests/mocks/mock_csr.h | 8 +- unit_tests/mocks/mock_wddm.cpp | 16 +- unit_tests/mocks/mock_wddm.h | 9 +- .../linux/drm_command_stream_tests.cpp | 91 ++++++------ .../linux/os_interface_linux_tests.cpp | 2 +- .../windows/deferrable_deletion_win_tests.cpp | 34 +++-- .../windows/device_command_stream_tests.cpp | 57 ++++--- .../windows/driver_info_tests.cpp | 4 +- .../windows/os_interface_win_tests.cpp | 12 +- .../os_interface/windows/wddm20_tests.cpp | 55 ++++--- .../os_interface/windows/wddm23_tests.cpp | 77 ++++++---- .../os_interface/windows/wddm_fixture.h | 30 +++- ..._manager_allocate_in_device_pool_tests.inl | 2 +- .../windows/wddm_memory_manager_tests.cpp | 139 ++++++++++++------ .../windows/wddm_memory_manager_tests.h | 31 +++- .../windows/wddm_preemption_tests.cpp | 6 +- 58 files changed, 615 insertions(+), 429 deletions(-) diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index a188f710cb..48f0b1decc 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -156,7 +156,7 @@ void CommandQueue::waitUntilComplete(uint32_t taskCountToWait, FlushStamp flushS DBG_LOG(LogTaskCounts, __FUNCTION__, "Waiting for taskCount:", taskCountToWait); DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "Current taskCount:", getHwTag()); - device->getCommandStreamReceiver().waitForTaskCountWithKmdNotifyFallback(taskCountToWait, flushStampToWait, useQuickKmdSleep); + device->getCommandStreamReceiver().waitForTaskCountWithKmdNotifyFallback(taskCountToWait, flushStampToWait, useQuickKmdSleep, *device->getOsContext()); DEBUG_BREAK_IF(getHwTag() < taskCountToWait); latestTaskCountWaited = taskCountToWait; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 246d948d34..af78e6b0fa 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -40,11 +40,11 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverHw { using ExternalAllocationsContainer = std::vector; public: - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeResident(GraphicsAllocation &gfxAllocation) override; void makeNonResident(GraphicsAllocation &gfxAllocation) override; - void processResidency(ResidencyContainer *allocationsForResidency) override; + void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeResidentExternal(AllocationView &allocationView); void makeNonResidentExternal(uint64_t gpuAddress); diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 9db7ccdc10..70ca96531e 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -245,7 +245,7 @@ CommandStreamReceiver *AUBCommandStreamReceiverHw::create(const Hardw template FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer, - EngineType engineType, ResidencyContainer *allocationsForResidency) { + EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) { if (subCaptureManager->isSubCaptureMode()) { if (!subCaptureManager->isSubCaptureEnabled()) { if (this->standalone) { @@ -305,7 +305,7 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer allocationsForResidency->push_back(batchBuffer.commandBufferAllocation); batchBuffer.commandBufferAllocation->residencyTaskCount = this->taskCount; } - processResidency(allocationsForResidency); + processResidency(allocationsForResidency, osContext); } if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { addGUCStartMessage(static_cast(reinterpret_cast(pBatchBuffer)), engineType); @@ -577,7 +577,7 @@ bool AUBCommandStreamReceiverHw::writeMemory(AllocationView &allocati } template -void AUBCommandStreamReceiverHw::processResidency(ResidencyContainer *allocationsForResidency) { +void AUBCommandStreamReceiverHw::processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) { if (subCaptureManager->isSubCaptureMode()) { if (!subCaptureManager->isSubCaptureEnabled()) { return; diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 639760124d..d1e0a49e18 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -45,6 +45,7 @@ class MemoryManager; class GmmPageTableMngr; class OSInterface; class ExecutionEnvironment; +class OsContext; enum class DispatchMode { DeviceDefault = 0, //default for given device @@ -65,7 +66,7 @@ class CommandStreamReceiver { CommandStreamReceiver(ExecutionEnvironment &executionEnvironment, size_t defaultSshSize); virtual ~CommandStreamReceiver(); - virtual FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) = 0; + virtual FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) = 0; virtual CompletionStamp flushTask(LinearStream &commandStream, size_t commandStreamStart, const IndirectHeap &dsh, const IndirectHeap &ioh, const IndirectHeap &ssh, @@ -77,7 +78,7 @@ class CommandStreamReceiver { virtual void makeResident(GraphicsAllocation &gfxAllocation); virtual void makeNonResident(GraphicsAllocation &gfxAllocation); void makeSurfacePackNonResident(ResidencyContainer *allocationsForResidency); - virtual void processResidency(ResidencyContainer *allocationsForResidency) {} + virtual void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) {} virtual void processEviction(); void makeResidentHostPtrAllocation(GraphicsAllocation *gfxAllocation); virtual void waitBeforeMakingNonResidentWhenRequired() {} @@ -102,7 +103,7 @@ class CommandStreamReceiver { } volatile uint32_t *getTagAddress() const { return tagAddress; } - virtual bool waitForFlushStamp(FlushStamp &flushStampToWait) { return true; }; + virtual bool waitForFlushStamp(FlushStamp &flushStampToWait, OsContext &osContext) { return true; }; uint32_t peekTaskCount() const { return taskCount; } @@ -129,7 +130,7 @@ class CommandStreamReceiver { void requestThreadArbitrationPolicy(uint32_t requiredPolicy) { this->requiredThreadArbitrationPolicy = requiredPolicy; } - virtual void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep) = 0; + virtual void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, OsContext &osContext) = 0; MOCKABLE_VIRTUAL bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait); void setSamplerCacheFlushRequired(SamplerCacheFlushState value) { this->samplerCacheFlushRequired = value; } diff --git a/runtime/command_stream/command_stream_receiver_hw.h b/runtime/command_stream/command_stream_receiver_hw.h index c0392e1321..57ba50f3d2 100644 --- a/runtime/command_stream/command_stream_receiver_hw.h +++ b/runtime/command_stream/command_stream_receiver_hw.h @@ -43,7 +43,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { CommandStreamReceiverHw(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment); - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; CompletionStamp flushTask(LinearStream &commandStream, size_t commandStreamStart, const IndirectHeap &dsh, const IndirectHeap &ioh, const IndirectHeap &ssh, @@ -69,7 +69,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { size_t getCmdSizeForMediaSampler(bool mediaSamplerRequired) const; void programCoherency(LinearStream &csr, DispatchFlags &dispatchFlags); - void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep) override; + void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, OsContext &osContext) override; const HardwareInfo &peekHwInfo() const { return hwInfo; } void collectStateBaseAddresPatchInfo( diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index d2bbaae908..7bdba820e8 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -49,7 +49,7 @@ CommandStreamReceiverHw::CommandStreamReceiverHw(const HardwareInfo & } template -FlushStamp CommandStreamReceiverHw::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) { +FlushStamp CommandStreamReceiverHw::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) { return flushStamp->peekStamp(); } @@ -434,7 +434,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( if (submitCSR | submitTask) { if (this->dispatchMode == DispatchMode::ImmediateDispatch) { - flushStamp->setStamp(this->flush(batchBuffer, engineType, nullptr)); + flushStamp->setStamp(this->flush(batchBuffer, engineType, nullptr, *device.getOsContext())); this->latestFlushedTaskCount = this->taskCount + 1; this->makeSurfacePackNonResident(nullptr); } else { @@ -555,7 +555,7 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { if (epiloguePipeControlLocation) { ((PIPE_CONTROL *)epiloguePipeControlLocation)->setDcFlushEnable(true); } - auto flushStamp = this->flush(primaryCmdBuffer->batchBuffer, engineType, &surfacesForSubmit); + auto flushStamp = this->flush(primaryCmdBuffer->batchBuffer, engineType, &surfacesForSubmit, *device.getOsContext()); //after flush task level is closed this->taskLevel++; @@ -656,13 +656,13 @@ inline void CommandStreamReceiverHw::emitNoop(LinearStream &commandSt } template -inline void CommandStreamReceiverHw::waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep) { +inline void CommandStreamReceiverHw::waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, OsContext &osContext) { int64_t waitTimeout = 0; bool enableTimeout = kmdNotifyHelper->obtainTimeoutParams(waitTimeout, useQuickKmdSleep, *getTagAddress(), taskCountToWait, flushStampToWait); auto status = waitForCompletionWithTimeout(enableTimeout, waitTimeout, taskCountToWait); if (!status) { - waitForFlushStamp(flushStampToWait); + waitForFlushStamp(flushStampToWait, osContext); //now call blocking wait, this is to ensure that task count is reached waitForCompletionWithTimeout(false, 0, taskCountToWait); } diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.h b/runtime/command_stream/command_stream_receiver_with_aub_dump.h index 5b23222de9..54842d6a32 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.h +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.h @@ -34,8 +34,8 @@ class CommandStreamReceiverWithAUBDump : public BaseCSR { CommandStreamReceiverWithAUBDump(const CommandStreamReceiverWithAUBDump &) = delete; CommandStreamReceiverWithAUBDump &operator=(const CommandStreamReceiverWithAUBDump &) = delete; - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency) override; - void processResidency(ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; + void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) override; diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl index 64b25f4495..1ff30c955b 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl @@ -39,19 +39,19 @@ CommandStreamReceiverWithAUBDump::~CommandStreamReceiverWithAUBDump() { } template -FlushStamp CommandStreamReceiverWithAUBDump::flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency) { - FlushStamp flushStamp = BaseCSR::flush(batchBuffer, engineOrdinal, allocationsForResidency); +FlushStamp CommandStreamReceiverWithAUBDump::flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency, OsContext &osContext) { + FlushStamp flushStamp = BaseCSR::flush(batchBuffer, engineOrdinal, allocationsForResidency, osContext); if (aubCSR) { - aubCSR->flush(batchBuffer, engineOrdinal, allocationsForResidency); + aubCSR->flush(batchBuffer, engineOrdinal, allocationsForResidency, osContext); } return flushStamp; } template -void CommandStreamReceiverWithAUBDump::processResidency(ResidencyContainer *allocationsForResidency) { - BaseCSR::processResidency(allocationsForResidency); +void CommandStreamReceiverWithAUBDump::processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) { + BaseCSR::processResidency(allocationsForResidency, osContext); if (aubCSR) { - aubCSR->processResidency(allocationsForResidency); + aubCSR->processResidency(allocationsForResidency, osContext); } } diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index fb6b1e1daf..4e4196399f 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -45,10 +45,10 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverHw { typedef typename AUB::MiContextDescriptorReg MiContextDescriptorReg; public: - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeCoherent(GraphicsAllocation &gfxAllocation) override; - void processResidency(ResidencyContainer *allocationsForResidency) override; + void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void waitBeforeMakingNonResidentWhenRequired() override; bool writeMemory(GraphicsAllocation &gfxAllocation); diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index faa4718812..9b025c731e 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -189,7 +189,7 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw::create(const Hardw } template -FlushStamp TbxCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) { +FlushStamp TbxCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) { uint32_t mmioBase = getCsTraits(engineType).mmioBase; auto &engineInfo = engineInfoTable[engineType]; @@ -217,7 +217,7 @@ FlushStamp TbxCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer } // Write allocations for residency - processResidency(allocationsForResidency); + processResidency(allocationsForResidency, osContext); // Add a batch buffer start to the RCS auto previousTail = engineInfo.tailRCS; @@ -363,7 +363,7 @@ bool TbxCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA } template -void TbxCommandStreamReceiverHw::processResidency(ResidencyContainer *allocationsForResidency) { +void TbxCommandStreamReceiverHw::processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) { auto &residencyAllocations = allocationsForResidency ? *allocationsForResidency : this->getMemoryManager()->getResidencyAllocations(); for (auto &gfxAllocation : residencyAllocations) { diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index c19b757024..1d7a69d810 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -36,6 +36,7 @@ #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/options.h" #include "runtime/memory_manager/memory_manager.h" +#include "runtime/os_interface/os_context.h" #include "runtime/os_interface/os_interface.h" #include "runtime/os_interface/os_time.h" #include "runtime/source_level_debugger/source_level_debugger.h" @@ -79,8 +80,7 @@ bool familyEnabled[IGFX_MAX_CORE] = { }; Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment) - : enabledClVersion(false), hwInfo(hwInfo), tagAddress(nullptr), preemptionAllocation(nullptr), - osTime(nullptr), slmWindowStartAddress(nullptr), executionEnvironment(executionEnvironment) { + : hwInfo(hwInfo), executionEnvironment(executionEnvironment) { memset(&deviceInfo, 0, sizeof(deviceInfo)); deviceExtensions.reserve(1000); name.reserve(100); @@ -120,6 +120,9 @@ Device::~Device() { alignedFree(this->slmWindowStartAddress); } + if (osContext) { + osContext->decRefInternal(); + } executionEnvironment->decRefInternal(); } @@ -129,7 +132,8 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo)) { return false; } - + outDevice.osContext = new OsContext(executionEnvironment->osInterface.get()); + outDevice.osContext->incRefInternal(); executionEnvironment->initializeMemoryManager(outDevice.getEnabled64kbPages()); CommandStreamReceiver *commandStreamReceiver = executionEnvironment->commandStreamReceiver.get(); diff --git a/runtime/device/device.h b/runtime/device/device.h index 14cc1723d1..01393f597b 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -39,6 +39,7 @@ class OSTime; class DriverInfo; struct HardwareInfo; class SourceLevelDebugger; +class OsContext; template <> struct OpenCLObjectMapper<_cl_device_id> { @@ -131,6 +132,7 @@ class Device : public BaseObject<_cl_device_id> { SourceLevelDebugger *getSourceLevelDebugger() { return executionEnvironment->sourceLevelDebugger.get(); } ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; } const HardwareCapabilities &getHardwareCapabilities() { return hardwareCapabilities; } + OsContext *getOsContext() const { return osContext; } protected: Device() = delete; @@ -151,19 +153,21 @@ class Device : public BaseObject<_cl_device_id> { void setupFp64Flags(); void appendOSExtensions(std::string &deviceExtensions); - unsigned int enabledClVersion; + unsigned int enabledClVersion = 0u; const HardwareInfo &hwInfo; HardwareCapabilities hardwareCapabilities = {}; DeviceInfo deviceInfo; - volatile uint32_t *tagAddress; - GraphicsAllocation *preemptionAllocation; + volatile uint32_t *tagAddress = nullptr; + GraphicsAllocation *preemptionAllocation = nullptr; std::unique_ptr osTime; std::unique_ptr driverInfo; std::unique_ptr performanceCounters; - void *slmWindowStartAddress; + OsContext *osContext = nullptr; + + void *slmWindowStartAddress = nullptr; std::string exposedBuiltinKernels = ""; diff --git a/runtime/memory_manager/host_ptr_defines.h b/runtime/memory_manager/host_ptr_defines.h index 2f3162a7c9..35da09867c 100644 --- a/runtime/memory_manager/host_ptr_defines.h +++ b/runtime/memory_manager/host_ptr_defines.h @@ -23,11 +23,13 @@ #pragma once #include #include +#include "runtime/os_interface/os_context.h" namespace OCLRT { struct OsHandle; -typedef OsHandle OsGraphicsHandle; + +using OsGraphicsHandle = OsHandle; const int max_fragments_count = 3; @@ -54,8 +56,21 @@ enum RequirementsStatus { struct ResidencyData { ResidencyData() { } + void addOsContext(OsContext *osContext) { + if (!this->osContext) { + osContext->incRefInternal(); + this->osContext = osContext; + } + DEBUG_BREAK_IF(this->osContext != osContext); + } + ~ResidencyData() { + if (osContext) { + osContext->decRefInternal(); + } + } bool resident = false; uint64_t lastFence = 0; + OsContext *osContext = nullptr; }; struct PartialAllocation { diff --git a/runtime/os_interface/linux/drm_command_stream.h b/runtime/os_interface/linux/drm_command_stream.h index 4ed1e8238a..c0c771a916 100644 --- a/runtime/os_interface/linux/drm_command_stream.h +++ b/runtime/os_interface/linux/drm_command_stream.h @@ -50,11 +50,11 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { // When drm is passed, DCSR will not free it at destruction DrmCommandStreamReceiver(const HardwareInfo &hwInfoIn, Drm *drm, ExecutionEnvironment &executionEnvironment, gemCloseWorkerMode mode = gemCloseWorkerMode::gemCloseWorkerActive); - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeResident(GraphicsAllocation &gfxAllocation) override; - void processResidency(ResidencyContainer *allocationsForResidency) override; + void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeNonResident(GraphicsAllocation &gfxAllocation) override; - bool waitForFlushStamp(FlushStamp &flushStampToWait) override; + bool waitForFlushStamp(FlushStamp &flushStampToWait, OsContext &osContext) override; void overrideMediaVFEStateDirty(bool dirty) override; DrmMemoryManager *getMemoryManager(); diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 83901f9e9f..3596155afb 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -56,7 +56,7 @@ DrmCommandStreamReceiver::DrmCommandStreamReceiver(const HardwareInfo } template -FlushStamp DrmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) { +FlushStamp DrmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) { unsigned int engineFlag = 0xFF; bool ret = DrmEngineMapper::engineNodeMap(engineType, engineFlag); UNRECOVERABLE_IF(!(ret)); @@ -70,7 +70,7 @@ FlushStamp DrmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, if (bb) { flushStamp = bb->peekHandle(); - this->processResidency(allocationsForResidency); + this->processResidency(allocationsForResidency, osContext); // Residency hold all allocation except command buffer, hence + 1 auto requiredSize = this->residency.size() + 1; if (requiredSize > this->execObjectsStorage.size()) { @@ -118,7 +118,7 @@ void DrmCommandStreamReceiver::makeResident(BufferObject *bo) { } template -void DrmCommandStreamReceiver::processResidency(ResidencyContainer *inputAllocationsForResidency) { +void DrmCommandStreamReceiver::processResidency(ResidencyContainer *inputAllocationsForResidency, OsContext &osContext) { auto &allocationsForResidency = inputAllocationsForResidency ? *inputAllocationsForResidency : getMemoryManager()->getResidencyAllocations(); for (uint32_t a = 0; a < allocationsForResidency.size(); a++) { DrmAllocation *drmAlloc = reinterpret_cast(allocationsForResidency[a]); @@ -168,7 +168,7 @@ MemoryManager *DrmCommandStreamReceiver::createMemoryManager(bool ena } template -bool DrmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStamp) { +bool DrmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStamp, OsContext &osContext) { drm_i915_gem_wait wait = {}; wait.bo_handle = static_cast(flushStamp); wait.timeout_ns = -1; diff --git a/runtime/os_interface/linux/os_context_linux.cpp b/runtime/os_interface/linux/os_context_linux.cpp index 1b10aa2606..ea5858c0ee 100644 --- a/runtime/os_interface/linux/os_context_linux.cpp +++ b/runtime/os_interface/linux/os_context_linux.cpp @@ -24,7 +24,7 @@ namespace OCLRT { class OsContext::OsContextImpl {}; -OsContext::OsContext(OSInterface &osInterface) { +OsContext::OsContext(OSInterface *osInterface) { osContextImpl = std::make_unique(); } diff --git a/runtime/os_interface/os_context.h b/runtime/os_interface/os_context.h index 73297f1f42..0e817e711d 100644 --- a/runtime/os_interface/os_context.h +++ b/runtime/os_interface/os_context.h @@ -21,14 +21,16 @@ */ #pragma once +#include "runtime/utilities/reference_tracked_object.h" #include + namespace OCLRT { class OSInterface; -class OsContext { +class OsContext : public ReferenceTrackedObject { public: class OsContextImpl; - OsContext(OSInterface &osInterface); - ~OsContext(); + OsContext(OSInterface *osInterface); + ~OsContext() override; OsContextImpl *get() const { return osContextImpl.get(); }; diff --git a/runtime/os_interface/windows/deferrable_deletion_win.cpp b/runtime/os_interface/windows/deferrable_deletion_win.cpp index ca28eff919..764ffd9135 100644 --- a/runtime/os_interface/windows/deferrable_deletion_win.cpp +++ b/runtime/os_interface/windows/deferrable_deletion_win.cpp @@ -30,10 +30,10 @@ DeferrableDeletion *DeferrableDeletion::create(Args... args) { return new DeferrableDeletionImpl(std::forward(args)...); } template DeferrableDeletion *DeferrableDeletion::create(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, - D3DKMT_HANDLE resourceHandle); + D3DKMT_HANDLE resourceHandle, OsContextWin *osContext); DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, - D3DKMT_HANDLE resourceHandle) { + D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) : osContext(osContext) { this->wddm = wddm; if (handles) { this->handles = new D3DKMT_HANDLE[allocationCount]; @@ -46,7 +46,7 @@ DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handle this->resourceHandle = resourceHandle; } void DeferrableDeletionImpl::apply() { - bool destroyStatus = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle); + bool destroyStatus = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle, osContext); DEBUG_BREAK_IF(!destroyStatus); } DeferrableDeletionImpl::~DeferrableDeletionImpl() { diff --git a/runtime/os_interface/windows/deferrable_deletion_win.h b/runtime/os_interface/windows/deferrable_deletion_win.h index e9364d6ade..3e7061efa6 100644 --- a/runtime/os_interface/windows/deferrable_deletion_win.h +++ b/runtime/os_interface/windows/deferrable_deletion_win.h @@ -22,6 +22,7 @@ #pragma once #include "runtime/memory_manager/deferrable_deletion.h" +#include "runtime/os_interface/os_context.h" #include "runtime/os_interface/windows/windows_wrapper.h" #include @@ -29,10 +30,12 @@ namespace OCLRT { class Wddm; +using OsContextWin = OsContext::OsContextImpl; + class DeferrableDeletionImpl : public DeferrableDeletion { public: DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, - D3DKMT_HANDLE resourceHandle); + D3DKMT_HANDLE resourceHandle, OsContextWin *osContext); void apply() override; ~DeferrableDeletionImpl(); @@ -45,5 +48,6 @@ class DeferrableDeletionImpl : public DeferrableDeletion { uint32_t allocationCount; uint64_t lastFenceValue; D3DKMT_HANDLE resourceHandle; + OsContextWin *osContext = nullptr; }; } // namespace OCLRT diff --git a/runtime/os_interface/windows/os_context_win.cpp b/runtime/os_interface/windows/os_context_win.cpp index 1df0005467..6a28072928 100644 --- a/runtime/os_interface/windows/os_context_win.cpp +++ b/runtime/os_interface/windows/os_context_win.cpp @@ -28,10 +28,8 @@ namespace OCLRT { OsContextWin::OsContextImpl(Wddm &wddm) : wddm(wddm) { + UNRECOVERABLE_IF(!wddm.isInitialized()); auto wddmInterface = wddm.getWddmInterface(); - if (!wddmInterface) { - return; - } if (!wddm.createContext(context)) { return; } @@ -43,9 +41,7 @@ OsContextWin::OsContextImpl(Wddm &wddm) : wddm(wddm) { initialized = wddmInterface->createMonitoredFence(*this); }; OsContextWin::~OsContextImpl() { - if (wddm.getWddmInterface()) { - wddm.getWddmInterface()->destroyHwQueue(hwQueueHandle); - } + wddm.getWddmInterface()->destroyHwQueue(hwQueueHandle); wddm.destroyContext(context); } @@ -57,8 +53,10 @@ void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cp monitoredFence.gpuAddress = gpuAddress; } -OsContext::OsContext(OSInterface &osInterface) { - osContextImpl = std::make_unique(*osInterface.get()->getWddm()); +OsContext::OsContext(OSInterface *osInterface) { + if (osInterface) { + osContextImpl = std::make_unique(*osInterface->get()->getWddm()); + } } OsContext::~OsContext() = default; diff --git a/runtime/os_interface/windows/os_context_win.h b/runtime/os_interface/windows/os_context_win.h index 2c0d9c7fcd..6025daf7f8 100644 --- a/runtime/os_interface/windows/os_context_win.h +++ b/runtime/os_interface/windows/os_context_win.h @@ -49,6 +49,7 @@ class OsContext::OsContextImpl { } MonitoredFence &getMonitoredFence() { return monitoredFence; } void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress); + Wddm *getWddm() const { return &wddm; } protected: bool initialized = false; diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index b6a83e4f6e..7c4e12cff3 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -539,11 +539,13 @@ NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) { return status; } -bool Wddm::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle) { +bool Wddm::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) { NTSTATUS status = STATUS_SUCCESS; D3DKMT_DESTROYALLOCATION2 DestroyAllocation = {0}; DEBUG_BREAK_IF(!(allocationCount <= 1 || resourceHandle == 0)); - waitFromCpu(lastFenceValue); + if (lastFenceValue > 0) { + waitFromCpu(lastFenceValue, *osContext); + } DestroyAllocation.hDevice = device; DestroyAllocation.hResource = resourceHandle; @@ -711,17 +713,17 @@ bool Wddm::destroyContext(D3DKMT_HANDLE context) { return status == STATUS_SUCCESS; } -bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader) { +bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) { bool status = false; - if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU(osContext->getContext())) { + if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU(osContext.getContext())) { return false; } - DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext->getMonitoredFence().currentFenceValue); + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.getMonitoredFence().currentFenceValue); - status = wddmInterface->submit(commandBuffer, size, commandHeader, *osContext); + status = wddmInterface->submit(commandBuffer, size, commandHeader, osContext); if (status) { - osContext->getMonitoredFence().lastSubmittedFence = osContext->getMonitoredFence().currentFenceValue; - osContext->getMonitoredFence().currentFenceValue++; + osContext.getMonitoredFence().lastSubmittedFence = osContext.getMonitoredFence().currentFenceValue; + osContext.getMonitoredFence().currentFenceValue++; } getDeviceState(); UNRECOVERABLE_IF(!status); @@ -746,10 +748,10 @@ void Wddm::getDeviceState() { #endif } -void Wddm::handleCompletion() { - if (osContext->getMonitoredFence().cpuAddress) { - auto *currentTag = osContext->getMonitoredFence().cpuAddress; - while (*currentTag < osContext->getMonitoredFence().currentFenceValue - 1) +void Wddm::handleCompletion(OsContextWin &osContext) { + if (osContext.getMonitoredFence().cpuAddress) { + auto *currentTag = osContext.getMonitoredFence().cpuAddress; + while (*currentTag < osContext.getMonitoredFence().currentFenceValue - 1) ; } } @@ -772,13 +774,13 @@ bool Wddm::waitOnGPU(D3DKMT_HANDLE context) { return status == STATUS_SUCCESS; } -bool Wddm::waitFromCpu(uint64_t lastFenceValue) { +bool Wddm::waitFromCpu(uint64_t lastFenceValue, OsContextWin &osContext) { NTSTATUS status = STATUS_SUCCESS; - if (lastFenceValue > *osContext->getMonitoredFence().cpuAddress) { + if (lastFenceValue > *osContext.getMonitoredFence().cpuAddress) { D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU waitFromCpu = {0}; waitFromCpu.ObjectCount = 1; - waitFromCpu.ObjectHandleArray = &osContext->getMonitoredFence().fenceHandle; + waitFromCpu.ObjectHandleArray = &osContext.getMonitoredFence().fenceHandle; waitFromCpu.FenceValueArray = &lastFenceValue; waitFromCpu.hDevice = device; waitFromCpu.hAsyncEvent = NULL; @@ -884,11 +886,6 @@ void *Wddm::virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned int Wddm::virtualFree(void *ptr, size_t size, unsigned long flags) { return virtualFreeFnc(ptr, size, flags); } -MonitoredFence &Wddm::getMonitoredFence() { return osContext->getMonitoredFence(); } - -D3DKMT_HANDLE Wddm::getOsDeviceContext() const { - return osContext->getContext(); -} bool Wddm::configureDeviceAddressSpace() { SYSTEM_INFO sysInfo; @@ -927,11 +924,7 @@ bool Wddm::init() { if (!gmmMemory) { gmmMemory.reset(GmmMemory::create()); } - if (!configureDeviceAddressSpace()) { - return false; - } - osContext = std::make_unique(*this); - initialized = osContext->isInitialized(); + initialized = configureDeviceAddressSpace(); } return initialized; } diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index 5625277680..f40ad0895f 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -78,7 +78,7 @@ class Wddm { MOCKABLE_VIRTUAL NTSTATUS createAllocation(WddmAllocation *alloc); MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc); MOCKABLE_VIRTUAL NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles); - MOCKABLE_VIRTUAL bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle); + MOCKABLE_VIRTUAL bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext); MOCKABLE_VIRTUAL bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc); bool openNTHandle(HANDLE handle, WddmAllocation *alloc); MOCKABLE_VIRTUAL void *lockResource(WddmAllocation *wddmAllocation); @@ -89,8 +89,8 @@ class Wddm { MOCKABLE_VIRTUAL bool destroyContext(D3DKMT_HANDLE context); MOCKABLE_VIRTUAL bool queryAdapterInfo(); - MOCKABLE_VIRTUAL bool submit(uint64_t commandBuffer, size_t size, void *commandHeader); - MOCKABLE_VIRTUAL bool waitFromCpu(uint64_t lastFenceValue); + MOCKABLE_VIRTUAL bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext); + MOCKABLE_VIRTUAL bool waitFromCpu(uint64_t lastFenceValue, OsContextWin &osContext); NTSTATUS escape(D3DKMT_ESCAPE &escapeCommand); void registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, WddmMemoryManager *memoryManager); @@ -121,8 +121,6 @@ class Wddm { return deviceRegistryPath; } - MonitoredFence &getMonitoredFence(); - uint64_t getSystemSharedMemory() const; uint64_t getMaxApplicationAddress() const; @@ -165,7 +163,6 @@ class Wddm { PreemptionMode getPreemptionMode() const { return preemptionMode; } - D3DKMT_HANDLE getOsDeviceContext() const; unsigned int readEnablePreemptionRegKey(); @@ -210,7 +207,7 @@ class Wddm { bool destroyDevice(); bool closeAdapter(); void getDeviceState(); - void handleCompletion(); + void handleCompletion(OsContextWin &osContext); static CreateDXGIFactoryFcn createDxgiFactory; static GetSystemInfoFcn getSystemInfo; @@ -221,6 +218,5 @@ class Wddm { std::unique_ptr kmDafListener; std::unique_ptr wddmInterface; - std::unique_ptr osContext; }; } // namespace OCLRT diff --git a/runtime/os_interface/windows/wddm/wddm_interface.cpp b/runtime/os_interface/windows/wddm/wddm_interface.cpp index ef7bebd54c..4bd565340e 100644 --- a/runtime/os_interface/windows/wddm/wddm_interface.cpp +++ b/runtime/os_interface/windows/wddm/wddm_interface.cpp @@ -56,7 +56,7 @@ bool OCLRT::WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *c D3DKMT_SUBMITCOMMAND SubmitCommand = {0}; NTSTATUS status = STATUS_SUCCESS; - auto monitoredFence = wddm.getMonitoredFence(); + auto monitoredFence = osContext.getMonitoredFence(); SubmitCommand.Commands = commandBuffer; SubmitCommand.CommandLength = static_cast(size); SubmitCommand.BroadcastContextCount = 1; @@ -119,7 +119,7 @@ const bool OCLRT::WddmInterface23::hwQueuesSupported() { } bool OCLRT::WddmInterface23::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) { - auto monitoredFence = wddm.getMonitoredFence(); + auto monitoredFence = osContext.getMonitoredFence(); D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {}; submitCommand.hHwQueue = osContext.getHwQueue(); diff --git a/runtime/os_interface/windows/wddm_device_command_stream.h b/runtime/os_interface/windows/wddm_device_command_stream.h index 482c9f7e47..4562e84e41 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.h +++ b/runtime/os_interface/windows/wddm_device_command_stream.h @@ -40,11 +40,11 @@ class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, Wddm *wddm, ExecutionEnvironment &executionEnvironment); virtual ~WddmCommandStreamReceiver(); - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeResident(GraphicsAllocation &gfxAllocation) override; - void processResidency(ResidencyContainer *allocationsForResidency) override; + void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void processEviction() override; - bool waitForFlushStamp(FlushStamp &flushStampToWait) override; + bool waitForFlushStamp(FlushStamp &flushStampToWait, OsContext &osContext) override; WddmMemoryManager *getMemoryManager(); MemoryManager *createMemoryManager(bool enable64kbPages); diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index d5e9ee6da6..cb248a1b0b 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -39,6 +39,7 @@ #undef max #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" #include "runtime/os_interface/windows/wddm_engine_mapper.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" @@ -59,6 +60,7 @@ WddmCommandStreamReceiver::WddmCommandStreamReceiver(const HardwareIn this->wddm->setNode(nodeOrdinal); PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoIn); this->wddm->setPreemptionMode(preemptionMode); + executionEnvironment.osInterface.reset(new OSInterface()); this->osInterface = executionEnvironment.osInterface.get(); this->osInterface->get()->setWddm(this->wddm); @@ -89,7 +91,7 @@ WddmCommandStreamReceiver::~WddmCommandStreamReceiver() { template FlushStamp WddmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, - EngineType engineType, ResidencyContainer *allocationsForResidency) { + EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) { auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset); if (this->dispatchMode == DispatchMode::ImmediateDispatch) { @@ -99,7 +101,7 @@ FlushStamp WddmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, batchBuffer.commandBufferAllocation->residencyTaskCount = this->taskCount; } - this->processResidency(allocationsForResidency); + this->processResidency(allocationsForResidency, osContext); COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandBufferHeader); pHeader->RequiresCoherency = batchBuffer.requiresCoherency; @@ -124,9 +126,9 @@ FlushStamp WddmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, this->kmDafLockAllocations(allocationsForResidency); } - wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader); + wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContext.get()); - return wddm->getMonitoredFence().lastSubmittedFence; + return osContext.get()->getMonitoredFence().lastSubmittedFence; } template @@ -145,8 +147,8 @@ void WddmCommandStreamReceiver::makeResident(GraphicsAllocation &gfxA } template -void WddmCommandStreamReceiver::processResidency(ResidencyContainer *allocationsForResidency) { - bool success = getMemoryManager()->makeResidentResidencyAllocations(allocationsForResidency); +void WddmCommandStreamReceiver::processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) { + bool success = getMemoryManager()->makeResidentResidencyAllocations(allocationsForResidency, osContext); DEBUG_BREAK_IF(!success); } @@ -167,8 +169,8 @@ MemoryManager *WddmCommandStreamReceiver::createMemoryManager(bool en } template -bool WddmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStampToWait) { - return wddm->waitFromCpu(flushStampToWait); +bool WddmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStampToWait, OsContext &osContext) { + return wddm->waitFromCpu(flushStampToWait, *osContext.get()); } template diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 70d6eb89b0..c41ea76908 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -33,6 +33,8 @@ #include "runtime/memory_manager/deferred_deleter.h" #include "runtime/os_interface/windows/wddm/wddm.h" #include "runtime/os_interface/windows/wddm_allocation.h" +#include "runtime/os_interface/windows/os_context_win.h" +#include "runtime/platform/platform.h" #include namespace OCLRT { @@ -324,7 +326,11 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation unlockResource(input); input->setLocked(false); } - auto status = tryDeferDeletions(allocationHandles, allocationCount, input->getResidencyData().lastFence, resourceHandle); + OsContextWin *osContextWin = nullptr; + if (input->getResidencyData().osContext) { + osContextWin = input->getResidencyData().osContext->get(); + } + auto status = tryDeferDeletions(allocationHandles, allocationCount, input->getResidencyData().lastFence, resourceHandle, osContextWin); DEBUG_BREAK_IF(!status); alignedFreeWrapper(cpuPtr); } @@ -332,12 +338,12 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation delete gfxAllocation; } -bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle) { +bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) { bool status = true; if (deferredDeleter) { - deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, lastFenceValue, resourceHandle)); + deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, lastFenceValue, resourceHandle, osContext)); } else { - status = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle); + status = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle, osContext); } return status; } @@ -385,6 +391,7 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) { auto allocationCount = 0; uint64_t lastFenceValue = 0; + OsContext *osContext = nullptr; for (unsigned int i = 0; i < max_fragments_count; i++) { if (handleStorage.fragmentStorageData[i].freeTheFragment) { @@ -392,10 +399,15 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) { handleStorage.fragmentStorageData[i].residency->resident = false; allocationCount++; lastFenceValue = std::max(handleStorage.fragmentStorageData[i].residency->lastFence, lastFenceValue); + osContext = handleStorage.fragmentStorageData[i].residency->osContext; } } - bool success = tryDeferDeletions(handles, allocationCount, lastFenceValue, 0); + OsContextWin *osContextWin = nullptr; + if (osContext) { + osContextWin = osContext->get(); + } + bool success = tryDeferDeletions(handles, allocationCount, lastFenceValue, 0, osContextWin); for (unsigned int i = 0; i < max_fragments_count; i++) { if (handleStorage.fragmentStorageData[i].freeTheFragment) { @@ -445,7 +457,7 @@ uint64_t WddmMemoryManager::getInternalHeapBaseAddress() { return this->wddm->getGfxPartition().Heap32[1].Base; } -bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer *allocationsForResidency) { +bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer *allocationsForResidency, OsContext &osContext) { auto &residencyAllocations = allocationsForResidency ? *allocationsForResidency : this->residencyAllocations; @@ -456,7 +468,7 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer *all acquireResidencyLock(); - DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", wddm->getMonitoredFence().currentFenceValue); + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.get()->getMonitoredFence().currentFenceValue); for (uint32_t i = 0; i < residencyCount; i++) { WddmAllocation *allocation = reinterpret_cast(residencyAllocations[i]); @@ -511,13 +523,16 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer *all for (uint32_t i = 0; i < residencyCount; i++) { WddmAllocation *allocation = reinterpret_cast(residencyAllocations[i]); // Update fence value not to early destroy / evict allocation - allocation->getResidencyData().lastFence = wddm->getMonitoredFence().currentFenceValue; + allocation->getResidencyData().addOsContext(&osContext); + allocation->getResidencyData().lastFence = osContext.get()->getMonitoredFence().currentFenceValue; allocation->getResidencyData().resident = true; for (uint32_t allocationId = 0; allocationId < allocation->fragmentsStorage.fragmentCount; allocationId++) { - allocation->fragmentsStorage.fragmentStorageData[allocationId].residency->resident = true; + auto residencyData = allocation->fragmentsStorage.fragmentStorageData[allocationId].residency; + residencyData->addOsContext(&osContext); + residencyData->resident = allocation->getResidencyData().resident; // Update fence value not to remove the fragment referenced by different GA in trimming callback - allocation->fragmentsStorage.fragmentStorageData[allocationId].residency->lastFence = wddm->getMonitoredFence().currentFenceValue; + residencyData->lastFence = allocation->getResidencyData().lastFence; } } } @@ -635,6 +650,7 @@ void WddmMemoryManager::compactTrimCandidateList() { } void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint64_t bytes) { + OsContext *osContext = nullptr; if (flags.PeriodicTrim) { bool periodicTrimDone = false; D3DKMT_HANDLE fragmentEvictHandles[3] = {0}; @@ -648,7 +664,7 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6 DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "lastPeriodicTrimFenceValue = ", lastPeriodicTrimFenceValue); // allocation was not used from last periodic trim - if ((wddmAllocation)->getResidencyData().lastFence <= lastPeriodicTrimFenceValue) { + if (wddmAllocation->getResidencyData().lastFence <= lastPeriodicTrimFenceValue) { DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation: handle =", wddmAllocation->handle, "lastFence =", (wddmAllocation)->getResidencyData().lastFence); @@ -674,6 +690,7 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6 } wddmAllocation->getResidencyData().resident = false; + osContext = wddmAllocation->getResidencyData().osContext; removeFromTrimCandidateList(wddmAllocation); } else { periodicTrimDone = true; @@ -698,7 +715,10 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6 } if (flags.PeriodicTrim || flags.RestartPeriodicTrim) { - lastPeriodicTrimFenceValue = *wddm->getMonitoredFence().cpuAddress; + if (!osContext) { + osContext = platform()->getDevice(0)->getOsContext(); + } + lastPeriodicTrimFenceValue = *osContext->get()->getMonitoredFence().cpuAddress; DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "updated lastPeriodicTrimFenceValue =", lastPeriodicTrimFenceValue); } } @@ -739,14 +759,20 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) { } lastFence = wddmAllocation->getResidencyData().lastFence; + auto osContext = wddmAllocation->getResidencyData().osContext; + if (!osContext) { + removeFromTrimCandidateList(wddmAllocation); + continue; + } + auto &monitoredFence = osContext->get()->getMonitoredFence(); - if (lastFence <= wddm->getMonitoredFence().lastSubmittedFence) { + if (lastFence <= monitoredFence.lastSubmittedFence) { uint32_t fragmentsToEvict = 0; uint64_t sizeEvicted = 0; uint64_t sizeToTrim = 0; - if (lastFence > *wddm->getMonitoredFence().cpuAddress) { - wddm->waitFromCpu(lastFence); + if (lastFence > *monitoredFence.cpuAddress) { + wddm->waitFromCpu(lastFence, *osContext->get()); } if (wddmAllocation->fragmentsStorage.fragmentCount == 0) { @@ -754,9 +780,10 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) { sizeEvicted = wddmAllocation->getAlignedSize(); } else { + auto &fragmentStorageData = wddmAllocation->fragmentsStorage.fragmentStorageData; for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) { - if (wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->lastFence <= wddm->getMonitoredFence().lastSubmittedFence) { - fragmentEvictHandles[fragmentsToEvict++] = wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle; + if (fragmentStorageData[allocationId].residency->lastFence <= monitoredFence.lastSubmittedFence) { + fragmentEvictHandles[fragmentsToEvict++] = fragmentStorageData[allocationId].osHandleStorage->handle; } } @@ -764,9 +791,9 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) { wddm->evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim); for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) { - if (wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->lastFence <= wddm->getMonitoredFence().lastSubmittedFence) { - wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->resident = false; - sizeEvicted += wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].fragmentSize; + if (fragmentStorageData[allocationId].residency->lastFence <= monitoredFence.lastSubmittedFence) { + fragmentStorageData[allocationId].residency->resident = false; + sizeEvicted += fragmentStorageData[allocationId].fragmentSize; } } } @@ -815,7 +842,7 @@ bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, Allocat mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr(), allocation->is32BitAllocation, false, useHeap1); } if (!mapSuccess) { - wddm->destroyAllocations(&allocation->handle, 1, 0, allocation->resourceHandle); + wddm->destroyAllocations(&allocation->handle, 1, 0, allocation->resourceHandle, nullptr); wddmSuccess = STATUS_UNSUCCESSFUL; } allocation->setGpuAddress(allocation->gpuPtr); diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index 87d94cf95c..ba5243bfb9 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -23,6 +23,7 @@ #pragma once #include "runtime/helpers/aligned_memory.h" #include "runtime/memory_manager/memory_manager.h" +#include "runtime/os_interface/os_context.h" #include "runtime/os_interface/windows/wddm_allocation.h" #include "runtime/os_interface/windows/windows_wrapper.h" #include @@ -34,6 +35,8 @@ namespace OCLRT { class Gmm; class Wddm; +using OsContextWin = OsContext::OsContextImpl; + class WddmMemoryManager : public MemoryManager { public: using MemoryManager::allocateGraphicsMemory; @@ -60,7 +63,7 @@ class WddmMemoryManager : public MemoryManager { void *lockResource(GraphicsAllocation *graphicsAllocation) override; void unlockResource(GraphicsAllocation *graphicsAllocation) override; - bool makeResidentResidencyAllocations(ResidencyContainer *allocationsForResidency); + bool makeResidentResidencyAllocations(ResidencyContainer *allocationsForResidency, OsContext &osContext); void makeNonResidentEvictionAllocations(); AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override; @@ -89,7 +92,7 @@ class WddmMemoryManager : public MemoryManager { residencyLock = false; } - bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle); + bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext); bool isMemoryBudgetExhausted() const override { return memoryBudgetExhausted; } diff --git a/unit_tests/aub_tests/command_stream/aub_command_stream_tests.cpp b/unit_tests/aub_tests/command_stream/aub_command_stream_tests.cpp index 87a78f8545..6fd628d7fa 100644 --- a/unit_tests/aub_tests/command_stream/aub_command_stream_tests.cpp +++ b/unit_tests/aub_tests/command_stream/aub_command_stream_tests.cpp @@ -70,7 +70,7 @@ struct AUBFixture : public AUBCommandStreamFixture, CommandStreamReceiverHw::alignToCacheLine(*pCS); BatchBuffer batchBuffer{pCS->getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, pCS->getUsed(), pCS}; ResidencyContainer allocationsForResidency; - pCommandStreamReceiver->flush(batchBuffer, engineType, &allocationsForResidency); + pCommandStreamReceiver->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); auto mmioBase = AUBCommandStreamReceiverHw::getCsTraits(engineType).mmioBase; AUBCommandStreamFixture::expectMMIO(mmioBase + 0x2094, noopId); @@ -84,10 +84,10 @@ HWTEST_F(AUBcommandstreamTests, testFlushTwice) { CommandStreamReceiverHw::alignToCacheLine(*pCS); BatchBuffer batchBuffer{pCS->getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, pCS->getUsed(), pCS}; ResidencyContainer allocationsForResidency; - pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency); + pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency, *pDevice->getOsContext()); BatchBuffer batchBuffer2{pCS->getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, pCS->getUsed(), pCS}; ResidencyContainer allocationsForResidency2; - pCommandStreamReceiver->flush(batchBuffer2, EngineType::ENGINE_RCS, &allocationsForResidency); + pCommandStreamReceiver->flush(batchBuffer2, EngineType::ENGINE_RCS, &allocationsForResidency, *pDevice->getOsContext()); } HWTEST_F(AUBcommandstreamTests, testNoopIdRcs) { @@ -112,7 +112,7 @@ TEST_F(AUBcommandstreamTests, makeResident) { auto &commandStreamReceiver = pDevice->getCommandStreamReceiver(); auto graphicsAllocation = commandStreamReceiver.createAllocationAndHandleResidency(buffer, size); ResidencyContainer allocationsForResidency = {graphicsAllocation}; - commandStreamReceiver.processResidency(&allocationsForResidency); + commandStreamReceiver.processResidency(&allocationsForResidency, *pDevice->getOsContext()); } HWTEST_F(AUBcommandstreamTests, expectMemorySingle) { @@ -121,7 +121,7 @@ HWTEST_F(AUBcommandstreamTests, expectMemorySingle) { auto &commandStreamReceiver = pDevice->getCommandStreamReceiver(); auto graphicsAllocation = commandStreamReceiver.createAllocationAndHandleResidency(&buffer, size); ResidencyContainer allocationsForResidency = {graphicsAllocation}; - commandStreamReceiver.processResidency(&allocationsForResidency); + commandStreamReceiver.processResidency(&allocationsForResidency, *pDevice->getOsContext()); AUBCommandStreamFixture::expectMemory(&buffer, &buffer, size); } @@ -137,7 +137,7 @@ HWTEST_F(AUBcommandstreamTests, expectMemoryLarge) { auto &commandStreamReceiver = pDevice->getCommandStreamReceiver(); auto graphicsAllocation = commandStreamReceiver.createAllocationAndHandleResidency(buffer, sizeBuffer); ResidencyContainer allocationsForResidency = {graphicsAllocation}; - commandStreamReceiver.processResidency(&allocationsForResidency); + commandStreamReceiver.processResidency(&allocationsForResidency, *pDevice->getOsContext()); AUBCommandStreamFixture::expectMemory(buffer, buffer, sizeBuffer); delete[] buffer; diff --git a/unit_tests/command_queue/drm_requirements_tests.cpp b/unit_tests/command_queue/drm_requirements_tests.cpp index ea6861ba5c..af6bc1b20c 100644 --- a/unit_tests/command_queue/drm_requirements_tests.cpp +++ b/unit_tests/command_queue/drm_requirements_tests.cpp @@ -40,7 +40,7 @@ class CommandStreamReceiverDrmMock : public UltCommandStreamReceiver std::vector toFree; // pointers to be freed on destruction public: - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { EXPECT_NE(nullptr, batchBuffer.commandBufferAllocation->getUnderlyingBuffer()); toFree.push_back(batchBuffer.commandBufferAllocation); diff --git a/unit_tests/command_queue/enqueue_thread_tests.cpp b/unit_tests/command_queue/enqueue_thread_tests.cpp index 50bd51d7f3..5db6bbd8f0 100644 --- a/unit_tests/command_queue/enqueue_thread_tests.cpp +++ b/unit_tests/command_queue/enqueue_thread_tests.cpp @@ -48,7 +48,7 @@ class CommandStreamReceiverMock : public UltCommandStreamReceiver { this->pDevice = pDevice; } - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { EXPECT_NE(nullptr, batchBuffer.commandBufferAllocation->getUnderlyingBuffer()); toFree.push_back(batchBuffer.commandBufferAllocation); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp index d674cda409..bfac1e1243 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -304,7 +304,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(nullptr, aubCsr->engineInfoTable[engineType].pLRCA); EXPECT_NE(nullptr, aubCsr->engineInfoTable[engineType].pGlobalHWStatusPage); EXPECT_NE(nullptr, aubCsr->engineInfoTable[engineType].pRingBuffer); @@ -325,7 +325,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_EQ(nullptr, aubCsr->engineInfoTable[engineType].pLRCA); EXPECT_EQ(nullptr, aubCsr->engineInfoTable[engineType].pGlobalHWStatusPage); EXPECT_EQ(nullptr, aubCsr->engineInfoTable[engineType].pRingBuffer); @@ -343,12 +343,12 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs // First flush typically includes a preamble and chain to command buffer aubCsr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); - aubCsr->flush(batchBuffer, engineType, nullptr); + aubCsr->flush(batchBuffer, engineType, nullptr, *pDevice->getOsContext()); EXPECT_EQ(0ull, aubCsr->engineInfoTable[engineType].tailRingBuffer % ringTailAlignment); // Second flush should just submit command buffer cs.getSpace(sizeof(uint64_t)); - aubCsr->flush(batchBuffer, engineType, nullptr); + aubCsr->flush(batchBuffer, engineType, nullptr, *pDevice->getOsContext()); EXPECT_EQ(0ull, aubCsr->engineInfoTable[engineType].tailRingBuffer % ringTailAlignment); } @@ -367,7 +367,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); @@ -388,7 +388,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_EQ(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); } @@ -413,7 +413,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_EQ(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); } @@ -438,7 +438,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); @@ -465,7 +465,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_FALSE(aubCsr->subCaptureManager->isSubCaptureEnabled()); } @@ -482,7 +482,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); aubCsr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); - aubCsr->flush(batchBuffer, engineType, nullptr); + aubCsr->flush(batchBuffer, engineType, nullptr, *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, commandBuffer->residencyTaskCount); EXPECT_EQ((int)aubCsr->peekTaskCount() + 1, commandBuffer->residencyTaskCount); @@ -502,7 +502,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNoneStand EXPECT_EQ(ObjectNotResident, aubExecutionEnvironment->commandBuffer->residencyTaskCount); - aubCsr->flush(batchBuffer, engineType, nullptr); + aubCsr->flush(batchBuffer, engineType, nullptr, *pDevice->getOsContext()); EXPECT_EQ(ObjectNotResident, aubExecutionEnvironment->commandBuffer->residencyTaskCount); } @@ -525,7 +525,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); aubCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ((int)aubCsr->peekTaskCount() + 1, gfxAllocation->residencyTaskCount); @@ -557,7 +557,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNoneStand EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); @@ -594,7 +594,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); aubCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ((int)aubCsr->peekTaskCount() + 1, gfxAllocation->residencyTaskCount); @@ -629,7 +629,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess auto gfxDefaultAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ResidencyContainer allocationsForResidency = {gfxDefaultAllocation}; - aubCsr->processResidency(&allocationsForResidency); + aubCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(gfxDefaultAllocation->isAubWritable()); @@ -671,7 +671,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); ResidencyContainer allocationsForResidency = {gfxBufferAllocation, gfxImageAllocation}; - aubCsr->processResidency(&allocationsForResidency); + aubCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_FALSE(gfxBufferAllocation->isAubWritable()); EXPECT_FALSE(gfxImageAllocation->isAubWritable()); @@ -697,7 +697,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur aubCsr->dumpAubNonWritable = true; ResidencyContainer allocationsForResidency = {gfxBufferAllocation, gfxImageAllocation}; - aubCsr->processResidency(&allocationsForResidency); + aubCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(gfxBufferAllocation->isAubWritable()); EXPECT_TRUE(gfxImageAllocation->isAubWritable()); @@ -723,7 +723,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess aubCsr->dumpAubNonWritable = false; ResidencyContainer allocationsForResidency = {gfxBufferAllocation, gfxImageAllocation}; - aubCsr->processResidency(&allocationsForResidency); + aubCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_FALSE(gfxBufferAllocation->isAubWritable()); EXPECT_FALSE(gfxImageAllocation->isAubWritable()); @@ -1260,7 +1260,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefault ResidencyContainer allocationsForResidency = {}; EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).Times(0); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndImmediateDispatchModeThenExpectFlattenBatchBufferIsCalled) { @@ -1286,7 +1286,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF std::unique_ptr ptr(alignedMalloc(4096, 4096), alignedFree); EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).WillOnce(::testing::Return(ptr.release())); - aubCsr->flush(batchBuffer, engineType, nullptr); + aubCsr->flush(batchBuffer, engineType, nullptr, *pDevice->getOsContext()); aubExecutionEnvironment->executionEnvironment->memoryManager->freeGraphicsMemory(chainedBatchBuffer); } @@ -1307,7 +1307,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto engineType = OCLRT::ENGINE_RCS; EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).Times(1); - aubCsr->flush(batchBuffer, engineType, nullptr); + aubCsr->flush(batchBuffer, engineType, nullptr, *pDevice->getOsContext()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndBatchedDispatchModeThenExpectFlattenBatchBufferIsCalledAnyway) { @@ -1327,7 +1327,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto engineType = OCLRT::ENGINE_RCS; EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).Times(1); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatchInfoCommentsForAUBDumpIsSetThenAddPatchInfoCommentsIsCalled) { @@ -1343,7 +1343,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc ResidencyContainer allocationsForResidency; EXPECT_CALL(*aubCsr, addPatchInfoComments()).Times(1); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatchInfoCommentsForAUBDumpIsNotSetThenAddPatchInfoCommentsIsNotCalled) { @@ -1356,7 +1356,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc ResidencyContainer allocationsForResidency; EXPECT_CALL(*aubCsr, addPatchInfoComments()).Times(0); - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenNoPatchInfoDataObjectsThenCommentsAreEmpty) { @@ -1402,7 +1402,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(mockAubFileStreamPtr->flushCalled); mockAubFileStream.swap(aubCsr->stream); @@ -1875,7 +1875,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess ASSERT_EQ(1u, aubCsr->externalAllocations.size()); ResidencyContainer allocationsForResidency; - aubCsr->processResidency(&allocationsForResidency); + aubCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(aubCsr->writeMemoryParametrization.wasCalled); EXPECT_EQ(addr, aubCsr->writeMemoryParametrization.receivedAllocationView.first); @@ -1890,7 +1890,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess ASSERT_EQ(1u, aubCsr->externalAllocations.size()); ResidencyContainer allocationsForResidency; - aubCsr->processResidency(&allocationsForResidency); + aubCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(aubCsr->writeMemoryParametrization.wasCalled); EXPECT_EQ(0u, aubCsr->writeMemoryParametrization.receivedAllocationView.first); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp index 5e98705b3b..ccffe5055f 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp @@ -774,7 +774,7 @@ struct CommandStreamReceiverHwLog : public UltCommandStreamReceiver flushCount(0) { } - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { ++flushCount; return 0; } diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index f122ad0482..7d826c442c 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -255,7 +255,7 @@ TEST_F(CommandStreamReceiverTest, makeResidentPushesAllocationToMemoryManagerRes TEST_F(CommandStreamReceiverTest, makeResidentWithoutParametersDoesNothing) { auto *memoryManager = commandStreamReceiver->getMemoryManager(); - commandStreamReceiver->processResidency(nullptr); + commandStreamReceiver->processResidency(nullptr, *pDevice->getOsContext()); auto &residencyAllocations = memoryManager->getResidencyAllocations(); EXPECT_EQ(0u, residencyAllocations.size()); } diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index 3b79406362..fc534b3dcc 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -34,7 +34,7 @@ struct MyMockCsr : UltCommandStreamReceiver { MyMockCsr(const HardwareInfo &hwInfoIn, void *ptr, ExecutionEnvironment &executionEnvironment) : UltCommandStreamReceiver(hwInfoIn, executionEnvironment) { } - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { flushParametrization.wasCalled = true; flushParametrization.receivedBatchBuffer = &batchBuffer; flushParametrization.receivedEngine = engineOrdinal; @@ -47,7 +47,7 @@ struct MyMockCsr : UltCommandStreamReceiver { makeResidentParameterization.receivedGfxAllocation = &gfxAllocation; } - void processResidency(ResidencyContainer *allocationsForResidency) override { + void processResidency(ResidencyContainer *allocationsForResidency, OsContext &osContext) override { processResidencyParameterization.wasCalled = true; processResidencyParameterization.receivedAllocationsForResidency = allocationsForResidency; } @@ -145,8 +145,10 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; + OsContext osContext(nullptr); + ResidencyContainer allocationsForResidency; - FlushStamp flushStamp = csrWithAubDump->flush(batchBuffer, engineType, &allocationsForResidency); + FlushStamp flushStamp = csrWithAubDump->flush(batchBuffer, engineType, &allocationsForResidency, osContext); EXPECT_EQ(flushStamp, csrWithAubDump->flushParametrization.flushStampToReturn); EXPECT_TRUE(csrWithAubDump->flushParametrization.wasCalled); @@ -186,7 +188,8 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub ASSERT_NE(nullptr, gfxAllocation); ResidencyContainer allocationsForResidency = {gfxAllocation}; - csrWithAubDump->processResidency(&allocationsForResidency); + OsContext osContext(nullptr); + csrWithAubDump->processResidency(&allocationsForResidency, osContext); EXPECT_TRUE(csrWithAubDump->processResidencyParameterization.wasCalled); EXPECT_EQ(&allocationsForResidency, csrWithAubDump->processResidencyParameterization.receivedAllocationsForResidency); diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 3bcbcde85e..829f328b01 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -104,7 +104,7 @@ TEST_F(TbxCommandStreamTests, DISABLED_flush) { LinearStream cs(buffer, 4096); size_t startOffset = 0; BatchBuffer batchBuffer{cs.getGraphicsAllocation(), startOffset, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *pDevice->getOsContext()); } HWTEST_F(TbxCommandStreamTests, DISABLED_flushUntilTailRCSLargerThanSizeRCS) { @@ -116,12 +116,12 @@ HWTEST_F(TbxCommandStreamTests, DISABLED_flushUntilTailRCSLargerThanSizeRCS) { auto &engineInfo = tbxCsr->engineInfoTable[EngineType::ENGINE_RCS]; BatchBuffer batchBuffer{cs.getGraphicsAllocation(), startOffset, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *pDevice->getOsContext()); auto size = engineInfo.sizeRCS; engineInfo.sizeRCS = 64; - pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); - pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); - pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *pDevice->getOsContext()); + pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *pDevice->getOsContext()); + pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *pDevice->getOsContext()); engineInfo.sizeRCS = size; } @@ -242,7 +242,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidenc EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); memoryManager->pushAllocationForResidency(graphicsAllocation); - tbxCsr->processResidency(nullptr); + tbxCsr->processResidency(nullptr, *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); @@ -261,7 +261,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidenc EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); ResidencyContainer allocationsForResidency = {graphicsAllocation}; - tbxCsr->processResidency(&allocationsForResidency); + tbxCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); @@ -287,7 +287,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); - tbxCsr->flush(batchBuffer, engineType, &allocationsForResidency); + tbxCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); diff --git a/unit_tests/device/device_win_timers_tests.cpp b/unit_tests/device/device_win_timers_tests.cpp index f97e33e450..c6739b3af8 100644 --- a/unit_tests/device/device_win_timers_tests.cpp +++ b/unit_tests/device/device_win_timers_tests.cpp @@ -37,8 +37,6 @@ TEST_F(MockOSTimeWinTest, DynamicResolution) { auto mDev = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); bool error = wddmMock->init(); - EXPECT_EQ(1u, wddmMock->createContextResult.called); - std::unique_ptr timeWin(new MockOSTimeWin(wddmMock.get())); double res = 0.0; diff --git a/unit_tests/helpers/kmd_notify_tests.cpp b/unit_tests/helpers/kmd_notify_tests.cpp index b3c9c1151e..9123be224f 100644 --- a/unit_tests/helpers/kmd_notify_tests.cpp +++ b/unit_tests/helpers/kmd_notify_tests.cpp @@ -38,7 +38,7 @@ struct KmdNotifyTests : public ::testing::Test { device.reset(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); cmdQ.reset(new CommandQueue(&context, device.get(), nullptr)); *device->getTagAddress() = taskCountToWait; - device->getCommandStreamReceiver().waitForFlushStamp(flushStampToWait); + device->getCommandStreamReceiver().waitForFlushStamp(flushStampToWait, *device->getOsContext()); overrideKmdNotifyParams(true, 2, true, 1, false, 0); } @@ -83,7 +83,7 @@ struct KmdNotifyTests : public ::testing::Test { class MockKmdNotifyCsr : public UltCommandStreamReceiver { public: MockKmdNotifyCsr(const HardwareInfo &hwInfo, const ExecutionEnvironment &executionEnvironment) : UltCommandStreamReceiver(hwInfo, const_cast(executionEnvironment)) {} - MOCK_METHOD1(waitForFlushStamp, bool(FlushStamp &flushStampToWait)); + MOCK_METHOD2(waitForFlushStamp, bool(FlushStamp &flushStampToWait, OsContext &osContext)); MOCK_METHOD3(waitForCompletionWithTimeout, bool(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait)); }; @@ -120,7 +120,7 @@ HWTEST_F(KmdNotifyTests, givenTaskCountAndKmdNotifyDisabledWhenWaitUntilCompleti auto csr = createMockCsr(); EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, 0, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForFlushStamp(::testing::_)).Times(0); + EXPECT_CALL(*csr, waitForFlushStamp(::testing::_, ::testing::_)).Times(0); cmdQ->waitUntilComplete(taskCountToWait, flushStampToWait, false); } @@ -131,7 +131,7 @@ HWTEST_F(KmdNotifyTests, givenNotReadyTaskCountWhenWaitUntilCompletionCalledThen ::testing::InSequence is; EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 2, taskCountToWait)).Times(1).WillOnce(::testing::Return(false)); - EXPECT_CALL(*csr, waitForFlushStamp(flushStampToWait)).Times(1).WillOnce(::testing::Return(true)); + EXPECT_CALL(*csr, waitForFlushStamp(flushStampToWait, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, 0, taskCountToWait)).Times(1).WillOnce(::testing::Return(false)); //we have unrecoverable for this case, this will throw. @@ -143,7 +143,7 @@ HWTEST_F(KmdNotifyTests, givenReadyTaskCountWhenWaitUntilCompletionCalledThenTry ::testing::InSequence is; EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 2, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForFlushStamp(::testing::_)).Times(0); + EXPECT_CALL(*csr, waitForFlushStamp(::testing::_, ::testing::_)).Times(0); cmdQ->waitUntilComplete(taskCountToWait, flushStampToWait, false); } @@ -187,9 +187,9 @@ HWTEST_F(KmdNotifyTests, givenZeroFlushStampWhenWaitIsCalledThenDisableTimeout) EXPECT_TRUE(device->getHardwareInfo().capabilityTable.kmdNotifyProperties.enableKmdNotify); EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, ::testing::_, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForFlushStamp(::testing::_)).Times(0); + EXPECT_CALL(*csr, waitForFlushStamp(::testing::_, ::testing::_)).Times(0); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 0, false); + csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 0, false, *device->getOsContext()); } HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsSporadicWaitThenOverrideQuickSleepRequest) { @@ -202,7 +202,7 @@ HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsSporadicWaitThenOverrid int64_t timeSinceLastWait = mockKmdNotifyHelper->properties->delayQuickKmdSleepForSporadicWaitsMicroseconds + 1; mockKmdNotifyHelper->lastWaitForCompletionTimestampUs = mockKmdNotifyHelper->getMicrosecondsSinceEpoch() - timeSinceLastWait; - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false); + csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, *device->getOsContext()); } HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsNotSporadicWaitThenOverrideQuickSleepRequest) { @@ -212,7 +212,7 @@ HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsNotSporadicWaitThenOver auto expectedDelay = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, expectedDelay, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false); + csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, *device->getOsContext()); } HWTEST_F(KmdNotifyTests, givenQuickSleepRequestWhenItsSporadicWaitOptimizationIsDisabledThenDontOverrideQuickSleepRequest) { @@ -222,7 +222,7 @@ HWTEST_F(KmdNotifyTests, givenQuickSleepRequestWhenItsSporadicWaitOptimizationIs auto expectedDelay = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds; EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, expectedDelay, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, true); + csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, true, *device->getOsContext()); } HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultiplyTimeout) { @@ -233,7 +233,7 @@ HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultipl EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false); + csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, *device->getOsContext()); } HWTEST_F(KmdNotifyTests, givenTaskCountLowerThanHwTagWhenWaitCalledThenDontMultiplyTimeout) { @@ -244,7 +244,7 @@ HWTEST_F(KmdNotifyTests, givenTaskCountLowerThanHwTagWhenWaitCalledThenDontMulti EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false); + csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, *device->getOsContext()); } HWTEST_F(KmdNotifyTests, givenDefaultCommandStreamReceiverWhenWaitCalledThenUpdateWaitTimestamp) { @@ -254,7 +254,7 @@ HWTEST_F(KmdNotifyTests, givenDefaultCommandStreamReceiverWhenWaitCalledThenUpda EXPECT_NE(0, mockKmdNotifyHelper->lastWaitForCompletionTimestampUs.load()); EXPECT_EQ(1u, mockKmdNotifyHelper->updateLastWaitForCompletionTimestampCalled); - csr->waitForTaskCountWithKmdNotifyFallback(0, 0, false); + csr->waitForTaskCountWithKmdNotifyFallback(0, 0, false, *device->getOsContext()); EXPECT_EQ(2u, mockKmdNotifyHelper->updateLastWaitForCompletionTimestampCalled); } @@ -264,7 +264,7 @@ HWTEST_F(KmdNotifyTests, givenDefaultCommandStreamReceiverWithDisabledSporadicWa auto csr = createMockCsr(); EXPECT_EQ(0, mockKmdNotifyHelper->lastWaitForCompletionTimestampUs.load()); - csr->waitForTaskCountWithKmdNotifyFallback(0, 0, false); + csr->waitForTaskCountWithKmdNotifyFallback(0, 0, false, *device->getOsContext()); EXPECT_EQ(0u, mockKmdNotifyHelper->updateLastWaitForCompletionTimestampCalled); } diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index b4882550d0..ae8cd8cca7 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -436,14 +436,14 @@ class CommandStreamReceiverMock : public CommandStreamReceiver { CommandStreamReceiver::makeNonResident(graphicsAllocation); } - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { return flushStamp->peekStamp(); } void addPipeControl(LinearStream &commandStream, bool dcFlush) override { } - void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep) override { + void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, OsContext &osContext) override { } CompletionStamp flushTask( diff --git a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp index 5f6ae1de24..01e6445286 100644 --- a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp @@ -33,7 +33,6 @@ template class MyCsr : public UltCommandStreamReceiver { public: MyCsr(const HardwareInfo &hwInfo, const ExecutionEnvironment &executionEnvironment) : UltCommandStreamReceiver(hwInfo, const_cast(executionEnvironment)) {} - MOCK_METHOD1(waitForFlushStamp, bool(FlushStamp &flushStampToWait)); MOCK_METHOD3(waitForCompletionWithTimeout, bool(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait)); }; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 8bf26571cf..525d5beb45 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1789,3 +1789,26 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation GraphicsAllocation graphicsAllocation(addressWithTrailingBitSet, 1u, sharedHandle); EXPECT_EQ(expectedGpuAddress, graphicsAllocation.getGpuAddress()); } + +TEST(ResidencyDataTest, givenResidencyDataWithOsContextWhenDestructorIsCalledThenDecrementRefCount) { + OsContext *osContext = new OsContext(nullptr); + osContext->incRefInternal(); + EXPECT_EQ(1, osContext->getRefInternalCount()); + { + ResidencyData residencyData; + residencyData.addOsContext(osContext); + EXPECT_EQ(2, osContext->getRefInternalCount()); + } + EXPECT_EQ(1, osContext->getRefInternalCount()); + osContext->decRefInternal(); +} + +TEST(ResidencyDataTest, givenResidencyDataWhenAddTheSameOsContextTwiceThenIncrementRefCounterOnlyOnce) { + OsContext *osContext = new OsContext(nullptr); + ResidencyData residencyData; + EXPECT_EQ(0, osContext->getRefInternalCount()); + residencyData.addOsContext(osContext); + EXPECT_EQ(1, osContext->getRefInternalCount()); + residencyData.addOsContext(osContext); + EXPECT_EQ(1, osContext->getRefInternalCount()); +} \ No newline at end of file diff --git a/unit_tests/mocks/mock_csr.cpp b/unit_tests/mocks/mock_csr.cpp index deeb21f969..7bff8feca6 100644 --- a/unit_tests/mocks/mock_csr.cpp +++ b/unit_tests/mocks/mock_csr.cpp @@ -23,7 +23,7 @@ #include "unit_tests/mocks/mock_csr.h" #include "runtime/os_interface/os_interface.h" -FlushStamp MockCommandStreamReceiver::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) { +FlushStamp MockCommandStreamReceiver::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) { FlushStamp stamp = 0; return stamp; } diff --git a/unit_tests/mocks/mock_csr.h b/unit_tests/mocks/mock_csr.h index d54ce8fb67..04bf51f0f9 100644 --- a/unit_tests/mocks/mock_csr.h +++ b/unit_tests/mocks/mock_csr.h @@ -112,7 +112,7 @@ class MockCsr : public MockCsrBase { MockCsr(int32_t &execStamp, ExecutionEnvironment &executionEnvironment) : BaseClass(execStamp, executionEnvironment) { } - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { return 0; } @@ -179,7 +179,7 @@ class MockCsrHw2 : public CommandStreamReceiverHw { bool peekMediaVfeStateDirty() const { return mediaVfeStateDirty; } FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, - ResidencyContainer *allocationsForResidency) override { + ResidencyContainer *allocationsForResidency, OsContext &osContext) override { flushCalledCount++; recordedCommandBuffer->batchBuffer = batchBuffer; copyOfAllocations.clear(); @@ -237,7 +237,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { ~MockCommandStreamReceiver() { } - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; CompletionStamp flushTask( LinearStream &commandStream, @@ -255,7 +255,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { } } - void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep) override { + void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, OsContext &osContext) override { } void addPipeControl(LinearStream &commandStream, bool dcFlush) override { diff --git a/unit_tests/mocks/mock_wddm.cpp b/unit_tests/mocks/mock_wddm.cpp index 15b44f58ad..99563d02a8 100644 --- a/unit_tests/mocks/mock_wddm.cpp +++ b/unit_tests/mocks/mock_wddm.cpp @@ -83,16 +83,16 @@ bool WddmMock::createAllocation64k(WddmAllocation *alloc) { return createAllocationResult.success = Wddm::createAllocation64k(alloc); } -bool WddmMock::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle) { +bool WddmMock::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) { destroyAllocationResult.called++; if (callBaseDestroyAllocations) { - return destroyAllocationResult.success = Wddm::destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle); + return destroyAllocationResult.success = Wddm::destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle, osContext); } else { return true; } } -bool WddmMock::destroyAllocation(WddmAllocation *alloc) { +bool WddmMock::destroyAllocation(WddmAllocation *alloc, OsContextWin *osContext) { D3DKMT_HANDLE *allocationHandles = nullptr; uint32_t allocationCount = 0; D3DKMT_HANDLE resourceHandle = 0; @@ -107,7 +107,7 @@ bool WddmMock::destroyAllocation(WddmAllocation *alloc) { cpuPtr = alloc->getAlignedCpuPtr(); } } - auto success = destroyAllocations(allocationHandles, allocationCount, alloc->getResidencyData().lastFence, resourceHandle); + auto success = destroyAllocations(allocationHandles, allocationCount, alloc->getResidencyData().lastFence, resourceHandle, osContext); ::alignedFree(cpuPtr); releaseReservedAddress(reserveAddress); return success; @@ -136,11 +136,11 @@ bool WddmMock::queryAdapterInfo() { return queryAdapterInfoResult.success = Wddm::queryAdapterInfo(); } -bool WddmMock::submit(uint64_t commandBuffer, size_t size, void *commandHeader) { +bool WddmMock::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) { submitResult.called++; submitResult.commandBufferSubmitted = commandBuffer; submitResult.commandHeaderSubmitted = commandHeader; - return submitResult.success = Wddm::submit(commandBuffer, size, commandHeader); + return submitResult.success = Wddm::submit(commandBuffer, size, commandHeader, osContext); } bool WddmMock::waitOnGPU(D3DKMT_HANDLE context) { @@ -194,10 +194,10 @@ GMM_GFX_PARTITIONING *WddmMock::getGfxPartitionPtr() { return &gfxPartition; } -bool WddmMock::waitFromCpu(uint64_t lastFenceValue) { +bool WddmMock::waitFromCpu(uint64_t lastFenceValue, OsContextWin &osContext) { waitFromCpuResult.called++; waitFromCpuResult.uint64ParamPassed = lastFenceValue; - return waitFromCpuResult.success = Wddm::waitFromCpu(lastFenceValue); + return waitFromCpuResult.success = Wddm::waitFromCpu(lastFenceValue, osContext); } void *WddmMock::virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) { diff --git a/unit_tests/mocks/mock_wddm.h b/unit_tests/mocks/mock_wddm.h index 86f1829773..c47211a3c3 100644 --- a/unit_tests/mocks/mock_wddm.h +++ b/unit_tests/mocks/mock_wddm.h @@ -56,7 +56,6 @@ class WddmMock : public Wddm { using Wddm::gdi; using Wddm::getSystemInfo; using Wddm::gmmMemory; - using Wddm::osContext; using Wddm::pagingFenceAddress; using Wddm::pagingQueue; using Wddm::preemptionMode; @@ -71,13 +70,13 @@ class WddmMock : public Wddm { bool freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override; NTSTATUS createAllocation(WddmAllocation *alloc) override; bool createAllocation64k(WddmAllocation *alloc) override; - bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle) override; - bool destroyAllocation(WddmAllocation *alloc); + bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) override; + bool destroyAllocation(WddmAllocation *alloc, OsContextWin *osContext); bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) override; bool createContext(D3DKMT_HANDLE &context) override; bool destroyContext(D3DKMT_HANDLE context) override; bool queryAdapterInfo() override; - bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) override; + bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) override; bool waitOnGPU(D3DKMT_HANDLE context) override; void *lockResource(WddmAllocation *allocation) override; void unlockResource(WddmAllocation *allocation) override; @@ -88,7 +87,7 @@ class WddmMock : public Wddm { bool openAdapter() override; void setHeap32(uint64_t base, uint64_t size); GMM_GFX_PARTITIONING *getGfxPartitionPtr(); - bool waitFromCpu(uint64_t lastFenceValue) override; + bool waitFromCpu(uint64_t lastFenceValue, OsContextWin &osContext) override; void *virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) override; int virtualFree(void *ptr, size_t size, unsigned long flags) override; void releaseReservedAddress(void *reservedAddress) override; 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 a0d8775a48..af27875d9f 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -56,7 +56,7 @@ class DrmCommandStreamFixture { const int mockFd = 33; void SetUp() { - + osContext = std::make_unique(nullptr); this->dbgState = new DebugManagerStateRestore(); //make sure this is disabled, we don't want test this now DebugManager.flags.EnableForcePin.set(false); @@ -92,6 +92,7 @@ class DrmCommandStreamFixture { static const uint64_t alignment = MemoryConstants::allocationAlignment; DebugManagerStateRestore *dbgState; ExecutionEnvironment executionEnvironment; + std::unique_ptr osContext; }; typedef Test DrmCommandStreamTest; @@ -111,7 +112,7 @@ TEST_F(DrmCommandStreamTest, givenFlushStampWhenWaitCalledThenWaitForSpecifiedBo .Times(1) .WillRepeatedly(copyIoctlParam(&calledWait)); - csr->waitForFlushStamp(handleToWait); + csr->waitForFlushStamp(handleToWait, *osContext); EXPECT_TRUE(memcmp(&expectedWait, &calledWait, sizeof(drm_i915_gem_wait)) == 0); } @@ -218,7 +219,7 @@ TEST_F(DrmCommandStreamTest, Flush) { csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto availableSpacePriorToFlush = cs.getAvailableSpace(); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); EXPECT_EQ(static_cast(boHandle), flushStamp); EXPECT_NE(cs.getCpuBase(), nullptr); EXPECT_EQ(availableSpacePriorToFlush, cs.getAvailableSpace()); @@ -253,7 +254,7 @@ TEST_F(DrmCommandStreamTest, FlushWithLowPriorityContext) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, true, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); EXPECT_NE(cs.getCpuBase(), nullptr); } @@ -282,7 +283,7 @@ TEST_F(DrmCommandStreamTest, FlushInvalidAddress) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); delete[] commandBuffer; } @@ -313,7 +314,7 @@ TEST_F(DrmCommandStreamTest, FlushNotEmptyBB) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamTest, FlushNotEmptyNotPaddedBB) { @@ -342,7 +343,7 @@ TEST_F(DrmCommandStreamTest, FlushNotEmptyNotPaddedBB) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamTest, FlushNotAligned) { @@ -373,7 +374,7 @@ TEST_F(DrmCommandStreamTest, FlushNotAligned) { csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 4, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } ACTION_P(UserptrSetHandle, _set_handle) { @@ -425,7 +426,7 @@ TEST_F(DrmCommandStreamTest, FlushCheckFlags) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamTest, CheckDrmFree) { @@ -458,7 +459,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFree) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 4, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamTest, GIVENCSRWHENgetDMTHENNotNull) { @@ -499,7 +500,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFreeCloseFailed) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 4, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } struct DrmCsrVfeTests : ::testing::Test { @@ -510,7 +511,7 @@ struct DrmCsrVfeTests : ::testing::Test { using CommandStreamReceiver::commandStream; MyCsr(ExecutionEnvironment &executionEnvironment) : DrmCommandStreamReceiver(*platformDevices[0], nullptr, executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive) {} - FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { + FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { return (FlushStamp)0; } bool peekDefaultMediaVfeStateDirty() { @@ -668,6 +669,7 @@ class DrmCommandStreamEnhancedFixture DeviceCommandStreamReceiver *csr = nullptr; DrmMemoryManager *mm = nullptr; MockDevice *device = nullptr; + OsContext *osContext; DebugManagerStateRestore *dbgState; ExecutionEnvironment *executionEnvironment; @@ -687,6 +689,7 @@ class DrmCommandStreamEnhancedFixture executionEnvironment->memoryManager.reset(mm); device = Device::create(platformDevices[0], executionEnvironment); ASSERT_NE(nullptr, device); + osContext = device->getOsContext(); } void TearDown() { @@ -802,7 +805,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemC auto storedBase = cs.getCpuBase(); auto storedGraphicsAllocation = cs.getGraphicsAllocation(); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); EXPECT_EQ(cs.getCpuBase(), storedBase); EXPECT_EQ(cs.getGraphicsAllocation(), storedGraphicsAllocation); @@ -837,7 +840,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWh csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); EXPECT_EQ(11u, this->mock->execBuffer.buffer_count); mm->freeGraphicsMemory(commandBuffer); @@ -858,7 +861,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeRe csr->makeResident(*dummyAllocation); EXPECT_EQ(1u, bo->getRefCount()); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); csr->makeNonResident(*dummyAllocation); EXPECT_EQ(1u, bo->getRefCount()); @@ -878,7 +881,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, GivenTwoAllocationsWhenBackingStorageIsDi EXPECT_FALSE(bo1->peekIsResident()); EXPECT_FALSE(bo2->peekIsResident()); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(bo1->peekIsResident()); EXPECT_TRUE(bo2->peekIsResident()); @@ -909,7 +912,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsF auto storedBase = cs.getCpuBase(); auto storedGraphicsAllocation = cs.getGraphicsAllocation(); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); EXPECT_EQ(cs.getCpuBase(), storedBase); EXPECT_EQ(cs.getGraphicsAllocation(), storedGraphicsAllocation); @@ -963,7 +966,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); //preemption allocation + Sip Kernel int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 2 : 0; @@ -1111,7 +1114,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResident) { EXPECT_EQ(nullptr, allocation->getUnderlyingBuffer()); csr->makeResident(*allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(isResident(buffer)); auto bo = getResident(buffer); @@ -1136,7 +1139,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentOnly) { csr->makeResident(*allocation1); csr->makeResident(*allocation2); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(isResident(buffer1)); EXPECT_TRUE(isResident(buffer2)); @@ -1160,7 +1163,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentTwice) { auto allocation = new DrmAllocation(buffer, nullptr, buffer->peekSize(), MemoryPool::MemoryNull); csr->makeResident(*allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(isResident(buffer)); auto bo1 = getResident(buffer); @@ -1169,7 +1172,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentTwice) { csr->getMemoryManager()->clearResidencyAllocations(); csr->makeResident(*allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(isResident(buffer)); auto bo2 = getResident(buffer); @@ -1198,7 +1201,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentTwiceWhenFragmentStorage) { csr->makeResident(*allocation); csr->makeResident(*allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); for (int i = 0; i < max_fragments_count; i++) { ASSERT_EQ(allocation->fragmentsStorage.fragmentStorageData[i].cpuPtr, reqs.AllocationFragments[i].allocationPtr); @@ -1241,7 +1244,7 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW tCsr->makeResident(*graphicsAllocation); tCsr->makeResident(*graphicsAllocation2); - tCsr->processResidency(nullptr); + tCsr->processResidency(nullptr, *osContext); EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident); EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident); @@ -1265,7 +1268,7 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW tCsr->makeResident(*graphicsAllocation); tCsr->makeResident(*graphicsAllocation2); - tCsr->processResidency(nullptr); + tCsr->processResidency(nullptr, *osContext); EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident); EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident); @@ -1301,7 +1304,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationCreatedFromThreeFragmentsWhenMa ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount); csr->makeResident(*allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); for (int i = 0; i < max_fragments_count; i++) { ASSERT_EQ(allocation->fragmentsStorage.fragmentStorageData[i].cpuPtr, @@ -1339,7 +1342,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag ASSERT_EQ(2u, reqs.requiredFragmentsCount); csr->makeResident(*allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); for (unsigned int i = 0; i < reqs.requiredFragmentsCount; i++) { ASSERT_EQ(allocation->fragmentsStorage.fragmentStorageData[i].cpuPtr, @@ -1371,7 +1374,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag ASSERT_EQ(1u, reqs.requiredFragmentsCount); csr->makeResident(*allocation2); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); for (unsigned int i = 0; i < reqs.requiredFragmentsCount; i++) { ASSERT_EQ(allocation2->fragmentsStorage.fragmentStorageData[i].cpuPtr, @@ -1405,7 +1408,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenTwoAllocationsWhenBackingStorageIsTheSame csr->makeResident(*allocation); csr->makeResident(*allocation2); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_EQ(tCsr->getResidencyVector()->size(), 1u); @@ -1428,7 +1431,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenTwoAllocationsWhenBackingStorageIsDiffere csr->makeResident(*allocation); csr->makeResident(*allocation2); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_EQ(tCsr->getResidencyVector()->size(), 2u); @@ -1447,7 +1450,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentSizeZero) { EXPECT_EQ(buffer->peekSize(), allocation.getUnderlyingBufferSize()); csr->makeResident(allocation); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_FALSE(isResident(buffer.get())); auto bo = getResident(buffer.get()); @@ -1462,7 +1465,7 @@ TEST_F(DrmCommandStreamLeaksTest, Flush) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); EXPECT_NE(cs.getCpuBase(), nullptr); EXPECT_NE(cs.getGraphicsAllocation(), nullptr); } @@ -1476,7 +1479,7 @@ TEST_F(DrmCommandStreamLeaksTest, ClearResidencyWhenFlushNotCalled) { EXPECT_EQ(tCsr->getResidencyVector()->size(), 0u); csr->makeResident(*allocation1); csr->makeResident(*allocation2); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(isResident(allocation1->getBO())); EXPECT_TRUE(isResident(allocation2->getBO())); @@ -1506,14 +1509,14 @@ TEST_F(DrmCommandStreamLeaksTest, FlushMultipleTimes) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); cs.replaceBuffer(commandBuffer->getUnderlyingBuffer(), commandBuffer->getUnderlyingBufferSize()); cs.replaceGraphicsAllocation(commandBuffer); csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer2{cs.getGraphicsAllocation(), 8, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer2, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer2, EngineType::ENGINE_RCS, nullptr, *osContext); auto allocation = mm->allocateGraphicsMemory(1024); ASSERT_NE(nullptr, allocation); @@ -1532,7 +1535,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushMultipleTimes) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer3{cs.getGraphicsAllocation(), 16, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer3, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer3, EngineType::ENGINE_RCS, nullptr, *osContext); csr->makeSurfacePackNonResident(nullptr); mm->freeGraphicsMemory(allocation); mm->freeGraphicsMemory(allocation2); @@ -1545,7 +1548,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushMultipleTimes) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer4{cs.getGraphicsAllocation(), 24, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer4, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer4, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamLeaksTest, FlushNotEmptyBB) { @@ -1558,7 +1561,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushNotEmptyBB) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamLeaksTest, FlushNotEmptyNotPaddedBB) { @@ -1571,7 +1574,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushNotEmptyNotPaddedBB) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamLeaksTest, FlushNotAligned) { @@ -1585,7 +1588,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushNotAligned) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 4, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); } TEST_F(DrmCommandStreamLeaksTest, CheckDrmFree) { @@ -1602,7 +1605,7 @@ TEST_F(DrmCommandStreamLeaksTest, CheckDrmFree) { csr->addBatchBufferEnd(cs, nullptr); csr->alignToCacheLine(cs); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 4, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); csr->makeNonResident(*allocation); mm->freeGraphicsMemory(allocation); } @@ -1618,7 +1621,7 @@ TEST_F(DrmCommandStreamLeaksTest, MakeResidentClearResidencyAllocationsInMemoryM csr->makeResident(*allocation2); EXPECT_NE(0u, mm->getResidencyAllocations().size()); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *device->getOsContext()); csr->makeSurfacePackNonResident(nullptr); EXPECT_EQ(0u, mm->getResidencyAllocations().size()); @@ -1636,7 +1639,7 @@ TEST_F(DrmCommandStreamLeaksTest, givenMultipleMakeResidentWhenMakeNonResidentIs EXPECT_NE(0u, mm->getResidencyAllocations().size()); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *device->getOsContext()); csr->makeSurfacePackNonResident(nullptr); EXPECT_EQ(0u, mm->getResidencyAllocations().size()); @@ -1698,7 +1701,7 @@ TEST_F(DrmCommandStreamLeaksTest, BufferResidency) { //make it resident 8 times for (int c = 0; c < 8; c++) { csr->makeResident(*buffer->getGraphicsAllocation()); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *osContext); EXPECT_TRUE(buffer->getGraphicsAllocation()->isResident()); EXPECT_EQ(buffer->getGraphicsAllocation()->residencyTaskCount, (int)csr->peekTaskCount() + 1); } diff --git a/unit_tests/os_interface/linux/os_interface_linux_tests.cpp b/unit_tests/os_interface/linux/os_interface_linux_tests.cpp index 9d5ef8569f..f17b0dcd37 100644 --- a/unit_tests/os_interface/linux/os_interface_linux_tests.cpp +++ b/unit_tests/os_interface/linux/os_interface_linux_tests.cpp @@ -37,7 +37,7 @@ TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsRetu TEST(OsContextTest, WhenOsContextIsCreatedThenImplIsAvailable) { OSInterface osInterface; - auto osContext = std::make_unique(osInterface); + auto osContext = std::make_unique(&osInterface); EXPECT_NE(nullptr, osContext->get()); } } // namespace OCLRT \ No newline at end of file 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 5eec3ef139..ca1b664d90 100644 --- a/unit_tests/os_interface/windows/deferrable_deletion_win_tests.cpp +++ b/unit_tests/os_interface/windows/deferrable_deletion_win_tests.cpp @@ -39,13 +39,13 @@ TEST(DeferrableDeletionImpl, NonAssignable) { class MockDeferrableDeletion : public DeferrableDeletionImpl { public: - MockDeferrableDeletion(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, - D3DKMT_HANDLE resourceHandle) : DeferrableDeletionImpl(wddm, handles, allocationCount, lastFenceValue, resourceHandle){}; - Wddm *getWddm() { return wddm; } - D3DKMT_HANDLE *getHandles() { return handles; } - uint32_t getAllocationCount() { return allocationCount; } - uint64_t getLastFenceValue() { return lastFenceValue; } - D3DKMT_HANDLE getResourceHandle() { return resourceHandle; } + using DeferrableDeletionImpl::allocationCount; + using DeferrableDeletionImpl::DeferrableDeletionImpl; + using DeferrableDeletionImpl::handles; + using DeferrableDeletionImpl::lastFenceValue; + using DeferrableDeletionImpl::osContext; + using DeferrableDeletionImpl::resourceHandle; + using DeferrableDeletionImpl::wddm; }; class DeferrableDeletionTest : public ::testing::Test { @@ -55,22 +55,24 @@ class DeferrableDeletionTest : public ::testing::Test { uint32_t allocationCount = 1; uint64_t lastFenceValue = 0; D3DKMT_HANDLE resourceHandle = 0; + OsContextWin *osContext = nullptr; }; TEST_F(DeferrableDeletionTest, givenDeferrableDeletionWhenIsCreatedThenObjectMembersAreSetProperly) { - MockDeferrableDeletion deletion(&wddm, &handle, allocationCount, lastFenceValue, resourceHandle); - EXPECT_EQ(&wddm, deletion.getWddm()); - EXPECT_NE(nullptr, deletion.getHandles()); - EXPECT_EQ(handle, *deletion.getHandles()); - EXPECT_NE(&handle, deletion.getHandles()); - EXPECT_EQ(allocationCount, deletion.getAllocationCount()); - EXPECT_EQ(lastFenceValue, deletion.getLastFenceValue()); - EXPECT_EQ(resourceHandle, deletion.getResourceHandle()); + MockDeferrableDeletion deletion(&wddm, &handle, allocationCount, lastFenceValue, resourceHandle, osContext); + EXPECT_EQ(&wddm, deletion.wddm); + EXPECT_NE(nullptr, deletion.handles); + EXPECT_EQ(handle, *deletion.handles); + EXPECT_NE(&handle, deletion.handles); + EXPECT_EQ(allocationCount, deletion.allocationCount); + EXPECT_EQ(lastFenceValue, deletion.lastFenceValue); + EXPECT_EQ(resourceHandle, deletion.resourceHandle); + EXPECT_EQ(osContext, deletion.osContext); } TEST_F(DeferrableDeletionTest, givenDeferrableDeletionWhenApplyIsCalledThenDeletionIsApplied) { wddm.callBaseDestroyAllocations = false; - std::unique_ptr deletion(DeferrableDeletion::create((Wddm *)&wddm, &handle, allocationCount, lastFenceValue, resourceHandle)); + std::unique_ptr deletion(DeferrableDeletion::create((Wddm *)&wddm, &handle, allocationCount, lastFenceValue, resourceHandle, osContext)); EXPECT_EQ(0, wddm.destroyAllocationResult.called); deletion->apply(); 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 6fcf071481..8bbd93245c 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -32,9 +32,11 @@ #include "runtime/helpers/options.h" #include "runtime/mem_obj/buffer.h" #include "runtime/memory_manager/memory_manager.h" +#include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/wddm_device_command_stream.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" +#include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/fixtures/memory_management_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" @@ -65,14 +67,13 @@ class WddmCommandStreamFixture { DebugManagerStateRestore stateRestore; virtual void SetUp() { - device.reset(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); - ASSERT_NE(nullptr, device); wddm = static_cast(Wddm::createWddm()); ASSERT_NE(wddm, nullptr); + auto executionEnvironment = new ExecutionEnvironment; DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); - csr.reset(new WddmCommandStreamReceiver(*platformDevices[0], wddm, *device->executionEnvironment)); + csr.reset(new WddmCommandStreamReceiver(*platformDevices[0], wddm, *executionEnvironment)); ASSERT_NE(nullptr, csr); mockWddmMM = new MockWddmMemoryManager(wddm); @@ -80,6 +81,8 @@ class WddmCommandStreamFixture { csr->setMemoryManager(memManager.get()); ASSERT_NE(nullptr, memManager); + device.reset(Device::create(platformDevices[0], executionEnvironment)); + ASSERT_NE(nullptr, device); } virtual void TearDown() { @@ -160,7 +163,7 @@ class WddmCommandStreamWithMockGdiFixture { using WddmCommandStreamTest = ::Test; using WddmCommandStreamMockGdiTest = ::Test; -using WddmDefaultTest = ::Test; +using WddmDefaultTest = ::Test; using DeviceCommandStreamTest = ::Test; TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { @@ -181,7 +184,7 @@ TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) { TEST_F(WddmCommandStreamTest, givenFlushStampWhenWaitCalledThenWaitForSpecifiedMonitoredFence) { uint64_t stampToWait = 123; - csr->waitForFlushStamp(stampToWait); + csr->waitForFlushStamp(stampToWait, *device->getOsContext()); EXPECT_EQ(1u, wddm->waitFromCpuResult.called); EXPECT_TRUE(wddm->waitFromCpuResult.success); EXPECT_EQ(stampToWait, wddm->waitFromCpuResult.uint64ParamPassed); @@ -192,11 +195,11 @@ TEST_F(WddmCommandStreamTest, Flush) { ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); EXPECT_EQ(1u, wddm->submitResult.called); EXPECT_TRUE(wddm->submitResult.success); - EXPECT_EQ(flushStamp, wddm->getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(flushStamp, device->getOsContext()->get()->getMonitoredFence().lastSubmittedFence); memManager->freeGraphicsMemory(commandBuffer); } @@ -210,7 +213,7 @@ TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWithDifferentGpuAddressThen LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); EXPECT_EQ(mockGpuAddres, wddm->submitResult.commandBufferSubmitted); memManager->freeGraphicsMemory(commandBuffer); } @@ -221,7 +224,7 @@ TEST_F(WddmCommandStreamTest, FlushWithOffset) { LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), offset, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); EXPECT_EQ(1u, wddm->submitResult.called); EXPECT_TRUE(wddm->submitResult.success); EXPECT_EQ(wddm->submitResult.commandBufferSubmitted, reinterpret_cast(commandBuffer->getUnderlyingBuffer()) + offset); @@ -235,7 +238,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFl LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); @@ -259,12 +262,15 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - executionEnvironment.commandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + OsContext *osContext = new OsContext(executionEnvironment.osInterface.get()); + osContext->incRefInternal(); + executionEnvironment.commandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); EXPECT_FALSE(pHeader->NeedsMidBatchPreEmptionSupport); executionEnvironment.memoryManager->freeGraphicsMemory(commandBuffer); + osContext->decRefInternal(); } TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOnWhenWorkloadIsSubmittedThenHeaderDoesHavePreemptionFieldSet) { @@ -280,12 +286,15 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - executionEnvironment.commandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + OsContext *osContext = new OsContext(executionEnvironment.osInterface.get()); + osContext->incRefInternal(); + executionEnvironment.commandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *osContext); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); EXPECT_TRUE(pHeader->NeedsMidBatchPreEmptionSupport); executionEnvironment.memoryManager->freeGraphicsMemory(commandBuffer); + osContext->decRefInternal(); } TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderContainsPreemptionFieldSet) { @@ -316,7 +325,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToLowThenS LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::LOW, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); @@ -334,7 +343,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToMediumTh LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); @@ -352,7 +361,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToHighThen LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::HIGH, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); @@ -376,7 +385,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafDisabledWhenFlushIsCalledWithAll ResidencyContainer allocationsForResidency = {linearStreamAllocation}; EXPECT_FALSE(wddm->isKmDafEnabled()); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency, *device->getOsContext()); EXPECT_EQ(0u, wddm->kmDafLockResult.called); EXPECT_EQ(0u, wddm->kmDafLockResult.lockedAllocations.size()); @@ -392,7 +401,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithoutA BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; wddm->setKmDafEnabled(true); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); EXPECT_EQ(0u, wddm->kmDafLockResult.called); EXPECT_EQ(0u, wddm->kmDafLockResult.lockedAllocations.size()); @@ -415,7 +424,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResi EXPECT_EQ(linearStreamAllocation, memManager->getResidencyAllocations()[0]); wddm->setKmDafEnabled(true); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); EXPECT_EQ(1u, wddm->kmDafLockResult.called); EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); @@ -437,7 +446,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo ResidencyContainer allocationsForResidency = {linearStreamAllocation}; wddm->setKmDafEnabled(true); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency, *device->getOsContext()); EXPECT_EQ(1u, wddm->kmDafLockResult.called); EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); @@ -459,7 +468,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo ResidencyContainer allocationsForResidency = {fillPatternAllocation}; wddm->setKmDafEnabled(true); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency, *device->getOsContext()); EXPECT_EQ(1u, wddm->kmDafLockResult.called); EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); @@ -480,7 +489,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo ResidencyContainer allocationsForResidency = {nonLinearStreamAllocation}; wddm->setKmDafEnabled(true); - auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency, *device->getOsContext()); EXPECT_EQ(0u, wddm->kmDafLockResult.called); EXPECT_EQ(0u, wddm->kmDafLockResult.lockedAllocations.size()); @@ -662,7 +671,7 @@ TEST_F(WddmCommandStreamMockGdiTest, FlushCallsWddmMakeResidentForResidencyAlloc gdi->getMakeResidentArg().NumAllocations = 0; BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); + csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr, *device->getOsContext()); EXPECT_NE(0u, gdi->getMakeResidentArg().NumAllocations); @@ -681,7 +690,7 @@ TEST_F(WddmCommandStreamMockGdiTest, makeResidentClearsResidencyAllocations) { EXPECT_EQ(trimListUnusedPosition, ((WddmAllocation *)commandBuffer)->getTrimCandidateListPosition()); - csr->processResidency(nullptr); + csr->processResidency(nullptr, *device->getOsContext()); csr->makeSurfacePackNonResident(nullptr); @@ -795,7 +804,7 @@ HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVer FeatureTable myFtrTable = *myHwInfo.pSkuTable; myHwInfo.pSkuTable = &myFtrTable; - WddmCommandStreamReceiver wddmCsr(myHwInfo, nullptr, *device->executionEnvironment); + WddmCommandStreamReceiver wddmCsr(myHwInfo, nullptr, *pDevice->executionEnvironment); auto wddm = wddmCsr.peekWddm(); EXPECT_EQ(typeid(*wddm), typeid(WddmMock)); } diff --git a/unit_tests/os_interface/windows/driver_info_tests.cpp b/unit_tests/os_interface/windows/driver_info_tests.cpp index 8e0291eb7c..64a71a5936 100644 --- a/unit_tests/os_interface/windows/driver_info_tests.cpp +++ b/unit_tests/os_interface/windows/driver_info_tests.cpp @@ -57,7 +57,9 @@ CommandStreamReceiver *createMockCommandStreamReceiver(const HardwareInfo &hwInf auto csr = new MockCommandStreamReceiver(); OSInterface *osInterface = new OSInterface(); executionEnvironment.osInterface.reset(osInterface); - osInterface->get()->setWddm(new WddmMock()); + auto wddm = new WddmMock(); + wddm->init(); + osInterface->get()->setWddm(wddm); csr->setOSInterface(osInterface); return csr; } 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 c0f363bea1..22797ff069 100644 --- a/unit_tests/os_interface/windows/os_interface_win_tests.cpp +++ b/unit_tests/os_interface/windows/os_interface_win_tests.cpp @@ -44,9 +44,7 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextBeforeInitWddmThenOsContextIsNot auto wddm = new WddmMock; OSInterface osInterface; osInterface.get()->setWddm(wddm); - auto osContext = std::make_unique(osInterface); - EXPECT_NE(nullptr, osContext->get()); - EXPECT_FALSE(osContext->get()->isInitialized()); + EXPECT_THROW(auto osContext = std::make_unique(&osInterface), std::exception); } TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitialized) { @@ -54,7 +52,13 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit OSInterface osInterface; osInterface.get()->setWddm(wddm); wddm->init(); - auto osContext = std::make_unique(osInterface); + auto osContext = std::make_unique(&osInterface); EXPECT_NE(nullptr, osContext->get()); EXPECT_TRUE(osContext->get()->isInitialized()); + EXPECT_EQ(osContext->get()->getWddm(), wddm); +} + +TEST(OsContextTest, whenCreateOsContextWithoutOsInterfaceThenOsContextImplIsNotAvailable) { + auto osContext = std::make_unique(nullptr); + EXPECT_EQ(nullptr, osContext->get()); } diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index bb5b96b6c6..34fa651b57 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -64,7 +64,7 @@ struct Wddm20WithMockGdiDllTests : public Wddm20WithMockGdiDllTestsWithoutWddmIn using Wddm20WithMockGdiDllTestsWithoutWddmInit::TearDown; void SetUp() override { Wddm20WithMockGdiDllTestsWithoutWddmInit::SetUp(); - EXPECT_TRUE(wddm->init()); + init(); } }; @@ -175,7 +175,7 @@ TEST(Wddm20EnumAdaptersTest, givenUnknownPlatformWhenEnumAdapterIsCalledThenFals } TEST_F(Wddm20Tests, whenInitializeWddmThenContextIsCreated) { - auto context = wddm->osContext->getContext(); + auto context = osContextWin->getContext(); EXPECT_TRUE(context != static_cast(0)); } @@ -190,7 +190,7 @@ TEST_F(Wddm20Tests, allocation) { EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_TRUE(allocation.handle != 0); - auto error = wddm->destroyAllocation(&allocation); + auto error = wddm->destroyAllocation(&allocation, osContextWin); EXPECT_TRUE(error); delete gmm; @@ -220,7 +220,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages); EXPECT_NE(underlyingPages, getLastCallMapGpuVaArgFcn()->SizeInPages); - ret = wddm->destroyAllocation(&allocation); + ret = wddm->destroyAllocation(&allocation, osContextWin); EXPECT_TRUE(ret); delete gmm; @@ -270,7 +270,7 @@ TEST_F(Wddm20Tests, createAllocation32bit) { EXPECT_LE(heap32baseAddress, allocation.gpuPtr); EXPECT_GT(heap32baseAddress + heap32Size, allocation.gpuPtr); - auto success = wddm->destroyAllocation(&allocation); + auto success = wddm->destroyAllocation(&allocation, osContextWin); EXPECT_TRUE(success); delete gmm; @@ -315,7 +315,7 @@ TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocati storage.fragmentStorageData[2].freeTheFragment = true; D3DKMT_HANDLE handles[3] = {ALLOCATION_HANDLE, ALLOCATION_HANDLE, ALLOCATION_HANDLE}; - bool retVal = wddm->destroyAllocations(handles, 3, 0, 0); + bool retVal = wddm->destroyAllocations(handles, 3, 0, 0, osContextWin); EXPECT_TRUE(retVal); auto destroyWithResourceHandleCalled = 0u; @@ -346,7 +346,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) { EXPECT_TRUE(error); EXPECT_TRUE(allocation.gpuPtr == 0); - error = wddm->destroyAllocation(&allocation); + error = wddm->destroyAllocation(&allocation, osContextWin); EXPECT_TRUE(error); delete gmm; mm.freeSystemMemory(allocation.getUnderlyingBuffer()); @@ -394,12 +394,12 @@ TEST_F(Wddm20Tests, makeResidentNonResident) { error = wddm->evict(&allocation.handle, 1, sizeToTrim); EXPECT_TRUE(error); - auto monitoredFence = wddm->getMonitoredFence(); + auto monitoredFence = osContextWin->getMonitoredFence(); UINT64 fenceValue = 100; monitoredFence.cpuAddress = &fenceValue; monitoredFence.currentFenceValue = 101; - error = wddm->destroyAllocation(&allocation); + error = wddm->destroyAllocation(&allocation, osContextWin); EXPECT_TRUE(error); delete gmm; @@ -412,7 +412,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); - WddmMemoryManager mm(false, wddm.get()); + WddmMemoryManager mm(false, wddm); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; @@ -449,17 +449,16 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); - auto mockWddm = wddm.get(); - WddmMemoryManager mm(false, mockWddm); + WddmMemoryManager mm(false, wddm); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); if (is32bit) { - EXPECT_NE(mockWddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); + EXPECT_NE(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); } else { - EXPECT_EQ(mockWddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); + EXPECT_EQ(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); } mm.freeGraphicsMemory(graphicsAllocation); @@ -554,7 +553,7 @@ TEST_F(Wddm20Tests, getMaxApplicationAddress) { TEST_F(Wddm20WithMockGdiDllTestsWithoutWddmInit, givenUseNoRingFlushesKmdModeDebugFlagToFalseWhenCreateContextIsCalledThenNoRingFlushesKmdModeIsSetToFalse) { DebugManagerStateRestore dbgRestore; DebugManager.flags.UseNoRingFlushesKmdMode.set(false); - wddm->init(); + init(); auto createContextParams = this->getCreateContextDataFcn(); auto privateData = (CREATECONTEXT_PVTDATA *)createContextParams->pPrivateDriverData; EXPECT_FALSE(!!privateData->NoRingFlushes); @@ -563,7 +562,7 @@ TEST_F(Wddm20WithMockGdiDllTestsWithoutWddmInit, givenUseNoRingFlushesKmdModeDeb TEST_F(Wddm20WithMockGdiDllTestsWithoutWddmInit, givenUseNoRingFlushesKmdModeDebugFlagToTrueWhenCreateContextIsCalledThenNoRingFlushesKmdModeIsSetToTrue) { DebugManagerStateRestore dbgRestore; DebugManager.flags.UseNoRingFlushesKmdMode.set(true); - wddm->init(); + init(); auto createContextParams = this->getCreateContextDataFcn(); auto privateData = (CREATECONTEXT_PVTDATA *)createContextParams->pPrivateDriverData; EXPECT_TRUE(!!privateData->NoRingFlushes); @@ -575,7 +574,7 @@ TEST_F(Wddm20WithMockGdiDllTests, whenCreateContextIsCalledThenDisableHwQueues) } TEST_F(Wddm20Tests, whenCreateHwQueueIsCalledThenAlwaysReturnFalse) { - EXPECT_FALSE(wddm->wddmInterface->createHwQueue(wddm->preemptionMode, *wddm->osContext)); + EXPECT_FALSE(wddm->wddmInterface->createHwQueue(wddm->preemptionMode, *osContextWin)); } TEST_F(Wddm20Tests, whenWddmIsInitializedThenGdiDoesntHaveHwQueueDDIs) { @@ -656,7 +655,7 @@ TEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCa allocation.getResidencyData().lastFence = 20; allocation.handle = ALLOCATION_HANDLE; - *wddm->getMonitoredFence().cpuAddress = 10; + *osContextWin->getMonitoredFence().cpuAddress = 10; D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234; @@ -672,12 +671,12 @@ TEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCa gdi->getDestroyArg().hResource = (D3DKMT_HANDLE)0; gdi->getDestroyArg().phAllocationList = nullptr; - wddm->destroyAllocation(&allocation); + wddm->destroyAllocation(&allocation, osContextWin); EXPECT_NE(nullptr, gdi->getWaitFromCpuArg().FenceValueArray); EXPECT_EQ(wddm->getDevice(), gdi->getWaitFromCpuArg().hDevice); EXPECT_EQ(1u, gdi->getWaitFromCpuArg().ObjectCount); - EXPECT_EQ(&wddm->getMonitoredFence().fenceHandle, gdi->getWaitFromCpuArg().ObjectHandleArray); + EXPECT_EQ(&osContextWin->getMonitoredFence().fenceHandle, gdi->getWaitFromCpuArg().ObjectHandleArray); EXPECT_EQ(wddm->getDevice(), gdi->getDestroyArg().hDevice); EXPECT_EQ(1u, gdi->getDestroyArg().AllocationCount); @@ -689,7 +688,7 @@ TEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDo allocation.getResidencyData().lastFence = 10; allocation.handle = ALLOCATION_HANDLE; - *wddm->getMonitoredFence().cpuAddress = 10; + *osContextWin->getMonitoredFence().cpuAddress = 10; D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234; @@ -705,7 +704,7 @@ TEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDo gdi->getDestroyArg().hResource = (D3DKMT_HANDLE)0; gdi->getDestroyArg().phAllocationList = nullptr; - wddm->destroyAllocation(&allocation); + wddm->destroyAllocation(&allocation, osContextWin); EXPECT_EQ(nullptr, gdi->getWaitFromCpuArg().FenceValueArray); EXPECT_EQ((D3DKMT_HANDLE)0, gdi->getWaitFromCpuArg().hDevice); @@ -722,7 +721,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle allocation.getResidencyData().lastFence = 10; allocation.handle = ALLOCATION_HANDLE; - *wddm->getMonitoredFence().cpuAddress = 10; + *osContextWin->getMonitoredFence().cpuAddress = 10; gdi->getWaitFromCpuArg().FenceValueArray = nullptr; gdi->getWaitFromCpuArg().Flags.Value = 0; @@ -730,7 +729,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle gdi->getWaitFromCpuArg().ObjectCount = 0; gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr; - auto status = wddm->waitFromCpu(10); + auto status = wddm->waitFromCpu(10, *osContextWin); EXPECT_TRUE(status); @@ -745,7 +744,7 @@ TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { allocation.getResidencyData().lastFence = 10; allocation.handle = ALLOCATION_HANDLE; - *wddm->getMonitoredFence().cpuAddress = 10; + *osContextWin->getMonitoredFence().cpuAddress = 10; gdi->getWaitFromCpuArg().FenceValueArray = nullptr; gdi->getWaitFromCpuArg().Flags.Value = 0; @@ -753,7 +752,7 @@ TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { gdi->getWaitFromCpuArg().ObjectCount = 0; gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr; - auto status = wddm->waitFromCpu(20); + auto status = wddm->waitFromCpu(20, *osContextWin); EXPECT_TRUE(status); @@ -768,10 +767,10 @@ TEST_F(Wddm20Tests, createMonitoredFenceIsInitializedWithFenceValueZeroAndCurren gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300; - wddm->wddmInterface->createMonitoredFence(*wddm->osContext); + wddm->wddmInterface->createMonitoredFence(*osContextWin); EXPECT_EQ(0u, gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue); - EXPECT_EQ(1u, wddm->getMonitoredFence().currentFenceValue); + EXPECT_EQ(1u, osContextWin->getMonitoredFence().currentFenceValue); } NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) { diff --git a/unit_tests/os_interface/windows/wddm23_tests.cpp b/unit_tests/os_interface/windows/wddm23_tests.cpp index f6ff5f55ca..b1da1f32f2 100644 --- a/unit_tests/os_interface/windows/wddm23_tests.cpp +++ b/unit_tests/os_interface/windows/wddm23_tests.cpp @@ -27,6 +27,7 @@ #include "unit_tests/mocks/mock_wddm_interface23.h" #include "unit_tests/os_interface/windows/gdi_dll_fixture.h" #include "runtime/os_interface/windows/os_context_win.h" +#include "runtime/os_interface/windows/os_interface.h" #include "test.h" using namespace OCLRT; @@ -36,19 +37,31 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, publi GmmEnvironmentFixture::SetUp(); GdiDllFixture::SetUp(); - wddm.reset(static_cast(Wddm::createWddm())); + wddm = static_cast(Wddm::createWddm()); + osInterface = std::make_unique(); + osInterface->get()->setWddm(wddm); + wddm->featureTable->ftrWddmHwQueues = true; wddmMockInterface = new WddmMockInterface23(*wddm); wddm->wddmInterface.reset(wddmMockInterface); wddm->registryReader.reset(new RegistryReaderMock()); } + void init() { + EXPECT_TRUE(wddm->init()); + osContext = std::make_unique(osInterface.get()); + osContextWin = osContext->get(); + } + void TearDown() override { GdiDllFixture::TearDown(); GmmEnvironmentFixture::TearDown(); } - std::unique_ptr wddm; + std::unique_ptr osInterface; + std::unique_ptr osContext; + OsContextWin *osContextWin = nullptr; + WddmMock *wddm = nullptr; WddmMockInterface23 *wddmMockInterface = nullptr; }; @@ -56,7 +69,7 @@ struct Wddm23Tests : public Wddm23TestsWithoutWddmInit { using Wddm23TestsWithoutWddmInit::TearDown; void SetUp() override { Wddm23TestsWithoutWddmInit::SetUp(); - EXPECT_TRUE(wddm->init()); + init(); } }; @@ -66,68 +79,68 @@ TEST_F(Wddm23Tests, whenCreateContextIsCalledThenEnableHwQueues) { } TEST_F(Wddm23Tests, whenCreateHwQueueIsCalledThenSetAllRequiredFieldsAndMonitoredFence) { - EXPECT_EQ(wddm->osContext->getContext(), getCreateHwQueueDataFcn()->hHwContext); + EXPECT_EQ(osContextWin->getContext(), getCreateHwQueueDataFcn()->hHwContext); EXPECT_EQ(0u, getCreateHwQueueDataFcn()->PrivateDriverDataSize); EXPECT_EQ(nullptr, getCreateHwQueueDataFcn()->pPrivateDriverData); - EXPECT_TRUE(nullptr != wddm->getMonitoredFence().cpuAddress); - EXPECT_EQ(1u, wddm->getMonitoredFence().currentFenceValue); - EXPECT_NE(static_cast(0), wddm->getMonitoredFence().fenceHandle); - EXPECT_NE(static_cast(0), wddm->getMonitoredFence().gpuAddress); - EXPECT_EQ(0u, wddm->getMonitoredFence().lastSubmittedFence); + EXPECT_TRUE(nullptr != osContextWin->getMonitoredFence().cpuAddress); + EXPECT_EQ(1u, osContextWin->getMonitoredFence().currentFenceValue); + EXPECT_NE(static_cast(0), osContextWin->getMonitoredFence().fenceHandle); + EXPECT_NE(static_cast(0), osContextWin->getMonitoredFence().gpuAddress); + EXPECT_EQ(0u, osContextWin->getMonitoredFence().lastSubmittedFence); } TEST_F(Wddm23Tests, givenPreemptionModeWhenCreateHwQueueCalledThenSetGpuTimeoutIfEnabled) { wddm->setPreemptionMode(PreemptionMode::Disabled); - wddm->wddmInterface->createHwQueue(wddm->preemptionMode, *wddm->osContext); + wddm->wddmInterface->createHwQueue(wddm->preemptionMode, *osContextWin); EXPECT_EQ(0u, getCreateHwQueueDataFcn()->Flags.DisableGpuTimeout); wddm->setPreemptionMode(PreemptionMode::MidBatch); - wddm->wddmInterface->createHwQueue(wddm->preemptionMode, *wddm->osContext); + wddm->wddmInterface->createHwQueue(wddm->preemptionMode, *osContextWin); EXPECT_EQ(1u, getCreateHwQueueDataFcn()->Flags.DisableGpuTimeout); } TEST_F(Wddm23Tests, whenDestroyHwQueueCalledThenPassExistingHandle) { D3DKMT_HANDLE hwQueue = 123; - wddm->osContext->setHwQueue(hwQueue); - wddmMockInterface->destroyHwQueue(wddm->osContext->getHwQueue()); + osContextWin->setHwQueue(hwQueue); + wddmMockInterface->destroyHwQueue(osContextWin->getHwQueue()); EXPECT_EQ(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue); hwQueue = 0; - wddm->osContext->setHwQueue(hwQueue); - wddmMockInterface->destroyHwQueue(wddm->osContext->getHwQueue()); + osContextWin->setHwQueue(hwQueue); + wddmMockInterface->destroyHwQueue(osContextWin->getHwQueue()); EXPECT_NE(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue); // gdi not called when 0 } TEST_F(Wddm23Tests, whenObjectIsDestructedThenDestroyHwQueue) { D3DKMT_HANDLE hwQueue = 123; - wddm->osContext->setHwQueue(hwQueue); - wddm.reset(nullptr); + osContextWin->setHwQueue(hwQueue); + osContext.reset(); EXPECT_EQ(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue); } TEST_F(Wddm23Tests, givenCmdBufferWhenSubmitCalledThenSetAllRequiredFiledsAndUpdateMonitoredFence) { uint64_t cmdBufferAddress = 123; size_t cmdSize = 456; - auto hwQueue = wddm->osContext->getHwQueue(); + auto hwQueue = osContextWin->getHwQueue(); COMMAND_BUFFER_HEADER cmdBufferHeader = {}; - EXPECT_EQ(1u, wddm->getMonitoredFence().currentFenceValue); - EXPECT_EQ(0u, wddm->getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(1u, osContextWin->getMonitoredFence().currentFenceValue); + EXPECT_EQ(0u, osContextWin->getMonitoredFence().lastSubmittedFence); - wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader); + wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContextWin); EXPECT_EQ(cmdBufferAddress, getSubmitCommandToHwQueueDataFcn()->CommandBuffer); EXPECT_EQ(static_cast(cmdSize), getSubmitCommandToHwQueueDataFcn()->CommandLength); EXPECT_EQ(hwQueue, getSubmitCommandToHwQueueDataFcn()->hHwQueue); - EXPECT_EQ(wddm->getMonitoredFence().fenceHandle, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId); + EXPECT_EQ(osContextWin->getMonitoredFence().fenceHandle, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId); EXPECT_EQ(&cmdBufferHeader, getSubmitCommandToHwQueueDataFcn()->pPrivateDriverData); EXPECT_EQ(static_cast(sizeof(COMMAND_BUFFER_HEADER)), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); - EXPECT_EQ(wddm->getMonitoredFence().gpuAddress, cmdBufferHeader.MonitorFenceVA); - EXPECT_EQ(wddm->getMonitoredFence().lastSubmittedFence, cmdBufferHeader.MonitorFenceValue); - EXPECT_EQ(2u, wddm->getMonitoredFence().currentFenceValue); - EXPECT_EQ(1u, wddm->getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(osContextWin->getMonitoredFence().gpuAddress, cmdBufferHeader.MonitorFenceVA); + EXPECT_EQ(osContextWin->getMonitoredFence().lastSubmittedFence, cmdBufferHeader.MonitorFenceValue); + EXPECT_EQ(2u, osContextWin->getMonitoredFence().currentFenceValue); + EXPECT_EQ(1u, osContextWin->getMonitoredFence().lastSubmittedFence); } TEST_F(Wddm23Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhenSubmitCalledThenCallWaitOnGpu) { @@ -137,11 +150,11 @@ TEST_F(Wddm23Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhe *wddm->pagingFenceAddress = 1; wddm->currentPagingFenceValue = 1; - wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader); + wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContextWin); EXPECT_EQ(0u, wddm->waitOnGPUResult.called); wddm->currentPagingFenceValue = 2; - wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader); + wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContextWin); EXPECT_EQ(1u, wddm->waitOnGPUResult.called); } @@ -150,7 +163,7 @@ TEST_F(Wddm23TestsWithoutWddmInit, whenInitCalledThenInitializeNewGdiDDIsAndCall EXPECT_EQ(nullptr, wddm->gdi->destroyHwQueue.mFunc); EXPECT_EQ(nullptr, wddm->gdi->submitCommandToHwQueue.mFunc); - EXPECT_TRUE(wddm->init()); + init(); EXPECT_EQ(1u, wddmMockInterface->createHwQueueCalled); EXPECT_NE(nullptr, wddm->gdi->createHwQueue.mFunc); @@ -160,7 +173,8 @@ TEST_F(Wddm23TestsWithoutWddmInit, whenInitCalledThenInitializeNewGdiDDIsAndCall TEST_F(Wddm23TestsWithoutWddmInit, whenCreateHwQueueFailedThenReturnFalseFromInit) { wddmMockInterface->forceCreateHwQueueFail = true; - EXPECT_FALSE(wddm->init()); + init(); + EXPECT_FALSE(osContextWin->isInitialized()); } TEST_F(Wddm23TestsWithoutWddmInit, givenFailureOnGdiInitializationWhenCreatingHwQueueThenReturnFailure) { @@ -171,7 +185,8 @@ TEST_F(Wddm23TestsWithoutWddmInit, givenFailureOnGdiInitializationWhenCreatingHw }; auto myMockGdi = new MyMockGdi(); wddm->gdi.reset(myMockGdi); - EXPECT_FALSE(wddm->init()); + init(); + EXPECT_FALSE(osContextWin->isInitialized()); EXPECT_EQ(1u, wddmMockInterface->createHwQueueCalled); EXPECT_FALSE(wddmMockInterface->createHwQueueResult); } diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index e42e98fe56..be23e22fbc 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -23,6 +23,7 @@ #pragma once #include "runtime/os_interface/windows/gdi_interface.h" +#include "runtime/os_interface/windows/os_interface.h" #include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/mocks/mock_wddm.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h" @@ -34,11 +35,14 @@ namespace OCLRT { struct WddmFixture : public GmmEnvironmentFixture { void SetUp() override { GmmEnvironmentFixture::SetUp(); - wddm.reset(static_cast(Wddm::createWddm())); + wddm = static_cast(Wddm::createWddm()); + osInterface = std::make_unique(); + osInterface->get()->setWddm(wddm); gdi = new MockGdi(); wddm->gdi.reset(gdi); - EXPECT_TRUE(wddm->osContext == nullptr); wddm->init(); + osContext = std::make_unique(osInterface.get()); + osContextWin = osContext->get(); ASSERT_TRUE(wddm->isInitialized()); } @@ -46,7 +50,11 @@ struct WddmFixture : public GmmEnvironmentFixture { GmmEnvironmentFixture::TearDown(); }; - std::unique_ptr wddm; + WddmMock *wddm = nullptr; + std::unique_ptr osInterface; + std::unique_ptr osContext; + OsContextWin *osContextWin = nullptr; + MockGdi *gdi = nullptr; }; @@ -54,7 +62,16 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi void SetUp() override { GmmEnvironmentFixture::SetUp(); GdiDllFixture::SetUp(); - wddm.reset(static_cast(Wddm::createWddm())); + wddm = static_cast(Wddm::createWddm()); + osInterface = std::make_unique(); + osInterface->get()->setWddm(wddm); + } + + void init() { + EXPECT_TRUE(wddm->init()); + osContext = std::make_unique(osInterface.get()); + osContextWin = osContext->get(); + ASSERT_TRUE(wddm->isInitialized()); } void TearDown() override { @@ -62,7 +79,10 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi GmmEnvironmentFixture::TearDown(); } - std::unique_ptr wddm; + WddmMock *wddm = nullptr; + std::unique_ptr osInterface; + std::unique_ptr osContext; + OsContextWin *osContextWin = nullptr; }; struct WddmInstrumentationGmmFixture : public GmmEnvironmentFixture { diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl index 6e7a60824f..05e684864d 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl @@ -27,7 +27,7 @@ using namespace OCLRT; using namespace ::testing; TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInDevicePoolIsCalledThenNullptrIsReturned) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; allocData.allFlags = 0; 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 c80c5e5f40..607d4850d1 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -26,6 +26,8 @@ #include "runtime/mem_obj/buffer.h" #include "runtime/mem_obj/image.h" #include "runtime/os_interface/os_library.h" +#include "runtime/os_interface/windows/os_context_win.h" +#include "runtime/platform/platform.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_deferred_deleter.h" @@ -91,7 +93,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(size); @@ -108,7 +110,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false); EXPECT_NE(nullptr, allocation); @@ -118,7 +120,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); @@ -131,7 +133,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; @@ -145,7 +147,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); @@ -156,7 +158,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { - memoryManager.reset(new MockWddmMemoryManager(true, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(true, wddm)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); @@ -166,7 +168,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) { - memoryManager.reset(new MockWddmMemoryManager(false, wddm.get())); + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); auto osHandle = 1u; gdi->getQueryResourceInfoArgOut().NumAllocations = 1; std::unique_ptr gmm(new Gmm(nullptr, 0, false)); @@ -1024,7 +1026,7 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllo memoryManager->pushAllocationForResidency(&allocation3); memoryManager->pushAllocationForResidency(&allocation4); - memoryManager->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_TRUE(allocation1.getResidencyData().resident); EXPECT_TRUE(allocation2.getResidencyData().resident); @@ -1040,9 +1042,9 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdatesLa memoryManager->pushAllocationForResidency(&allocation3); memoryManager->pushAllocationForResidency(&allocation4); - wddm->getMonitoredFence().currentFenceValue = 20; + osContext->get()->getMonitoredFence().currentFenceValue = 20; - memoryManager->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_EQ(20u, allocation1.getResidencyData().lastFence); EXPECT_EQ(20u, allocation2.getResidencyData().lastFence); @@ -1060,7 +1062,7 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTrip memoryManager->pushAllocationForResidency(allocationTriple); memoryManager->pushAllocationForResidency(&allocation2); - memoryManager->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident); @@ -1076,13 +1078,13 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLastF WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, reinterpret_cast(0x1500)); - wddm->getMonitoredFence().currentFenceValue = 20; + osContext->get()->getMonitoredFence().currentFenceValue = 20; memoryManager->pushAllocationForResidency(&allocation1); memoryManager->pushAllocationForResidency(allocationTriple); memoryManager->pushAllocationForResidency(&allocation2); - memoryManager->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->lastFence); @@ -1104,13 +1106,16 @@ TEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeriod // allocations have fence value == 0 by default MockWddmAllocation allocation1, allocation2; + + allocation1.getResidencyData().addOsContext(osContext); + allocation2.getResidencyData().addOsContext(osContext); allocation1.getResidencyData().resident = true; allocation2.getResidencyData().resident = true; // Set last periodic fence value memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value - wddm->getMonitoredFence().currentFenceValue = 20; + osContext->get()->getMonitoredFence().currentFenceValue = 20; wddm->makeNonResidentResult.called = 0; @@ -1142,10 +1147,13 @@ TEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPeriodi allocation2.getResidencyData().lastFence = 11; allocation2.getResidencyData().resident = true; + allocation1.getResidencyData().addOsContext(osContext); + allocation2.getResidencyData().addOsContext(osContext); + // Set last periodic fence value memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value - wddm->getMonitoredFence().currentFenceValue = 20; + osContext->get()->getMonitoredFence().currentFenceValue = 20; wddm->makeNonResidentResult.called = 0; @@ -1176,21 +1184,26 @@ TEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFra WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); // whole allocation unused since previous trim allocationTriple->getResidencyData().lastFence = 0; + allocationTriple->getResidencyData().addOsContext(osContext); EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount); allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->lastFence = 0; allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->addOsContext(osContext); // this fragment was used allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->lastFence = 11; allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->addOsContext(osContext); + allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->lastFence = 0; allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->addOsContext(osContext); // Set last periodic fence value memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value - wddm->getMonitoredFence().currentFenceValue = 20; + osContext->get()->getMonitoredFence().currentFenceValue = 20; wddm->makeNonResidentResult.called = 0; @@ -1210,6 +1223,8 @@ TEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFra } TEST_F(WddmMemoryManagerResidencyTest, givenPeriodicTrimWhenTrimCallbackCalledThenLastPeriodicTrimFenceIsSetToCurrentFenceValue) { + platform()->peekExecutionEnvironment()->osInterface = std::move(osInterface); + platform()->initialize(); D3DKMT_TRIMNOTIFICATION trimNotification = {0}; trimNotification.Flags.PeriodicTrim = 1; trimNotification.NumBytesToTrim = 0; @@ -1217,7 +1232,7 @@ TEST_F(WddmMemoryManagerResidencyTest, givenPeriodicTrimWhenTrimCallbackCalledTh // Set last periodic fence value memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value - *wddm->getMonitoredFence().cpuAddress = 20; + *osContext->get()->getMonitoredFence().cpuAddress = 20; memoryManager->trimCandidateList.resize(0); memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); @@ -1226,6 +1241,8 @@ TEST_F(WddmMemoryManagerResidencyTest, givenPeriodicTrimWhenTrimCallbackCalledTh } TEST_F(WddmMemoryManagerResidencyTest, givenRestartPeriodicTrimWhenTrimCallbackCalledThenLastPeriodicTrimFenceIsSetToCurrentFenceValue) { + platform()->peekExecutionEnvironment()->osInterface = std::move(osInterface); + platform()->initialize(); D3DKMT_TRIMNOTIFICATION trimNotification = {0}; trimNotification.Flags.RestartPeriodicTrim = 1; trimNotification.NumBytesToTrim = 0; @@ -1233,7 +1250,7 @@ TEST_F(WddmMemoryManagerResidencyTest, givenRestartPeriodicTrimWhenTrimCallbackC // Set last periodic fence value memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value - *wddm->getMonitoredFence().cpuAddress = 20; + *osContext->get()->getMonitoredFence().cpuAddress = 20; memoryManager->trimCandidateList.resize(0); memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); @@ -1251,18 +1268,22 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) { gdi->setNonZeroNumBytesToTrimInEvict(); MockWddmAllocation allocation1, allocation2, allocation3; + allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; + allocation1.getResidencyData().addOsContext(osContext); allocation2.getResidencyData().lastFence = 1; allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().addOsContext(osContext); allocation3.getResidencyData().lastFence = 2; allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().addOsContext(osContext); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 1; - wddm->getMonitoredFence().currentFenceValue = 1; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 1; + osContext->get()->getMonitoredFence().currentFenceValue = 1; wddm->makeNonResidentResult.called = 0; @@ -1289,11 +1310,13 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToTri gdi->setNonZeroNumBytesToTrimInEvict(); MockWddmAllocation allocation1; + allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; + allocation1.getResidencyData().addOsContext(osContext); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 1; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 1; wddm->makeNonResidentResult.called = 0; memoryManager->trimCandidateList.resize(0); @@ -1315,16 +1338,19 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesToTr allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; + allocation1.getResidencyData().addOsContext(osContext); allocation2.getResidencyData().lastFence = 1; allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().addOsContext(osContext); allocation3.getResidencyData().lastFence = 2; allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().addOsContext(osContext); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 1; - wddm->getMonitoredFence().currentFenceValue = 1; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 1; + osContext->get()->getMonitoredFence().currentFenceValue = 1; wddm->makeNonResidentResult.called = 0; @@ -1349,18 +1375,22 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonResi gdi->setNonZeroNumBytesToTrimInEvict(); MockWddmAllocation allocation1, allocation2, allocation3; + allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; + allocation1.getResidencyData().addOsContext(osContext); allocation2.getResidencyData().lastFence = 1; allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().addOsContext(osContext); allocation3.getResidencyData().lastFence = 2; allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().addOsContext(osContext); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 1; - wddm->getMonitoredFence().currentFenceValue = 1; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 1; + osContext->get()->getMonitoredFence().currentFenceValue = 1; wddm->makeNonResidentResult.called = 0; @@ -1381,12 +1411,14 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIsGr gdi->setNonZeroNumBytesToTrimInEvict(); MockWddmAllocation allocation1; + allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 2; + allocation1.getResidencyData().addOsContext(osContext); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 2; - wddm->getMonitoredFence().currentFenceValue = 3; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 2; + osContext->get()->getMonitoredFence().currentFenceValue = 3; wddm->makeNonResidentResult.called = 0; wddm->waitFromCpuResult.called = 0; @@ -1410,23 +1442,28 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { void *ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1000); WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull); WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull); + allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; + allocation1.getResidencyData().addOsContext(osContext); allocation2.getResidencyData().lastFence = 1; allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().addOsContext(osContext); void *ptrTriple = reinterpret_cast(reinterpret_cast(ptr) + 0x500); WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemory(8196, ptrTriple)); allocationTriple->getResidencyData().lastFence = 1; allocationTriple->getResidencyData().resident = true; + allocationTriple->getResidencyData().addOsContext(osContext); EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount); for (uint32_t i = 0; i < 3; i++) { allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->lastFence = 1; allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->addOsContext(osContext); } // This should not be evicted @@ -1438,9 +1475,9 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { memoryManager->addToTrimCandidateList(allocationTriple); memoryManager->addToTrimCandidateList(&allocation2); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 1; - wddm->getMonitoredFence().currentFenceValue = 2; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 1; + osContext->get()->getMonitoredFence().currentFenceValue = 2; wddm->makeNonResidentResult.called = 0; @@ -1497,16 +1534,19 @@ TEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerTha allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; + allocation1.getResidencyData().addOsContext(osContext); allocation2.getResidencyData().lastFence = 1; allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().addOsContext(osContext); allocation3.getResidencyData().lastFence = 1; allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().addOsContext(osContext); - *wddm->getMonitoredFence().cpuAddress = 1; - wddm->getMonitoredFence().lastSubmittedFence = 1; - wddm->getMonitoredFence().currentFenceValue = 1; + *osContext->get()->getMonitoredFence().cpuAddress = 1; + osContext->get()->getMonitoredFence().lastSubmittedFence = 1; + osContext->get()->getMonitoredFence().currentFenceValue = 1; wddm->makeNonResidentResult.called = 0; @@ -1699,7 +1739,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAlloca memoryManager->pushAllocationForResidency(&allocation3); memoryManager->pushAllocationForResidency(&allocation4); - bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_FALSE(result); @@ -1724,7 +1764,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTriple memoryManager->pushAllocationForResidency(allocationTriple); memoryManager->pushAllocationForResidency(&allocation2); - bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_FALSE(result); @@ -1748,7 +1788,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeResi memoryManager->pushAllocationForResidency(&allocation3); memoryManager->pushAllocationForResidency(&allocation4); - bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_FALSE(result); @@ -1769,7 +1809,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsCallsMakeResident memoryManager->pushAllocationForResidency(&allocation1); - bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_FALSE(result); } @@ -1795,7 +1835,7 @@ TEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResiden EXPECT_CALL(*wddm, makeResident(::testing::_, 2, false, ::testing::_)).Times(1); memoryManager->pushAllocationForResidency(&allocation3); - bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack); + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_TRUE(result); } @@ -1805,7 +1845,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR size_t allocationSize = 0x1000; WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, allocationSize, nullptr, MemoryPool::MemoryNull); - allocationToTrim.getResidencyData().lastFence = wddm->getMonitoredFence().lastSubmittedFence; + allocationToTrim.getResidencyData().lastFence = osContext->get()->getMonitoredFence().lastSubmittedFence; + allocationToTrim.getResidencyData().addOsContext(osContext); auto makeResidentWithOutBytesToTrim = [allocationSize](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = allocationSize; return false; }; @@ -1815,7 +1856,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR memoryManager->pushAllocationForResidency(&allocation1); - bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_TRUE(result); @@ -1831,7 +1872,7 @@ TEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemory EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(makeResidentThatFails)).WillOnce(::testing::Invoke(makeResidentThatSucceds)); memoryManager->pushAllocationForResidency(&allocation1); - bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr, *osContext); EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted()); } @@ -1842,9 +1883,9 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledTh MockWddmMemoryManager memoryManager(wddm.get()); memoryManager.setDeferredDeleter(deleter); EXPECT_EQ(0, deleter->deferDeletionCalled); - memoryManager.tryDeferDeletions(nullptr, 0, 0, 0); + memoryManager.tryDeferDeletions(nullptr, 0, 0, 0, nullptr); EXPECT_EQ(1, deleter->deferDeletionCalled); - EXPECT_EQ(1u, wddm->destroyAllocationResult.called); + EXPECT_EQ(1u, wddm.get()->destroyAllocationResult.called); } TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) { @@ -1852,7 +1893,7 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledT wddm->callBaseDestroyAllocations = false; MockWddmMemoryManager memoryManager(wddm.get()); memoryManager.setDeferredDeleter(nullptr); - memoryManager.tryDeferDeletions(nullptr, 0, 0, 0); + memoryManager.tryDeferDeletions(nullptr, 0, 0, 0, nullptr); EXPECT_EQ(1u, wddm->destroyAllocationResult.called); } 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 1cabe71d9c..de756226c1 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -31,6 +31,7 @@ #include "unit_tests/mocks/mock_gmm_page_table_mngr.h" #include "unit_tests/mocks/mock_gmm.h" #include "unit_tests/os_interface/windows/wddm_fixture.h" +#include "runtime/os_interface/windows/os_interface.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h" #include "unit_tests/os_interface/windows/mock_wddm_memory_manager.h" #include @@ -57,25 +58,32 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture { public: void SetUp() { GmmEnvironmentFixture::SetUp(); - wddm.reset(static_cast(Wddm::createWddm())); + wddm = (static_cast(Wddm::createWddm())); + osInterface = std::make_unique(); + osInterface->get()->setWddm(wddm); gdi = new MockGdi(); wddm->gdi.reset(gdi); EXPECT_TRUE(wddm->init()); + osContext = new OsContext(osInterface.get()); + osContext->incRefInternal(); uint64_t heap32Base = (uint64_t)(0x800000000000); if (sizeof(uintptr_t) == 4) { heap32Base = 0x1000; } wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get())); + memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm)); //assert we have memory manager ASSERT_NE(nullptr, memoryManager); } void TearDown() { + osContext->decRefInternal(); GmmEnvironmentFixture::TearDown(); } std::unique_ptr memoryManager; - std::unique_ptr wddm; + WddmMock *wddm = nullptr; + std::unique_ptr osInterface; + OsContext *osContext; MockGdi *gdi = nullptr; }; @@ -117,23 +125,30 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture { void SetUp() { GmmEnvironmentFixture::SetUp(); // wddm is deleted by memory manager - wddm.reset(new NiceMock); + wddm = new NiceMock; + osInterface = std::make_unique(); ASSERT_NE(nullptr, wddm); + EXPECT_TRUE(wddm->init()); + osInterface->get()->setWddm(wddm); + osContext = new OsContext(osInterface.get()); + osContext->incRefInternal(); wddm->init(); - memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm.get()); + memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm); //assert we have memory manager ASSERT_NE(nullptr, memoryManager); - ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm.get(), &GmockWddm::baseCreateAllocationAndMapGpuVa)); + ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm, &GmockWddm::baseCreateAllocationAndMapGpuVa)); } void TearDown() { + osContext->decRefInternal(); delete memoryManager; - wddm = nullptr; GmmEnvironmentFixture::TearDown(); } - std::unique_ptr> wddm; + NiceMock *wddm = nullptr; + std::unique_ptr osInterface; + OsContext *osContext; }; typedef ::Test WddmMemoryManagerTest2; diff --git a/unit_tests/os_interface/windows/wddm_preemption_tests.cpp b/unit_tests/os_interface/windows/wddm_preemption_tests.cpp index dec6e59793..2db64dc13f 100644 --- a/unit_tests/os_interface/windows/wddm_preemption_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_preemption_tests.cpp @@ -42,13 +42,17 @@ class WddmPreemptionTests : public Test { } void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) { - wddm.reset(static_cast(Wddm::createWddm())); + wddm = static_cast(Wddm::createWddm()); + osInterface = std::make_unique(); + osInterface->get()->setWddm(wddm); auto regReader = new RegistryReaderMock(); wddm->registryReader.reset(regReader); regReader->forceRetValue = forceReturnPreemptionRegKeyValue; PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest); wddm->setPreemptionMode(preemptionMode); wddm->init(); + osContext = std::make_unique(osInterface.get()); + osContextWin = osContext->get(); } DebugManagerStateRestore *dbgRestorer = nullptr;