Skip to content

Commit efcbd38

Browse files
fix: Fix copying with blitter
Related-To: NEO-12134, NEO-13874 Thanks to this change we avoid programming y1 offset for 2D surface above the maximum allowable value, i.e. 16 kb for blitter for BMG Signed-off-by: Andrzej Koska <[email protected]>
1 parent d7b0495 commit efcbd38

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed

shared/source/helpers/blit_commands_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct BlitCommandsHelper {
7474
static void appendTilingEnable(typename GfxFamily::XY_COLOR_BLT &blitCmd);
7575
static void appendTilingType(const GMM_TILE_TYPE srcTilingType, const GMM_TILE_TYPE dstTilingType, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd);
7676
static void appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd, uint32_t sliceIndex, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t srcSlicePitch, uint32_t dstSlicePitch);
77+
static void appendBaseAddressOffset(const BlitProperties &blitProperties, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd, const bool isSource);
7778
static void getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType,
7879
uint32_t &mipTailLod, uint32_t &compressionDetails,
7980
const RootDeviceEnvironment &rootDeviceEnvironment, GMM_YUV_PLANE_ENUM plane);

shared/source/helpers/blit_commands_helper_base.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ size_t BlitCommandsHelper<GfxFamily>::getProfilingMmioCmdsSize() {
559559
return 4 * sizeof(typename GfxFamily::MI_STORE_REGISTER_MEM);
560560
}
561561

562+
template <typename GfxFamily>
563+
void BlitCommandsHelper<GfxFamily>::appendBaseAddressOffset(const BlitProperties &blitProperties, typename GfxFamily::XY_BLOCK_COPY_BLT &blitCmd, const bool isSource) {}
564+
562565
template <typename GfxFamily>
563566
void BlitCommandsHelper<GfxFamily>::encodeWa(LinearStream &cmdStream, const BlitProperties &blitProperties, uint32_t &latestSentBcsWaValue) {
564567
}

shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,54 @@ void BlitCommandsHelper<Family>::appendBlitCommandsBlockCopy(const BlitPropertie
134134
blitCmd.setSourceMOCS(mocs);
135135
}
136136

137+
template <>
138+
void BlitCommandsHelper<Family>::appendBaseAddressOffset(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, const bool isSource) {
139+
using XY_BLOCK_COPY_BLT = typename Family::XY_BLOCK_COPY_BLT;
140+
auto surfaceType = isSource ? blitCmd.getSourceSurfaceType() : blitCmd.getDestinationSurfaceType();
141+
if (surfaceType == XY_BLOCK_COPY_BLT::SURFACE_TYPE_SURFTYPE_2D) {
142+
// max allowed y1 offset for 2D surface is 0x3fff,
143+
// if it's bigger then we need to reduce it by adding offset to base address instead
144+
GMM_REQ_OFFSET_INFO offsetInfo = {};
145+
offsetInfo.ArrayIndex = isSource ? (blitCmd.getSourceArrayIndex() - 1) : (blitCmd.getDestinationArrayIndex() - 1);
146+
offsetInfo.ReqRender = 1;
147+
148+
if (isSource) {
149+
blitProperties.srcAllocation->getDefaultGmm()->gmmResourceInfo->getOffset(offsetInfo);
150+
blitCmd.setSourceBaseAddress(ptrOffset(blitProperties.srcGpuAddress, offsetInfo.Render.Offset));
151+
blitCmd.setSourceXOffset(offsetInfo.Render.XOffset);
152+
blitCmd.setSourceYOffset(offsetInfo.Render.YOffset);
153+
blitCmd.setSourceSurfaceDepth(1);
154+
blitCmd.setSourceArrayIndex(1);
155+
} else {
156+
blitProperties.dstAllocation->getDefaultGmm()->gmmResourceInfo->getOffset(offsetInfo);
157+
blitCmd.setDestinationBaseAddress(ptrOffset(blitProperties.dstGpuAddress, offsetInfo.Render.Offset));
158+
blitCmd.setDestinationXOffset(offsetInfo.Render.XOffset);
159+
blitCmd.setDestinationYOffset(offsetInfo.Render.YOffset);
160+
blitCmd.setDestinationSurfaceDepth(1);
161+
blitCmd.setDestinationArrayIndex(1);
162+
}
163+
}
164+
}
165+
166+
template <>
167+
void BlitCommandsHelper<Family>::appendSliceOffsets(const BlitProperties &blitProperties, typename Family::XY_BLOCK_COPY_BLT &blitCmd, uint32_t sliceIndex, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t srcSlicePitch, uint32_t dstSlicePitch) {
168+
using XY_BLOCK_COPY_BLT = typename Family::XY_BLOCK_COPY_BLT;
169+
auto srcAddress = blitProperties.srcGpuAddress;
170+
auto dstAddress = blitProperties.dstGpuAddress;
171+
if (blitCmd.getSourceTiling() == XY_BLOCK_COPY_BLT::TILING::TILING_LINEAR) {
172+
blitCmd.setSourceBaseAddress(ptrOffset(srcAddress, srcSlicePitch * (sliceIndex + blitProperties.srcOffset.z)));
173+
} else {
174+
blitCmd.setSourceArrayIndex(sliceIndex + static_cast<uint32_t>(blitProperties.srcOffset.z) + 1);
175+
appendBaseAddressOffset(blitProperties, blitCmd, true);
176+
}
177+
if (blitCmd.getDestinationTiling() == XY_BLOCK_COPY_BLT::TILING::TILING_LINEAR) {
178+
blitCmd.setDestinationBaseAddress(ptrOffset(dstAddress, dstSlicePitch * (sliceIndex + blitProperties.dstOffset.z)));
179+
} else {
180+
blitCmd.setDestinationArrayIndex(sliceIndex + static_cast<uint32_t>(blitProperties.dstOffset.z) + 1);
181+
appendBaseAddressOffset(blitProperties, blitCmd, false);
182+
}
183+
}
184+
137185
template <>
138186
template <typename T>
139187
void BlitCommandsHelper<Family>::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, T &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment) {

shared/test/unit_test/helpers/blit_commands_helper_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ HWTEST_F(BlitTests, givenXyCopyBltCommandWhenAppendBlitCommandsMemCopyIsCalledTh
405405
EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0);
406406
}
407407

408+
HWTEST_F(BlitTests, givenXyBlockCopyBltCommandAndSliceIndex0WhenAppendBaseAddressOffsetIsCalledThenNothingChanged) {
409+
using XY_BLOCK_COPY_BLT = typename FamilyType::XY_BLOCK_COPY_BLT;
410+
auto bltCmd = FamilyType::cmdInitXyBlockCopyBlt;
411+
auto bltCmdBefore = bltCmd;
412+
BlitProperties properties{};
413+
414+
NEO::BlitCommandsHelper<FamilyType>::appendBaseAddressOffset(properties, bltCmd, false);
415+
EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_BLOCK_COPY_BLT)), 0);
416+
417+
NEO::BlitCommandsHelper<FamilyType>::appendBaseAddressOffset(properties, bltCmd, true);
418+
EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_BLOCK_COPY_BLT)), 0);
419+
}
420+
408421
using BlitColor = IsWithinProducts<IGFX_SKYLAKE, IGFX_ICELAKE_LP>;
409422

410423
HWTEST2_F(BlitTests, givenMemoryWhenFillPatternSizeIs4BytesThen32BitMaskISSetCorrectly, BlitColor) {

shared/test/unit_test/helpers/test_blit_commands_helper_xehp_and_later.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,3 +669,33 @@ HWTEST2_F(BlitTests, givenDispatchDummyBlitWhenForceDummyBlitWaDisabledThenAddit
669669
EXPECT_EQ(expectedSize, stream.getUsed());
670670
EXPECT_EQ(nullptr, rootDeviceEnvironment.getDummyAllocation());
671671
}
672+
673+
struct IsAtLeastXeHpCoreAndNotXe2HpgCoreWith2DArrayImageSupport {
674+
template <PRODUCT_FAMILY productFamily>
675+
static constexpr bool isMatched() {
676+
return IsAtLeastGfxCore<IGFX_XE_HP_CORE>::isMatched<productFamily>() && !IsXe2HpgCore::isMatched<productFamily>() && NEO::HwMapper<productFamily>::GfxProduct::supportsSampler;
677+
}
678+
};
679+
680+
HWTEST2_F(BlitTests, givenXeHPOrAboveTiledResourcesWhenAppendSliceOffsetsIsCalledThenIndexesAreSet, IsAtLeastXeHpCoreAndNotXe2HpgCoreWith2DArrayImageSupport) {
681+
using XY_BLOCK_COPY_BLT = typename FamilyType::XY_BLOCK_COPY_BLT;
682+
683+
auto blitCmd = FamilyType::cmdInitXyBlockCopyBlt;
684+
blitCmd.setSourceTiling(XY_BLOCK_COPY_BLT::TILING::TILING_TILE64);
685+
blitCmd.setDestinationTiling(XY_BLOCK_COPY_BLT::TILING::TILING_TILE64);
686+
MockGraphicsAllocation mockAllocationSrc(0, 1u /*num gmms*/, AllocationType::internalHostMemory,
687+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
688+
MemoryPool::system4KBPages, MemoryManager::maxOsContextCount);
689+
MockGraphicsAllocation mockAllocationDst(0, 1u /*num gmms*/, AllocationType::internalHostMemory,
690+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
691+
MemoryPool::system4KBPages, MemoryManager::maxOsContextCount);
692+
BlitProperties properties{};
693+
uint32_t sliceIndex = 1;
694+
auto srcSlicePitch = static_cast<uint32_t>(properties.srcSlicePitch);
695+
auto dstSlicePitch = static_cast<uint32_t>(properties.dstSlicePitch);
696+
697+
BlitCommandsHelper<FamilyType>::appendSliceOffsets(properties, blitCmd, sliceIndex, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch);
698+
699+
EXPECT_EQ(blitCmd.getDestinationArrayIndex(), sliceIndex + 1);
700+
EXPECT_EQ(blitCmd.getSourceArrayIndex(), sliceIndex + 1);
701+
}

shared/test/unit_test/xe2_hpg_core/test_blit_commands_helper_xe2_hpg_core.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,58 @@ HWTEST2_F(BlitTests, givenMemoryAndImageWhenDispatchCopyImageCallThenCommandAdde
396396
auto itor = find<XY_BLOCK_COPY_BLT *>(cmdList.begin(), cmdList.end());
397397
EXPECT_NE(cmdList.end(), itor);
398398
}
399+
400+
HWTEST2_F(BlitTests, givenSurfaceTypeAndSliceIndexWhenAppendBaseAddressOffsetIsCalledThenBaseAddressAndArrayIndexAreCorrectlySet, IsXe2HpgCore) {
401+
using XY_BLOCK_COPY_BLT = typename FamilyType::XY_BLOCK_COPY_BLT;
402+
MockGraphicsAllocation mockAllocationSrc(reinterpret_cast<void *>(0x1234), 0x1000, sizeof(uint32_t));
403+
MockGraphicsAllocation mockAllocationDst(reinterpret_cast<void *>(0x1234), 0x1000, sizeof(uint32_t));
404+
auto gmm = std::make_unique<MockGmm>(pDevice->getGmmHelper());
405+
mockAllocationSrc.setGmm(gmm.get(), 0u);
406+
mockAllocationDst.setGmm(gmm.get(), 0u);
407+
BlitProperties properties{};
408+
properties.srcAllocation = &mockAllocationSrc;
409+
properties.dstAllocation = &mockAllocationDst;
410+
properties.srcGpuAddress = mockAllocationSrc.getGpuAddress();
411+
properties.dstGpuAddress = mockAllocationDst.getGpuAddress();
412+
properties.srcRowPitch = 1;
413+
properties.dstRowPitch = 1;
414+
properties.srcSize.z = 129;
415+
properties.dstSize.z = 129;
416+
std::array<std::tuple<typename XY_BLOCK_COPY_BLT::SURFACE_TYPE, uint32_t, uint32_t, uint32_t>, 4> testParams =
417+
{{{XY_BLOCK_COPY_BLT::SURFACE_TYPE::SURFACE_TYPE_SURFTYPE_2D, 0u, 0u, 0u},
418+
{XY_BLOCK_COPY_BLT::SURFACE_TYPE::SURFACE_TYPE_SURFTYPE_2D, 64u, 64u, 64u},
419+
{XY_BLOCK_COPY_BLT::SURFACE_TYPE::SURFACE_TYPE_SURFTYPE_2D, 64u, 128u, 128u},
420+
{XY_BLOCK_COPY_BLT::SURFACE_TYPE::SURFACE_TYPE_SURFTYPE_2D, 4096u, 1u, 1u}}};
421+
for (const auto &isSource : {false, true}) {
422+
for (const auto &[surfaceType, qPitch, sliceIndex, anchorSliceIndex] : testParams) {
423+
uint32_t y1Top = 0;
424+
uint32_t yOffset = 0;
425+
auto blitCmd = FamilyType::cmdInitXyBlockCopyBlt;
426+
blitCmd.setSourceTiling(XY_BLOCK_COPY_BLT::TILING::TILING_TILE4);
427+
blitCmd.setDestinationTiling(XY_BLOCK_COPY_BLT::TILING::TILING_TILE4);
428+
blitCmd.setSourceSurfaceType(surfaceType);
429+
blitCmd.setDestinationSurfaceType(surfaceType);
430+
blitCmd.setSourceBaseAddress(properties.srcGpuAddress);
431+
blitCmd.setDestinationBaseAddress(properties.dstGpuAddress);
432+
blitCmd.setSourceY1CoordinateTop(y1Top);
433+
blitCmd.setDestinationY1CoordinateTop(y1Top);
434+
blitCmd.setSourceYOffset(yOffset);
435+
blitCmd.setDestinationYOffset(yOffset);
436+
blitCmd.setSourceSurfaceQpitch(qPitch);
437+
blitCmd.setDestinationSurfaceQpitch(qPitch);
438+
blitCmd.setSourceSurfaceDepth(static_cast<uint32_t>(properties.srcSize.z));
439+
blitCmd.setDestinationSurfaceDepth(static_cast<uint32_t>(properties.dstSize.z));
440+
BlitCommandsHelper<FamilyType>::appendBaseAddressOffset(properties, blitCmd, isSource);
441+
auto gpuAddress = isSource ? properties.srcGpuAddress : properties.dstGpuAddress;
442+
if (isSource) {
443+
EXPECT_EQ(blitCmd.getSourceBaseAddress(), gpuAddress);
444+
EXPECT_EQ(blitCmd.getSourceSurfaceDepth(), 1u);
445+
EXPECT_EQ(blitCmd.getSourceArrayIndex(), 1u);
446+
} else {
447+
EXPECT_EQ(blitCmd.getDestinationBaseAddress(), gpuAddress);
448+
EXPECT_EQ(blitCmd.getDestinationSurfaceDepth(), 1u);
449+
EXPECT_EQ(blitCmd.getDestinationArrayIndex(), 1u);
450+
}
451+
}
452+
}
453+
}

0 commit comments

Comments
 (0)