diff --git a/shared/source/direct_submission/windows/wddm_direct_submission.inl b/shared/source/direct_submission/windows/wddm_direct_submission.inl index 0010dab89f..848c4fe0fa 100644 --- a/shared/source/direct_submission/windows/wddm_direct_submission.inl +++ b/shared/source/direct_submission/windows/wddm_direct_submission.inl @@ -150,7 +150,7 @@ uint64_t WddmDirectSubmission::updateTagValue(bool requir if (requireMonitorFence) { return this->updateTagValueImpl(this->currentRingBuffer); } - MonitoredFence ¤tFence = osContextWin->getResidencyController().getMonitoredFence(); + MonitoredFence ¤tFence = osContextWin->getMonitoredFence(); return currentFence.currentFenceValue; } @@ -161,7 +161,7 @@ bool WddmDirectSubmission::dispatchMonitorFenceRequired(b template uint64_t WddmDirectSubmission::updateTagValueImpl(uint32_t completionBufferIndex) { - MonitoredFence ¤tFence = osContextWin->getResidencyController().getMonitoredFence(); + MonitoredFence ¤tFence = osContextWin->getMonitoredFence(); currentFence.lastSubmittedFence = currentFence.currentFenceValue; currentFence.currentFenceValue++; @@ -182,7 +182,7 @@ void WddmDirectSubmission::handleCompletionFence(uint64_t template void WddmDirectSubmission::getTagAddressValue(TagData &tagData) { - MonitoredFence ¤tFence = osContextWin->getResidencyController().getMonitoredFence(); + MonitoredFence ¤tFence = osContextWin->getMonitoredFence(); auto gmmHelper = wddm->getRootDeviceEnvironment().getGmmHelper(); tagData.tagAddress = gmmHelper->canonize(currentFence.gpuAddress); @@ -226,7 +226,7 @@ void WddmDirectSubmission::updateMonitorFenceValueForResi if (allocationsForResidency == nullptr) { return; } - const auto currentFence = osContextWin->getResidencyController().getMonitoredFence().currentFenceValue; + const auto currentFence = osContextWin->getMonitoredFence().currentFenceValue; auto contextId = osContextWin->getContextId(); for (uint32_t i = 0; i < allocationsForResidency->size(); i++) { WddmAllocation *allocation = static_cast((*allocationsForResidency)[i]); diff --git a/shared/source/os_interface/windows/os_context_win.cpp b/shared/source/os_interface/windows/os_context_win.cpp index 35aee7e3ad..4158c90b68 100644 --- a/shared/source/os_interface/windows/os_context_win.cpp +++ b/shared/source/os_interface/windows/os_context_win.cpp @@ -51,7 +51,7 @@ bool OsContextWin::initializeContext(bool allocateInterrupt) { } return true; -}; +} void OsContextWin::reInitializeContext() { NEO::EnvironmentVariableReader envReader; @@ -68,7 +68,15 @@ void OsContextWin::reInitializeContext() { UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this)); } } -}; +} + +void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) { + monitoredFence.lastSubmittedFence = 0; + monitoredFence.currentFenceValue = 1; + monitoredFence.fenceHandle = handle; + monitoredFence.cpuAddress = cpuAddress; + monitoredFence.gpuAddress = gpuAddress; +} void OsContextWin::getDeviceLuidArray(std::vector &luidData, size_t arraySize) { auto *wddm = this->getWddm(); @@ -85,7 +93,7 @@ void OsContextWin::getDeviceLuidArray(std::vector &luidData, size_t arr luidData.emplace(luidData.end(), luidArray[i - 4]); } } -}; +} uint32_t OsContextWin::getDeviceNodeMask() { auto *wddm = this->getWddm(); @@ -108,8 +116,8 @@ bool OsContextWin::isDirectSubmissionSupported() const { OsContextWin::~OsContextWin() { if (contextInitialized && (false == this->wddm.skipResourceCleanup())) { wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle); - if (residencyController.getMonitoredFence().fenceHandle != hardwareQueue.progressFenceHandle) { - wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence().fenceHandle); + if (getMonitoredFence().fenceHandle != hardwareQueue.progressFenceHandle) { + wddm.getWddmInterface()->destroyMonitorFence(getMonitoredFence().fenceHandle); } if (!isPartOfContextGroup() || diff --git a/shared/source/os_interface/windows/os_context_win.h b/shared/source/os_interface/windows/os_context_win.h index d7eaa753a3..2884ff5102 100644 --- a/shared/source/os_interface/windows/os_context_win.h +++ b/shared/source/os_interface/windows/os_context_win.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -35,6 +35,11 @@ class OsContextWin : public OsContext { Wddm *getWddm() const { return &wddm; } MOCKABLE_VIRTUAL WddmResidencyController &getResidencyController() { return residencyController; } static OsContext *create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor); + MonitoredFence &getMonitoredFence() { return monitoredFence; } + void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress); + bool wasAllocationUsedSinceLastTrim(uint64_t fenceValue) { return fenceValue > lastTrimFenceValue; } + void updateLastTrimFenceValue() { lastTrimFenceValue = *this->getMonitoredFence().cpuAddress; } + uint64_t getLastTrimFenceValue() const { return this->lastTrimFenceValue; }; void reInitializeContext() override; void getDeviceLuidArray(std::vector &luidData, size_t arraySize); uint32_t getDeviceNodeMask(); @@ -44,7 +49,12 @@ class OsContextWin : public OsContext { bool initializeContext(bool allocateInterrupt) override; WddmResidencyController residencyController; + HardwareQueue hardwareQueue; + + MonitoredFence monitoredFence = {}; + uint64_t lastTrimFenceValue = 0u; + Wddm &wddm; D3DKMT_HANDLE wddmContextHandle = 0; }; diff --git a/shared/source/os_interface/windows/trim_callback.cpp b/shared/source/os_interface/windows/trim_callback.cpp index 0c72a85f8f..e112617249 100644 --- a/shared/source/os_interface/windows/trim_callback.cpp +++ b/shared/source/os_interface/windows/trim_callback.cpp @@ -7,6 +7,7 @@ #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/os_interface/windows/gdi_interface.h" +#include "shared/source/os_interface/windows/os_context_win.h" #include "shared/source/os_interface/windows/wddm/wddm.h" #include "shared/source/os_interface/windows/wddm/wddm_residency_logger.h" #include "shared/source/os_interface/windows/wddm_allocation.h" @@ -56,7 +57,8 @@ void APIENTRY WddmResidencyController::trimCallback(_Inout_ D3DKMT_TRIMNOTIFICAT void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS &flags, uint64_t bytes) { std::chrono::high_resolution_clock::time_point callbackStart; perfLogResidencyTrimCallbackBegin(wddm.getResidencyLogger(), callbackStart); - uint32_t osContextId = this->csr->getOsContext().getContextId(); + auto &osContext = static_cast(this->csr->getOsContext()); + uint32_t osContextId = osContext.getContextId(); if (flags.PeriodicTrim) { uint64_t sizeToTrim = 0; @@ -67,9 +69,9 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS for (auto allocationIter = evictionAllocations.begin(); allocationIter != evictionAllocations.end();) { wddmAllocation = reinterpret_cast(*allocationIter); - DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "lastPeriodicTrimFenceValue = ", lastTrimFenceValue); + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "lastPeriodicTrimFenceValue = ", osContext.getLastTrimFenceValue()); - if (wasAllocationUsedSinceLastTrim(wddmAllocation->getResidencyData().getFenceValueForContextId(osContextId))) { + if (osContext.wasAllocationUsedSinceLastTrim(wddmAllocation->getResidencyData().getFenceValueForContextId(osContextId))) { allocationIter++; continue; } @@ -87,7 +89,7 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) { AllocationStorageData &fragmentStorageData = wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId]; - if (!wasAllocationUsedSinceLastTrim(fragmentStorageData.residency->getFenceValueForContextId(osContextId))) { + if (!osContext.wasAllocationUsedSinceLastTrim(fragmentStorageData.residency->getFenceValueForContextId(osContextId))) { auto osHandle = static_cast(wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage); DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict fragment: handle =", osHandle->handle, "lastFence =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(osContextId)); @@ -112,8 +114,8 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS } if (flags.PeriodicTrim || flags.RestartPeriodicTrim) { - this->updateLastTrimFenceValue(); - DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "updated lastPeriodicTrimFenceValue =", lastTrimFenceValue); + osContext.updateLastTrimFenceValue(); + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "updated lastPeriodicTrimFenceValue =", osContext.getLastTrimFenceValue()); } perfLogResidencyTrimCallbackEnd(wddm.getResidencyLogger(), flags.Value, this, callbackStart); @@ -121,7 +123,8 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) { this->csr->drainPagingFenceQueue(); - uint32_t osContextId = this->csr->getOsContext().getContextId(); + auto &osContext = static_cast(this->csr->getOsContext()); + uint32_t osContextId = osContext.getContextId(); uint64_t sizeToTrim = 0; uint64_t numberOfBytesToTrim = bytes; WddmAllocation *wddmAllocation = nullptr; @@ -133,7 +136,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) { while (numberOfBytesToTrim > 0 && allocationIter != evictionAllocations.end()) { wddmAllocation = reinterpret_cast(*allocationIter); uint64_t lastFence = wddmAllocation->getResidencyData().getFenceValueForContextId(osContextId); - auto &monitoredFence = this->getMonitoredFence(); + auto &monitoredFence = osContext.getMonitoredFence(); if (lastFence > monitoredFence.lastSubmittedFence) { allocationIter++; @@ -148,7 +151,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) { uint64_t sizeEvicted = 0; if (lastFence > *monitoredFence.cpuAddress) { - this->wddm.waitFromCpu(lastFence, this->getMonitoredFence(), false); + this->wddm.waitFromCpu(lastFence, osContext.getMonitoredFence(), false); } if (wddmAllocation->fragmentsStorage.fragmentCount == 0) { diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 4ebd70a0ee..d3437434ff 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -1197,7 +1197,7 @@ bool Wddm::waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredF if (!skipResourceCleanup() && lastFenceValue > *monitoredFence.cpuAddress) { CommandStreamReceiver *csr = nullptr; this->forEachContextWithinWddm([&monitoredFence, &csr](const EngineControl &engine) { - auto &contextMonitoredFence = static_cast(engine.osContext)->getResidencyController().getMonitoredFence(); + auto &contextMonitoredFence = static_cast(engine.osContext)->getMonitoredFence(); if (contextMonitoredFence.cpuAddress == monitoredFence.cpuAddress) { csr = engine.commandStreamReceiver; } @@ -1239,7 +1239,7 @@ bool Wddm::waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredF bool Wddm::isGpuHangDetected(OsContext &osContext) { const auto osContextWin = static_cast(&osContext); - const auto &monitoredFence = osContextWin->getResidencyController().getMonitoredFence(); + const auto &monitoredFence = osContextWin->getMonitoredFence(); bool hangDetected = monitoredFence.cpuAddress && *monitoredFence.cpuAddress == gpuHangIndication; PRINT_DEBUG_STRING(hangDetected && debugManager.flags.PrintDebugMessages.get(), stderr, "%s", "ERROR: GPU HANG detected!\n"); diff --git a/shared/source/os_interface/windows/wddm/wddm_interface.cpp b/shared/source/os_interface/windows/wddm/wddm_interface.cpp index ac1180872f..c8bb146064 100644 --- a/shared/source/os_interface/windows/wddm/wddm_interface.cpp +++ b/shared/source/os_interface/windows/wddm/wddm_interface.cpp @@ -47,8 +47,7 @@ bool WddmInterface20::createHwQueue(OsContextWin &osContext) { void WddmInterface20::destroyHwQueue(D3DKMT_HANDLE hwQueue) {} bool WddmInterface20::createMonitoredFence(OsContextWin &osContext) { - auto &residencyController = osContext.getResidencyController(); - MonitoredFence &monitorFence = residencyController.getMonitoredFence(); + MonitoredFence &monitorFence = osContext.getMonitoredFence(); bool ret = WddmInterface::createMonitoredFence(monitorFence); monitorFence.currentFenceValue = 1; @@ -131,11 +130,10 @@ bool WddmInterface23::createHwQueue(OsContextWin &osContext) { } bool WddmInterface23::createMonitoredFence(OsContextWin &osContext) { - auto &residencyController = osContext.getResidencyController(); auto hwQueue = osContext.getHwQueue(); - residencyController.resetMonitoredFenceParams(hwQueue.progressFenceHandle, - reinterpret_cast(hwQueue.progressFenceCpuVA), - hwQueue.progressFenceGpuVA); + osContext.resetMonitoredFenceParams(hwQueue.progressFenceHandle, + reinterpret_cast(hwQueue.progressFenceCpuVA), + hwQueue.progressFenceGpuVA); return true; } @@ -187,14 +185,13 @@ bool WddmInterface23::submit(uint64_t commandBuffer, size_t size, void *commandH bool NEO::WddmInterface23::createFenceForDirectSubmission(MonitoredFence &monitorFence, OsContextWin &osContext) { MonitoredFence monitorFenceForResidency{}; auto ret = createSyncObject(monitorFenceForResidency); - auto &residencyController = osContext.getResidencyController(); - auto lastSubmittedFence = residencyController.getMonitoredFence().lastSubmittedFence; - auto currentFenceValue = residencyController.getMonitoredFence().currentFenceValue; - residencyController.resetMonitoredFenceParams(monitorFenceForResidency.fenceHandle, - const_cast(monitorFenceForResidency.cpuAddress), - monitorFenceForResidency.gpuAddress); - residencyController.getMonitoredFence().currentFenceValue = currentFenceValue; - residencyController.getMonitoredFence().lastSubmittedFence = lastSubmittedFence; + auto lastSubmittedFence = osContext.getMonitoredFence().lastSubmittedFence; + auto currentFenceValue = osContext.getMonitoredFence().currentFenceValue; + osContext.resetMonitoredFenceParams(monitorFenceForResidency.fenceHandle, + const_cast(monitorFenceForResidency.cpuAddress), + monitorFenceForResidency.gpuAddress); + osContext.getMonitoredFence().currentFenceValue = currentFenceValue; + osContext.getMonitoredFence().lastSubmittedFence = lastSubmittedFence; auto hwQueue = osContext.getHwQueue(); monitorFence.cpuAddress = reinterpret_cast(hwQueue.progressFenceCpuVA); diff --git a/shared/source/os_interface/windows/wddm_device_command_stream.inl b/shared/source/os_interface/windows/wddm_device_command_stream.inl index 599f85718d..4eb298e3f3 100644 --- a/shared/source/os_interface/windows/wddm_device_command_stream.inl +++ b/shared/source/os_interface/windows/wddm_device_command_stream.inl @@ -134,7 +134,7 @@ SubmissionStatus WddmCommandStreamReceiver::flush(BatchBuffer &batchB WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContextWin->getWddmContextHandle(); submitArgs.hwQueueHandle = osContextWin->getHwQueue().handle; - submitArgs.monitorFence = &osContextWin->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContextWin->getMonitoredFence(); auto status = wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, submitArgs); this->flushStamp->setStamp(submitArgs.monitorFence->lastSubmittedFence); @@ -147,7 +147,7 @@ SubmissionStatus WddmCommandStreamReceiver::flush(BatchBuffer &batchB template SubmissionStatus WddmCommandStreamReceiver::processResidency(ResidencyContainer &allocationsForResidency, uint32_t handleId) { - return static_cast(this->osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency, this->requiresBlockingResidencyHandling, this->osContext->getContextId()) ? SubmissionStatus::success : SubmissionStatus::outOfMemory; + return static_cast(this->osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency, this->requiresBlockingResidencyHandling, *static_cast(this->osContext)) ? SubmissionStatus::success : SubmissionStatus::outOfMemory; } template @@ -161,7 +161,7 @@ WddmMemoryManager *WddmCommandStreamReceiver::getMemoryManager() cons template bool WddmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStampToWait) { - return wddm->waitFromCpu(flushStampToWait, static_cast(this->osContext)->getResidencyController().getMonitoredFence(), false); + return wddm->waitFromCpu(flushStampToWait, static_cast(this->osContext)->getMonitoredFence(), false); } template diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 6f15a575b1..c54cffe796 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -815,7 +815,7 @@ void WddmMemoryManager::handleFenceCompletion(GraphicsAllocation *allocation) { for (auto &engine : getRegisteredEngines(allocation->getRootDeviceIndex())) { const auto lastFenceValue = wddmAllocation->getResidencyData().getFenceValueForContextId(engine.osContext->getContextId()); if (lastFenceValue != 0u) { - const auto &monitoredFence = static_cast(engine.osContext)->getResidencyController().getMonitoredFence(); + const auto &monitoredFence = static_cast(engine.osContext)->getMonitoredFence(); const auto wddm = static_cast(engine.osContext)->getWddm(); wddm->waitFromCpu(lastFenceValue, monitoredFence, engine.commandStreamReceiver->isAnyDirectSubmissionEnabled()); } diff --git a/shared/source/os_interface/windows/wddm_residency_controller.cpp b/shared/source/os_interface/windows/wddm_residency_controller.cpp index 425beca5df..1c506debeb 100644 --- a/shared/source/os_interface/windows/wddm_residency_controller.cpp +++ b/shared/source/os_interface/windows/wddm_residency_controller.cpp @@ -9,6 +9,7 @@ #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/os_interface/windows/os_context_win.h" #include "shared/source/os_interface/windows/wddm/wddm.h" #include "shared/source/os_interface/windows/wddm_allocation.h" #include "shared/source/os_interface/windows/wddm_residency_allocations_container.h" @@ -41,14 +42,6 @@ std::unique_lock WddmResidencyController::acquireTrimCallbackLock() { return std::unique_lock{this->trimCallbackLock}; } -void WddmResidencyController::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) { - monitoredFence.lastSubmittedFence = 0; - monitoredFence.currentFenceValue = 1; - monitoredFence.fenceHandle = handle; - monitoredFence.cpuAddress = cpuAddress; - monitoredFence.gpuAddress = gpuAddress; -} - /** * @brief Makes resident passed allocations on a device * @@ -61,7 +54,8 @@ void WddmResidencyController::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, u * * @return returns true if all allocations either succeeded or are pending to be resident */ -bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, uint32_t osContextId) { +bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, OsContextWin &osContext) { + auto osContextId = osContext.getContextId(); const size_t residencyCount = allocationsForResidency.size(); requiresBlockingResidencyHandling = false; if (debugManager.flags.WaitForPagingFenceInController.get() != -1) { @@ -70,7 +64,7 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine auto lock = this->acquireLock(); backupResidencyContainer = allocationsForResidency; - auto totalSize = fillHandlesContainer(allocationsForResidency, requiresBlockingResidencyHandling, osContextId); + auto totalSize = fillHandlesContainer(allocationsForResidency, requiresBlockingResidencyHandling, osContext); bool result = true; if (!handlesForResidency.empty()) { @@ -81,7 +75,7 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine allocationsForResidency = backupResidencyContainer; if (!trimmingDone) { auto evictionStatus = wddm.getTemporaryResourcesContainer()->evictAllResources(); - totalSize = fillHandlesContainer(allocationsForResidency, requiresBlockingResidencyHandling, osContextId); + totalSize = fillHandlesContainer(allocationsForResidency, requiresBlockingResidencyHandling, osContext); if (evictionStatus == MemoryOperationsStatus::success) { continue; } @@ -91,10 +85,10 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine } while (debugManager.flags.WaitForMemoryRelease.get() && result == false); break; } - totalSize = fillHandlesContainer(allocationsForResidency, requiresBlockingResidencyHandling, osContextId); + totalSize = fillHandlesContainer(allocationsForResidency, requiresBlockingResidencyHandling, osContext); } } - const auto currentFence = this->getMonitoredFence().currentFenceValue; + const auto currentFence = osContext.getMonitoredFence().currentFenceValue; if (result == true) { for (uint32_t i = 0; i < residencyCount; i++) { @@ -121,13 +115,14 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine * * @return returns total size in bytes of allocations which are not yet resident. */ -size_t WddmResidencyController::fillHandlesContainer(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, uint32_t osContextId) { +size_t WddmResidencyController::fillHandlesContainer(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, OsContextWin &osContext) { + auto osContextId = osContext.getContextId(); size_t totalSize = 0; const size_t residencyCount = allocationsForResidency.size(); handlesForResidency.clear(); handlesForResidency.reserve(residencyCount); - DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", this->getMonitoredFence().currentFenceValue); + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.getMonitoredFence().currentFenceValue); auto checkIfAlreadyResident = [&](GraphicsAllocation *alloc) { WddmAllocation *allocation = static_cast(alloc); diff --git a/shared/source/os_interface/windows/wddm_residency_controller.h b/shared/source/os_interface/windows/wddm_residency_controller.h index 8d108824df..397e645453 100644 --- a/shared/source/os_interface/windows/wddm_residency_controller.h +++ b/shared/source/os_interface/windows/wddm_residency_controller.h @@ -25,6 +25,7 @@ class GraphicsAllocation; class WddmAllocation; class Wddm; class CommandStreamReceiver; +class OsContextWin; class WddmResidencyController { public: @@ -36,12 +37,6 @@ class WddmResidencyController { [[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock acquireLock(); [[nodiscard]] std::unique_lock acquireTrimCallbackLock(); - bool wasAllocationUsedSinceLastTrim(uint64_t fenceValue) { return fenceValue > lastTrimFenceValue; } - void updateLastTrimFenceValue() { lastTrimFenceValue = *this->getMonitoredFence().cpuAddress; } - - MonitoredFence &getMonitoredFence() { return monitoredFence; } - void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress); - void registerCallback(); void trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS &flags, uint64_t bytes); @@ -50,7 +45,7 @@ class WddmResidencyController { bool isMemoryBudgetExhausted() const { return memoryBudgetExhausted; } void setMemoryBudgetExhausted() { memoryBudgetExhausted = true; } - bool makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, uint32_t osContextId); + bool makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, OsContextWin &osContext); bool isInitialized() const; @@ -63,15 +58,11 @@ class WddmResidencyController { } protected: - size_t fillHandlesContainer(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, uint32_t osContextId); - - MonitoredFence monitoredFence = {}; + size_t fillHandlesContainer(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, OsContextWin &osContext); SpinLock lock; SpinLock trimCallbackLock; - uint64_t lastTrimFenceValue = 0u; - Wddm &wddm; VOID *trimCallbackHandle = nullptr; diff --git a/shared/test/common/mocks/mock_os_context_win.h b/shared/test/common/mocks/mock_os_context_win.h index ff23662518..f0086e4001 100644 --- a/shared/test/common/mocks/mock_os_context_win.h +++ b/shared/test/common/mocks/mock_os_context_win.h @@ -12,6 +12,8 @@ namespace NEO { class MockOsContextWin : public OsContextWin { public: + using OsContextWin::lastTrimFenceValue; + MockOsContextWin(Wddm &wddm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor) : OsContextWin(wddm, rootDeviceIndex, contextId, engineDescriptor), mockResidencyController(wddm) {} diff --git a/shared/test/common/mocks/mock_wddm_residency_controller.h b/shared/test/common/mocks/mock_wddm_residency_controller.h index ec78145ebd..be8b356f9f 100644 --- a/shared/test/common/mocks/mock_wddm_residency_controller.h +++ b/shared/test/common/mocks/mock_wddm_residency_controller.h @@ -12,7 +12,6 @@ namespace NEO { class MockWddmResidencyController : public WddmResidencyController { public: using WddmResidencyController::csr; - using WddmResidencyController::lastTrimFenceValue; using WddmResidencyController::lock; using WddmResidencyController::trimCallbackHandle; using WddmResidencyController::trimResidency; diff --git a/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp b/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp index 9b90c30fe3..a4d105c85d 100644 --- a/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp +++ b/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp @@ -279,7 +279,7 @@ HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenAllocateOsResourcesResidencyFail HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenGettingTagDataThenExpectContextMonitorFence) { uint64_t address = 0xFF00FF0000ull; uint64_t value = 0x12345678ull; - MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); + MonitoredFence &contextFence = osContext->getMonitoredFence(); contextFence.gpuAddress = address; contextFence.currentFenceValue = value; @@ -304,7 +304,7 @@ HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenHandleResidencyThenExpectWddmWai HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenHandlingRingBufferCompletionThenExpectWaitFromCpuWithCorrectFenceValue) { uint64_t address = 0xFF00FF0000ull; uint64_t value = 0x12345678ull; - MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); + MonitoredFence &contextFence = osContext->getMonitoredFence(); contextFence.gpuAddress = address; contextFence.currentFenceValue = value; @@ -532,7 +532,7 @@ HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenSwitchingRingBufferStartedAndWai HWTEST_F(WddmDirectSubmissionTest, givenWddmDisableMonitorFenceAndStallingCmdsWhenUpdatingTagValueThenUpdateCompletionFence) { uint64_t address = 0xFF00FF0000ull; uint64_t value = 0x12345678ull; - MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); + MonitoredFence &contextFence = osContext->getMonitoredFence(); contextFence.gpuAddress = address; contextFence.currentFenceValue = value; @@ -551,7 +551,7 @@ HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenNoMonitorFenceHangDetected VariableBackup backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn()); - MonitoredFence &contextFence = osContextWin->getResidencyController().getMonitoredFence(); + MonitoredFence &contextFence = osContextWin->getMonitoredFence(); VariableBackup backupWddmMonitorFence(contextFence.cpuAddress); *contextFence.cpuAddress = 1; contextFence.currentFenceValue = 2u; @@ -574,7 +574,7 @@ HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenWddmMonitorFenceHangDetect VariableBackup backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn()); - MonitoredFence &contextFence = osContextWin->getResidencyController().getMonitoredFence(); + MonitoredFence &contextFence = osContextWin->getMonitoredFence(); VariableBackup backupWddmMonitorFence(contextFence.cpuAddress); *contextFence.cpuAddress = std::numeric_limits::max(); @@ -607,7 +607,7 @@ HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenRingMonitorFenceHangDetect HWTEST_F(WddmDirectSubmissionTest, givenDetectGpuFalseAndRequiredMonitorFenceWhenCallUpdateTagValueThenCurrentFenceValueIsReturned) { uint64_t value = 0x12345678ull; - MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); + MonitoredFence &contextFence = osContext->getMonitoredFence(); contextFence.currentFenceValue = value; MockWddmDirectSubmission> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); @@ -812,7 +812,7 @@ HWTEST_F(WddmDirectSubmissionTest, hwParse.parseCommands(wddmDirectSubmission.ringCommandStream, sizeUsedBefore); hwParse.findHardwareCommands(); - auto &monitorFence = osContext->getResidencyController().getMonitoredFence(); + auto &monitorFence = osContext->getMonitoredFence(); bool foundFenceUpdate = false; for (auto it = hwParse.pipeControlList.begin(); it != hwParse.pipeControlList.end(); it++) { @@ -875,7 +875,7 @@ HWTEST_F(WddmDirectSubmissionTest, hwParse.parseCommands(wddmDirectSubmission.ringCommandStream, sizeUsedBefore); hwParse.findHardwareCommands(); - auto &monitorFence = osContext->getResidencyController().getMonitoredFence(); + auto &monitorFence = osContext->getMonitoredFence(); bool foundFenceUpdate = false; for (auto it = hwParse.pipeControlList.begin(); it != hwParse.pipeControlList.end(); it++) { @@ -954,18 +954,6 @@ HWTEST_F(WddmDirectSubmissionTest, givenNullPtrResidencyControllerWhenUpdatingRe EXPECT_EQ(mockOsContextWin->getResidencyControllerCalledTimes, 0u); } -HWTEST_F(WddmDirectSubmissionTest, givenEmptyResidencyControllerWhenUpdatingResidencyAfterSwitchRingThenReturnAfterAccessingContextId) { - - using Dispatcher = RenderDispatcher; - auto mockOsContextWin = std::make_unique(*wddm, 0, 0, EngineDescriptorHelper::getDefaultDescriptor()); - - MockWddmDirectSubmission wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); - wddmDirectSubmission.osContextWin = mockOsContextWin.get(); - ResidencyContainer container; - wddmDirectSubmission.updateMonitorFenceValueForResidencyList(&container); - EXPECT_EQ(mockOsContextWin->getResidencyControllerCalledTimes, 1u); -} - HWTEST_F(WddmDirectSubmissionTest, givenResidencyControllerWhenUpdatingResidencyAfterSwitchRingThenAllocationCallUpdateResidency) { using Dispatcher = RenderDispatcher; diff --git a/shared/test/unit_test/os_interface/windows/device_command_stream_tests.cpp b/shared/test/unit_test/os_interface/windows/device_command_stream_tests.cpp index 2b63d40954..f11381895c 100644 --- a/shared/test/unit_test/os_interface/windows/device_command_stream_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/device_command_stream_tests.cpp @@ -233,7 +233,7 @@ HWTEST_TEMPLATED_F(WddmCommandStreamTest, WhenFlushingThenFlushIsSubmitted) { EXPECT_EQ(1u, wddm->submitResult.called); EXPECT_TRUE(wddm->submitResult.success); - EXPECT_EQ(csr->obtainCurrentFlushStamp(), static_cast(csr->getOsContext()).getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(csr->obtainCurrentFlushStamp(), static_cast(csr->getOsContext()).getMonitoredFence().lastSubmittedFence); memoryManager->freeGraphicsMemory(commandBuffer); } @@ -1103,7 +1103,7 @@ HWTEST_TEMPLATED_F(WddmCommandStreamMockGdiTest, givenLastSubmittedFenceLowerTha monitorFence.cpuAddress = &value; auto gpuVa = castToUint64(&value); - static_cast(device->getDefaultEngine().osContext)->getResidencyController().resetMonitoredFenceParams(handle, &value, gpuVa); + static_cast(device->getDefaultEngine().osContext)->resetMonitoredFenceParams(handle, &value, gpuVa); wddm->waitFromCpu(1, monitorFence, false); EXPECT_EQ(directSubmission->flushMonitorFenceCalled, 2u); diff --git a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp index d5c7a4848b..00f5325a5a 100644 --- a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -334,7 +334,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenWddmAllocationWhenMappingGpuVaThenUseGmmS } TEST_F(Wddm20WithMockGdiDllTests, GivenInvalidCpuAddressWhenCheckingForGpuHangThenFalseIsReturned) { - osContext->getResidencyController().getMonitoredFence().cpuAddress = nullptr; + osContext->getMonitoredFence().cpuAddress = nullptr; EXPECT_FALSE(wddm->isGpuHangDetected(*osContext)); } @@ -342,7 +342,7 @@ TEST_F(Wddm20WithMockGdiDllTests, GivenCpuValueDifferentThanGpuHangIndicationWhe constexpr auto cpuValue{777u}; ASSERT_NE(NEO::Wddm::gpuHangIndication, cpuValue); - *osContext->getResidencyController().getMonitoredFence().cpuAddress = cpuValue; + *osContext->getMonitoredFence().cpuAddress = cpuValue; EXPECT_FALSE(wddm->isGpuHangDetected(*osContext)); } @@ -355,7 +355,7 @@ TEST_F(Wddm20WithMockGdiDllTests, whencreateMonitoredFenceForDirectSubmissionThe } TEST_F(Wddm20WithMockGdiDllTests, GivenGpuHangIndicationWhenCheckingForGpuHangThenTrueIsReturned) { - auto fenceCpuAddress = osContext->getResidencyController().getMonitoredFence().cpuAddress; + auto fenceCpuAddress = osContext->getMonitoredFence().cpuAddress; VariableBackup backupWddmMonitorFence(fenceCpuAddress); *fenceCpuAddress = NEO::Wddm::gpuHangIndication; @@ -878,7 +878,7 @@ TEST_F(Wddm20WithMockGdiDllTests, whenCreateContextIsCalledThenDisableHwQueues) } TEST_F(Wddm20WithMockGdiDllTests, givenDestructionOsContextWinWhenCallingDestroyMonitorFenceThenDoCallGdiDestroy) { - auto fenceHandle = osContext->getResidencyController().getMonitoredFence().fenceHandle; + auto fenceHandle = osContext->getMonitoredFence().fenceHandle; osContext.reset(nullptr); EXPECT_EQ(1u, wddmMockInterface->destroyMonitorFenceCalled); @@ -978,7 +978,7 @@ TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedTo allocation.getResidencyData().updateCompletionData(10, osContext->getContextId()); allocation.handle = ALLOCATION_HANDLE; - *osContext->getResidencyController().getMonitoredFence().cpuAddress = 10; + *osContext->getMonitoredFence().cpuAddress = 10; gdi->getWaitFromCpuArg().FenceValueArray = nullptr; gdi->getWaitFromCpuArg().Flags.Value = 0; @@ -1004,7 +1004,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle allocation.getResidencyData().updateCompletionData(10, osContext->getContextId()); allocation.handle = ALLOCATION_HANDLE; - *osContext->getResidencyController().getMonitoredFence().cpuAddress = 10; + *osContext->getMonitoredFence().cpuAddress = 10; gdi->getWaitFromCpuArg().FenceValueArray = nullptr; gdi->getWaitFromCpuArg().Flags.Value = 0; @@ -1012,7 +1012,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle gdi->getWaitFromCpuArg().ObjectCount = 0; gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr; - auto status = wddm->waitFromCpu(10, osContext->getResidencyController().getMonitoredFence(), true); + auto status = wddm->waitFromCpu(10, osContext->getMonitoredFence(), true); EXPECT_TRUE(status); @@ -1027,7 +1027,7 @@ TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { allocation.getResidencyData().updateCompletionData(10, osContext->getContextId()); allocation.handle = ALLOCATION_HANDLE; - *osContext->getResidencyController().getMonitoredFence().cpuAddress = 10; + *osContext->getMonitoredFence().cpuAddress = 10; gdi->getWaitFromCpuArg().FenceValueArray = nullptr; gdi->getWaitFromCpuArg().Flags.Value = 0; @@ -1035,7 +1035,7 @@ TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { gdi->getWaitFromCpuArg().ObjectCount = 0; gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr; - auto status = wddm->waitFromCpu(20, osContext->getResidencyController().getMonitoredFence(), true); + auto status = wddm->waitFromCpu(20, osContext->getMonitoredFence(), true); EXPECT_TRUE(status); @@ -1053,7 +1053,7 @@ TEST_F(Wddm20Tests, WhenCreatingMonitoredFenceThenItIsInitializedWithFenceValueZ wddm->wddmInterface->createMonitoredFence(*osContext); EXPECT_EQ(0u, gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue); - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); + EXPECT_EQ(1u, osContext->getMonitoredFence().currentFenceValue); } NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) { diff --git a/shared/test/unit_test/os_interface/windows/wddm23_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm23_tests.cpp index adb4f36fa6..0f16ea6834 100644 --- a/shared/test/unit_test/os_interface/windows/wddm23_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm23_tests.cpp @@ -110,15 +110,15 @@ TEST_F(Wddm23Tests, whenObjectIsDestructedThenDestroyHwQueue) { } TEST_F(Wddm23Tests, whencreateMonitoredFenceForDirectSubmissionThenObtainHwQueueFenceAndReplaceResidencyControllerWithNewFence) { - EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().fenceHandle, osContext->getHwQueue().progressFenceHandle); - osContext->getResidencyController().getMonitoredFence().currentFenceValue = 2u; - osContext->getResidencyController().getMonitoredFence().lastSubmittedFence = 1u; + EXPECT_EQ(osContext->getMonitoredFence().fenceHandle, osContext->getHwQueue().progressFenceHandle); + osContext->getMonitoredFence().currentFenceValue = 2u; + osContext->getMonitoredFence().lastSubmittedFence = 1u; MonitoredFence fence{}; wddm->getWddmInterface()->createFenceForDirectSubmission(fence, *osContext); EXPECT_EQ(osContext->getHwQueue().progressFenceHandle, fence.fenceHandle); - EXPECT_NE(osContext->getResidencyController().getMonitoredFence().fenceHandle, osContext->getHwQueue().progressFenceHandle); - EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().currentFenceValue, 2u); - EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().lastSubmittedFence, 1u); + EXPECT_NE(osContext->getMonitoredFence().fenceHandle, osContext->getHwQueue().progressFenceHandle); + EXPECT_EQ(osContext->getMonitoredFence().currentFenceValue, 2u); + EXPECT_EQ(osContext->getMonitoredFence().lastSubmittedFence, 1u); EXPECT_EQ(fence.currentFenceValue, 2u); EXPECT_EQ(fence.lastSubmittedFence, 1u); } @@ -129,26 +129,26 @@ TEST_F(Wddm23Tests, givenCmdBufferWhenSubmitCalledThenSetAllRequiredFiledsAndUpd auto hwQueue = osContext->getHwQueue(); COMMAND_BUFFER_HEADER cmdBufferHeader = {}; - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); - EXPECT_EQ(0u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(1u, osContext->getMonitoredFence().currentFenceValue); + EXPECT_EQ(0u, osContext->getMonitoredFence().lastSubmittedFence); WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = hwQueue.handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, submitArgs); EXPECT_EQ(cmdBufferAddress, getSubmitCommandToHwQueueDataFcn()->CommandBuffer); EXPECT_EQ(static_cast(cmdSize), getSubmitCommandToHwQueueDataFcn()->CommandLength); EXPECT_EQ(hwQueue.handle, getSubmitCommandToHwQueueDataFcn()->hHwQueue); - EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().lastSubmittedFence, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId); + EXPECT_EQ(osContext->getMonitoredFence().lastSubmittedFence, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId); EXPECT_EQ(&cmdBufferHeader, getSubmitCommandToHwQueueDataFcn()->pPrivateDriverData); EXPECT_EQ(static_cast(sizeof(COMMAND_BUFFER_HEADER)), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); EXPECT_EQ(0u, cmdBufferHeader.MonitorFenceVA); EXPECT_EQ(0u, cmdBufferHeader.MonitorFenceValue); - EXPECT_EQ(2u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(2u, osContext->getMonitoredFence().currentFenceValue); + EXPECT_EQ(1u, osContext->getMonitoredFence().lastSubmittedFence); } TEST_F(Wddm23Tests, givenDebugVariableSetWhenSubmitCalledThenUseCmdBufferHeaderSizeForPrivateDriverDataSize) { @@ -160,7 +160,7 @@ TEST_F(Wddm23Tests, givenDebugVariableSetWhenSubmitCalledThenUseCmdBufferHeaderS WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = osContext->getHwQueue().handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); wddm->submit(123, 456, &cmdBufferHeader, submitArgs); EXPECT_EQ(static_cast(sizeof(COMMAND_BUFFER_HEADER)), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); @@ -171,7 +171,7 @@ TEST_F(Wddm23Tests, givenDebugVariableSetWhenSubmitCalledThenUseCmdBufferHeaderS submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = osContext->getHwQueue().handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); wddm->submit(123, 456, &cmdBufferHeader, submitArgs); EXPECT_EQ(static_cast(MemoryConstants::pageSize), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); @@ -181,11 +181,11 @@ TEST_F(Wddm23Tests, whenMonitoredFenceIsCreatedThenSetupAllRequiredFields) { wddm->wddmInterface->createMonitoredFence(*osContext); auto hwQueue = osContext->getHwQueue(); - EXPECT_EQ(hwQueue.progressFenceCpuVA, osContext->getResidencyController().getMonitoredFence().cpuAddress); - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); - EXPECT_EQ(hwQueue.progressFenceHandle, osContext->getResidencyController().getMonitoredFence().fenceHandle); - EXPECT_EQ(hwQueue.progressFenceGpuVA, osContext->getResidencyController().getMonitoredFence().gpuAddress); - EXPECT_EQ(0u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(hwQueue.progressFenceCpuVA, osContext->getMonitoredFence().cpuAddress); + EXPECT_EQ(1u, osContext->getMonitoredFence().currentFenceValue); + EXPECT_EQ(hwQueue.progressFenceHandle, osContext->getMonitoredFence().fenceHandle); + EXPECT_EQ(hwQueue.progressFenceGpuVA, osContext->getMonitoredFence().gpuAddress); + EXPECT_EQ(0u, osContext->getMonitoredFence().lastSubmittedFence); } TEST_F(Wddm23Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhenSubmitCalledThenCallWaitOnGpu) { @@ -196,7 +196,7 @@ TEST_F(Wddm23Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhe WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = osContext->getHwQueue().handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); VariableBackup pagingFenceBackup(wddm->pagingFenceAddress); *wddm->pagingFenceAddress = 1; diff --git a/shared/test/unit_test/os_interface/windows/wddm32_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm32_tests.cpp index 04671bf84d..9a3a2c4a54 100644 --- a/shared/test/unit_test/os_interface/windows/wddm32_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm32_tests.cpp @@ -60,26 +60,26 @@ TEST_F(Wddm32Tests, givenCmdBufferWhenSubmitCalledThenSetAllRequiredFiledsAndUpd auto hwQueue = osContext->getHwQueue(); COMMAND_BUFFER_HEADER cmdBufferHeader = {}; - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); - EXPECT_EQ(0u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(1u, osContext->getMonitoredFence().currentFenceValue); + EXPECT_EQ(0u, osContext->getMonitoredFence().lastSubmittedFence); WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = hwQueue.handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, submitArgs); EXPECT_EQ(cmdBufferAddress, getSubmitCommandToHwQueueDataFcn()->CommandBuffer); EXPECT_EQ(static_cast(cmdSize), getSubmitCommandToHwQueueDataFcn()->CommandLength); EXPECT_EQ(hwQueue.handle, getSubmitCommandToHwQueueDataFcn()->hHwQueue); - EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().lastSubmittedFence, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId); + EXPECT_EQ(osContext->getMonitoredFence().lastSubmittedFence, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId); EXPECT_EQ(&cmdBufferHeader, getSubmitCommandToHwQueueDataFcn()->pPrivateDriverData); EXPECT_EQ(static_cast(sizeof(COMMAND_BUFFER_HEADER)), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); EXPECT_EQ(0u, cmdBufferHeader.MonitorFenceVA); EXPECT_EQ(0u, cmdBufferHeader.MonitorFenceValue); - EXPECT_EQ(2u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(2u, osContext->getMonitoredFence().currentFenceValue); + EXPECT_EQ(1u, osContext->getMonitoredFence().lastSubmittedFence); } TEST_F(Wddm32Tests, givenDebugVariableSetWhenSubmitCalledThenUseCmdBufferHeaderSizeForPrivateDriverDataSize) { @@ -91,7 +91,7 @@ TEST_F(Wddm32Tests, givenDebugVariableSetWhenSubmitCalledThenUseCmdBufferHeaderS WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = osContext->getHwQueue().handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); wddm->submit(123, 456, &cmdBufferHeader, submitArgs); EXPECT_EQ(static_cast(sizeof(COMMAND_BUFFER_HEADER)), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); @@ -102,7 +102,7 @@ TEST_F(Wddm32Tests, givenDebugVariableSetWhenSubmitCalledThenUseCmdBufferHeaderS submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = osContext->getHwQueue().handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); wddm->submit(123, 456, &cmdBufferHeader, submitArgs); EXPECT_EQ(static_cast(MemoryConstants::pageSize), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize); @@ -112,11 +112,11 @@ TEST_F(Wddm32Tests, whenMonitoredFenceIsCreatedThenSetupAllRequiredFields) { wddm->wddmInterface->createMonitoredFence(*osContext); auto hwQueue = osContext->getHwQueue(); - EXPECT_EQ(hwQueue.progressFenceCpuVA, osContext->getResidencyController().getMonitoredFence().cpuAddress); - EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue); - EXPECT_EQ(hwQueue.progressFenceHandle, osContext->getResidencyController().getMonitoredFence().fenceHandle); - EXPECT_EQ(hwQueue.progressFenceGpuVA, osContext->getResidencyController().getMonitoredFence().gpuAddress); - EXPECT_EQ(0u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence); + EXPECT_EQ(hwQueue.progressFenceCpuVA, osContext->getMonitoredFence().cpuAddress); + EXPECT_EQ(1u, osContext->getMonitoredFence().currentFenceValue); + EXPECT_EQ(hwQueue.progressFenceHandle, osContext->getMonitoredFence().fenceHandle); + EXPECT_EQ(hwQueue.progressFenceGpuVA, osContext->getMonitoredFence().gpuAddress); + EXPECT_EQ(0u, osContext->getMonitoredFence().lastSubmittedFence); } TEST_F(Wddm32Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhenSubmitCalledThenCallWaitOnGpu) { @@ -127,7 +127,7 @@ TEST_F(Wddm32Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhe WddmSubmitArguments submitArgs = {}; submitArgs.contextHandle = osContext->getWddmContextHandle(); submitArgs.hwQueueHandle = osContext->getHwQueue().handle; - submitArgs.monitorFence = &osContext->getResidencyController().getMonitoredFence(); + submitArgs.monitorFence = &osContext->getMonitoredFence(); VariableBackup pagingFenceBackup(wddm->pagingFenceAddress); *wddm->pagingFenceAddress = 1; diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index cc8d85762e..32e2890dbd 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1309,7 +1309,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenNonZeroFenceValueOnSingleEngineRegister ASSERT_EQ(1u, memoryManager->getRegisteredEngines(0).size()); auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties({0, 32, AllocationType::buffer, mockDeviceBitfield})); - auto fence = &static_cast(memoryManager->getRegisteredEngines(0)[0].osContext)->getResidencyController().getMonitoredFence(); + auto fence = &static_cast(memoryManager->getRegisteredEngines(0)[0].osContext)->getMonitoredFence(); allocation->getResidencyData().updateCompletionData(129u, 0u); memoryManager->handleFenceCompletion(allocation); @@ -1338,7 +1338,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenNonZeroFenceValuesOnMultipleEnginesRegi ASSERT_EQ(1u, memoryManager->getRegisteredEngines(rootDeviceIndex).size()); auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties({0u, 32, AllocationType::buffer, mockDeviceBitfield})); - auto lastEngineFence = &static_cast(memoryManager->getRegisteredEngines(0)[0].osContext)->getResidencyController().getMonitoredFence(); + auto lastEngineFence = &static_cast(memoryManager->getRegisteredEngines(0)[0].osContext)->getMonitoredFence(); allocation->getResidencyData().updateCompletionData(129u, 0u); allocation->getResidencyData().updateCompletionData(152u, 1u); @@ -1370,7 +1370,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenNonZeroFenceValueOnSomeOfMultipleEngine ASSERT_EQ(2u, memoryManager->getRegisteredEngines(rootDeviceIndex).size()); auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties({1u, 32, AllocationType::buffer, mockDeviceBitfield})); - auto lastEngineFence = &static_cast(memoryManager->getRegisteredEngines(1)[0].osContext)->getResidencyController().getMonitoredFence(); + auto lastEngineFence = &static_cast(memoryManager->getRegisteredEngines(1)[0].osContext)->getMonitoredFence(); allocation->getResidencyData().updateCompletionData(129u, 1u); allocation->getResidencyData().updateCompletionData(0, 2u); diff --git a/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp index 403e75e7d2..dd3192ca49 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp @@ -214,20 +214,20 @@ TEST(WddmResidencyController, givenWddmResidencyControllerWhenRegisterCallbackTh } TEST_F(WddmResidencyControllerTest, givenWddmResidencyControllerWhenCallingWasAllocationUsedSinceLastTrimThenReturnCorrectValues) { - residencyController->lastTrimFenceValue = 100; - EXPECT_FALSE(residencyController->wasAllocationUsedSinceLastTrim(99)); - EXPECT_FALSE(residencyController->wasAllocationUsedSinceLastTrim(99)); - EXPECT_TRUE(residencyController->wasAllocationUsedSinceLastTrim(101)); + mockOsContextWin->lastTrimFenceValue = 100; + EXPECT_FALSE(mockOsContextWin->wasAllocationUsedSinceLastTrim(99)); + EXPECT_FALSE(mockOsContextWin->wasAllocationUsedSinceLastTrim(99)); + EXPECT_TRUE(mockOsContextWin->wasAllocationUsedSinceLastTrim(101)); } TEST_F(WddmResidencyControllerTest, givenWddmResidencyControllerThenUpdateLastTrimFenceValueUsesMonitoredFence) { - *residencyController->getMonitoredFence().cpuAddress = 1234; - residencyController->updateLastTrimFenceValue(); - EXPECT_EQ(1234u, residencyController->lastTrimFenceValue); + *mockOsContextWin->getMonitoredFence().cpuAddress = 1234; + mockOsContextWin->updateLastTrimFenceValue(); + EXPECT_EQ(1234u, mockOsContextWin->lastTrimFenceValue); - *residencyController->getMonitoredFence().cpuAddress = 12345; - residencyController->updateLastTrimFenceValue(); - EXPECT_EQ(12345u, residencyController->lastTrimFenceValue); + *mockOsContextWin->getMonitoredFence().cpuAddress = 12345; + mockOsContextWin->updateLastTrimFenceValue(); + EXPECT_EQ(12345u, mockOsContextWin->lastTrimFenceValue); } TEST_F(WddmResidencyControllerWithGdiTest, givenWddmResidencyControllerWhenItIsDestructedThenUnregisterTrimCallback) { @@ -279,9 +279,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe allocation2.getResidencyData().resident[osContextId] = true; // Set last periodic fence value - residencyController->lastTrimFenceValue = 10; + mockOsContextWin->lastTrimFenceValue = 10; // Set current fence value to greater value - residencyController->getMonitoredFence().currentFenceValue = 20; + mockOsContextWin->getMonitoredFence().currentFenceValue = 20; wddm->evictResult.called = 0; wddm->callBaseEvict = true; @@ -315,9 +315,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenOneUsedAllocationFromPreviousPer allocation2.getResidencyData().resident[osContextId] = true; // Set last periodic fence value - residencyController->lastTrimFenceValue = 10; + mockOsContextWin->lastTrimFenceValue = 10; // Set current fence value to greater value - residencyController->getMonitoredFence().currentFenceValue = 20; + mockOsContextWin->getMonitoredFence().currentFenceValue = 20; wddm->evictResult.called = 0; @@ -369,10 +369,10 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId] = true; // Set last periodic fence value - *residencyController->getMonitoredFence().cpuAddress = 10; - residencyController->updateLastTrimFenceValue(); + *static_cast(osContext)->getMonitoredFence().cpuAddress = 10; + static_cast(osContext)->updateLastTrimFenceValue(); // Set current fence value to greater value - residencyController->getMonitoredFence().currentFenceValue = 20; + static_cast(osContext)->getMonitoredFence().currentFenceValue = 20; wddm->evictResult.called = 0; wddm->callBaseEvict = true; @@ -397,13 +397,13 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenPeriodicTrimWhenTrimCallbackCall trimNotification.NumBytesToTrim = 0; // Set last periodic fence value - residencyController->lastTrimFenceValue = 10; + mockOsContextWin->lastTrimFenceValue = 10; // Set current fence value to greater value - *residencyController->getMonitoredFence().cpuAddress = 20; + *mockOsContextWin->getMonitoredFence().cpuAddress = 20; residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); - EXPECT_EQ(20u, residencyController->lastTrimFenceValue); + EXPECT_EQ(20u, mockOsContextWin->lastTrimFenceValue); } TEST_F(WddmResidencyControllerWithGdiTest, givenRestartPeriodicTrimWhenTrimCallbackCalledThenLastPeriodicTrimFenceIsSetToCurrentFenceValue) { @@ -412,13 +412,13 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenRestartPeriodicTrimWhenTrimCallb trimNotification.NumBytesToTrim = 0; // Set last periodic fence value - residencyController->lastTrimFenceValue = 10; + mockOsContextWin->lastTrimFenceValue = 10; // Set current fence value to greater value - *residencyController->getMonitoredFence().cpuAddress = 20; + *mockOsContextWin->getMonitoredFence().cpuAddress = 20; residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); - EXPECT_EQ(20u, residencyController->lastTrimFenceValue); + EXPECT_EQ(20u, mockOsContextWin->lastTrimFenceValue); } HWTEST_F(WddmResidencyControllerWithGdiTest, GivenZeroWhenTrimmingToBudgetThenTrueIsReturnedAndDrainPagingFenceQueueCalled) { @@ -445,9 +445,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca allocation3.getResidencyData().updateCompletionData(2, osContextId); allocation3.getResidencyData().resident[osContextId] = true; - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; wddm->callBaseEvict = true; @@ -474,8 +474,8 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenNumBytesToTrimIsNotZeroWhenTrimm allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; wddm->evictResult.called = 0; @@ -506,9 +506,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenNumBytesToTrimIsZeroWhenTrimming allocation3.getResidencyData().updateCompletionData(2, osContextId); allocation3.getResidencyData().resident[osContextId] = true; - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; @@ -541,9 +541,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenEvictedAlloca allocation3.getResidencyData().updateCompletionData(2, osContextId); allocation3.getResidencyData().resident[osContextId] = true; - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; @@ -566,9 +566,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenAlwaysResidentAllocationWhenTrim allocation.getResidencyData().resident[osContextId] = true; allocation.getResidencyData().updateCompletionData(0, osContextId); - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; @@ -588,9 +588,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenAlwaysResidentAllocationWhenTrim allocation.getResidencyData().resident[osContextId] = true; allocation.getResidencyData().updateCompletionData(0, osContextId); - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; @@ -613,9 +613,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenLastFenceIsGreaterThanMonitoredW allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(2, osContextId); - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 2; - residencyController->getMonitoredFence().currentFenceValue = 3; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 2; + mockOsContextWin->getMonitoredFence().currentFenceValue = 3; wddm->evictResult.called = 0; wddm->waitFromCpuResult.called = 0; @@ -668,9 +668,9 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, WhenTrimmingToBudgetT residencyController->getEvictionAllocations().push_back(allocationTriple); residencyController->getEvictionAllocations().push_back(&allocation2); - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 2; + *static_cast(osContext)->getMonitoredFence().cpuAddress = 1; + static_cast(osContext)->getMonitoredFence().lastSubmittedFence = 1; + static_cast(osContext)->getMonitoredFence().currentFenceValue = 2; wddm->evictResult.called = 0; wddm->callBaseEvict = true; @@ -713,9 +713,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge allocation3.getResidencyData().updateCompletionData(1, osContextId); allocation3.getResidencyData().resident[osContextId] = true; - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; @@ -777,7 +777,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, WhenMakingResidentRes MockWddmAllocation allocation4(gmmHelper); ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; bool requiresBlockingResidencyHandling = true; - residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_TRUE(allocation1.getResidencyData().resident[osContextId]); EXPECT_TRUE(allocation2.getResidencyData().resident[osContextId]); @@ -792,9 +792,9 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, WhenMakingResidentRes MockWddmAllocation allocation4(gmmHelper); ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; - residencyController->getMonitoredFence().currentFenceValue = 20; + static_cast(osContext)->getMonitoredFence().currentFenceValue = 20; bool requiresBlockingResidencyHandling = true; - residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_EQ(20u, allocation1.getResidencyData().getFenceValueForContextId(osContext->getContextId())); EXPECT_EQ(20u, allocation2.getResidencyData().getFenceValueForContextId(osContext->getContextId())); @@ -814,7 +814,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, GivenTripleAllocation WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptr); ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; bool requiresBlockingResidencyHandling = true; - residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident[osContextId]); @@ -831,10 +831,10 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, GivenTripleAllocation WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, reinterpret_cast(0x1500))); - residencyController->getMonitoredFence().currentFenceValue = 20; + static_cast(osContext)->getMonitoredFence().currentFenceValue = 20; bool requiresBlockingResidencyHandling = true; ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; - residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->getFenceValueForContextId(0)); @@ -854,7 +854,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_FALSE(result); @@ -876,7 +876,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_FALSE(result); EXPECT_EQ(residencyPack.size(), 0u); @@ -895,7 +895,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_FALSE(result); @@ -910,14 +910,14 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenCallItAgainWithCantTrimFurtherSetToTrue) { MockWddmAllocation allocation1(gmmHelper); allocation1.getResidencyData().updateCompletionData(0, osContextId); - residencyController->getMonitoredFence().currentFenceValue = 10; + static_cast(osContext)->getMonitoredFence().currentFenceValue = 10; wddm->makeResidentNumberOfBytesToTrim = 4 * 4096; wddm->makeResidentStatus = false; ResidencyContainer residencyPack{&allocation1}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_FALSE(result); EXPECT_NE(wddm->makeResidentParamsPassed[0].cantTrimFurther, wddm->makeResidentParamsPassed[1].cantTrimFurther); @@ -932,7 +932,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenAllocationPackPassedWhenCal allocation2.handle = 2; ResidencyContainer residencyPack{&allocation1, &allocation2}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_TRUE(result); EXPECT_EQ(2 * EngineLimits::maxHandleCount, wddm->makeResidentResult.handleCount); EXPECT_EQ(false, wddm->makeResidentResult.cantTrimFurther); @@ -948,7 +948,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB auto canonizedAddress = gmmHelper->canonize(castToUint64(const_cast(cpuPtr))); WddmAllocation allocationToTrim(0, 1u /*num gmms*/, AllocationType::unknown, cpuPtr, canonizedAddress, allocationSize, nullptr, MemoryPool::memoryNull, 0u, 1u); - allocationToTrim.getResidencyData().updateCompletionData(residencyController->getMonitoredFence().lastSubmittedFence, osContextId); + allocationToTrim.getResidencyData().updateCompletionData(static_cast(osContext)->getMonitoredFence().lastSubmittedFence, osContextId); allocationToTrim.getResidencyData().resident[osContextId] = true; residencyController->getEvictionAllocations().push_back(&allocationToTrim); @@ -957,7 +957,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB ResidencyContainer residencyPack{&allocation1}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_TRUE(result); @@ -974,7 +974,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB auto canonizedAddress = gmmHelper->canonize(castToUint64(const_cast(cpuPtr))); WddmAllocation allocationAlreadyResident(0, 1u /*num gmms*/, AllocationType::unknown, cpuPtr, canonizedAddress, allocationSize, nullptr, MemoryPool::memoryNull, 0u, 1u); - allocationAlreadyResident.getResidencyData().updateCompletionData(residencyController->getMonitoredFence().lastSubmittedFence, osContextId); + allocationAlreadyResident.getResidencyData().updateCompletionData(static_cast(osContext)->getMonitoredFence().lastSubmittedFence, osContextId); allocationAlreadyResident.getResidencyData().resident[osContextId] = true; residencyController->getEvictionAllocations().push_back(&allocationAlreadyResident); @@ -983,7 +983,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB ResidencyContainer residencyPack{&allocation1, &allocationAlreadyResident}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_TRUE(result); @@ -1000,7 +1000,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin wddm->makeResidentResults = {false, true}; bool requiresBlockingResidencyHandling = true; - residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_TRUE(residencyController->isMemoryBudgetExhausted()); EXPECT_EQ(2u, wddm->makeResidentResult.called); } @@ -1052,7 +1052,7 @@ TEST_F(WddmResidencyControllerWithMockWddmMakeResidentTest, givenMakeResidentFai MockWddmAllocation allocation1(gmmHelper); ResidencyContainer residencyPack{&allocation1}; bool requiresBlockingResidencyHandling = true; - bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId()); + bool result = residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast(osContext)); EXPECT_TRUE(result); EXPECT_EQ(3u, wddm->makeResidentResult.called); @@ -1125,9 +1125,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenResidencyLoggingEnabledWhenTrimm allocation3.getResidencyData().updateCompletionData(2, osContextId); allocation3.getResidencyData().resident[osContextId] = true; - *residencyController->getMonitoredFence().cpuAddress = 1; - residencyController->getMonitoredFence().lastSubmittedFence = 1; - residencyController->getMonitoredFence().currentFenceValue = 1; + *mockOsContextWin->getMonitoredFence().cpuAddress = 1; + mockOsContextWin->getMonitoredFence().lastSubmittedFence = 1; + mockOsContextWin->getMonitoredFence().currentFenceValue = 1; wddm->evictResult.called = 0; wddm->callBaseEvict = true;