2019-06-26 17:37:46 +08:00
|
|
|
/*
|
2022-02-03 21:29:48 +08:00
|
|
|
* Copyright (C) 2019-2022 Intel Corporation
|
2019-06-26 17:37:46 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/blit_commands_helper.h"
|
2019-06-26 17:37:46 +08:00
|
|
|
|
2021-07-29 19:22:24 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
|
|
|
#include "shared/source/memory_manager/surface.h"
|
2019-06-26 17:37:46 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
2020-07-10 23:04:42 +08:00
|
|
|
|
|
|
|
namespace BlitHelperFunctions {
|
|
|
|
BlitMemoryToAllocationFunc blitMemoryToAllocation = BlitHelper::blitMemoryToAllocation;
|
|
|
|
} // namespace BlitHelperFunctions
|
|
|
|
|
2021-06-08 21:09:19 +08:00
|
|
|
BlitProperties BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection blitDirection,
|
|
|
|
CommandStreamReceiver &commandStreamReceiver,
|
|
|
|
GraphicsAllocation *memObjAllocation,
|
|
|
|
GraphicsAllocation *preallocatedHostAllocation,
|
|
|
|
const void *hostPtr, uint64_t memObjGpuVa,
|
2021-09-08 05:21:19 +08:00
|
|
|
uint64_t hostAllocGpuVa, const Vec3<size_t> &hostPtrOffset,
|
|
|
|
const Vec3<size_t> ©Offset, Vec3<size_t> copySize,
|
2021-06-08 21:09:19 +08:00
|
|
|
size_t hostRowPitch, size_t hostSlicePitch,
|
|
|
|
size_t gpuRowPitch, size_t gpuSlicePitch) {
|
2019-09-18 17:18:32 +08:00
|
|
|
GraphicsAllocation *hostAllocation = nullptr;
|
2020-11-19 07:58:42 +08:00
|
|
|
auto clearColorAllocation = commandStreamReceiver.getClearColorAllocation();
|
2019-09-18 17:18:32 +08:00
|
|
|
|
2021-06-16 22:41:26 +08:00
|
|
|
copySize.y = copySize.y ? copySize.y : 1;
|
|
|
|
copySize.z = copySize.z ? copySize.z : 1;
|
|
|
|
|
2019-12-12 17:47:28 +08:00
|
|
|
if (preallocatedHostAllocation) {
|
|
|
|
hostAllocation = preallocatedHostAllocation;
|
|
|
|
UNRECOVERABLE_IF(hostAllocGpuVa == 0);
|
2019-09-18 17:18:32 +08:00
|
|
|
} else {
|
2021-06-16 22:41:26 +08:00
|
|
|
HostPtrSurface hostPtrSurface(hostPtr, static_cast<size_t>(copySize.x * copySize.y * copySize.z), true);
|
2019-09-18 17:18:32 +08:00
|
|
|
bool success = commandStreamReceiver.createAllocationForHostSurface(hostPtrSurface, false);
|
|
|
|
UNRECOVERABLE_IF(!success);
|
|
|
|
hostAllocation = hostPtrSurface.getAllocation();
|
2019-12-12 17:47:28 +08:00
|
|
|
hostAllocGpuVa = hostAllocation->getGpuAddress();
|
2019-09-18 17:18:32 +08:00
|
|
|
}
|
2019-07-01 17:08:58 +08:00
|
|
|
|
2020-10-20 21:27:49 +08:00
|
|
|
if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection ||
|
|
|
|
BlitterConstants::BlitDirection::HostPtrToImage == blitDirection) {
|
2019-12-12 17:47:28 +08:00
|
|
|
return {
|
|
|
|
nullptr, // outputTimestampPacket
|
|
|
|
blitDirection, // blitDirection
|
|
|
|
{}, // csrDependencies
|
|
|
|
AuxTranslationDirection::None, // auxTranslationDirection
|
|
|
|
memObjAllocation, // dstAllocation
|
|
|
|
hostAllocation, // srcAllocation
|
2020-11-19 07:58:42 +08:00
|
|
|
clearColorAllocation, // clearColorAllocation
|
2019-12-12 17:47:28 +08:00
|
|
|
memObjGpuVa, // dstGpuAddress
|
|
|
|
hostAllocGpuVa, // srcGpuAddress
|
|
|
|
copySize, // copySize
|
|
|
|
copyOffset, // dstOffset
|
2020-03-30 21:20:55 +08:00
|
|
|
hostPtrOffset, // srcOffset
|
2020-10-20 21:27:49 +08:00
|
|
|
gpuRowPitch, // dstRowPitch
|
|
|
|
gpuSlicePitch, // dstSlicePitch
|
|
|
|
hostRowPitch, // srcRowPitch
|
2021-06-07 21:58:03 +08:00
|
|
|
hostSlicePitch, // srcSlicePitch
|
|
|
|
copySize, // dstSize
|
|
|
|
copySize // srcSize
|
|
|
|
};
|
2020-03-30 21:20:55 +08:00
|
|
|
|
2019-06-26 17:37:46 +08:00
|
|
|
} else {
|
2019-12-12 17:47:28 +08:00
|
|
|
return {
|
|
|
|
nullptr, // outputTimestampPacket
|
|
|
|
blitDirection, // blitDirection
|
|
|
|
{}, // csrDependencies
|
|
|
|
AuxTranslationDirection::None, // auxTranslationDirection
|
|
|
|
hostAllocation, // dstAllocation
|
|
|
|
memObjAllocation, // srcAllocation
|
2020-11-19 07:58:42 +08:00
|
|
|
clearColorAllocation, // clearColorAllocation
|
2019-12-12 17:47:28 +08:00
|
|
|
hostAllocGpuVa, // dstGpuAddress
|
|
|
|
memObjGpuVa, // srcGpuAddress
|
|
|
|
copySize, // copySize
|
|
|
|
hostPtrOffset, // dstOffset
|
2020-02-25 16:55:13 +08:00
|
|
|
copyOffset, // srcOffset
|
|
|
|
hostRowPitch, // dstRowPitch
|
|
|
|
hostSlicePitch, // dstSlicePitch
|
|
|
|
gpuRowPitch, // srcRowPitch
|
2021-06-07 21:58:03 +08:00
|
|
|
gpuSlicePitch, // srcSlicePitch
|
|
|
|
copySize, // dstSize
|
|
|
|
copySize // srcSize
|
|
|
|
};
|
2020-02-25 16:55:13 +08:00
|
|
|
};
|
2019-06-26 17:37:46 +08:00
|
|
|
}
|
2019-06-27 22:08:20 +08:00
|
|
|
|
2021-07-30 08:28:45 +08:00
|
|
|
BlitProperties BlitProperties::constructPropertiesForCopy(GraphicsAllocation *dstAllocation, GraphicsAllocation *srcAllocation,
|
2021-09-08 05:21:19 +08:00
|
|
|
const Vec3<size_t> &dstOffset, const Vec3<size_t> &srcOffset, Vec3<size_t> copySize,
|
2021-07-30 08:28:45 +08:00
|
|
|
size_t srcRowPitch, size_t srcSlicePitch,
|
|
|
|
size_t dstRowPitch, size_t dstSlicePitch, GraphicsAllocation *clearColorAllocation) {
|
2020-04-02 17:47:30 +08:00
|
|
|
copySize.y = copySize.y ? copySize.y : 1;
|
|
|
|
copySize.z = copySize.z ? copySize.z : 1;
|
2019-07-01 17:08:58 +08:00
|
|
|
|
2019-12-12 17:47:28 +08:00
|
|
|
return {
|
|
|
|
nullptr, // outputTimestampPacket
|
|
|
|
BlitterConstants::BlitDirection::BufferToBuffer, // blitDirection
|
|
|
|
{}, // csrDependencies
|
|
|
|
AuxTranslationDirection::None, // auxTranslationDirection
|
|
|
|
dstAllocation, // dstAllocation
|
|
|
|
srcAllocation, // srcAllocation
|
2020-11-19 07:58:42 +08:00
|
|
|
clearColorAllocation, // clearColorAllocation
|
2019-12-12 17:47:28 +08:00
|
|
|
dstAllocation->getGpuAddress(), // dstGpuAddress
|
|
|
|
srcAllocation->getGpuAddress(), // srcGpuAddress
|
2020-04-02 17:47:30 +08:00
|
|
|
copySize, // copySize
|
|
|
|
dstOffset, // dstOffset
|
|
|
|
srcOffset, // srcOffset
|
|
|
|
dstRowPitch, // dstRowPitch
|
|
|
|
dstSlicePitch, // dstSlicePitch
|
|
|
|
srcRowPitch, // srcRowPitch
|
|
|
|
srcSlicePitch}; // srcSlicePitch
|
2019-07-04 20:22:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BlitProperties BlitProperties::constructPropertiesForAuxTranslation(AuxTranslationDirection auxTranslationDirection,
|
2020-11-19 07:58:42 +08:00
|
|
|
GraphicsAllocation *allocation, GraphicsAllocation *clearColorAllocation) {
|
2019-12-12 17:47:28 +08:00
|
|
|
|
2019-07-04 20:22:28 +08:00
|
|
|
auto allocationSize = allocation->getUnderlyingBufferSize();
|
2019-12-12 17:47:28 +08:00
|
|
|
return {
|
|
|
|
nullptr, // outputTimestampPacket
|
|
|
|
BlitterConstants::BlitDirection::BufferToBuffer, // blitDirection
|
|
|
|
{}, // csrDependencies
|
|
|
|
auxTranslationDirection, // auxTranslationDirection
|
|
|
|
allocation, // dstAllocation
|
|
|
|
allocation, // srcAllocation
|
2020-11-19 07:58:42 +08:00
|
|
|
clearColorAllocation, // clearColorAllocation
|
2019-12-12 17:47:28 +08:00
|
|
|
allocation->getGpuAddress(), // dstGpuAddress
|
|
|
|
allocation->getGpuAddress(), // srcGpuAddress
|
2020-02-25 16:55:13 +08:00
|
|
|
{allocationSize, 1, 1}, // copySize
|
2019-12-12 17:47:28 +08:00
|
|
|
0, // dstOffset
|
|
|
|
0 // srcOffset
|
|
|
|
};
|
2019-07-01 17:08:58 +08:00
|
|
|
}
|
|
|
|
|
2019-11-18 20:35:44 +08:00
|
|
|
void BlitProperties::setupDependenciesForAuxTranslation(BlitPropertiesContainer &blitPropertiesContainer, TimestampPacketDependencies ×tampPacketDependencies,
|
2020-01-27 20:06:03 +08:00
|
|
|
TimestampPacketContainer &kernelTimestamps, const CsrDependencies &depsFromEvents,
|
2019-11-18 20:35:44 +08:00
|
|
|
CommandStreamReceiver &gpguCsr, CommandStreamReceiver &bcsCsr) {
|
|
|
|
auto numObjects = blitPropertiesContainer.size() / 2;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < numObjects; i++) {
|
|
|
|
blitPropertiesContainer[i].outputTimestampPacket = timestampPacketDependencies.auxToNonAuxNodes.peekNodes()[i];
|
|
|
|
blitPropertiesContainer[i + numObjects].outputTimestampPacket = timestampPacketDependencies.nonAuxToAuxNodes.peekNodes()[i];
|
|
|
|
}
|
|
|
|
|
2021-11-06 09:42:54 +08:00
|
|
|
gpguCsr.requestStallingCommandsOnNextFlush();
|
2019-11-18 20:35:44 +08:00
|
|
|
auto nodesAllocator = gpguCsr.getTimestampPacketAllocator();
|
|
|
|
timestampPacketDependencies.barrierNodes.add(nodesAllocator->getTag());
|
|
|
|
|
|
|
|
// wait for barrier and events before AuxToNonAux
|
2021-03-11 21:48:04 +08:00
|
|
|
blitPropertiesContainer[0].csrDependencies.timestampPacketContainer.push_back(×tampPacketDependencies.barrierNodes);
|
2020-01-27 20:06:03 +08:00
|
|
|
|
2021-03-11 21:48:04 +08:00
|
|
|
for (auto dep : depsFromEvents.timestampPacketContainer) {
|
|
|
|
blitPropertiesContainer[0].csrDependencies.timestampPacketContainer.push_back(dep);
|
2020-01-27 20:06:03 +08:00
|
|
|
}
|
2019-11-18 20:35:44 +08:00
|
|
|
|
|
|
|
// wait for NDR before NonAuxToAux
|
2021-03-11 21:48:04 +08:00
|
|
|
blitPropertiesContainer[numObjects].csrDependencies.timestampPacketContainer.push_back(×tampPacketDependencies.cacheFlushNodes);
|
|
|
|
blitPropertiesContainer[numObjects].csrDependencies.timestampPacketContainer.push_back(&kernelTimestamps);
|
2019-11-18 20:35:44 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 19:22:24 +08:00
|
|
|
BlitOperationResult BlitHelper::blitMemoryToAllocation(const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
|
2021-09-08 05:21:19 +08:00
|
|
|
const Vec3<size_t> &size) {
|
2021-07-29 19:22:24 +08:00
|
|
|
auto memoryBanks = memory->storageInfo.getMemoryBanks();
|
|
|
|
return blitMemoryToAllocationBanks(device, memory, offset, hostPtr, size, memoryBanks);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlitOperationResult BlitHelper::blitMemoryToAllocationBanks(const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
|
2021-09-08 05:21:19 +08:00
|
|
|
const Vec3<size_t> &size, DeviceBitfield memoryBanks) {
|
2021-07-29 19:22:24 +08:00
|
|
|
const auto &hwInfo = device.getHardwareInfo();
|
2021-10-21 19:16:19 +08:00
|
|
|
if (!hwInfo.capabilityTable.blitterOperationsSupported) {
|
2021-10-20 04:45:59 +08:00
|
|
|
return BlitOperationResult::Unsupported;
|
|
|
|
}
|
2022-12-12 20:39:04 +08:00
|
|
|
auto &gfxCoreHelper = device.getGfxCoreHelper();
|
2021-07-29 19:22:24 +08:00
|
|
|
|
|
|
|
UNRECOVERABLE_IF(memoryBanks.none());
|
|
|
|
|
|
|
|
auto pRootDevice = device.getRootDevice();
|
|
|
|
|
|
|
|
for (uint8_t tileId = 0u; tileId < 4u; tileId++) {
|
|
|
|
if (!memoryBanks.test(tileId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNRECOVERABLE_IF(!pRootDevice->getDeviceBitfield().test(tileId));
|
2021-08-31 19:49:04 +08:00
|
|
|
auto pDeviceForBlit = pRootDevice->getNearestGenericSubDevice(tileId);
|
2021-07-29 19:22:24 +08:00
|
|
|
auto &selectorCopyEngine = pDeviceForBlit->getSelectorCopyEngine();
|
2021-08-17 22:15:49 +08:00
|
|
|
auto deviceBitfield = pDeviceForBlit->getDeviceBitfield();
|
2022-04-27 19:06:16 +08:00
|
|
|
auto internalUsage = true;
|
2022-12-20 19:23:46 +08:00
|
|
|
auto bcsEngineType = EngineHelpers::getBcsEngineType(pDeviceForBlit->getRootDeviceEnvironment(), deviceBitfield, selectorCopyEngine, internalUsage);
|
2022-12-08 20:22:35 +08:00
|
|
|
auto bcsEngineUsage = gfxCoreHelper.preferInternalBcsEngine() ? EngineUsage::Internal : EngineUsage::Regular;
|
2022-04-27 19:06:16 +08:00
|
|
|
auto bcsEngine = pDeviceForBlit->tryGetEngine(bcsEngineType, bcsEngineUsage);
|
2021-08-04 18:58:15 +08:00
|
|
|
if (!bcsEngine) {
|
|
|
|
return BlitOperationResult::Unsupported;
|
|
|
|
}
|
|
|
|
|
2022-11-03 23:25:30 +08:00
|
|
|
bcsEngine->commandStreamReceiver->initializeResources();
|
2022-04-19 22:44:06 +08:00
|
|
|
bcsEngine->commandStreamReceiver->initDirectSubmission();
|
2021-07-29 19:22:24 +08:00
|
|
|
BlitPropertiesContainer blitPropertiesContainer;
|
|
|
|
blitPropertiesContainer.push_back(
|
|
|
|
BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::HostPtrToBuffer,
|
2021-08-04 18:58:15 +08:00
|
|
|
*bcsEngine->commandStreamReceiver, memory, nullptr,
|
2021-07-29 19:22:24 +08:00
|
|
|
hostPtr,
|
|
|
|
(memory->getGpuAddress() + offset),
|
|
|
|
0, 0, 0, size, 0, 0, 0, 0));
|
2022-05-06 00:52:25 +08:00
|
|
|
|
|
|
|
const auto newTaskCount = bcsEngine->commandStreamReceiver->flushBcsTask(blitPropertiesContainer, true, false, *pDeviceForBlit);
|
2022-11-04 21:57:42 +08:00
|
|
|
if (newTaskCount == CompletionStamp::gpuHang) {
|
2022-05-06 00:52:25 +08:00
|
|
|
return BlitOperationResult::GpuHang;
|
|
|
|
}
|
2021-07-29 19:22:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return BlitOperationResult::Success;
|
|
|
|
}
|
|
|
|
|
2019-06-26 17:37:46 +08:00
|
|
|
} // namespace NEO
|