Add batch buffer start/end encoder

Change-Id: Id959f9692f0f23cb1c2c8a12a51a031e39019351
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka 2020-01-28 13:50:19 +01:00 committed by sys_ocldev
parent bb8dd181a7
commit 8b53126102
8 changed files with 132 additions and 0 deletions

View File

@ -181,4 +181,15 @@ struct EncodeAtomic {
DATA_SIZE dataSize); DATA_SIZE dataSize);
}; };
template <typename GfxFamily>
struct EncodeBatchBufferStartOrEnd {
using MI_BATCH_BUFFER_START = typename GfxFamily::MI_BATCH_BUFFER_START;
using MI_BATCH_BUFFER_END = typename GfxFamily::MI_BATCH_BUFFER_END;
static void programBatchBufferStart(LinearStream *commandStream,
uint64_t address,
bool secondLevel);
static void programBatchBufferEnd(CommandContainer &container);
};
} // namespace NEO } // namespace NEO

View File

@ -314,4 +314,25 @@ void EncodeAtomic<Family>::programMiAtomic(MI_ATOMIC *atomic, uint64_t writeAddr
atomic->setMemoryAddressHigh(static_cast<uint32_t>(writeAddress >> 32)); atomic->setMemoryAddressHigh(static_cast<uint32_t>(writeAddress >> 32));
} }
template <typename Family>
void EncodeBatchBufferStartOrEnd<Family>::programBatchBufferStart(LinearStream *commandStream,
uint64_t address,
bool secondLevel) {
MI_BATCH_BUFFER_START cmd = Family::cmdInitBatchBufferStart;
if (secondLevel) {
cmd.setSecondLevelBatchBuffer(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER_SECOND_LEVEL_BATCH);
}
cmd.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
cmd.setBatchBufferStartAddressGraphicsaddress472(address);
auto buffer = commandStream->getSpaceForCmd<MI_BATCH_BUFFER_START>();
*reinterpret_cast<MI_BATCH_BUFFER_START *>(buffer) = cmd;
}
template <typename Family>
void EncodeBatchBufferStartOrEnd<Family>::programBatchBufferEnd(CommandContainer &container) {
MI_BATCH_BUFFER_END cmd = Family::cmdInitBatchBufferEnd;
auto buffer = container.getCommandStream()->getSpace(sizeof(cmd));
*reinterpret_cast<MI_BATCH_BUFFER_END *>(buffer) = cmd;
}
} // namespace NEO } // namespace NEO

View File

@ -27,4 +27,5 @@ template struct EncodeStoreMMIO<Family>;
template struct EncodeSurfaceState<Family>; template struct EncodeSurfaceState<Family>;
template struct EncodeAtomic<Family>; template struct EncodeAtomic<Family>;
template struct EncodeSempahore<Family>; template struct EncodeSempahore<Family>;
template struct EncodeBatchBufferStartOrEnd<Family>;
} // namespace NEO } // namespace NEO

View File

@ -47,5 +47,6 @@ template struct EncodeStoreMMIO<Family>;
template struct EncodeSurfaceState<Family>; template struct EncodeSurfaceState<Family>;
template struct EncodeAtomic<Family>; template struct EncodeAtomic<Family>;
template struct EncodeSempahore<Family>; template struct EncodeSempahore<Family>;
template struct EncodeBatchBufferStartOrEnd<Family>;
} // namespace NEO } // namespace NEO

View File

@ -28,5 +28,6 @@ template struct EncodeStoreMMIO<Family>;
template struct EncodeSurfaceState<Family>; template struct EncodeSurfaceState<Family>;
template struct EncodeAtomic<Family>; template struct EncodeAtomic<Family>;
template struct EncodeSempahore<Family>; template struct EncodeSempahore<Family>;
template struct EncodeBatchBufferStartOrEnd<Family>;
} // namespace NEO } // namespace NEO

View File

@ -28,4 +28,5 @@ template struct EncodeStoreMMIO<Family>;
template struct EncodeSurfaceState<Family>; template struct EncodeSurfaceState<Family>;
template struct EncodeAtomic<Family>; template struct EncodeAtomic<Family>;
template struct EncodeSempahore<Family>; template struct EncodeSempahore<Family>;
template struct EncodeBatchBufferStartOrEnd<Family>;
} // namespace NEO } // namespace NEO

View File

@ -7,6 +7,7 @@
set(NEO_CORE_ENCODERS_TESTS set(NEO_CORE_ENCODERS_TESTS
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_encode_atomic.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_atomic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_encode_command_buffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_encode_dispatch_kernel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_dispatch_kernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_encode_flush.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_flush.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_encode_math.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_math.cpp

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/command_container/cmdcontainer.h"
#include "core/command_container/command_encoder.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/gen_common/gen_cmd_parse.h"
using namespace NEO;
using EncodeBatchBufferStartOrEndTest = Test<DeviceFixture>;
HWTEST_F(EncodeBatchBufferStartOrEndTest, givenCommandContainerWhenEncodeBBEndThenCommandIsAdded) {
CommandContainer cmdContainer;
cmdContainer.initialize(pDevice);
EncodeBatchBufferStartOrEnd<FamilyType>::programBatchBufferEnd(cmdContainer);
GenCmdList commands;
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(cmdContainer.getCommandStream()->getCpuBase(), 0), cmdContainer.getCommandStream()->getUsed());
using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END;
auto itor = find<MI_BATCH_BUFFER_END *>(commands.begin(), commands.end());
ASSERT_NE(itor, commands.end());
}
HWTEST_F(EncodeBatchBufferStartOrEndTest, givenCommandContainerWhenEncodeBBStartThenCommandIsAdded) {
CommandContainer cmdContainer;
cmdContainer.initialize(pDevice);
EncodeBatchBufferStartOrEnd<FamilyType>::programBatchBufferStart(cmdContainer.getCommandStream(), 0, true);
GenCmdList commands;
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(cmdContainer.getCommandStream()->getCpuBase(), 0), cmdContainer.getCommandStream()->getUsed());
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START;
auto itor = find<MI_BATCH_BUFFER_START *>(commands.begin(), commands.end());
ASSERT_NE(itor, commands.end());
}
HWTEST_F(EncodeBatchBufferStartOrEndTest, givenCommandContainerWhenEncodeBBStartWithSecondLevelParameterThenCommandIsProgrammedCorrectly) {
CommandContainer cmdContainer;
cmdContainer.initialize(pDevice);
EncodeBatchBufferStartOrEnd<FamilyType>::programBatchBufferStart(cmdContainer.getCommandStream(), 0, true);
GenCmdList commands;
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(cmdContainer.getCommandStream()->getCpuBase(), 0), cmdContainer.getCommandStream()->getUsed());
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START;
auto itor = find<MI_BATCH_BUFFER_START *>(commands.begin(), commands.end());
ASSERT_NE(itor, commands.end());
{
auto cmd = genCmdCast<MI_BATCH_BUFFER_START *>(*itor);
EXPECT_EQ(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER_SECOND_LEVEL_BATCH, cmd->getSecondLevelBatchBuffer());
}
}
HWTEST_F(EncodeBatchBufferStartOrEndTest, givenCommandContainerWhenEncodeBBStartWithFirstLevelParameterThenCommandIsProgrammedCorrectly) {
CommandContainer cmdContainer;
cmdContainer.initialize(pDevice);
EncodeBatchBufferStartOrEnd<FamilyType>::programBatchBufferStart(cmdContainer.getCommandStream(), 0, false);
GenCmdList commands;
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(cmdContainer.getCommandStream()->getCpuBase(), 0), cmdContainer.getCommandStream()->getUsed());
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START;
auto itor = find<MI_BATCH_BUFFER_START *>(commands.begin(), commands.end());
ASSERT_NE(itor, commands.end());
{
auto cmd = genCmdCast<MI_BATCH_BUFFER_START *>(*itor);
EXPECT_EQ(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER_FIRST_LEVEL_BATCH, cmd->getSecondLevelBatchBuffer());
}
}
HWTEST_F(EncodeBatchBufferStartOrEndTest, givenGpuAddressWhenEncodeBBStartThenAddressIsProgrammedCorrectly) {
CommandContainer cmdContainer;
cmdContainer.initialize(pDevice);
uint64_t gpuAddress = 12 * MemoryConstants::pageSize;
EncodeBatchBufferStartOrEnd<FamilyType>::programBatchBufferStart(cmdContainer.getCommandStream(), gpuAddress, false);
GenCmdList commands;
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(cmdContainer.getCommandStream()->getCpuBase(), 0), cmdContainer.getCommandStream()->getUsed());
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START;
auto itor = find<MI_BATCH_BUFFER_START *>(commands.begin(), commands.end());
ASSERT_NE(itor, commands.end());
{
auto cmd = genCmdCast<MI_BATCH_BUFFER_START *>(*itor);
EXPECT_EQ(gpuAddress, cmd->getBatchBufferStartAddressGraphicsaddress472());
}
}