Files
compute-runtime/shared/source/os_interface/windows/wddm_residency_controller.h
Lukasz Jobczyk f1f13f05e2 refactor: Move monitor fence to os context win
Related-To: NEO-13315

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
2025-10-15 11:06:54 +02:00

79 lines
2.3 KiB
C++

/*
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/memory_manager/residency_container.h"
#include "shared/source/os_interface/windows/windows_defs.h"
#include "shared/source/os_interface/windows/windows_wrapper.h"
#include "shared/source/utilities/spinlock.h"
#include <atomic>
#include <mutex>
struct _D3DKMT_TRIMNOTIFICATION;
typedef _D3DKMT_TRIMNOTIFICATION D3DKMT_TRIMNOTIFICATION;
struct D3DDDI_TRIMRESIDENCYSET_FLAGS;
namespace NEO {
class GraphicsAllocation;
class WddmAllocation;
class Wddm;
class CommandStreamReceiver;
class OsContextWin;
class WddmResidencyController {
public:
WddmResidencyController(Wddm &wddm);
MOCKABLE_VIRTUAL ~WddmResidencyController();
static void APIENTRY trimCallback(_Inout_ D3DKMT_TRIMNOTIFICATION *trimNotification);
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
[[nodiscard]] std::unique_lock<SpinLock> acquireTrimCallbackLock();
void registerCallback();
void trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS &flags, uint64_t bytes);
bool trimResidencyToBudget(uint64_t bytes);
bool isMemoryBudgetExhausted() const { return memoryBudgetExhausted; }
void setMemoryBudgetExhausted() { memoryBudgetExhausted = true; }
bool makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, OsContextWin &osContext);
bool isInitialized() const;
void setCommandStreamReceiver(CommandStreamReceiver *csr);
void removeAllocation(ResidencyContainer &container, GraphicsAllocation *gfxAllocation);
ResidencyContainer &getEvictionAllocations() {
return this->evictionAllocations;
}
protected:
size_t fillHandlesContainer(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling, OsContextWin &osContext);
SpinLock lock;
SpinLock trimCallbackLock;
Wddm &wddm;
VOID *trimCallbackHandle = nullptr;
bool memoryBudgetExhausted = false;
CommandStreamReceiver *csr = nullptr;
ResidencyContainer evictionAllocations;
ResidencyContainer backupResidencyContainer; // Stores allocations which should be resident
std::vector<D3DKMT_HANDLE> handlesForResidency; // Stores D3DKMT handles of allocations which are not yet resident
};
} // namespace NEO