From dd1e85a3d4fdcc095139487074d63727dc8e689a Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Mon, 3 Feb 2025 11:36:01 +0000 Subject: [PATCH] fix: bcs mem fill pattern alignment Related-To: NEO-13928 Signed-off-by: Bartosz Dunajski --- .../hw_cmds_generated_xe2_hpg_core.inl | 2 +- .../xe3_core/hw_cmds_generated_xe3_core.inl | 2 +- .../helpers/blit_commands_helper_base.inl | 8 +++--- .../helpers/blit_commands_helper_tests.cpp | 27 +++++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/shared/source/generated/xe2_hpg_core/hw_cmds_generated_xe2_hpg_core.inl b/shared/source/generated/xe2_hpg_core/hw_cmds_generated_xe2_hpg_core.inl index d631ed5163..827c274fed 100644 --- a/shared/source/generated/xe2_hpg_core/hw_cmds_generated_xe2_hpg_core.inl +++ b/shared/source/generated/xe2_hpg_core/hw_cmds_generated_xe2_hpg_core.inl @@ -4617,7 +4617,7 @@ typedef struct tagXY_FAST_COLOR_BLT { return static_cast(TheStructure.Common.Client); } inline void setDestinationPitch(const uint32_t value) { - UNRECOVERABLE_IF(value > 0x3ffff); + UNRECOVERABLE_IF(value > 0x3ffff + 1); // patched TheStructure.Common.DestinationPitch = value - 1; } inline uint32_t getDestinationPitch() const { diff --git a/shared/source/generated/xe3_core/hw_cmds_generated_xe3_core.inl b/shared/source/generated/xe3_core/hw_cmds_generated_xe3_core.inl index 6d64419c9f..9d00d77d31 100644 --- a/shared/source/generated/xe3_core/hw_cmds_generated_xe3_core.inl +++ b/shared/source/generated/xe3_core/hw_cmds_generated_xe3_core.inl @@ -4605,7 +4605,7 @@ typedef struct tagXY_FAST_COLOR_BLT { return static_cast(TheStructure.Common.Client); } inline void setDestinationPitch(const uint32_t value) { - UNRECOVERABLE_IF(value > 0x3ffff); + UNRECOVERABLE_IF(value > 0x3ffff + 1); // patched TheStructure.Common.DestinationPitch = value - 1; } inline uint32_t getDestinationPitch() const { diff --git a/shared/source/helpers/blit_commands_helper_base.inl b/shared/source/helpers/blit_commands_helper_base.inl index 18c24b1d60..0bff2b70d9 100644 --- a/shared/source/helpers/blit_commands_helper_base.inl +++ b/shared/source/helpers/blit_commands_helper_base.inl @@ -264,6 +264,7 @@ void BlitCommandsHelper::dispatchBlitMemoryFill(const BlitProperties const auto maxHeight = getMaxBlitHeight(rootDeviceEnvironment, true); auto colorDepth = COLOR_DEPTH::COLOR_DEPTH_128_BIT_COLOR; + size_t patternSize = 16; const LookupArray colorDepthLookup({{ {1, COLOR_DEPTH::COLOR_DEPTH_8_BIT_COLOR}, @@ -275,12 +276,13 @@ void BlitCommandsHelper::dispatchBlitMemoryFill(const BlitProperties auto colorDepthV = colorDepthLookup.find(blitProperties.fillPatternSize); if (colorDepthV.has_value()) { colorDepth = *colorDepthV; + patternSize = blitProperties.fillPatternSize; } blitCmd.setFillColor(blitProperties.fillPattern); blitCmd.setColorDepth(colorDepth); - uint64_t sizeToFill = blitProperties.copySize.x / blitProperties.fillPatternSize; + uint64_t sizeToFill = blitProperties.copySize.x / patternSize; uint64_t offset = blitProperties.dstOffset.x; while (sizeToFill != 0) { auto tmpCmd = blitCmd; @@ -299,7 +301,7 @@ void BlitCommandsHelper::dispatchBlitMemoryFill(const BlitProperties } tmpCmd.setDestinationX2CoordinateRight(static_cast(width)); tmpCmd.setDestinationY2CoordinateBottom(static_cast(height)); - tmpCmd.setDestinationPitch(static_cast(width * blitProperties.fillPatternSize)); + tmpCmd.setDestinationPitch(static_cast(width * patternSize)); appendBlitMemoryOptionsForFillBuffer(blitProperties.dstAllocation, tmpCmd, rootDeviceEnvironment); appendBlitFillCommand(blitProperties, tmpCmd); @@ -307,7 +309,7 @@ void BlitCommandsHelper::dispatchBlitMemoryFill(const BlitProperties auto cmd = linearStream.getSpaceForCmd(); *cmd = tmpCmd; auto blitSize = width * height; - offset += (blitSize * blitProperties.fillPatternSize); + offset += (blitSize * patternSize); sizeToFill -= blitSize; } } 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 5e24bc0c92..2140c323cb 100644 --- a/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp +++ b/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp @@ -264,6 +264,33 @@ HWTEST_F(BlitTests, givenMemoryWhenFillPatternWithBlitThenCommandIsProgrammed) { EXPECT_NE(cmdList.end(), itor); } +HWTEST_F(BlitTests, givenUnalignedPatternSizeWhenDispatchingBlitFillThenSetCorrectColorDepth) { + using XY_COLOR_BLT = typename FamilyType::XY_COLOR_BLT; + uint32_t pattern[4] = {1, 0, 0, 0}; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, 1u /*num gmms*/, AllocationType::internalHostMemory, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::system4KBPages, MemoryManager::maxOsContextCount); + + size_t copySize = 0x800'0000; + + auto blitProperties = BlitProperties::constructPropertiesForMemoryFill(&mockAllocation, copySize, pattern, 3, 0); + + BlitCommandsHelper::dispatchBlitMemoryColorFill(blitProperties, stream, pDevice->getRootDeviceEnvironmentRef()); + GenCmdList cmdList; + + ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(cmdList, stream.getCpuBase(), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), itor); + + auto cmd = genCmdCast(*itor); + EXPECT_EQ(cmd->getColorDepth(), XY_COLOR_BLT::COLOR_DEPTH::COLOR_DEPTH_128_BIT_COLOR); + EXPECT_EQ(cmd->getDestinationX2CoordinateRight(), 0x4000u); + EXPECT_EQ(cmd->getDestinationY2CoordinateBottom(), 0x200u); + EXPECT_EQ(cmd->getDestinationPitch(), 0x4000u * 16u); +} + HWTEST_F(BlitTests, givenMemorySizeBiggerThanMaxWidthButLessThanTwiceMaxWidthWhenFillPatternWithBlitThenHeightIsOne) { using XY_COLOR_BLT = typename FamilyType::XY_COLOR_BLT; uint32_t pattern[4] = {1, 0, 0, 0};