|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, Intel Corporation |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | + * copy of this software and associated documentation files (the "Software"), |
| 6 | + * to deal in the Software without restriction, including without limitation |
| 7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | + * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | + * Software is furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included |
| 12 | + * in all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | + * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + */ |
| 22 | + |
| 23 | +#include "runtime/os_interface/windows/gdi_interface.h" |
| 24 | +#include "runtime/os_interface/windows/wddm/wddm23.h" |
| 25 | + |
| 26 | +namespace OCLRT { |
| 27 | +Wddm23::Wddm23() : Wddm20() {} |
| 28 | + |
| 29 | +Wddm23::~Wddm23() { |
| 30 | + destroyHwQueue(); |
| 31 | +} |
| 32 | + |
| 33 | +bool Wddm23::createHwQueue() { |
| 34 | + D3DKMT_CREATEHWQUEUE createHwQueue = {}; |
| 35 | + |
| 36 | + if (!gdi->setupHwQueueProcAddresses()) { |
| 37 | + return false; |
| 38 | + } |
| 39 | + |
| 40 | + createHwQueue.hHwContext = context; |
| 41 | + if (preemptionMode >= PreemptionMode::MidBatch) { |
| 42 | + createHwQueue.Flags.DisableGpuTimeout = readEnablePreemptionRegKey(); |
| 43 | + } |
| 44 | + |
| 45 | + auto status = gdi->createHwQueue(&createHwQueue); |
| 46 | + UNRECOVERABLE_IF(status != STATUS_SUCCESS); |
| 47 | + hwQueueHandle = createHwQueue.hHwQueue; |
| 48 | + |
| 49 | + resetMonitoredFenceParams(createHwQueue.hHwQueueProgressFence, |
| 50 | + reinterpret_cast<uint64_t *>(createHwQueue.HwQueueProgressFenceCPUVirtualAddress), |
| 51 | + createHwQueue.HwQueueProgressFenceGPUVirtualAddress); |
| 52 | + |
| 53 | + return status == STATUS_SUCCESS; |
| 54 | +} |
| 55 | + |
| 56 | +void Wddm23::destroyHwQueue() { |
| 57 | + if (hwQueueHandle) { |
| 58 | + D3DKMT_DESTROYHWQUEUE destroyHwQueue = {}; |
| 59 | + destroyHwQueue.hHwQueue = hwQueueHandle; |
| 60 | + |
| 61 | + auto status = gdi->destroyHwQueue(&destroyHwQueue); |
| 62 | + DEBUG_BREAK_IF(status != STATUS_SUCCESS); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +bool Wddm23::submit(uint64_t commandBuffer, size_t size, void *commandHeader) { |
| 67 | + D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {}; |
| 68 | + submitCommand.hHwQueue = hwQueueHandle; |
| 69 | + submitCommand.HwQueueProgressFenceId = monitoredFence.fenceHandle; |
| 70 | + submitCommand.CommandBuffer = commandBuffer; |
| 71 | + submitCommand.CommandLength = static_cast<UINT>(size); |
| 72 | + |
| 73 | + COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader); |
| 74 | + pHeader->MonitorFenceVA = monitoredFence.gpuAddress; |
| 75 | + pHeader->MonitorFenceValue = monitoredFence.currentFenceValue; |
| 76 | + |
| 77 | + submitCommand.pPrivateDriverData = commandHeader; |
| 78 | + submitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER); |
| 79 | + |
| 80 | + if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU()) { |
| 81 | + return false; |
| 82 | + } |
| 83 | + |
| 84 | + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", monitoredFence.currentFenceValue); |
| 85 | + |
| 86 | + auto status = gdi->submitCommandToHwQueue(&submitCommand); |
| 87 | + UNRECOVERABLE_IF(status != STATUS_SUCCESS); |
| 88 | + |
| 89 | + if (STATUS_SUCCESS == status) { |
| 90 | + monitoredFence.lastSubmittedFence = monitoredFence.currentFenceValue; |
| 91 | + monitoredFence.currentFenceValue++; |
| 92 | + } |
| 93 | + |
| 94 | + getDeviceState(); |
| 95 | + |
| 96 | + return status == STATUS_SUCCESS; |
| 97 | +} |
| 98 | +} // namespace OCLRT |
0 commit comments