refactor: Move monitor fence to os context win

Related-To: NEO-13315

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2025-10-15 09:21:43 +00:00
committed by Compute-Runtime-Automation
parent dd252e7852
commit f1f13f05e2
19 changed files with 199 additions and 206 deletions

View File

@@ -150,7 +150,7 @@ uint64_t WddmDirectSubmission<GfxFamily, Dispatcher>::updateTagValue(bool requir
if (requireMonitorFence) {
return this->updateTagValueImpl(this->currentRingBuffer);
}
MonitoredFence &currentFence = osContextWin->getResidencyController().getMonitoredFence();
MonitoredFence &currentFence = osContextWin->getMonitoredFence();
return currentFence.currentFenceValue;
}
@@ -161,7 +161,7 @@ bool WddmDirectSubmission<GfxFamily, Dispatcher>::dispatchMonitorFenceRequired(b
template <typename GfxFamily, typename Dispatcher>
uint64_t WddmDirectSubmission<GfxFamily, Dispatcher>::updateTagValueImpl(uint32_t completionBufferIndex) {
MonitoredFence &currentFence = osContextWin->getResidencyController().getMonitoredFence();
MonitoredFence &currentFence = osContextWin->getMonitoredFence();
currentFence.lastSubmittedFence = currentFence.currentFenceValue;
currentFence.currentFenceValue++;
@@ -182,7 +182,7 @@ void WddmDirectSubmission<GfxFamily, Dispatcher>::handleCompletionFence(uint64_t
template <typename GfxFamily, typename Dispatcher>
void WddmDirectSubmission<GfxFamily, Dispatcher>::getTagAddressValue(TagData &tagData) {
MonitoredFence &currentFence = osContextWin->getResidencyController().getMonitoredFence();
MonitoredFence &currentFence = osContextWin->getMonitoredFence();
auto gmmHelper = wddm->getRootDeviceEnvironment().getGmmHelper();
tagData.tagAddress = gmmHelper->canonize(currentFence.gpuAddress);
@@ -226,7 +226,7 @@ void WddmDirectSubmission<GfxFamily, Dispatcher>::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<WddmAllocation *>((*allocationsForResidency)[i]);

View File

@@ -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<uint8_t> &luidData, size_t arraySize) {
auto *wddm = this->getWddm();
@@ -85,7 +93,7 @@ void OsContextWin::getDeviceLuidArray(std::vector<uint8_t> &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() ||

View File

@@ -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<uint8_t> &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;
};

View File

@@ -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<NEO::OsContextWin &>(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<WddmAllocation *>(*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<OsHandleWin *>(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<NEO::OsContextWin &>(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<WddmAllocation *>(*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) {

View File

@@ -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<OsContextWin *>(engine.osContext)->getResidencyController().getMonitoredFence();
auto &contextMonitoredFence = static_cast<OsContextWin *>(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<OsContextWin *>(&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");

View File

@@ -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<uint64_t *>(hwQueue.progressFenceCpuVA),
hwQueue.progressFenceGpuVA);
osContext.resetMonitoredFenceParams(hwQueue.progressFenceHandle,
reinterpret_cast<uint64_t *>(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<uint64_t *>(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<uint64_t *>(monitorFenceForResidency.cpuAddress),
monitorFenceForResidency.gpuAddress);
osContext.getMonitoredFence().currentFenceValue = currentFenceValue;
osContext.getMonitoredFence().lastSubmittedFence = lastSubmittedFence;
auto hwQueue = osContext.getHwQueue();
monitorFence.cpuAddress = reinterpret_cast<uint64_t *>(hwQueue.progressFenceCpuVA);

View File

@@ -134,7 +134,7 @@ SubmissionStatus WddmCommandStreamReceiver<GfxFamily>::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<GfxFamily>::flush(BatchBuffer &batchB
template <typename GfxFamily>
SubmissionStatus WddmCommandStreamReceiver<GfxFamily>::processResidency(ResidencyContainer &allocationsForResidency, uint32_t handleId) {
return static_cast<OsContextWin *>(this->osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency, this->requiresBlockingResidencyHandling, this->osContext->getContextId()) ? SubmissionStatus::success : SubmissionStatus::outOfMemory;
return static_cast<OsContextWin *>(this->osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency, this->requiresBlockingResidencyHandling, *static_cast<OsContextWin *>(this->osContext)) ? SubmissionStatus::success : SubmissionStatus::outOfMemory;
}
template <typename GfxFamily>
@@ -161,7 +161,7 @@ WddmMemoryManager *WddmCommandStreamReceiver<GfxFamily>::getMemoryManager() cons
template <typename GfxFamily>
bool WddmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStampToWait) {
return wddm->waitFromCpu(flushStampToWait, static_cast<OsContextWin *>(this->osContext)->getResidencyController().getMonitoredFence(), false);
return wddm->waitFromCpu(flushStampToWait, static_cast<OsContextWin *>(this->osContext)->getMonitoredFence(), false);
}
template <typename GfxFamily>

View File

@@ -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<OsContextWin *>(engine.osContext)->getResidencyController().getMonitoredFence();
const auto &monitoredFence = static_cast<OsContextWin *>(engine.osContext)->getMonitoredFence();
const auto wddm = static_cast<OsContextWin *>(engine.osContext)->getWddm();
wddm->waitFromCpu(lastFenceValue, monitoredFence, engine.commandStreamReceiver->isAnyDirectSubmissionEnabled());
}

View File

@@ -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<SpinLock> WddmResidencyController::acquireTrimCallbackLock() {
return std::unique_lock<SpinLock>{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<WddmAllocation *>(alloc);

View File

@@ -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<SpinLock> acquireLock();
[[nodiscard]] std::unique_lock<SpinLock> 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;

View File

@@ -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) {}

View File

@@ -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;

View File

@@ -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<bool> backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn());
MonitoredFence &contextFence = osContextWin->getResidencyController().getMonitoredFence();
MonitoredFence &contextFence = osContextWin->getMonitoredFence();
VariableBackup<volatile uint64_t> backupWddmMonitorFence(contextFence.cpuAddress);
*contextFence.cpuAddress = 1;
contextFence.currentFenceValue = 2u;
@@ -574,7 +574,7 @@ HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenWddmMonitorFenceHangDetect
VariableBackup<bool> backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn());
MonitoredFence &contextFence = osContextWin->getResidencyController().getMonitoredFence();
MonitoredFence &contextFence = osContextWin->getMonitoredFence();
VariableBackup<volatile uint64_t> backupWddmMonitorFence(contextFence.cpuAddress);
*contextFence.cpuAddress = std::numeric_limits<uint64_t>::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<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
@@ -812,7 +812,7 @@ HWTEST_F(WddmDirectSubmissionTest,
hwParse.parseCommands<FamilyType>(wddmDirectSubmission.ringCommandStream, sizeUsedBefore);
hwParse.findHardwareCommands<FamilyType>();
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<FamilyType>(wddmDirectSubmission.ringCommandStream, sizeUsedBefore);
hwParse.findHardwareCommands<FamilyType>();
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<FamilyType>;
auto mockOsContextWin = std::make_unique<MockOsContextWin>(*wddm, 0, 0, EngineDescriptorHelper::getDefaultDescriptor());
MockWddmDirectSubmission<FamilyType, Dispatcher> 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<FamilyType>;

View File

@@ -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<OsContextWin &>(csr->getOsContext()).getResidencyController().getMonitoredFence().lastSubmittedFence);
EXPECT_EQ(csr->obtainCurrentFlushStamp(), static_cast<OsContextWin &>(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<OsContextWin *>(device->getDefaultEngine().osContext)->getResidencyController().resetMonitoredFenceParams(handle, &value, gpuVa);
static_cast<OsContextWin *>(device->getDefaultEngine().osContext)->resetMonitoredFenceParams(handle, &value, gpuVa);
wddm->waitFromCpu(1, monitorFence, false);
EXPECT_EQ(directSubmission->flushMonitorFenceCalled, 2u);

View File

@@ -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<volatile uint64_t> 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) {

View File

@@ -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<UINT>(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<UINT>(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<UINT>(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<UINT>(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<volatile uint64_t> pagingFenceBackup(wddm->pagingFenceAddress);
*wddm->pagingFenceAddress = 1;

View File

@@ -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<UINT>(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<UINT>(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<UINT>(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<UINT>(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<volatile uint64_t> pagingFenceBackup(wddm->pagingFenceAddress);
*wddm->pagingFenceAddress = 1;

View File

@@ -1309,7 +1309,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenNonZeroFenceValueOnSingleEngineRegister
ASSERT_EQ(1u, memoryManager->getRegisteredEngines(0).size());
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties({0, 32, AllocationType::buffer, mockDeviceBitfield}));
auto fence = &static_cast<OsContextWin *>(memoryManager->getRegisteredEngines(0)[0].osContext)->getResidencyController().getMonitoredFence();
auto fence = &static_cast<OsContextWin *>(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<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties({0u, 32, AllocationType::buffer, mockDeviceBitfield}));
auto lastEngineFence = &static_cast<OsContextWin *>(memoryManager->getRegisteredEngines(0)[0].osContext)->getResidencyController().getMonitoredFence();
auto lastEngineFence = &static_cast<OsContextWin *>(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<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties({1u, 32, AllocationType::buffer, mockDeviceBitfield}));
auto lastEngineFence = &static_cast<OsContextWin *>(memoryManager->getRegisteredEngines(1)[0].osContext)->getResidencyController().getMonitoredFence();
auto lastEngineFence = &static_cast<OsContextWin *>(memoryManager->getRegisteredEngines(1)[0].osContext)->getMonitoredFence();
allocation->getResidencyData().updateCompletionData(129u, 1u);
allocation->getResidencyData().updateCompletionData(0, 2u);

View File

@@ -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<OsContextWin *>(osContext)->getMonitoredFence().cpuAddress = 10;
static_cast<OsContextWin *>(osContext)->updateLastTrimFenceValue();
// Set current fence value to greater value
residencyController->getMonitoredFence().currentFenceValue = 20;
static_cast<OsContextWin *>(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<OsContextWin *>(osContext)->getMonitoredFence().cpuAddress = 1;
static_cast<OsContextWin *>(osContext)->getMonitoredFence().lastSubmittedFence = 1;
static_cast<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(osContext)->getMonitoredFence().currentFenceValue = 20;
bool requiresBlockingResidencyHandling = true;
residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId());
residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast<OsContextWin *>(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<OsContextWin *>(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<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, reinterpret_cast<void *>(0x1500)));
residencyController->getMonitoredFence().currentFenceValue = 20;
static_cast<OsContextWin *>(osContext)->getMonitoredFence().currentFenceValue = 20;
bool requiresBlockingResidencyHandling = true;
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, osContext->getContextId());
residencyController->makeResidentResidencyAllocations(residencyPack, requiresBlockingResidencyHandling, *static_cast<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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<void *>(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<OsContextWin *>(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<OsContextWin *>(osContext));
EXPECT_TRUE(result);
@@ -974,7 +974,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB
auto canonizedAddress = gmmHelper->canonize(castToUint64(const_cast<void *>(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<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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<OsContextWin *>(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;