2018-10-04 06:52:51 +08:00
|
|
|
/*
|
2024-08-07 00:13:06 +08:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2018-10-04 06:52:51 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#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"
|
2018-10-04 06:52:51 +08:00
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
#include <atomic>
|
2018-10-16 21:53:39 +08:00
|
|
|
#include <mutex>
|
2018-10-04 06:52:51 +08:00
|
|
|
|
2021-05-26 00:42:36 +08:00
|
|
|
struct _D3DKMT_TRIMNOTIFICATION;
|
|
|
|
typedef _D3DKMT_TRIMNOTIFICATION D3DKMT_TRIMNOTIFICATION;
|
|
|
|
struct D3DDDI_TRIMRESIDENCYSET_FLAGS;
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-10-04 06:52:51 +08:00
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
class GraphicsAllocation;
|
|
|
|
class WddmAllocation;
|
2018-10-23 22:57:22 +08:00
|
|
|
class Wddm;
|
2024-08-22 18:25:49 +08:00
|
|
|
class CommandStreamReceiver;
|
2018-10-04 06:52:51 +08:00
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
class WddmResidencyController {
|
|
|
|
public:
|
2018-10-23 22:57:22 +08:00
|
|
|
WddmResidencyController(Wddm &wddm, uint32_t osContextId);
|
2018-10-30 21:40:02 +08:00
|
|
|
MOCKABLE_VIRTUAL ~WddmResidencyController();
|
2018-10-04 06:52:51 +08:00
|
|
|
|
2018-11-15 18:44:37 +08:00
|
|
|
static void APIENTRY trimCallback(_Inout_ D3DKMT_TRIMNOTIFICATION *trimNotification);
|
|
|
|
|
2022-09-01 23:54:57 +08:00
|
|
|
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
|
|
|
|
[[nodiscard]] std::unique_lock<SpinLock> acquireTrimCallbackLock();
|
2018-10-15 23:12:55 +08:00
|
|
|
|
2018-11-15 21:45:35 +08:00
|
|
|
bool wasAllocationUsedSinceLastTrim(uint64_t fenceValue) { return fenceValue > lastTrimFenceValue; }
|
2018-11-15 18:44:37 +08:00
|
|
|
void updateLastTrimFenceValue() { lastTrimFenceValue = *this->getMonitoredFence().cpuAddress; }
|
2018-10-04 06:52:51 +08:00
|
|
|
|
2018-10-22 21:59:26 +08:00
|
|
|
MonitoredFence &getMonitoredFence() { return monitoredFence; }
|
|
|
|
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
|
|
|
|
|
2018-11-14 21:35:45 +08:00
|
|
|
void registerCallback();
|
|
|
|
|
2021-05-26 00:42:36 +08:00
|
|
|
void trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS &flags, uint64_t bytes);
|
2024-09-24 18:58:26 +08:00
|
|
|
bool trimResidencyToBudget(uint64_t bytes);
|
2018-10-26 18:22:47 +08:00
|
|
|
|
2018-11-05 22:15:31 +08:00
|
|
|
bool isMemoryBudgetExhausted() const { return memoryBudgetExhausted; }
|
|
|
|
void setMemoryBudgetExhausted() { memoryBudgetExhausted = true; }
|
|
|
|
|
2024-08-22 18:25:49 +08:00
|
|
|
bool makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling);
|
2018-11-05 22:47:32 +08:00
|
|
|
|
2019-12-19 21:02:05 +08:00
|
|
|
bool isInitialized() const;
|
|
|
|
|
2024-08-22 18:25:49 +08:00
|
|
|
void setCommandStreamReceiver(CommandStreamReceiver *csr);
|
|
|
|
|
2024-08-29 18:13:00 +08:00
|
|
|
void removeAllocation(ResidencyContainer &container, GraphicsAllocation *gfxAllocation);
|
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
protected:
|
2024-10-07 21:43:59 +08:00
|
|
|
size_t fillHandlesContainer(ResidencyContainer &allocationsForResidency, bool &requiresBlockingResidencyHandling);
|
2018-10-23 22:57:22 +08:00
|
|
|
|
2024-09-05 20:38:10 +08:00
|
|
|
MonitoredFence monitoredFence = {};
|
2022-07-27 09:00:20 +08:00
|
|
|
|
2018-10-16 21:53:39 +08:00
|
|
|
SpinLock lock;
|
|
|
|
SpinLock trimCallbackLock;
|
2018-10-23 22:57:22 +08:00
|
|
|
|
2018-10-09 23:03:07 +08:00
|
|
|
uint64_t lastTrimFenceValue = 0u;
|
2018-10-30 21:40:02 +08:00
|
|
|
|
2022-07-27 09:00:20 +08:00
|
|
|
Wddm &wddm;
|
2018-10-30 21:40:02 +08:00
|
|
|
VOID *trimCallbackHandle = nullptr;
|
2022-07-27 09:00:20 +08:00
|
|
|
|
|
|
|
uint32_t osContextId;
|
|
|
|
|
|
|
|
bool memoryBudgetExhausted = false;
|
2024-08-22 18:25:49 +08:00
|
|
|
|
2024-09-10 20:03:42 +08:00
|
|
|
CommandStreamReceiver *csr = nullptr;
|
2024-09-05 20:38:10 +08:00
|
|
|
|
2024-10-07 21:43:59 +08:00
|
|
|
ResidencyContainer backupResidencyContainer; // Stores allocations which should be resident
|
2024-09-05 20:38:10 +08:00
|
|
|
std::vector<D3DKMT_HANDLE> handlesForResidency; // Stores D3DKMT handles of allocations which are not yet resident
|
2018-10-04 06:52:51 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|