2020-01-16 00:02:47 +08:00
|
|
|
/*
|
2021-02-05 23:27:21 +08:00
|
|
|
* Copyright (C) 2020-2021 Intel Corporation
|
2020-01-16 00:02:47 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
2021-06-08 03:47:12 +08:00
|
|
|
#include "shared/source/device/device.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/direct_submission/linux/drm_direct_submission.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_allocation.h"
|
2020-07-17 17:28:59 +08:00
|
|
|
#include "shared/source/os_interface/linux/drm_buffer_object.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
|
|
|
#include "shared/source/os_interface/linux/os_context_linux.h"
|
|
|
|
|
|
|
|
#include <memory>
|
2020-01-16 00:02:47 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
DrmDirectSubmission<GfxFamily, Dispatcher>::DrmDirectSubmission(Device &device,
|
|
|
|
OsContext &osContext)
|
2021-02-05 23:27:21 +08:00
|
|
|
: DirectSubmissionHw<GfxFamily, Dispatcher>(device, osContext) {
|
|
|
|
|
2021-03-29 20:23:38 +08:00
|
|
|
this->disableMonitorFence = true;
|
|
|
|
|
|
|
|
if (DebugManager.flags.DirectSubmissionDisableMonitorFence.get() != -1) {
|
|
|
|
this->disableMonitorFence = DebugManager.flags.DirectSubmissionDisableMonitorFence.get();
|
|
|
|
}
|
2021-05-11 18:26:43 +08:00
|
|
|
|
|
|
|
auto osContextLinux = static_cast<OsContextLinux *>(&this->osContext);
|
|
|
|
osContextLinux->getDrm().setDirectSubmissionActive(true);
|
2021-02-05 23:27:21 +08:00
|
|
|
};
|
2020-07-17 17:28:59 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
inline DrmDirectSubmission<GfxFamily, Dispatcher>::~DrmDirectSubmission() {
|
2021-08-25 23:19:44 +08:00
|
|
|
this->stopRingBuffer();
|
|
|
|
this->wait(static_cast<uint32_t>(this->currentTagData.tagValue));
|
2020-07-17 17:28:59 +08:00
|
|
|
this->deallocateResources();
|
2020-01-16 00:02:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
2020-07-17 17:28:59 +08:00
|
|
|
bool DrmDirectSubmission<GfxFamily, Dispatcher>::allocateOsResources() {
|
2020-08-07 16:57:53 +08:00
|
|
|
this->currentTagData.tagAddress = this->semaphoreGpuVa + MemoryConstants::cacheLineSize;
|
|
|
|
this->currentTagData.tagValue = 0u;
|
|
|
|
this->tagAddress = reinterpret_cast<volatile uint32_t *>(reinterpret_cast<uint8_t *>(this->semaphorePtr) + MemoryConstants::cacheLineSize);
|
2020-07-17 17:28:59 +08:00
|
|
|
return true;
|
2020-01-16 00:02:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
bool DrmDirectSubmission<GfxFamily, Dispatcher>::submit(uint64_t gpuAddress, size_t size) {
|
2020-07-17 17:28:59 +08:00
|
|
|
auto bb = static_cast<DrmAllocation *>(this->ringCommandStream.getGraphicsAllocation())->getBO();
|
|
|
|
|
|
|
|
auto osContextLinux = static_cast<OsContextLinux *>(&this->osContext);
|
|
|
|
auto execFlags = osContextLinux->getEngineFlag() | I915_EXEC_NO_RELOC;
|
|
|
|
auto &drmContextIds = osContextLinux->getDrmContextIds();
|
|
|
|
|
|
|
|
drm_i915_gem_exec_object2 execObject{};
|
|
|
|
|
2021-02-05 23:27:21 +08:00
|
|
|
this->handleResidency();
|
|
|
|
|
2021-07-30 17:56:58 +08:00
|
|
|
auto currentBase = this->ringCommandStream.getGraphicsAllocation()->getGpuAddress();
|
|
|
|
auto offset = ptrDiff(gpuAddress, currentBase);
|
|
|
|
|
2020-07-17 17:28:59 +08:00
|
|
|
bool ret = false;
|
2020-09-15 18:43:16 +08:00
|
|
|
uint32_t drmContextId = 0u;
|
|
|
|
for (auto drmIterator = 0u; drmIterator < osContextLinux->getDeviceBitfield().size(); drmIterator++) {
|
|
|
|
if (osContextLinux->getDeviceBitfield().test(drmIterator)) {
|
2020-09-18 19:11:50 +08:00
|
|
|
ret |= !!bb->exec(static_cast<uint32_t>(size),
|
2021-07-30 17:56:58 +08:00
|
|
|
offset,
|
2020-09-18 19:11:50 +08:00
|
|
|
execFlags,
|
|
|
|
false,
|
|
|
|
&this->osContext,
|
|
|
|
drmIterator,
|
|
|
|
drmContextIds[drmContextId],
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
&execObject);
|
2020-09-15 18:43:16 +08:00
|
|
|
drmContextId++;
|
|
|
|
}
|
2020-07-17 17:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return !ret;
|
2020-01-16 00:02:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
bool DrmDirectSubmission<GfxFamily, Dispatcher>::handleResidency() {
|
2021-02-05 23:27:21 +08:00
|
|
|
auto osContextLinux = static_cast<OsContextLinux *>(&this->osContext);
|
|
|
|
osContextLinux->waitForPagingFence();
|
2020-07-17 17:28:59 +08:00
|
|
|
return true;
|
2020-01-16 00:02:47 +08:00
|
|
|
}
|
|
|
|
|
2021-04-14 22:40:23 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
bool DrmDirectSubmission<GfxFamily, Dispatcher>::isNewResourceHandleNeeded() {
|
|
|
|
auto osContextLinux = static_cast<OsContextLinux *>(&this->osContext);
|
|
|
|
auto newResourcesBound = osContextLinux->getDrm().getNewResourceBound();
|
|
|
|
|
|
|
|
if (DebugManager.flags.DirectSubmissionNewResourceTlbFlush.get() != -1) {
|
|
|
|
newResourcesBound = DebugManager.flags.DirectSubmissionNewResourceTlbFlush.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return newResourcesBound;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
void DrmDirectSubmission<GfxFamily, Dispatcher>::handleNewResourcesSubmission() {
|
|
|
|
if (isNewResourceHandleNeeded()) {
|
2021-07-29 14:40:42 +08:00
|
|
|
Dispatcher::dispatchTlbFlush(this->ringCommandStream, this->gpuVaForMiFlush);
|
2021-04-14 22:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto osContextLinux = static_cast<OsContextLinux *>(&this->osContext);
|
|
|
|
if (!EngineHelpers::isBcs(osContextLinux->getEngineType())) {
|
|
|
|
osContextLinux->getDrm().setNewResourceBound(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
size_t DrmDirectSubmission<GfxFamily, Dispatcher>::getSizeNewResourceHandler() {
|
|
|
|
size_t size = 0u;
|
|
|
|
|
|
|
|
if (isNewResourceHandleNeeded()) {
|
|
|
|
size += Dispatcher::getSizeTlbFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2021-08-25 23:19:44 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
void DrmDirectSubmission<GfxFamily, Dispatcher>::handleStopRingBuffer() {
|
|
|
|
if (this->disableMonitorFence) {
|
|
|
|
this->currentTagData.tagValue++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
2020-07-17 17:28:59 +08:00
|
|
|
void DrmDirectSubmission<GfxFamily, Dispatcher>::handleSwitchRingBuffers() {
|
2021-03-29 20:23:38 +08:00
|
|
|
if (this->disableMonitorFence) {
|
|
|
|
auto previousRingBuffer = this->currentRingBuffer == DirectSubmissionHw<GfxFamily, Dispatcher>::RingBufferUse::FirstBuffer ? DirectSubmissionHw<GfxFamily, Dispatcher>::RingBufferUse::SecondBuffer : DirectSubmissionHw<GfxFamily, Dispatcher>::RingBufferUse::FirstBuffer;
|
|
|
|
this->currentTagData.tagValue++;
|
|
|
|
this->completionRingBuffers[previousRingBuffer] = this->currentTagData.tagValue;
|
|
|
|
}
|
|
|
|
|
2020-08-07 16:57:53 +08:00
|
|
|
if (this->ringStart) {
|
|
|
|
if (this->completionRingBuffers[this->currentRingBuffer] != 0) {
|
|
|
|
this->wait(static_cast<uint32_t>(this->completionRingBuffers[this->currentRingBuffer]));
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 00:02:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
uint64_t DrmDirectSubmission<GfxFamily, Dispatcher>::updateTagValue() {
|
2021-03-29 20:23:38 +08:00
|
|
|
if (!this->disableMonitorFence) {
|
|
|
|
this->currentTagData.tagValue++;
|
|
|
|
this->completionRingBuffers[this->currentRingBuffer] = this->currentTagData.tagValue;
|
|
|
|
}
|
2020-01-16 00:02:47 +08:00
|
|
|
return 0ull;
|
|
|
|
}
|
|
|
|
|
2020-03-27 03:13:10 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
void DrmDirectSubmission<GfxFamily, Dispatcher>::getTagAddressValue(TagData &tagData) {
|
2020-08-07 16:57:53 +08:00
|
|
|
tagData.tagAddress = this->currentTagData.tagAddress;
|
|
|
|
tagData.tagValue = this->currentTagData.tagValue + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
void DrmDirectSubmission<GfxFamily, Dispatcher>::wait(uint32_t taskCountToWait) {
|
|
|
|
while (taskCountToWait > *this->tagAddress) {
|
|
|
|
}
|
2020-01-16 00:02:47 +08:00
|
|
|
}
|
2020-08-07 16:57:53 +08:00
|
|
|
|
2020-01-16 00:02:47 +08:00
|
|
|
} // namespace NEO
|