2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-21 22:35:08 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
|
|
|
#include "shared/source/helpers/pipeline_select_helper.h"
|
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/command_queue/command_queue.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/gen_common/gen_cmd_parse.h"
|
2019-01-30 20:11:30 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
struct HardwareParse {
|
2020-03-10 22:21:12 +08:00
|
|
|
HardwareParse() {
|
2017-12-21 07:45:38 +08:00
|
|
|
itorMediaInterfaceDescriptorLoad = cmdList.end();
|
|
|
|
itorMediaVfeState = cmdList.end();
|
|
|
|
itorPipelineSelect = cmdList.end();
|
|
|
|
itorStateBaseAddress = cmdList.end();
|
|
|
|
itorWalker = cmdList.end();
|
|
|
|
itorGpgpuCsrBaseAddress = cmdList.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() {
|
|
|
|
cmdList.clear();
|
|
|
|
lriList.clear();
|
2020-03-18 21:14:04 +08:00
|
|
|
pipeControlList.clear();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CmdType>
|
|
|
|
GenCmdList getCommandsList() {
|
|
|
|
GenCmdList list;
|
|
|
|
for (auto it = cmdList.begin(); it != cmdList.end(); it++) {
|
|
|
|
auto cmd = genCmdCast<CmdType *>(*it);
|
|
|
|
if (cmd) {
|
|
|
|
list.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FamilyType>
|
|
|
|
void findCsrBaseAddress();
|
|
|
|
|
|
|
|
template <typename FamilyType>
|
2018-05-21 22:41:58 +08:00
|
|
|
void findHardwareCommands();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-01 20:13:12 +08:00
|
|
|
template <typename FamilyType>
|
|
|
|
void findHardwareCommands(IndirectHeap *dsh);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <typename FamilyType>
|
2019-03-26 18:59:46 +08:00
|
|
|
void parseCommands(NEO::LinearStream &commandStream, size_t startOffset = 0) {
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_LE(startOffset, commandStream.getUsed());
|
|
|
|
auto sizeToParse = commandStream.getUsed() - startOffset;
|
|
|
|
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
|
|
|
|
cmdList,
|
2018-03-05 18:03:38 +08:00
|
|
|
ptrOffset(commandStream.getCpuBase(), startOffset),
|
2017-12-21 07:45:38 +08:00
|
|
|
sizeToParse));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FamilyType>
|
2019-03-26 18:59:46 +08:00
|
|
|
void parseCommands(NEO::CommandQueue &commandQueue) {
|
2019-07-15 20:28:09 +08:00
|
|
|
auto &commandStreamReceiver = commandQueue.getGpgpuCommandStreamReceiver();
|
2017-12-21 07:45:38 +08:00
|
|
|
auto &commandStreamCSR = commandStreamReceiver.getCS();
|
|
|
|
|
|
|
|
parseCommands<FamilyType>(commandStreamCSR, startCSRCS);
|
|
|
|
startCSRCS = commandStreamCSR.getUsed();
|
|
|
|
|
2018-08-24 14:48:59 +08:00
|
|
|
auto &commandStream = commandQueue.getCS(1024);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (previousCS != &commandStream) {
|
|
|
|
startCS = 0;
|
|
|
|
}
|
|
|
|
parseCommands<FamilyType>(commandStream, startCS);
|
|
|
|
startCS = commandStream.getUsed();
|
|
|
|
previousCS = &commandStream;
|
|
|
|
|
|
|
|
sizeUsed = commandStream.getUsed();
|
2019-02-01 20:13:12 +08:00
|
|
|
findHardwareCommands<FamilyType>(&commandStreamReceiver.getIndirectHeap(IndirectHeap::DYNAMIC_STATE, 0));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FamilyType>
|
2019-02-04 22:12:06 +08:00
|
|
|
const typename FamilyType::RENDER_SURFACE_STATE &getSurfaceState(IndirectHeap *ssh, uint32_t index) {
|
2017-12-21 07:45:38 +08:00
|
|
|
typedef typename FamilyType::BINDING_TABLE_STATE BINDING_TABLE_STATE;
|
|
|
|
typedef typename FamilyType::INTERFACE_DESCRIPTOR_DATA INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
|
|
|
|
typedef typename FamilyType::STATE_BASE_ADDRESS STATE_BASE_ADDRESS;
|
|
|
|
|
|
|
|
const auto &interfaceDescriptorData = *(INTERFACE_DESCRIPTOR_DATA *)cmdInterfaceDescriptorData;
|
|
|
|
|
|
|
|
auto cmdSBA = (STATE_BASE_ADDRESS *)cmdStateBaseAddress;
|
|
|
|
auto surfaceStateHeap = cmdSBA->getSurfaceStateBaseAddress();
|
2019-02-04 22:12:06 +08:00
|
|
|
if (ssh && (ssh->getHeapGpuBase() == surfaceStateHeap)) {
|
|
|
|
surfaceStateHeap = reinterpret_cast<uint64_t>(ssh->getCpuBase());
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_NE(0u, surfaceStateHeap);
|
|
|
|
|
|
|
|
auto bindingTablePointer = interfaceDescriptorData.getBindingTablePointer();
|
|
|
|
|
|
|
|
const auto &bindingTableState = reinterpret_cast<BINDING_TABLE_STATE *>(surfaceStateHeap + bindingTablePointer)[index];
|
|
|
|
auto surfaceStatePointer = bindingTableState.getSurfaceStatePointer();
|
|
|
|
|
|
|
|
return *(RENDER_SURFACE_STATE *)(surfaceStateHeap + surfaceStatePointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FamilyType>
|
|
|
|
const typename FamilyType::SAMPLER_STATE &getSamplerState(uint32_t index) {
|
|
|
|
typedef typename FamilyType::INTERFACE_DESCRIPTOR_DATA INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE;
|
|
|
|
typedef typename FamilyType::STATE_BASE_ADDRESS STATE_BASE_ADDRESS;
|
|
|
|
|
|
|
|
const auto &interfaceDescriptorData = *(INTERFACE_DESCRIPTOR_DATA *)cmdInterfaceDescriptorData;
|
|
|
|
|
|
|
|
auto cmdSBA = (STATE_BASE_ADDRESS *)cmdStateBaseAddress;
|
|
|
|
auto dynamicStateHeap = cmdSBA->getDynamicStateBaseAddress();
|
|
|
|
EXPECT_NE(0, dynamicStateHeap);
|
|
|
|
|
|
|
|
const auto samplerState = reinterpret_cast<SAMPLER_STATE *>(dynamicStateHeap + interfaceDescriptorData.getSamplerStatePointer());
|
|
|
|
return samplerState[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FamilyType>
|
2018-05-21 22:41:58 +08:00
|
|
|
const void *getStatelessArgumentPointer(const Kernel &kernel, uint32_t indexArg, IndirectHeap &ioh);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
template <typename CmdType>
|
|
|
|
CmdType *getCommand(GenCmdList::iterator itorStart, GenCmdList::iterator itorEnd) {
|
2018-01-17 15:37:47 +08:00
|
|
|
auto itorCmd = find<CmdType *>(itorStart, itorEnd);
|
2017-12-21 07:45:38 +08:00
|
|
|
return itorCmd != cmdList.end()
|
|
|
|
? genCmdCast<CmdType *>(*itorCmd)
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CmdType>
|
|
|
|
CmdType *getCommand() {
|
|
|
|
return getCommand<CmdType>(cmdList.begin(), cmdList.end());
|
|
|
|
}
|
|
|
|
|
2018-01-17 15:37:47 +08:00
|
|
|
template <typename FamilyType>
|
|
|
|
int getNumberOfPipelineSelectsThatEnablePipelineSelect() {
|
|
|
|
typedef typename FamilyType::PIPELINE_SELECT PIPELINE_SELECT;
|
|
|
|
int numCommands = 0;
|
|
|
|
auto itorCmd = find<PIPELINE_SELECT *>(cmdList.begin(), cmdList.end());
|
|
|
|
while (itorCmd != cmdList.end()) {
|
|
|
|
auto cmd = getCommand<PIPELINE_SELECT>(itorCmd, cmdList.end());
|
|
|
|
if (cmd->getPipelineSelection() == PIPELINE_SELECT::PIPELINE_SELECTION_GPGPU &&
|
|
|
|
pipelineSelectEnablePipelineSelectMaskBits == (pipelineSelectEnablePipelineSelectMaskBits & cmd->getMaskBits())) {
|
|
|
|
numCommands++;
|
|
|
|
}
|
|
|
|
itorCmd = find<PIPELINE_SELECT *>(++itorCmd, cmdList.end());
|
|
|
|
}
|
|
|
|
return numCommands;
|
|
|
|
}
|
|
|
|
|
2018-10-17 06:37:07 +08:00
|
|
|
template <typename CmdType>
|
|
|
|
uint32_t getCommandCount() {
|
|
|
|
GenCmdList::iterator cmdItor = cmdList.begin();
|
|
|
|
uint32_t cmdCount = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
cmdItor = find<CmdType *>(cmdItor, cmdList.end());
|
|
|
|
if (cmdItor != cmdList.end()) {
|
|
|
|
++cmdCount;
|
|
|
|
++cmdItor;
|
|
|
|
}
|
|
|
|
} while (cmdItor != cmdList.end());
|
|
|
|
|
|
|
|
return cmdCount;
|
|
|
|
}
|
|
|
|
|
2019-01-30 20:11:30 +08:00
|
|
|
template <typename FamilyType>
|
|
|
|
static const char *getCommandName(void *cmd) {
|
|
|
|
return FamilyType::PARSE::getCommandName(cmd);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
// The starting point of parsing commandBuffers. This is important
|
|
|
|
// because as buffers get reused, we only want to parse the deltas.
|
2020-03-10 22:21:12 +08:00
|
|
|
LinearStream *previousCS = nullptr;
|
|
|
|
size_t startCS = 0u;
|
|
|
|
size_t startCSRCS = 0u;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-03-10 22:21:12 +08:00
|
|
|
size_t sizeUsed = 0u;
|
2017-12-21 07:45:38 +08:00
|
|
|
GenCmdList cmdList;
|
|
|
|
GenCmdList lriList;
|
2020-03-18 21:14:04 +08:00
|
|
|
GenCmdList pipeControlList;
|
2017-12-21 07:45:38 +08:00
|
|
|
GenCmdList::iterator itorMediaInterfaceDescriptorLoad;
|
|
|
|
GenCmdList::iterator itorMediaVfeState;
|
|
|
|
GenCmdList::iterator itorPipelineSelect;
|
|
|
|
GenCmdList::iterator itorStateBaseAddress;
|
|
|
|
GenCmdList::iterator itorWalker;
|
|
|
|
GenCmdList::iterator itorBBStartAfterWalker;
|
|
|
|
GenCmdList::iterator itorGpgpuCsrBaseAddress;
|
|
|
|
|
2020-03-10 22:21:12 +08:00
|
|
|
void *cmdInterfaceDescriptorData = nullptr;
|
|
|
|
void *cmdMediaInterfaceDescriptorLoad = nullptr;
|
|
|
|
void *cmdMediaVfeState = nullptr;
|
|
|
|
void *cmdPipelineSelect = nullptr;
|
|
|
|
void *cmdStateBaseAddress = nullptr;
|
|
|
|
void *cmdWalker = nullptr;
|
|
|
|
void *cmdBBStartAfterWalker = nullptr;
|
|
|
|
void *cmdGpgpuCsrBaseAddress = nullptr;
|
2020-03-18 21:14:04 +08:00
|
|
|
|
|
|
|
bool parsePipeControl = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-01-30 20:11:30 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|