/* * Copyright (C) 2019-2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/gen12lp/hw_cmds.h" #include "shared/source/gmm_helper/resource_info.h" using Family = NEO::Gen12LpFamily; #include "shared/source/command_stream/command_stream_receiver_hw_base.inl" #include "shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl" #include "shared/source/command_stream/device_command_stream.h" #include "shared/source/gmm_helper/gmm.h" #include "shared/source/helpers/address_patch.h" #include "shared/source/helpers/blit_commands_helper_base.inl" #include "shared/source/helpers/populate_factory.h" #include "shared/source/helpers/state_base_address_tgllp_and_later.inl" namespace NEO { static auto gfxCore = IGFX_GEN12LP_CORE; template bool CommandStreamReceiverHw::are4GbHeapsAvailable() const { return true; } template size_t CommandStreamReceiverHw::getRequiredStateBaseAddressSize(const Device &device) const { size_t size = 0; const auto &productHelper = getProductHelper(); if (productHelper.is3DPipelineSelectWARequired()) { size += (2 * PreambleHelper::getCmdSizeForPipelineSelect(peekRootDeviceEnvironment())); } size += sizeof(typename GfxFamily::STATE_BASE_ADDRESS) + sizeof(PIPE_CONTROL); return size; } template void CommandStreamReceiverHw::programPipelineSelect(LinearStream &commandStream, PipelineSelectArgs &pipelineSelectArgs) { if (csrSizeRequestFlags.mediaSamplerConfigChanged || csrSizeRequestFlags.systolicPipelineSelectMode || !isPreambleSent) { if (!isPipelineSelectAlreadyProgrammed()) { PreambleHelper::programPipelineSelect(&commandStream, pipelineSelectArgs, peekRootDeviceEnvironment()); } this->lastMediaSamplerConfig = pipelineSelectArgs.mediaSamplerRequired; this->lastSystolicPipelineSelectMode = pipelineSelectArgs.systolicPipelineSelectMode; this->streamProperties.pipelineSelect.setPropertiesAll(true, this->lastMediaSamplerConfig, this->lastSystolicPipelineSelectMode); this->streamProperties.pipelineSelect.clearIsDirty(); } } template void CommandStreamReceiverHw::createScratchSpaceController() { scratchSpaceController = std::make_unique(rootDeviceIndex, executionEnvironment, *internalAllocationStorage.get()); } template void CommandStreamReceiverHw::programEpliogueCommands(LinearStream &csr, const DispatchFlags &dispatchFlags) { this->programEngineModeEpliogue(csr, dispatchFlags); } template size_t CommandStreamReceiverHw::getCmdSizeForEpilogueCommands(const DispatchFlags &dispatchFlags) const { return this->getCmdSizeForEngineMode(dispatchFlags); } template bool CommandStreamReceiverHw::isMultiOsContextCapable() const { return false; } template inline void CommandStreamReceiverHw::addPipeControlBeforeStateSip(LinearStream &commandStream, Device &device) {} template inline void CommandStreamReceiverHw::addPipeControlBefore3dState(LinearStream &commandStream, DispatchFlags &dispatchFlags) {} template bool CommandStreamReceiverHw::checkPlatformSupportsNewResourceImplicitFlush() const { return false; } template bool CommandStreamReceiverHw::checkPlatformSupportsGpuIdleImplicitFlush() const { return false; } template GraphicsAllocation *CommandStreamReceiverHw::getClearColorAllocation() { return nullptr; } template void CommandStreamReceiverHw::programPerDssBackedBuffer(LinearStream &commandStream, Device &device, DispatchFlags &dispatchFlags) { } template size_t CommandStreamReceiverHw::getCmdSizeForPerDssBackedBuffer(const HardwareInfo &hwInfo) { return 0; } template void CommandStreamReceiverHw::dispatchRayTracingStateCommand(LinearStream &cmdStream, Device &device) { } template void CommandStreamReceiverHw::collectStateBaseAddresIohPatchInfo(uint64_t commandBufferAddress, uint64_t commandOffset, const LinearStream &ioh) { using STATE_BASE_ADDRESS = typename GfxFamily::STATE_BASE_ADDRESS; PatchInfoData indirectObjectPatchInfo = {ioh.getGraphicsAllocation()->getGpuAddress(), 0u, PatchInfoAllocationType::indirectObjectHeap, commandBufferAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::INDIRECTOBJECTBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::defaultType}; flatBatchBufferHelper->setPatchInfoData(indirectObjectPatchInfo); } template size_t CommandStreamReceiverHw::getCmdSizeForActivePartitionConfig() const { return 0; } template inline void CommandStreamReceiverHw::programActivePartitionConfig(LinearStream &csr) { } template inline size_t CommandStreamReceiverHw::getCmdSizeForStallingNoPostSyncCommands() const { return sizeof(typename GfxFamily::PIPE_CONTROL); } template inline size_t CommandStreamReceiverHw::getCmdSizeForStallingPostSyncCommands() const { return MemorySynchronizationCommands::getSizeForBarrierWithPostSyncOperation(peekRootDeviceEnvironment(), false); } template inline void CommandStreamReceiverHw::programStallingNoPostSyncCommandsForBarrier(LinearStream &cmdStream) { PipeControlArgs args; MemorySynchronizationCommands::addSingleBarrier(cmdStream, args); } template inline void CommandStreamReceiverHw::programStallingPostSyncCommandsForBarrier(LinearStream &cmdStream, TagNodeBase &tagNode, bool dcFlushRequired) { auto barrierTimestampPacketGpuAddress = TimestampPacketHelper::getContextEndGpuAddress(tagNode); PipeControlArgs args; args.dcFlushEnable = this->dcFlushSupport && dcFlushRequired; MemorySynchronizationCommands::addBarrierWithPostSyncOperation( cmdStream, PostSyncMode::immediateData, barrierTimestampPacketGpuAddress, 0, peekRootDeviceEnvironment(), args); } template inline void CommandStreamReceiverHw::configurePostSyncWriteOffset() { } template uint64_t BlitCommandsHelper::getMaxBlitWidthOverride(const RootDeviceEnvironment &rootDeviceEnvironment) { return 0; } template uint64_t BlitCommandsHelper::getMaxBlitHeightOverride(const RootDeviceEnvironment &rootDeviceEnvironment, bool isSystemMemoryPoolUsed) { return 0; } template void BlitCommandsHelper::appendBlitCommandsBlockCopy(const BlitProperties &blitProperties, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment) { appendExtraMemoryProperties(blitCmd, rootDeviceEnvironment); } template void BlitCommandsHelper::appendSurfaceType(const BlitProperties &blitProperties, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd) { } template void BlitCommandsHelper::appendTilingEnable(typename GfxFamily::XY_COLOR_BLT &blitCmd) { using XY_COLOR_BLT = typename GfxFamily::XY_COLOR_BLT; blitCmd.setDestTilingEnable(XY_COLOR_BLT::DEST_TILING_ENABLE::DEST_TILING_ENABLE_TILING_ENABLED); } template void BlitCommandsHelper::appendTilingType(const GMM_TILE_TYPE srcTilingType, const GMM_TILE_TYPE dstTilingType, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd) { } template void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod, uint32_t &compressionDetails, const RootDeviceEnvironment &rootDeviceEnvironment, GMM_YUV_PLANE_ENUM plane) { } template void BlitCommandsHelper::programGlobalSequencerFlush(LinearStream &commandStream) { } template size_t BlitCommandsHelper::getSizeForGlobalSequencerFlush() { return 0u; } template bool BlitCommandsHelper::miArbCheckWaRequired() { return false; } template void BlitCommandsHelper::appendClearColor(const BlitProperties &blitProperties, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd) { } template void BlitCommandsHelper::printImageBlitBlockCopyCommand(const typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd, const uint32_t sliceIndex) {} template void BlitCommandsHelper::dispatchDummyBlit(LinearStream &linearStream, EncodeDummyBlitWaArgs &waArgs) {} template bool BlitCommandsHelper::isDummyBlitWaNeeded(const EncodeDummyBlitWaArgs &waArgs) { return false; } template size_t BlitCommandsHelper::getDummyBlitSize(const EncodeDummyBlitWaArgs &waArgs) { return 0u; } template <> void CommandStreamReceiverHw::programL3(LinearStream &csr, uint32_t &newL3Config, bool isBcs) { } template <> size_t CommandStreamReceiverHw::getCmdSizeForL3Config() const { return 0; } template <> void populateFactoryTable>() { extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE]; commandStreamReceiverFactory[gfxCore] = DeviceCommandStreamReceiver::create; } template <> template <> void BlitCommandsHelper::appendColorDepth(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd) { using XY_BLOCK_COPY_BLT = typename Family::XY_BLOCK_COPY_BLT; switch (blitProperties.bytesPerPixel) { default: UNRECOVERABLE_IF(true); break; case 1: blitCmd.setColorDepth(XY_BLOCK_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_8_BIT_COLOR); break; case 2: blitCmd.setColorDepth(XY_BLOCK_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_16_BIT_COLOR); break; case 4: blitCmd.setColorDepth(XY_BLOCK_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_32_BIT_COLOR); break; case 8: blitCmd.setColorDepth(XY_BLOCK_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_64_BIT_COLOR); break; case 16: blitCmd.setColorDepth(XY_BLOCK_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_128_BIT_COLOR); break; } } template <> void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod, uint32_t &compressionDetails, const RootDeviceEnvironment &rootDeviceEnvironment, GMM_YUV_PLANE_ENUM plane) { if (allocation.getDefaultGmm()) { auto gmmResourceInfo = allocation.getDefaultGmm()->gmmResourceInfo.get(); if (!gmmResourceInfo->getResourceFlags()->Info.Linear) { qPitch = gmmResourceInfo->getQPitch() ? static_cast(gmmResourceInfo->getQPitch()) : qPitch; pitch = gmmResourceInfo->getRenderPitch() ? static_cast(gmmResourceInfo->getRenderPitch()) : pitch; } } } template <> void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, uint32_t sliceIndex, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t srcSlicePitch, uint32_t dstSlicePitch) { auto srcAddress = blitProperties.srcGpuAddress; auto dstAddress = blitProperties.dstGpuAddress; blitCmd.setSourceBaseAddress(ptrOffset(srcAddress, srcSlicePitch * (sliceIndex + blitProperties.srcOffset.z))); blitCmd.setDestinationBaseAddress(ptrOffset(dstAddress, dstSlicePitch * (sliceIndex + blitProperties.dstOffset.z))); } template <> void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t &srcSlicePitch, uint32_t &dstSlicePitch) { auto tileType = GMM_NOT_TILED; auto srcAllocation = blitProperties.srcAllocation; auto dstAllocation = blitProperties.dstAllocation; auto srcQPitch = static_cast(blitProperties.srcSize.y); auto dstQPitch = static_cast(blitProperties.dstSize.y); auto srcRowPitch = static_cast(blitProperties.srcRowPitch); auto dstRowPitch = static_cast(blitProperties.dstRowPitch); uint32_t mipTailLod = 0; auto compressionDetails = 0u; getBlitAllocationProperties(*srcAllocation, srcRowPitch, srcQPitch, tileType, mipTailLod, compressionDetails, rootDeviceEnvironment, blitProperties.srcPlane); getBlitAllocationProperties(*dstAllocation, dstRowPitch, dstQPitch, tileType, mipTailLod, compressionDetails, rootDeviceEnvironment, blitProperties.dstPlane); blitCmd.setSourcePitch(srcRowPitch); blitCmd.setDestinationPitch(dstRowPitch); srcSlicePitch = std::max(srcSlicePitch, srcRowPitch * srcQPitch); dstSlicePitch = std::max(dstSlicePitch, dstRowPitch * dstQPitch); } template <> void BlitCommandsHelper::dispatchBlitMemoryByteFill(const BlitProperties &blitProperties, LinearStream &linearStream, RootDeviceEnvironment &rootDeviceEnvironment) { NEO::BlitCommandsHelper::dispatchBlitMemoryFill(blitProperties, linearStream, rootDeviceEnvironment); } template <> void BlitCommandsHelper::appendBlitMemSetCompressionFormat(void *blitCmd, NEO::GraphicsAllocation *dstAlloc, uint32_t compressionFormat) {} template <> void BlitCommandsHelper::appendBlitMemoryOptionsForFillBuffer(NEO::GraphicsAllocation *dstAlloc, typename Family::XY_COLOR_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment) { } template <> void BlitCommandsHelper::appendTilingEnable(typename Family::XY_COLOR_BLT &blitCmd) {} template <> bool BlitCommandsHelper::preBlitCommandWARequired() { return true; } template class CommandStreamReceiverHw; template struct BlitCommandsHelper; const Family::GPGPU_WALKER Family::cmdInitGpgpuWalker = Family::GPGPU_WALKER::sInit(); const Family::INTERFACE_DESCRIPTOR_DATA Family::cmdInitInterfaceDescriptorData = Family::INTERFACE_DESCRIPTOR_DATA::sInit(); const Family::MEDIA_INTERFACE_DESCRIPTOR_LOAD Family::cmdInitMediaInterfaceDescriptorLoad = Family::MEDIA_INTERFACE_DESCRIPTOR_LOAD::sInit(); const Family::MEDIA_STATE_FLUSH Family::cmdInitMediaStateFlush = Family::MEDIA_STATE_FLUSH::sInit(); const Family::MI_BATCH_BUFFER_START Family::cmdInitBatchBufferStart = Family::MI_BATCH_BUFFER_START::sInit(); const Family::MI_BATCH_BUFFER_END Family::cmdInitBatchBufferEnd = Family::MI_BATCH_BUFFER_END::sInit(); const Family::PIPE_CONTROL Family::cmdInitPipeControl = Family::PIPE_CONTROL::sInit(); const Family::STATE_COMPUTE_MODE Family::cmdInitStateComputeMode = Family::STATE_COMPUTE_MODE::sInit(); const Family::MI_SEMAPHORE_WAIT Family::cmdInitMiSemaphoreWait = Family::MI_SEMAPHORE_WAIT::sInit(); const Family::RENDER_SURFACE_STATE Family::cmdInitRenderSurfaceState = Family::RENDER_SURFACE_STATE::sInit(); const Family::MI_LOAD_REGISTER_IMM Family::cmdInitLoadRegisterImm = Family::MI_LOAD_REGISTER_IMM::sInit(); const Family::MI_LOAD_REGISTER_REG Family::cmdInitLoadRegisterReg = Family::MI_LOAD_REGISTER_REG::sInit(); const Family::MI_LOAD_REGISTER_MEM Family::cmdInitLoadRegisterMem = Family::MI_LOAD_REGISTER_MEM::sInit(); const Family::MI_STORE_DATA_IMM Family::cmdInitStoreDataImm = Family::MI_STORE_DATA_IMM::sInit(); const Family::MI_STORE_REGISTER_MEM Family::cmdInitStoreRegisterMem = Family::MI_STORE_REGISTER_MEM::sInit(); const Family::MI_NOOP Family::cmdInitNoop = Family::MI_NOOP::sInit(); const Family::MI_REPORT_PERF_COUNT Family::cmdInitReportPerfCount = Family::MI_REPORT_PERF_COUNT::sInit(); const Family::MI_ATOMIC Family::cmdInitAtomic = Family::MI_ATOMIC::sInit(); const Family::PIPELINE_SELECT Family::cmdInitPipelineSelect = Family::PIPELINE_SELECT::sInit(); const Family::MI_ARB_CHECK Family::cmdInitArbCheck = Family::MI_ARB_CHECK::sInit(); const Family::MEDIA_VFE_STATE Family::cmdInitMediaVfeState = Family::MEDIA_VFE_STATE::sInit(); const Family::STATE_BASE_ADDRESS Family::cmdInitStateBaseAddress = Family::STATE_BASE_ADDRESS::sInit(); const Family::MEDIA_SURFACE_STATE Family::cmdInitMediaSurfaceState = Family::MEDIA_SURFACE_STATE::sInit(); const Family::SAMPLER_STATE Family::cmdInitSamplerState = Family::SAMPLER_STATE::sInit(); const Family::GPGPU_CSR_BASE_ADDRESS Family::cmdInitGpgpuCsrBaseAddress = Family::GPGPU_CSR_BASE_ADDRESS::sInit(); const Family::STATE_SIP Family::cmdInitStateSip = Family::STATE_SIP::sInit(); const Family::BINDING_TABLE_STATE Family::cmdInitBindingTableState = Family::BINDING_TABLE_STATE::sInit(); const Family::MI_USER_INTERRUPT Family::cmdInitUserInterrupt = Family::MI_USER_INTERRUPT::sInit(); const Family::L3_CONTROL Family::cmdInitL3ControlWithoutPostSync = Family::L3_CONTROL::sInit(); const Family::L3_CONTROL Family::cmdInitL3ControlWithPostSync = Family::L3_CONTROL::sInit(); const Family::XY_BLOCK_COPY_BLT Family::cmdInitXyBlockCopyBlt = Family::XY_BLOCK_COPY_BLT::sInit(); const Family::XY_COPY_BLT Family::cmdInitXyCopyBlt = Family::XY_COPY_BLT::sInit(); const Family::MI_FLUSH_DW Family::cmdInitMiFlushDw = Family::MI_FLUSH_DW::sInit(); const Family::XY_FAST_COLOR_BLT Family::cmdInitXyColorBlt = Family::XY_FAST_COLOR_BLT::sInit(); } // namespace NEO