diff --git a/opencl/test/unit_test/command_queue/enqueue_command_without_kernel_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_command_without_kernel_tests.cpp index 464dc37775..53871d01cd 100644 --- a/opencl/test/unit_test/command_queue/enqueue_command_without_kernel_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_command_without_kernel_tests.cpp @@ -8,9 +8,11 @@ #include "shared/source/helpers/timestamp_packet.h" #include "shared/source/memory_manager/surface.h" #include "shared/source/os_interface/os_context.h" +#include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/mocks/mock_csr.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" +#include "shared/test/common/mocks/mock_logical_state_helper.h" #include "shared/test/common/mocks/mock_timestamp_container.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/common/test_macros/test_checks_shared.h" @@ -60,6 +62,66 @@ HWTEST_F(EnqueueHandlerTest, GivenCommandStreamWithoutKernelWhenCommandEnqueuedT EXPECT_EQ(allocation->getTaskCount(mockCmdQ->getGpgpuCommandStreamReceiver().getOsContext().getContextId()), 1u); } +HWTEST_F(EnqueueHandlerTest, givenLogicalStateHelperWhenDispatchingCommandsThenAddLastCommand) { + using MI_NOOP = typename FamilyType::MI_NOOP; + + auto mockCmdQ = std::make_unique>(context, pClDevice, nullptr); + auto logicalStateHelper = new LogicalStateHelperMock(); + + auto &ultCsr = static_cast &>(mockCmdQ->getGpgpuCommandStreamReceiver()); + ultCsr.logicalStateHelper.reset(logicalStateHelper); + + auto surface = std::make_unique(); + EventsRequest eventsRequest(0, nullptr, nullptr); + EventBuilder eventBuilder; + Surface *surfaces[] = {surface.get()}; + bool blocking = true; + + TimestampPacketDependencies timestampPacketDependencies; + + CsrDependencies csrDeps; + EnqueueProperties enqueueProperties(false, false, false, true, false, nullptr); + + EXPECT_EQ(0u, logicalStateHelper->writeStreamInlineCalledCounter); + + mockCmdQ->enqueueCommandWithoutKernel(surfaces, 1, &mockCmdQ->getCS(0), 0, blocking, enqueueProperties, timestampPacketDependencies, + eventsRequest, eventBuilder, 0, csrDeps, nullptr); + + EXPECT_EQ(1u, logicalStateHelper->writeStreamInlineCalledCounter); + + HardwareParse cmdParser; + cmdParser.parseCommands(ultCsr.commandStream); + + auto miNoop = find(cmdParser.cmdList.begin(), cmdParser.cmdList.end()); + bool miNoopFound = false; + uint32_t cmdsAfterNoop = 0; + + while (miNoop != cmdParser.cmdList.end()) { + auto miNoopCmd = genCmdCast(*miNoop); + if (miNoopCmd->getIdentificationNumber() == 0x123) { + miNoopFound = true; + break; + } + + miNoop = find(++miNoop, cmdParser.cmdList.end()); + } + + miNoop++; + + while (miNoop != cmdParser.cmdList.end()) { + auto miNoopCmd = genCmdCast(*miNoop); + + if (miNoopCmd == nullptr) { + cmdsAfterNoop++; + } + + miNoop++; + } + + EXPECT_TRUE(miNoopFound); + EXPECT_EQ(1u, cmdsAfterNoop); +} + template struct EnqueueHandlerTimestampTest : public EnqueueHandlerTest { void SetUp() override { 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 5e470165a1..4ddeca33b5 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -533,6 +533,10 @@ CompletionStamp CommandStreamReceiverHw::flushTask( makeResident(*workPartitionAllocation); } + if (logicalStateHelper) { + logicalStateHelper->writeStreamInline(commandStreamCSR); + } + // If the CSR has work in its CS, flush it before the task bool submitTask = commandStreamStartTask != commandStreamTask.getUsed(); bool submitCSR = (commandStreamStartCSR != commandStreamCSR.getUsed()) || this->isMultiOsContextCapable(); diff --git a/shared/test/common/mocks/CMakeLists.txt b/shared/test/common/mocks/CMakeLists.txt index 0d16e91a91..fd358b01b5 100644 --- a/shared/test/common/mocks/CMakeLists.txt +++ b/shared/test/common/mocks/CMakeLists.txt @@ -66,6 +66,7 @@ set(NEO_CORE_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_io_functions.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel_info.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_logical_state_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_lrca_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_operations_handler.h diff --git a/shared/test/common/mocks/mock_logical_state_helper.h b/shared/test/common/mocks/mock_logical_state_helper.h new file mode 100644 index 0000000000..2a113ca769 --- /dev/null +++ b/shared/test/common/mocks/mock_logical_state_helper.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/command_stream/linear_stream.h" +#include "shared/source/helpers/logical_state_helper.h" + +#include "hw_cmds.h" + +namespace NEO { + +template +class LogicalStateHelperMock : public LogicalStateHelper { + public: + LogicalStateHelperMock() = default; + + void writeStreamInline(LinearStream &linearStream) override { + writeStreamInlineCalledCounter++; + + auto cmd = linearStream.getSpaceForCmd(); + *cmd = GfxFamily::cmdInitNoop; + cmd->setIdentificationNumber(0x123); + } + + uint32_t writeStreamInlineCalledCounter = 0; +}; +} // namespace NEO