2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-12-30 21:40:24 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-20 11:54:29 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Need to suppress warining 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)
|
2020-02-24 05:44:01 +08:00
|
|
|
#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/page_table_mngr.h"
|
|
|
|
#include "shared/source/helpers/flush_stamp.h"
|
|
|
|
#include "shared/source/helpers/hw_cmds.h"
|
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
|
|
|
#include "shared/source/helpers/windows/gmm_callbacks.h"
|
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/os_interface/windows/wddm_device_command_stream.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#pragma warning(pop)
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#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/os_interface.h"
|
|
|
|
#include "shared/source/os_interface/windows/wddm_memory_manager.h"
|
2019-11-24 21:50:41 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Initialize COMMAND_BUFFER_HEADER Type PatchList Streamer Perf Tag
|
|
|
|
DECLARE_COMMAND_BUFFER(CommandBufferHeader, UMD_OCL, FALSE, FALSE, PERFTAG_OCL);
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-10-29 15:01:53 +08:00
|
|
|
WddmCommandStreamReceiver<GfxFamily>::WddmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex)
|
|
|
|
: BaseClass(executionEnvironment, rootDeviceIndex) {
|
2018-08-30 15:27:47 +08:00
|
|
|
|
2019-06-19 20:04:58 +08:00
|
|
|
notifyAubCaptureImpl = DeviceCallbacks<GfxFamily>::notifyAubCapture;
|
2020-02-03 20:24:53 +08:00
|
|
|
this->wddm = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getWddm();
|
2018-08-30 15:27:47 +08:00
|
|
|
|
2019-02-27 17:06:14 +08:00
|
|
|
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(peekHwInfo());
|
2018-08-27 21:48:29 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
commandBufferHeader = new COMMAND_BUFFER_HEADER;
|
|
|
|
*commandBufferHeader = CommandBufferHeader;
|
2018-08-06 17:18:52 +08:00
|
|
|
|
|
|
|
if (preemptionMode != PreemptionMode::Disabled) {
|
|
|
|
commandBufferHeader->NeedsMidBatchPreEmptionSupport = true;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
this->dispatchMode = DispatchMode::BatchedDispatch;
|
|
|
|
|
|
|
|
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>
|
2019-11-24 21:50:41 +08:00
|
|
|
bool WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
2018-03-01 23:21:18 +08:00
|
|
|
auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-16 00:02:47 +08:00
|
|
|
allocationsForResidency.push_back(batchBuffer.commandBufferAllocation);
|
|
|
|
batchBuffer.commandBufferAllocation->updateResidencyTaskCount(this->taskCount, this->osContext->getContextId());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-04 00:50:53 +08:00
|
|
|
this->processResidency(allocationsForResidency, 0u);
|
2020-01-16 00:02:47 +08:00
|
|
|
if (directSubmission.get()) {
|
|
|
|
return directSubmission->dispatchCommandBuffer(batchBuffer, *(flushStamp.get()));
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandBufferHeader);
|
|
|
|
pHeader->RequiresCoherency = batchBuffer.requiresCoherency;
|
2018-01-29 18:18:34 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
pHeader->UmdRequestedSliceState = 0;
|
|
|
|
pHeader->UmdRequestedEUCount = wddm->getGtSysInfo()->EUCount / wddm->getGtSysInfo()->SubSliceCount;
|
|
|
|
|
2018-01-29 18:18:34 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-23 04:13:45 +08:00
|
|
|
if (wddm->isKmDafEnabled()) {
|
|
|
|
this->kmDafLockAllocations(allocationsForResidency);
|
|
|
|
}
|
|
|
|
|
2019-02-27 18:17:17 +08:00
|
|
|
auto osContextWin = static_cast<OsContextWin *>(osContext);
|
2019-12-16 22:42:13 +08:00
|
|
|
WddmSubmitArguments submitArgs = {};
|
|
|
|
submitArgs.contextHandle = osContextWin->getWddmContextHandle();
|
|
|
|
submitArgs.hwQueueHandle = osContextWin->getHwQueue().handle;
|
|
|
|
submitArgs.monitorFence = &osContextWin->getResidencyController().getMonitoredFence();
|
|
|
|
auto status = wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, submitArgs);
|
2018-03-23 04:13:45 +08:00
|
|
|
|
2019-12-16 22:42:13 +08:00
|
|
|
flushStamp->setStamp(submitArgs.monitorFence->lastSubmittedFence);
|
2019-11-24 21:50:41 +08:00
|
|
|
return status;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2020-02-04 00:50:53 +08:00
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::processResidency(const ResidencyContainer &allocationsForResidency, uint32_t handleId) {
|
2019-02-27 18:17:17 +08:00
|
|
|
bool success = static_cast<OsContextWin *>(osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency);
|
2017-12-21 07:45:38 +08:00
|
|
|
DEBUG_BREAK_IF(!success);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-11-26 21:04:52 +08:00
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::processEviction() {
|
2019-02-27 18:17:17 +08:00
|
|
|
static_cast<OsContextWin *>(osContext)->getResidencyController().makeNonResidentEvictionAllocations(this->getEvictionAllocations());
|
2018-09-14 19:48:02 +08:00
|
|
|
this->getEvictionAllocations().clear();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-07-29 22:11:51 +08:00
|
|
|
WddmMemoryManager *WddmCommandStreamReceiver<GfxFamily>::getMemoryManager() const {
|
2018-10-11 17:19:49 +08:00
|
|
|
return static_cast<WddmMemoryManager *>(CommandStreamReceiver::getMemoryManager());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-11-26 21:04:52 +08:00
|
|
|
bool WddmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStampToWait) {
|
2019-02-27 18:17:17 +08:00
|
|
|
return wddm->waitFromCpu(flushStampToWait, static_cast<OsContextWin *>(osContext)->getResidencyController().getMonitoredFence());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
GmmPageTableMngr *WddmCommandStreamReceiver<GfxFamily>::createPageTableManager() {
|
|
|
|
GMM_TRANSLATIONTABLE_CALLBACKS ttCallbacks = {};
|
2019-06-19 20:04:58 +08:00
|
|
|
ttCallbacks.pfWriteL3Adr = TTCallbacks<GfxFamily>::writeL3Address;
|
|
|
|
|
2020-01-23 21:27:01 +08:00
|
|
|
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex].get();
|
|
|
|
|
2020-02-25 01:04:30 +08:00
|
|
|
GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(rootDeviceEnvironment->getGmmClientContext(), TT_TYPE::AUXTT, &ttCallbacks);
|
2019-06-19 20:04:58 +08:00
|
|
|
gmmPageTableMngr->setCsrHandle(this);
|
2020-01-23 21:27:01 +08:00
|
|
|
rootDeviceEnvironment->pageTableManager.reset(gmmPageTableMngr);
|
2018-08-17 19:38:09 +08:00
|
|
|
return gmmPageTableMngr;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 04:13:45 +08:00
|
|
|
template <typename GfxFamily>
|
2018-09-25 18:38:00 +08:00
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::kmDafLockAllocations(ResidencyContainer &allocationsForResidency) {
|
|
|
|
for (auto &graphicsAllocation : allocationsForResidency) {
|
2018-07-05 22:31:57 +08:00
|
|
|
if ((GraphicsAllocation::AllocationType::LINEAR_STREAM == graphicsAllocation->getAllocationType()) ||
|
2019-02-20 19:43:37 +08:00
|
|
|
(GraphicsAllocation::AllocationType::FILL_PATTERN == graphicsAllocation->getAllocationType()) ||
|
|
|
|
(GraphicsAllocation::AllocationType::COMMAND_BUFFER == graphicsAllocation->getAllocationType())) {
|
2019-03-05 16:25:18 +08:00
|
|
|
wddm->kmDafLock(static_cast<WddmAllocation *>(graphicsAllocation)->getDefaultHandle());
|
2018-03-23 04:13:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 00:02:47 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
bool WddmCommandStreamReceiver<GfxFamily>::initDirectSubmission(Device &device, OsContext &osContext) {
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (DebugManager.flags.EnableDirectSubmission.get() == 1) {
|
|
|
|
auto contextEngineType = osContext.getEngineType();
|
|
|
|
const DirectSubmissionProperties &directSubmissionProperty =
|
|
|
|
device.getHardwareInfo().capabilityTable.directSubmissionEngines.data[contextEngineType];
|
2020-03-04 06:33:31 +08:00
|
|
|
|
|
|
|
bool startDirect = true;
|
2020-03-07 02:02:24 +08:00
|
|
|
if (!osContext.isDefaultContext()) {
|
|
|
|
startDirect = directSubmissionProperty.useNonDefault;
|
|
|
|
}
|
2020-03-04 06:33:31 +08:00
|
|
|
if (osContext.isLowPriority()) {
|
|
|
|
startDirect = directSubmissionProperty.useLowPriority;
|
|
|
|
}
|
|
|
|
if (osContext.isInternalEngine()) {
|
|
|
|
startDirect = directSubmissionProperty.useInternal;
|
|
|
|
}
|
|
|
|
if (osContext.isRootDevice()) {
|
|
|
|
startDirect = directSubmissionProperty.useRootDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (directSubmissionProperty.engineSupported && startDirect) {
|
2020-01-16 00:02:47 +08:00
|
|
|
if (contextEngineType == ENGINE_TYPE_BCS) {
|
|
|
|
directSubmission = std::make_unique<WddmDirectSubmission<GfxFamily>>(device,
|
|
|
|
std::make_unique<BlitterDispatcher<GfxFamily>>(),
|
|
|
|
osContext);
|
|
|
|
} else {
|
|
|
|
directSubmission = std::make_unique<WddmDirectSubmission<GfxFamily>>(device,
|
|
|
|
std::make_unique<RenderDispatcher<GfxFamily>>(),
|
|
|
|
osContext);
|
|
|
|
}
|
|
|
|
ret = directSubmission->initialize(directSubmissionProperty.submitOnInit);
|
|
|
|
this->dispatchMode = DispatchMode::ImmediateDispatch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|