2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-17 17:34:14 +08:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/helpers/options.h"
|
|
|
|
#include "runtime/os_interface/windows/gdi_interface.h"
|
2018-01-31 18:22:13 +08:00
|
|
|
#include "runtime/os_interface/windows/kmdaf_listener.h"
|
2018-06-21 17:36:47 +08:00
|
|
|
#include "runtime/gmm_helper/gmm.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/gmm_helper/gmm_helper.h"
|
|
|
|
#include "runtime/gmm_helper/resource_info.h"
|
|
|
|
#include "runtime/gmm_helper/page_table_mngr.h"
|
2018-05-10 17:42:41 +08:00
|
|
|
#include "runtime/os_interface/windows/wddm/wddm.h"
|
2018-04-05 00:38:36 +08:00
|
|
|
#include "runtime/os_interface/hw_info_config.h"
|
2018-08-23 17:29:39 +08:00
|
|
|
#include "runtime/os_interface/windows/gdi_interface.h"
|
2018-08-21 23:36:08 +08:00
|
|
|
#include "runtime/os_interface/windows/os_context_win.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/windows/wddm_allocation.h"
|
2018-11-26 21:04:52 +08:00
|
|
|
#include "runtime/os_interface/windows/wddm_engine_mapper.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/windows/registry_reader.h"
|
|
|
|
#include "runtime/helpers/debug_helpers.h"
|
|
|
|
#include "runtime/helpers/hw_info.h"
|
|
|
|
#include "runtime/helpers/wddm_helper.h"
|
|
|
|
#include "runtime/command_stream/linear_stream.h"
|
2018-01-09 21:08:34 +08:00
|
|
|
#include "runtime/sku_info/operations/sku_info_receiver.h"
|
2018-01-30 22:07:58 +08:00
|
|
|
#include "runtime/utilities/stackvec.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <dxgi.h>
|
|
|
|
#include "CL/cl.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
extern Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory();
|
|
|
|
extern Wddm::GetSystemInfoFcn getGetSystemInfo();
|
2018-03-22 17:38:23 +08:00
|
|
|
extern Wddm::VirtualAllocFcn getVirtualAlloc();
|
|
|
|
extern Wddm::VirtualFreeFcn getVirtualFree();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class WddmMemoryManager;
|
|
|
|
|
|
|
|
Wddm::CreateDXGIFactoryFcn Wddm::createDxgiFactory = getCreateDxgiFactory();
|
|
|
|
Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo();
|
2018-03-22 17:38:23 +08:00
|
|
|
Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc();
|
|
|
|
Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-21 23:36:08 +08:00
|
|
|
Wddm::Wddm() {
|
2018-03-03 04:43:37 +08:00
|
|
|
featureTable.reset(new FeatureTable());
|
|
|
|
waTable.reset(new WorkaroundTable());
|
|
|
|
gtSystemInfo.reset(new GT_SYSTEM_INFO);
|
|
|
|
gfxPlatform.reset(new PLATFORM);
|
|
|
|
memset(gtSystemInfo.get(), 0, sizeof(*gtSystemInfo));
|
|
|
|
memset(gfxPlatform.get(), 0, sizeof(*gfxPlatform));
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
registryReader.reset(new RegistryReader("System\\CurrentControlSet\\Control\\GraphicsDrivers\\Scheduler"));
|
|
|
|
adapterLuid.HighPart = 0;
|
|
|
|
adapterLuid.LowPart = 0;
|
2018-01-31 18:22:13 +08:00
|
|
|
kmDafListener = std::unique_ptr<KmDafListener>(new KmDafListener);
|
2018-05-10 17:42:41 +08:00
|
|
|
gdi = std::unique_ptr<Gdi>(new Gdi());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Wddm::~Wddm() {
|
|
|
|
resetPageTableManager(nullptr);
|
|
|
|
destroyPagingQueue();
|
|
|
|
destroyDevice();
|
|
|
|
closeAdapter();
|
|
|
|
}
|
|
|
|
|
2018-06-20 17:19:55 +08:00
|
|
|
bool Wddm::enumAdapters(HardwareInfo &outHardwareInfo) {
|
2018-08-10 17:07:17 +08:00
|
|
|
if (!gdi->isInitialized()) {
|
2018-06-12 15:42:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-10 17:07:17 +08:00
|
|
|
if (!openAdapter()) {
|
2018-06-12 15:42:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-10 17:07:17 +08:00
|
|
|
if (!queryAdapterInfo()) {
|
2018-06-12 15:42:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:07:17 +08:00
|
|
|
auto productFamily = gfxPlatform->eProductFamily;
|
2018-06-12 15:42:47 +08:00
|
|
|
if (!hardwareInfoTable[productFamily]) {
|
|
|
|
return false;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-02-28 23:52:08 +08:00
|
|
|
|
2018-08-10 17:07:17 +08:00
|
|
|
outHardwareInfo.pPlatform = new PLATFORM(*gfxPlatform);
|
|
|
|
outHardwareInfo.pSkuTable = new FeatureTable(*featureTable);
|
|
|
|
outHardwareInfo.pWaTable = new WorkaroundTable(*waTable);
|
|
|
|
outHardwareInfo.pSysInfo = new GT_SYSTEM_INFO(*gtSystemInfo);
|
2018-02-28 23:52:08 +08:00
|
|
|
|
2018-06-12 15:42:47 +08:00
|
|
|
outHardwareInfo.capabilityTable = hardwareInfoTable[productFamily]->capabilityTable;
|
2018-08-10 17:07:17 +08:00
|
|
|
outHardwareInfo.capabilityTable.maxRenderFrequency = maxRenderFrequency;
|
|
|
|
outHardwareInfo.capabilityTable.instrumentationEnabled &= instrumentationEnabled;
|
2018-04-05 00:38:36 +08:00
|
|
|
|
2018-06-12 15:42:47 +08:00
|
|
|
HwInfoConfig *hwConfig = HwInfoConfig::get(productFamily);
|
|
|
|
hwConfig->adjustPlatformForProductFamily(&outHardwareInfo);
|
|
|
|
|
|
|
|
return true;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::queryAdapterInfo() {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_QUERYADAPTERINFO QueryAdapterInfo = {0};
|
2018-03-03 04:43:37 +08:00
|
|
|
ADAPTER_INFO adapterInfo = {0};
|
2017-12-21 07:45:38 +08:00
|
|
|
QueryAdapterInfo.hAdapter = adapter;
|
|
|
|
QueryAdapterInfo.Type = KMTQAITYPE_UMDRIVERPRIVATE;
|
2018-03-03 04:43:37 +08:00
|
|
|
QueryAdapterInfo.pPrivateDriverData = &adapterInfo;
|
2017-12-21 07:45:38 +08:00
|
|
|
QueryAdapterInfo.PrivateDriverDataSize = sizeof(ADAPTER_INFO);
|
|
|
|
|
|
|
|
status = gdi->queryAdapterInfo(&QueryAdapterInfo);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
|
|
|
|
// translate
|
|
|
|
if (status == STATUS_SUCCESS) {
|
2018-03-03 04:43:37 +08:00
|
|
|
memcpy_s(gtSystemInfo.get(), sizeof(GT_SYSTEM_INFO), &adapterInfo.SystemInfo, sizeof(GT_SYSTEM_INFO));
|
|
|
|
memcpy_s(gfxPlatform.get(), sizeof(PLATFORM), &adapterInfo.GfxPlatform, sizeof(PLATFORM));
|
|
|
|
|
|
|
|
SkuInfoReceiver::receiveFtrTableFromAdapterInfo(featureTable.get(), &adapterInfo);
|
|
|
|
SkuInfoReceiver::receiveWaTableFromAdapterInfo(waTable.get(), &adapterInfo);
|
|
|
|
|
|
|
|
memcpy_s(&gfxPartition, sizeof(gfxPartition), &adapterInfo.GfxPartition, sizeof(GMM_GFX_PARTITIONING));
|
|
|
|
|
|
|
|
deviceRegistryPath = adapterInfo.DeviceRegistryPath;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-03 04:43:37 +08:00
|
|
|
systemSharedMemory = adapterInfo.SystemSharedMemory;
|
|
|
|
maxRenderFrequency = adapterInfo.MaxRenderFreq;
|
|
|
|
instrumentationEnabled = adapterInfo.Caps.InstrumentationIsEnabled != 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::createPagingQueue() {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_CREATEPAGINGQUEUE CreatePagingQueue = {0};
|
|
|
|
CreatePagingQueue.hDevice = device;
|
|
|
|
CreatePagingQueue.Priority = D3DDDI_PAGINGQUEUE_PRIORITY_NORMAL;
|
|
|
|
|
|
|
|
status = gdi->createPagingQueue(&CreatePagingQueue);
|
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS) {
|
|
|
|
pagingQueue = CreatePagingQueue.hPagingQueue;
|
|
|
|
pagingQueueSyncObject = CreatePagingQueue.hSyncObject;
|
|
|
|
pagingFenceAddress = reinterpret_cast<UINT64 *>(CreatePagingQueue.FenceValueCPUVirtualAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::destroyPagingQueue() {
|
|
|
|
D3DDDI_DESTROYPAGINGQUEUE DestroyPagingQueue = {0};
|
|
|
|
if (pagingQueue) {
|
|
|
|
DestroyPagingQueue.hPagingQueue = pagingQueue;
|
|
|
|
|
|
|
|
NTSTATUS status = gdi->destroyPagingQueue(&DestroyPagingQueue);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
pagingQueue = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:30:39 +08:00
|
|
|
bool Wddm::createDevice(PreemptionMode preemptionMode) {
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_CREATEDEVICE CreateDevice = {{0}};
|
|
|
|
if (adapter) {
|
|
|
|
CreateDevice.hAdapter = adapter;
|
|
|
|
CreateDevice.Flags.LegacyMode = FALSE;
|
2018-02-06 18:58:05 +08:00
|
|
|
if (preemptionMode >= PreemptionMode::MidBatch) {
|
2017-12-21 07:45:38 +08:00
|
|
|
CreateDevice.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
status = gdi->createDevice(&CreateDevice);
|
|
|
|
if (status == STATUS_SUCCESS) {
|
|
|
|
device = CreateDevice.hDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::destroyDevice() {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_DESTROYDEVICE DestroyDevice = {0};
|
|
|
|
if (device) {
|
|
|
|
DestroyDevice.hDevice = device;
|
|
|
|
|
|
|
|
status = gdi->destroyDevice(&DestroyDevice);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
device = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::closeAdapter() {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_CLOSEADAPTER CloseAdapter = {0};
|
|
|
|
CloseAdapter.hAdapter = adapter;
|
|
|
|
status = gdi->closeAdapter(&CloseAdapter);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
adapter = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::openAdapter() {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {{0}};
|
|
|
|
DXGI_ADAPTER_DESC1 OpenAdapterDesc = {{0}};
|
|
|
|
|
|
|
|
IDXGIFactory1 *pFactory = nullptr;
|
|
|
|
IDXGIAdapter1 *pAdapter = nullptr;
|
|
|
|
DWORD iDevNum = 0;
|
|
|
|
|
|
|
|
HRESULT hr = Wddm::createDxgiFactory(__uuidof(IDXGIFactory), (void **)(&pFactory));
|
|
|
|
if ((hr != S_OK) || (pFactory == nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (pFactory->EnumAdapters1(iDevNum++, &pAdapter) != DXGI_ERROR_NOT_FOUND) {
|
|
|
|
hr = pAdapter->GetDesc1(&OpenAdapterDesc);
|
|
|
|
if (hr == S_OK) {
|
|
|
|
// Check for adapters that include either "Intel" or "Citrix" (which may
|
|
|
|
// be virtualizing one of our adapters) in the description
|
|
|
|
if ((wcsstr(OpenAdapterDesc.Description, L"Intel") != 0) ||
|
|
|
|
(wcsstr(OpenAdapterDesc.Description, L"Citrix") != 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Release all the non-Intel adapters
|
|
|
|
pAdapter->Release();
|
|
|
|
pAdapter = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenAdapterData.AdapterLuid = OpenAdapterDesc.AdapterLuid;
|
|
|
|
status = gdi->openAdapterFromLuid(&OpenAdapterData);
|
|
|
|
|
|
|
|
if (pAdapter != nullptr) {
|
|
|
|
// If an Intel adapter was found, release it here
|
|
|
|
pAdapter->Release();
|
|
|
|
pAdapter = nullptr;
|
|
|
|
}
|
|
|
|
if (pFactory != nullptr) {
|
|
|
|
pFactory->Release();
|
|
|
|
pFactory = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS) {
|
|
|
|
adapter = OpenAdapterData.hAdapter;
|
|
|
|
adapterLuid = OpenAdapterDesc.AdapterLuid;
|
|
|
|
}
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::evict(D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim) {
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DKMT_EVICT Evict = {0};
|
|
|
|
Evict.AllocationList = handleList;
|
|
|
|
Evict.hDevice = device;
|
|
|
|
Evict.NumAllocations = numOfHandles;
|
|
|
|
Evict.NumBytesToTrim = 0;
|
|
|
|
|
|
|
|
status = gdi->evict(&Evict);
|
|
|
|
|
|
|
|
sizeToTrim = Evict.NumBytesToTrim;
|
|
|
|
|
2018-01-31 18:22:13 +08:00
|
|
|
kmDafListener->notifyEvict(featureTable->ftrKmdDaf, adapter, device, handleList, numOfHandles, gdi->escape);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) {
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DDDI_MAKERESIDENT makeResident = {0};
|
|
|
|
UINT priority = 0;
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
makeResident.AllocationList = handles;
|
|
|
|
makeResident.hPagingQueue = pagingQueue;
|
|
|
|
makeResident.NumAllocations = count;
|
|
|
|
makeResident.PriorityList = &priority;
|
|
|
|
makeResident.Flags.CantTrimFurther = cantTrimFurther ? 1 : 0;
|
|
|
|
makeResident.Flags.MustSucceed = cantTrimFurther ? 1 : 0;
|
|
|
|
|
|
|
|
status = gdi->makeResident(&makeResident);
|
|
|
|
|
|
|
|
if (status == STATUS_PENDING) {
|
|
|
|
interlockedMax(currentPagingFenceValue, makeResident.PagingFenceValue);
|
|
|
|
success = true;
|
|
|
|
} else if (status == STATUS_SUCCESS) {
|
|
|
|
success = true;
|
|
|
|
} else {
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
if (numberOfBytesToTrim != nullptr)
|
|
|
|
*numberOfBytesToTrim = makeResident.NumBytesToTrim;
|
|
|
|
UNRECOVERABLE_IF(cantTrimFurther);
|
|
|
|
}
|
|
|
|
|
2018-01-31 18:22:13 +08:00
|
|
|
kmDafListener->notifyMakeResident(featureTable->ftrKmdDaf, adapter, device, handles, count, gdi->escape);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-01-31 18:22:13 +08:00
|
|
|
return success;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-12 21:42:46 +08:00
|
|
|
bool Wddm::mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1) {
|
2018-01-30 22:07:58 +08:00
|
|
|
void *mapPtr = allocation->getReservedAddress() != nullptr ? allocation->getReservedAddress() : cpuPtr;
|
2018-07-12 21:42:46 +08:00
|
|
|
return mapGpuVirtualAddressImpl(allocation->gmm, allocation->handle, mapPtr, allocation->gpuPtr, allocation32bit, use64kbPages, useHeap1);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bool allocation32bit, bool use64kbPages) {
|
|
|
|
return mapGpuVirtualAddressImpl(allocationStorageData->osHandleStorage->gmm,
|
|
|
|
allocationStorageData->osHandleStorage->handle,
|
|
|
|
const_cast<void *>(allocationStorageData->cpuPtr),
|
|
|
|
allocationStorageData->osHandleStorage->gpuPtr,
|
2018-02-27 18:08:22 +08:00
|
|
|
allocation32bit, use64kbPages, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-12 21:42:46 +08:00
|
|
|
bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1) {
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DDDI_MAPGPUVIRTUALADDRESS MapGPUVA = {0};
|
|
|
|
D3DDDIGPUVIRTUALADDRESS_PROTECTION_TYPE protectionType = {{{0}}};
|
|
|
|
protectionType.Write = TRUE;
|
|
|
|
|
2018-07-12 21:42:46 +08:00
|
|
|
uint64_t size = static_cast<uint64_t>(gmm->gmmResourceInfo->getSizeAllocation());
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
MapGPUVA.hPagingQueue = pagingQueue;
|
|
|
|
MapGPUVA.hAllocation = handle;
|
|
|
|
MapGPUVA.Protection = protectionType;
|
|
|
|
MapGPUVA.SizeInPages = size / MemoryConstants::pageSize;
|
|
|
|
MapGPUVA.OffsetInPages = 0;
|
|
|
|
|
2018-08-24 21:23:45 +08:00
|
|
|
auto productFamily = gfxPlatform->eProductFamily;
|
|
|
|
UNRECOVERABLE_IF(!hardwareInfoTable[productFamily]);
|
|
|
|
|
2018-02-27 18:08:22 +08:00
|
|
|
if (useHeap1) {
|
2018-03-03 04:43:37 +08:00
|
|
|
MapGPUVA.MinimumAddress = gfxPartition.Heap32[1].Base;
|
|
|
|
MapGPUVA.MaximumAddress = gfxPartition.Heap32[1].Limit;
|
2018-02-27 18:08:22 +08:00
|
|
|
MapGPUVA.BaseAddress = 0;
|
|
|
|
} else if (use64kbPages) {
|
2018-03-03 04:43:37 +08:00
|
|
|
MapGPUVA.MinimumAddress = gfxPartition.Standard64KB.Base;
|
|
|
|
MapGPUVA.MaximumAddress = gfxPartition.Standard64KB.Limit;
|
2017-12-21 07:45:38 +08:00
|
|
|
} else {
|
2018-08-24 21:23:45 +08:00
|
|
|
if (hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) {
|
|
|
|
MapGPUVA.BaseAddress = reinterpret_cast<D3DGPU_VIRTUAL_ADDRESS>(cpuPtr);
|
|
|
|
MapGPUVA.MinimumAddress = static_cast<D3DGPU_VIRTUAL_ADDRESS>(0x0);
|
|
|
|
MapGPUVA.MaximumAddress =
|
|
|
|
static_cast<D3DGPU_VIRTUAL_ADDRESS>((sizeof(size_t) == 8) ? 0x7fffffffffff : (D3DGPU_VIRTUAL_ADDRESS)0xffffffff);
|
|
|
|
if (!cpuPtr) {
|
|
|
|
MapGPUVA.MinimumAddress = gfxPartition.Standard.Base;
|
|
|
|
MapGPUVA.MaximumAddress = gfxPartition.Standard.Limit;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MapGPUVA.BaseAddress = 0;
|
|
|
|
MapGPUVA.MinimumAddress = 0x0;
|
|
|
|
MapGPUVA.MaximumAddress = hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-08-24 21:23:45 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
if (allocation32bit) {
|
2018-12-05 23:19:12 +08:00
|
|
|
MapGPUVA.MinimumAddress = gfxPartition.Heap32[3].Base + MemoryConstants::pageSize;
|
2018-12-03 16:32:36 +08:00
|
|
|
MapGPUVA.MaximumAddress = gfxPartition.Heap32[3].Limit;
|
2017-12-21 07:45:38 +08:00
|
|
|
MapGPUVA.BaseAddress = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = gdi->mapGpuVirtualAddress(&MapGPUVA);
|
2018-06-21 17:36:47 +08:00
|
|
|
gpuPtr = GmmHelper::canonize(MapGPUVA.VirtualAddress);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
if (status == STATUS_PENDING) {
|
|
|
|
interlockedMax(currentPagingFenceValue, MapGPUVA.PagingFenceValue);
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS) {
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
kmDafListener->notifyMapGpuVA(featureTable->ftrKmdDaf, adapter, device, handle, MapGPUVA.VirtualAddress, gdi->escape);
|
|
|
|
|
|
|
|
if (gmm->isRenderCompressed && pageTableManager.get()) {
|
2018-01-25 22:10:07 +08:00
|
|
|
return updateAuxTable(gpuPtr, gmm, true);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-01-25 22:10:07 +08:00
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
return true;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) {
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DKMT_FREEGPUVIRTUALADDRESS FreeGPUVA = {0};
|
|
|
|
FreeGPUVA.hAdapter = adapter;
|
2018-06-21 17:36:47 +08:00
|
|
|
FreeGPUVA.BaseAddress = GmmHelper::decanonize(gpuPtr);
|
2017-12-21 07:45:38 +08:00
|
|
|
FreeGPUVA.Size = size;
|
|
|
|
|
|
|
|
status = gdi->freeGpuVirtualAddress(&FreeGPUVA);
|
|
|
|
gpuPtr = static_cast<D3DGPU_VIRTUAL_ADDRESS>(0);
|
2018-01-31 18:22:13 +08:00
|
|
|
|
|
|
|
kmDafListener->notifyUnmapGpuVA(featureTable->ftrKmdDaf, adapter, device, FreeGPUVA.BaseAddress, gdi->escape);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-01-08 23:31:29 +08:00
|
|
|
NTSTATUS Wddm::createAllocation(WddmAllocation *alloc) {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
2017-12-21 07:45:38 +08:00
|
|
|
D3DDDI_ALLOCATIONINFO AllocationInfo = {0};
|
|
|
|
D3DKMT_CREATEALLOCATION CreateAllocation = {0};
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (alloc == nullptr)
|
|
|
|
return false;
|
2018-02-02 00:16:36 +08:00
|
|
|
size = alloc->getAlignedSize();
|
2017-12-21 07:45:38 +08:00
|
|
|
if (size == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AllocationInfo.pSystemMem = alloc->getAlignedCpuPtr();
|
|
|
|
AllocationInfo.pPrivateDriverData = alloc->gmm->gmmResourceInfo->peekHandle();
|
|
|
|
AllocationInfo.PrivateDriverDataSize = static_cast<unsigned int>(sizeof(GMM_RESOURCE_INFO));
|
|
|
|
AllocationInfo.Flags.Primary = 0;
|
|
|
|
|
|
|
|
CreateAllocation.hGlobalShare = 0;
|
|
|
|
CreateAllocation.PrivateRuntimeDataSize = 0;
|
|
|
|
CreateAllocation.PrivateDriverDataSize = 0;
|
|
|
|
CreateAllocation.Flags.Reserved = 0;
|
|
|
|
CreateAllocation.NumAllocations = 1;
|
|
|
|
CreateAllocation.pPrivateRuntimeData = NULL;
|
|
|
|
CreateAllocation.pPrivateDriverData = NULL;
|
|
|
|
CreateAllocation.Flags.NonSecure = FALSE;
|
|
|
|
CreateAllocation.Flags.CreateShared = FALSE;
|
|
|
|
CreateAllocation.Flags.RestrictSharedAccess = FALSE;
|
|
|
|
CreateAllocation.Flags.CreateResource = alloc->getAlignedCpuPtr() == 0 ? TRUE : FALSE;
|
|
|
|
CreateAllocation.pAllocationInfo = &AllocationInfo;
|
|
|
|
CreateAllocation.hDevice = device;
|
|
|
|
|
2018-02-07 05:43:38 +08:00
|
|
|
status = gdi->createAllocation(&CreateAllocation);
|
|
|
|
if (status != STATUS_SUCCESS) {
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
return status;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-01-31 18:22:13 +08:00
|
|
|
|
2018-02-07 05:43:38 +08:00
|
|
|
alloc->handle = AllocationInfo.hAllocation;
|
|
|
|
kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, alloc->handle, gdi->escape);
|
|
|
|
|
2018-01-08 23:31:29 +08:00
|
|
|
return status;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::createAllocation64k(WddmAllocation *alloc) {
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DDDI_ALLOCATIONINFO AllocationInfo = {0};
|
|
|
|
D3DKMT_CREATEALLOCATION CreateAllocation = {0};
|
|
|
|
|
|
|
|
AllocationInfo.pSystemMem = 0;
|
|
|
|
AllocationInfo.pPrivateDriverData = alloc->gmm->gmmResourceInfo->peekHandle();
|
|
|
|
AllocationInfo.PrivateDriverDataSize = static_cast<unsigned int>(sizeof(GMM_RESOURCE_INFO));
|
|
|
|
AllocationInfo.Flags.Primary = 0;
|
|
|
|
|
|
|
|
CreateAllocation.NumAllocations = 1;
|
|
|
|
CreateAllocation.pPrivateRuntimeData = NULL;
|
|
|
|
CreateAllocation.pPrivateDriverData = NULL;
|
|
|
|
CreateAllocation.Flags.CreateResource = TRUE;
|
|
|
|
CreateAllocation.pAllocationInfo = &AllocationInfo;
|
|
|
|
CreateAllocation.hDevice = device;
|
|
|
|
|
2018-08-28 18:56:05 +08:00
|
|
|
status = gdi->createAllocation(&CreateAllocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-28 18:56:05 +08:00
|
|
|
if (status != STATUS_SUCCESS) {
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-28 18:56:05 +08:00
|
|
|
alloc->handle = AllocationInfo.hAllocation;
|
2018-01-31 18:22:13 +08:00
|
|
|
|
2018-08-28 18:56:05 +08:00
|
|
|
kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, alloc->handle, gdi->escape);
|
2017-12-21 07:45:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-23 17:07:31 +08:00
|
|
|
NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) {
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
2018-10-22 20:20:05 +08:00
|
|
|
D3DDDI_ALLOCATIONINFO AllocationInfo[maxFragmentsCount] = {{0}};
|
2017-12-21 07:45:38 +08:00
|
|
|
D3DKMT_CREATEALLOCATION CreateAllocation = {0};
|
|
|
|
|
|
|
|
auto allocationCount = 0;
|
2018-10-22 20:20:05 +08:00
|
|
|
for (unsigned int i = 0; i < maxFragmentsCount; i++) {
|
2017-12-21 07:45:38 +08:00
|
|
|
if (!osHandles.fragmentStorageData[i].osHandleStorage) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osHandles.fragmentStorageData[i].osHandleStorage->handle == (D3DKMT_HANDLE) nullptr && osHandles.fragmentStorageData[i].fragmentSize) {
|
|
|
|
AllocationInfo[allocationCount].pPrivateDriverData = osHandles.fragmentStorageData[i].osHandleStorage->gmm->gmmResourceInfo->peekHandle();
|
|
|
|
auto pSysMem = osHandles.fragmentStorageData[i].cpuPtr;
|
|
|
|
auto PSysMemFromGmm = osHandles.fragmentStorageData[i].osHandleStorage->gmm->gmmResourceInfo->getSystemMemPointer(CL_TRUE);
|
|
|
|
DEBUG_BREAK_IF(PSysMemFromGmm != pSysMem);
|
|
|
|
AllocationInfo[allocationCount].pSystemMem = osHandles.fragmentStorageData[i].cpuPtr;
|
|
|
|
AllocationInfo[allocationCount].PrivateDriverDataSize = static_cast<unsigned int>(sizeof(GMM_RESOURCE_INFO));
|
|
|
|
allocationCount++;
|
|
|
|
}
|
|
|
|
}
|
2018-03-23 17:07:31 +08:00
|
|
|
if (allocationCount == 0) {
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
CreateAllocation.hGlobalShare = 0;
|
|
|
|
CreateAllocation.PrivateRuntimeDataSize = 0;
|
|
|
|
CreateAllocation.PrivateDriverDataSize = 0;
|
|
|
|
CreateAllocation.Flags.Reserved = 0;
|
|
|
|
CreateAllocation.NumAllocations = allocationCount;
|
|
|
|
CreateAllocation.pPrivateRuntimeData = NULL;
|
|
|
|
CreateAllocation.pPrivateDriverData = NULL;
|
|
|
|
CreateAllocation.Flags.NonSecure = FALSE;
|
|
|
|
CreateAllocation.Flags.CreateShared = FALSE;
|
|
|
|
CreateAllocation.Flags.RestrictSharedAccess = FALSE;
|
|
|
|
CreateAllocation.Flags.CreateResource = FALSE;
|
|
|
|
CreateAllocation.pAllocationInfo = AllocationInfo;
|
|
|
|
CreateAllocation.hDevice = device;
|
|
|
|
|
2018-03-23 17:07:31 +08:00
|
|
|
while (status == STATUS_UNSUCCESSFUL) {
|
2017-12-21 07:45:38 +08:00
|
|
|
status = gdi->createAllocation(&CreateAllocation);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS) {
|
|
|
|
DBG_LOG(PrintDebugMessages, __FUNCTION__, "status: ", status);
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
auto allocationIndex = 0;
|
|
|
|
for (int i = 0; i < allocationCount; i++) {
|
|
|
|
while (osHandles.fragmentStorageData[allocationIndex].osHandleStorage->handle) {
|
|
|
|
allocationIndex++;
|
|
|
|
}
|
|
|
|
osHandles.fragmentStorageData[allocationIndex].osHandleStorage->handle = AllocationInfo[i].hAllocation;
|
2018-03-23 17:07:31 +08:00
|
|
|
bool success = mapGpuVirtualAddress(&osHandles.fragmentStorageData[allocationIndex], false, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
allocationIndex++;
|
|
|
|
|
2018-01-31 18:22:13 +08:00
|
|
|
if (!success) {
|
|
|
|
DBG_LOG(PrintDebugMessages, __FUNCTION__, "mapGpuVirtualAddress: ", success);
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, AllocationInfo[i].hAllocation, gdi->escape);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 17:07:31 +08:00
|
|
|
status = STATUS_SUCCESS;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-03-23 17:07:31 +08:00
|
|
|
return status;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-06 23:58:32 +08:00
|
|
|
bool Wddm::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) {
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DKMT_DESTROYALLOCATION2 DestroyAllocation = {0};
|
|
|
|
DEBUG_BREAK_IF(!(allocationCount <= 1 || resourceHandle == 0));
|
|
|
|
|
|
|
|
DestroyAllocation.hDevice = device;
|
|
|
|
DestroyAllocation.hResource = resourceHandle;
|
|
|
|
DestroyAllocation.phAllocationList = handles;
|
|
|
|
DestroyAllocation.AllocationCount = allocationCount;
|
|
|
|
|
|
|
|
DestroyAllocation.Flags.AssumeNotInUse = 1;
|
|
|
|
|
|
|
|
status = gdi->destroyAllocation2(&DestroyAllocation);
|
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
|
|
|
|
D3DKMT_QUERYRESOURCEINFO QueryResourceInfo = {0};
|
|
|
|
QueryResourceInfo.hDevice = device;
|
|
|
|
QueryResourceInfo.hGlobalShare = handle;
|
|
|
|
auto status = gdi->queryResourceInfo(&QueryResourceInfo);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
|
2017-12-22 00:28:17 +08:00
|
|
|
if (QueryResourceInfo.NumAllocations == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
std::unique_ptr<char[]> allocPrivateData(new char[QueryResourceInfo.TotalPrivateDriverDataSize]);
|
|
|
|
std::unique_ptr<char[]> resPrivateData(new char[QueryResourceInfo.ResourcePrivateDriverDataSize]);
|
|
|
|
std::unique_ptr<char[]> resPrivateRuntimeData(new char[QueryResourceInfo.PrivateRuntimeDataSize]);
|
|
|
|
std::unique_ptr<D3DDDI_OPENALLOCATIONINFO[]> allocationInfo(new D3DDDI_OPENALLOCATIONINFO[QueryResourceInfo.NumAllocations]);
|
|
|
|
|
|
|
|
D3DKMT_OPENRESOURCE OpenResource = {0};
|
|
|
|
|
|
|
|
OpenResource.hDevice = device;
|
|
|
|
OpenResource.hGlobalShare = handle;
|
|
|
|
OpenResource.NumAllocations = QueryResourceInfo.NumAllocations;
|
|
|
|
OpenResource.pOpenAllocationInfo = allocationInfo.get();
|
|
|
|
OpenResource.pTotalPrivateDriverDataBuffer = allocPrivateData.get();
|
|
|
|
OpenResource.TotalPrivateDriverDataBufferSize = QueryResourceInfo.TotalPrivateDriverDataSize;
|
|
|
|
OpenResource.pResourcePrivateDriverData = resPrivateData.get();
|
|
|
|
OpenResource.ResourcePrivateDriverDataSize = QueryResourceInfo.ResourcePrivateDriverDataSize;
|
|
|
|
OpenResource.pPrivateRuntimeData = resPrivateRuntimeData.get();
|
|
|
|
OpenResource.PrivateRuntimeDataSize = QueryResourceInfo.PrivateRuntimeDataSize;
|
|
|
|
|
|
|
|
status = gdi->openResource(&OpenResource);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
|
|
|
|
alloc->handle = allocationInfo[0].hAllocation;
|
|
|
|
alloc->resourceHandle = OpenResource.hResource;
|
|
|
|
|
2018-06-29 17:48:19 +08:00
|
|
|
auto resourceInfo = const_cast<void *>(allocationInfo[0].pPrivateDriverData);
|
|
|
|
alloc->gmm = new Gmm(static_cast<GMM_RESOURCE_INFO *>(resourceInfo));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2017-12-22 00:28:17 +08:00
|
|
|
return true;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::openNTHandle(HANDLE handle, WddmAllocation *alloc) {
|
|
|
|
D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE queryResourceInfoFromNtHandle = {};
|
|
|
|
queryResourceInfoFromNtHandle.hDevice = device;
|
|
|
|
queryResourceInfoFromNtHandle.hNtHandle = handle;
|
|
|
|
auto status = gdi->queryResourceInfoFromNtHandle(&queryResourceInfoFromNtHandle);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
|
|
|
|
std::unique_ptr<char[]> allocPrivateData(new char[queryResourceInfoFromNtHandle.TotalPrivateDriverDataSize]);
|
|
|
|
std::unique_ptr<char[]> resPrivateData(new char[queryResourceInfoFromNtHandle.ResourcePrivateDriverDataSize]);
|
|
|
|
std::unique_ptr<char[]> resPrivateRuntimeData(new char[queryResourceInfoFromNtHandle.PrivateRuntimeDataSize]);
|
|
|
|
std::unique_ptr<D3DDDI_OPENALLOCATIONINFO2[]> allocationInfo2(new D3DDDI_OPENALLOCATIONINFO2[queryResourceInfoFromNtHandle.NumAllocations]);
|
|
|
|
|
|
|
|
D3DKMT_OPENRESOURCEFROMNTHANDLE openResourceFromNtHandle = {};
|
|
|
|
|
|
|
|
openResourceFromNtHandle.hDevice = device;
|
|
|
|
openResourceFromNtHandle.hNtHandle = handle;
|
|
|
|
openResourceFromNtHandle.NumAllocations = queryResourceInfoFromNtHandle.NumAllocations;
|
|
|
|
openResourceFromNtHandle.pOpenAllocationInfo2 = allocationInfo2.get();
|
|
|
|
openResourceFromNtHandle.pTotalPrivateDriverDataBuffer = allocPrivateData.get();
|
|
|
|
openResourceFromNtHandle.TotalPrivateDriverDataBufferSize = queryResourceInfoFromNtHandle.TotalPrivateDriverDataSize;
|
|
|
|
openResourceFromNtHandle.pResourcePrivateDriverData = resPrivateData.get();
|
|
|
|
openResourceFromNtHandle.ResourcePrivateDriverDataSize = queryResourceInfoFromNtHandle.ResourcePrivateDriverDataSize;
|
|
|
|
openResourceFromNtHandle.pPrivateRuntimeData = resPrivateRuntimeData.get();
|
|
|
|
openResourceFromNtHandle.PrivateRuntimeDataSize = queryResourceInfoFromNtHandle.PrivateRuntimeDataSize;
|
|
|
|
|
|
|
|
status = gdi->openResourceFromNtHandle(&openResourceFromNtHandle);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
|
|
|
|
alloc->handle = allocationInfo2[0].hAllocation;
|
|
|
|
alloc->resourceHandle = openResourceFromNtHandle.hResource;
|
|
|
|
|
2018-06-29 17:48:19 +08:00
|
|
|
auto resourceInfo = const_cast<void *>(allocationInfo2[0].pPrivateDriverData);
|
|
|
|
alloc->gmm = new Gmm(static_cast<GMM_RESOURCE_INFO *>(resourceInfo));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2017-12-22 00:28:17 +08:00
|
|
|
return true;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
void *Wddm::lockResource(WddmAllocation &wddmAllocation) {
|
2019-01-16 22:09:33 +08:00
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
if (wddmAllocation.needsMakeResidentBeforeLock) {
|
2019-01-16 22:09:33 +08:00
|
|
|
applyBlockingMakeResident(wddmAllocation);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_LOCK2 lock2 = {};
|
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
lock2.hAllocation = wddmAllocation.handle;
|
2017-12-21 07:45:38 +08:00
|
|
|
lock2.hDevice = this->device;
|
|
|
|
|
|
|
|
status = gdi->lock2(&lock2);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
kmDafListener->notifyLock(featureTable->ftrKmdDaf, adapter, device, wddmAllocation.handle, 0, gdi->escape);
|
2018-01-31 18:22:13 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
return lock2.pData;
|
|
|
|
}
|
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
void Wddm::unlockResource(WddmAllocation &wddmAllocation) {
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_UNLOCK2 unlock2 = {};
|
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
unlock2.hAllocation = wddmAllocation.handle;
|
2017-12-21 07:45:38 +08:00
|
|
|
unlock2.hDevice = this->device;
|
|
|
|
|
|
|
|
status = gdi->unlock2(&unlock2);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
2018-01-31 18:22:13 +08:00
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
kmDafListener->notifyUnlock(featureTable->ftrKmdDaf, adapter, device, &wddmAllocation.handle, 1, gdi->escape);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:13:45 +08:00
|
|
|
void Wddm::kmDafLock(WddmAllocation *wddmAllocation) {
|
|
|
|
kmDafListener->notifyLock(featureTable->ftrKmdDaf, adapter, device, wddmAllocation->handle, 0, gdi->escape);
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:30:39 +08:00
|
|
|
bool Wddm::createContext(D3DKMT_HANDLE &context, EngineInstanceT engineType, PreemptionMode preemptionMode) {
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
D3DKMT_CREATECONTEXTVIRTUAL CreateContext = {0};
|
|
|
|
CREATECONTEXT_PVTDATA PrivateData = {{0}};
|
|
|
|
|
|
|
|
PrivateData.IsProtectedProcess = FALSE;
|
|
|
|
PrivateData.IsDwm = FALSE;
|
|
|
|
PrivateData.ProcessID = GetCurrentProcessId();
|
|
|
|
PrivateData.GpuVAContext = TRUE;
|
|
|
|
PrivateData.pHwContextId = &hwContextId;
|
|
|
|
PrivateData.IsMediaUsage = false;
|
2018-02-16 16:07:49 +08:00
|
|
|
PrivateData.NoRingFlushes = DebugManager.flags.UseNoRingFlushesKmdMode.get();
|
2018-09-12 20:44:18 +08:00
|
|
|
applyAdditionalContextFlags(PrivateData);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
CreateContext.EngineAffinity = 0;
|
2018-05-15 20:07:37 +08:00
|
|
|
CreateContext.Flags.NullRendering = static_cast<UINT>(DebugManager.flags.EnableNullHardware.get());
|
2018-08-10 22:41:44 +08:00
|
|
|
CreateContext.Flags.HwQueueSupported = wddmInterface->hwQueuesSupported();
|
2018-02-22 21:19:08 +08:00
|
|
|
|
|
|
|
if (preemptionMode >= PreemptionMode::MidBatch) {
|
|
|
|
CreateContext.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
CreateContext.PrivateDriverDataSize = sizeof(PrivateData);
|
2018-11-26 21:04:52 +08:00
|
|
|
CreateContext.NodeOrdinal = WddmEngineMapper::engineNodeMap(engineType.type);
|
2017-12-21 07:45:38 +08:00
|
|
|
CreateContext.pPrivateDriverData = &PrivateData;
|
|
|
|
CreateContext.ClientHint = D3DKMT_CLIENTHINT_OPENGL;
|
|
|
|
CreateContext.hDevice = device;
|
|
|
|
|
|
|
|
status = gdi->createContext(&CreateContext);
|
2018-05-02 18:00:28 +08:00
|
|
|
context = CreateContext.hContext;
|
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wddm::destroyContext(D3DKMT_HANDLE context) {
|
|
|
|
D3DKMT_DESTROYCONTEXT DestroyContext = {0};
|
|
|
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
|
|
|
|
|
|
|
if (context != static_cast<D3DKMT_HANDLE>(0)) {
|
|
|
|
DestroyContext.hContext = context;
|
|
|
|
status = gdi->destroyContext(&DestroyContext);
|
|
|
|
}
|
2018-05-02 18:00:28 +08:00
|
|
|
return status == STATUS_SUCCESS;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:48:29 +08:00
|
|
|
bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) {
|
2018-08-10 22:41:44 +08:00
|
|
|
bool status = false;
|
2018-08-27 21:48:29 +08:00
|
|
|
if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU(osContext.getContext())) {
|
2018-08-10 22:41:44 +08:00
|
|
|
return false;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-10-22 21:59:26 +08:00
|
|
|
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.getResidencyController().getMonitoredFence().currentFenceValue);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-27 21:48:29 +08:00
|
|
|
status = wddmInterface->submit(commandBuffer, size, commandHeader, osContext);
|
2018-08-10 22:41:44 +08:00
|
|
|
if (status) {
|
2018-10-22 21:59:26 +08:00
|
|
|
osContext.getResidencyController().getMonitoredFence().lastSubmittedFence = osContext.getResidencyController().getMonitoredFence().currentFenceValue;
|
|
|
|
osContext.getResidencyController().getMonitoredFence().currentFenceValue++;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
getDeviceState();
|
2018-08-10 22:41:44 +08:00
|
|
|
UNRECOVERABLE_IF(!status);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-10 22:41:44 +08:00
|
|
|
return status;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-03-27 16:06:08 +08:00
|
|
|
void Wddm::getDeviceState() {
|
2017-12-21 07:45:38 +08:00
|
|
|
#ifdef _DEBUG
|
|
|
|
D3DKMT_GETDEVICESTATE GetDevState;
|
|
|
|
memset(&GetDevState, 0, sizeof(GetDevState));
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
GetDevState.hDevice = device;
|
|
|
|
GetDevState.StateType = D3DKMT_DEVICESTATE_EXECUTION;
|
|
|
|
|
|
|
|
status = gdi->getDeviceState(&GetDevState);
|
2018-03-27 16:06:08 +08:00
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (status == STATUS_SUCCESS) {
|
2018-03-27 16:06:08 +08:00
|
|
|
DEBUG_BREAK_IF(GetDevState.ExecutionState != D3DKMT_DEVICEEXECUTION_ACTIVE);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-08-27 21:48:29 +08:00
|
|
|
void Wddm::handleCompletion(OsContextWin &osContext) {
|
2018-10-22 21:59:26 +08:00
|
|
|
auto &monitoredFence = osContext.getResidencyController().getMonitoredFence();
|
|
|
|
if (monitoredFence.cpuAddress) {
|
|
|
|
auto *currentTag = monitoredFence.cpuAddress;
|
|
|
|
while (*currentTag < monitoredFence.currentFenceValue - 1)
|
2017-12-21 07:45:38 +08:00
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Wddm::readEnablePreemptionRegKey() {
|
|
|
|
return static_cast<unsigned int>(registryReader->getSetting("EnablePreemption", 1));
|
|
|
|
}
|
|
|
|
|
2018-08-21 23:36:08 +08:00
|
|
|
bool Wddm::waitOnGPU(D3DKMT_HANDLE context) {
|
2017-12-21 07:45:38 +08:00
|
|
|
D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMGPU WaitOnGPU = {0};
|
|
|
|
|
|
|
|
WaitOnGPU.hContext = context;
|
|
|
|
WaitOnGPU.ObjectCount = 1;
|
|
|
|
WaitOnGPU.ObjectHandleArray = &pagingQueueSyncObject;
|
|
|
|
uint64_t localPagingFenceValue = currentPagingFenceValue;
|
|
|
|
|
|
|
|
WaitOnGPU.MonitoredFenceValueArray = &localPagingFenceValue;
|
|
|
|
NTSTATUS status = gdi->waitForSynchronizationObjectFromGpu(&WaitOnGPU);
|
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-10-26 18:22:47 +08:00
|
|
|
bool Wddm::waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredFence) {
|
2017-12-21 07:45:38 +08:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
2018-10-26 18:22:47 +08:00
|
|
|
if (lastFenceValue > *monitoredFence.cpuAddress) {
|
2017-12-21 07:45:38 +08:00
|
|
|
D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU waitFromCpu = {0};
|
|
|
|
waitFromCpu.ObjectCount = 1;
|
2018-10-26 18:22:47 +08:00
|
|
|
waitFromCpu.ObjectHandleArray = &monitoredFence.fenceHandle;
|
2017-12-21 07:45:38 +08:00
|
|
|
waitFromCpu.FenceValueArray = &lastFenceValue;
|
|
|
|
waitFromCpu.hDevice = device;
|
|
|
|
waitFromCpu.hAsyncEvent = NULL;
|
|
|
|
|
|
|
|
status = gdi->waitForSynchronizationObjectFromCpu(&waitFromCpu);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:43:37 +08:00
|
|
|
uint64_t Wddm::getSystemSharedMemory() const {
|
|
|
|
return systemSharedMemory;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-03-03 04:43:37 +08:00
|
|
|
uint64_t Wddm::getMaxApplicationAddress() const {
|
2017-12-21 07:45:38 +08:00
|
|
|
return maximumApplicationAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS Wddm::escape(D3DKMT_ESCAPE &escapeCommand) {
|
|
|
|
escapeCommand.hAdapter = adapter;
|
|
|
|
return gdi->escape(&escapeCommand);
|
|
|
|
};
|
|
|
|
|
|
|
|
PFND3DKMT_ESCAPE Wddm::getEscapeHandle() const {
|
|
|
|
return gdi->escape;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Wddm::getHeap32Base() {
|
2018-12-03 16:32:36 +08:00
|
|
|
return alignUp(gfxPartition.Heap32[3].Base, MemoryConstants::pageSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Wddm::getHeap32Size() {
|
2018-12-03 16:32:36 +08:00
|
|
|
return alignDown(gfxPartition.Heap32[3].Limit, MemoryConstants::pageSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-30 21:40:02 +08:00
|
|
|
VOID *Wddm::registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, WddmResidencyController &residencyController) {
|
2018-09-18 09:23:04 +08:00
|
|
|
if (DebugManager.flags.DoNotRegisterTrimCallback.get()) {
|
2018-10-23 22:17:31 +08:00
|
|
|
return nullptr;
|
2018-09-18 09:23:04 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
D3DKMT_REGISTERTRIMNOTIFICATION registerTrimNotification;
|
|
|
|
registerTrimNotification.Callback = callback;
|
|
|
|
registerTrimNotification.AdapterLuid = this->adapterLuid;
|
2018-10-30 21:40:02 +08:00
|
|
|
registerTrimNotification.Context = &residencyController;
|
2017-12-21 07:45:38 +08:00
|
|
|
registerTrimNotification.hDevice = this->device;
|
|
|
|
|
|
|
|
NTSTATUS status = gdi->registerTrimNotification(®isterTrimNotification);
|
|
|
|
if (status == STATUS_SUCCESS) {
|
2018-10-23 22:17:31 +08:00
|
|
|
return registerTrimNotification.Handle;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-10-23 22:17:31 +08:00
|
|
|
return nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-23 22:17:31 +08:00
|
|
|
void Wddm::unregisterTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, VOID *trimCallbackHandle) {
|
|
|
|
DEBUG_BREAK_IF(callback == nullptr);
|
|
|
|
if (trimCallbackHandle == nullptr) {
|
2018-10-15 23:12:55 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
D3DKMT_UNREGISTERTRIMNOTIFICATION unregisterTrimNotification;
|
|
|
|
unregisterTrimNotification.Callback = callback;
|
2018-10-23 22:17:31 +08:00
|
|
|
unregisterTrimNotification.Handle = trimCallbackHandle;
|
2018-10-15 23:12:55 +08:00
|
|
|
|
|
|
|
NTSTATUS status = gdi->unregisterTrimNotification(&unregisterTrimNotification);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-01-30 22:07:58 +08:00
|
|
|
void Wddm::releaseReservedAddress(void *reservedAddress) {
|
|
|
|
if (reservedAddress) {
|
2018-03-22 17:38:23 +08:00
|
|
|
auto status = virtualFree(reservedAddress, 0, MEM_RELEASE);
|
2018-01-30 22:07:58 +08:00
|
|
|
DEBUG_BREAK_IF(!status);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-25 22:10:07 +08:00
|
|
|
bool Wddm::updateAuxTable(D3DGPU_VIRTUAL_ADDRESS gpuVa, Gmm *gmm, bool map) {
|
2018-10-03 01:10:29 +08:00
|
|
|
GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {};
|
|
|
|
ddiUpdateAuxTable.BaseGpuVA = gpuVa;
|
|
|
|
ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle();
|
|
|
|
ddiUpdateAuxTable.DoNotWait = true;
|
|
|
|
ddiUpdateAuxTable.Map = map ? 1u : 0u;
|
|
|
|
return pageTableManager->updateAuxTable(&ddiUpdateAuxTable) == GMM_STATUS::GMM_SUCCESS;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wddm::resetPageTableManager(GmmPageTableMngr *newPageTableManager) {
|
|
|
|
pageTableManager.reset(newPageTableManager);
|
|
|
|
}
|
|
|
|
|
2018-01-30 22:07:58 +08:00
|
|
|
bool Wddm::reserveValidAddressRange(size_t size, void *&reservedMem) {
|
2018-03-22 17:38:23 +08:00
|
|
|
reservedMem = virtualAlloc(nullptr, size, MEM_RESERVE, PAGE_READWRITE);
|
2018-01-30 22:07:58 +08:00
|
|
|
if (reservedMem == nullptr) {
|
|
|
|
return false;
|
|
|
|
} else if (minAddress > reinterpret_cast<uintptr_t>(reservedMem)) {
|
|
|
|
StackVec<void *, 100> invalidAddrVector;
|
|
|
|
invalidAddrVector.push_back(reservedMem);
|
|
|
|
do {
|
2018-03-22 17:38:23 +08:00
|
|
|
reservedMem = virtualAlloc(nullptr, size, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE);
|
2018-01-30 22:07:58 +08:00
|
|
|
if (minAddress > reinterpret_cast<uintptr_t>(reservedMem) && reservedMem != nullptr) {
|
|
|
|
invalidAddrVector.push_back(reservedMem);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
for (auto &it : invalidAddrVector) {
|
2018-03-22 17:38:23 +08:00
|
|
|
auto status = virtualFree(it, 0, MEM_RELEASE);
|
2018-01-30 22:07:58 +08:00
|
|
|
DEBUG_BREAK_IF(!status);
|
|
|
|
}
|
|
|
|
if (reservedMem == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:38:23 +08:00
|
|
|
void *Wddm::virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type) {
|
|
|
|
return virtualAllocFnc(inPtr, size, flags, type);
|
|
|
|
}
|
2018-05-18 16:18:16 +08:00
|
|
|
|
2018-03-22 17:38:23 +08:00
|
|
|
int Wddm::virtualFree(void *ptr, size_t size, unsigned long flags) {
|
|
|
|
return virtualFreeFnc(ptr, size, flags);
|
|
|
|
}
|
2018-08-23 17:29:39 +08:00
|
|
|
|
|
|
|
bool Wddm::configureDeviceAddressSpace() {
|
|
|
|
SYSTEM_INFO sysInfo;
|
|
|
|
Wddm::getSystemInfo(&sysInfo);
|
|
|
|
maximumApplicationAddress = reinterpret_cast<uintptr_t>(sysInfo.lpMaximumApplicationAddress);
|
2018-08-24 21:23:45 +08:00
|
|
|
auto productFamily = gfxPlatform->eProductFamily;
|
|
|
|
if (!hardwareInfoTable[productFamily]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto svmSize = hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress
|
|
|
|
? maximumApplicationAddress + 1u
|
|
|
|
: 0u;
|
2018-08-23 17:29:39 +08:00
|
|
|
|
2018-08-24 21:23:45 +08:00
|
|
|
return gmmMemory->configureDevice(adapter, device, gdi->escape, svmSize, featureTable->ftrL3IACoherency, gfxPartition, minAddress);
|
2018-08-23 17:29:39 +08:00
|
|
|
}
|
|
|
|
|
2018-12-10 17:30:39 +08:00
|
|
|
bool Wddm::init(PreemptionMode preemptionMode) {
|
2018-08-23 17:29:39 +08:00
|
|
|
if (gdi != nullptr && gdi->isInitialized() && !initialized) {
|
|
|
|
if (!openAdapter()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!queryAdapterInfo()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wddmInterface) {
|
|
|
|
if (featureTable->ftrWddmHwQueues) {
|
|
|
|
wddmInterface = std::make_unique<WddmInterface23>(*this);
|
|
|
|
} else {
|
|
|
|
wddmInterface = std::make_unique<WddmInterface20>(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:30:39 +08:00
|
|
|
if (!createDevice(preemptionMode)) {
|
2018-08-23 17:29:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!createPagingQueue()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!gmmMemory) {
|
|
|
|
gmmMemory.reset(GmmMemory::create());
|
|
|
|
}
|
2018-08-27 21:48:29 +08:00
|
|
|
initialized = configureDeviceAddressSpace();
|
2018-08-23 17:29:39 +08:00
|
|
|
}
|
|
|
|
return initialized;
|
|
|
|
}
|
2019-01-16 22:09:33 +08:00
|
|
|
|
|
|
|
EvictionStatus Wddm::evictAllTemporaryResources() {
|
|
|
|
decltype(temporaryResources) resourcesToEvict;
|
|
|
|
auto &lock = acquireLock(temporaryResourcesLock);
|
|
|
|
temporaryResources.swap(resourcesToEvict);
|
|
|
|
if (resourcesToEvict.empty()) {
|
|
|
|
return EvictionStatus::NOT_APPLIED;
|
|
|
|
}
|
|
|
|
uint64_t sizeToTrim = 0;
|
|
|
|
bool error = false;
|
|
|
|
for (auto &handle : resourcesToEvict) {
|
|
|
|
if (!evict(&handle, 1, sizeToTrim)) {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error ? EvictionStatus::FAILED : EvictionStatus::SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
EvictionStatus Wddm::evictTemporaryResource(WddmAllocation &allocation) {
|
2019-01-16 22:09:33 +08:00
|
|
|
auto &lock = acquireLock(temporaryResourcesLock);
|
2019-01-24 18:51:33 +08:00
|
|
|
auto position = std::find(temporaryResources.begin(), temporaryResources.end(), allocation.handle);
|
2019-01-16 22:09:33 +08:00
|
|
|
if (position == temporaryResources.end()) {
|
|
|
|
return EvictionStatus::NOT_APPLIED;
|
|
|
|
}
|
|
|
|
*position = temporaryResources.back();
|
|
|
|
temporaryResources.pop_back();
|
|
|
|
uint64_t sizeToTrim = 0;
|
2019-01-24 18:51:33 +08:00
|
|
|
if (!evict(&allocation.handle, 1, sizeToTrim)) {
|
2019-01-16 22:09:33 +08:00
|
|
|
return EvictionStatus::FAILED;
|
|
|
|
}
|
|
|
|
return EvictionStatus::SUCCESS;
|
|
|
|
}
|
2019-01-24 18:51:33 +08:00
|
|
|
void Wddm::applyBlockingMakeResident(WddmAllocation &allocation) {
|
2019-01-16 22:09:33 +08:00
|
|
|
bool madeResident = false;
|
2019-01-24 18:51:33 +08:00
|
|
|
while (!(madeResident = makeResident(&allocation.handle, 1, false, nullptr))) {
|
2019-01-16 22:09:33 +08:00
|
|
|
if (evictAllTemporaryResources() == EvictionStatus::SUCCESS) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-01-24 18:51:33 +08:00
|
|
|
if (!makeResident(&allocation.handle, 1, false, nullptr)) {
|
2019-01-16 22:09:33 +08:00
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DEBUG_BREAK_IF(!madeResident);
|
|
|
|
auto &lock = acquireLock(temporaryResourcesLock);
|
2019-01-24 18:51:33 +08:00
|
|
|
temporaryResources.push_back(allocation.handle);
|
2019-01-16 22:09:33 +08:00
|
|
|
lock.unlock();
|
|
|
|
while (currentPagingFenceValue > *getPagingFenceAddress())
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_lock<SpinLock> Wddm::acquireLock(SpinLock &lock) {
|
|
|
|
return std::unique_lock<SpinLock>{lock};
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|