2019-04-03 21:59:31 +08:00
|
|
|
/*
|
2020-02-05 23:07:52 +08:00
|
|
|
* Copyright (C) 2019-2020 Intel Corporation
|
2019-04-03 21:59:31 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-03-13 19:29:45 +08:00
|
|
|
#include "shared/source/command_container/command_encoder.h"
|
2020-05-21 18:36:23 +08:00
|
|
|
#include "shared/source/gmm_helper/gmm.h"
|
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
|
|
|
#include "shared/source/gmm_helper/resource_info.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/blit_commands_helper.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
2019-04-03 21:59:31 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
2020-05-06 20:54:30 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
uint64_t BlitCommandsHelper<GfxFamily>::getMaxBlitWidth() {
|
|
|
|
if (DebugManager.flags.LimitBlitterMaxWidth.get() != -1) {
|
|
|
|
return static_cast<uint64_t>(DebugManager.flags.LimitBlitterMaxWidth.get());
|
|
|
|
}
|
|
|
|
return BlitterConstants::maxBlitWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
uint64_t BlitCommandsHelper<GfxFamily>::getMaxBlitHeight() {
|
|
|
|
if (DebugManager.flags.LimitBlitterMaxHeight.get() != -1) {
|
|
|
|
return static_cast<uint64_t>(DebugManager.flags.LimitBlitterMaxHeight.get());
|
|
|
|
}
|
|
|
|
return BlitterConstants::maxBlitHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void BlitCommandsHelper<GfxFamily>::dispatchPostBlitCommand(LinearStream &linearStream) {
|
|
|
|
bool useFlush = false;
|
|
|
|
if (DebugManager.flags.FlushAfterEachBlit.get() != -1) {
|
|
|
|
useFlush = static_cast<bool>(DebugManager.flags.FlushAfterEachBlit.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useFlush) {
|
|
|
|
EncodeMiFlushDW<GfxFamily>::programMiFlushDw(linearStream, 0, 0, false, false);
|
|
|
|
} else {
|
|
|
|
auto miArbCheckStream = linearStream.getSpaceForCmd<typename GfxFamily::MI_ARB_CHECK>();
|
|
|
|
*miArbCheckStream = GfxFamily::cmdInitArbCheck;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
size_t BlitCommandsHelper<GfxFamily>::estimatePostBlitCommandSize() {
|
|
|
|
bool useFlush = false;
|
|
|
|
if (DebugManager.flags.FlushAfterEachBlit.get() != -1) {
|
|
|
|
useFlush = static_cast<bool>(DebugManager.flags.FlushAfterEachBlit.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useFlush) {
|
|
|
|
return sizeof(typename GfxFamily::MI_FLUSH_DW);
|
|
|
|
}
|
|
|
|
return sizeof(typename GfxFamily::MI_ARB_CHECK);
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:59:31 +08:00
|
|
|
template <typename GfxFamily>
|
2020-04-29 20:06:01 +08:00
|
|
|
size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(Vec3<size_t> copySize, const CsrDependencies &csrDependencies, bool updateTimestampPacket, bool profilingEnabled) {
|
2019-04-03 21:59:31 +08:00
|
|
|
size_t numberOfBlits = 0;
|
|
|
|
uint64_t width = 1;
|
|
|
|
uint64_t height = 1;
|
|
|
|
|
2020-02-25 16:55:13 +08:00
|
|
|
for (uint64_t slice = 0; slice < copySize.z; slice++) {
|
|
|
|
for (uint64_t row = 0; row < copySize.y; row++) {
|
|
|
|
uint64_t sizeToBlit = copySize.x;
|
|
|
|
while (sizeToBlit != 0) {
|
2020-05-06 20:54:30 +08:00
|
|
|
if (sizeToBlit > getMaxBlitWidth()) {
|
2020-02-25 16:55:13 +08:00
|
|
|
// dispatch 2D blit: maxBlitWidth x (1 .. maxBlitHeight)
|
2020-05-06 20:54:30 +08:00
|
|
|
width = getMaxBlitWidth();
|
|
|
|
height = std::min((sizeToBlit / width), getMaxBlitHeight());
|
2020-02-25 16:55:13 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// dispatch 1D blt: (1 .. maxBlitWidth) x 1
|
|
|
|
width = sizeToBlit;
|
|
|
|
height = 1;
|
|
|
|
}
|
|
|
|
sizeToBlit -= (width * height);
|
|
|
|
numberOfBlits++;
|
|
|
|
}
|
2019-04-03 21:59:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:54:30 +08:00
|
|
|
const size_t cmdsSizePerBlit = (sizeof(typename GfxFamily::XY_COPY_BLT) + estimatePostBlitCommandSize());
|
2020-04-24 18:24:40 +08:00
|
|
|
|
2020-04-29 20:06:01 +08:00
|
|
|
size_t timestampCmdSize = 0;
|
|
|
|
if (updateTimestampPacket) {
|
|
|
|
if (profilingEnabled) {
|
|
|
|
timestampCmdSize = 4 * sizeof(typename GfxFamily::MI_STORE_REGISTER_MEM);
|
|
|
|
} else {
|
|
|
|
timestampCmdSize = EncodeMiFlushDW<GfxFamily>::getMiFlushDwCmdSizeForDataWrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 16:15:53 +08:00
|
|
|
return TimestampPacketHelper::getRequiredCmdStreamSize<GfxFamily>(csrDependencies) +
|
2020-04-29 20:06:01 +08:00
|
|
|
(cmdsSizePerBlit * numberOfBlits) + timestampCmdSize;
|
2019-11-07 16:15:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2020-06-17 20:58:28 +08:00
|
|
|
size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(const BlitPropertiesContainer &blitPropertiesContainer, const HardwareInfo &hwInfo, bool profilingEnabled, bool debugPauseEnabled) {
|
2019-11-07 16:15:53 +08:00
|
|
|
size_t size = 0;
|
|
|
|
for (auto &blitProperties : blitPropertiesContainer) {
|
|
|
|
size += BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(blitProperties.copySize, blitProperties.csrDependencies,
|
2020-04-29 20:06:01 +08:00
|
|
|
blitProperties.outputTimestampPacket != nullptr, profilingEnabled);
|
2019-11-07 16:15:53 +08:00
|
|
|
}
|
2020-02-17 19:45:24 +08:00
|
|
|
size += MemorySynchronizationCommands<GfxFamily>::getSizeForAdditonalSynchronization(hwInfo);
|
2020-03-13 19:29:45 +08:00
|
|
|
size += EncodeMiFlushDW<GfxFamily>::getMiFlushDwCmdSizeForDataWrite() + sizeof(typename GfxFamily::MI_BATCH_BUFFER_END);
|
2019-04-03 21:59:31 +08:00
|
|
|
|
2020-06-17 20:58:28 +08:00
|
|
|
if (debugPauseEnabled) {
|
|
|
|
size += BlitCommandsHelper<GfxFamily>::getSizeForDebugPauseCommands();
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:59:31 +08:00
|
|
|
return alignUp(size, MemoryConstants::cacheLineSize);
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:55:13 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
uint64_t BlitCommandsHelper<GfxFamily>::calculateBlitCommandDestinationBaseAddress(const BlitProperties &blitProperties, uint64_t offset, uint64_t row, uint64_t slice) {
|
|
|
|
return blitProperties.dstGpuAddress + blitProperties.dstOffset.x + offset +
|
|
|
|
blitProperties.dstOffset.y * blitProperties.dstRowPitch +
|
|
|
|
blitProperties.dstOffset.z * blitProperties.dstSlicePitch +
|
|
|
|
row * blitProperties.dstRowPitch +
|
|
|
|
slice * blitProperties.dstSlicePitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
uint64_t BlitCommandsHelper<GfxFamily>::calculateBlitCommandSourceBaseAddress(const BlitProperties &blitProperties, uint64_t offset, uint64_t row, uint64_t slice) {
|
|
|
|
return blitProperties.srcGpuAddress + blitProperties.srcOffset.x + offset +
|
|
|
|
blitProperties.srcOffset.y * blitProperties.srcRowPitch +
|
|
|
|
blitProperties.srcOffset.z * blitProperties.srcSlicePitch +
|
|
|
|
row * blitProperties.srcRowPitch +
|
|
|
|
slice * blitProperties.srcSlicePitch;
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:59:31 +08:00
|
|
|
template <typename GfxFamily>
|
2020-02-10 21:17:12 +08:00
|
|
|
void BlitCommandsHelper<GfxFamily>::dispatchBlitCommandsForBuffer(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) {
|
2019-04-03 21:59:31 +08:00
|
|
|
uint64_t width = 1;
|
|
|
|
uint64_t height = 1;
|
|
|
|
|
2020-02-25 16:55:13 +08:00
|
|
|
for (uint64_t slice = 0; slice < blitProperties.copySize.z; slice++) {
|
|
|
|
for (uint64_t row = 0; row < blitProperties.copySize.y; row++) {
|
|
|
|
uint64_t offset = 0;
|
|
|
|
uint64_t sizeToBlit = blitProperties.copySize.x;
|
|
|
|
while (sizeToBlit != 0) {
|
2020-05-06 20:54:30 +08:00
|
|
|
if (sizeToBlit > getMaxBlitWidth()) {
|
2020-02-25 16:55:13 +08:00
|
|
|
// dispatch 2D blit: maxBlitWidth x (1 .. maxBlitHeight)
|
2020-05-06 20:54:30 +08:00
|
|
|
width = getMaxBlitWidth();
|
|
|
|
height = std::min((sizeToBlit / width), getMaxBlitHeight());
|
2020-02-25 16:55:13 +08:00
|
|
|
} else {
|
|
|
|
// dispatch 1D blt: (1 .. maxBlitWidth) x 1
|
|
|
|
width = sizeToBlit;
|
|
|
|
height = 1;
|
|
|
|
}
|
|
|
|
|
2020-04-24 18:24:40 +08:00
|
|
|
{
|
|
|
|
auto bltCmd = GfxFamily::cmdInitXyCopyBlt;
|
|
|
|
|
|
|
|
bltCmd.setTransferWidth(static_cast<uint32_t>(width));
|
|
|
|
bltCmd.setTransferHeight(static_cast<uint32_t>(height));
|
|
|
|
bltCmd.setDestinationPitch(static_cast<uint32_t>(width));
|
|
|
|
bltCmd.setSourcePitch(static_cast<uint32_t>(width));
|
2020-02-25 16:55:13 +08:00
|
|
|
|
2020-04-24 18:24:40 +08:00
|
|
|
auto dstAddr = calculateBlitCommandDestinationBaseAddress(blitProperties, offset, row, slice);
|
|
|
|
auto srcAddr = calculateBlitCommandSourceBaseAddress(blitProperties, offset, row, slice);
|
2020-02-25 16:55:13 +08:00
|
|
|
|
2020-04-24 18:24:40 +08:00
|
|
|
bltCmd.setDestinationBaseAddress(dstAddr);
|
|
|
|
bltCmd.setSourceBaseAddress(srcAddr);
|
2020-02-25 16:55:13 +08:00
|
|
|
|
2020-04-24 18:24:40 +08:00
|
|
|
appendBlitCommandsForBuffer(blitProperties, bltCmd, rootDeviceEnvironment);
|
2020-02-25 16:55:13 +08:00
|
|
|
|
2020-04-24 18:24:40 +08:00
|
|
|
auto bltStream = linearStream.getSpaceForCmd<typename GfxFamily::XY_COPY_BLT>();
|
|
|
|
*bltStream = bltCmd;
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:54:30 +08:00
|
|
|
dispatchPostBlitCommand(linearStream);
|
2020-02-25 16:55:13 +08:00
|
|
|
|
|
|
|
auto blitSize = width * height;
|
|
|
|
sizeToBlit -= blitSize;
|
|
|
|
offset += blitSize;
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 21:59:31 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-28 16:24:22 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
template <size_t patternSize>
|
|
|
|
void BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryFill(NEO::GraphicsAllocation *dstAlloc, uint32_t *pattern, LinearStream &linearStream, size_t size, const RootDeviceEnvironment &rootDeviceEnvironment, COLOR_DEPTH depth) {
|
|
|
|
using XY_COLOR_BLT = typename GfxFamily::XY_COLOR_BLT;
|
|
|
|
auto blitCmd = GfxFamily::cmdInitXyColorBlt;
|
|
|
|
|
|
|
|
blitCmd.setFillColor(pattern);
|
|
|
|
blitCmd.setColorDepth(depth);
|
|
|
|
|
|
|
|
uint64_t offset = 0;
|
|
|
|
uint64_t sizeToFill = size;
|
|
|
|
while (sizeToFill != 0) {
|
|
|
|
auto tmpCmd = blitCmd;
|
|
|
|
tmpCmd.setDestinationBaseAddress(ptrOffset(dstAlloc->getGpuAddress(), static_cast<size_t>(offset)));
|
|
|
|
uint64_t height = 0;
|
|
|
|
uint64_t width = 0;
|
2020-05-06 20:54:30 +08:00
|
|
|
if (sizeToFill <= getMaxBlitWidth()) {
|
2020-04-28 16:24:22 +08:00
|
|
|
width = sizeToFill;
|
|
|
|
height = 1;
|
|
|
|
} else {
|
2020-05-06 20:54:30 +08:00
|
|
|
width = getMaxBlitWidth();
|
|
|
|
height = std::min((sizeToFill / width), getMaxBlitHeight());
|
2020-04-28 16:24:22 +08:00
|
|
|
if (height > 1) {
|
|
|
|
appendTilingEnable(tmpCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmpCmd.setTransferWidth(static_cast<uint32_t>(width));
|
|
|
|
tmpCmd.setTransferHeight(static_cast<uint32_t>(height));
|
|
|
|
tmpCmd.setDestinationPitch(static_cast<uint32_t>(width));
|
2020-05-21 18:36:23 +08:00
|
|
|
|
|
|
|
appendBlitCommandsForFillBuffer(dstAlloc, tmpCmd, rootDeviceEnvironment);
|
|
|
|
|
2020-04-28 16:24:22 +08:00
|
|
|
auto cmd = linearStream.getSpaceForCmd<XY_COLOR_BLT>();
|
|
|
|
*cmd = tmpCmd;
|
|
|
|
auto blitSize = width * height;
|
|
|
|
offset += (blitSize);
|
|
|
|
sizeToFill -= blitSize;
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 15:12:52 +08:00
|
|
|
|
2020-05-21 18:36:23 +08:00
|
|
|
template <typename GfxFamily>
|
2020-06-03 20:42:08 +08:00
|
|
|
void BlitCommandsHelper<GfxFamily>::dispatchBlitCommandsForImages(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) {
|
2020-05-21 18:36:23 +08:00
|
|
|
auto dstAllocation = blitProperties.dstAllocation;
|
|
|
|
auto srcAllocation = blitProperties.srcAllocation;
|
|
|
|
|
|
|
|
UNRECOVERABLE_IF(blitProperties.copySize.x > BlitterConstants::maxBlitWidth || blitProperties.copySize.y > BlitterConstants::maxBlitWidth);
|
|
|
|
auto bltCmd = GfxFamily::cmdInitXyCopyBlt;
|
|
|
|
|
|
|
|
bltCmd.setSourceBaseAddress(srcAllocation->getGpuAddress());
|
|
|
|
bltCmd.setDestinationBaseAddress(dstAllocation->getGpuAddress());
|
|
|
|
|
|
|
|
bltCmd.setDestinationX1CoordinateLeft(static_cast<uint32_t>(blitProperties.dstOffset.x));
|
|
|
|
bltCmd.setDestinationY1CoordinateTop(static_cast<uint32_t>(blitProperties.dstOffset.y));
|
|
|
|
bltCmd.setTransferWidth(static_cast<uint32_t>(blitProperties.dstOffset.x + blitProperties.copySize.x));
|
|
|
|
bltCmd.setTransferHeight(static_cast<uint32_t>(blitProperties.dstOffset.y + blitProperties.copySize.y));
|
|
|
|
|
|
|
|
bltCmd.setSourceX1CoordinateLeft(static_cast<uint32_t>(blitProperties.srcOffset.x));
|
|
|
|
bltCmd.setSourceY1CoordinateTop(static_cast<uint32_t>(blitProperties.srcOffset.y));
|
|
|
|
|
|
|
|
appendBlitCommandsForBuffer(blitProperties, bltCmd, rootDeviceEnvironment);
|
|
|
|
appendBlitCommandsForImages(blitProperties, bltCmd);
|
|
|
|
appendColorDepth(blitProperties, bltCmd);
|
|
|
|
appendSurfaceType(blitProperties, bltCmd);
|
|
|
|
for (uint32_t i = 0; i < blitProperties.copySize.z; i++) {
|
|
|
|
appendSliceOffsets(blitProperties, bltCmd, i);
|
|
|
|
auto cmd = linearStream.getSpaceForCmd<typename GfxFamily::XY_COPY_BLT>();
|
|
|
|
*cmd = bltCmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 20:58:28 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void BlitCommandsHelper<GfxFamily>::dispatchDebugPauseCommands(LinearStream &commandStream, uint64_t debugPauseStateGPUAddress, DebugPauseState confirmationTrigger, DebugPauseState waitCondition) {
|
|
|
|
using MI_SEMAPHORE_WAIT = typename GfxFamily::MI_SEMAPHORE_WAIT;
|
|
|
|
|
|
|
|
EncodeMiFlushDW<GfxFamily>::programMiFlushDw(commandStream, debugPauseStateGPUAddress, static_cast<uint32_t>(confirmationTrigger), false, true);
|
|
|
|
|
|
|
|
auto miSemaphoreCmd = commandStream.getSpaceForCmd<MI_SEMAPHORE_WAIT>();
|
|
|
|
EncodeSempahore<GfxFamily>::programMiSemaphoreWait(miSemaphoreCmd, debugPauseStateGPUAddress, static_cast<uint32_t>(waitCondition), MI_SEMAPHORE_WAIT::COMPARE_OPERATION::COMPARE_OPERATION_SAD_EQUAL_SDD);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
size_t BlitCommandsHelper<GfxFamily>::getSizeForDebugPauseCommands() {
|
|
|
|
return (EncodeMiFlushDW<GfxFamily>::getMiFlushDwCmdSizeForDataWrite() + EncodeSempahore<GfxFamily>::getSizeMiSemaphoreWait()) * 2;
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:59:31 +08:00
|
|
|
} // namespace NEO
|