From f5b55c5c7e1db02d2a82789a4c8038e414b76582 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Mon, 22 Oct 2018 15:09:08 +0200 Subject: [PATCH] Remove code duplication from cmd_parse_genX files Change-Id: I64bb9d8be018ea4da6cb006439c58b1d52100e06 Signed-off-by: Filip Hazubski --- runtime/gen10/hw_cmds.h | 5 +- runtime/gen8/hw_cmds_base.h | 5 +- runtime/gen9/hw_cmds_base.h | 5 +- unit_tests/gen10/cmd_parse_gen10.cpp | 449 +----------------- unit_tests/gen10/gen_cmd_parse.h | 18 - unit_tests/gen8/cmd_parse_gen8.cpp | 422 +--------------- unit_tests/gen8/gen_cmd_parse.h | 33 -- unit_tests/gen9/cmd_parse_gen9.cpp | 449 +----------------- unit_tests/gen9/gen_cmd_parse.h | 33 -- unit_tests/gen_common/CMakeLists.txt | 7 +- unit_tests/gen_common/cmd_parse_base.inl | 267 +++++++++++ .../gen_common/cmd_parse_base_mi_arb.inl | 16 + .../gen_common/cmd_parse_gpgpu_walker.inl | 162 +++++++ unit_tests/gen_common/cmd_parse_sip.inl | 36 ++ unit_tests/gen_common/gen_cmd_parse.h | 84 +++- unit_tests/gen_common/gen_cmd_parse_base.h | 87 ---- unit_tests/libult/CMakeLists.txt | 2 +- .../linux/drm_command_stream_tests.cpp | 2 +- 18 files changed, 599 insertions(+), 1483 deletions(-) delete mode 100644 unit_tests/gen10/gen_cmd_parse.h delete mode 100644 unit_tests/gen8/gen_cmd_parse.h delete mode 100644 unit_tests/gen9/gen_cmd_parse.h create mode 100644 unit_tests/gen_common/cmd_parse_base.inl create mode 100644 unit_tests/gen_common/cmd_parse_base_mi_arb.inl create mode 100644 unit_tests/gen_common/cmd_parse_gpgpu_walker.inl create mode 100644 unit_tests/gen_common/cmd_parse_sip.inl delete mode 100644 unit_tests/gen_common/gen_cmd_parse_base.h diff --git a/runtime/gen10/hw_cmds.h b/runtime/gen10/hw_cmds.h index 145ea210dd..b51db4585a 100644 --- a/runtime/gen10/hw_cmds.h +++ b/runtime/gen10/hw_cmds.h @@ -13,7 +13,8 @@ #include "igfxfmid.h" #define TILERESOURCE_CHICKENBIT_VECTOR_ADDRESS 0x4DFC #define TILERESOURCE_CHICKENBIT_VECTOR_BITMASK (1UL << 8) -struct CnlParse; +template +struct CmdParse; namespace OCLRT { struct GEN10 { @@ -22,7 +23,7 @@ struct GEN10 { }; struct CNLFamily : public GEN10 { - using PARSE = CnlParse; + using PARSE = CmdParse; using GfxFamily = CNLFamily; using WALKER_TYPE = GPGPU_WALKER; static const GPGPU_WALKER cmdInitGpgpuWalker; diff --git a/runtime/gen8/hw_cmds_base.h b/runtime/gen8/hw_cmds_base.h index cd75a6e82e..bffb4bc9a0 100644 --- a/runtime/gen8/hw_cmds_base.h +++ b/runtime/gen8/hw_cmds_base.h @@ -13,7 +13,8 @@ #include "igfxfmid.h" //forward declaration for parsing logic -struct BdwParse; +template +struct CmdParse; namespace OCLRT { struct GEN8 { @@ -21,7 +22,7 @@ struct GEN8 { #include "runtime/gen8/hw_cmds_generated_patched.h" }; struct BDWFamily : public GEN8 { - using PARSE = BdwParse; + using PARSE = CmdParse; using GfxFamily = BDWFamily; using WALKER_TYPE = GPGPU_WALKER; static const GPGPU_WALKER cmdInitGpgpuWalker; diff --git a/runtime/gen9/hw_cmds_base.h b/runtime/gen9/hw_cmds_base.h index c7ae1159e4..a6cd4cf5cc 100644 --- a/runtime/gen9/hw_cmds_base.h +++ b/runtime/gen9/hw_cmds_base.h @@ -12,7 +12,8 @@ #include "hw_info.h" #include "igfxfmid.h" -struct SklParse; +template +struct CmdParse; namespace OCLRT { @@ -22,7 +23,7 @@ struct GEN9 { }; struct SKLFamily : public GEN9 { - using PARSE = SklParse; + using PARSE = CmdParse; using GfxFamily = SKLFamily; using WALKER_TYPE = GPGPU_WALKER; static const GPGPU_WALKER cmdInitGpgpuWalker; diff --git a/unit_tests/gen10/cmd_parse_gen10.cpp b/unit_tests/gen10/cmd_parse_gen10.cpp index deab9e549c..fd315844f2 100644 --- a/unit_tests/gen10/cmd_parse_gen10.cpp +++ b/unit_tests/gen10/cmd_parse_gen10.cpp @@ -6,335 +6,23 @@ */ #include "unit_tests/gen_common/gen_cmd_parse.h" +#include "gtest/gtest.h" +using GenStruct = OCLRT::GEN10; +using GenGfxFamily = OCLRT::CNL; +#include "unit_tests/gen_common/cmd_parse_base.inl" +#include "unit_tests/gen_common/cmd_parse_base_mi_arb.inl" +#include "unit_tests/gen_common/cmd_parse_gpgpu_walker.inl" +#include "unit_tests/gen_common/cmd_parse_sip.inl" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/helpers/hw_parse.inl" -#include "gtest/gtest.h" - -// clang-format off -using namespace OCLRT; -using GPGPU_WALKER = GEN10::GPGPU_WALKER; -using MEDIA_INTERFACE_DESCRIPTOR_LOAD = GEN10::MEDIA_INTERFACE_DESCRIPTOR_LOAD; -using MEDIA_STATE_FLUSH = GEN10::MEDIA_STATE_FLUSH; -using MEDIA_VFE_STATE = GEN10::MEDIA_VFE_STATE; -using MI_ARB_CHECK = GEN10::MI_ARB_CHECK; -using MI_ATOMIC = GEN10::MI_ATOMIC; -using MI_BATCH_BUFFER_END = GEN10::MI_BATCH_BUFFER_END; -using MI_BATCH_BUFFER_START = GEN10::MI_BATCH_BUFFER_START; -using MI_LOAD_REGISTER_IMM = GEN10::MI_LOAD_REGISTER_IMM; -using MI_LOAD_REGISTER_MEM = GEN10::MI_LOAD_REGISTER_MEM; -using MI_STORE_REGISTER_MEM = GEN10::MI_STORE_REGISTER_MEM; -using MI_NOOP = GEN10::MI_NOOP; -using PIPE_CONTROL = GEN10::PIPE_CONTROL; -using PIPELINE_SELECT = GEN10::PIPELINE_SELECT; -using STATE_BASE_ADDRESS = GEN10::STATE_BASE_ADDRESS; -using MI_REPORT_PERF_COUNT = GEN10::MI_REPORT_PERF_COUNT; -using MI_LOAD_REGISTER_REG = GEN10::MI_LOAD_REGISTER_REG; -using MI_MATH = GEN10::MI_MATH; -using GPGPU_CSR_BASE_ADDRESS = GEN10::GPGPU_CSR_BASE_ADDRESS; -using STATE_SIP = GEN10::STATE_SIP; -using MI_SEMAPHORE_WAIT = GEN10::MI_SEMAPHORE_WAIT; -using MI_STORE_DATA_IMM = GEN10::MI_STORE_DATA_IMM; -// clang-format on template <> -STATE_BASE_ADDRESS *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return STATE_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - STATE_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - STATE_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - STATE_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_STATE_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -GPGPU_WALKER *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return GPGPU_WALKER::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - GPGPU_WALKER::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - GPGPU_WALKER::MEDIA_COMMAND_OPCODE_GPGPU_WALKER == pCmd->TheStructure.Common.MediaCommandOpcode && - GPGPU_WALKER::SUBOPCODE_GPGPU_WALKER_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_INTERFACE_DESCRIPTOR_LOAD *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_INTERFACE_DESCRIPTOR_LOAD::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::MEDIA_COMMAND_OPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::SUBOPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_VFE_STATE *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_VFE_STATE::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_VFE_STATE::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_VFE_STATE::MEDIA_COMMAND_OPCODE_MEDIA_VFE_STATE == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_VFE_STATE::SUBOPCODE_MEDIA_VFE_STATE_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_STATE_FLUSH *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_STATE_FLUSH::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_STATE_FLUSH::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_STATE_FLUSH::MEDIA_COMMAND_OPCODE_MEDIA_STATE_FLUSH == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_STATE_FLUSH::SUBOPCODE_MEDIA_STATE_FLUSH_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -PIPE_CONTROL *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return PIPE_CONTROL::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - PIPE_CONTROL::COMMAND_SUBTYPE_GFXPIPE_3D == pCmd->TheStructure.Common.CommandSubtype && - PIPE_CONTROL::_3D_COMMAND_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandOpcode && - PIPE_CONTROL::_3D_COMMAND_SUB_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -PIPELINE_SELECT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return PIPELINE_SELECT::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - PIPELINE_SELECT::COMMAND_SUBTYPE_GFXPIPE_SINGLE_DW == pCmd->TheStructure.Common.CommandSubtype && - PIPELINE_SELECT::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - PIPELINE_SELECT::_3D_COMMAND_SUB_OPCODE_PIPELINE_SELECT == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -MI_ARB_CHECK *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_ARB_CHECK::MI_INSTRUCTION_TYPE_MI_INSTRUCTION == pCmd->TheStructure.Common.MiInstructionType && - MI_ARB_CHECK::MI_INSTRUCTION_OPCODE_MI_ARB_CHECK == pCmd->TheStructure.Common.MiInstructionOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_IMM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_IMM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_IMM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_NOOP *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_NOOP::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_NOOP::MI_COMMAND_OPCODE_MI_NOOP == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_ATOMIC *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_ATOMIC::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_ATOMIC::MI_COMMAND_OPCODE_MI_ATOMIC == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_BATCH_BUFFER_END *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_BATCH_BUFFER_END::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_BATCH_BUFFER_END::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_END == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_BATCH_BUFFER_START *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_BATCH_BUFFER_START::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_BATCH_BUFFER_START::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_START == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_MEM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_MEM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_STORE_REGISTER_MEM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_STORE_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_STORE_REGISTER_MEM::MI_COMMAND_OPCODE_MI_STORE_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_REPORT_PERF_COUNT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_REPORT_PERF_COUNT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_REPORT_PERF_COUNT::MI_COMMAND_OPCODE_MI_REPORT_PERF_COUNT == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_MATH *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_MATH::COMMAND_TYPE_MI_COMMAND == pCmd->DW0.BitField.InstructionType && - MI_MATH::MI_COMMAND_OPCODE_MI_MATH == pCmd->DW0.BitField.InstructionOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_REG *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_REG::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_REG::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_REG == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -GPGPU_CSR_BASE_ADDRESS *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return GPGPU_CSR_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - GPGPU_CSR_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - GPGPU_CSR_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - GPGPU_CSR_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_GPGPU_CSR_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -STATE_SIP *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return STATE_SIP::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - STATE_SIP::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - STATE_SIP::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - STATE_SIP::_3D_COMMAND_SUB_OPCODE_STATE_SIP == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -MI_SEMAPHORE_WAIT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_SEMAPHORE_WAIT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_SEMAPHORE_WAIT::MI_COMMAND_OPCODE_MI_SEMAPHORE_WAIT == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_STORE_DATA_IMM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_STORE_DATA_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_STORE_DATA_IMM::MI_COMMAND_OPCODE_MI_STORE_DATA_IMM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -size_t CnlParse::getCommandLength(void *cmd) { - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } +size_t CmdParse::getCommandLengthHwSpecific(void *cmd) { { auto pCmd = genCmdCast(cmd); if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return sizeof(MI_ATOMIC) / sizeof(uint32_t); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } { auto pCmd = genCmdCast(cmd); if (pCmd) @@ -350,21 +38,6 @@ size_t CnlParse::getCommandLength(void *cmd) { if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->DW0.BitField.DwordLength + 2; - } { auto pCmd = genCmdCast(cmd); if (pCmd) @@ -375,114 +48,10 @@ size_t CnlParse::getCommandLength(void *cmd) { if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 3; - } return 0; } -bool CnlParse::parseCommandBuffer(GenCmdList &cmds, void *buffer, size_t length) { - if (!buffer || length % sizeof(uint32_t)) { - return false; - } - - void *bufferEnd = reinterpret_cast(buffer) + length; - while (buffer < bufferEnd) { - size_t length = getCommandLength(buffer); - if (!length) { - return false; - } - - cmds.push_back(buffer); - - buffer = reinterpret_cast(buffer) + length; - } - - return buffer == bufferEnd; -} - -// MIDL should have a MSF between it and a previous walker -template <> -void CnlParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { - auto itorCurrent = itorBegin; - auto itorWalker = itorEnd; - - // Find last GPGPU_WALKER prior to itorCmd - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorWalker = itorCurrent; - } - - ++itorCurrent; - } - - // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list - itorWalker = itorWalker == itorEnd - ? itorBegin - : itorWalker; - - // Look for MEDIA_STATE_FLUSH between last GPGPU_WALKER and MIDL. - auto itorMSF = itorEnd; - - itorCurrent = itorWalker; - ++itorCurrent; - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorMSF = itorCurrent; - break; - } - ++itorCurrent; - } - - ASSERT_FALSE(itorMSF == itorEnd) << "A MEDIA_STATE_FLUSH is required before a MEDIA_INTERFACE_DESCRIPTOR_LOAD."; -} - -template <> -void CnlParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { -} - -// MVFES should have a stalling PC between it and a previous walker -template <> -void CnlParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { - auto itorCurrent = itorBegin; - auto itorWalker = itorEnd; - - // Find last GPGPU_WALKER prior to itorCmd - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorWalker = itorCurrent; - } - - ++itorCurrent; - } - - // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list - itorWalker = itorWalker == itorEnd - ? itorBegin - : itorWalker; - - // Look for PIPE_CONTROL between last GPGPU_WALKER and MVFES. - itorCurrent = itorWalker; - ++itorCurrent; - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - auto pPC = genCmdCast(*itorCurrent); - if (pPC->getCommandStreamerStallEnable()) { - return; - } - } - ++itorCurrent; - } - - ASSERT_TRUE(false) << "A PIPE_CONTROL w/ CS stall is required before a MEDIA_VFE_STATE."; -} +template struct CmdParse; namespace OCLRT { template void HardwareParse::findHardwareCommands(); diff --git a/unit_tests/gen10/gen_cmd_parse.h b/unit_tests/gen10/gen_cmd_parse.h deleted file mode 100644 index fe88256a58..0000000000 --- a/unit_tests/gen10/gen_cmd_parse.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2017-2018 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "unit_tests/gen_common/gen_cmd_parse_base.h" - -struct CnlParse : public OCLRT::CNL { - static size_t getCommandLength(void *cmd); - - static bool parseCommandBuffer(GenCmdList &_cmds, void *_buffer, size_t _length); - - template - static void validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd); -}; diff --git a/unit_tests/gen8/cmd_parse_gen8.cpp b/unit_tests/gen8/cmd_parse_gen8.cpp index bcddbacf86..80e24c54ae 100644 --- a/unit_tests/gen8/cmd_parse_gen8.cpp +++ b/unit_tests/gen8/cmd_parse_gen8.cpp @@ -6,309 +6,22 @@ */ #include "unit_tests/gen_common/gen_cmd_parse.h" +#include "gtest/gtest.h" +using GenStruct = OCLRT::GEN8; +using GenGfxFamily = OCLRT::BDW; +#include "unit_tests/gen_common/cmd_parse_base.inl" +#include "unit_tests/gen_common/cmd_parse_base_mi_arb.inl" +#include "unit_tests/gen_common/cmd_parse_gpgpu_walker.inl" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/helpers/hw_parse.inl" -#include "gtest/gtest.h" - -// clang-format off -using namespace OCLRT; -using GPGPU_WALKER = GEN8::GPGPU_WALKER; -using MEDIA_INTERFACE_DESCRIPTOR_LOAD = GEN8::MEDIA_INTERFACE_DESCRIPTOR_LOAD; -using MEDIA_STATE_FLUSH = GEN8::MEDIA_STATE_FLUSH; -using MEDIA_VFE_STATE = GEN8::MEDIA_VFE_STATE; -using MI_ARB_CHECK = GEN8::MI_ARB_CHECK; -using MI_ATOMIC = GEN8::MI_ATOMIC; -using MI_BATCH_BUFFER_END = GEN8::MI_BATCH_BUFFER_END; -using MI_BATCH_BUFFER_START = GEN8::MI_BATCH_BUFFER_START; -using MI_LOAD_REGISTER_IMM = GEN8::MI_LOAD_REGISTER_IMM; -using MI_LOAD_REGISTER_MEM = GEN8::MI_LOAD_REGISTER_MEM; -using MI_STORE_REGISTER_MEM = GEN8::MI_STORE_REGISTER_MEM; -using MI_NOOP = GEN8::MI_NOOP; -using PIPE_CONTROL = GEN8::PIPE_CONTROL; -using PIPELINE_SELECT = GEN8::PIPELINE_SELECT; -using STATE_BASE_ADDRESS = GEN8::STATE_BASE_ADDRESS; -using MI_REPORT_PERF_COUNT = GEN8::MI_REPORT_PERF_COUNT; -using MI_MATH = GEN8::MI_MATH; -using MI_LOAD_REGISTER_REG = GEN8::MI_LOAD_REGISTER_REG; -using MI_SEMAPHORE_WAIT = GEN8::MI_SEMAPHORE_WAIT; -using MI_STORE_DATA_IMM = GEN8::MI_STORE_DATA_IMM; -// clang-format on template <> -STATE_BASE_ADDRESS *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return STATE_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - STATE_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - STATE_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - STATE_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_STATE_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -GPGPU_WALKER *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return GPGPU_WALKER::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - GPGPU_WALKER::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - GPGPU_WALKER::MEDIA_COMMAND_OPCODE_GPGPU_WALKER == pCmd->TheStructure.Common.MediaCommandOpcode && - GPGPU_WALKER::SUBOPCODE_GPGPU_WALKER_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_INTERFACE_DESCRIPTOR_LOAD *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_INTERFACE_DESCRIPTOR_LOAD::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::MEDIA_COMMAND_OPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::SUBOPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_VFE_STATE *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_VFE_STATE::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_VFE_STATE::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_VFE_STATE::MEDIA_COMMAND_OPCODE_MEDIA_VFE_STATE == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_VFE_STATE::SUBOPCODE_MEDIA_VFE_STATE_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_STATE_FLUSH *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_STATE_FLUSH::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_STATE_FLUSH::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_STATE_FLUSH::MEDIA_COMMAND_OPCODE_MEDIA_STATE_FLUSH == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_STATE_FLUSH::SUBOPCODE_MEDIA_STATE_FLUSH_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -PIPE_CONTROL *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return PIPE_CONTROL::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - PIPE_CONTROL::COMMAND_SUBTYPE_GFXPIPE_3D == pCmd->TheStructure.Common.CommandSubtype && - PIPE_CONTROL::_3D_COMMAND_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandOpcode && - PIPE_CONTROL::_3D_COMMAND_SUB_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -PIPELINE_SELECT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return PIPELINE_SELECT::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - PIPELINE_SELECT::COMMAND_SUBTYPE_GFXPIPE_SINGLE_DW == pCmd->TheStructure.Common.CommandSubtype && - PIPELINE_SELECT::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - PIPELINE_SELECT::_3D_COMMAND_SUB_OPCODE_PIPELINE_SELECT == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -MI_ARB_CHECK *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_ARB_CHECK::MI_INSTRUCTION_TYPE_MI_INSTRUCTION == pCmd->TheStructure.Common.MiInstructionType && - MI_ARB_CHECK::MI_INSTRUCTION_OPCODE_MI_ARB_CHECK == pCmd->TheStructure.Common.MiInstructionOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_IMM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_IMM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_IMM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_NOOP *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_NOOP::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_NOOP::MI_COMMAND_OPCODE_MI_NOOP == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_ATOMIC *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_ATOMIC::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_ATOMIC::MI_COMMAND_OPCODE_MI_ATOMIC == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_BATCH_BUFFER_END *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_BATCH_BUFFER_END::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_BATCH_BUFFER_END::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_END == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_BATCH_BUFFER_START *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_BATCH_BUFFER_START::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_BATCH_BUFFER_START::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_START == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_MEM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_MEM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_STORE_REGISTER_MEM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_STORE_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_STORE_REGISTER_MEM::MI_COMMAND_OPCODE_MI_STORE_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_REPORT_PERF_COUNT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_REPORT_PERF_COUNT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_REPORT_PERF_COUNT::MI_COMMAND_OPCODE_MI_REPORT_PERF_COUNT == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_MATH *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_MATH::COMMAND_TYPE_MI_COMMAND == pCmd->DW0.BitField.InstructionType && - MI_MATH::MI_COMMAND_OPCODE_MI_MATH == pCmd->DW0.BitField.InstructionOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_REG *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_REG::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_REG::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_REG == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_SEMAPHORE_WAIT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_SEMAPHORE_WAIT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_SEMAPHORE_WAIT::MI_COMMAND_OPCODE_MI_SEMAPHORE_WAIT == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_STORE_DATA_IMM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_STORE_DATA_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_STORE_DATA_IMM::MI_COMMAND_OPCODE_MI_STORE_DATA_IMM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -size_t BdwParse::getCommandLength(void *cmd) { - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } +size_t CmdParse::getCommandLengthHwSpecific(void *cmd) { { auto pCmd = genCmdCast(cmd); if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return sizeof(MI_ATOMIC) / sizeof(uint32_t); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } { auto pCmd = genCmdCast(cmd); if (pCmd) @@ -324,129 +37,10 @@ size_t BdwParse::getCommandLength(void *cmd) { if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->DW0.BitField.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 3; - } return 0; } -bool BdwParse::parseCommandBuffer(GenCmdList &cmds, void *buffer, size_t length) { - if (!buffer || length % sizeof(uint32_t)) { - return false; - } - - void *bufferEnd = reinterpret_cast(buffer) + length; - while (buffer < bufferEnd) { - size_t length = getCommandLength(buffer); - if (!length) { - return false; - } - - cmds.push_back(buffer); - - buffer = reinterpret_cast(buffer) + length; - } - - return buffer == bufferEnd; -} - -// MIDL should have a MSF between it and a previous walker -template <> -void BdwParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { - auto itorCurrent = itorBegin; - auto itorWalker = itorEnd; - - // Find last GPGPU_WALKER prior to itorCmd - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorWalker = itorCurrent; - } - - ++itorCurrent; - } - - // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list - itorWalker = itorWalker == itorEnd - ? itorBegin - : itorWalker; - - // Look for MEDIA_STATE_FLUSH between last GPGPU_WALKER and MIDL. - auto itorMSF = itorEnd; - - itorCurrent = itorWalker; - ++itorCurrent; - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorMSF = itorCurrent; - break; - } - ++itorCurrent; - } - - ASSERT_FALSE(itorMSF == itorEnd) << "A MEDIA_STATE_FLUSH is required before a MEDIA_INTERFACE_DESCRIPTOR_LOAD."; -} - -template <> -void BdwParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { -} - -// MVFES should have a stalling PC between it and a previous walker -template <> -void BdwParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { - auto itorCurrent = itorBegin; - auto itorWalker = itorEnd; - - // Find last GPGPU_WALKER prior to itorCmd - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorWalker = itorCurrent; - } - - ++itorCurrent; - } - - // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list - itorWalker = itorWalker == itorEnd - ? itorBegin - : itorWalker; - - // Look for PIPE_CONTROL between last GPGPU_WALKER and MVFES. - itorCurrent = itorWalker; - ++itorCurrent; - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - auto pPC = genCmdCast(*itorCurrent); - if (pPC->getCommandStreamerStallEnable()) { - return; - } - } - ++itorCurrent; - } - - ASSERT_TRUE(false) << "A PIPE_CONTROL w/ CS stall is required before a MEDIA_VFE_STATE."; -} +template struct CmdParse; namespace OCLRT { template void HardwareParse::findHardwareCommands(); diff --git a/unit_tests/gen8/gen_cmd_parse.h b/unit_tests/gen8/gen_cmd_parse.h deleted file mode 100644 index 020a123bfe..0000000000 --- a/unit_tests/gen8/gen_cmd_parse.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#pragma once -#include "unit_tests/gen_common/gen_cmd_parse_base.h" - -struct BdwParse : public OCLRT::BDW { - static size_t getCommandLength(void *cmd); - - static bool parseCommandBuffer(GenCmdList &_cmds, void *_buffer, size_t _length); - - template - static void validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd); -}; diff --git a/unit_tests/gen9/cmd_parse_gen9.cpp b/unit_tests/gen9/cmd_parse_gen9.cpp index 40a58b0935..31bb95170b 100644 --- a/unit_tests/gen9/cmd_parse_gen9.cpp +++ b/unit_tests/gen9/cmd_parse_gen9.cpp @@ -6,335 +6,23 @@ */ #include "unit_tests/gen_common/gen_cmd_parse.h" +#include "gtest/gtest.h" +using GenStruct = OCLRT::GEN9; +using GenGfxFamily = OCLRT::SKL; +#include "unit_tests/gen_common/cmd_parse_base.inl" +#include "unit_tests/gen_common/cmd_parse_base_mi_arb.inl" +#include "unit_tests/gen_common/cmd_parse_gpgpu_walker.inl" +#include "unit_tests/gen_common/cmd_parse_sip.inl" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/helpers/hw_parse.inl" -#include "gtest/gtest.h" - -// clang-format off -using namespace OCLRT; -using GPGPU_WALKER = GEN9::GPGPU_WALKER; -using MEDIA_INTERFACE_DESCRIPTOR_LOAD = GEN9::MEDIA_INTERFACE_DESCRIPTOR_LOAD; -using MEDIA_STATE_FLUSH = GEN9::MEDIA_STATE_FLUSH; -using MEDIA_VFE_STATE = GEN9::MEDIA_VFE_STATE; -using MI_ARB_CHECK = GEN9::MI_ARB_CHECK; -using MI_ATOMIC = GEN9::MI_ATOMIC; -using MI_BATCH_BUFFER_END = GEN9::MI_BATCH_BUFFER_END; -using MI_BATCH_BUFFER_START = GEN9::MI_BATCH_BUFFER_START; -using MI_LOAD_REGISTER_IMM = GEN9::MI_LOAD_REGISTER_IMM; -using MI_LOAD_REGISTER_MEM = GEN9::MI_LOAD_REGISTER_MEM; -using MI_STORE_REGISTER_MEM = GEN9::MI_STORE_REGISTER_MEM; -using MI_NOOP = GEN9::MI_NOOP; -using PIPE_CONTROL = GEN9::PIPE_CONTROL; -using PIPELINE_SELECT = GEN9::PIPELINE_SELECT; -using STATE_BASE_ADDRESS = GEN9::STATE_BASE_ADDRESS; -using MI_REPORT_PERF_COUNT = GEN9::MI_REPORT_PERF_COUNT; -using MI_MATH = GEN9::MI_MATH; -using MI_LOAD_REGISTER_REG = GEN9::MI_LOAD_REGISTER_REG; -using GPGPU_CSR_BASE_ADDRESS = GEN9::GPGPU_CSR_BASE_ADDRESS; -using STATE_SIP = GEN9::STATE_SIP; -using MI_SEMAPHORE_WAIT = GEN9::MI_SEMAPHORE_WAIT; -using MI_STORE_DATA_IMM = GEN9::MI_STORE_DATA_IMM; -// clang-format on template <> -STATE_BASE_ADDRESS *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return STATE_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - STATE_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - STATE_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - STATE_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_STATE_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -GPGPU_WALKER *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return GPGPU_WALKER::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - GPGPU_WALKER::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - GPGPU_WALKER::MEDIA_COMMAND_OPCODE_GPGPU_WALKER == pCmd->TheStructure.Common.MediaCommandOpcode && - GPGPU_WALKER::SUBOPCODE_GPGPU_WALKER_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_INTERFACE_DESCRIPTOR_LOAD *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_INTERFACE_DESCRIPTOR_LOAD::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::MEDIA_COMMAND_OPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_INTERFACE_DESCRIPTOR_LOAD::SUBOPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_VFE_STATE *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_VFE_STATE::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_VFE_STATE::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_VFE_STATE::MEDIA_COMMAND_OPCODE_MEDIA_VFE_STATE == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_VFE_STATE::SUBOPCODE_MEDIA_VFE_STATE_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -MEDIA_STATE_FLUSH *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MEDIA_STATE_FLUSH::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - MEDIA_STATE_FLUSH::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && - MEDIA_STATE_FLUSH::MEDIA_COMMAND_OPCODE_MEDIA_STATE_FLUSH == pCmd->TheStructure.Common.MediaCommandOpcode && - MEDIA_STATE_FLUSH::SUBOPCODE_MEDIA_STATE_FLUSH_SUBOP == pCmd->TheStructure.Common.Subopcode - ? pCmd - : nullptr; -} - -template <> -PIPE_CONTROL *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return PIPE_CONTROL::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - PIPE_CONTROL::COMMAND_SUBTYPE_GFXPIPE_3D == pCmd->TheStructure.Common.CommandSubtype && - PIPE_CONTROL::_3D_COMMAND_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandOpcode && - PIPE_CONTROL::_3D_COMMAND_SUB_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -PIPELINE_SELECT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return PIPELINE_SELECT::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - PIPELINE_SELECT::COMMAND_SUBTYPE_GFXPIPE_SINGLE_DW == pCmd->TheStructure.Common.CommandSubtype && - PIPELINE_SELECT::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - PIPELINE_SELECT::_3D_COMMAND_SUB_OPCODE_PIPELINE_SELECT == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -MI_ARB_CHECK *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_ARB_CHECK::MI_INSTRUCTION_TYPE_MI_INSTRUCTION == pCmd->TheStructure.Common.MiInstructionType && - MI_ARB_CHECK::MI_INSTRUCTION_OPCODE_MI_ARB_CHECK == pCmd->TheStructure.Common.MiInstructionOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_IMM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_IMM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_IMM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_NOOP *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_NOOP::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_NOOP::MI_COMMAND_OPCODE_MI_NOOP == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_ATOMIC *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_ATOMIC::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_ATOMIC::MI_COMMAND_OPCODE_MI_ATOMIC == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_BATCH_BUFFER_END *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_BATCH_BUFFER_END::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_BATCH_BUFFER_END::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_END == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_BATCH_BUFFER_START *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_BATCH_BUFFER_START::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_BATCH_BUFFER_START::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_START == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_MEM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_MEM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_STORE_REGISTER_MEM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_STORE_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_STORE_REGISTER_MEM::MI_COMMAND_OPCODE_MI_STORE_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_REPORT_PERF_COUNT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_REPORT_PERF_COUNT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_REPORT_PERF_COUNT::MI_COMMAND_OPCODE_MI_REPORT_PERF_COUNT == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_MATH *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_MATH::COMMAND_TYPE_MI_COMMAND == pCmd->DW0.BitField.InstructionType && - MI_MATH::MI_COMMAND_OPCODE_MI_MATH == pCmd->DW0.BitField.InstructionOpcode - ? pCmd - : nullptr; -} - -template <> -MI_LOAD_REGISTER_REG *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_LOAD_REGISTER_REG::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_LOAD_REGISTER_REG::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_REG == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -GPGPU_CSR_BASE_ADDRESS *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return GPGPU_CSR_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - GPGPU_CSR_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - GPGPU_CSR_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - GPGPU_CSR_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_GPGPU_CSR_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -STATE_SIP *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return STATE_SIP::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && - STATE_SIP::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && - STATE_SIP::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && - STATE_SIP::_3D_COMMAND_SUB_OPCODE_STATE_SIP == pCmd->TheStructure.Common._3DCommandSubOpcode - ? pCmd - : nullptr; -} - -template <> -MI_SEMAPHORE_WAIT *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_SEMAPHORE_WAIT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_SEMAPHORE_WAIT::MI_COMMAND_OPCODE_MI_SEMAPHORE_WAIT == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -template <> -MI_STORE_DATA_IMM *genCmdCast(void *buffer) { - auto pCmd = reinterpret_cast(buffer); - - return MI_STORE_DATA_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && - MI_STORE_DATA_IMM::MI_COMMAND_OPCODE_MI_STORE_DATA_IMM == pCmd->TheStructure.Common.MiCommandOpcode - ? pCmd - : nullptr; -} - -size_t SklParse::getCommandLength(void *cmd) { - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } +size_t CmdParse::getCommandLengthHwSpecific(void *cmd) { { auto pCmd = genCmdCast(cmd); if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return sizeof(MI_ATOMIC) / sizeof(uint32_t); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return SIZE32(*pCmd); - } { auto pCmd = genCmdCast(cmd); if (pCmd) @@ -350,21 +38,6 @@ size_t SklParse::getCommandLength(void *cmd) { if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->DW0.BitField.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } { auto pCmd = genCmdCast(cmd); if (pCmd) @@ -375,114 +48,10 @@ size_t SklParse::getCommandLength(void *cmd) { if (pCmd) return pCmd->TheStructure.Common.DwordLength + 2; } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 2; - } - { - auto pCmd = genCmdCast(cmd); - if (pCmd) - return pCmd->TheStructure.Common.DwordLength + 3; - } return 0; } -bool SklParse::parseCommandBuffer(GenCmdList &cmds, void *buffer, size_t length) { - if (!buffer || length % sizeof(uint32_t)) { - return false; - } - - void *bufferEnd = reinterpret_cast(buffer) + length; - while (buffer < bufferEnd) { - size_t length = getCommandLength(buffer); - if (!length) { - return false; - } - - cmds.push_back(buffer); - - buffer = reinterpret_cast(buffer) + length; - } - - return buffer == bufferEnd; -} - -// MIDL should have a MSF between it and a previous walker -template <> -void SklParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { - auto itorCurrent = itorBegin; - auto itorWalker = itorEnd; - - // Find last GPGPU_WALKER prior to itorCmd - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorWalker = itorCurrent; - } - - ++itorCurrent; - } - - // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list - itorWalker = itorWalker == itorEnd - ? itorBegin - : itorWalker; - - // Look for MEDIA_STATE_FLUSH between last GPGPU_WALKER and MIDL. - auto itorMSF = itorEnd; - - itorCurrent = itorWalker; - ++itorCurrent; - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorMSF = itorCurrent; - break; - } - ++itorCurrent; - } - - ASSERT_FALSE(itorMSF == itorEnd) << "A MEDIA_STATE_FLUSH is required before a MEDIA_INTERFACE_DESCRIPTOR_LOAD."; -} - -template <> -void SklParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { -} - -// MVFES should have a stalling PC between it and a previous walker -template <> -void SklParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { - auto itorCurrent = itorBegin; - auto itorWalker = itorEnd; - - // Find last GPGPU_WALKER prior to itorCmd - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - itorWalker = itorCurrent; - } - - ++itorCurrent; - } - - // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list - itorWalker = itorWalker == itorEnd - ? itorBegin - : itorWalker; - - // Look for PIPE_CONTROL between last GPGPU_WALKER and MVFES. - itorCurrent = itorWalker; - ++itorCurrent; - while (itorCurrent != itorEnd) { - if (genCmdCast(*itorCurrent)) { - auto pPC = genCmdCast(*itorCurrent); - if (pPC->getCommandStreamerStallEnable()) { - return; - } - } - ++itorCurrent; - } - - ASSERT_TRUE(false) << "A PIPE_CONTROL w/ CS stall is required before a MEDIA_VFE_STATE."; -} +template struct CmdParse; namespace OCLRT { template void HardwareParse::findHardwareCommands(); diff --git a/unit_tests/gen9/gen_cmd_parse.h b/unit_tests/gen9/gen_cmd_parse.h deleted file mode 100644 index 725a310929..0000000000 --- a/unit_tests/gen9/gen_cmd_parse.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#pragma once -#include "unit_tests/gen_common/gen_cmd_parse_base.h" - -struct SklParse : public OCLRT::SKLFamily { - static size_t getCommandLength(void *cmd); - - static bool parseCommandBuffer(GenCmdList &_cmds, void *_buffer, size_t _length); - - template - static void validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd); -}; diff --git a/unit_tests/gen_common/CMakeLists.txt b/unit_tests/gen_common/CMakeLists.txt index 500bb72fd9..e075ea9853 100644 --- a/unit_tests/gen_common/CMakeLists.txt +++ b/unit_tests/gen_common/CMakeLists.txt @@ -6,10 +6,15 @@ set(IGDRCL_SRCS_tests_gen_common ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_base.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_base_mi_arb.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_gpgpu_walker.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_sip.inl ${CMAKE_CURRENT_SOURCE_DIR}/gen_cmd_parse.h - ${CMAKE_CURRENT_SOURCE_DIR}/gen_cmd_parse_base.h ${CMAKE_CURRENT_SOURCE_DIR}/gen_commands_common_validation.h ${CMAKE_CURRENT_SOURCE_DIR}/matchers.h ${CMAKE_CURRENT_SOURCE_DIR}/test.h ) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_gen_common}) + +add_subdirectories() diff --git a/unit_tests/gen_common/cmd_parse_base.inl b/unit_tests/gen_common/cmd_parse_base.inl new file mode 100644 index 0000000000..2859d862c1 --- /dev/null +++ b/unit_tests/gen_common/cmd_parse_base.inl @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +// clang-format off +using namespace OCLRT; +using MI_ARB_CHECK = GenStruct::MI_ARB_CHECK; +using MI_ATOMIC = GenStruct::MI_ATOMIC; +using MI_BATCH_BUFFER_END = GenStruct::MI_BATCH_BUFFER_END; +using MI_BATCH_BUFFER_START = GenStruct::MI_BATCH_BUFFER_START; +using MI_LOAD_REGISTER_IMM = GenStruct::MI_LOAD_REGISTER_IMM; +using MI_LOAD_REGISTER_MEM = GenStruct::MI_LOAD_REGISTER_MEM; +using MI_STORE_REGISTER_MEM = GenStruct::MI_STORE_REGISTER_MEM; +using MI_NOOP = GenStruct::MI_NOOP; +using PIPE_CONTROL = GenStruct::PIPE_CONTROL; +using PIPELINE_SELECT = GenStruct::PIPELINE_SELECT; +using STATE_BASE_ADDRESS = GenStruct::STATE_BASE_ADDRESS; +using MI_REPORT_PERF_COUNT = GenStruct::MI_REPORT_PERF_COUNT; +using MI_MATH = GenStruct::MI_MATH; +using MI_LOAD_REGISTER_REG = GenStruct::MI_LOAD_REGISTER_REG; +using MI_SEMAPHORE_WAIT = GenStruct::MI_SEMAPHORE_WAIT; +using MI_STORE_DATA_IMM = GenStruct::MI_STORE_DATA_IMM; +// clang-format on + +template <> +STATE_BASE_ADDRESS *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return STATE_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + STATE_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && + STATE_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && + STATE_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_STATE_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode + ? pCmd + : nullptr; +} + +template <> +PIPE_CONTROL *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return PIPE_CONTROL::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + PIPE_CONTROL::COMMAND_SUBTYPE_GFXPIPE_3D == pCmd->TheStructure.Common.CommandSubtype && + PIPE_CONTROL::_3D_COMMAND_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandOpcode && + PIPE_CONTROL::_3D_COMMAND_SUB_OPCODE_PIPE_CONTROL == pCmd->TheStructure.Common._3DCommandSubOpcode + ? pCmd + : nullptr; +} + +template <> +PIPELINE_SELECT *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return PIPELINE_SELECT::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + PIPELINE_SELECT::COMMAND_SUBTYPE_GFXPIPE_SINGLE_DW == pCmd->TheStructure.Common.CommandSubtype && + PIPELINE_SELECT::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && + PIPELINE_SELECT::_3D_COMMAND_SUB_OPCODE_PIPELINE_SELECT == pCmd->TheStructure.Common._3DCommandSubOpcode + ? pCmd + : nullptr; +} + +template <> +MI_LOAD_REGISTER_IMM *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_LOAD_REGISTER_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_LOAD_REGISTER_IMM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_IMM == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_NOOP *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_NOOP::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_NOOP::MI_COMMAND_OPCODE_MI_NOOP == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_ATOMIC *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_ATOMIC::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_ATOMIC::MI_COMMAND_OPCODE_MI_ATOMIC == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_BATCH_BUFFER_END *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_BATCH_BUFFER_END::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_BATCH_BUFFER_END::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_END == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_BATCH_BUFFER_START *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_BATCH_BUFFER_START::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_BATCH_BUFFER_START::MI_COMMAND_OPCODE_MI_BATCH_BUFFER_START == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_LOAD_REGISTER_MEM *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_LOAD_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_LOAD_REGISTER_MEM::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_STORE_REGISTER_MEM *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_STORE_REGISTER_MEM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_STORE_REGISTER_MEM::MI_COMMAND_OPCODE_MI_STORE_REGISTER_MEM == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_REPORT_PERF_COUNT *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_REPORT_PERF_COUNT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_REPORT_PERF_COUNT::MI_COMMAND_OPCODE_MI_REPORT_PERF_COUNT == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_MATH *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_MATH::COMMAND_TYPE_MI_COMMAND == pCmd->DW0.BitField.InstructionType && + MI_MATH::MI_COMMAND_OPCODE_MI_MATH == pCmd->DW0.BitField.InstructionOpcode + ? pCmd + : nullptr; +} + +template <> +MI_LOAD_REGISTER_REG *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_LOAD_REGISTER_REG::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_LOAD_REGISTER_REG::MI_COMMAND_OPCODE_MI_LOAD_REGISTER_REG == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_SEMAPHORE_WAIT *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_SEMAPHORE_WAIT::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_SEMAPHORE_WAIT::MI_COMMAND_OPCODE_MI_SEMAPHORE_WAIT == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template <> +MI_STORE_DATA_IMM *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_STORE_DATA_IMM::COMMAND_TYPE_MI_COMMAND == pCmd->TheStructure.Common.CommandType && + MI_STORE_DATA_IMM::MI_COMMAND_OPCODE_MI_STORE_DATA_IMM == pCmd->TheStructure.Common.MiCommandOpcode + ? pCmd + : nullptr; +} + +template +size_t CmdParse::getCommandLength(void *cmd) { + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return SIZE32(*pCmd); + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return sizeof(MI_ATOMIC) / sizeof(uint32_t); + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return SIZE32(*pCmd); + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return SIZE32(*pCmd); + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return SIZE32(*pCmd); + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->DW0.BitField.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 3; + } + return getCommandLengthHwSpecific(cmd); +} diff --git a/unit_tests/gen_common/cmd_parse_base_mi_arb.inl b/unit_tests/gen_common/cmd_parse_base_mi_arb.inl new file mode 100644 index 0000000000..269529d48e --- /dev/null +++ b/unit_tests/gen_common/cmd_parse_base_mi_arb.inl @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +template <> +MI_ARB_CHECK *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MI_ARB_CHECK::MI_INSTRUCTION_TYPE_MI_INSTRUCTION == pCmd->TheStructure.Common.MiInstructionType && + MI_ARB_CHECK::MI_INSTRUCTION_OPCODE_MI_ARB_CHECK == pCmd->TheStructure.Common.MiInstructionOpcode + ? pCmd + : nullptr; +} diff --git a/unit_tests/gen_common/cmd_parse_gpgpu_walker.inl b/unit_tests/gen_common/cmd_parse_gpgpu_walker.inl new file mode 100644 index 0000000000..cbfb38a7f4 --- /dev/null +++ b/unit_tests/gen_common/cmd_parse_gpgpu_walker.inl @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +// clang-format off +using namespace OCLRT; +using GPGPU_WALKER = GenStruct::GPGPU_WALKER; +using MEDIA_INTERFACE_DESCRIPTOR_LOAD = GenStruct::MEDIA_INTERFACE_DESCRIPTOR_LOAD; +using MEDIA_STATE_FLUSH = GenStruct::MEDIA_STATE_FLUSH; +using MEDIA_VFE_STATE = GenStruct::MEDIA_VFE_STATE; +// clang-format on + +template <> +GPGPU_WALKER *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return GPGPU_WALKER::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + GPGPU_WALKER::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && + GPGPU_WALKER::MEDIA_COMMAND_OPCODE_GPGPU_WALKER == pCmd->TheStructure.Common.MediaCommandOpcode && + GPGPU_WALKER::SUBOPCODE_GPGPU_WALKER_SUBOP == pCmd->TheStructure.Common.Subopcode + ? pCmd + : nullptr; +} + +template <> +MEDIA_INTERFACE_DESCRIPTOR_LOAD *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MEDIA_INTERFACE_DESCRIPTOR_LOAD::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + MEDIA_INTERFACE_DESCRIPTOR_LOAD::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && + MEDIA_INTERFACE_DESCRIPTOR_LOAD::MEDIA_COMMAND_OPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD == pCmd->TheStructure.Common.MediaCommandOpcode && + MEDIA_INTERFACE_DESCRIPTOR_LOAD::SUBOPCODE_MEDIA_INTERFACE_DESCRIPTOR_LOAD_SUBOP == pCmd->TheStructure.Common.Subopcode + ? pCmd + : nullptr; +} + +template <> +MEDIA_VFE_STATE *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MEDIA_VFE_STATE::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + MEDIA_VFE_STATE::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && + MEDIA_VFE_STATE::MEDIA_COMMAND_OPCODE_MEDIA_VFE_STATE == pCmd->TheStructure.Common.MediaCommandOpcode && + MEDIA_VFE_STATE::SUBOPCODE_MEDIA_VFE_STATE_SUBOP == pCmd->TheStructure.Common.Subopcode + ? pCmd + : nullptr; +} + +template <> +MEDIA_STATE_FLUSH *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return MEDIA_STATE_FLUSH::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + MEDIA_STATE_FLUSH::PIPELINE_MEDIA == pCmd->TheStructure.Common.Pipeline && + MEDIA_STATE_FLUSH::MEDIA_COMMAND_OPCODE_MEDIA_STATE_FLUSH == pCmd->TheStructure.Common.MediaCommandOpcode && + MEDIA_STATE_FLUSH::SUBOPCODE_MEDIA_STATE_FLUSH_SUBOP == pCmd->TheStructure.Common.Subopcode + ? pCmd + : nullptr; +} + +template +bool CmdParse::parseCommandBuffer(GenCmdList &cmds, void *buffer, size_t length) { + if (!buffer || length % sizeof(uint32_t)) { + return false; + } + + void *bufferEnd = reinterpret_cast(buffer) + length; + while (buffer < bufferEnd) { + size_t length = getCommandLength(buffer); + if (!length) { + return false; + } + + cmds.push_back(buffer); + + buffer = reinterpret_cast(buffer) + length; + } + + return buffer == bufferEnd; +} + +// MIDL should have a MSF between it and a previous walker +template <> +template <> +void CmdParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { + auto itorCurrent = itorBegin; + auto itorWalker = itorEnd; + + // Find last GPGPU_WALKER prior to itorCmd + while (itorCurrent != itorEnd) { + if (genCmdCast(*itorCurrent)) { + itorWalker = itorCurrent; + } + + ++itorCurrent; + } + + // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list + itorWalker = itorWalker == itorEnd + ? itorBegin + : itorWalker; + + // Look for MEDIA_STATE_FLUSH between last GPGPU_WALKER and MIDL. + auto itorMSF = itorEnd; + + itorCurrent = itorWalker; + ++itorCurrent; + while (itorCurrent != itorEnd) { + if (genCmdCast(*itorCurrent)) { + itorMSF = itorCurrent; + break; + } + ++itorCurrent; + } + + ASSERT_FALSE(itorMSF == itorEnd) << "A MEDIA_STATE_FLUSH is required before a MEDIA_INTERFACE_DESCRIPTOR_LOAD."; +} + +template <> +template <> +void CmdParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { +} + +// MVFES should have a stalling PC between it and a previous walker +template <> +template <> +void CmdParse::validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd) { + auto itorCurrent = itorBegin; + auto itorWalker = itorEnd; + + // Find last GPGPU_WALKER prior to itorCmd + while (itorCurrent != itorEnd) { + if (genCmdCast(*itorCurrent)) { + itorWalker = itorCurrent; + } + + ++itorCurrent; + } + + // If we don't find a GPGPU_WALKER, assume the beginning of a cmd list + itorWalker = itorWalker == itorEnd + ? itorBegin + : itorWalker; + + // Look for PIPE_CONTROL between last GPGPU_WALKER and MVFES. + itorCurrent = itorWalker; + ++itorCurrent; + while (itorCurrent != itorEnd) { + if (genCmdCast(*itorCurrent)) { + auto pPC = genCmdCast(*itorCurrent); + if (pPC->getCommandStreamerStallEnable()) { + return; + } + } + ++itorCurrent; + } + + ASSERT_TRUE(false) << "A PIPE_CONTROL w/ CS stall is required before a MEDIA_VFE_STATE."; +} diff --git a/unit_tests/gen_common/cmd_parse_sip.inl b/unit_tests/gen_common/cmd_parse_sip.inl new file mode 100644 index 0000000000..266c801f8b --- /dev/null +++ b/unit_tests/gen_common/cmd_parse_sip.inl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +// clang-format off +using namespace OCLRT; +using GPGPU_CSR_BASE_ADDRESS = GenStruct::GPGPU_CSR_BASE_ADDRESS; +using STATE_SIP = GenStruct::STATE_SIP; +// clang-format on + +template <> +GPGPU_CSR_BASE_ADDRESS *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return GPGPU_CSR_BASE_ADDRESS::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + GPGPU_CSR_BASE_ADDRESS::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && + GPGPU_CSR_BASE_ADDRESS::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && + GPGPU_CSR_BASE_ADDRESS::_3D_COMMAND_SUB_OPCODE_GPGPU_CSR_BASE_ADDRESS == pCmd->TheStructure.Common._3DCommandSubOpcode + ? pCmd + : nullptr; +} + +template <> +STATE_SIP *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return STATE_SIP::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + STATE_SIP::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && + STATE_SIP::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && + STATE_SIP::_3D_COMMAND_SUB_OPCODE_STATE_SIP == pCmd->TheStructure.Common._3DCommandSubOpcode + ? pCmd + : nullptr; +} diff --git a/unit_tests/gen_common/gen_cmd_parse.h b/unit_tests/gen_common/gen_cmd_parse.h index bf49285df9..7f5b502518 100644 --- a/unit_tests/gen_common/gen_cmd_parse.h +++ b/unit_tests/gen_common/gen_cmd_parse.h @@ -6,12 +6,78 @@ */ #pragma once -#ifdef TESTS_GEN8 -#include "unit_tests/gen8/gen_cmd_parse.h" -#endif -#ifdef TESTS_GEN9 -#include "unit_tests/gen9/gen_cmd_parse.h" -#endif -#ifdef TESTS_GEN10 -#include "unit_tests/gen10/gen_cmd_parse.h" -#endif +#include "runtime/gen_common/hw_cmds.h" +#include + +typedef std::list GenCmdList; + +template +Type genCmdCast(void *cmd); + +template +static inline GenCmdList::iterator find(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd) { + GenCmdList::iterator itor = itorStart; + while (itor != itorEnd) { + if (genCmdCast(*itor)) + break; + ++itor; + } + return itor; +} + +template +static inline GenCmdList::iterator findMmio(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd, uint32_t regOffset) { + GenCmdList::iterator itor = itorStart; + while (itor != itorEnd) { + auto cmd = genCmdCast(*itor); + if (cmd && cmd->getRegisterOffset() == regOffset) + break; + ++itor; + } + return itor; +} + +template +static inline size_t countMmio(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd, uint32_t regOffset) { + size_t count = 0; + GenCmdList::iterator itor = itorStart; + while (itor != itorEnd) { + auto cmd = genCmdCast(*itor); + if (cmd && cmd->getRegisterOffset() == regOffset) { + ++count; + } + ++itor; + } + return count; +} + +template +static inline typename FamilyType::MI_LOAD_REGISTER_IMM *findMmioCmd(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd, uint32_t regOffset) { + auto itor = findMmio(itorStart, itorEnd, regOffset); + if (itor == itorEnd) { + return nullptr; + } + return reinterpret_cast(*itor); +} + +template +static inline GenCmdList::reverse_iterator reverse_find(GenCmdList::reverse_iterator itorStart, GenCmdList::const_reverse_iterator itorEnd) { + GenCmdList::reverse_iterator itor = itorStart; + while (itor != itorEnd) { + if (genCmdCast(*itor)) + break; + ++itor; + } + return itor; +} + +template +struct CmdParse : public T { + static size_t getCommandLength(void *cmd); + static size_t getCommandLengthHwSpecific(void *cmd); + + static bool parseCommandBuffer(GenCmdList &_cmds, void *_buffer, size_t _length); + + template + static void validateCommand(GenCmdList::iterator itorBegin, GenCmdList::iterator itorEnd); +}; diff --git a/unit_tests/gen_common/gen_cmd_parse_base.h b/unit_tests/gen_common/gen_cmd_parse_base.h deleted file mode 100644 index 3ce2032298..0000000000 --- a/unit_tests/gen_common/gen_cmd_parse_base.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#pragma once -#include "runtime/gen_common/hw_cmds.h" -#include - -typedef std::list GenCmdList; - -template -Type genCmdCast(void *cmd); - -template -static inline GenCmdList::iterator find(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd) { - GenCmdList::iterator itor = itorStart; - while (itor != itorEnd) { - if (genCmdCast(*itor)) - break; - ++itor; - } - return itor; -} - -template -static inline GenCmdList::iterator findMmio(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd, uint32_t regOffset) { - GenCmdList::iterator itor = itorStart; - while (itor != itorEnd) { - auto cmd = genCmdCast(*itor); - if (cmd && cmd->getRegisterOffset() == regOffset) - break; - ++itor; - } - return itor; -} - -template -static inline size_t countMmio(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd, uint32_t regOffset) { - size_t count = 0; - GenCmdList::iterator itor = itorStart; - while (itor != itorEnd) { - auto cmd = genCmdCast(*itor); - if (cmd && cmd->getRegisterOffset() == regOffset) { - ++count; - } - ++itor; - } - return count; -} - -template -static inline typename FamilyType::MI_LOAD_REGISTER_IMM *findMmioCmd(GenCmdList::iterator itorStart, GenCmdList::const_iterator itorEnd, uint32_t regOffset) { - auto itor = findMmio(itorStart, itorEnd, regOffset); - if (itor == itorEnd) { - return nullptr; - } - return reinterpret_cast(*itor); -} - -template -static inline GenCmdList::reverse_iterator reverse_find(GenCmdList::reverse_iterator itorStart, GenCmdList::const_reverse_iterator itorEnd) { - GenCmdList::reverse_iterator itor = itorStart; - while (itor != itorEnd) { - if (genCmdCast(*itor)) - break; - ++itor; - } - return itor; -} diff --git a/unit_tests/libult/CMakeLists.txt b/unit_tests/libult/CMakeLists.txt index 40fb41954b..ec3bccb2ce 100644 --- a/unit_tests/libult/CMakeLists.txt +++ b/unit_tests/libult/CMakeLists.txt @@ -7,7 +7,6 @@ macro(macro_for_each_gen) list(APPEND IGDRCL_SRCS_ENABLE_TESTED_HW ${IGDRCL_SOURCE_DIR}/unit_tests/${GEN_TYPE_LOWER}/cmd_parse_${GEN_TYPE_LOWER}.cpp - ${IGDRCL_SOURCE_DIR}/unit_tests/${GEN_TYPE_LOWER}/gen_cmd_parse.h ${IGDRCL_SOURCE_DIR}/unit_tests/libult/${GEN_TYPE_LOWER}.cpp ${IGDRCL_SOURCE_DIR}/runtime/${GEN_TYPE_LOWER}/enable_family_full_${GEN_TYPE_LOWER}.cpp ${IGDRCL_SOURCE_DIR}/runtime/${GEN_TYPE_LOWER}/enable_hw_info_config_${GEN_TYPE_LOWER}.cpp @@ -18,6 +17,7 @@ endmacro() apply_macro_for_each_gen("TESTED") set(IGDRCL_SRCS_LIB_ULT + ${IGDRCL_SOURCE_DIR}/unit_tests/gen_common/gen_cmd_parse.h ${IGDRCL_SOURCE_DIR}/unit_tests/abort.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/helpers/built_ins_helper.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/libult/create_tbx_sockets.cpp diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index b45412f879..5c7bd48347 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -20,7 +20,7 @@ #include "runtime/os_interface/linux/os_interface.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" -#include "unit_tests/gen_common/gen_cmd_parse_base.h" +#include "unit_tests/gen_common/gen_cmd_parse.h" #include "unit_tests/helpers/hw_parse.h" #include "unit_tests/mocks/mock_program.h" #include "unit_tests/mocks/mock_submissions_aggregator.h"