/* * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/direct_submission/dispatchers/blitter_dispatcher.h" #include "shared/source/helpers/definitions/command_encoder_args.h" #include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/mocks/mock_command_encoder.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/unit_test/direct_submission/dispatchers/dispatcher_fixture.h" using namespace NEO; using BlitterDispatcheTest = Test; HWTEST_F(BlitterDispatcheTest, givenBlitterWhenAskingForPreemptionCmdSizeThenReturnZero) { EXPECT_EQ(0u, BlitterDispatcher::getSizePreemption()); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenDispatchingPreemptionCmdThenDispatchNothing) { BlitterDispatcher::dispatchPreemption(cmdBuffer); EXPECT_EQ(0u, cmdBuffer.getUsed()); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenAskingForMonitorFenceCmdSizeThenReturnExpectedNumberOfMiFlush) { EncodeDummyBlitWaArgs waArgs{false, &(pDevice->getRootDeviceEnvironmentRef())}; size_t expectedSize = EncodeMiFlushDW::getCommandSizeWithWa(waArgs); EXPECT_EQ(expectedSize, BlitterDispatcher::getSizeMonitorFence(pDevice->getRootDeviceEnvironment())); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenDispatchingMonitorFenceCmdThenDispatchMiFlushWithPostSync) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; EncodeDummyBlitWaArgs waArgs{false, &(pDevice->getRootDeviceEnvironmentRef())}; size_t expectedSize = EncodeMiFlushDW::getCommandSizeWithWa(waArgs); uint64_t expectedGpuAddress = 0x5100ull; uint64_t expectedValue = 0x1234ull; BlitterDispatcher::dispatchMonitorFence(cmdBuffer, expectedGpuAddress, expectedValue, pDevice->getRootDeviceEnvironment(), false, false, false); EXPECT_EQ(expectedSize, cmdBuffer.getUsed()); HardwareParse hwParse; hwParse.parseCommands(cmdBuffer); auto commandsList = hwParse.getCommandsList(); bool foundPostSync = false; for (auto &cmd : commandsList) { MI_FLUSH_DW *miFlush = static_cast(cmd); if (miFlush->getDestinationAddress() == expectedGpuAddress && miFlush->getImmediateData() == expectedValue) { foundPostSync = true; } } EXPECT_TRUE(foundPostSync); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenAskingForCacheFlushCmdSizeThenReturnExpetedSize) { EncodeDummyBlitWaArgs waArgs{false, &(pDevice->getRootDeviceEnvironmentRef())}; size_t expectedSize = EncodeMiFlushDW::getCommandSizeWithWa(waArgs); EXPECT_EQ(expectedSize, BlitterDispatcher::getSizeCacheFlush(pDevice->getRootDeviceEnvironment())); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenDispatchingCacheFlushCmdThenDispatchMiFlushCommand) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; EncodeDummyBlitWaArgs waArgs{false, &(pDevice->getRootDeviceEnvironmentRef())}; size_t expectedSize = EncodeMiFlushDW::getCommandSizeWithWa(waArgs); BlitterDispatcher::dispatchCacheFlush(cmdBuffer, pDevice->getRootDeviceEnvironment(), 0ull); EXPECT_EQ(expectedSize, cmdBuffer.getUsed()); HardwareParse hwParse; hwParse.parseCommands(cmdBuffer); auto commandsList = hwParse.getCommandsList(); EXPECT_LE(1u, commandsList.size()); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenDispatchingTlbFlushThenDispatchMiFlushCommandWithproperBits) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; EncodeDummyBlitWaArgs waArgs{false, &(pDevice->getRootDeviceEnvironmentRef())}; size_t expectedSize = EncodeMiFlushDW::getCommandSizeWithWa(waArgs); BlitterDispatcher::dispatchTlbFlush(cmdBuffer, 0ull, pDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedSize, cmdBuffer.getUsed()); HardwareParse hwParse; hwParse.parseCommands(cmdBuffer, MockEncodeMiFlushDW::getWaSize(waArgs)); auto miFlushDw = hwParse.getCommand(); EXPECT_TRUE(miFlushDw->getTlbInvalidate()); EXPECT_EQ(miFlushDw->getPostSyncOperation(), MI_FLUSH_DW::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA_QWORD); EXPECT_EQ(BlitterDispatcher::getSizeTlbFlush(pDevice->getRootDeviceEnvironment()), EncodeMiFlushDW::getCommandSizeWithWa(waArgs)); } HWTEST_F(BlitterDispatcheTest, givenBlitterWhenCheckingForMultiTileSynchronizationSupportThenExpectFalse) { EXPECT_FALSE(BlitterDispatcher::isMultiTileSynchronizationSupported()); }