1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/wddm/wddm_interface.h"
#include "shared/source/helpers/constants.h"
#include "shared/source/os_interface/windows/gdi_interface.h"
#include "shared/source/os_interface/windows/os_context_win.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
using namespace NEO;
bool WddmInterface::createMonitoredFence(MonitoredFence &monitorFence) {
NTSTATUS status = STATUS_SUCCESS;
D3DKMT_CREATESYNCHRONIZATIONOBJECT2 CreateSynchronizationObject = {0};
CreateSynchronizationObject.hDevice = wddm.getDevice();
CreateSynchronizationObject.Info.Type = D3DDDI_MONITORED_FENCE;
CreateSynchronizationObject.Info.MonitoredFence.InitialFenceValue = 0;
status = wddm.getGdi()->createSynchronizationObject2(&CreateSynchronizationObject);
DEBUG_BREAK_IF(STATUS_SUCCESS != status);
monitorFence.fenceHandle = CreateSynchronizationObject.hSyncObject;
monitorFence.cpuAddress = reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress);
monitorFence.gpuAddress = CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress;
return status == STATUS_SUCCESS;
}
void WddmInterface::destroyMonitorFence(D3DKMT_HANDLE fenceHandle) {
NTSTATUS status = STATUS_SUCCESS;
D3DKMT_DESTROYSYNCHRONIZATIONOBJECT destroySyncObject = {0};
destroySyncObject.hSyncObject = fenceHandle;
status = wddm.getGdi()->destroySynchronizationObject(&destroySyncObject);
DEBUG_BREAK_IF(STATUS_SUCCESS != status);
}
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);
}
const bool WddmInterface20::hwQueuesSupported() {
return false;
}
bool WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments) {
D3DKMT_SUBMITCOMMAND SubmitCommand = {0};
NTSTATUS status = STATUS_SUCCESS;
SubmitCommand.Commands = commandBuffer;
SubmitCommand.CommandLength = static_cast<UINT>(size);
SubmitCommand.BroadcastContextCount = 1;
SubmitCommand.BroadcastContext[0] = submitArguments.contextHandle;
SubmitCommand.Flags.NullRendering = (UINT)DebugManager.flags.EnableNullHardware.get();
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
pHeader->MonitorFenceVA = submitArguments.monitorFence->gpuAddress;
pHeader->MonitorFenceValue = submitArguments.monitorFence->currentFenceValue;
// 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;
}
bool WddmInterface23::createHwQueue(OsContextWin &osContext) {
D3DKMT_CREATEHWQUEUE createHwQueue = {};
if (!wddm.getGdi()->setupHwQueueProcAddresses()) {
return false;
}
createHwQueue.hHwContext = osContext.getWddmContextHandle();
if (osContext.getPreemptionMode() >= PreemptionMode::MidBatch) {
createHwQueue.Flags.DisableGpuTimeout = wddm.readEnablePreemptionRegKey();
}
auto status = wddm.getGdi()->createHwQueue(&createHwQueue);
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
osContext.setHwQueue({createHwQueue.hHwQueue, createHwQueue.hHwQueueProgressFence, createHwQueue.HwQueueProgressFenceCPUVirtualAddress,
createHwQueue.HwQueueProgressFenceGPUVirtualAddress});
return status == STATUS_SUCCESS;
}
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;
}
void WddmInterface23::destroyMonitorFence(MonitoredFence &monitorFence) {
}
void WddmInterface23::destroyHwQueue(D3DKMT_HANDLE hwQueue) {
if (hwQueue) {
D3DKMT_DESTROYHWQUEUE destroyHwQueue = {};
destroyHwQueue.hHwQueue = hwQueue;
auto status = wddm.getGdi()->destroyHwQueue(&destroyHwQueue);
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
}
}
const bool WddmInterface23::hwQueuesSupported() {
return true;
}
bool WddmInterface23::submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments) {
D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {};
submitCommand.hHwQueue = submitArguments.hwQueueHandle;
submitCommand.HwQueueProgressFenceId = submitArguments.monitorFence->currentFenceValue;
submitCommand.CommandBuffer = commandBuffer;
submitCommand.CommandLength = static_cast<UINT>(size);
submitCommand.pPrivateDriverData = commandHeader;
submitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
if (!DebugManager.flags.UseCommandBufferHeaderSizeForWddmQueueSubmission.get()) {
submitCommand.PrivateDriverDataSize = MemoryConstants::pageSize;
}
auto status = wddm.getGdi()->submitCommandToHwQueue(&submitCommand);
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
return status == STATUS_SUCCESS;
}
|