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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
// Need to suppress warning 4005 caused by hw_cmds.h and wddm.h order.
// Current order must be preserved due to two versions of igfxfmid.h
#pragma warning(push)
#pragma warning(disable : 4005)
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/command_stream/preemption.h"
#include "shared/source/direct_submission/dispatchers/blitter_dispatcher.h"
#include "shared/source/direct_submission/dispatchers/render_dispatcher.h"
#include "shared/source/direct_submission/windows/wddm_direct_submission.h"
#include "shared/source/gmm_helper/gmm_callbacks.h"
#include "shared/source/gmm_helper/page_table_mngr.h"
#include "shared/source/helpers/flush_stamp.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
#include "shared/source/os_interface/windows/wddm/wddm_residency_logger.h"
#include "shared/source/os_interface/windows/wddm_device_command_stream.h"
#pragma warning(pop)
#include "shared/source/command_stream/submissions_aggregator.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_memory_manager.h"
namespace NEO {
// Initialize COMMAND_BUFFER_HEADER Type PatchList Streamer Perf Tag
DECLARE_COMMAND_BUFFER(CommandBufferHeader, UMD_OCL, FALSE, FALSE, PERFTAG_OCL);
template <typename GfxFamily>
WddmCommandStreamReceiver<GfxFamily>::WddmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment,
uint32_t rootDeviceIndex,
const DeviceBitfield deviceBitfield)
: BaseClass(executionEnvironment, rootDeviceIndex, deviceBitfield) {
this->wddm = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->as<Wddm>();
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(this->peekHwInfo());
commandBufferHeader = new COMMAND_BUFFER_HEADER;
*commandBufferHeader = CommandBufferHeader;
if (preemptionMode != PreemptionMode::Disabled) {
commandBufferHeader->NeedsMidBatchPreEmptionSupport = true;
}
this->dispatchMode = DispatchMode::batchedDispatch;
if (ApiSpecificConfig::getApiType() == ApiSpecificConfig::L0) {
this->dispatchMode = DispatchMode::immediateDispatch;
}
if (debugManager.flags.CsrDispatchMode.get()) {
this->dispatchMode = (DispatchMode)debugManager.flags.CsrDispatchMode.get();
}
}
template <typename GfxFamily>
WddmCommandStreamReceiver<GfxFamily>::~WddmCommandStreamReceiver() {
if (commandBufferHeader) {
delete commandBufferHeader;
}
}
template <typename GfxFamily>
SubmissionStatus WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
this->printDeviceIndex();
auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
allocationsForResidency.push_back(batchBuffer.commandBufferAllocation);
batchBuffer.commandBufferAllocation->updateResidencyTaskCount(this->taskCount, this->osContext->getContextId());
perfLogResidencyVariadicLog(wddm->getResidencyLogger(), "Wddm CSR processing residency set: %zu\n", allocationsForResidency.size());
auto submissionStatus = this->processResidency(allocationsForResidency, 0u);
if (submissionStatus != SubmissionStatus::success) {
return submissionStatus;
}
batchBuffer.allocationsForResidency = &allocationsForResidency;
auto mustWaitForResidency = this->requiresBlockingResidencyHandling;
mustWaitForResidency |= !this->executionEnvironment.directSubmissionController.get();
batchBuffer.pagingFenceSemInfo.requiresBlockingResidencyHandling = mustWaitForResidency;
auto pagingFenceValue = this->wddm->getCurrentPagingFenceValue();
if (this->validForEnqueuePagingFence(pagingFenceValue)) {
auto waitEnqueued = this->enqueueWaitForPagingFence(pagingFenceValue);
if (waitEnqueued) {
batchBuffer.pagingFenceSemInfo.pagingFenceValue = pagingFenceValue;
this->lastEnqueuedPagingFenceValue = pagingFenceValue;
}
}
if (this->directSubmission.get()) {
auto ret = this->directSubmission->dispatchCommandBuffer(batchBuffer, *(this->flushStamp.get()));
if (ret == false) {
return SubmissionStatus::failed;
}
return SubmissionStatus::success;
}
if (this->blitterDirectSubmission.get()) {
auto ret = this->blitterDirectSubmission->dispatchCommandBuffer(batchBuffer, *(this->flushStamp.get()));
if (ret == false) {
return SubmissionStatus::failed;
}
return SubmissionStatus::success;
}
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandBufferHeader);
pHeader->RequiresCoherency = false;
pHeader->UmdRequestedSliceState = 0;
pHeader->UmdRequestedEUCount = wddm->getRequestedEUCount();
const uint32_t maxRequestedSubsliceCount = 7;
switch (batchBuffer.throttle) {
case QueueThrottle::LOW:
case QueueThrottle::MEDIUM:
pHeader->UmdRequestedSubsliceCount = 0;
break;
case QueueThrottle::HIGH:
pHeader->UmdRequestedSubsliceCount = (wddm->getGtSysInfo()->SubSliceCount <= maxRequestedSubsliceCount) ? wddm->getGtSysInfo()->SubSliceCount : 0;
break;
}
auto osContextWin = static_cast<OsContextWin *>(this->osContext);
WddmSubmitArguments submitArgs = {};
submitArgs.contextHandle = osContextWin->getWddmContextHandle();
submitArgs.hwQueueHandle = osContextWin->getHwQueue().handle;
submitArgs.monitorFence = &osContextWin->getMonitoredFence();
auto status = wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, submitArgs);
this->flushStamp->setStamp(submitArgs.monitorFence->lastSubmittedFence);
if (status == false) {
return SubmissionStatus::failed;
}
return SubmissionStatus::success;
}
template <typename GfxFamily>
SubmissionStatus WddmCommandStreamReceiver<GfxFamily>::processResidency(ResidencyContainer &allocationsForResidency, uint32_t handleId) {
return static_cast<OsContextWin *>(this->osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency, this->requiresBlockingResidencyHandling, this) ? SubmissionStatus::success : SubmissionStatus::outOfMemory;
}
template <typename GfxFamily>
void WddmCommandStreamReceiver<GfxFamily>::processEviction() {
}
template <typename GfxFamily>
WddmMemoryManager *WddmCommandStreamReceiver<GfxFamily>::getMemoryManager() const {
return static_cast<WddmMemoryManager *>(CommandStreamReceiver::getMemoryManager());
}
template <typename GfxFamily>
bool WddmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStampToWait) {
return wddm->waitFromCpu(flushStampToWait, static_cast<OsContextWin *>(this->osContext)->getMonitoredFence(), false);
}
template <typename GfxFamily>
bool WddmCommandStreamReceiver<GfxFamily>::isTlbFlushRequiredForStateCacheFlush() {
return true;
}
template <typename GfxFamily>
GmmPageTableMngr *WddmCommandStreamReceiver<GfxFamily>::createPageTableManager() {
GMM_TRANSLATIONTABLE_CALLBACKS ttCallbacks = {};
auto rootDeviceEnvironment = this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex].get();
auto hwInfo = rootDeviceEnvironment->getHardwareInfo();
ttCallbacks.pfWriteL3Adr = writeL3AddressFuncFactory[hwInfo->platform.eRenderCoreFamily];
void *aubCsrHandle = this->wddm->needsNotifyAubCaptureCallback() ? this : nullptr;
GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(rootDeviceEnvironment->getGmmClientContext(), TT_TYPE::AUXTT, &ttCallbacks, aubCsrHandle);
this->pageTableManager.reset(gmmPageTableMngr);
return gmmPageTableMngr;
}
template <typename GfxFamily>
void WddmCommandStreamReceiver<GfxFamily>::flushMonitorFence(bool notifyKmd) {
if (this->directSubmission.get()) {
this->directSubmission->flushMonitorFence(notifyKmd);
} else if (this->blitterDirectSubmission.get()) {
this->blitterDirectSubmission->flushMonitorFence(notifyKmd);
}
}
template <typename GfxFamily>
CommandStreamReceiver *createWddmDeviceCommandStreamReceiver(bool withAubDump,
ExecutionEnvironment &executionEnvironment,
uint32_t rootDeviceIndex,
const DeviceBitfield deviceBitfield) {
if (withAubDump) {
return new CommandStreamReceiverWithAUBDump<WddmCommandStreamReceiver<GfxFamily>>(ApiSpecificConfig::getName(),
executionEnvironment,
rootDeviceIndex,
deviceBitfield);
} else {
return new WddmCommandStreamReceiver<GfxFamily>(executionEnvironment, rootDeviceIndex, deviceBitfield);
}
}
template <typename GfxFamily>
void WddmCommandStreamReceiver<GfxFamily>::setupContext(OsContext &osContext) {
this->osContext = &osContext;
}
template <typename GfxFamily>
void WddmCommandStreamReceiver<GfxFamily>::addToEvictionContainer(GraphicsAllocation &gfxAllocation) {
// Eviction allocations are shared with trim callback thread.
auto lock = static_cast<OsContextWin *>(this->osContext)->getResidencyController().acquireLock();
static_cast<OsContextWin *>(this->osContext)->getResidencyController().getEvictionAllocations().push_back(&gfxAllocation);
}
template <typename GfxFamily>
bool WddmCommandStreamReceiver<GfxFamily>::validForEnqueuePagingFence(uint64_t pagingFenceValue) const {
return !this->requiresBlockingResidencyHandling &&
pagingFenceValue > *this->wddm->getPagingFenceAddress() &&
pagingFenceValue > this->lastEnqueuedPagingFenceValue;
}
} // namespace NEO
|