2018-08-10 22:41:44 +08:00
|
|
|
/*
|
2020-01-08 22:00:45 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-08-10 22:41:44 +08:00
|
|
|
|
2020-02-24 01:46:50 +08:00
|
|
|
#include "os_interface/windows/wddm/wddm_interface.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 01:46:50 +08:00
|
|
|
#include "memory_manager/memory_constants.h"
|
|
|
|
#include "os_interface/windows/gdi_interface.h"
|
|
|
|
#include "os_interface/windows/os_context_win.h"
|
|
|
|
#include "os_interface/windows/wddm/wddm.h"
|
2018-08-10 22:41:44 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2018-09-12 18:43:15 +08:00
|
|
|
|
2019-12-17 22:26:00 +08:00
|
|
|
bool WddmInterface::createMonitoredFence(MonitoredFence &monitorFence) {
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2018-08-10 22:41:44 +08:00
|
|
|
D3DKMT_CREATESYNCHRONIZATIONOBJECT2 CreateSynchronizationObject = {0};
|
|
|
|
CreateSynchronizationObject.hDevice = wddm.getDevice();
|
|
|
|
CreateSynchronizationObject.Info.Type = D3DDDI_MONITORED_FENCE;
|
|
|
|
CreateSynchronizationObject.Info.MonitoredFence.InitialFenceValue = 0;
|
|
|
|
|
2019-12-17 22:26:00 +08:00
|
|
|
status = wddm.getGdi()->createSynchronizationObject2(&CreateSynchronizationObject);
|
|
|
|
DEBUG_BREAK_IF(STATUS_SUCCESS != status);
|
2018-08-10 22:41:44 +08:00
|
|
|
|
2019-12-17 22:26:00 +08:00
|
|
|
monitorFence.fenceHandle = CreateSynchronizationObject.hSyncObject;
|
|
|
|
monitorFence.cpuAddress = reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress);
|
|
|
|
monitorFence.gpuAddress = CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress;
|
2018-08-10 22:41:44 +08:00
|
|
|
|
2019-12-17 22:26:00 +08:00
|
|
|
return status == STATUS_SUCCESS;
|
2018-08-10 22:41:44 +08:00
|
|
|
}
|
2019-12-17 22:26:00 +08:00
|
|
|
void WddmInterface::destroyMonitorFence(D3DKMT_HANDLE fenceHandle) {
|
2019-12-13 22:47:45 +08:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
D3DKMT_DESTROYSYNCHRONIZATIONOBJECT destroySyncObject = {0};
|
|
|
|
destroySyncObject.hSyncObject = fenceHandle;
|
|
|
|
status = wddm.getGdi()->destroySynchronizationObject(&destroySyncObject);
|
|
|
|
DEBUG_BREAK_IF(STATUS_SUCCESS != status);
|
|
|
|
}
|
|
|
|
|
2019-12-17 22:26:00 +08:00
|
|
|
bool WddmInterface20::createHwQueue(OsContextWin &osContext) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void WddmInterface20::destroyHwQueue(D3DKMT_HANDLE hwQueue) {}
|
|
|
|
|
|
|
|
bool WddmInterface20::createMonitoredFence(OsContextWin &osContext) {
|
|
|
|
auto &residencyController = osContext.getResidencyController();
|
|
|
|
MonitoredFence &monitorFence = residencyController.getMonitoredFence();
|
|
|
|
bool ret = WddmInterface::createMonitoredFence(monitorFence);
|
|
|
|
|
|
|
|
monitorFence.currentFenceValue = 1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WddmInterface20::destroyMonitorFence(MonitoredFence &monitorFence) {
|
|
|
|
WddmInterface::destroyMonitorFence(monitorFence.fenceHandle);
|
|
|
|
}
|
|
|
|
|
2018-09-12 18:43:15 +08:00
|
|
|
const bool WddmInterface20::hwQueuesSupported() {
|
2018-08-10 22:41:44 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-16 22:42:13 +08:00
|
|
|
bool WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments) {
|
2018-08-10 22:41:44 +08:00
|
|
|
D3DKMT_SUBMITCOMMAND SubmitCommand = {0};
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
SubmitCommand.Commands = commandBuffer;
|
|
|
|
SubmitCommand.CommandLength = static_cast<UINT>(size);
|
|
|
|
SubmitCommand.BroadcastContextCount = 1;
|
2019-12-16 22:42:13 +08:00
|
|
|
SubmitCommand.BroadcastContext[0] = submitArguments.contextHandle;
|
2018-08-10 22:41:44 +08:00
|
|
|
SubmitCommand.Flags.NullRendering = (UINT)DebugManager.flags.EnableNullHardware.get();
|
|
|
|
|
|
|
|
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
|
|
|
|
|
2019-12-16 22:42:13 +08:00
|
|
|
pHeader->MonitorFenceVA = submitArguments.monitorFence->gpuAddress;
|
|
|
|
pHeader->MonitorFenceValue = submitArguments.monitorFence->currentFenceValue;
|
2018-08-10 22:41:44 +08:00
|
|
|
|
|
|
|
// Note: Private data should be the CPU VA Address
|
|
|
|
SubmitCommand.pPrivateDriverData = commandHeader;
|
|
|
|
SubmitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
|
|
|
|
|
|
|
|
status = wddm.getGdi()->submitCommand(&SubmitCommand);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS == status;
|
|
|
|
}
|
|
|
|
|
2019-02-27 18:17:17 +08:00
|
|
|
bool WddmInterface23::createHwQueue(OsContextWin &osContext) {
|
2018-08-10 22:41:44 +08:00
|
|
|
D3DKMT_CREATEHWQUEUE createHwQueue = {};
|
|
|
|
|
|
|
|
if (!wddm.getGdi()->setupHwQueueProcAddresses()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-01 19:21:30 +08:00
|
|
|
createHwQueue.hHwContext = osContext.getWddmContextHandle();
|
2019-02-27 18:17:17 +08:00
|
|
|
if (osContext.getPreemptionMode() >= PreemptionMode::MidBatch) {
|
2018-08-10 22:41:44 +08:00
|
|
|
createHwQueue.Flags.DisableGpuTimeout = wddm.readEnablePreemptionRegKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto status = wddm.getGdi()->createHwQueue(&createHwQueue);
|
|
|
|
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
|
2019-09-13 14:13:02 +08:00
|
|
|
osContext.setHwQueue({createHwQueue.hHwQueue, createHwQueue.hHwQueueProgressFence, createHwQueue.HwQueueProgressFenceCPUVirtualAddress,
|
|
|
|
createHwQueue.HwQueueProgressFenceGPUVirtualAddress});
|
2018-08-10 22:41:44 +08:00
|
|
|
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-09-13 14:13:02 +08:00
|
|
|
bool WddmInterface23::createMonitoredFence(OsContextWin &osContext) {
|
|
|
|
auto &residencyController = osContext.getResidencyController();
|
|
|
|
auto hwQueue = osContext.getHwQueue();
|
|
|
|
residencyController.resetMonitoredFenceParams(hwQueue.progressFenceHandle,
|
|
|
|
reinterpret_cast<uint64_t *>(hwQueue.progressFenceCpuVA),
|
|
|
|
hwQueue.progressFenceGpuVA);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-17 22:26:00 +08:00
|
|
|
void WddmInterface23::destroyMonitorFence(MonitoredFence &monitorFence) {
|
2019-12-13 22:47:45 +08:00
|
|
|
}
|
|
|
|
|
2018-09-12 18:43:15 +08:00
|
|
|
void WddmInterface23::destroyHwQueue(D3DKMT_HANDLE hwQueue) {
|
2018-08-21 23:36:08 +08:00
|
|
|
if (hwQueue) {
|
2018-08-10 22:41:44 +08:00
|
|
|
D3DKMT_DESTROYHWQUEUE destroyHwQueue = {};
|
2018-08-21 23:36:08 +08:00
|
|
|
destroyHwQueue.hHwQueue = hwQueue;
|
2018-08-10 22:41:44 +08:00
|
|
|
|
|
|
|
auto status = wddm.getGdi()->destroyHwQueue(&destroyHwQueue);
|
|
|
|
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 18:43:15 +08:00
|
|
|
const bool WddmInterface23::hwQueuesSupported() {
|
2018-08-10 22:41:44 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-16 22:42:13 +08:00
|
|
|
bool WddmInterface23::submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments) {
|
2018-08-10 22:41:44 +08:00
|
|
|
D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {};
|
2019-12-16 22:42:13 +08:00
|
|
|
submitCommand.hHwQueue = submitArguments.hwQueueHandle;
|
|
|
|
submitCommand.HwQueueProgressFenceId = submitArguments.monitorFence->currentFenceValue;
|
2018-08-10 22:41:44 +08:00
|
|
|
submitCommand.CommandBuffer = commandBuffer;
|
|
|
|
submitCommand.CommandLength = static_cast<UINT>(size);
|
|
|
|
|
|
|
|
submitCommand.pPrivateDriverData = commandHeader;
|
2018-09-12 18:43:15 +08:00
|
|
|
submitCommand.PrivateDriverDataSize = MemoryConstants::pageSize;
|
2018-08-10 22:41:44 +08:00
|
|
|
|
|
|
|
auto status = wddm.getGdi()->submitCommandToHwQueue(&submitCommand);
|
|
|
|
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
|
|
|
|
return status == STATUS_SUCCESS;
|
|
|
|
}
|