/* * Copyright (C) 2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "runtime/helpers/blit_commands_helper.h" namespace NEO { template size_t BlitCommandsHelper::estimateBlitCommandsSize(uint64_t copySize, const CsrDependencies &csrDependencies, bool updateTimestampPacket) { size_t numberOfBlits = 0; uint64_t sizeToBlit = copySize; uint64_t width = 1; uint64_t height = 1; while (sizeToBlit != 0) { if (sizeToBlit > BlitterConstants::maxBlitWidth) { // 2D: maxBlitWidth x (1 .. maxBlitHeight) width = BlitterConstants::maxBlitWidth; height = std::min((sizeToBlit / width), BlitterConstants::maxBlitHeight); } else { // 1D: (1 .. maxBlitWidth) x 1 width = sizeToBlit; height = 1; } sizeToBlit -= (width * height); numberOfBlits++; } return TimestampPacketHelper::getRequiredCmdStreamSize(csrDependencies) + (sizeof(typename GfxFamily::XY_COPY_BLT) * numberOfBlits) + (sizeof(typename GfxFamily::MI_FLUSH_DW) * static_cast(updateTimestampPacket)); } template size_t BlitCommandsHelper::estimateBlitCommandsSize(const BlitPropertiesContainer &blitPropertiesContainer) { size_t size = 0; for (auto &blitProperties : blitPropertiesContainer) { size += BlitCommandsHelper::estimateBlitCommandsSize(blitProperties.copySize, blitProperties.csrDependencies, blitProperties.outputTimestampPacket != nullptr); } size += sizeof(typename GfxFamily::MI_FLUSH_DW) + sizeof(typename GfxFamily::MI_BATCH_BUFFER_END); return alignUp(size, MemoryConstants::cacheLineSize); } template void BlitCommandsHelper::dispatchBlitCommandsForBuffer(const BlitProperties &blitProperties, LinearStream &linearStream) { uint64_t sizeToBlit = blitProperties.copySize; uint64_t width = 1; uint64_t height = 1; uint64_t offset = 0; while (sizeToBlit != 0) { if (sizeToBlit > BlitterConstants::maxBlitWidth) { // dispatch 2D blit: maxBlitWidth x (1 .. maxBlitHeight) width = BlitterConstants::maxBlitWidth; height = std::min((sizeToBlit / width), BlitterConstants::maxBlitHeight); } else { // dispatch 1D blt: (1 .. maxBlitWidth) x 1 width = sizeToBlit; height = 1; } auto bltCmd = linearStream.getSpaceForCmd(); *bltCmd = GfxFamily::cmdInitXyCopyBlt; bltCmd->setTransferWidth(static_cast(width)); bltCmd->setTransferHeight(static_cast(height)); bltCmd->setDestinationPitch(static_cast(width)); bltCmd->setSourcePitch(static_cast(width)); bltCmd->setDestinationBaseAddress(blitProperties.dstGpuAddress + blitProperties.dstOffset + offset); bltCmd->setSourceBaseAddress(blitProperties.srcGpuAddress + blitProperties.srcOffset + offset); appendBlitCommandsForBuffer(blitProperties, *bltCmd); auto blitSize = width * height; sizeToBlit -= blitSize; offset += blitSize; } } } // namespace NEO