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"
|
|
|
|
#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-07-17 17:28:59 +08:00
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
inline std::unique_ptr<DirectSubmissionHw<GfxFamily, Dispatcher>> DirectSubmissionHw<GfxFamily, Dispatcher>::create(Device &device, OsContext &osContext) {
|
|
|
|
return std::make_unique<DrmDirectSubmission<GfxFamily, Dispatcher>>(device, osContext);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
auto osContextLinux = static_cast<OsContextLinux *>(&this->osContext);
|
|
|
|
osContextLinux->getDrm().setDirectSubmissionActive(true);
|
|
|
|
};
|
2020-07-17 17:28:59 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily, typename Dispatcher>
|
|
|
|
inline DrmDirectSubmission<GfxFamily, Dispatcher>::~DrmDirectSubmission() {
|
|
|
|
if (this->ringStart) {
|
2020-08-07 16:57:53 +08:00
|
|
|
this->wait(static_cast<uint32_t>(this->currentTagData.tagValue));
|
2020-07-17 17:28:59 +08:00
|
|
|
this->stopRingBuffer();
|
2020-08-07 16:57:53 +08:00
|
|
|
auto bb = static_cast<DrmAllocation *>(this->ringBuffer)->getBO();
|
2020-07-17 17:28:59 +08:00
|
|
|
bb->wait(-1);
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
|
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),
|
|
|
|
0,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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() {
|
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() {
|
2020-08-07 16:57:53 +08:00
|
|
|
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
|