2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-19 04:17:55 +08:00
|
|
|
* Copyright (C) 2017-2018 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-19 04:17:55 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hw_cmds.h"
|
2018-07-25 00:36:26 +08:00
|
|
|
#include "runtime/aub/aub_helper.h"
|
2018-09-11 16:26:39 +08:00
|
|
|
#include "runtime/aub_mem_dump/page_table_entry_bits.h"
|
2018-09-20 06:36:44 +08:00
|
|
|
#include "runtime/command_stream/aub_stream_provider.h"
|
2018-06-13 02:33:03 +08:00
|
|
|
#include "runtime/command_stream/aub_subcapture.h"
|
2018-09-20 06:36:44 +08:00
|
|
|
#include "runtime/execution_environment/execution_environment.h"
|
2018-09-04 04:44:58 +08:00
|
|
|
#include "runtime/gmm_helper/gmm.h"
|
2018-07-20 03:34:45 +08:00
|
|
|
#include "runtime/gmm_helper/gmm_helper.h"
|
2018-09-04 04:44:58 +08:00
|
|
|
#include "runtime/gmm_helper/resource_info.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/helpers/debug_helpers.h"
|
2018-10-31 07:25:33 +08:00
|
|
|
#include "runtime/helpers/hash.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/ptr_math.h"
|
2018-07-20 03:34:45 +08:00
|
|
|
#include "runtime/helpers/string.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
2018-09-21 04:54:19 +08:00
|
|
|
#include "runtime/memory_manager/memory_banks.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
2018-06-06 23:03:46 +08:00
|
|
|
#include "runtime/os_interface/debug_settings_manager.h"
|
2018-11-26 21:04:52 +08:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2018-11-14 13:52:35 +08:00
|
|
|
#include "driver_version.h"
|
2018-11-27 15:31:00 +08:00
|
|
|
#include "third_party/aub_stream/headers/aub_manager.h"
|
2018-10-20 02:32:05 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-08-08 19:49:09 +08:00
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment)
|
|
|
|
: BaseClass(hwInfoIn, executionEnvironment),
|
2018-11-27 15:31:00 +08:00
|
|
|
defaultEngineType(hwInfoIn.capabilityTable.defaultEngineType),
|
2018-09-04 04:44:58 +08:00
|
|
|
subCaptureManager(std::make_unique<AubSubCaptureManager>(fileName)),
|
2018-09-21 04:54:19 +08:00
|
|
|
standalone(standalone) {
|
|
|
|
|
2018-11-26 06:58:12 +08:00
|
|
|
executionEnvironment.initAubCenter(&this->peekHwInfo(), this->localMemoryEnabled, fileName);
|
2018-09-26 21:28:11 +08:00
|
|
|
auto aubCenter = executionEnvironment.aubCenter.get();
|
|
|
|
UNRECOVERABLE_IF(nullptr == aubCenter);
|
2018-09-21 04:54:19 +08:00
|
|
|
|
2018-11-27 15:31:00 +08:00
|
|
|
aubManager = aubCenter->getAubManager();
|
|
|
|
if (aubManager) {
|
|
|
|
hardwareContext = std::unique_ptr<HardwareContext>(aubManager->createHardwareContext(0, defaultEngineType));
|
|
|
|
}
|
|
|
|
|
2018-09-26 21:28:11 +08:00
|
|
|
if (!aubCenter->getPhysicalAddressAllocator()) {
|
2018-10-04 22:22:22 +08:00
|
|
|
aubCenter->initPhysicalAddressAllocator(this->createPhysicalAddressAllocator());
|
2018-09-26 21:28:11 +08:00
|
|
|
}
|
|
|
|
auto physicalAddressAllocator = aubCenter->getPhysicalAddressAllocator();
|
|
|
|
UNRECOVERABLE_IF(nullptr == physicalAddressAllocator);
|
|
|
|
|
2018-09-27 21:08:57 +08:00
|
|
|
ppgtt = std::make_unique<std::conditional<is64bit, PML4, PDPE>::type>(physicalAddressAllocator);
|
2018-09-26 21:28:11 +08:00
|
|
|
ggtt = std::make_unique<PDPE>(physicalAddressAllocator);
|
|
|
|
|
2018-10-02 16:37:17 +08:00
|
|
|
gttRemap = aubCenter->getAddressMapper();
|
|
|
|
UNRECOVERABLE_IF(nullptr == gttRemap);
|
|
|
|
|
2018-09-26 21:28:11 +08:00
|
|
|
auto streamProvider = aubCenter->getStreamProvider();
|
|
|
|
UNRECOVERABLE_IF(nullptr == streamProvider);
|
|
|
|
|
|
|
|
stream = streamProvider->getStream();
|
|
|
|
UNRECOVERABLE_IF(nullptr == stream);
|
2018-09-21 04:54:19 +08:00
|
|
|
|
2018-04-04 17:34:46 +08:00
|
|
|
this->dispatchMode = DispatchMode::BatchedDispatch;
|
2018-01-14 00:32:04 +08:00
|
|
|
if (DebugManager.flags.CsrDispatchMode.get()) {
|
2018-04-04 17:34:46 +08:00
|
|
|
this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get();
|
2018-01-14 00:32:04 +08:00
|
|
|
}
|
2018-10-20 02:32:05 +08:00
|
|
|
|
|
|
|
setCsrProgrammingMode();
|
|
|
|
|
2018-06-13 02:33:03 +08:00
|
|
|
if (DebugManager.flags.AUBDumpSubCaptureMode.get()) {
|
|
|
|
this->subCaptureManager->subCaptureMode = static_cast<AubSubCaptureManager::SubCaptureMode>(DebugManager.flags.AUBDumpSubCaptureMode.get());
|
|
|
|
this->subCaptureManager->subCaptureFilter.dumpKernelStartIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterKernelStartIdx.get());
|
|
|
|
this->subCaptureManager->subCaptureFilter.dumpKernelEndIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterKernelEndIdx.get());
|
2018-07-26 17:35:13 +08:00
|
|
|
this->subCaptureManager->subCaptureFilter.dumpNamedKernelStartIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterNamedKernelStartIdx.get());
|
|
|
|
this->subCaptureManager->subCaptureFilter.dumpNamedKernelEndIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterNamedKernelEndIdx.get());
|
2018-06-13 02:33:03 +08:00
|
|
|
if (DebugManager.flags.AUBDumpFilterKernelName.get() != "unk") {
|
|
|
|
this->subCaptureManager->subCaptureFilter.dumpKernelName = DebugManager.flags.AUBDumpFilterKernelName.get();
|
|
|
|
}
|
|
|
|
}
|
2018-06-06 23:03:46 +08:00
|
|
|
auto debugDeviceId = DebugManager.flags.OverrideAubDeviceId.get();
|
|
|
|
this->aubDeviceId = debugDeviceId == -1
|
|
|
|
? hwInfoIn.capabilityTable.aubDeviceId
|
|
|
|
: static_cast<uint32_t>(debugDeviceId);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::~AUBCommandStreamReceiverHw() {
|
2018-07-09 17:31:36 +08:00
|
|
|
freeEngineInfoTable();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-10-24 17:15:06 +08:00
|
|
|
const AubMemDump::LrcaHelper &AUBCommandStreamReceiverHw<GfxFamily>::getCsTraits(EngineInstanceT engineInstance) {
|
|
|
|
return *AUBFamilyMapper<GfxFamily>::csTraits[engineInstance.type];
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-20 02:32:05 +08:00
|
|
|
template <typename GfxFamily>
|
2018-10-31 02:08:09 +08:00
|
|
|
size_t AUBCommandStreamReceiverHw<GfxFamily>::getEngineIndexFromInstance(EngineInstanceT engineInstance) {
|
|
|
|
auto findCriteria = [&](const auto &it) { return it.type == engineInstance.type && it.id == engineInstance.id; };
|
2018-11-23 21:59:27 +08:00
|
|
|
auto findResult = std::find_if(allEngineInstances.begin(), allEngineInstances.end(), findCriteria);
|
|
|
|
UNRECOVERABLE_IF(findResult == allEngineInstances.end());
|
|
|
|
return findResult - allEngineInstances.begin();
|
2018-10-31 02:08:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
size_t AUBCommandStreamReceiverHw<GfxFamily>::getEngineIndex(EngineType engineType) {
|
|
|
|
return getEngineIndexFromInstance(engineType);
|
2018-10-20 02:32:05 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <typename GfxFamily>
|
2018-10-24 17:15:06 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::initEngineMMIO(EngineInstanceT engineInstance) {
|
|
|
|
auto mmioList = AUBFamilyMapper<GfxFamily>::perEngineMMIO[engineInstance.type];
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
DEBUG_BREAK_IF(!mmioList);
|
|
|
|
for (auto &mmioPair : *mmioList) {
|
2018-03-14 18:07:51 +08:00
|
|
|
stream->writeMMIO(mmioPair.first, mmioPair.second);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
template <typename GfxFamily>
|
2018-09-20 06:36:44 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::openFile(const std::string &fileName) {
|
2018-11-02 13:28:20 +08:00
|
|
|
auto streamLocked = getAubStream()->lockStream();
|
2018-09-20 06:36:44 +08:00
|
|
|
initFile(fileName);
|
|
|
|
}
|
2018-07-09 17:31:36 +08:00
|
|
|
|
2018-09-20 06:36:44 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
bool AUBCommandStreamReceiverHw<GfxFamily>::reopenFile(const std::string &fileName) {
|
2018-11-02 13:28:20 +08:00
|
|
|
auto streamLocked = getAubStream()->lockStream();
|
2018-09-20 06:36:44 +08:00
|
|
|
if (isFileOpen()) {
|
|
|
|
if (fileName != getFileName()) {
|
|
|
|
closeFile();
|
|
|
|
freeEngineInfoTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isFileOpen()) {
|
|
|
|
initFile(fileName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-09 17:31:36 +08:00
|
|
|
|
2018-09-20 06:36:44 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::initFile(const std::string &fileName) {
|
2018-11-02 13:28:20 +08:00
|
|
|
if (!getAubStream()->isOpen()) {
|
2018-09-20 06:36:44 +08:00
|
|
|
// Open our file
|
|
|
|
stream->open(fileName.c_str());
|
|
|
|
|
2018-11-02 13:28:20 +08:00
|
|
|
if (!getAubStream()->isOpen()) {
|
2018-09-20 06:36:44 +08:00
|
|
|
// This DEBUG_BREAK_IF most probably means you are not executing aub tests with correct current directory (containing aub_out folder)
|
|
|
|
// try adding <familycodename>_aub
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
}
|
|
|
|
// Add the file header
|
|
|
|
stream->init(AubMemDump::SteppingValues::A, aubDeviceId);
|
2018-07-09 17:31:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::closeFile() {
|
|
|
|
stream->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-10-02 16:37:17 +08:00
|
|
|
bool AUBCommandStreamReceiverHw<GfxFamily>::isFileOpen() const {
|
2018-11-02 13:28:20 +08:00
|
|
|
return getAubStream()->isOpen();
|
2018-07-09 17:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
const std::string &AUBCommandStreamReceiverHw<GfxFamily>::getFileName() {
|
2018-11-02 13:28:20 +08:00
|
|
|
return getAubStream()->getFileName();
|
2018-07-09 17:31:36 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <typename GfxFamily>
|
2018-10-24 17:15:06 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine(size_t engineIndex) {
|
2018-11-27 15:31:00 +08:00
|
|
|
if (hardwareContext) {
|
|
|
|
DEBUG_BREAK_IF(allEngineInstances[engineIndex].type != defaultEngineType);
|
|
|
|
hardwareContext->initialize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-24 17:15:06 +08:00
|
|
|
auto engineInstance = allEngineInstances[engineIndex];
|
2018-11-26 06:58:12 +08:00
|
|
|
auto csTraits = getCsTraits(engineInstance);
|
2018-10-24 17:15:06 +08:00
|
|
|
auto &engineInfo = engineInfoTable[engineIndex];
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-11-26 06:58:12 +08:00
|
|
|
if (engineInfo.pLRCA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-10 15:00:58 +08:00
|
|
|
this->initGlobalMMIO();
|
2018-10-24 17:15:06 +08:00
|
|
|
initEngineMMIO(engineInstance);
|
2018-11-02 13:28:20 +08:00
|
|
|
this->initAdditionalMMIO();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-11-14 13:52:35 +08:00
|
|
|
// Write driver version
|
|
|
|
{
|
|
|
|
#define QTR(a) #a
|
|
|
|
#define TOSTR(b) QTR(b)
|
|
|
|
const std::string driverVersion = TOSTR(NEO_DRIVER_VERSION);
|
|
|
|
#undef QTR
|
|
|
|
#undef TOSTR
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "driver version: " << driverVersion;
|
|
|
|
getAubStream()->addComment(str.str().c_str());
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
// Global HW Status Page
|
|
|
|
{
|
|
|
|
const size_t sizeHWSP = 0x1000;
|
|
|
|
const size_t alignHWSP = 0x1000;
|
|
|
|
engineInfo.pGlobalHWStatusPage = alignedMalloc(sizeHWSP, alignHWSP);
|
2018-10-02 16:37:17 +08:00
|
|
|
engineInfo.ggttHWSP = gttRemap->map(engineInfo.pGlobalHWStatusPage, sizeHWSP);
|
2018-09-19 04:17:55 +08:00
|
|
|
|
2018-09-26 07:27:29 +08:00
|
|
|
auto physHWSP = ggtt->map(engineInfo.ggttHWSP, sizeHWSP, this->getGTTBits(), getMemoryBankForGtt());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Write our GHWSP
|
|
|
|
{
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "ggtt: " << std::hex << std::showbase << engineInfo.ggttHWSP;
|
2018-11-02 13:28:20 +08:00
|
|
|
getAubStream()->addComment(str.str().c_str());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 21:25:01 +08:00
|
|
|
AubGTTData data = {0};
|
|
|
|
getGTTData(reinterpret_cast<void *>(physHWSP), data);
|
|
|
|
AUB::reserveAddressGGTT(*stream, engineInfo.ggttHWSP, sizeHWSP, physHWSP, data);
|
2018-11-26 18:20:50 +08:00
|
|
|
stream->writeMMIO(AubMemDump::computeRegisterOffset(csTraits.mmioBase, 0x2080), engineInfo.ggttHWSP);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate the LRCA
|
|
|
|
const size_t sizeLRCA = csTraits.sizeLRCA;
|
|
|
|
const size_t alignLRCA = csTraits.alignLRCA;
|
|
|
|
auto pLRCABase = alignedMalloc(sizeLRCA, alignLRCA);
|
|
|
|
engineInfo.pLRCA = pLRCABase;
|
|
|
|
|
|
|
|
// Initialize the LRCA to a known state
|
|
|
|
csTraits.initialize(pLRCABase);
|
|
|
|
|
|
|
|
// Reserve the ring buffer
|
|
|
|
engineInfo.sizeRingBuffer = 0x4 * 0x1000;
|
|
|
|
{
|
|
|
|
const size_t alignRingBuffer = 0x1000;
|
|
|
|
engineInfo.pRingBuffer = alignedMalloc(engineInfo.sizeRingBuffer, alignRingBuffer);
|
2018-10-02 16:37:17 +08:00
|
|
|
engineInfo.ggttRingBuffer = gttRemap->map(engineInfo.pRingBuffer, engineInfo.sizeRingBuffer);
|
2018-09-26 07:27:29 +08:00
|
|
|
auto physRingBuffer = ggtt->map(engineInfo.ggttRingBuffer, engineInfo.sizeRingBuffer, this->getGTTBits(), getMemoryBankForGtt());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "ggtt: " << std::hex << std::showbase << engineInfo.ggttRingBuffer;
|
2018-11-02 13:28:20 +08:00
|
|
|
getAubStream()->addComment(str.str().c_str());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 21:25:01 +08:00
|
|
|
AubGTTData data = {0};
|
|
|
|
getGTTData(reinterpret_cast<void *>(physRingBuffer), data);
|
|
|
|
AUB::reserveAddressGGTT(*stream, engineInfo.ggttRingBuffer, engineInfo.sizeRingBuffer, physRingBuffer, data);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the ring MMIO registers
|
|
|
|
{
|
|
|
|
uint32_t ringHead = 0x000;
|
|
|
|
uint32_t ringTail = 0x000;
|
|
|
|
auto ringBase = engineInfo.ggttRingBuffer;
|
|
|
|
auto ringCtrl = (uint32_t)((engineInfo.sizeRingBuffer - 0x1000) | 1);
|
|
|
|
csTraits.setRingHead(pLRCABase, ringHead);
|
|
|
|
csTraits.setRingTail(pLRCABase, ringTail);
|
|
|
|
csTraits.setRingBase(pLRCABase, ringBase);
|
|
|
|
csTraits.setRingCtrl(pLRCABase, ringCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write our LRCA
|
|
|
|
{
|
2018-10-02 16:37:17 +08:00
|
|
|
engineInfo.ggttLRCA = gttRemap->map(engineInfo.pLRCA, sizeLRCA);
|
2018-09-26 07:27:29 +08:00
|
|
|
auto lrcAddressPhys = ggtt->map(engineInfo.ggttLRCA, sizeLRCA, this->getGTTBits(), getMemoryBankForGtt());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "ggtt: " << std::hex << std::showbase << engineInfo.ggttLRCA;
|
2018-11-02 13:28:20 +08:00
|
|
|
getAubStream()->addComment(str.str().c_str());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 21:25:01 +08:00
|
|
|
AubGTTData data = {0};
|
|
|
|
getGTTData(reinterpret_cast<void *>(lrcAddressPhys), data);
|
|
|
|
AUB::reserveAddressGGTT(*stream, engineInfo.ggttLRCA, sizeLRCA, lrcAddressPhys, data);
|
2017-12-21 07:45:38 +08:00
|
|
|
AUB::addMemoryWrite(
|
2018-03-14 18:07:51 +08:00
|
|
|
*stream,
|
2017-12-21 07:45:38 +08:00
|
|
|
lrcAddressPhys,
|
|
|
|
pLRCABase,
|
|
|
|
sizeLRCA,
|
2018-09-28 00:56:02 +08:00
|
|
|
this->getAddressSpace(csTraits.aubHintLRCA),
|
2017-12-21 07:45:38 +08:00
|
|
|
csTraits.aubHintLRCA);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a context to facilitate AUB dumping of memory using PPGTT
|
2018-10-31 02:08:09 +08:00
|
|
|
addContextToken(getDumpHandle());
|
2018-11-26 06:58:12 +08:00
|
|
|
|
|
|
|
DEBUG_BREAK_IF(!engineInfo.pLRCA);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-07-09 17:31:36 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::freeEngineInfoTable() {
|
|
|
|
for (auto &engineInfo : engineInfoTable) {
|
|
|
|
alignedFree(engineInfo.pLRCA);
|
2018-10-02 16:37:17 +08:00
|
|
|
gttRemap->unmap(engineInfo.pLRCA);
|
2018-07-09 17:31:36 +08:00
|
|
|
engineInfo.pLRCA = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
alignedFree(engineInfo.pGlobalHWStatusPage);
|
2018-10-02 16:37:17 +08:00
|
|
|
gttRemap->unmap(engineInfo.pGlobalHWStatusPage);
|
2018-07-09 17:31:36 +08:00
|
|
|
engineInfo.pGlobalHWStatusPage = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
alignedFree(engineInfo.pRingBuffer);
|
2018-10-02 16:37:17 +08:00
|
|
|
gttRemap->unmap(engineInfo.pRingBuffer);
|
2018-07-09 17:31:36 +08:00
|
|
|
engineInfo.pRingBuffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-08-08 19:49:09 +08:00
|
|
|
CommandStreamReceiver *AUBCommandStreamReceiverHw<GfxFamily>::create(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment) {
|
|
|
|
auto csr = new AUBCommandStreamReceiverHw<GfxFamily>(hwInfoIn, fileName, standalone, executionEnvironment);
|
2018-07-09 17:31:36 +08:00
|
|
|
|
2018-11-27 15:31:00 +08:00
|
|
|
if (!csr->aubManager && !csr->subCaptureManager->isSubCaptureMode()) {
|
2018-09-20 06:36:44 +08:00
|
|
|
csr->openFile(fileName);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return csr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-11-26 21:04:52 +08:00
|
|
|
FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
2018-06-13 02:33:03 +08:00
|
|
|
if (subCaptureManager->isSubCaptureMode()) {
|
|
|
|
if (!subCaptureManager->isSubCaptureEnabled()) {
|
|
|
|
if (this->standalone) {
|
|
|
|
*this->tagAddress = this->peekLatestSentTaskCount();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 13:28:20 +08:00
|
|
|
auto streamLocked = getAubStream()->lockStream();
|
2018-11-26 21:04:52 +08:00
|
|
|
auto engineIndex = getEngineIndex(osContext->getEngineType().type);
|
2018-10-24 17:15:06 +08:00
|
|
|
auto engineInstance = allEngineInstances[engineIndex];
|
2018-07-09 17:31:36 +08:00
|
|
|
|
2018-11-26 06:58:12 +08:00
|
|
|
initializeEngine(engineIndex);
|
2018-07-09 17:31:36 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
// Write our batch buffer
|
|
|
|
auto pBatchBuffer = ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset);
|
2018-08-24 21:23:45 +08:00
|
|
|
auto batchBufferGpuAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
|
2017-12-21 07:45:38 +08:00
|
|
|
auto currentOffset = batchBuffer.usedSize;
|
|
|
|
DEBUG_BREAK_IF(currentOffset < batchBuffer.startOffset);
|
|
|
|
auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset;
|
2018-03-01 05:50:41 +08:00
|
|
|
|
2018-08-24 21:23:45 +08:00
|
|
|
std::unique_ptr<GraphicsAllocation, std::function<void(GraphicsAllocation *)>> flatBatchBuffer(
|
|
|
|
nullptr, [&](GraphicsAllocation *ptr) { this->getMemoryManager()->freeGraphicsMemory(ptr); });
|
2018-04-04 17:34:46 +08:00
|
|
|
if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) {
|
|
|
|
flatBatchBuffer.reset(this->flatBatchBufferHelper->flattenBatchBuffer(batchBuffer, sizeBatchBuffer, this->dispatchMode));
|
2018-03-01 05:50:41 +08:00
|
|
|
if (flatBatchBuffer.get() != nullptr) {
|
2018-08-24 21:23:45 +08:00
|
|
|
pBatchBuffer = flatBatchBuffer->getUnderlyingBuffer();
|
2018-10-05 21:38:20 +08:00
|
|
|
batchBufferGpuAddress = flatBatchBuffer->getGpuAddress();
|
|
|
|
batchBuffer.commandBufferAllocation = flatBatchBuffer.get();
|
2018-03-01 05:50:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-26 06:58:12 +08:00
|
|
|
if (this->standalone) {
|
|
|
|
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
|
|
|
|
if (!DebugManager.flags.FlattenBatchBufferForAUBDump.get()) {
|
|
|
|
CommandStreamReceiver::makeResident(*batchBuffer.commandBufferAllocation);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allocationsForResidency.push_back(batchBuffer.commandBufferAllocation);
|
2018-12-03 17:05:36 +08:00
|
|
|
batchBuffer.commandBufferAllocation->updateResidencyTaskCount(this->taskCount, this->osContext->getContextId());
|
2018-11-26 06:58:12 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-26 21:04:52 +08:00
|
|
|
processResidency(allocationsForResidency);
|
2018-11-26 06:58:12 +08:00
|
|
|
|
|
|
|
submitBatchBuffer(engineIndex, batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, this->getMemoryBank(batchBuffer.commandBufferAllocation), getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));
|
|
|
|
|
|
|
|
pollForCompletion(engineInstance);
|
|
|
|
if (this->standalone) {
|
|
|
|
*this->tagAddress = this->peekLatestSentTaskCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subCaptureManager->isSubCaptureMode()) {
|
|
|
|
subCaptureManager->disableSubCapture();
|
|
|
|
}
|
|
|
|
|
|
|
|
getAubStream()->flush();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
bool AUBCommandStreamReceiverHw<GfxFamily>::addPatchInfoComments() {
|
|
|
|
std::map<uint64_t, uint64_t> allocationsMap;
|
|
|
|
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "PatchInfoData" << std::endl;
|
|
|
|
for (auto &patchInfoData : this->flatBatchBufferHelper->getPatchInfoCollection()) {
|
|
|
|
str << std::hex << patchInfoData.sourceAllocation << ";";
|
|
|
|
str << std::hex << patchInfoData.sourceAllocationOffset << ";";
|
|
|
|
str << std::hex << patchInfoData.sourceType << ";";
|
|
|
|
str << std::hex << patchInfoData.targetAllocation << ";";
|
|
|
|
str << std::hex << patchInfoData.targetAllocationOffset << ";";
|
|
|
|
str << std::hex << patchInfoData.targetType << ";";
|
|
|
|
str << std::endl;
|
|
|
|
|
|
|
|
if (patchInfoData.sourceAllocation) {
|
|
|
|
allocationsMap.insert(std::pair<uint64_t, uint64_t>(patchInfoData.sourceAllocation,
|
|
|
|
ppgtt->map(static_cast<uintptr_t>(patchInfoData.sourceAllocation), 1, 0, MemoryBanks::MainBank)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (patchInfoData.targetAllocation) {
|
|
|
|
allocationsMap.insert(std::pair<uint64_t, uintptr_t>(patchInfoData.targetAllocation,
|
|
|
|
ppgtt->map(static_cast<uintptr_t>(patchInfoData.targetAllocation), 1, 0, MemoryBanks::MainBank)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool result = getAubStream()->addComment(str.str().c_str());
|
|
|
|
this->flatBatchBufferHelper->getPatchInfoCollection().clear();
|
|
|
|
if (!result) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostringstream allocationStr;
|
|
|
|
allocationStr << "AllocationsList" << std::endl;
|
|
|
|
for (auto &element : allocationsMap) {
|
|
|
|
allocationStr << std::hex << element.first << ";" << element.second << std::endl;
|
|
|
|
}
|
|
|
|
result = getAubStream()->addComment(allocationStr.str().c_str());
|
|
|
|
if (!result) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) {
|
2018-11-27 15:31:00 +08:00
|
|
|
if (hardwareContext) {
|
|
|
|
hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-26 06:58:12 +08:00
|
|
|
auto engineInstance = allEngineInstances[engineIndex];
|
|
|
|
auto csTraits = getCsTraits(engineInstance);
|
|
|
|
auto &engineInfo = engineInfoTable[engineIndex];
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ostringstream str;
|
2018-11-26 06:58:12 +08:00
|
|
|
str << "ppgtt: " << std::hex << std::showbase << batchBuffer;
|
2018-11-02 13:28:20 +08:00
|
|
|
getAubStream()->addComment(str.str().c_str());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-11-26 06:58:12 +08:00
|
|
|
auto physBatchBuffer = ppgtt->map(static_cast<uintptr_t>(batchBufferGpuAddress), batchBufferSize, entryBits, memoryBank);
|
2018-09-14 20:31:37 +08:00
|
|
|
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
2018-11-26 06:58:12 +08:00
|
|
|
AUB::reserveAddressPPGTT(*stream, static_cast<uintptr_t>(batchBufferGpuAddress), batchBufferSize, physBatchBuffer,
|
|
|
|
entryBits, aubHelperHw);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
AUB::addMemoryWrite(
|
2018-03-14 18:07:51 +08:00
|
|
|
*stream,
|
2017-12-21 07:45:38 +08:00
|
|
|
physBatchBuffer,
|
2018-11-26 06:58:12 +08:00
|
|
|
batchBuffer,
|
|
|
|
batchBufferSize,
|
2018-09-28 00:56:02 +08:00
|
|
|
this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary),
|
2017-12-21 07:45:38 +08:00
|
|
|
AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary);
|
|
|
|
}
|
|
|
|
|
2018-03-14 18:07:51 +08:00
|
|
|
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
|
2018-11-26 06:58:12 +08:00
|
|
|
addGUCStartMessage(static_cast<uint64_t>(reinterpret_cast<std::uintptr_t>(batchBuffer)), engineInstance.type);
|
2018-03-14 18:07:51 +08:00
|
|
|
addPatchInfoComments();
|
|
|
|
}
|
2018-03-01 05:50:41 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
// Add a batch buffer start to the ring buffer
|
|
|
|
auto previousTail = engineInfo.tailRingBuffer;
|
|
|
|
{
|
|
|
|
typedef typename GfxFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
|
|
|
|
typedef typename GfxFamily::MI_NOOP MI_NOOP;
|
|
|
|
|
|
|
|
auto pTail = ptrOffset(engineInfo.pRingBuffer, engineInfo.tailRingBuffer);
|
|
|
|
auto ggttTail = ptrOffset(engineInfo.ggttRingBuffer, engineInfo.tailRingBuffer);
|
|
|
|
|
|
|
|
auto sizeNeeded =
|
|
|
|
sizeof(MI_BATCH_BUFFER_START) +
|
|
|
|
sizeof(MI_LOAD_REGISTER_IMM);
|
|
|
|
|
|
|
|
auto tailAlignment = sizeof(uint64_t);
|
|
|
|
sizeNeeded = alignUp(sizeNeeded, tailAlignment);
|
|
|
|
|
|
|
|
if (engineInfo.tailRingBuffer + sizeNeeded >= engineInfo.sizeRingBuffer) {
|
|
|
|
// Pad the remaining ring with NOOPs
|
|
|
|
auto sizeToWrap = engineInfo.sizeRingBuffer - engineInfo.tailRingBuffer;
|
|
|
|
memset(pTail, 0, sizeToWrap);
|
|
|
|
// write remaining ring
|
2018-09-19 04:17:55 +08:00
|
|
|
|
2018-09-26 07:27:29 +08:00
|
|
|
auto physDumpStart = ggtt->map(ggttTail, sizeToWrap, this->getGTTBits(), getMemoryBankForGtt());
|
2017-12-21 07:45:38 +08:00
|
|
|
AUB::addMemoryWrite(
|
2018-03-14 18:07:51 +08:00
|
|
|
*stream,
|
2017-12-21 07:45:38 +08:00
|
|
|
physDumpStart,
|
|
|
|
pTail,
|
|
|
|
sizeToWrap,
|
2018-09-28 00:56:02 +08:00
|
|
|
this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceCommandBuffer),
|
2017-12-21 07:45:38 +08:00
|
|
|
AubMemDump::DataTypeHintValues::TraceCommandBuffer);
|
|
|
|
previousTail = 0;
|
|
|
|
engineInfo.tailRingBuffer = 0;
|
|
|
|
pTail = engineInfo.pRingBuffer;
|
|
|
|
} else if (engineInfo.tailRingBuffer == 0) {
|
|
|
|
// Add a LRI if this is our first submission
|
|
|
|
auto lri = MI_LOAD_REGISTER_IMM::sInit();
|
2018-11-26 18:20:50 +08:00
|
|
|
lri.setRegisterOffset(AubMemDump::computeRegisterOffset(csTraits.mmioBase, 0x2244));
|
2017-12-21 07:45:38 +08:00
|
|
|
lri.setDataDword(0x00010000);
|
|
|
|
*(MI_LOAD_REGISTER_IMM *)pTail = lri;
|
|
|
|
pTail = ((MI_LOAD_REGISTER_IMM *)pTail) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add our BBS
|
|
|
|
auto bbs = MI_BATCH_BUFFER_START::sInit();
|
2018-08-24 21:23:45 +08:00
|
|
|
bbs.setBatchBufferStartAddressGraphicsaddress472(static_cast<uint64_t>(batchBufferGpuAddress));
|
2017-12-21 07:45:38 +08:00
|
|
|
bbs.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
|
|
|
|
*(MI_BATCH_BUFFER_START *)pTail = bbs;
|
|
|
|
pTail = ((MI_BATCH_BUFFER_START *)pTail) + 1;
|
|
|
|
|
|
|
|
// Compute our new ring tail.
|
|
|
|
engineInfo.tailRingBuffer = (uint32_t)ptrDiff(pTail, engineInfo.pRingBuffer);
|
|
|
|
|
|
|
|
// Add NOOPs as needed as our tail needs to be aligned
|
|
|
|
while (engineInfo.tailRingBuffer % tailAlignment) {
|
|
|
|
*(MI_NOOP *)pTail = MI_NOOP::sInit();
|
|
|
|
pTail = ((MI_NOOP *)pTail) + 1;
|
|
|
|
engineInfo.tailRingBuffer = (uint32_t)ptrDiff(pTail, engineInfo.pRingBuffer);
|
|
|
|
}
|
|
|
|
UNRECOVERABLE_IF((engineInfo.tailRingBuffer % tailAlignment) != 0);
|
|
|
|
|
|
|
|
// Only dump the new commands
|
|
|
|
auto ggttDumpStart = ptrOffset(engineInfo.ggttRingBuffer, previousTail);
|
|
|
|
auto dumpStart = ptrOffset(engineInfo.pRingBuffer, previousTail);
|
|
|
|
auto dumpLength = engineInfo.tailRingBuffer - previousTail;
|
|
|
|
|
|
|
|
// write ring
|
|
|
|
{
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "ggtt: " << std::hex << std::showbase << ggttDumpStart;
|
2018-11-02 13:28:20 +08:00
|
|
|
getAubStream()->addComment(str.str().c_str());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 07:27:29 +08:00
|
|
|
auto physDumpStart = ggtt->map(ggttDumpStart, dumpLength, this->getGTTBits(), getMemoryBankForGtt());
|
2017-12-21 07:45:38 +08:00
|
|
|
AUB::addMemoryWrite(
|
2018-03-14 18:07:51 +08:00
|
|
|
*stream,
|
2017-12-21 07:45:38 +08:00
|
|
|
physDumpStart,
|
|
|
|
dumpStart,
|
|
|
|
dumpLength,
|
2018-09-28 00:56:02 +08:00
|
|
|
this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceCommandBuffer),
|
2017-12-21 07:45:38 +08:00
|
|
|
AubMemDump::DataTypeHintValues::TraceCommandBuffer);
|
|
|
|
|
|
|
|
// update the ring mmio tail in the LRCA
|
|
|
|
{
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "ggtt: " << std::hex << std::showbase << engineInfo.ggttLRCA + 0x101c;
|
2018-11-02 13:28:20 +08:00
|
|
|
getAubStream()->addComment(str.str().c_str());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 07:27:29 +08:00
|
|
|
auto physLRCA = ggtt->map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRingBuffer), this->getGTTBits(), getMemoryBankForGtt());
|
2017-12-21 07:45:38 +08:00
|
|
|
AUB::addMemoryWrite(
|
2018-03-14 18:07:51 +08:00
|
|
|
*stream,
|
2017-12-21 07:45:38 +08:00
|
|
|
physLRCA + 0x101c,
|
|
|
|
&engineInfo.tailRingBuffer,
|
|
|
|
sizeof(engineInfo.tailRingBuffer),
|
2018-11-26 06:58:12 +08:00
|
|
|
this->getAddressSpace(csTraits.aubHintLRCA));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
DEBUG_BREAK_IF(engineInfo.tailRingBuffer >= engineInfo.sizeRingBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submit our execlist by submitting to the execlist submit ports
|
|
|
|
{
|
|
|
|
typename AUB::MiContextDescriptorReg contextDescriptor = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
|
|
|
|
|
|
|
contextDescriptor.sData.Valid = true;
|
|
|
|
contextDescriptor.sData.ForcePageDirRestore = false;
|
|
|
|
contextDescriptor.sData.ForceRestore = false;
|
|
|
|
contextDescriptor.sData.Legacy = true;
|
|
|
|
contextDescriptor.sData.FaultSupport = 0;
|
|
|
|
contextDescriptor.sData.PrivilegeAccessOrPPGTT = true;
|
|
|
|
contextDescriptor.sData.ADor64bitSupport = AUB::Traits::addressingBits > 32;
|
|
|
|
|
|
|
|
auto ggttLRCA = engineInfo.ggttLRCA;
|
|
|
|
contextDescriptor.sData.LogicalRingCtxAddress = ggttLRCA / 4096;
|
|
|
|
contextDescriptor.sData.ContextID = 0;
|
|
|
|
|
2018-10-24 17:15:06 +08:00
|
|
|
submitLRCA(engineInstance, contextDescriptor);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-03-14 18:07:51 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <typename GfxFamily>
|
2018-10-24 17:15:06 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::submitLRCA(EngineInstanceT engineInstance, const typename AUBCommandStreamReceiverHw<GfxFamily>::MiContextDescriptorReg &contextDescriptor) {
|
|
|
|
auto mmioBase = getCsTraits(engineInstance).mmioBase;
|
2018-11-26 18:20:50 +08:00
|
|
|
stream->writeMMIO(AubMemDump::computeRegisterOffset(mmioBase, 0x2230), 0);
|
|
|
|
stream->writeMMIO(AubMemDump::computeRegisterOffset(mmioBase, 0x2230), 0);
|
|
|
|
stream->writeMMIO(AubMemDump::computeRegisterOffset(mmioBase, 0x2230), contextDescriptor.ulData[1]);
|
|
|
|
stream->writeMMIO(AubMemDump::computeRegisterOffset(mmioBase, 0x2230), contextDescriptor.ulData[0]);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-10-24 17:15:06 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletion(EngineInstanceT engineInstance) {
|
2018-11-27 15:31:00 +08:00
|
|
|
if (hardwareContext) {
|
|
|
|
hardwareContext->pollForCompletion();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
typedef typename AubMemDump::CmdServicesMemTraceRegisterPoll CmdServicesMemTraceRegisterPoll;
|
|
|
|
|
2018-10-24 17:15:06 +08:00
|
|
|
auto mmioBase = getCsTraits(engineInstance).mmioBase;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool pollNotEqual = false;
|
2018-11-02 13:28:20 +08:00
|
|
|
stream->registerPoll(
|
2018-11-26 18:20:50 +08:00
|
|
|
AubMemDump::computeRegisterOffset(mmioBase, 0x2234), //EXECLIST_STATUS
|
2017-12-21 07:45:38 +08:00
|
|
|
0x100,
|
|
|
|
0x100,
|
|
|
|
pollNotEqual,
|
|
|
|
CmdServicesMemTraceRegisterPoll::TimeoutActionValues::Abort);
|
|
|
|
}
|
|
|
|
|
2018-08-17 19:38:09 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::makeResidentExternal(AllocationView &allocationView) {
|
|
|
|
externalAllocations.push_back(allocationView);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::makeNonResidentExternal(uint64_t gpuAddress) {
|
|
|
|
for (auto it = externalAllocations.begin(); it != externalAllocations.end(); it++) {
|
|
|
|
if (it->first == gpuAddress) {
|
|
|
|
externalAllocations.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 10:17:57 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) {
|
2018-11-27 15:31:00 +08:00
|
|
|
if (hardwareContext) {
|
|
|
|
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
|
|
|
|
hardwareContext->writeMemory(gpuAddress, cpuAddress, size, memoryBank, hint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-27 10:17:57 +08:00
|
|
|
{
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "ppgtt: " << std::hex << std::showbase << gpuAddress << " end address: " << gpuAddress + size << " cpu address: " << cpuAddress << " device mask: " << devicesBitfield << " size: " << std::dec << size;
|
|
|
|
getAubStream()->addComment(str.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
|
|
|
|
|
|
|
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
|
|
|
|
AUB::reserveAddressGGTTAndWriteMmeory(*stream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, entryBits,
|
|
|
|
aubHelperHw);
|
|
|
|
};
|
|
|
|
|
|
|
|
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, entryBits, walker, memoryBank);
|
|
|
|
}
|
|
|
|
|
2018-01-11 05:03:23 +08:00
|
|
|
template <typename GfxFamily>
|
2018-01-17 07:58:11 +08:00
|
|
|
bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxAllocation) {
|
2018-11-27 16:51:11 +08:00
|
|
|
auto cpuAddress = gfxAllocation.getUnderlyingBuffer();
|
2018-06-21 17:36:47 +08:00
|
|
|
auto gpuAddress = GmmHelper::decanonize(gfxAllocation.getGpuAddress());
|
2018-01-11 05:03:23 +08:00
|
|
|
auto size = gfxAllocation.getUnderlyingBufferSize();
|
2018-09-04 04:44:58 +08:00
|
|
|
if (gfxAllocation.gmm && gfxAllocation.gmm->isRenderCompressed) {
|
|
|
|
size = gfxAllocation.gmm->gmmResourceInfo->getSizeAllocation();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-07-20 03:34:45 +08:00
|
|
|
if ((size == 0) || !gfxAllocation.isAubWritable())
|
2018-01-17 07:58:11 +08:00
|
|
|
return false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-18 02:14:40 +08:00
|
|
|
if (cpuAddress == nullptr) {
|
|
|
|
DEBUG_BREAK_IF(gfxAllocation.isLocked());
|
|
|
|
cpuAddress = this->getMemoryManager()->lockResource(&gfxAllocation);
|
|
|
|
gfxAllocation.setLocked(true);
|
|
|
|
}
|
2018-09-11 20:45:43 +08:00
|
|
|
|
2018-11-27 10:17:57 +08:00
|
|
|
writeMemory(gpuAddress, cpuAddress, size, this->getMemoryBank(&gfxAllocation), getPPGTTAdditionalBits(&gfxAllocation), gfxAllocation.devicesBitfield);
|
2018-01-17 07:58:11 +08:00
|
|
|
|
2018-02-18 02:14:40 +08:00
|
|
|
if (gfxAllocation.isLocked()) {
|
|
|
|
this->getMemoryManager()->unlockResource(&gfxAllocation);
|
|
|
|
gfxAllocation.setLocked(false);
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:36:26 +08:00
|
|
|
if (AubHelper::isOneTimeAubWritableAllocationType(gfxAllocation.getAllocationType())) {
|
2018-07-20 03:34:45 +08:00
|
|
|
gfxAllocation.setAubWritable(false);
|
|
|
|
}
|
2018-01-17 07:58:11 +08:00
|
|
|
return true;
|
2018-01-11 05:03:23 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 19:38:09 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(AllocationView &allocationView) {
|
2018-11-07 20:04:10 +08:00
|
|
|
GraphicsAllocation gfxAllocation(reinterpret_cast<void *>(allocationView.first), allocationView.first, 0llu, allocationView.second, this->getMemoryManager()->getOsContextCount(), false);
|
2018-08-17 19:38:09 +08:00
|
|
|
return writeMemory(gfxAllocation);
|
|
|
|
}
|
|
|
|
|
2018-09-24 12:42:07 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::expectMMIO(uint32_t mmioRegister, uint32_t expectedValue) {
|
|
|
|
using AubMemDump::CmdServicesMemTraceRegisterCompare;
|
|
|
|
CmdServicesMemTraceRegisterCompare header;
|
|
|
|
memset(&header, 0, sizeof(header));
|
|
|
|
header.setHeader();
|
|
|
|
|
|
|
|
header.data[0] = expectedValue;
|
|
|
|
header.registerOffset = mmioRegister;
|
|
|
|
header.noReadExpect = CmdServicesMemTraceRegisterCompare::NoReadExpectValues::ReadExpect;
|
|
|
|
header.registerSize = CmdServicesMemTraceRegisterCompare::RegisterSizeValues::Dword;
|
|
|
|
header.registerSpace = CmdServicesMemTraceRegisterCompare::RegisterSpaceValues::Mmio;
|
|
|
|
header.readMaskLow = 0xffffffff;
|
|
|
|
header.readMaskHigh = 0xffffffff;
|
|
|
|
header.dwordCount = (sizeof(header) / sizeof(uint32_t)) - 1;
|
|
|
|
|
2018-11-02 13:28:20 +08:00
|
|
|
this->getAubStream()->fileHandle.write(reinterpret_cast<char *>(&header), sizeof(header));
|
2018-09-24 12:42:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-11-16 18:18:53 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) {
|
|
|
|
expectMemory(gfxAddress, srcAddress, length,
|
|
|
|
AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) {
|
|
|
|
expectMemory(gfxAddress, srcAddress, length,
|
|
|
|
AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::expectMemory(void *gfxAddress, const void *srcAddress,
|
|
|
|
size_t length, uint32_t compareOperation) {
|
2018-09-24 12:42:07 +08:00
|
|
|
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
|
|
|
|
UNRECOVERABLE_IF(offset > length);
|
|
|
|
|
2018-11-02 13:28:20 +08:00
|
|
|
this->getAubStream()->expectMemory(physAddress,
|
|
|
|
reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(srcAddress) + offset),
|
|
|
|
size,
|
2018-11-16 18:18:53 +08:00
|
|
|
this->getAddressSpaceFromPTEBits(entryBits),
|
|
|
|
compareOperation);
|
2018-09-24 12:42:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this->ppgtt->pageWalk(reinterpret_cast<uintptr_t>(gfxAddress), length, 0, PageTableEntry::nonValidBits, walker, MemoryBanks::BankNotSpecified);
|
|
|
|
}
|
|
|
|
|
2018-01-11 05:03:23 +08:00
|
|
|
template <typename GfxFamily>
|
2018-11-26 21:04:52 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::processResidency(ResidencyContainer &allocationsForResidency) {
|
2018-06-13 02:33:03 +08:00
|
|
|
if (subCaptureManager->isSubCaptureMode()) {
|
|
|
|
if (!subCaptureManager->isSubCaptureEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 19:38:09 +08:00
|
|
|
for (auto &externalAllocation : externalAllocations) {
|
|
|
|
if (!writeMemory(externalAllocation)) {
|
|
|
|
DEBUG_BREAK_IF(externalAllocation.second != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 16:39:21 +08:00
|
|
|
for (auto &gfxAllocation : allocationsForResidency) {
|
2018-07-09 17:31:36 +08:00
|
|
|
if (dumpAubNonWritable) {
|
2018-07-20 03:34:45 +08:00
|
|
|
gfxAllocation->setAubWritable(true);
|
2018-07-09 17:31:36 +08:00
|
|
|
}
|
2018-01-17 07:58:11 +08:00
|
|
|
if (!writeMemory(*gfxAllocation)) {
|
2018-07-20 03:34:45 +08:00
|
|
|
DEBUG_BREAK_IF(!((gfxAllocation->getUnderlyingBufferSize() == 0) || !gfxAllocation->isAubWritable()));
|
2018-01-17 07:58:11 +08:00
|
|
|
}
|
2018-12-03 17:05:36 +08:00
|
|
|
gfxAllocation->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-07-09 17:31:36 +08:00
|
|
|
|
|
|
|
dumpAubNonWritable = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::makeNonResident(GraphicsAllocation &gfxAllocation) {
|
2018-12-03 17:05:36 +08:00
|
|
|
if (gfxAllocation.isResident(this->osContext->getContextId())) {
|
2018-09-14 19:48:02 +08:00
|
|
|
this->getEvictionAllocations().push_back(&gfxAllocation);
|
2018-12-03 17:05:36 +08:00
|
|
|
gfxAllocation.resetResidencyTaskCount(this->osContext->getContextId());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 02:33:03 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) {
|
2018-07-09 17:31:36 +08:00
|
|
|
bool active = subCaptureManager->activateSubCapture(dispatchInfo);
|
|
|
|
if (active) {
|
|
|
|
std::string subCaptureFile = subCaptureManager->getSubCaptureFileName(dispatchInfo);
|
2018-09-20 06:36:44 +08:00
|
|
|
auto isReopened = reopenFile(subCaptureFile);
|
|
|
|
if (isReopened) {
|
2018-07-09 17:31:36 +08:00
|
|
|
dumpAubNonWritable = true;
|
|
|
|
}
|
|
|
|
}
|
2018-06-13 02:33:03 +08:00
|
|
|
if (this->standalone) {
|
|
|
|
if (DebugManager.flags.ForceCsrFlushing.get()) {
|
|
|
|
this->flushBatchedSubmissions();
|
|
|
|
}
|
|
|
|
if (DebugManager.flags.ForceCsrReprogramming.get()) {
|
|
|
|
this->initProgrammingFlags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:08:09 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getDumpHandle() {
|
2018-10-31 07:25:33 +08:00
|
|
|
return hashPtrToU32(this);
|
2018-10-31 02:08:09 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <typename GfxFamily>
|
2018-10-20 02:32:05 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::addContextToken(uint32_t dumpHandle) {
|
2017-12-21 07:45:38 +08:00
|
|
|
// Some simulator versions don't support adding the context token.
|
|
|
|
// This hook allows specialization for those that do.
|
|
|
|
}
|
2018-03-14 18:07:51 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2018-04-04 17:34:46 +08:00
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::addGUCStartMessage(uint64_t batchBufferAddress, EngineType engineType) {
|
|
|
|
typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
|
|
|
|
|
|
|
|
auto bufferSize = sizeof(uint32_t) + sizeof(MI_BATCH_BUFFER_START);
|
2018-09-14 20:31:37 +08:00
|
|
|
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
2018-04-04 17:34:46 +08:00
|
|
|
|
|
|
|
std::unique_ptr<void, std::function<void(void *)>> buffer(this->getMemoryManager()->alignedMallocWrapper(bufferSize, MemoryConstants::pageSize), [&](void *ptr) { this->getMemoryManager()->alignedFreeWrapper(ptr); });
|
|
|
|
LinearStream linearStream(buffer.get(), bufferSize);
|
|
|
|
|
|
|
|
uint32_t *header = static_cast<uint32_t *>(linearStream.getSpace(sizeof(uint32_t)));
|
|
|
|
*header = getGUCWorkQueueItemHeader(engineType);
|
|
|
|
|
|
|
|
MI_BATCH_BUFFER_START *miBatchBufferStart = linearStream.getSpaceForCmd<MI_BATCH_BUFFER_START>();
|
|
|
|
DEBUG_BREAK_IF(bufferSize != linearStream.getUsed());
|
|
|
|
miBatchBufferStart->init();
|
|
|
|
miBatchBufferStart->setBatchBufferStartAddressGraphicsaddress472(AUB::ptrToPPGTT(buffer.get()));
|
|
|
|
miBatchBufferStart->setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
|
|
|
|
|
2018-09-19 04:17:55 +08:00
|
|
|
auto physBufferAddres = ppgtt->map(reinterpret_cast<uintptr_t>(buffer.get()), bufferSize,
|
|
|
|
getPPGTTAdditionalBits(linearStream.getGraphicsAllocation()),
|
2018-09-21 04:54:19 +08:00
|
|
|
MemoryBanks::MainBank);
|
2018-09-19 04:17:55 +08:00
|
|
|
|
2018-09-14 20:31:37 +08:00
|
|
|
AUB::reserveAddressPPGTT(*stream, reinterpret_cast<uintptr_t>(buffer.get()), bufferSize, physBufferAddres,
|
|
|
|
getPPGTTAdditionalBits(linearStream.getGraphicsAllocation()),
|
|
|
|
aubHelperHw);
|
2018-04-04 17:34:46 +08:00
|
|
|
|
|
|
|
AUB::addMemoryWrite(
|
|
|
|
*stream,
|
|
|
|
physBufferAddres,
|
|
|
|
buffer.get(),
|
|
|
|
bufferSize,
|
2018-09-28 00:56:02 +08:00
|
|
|
this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceNotype));
|
2018-04-04 17:34:46 +08:00
|
|
|
|
|
|
|
PatchInfoData patchInfoData(batchBufferAddress, 0u, PatchInfoAllocationType::Default, reinterpret_cast<uintptr_t>(buffer.get()), sizeof(uint32_t) + sizeof(MI_BATCH_BUFFER_START) - sizeof(uint64_t), PatchInfoAllocationType::GUCStartMessage);
|
|
|
|
this->flatBatchBufferHelper->setPatchInfoData(patchInfoData);
|
2018-03-14 18:07:51 +08:00
|
|
|
}
|
2018-04-04 17:34:46 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getGUCWorkQueueItemHeader(EngineType engineType) {
|
|
|
|
uint32_t GUCWorkQueueItemHeader = 0x00030001;
|
|
|
|
return GUCWorkQueueItemHeader;
|
|
|
|
}
|
|
|
|
|
2018-05-09 21:25:01 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
uint64_t AUBCommandStreamReceiverHw<GfxFamily>::getPPGTTAdditionalBits(GraphicsAllocation *gfxAllocation) {
|
2018-09-11 16:26:39 +08:00
|
|
|
return BIT(PageTableEntry::presentBit) | BIT(PageTableEntry::writableBit) | BIT(PageTableEntry::userSupervisorBit);
|
2018-05-09 21:25:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void AUBCommandStreamReceiverHw<GfxFamily>::getGTTData(void *memory, AubGTTData &data) {
|
|
|
|
data.present = true;
|
2018-06-21 20:54:59 +08:00
|
|
|
data.localMemory = false;
|
2018-05-09 21:25:01 +08:00
|
|
|
}
|
|
|
|
|
2018-09-21 10:33:21 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
int AUBCommandStreamReceiverHw<GfxFamily>::getAddressSpaceFromPTEBits(uint64_t entryBits) const {
|
|
|
|
return AubMemDump::AddressSpaceValues::TraceNonlocal;
|
|
|
|
}
|
|
|
|
|
2018-09-21 04:54:19 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getMemoryBankForGtt() const {
|
|
|
|
return MemoryBanks::getBank(this->deviceIndex);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|