From 74c4536a8cb91329ec5505ba0cef38277b2a9915 Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Wed, 3 Jun 2020 14:42:08 +0200 Subject: [PATCH] Refactor blitter functions for images, make blitProperties const Change-Id: I5a9aa96771a6b29113bb81d39ec32adc6e3c778c Signed-off-by: Kamil Kopryk Related-To: NEO-4692 --- .../command_stream_receiver_hw_gen12lp.cpp | 97 ++++++++++--------- shared/source/helpers/blit_commands_helper.h | 5 +- .../helpers/blit_commands_helper_base.inl | 2 +- .../helpers/blit_commands_helper_bdw_plus.inl | 6 +- .../helpers/blit_commands_helper_tests.cpp | 24 ++++- .../blit_commands_helper_tests_gen12lp.cpp | 18 +++- 6 files changed, 95 insertions(+), 57 deletions(-) diff --git a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp index 83c6598530..c1490ea2bf 100644 --- a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp +++ b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp @@ -98,67 +98,70 @@ template <> void BlitCommandsHelper::appendSurfaceType(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd) { } +template <> +void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod) { + constexpr uint32_t TILED_Y_PITCH_ALIGNMENT = 128; + constexpr uint32_t NON_TILED_PITCH_ALIGNMENT = 16; + + if (allocation.getDefaultGmm()) { + auto gmmResInfo = allocation.getDefaultGmm()->gmmResourceInfo.get(); + auto resInfo = gmmResInfo->getResourceFlags()->Info; + if (resInfo.TiledY) { + tileType = GMM_TILED_Y; + pitch = static_cast(gmmResInfo->getRenderPitch()); + pitch = alignUp(pitch, TILED_Y_PITCH_ALIGNMENT); + qPitch = static_cast(gmmResInfo->getQPitch()); + } else { + pitch = alignUp(pitch, NON_TILED_PITCH_ALIGNMENT); + } + } +} + template <> void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, uint32_t sliceIndex) { using XY_COPY_BLT = typename Family::XY_COPY_BLT; - auto dstAllocation = blitProperties.dstAllocation; auto srcAllocation = blitProperties.srcAllocation; + auto dstAllocation = blitProperties.dstAllocation; + auto srcQPitch = blitProperties.srcSize.y; + auto dstQPitch = blitProperties.dstSize.y; + auto srcPitch = static_cast(blitProperties.srcRowPitch); + auto dstPitch = static_cast(blitProperties.dstRowPitch); + auto tileType = GMM_NOT_TILED; + uint32_t mipTailLod = 0; - size_t srcOffset = blitProperties.srcSlicePitch * (sliceIndex + static_cast(blitProperties.srcOffset.z)); - size_t dstOffset = blitProperties.dstSlicePitch * (sliceIndex + static_cast(blitProperties.dstOffset.z)); + getBlitAllocationProperties(*srcAllocation, srcPitch, srcQPitch, tileType, mipTailLod); + getBlitAllocationProperties(*dstAllocation, dstPitch, dstQPitch, tileType, mipTailLod); + + auto srcSlicePitch = srcPitch * srcQPitch; + auto dstSlicePitch = dstPitch * dstQPitch; + + size_t srcOffset = srcSlicePitch * (sliceIndex + blitProperties.srcOffset.z); + size_t dstOffset = dstSlicePitch * (sliceIndex + blitProperties.dstOffset.z); blitCmd.setSourceBaseAddress(ptrOffset(srcAllocation->getGpuAddress(), srcOffset)); blitCmd.setDestinationBaseAddress(ptrOffset(dstAllocation->getGpuAddress(), dstOffset)); } template <> -void BlitCommandsHelper::appendBlitCommandsForImages(BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd) { - uint32_t dstPitch = static_cast(blitProperties.dstRowPitch); - uint32_t srcPitch = static_cast(blitProperties.srcRowPitch); - uint32_t dstQPitch = static_cast(blitProperties.dstSize.y); - uint32_t srcQPitch = static_cast(blitProperties.srcSize.y); - auto dstAllocation = blitProperties.dstAllocation; +void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd) { + auto srcTileType = GMM_NOT_TILED; + auto dstTileType = GMM_NOT_TILED; auto srcAllocation = blitProperties.srcAllocation; - GMM_TILE_TYPE dstTileType = GMM_NOT_TILED; - GMM_TILE_TYPE srcTileType = GMM_NOT_TILED; + auto dstAllocation = blitProperties.dstAllocation; + auto srcQPitch = blitProperties.srcSize.y; + auto dstQPitch = blitProperties.dstSize.y; + auto srcPitch = static_cast(blitProperties.srcRowPitch); + auto dstPitch = static_cast(blitProperties.dstRowPitch); + uint32_t mipTailLod = 0; - constexpr uint32_t TILED_Y_PITCH_ALIGNMENT = 128; - constexpr uint32_t NON_TILED_PITCH_ALIGNMENT = 16; + getBlitAllocationProperties(*srcAllocation, srcPitch, srcQPitch, srcTileType, mipTailLod); + getBlitAllocationProperties(*dstAllocation, dstPitch, dstQPitch, dstTileType, mipTailLod); - if (dstAllocation->getDefaultGmm()) { - auto dstResInfo = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFlags()->Info; - if (dstResInfo.TiledY) { - dstTileType = GMM_TILED_Y; - dstPitch = static_cast(dstAllocation->getDefaultGmm()->gmmResourceInfo->getRenderPitch()); - dstQPitch = static_cast(dstAllocation->getDefaultGmm()->gmmResourceInfo->getQPitch()); - dstPitch = alignUp(dstPitch, TILED_Y_PITCH_ALIGNMENT); - } else { - dstPitch = alignUp(dstPitch, NON_TILED_PITCH_ALIGNMENT); - } - } - if (srcAllocation->getDefaultGmm()) { - auto srcResInfo = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFlags()->Info; - if (srcResInfo.TiledY) { - srcTileType = GMM_TILED_Y; - srcPitch = static_cast(srcAllocation->getDefaultGmm()->gmmResourceInfo->getRenderPitch()); - srcQPitch = static_cast(srcAllocation->getDefaultGmm()->gmmResourceInfo->getQPitch()); - srcPitch = alignUp(srcPitch, TILED_Y_PITCH_ALIGNMENT); - } else { - srcPitch = alignUp(srcPitch, NON_TILED_PITCH_ALIGNMENT); - } - } - blitProperties.srcSlicePitch = srcPitch * srcQPitch; - blitProperties.dstSlicePitch = dstPitch * dstQPitch; - if (dstTileType != GMM_NOT_TILED) { - blitCmd.setDestinationPitch(dstPitch / 4); - } else { - blitCmd.setDestinationPitch(dstPitch); - } - if (srcTileType != GMM_NOT_TILED) { - blitCmd.setSourcePitch(srcPitch / 4); - } else { - blitCmd.setSourcePitch(srcPitch); - } + srcPitch = (srcTileType == GMM_NOT_TILED) ? srcPitch : srcPitch / 4; + dstPitch = (srcTileType == GMM_NOT_TILED) ? dstPitch : dstPitch / 4; + + blitCmd.setSourcePitch(srcPitch); + blitCmd.setDestinationPitch(dstPitch); appendTilingType(srcTileType, dstTileType, blitCmd); } diff --git a/shared/source/helpers/blit_commands_helper.h b/shared/source/helpers/blit_commands_helper.h index 7e271b435b..f15aa85bc6 100644 --- a/shared/source/helpers/blit_commands_helper.h +++ b/shared/source/helpers/blit_commands_helper.h @@ -88,17 +88,18 @@ struct BlitCommandsHelper { static uint64_t calculateBlitCommandDestinationBaseAddress(const BlitProperties &blitProperties, uint64_t offset, uint64_t row, uint64_t slice); static uint64_t calculateBlitCommandSourceBaseAddress(const BlitProperties &blitProperties, uint64_t offset, uint64_t row, uint64_t slice); static void dispatchBlitCommandsForBuffer(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment); - static void dispatchBlitCommandsForImages(BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment); + static void dispatchBlitCommandsForImages(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment); static void dispatchBlitMemoryColorFill(NEO::GraphicsAllocation *dstAlloc, uint32_t *pattern, size_t patternSize, LinearStream &linearStream, size_t size, const RootDeviceEnvironment &rootDeviceEnvironment); template static void dispatchBlitMemoryFill(NEO::GraphicsAllocation *dstAlloc, uint32_t *pattern, LinearStream &linearStream, size_t size, const RootDeviceEnvironment &rootDeviceEnvironment, COLOR_DEPTH depth); static void appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); - static void appendBlitCommandsForImages(BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); + static void appendBlitCommandsForImages(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); static void appendColorDepth(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); static void appendBlitCommandsForFillBuffer(NEO::GraphicsAllocation *dstAlloc, typename GfxFamily::XY_COLOR_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); static void appendSurfaceType(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); static void appendTilingEnable(typename GfxFamily::XY_COLOR_BLT &blitCmd); static void appendTilingType(const GMM_TILE_TYPE srcTilingType, const GMM_TILE_TYPE dstTilingType, typename GfxFamily::XY_COPY_BLT &blitCmd); static void appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, uint32_t sliceIndex); + static void getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod); }; } // namespace NEO diff --git a/shared/source/helpers/blit_commands_helper_base.inl b/shared/source/helpers/blit_commands_helper_base.inl index 8d17ed4a9f..f34a56cb42 100644 --- a/shared/source/helpers/blit_commands_helper_base.inl +++ b/shared/source/helpers/blit_commands_helper_base.inl @@ -221,7 +221,7 @@ void BlitCommandsHelper::dispatchBlitMemoryFill(NEO::GraphicsAllocati } template -void BlitCommandsHelper::dispatchBlitCommandsForImages(BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) { +void BlitCommandsHelper::dispatchBlitCommandsForImages(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) { auto dstAllocation = blitProperties.dstAllocation; auto srcAllocation = blitProperties.srcAllocation; diff --git a/shared/source/helpers/blit_commands_helper_bdw_plus.inl b/shared/source/helpers/blit_commands_helper_bdw_plus.inl index 756a79a06f..79ad6bdfb3 100644 --- a/shared/source/helpers/blit_commands_helper_bdw_plus.inl +++ b/shared/source/helpers/blit_commands_helper_bdw_plus.inl @@ -13,7 +13,7 @@ template void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment) {} template -void BlitCommandsHelper::appendBlitCommandsForImages(BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd) { +void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd) { appendTilingType(GMM_NOT_TILED, GMM_NOT_TILED, blitCmd); } @@ -59,4 +59,8 @@ template void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, uint32_t sliceIndex) { } +template +void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod) { +} + } // namespace NEO 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 7417eae3d3..d655003694 100644 --- a/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp +++ b/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp @@ -276,4 +276,26 @@ HWTEST2_F(BlitTests, givenMemoryAndImageWhenDispatchCopyImageCallThenCommandAdde cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); auto itor = find(cmdList.begin(), cmdList.end()); EXPECT_NE(cmdList.end(), itor); -} \ No newline at end of file +} + +HWTEST2_F(BlitTests, givenGen9AndGetBlitAllocationPropertiesThenCorrectValuesAreReturned, IsGen9) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + + MockGraphicsAllocation alloc; + uint32_t pitch = 0x10; + uint32_t qPitch = 0x20; + GMM_TILE_TYPE tileType = GMM_NOT_TILED; + uint32_t mipTailLod = 0; + + auto expectedPitch = pitch; + auto expectedQPitch = qPitch; + auto expectedtileType = tileType; + auto expectedMipTailLod = mipTailLod; + + NEO::BlitCommandsHelper::getBlitAllocationProperties(alloc, pitch, qPitch, tileType, mipTailLod); + + EXPECT_EQ(expectedPitch, pitch); + EXPECT_EQ(expectedQPitch, qPitch); + EXPECT_EQ(expectedtileType, tileType); + EXPECT_EQ(expectedMipTailLod, mipTailLod); +} diff --git a/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp b/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp index fbecff0588..8f40b0a25a 100644 --- a/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp +++ b/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp @@ -149,14 +149,22 @@ HWTEST2_F(BlitTests, givenSrcAndDestinationImagesWhenAppendSliceOffsetsThenAdres BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; - properties.dstSlicePitch = 0x1000; - properties.srcSlicePitch = 0x2000; + + properties.srcSize.y = 0x10; + properties.srcRowPitch = 0x10; + auto srcSlicePitch = properties.srcSize.y * properties.srcRowPitch; + + properties.dstSize.y = 0x20; + properties.dstRowPitch = 0x20; + auto dstSlicePitch = properties.dstSize.y * properties.dstRowPitch; + properties.srcOffset = {0x10, 0x10, 0x10}; properties.dstOffset = {0x20, 0x20, 0x20}; uint32_t index = 7; BlitCommandsHelper::appendSliceOffsets(properties, bltCmd, index); - auto expectesSrcOffset = (index + properties.srcOffset.z) * properties.srcSlicePitch; - auto expectesDstOffset = (index + properties.dstOffset.z) * properties.dstSlicePitch; + auto expectesSrcOffset = (index + properties.srcOffset.z) * srcSlicePitch; + auto expectesDstOffset = (index + properties.dstOffset.z) * dstSlicePitch; + EXPECT_EQ(bltCmd.getSourceBaseAddress(), ptrOffset(mockAllocationSrc.getGpuAddress(), expectesSrcOffset)); EXPECT_EQ(bltCmd.getDestinationBaseAddress(), ptrOffset(mockAllocationDst.getGpuAddress(), expectesDstOffset)); } @@ -263,4 +271,4 @@ HWTEST2_F(BlitTests, givenTiledSrcAndDestinationWhenGmmReturnsNotAlignedPitchThe BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); EXPECT_EQ(bltCmd.getDestinationPitch(), expectedPitch / sizeof(uint32_t)); EXPECT_EQ(bltCmd.getSourcePitch(), expectedPitch / sizeof(uint32_t)); -} \ No newline at end of file +}