2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-02-20 12:43:37 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-19 20:54:29 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01: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)
|
2019-08-22 16:51:02 +02:00
|
|
|
#include "core/command_stream/linear_stream.h"
|
2019-05-28 19:09:40 -07:00
|
|
|
#include "core/helpers/ptr_math.h"
|
2018-02-06 11:58:05 +01:00
|
|
|
#include "runtime/command_stream/preemption.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/device/device.h"
|
2018-07-18 14:11:05 +02:00
|
|
|
#include "runtime/gmm_helper/page_table_mngr.h"
|
2018-08-17 13:38:09 +02:00
|
|
|
#include "runtime/helpers/gmm_callbacks.h"
|
2018-07-18 14:11:05 +02:00
|
|
|
#include "runtime/mem_obj/mem_obj.h"
|
|
|
|
|
#include "runtime/os_interface/windows/wddm/wddm.h"
|
|
|
|
|
#include "runtime/os_interface/windows/wddm_device_command_stream.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
|
|
|
|
#include "hw_cmds.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#pragma warning(pop)
|
|
|
|
|
|
|
|
|
|
#include "runtime/os_interface/windows/gdi_interface.h"
|
2018-08-27 15:48:29 +02:00
|
|
|
#include "runtime/os_interface/windows/os_context_win.h"
|
2018-07-18 14:11:05 +02:00
|
|
|
#include "runtime/os_interface/windows/os_interface.h"
|
|
|
|
|
#include "runtime/os_interface/windows/wddm_memory_manager.h"
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
// Initialize COMMAND_BUFFER_HEADER Type PatchList Streamer Perf Tag
|
|
|
|
|
DECLARE_COMMAND_BUFFER(CommandBufferHeader, UMD_OCL, FALSE, FALSE, PERFTAG_OCL);
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-02-27 10:06:14 +01:00
|
|
|
WddmCommandStreamReceiver<GfxFamily>::WddmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment)
|
|
|
|
|
: BaseClass(executionEnvironment) {
|
2018-08-30 09:27:47 +02:00
|
|
|
|
2019-06-19 14:04:58 +02:00
|
|
|
notifyAubCaptureImpl = DeviceCallbacks<GfxFamily>::notifyAubCapture;
|
2018-09-17 15:42:15 +02:00
|
|
|
this->wddm = executionEnvironment.osInterface->get()->getWddm();
|
|
|
|
|
this->osInterface = executionEnvironment.osInterface.get();
|
2018-08-30 09:27:47 +02:00
|
|
|
|
2019-02-27 10:06:14 +01:00
|
|
|
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(peekHwInfo());
|
2018-08-27 15:48:29 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
commandBufferHeader = new COMMAND_BUFFER_HEADER;
|
|
|
|
|
*commandBufferHeader = CommandBufferHeader;
|
2018-08-06 11:18:52 +02:00
|
|
|
|
|
|
|
|
if (preemptionMode != PreemptionMode::Disabled) {
|
|
|
|
|
commandBufferHeader->NeedsMidBatchPreEmptionSupport = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01: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>
|
2018-11-26 14:04:52 +01:00
|
|
|
FlushStamp WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
2018-03-01 16:21:18 +01:00
|
|
|
auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
|
|
|
|
|
makeResident(*batchBuffer.commandBufferAllocation);
|
|
|
|
|
} else {
|
2018-09-25 12:38:00 +02:00
|
|
|
allocationsForResidency.push_back(batchBuffer.commandBufferAllocation);
|
2018-12-03 10:05:36 +01:00
|
|
|
batchBuffer.commandBufferAllocation->updateResidencyTaskCount(this->taskCount, this->osContext->getContextId());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-26 14:04:52 +01:00
|
|
|
this->processResidency(allocationsForResidency);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandBufferHeader);
|
|
|
|
|
pHeader->RequiresCoherency = batchBuffer.requiresCoherency;
|
2018-01-29 11:18:34 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
pHeader->UmdRequestedSliceState = 0;
|
|
|
|
|
pHeader->UmdRequestedEUCount = wddm->getGtSysInfo()->EUCount / wddm->getGtSysInfo()->SubSliceCount;
|
|
|
|
|
|
2018-01-29 11:18:34 +01: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-22 21:13:45 +01:00
|
|
|
if (wddm->isKmDafEnabled()) {
|
|
|
|
|
this->kmDafLockAllocations(allocationsForResidency);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 11:17:17 +01:00
|
|
|
auto osContextWin = static_cast<OsContextWin *>(osContext);
|
|
|
|
|
wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContextWin);
|
2018-03-22 21:13:45 +01:00
|
|
|
|
2019-02-27 11:17:17 +01:00
|
|
|
return osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::makeResident(GraphicsAllocation &gfxAllocation) {
|
2019-07-29 16:11:51 +02:00
|
|
|
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation =", &gfxAllocation);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
if (gfxAllocation.fragmentsStorage.fragmentCount == 0) {
|
2019-07-29 16:11:51 +02:00
|
|
|
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation default handle =", static_cast<WddmAllocation &>(gfxAllocation).getDefaultHandle());
|
2017-12-21 00:45:38 +01:00
|
|
|
} else {
|
2019-07-29 16:11:51 +02:00
|
|
|
for (uint32_t allocationId = 0; allocationId < gfxAllocation.fragmentsStorage.fragmentCount; allocationId++) {
|
|
|
|
|
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "fragment handle =", gfxAllocation.fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandStreamReceiver::makeResident(gfxAllocation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-09-05 11:02:40 +02:00
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::processResidency(const ResidencyContainer &allocationsForResidency) {
|
2019-02-27 11:17:17 +01:00
|
|
|
bool success = static_cast<OsContextWin *>(osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency);
|
2017-12-21 00:45:38 +01:00
|
|
|
DEBUG_BREAK_IF(!success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-11-26 14:04:52 +01:00
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::processEviction() {
|
2019-02-27 11:17:17 +01:00
|
|
|
static_cast<OsContextWin *>(osContext)->getResidencyController().makeNonResidentEvictionAllocations(this->getEvictionAllocations());
|
2018-09-14 13:48:02 +02:00
|
|
|
this->getEvictionAllocations().clear();
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-07-29 16:11:51 +02:00
|
|
|
WddmMemoryManager *WddmCommandStreamReceiver<GfxFamily>::getMemoryManager() const {
|
2018-10-11 11:19:49 +02:00
|
|
|
return static_cast<WddmMemoryManager *>(CommandStreamReceiver::getMemoryManager());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-11-26 14:04:52 +01:00
|
|
|
bool WddmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStampToWait) {
|
2019-02-27 11:17:17 +01:00
|
|
|
return wddm->waitFromCpu(flushStampToWait, static_cast<OsContextWin *>(osContext)->getResidencyController().getMonitoredFence());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
GmmPageTableMngr *WddmCommandStreamReceiver<GfxFamily>::createPageTableManager() {
|
|
|
|
|
GMM_TRANSLATIONTABLE_CALLBACKS ttCallbacks = {};
|
2019-06-19 14:04:58 +02:00
|
|
|
ttCallbacks.pfWriteL3Adr = TTCallbacks<GfxFamily>::writeL3Address;
|
|
|
|
|
|
|
|
|
|
GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(TT_TYPE::TRTT | TT_TYPE::AUXTT, &ttCallbacks);
|
|
|
|
|
gmmPageTableMngr->setCsrHandle(this);
|
2018-08-17 13:38:09 +02:00
|
|
|
this->wddm->resetPageTableManager(gmmPageTableMngr);
|
|
|
|
|
return gmmPageTableMngr;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::initPageTableManagerRegisters(LinearStream &csr) {
|
2018-02-14 20:14:20 +01:00
|
|
|
if (wddm->getPageTableManager() && !pageTableManagerInitialized) {
|
|
|
|
|
wddm->getPageTableManager()->initContextTRTableRegister(this, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS);
|
|
|
|
|
wddm->getPageTableManager()->initContextAuxTableRegister(this, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS);
|
|
|
|
|
|
|
|
|
|
pageTableManagerInitialized = true;
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2018-03-22 21:13:45 +01:00
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-09-25 12:38:00 +02:00
|
|
|
void WddmCommandStreamReceiver<GfxFamily>::kmDafLockAllocations(ResidencyContainer &allocationsForResidency) {
|
|
|
|
|
for (auto &graphicsAllocation : allocationsForResidency) {
|
2018-07-05 16:31:57 +02:00
|
|
|
if ((GraphicsAllocation::AllocationType::LINEAR_STREAM == graphicsAllocation->getAllocationType()) ||
|
2019-02-20 12:43:37 +01:00
|
|
|
(GraphicsAllocation::AllocationType::FILL_PATTERN == graphicsAllocation->getAllocationType()) ||
|
|
|
|
|
(GraphicsAllocation::AllocationType::COMMAND_BUFFER == graphicsAllocation->getAllocationType())) {
|
2019-03-05 09:25:18 +01:00
|
|
|
wddm->kmDafLock(static_cast<WddmAllocation *>(graphicsAllocation)->getDefaultHandle());
|
2018-03-22 21:13:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|