diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp index dfd7a45d41..d0b150d894 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp @@ -868,10 +868,10 @@ HWTEST_F(BcsTests, givenTimestampPacketWriteRequestWhenEstimatingSizeForCommands auto expectedSizeWithTimestampPacketWrite = expectedBaseSize + EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); auto expectedSizeWithoutTimestampPacketWrite = expectedBaseSize; - auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper::estimateBlitCommandsSize( - {1, 1, 1}, csrDependencies, true, false, pClDevice->getRootDeviceEnvironment()); - auto estimatedSizeWithoutTimestampPacketWrite = BlitCommandsHelper::estimateBlitCommandsSize( - {1, 1, 1}, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment()); + auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper::estimateBlitCommandSize( + {1, 1, 1}, csrDependencies, true, false, false, pClDevice->getRootDeviceEnvironment()); + auto estimatedSizeWithoutTimestampPacketWrite = BlitCommandsHelper::estimateBlitCommandSize( + {1, 1, 1}, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedSizeWithTimestampPacketWrite, estimatedSizeWithTimestampPacketWrite); EXPECT_EQ(expectedSizeWithoutTimestampPacketWrite, estimatedSizeWithoutTimestampPacketWrite); @@ -891,10 +891,10 @@ HWTEST_F(BcsTests, givenTimestampPacketWriteRequestWhenEstimatingSizeForCommands auto expectedSizeWithTimestampPacketWriteAndProfiling = expectedBaseSize + BlitCommandsHelper::getProfilingMmioCmdsSize(); - auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper::estimateBlitCommandsSize( - {1, 1, 1}, csrDependencies, true, false, pClDevice->getRootDeviceEnvironment()); - auto estimatedSizeWithTimestampPacketWriteAndProfiling = BlitCommandsHelper::estimateBlitCommandsSize( - {1, 1, 1}, csrDependencies, true, true, pClDevice->getRootDeviceEnvironment()); + auto estimatedSizeWithTimestampPacketWrite = BlitCommandsHelper::estimateBlitCommandSize( + {1, 1, 1}, csrDependencies, true, false, false, pClDevice->getRootDeviceEnvironment()); + auto estimatedSizeWithTimestampPacketWriteAndProfiling = BlitCommandsHelper::estimateBlitCommandSize( + {1, 1, 1}, csrDependencies, true, true, false, pClDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedSizeWithTimestampPacketWriteAndProfiling, estimatedSizeWithTimestampPacketWriteAndProfiling); EXPECT_EQ(expectedBaseSize, estimatedSizeWithTimestampPacketWrite); @@ -923,12 +923,48 @@ HWTEST_F(BcsTests, givenBltSizeAndCsrDependenciesWhenEstimatingCommandSizeThenAd expectedSize += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); } - auto estimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - {1, 1, 1}, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment()); + auto estimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + {1, 1, 1}, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedSize, estimatedSize); } +HWTEST_F(BcsTests, givenImageAndBufferWhenEstimateBlitCommandSizeThenReturnCorrectCommandSize) { + + for (auto isImage : {false, true}) { + auto expectedSize = sizeof(typename FamilyType::MI_ARB_CHECK); + expectedSize += isImage ? sizeof(typename FamilyType::XY_BLOCK_COPY_BLT) : sizeof(typename FamilyType::XY_COPY_BLT); + + if (BlitCommandsHelper::miArbCheckWaRequired()) { + expectedSize += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); + } + if (BlitCommandsHelper::preBlitCommandWARequired()) { + expectedSize += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); + } + + auto estimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + {1, 1, 1}, csrDependencies, false, false, isImage, pClDevice->getRootDeviceEnvironment()); + + EXPECT_EQ(expectedSize, estimatedSize); + } +} + +HWTEST_F(BcsTests, givenImageAndBufferBlitDirectionsWhenIsImageOperationIsCalledThenReturnCorrectValue) { + + BlitProperties blitProperties{}; + std::pair params[] = {{false, BlitterConstants::BlitDirection::HostPtrToBuffer}, + {false, BlitterConstants::BlitDirection::BufferToHostPtr}, + {false, BlitterConstants::BlitDirection::BufferToBuffer}, + {true, BlitterConstants::BlitDirection::HostPtrToImage}, + {true, BlitterConstants::BlitDirection::ImageToHostPtr}, + {true, BlitterConstants::BlitDirection::ImageToImage}}; + + for (auto [isImageDirection, blitDirection] : params) { + blitProperties.blitDirection = blitDirection; + EXPECT_EQ(isImageDirection, blitProperties.isImageOperation()); + } +} + HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredCommands) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp index b1c5f6a463..d229964704 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp @@ -55,10 +55,10 @@ HWTEST_F(BcsTests, givenBltSizeWhenEstimatingCommandSizeThenAddAllRequiredComman auto alignedCopySize = Vec3{alignedBltSize, 1, 1}; auto notAlignedCopySize = Vec3{notAlignedBltSize, 1, 1}; - auto alignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - alignedCopySize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment()); - auto notAlignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - notAlignedCopySize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment()); + auto alignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + alignedCopySize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment()); + auto notAlignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + notAlignedCopySize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedAlignedSize, alignedEstimatedSize); EXPECT_EQ(expectedNotAlignedSize, notAlignedEstimatedSize); @@ -116,10 +116,10 @@ HWTEST_F(BcsTests, givenBltSizeWhenEstimatingCommandSizeForReadBufferRectThenAdd expectedNotAlignedSize += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); } - auto alignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - alignedBltSize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment()); - auto notAlignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - notAlignedBltSize, csrDependencies, false, false, pClDevice->getRootDeviceEnvironment()); + auto alignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + alignedBltSize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment()); + auto notAlignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + notAlignedBltSize, csrDependencies, false, false, false, pClDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedAlignedSize, alignedEstimatedSize); EXPECT_EQ(expectedNotAlignedSize, notAlignedEstimatedSize); @@ -154,10 +154,10 @@ HWTEST_F(BcsTests, givenBltWithBigCopySizeWhenEstimatingCommandSizeForReadBuffer expectedNotAlignedSize += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); } - auto alignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - alignedBltSize, csrDependencies, false, false, rootDeviceEnvironment); - auto notAlignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandsSize( - notAlignedBltSize, csrDependencies, false, false, rootDeviceEnvironment); + auto alignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + alignedBltSize, csrDependencies, false, false, false, rootDeviceEnvironment); + auto notAlignedEstimatedSize = BlitCommandsHelper::estimateBlitCommandSize( + notAlignedBltSize, csrDependencies, false, false, false, rootDeviceEnvironment); EXPECT_EQ(expectedAlignedSize, alignedEstimatedSize); EXPECT_EQ(expectedNotAlignedSize, notAlignedEstimatedSize); diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index d696682db8..ff878e6568 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -1014,8 +1014,9 @@ uint32_t CommandStreamReceiverHw::flushBcsTask(const BlitPropertiesCo auto lock = obtainUniqueOwnership(); bool blitterDirectSubmission = this->isBlitterDirectSubmissionEnabled(); - auto &commandStream = getCS(BlitCommandsHelper::estimateBlitCommandsSize(blitPropertiesContainer, profilingEnabled, PauseOnGpuProperties::featureEnabled(DebugManager.flags.PauseOnBlitCopy.get()), - blitterDirectSubmission, *this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex])); + auto debugPauseEnabled = PauseOnGpuProperties::featureEnabled(DebugManager.flags.PauseOnBlitCopy.get()); + auto &commandStream = getCS(BlitCommandsHelper::estimateBlitCommandsSize(blitPropertiesContainer, profilingEnabled, debugPauseEnabled, blitterDirectSubmission, + *this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex])); auto commandStreamStart = commandStream.getUsed(); auto newTaskCount = taskCount + 1; latestSentTaskCount = newTaskCount; diff --git a/shared/source/helpers/blit_commands_helper.h b/shared/source/helpers/blit_commands_helper.h index 95b5e50bb1..53cfe8c98e 100644 --- a/shared/source/helpers/blit_commands_helper.h +++ b/shared/source/helpers/blit_commands_helper.h @@ -62,7 +62,7 @@ struct BlitProperties { CommandStreamReceiver &gpguCsr, CommandStreamReceiver &bcsCsr); TagNodeBase *outputTimestampPacket = nullptr; - BlitterConstants::BlitDirection blitDirection; + BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::BufferToHostPtr; CsrDependencies csrDependencies; AuxTranslationDirection auxTranslationDirection = AuxTranslationDirection::None; @@ -83,6 +83,12 @@ struct BlitProperties { Vec3 dstSize = 0; Vec3 srcSize = 0; size_t bytesPerPixel = 1; + + bool isImageOperation() const { + return blitDirection == BlitterConstants::BlitDirection::HostPtrToImage || + blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr || + blitDirection == BlitterConstants::BlitDirection::ImageToImage; + } }; enum class BlitOperationResult { @@ -118,8 +124,8 @@ struct BlitCommandsHelper { static size_t estimatePreBlitCommandSize(); static void dispatchPostBlitCommand(LinearStream &linearStream, const HardwareInfo &hwInfo); static size_t estimatePostBlitCommandSize(); - static size_t estimateBlitCommandsSize(const Vec3 ©Size, const CsrDependencies &csrDependencies, bool updateTimestampPacket, - bool profilingEnabled, const RootDeviceEnvironment &rootDeviceEnvironment); + static size_t estimateBlitCommandSize(const Vec3 ©Size, const CsrDependencies &csrDependencies, bool updateTimestampPacket, + bool profilingEnabled, bool isImage, const RootDeviceEnvironment &rootDeviceEnvironment); static size_t estimateBlitCommandsSize(const BlitPropertiesContainer &blitPropertiesContainer, bool profilingEnabled, bool debugPauseEnabled, bool blitterDirectSubmission, const RootDeviceEnvironment &rootDeviceEnvironment); static size_t getNumberOfBlitsForCopyRegion(const Vec3 ©Size, const RootDeviceEnvironment &rootDeviceEnvironment); diff --git a/shared/source/helpers/blit_commands_helper_base.inl b/shared/source/helpers/blit_commands_helper_base.inl index 370d064d97..6f0d65770c 100644 --- a/shared/source/helpers/blit_commands_helper_base.inl +++ b/shared/source/helpers/blit_commands_helper_base.inl @@ -101,9 +101,8 @@ size_t BlitCommandsHelper::estimatePostBlitCommandSize() { } template -size_t BlitCommandsHelper::estimateBlitCommandsSize(const Vec3 ©Size, const CsrDependencies &csrDependencies, - bool updateTimestampPacket, bool profilingEnabled, - const RootDeviceEnvironment &rootDeviceEnvironment) { +size_t BlitCommandsHelper::estimateBlitCommandSize(const Vec3 ©Size, const CsrDependencies &csrDependencies, + bool updateTimestampPacket, bool profilingEnabled, bool isImage, const RootDeviceEnvironment &rootDeviceEnvironment) { size_t timestampCmdSize = 0; if (updateTimestampPacket) { timestampCmdSize += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); @@ -112,12 +111,19 @@ size_t BlitCommandsHelper::estimateBlitCommandsSize(const Vec3(csrDependencies) + TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer(csrDependencies) + (sizePerBlit * nBlits) + @@ -131,17 +137,14 @@ size_t BlitCommandsHelper::estimateBlitCommandsSize(const BlitPropert bool blitterDirectSubmission, const RootDeviceEnvironment &rootDeviceEnvironment) { size_t size = 0; for (auto &blitProperties : blitPropertiesContainer) { - size += BlitCommandsHelper::estimateBlitCommandsSize(blitProperties.copySize, blitProperties.csrDependencies, - blitProperties.outputTimestampPacket != nullptr, profilingEnabled, - rootDeviceEnvironment); + auto updateTimestampPacket = blitProperties.outputTimestampPacket != nullptr; + auto isImage = blitProperties.isImageOperation(); + size += BlitCommandsHelper::estimateBlitCommandSize(blitProperties.copySize, blitProperties.csrDependencies, updateTimestampPacket, + profilingEnabled, isImage, rootDeviceEnvironment); } size += MemorySynchronizationCommands::getSizeForAdditonalSynchronization(*rootDeviceEnvironment.getHardwareInfo()); size += EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(); - if (blitterDirectSubmission) { - size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_START); - } else { - size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_END); - } + size += blitterDirectSubmission ? sizeof(typename GfxFamily::MI_BATCH_BUFFER_START) : sizeof(typename GfxFamily::MI_BATCH_BUFFER_END); if (debugPauseEnabled) { size += BlitCommandsHelper::getSizeForDebugPauseCommands(); @@ -337,10 +340,7 @@ uint32_t BlitCommandsHelper::getAvailableBytesPerPixel(size_t copySiz template void BlitCommandsHelper::dispatchBlitCommands(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) { - - if (blitProperties.blitDirection == BlitterConstants::BlitDirection::HostPtrToImage || - blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr || - blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) { + if (blitProperties.isImageOperation()) { dispatchBlitCommandsForImageRegion(blitProperties, linearStream, rootDeviceEnvironment); } else { bool preferCopyBufferRegion = isCopyRegionPreferred(blitProperties.copySize, rootDeviceEnvironment);