2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-02-02 01:06:21 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "submissions_aggregator.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/flush_stamp.h"
|
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
void NEO::SubmissionAggregator::recordCommandBuffer(CommandBuffer *commandBuffer) {
|
2017-12-21 07:45:38 +08:00
|
|
|
this->cmdBuffers.pushTailOne(*commandBuffer);
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
void NEO::SubmissionAggregator::aggregateCommandBuffers(ResourcePackage &resourcePackage, size_t &totalUsedSize, size_t totalMemoryBudget, uint32_t osContextId) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto primaryCommandBuffer = this->cmdBuffers.peekHead();
|
|
|
|
auto currentInspection = this->inspectionId;
|
|
|
|
|
|
|
|
if (!primaryCommandBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto primaryBatchGraphicsAllocation = primaryCommandBuffer->batchBuffer.commandBufferAllocation;
|
|
|
|
|
|
|
|
this->inspectionId++;
|
|
|
|
primaryCommandBuffer->inspectionId = currentInspection;
|
|
|
|
|
2022-11-19 05:02:29 +08:00
|
|
|
// primary command buffers must fix to budget
|
2017-12-21 07:45:38 +08:00
|
|
|
for (auto &graphicsAllocation : primaryCommandBuffer->surfaces) {
|
2018-12-04 22:11:29 +08:00
|
|
|
if (graphicsAllocation->getInspectionId(osContextId) < currentInspection) {
|
|
|
|
graphicsAllocation->setInspectionId(currentInspection, osContextId);
|
2017-12-21 07:45:38 +08:00
|
|
|
resourcePackage.push_back(graphicsAllocation);
|
|
|
|
totalUsedSize += graphicsAllocation->getUnderlyingBufferSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 05:02:29 +08:00
|
|
|
// check if we have anything for merge
|
2017-12-21 07:45:38 +08:00
|
|
|
if (!primaryCommandBuffer->next) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-19 05:02:29 +08:00
|
|
|
// check if next cmd buffer is compatible
|
2017-12-21 07:45:38 +08:00
|
|
|
if (primaryCommandBuffer->next->batchBuffer.requiresCoherency != primaryCommandBuffer->batchBuffer.requiresCoherency) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-28 17:38:31 +08:00
|
|
|
if (primaryCommandBuffer->next->batchBuffer.lowPriority != primaryCommandBuffer->batchBuffer.lowPriority) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-29 18:18:34 +08:00
|
|
|
if (primaryCommandBuffer->next->batchBuffer.throttle != primaryCommandBuffer->batchBuffer.throttle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-21 18:50:47 +08:00
|
|
|
if (primaryCommandBuffer->next->batchBuffer.sliceCount != primaryCommandBuffer->batchBuffer.sliceCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
auto nextCommandBuffer = primaryCommandBuffer->next;
|
|
|
|
ResourcePackage newResources;
|
|
|
|
|
|
|
|
while (nextCommandBuffer) {
|
|
|
|
size_t nextCommandBufferNewResourcesSize = 0;
|
2022-11-19 05:02:29 +08:00
|
|
|
// evaluate if buffer fits
|
2017-12-21 07:45:38 +08:00
|
|
|
for (auto &graphicsAllocation : nextCommandBuffer->surfaces) {
|
|
|
|
if (graphicsAllocation == primaryBatchGraphicsAllocation) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-12-04 22:11:29 +08:00
|
|
|
if (graphicsAllocation->getInspectionId(osContextId) < currentInspection) {
|
|
|
|
graphicsAllocation->setInspectionId(currentInspection, osContextId);
|
2017-12-21 07:45:38 +08:00
|
|
|
newResources.push_back(graphicsAllocation);
|
|
|
|
nextCommandBufferNewResourcesSize += graphicsAllocation->getUnderlyingBufferSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextCommandBuffer->batchBuffer.commandBufferAllocation && (nextCommandBuffer->batchBuffer.commandBufferAllocation != primaryBatchGraphicsAllocation)) {
|
2018-12-04 22:11:29 +08:00
|
|
|
if (nextCommandBuffer->batchBuffer.commandBufferAllocation->getInspectionId(osContextId) < currentInspection) {
|
|
|
|
nextCommandBuffer->batchBuffer.commandBufferAllocation->setInspectionId(currentInspection, osContextId);
|
2017-12-21 07:45:38 +08:00
|
|
|
newResources.push_back(nextCommandBuffer->batchBuffer.commandBufferAllocation);
|
|
|
|
nextCommandBufferNewResourcesSize += nextCommandBuffer->batchBuffer.commandBufferAllocation->getUnderlyingBufferSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextCommandBufferNewResourcesSize + totalUsedSize <= totalMemoryBudget) {
|
|
|
|
auto currentNode = nextCommandBuffer;
|
|
|
|
nextCommandBuffer = nextCommandBuffer->next;
|
|
|
|
totalUsedSize += nextCommandBufferNewResourcesSize;
|
|
|
|
currentNode->inspectionId = currentInspection;
|
|
|
|
|
|
|
|
for (auto &newResource : newResources) {
|
|
|
|
resourcePackage.push_back(newResource);
|
|
|
|
}
|
|
|
|
newResources.clear();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 18:50:47 +08:00
|
|
|
NEO::BatchBuffer::BatchBuffer(GraphicsAllocation *commandBufferAllocation, size_t startOffset,
|
2022-11-19 05:02:29 +08:00
|
|
|
size_t chainedBatchBufferStartOffset, uint64_t taskStartAddress, GraphicsAllocation *chainedBatchBuffer,
|
2022-11-27 04:10:32 +08:00
|
|
|
bool requiresCoherency, bool lowPriority, QueueThrottle throttle, uint64_t sliceCount,
|
2023-02-02 01:06:21 +08:00
|
|
|
size_t usedSize, LinearStream *stream, void *endCmdPtr, uint32_t numCsrClients, bool hasStallingCmds,
|
2022-11-27 04:10:32 +08:00
|
|
|
bool hasRelaxedOrderingDependencies)
|
2019-08-21 18:50:47 +08:00
|
|
|
: commandBufferAllocation(commandBufferAllocation), startOffset(startOffset),
|
2022-11-19 05:02:29 +08:00
|
|
|
chainedBatchBufferStartOffset(chainedBatchBufferStartOffset), taskStartAddress(taskStartAddress), chainedBatchBuffer(chainedBatchBuffer),
|
2023-04-28 17:38:31 +08:00
|
|
|
requiresCoherency(requiresCoherency), lowPriority(lowPriority),
|
2019-08-21 18:50:47 +08:00
|
|
|
throttle(throttle), sliceCount(sliceCount),
|
2023-02-02 01:06:21 +08:00
|
|
|
usedSize(usedSize), stream(stream), endCmdPtr(endCmdPtr), numCsrClients(numCsrClients), hasStallingCmds(hasStallingCmds),
|
2022-11-27 04:10:32 +08:00
|
|
|
hasRelaxedOrderingDependencies(hasRelaxedOrderingDependencies) {}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
NEO::CommandBuffer::CommandBuffer(Device &device) : device(device) {
|
2017-12-21 07:45:38 +08:00
|
|
|
flushStamp.reset(new FlushStampTracker(false));
|
|
|
|
}
|