diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_3_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_3_tests.cpp index 9814368163..eca0c6c641 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_3_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_3_tests.cpp @@ -147,6 +147,19 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndTwoRecord EXPECT_EQ(mockCsr->recordedCommandBuffer->batchBuffer.endCmdPtr, lastbbEndPtr); } +HWTEST_F(CommandStreamReceiverFlushTaskTests, whenFlushSmallTaskThenCommandStreamAlignedToCacheLine) { + using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; + auto &csr = pDevice->getUltCommandStreamReceiver(); + + auto &stream = csr.getCS(2 * MemoryConstants::cacheLineSize); + stream.getSpace(MemoryConstants::cacheLineSize - sizeof(MI_BATCH_BUFFER_END) - 2); + csr.flushSmallTask(stream, stream.getUsed()); + + auto used = csr.commandStream.getUsed(); + auto expected = 2 * MemoryConstants::cacheLineSize; + EXPECT_EQ(used, expected); +} + HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeRecordedCommandBuffersWhenFlushTaskIsCalledThenBatchBuffersAreCombined) { typedef typename FamilyType::MI_BATCH_BUFFER_END MI_BATCH_BUFFER_END; 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 ba9eecb7da..7dbaee6fc2 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -1284,6 +1284,7 @@ void CommandStreamReceiverHw::flushSemaphoreWait(GraphicsAllocation * template void CommandStreamReceiverHw::flushSmallTask(LinearStream &commandStreamTask, size_t commandStreamStartTask) { + using MI_BATCH_BUFFER_START = typename GfxFamily::MI_BATCH_BUFFER_START; using MI_BATCH_BUFFER_END = typename GfxFamily::MI_BATCH_BUFFER_END; void *endingCmdPtr = nullptr; @@ -1298,6 +1299,8 @@ void CommandStreamReceiverHw::flushSmallTask(LinearStream &commandStr *batchBufferEnd = GfxFamily::cmdInitBatchBufferEnd; } + auto bytesToPad = sizeof(MI_BATCH_BUFFER_START) - sizeof(MI_BATCH_BUFFER_END); + EncodeNoop::emitNoop(commandStreamTask, bytesToPad); EncodeNoop::alignToCacheLine(commandStreamTask); if (globalFenceAllocation) {