diff --git a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp index df806d8b26..0b99b5960c 100644 --- a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp +++ b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp @@ -16,6 +16,7 @@ using Family = NEO::Gen12LpFamily; #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/blit_commands_helper_from_gen12lp_to_xe3.inl" #include "shared/source/helpers/populate_factory.h" #include "shared/source/helpers/state_base_address_tgllp_and_later.inl" @@ -332,6 +333,8 @@ bool BlitCommandsHelper::preBlitCommandWARequired() { template class CommandStreamReceiverHw; template struct BlitCommandsHelper; +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); + 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(); diff --git a/shared/source/helpers/CMakeLists.txt b/shared/source/helpers/CMakeLists.txt index 00f86b63e5..64529168cd 100644 --- a/shared/source/helpers/CMakeLists.txt +++ b/shared/source/helpers/CMakeLists.txt @@ -234,6 +234,12 @@ if(SUPPORT_XE3_AND_LATER) ) endif() +if(SUPPORT_XE3_AND_BEFORE) + list(APPEND NEO_CORE_HELPERS + ${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_from_gen12lp_to_xe3.inl + ) +endif() + set(NEO_CORE_HELPERS_GMM_CALLBACKS_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/windows/gmm_callbacks.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows/gmm_callbacks.h diff --git a/shared/source/helpers/blit_commands_helper.h b/shared/source/helpers/blit_commands_helper.h index ded2805871..5e5b3c7bc8 100644 --- a/shared/source/helpers/blit_commands_helper.h +++ b/shared/source/helpers/blit_commands_helper.h @@ -96,5 +96,8 @@ struct BlitCommandsHelper { static void encodeWa(LinearStream &cmdStream, const BlitProperties &blitProperties, uint32_t &latestSentBcsWaValue); static size_t getWaCmdsSize(const BlitPropertiesContainer &blitPropertiesContainer); + + template + static void applyAdditionalBlitProperties(const BlitProperties &blitProperties, CommandType &cmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); }; } // namespace NEO diff --git a/shared/source/helpers/blit_commands_helper_base.inl b/shared/source/helpers/blit_commands_helper_base.inl index 312e99227c..7bb4e67df1 100644 --- a/shared/source/helpers/blit_commands_helper_base.inl +++ b/shared/source/helpers/blit_commands_helper_base.inl @@ -209,10 +209,13 @@ void BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(const Bl appendColorDepth(blitProperties, bltCmd); + const bool useAdditionalBlitProperties = rootDeviceEnvironment.getHelper().useAdditionalBlitProperties(); + for (uint64_t slice = 0; slice < blitProperties.copySize.z; slice++) { for (uint64_t row = 0; row < blitProperties.copySize.y; row++) { uint64_t offset = 0; uint64_t sizeToBlit = blitProperties.copySize.x; + bool lastIteration = (slice == blitProperties.copySize.z - 1) && (row == blitProperties.copySize.y - 1); while (sizeToBlit != 0) { if (sizeToBlit > maxWidth) { // dispatch 2D blit: maxBlitWidth x (1 .. maxBlitHeight) @@ -223,6 +226,8 @@ void BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(const Bl width = sizeToBlit; height = 1; } + auto blitSize = width * height; + auto lastCommand = lastIteration && (sizeToBlit - blitSize == 0); bltCmd.setDestinationX2CoordinateRight(static_cast(width)); bltCmd.setDestinationY2CoordinateBottom(static_cast(height)); @@ -237,6 +242,9 @@ void BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(const Bl bltCmd.setDestinationBaseAddress(dstAddr); bltCmd.setSourceBaseAddress(srcAddr); + if (useAdditionalBlitProperties && lastCommand) { + applyAdditionalBlitProperties(blitProperties, bltCmd, rootDeviceEnvironment, lastCommand); + } appendBlitCommandsForBuffer(blitProperties, bltCmd, rootDeviceEnvironment); @@ -245,7 +253,6 @@ void BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(const Bl dispatchPostBlitCommand(linearStream, rootDeviceEnvironment); - auto blitSize = width * height; sizeToBlit -= blitSize; offset += blitSize; } diff --git a/shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl b/shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl new file mode 100644 index 0000000000..09a191b43c --- /dev/null +++ b/shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/blit_properties.h" + +namespace NEO { + +template +template +void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, + CommandType &cmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last) { +} + +} // namespace NEO diff --git a/shared/source/helpers/blit_properties.h b/shared/source/helpers/blit_properties.h index 6a19c94414..7f79cfb67a 100644 --- a/shared/source/helpers/blit_properties.h +++ b/shared/source/helpers/blit_properties.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/command_container/command_encoder.h" #include "shared/source/command_stream/csr_deps.h" #include "shared/source/gmm_helper/gmm_lib.h" #include "shared/source/helpers/aux_translation.h" @@ -17,6 +18,7 @@ namespace NEO { struct TimestampPacketDependencies; +struct BlitSyncPropertiesExt; class TagNodeBase; class TimestampPacketContainer; class GraphicsAllocation; @@ -31,13 +33,13 @@ enum class BlitSyncMode { }; struct BlitSyncProperties { + EncodePostSyncArgs postSyncArgs{}; TagNodeBase *outputTimestampPacket = nullptr; BlitSyncMode syncMode = BlitSyncMode::none; uint64_t deviceGpuWriteAddress = 0; uint64_t hostGpuWriteAddress = 0; uint64_t timestampGpuWriteAddress = 0; uint64_t writeValue = 0; - bool isTimestampMode() const { return (syncMode == BlitSyncMode::timestamp) || (syncMode == BlitSyncMode::timestampAndImmediate); } @@ -104,4 +106,4 @@ struct BlitProperties { bool isSystemMemoryPoolUsed = false; }; -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp b/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp index 1081470710..8527d246a8 100644 --- a/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp +++ b/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp @@ -15,6 +15,7 @@ using Family = NEO::Xe2HpgCoreFamily; #include "shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl" #include "shared/source/command_stream/command_stream_receiver_hw_xehp_and_later.inl" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl" #include "shared/source/helpers/blit_commands_helper_pvc_and_later.inl" #include "shared/source/helpers/blit_commands_helper_xe2_and_later.inl" #include "shared/source/helpers/blit_commands_helper_xehp_and_later.inl" @@ -271,6 +272,9 @@ template void BlitCommandsHelper::appendColorDepth::appendColorDepth(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd); template void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); + const Family::COMPUTE_WALKER Family::cmdInitGpgpuWalker = Family::COMPUTE_WALKER::sInit(); const Family::CFE_STATE Family::cmdInitCfeState = Family::CFE_STATE::sInit(); const Family::INTERFACE_DESCRIPTOR_DATA Family::cmdInitInterfaceDescriptorData = Family::INTERFACE_DESCRIPTOR_DATA::sInit(); diff --git a/shared/source/xe3_core/command_stream_receiver_hw_xe3_core.cpp b/shared/source/xe3_core/command_stream_receiver_hw_xe3_core.cpp index f64134ab79..5a626a52b5 100644 --- a/shared/source/xe3_core/command_stream_receiver_hw_xe3_core.cpp +++ b/shared/source/xe3_core/command_stream_receiver_hw_xe3_core.cpp @@ -14,6 +14,7 @@ using Family = NEO::Xe3CoreFamily; #include "shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl" #include "shared/source/command_stream/command_stream_receiver_hw_xehp_and_later.inl" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl" #include "shared/source/helpers/blit_commands_helper_pvc_and_later.inl" #include "shared/source/helpers/blit_commands_helper_xe2_and_later.inl" #include "shared/source/helpers/blit_commands_helper_xehp_and_later.inl" @@ -225,6 +226,9 @@ template void BlitCommandsHelper::appendColorDepth::appendColorDepth(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd); template void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); + const Family::COMPUTE_WALKER Family::cmdInitGpgpuWalker = Family::COMPUTE_WALKER::sInit(); const Family::CFE_STATE Family::cmdInitCfeState = Family::CFE_STATE::sInit(); const Family::INTERFACE_DESCRIPTOR_DATA Family::cmdInitInterfaceDescriptorData = Family::INTERFACE_DESCRIPTOR_DATA::sInit(); diff --git a/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp b/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp index dbeb395a0b..c14ab56de4 100644 --- a/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp +++ b/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp @@ -16,6 +16,7 @@ using Family = NEO::XeHpcCoreFamily; #include "shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl" #include "shared/source/command_stream/command_stream_receiver_hw_xehp_and_later.inl" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl" #include "shared/source/helpers/blit_commands_helper_pvc_and_later.inl" #include "shared/source/helpers/blit_commands_helper_xehp_and_later.inl" #include "shared/source/helpers/blit_properties.h" @@ -273,6 +274,8 @@ template class CommandStreamReceiverHw; template struct BlitCommandsHelper; template void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); + const Family::COMPUTE_WALKER Family::cmdInitGpgpuWalker = Family::COMPUTE_WALKER::sInit(); const Family::CFE_STATE Family::cmdInitCfeState = Family::CFE_STATE::sInit(); const Family::INTERFACE_DESCRIPTOR_DATA Family::cmdInitInterfaceDescriptorData = Family::INTERFACE_DESCRIPTOR_DATA::sInit(); diff --git a/shared/source/xe_hpg_core/command_stream_receiver_hw_xe_hpg_core.cpp b/shared/source/xe_hpg_core/command_stream_receiver_hw_xe_hpg_core.cpp index 070f0ae6f3..00ddbd650f 100644 --- a/shared/source/xe_hpg_core/command_stream_receiver_hw_xe_hpg_core.cpp +++ b/shared/source/xe_hpg_core/command_stream_receiver_hw_xe_hpg_core.cpp @@ -14,6 +14,7 @@ using Family = NEO::XeHpgCoreFamily; #include "shared/source/command_stream/command_stream_receiver_hw_dg2_and_later.inl" #include "shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl" #include "shared/source/command_stream/command_stream_receiver_hw_xehp_and_later.inl" +#include "shared/source/helpers/blit_commands_helper_from_gen12lp_to_xe3.inl" #include "shared/source/helpers/blit_commands_helper_xehp_and_later.inl" #include "shared/source/helpers/populate_factory.h" #include "shared/source/helpers/state_base_address_xehp_and_later.inl" @@ -162,6 +163,8 @@ template struct BlitCommandsHelper; template void BlitCommandsHelper::appendColorDepth(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd); template void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); +template void BlitCommandsHelper::applyAdditionalBlitProperties(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, bool last); + const Family::COMPUTE_WALKER Family::cmdInitGpgpuWalker = Family::COMPUTE_WALKER::sInit(); const Family::CFE_STATE Family::cmdInitCfeState = Family::CFE_STATE::sInit(); const Family::INTERFACE_DESCRIPTOR_DATA Family::cmdInitInterfaceDescriptorData = Family::INTERFACE_DESCRIPTOR_DATA::sInit(); diff --git a/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp b/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp index cfeba8f46c..de550a9c0e 100644 --- a/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp +++ b/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp @@ -15,6 +15,7 @@ #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/helpers/mock_product_helper_hw.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_timestamp_container.h" @@ -710,3 +711,79 @@ HWTEST_F(BlitTests, givenPlatformWhenCallingDispatchPreBlitCommandThenNoneMiFlus blitPropertiesContainer2, false, true, false, false, pDevice->getRootDeviceEnvironment()); EXPECT_NE(estimatedSizeWithoutNode, estimatedSizeWithNode); } + +HWTEST2_F(BlitTests, givenPlatformWithBlitSyncPropertiesWithAndWithoutTimestampModeWhenCallingDispatchBlitCommandForBufferThenTheResultsAreTheSame, MatchAny) { + uint32_t src[] = {1, 2, 3, 4}; + uint32_t dst[] = {4, 3, 2, 1}; + uint32_t clear[] = {5, 6, 7, 8}; + uint64_t srcGpuAddr = 0x12345; + uint64_t dstGpuAddr = 0x54321; + uint64_t clearGpuAddr = 0x5678; + std::unique_ptr srcAlloc(new MockGraphicsAllocation(src, srcGpuAddr, sizeof(src))); + std::unique_ptr dstAlloc(new MockGraphicsAllocation(dst, dstGpuAddr, sizeof(dst))); + std::unique_ptr clearColorAllocation(new MockGraphicsAllocation(clear, clearGpuAddr, sizeof(clear))); + + Vec3 srcOffsets{1, 0, 0}; + Vec3 dstOffsets{1, 0, 0}; + Vec3 copySize{(BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 1, 2, 2}; + + size_t srcRowPitch = 0; + size_t srcSlicePitch = 0; + + size_t dstRowPitch = 0; + size_t dstSlicePitch = 0; + + auto blitProperties = NEO::BlitProperties::constructPropertiesForCopy(dstAlloc.get(), srcAlloc.get(), + dstOffsets, srcOffsets, copySize, srcRowPitch, srcSlicePitch, + dstRowPitch, dstSlicePitch, clearColorAllocation.get()); + + uint32_t streamBuffer[400] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + NEO::BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(blitProperties, stream, pDevice->getRootDeviceEnvironmentRef()); + + // change it into timestamp mode + blitProperties.blitSyncProperties.syncMode = NEO::BlitSyncMode::timestamp; + + uint32_t streamBuffer2[400] = {}; + LinearStream stream2(streamBuffer2, sizeof(streamBuffer2)); + NEO::BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(blitProperties, stream2, pDevice->getRootDeviceEnvironmentRef()); + + EXPECT_EQ(stream.getUsed(), stream2.getUsed()); + EXPECT_EQ(0, memcmp(ptrOffset(stream.getCpuBase(), 0), ptrOffset(stream2.getCpuBase(), 0), std::min(stream.getUsed(), stream2.getUsed()))); + + // change productHelper to return true + pDevice->getRootDeviceEnvironmentRef().productHelper.reset(new MockProductHelperHw); + auto *mockProductHelper = static_cast *>(pDevice->getRootDeviceEnvironmentRef().productHelper.get()); + mockProductHelper->enableAdditionalBlitProperties = true; + + uint32_t streamBuffer3[400] = {}; + LinearStream stream3(streamBuffer3, sizeof(streamBuffer2)); + NEO::BlitCommandsHelper::dispatchBlitCommandsForBufferPerRow(blitProperties, stream3, pDevice->getRootDeviceEnvironmentRef()); + + EXPECT_EQ(stream.getUsed(), stream3.getUsed()); + EXPECT_EQ(0, memcmp(ptrOffset(stream.getCpuBase(), 0), ptrOffset(stream3.getCpuBase(), 0), std::min(stream.getUsed(), stream3.getUsed()))); +} + +HWTEST_F(BlitTests, givenBlitPropertieswithImageOperationWhenCallingEstimateBlitCommandSizeThenBlockCopySizeIsReturned) { + Vec3 copySize{BlitterConstants::maxBlitWidth - 1, 1, 1}; + NEO::CsrDependencies csrDependencies{}; + + size_t totalSize = NEO::BlitCommandsHelper::estimateBlitCommandSize(copySize, csrDependencies, false, false, true, pDevice->getRootDeviceEnvironmentRef(), false, false); + + size_t expectedSize = sizeof(typename FamilyType::XY_BLOCK_COPY_BLT); + expectedSize += NEO::BlitCommandsHelper::estimatePostBlitCommandSize(); + expectedSize += NEO::BlitCommandsHelper::estimatePreBlitCommandSize(); + EXPECT_EQ(expectedSize, totalSize); +} + +using IsWithinGen12LPAndXe3Core = IsWithinGfxCore; +HWTEST2_F(BlitTests, givenXyCopyBltCommandWhenApplyBlitPropertiesIsCalledThenNothingChanged, IsWithinGen12LPAndXe3Core) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + auto bltCmd = FamilyType::cmdInitXyCopyBlt; + auto bltCmdBefore = bltCmd; + BlitProperties properties = {}; + NEO::BlitCommandsHelper::applyAdditionalBlitProperties(properties, bltCmd, pDevice->getRootDeviceEnvironment(), false); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); + NEO::BlitCommandsHelper::applyAdditionalBlitProperties(properties, bltCmd, pDevice->getRootDeviceEnvironment(), true); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); +}