2018-10-04 06:52:51 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2018-10-04 06:52:51 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-08-29 18:15:33 +08:00
|
|
|
#include "core/os_interface/windows/windows_wrapper.h"
|
2019-07-12 22:50:14 +08:00
|
|
|
#include "core/utilities/spinlock.h"
|
2018-10-04 06:52:51 +08:00
|
|
|
#include "runtime/memory_manager/residency_container.h"
|
2018-10-22 21:59:26 +08:00
|
|
|
#include "runtime/os_interface/windows/windows_defs.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
|
|
|
|
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;
|
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);
|
|
|
|
|
2018-10-30 22:33:55 +08:00
|
|
|
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
|
2018-10-16 21:53:39 +08:00
|
|
|
std::unique_lock<SpinLock> acquireTrimCallbackLock();
|
2018-10-15 23:12:55 +08:00
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
WddmAllocation *getTrimCandidateHead();
|
|
|
|
void addToTrimCandidateList(GraphicsAllocation *allocation);
|
|
|
|
void removeFromTrimCandidateList(GraphicsAllocation *allocation, bool compactList);
|
2018-10-09 23:03:07 +08:00
|
|
|
void removeFromTrimCandidateListIfUsed(WddmAllocation *allocation, bool compactList);
|
2018-10-04 06:52:51 +08:00
|
|
|
void checkTrimCandidateCount();
|
|
|
|
|
|
|
|
bool checkTrimCandidateListCompaction();
|
|
|
|
void compactTrimCandidateList();
|
|
|
|
|
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
|
|
|
const ResidencyContainer &peekTrimCandidateList() const { return trimCandidateList; }
|
|
|
|
uint32_t peekTrimCandidatesCount() const { return trimCandidatesCount; }
|
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();
|
|
|
|
|
2018-10-26 18:22:47 +08:00
|
|
|
void trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint64_t bytes);
|
|
|
|
bool trimResidencyToBudget(uint64_t bytes);
|
|
|
|
|
2018-11-05 22:15:31 +08:00
|
|
|
bool isMemoryBudgetExhausted() const { return memoryBudgetExhausted; }
|
|
|
|
void setMemoryBudgetExhausted() { memoryBudgetExhausted = true; }
|
|
|
|
|
2018-11-05 22:47:32 +08:00
|
|
|
bool makeResidentResidencyAllocations(ResidencyContainer &allocationsForResidency);
|
|
|
|
void makeNonResidentEvictionAllocations(ResidencyContainer &evictionAllocations);
|
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
protected:
|
2018-10-23 22:57:22 +08:00
|
|
|
Wddm &wddm;
|
2018-10-09 23:03:07 +08:00
|
|
|
uint32_t osContextId;
|
2018-10-26 18:22:47 +08:00
|
|
|
MonitoredFence monitoredFence = {};
|
2018-10-23 22:57:22 +08:00
|
|
|
|
2018-10-16 21:53:39 +08:00
|
|
|
SpinLock lock;
|
|
|
|
SpinLock trimCallbackLock;
|
2018-10-23 22:57:22 +08:00
|
|
|
|
2018-11-05 22:15:31 +08:00
|
|
|
bool memoryBudgetExhausted = false;
|
2018-10-09 23:03:07 +08:00
|
|
|
uint64_t lastTrimFenceValue = 0u;
|
2018-10-04 06:52:51 +08:00
|
|
|
ResidencyContainer trimCandidateList;
|
|
|
|
uint32_t trimCandidatesCount = 0;
|
2018-10-30 21:40:02 +08:00
|
|
|
|
|
|
|
VOID *trimCallbackHandle = nullptr;
|
2018-10-04 06:52:51 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|