2017-12-21 00:45:38 +01:00
/*
2022-01-07 14:53:31 +00:00
* Copyright (C) 2019-2022 Intel Corporation
2017-12-21 00:45:38 +01:00
*
2018-09-18 12:29:07 -07:00
* SPDX-License-Identifier: MIT
2017-12-21 00:45:38 +01:00
*
*/
2022-05-25 14:39:35 +00:00
#include "shared/source/built_ins/sip.h"
2021-11-17 19:51:43 +00:00
#include "shared/source/command_container/command_encoder.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/command_stream/command_stream_receiver_hw.h"
#include "shared/source/command_stream/experimental_command_buffer.h"
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/command_stream/preemption.h"
#include "shared/source/command_stream/scratch_space_controller_base.h"
2021-05-18 02:46:21 +00:00
#include "shared/source/command_stream/stream_properties.h"
2022-02-22 12:51:29 +00:00
#include "shared/source/command_stream/wait_status.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h"
2021-07-30 09:56:58 +00:00
#include "shared/source/direct_submission/direct_submission_controller.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/direct_submission/direct_submission_hw.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/page_table_mngr.h"
#include "shared/source/helpers/blit_commands_helper.h"
#include "shared/source/helpers/cache_policy.h"
2021-07-22 08:56:08 +00:00
#include "shared/source/helpers/engine_node_helper.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/helpers/flat_batch_buffer_helper_hw.h"
#include "shared/source/helpers/flush_stamp.h"
#include "shared/source/helpers/hw_helper.h"
2022-06-14 14:18:28 +00:00
#include "shared/source/helpers/logical_state_helper.h"
2020-09-24 10:52:53 +02:00
#include "shared/source/helpers/pause_on_gpu_properties.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/helpers/preamble.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/state_base_address.h"
#include "shared/source/helpers/timestamp_packet.h"
#include "shared/source/indirect_heap/indirect_heap.h"
#include "shared/source/memory_manager/internal_allocation_storage.h"
#include "shared/source/memory_manager/memory_manager.h"
2021-09-06 10:34:34 +00:00
#include "shared/source/os_interface/hw_info_config.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/os_interface/os_context.h"
#include "shared/source/utilities/tag_allocator.h"
2017-12-21 00:45:38 +01:00
2019-10-11 12:54:10 +08:00
#include "command_stream_receiver_hw_ext.inl"
2019-03-26 11:59:46 +01:00
namespace NEO {
2017-12-21 00:45:38 +01:00
2020-01-15 17:02:47 +01:00
template <typename GfxFamily>
2021-07-30 09:56:58 +00:00
CommandStreamReceiverHw<GfxFamily>::~CommandStreamReceiverHw() {
2022-03-25 13:00:53 +00:00
this->unregisterDirectSubmissionFromController();
2022-04-26 13:29:31 +00:00
if (completionFenceValuePointer) {
completionFenceValue = *completionFenceValuePointer;
completionFenceValuePointer = &completionFenceValue;
}
2021-07-30 09:56:58 +00:00
}
2020-01-15 17:02:47 +01:00
2018-02-20 08:11:24 +01:00
template <typename GfxFamily>
2020-10-28 16:08:37 +01:00
CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiverHw(ExecutionEnvironment &executionEnvironment,
uint32_t rootDeviceIndex,
2020-10-29 15:33:35 +01:00
const DeviceBitfield deviceBitfield)
2020-10-28 16:08:37 +01:00
: CommandStreamReceiver(executionEnvironment, rootDeviceIndex, deviceBitfield) {
2018-10-18 13:40:53 +02:00
2021-12-20 14:37:33 +00:00
const auto &hwInfo = peekHwInfo();
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
localMemoryEnabled = hwHelper.getEnableLocalMemory(hwInfo);
2018-10-18 13:40:53 +02:00
2021-12-20 14:37:33 +00:00
resetKmdNotifyHelper(new KmdNotifyHelper(&hwInfo.capabilityTable.kmdNotifyProperties));
2021-10-21 12:32:45 +00:00
if (DebugManager.flags.FlattenBatchBufferForAUBDump.get() || DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
flatBatchBufferHelper.reset(new FlatBatchBufferHelperHw<GfxFamily>(executionEnvironment));
}
2018-09-03 16:44:42 +02:00
defaultSshSize = getSshHeapSize();
2021-03-31 20:21:59 +00:00
canUse4GbHeaps = are4GbHeapsAvailable();
2018-10-18 13:40:53 +02:00
timestampPacketWriteEnabled = hwHelper.timestampPacketWriteSupported();
if (DebugManager.flags.EnableTimestampPacket.get() != -1) {
timestampPacketWriteEnabled = !!DebugManager.flags.EnableTimestampPacket.get();
}
2022-06-14 14:18:28 +00:00
2022-07-04 14:16:44 +00:00
logicalStateHelper.reset(LogicalStateHelper::create<GfxFamily>());
2022-06-14 14:18:28 +00:00
2019-03-29 00:49:23 +01:00
createScratchSpaceController();
2021-11-30 14:41:26 +00:00
configurePostSyncWriteOffset();
2018-02-20 08:11:24 +01:00
}
2018-02-02 10:33:31 +01:00
template <typename GfxFamily>
2022-01-07 14:53:31 +00:00
SubmissionStatus CommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
return SubmissionStatus::SUCCESS;
2018-02-02 10:33:31 +01:00
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::addBatchBufferEnd(LinearStream &commandStream, void **patchLocation) {
2020-04-26 21:48:59 +02:00
using MI_BATCH_BUFFER_END = typename GfxFamily::MI_BATCH_BUFFER_END;
2017-12-21 00:45:38 +01:00
2020-04-26 21:48:59 +02:00
auto pCmd = commandStream.getSpaceForCmd<MI_BATCH_BUFFER_END>();
2017-12-21 00:45:38 +01:00
*pCmd = GfxFamily::cmdInitBatchBufferEnd;
if (patchLocation) {
*patchLocation = pCmd;
}
}
2020-01-15 17:02:47 +01:00
template <typename GfxFamily>
2021-01-28 17:30:56 +00:00
inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled) {
2020-01-15 17:02:47 +01:00
if (directSubmissionEnabled) {
2022-03-10 18:44:28 +00:00
uint64_t startAddress = commandStream.getGraphicsAllocation()->getGpuAddress() + commandStream.getUsed();
if (DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.get() == 0) {
startAddress = 0;
2022-03-10 13:34:16 +00:00
}
2020-01-15 17:02:47 +01:00
*patchLocation = commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START));
auto bbStart = reinterpret_cast<MI_BATCH_BUFFER_START *>(*patchLocation);
2020-04-27 18:55:26 +02:00
MI_BATCH_BUFFER_START cmd = {};
2022-03-10 13:34:16 +00:00
addBatchBufferStart(&cmd, startAddress, false);
2020-04-27 18:55:26 +02:00
*bbStart = cmd;
2020-01-15 17:02:47 +01:00
} else {
2022-03-10 13:34:16 +00:00
if (!EngineHelpers::isBcs(osContext->getEngineType())) {
PreemptionHelper::programStateSipEndWa<GfxFamily>(commandStream, device);
}
2020-01-15 17:02:47 +01:00
this->addBatchBufferEnd(commandStream, patchLocation);
}
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
2018-07-05 11:23:28 +02:00
inline void CommandStreamReceiverHw<GfxFamily>::addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress, bool secondary) {
2020-04-27 18:55:26 +02:00
MI_BATCH_BUFFER_START cmd = GfxFamily::cmdInitBatchBufferStart;
2021-12-16 18:02:45 +00:00
cmd.setBatchBufferStartAddress(startAddress);
2020-04-27 18:55:26 +02:00
cmd.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
2018-07-05 11:23:28 +02:00
if (secondary) {
2020-04-27 18:55:26 +02:00
cmd.setSecondLevelBatchBuffer(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER_SECOND_LEVEL_BATCH);
2018-07-05 11:23:28 +02:00
}
2018-04-04 11:34:46 +02:00
if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) {
flatBatchBufferHelper->registerBatchBufferStartAddress(reinterpret_cast<uint64_t>(commandBufferMemory), startAddress);
}
2020-04-27 18:55:26 +02:00
*commandBufferMemory = cmd;
2017-12-21 00:45:38 +01:00
}
2019-05-16 17:17:53 +02:00
template <typename GfxFamily>
inline size_t CommandStreamReceiverHw<GfxFamily>::getRequiredCmdSizeForPreamble(Device &device) const {
size_t size = 0;
if (mediaVfeStateDirty) {
size += PreambleHelper<GfxFamily>::getVFECommandsSize();
}
if (!this->isPreambleSent) {
size += PreambleHelper<GfxFamily>::getAdditionalCommandsSize(device);
}
2020-06-24 14:53:51 +02:00
if (!this->isPreambleSent) {
if (DebugManager.flags.ForceSemaphoreDelayBetweenWaits.get() > -1) {
size += PreambleHelper<GfxFamily>::getSemaphoreDelayCommandSize();
}
}
2019-05-16 17:17:53 +02:00
return size;
}
2020-05-27 15:30:31 +02:00
template <typename GfxFamily>
2020-05-22 18:11:28 +02:00
void CommandStreamReceiverHw<GfxFamily>::programHardwareContext(LinearStream &cmdStream) {
programEnginePrologue(cmdStream);
2020-05-27 15:30:31 +02:00
}
template <typename GfxFamily>
size_t CommandStreamReceiverHw<GfxFamily>::getCmdsSizeForHardwareContext() const {
return getCmdSizeForPrologue();
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
LinearStream &commandStreamTask,
size_t commandStreamStartTask,
2022-03-28 12:55:12 +00:00
const IndirectHeap *dsh,
const IndirectHeap *ioh,
const IndirectHeap *ssh,
2017-12-21 00:45:38 +01:00
uint32_t taskLevel,
2018-08-01 10:01:41 +02:00
DispatchFlags &dispatchFlags,
Device &device) {
2017-12-21 00:45:38 +01:00
typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
typedef typename GfxFamily::MI_BATCH_BUFFER_END MI_BATCH_BUFFER_END;
typedef typename GfxFamily::PIPE_CONTROL PIPE_CONTROL;
typedef typename GfxFamily::STATE_BASE_ADDRESS STATE_BASE_ADDRESS;
DEBUG_BREAK_IF(&commandStreamTask == &commandStream);
2018-08-01 10:01:41 +02:00
DEBUG_BREAK_IF(!(dispatchFlags.preemptionMode == PreemptionMode::Disabled ? device.getPreemptionMode() == PreemptionMode::Disabled : true));
2020-06-16 11:19:11 +00:00
DEBUG_BREAK_IF(taskLevel >= CompletionStamp::notReady);
2017-12-21 00:45:38 +01:00
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "taskLevel", taskLevel);
auto levelClosed = false;
2020-09-17 08:58:06 +02:00
bool implicitFlush = dispatchFlags.implicitFlush || dispatchFlags.blocking || DebugManager.flags.ForceImplicitFlush.get();
2017-12-21 00:45:38 +01:00
void *currentPipeControlForNooping = nullptr;
2018-02-15 08:29:57 +01:00
void *epiloguePipeControlLocation = nullptr;
2022-07-01 08:15:04 +00:00
PipeControlArgs args;
2017-12-21 00:45:38 +01:00
2020-11-18 13:56:18 +00:00
bool csrFlush = this->wasSubmittedToSingleSubdevice != dispatchFlags.useSingleSubdevice;
csrFlush |= DebugManager.flags.ForceCsrFlushing.get();
if (csrFlush) {
2018-06-12 20:33:03 +02:00
flushBatchedSubmissions();
}
2020-06-19 09:50:04 +02:00
2019-01-28 13:44:59 +01:00
if (detectInitProgrammingFlagsRequired(dispatchFlags)) {
2018-06-12 20:33:03 +02:00
initProgrammingFlags();
}
2021-12-20 14:37:33 +00:00
const auto &hwInfo = peekHwInfo();
2022-03-02 12:43:02 +00:00
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
2017-12-21 00:45:38 +01:00
if (dispatchFlags.blocking || dispatchFlags.dcFlush || dispatchFlags.guardCommandBufferWithPipeControl) {
2018-04-04 11:34:46 +02:00
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
2022-06-28 18:52:33 +00:00
// for ImmediateDispatch we will send this right away, therefore this pipe control will close the level
// for BatchedSubmissions it will be nooped and only last ppc in batch will be emitted.
2017-12-21 00:45:38 +01:00
levelClosed = true;
2022-06-28 18:52:33 +00:00
// if we guard with ppc, flush dc as well to speed up completion latency
2021-12-20 14:34:39 +00:00
if (dispatchFlags.guardCommandBufferWithPipeControl) {
2022-03-02 12:43:02 +00:00
const auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily);
if (hwInfoConfig.isDcFlushAllowed()) {
dispatchFlags.dcFlush = true;
}
2018-02-13 10:01:20 +01:00
}
2017-12-21 00:45:38 +01:00
}
2018-03-05 11:03:38 +01:00
epiloguePipeControlLocation = ptrOffset(commandStreamTask.getCpuBase(), commandStreamTask.getUsed());
2018-02-15 08:29:57 +01:00
2018-09-06 09:03:07 +02:00
if ((dispatchFlags.outOfOrderExecutionAllowed || timestampPacketWriteEnabled) &&
2018-08-30 11:05:18 +02:00
!dispatchFlags.dcFlush) {
2018-02-15 08:29:57 +01:00
currentPipeControlForNooping = epiloguePipeControlLocation;
2017-12-21 00:45:38 +01:00
}
2018-11-23 10:32:15 +01:00
auto address = getTagAllocation()->getGpuAddress();
2020-04-26 21:48:59 +02:00
2022-03-25 13:00:53 +00:00
args.dcFlushEnable = MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(dispatchFlags.dcFlush, hwInfo);
args.notifyEnable = isUsedNotifyEnableForPostSync();
args.tlbInvalidation |= dispatchFlags.memoryMigrationRequired;
args.textureCacheInvalidationEnable |= dispatchFlags.textureCacheFlush;
args.workloadPartitionOffset = isMultiTileOperationEnabled();
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands<GfxFamily>::addBarrierWithPostSyncOperation(
2022-03-25 13:00:53 +00:00
commandStreamTask,
2022-07-21 14:28:10 +00:00
PostSyncMode::ImmediateData,
2022-03-25 13:00:53 +00:00
address,
taskCount + 1,
hwInfo,
args);
2017-12-21 00:45:38 +01:00
2020-07-17 22:03:16 +05:30
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "taskCount", peekTaskCount());
2018-04-04 11:34:46 +02:00
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
flatBatchBufferHelper->setPatchInfoData(PatchInfoData(address, 0u,
PatchInfoAllocationType::TagAddress,
commandStreamTask.getGraphicsAllocation()->getGpuAddress(),
commandStreamTask.getUsed() - 2 * sizeof(uint64_t),
PatchInfoAllocationType::Default));
flatBatchBufferHelper->setPatchInfoData(PatchInfoData(address, 0u,
PatchInfoAllocationType::TagValue,
commandStreamTask.getGraphicsAllocation()->getGpuAddress(),
commandStreamTask.getUsed() - sizeof(uint64_t),
PatchInfoAllocationType::Default));
}
2017-12-21 00:45:38 +01:00
}
2022-03-25 13:00:53 +00:00
this->latestSentTaskCount = taskCount + 1;
2017-12-21 00:45:38 +01:00
if (DebugManager.flags.ForceSLML3Config.get()) {
dispatchFlags.useSLM = true;
}
2021-12-20 14:37:33 +00:00
auto newL3Config = PreambleHelper<GfxFamily>::getL3Config(hwInfo, dispatchFlags.useSLM);
2022-08-31 13:26:29 +00:00
auto isSystolicPipelineSelectModeChanged = PreambleHelper<GfxFamily>::isSystolicPipelineSelectModeChanged(lastSystolicPipelineSelectMode,
dispatchFlags.pipelineSelectArgs.systolicPipelineSelectMode,
hwInfo);
2017-12-21 00:45:38 +01:00
2021-12-20 16:09:41 +00:00
auto requiresCoherency = hwHelper.forceNonGpuCoherencyWA(dispatchFlags.requiresCoherency);
this->streamProperties.stateComputeMode.setProperties(requiresCoherency, dispatchFlags.numGrfRequired,
2022-06-23 15:25:10 +00:00
dispatchFlags.threadArbitrationPolicy, device.getPreemptionMode(), hwInfo);
2021-12-08 16:22:18 +00:00
2017-12-21 00:45:38 +01:00
csrSizeRequestFlags.l3ConfigChanged = this->lastSentL3Config != newL3Config;
csrSizeRequestFlags.preemptionRequestChanged = this->lastPreemptionMode != dispatchFlags.preemptionMode;
2019-09-10 16:13:11 +02:00
csrSizeRequestFlags.mediaSamplerConfigChanged = this->lastMediaSamplerConfig != static_cast<int8_t>(dispatchFlags.pipelineSelectArgs.mediaSamplerRequired);
2022-08-31 13:26:29 +00:00
csrSizeRequestFlags.systolicPipelineSelectMode = isSystolicPipelineSelectModeChanged;
2020-08-21 13:05:01 +02:00
2021-11-17 19:51:43 +00:00
csrSizeRequestFlags.activePartitionsChanged = isProgramActivePartitionConfigRequired();
2021-09-23 18:13:37 +00:00
2017-12-21 00:45:38 +01:00
auto force32BitAllocations = getMemoryManager()->peekForce32BitAllocations();
bool stateBaseAddressDirty = false;
2018-11-22 15:16:20 +01:00
bool checkVfeStateDirty = false;
2019-07-15 09:12:53 +02:00
if (requiredScratchSize || requiredPrivateScratchSize) {
2022-03-28 12:55:12 +00:00
scratchSpaceController->setRequiredScratchSpace(ssh->getCpuBase(),
2020-10-05 11:39:15 +02:00
0u,
2018-11-22 15:16:20 +01:00
requiredScratchSize,
2019-06-28 09:37:04 +02:00
requiredPrivateScratchSize,
2018-11-22 15:16:20 +01:00
this->taskCount,
2019-09-16 14:59:54 +02:00
*this->osContext,
2018-11-22 15:16:20 +01:00
stateBaseAddressDirty,
checkVfeStateDirty);
if (checkVfeStateDirty) {
2018-12-13 11:06:28 +01:00
setMediaVFEStateDirty(true);
2017-12-21 00:45:38 +01:00
}
2019-07-15 09:12:53 +02:00
if (scratchSpaceController->getScratchSpaceAllocation()) {
makeResident(*scratchSpaceController->getScratchSpaceAllocation());
}
if (scratchSpaceController->getPrivateScratchSpaceAllocation()) {
makeResident(*scratchSpaceController->getPrivateScratchSpaceAllocation());
}
2017-12-21 00:45:38 +01:00
}
2020-01-29 14:15:10 +01:00
if (dispatchFlags.usePerDssBackedBuffer) {
2019-09-04 16:44:27 +02:00
if (!perDssBackedBuffer) {
createPerDssBackedBuffer(device);
}
makeResident(*perDssBackedBuffer);
}
2022-06-24 16:50:31 +00:00
if (!logicalStateHelper) {
if (dispatchFlags.additionalKernelExecInfo != AdditionalKernelExecInfo::NotApplicable && lastAdditionalKernelExecInfo != dispatchFlags.additionalKernelExecInfo) {
setMediaVFEStateDirty(true);
}
2020-09-02 11:38:54 +02:00
2022-06-24 16:50:31 +00:00
if (dispatchFlags.kernelExecutionType != KernelExecutionType::NotApplicable && lastKernelExecutionType != dispatchFlags.kernelExecutionType) {
setMediaVFEStateDirty(true);
}
2020-11-17 11:42:29 +01:00
}
2018-08-07 09:07:50 +02:00
auto &commandStreamCSR = this->getCS(getRequiredCmdStreamSizeAligned(dispatchFlags, device));
2018-05-15 09:46:22 +02:00
auto commandStreamStartCSR = commandStreamCSR.getUsed();
2021-06-23 10:34:31 +00:00
TimestampPacketHelper::programCsrDependenciesForTimestampPacketContainer<GfxFamily>(commandStreamCSR, dispatchFlags.csrDependencies);
2021-06-14 15:33:53 +00:00
TimestampPacketHelper::programCsrDependenciesForForTaskCountContainer<GfxFamily>(commandStreamCSR, dispatchFlags.csrDependencies);
2019-01-25 10:20:32 +01:00
2021-11-17 19:51:43 +00:00
programActivePartitionConfigFlushTask(commandStreamCSR);
2019-10-11 12:54:10 +08:00
programEngineModeCommands(commandStreamCSR, dispatchFlags);
2022-02-02 16:30:03 +00:00
2021-09-29 15:59:41 +00:00
if (pageTableManager.get() && !pageTableManagerInitialized) {
pageTableManagerInitialized = pageTableManager->initPageTableManagerRegisters(this);
2019-11-06 18:14:30 +01:00
}
2020-05-27 15:30:31 +02:00
2020-05-22 18:11:28 +02:00
programHardwareContext(commandStreamCSR);
2021-12-20 14:37:33 +00:00
programComputeMode(commandStreamCSR, dispatchFlags, hwInfo);
2019-09-10 16:13:11 +02:00
programPipelineSelect(commandStreamCSR, dispatchFlags.pipelineSelectArgs);
2021-11-04 12:54:18 +00:00
programL3(commandStreamCSR, newL3Config);
programPreamble(commandStreamCSR, device, newL3Config);
2018-05-15 09:46:22 +02:00
programMediaSampler(commandStreamCSR, dispatchFlags);
2021-09-30 11:10:58 +00:00
addPipeControlBefore3dState(commandStreamCSR, dispatchFlags);
2020-11-26 19:02:18 +00:00
programPerDssBackedBuffer(commandStreamCSR, device, dispatchFlags);
2018-05-15 09:46:22 +02:00
2019-09-13 12:00:30 +02:00
stateBaseAddressDirty |= ((GSBAFor32BitProgrammed ^ dispatchFlags.gsba32BitRequired) && force32BitAllocations);
2017-12-21 00:45:38 +01:00
2019-05-29 15:37:54 +02:00
programVFEState(commandStreamCSR, dispatchFlags, device.getDeviceInfo().maxFrontEndThreads);
2017-12-21 00:45:38 +01:00
2019-10-07 10:54:39 -07:00
programPreemption(commandStreamCSR, dispatchFlags);
2022-08-03 11:54:08 +00:00
EncodeKernelArgsBuffer<GfxFamily>::encodeKernelArgsBufferCmds(kernelArgsBufferAllocation, logicalStateHelper.get());
2022-02-02 16:30:03 +00:00
if (stallingCommandsOnNextFlushRequired) {
programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags);
}
2022-03-28 12:55:12 +00:00
const bool hasDsh = hwInfo.capabilityTable.supportsImages;
bool dshDirty = hasDsh ? dshState.updateAndCheck(dsh) : false;
bool iohDirty = iohState.updateAndCheck(ioh);
bool sshDirty = sshState.updateAndCheck(ssh);
2017-12-21 00:45:38 +01:00
2018-03-27 12:55:20 +02:00
auto isStateBaseAddressDirty = dshDirty || iohDirty || sshDirty || stateBaseAddressDirty;
2017-12-21 00:45:38 +01:00
2020-08-20 11:48:10 +02:00
auto mocsIndex = latestSentStatelessMocsConfig;
if (dispatchFlags.l3CacheSettings != L3CachingSettings::NotApplicable) {
auto l3On = dispatchFlags.l3CacheSettings != L3CachingSettings::l3CacheOff;
auto l1On = dispatchFlags.l3CacheSettings == L3CachingSettings::l3AndL1On;
mocsIndex = hwHelper.getMocsIndex(*device.getGmmHelper(), l3On, l1On);
}
2017-12-21 00:45:38 +01:00
2019-08-26 15:15:22 +02:00
if (mocsIndex != latestSentStatelessMocsConfig) {
2017-12-21 00:45:38 +01:00
isStateBaseAddressDirty = true;
2019-08-27 14:18:06 +02:00
latestSentStatelessMocsConfig = mocsIndex;
2017-12-21 00:45:38 +01:00
}
2022-05-18 18:10:53 +00:00
if (this->isGlobalAtomicsProgrammingRequired(dispatchFlags.useGlobalAtomics) && (this->isMultiOsContextCapable() || dispatchFlags.areMultipleSubDevicesInContext)) {
2021-03-03 12:25:26 +00:00
isStateBaseAddressDirty = true;
lastSentUseGlobalAtomics = dispatchFlags.useGlobalAtomics;
}
2022-04-21 17:57:54 +00:00
bool debuggingEnabled = device.getDebugger() != nullptr;
2020-06-22 17:13:30 +02:00
bool sourceLevelDebuggerActive = device.getSourceLevelDebugger() != nullptr ? true : false;
2021-01-19 14:19:33 +01:00
auto memoryCompressionState = lastMemoryCompressionState;
2020-12-17 00:36:45 +00:00
if (dispatchFlags.memoryCompressionState != MemoryCompressionState::NotApplicable) {
2021-01-19 14:19:33 +01:00
memoryCompressionState = dispatchFlags.memoryCompressionState;
}
if (memoryCompressionState != lastMemoryCompressionState) {
isStateBaseAddressDirty = true;
lastMemoryCompressionState = memoryCompressionState;
2020-12-17 00:36:45 +00:00
}
2022-06-28 18:52:33 +00:00
// Reprogram state base address if required
2020-06-22 17:13:30 +02:00
if (isStateBaseAddressDirty || sourceLevelDebuggerActive) {
2022-03-18 11:06:51 +00:00
EncodeWA<GfxFamily>::addPipeControlBeforeStateBaseAddress(commandStreamCSR, hwInfo, isRcs());
2022-03-09 17:15:48 +00:00
EncodeWA<GfxFamily>::encodeAdditionalPipelineSelect(commandStreamCSR, dispatchFlags.pipelineSelectArgs, true, hwInfo, isRcs());
2017-12-21 00:45:38 +01:00
uint64_t newGSHbase = 0;
GSBAFor32BitProgrammed = false;
2018-11-22 15:16:20 +01:00
if (is64bit && scratchSpaceController->getScratchSpaceAllocation() && !force32BitAllocations) {
newGSHbase = scratchSpaceController->calculateNewGSH();
2019-09-13 12:00:30 +02:00
} else if (is64bit && force32BitAllocations && dispatchFlags.gsba32BitRequired) {
2020-07-01 14:03:46 +02:00
bool useLocalMemory = scratchSpaceController->getScratchSpaceAllocation() ? scratchSpaceController->getScratchSpaceAllocation()->isAllocatedInLocalMemoryPool() : false;
newGSHbase = getMemoryManager()->getExternalHeapBaseAddress(rootDeviceIndex, useLocalMemory);
2017-12-21 00:45:38 +01:00
GSBAFor32BitProgrammed = true;
}
2018-03-14 11:07:51 +01:00
auto stateBaseAddressCmdOffset = commandStreamCSR.getUsed();
2022-08-11 20:21:54 +00:00
auto stateBaseAddressCmdBuffer = StateBaseAddressHelper<GfxFamily>::getSpaceForSbaCmd(commandStreamCSR);
2021-05-24 18:57:32 +00:00
auto instructionHeapBaseAddress = getMemoryManager()->getInternalHeapBaseAddress(rootDeviceIndex, getMemoryManager()->isLocalMemoryUsedForIsa(rootDeviceIndex));
2022-08-04 23:45:59 +00:00
uint64_t indirectObjectStateBaseAddress = getMemoryManager()->getInternalHeapBaseAddress(rootDeviceIndex, ioh->getGraphicsAllocation()->isAllocatedInLocalMemoryPool());
STATE_BASE_ADDRESS stateBaseAddressCmd;
2022-08-11 13:36:02 +00:00
StateBaseAddressHelperArgs<GfxFamily> args = {
2022-08-17 22:33:49 +00:00
newGSHbase, // generalStateBase
indirectObjectStateBaseAddress, // indirectObjectHeapBaseAddress
instructionHeapBaseAddress, // instructionHeapBaseAddress
0, // globalHeapsBaseAddress
0, // surfaceStateBaseAddress
&stateBaseAddressCmd, // stateBaseAddressCmd
dsh, // dsh
ioh, // ioh
ssh, // ssh
device.getGmmHelper(), // gmmHelper
mocsIndex, // statelessMocsIndex
memoryCompressionState, // memoryCompressionState
true, // setInstructionStateBaseAddress
true, // setGeneralStateBaseAddress
false, // useGlobalHeapsBaseAddress
isMultiOsContextCapable(), // isMultiOsContextCapable
dispatchFlags.useGlobalAtomics, // useGlobalAtomics
dispatchFlags.areMultipleSubDevicesInContext, // areMultipleSubDevicesInContext
2022-08-23 11:48:18 +00:00
false, // overrideSurfaceStateBaseAddress
debuggingEnabled || device.isDebuggerActive() // isDebuggerActive
2022-08-11 13:36:02 +00:00
};
StateBaseAddressHelper<GfxFamily>::programStateBaseAddress(args);
2022-06-28 18:52:33 +00:00
2022-08-04 23:45:59 +00:00
if (stateBaseAddressCmdBuffer) {
*stateBaseAddressCmdBuffer = stateBaseAddressCmd;
2022-06-28 18:52:33 +00:00
}
2018-03-14 11:07:51 +01:00
2022-08-04 23:45:59 +00:00
programAdditionalStateBaseAddress(commandStreamCSR, stateBaseAddressCmd, device);
2021-06-23 13:34:56 +00:00
2022-04-21 17:57:54 +00:00
if (debuggingEnabled && !device.getDebugger()->isLegacy()) {
NEO::Debugger::SbaAddresses sbaAddresses = {};
2022-08-04 23:45:59 +00:00
NEO::EncodeStateBaseAddress<GfxFamily>::setSbaAddressesForDebugger(sbaAddresses, stateBaseAddressCmd);
2022-04-21 17:57:54 +00:00
device.getDebugger()->captureStateBaseAddress(commandStreamCSR, sbaAddresses);
}
2018-08-29 13:39:27 +02:00
if (sshDirty) {
2019-04-26 17:04:03 +02:00
bindingTableBaseAddressRequired = true;
}
if (bindingTableBaseAddressRequired) {
2022-03-28 12:55:12 +00:00
StateBaseAddressHelper<GfxFamily>::programBindingTableBaseAddress(commandStreamCSR, *ssh, device.getGmmHelper());
2019-04-26 17:04:03 +02:00
bindingTableBaseAddressRequired = false;
2018-08-29 13:39:27 +02:00
}
2022-03-09 17:15:48 +00:00
EncodeWA<GfxFamily>::encodeAdditionalPipelineSelect(commandStreamCSR, dispatchFlags.pipelineSelectArgs, false, hwInfo, isRcs());
2018-03-14 11:07:51 +01:00
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
2018-04-04 11:34:46 +02:00
collectStateBaseAddresPatchInfo(commandStream.getGraphicsAllocation()->getGpuAddress(), stateBaseAddressCmdOffset, dsh, ioh, ssh, newGSHbase);
2018-03-14 11:07:51 +01:00
}
2017-12-21 00:45:38 +01:00
}
2022-04-21 17:57:54 +00:00
addPipeControlBeforeStateSip(commandStreamCSR, device);
programStateSip(commandStreamCSR, device);
2017-12-21 00:45:38 +01:00
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "this->taskLevel", (uint32_t)this->taskLevel);
2021-11-25 09:31:14 +00:00
if (executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->workaroundTable.flags.waSamplerCacheFlushBetweenRedescribedSurfaceReads) {
2018-01-10 14:05:34 +01:00
if (this->samplerCacheFlushRequired != SamplerCacheFlushState::samplerCacheFlushNotRequired) {
2020-04-26 21:48:59 +02:00
PipeControlArgs args;
args.textureCacheInvalidationEnable = true;
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands<GfxFamily>::addSingleBarrier(commandStreamCSR, args);
2018-01-10 14:05:34 +01:00
if (this->samplerCacheFlushRequired == SamplerCacheFlushState::samplerCacheFlushBefore) {
this->samplerCacheFlushRequired = SamplerCacheFlushState::samplerCacheFlushAfter;
} else {
this->samplerCacheFlushRequired = SamplerCacheFlushState::samplerCacheFlushNotRequired;
}
}
}
2018-07-05 11:23:28 +02:00
if (experimentalCmdBuffer.get() != nullptr) {
size_t startingOffset = experimentalCmdBuffer->programExperimentalCommandBuffer<GfxFamily>();
experimentalCmdBuffer->injectBufferStart<GfxFamily>(commandStreamCSR, startingOffset);
}
2019-08-27 19:14:24 +02:00
if (requiresInstructionCacheFlush) {
2020-04-26 21:48:59 +02:00
PipeControlArgs args;
args.instructionCacheInvalidateEnable = true;
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands<GfxFamily>::addSingleBarrier(commandStreamCSR, args);
2019-08-27 19:14:24 +02:00
requiresInstructionCacheFlush = false;
}
2020-11-04 13:02:31 +00:00
// Add a Pipe Control if we have a dependency on a previous walker to avoid concurrency issues.
2017-12-21 00:45:38 +01:00
if (taskLevel > this->taskLevel) {
2021-12-09 16:18:18 +00:00
auto programPipeControl = !timestampPacketWriteEnabled;
if (DebugManager.flags.ResolveDependenciesViaPipeControls.get() == 1) {
programPipeControl = true;
}
if (programPipeControl) {
2020-04-26 21:48:59 +02:00
PipeControlArgs args;
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands<GfxFamily>::addSingleBarrier(commandStreamCSR, args);
2018-08-30 11:05:18 +02:00
}
2017-12-21 00:45:38 +01:00
this->taskLevel = taskLevel;
2020-07-17 22:03:16 +05:30
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "this->taskCount", peekTaskCount());
2017-12-21 00:45:38 +01:00
}
2020-07-06 09:34:15 +02:00
if (DebugManager.flags.ForcePipeControlPriorToWalker.get()) {
forcePipeControl(commandStreamCSR);
}
2022-03-28 12:55:12 +00:00
if (hasDsh) {
auto dshAllocation = dsh->getGraphicsAllocation();
this->makeResident(*dshAllocation);
dshAllocation->setEvictable(false);
}
auto iohAllocation = ioh->getGraphicsAllocation();
auto sshAllocation = ssh->getGraphicsAllocation();
2020-07-06 09:34:15 +02:00
2017-12-21 00:45:38 +01:00
this->makeResident(*iohAllocation);
this->makeResident(*sshAllocation);
2018-04-12 10:05:35 +02:00
iohAllocation->setEvictable(false);
2017-12-21 00:45:38 +01:00
this->makeResident(*tagAllocation);
2020-02-05 20:00:08 +01:00
if (globalFenceAllocation) {
makeResident(*globalFenceAllocation);
}
if (preemptionAllocation) {
2019-06-27 21:33:05 +02:00
makeResident(*preemptionAllocation);
2020-02-05 20:00:08 +01:00
}
2017-12-21 00:45:38 +01:00
2022-04-21 17:57:54 +00:00
if (dispatchFlags.preemptionMode == PreemptionMode::MidThread || debuggingEnabled) {
2021-04-16 12:52:30 +00:00
makeResident(*SipKernel::getSipKernel(device).getSipAllocation());
2022-04-21 17:57:54 +00:00
}
2022-09-06 17:30:55 +00:00
if (debuggingEnabled && debugSurface) {
2022-04-21 17:57:54 +00:00
makeResident(*debugSurface);
2018-03-12 17:18:00 +01:00
}
2018-07-05 11:23:28 +02:00
if (experimentalCmdBuffer.get() != nullptr) {
experimentalCmdBuffer->makeResidentAllocations();
}
2021-03-04 12:37:56 +00:00
if (workPartitionAllocation) {
makeResident(*workPartitionAllocation);
}
2022-08-03 11:54:08 +00:00
if (kernelArgsBufferAllocation) {
makeResident(*kernelArgsBufferAllocation);
}
2022-06-15 10:29:35 +00:00
if (logicalStateHelper) {
2022-07-04 14:16:44 +00:00
logicalStateHelper->writeStreamInline(commandStreamCSR, false);
2022-06-15 10:29:35 +00:00
}
2017-12-21 00:45:38 +01:00
// If the CSR has work in its CS, flush it before the task
bool submitTask = commandStreamStartTask != commandStreamTask.getUsed();
2019-04-01 17:26:32 +02:00
bool submitCSR = (commandStreamStartCSR != commandStreamCSR.getUsed()) || this->isMultiOsContextCapable();
2017-12-21 00:45:38 +01:00
bool submitCommandStreamFromCsr = false;
void *bbEndLocation = nullptr;
auto bbEndPaddingSize = this->dispatchMode == DispatchMode::ImmediateDispatch ? 0 : sizeof(MI_BATCH_BUFFER_START) - sizeof(MI_BATCH_BUFFER_END);
2018-02-28 22:50:41 +01:00
size_t chainedBatchBufferStartOffset = 0;
GraphicsAllocation *chainedBatchBuffer = nullptr;
2020-01-15 17:02:47 +01:00
bool directSubmissionEnabled = isDirectSubmissionEnabled();
2017-12-21 00:45:38 +01:00
if (submitTask) {
2021-01-28 17:30:56 +00:00
programEndingCmd(commandStreamTask, device, &bbEndLocation, directSubmissionEnabled);
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::emitNoop(commandStreamTask, bbEndPaddingSize);
EncodeNoop<GfxFamily>::alignToCacheLine(commandStreamTask);
2017-12-21 00:45:38 +01:00
if (submitCSR) {
2018-02-28 22:50:41 +01:00
chainedBatchBufferStartOffset = commandStreamCSR.getUsed();
chainedBatchBuffer = commandStreamTask.getGraphicsAllocation();
2017-12-21 00:45:38 +01:00
// Add MI_BATCH_BUFFER_START to chain from CSR -> Task
auto pBBS = reinterpret_cast<MI_BATCH_BUFFER_START *>(commandStreamCSR.getSpace(sizeof(MI_BATCH_BUFFER_START)));
2018-07-05 11:23:28 +02:00
addBatchBufferStart(pBBS, ptrOffset(commandStreamTask.getGraphicsAllocation()->getGpuAddress(), commandStreamStartTask), false);
2018-04-04 11:34:46 +02:00
if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) {
flatBatchBufferHelper->registerCommandChunk(commandStreamTask.getGraphicsAllocation()->getGpuAddress(),
reinterpret_cast<uint64_t>(commandStreamTask.getCpuBase()),
commandStreamStartTask,
static_cast<uint64_t>(ptrDiff(bbEndLocation,
commandStreamTask.getGraphicsAllocation()->getGpuAddress())) +
sizeof(MI_BATCH_BUFFER_START));
}
2017-12-21 00:45:38 +01:00
auto commandStreamAllocation = commandStreamTask.getGraphicsAllocation();
DEBUG_BREAK_IF(commandStreamAllocation == nullptr);
this->makeResident(*commandStreamAllocation);
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::alignToCacheLine(commandStreamCSR);
2017-12-21 00:45:38 +01:00
submitCommandStreamFromCsr = true;
2019-08-07 19:33:40 +02:00
} else if (dispatchFlags.epilogueRequired) {
this->makeResident(*commandStreamCSR.getGraphicsAllocation());
2017-12-21 00:45:38 +01:00
}
2021-01-28 17:30:56 +00:00
this->programEpilogue(commandStreamCSR, device, &bbEndLocation, dispatchFlags);
2019-08-07 19:33:40 +02:00
2017-12-21 00:45:38 +01:00
} else if (submitCSR) {
2021-01-28 17:30:56 +00:00
programEndingCmd(commandStreamCSR, device, &bbEndLocation, directSubmissionEnabled);
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::emitNoop(commandStreamCSR, bbEndPaddingSize);
EncodeNoop<GfxFamily>::alignToCacheLine(commandStreamCSR);
2017-12-21 00:45:38 +01:00
DEBUG_BREAK_IF(commandStreamCSR.getUsed() > commandStreamCSR.getMaxAvailableSpace());
submitCommandStreamFromCsr = true;
}
size_t startOffset = submitCommandStreamFromCsr ? commandStreamStartCSR : commandStreamStartTask;
auto &streamToSubmit = submitCommandStreamFromCsr ? commandStreamCSR : commandStreamTask;
2020-01-15 17:02:47 +01:00
BatchBuffer batchBuffer{streamToSubmit.getGraphicsAllocation(), startOffset, chainedBatchBufferStartOffset, chainedBatchBuffer,
dispatchFlags.requiresCoherency, dispatchFlags.lowPriority, dispatchFlags.throttle, dispatchFlags.sliceCount,
2020-11-18 13:56:18 +00:00
streamToSubmit.getUsed(), &streamToSubmit, bbEndLocation, dispatchFlags.useSingleSubdevice};
2021-06-22 10:09:40 +00:00
streamToSubmit.getGraphicsAllocation()->updateTaskCount(this->taskCount + 1, this->osContext->getContextId());
streamToSubmit.getGraphicsAllocation()->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
2017-12-21 00:45:38 +01:00
2022-08-17 22:33:49 +00:00
if (submitCSR || submitTask) {
2017-12-21 00:45:38 +01:00
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
2021-07-28 12:35:06 +00:00
flushHandler(batchBuffer, this->getResidencyAllocations());
2022-03-25 13:00:53 +00:00
if (dispatchFlags.blocking || dispatchFlags.dcFlush || dispatchFlags.guardCommandBufferWithPipeControl) {
2021-02-23 08:48:08 +00:00
this->latestFlushedTaskCount = this->taskCount + 1;
}
2017-12-21 00:45:38 +01:00
} else {
2018-08-16 11:18:05 +02:00
auto commandBuffer = new CommandBuffer(device);
2017-12-21 00:45:38 +01:00
commandBuffer->batchBuffer = batchBuffer;
2018-09-12 09:47:01 +02:00
commandBuffer->surfaces.swap(this->getResidencyAllocations());
2017-12-21 00:45:38 +01:00
commandBuffer->batchBufferEndLocation = bbEndLocation;
commandBuffer->taskCount = this->taskCount + 1;
commandBuffer->flushStamp->replaceStampObject(dispatchFlags.flushStampReference);
2018-02-15 08:29:57 +01:00
commandBuffer->pipeControlThatMayBeErasedLocation = currentPipeControlForNooping;
commandBuffer->epiloguePipeControlLocation = epiloguePipeControlLocation;
2022-07-01 08:15:04 +00:00
commandBuffer->epiloguePipeControlArgs = args;
2017-12-21 00:45:38 +01:00
this->submissionAggregator->recordCommandBuffer(commandBuffer);
}
} else {
2022-05-27 03:58:07 +00:00
this->makeSurfacePackNonResident(this->getResidencyAllocations(), true);
2017-12-21 00:45:38 +01:00
}
2020-11-18 13:56:18 +00:00
this->wasSubmittedToSingleSubdevice = dispatchFlags.useSingleSubdevice;
2022-06-28 18:52:33 +00:00
// check if we are not over the budget, if we are do implicit flush
2017-12-21 00:45:38 +01:00
if (getMemoryManager()->isMemoryBudgetExhausted()) {
2018-08-01 10:01:41 +02:00
if (this->totalMemoryUsed >= device.getDeviceInfo().globalMemSize / 4) {
2020-09-17 08:58:06 +02:00
implicitFlush = true;
}
}
if (DebugManager.flags.PerformImplicitFlushEveryEnqueueCount.get() != -1) {
if ((taskCount + 1) % DebugManager.flags.PerformImplicitFlushEveryEnqueueCount.get() == 0) {
implicitFlush = true;
2017-12-21 00:45:38 +01:00
}
}
2020-09-22 16:29:34 +02:00
if (this->newResources) {
implicitFlush = true;
this->newResources = false;
}
implicitFlush |= checkImplicitFlushForGpuIdle();
2020-09-17 08:58:06 +02:00
if (this->dispatchMode == DispatchMode::BatchedDispatch && implicitFlush) {
2017-12-21 00:45:38 +01:00
this->flushBatchedSubmissions();
}
++taskCount;
2020-07-17 22:03:16 +05:30
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "taskCount", peekTaskCount());
2017-12-21 00:45:38 +01:00
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "Current taskCount:", tagAddress ? *tagAddress : 0);
CompletionStamp completionStamp = {
taskCount,
this->taskLevel,
2018-11-26 14:04:52 +01:00
flushStamp->peekStamp()};
2017-12-21 00:45:38 +01:00
this->taskLevel += levelClosed ? 1 : 0;
2018-02-08 16:00:20 +01:00
2017-12-21 00:45:38 +01:00
return completionStamp;
}
2020-07-06 09:34:15 +02:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::forcePipeControl(NEO::LinearStream &commandStreamCSR) {
PipeControlArgs args;
2022-07-21 14:28:10 +00:00
args.csStallOnly = true;
MemorySynchronizationCommands<GfxFamily>::addSingleBarrier(commandStreamCSR, args);
args.csStallOnly = false;
MemorySynchronizationCommands<GfxFamily>::addSingleBarrier(commandStreamCSR, args);
2020-07-06 09:34:15 +02:00
}
2022-03-08 14:18:31 +00:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::programComputeMode(LinearStream &stream, DispatchFlags &dispatchFlags, const HardwareInfo &hwInfo) {
if (this->streamProperties.stateComputeMode.isDirty()) {
EncodeComputeMode<GfxFamily>::programComputeModeCommandWithSynchronization(
stream, this->streamProperties.stateComputeMode, dispatchFlags.pipelineSelectArgs,
2022-06-23 15:25:10 +00:00
hasSharedHandles(), hwInfo, isRcs(), logicalStateHelper.get());
2022-03-08 14:18:31 +00:00
}
}
2019-10-03 14:38:49 +02:00
template <typename GfxFamily>
2021-11-06 01:42:54 +00:00
inline void CommandStreamReceiverHw<GfxFamily>::programStallingCommandsForBarrier(LinearStream &cmdStream, DispatchFlags &dispatchFlags) {
stallingCommandsOnNextFlushRequired = false;
2019-10-03 14:38:49 +02:00
auto barrierTimestampPacketNodes = dispatchFlags.barrierTimestampPacketNodes;
if (barrierTimestampPacketNodes && barrierTimestampPacketNodes->peekNodes().size() != 0) {
2021-12-09 19:31:27 +00:00
programStallingPostSyncCommandsForBarrier(cmdStream, *barrierTimestampPacketNodes->peekNodes()[0]);
barrierTimestampPacketNodes->makeResident(*this);
2019-10-03 14:38:49 +02:00
} else {
2021-11-06 01:42:54 +00:00
programStallingNoPostSyncCommandsForBarrier(cmdStream);
2019-10-03 14:38:49 +02:00
}
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
2019-11-24 14:50:41 +01:00
inline bool CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
2018-04-04 11:34:46 +02:00
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
2019-11-24 14:50:41 +01:00
return true;
2017-12-21 00:45:38 +01:00
}
typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
2018-02-13 10:01:20 +01:00
typedef typename GfxFamily::PIPE_CONTROL PIPE_CONTROL;
2018-08-06 14:55:04 +02:00
std::unique_lock<MutexType> lockGuard(ownershipMutex);
2019-11-24 14:50:41 +01:00
bool submitResult = true;
2017-12-21 00:45:38 +01:00
auto &commandBufferList = this->submissionAggregator->peekCmdBufferList();
if (!commandBufferList.peekIsEmpty()) {
2018-12-04 15:11:29 +01:00
const auto totalMemoryBudget = static_cast<size_t>(commandBufferList.peekHead()->device.getDeviceInfo().globalMemSize / 2);
2018-08-16 11:18:05 +02:00
2017-12-21 00:45:38 +01:00
ResidencyContainer surfacesForSubmit;
ResourcePackage resourcePackage;
2021-12-20 14:37:33 +00:00
const auto &hwInfo = peekHwInfo();
2018-02-15 08:29:57 +01:00
void *currentPipeControlForNooping = nullptr;
void *epiloguePipeControlLocation = nullptr;
2017-12-21 00:45:38 +01:00
while (!commandBufferList.peekIsEmpty()) {
size_t totalUsedSize = 0u;
2018-12-04 15:11:29 +01:00
this->submissionAggregator->aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget, osContext->getContextId());
2017-12-21 00:45:38 +01:00
auto primaryCmdBuffer = commandBufferList.removeFrontOne();
auto nextCommandBuffer = commandBufferList.peekHead();
auto currentBBendLocation = primaryCmdBuffer->batchBufferEndLocation;
auto lastTaskCount = primaryCmdBuffer->taskCount;
2022-07-01 08:15:04 +00:00
auto lastPipeControlArgs = primaryCmdBuffer->epiloguePipeControlArgs;
2017-12-21 00:45:38 +01:00
2022-08-19 15:56:22 +00:00
auto pipeControlLocationSize = MemorySynchronizationCommands<GfxFamily>::getSizeForBarrierWithPostSyncOperation(hwInfo, lastPipeControlArgs.tlbInvalidation);
2017-12-21 00:45:38 +01:00
FlushStampUpdateHelper flushStampUpdateHelper;
flushStampUpdateHelper.insert(primaryCmdBuffer->flushStamp->getStampReference());
2018-02-15 08:29:57 +01:00
currentPipeControlForNooping = primaryCmdBuffer->pipeControlThatMayBeErasedLocation;
epiloguePipeControlLocation = primaryCmdBuffer->epiloguePipeControlLocation;
2017-12-21 00:45:38 +01:00
2018-04-04 11:34:46 +02:00
if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) {
2022-05-09 16:21:21 +00:00
flatBatchBufferHelper->registerCommandChunk(primaryCmdBuffer->batchBuffer, sizeof(MI_BATCH_BUFFER_START));
2018-04-04 11:34:46 +02:00
}
2021-07-13 11:56:41 +00:00
2017-12-21 00:45:38 +01:00
while (nextCommandBuffer && nextCommandBuffer->inspectionId == primaryCmdBuffer->inspectionId) {
2021-07-13 11:56:41 +00:00
2022-06-28 18:52:33 +00:00
// noop pipe control
2018-02-15 08:29:57 +01:00
if (currentPipeControlForNooping) {
2018-04-04 11:34:46 +02:00
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
2021-12-20 14:37:33 +00:00
flatBatchBufferHelper->removePipeControlData(pipeControlLocationSize, currentPipeControlForNooping, hwInfo);
2018-04-04 11:34:46 +02:00
}
2018-02-15 08:29:57 +01:00
memset(currentPipeControlForNooping, 0, pipeControlLocationSize);
2017-12-21 00:45:38 +01:00
}
2022-06-28 18:52:33 +00:00
// obtain next candidate for nooping
2018-02-15 08:29:57 +01:00
currentPipeControlForNooping = nextCommandBuffer->pipeControlThatMayBeErasedLocation;
2022-06-28 18:52:33 +00:00
// track epilogue pipe control
2018-02-15 08:29:57 +01:00
epiloguePipeControlLocation = nextCommandBuffer->epiloguePipeControlLocation;
2017-12-21 00:45:38 +01:00
flushStampUpdateHelper.insert(nextCommandBuffer->flushStamp->getStampReference());
2018-08-24 15:23:45 +02:00
auto nextCommandBufferAddress = nextCommandBuffer->batchBuffer.commandBufferAllocation->getGpuAddress();
2017-12-21 00:45:38 +01:00
auto offsetedCommandBuffer = (uint64_t)ptrOffset(nextCommandBufferAddress, nextCommandBuffer->batchBuffer.startOffset);
2021-07-13 11:56:41 +00:00
auto cpuAddressForCommandBufferDestination = ptrOffset(nextCommandBuffer->batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), nextCommandBuffer->batchBuffer.startOffset);
auto cpuAddressForCurrentCommandBufferEndingSection = alignUp(ptrOffset(currentBBendLocation, sizeof(MI_BATCH_BUFFER_START)), MemoryConstants::cacheLineSize);
2022-06-28 18:52:33 +00:00
// if we point to exact same command buffer, then batch buffer start is not needed at all
2021-07-13 11:56:41 +00:00
if (cpuAddressForCurrentCommandBufferEndingSection == cpuAddressForCommandBufferDestination) {
memset(currentBBendLocation, 0u, ptrDiff(cpuAddressForCurrentCommandBufferEndingSection, currentBBendLocation));
} else {
addBatchBufferStart((MI_BATCH_BUFFER_START *)currentBBendLocation, offsetedCommandBuffer, false);
}
2018-04-04 11:34:46 +02:00
if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) {
flatBatchBufferHelper->registerCommandChunk(nextCommandBuffer->batchBuffer, sizeof(MI_BATCH_BUFFER_START));
}
2017-12-21 00:45:38 +01:00
currentBBendLocation = nextCommandBuffer->batchBufferEndLocation;
lastTaskCount = nextCommandBuffer->taskCount;
2022-07-01 08:15:04 +00:00
lastPipeControlArgs = nextCommandBuffer->epiloguePipeControlArgs;
2017-12-21 00:45:38 +01:00
nextCommandBuffer = nextCommandBuffer->next;
2021-07-13 11:56:41 +00:00
2017-12-21 00:45:38 +01:00
commandBufferList.removeFrontOne();
}
surfacesForSubmit.reserve(resourcePackage.size() + 1);
for (auto &surface : resourcePackage) {
surfacesForSubmit.push_back(surface);
}
2022-06-28 18:52:33 +00:00
// make sure we flush DC if needed
2022-03-04 14:07:37 +00:00
if (epiloguePipeControlLocation && MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(true, hwInfo)) {
2022-07-01 08:15:04 +00:00
lastPipeControlArgs.dcFlushEnable = true;
2022-03-04 14:07:37 +00:00
if (DebugManager.flags.DisableDcFlushInEpilogue.get()) {
2022-07-01 08:15:04 +00:00
lastPipeControlArgs.dcFlushEnable = false;
2022-03-04 14:07:37 +00:00
}
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands<GfxFamily>::setBarrierWithPostSyncOperation(
2022-07-01 08:15:04 +00:00
epiloguePipeControlLocation,
2022-07-21 14:28:10 +00:00
PostSyncMode::ImmediateData,
2022-07-01 08:15:04 +00:00
getTagAllocation()->getGpuAddress(),
lastTaskCount,
hwInfo,
lastPipeControlArgs);
2018-03-09 14:48:42 +01:00
}
2019-11-24 14:50:41 +01:00
2020-09-22 14:19:07 +02:00
primaryCmdBuffer->batchBuffer.endCmdPtr = currentBBendLocation;
2022-01-07 14:53:31 +00:00
if (this->flush(primaryCmdBuffer->batchBuffer, surfacesForSubmit) != SubmissionStatus::SUCCESS) {
2019-11-24 14:50:41 +01:00
submitResult = false;
break;
}
2017-12-21 00:45:38 +01:00
2022-06-28 18:52:33 +00:00
// after flush task level is closed
2017-12-21 00:45:38 +01:00
this->taskLevel++;
2019-11-24 14:50:41 +01:00
flushStampUpdateHelper.updateAll(flushStamp->peekStamp());
2017-12-21 00:45:38 +01:00
2021-10-28 09:21:44 +00:00
if (!isUpdateTagFromWaitEnabled()) {
this->latestFlushedTaskCount = lastTaskCount;
}
2022-05-27 03:58:07 +00:00
this->makeSurfacePackNonResident(surfacesForSubmit, true);
2017-12-21 00:45:38 +01:00
resourcePackage.clear();
}
this->totalMemoryUsed = 0;
}
2019-11-24 14:50:41 +01:00
return submitResult;
2017-12-21 00:45:38 +01:00
}
2018-01-24 10:11:37 +01:00
template <typename GfxFamily>
2018-08-07 09:07:50 +02:00
size_t CommandStreamReceiverHw<GfxFamily>::getRequiredCmdStreamSizeAligned(const DispatchFlags &dispatchFlags, Device &device) {
size_t size = getRequiredCmdStreamSize(dispatchFlags, device);
2018-01-24 10:11:37 +01:00
return alignUp(size, MemoryConstants::cacheLineSize);
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
2018-08-07 09:07:50 +02:00
size_t CommandStreamReceiverHw<GfxFamily>::getRequiredCmdStreamSize(const DispatchFlags &dispatchFlags, Device &device) {
2018-08-16 11:18:05 +02:00
size_t size = getRequiredCmdSizeForPreamble(device);
2021-07-08 15:08:37 +00:00
size += getRequiredStateBaseAddressSize(device);
2022-04-21 17:57:54 +00:00
if (device.getDebugger()) {
size += device.getDebugger()->getSbaTrackingCommandsSize(NEO::Debugger::SbaAddresses::trackedAddressCount);
}
2022-04-20 14:12:20 +00:00
if (!this->isStateSipSent || device.getDebugger()) {
2021-10-17 12:21:29 +00:00
size += PreemptionHelper::getRequiredStateSipCmdSize<GfxFamily>(device, isRcs());
2018-11-05 11:52:19 +01:00
}
2022-08-19 15:56:22 +00:00
size += MemorySynchronizationCommands<GfxFamily>::getSizeForSingleBarrier(false);
2018-04-20 13:55:54 +02:00
size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_START);
2018-04-13 11:05:09 +02:00
size += getCmdSizeForL3Config();
2022-03-14 16:40:32 +00:00
if (this->streamProperties.stateComputeMode.isDirty()) {
2022-03-09 17:15:48 +00:00
size += getCmdSizeForComputeMode();
}
2019-09-10 16:13:11 +02:00
size += getCmdSizeForMediaSampler(dispatchFlags.pipelineSelectArgs.mediaSamplerRequired);
2018-04-13 11:05:09 +02:00
size += getCmdSizeForPipelineSelect();
size += getCmdSizeForPreemption(dispatchFlags);
2021-09-22 21:39:42 +00:00
if (dispatchFlags.usePerDssBackedBuffer && !isPerDssBackedBufferSent) {
size += getCmdSizeForPerDssBackedBuffer(device.getHardwareInfo());
}
2019-08-07 19:33:40 +02:00
size += getCmdSizeForEpilogue(dispatchFlags);
2020-05-27 15:30:31 +02:00
size += getCmdsSizeForHardwareContext();
2021-11-17 19:51:43 +00:00
if (csrSizeRequestFlags.activePartitionsChanged) {
size += getCmdSizeForActivePartitionConfig();
}
2017-12-21 00:45:38 +01:00
2021-11-25 09:31:14 +00:00
if (executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->workaroundTable.flags.waSamplerCacheFlushBetweenRedescribedSurfaceReads) {
2018-01-10 14:05:34 +01:00
if (this->samplerCacheFlushRequired != SamplerCacheFlushState::samplerCacheFlushNotRequired) {
size += sizeof(typename GfxFamily::PIPE_CONTROL);
}
}
2018-07-05 11:23:28 +02:00
if (experimentalCmdBuffer.get() != nullptr) {
size += experimentalCmdBuffer->getRequiredInjectionSize<GfxFamily>();
}
2019-01-25 10:20:32 +01:00
size += TimestampPacketHelper::getRequiredCmdStreamSize<GfxFamily>(dispatchFlags.csrDependencies);
2021-06-14 15:33:53 +00:00
size += TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer<GfxFamily>(dispatchFlags.csrDependencies);
2019-01-25 10:20:32 +01:00
2022-08-03 11:54:08 +00:00
size += EncodeKernelArgsBuffer<GfxFamily>::getKernelArgsBufferCmdsSize(kernelArgsBufferAllocation, logicalStateHelper.get());
2021-11-06 01:42:54 +00:00
if (stallingCommandsOnNextFlushRequired) {
size += getCmdSizeForStallingCommands(dispatchFlags);
2018-10-15 10:35:45 +02:00
}
2019-10-03 14:38:49 +02:00
2019-08-27 19:14:24 +02:00
if (requiresInstructionCacheFlush) {
2022-08-19 15:56:22 +00:00
size += MemorySynchronizationCommands<GfxFamily>::getSizeForSingleBarrier(false);
2019-08-27 19:14:24 +02:00
}
2020-07-06 09:34:15 +02:00
if (DebugManager.flags.ForcePipeControlPriorToWalker.get()) {
2022-08-19 15:56:22 +00:00
size += 2 * MemorySynchronizationCommands<GfxFamily>::getSizeForSingleBarrier(false);
2020-07-06 09:34:15 +02:00
}
2018-01-24 10:11:37 +01:00
return size;
2017-12-21 00:45:38 +01:00
}
2019-08-21 14:08:51 +02:00
template <typename GfxFamily>
inline size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForPipelineSelect() const {
2019-09-10 16:13:11 +02:00
size_t size = 0;
2020-03-19 15:15:51 +01:00
if ((csrSizeRequestFlags.mediaSamplerConfigChanged ||
2022-08-31 13:26:29 +00:00
csrSizeRequestFlags.systolicPipelineSelectMode ||
2020-03-19 15:15:51 +01:00
!isPreambleSent) &&
!isPipelineSelectAlreadyProgrammed()) {
2019-09-10 16:13:11 +02:00
size += PreambleHelper<GfxFamily>::getCmdSizeForPipelineSelect(peekHwInfo());
2019-08-21 14:08:51 +02:00
}
return size;
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
2022-03-23 14:36:07 +00:00
inline WaitStatus CommandStreamReceiverHw<GfxFamily>::waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, QueueThrottle throttle) {
const auto params = kmdNotifyHelper->obtainTimeoutParams(useQuickKmdSleep, *getTagAddress(), taskCountToWait, flushStampToWait, throttle, this->isKmdWaitModeActive(),
this->isAnyDirectSubmissionEnabled());
2018-03-21 10:00:49 +01:00
2022-03-23 14:36:07 +00:00
auto status = waitForCompletionWithTimeout(params, taskCountToWait);
2022-01-20 16:56:19 +00:00
if (status == WaitStatus::NotReady) {
2021-09-17 13:05:26 +00:00
waitForFlushStamp(flushStampToWait);
2022-06-28 18:52:33 +00:00
// now call blocking wait, this is to ensure that task count is reached
2022-03-23 14:36:07 +00:00
status = waitForCompletionWithTimeout(WaitParams{false, false, 0}, taskCountToWait);
2017-12-21 00:45:38 +01:00
}
2022-01-20 16:56:19 +00:00
// If GPU hang occured, then propagate it to the caller.
if (status == WaitStatus::GpuHang) {
return status;
}
2022-04-21 17:41:33 +00:00
for (uint32_t i = 0; i < this->activePartitions; i++) {
UNRECOVERABLE_IF(*(ptrOffset(getTagAddress(), (i * this->postSyncWriteOffset))) < taskCountToWait);
}
2018-03-22 09:41:17 +01:00
2018-04-10 10:26:59 +02:00
if (kmdNotifyHelper->quickKmdSleepForSporadicWaitsEnabled()) {
kmdNotifyHelper->updateLastWaitForCompletionTimestamp();
2018-03-22 09:41:17 +01:00
}
2022-01-20 16:56:19 +00:00
return WaitStatus::Ready;
2017-12-21 00:45:38 +01:00
}
template <typename GfxFamily>
2019-07-31 08:57:00 +02:00
inline void CommandStreamReceiverHw<GfxFamily>::programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags) {
PreemptionHelper::programCmdStream<GfxFamily>(csr, dispatchFlags.preemptionMode, this->lastPreemptionMode, preemptionAllocation);
2018-01-08 15:58:02 +01:00
this->lastPreemptionMode = dispatchFlags.preemptionMode;
2017-12-21 00:45:38 +01:00
}
2018-04-13 11:05:09 +02:00
template <typename GfxFamily>
inline size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForPreemption(const DispatchFlags &dispatchFlags) const {
return PreemptionHelper::getRequiredCmdStreamSize<GfxFamily>(dispatchFlags.preemptionMode, this->lastPreemptionMode);
}
2018-11-05 11:52:19 +01:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::programStateSip(LinearStream &cmdStream, Device &device) {
2022-04-21 17:57:54 +00:00
bool debuggingEnabled = device.getDebugger() != nullptr;
if (!this->isStateSipSent || debuggingEnabled) {
2022-06-21 10:28:33 +00:00
PreemptionHelper::programStateSip<GfxFamily>(cmdStream, device, logicalStateHelper.get());
2018-11-05 11:52:19 +01:00
this->isStateSipSent = true;
}
}
2017-12-21 00:45:38 +01:00
template <typename GfxFamily>
2021-11-04 12:54:18 +00:00
inline void CommandStreamReceiverHw<GfxFamily>::programPreamble(LinearStream &csr, Device &device, uint32_t &newL3Config) {
2017-12-21 00:45:38 +01:00
if (!this->isPreambleSent) {
2022-06-22 12:10:21 +00:00
PreambleHelper<GfxFamily>::programPreamble(&csr, device, newL3Config, this->preemptionAllocation, logicalStateHelper.get());
2017-12-21 00:45:38 +01:00
this->isPreambleSent = true;
this->lastSentL3Config = newL3Config;
}
}
template <typename GfxFamily>
2019-05-29 15:37:54 +02:00
inline void CommandStreamReceiverHw<GfxFamily>::programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t maxFrontEndThreads) {
2017-12-21 00:45:38 +01:00
if (mediaVfeStateDirty) {
2020-09-02 11:38:54 +02:00
if (dispatchFlags.additionalKernelExecInfo != AdditionalKernelExecInfo::NotApplicable) {
lastAdditionalKernelExecInfo = dispatchFlags.additionalKernelExecInfo;
}
2020-11-17 11:42:29 +01:00
if (dispatchFlags.kernelExecutionType != KernelExecutionType::NotApplicable) {
lastKernelExecutionType = dispatchFlags.kernelExecutionType;
}
2021-03-31 14:11:31 +00:00
auto &hwInfo = peekHwInfo();
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
2021-09-06 10:34:34 +00:00
const auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily);
2021-08-16 18:24:13 +00:00
auto engineGroupType = hwHelper.getEngineGroupType(getOsContext().getEngineType(), getOsContext().getEngineUsage(), hwInfo);
2021-04-01 18:26:29 +00:00
auto pVfeState = PreambleHelper<GfxFamily>::getSpaceForVfeState(&csr, hwInfo, engineGroupType);
2021-09-06 10:34:34 +00:00
auto disableOverdispatch = hwInfoConfig.isDisableOverdispatchAvailable(hwInfo) &&
2021-07-29 18:21:14 +00:00
(dispatchFlags.additionalKernelExecInfo != AdditionalKernelExecInfo::NotSet);
2021-05-31 12:04:57 +00:00
streamProperties.frontEndState.setProperties(lastKernelExecutionType == KernelExecutionType::Concurrent,
2022-02-10 23:33:40 +00:00
dispatchFlags.disableEUFusion, disableOverdispatch, osContext->isEngineInstanced(), hwInfo);
2021-04-01 18:26:29 +00:00
PreambleHelper<GfxFamily>::programVfeState(
pVfeState, hwInfo, requiredScratchSize, getScratchPatchAddress(),
2022-06-24 16:50:31 +00:00
maxFrontEndThreads, streamProperties, logicalStateHelper.get());
2021-03-31 14:11:31 +00:00
auto commandOffset = PreambleHelper<GfxFamily>::getScratchSpaceAddressOffsetForVfeState(&csr, pVfeState);
2019-08-13 11:34:56 +02:00
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
flatBatchBufferHelper->collectScratchSpacePatchInfo(getScratchPatchAddress(), commandOffset, csr);
}
2018-12-13 11:06:28 +01:00
setMediaVFEStateDirty(false);
2017-12-21 00:45:38 +01:00
}
}
2018-01-19 13:29:25 +01:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::programMediaSampler(LinearStream &commandStream, DispatchFlags &dispatchFlags) {
}
template <typename GfxFamily>
size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForMediaSampler(bool mediaSamplerRequired) const {
return 0;
}
2018-03-22 19:02:58 +01:00
2018-03-14 11:07:51 +01:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::collectStateBaseAddresPatchInfo(
uint64_t baseAddress,
uint64_t commandOffset,
2022-03-28 12:55:12 +00:00
const LinearStream *dsh,
const LinearStream *ioh,
const LinearStream *ssh,
2018-04-04 11:34:46 +02:00
uint64_t generalStateBase) {
2018-03-14 11:07:51 +01:00
typedef typename GfxFamily::STATE_BASE_ADDRESS STATE_BASE_ADDRESS;
2022-03-28 12:55:12 +00:00
if constexpr (GfxFamily::supportsSampler) {
PatchInfoData dynamicStatePatchInfo = {dsh->getGraphicsAllocation()->getGpuAddress(), 0u, PatchInfoAllocationType::DynamicStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::DYNAMICSTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default};
flatBatchBufferHelper->setPatchInfoData(dynamicStatePatchInfo);
}
2018-03-14 11:07:51 +01:00
PatchInfoData generalStatePatchInfo = {generalStateBase, 0u, PatchInfoAllocationType::GeneralStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::GENERALSTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default};
2022-03-28 12:55:12 +00:00
PatchInfoData surfaceStatePatchInfo = {ssh->getGraphicsAllocation()->getGpuAddress(), 0u, PatchInfoAllocationType::SurfaceStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::SURFACESTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default};
2018-04-04 11:34:46 +02:00
flatBatchBufferHelper->setPatchInfoData(generalStatePatchInfo);
flatBatchBufferHelper->setPatchInfoData(surfaceStatePatchInfo);
2022-03-28 12:55:12 +00:00
collectStateBaseAddresIohPatchInfo(baseAddress, commandOffset, *ioh);
2018-03-14 11:07:51 +01:00
}
2018-04-10 10:26:59 +02:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::resetKmdNotifyHelper(KmdNotifyHelper *newHelper) {
kmdNotifyHelper.reset(newHelper);
kmdNotifyHelper->updateAcLineStatus();
if (kmdNotifyHelper->quickKmdSleepForSporadicWaitsEnabled()) {
kmdNotifyHelper->updateLastWaitForCompletionTimestamp();
}
}
2018-05-21 10:57:28 +02:00
template <typename GfxFamily>
2022-05-13 00:29:53 +00:00
void CommandStreamReceiverHw<GfxFamily>::setClearSlmWorkAroundParameter(PipeControlArgs &args) {
2018-05-21 10:57:28 +02:00
}
2018-09-07 14:31:37 +02:00
2018-11-22 15:16:20 +01:00
template <typename GfxFamily>
uint64_t CommandStreamReceiverHw<GfxFamily>::getScratchPatchAddress() {
return scratchSpaceController->getScratchPatchAddress();
2018-09-12 16:32:42 +02:00
}
2019-01-28 13:44:59 +01:00
template <typename GfxFamily>
bool CommandStreamReceiverHw<GfxFamily>::detectInitProgrammingFlagsRequired(const DispatchFlags &dispatchFlags) const {
return DebugManager.flags.ForceCsrReprogramming.get();
}
2019-03-20 17:08:05 +01:00
2022-03-25 13:00:53 +00:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::unregisterDirectSubmissionFromController() {
auto directSubmissionController = executionEnvironment.directSubmissionController.get();
if (directSubmissionController) {
directSubmissionController->unregisterDirectSubmission(this);
}
}
2019-04-03 15:59:31 +02:00
template <typename GfxFamily>
2022-05-05 16:52:25 +00:00
std::optional<uint32_t> CommandStreamReceiverHw<GfxFamily>::flushBcsTask(const BlitPropertiesContainer &blitPropertiesContainer, bool blocking, bool profilingEnabled, Device &device) {
2019-04-03 15:59:31 +02:00
using MI_BATCH_BUFFER_END = typename GfxFamily::MI_BATCH_BUFFER_END;
using MI_FLUSH_DW = typename GfxFamily::MI_FLUSH_DW;
2019-04-15 08:54:38 +02:00
auto lock = obtainUniqueOwnership();
2020-10-19 15:36:57 +02:00
bool blitterDirectSubmission = this->isBlitterDirectSubmissionEnabled();
2022-02-07 16:52:08 +00:00
auto debugPauseEnabled = PauseOnGpuProperties::featureEnabled(DebugManager.flags.PauseOnBlitCopy.get());
auto &commandStream = getCS(BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(blitPropertiesContainer, profilingEnabled, debugPauseEnabled, blitterDirectSubmission,
*this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]));
2019-04-15 08:54:38 +02:00
auto commandStreamStart = commandStream.getUsed();
auto newTaskCount = taskCount + 1;
2019-04-16 13:02:34 +02:00
latestSentTaskCount = newTaskCount;
2019-04-03 15:59:31 +02:00
2021-04-15 16:14:04 +00:00
getOsContext().ensureContextInitialized();
2022-04-19 14:44:06 +00:00
this->initDirectSubmission();
2021-04-15 16:14:04 +00:00
2021-12-21 18:13:53 +00:00
const auto &hwInfo = this->peekHwInfo();
2020-09-24 10:52:53 +02:00
if (PauseOnGpuProperties::pauseModeAllowed(DebugManager.flags.PauseOnBlitCopy.get(), taskCount, PauseOnGpuProperties::PauseMode::BeforeWorkload)) {
2021-12-21 18:13:53 +00:00
BlitCommandsHelper<GfxFamily>::dispatchDebugPauseCommands(commandStream, getDebugPauseStateGPUAddress(),
DebugPauseState::waitingForUserStartConfirmation,
DebugPauseState::hasUserStartConfirmation, hwInfo);
2020-06-17 14:58:28 +02:00
}
2020-02-07 15:36:15 +01:00
programEnginePrologue(commandStream);
2021-09-29 15:59:41 +00:00
if (pageTableManager.get() && !pageTableManagerInitialized) {
pageTableManagerInitialized = pageTableManager->initPageTableManagerRegisters(this);
}
2022-06-23 09:44:45 +00:00
if (logicalStateHelper) {
2022-07-04 14:16:44 +00:00
logicalStateHelper->writeStreamInline(commandStream, false);
2022-06-23 09:44:45 +00:00
}
2019-11-07 09:15:53 +01:00
for (auto &blitProperties : blitPropertiesContainer) {
2021-06-23 10:34:31 +00:00
TimestampPacketHelper::programCsrDependenciesForTimestampPacketContainer<GfxFamily>(commandStream, blitProperties.csrDependencies);
2021-06-14 15:33:53 +00:00
TimestampPacketHelper::programCsrDependenciesForForTaskCountContainer<GfxFamily>(commandStream, blitProperties.csrDependencies);
2019-05-20 12:00:02 +02:00
2022-07-01 11:10:43 +00:00
BlitCommandsHelper<GfxFamily>::encodeWa(commandStream, blitProperties, latestSentBcsWaValue);
2020-04-29 14:06:01 +02:00
if (blitProperties.outputTimestampPacket && profilingEnabled) {
2021-04-01 11:54:16 +00:00
BlitCommandsHelper<GfxFamily>::encodeProfilingStartMmios(commandStream, *blitProperties.outputTimestampPacket);
2020-04-29 14:06:01 +02:00
}
2020-08-25 15:24:09 +02:00
BlitCommandsHelper<GfxFamily>::dispatchBlitCommands(blitProperties, commandStream, *this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]);
2019-04-03 15:59:31 +02:00
2019-11-07 09:15:53 +01:00
if (blitProperties.outputTimestampPacket) {
2020-04-29 14:06:01 +02:00
if (profilingEnabled) {
2021-06-17 11:55:28 +00:00
MiFlushArgs args;
2021-12-21 18:13:53 +00:00
EncodeMiFlushDW<GfxFamily>::programMiFlushDw(commandStream, 0llu, newTaskCount, args, hwInfo);
2020-10-19 18:10:53 +02:00
2021-04-01 11:54:16 +00:00
BlitCommandsHelper<GfxFamily>::encodeProfilingEndMmios(commandStream, *blitProperties.outputTimestampPacket);
2020-04-29 14:06:01 +02:00
} else {
auto timestampPacketGpuAddress = TimestampPacketHelper::getContextEndGpuAddress(*blitProperties.outputTimestampPacket);
2021-06-17 11:55:28 +00:00
MiFlushArgs args;
args.commandWithPostSync = true;
2021-12-21 18:13:53 +00:00
EncodeMiFlushDW<GfxFamily>::programMiFlushDw(commandStream, timestampPacketGpuAddress, 0, args, hwInfo);
2020-04-29 14:06:01 +02:00
}
2019-11-12 17:56:10 +01:00
makeResident(*blitProperties.outputTimestampPacket->getBaseGraphicsAllocation());
2019-11-07 09:15:53 +01:00
}
2019-04-03 15:59:31 +02:00
2019-11-07 09:15:53 +01:00
blitProperties.csrDependencies.makeResident(*this);
2022-05-05 12:01:59 +00:00
blitProperties.srcAllocation->prepareHostPtrForResidency(this);
blitProperties.dstAllocation->prepareHostPtrForResidency(this);
2019-11-07 09:15:53 +01:00
makeResident(*blitProperties.srcAllocation);
makeResident(*blitProperties.dstAllocation);
2020-11-18 23:58:42 +00:00
if (blitProperties.clearColorAllocation) {
makeResident(*blitProperties.clearColorAllocation);
}
2019-06-13 11:45:27 +02:00
}
2020-10-16 15:58:47 +02:00
BlitCommandsHelper<GfxFamily>::programGlobalSequencerFlush(commandStream);
2021-10-28 09:21:44 +00:00
auto updateTag = !isUpdateTagFromWaitEnabled();
updateTag |= blocking;
if (updateTag) {
2022-03-30 14:11:26 +00:00
MemorySynchronizationCommands<GfxFamily>::addAdditionalSynchronization(commandStream, tagAllocation->getGpuAddress(), false, peekHwInfo());
2020-02-07 15:36:15 +01:00
2021-10-28 09:21:44 +00:00
MiFlushArgs args;
args.commandWithPostSync = true;
args.notifyEnable = isUsedNotifyEnableForPostSync();
2021-12-21 18:13:53 +00:00
EncodeMiFlushDW<GfxFamily>::programMiFlushDw(commandStream, tagAllocation->getGpuAddress(), newTaskCount, args, hwInfo);
2019-11-07 09:15:53 +01:00
2022-03-30 14:11:26 +00:00
MemorySynchronizationCommands<GfxFamily>::addAdditionalSynchronization(commandStream, tagAllocation->getGpuAddress(), false, peekHwInfo());
2021-10-28 09:21:44 +00:00
}
2020-02-11 18:25:21 +01:00
2020-09-24 10:52:53 +02:00
if (PauseOnGpuProperties::pauseModeAllowed(DebugManager.flags.PauseOnBlitCopy.get(), taskCount, PauseOnGpuProperties::PauseMode::AfterWorkload)) {
2021-12-21 18:13:53 +00:00
BlitCommandsHelper<GfxFamily>::dispatchDebugPauseCommands(commandStream, getDebugPauseStateGPUAddress(),
DebugPauseState::waitingForUserEndConfirmation,
DebugPauseState::hasUserEndConfirmation, hwInfo);
2020-06-17 14:58:28 +02:00
}
2020-10-19 15:36:57 +02:00
void *endingCmdPtr = nullptr;
2022-03-10 13:34:16 +00:00
programEndingCmd(commandStream, device, &endingCmdPtr, blitterDirectSubmission);
2019-04-03 15:59:31 +02:00
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::alignToCacheLine(commandStream);
2019-04-03 15:59:31 +02:00
2019-04-11 11:34:35 +02:00
makeResident(*tagAllocation);
2020-02-07 15:36:15 +01:00
if (globalFenceAllocation) {
makeResident(*globalFenceAllocation);
}
2019-04-11 11:34:35 +02:00
2019-08-21 03:50:47 -07:00
BatchBuffer batchBuffer{commandStream.getGraphicsAllocation(), commandStreamStart, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount,
2020-11-18 13:56:18 +00:00
commandStream.getUsed(), &commandStream, endingCmdPtr, false};
2019-04-15 08:54:38 +02:00
2021-06-30 16:06:28 +00:00
commandStream.getGraphicsAllocation()->updateTaskCount(newTaskCount, this->osContext->getContextId());
commandStream.getGraphicsAllocation()->updateResidencyTaskCount(newTaskCount, this->osContext->getContextId());
2019-11-24 14:50:41 +01:00
flush(batchBuffer, getResidencyAllocations());
2022-05-27 03:58:07 +00:00
makeSurfacePackNonResident(getResidencyAllocations(), true);
2019-04-15 08:54:38 +02:00
2021-11-03 12:05:33 +00:00
if (updateTag) {
2021-10-28 09:21:44 +00:00
latestFlushedTaskCount = newTaskCount;
}
2019-04-15 08:54:38 +02:00
taskCount = newTaskCount;
2019-04-25 09:59:08 +02:00
auto flushStampToWait = flushStamp->peekStamp();
2019-04-15 08:54:38 +02:00
lock.unlock();
2019-11-07 09:15:53 +01:00
if (blocking) {
2022-05-05 16:52:25 +00:00
const auto waitStatus = waitForTaskCountWithKmdNotifyFallback(newTaskCount, flushStampToWait, false, QueueThrottle::MEDIUM);
2019-06-04 13:37:22 +02:00
internalAllocationStorage->cleanAllocationList(newTaskCount, TEMPORARY_ALLOCATION);
2022-05-05 16:52:25 +00:00
if (waitStatus == WaitStatus::GpuHang) {
return std::nullopt;
}
2019-06-04 13:37:22 +02:00
}
2019-10-22 11:25:14 +02:00
return newTaskCount;
2019-04-03 15:59:31 +02:00
}
2021-02-23 08:48:08 +00:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::flushTagUpdate() {
2021-10-28 04:11:32 +02:00
if (this->osContext != nullptr) {
2021-10-28 09:21:44 +00:00
if (EngineHelpers::isBcs(this->osContext->getEngineType())) {
2021-10-28 04:11:32 +02:00
this->flushMiFlushDW();
} else {
this->flushPipeControl();
}
2021-02-23 08:48:08 +00:00
}
}
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::flushMiFlushDW() {
auto lock = obtainUniqueOwnership();
auto &commandStream = getCS(EncodeMiFlushDW<GfxFamily>::getMiFlushDwCmdSizeForDataWrite());
auto commandStreamStart = commandStream.getUsed();
2021-12-21 18:13:53 +00:00
const auto &hwInfo = this->peekHwInfo();
2021-06-17 11:55:28 +00:00
MiFlushArgs args;
args.commandWithPostSync = true;
args.notifyEnable = isUsedNotifyEnableForPostSync();
2021-12-21 18:13:53 +00:00
EncodeMiFlushDW<GfxFamily>::programMiFlushDw(commandStream, tagAllocation->getGpuAddress(), taskCount + 1, args, hwInfo);
2021-02-23 08:48:08 +00:00
makeResident(*tagAllocation);
2021-04-13 01:49:19 +05:30
this->flushSmallTask(commandStream, commandStreamStart);
2021-10-28 09:21:44 +00:00
this->latestFlushedTaskCount = taskCount.load();
2021-04-13 01:49:19 +05:30
}
2021-02-23 08:48:08 +00:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::flushPipeControl() {
auto lock = obtainUniqueOwnership();
2021-12-20 14:37:33 +00:00
const auto &hwInfo = peekHwInfo();
2021-02-23 08:48:08 +00:00
2021-12-20 21:37:45 +00:00
PipeControlArgs args;
2021-12-22 14:25:58 +00:00
args.dcFlushEnable = MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(true, hwInfo);
2021-06-17 11:55:28 +00:00
args.notifyEnable = isUsedNotifyEnableForPostSync();
2021-12-10 21:31:34 +00:00
args.workloadPartitionOffset = isMultiTileOperationEnabled();
2022-08-19 15:56:22 +00:00
auto &commandStream = getCS(MemorySynchronizationCommands<GfxFamily>::getSizeForBarrierWithPostSyncOperation(hwInfo, args.tlbInvalidation));
auto commandStreamStart = commandStream.getUsed();
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands<GfxFamily>::addBarrierWithPostSyncOperation(commandStream,
PostSyncMode::ImmediateData,
getTagAllocation()->getGpuAddress(),
taskCount + 1,
hwInfo,
args);
2021-02-23 08:48:08 +00:00
makeResident(*tagAllocation);
this->flushSmallTask(commandStream, commandStreamStart);
2021-10-28 09:21:44 +00:00
this->latestFlushedTaskCount = taskCount.load();
2021-02-23 08:48:08 +00:00
}
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::flushSmallTask(LinearStream &commandStreamTask, size_t commandStreamStartTask) {
2021-12-27 11:41:16 +00:00
using MI_BATCH_BUFFER_START = typename GfxFamily::MI_BATCH_BUFFER_START;
2021-02-23 08:48:08 +00:00
using MI_BATCH_BUFFER_END = typename GfxFamily::MI_BATCH_BUFFER_END;
void *endingCmdPtr = nullptr;
2021-11-16 13:26:36 +00:00
if (isAnyDirectSubmissionEnabled()) {
2021-02-23 08:48:08 +00:00
endingCmdPtr = commandStreamTask.getSpace(0);
EncodeBatchBufferStartOrEnd<GfxFamily>::programBatchBufferStart(&commandStreamTask,
0ull,
false);
} else {
2022-09-02 13:10:48 +00:00
auto batchBufferEnd = commandStreamTask.getSpaceForCmd<MI_BATCH_BUFFER_END>();
2021-02-23 08:48:08 +00:00
*batchBufferEnd = GfxFamily::cmdInitBatchBufferEnd;
}
2022-09-02 13:10:48 +00:00
auto bytesToPad = EncodeBatchBufferStartOrEnd<GfxFamily>::getBatchBufferStartSize() -
EncodeBatchBufferStartOrEnd<GfxFamily>::getBatchBufferEndSize();
2021-12-27 11:41:16 +00:00
EncodeNoop<GfxFamily>::emitNoop(commandStreamTask, bytesToPad);
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::alignToCacheLine(commandStreamTask);
2021-02-23 08:48:08 +00:00
2021-05-13 01:50:22 +05:30
if (globalFenceAllocation) {
makeResident(*globalFenceAllocation);
}
2021-02-23 08:48:08 +00:00
BatchBuffer batchBuffer{commandStreamTask.getGraphicsAllocation(), commandStreamStartTask, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount,
commandStreamTask.getUsed(), &commandStreamTask, endingCmdPtr, false};
2021-10-28 09:21:44 +00:00
this->latestSentTaskCount = taskCount + 1;
2021-02-23 08:48:08 +00:00
flushHandler(batchBuffer, getResidencyAllocations());
2021-10-28 09:21:44 +00:00
taskCount++;
2021-02-23 08:48:08 +00:00
}
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
flush(batchBuffer, allocationsForResidency);
2022-05-27 03:58:07 +00:00
makeSurfacePackNonResident(allocationsForResidency, true);
2021-02-23 08:48:08 +00:00
}
template <typename GfxFamily>
inline bool CommandStreamReceiverHw<GfxFamily>::isUpdateTagFromWaitEnabled() {
2022-03-25 13:00:53 +00:00
auto &hwHelper = HwHelper::get(peekHwInfo().platform.eRenderCoreFamily);
auto enabled = hwHelper.isUpdateTaskCountFromWaitSupported();
enabled &= this->isAnyDirectSubmissionEnabled();
2021-02-23 08:48:08 +00:00
2021-11-17 15:05:48 +00:00
switch (DebugManager.flags.UpdateTaskCountFromWait.get()) {
case 0:
enabled = false;
break;
case 1:
enabled = this->isDirectSubmissionEnabled();
break;
case 2:
enabled = this->isAnyDirectSubmissionEnabled();
break;
case 3:
enabled = true;
break;
2021-02-23 08:48:08 +00:00
}
return enabled;
}
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::updateTagFromWait() {
2022-04-27 16:34:20 +00:00
flushBatchedSubmissions();
2021-02-23 08:48:08 +00:00
if (isUpdateTagFromWaitEnabled()) {
flushTagUpdate();
}
}
2021-06-23 13:34:56 +00:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::programAdditionalStateBaseAddress(LinearStream &csr, typename GfxFamily::STATE_BASE_ADDRESS &cmd, Device &device) {}
2020-12-17 00:36:45 +00:00
template <typename GfxFamily>
2021-08-02 10:44:48 +00:00
inline MemoryCompressionState CommandStreamReceiverHw<GfxFamily>::getMemoryCompressionState(bool auxTranslationRequired, const HardwareInfo &hwInfo) const {
2020-12-17 00:36:45 +00:00
return MemoryCompressionState::NotApplicable;
}
2020-03-19 15:15:51 +01:00
template <typename GfxFamily>
inline bool CommandStreamReceiverHw<GfxFamily>::isPipelineSelectAlreadyProgrammed() const {
2021-09-24 14:29:49 +00:00
const auto &hwInfoConfig = *HwInfoConfig::get(peekHwInfo().platform.eProductFamily);
2022-03-14 16:40:32 +00:00
return this->streamProperties.stateComputeMode.isDirty() && hwInfoConfig.is3DPipelineSelectWARequired() && isRcs();
2020-03-19 15:15:51 +01:00
}
2019-08-07 19:33:40 +02:00
template <typename GfxFamily>
2021-01-28 17:30:56 +00:00
inline void CommandStreamReceiverHw<GfxFamily>::programEpilogue(LinearStream &csr, Device &device, void **batchBufferEndLocation, DispatchFlags &dispatchFlags) {
2019-08-07 19:33:40 +02:00
if (dispatchFlags.epilogueRequired) {
auto currentOffset = ptrDiff(csr.getSpace(0u), csr.getCpuBase());
auto gpuAddress = ptrOffset(csr.getGraphicsAllocation()->getGpuAddress(), currentOffset);
addBatchBufferStart(reinterpret_cast<typename GfxFamily::MI_BATCH_BUFFER_START *>(*batchBufferEndLocation), gpuAddress, false);
2019-08-08 11:44:23 +02:00
this->programEpliogueCommands(csr, dispatchFlags);
2021-01-28 17:30:56 +00:00
programEndingCmd(csr, device, batchBufferEndLocation, isDirectSubmissionEnabled());
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::alignToCacheLine(csr);
2019-08-07 19:33:40 +02:00
}
}
template <typename GfxFamily>
inline size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForEpilogue(const DispatchFlags &dispatchFlags) const {
if (dispatchFlags.epilogueRequired) {
2020-01-15 17:02:47 +01:00
size_t terminateCmd = sizeof(typename GfxFamily::MI_BATCH_BUFFER_END);
if (isDirectSubmissionEnabled()) {
terminateCmd = sizeof(typename GfxFamily::MI_BATCH_BUFFER_START);
}
auto size = getCmdSizeForEpilogueCommands(dispatchFlags) + terminateCmd;
2019-08-08 11:44:23 +02:00
return alignUp(size, MemoryConstants::cacheLineSize);
2019-08-07 19:33:40 +02:00
}
return 0u;
}
2020-01-31 08:50:12 +01:00
template <typename GfxFamily>
2020-02-07 15:36:15 +01:00
inline void CommandStreamReceiverHw<GfxFamily>::programEnginePrologue(LinearStream &csr) {
2020-01-31 08:50:12 +01:00
}
template <typename GfxFamily>
2020-05-27 15:30:31 +02:00
inline size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForPrologue() const {
2020-01-31 08:50:12 +01:00
return 0u;
}
2021-07-30 09:56:58 +00:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::stopDirectSubmission() {
if (EngineHelpers::isBcs(this->osContext->getEngineType())) {
this->blitterDirectSubmission->stopRingBuffer();
} else {
this->directSubmission->stopRingBuffer();
}
}
2020-07-17 11:28:59 +02:00
template <typename GfxFamily>
2022-04-19 14:44:06 +00:00
inline bool CommandStreamReceiverHw<GfxFamily>::initDirectSubmission() {
2020-07-17 11:28:59 +02:00
bool ret = true;
2021-02-10 15:13:50 +00:00
bool submitOnInit = false;
2022-04-19 14:44:06 +00:00
auto startDirect = this->osContext->isDirectSubmissionAvailable(peekHwInfo(), submitOnInit);
2020-07-17 11:28:59 +02:00
2021-02-10 15:13:50 +00:00
if (startDirect) {
2021-08-24 09:47:25 +00:00
auto lock = this->obtainUniqueOwnership();
2021-11-16 13:26:36 +00:00
if (!this->isAnyDirectSubmissionEnabled()) {
2022-04-19 14:44:06 +00:00
if (EngineHelpers::isBcs(this->osContext->getEngineType())) {
blitterDirectSubmission = DirectSubmissionHw<GfxFamily, BlitterDispatcher<GfxFamily>>::create(*this);
2021-12-22 19:28:02 +00:00
ret = blitterDirectSubmission->initialize(submitOnInit, this->isUsedNotifyEnableForPostSync());
2022-04-26 13:29:31 +00:00
completionFenceValuePointer = blitterDirectSubmission->getCompletionValuePointer();
2021-07-30 09:56:58 +00:00
} else {
2022-04-19 14:44:06 +00:00
directSubmission = DirectSubmissionHw<GfxFamily, RenderDispatcher<GfxFamily>>::create(*this);
2021-12-22 19:28:02 +00:00
ret = directSubmission->initialize(submitOnInit, this->isUsedNotifyEnableForPostSync());
2022-04-26 13:29:31 +00:00
completionFenceValuePointer = directSubmission->getCompletionValuePointer();
2021-07-05 11:39:42 +00:00
}
2021-10-25 15:33:38 +00:00
auto directSubmissionController = executionEnvironment.initializeDirectSubmissionController();
2021-07-30 09:56:58 +00:00
if (directSubmissionController) {
directSubmissionController->registerDirectSubmission(this);
}
2022-03-25 13:00:53 +00:00
if (this->isUpdateTagFromWaitEnabled()) {
this->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
}
2020-07-17 11:28:59 +02:00
}
2022-04-19 14:44:06 +00:00
this->osContext->setDirectSubmissionActive();
2020-07-17 11:28:59 +02:00
}
return ret;
}
2021-04-28 10:49:38 +00:00
template <typename GfxFamily>
TagAllocatorBase *CommandStreamReceiverHw<GfxFamily>::getTimestampPacketAllocator() {
if (timestampPacketAllocator.get() == nullptr) {
2021-05-14 10:20:32 +00:00
auto &hwHelper = HwHelper::get(peekHwInfo().platform.eRenderCoreFamily);
2022-04-07 13:09:40 +00:00
const RootDeviceIndicesContainer rootDeviceIndices = {rootDeviceIndex};
2021-05-14 10:20:32 +00:00
timestampPacketAllocator = hwHelper.createTimestampPacketAllocator(rootDeviceIndices, getMemoryManager(), getPreferredTagPoolSize(), getType(), osContext->getDeviceBitfield());
2021-03-29 14:46:41 +00:00
}
return timestampPacketAllocator.get();
}
2021-05-19 21:41:59 +00:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::postInitFlagsSetup() {
useNewResourceImplicitFlush = checkPlatformSupportsNewResourceImplicitFlush();
int32_t overrideNewResourceImplicitFlush = DebugManager.flags.PerformImplicitFlushForNewResource.get();
if (overrideNewResourceImplicitFlush != -1) {
useNewResourceImplicitFlush = overrideNewResourceImplicitFlush == 0 ? false : true;
}
useGpuIdleImplicitFlush = checkPlatformSupportsGpuIdleImplicitFlush();
int32_t overrideGpuIdleImplicitFlush = DebugManager.flags.PerformImplicitFlushForIdleGpu.get();
if (overrideGpuIdleImplicitFlush != -1) {
useGpuIdleImplicitFlush = overrideGpuIdleImplicitFlush == 0 ? false : true;
}
}
2021-11-06 01:42:54 +00:00
template <typename GfxFamily>
size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForStallingCommands(const DispatchFlags &dispatchFlags) const {
auto barrierTimestampPacketNodes = dispatchFlags.barrierTimestampPacketNodes;
if (barrierTimestampPacketNodes && barrierTimestampPacketNodes->peekNodes().size() > 0) {
2021-12-09 19:31:27 +00:00
return getCmdSizeForStallingPostSyncCommands();
2021-11-06 01:42:54 +00:00
} else {
return getCmdSizeForStallingNoPostSyncCommands();
}
}
2021-11-17 19:51:43 +00:00
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::programActivePartitionConfigFlushTask(LinearStream &csr) {
if (csrSizeRequestFlags.activePartitionsChanged) {
programActivePartitionConfig(csr);
}
}
2022-03-09 17:15:48 +00:00
template <typename GfxFamily>
bool CommandStreamReceiverHw<GfxFamily>::hasSharedHandles() {
if (!csrSizeRequestFlags.hasSharedHandles) {
for (const auto &allocation : this->getResidencyAllocations()) {
if (allocation->peekSharedHandle()) {
csrSizeRequestFlags.hasSharedHandles = true;
break;
}
}
}
return csrSizeRequestFlags.hasSharedHandles;
}
template <typename GfxFamily>
size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForComputeMode() {
return EncodeComputeMode<GfxFamily>::getCmdSizeForComputeMode(this->peekHwInfo(), hasSharedHandles(), isRcs());
}
2022-05-18 18:10:53 +00:00
template <typename GfxFamily>
constexpr bool CommandStreamReceiverHw<GfxFamily>::isGlobalAtomicsProgrammingRequired(bool currentVal) const {
return false;
}
2022-08-03 11:54:08 +00:00
template <typename GfxFamily>
void CommandStreamReceiverHw<GfxFamily>::createKernelArgsBufferAllocation() {
}
2019-03-26 11:59:46 +01:00
} // namespace NEO