/* * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/helpers/blit_commands_helper.h" #include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/helpers/blit_commands_helper_tests.inl" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_gmm.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "gtest/gtest.h" #include using namespace NEO; using BlitTests = Test; HWTEST2_F(BlitTests, givenOneBytePerPixelWhenAppendColorDepthThenCorrectDepthIsSet, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.bytesPerPixel = 1; BlitCommandsHelper::appendColorDepth(properties, bltCmd); EXPECT_EQ(bltCmd.getColorDepth(), XY_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_8_BIT_COLOR); } HWTEST2_F(BlitTests, givenTwoBytePerPixelWhenAppendColorDepthThenCorrectDepthIsSet, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.bytesPerPixel = 2; BlitCommandsHelper::appendColorDepth(properties, bltCmd); EXPECT_EQ(bltCmd.getColorDepth(), XY_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_16_BIT_COLOR); } HWTEST2_F(BlitTests, givenFourBytePerPixelWhenAppendColorDepthThenCorrectDepthIsSet, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.bytesPerPixel = 4; BlitCommandsHelper::appendColorDepth(properties, bltCmd); EXPECT_EQ(bltCmd.getColorDepth(), XY_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_32_BIT_COLOR); } HWTEST2_F(BlitTests, givenEightBytePerPixelWhenAppendColorDepthThenCorrectDepthIsSet, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.bytesPerPixel = 8; BlitCommandsHelper::appendColorDepth(properties, bltCmd); EXPECT_EQ(bltCmd.getColorDepth(), XY_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_64_BIT_COLOR); } HWTEST2_F(BlitTests, givenSixteenBytePerPixelWhenAppendColorDepthThenCorrectDepthIsSet, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.bytesPerPixel = 16; BlitCommandsHelper::appendColorDepth(properties, bltCmd); EXPECT_EQ(bltCmd.getColorDepth(), XY_COPY_BLT::COLOR_DEPTH::COLOR_DEPTH_128_BIT_COLOR); } HWTEST2_F(BlitTests, givenIncorrectBytePerPixelWhenAppendColorDepthThenAbortIsThrown, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.bytesPerPixel = 48; EXPECT_THROW(BlitCommandsHelper::appendColorDepth(properties, bltCmd), std::exception); } HWTEST2_F(BlitTests, givenSrcAndDestinationImagesWhenAppendSliceOffsetsThenAdressAreCorectOffseted, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto gmm = std::make_unique(pDevice->getGmmClientContext()); MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); mockAllocationSrc.setGmm(gmm.get(), 0); mockAllocationDst.setGmm(gmm.get(), 0); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; properties.srcGpuAddress = mockAllocationSrc.getGpuAddress(); properties.dstGpuAddress = mockAllocationDst.getGpuAddress(); properties.srcSize.y = 0x10; properties.srcRowPitch = 0x10; auto srcSlicePitch = static_cast(properties.srcSize.y * properties.srcRowPitch); properties.dstSize.y = 0x20; properties.dstRowPitch = 0x20; auto dstSlicePitch = static_cast(properties.dstSize.y * properties.dstRowPitch); properties.srcOffset = {0x10, 0x10, 0x10}; properties.dstOffset = {0x20, 0x20, 0x20}; uint32_t index = 7; BlitCommandsHelper::appendSliceOffsets(properties, bltCmd, index, pDevice->getRootDeviceEnvironment(), srcSlicePitch, 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)); } HWTEST2_F(BlitTests, givenInputAndDefaultSlicePitchWhenAppendBlitCommandsForImagesThenSlicePitchesAreCorrect, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; properties.srcSize = {10, 10, 1}; properties.dstSize = {8, 12, 1}; properties.srcRowPitch = 0x10; properties.dstRowPitch = 0x40; { uint32_t inputSlicePitch = 0; auto srcSlicePitch = inputSlicePitch; auto dstSlicePitch = inputSlicePitch; BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); EXPECT_EQ(srcSlicePitch, static_cast(properties.srcRowPitch * properties.srcSize.y)); EXPECT_EQ(dstSlicePitch, static_cast(properties.dstRowPitch * properties.dstSize.y)); } { uint32_t inputSlicePitch = 0x40000; auto srcSlicePitch = inputSlicePitch; auto dstSlicePitch = inputSlicePitch; BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); EXPECT_EQ(srcSlicePitch, inputSlicePitch); EXPECT_EQ(dstSlicePitch, inputSlicePitch); } } struct MyMockResourecInfo : public GmmResourceInfo { using GmmResourceInfo::resourceInfo; MyMockResourecInfo(GmmClientContext *clientContext, GMM_RESCREATE_PARAMS *inputParams) : GmmResourceInfo(clientContext, inputParams){}; MyMockResourecInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) : GmmResourceInfo(clientContext, inputGmmResourceInfo){}; size_t getRenderPitch() override { return pitch; } uint32_t getQPitch() override { return 0; } GMM_RESOURCE_FLAG *getResourceFlags() override { return &flags; } uint32_t getMipTailStartLodSurfaceState() override { return 0; } size_t pitch = 0; GMM_RESOURCE_FLAG flags = {}; }; HWTEST2_F(BlitTests, givenTiledSrcAndDestinationImagesWhenAppendImageCommandsThenPitchIsValueFromGmm, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto gmm = std::make_unique(pDevice->getGmmClientContext()); GMM_RESCREATE_PARAMS gmmParams = {}; auto myResourecInfo = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); myResourecInfo->pitch = 0x100; myResourecInfo->flags.Info.TiledY = 1; gmm->gmmResourceInfo.reset(myResourecInfo.release()); MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); mockAllocationSrc.setGmm(gmm.get(), 0); mockAllocationDst.setGmm(gmm.get(), 0); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; properties.srcRowPitch = 0x1000; properties.dstRowPitch = 0x4000; auto srcSlicePitch = static_cast(properties.srcSlicePitch); auto dstSlicePitch = static_cast(properties.dstSlicePitch); BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); EXPECT_EQ(bltCmd.getDestinationPitch(), gmm->gmmResourceInfo->getRenderPitch()); EXPECT_EQ(bltCmd.getSourcePitch(), gmm->gmmResourceInfo->getRenderPitch()); EXPECT_NE(bltCmd.getDestinationPitch(), static_cast(properties.dstRowPitch)); EXPECT_NE(bltCmd.getSourcePitch(), static_cast(properties.srcRowPitch)); } HWTEST2_F(BlitTests, givenLinearSrcAndDestinationImagesWhenAppendImageCommandsThenPitchIsValueFromProperties, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto gmm = std::make_unique(pDevice->getGmmClientContext()); GMM_RESCREATE_PARAMS gmmParams = {}; auto myResourecInfo = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); myResourecInfo->pitch = 0x100; myResourecInfo->flags.Info.Linear = 1; gmm->gmmResourceInfo.reset(myResourecInfo.release()); MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); mockAllocationSrc.setGmm(gmm.get(), 0); mockAllocationDst.setGmm(gmm.get(), 0); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; properties.srcRowPitch = 0x1000; properties.dstRowPitch = 0x4000; auto srcSlicePitch = static_cast(properties.srcSlicePitch); auto dstSlicePitch = static_cast(properties.dstSlicePitch); BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); EXPECT_NE(bltCmd.getDestinationPitch(), gmm->gmmResourceInfo->getRenderPitch()); EXPECT_NE(bltCmd.getSourcePitch(), gmm->gmmResourceInfo->getRenderPitch()); EXPECT_EQ(bltCmd.getDestinationPitch(), static_cast(properties.dstRowPitch)); EXPECT_EQ(bltCmd.getSourcePitch(), static_cast(properties.srcRowPitch)); } HWTEST2_F(BlitTests, givenBlitCommandWhenAppendClearColorCalledThenNothingHappens, IsGen12LP) { auto bltCmd = FamilyType::cmdInitXyCopyBlt; auto expectedBlitCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; BlitCommandsHelper::appendClearColor(properties, bltCmd); EXPECT_EQ(0, std::memcmp(&expectedBlitCmd, &bltCmd, sizeof(bltCmd))); } HWTEST2_F(BlitTests, givenGen12LpPlatformWhenPreBlitCommandWARequiredThenReturnsTrue, IsGen12LP) { EXPECT_TRUE(BlitCommandsHelper::preBlitCommandWARequired()); } HWTEST2_F(BlitTests, givenGen12LpPlatformWhenEstimatePreBlitCommandSizeThenSizeOfFlushIsReturned, IsGen12LP) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; EXPECT_EQ(EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite(), BlitCommandsHelper::estimatePreBlitCommandSize()); } HWTEST2_F(BlitTests, givenGen12LpPlatformWhenDispatchPreBlitCommandThenMiFlushDwIsProgramed, IsGen12LP) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; auto miFlushBuffer = std::make_unique(); LinearStream linearStream(miFlushBuffer.get(), EncodeMiFlushDW::getMiFlushDwCmdSizeForDataWrite()); BlitCommandsHelper::dispatchPreBlitCommand(linearStream); HardwareParse hwParser; hwParser.parseCommands(linearStream); auto cmdIterator = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); ASSERT_NE(hwParser.cmdList.end(), cmdIterator); }