2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-20 11:54:29 +08:00
|
|
|
* Copyright (C) 2017-2018 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/command_stream/linear_stream.h"
|
|
|
|
#include "hw_cmds.h"
|
2018-07-27 19:59:39 +08:00
|
|
|
#include "runtime/execution_environment/execution_environment.h"
|
|
|
|
#include "runtime/gmm_helper/gmm_helper.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/helpers/preamble.h"
|
|
|
|
#include "runtime/mem_obj/buffer.h"
|
|
|
|
#include "runtime/os_interface/linux/drm_buffer_object.h"
|
|
|
|
#include "runtime/os_interface/linux/drm_command_stream.h"
|
2017-11-14 18:15:09 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_engine_mapper.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_memory_manager.h"
|
|
|
|
#include "runtime/os_interface/linux/drm_neo.h"
|
|
|
|
#include "runtime/os_interface/linux/os_interface.h"
|
2018-07-27 19:59:39 +08:00
|
|
|
#include "runtime/platform/platform.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(const HardwareInfo &hwInfoIn,
|
2018-08-30 15:27:47 +08:00
|
|
|
ExecutionEnvironment &executionEnvironment, gemCloseWorkerMode mode)
|
2018-08-08 19:49:09 +08:00
|
|
|
: BaseClass(hwInfoIn, executionEnvironment), gemCloseWorkerOperationMode(mode) {
|
2018-09-17 21:42:15 +08:00
|
|
|
|
|
|
|
this->drm = executionEnvironment.osInterface->get()->getDrm();
|
|
|
|
|
2018-08-30 15:27:47 +08:00
|
|
|
residency.reserve(512);
|
|
|
|
execObjectsStorage.reserve(512);
|
|
|
|
|
2018-08-10 17:07:17 +08:00
|
|
|
executionEnvironment.osInterface->get()->setDrm(this->drm);
|
|
|
|
CommandStreamReceiver::osInterface = executionEnvironment.osInterface.get();
|
2018-07-27 19:59:39 +08:00
|
|
|
auto gmmHelper = platform()->peekExecutionEnvironment()->getGmmHelper();
|
|
|
|
gmmHelper->setSimplifiedMocsTableUsage(this->drm->getSimplifiedMocsTableUsage());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-09-25 18:38:00 +08:00
|
|
|
FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer &allocationsForResidency, OsContext &osContext) {
|
2017-11-14 18:15:09 +08:00
|
|
|
unsigned int engineFlag = 0xFF;
|
|
|
|
bool ret = DrmEngineMapper<GfxFamily>::engineNodeMap(engineType, engineFlag);
|
|
|
|
UNRECOVERABLE_IF(!(ret));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
|
|
|
|
DEBUG_BREAK_IF(!alloc);
|
|
|
|
|
|
|
|
size_t alignedStart = (reinterpret_cast<uintptr_t>(batchBuffer.commandBufferAllocation->getUnderlyingBuffer()) & (MemoryConstants::allocationAlignment - 1)) + batchBuffer.startOffset;
|
|
|
|
BufferObject *bb = alloc->getBO();
|
|
|
|
FlushStamp flushStamp = 0;
|
|
|
|
|
|
|
|
if (bb) {
|
|
|
|
flushStamp = bb->peekHandle();
|
2018-09-25 18:38:00 +08:00
|
|
|
this->processResidency(allocationsForResidency, osContext);
|
2017-12-21 07:45:38 +08:00
|
|
|
// Residency hold all allocation except command buffer, hence + 1
|
|
|
|
auto requiredSize = this->residency.size() + 1;
|
|
|
|
if (requiredSize > this->execObjectsStorage.size()) {
|
|
|
|
this->execObjectsStorage.resize(requiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bb->swapResidencyVector(&this->residency);
|
|
|
|
bb->setExecObjectsStorage(this->execObjectsStorage.data());
|
|
|
|
this->residency.reserve(512);
|
|
|
|
|
|
|
|
bb->exec(static_cast<uint32_t>(alignUp(batchBuffer.usedSize - batchBuffer.startOffset, 8)),
|
2017-11-14 18:15:09 +08:00
|
|
|
alignedStart, engineFlag | I915_EXEC_NO_RELOC,
|
2017-12-21 07:45:38 +08:00
|
|
|
batchBuffer.requiresCoherency,
|
|
|
|
batchBuffer.low_priority);
|
|
|
|
|
2018-05-10 16:16:22 +08:00
|
|
|
bb->getResidency()->clear();
|
2018-05-11 15:57:59 +08:00
|
|
|
|
|
|
|
if (this->gemCloseWorkerOperationMode == gemCloseWorkerActive) {
|
|
|
|
bb->reference();
|
|
|
|
this->getMemoryManager()->peekGemCloseWorker()->push(bb);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return flushStamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::makeResident(GraphicsAllocation &gfxAllocation) {
|
|
|
|
|
|
|
|
if (gfxAllocation.getUnderlyingBufferSize() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CommandStreamReceiver::makeResident(gfxAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::makeResident(BufferObject *bo) {
|
2018-11-09 01:30:13 +08:00
|
|
|
if (bo) {
|
|
|
|
if (bo->peekIsReusableAllocation()) {
|
|
|
|
for (auto bufferObject : this->residency) {
|
|
|
|
if (bufferObject == bo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
residency.push_back(bo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-09-14 16:39:21 +08:00
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::processResidency(ResidencyContainer &inputAllocationsForResidency, OsContext &osContext) {
|
|
|
|
for (auto &alloc : inputAllocationsForResidency) {
|
2018-10-19 16:42:09 +08:00
|
|
|
auto drmAlloc = static_cast<DrmAllocation *>(alloc);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (drmAlloc->fragmentsStorage.fragmentCount) {
|
2018-06-08 20:40:21 +08:00
|
|
|
for (unsigned int f = 0; f < drmAlloc->fragmentsStorage.fragmentCount; f++) {
|
2018-11-09 01:30:13 +08:00
|
|
|
if (!drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident) {
|
|
|
|
makeResident(drmAlloc->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo);
|
|
|
|
drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident = true;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BufferObject *bo = drmAlloc->getBO();
|
|
|
|
makeResident(bo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::makeNonResident(GraphicsAllocation &gfxAllocation) {
|
|
|
|
// Vector is moved to command buffer inside flush.
|
|
|
|
// If flush wasn't called we need to make all objects non-resident.
|
|
|
|
// If makeNonResident is called before flush, vector will be cleared.
|
2018-11-06 18:38:49 +08:00
|
|
|
if (gfxAllocation.isResident(this->deviceIndex)) {
|
2017-12-21 07:45:38 +08:00
|
|
|
if (this->residency.size() != 0) {
|
|
|
|
this->residency.clear();
|
|
|
|
}
|
|
|
|
if (gfxAllocation.fragmentsStorage.fragmentCount) {
|
|
|
|
for (auto fragmentId = 0u; fragmentId < gfxAllocation.fragmentsStorage.fragmentCount; fragmentId++) {
|
|
|
|
gfxAllocation.fragmentsStorage.fragmentStorageData[fragmentId].residency->resident = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-06 18:38:49 +08:00
|
|
|
gfxAllocation.resetResidencyTaskCount(this->deviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
DrmMemoryManager *DrmCommandStreamReceiver<GfxFamily>::getMemoryManager() {
|
|
|
|
return (DrmMemoryManager *)CommandStreamReceiver::getMemoryManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-09-06 16:53:35 +08:00
|
|
|
MemoryManager *DrmCommandStreamReceiver<GfxFamily>::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) {
|
2018-10-11 17:19:49 +08:00
|
|
|
return new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true, this->executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-08-27 21:48:29 +08:00
|
|
|
bool DrmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStamp, OsContext &osContext) {
|
2017-12-21 07:45:38 +08:00
|
|
|
drm_i915_gem_wait wait = {};
|
2018-02-02 17:33:31 +08:00
|
|
|
wait.bo_handle = static_cast<uint32_t>(flushStamp);
|
2017-12-21 07:45:38 +08:00
|
|
|
wait.timeout_ns = -1;
|
|
|
|
|
|
|
|
drm->ioctl(DRM_IOCTL_I915_GEM_WAIT, &wait);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
inline void DrmCommandStreamReceiver<GfxFamily>::overrideMediaVFEStateDirty(bool dirty) {
|
|
|
|
this->mediaVfeStateDirty = dirty;
|
|
|
|
this->mediaVfeStateLowPriorityDirty = dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
inline void DrmCommandStreamReceiver<GfxFamily>::programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags) {
|
2018-01-24 19:00:27 +08:00
|
|
|
bool ¤tContextDirtyFlag = dispatchFlags.lowPriority ? mediaVfeStateLowPriorityDirty : mediaVfeStateDirty;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
if (currentContextDirtyFlag) {
|
|
|
|
PreambleHelper<GfxFamily>::programVFEState(&csr, hwInfo, requiredScratchSize, getScratchPatchAddress());
|
|
|
|
currentContextDirtyFlag = false;
|
|
|
|
}
|
|
|
|
}
|
2018-03-29 16:41:39 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|