2018-10-04 00:52:51 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2018 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
#include "runtime/memory_manager/residency_container.h"
|
2018-10-22 15:59:26 +02:00
|
|
|
#include "runtime/os_interface/windows/windows_wrapper.h"
|
|
|
|
|
#include "runtime/os_interface/windows/windows_defs.h"
|
2018-10-16 15:53:39 +02:00
|
|
|
#include "runtime/utilities/spinlock.h"
|
2018-10-04 00:52:51 +02:00
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
#include <atomic>
|
2018-10-16 15:53:39 +02:00
|
|
|
#include <mutex>
|
2018-10-04 00:52:51 +02:00
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
class GraphicsAllocation;
|
|
|
|
|
class WddmAllocation;
|
2018-10-23 16:57:22 +02:00
|
|
|
class Wddm;
|
2018-10-04 00:52:51 +02:00
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
class WddmResidencyController {
|
|
|
|
|
public:
|
2018-10-23 16:57:22 +02:00
|
|
|
WddmResidencyController(Wddm &wddm, uint32_t osContextId);
|
2018-10-04 00:52:51 +02:00
|
|
|
|
2018-10-30 15:33:55 +01:00
|
|
|
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
|
2018-10-16 15:53:39 +02:00
|
|
|
std::unique_lock<SpinLock> acquireTrimCallbackLock();
|
2018-10-15 17:12:55 +02:00
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
WddmAllocation *getTrimCandidateHead();
|
|
|
|
|
void addToTrimCandidateList(GraphicsAllocation *allocation);
|
|
|
|
|
void removeFromTrimCandidateList(GraphicsAllocation *allocation, bool compactList);
|
2018-10-09 17:03:07 +02:00
|
|
|
void removeFromTrimCandidateListIfUsed(WddmAllocation *allocation, bool compactList);
|
2018-10-04 00:52:51 +02:00
|
|
|
void checkTrimCandidateCount();
|
|
|
|
|
|
|
|
|
|
bool checkTrimCandidateListCompaction();
|
|
|
|
|
void compactTrimCandidateList();
|
|
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
uint64_t getLastTrimFenceValue() { return lastTrimFenceValue; }
|
|
|
|
|
void setLastTrimFenceValue(uint64_t value) { lastTrimFenceValue = value; }
|
2018-10-04 00:52:51 +02:00
|
|
|
const ResidencyContainer &peekTrimCandidateList() const { return trimCandidateList; }
|
|
|
|
|
uint32_t peekTrimCandidatesCount() const { return trimCandidatesCount; }
|
2018-10-04 00:52:51 +02:00
|
|
|
|
2018-10-22 15:59:26 +02:00
|
|
|
MonitoredFence &getMonitoredFence() { return monitoredFence; }
|
|
|
|
|
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
|
|
|
|
|
|
2018-10-26 12:22:47 +02:00
|
|
|
void trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint64_t bytes);
|
|
|
|
|
bool trimResidencyToBudget(uint64_t bytes);
|
|
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
protected:
|
2018-10-23 16:57:22 +02:00
|
|
|
Wddm &wddm;
|
2018-10-09 17:03:07 +02:00
|
|
|
uint32_t osContextId;
|
2018-10-26 12:22:47 +02:00
|
|
|
MonitoredFence monitoredFence = {};
|
2018-10-23 16:57:22 +02:00
|
|
|
|
2018-10-16 15:53:39 +02:00
|
|
|
SpinLock lock;
|
|
|
|
|
SpinLock trimCallbackLock;
|
2018-10-23 16:57:22 +02:00
|
|
|
|
2018-10-09 17:03:07 +02:00
|
|
|
uint64_t lastTrimFenceValue = 0u;
|
2018-10-04 00:52:51 +02:00
|
|
|
ResidencyContainer trimCandidateList;
|
|
|
|
|
uint32_t trimCandidatesCount = 0;
|
2018-10-04 00:52:51 +02:00
|
|
|
};
|
|
|
|
|
} // namespace OCLRT
|