feature: Implement appendMemoryCopy/Fill for Shared System USM

Related-To: NEO-13697

Signed-off-by: John Falkowski <john.falkowski@intel.com>
This commit is contained in:
John Falkowski
2025-06-06 22:53:08 +00:00
committed by Compute-Runtime-Automation
parent 994433d941
commit 805a716fe3
23 changed files with 700 additions and 125 deletions

View File

@@ -432,6 +432,8 @@ DECLARE_DEBUG_VARIABLE(int32_t, ForcePostSyncL1Flush, -1, "-1: default (do nothi
DECLARE_DEBUG_VARIABLE(int32_t, AllowNotZeroForCompressedOnWddm, -1, "-1: default (do nothing), 0: do not set AllowNotZeroed for compressed resources, 1: set AllowNotZeroed for compressed resources");
DECLARE_DEBUG_VARIABLE(int32_t, ForceWddmHugeChunkSizeMB, -1, "-1: default (do nothing), >0: set given huge chunk size in MegaBytes for WDDM");
DECLARE_DEBUG_VARIABLE(int64_t, ForceGmmSystemMemoryBufferForAllocations, 0, "0: default, >0: (bitmask) for given Allocation Types, force GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER gmm resource type");
DECLARE_DEBUG_VARIABLE(int32_t, EmitMemAdvisePriorToCopyForNonUsm, -1, "Enable Memadvise to system memory for copy/fill with shared system input: -1: default, 0: disabled, 1: enabled")
DECLARE_DEBUG_VARIABLE(int32_t, TreatNonUsmForTransfersAsSharedSystem, -1, "-1: default, 0: import non-usm as external host ptr on copy/fill (legacy mode), 1: treat non usm on copy/fill as shared system usm")
/*DIRECT SUBMISSION FLAGS*/
DECLARE_DEBUG_VARIABLE(int32_t, EnableDirectSubmission, -1, "-1: default (disabled), 0: disable, 1:enable. Enables direct submission of command buffers bypassing KMD")

View File

@@ -319,7 +319,7 @@ BlitCommandsResult BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryFill(const B
uint64_t offset = blitProperties.dstOffset.x;
while (sizeToFill != 0) {
auto tmpCmd = blitCmd;
tmpCmd.setDestinationBaseAddress(ptrOffset(blitProperties.dstAllocation->getGpuAddress(), static_cast<size_t>(offset)));
tmpCmd.setDestinationBaseAddress(ptrOffset(blitProperties.dstGpuAddress, static_cast<size_t>(offset)));
uint64_t height = 0;
uint64_t width = 0;
if (sizeToFill <= maxWidth) {
@@ -338,7 +338,9 @@ BlitCommandsResult BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryFill(const B
tmpCmd.setDestinationY2CoordinateBottom(static_cast<uint32_t>(height));
tmpCmd.setDestinationPitch(static_cast<uint32_t>(width * patternSize));
appendBlitMemoryOptionsForFillBuffer(blitProperties.dstAllocation, tmpCmd, rootDeviceEnvironment);
if (blitProperties.dstAllocation) {
appendBlitMemoryOptionsForFillBuffer(blitProperties.dstAllocation, tmpCmd, rootDeviceEnvironment);
}
appendBlitFillCommand(blitProperties, tmpCmd);
if (useAdditionalBlitProperties && (firstCommand || lastCommand)) {

View File

@@ -47,13 +47,15 @@ BlitCommandsResult BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryByteFill(con
blitCmd.setDestinationMOCS(mocs);
uint32_t compressionFormat = 0;
if (blitProperties.dstAllocation->isCompressionEnabled()) {
auto resourceFormat = blitProperties.dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = static_cast<uint32_t>(rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat));
if (blitProperties.dstAllocation) {
if (blitProperties.dstAllocation->isCompressionEnabled()) {
auto resourceFormat = blitProperties.dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = static_cast<uint32_t>(rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat));
}
appendBlitMemSetCompressionFormat(&blitCmd, blitProperties.dstAllocation, compressionFormat);
}
appendBlitMemSetCompressionFormat(&blitCmd, blitProperties.dstAllocation, compressionFormat);
blitCmd.setFillData(*blitProperties.fillPattern);
const bool useAdditionalBlitProperties = rootDeviceEnvironment.getHelper<ProductHelper>().useAdditionalBlitProperties();
@@ -64,7 +66,7 @@ BlitCommandsResult BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryByteFill(con
bool firstCommand = true;
while (sizeToFill != 0) {
auto tmpCmd = blitCmd;
tmpCmd.setDestinationStartAddress(ptrOffset(blitProperties.dstAllocation->getGpuAddress(), static_cast<size_t>(offset)));
tmpCmd.setDestinationStartAddress(ptrOffset(blitProperties.dstGpuAddress, static_cast<size_t>(offset)));
uint64_t height = 0;
uint64_t width = 0;
if (sizeToFill <= maxBlitSetWidth) {

View File

@@ -20,6 +20,7 @@ BlitProperties BlitProperties::constructPropertiesForMemoryFill(GraphicsAllocati
.blitDirection = BlitterConstants::BlitDirection::fill,
.dstAllocation = dstAllocation,
.fillPattern = pattern,
.dstGpuAddress = dstAllocation->getGpuAddress(),
.copySize = {size, 1, 1},
.dstOffset = {offset, 0, 0},
.srcOffset = {0, 0, 0},
@@ -27,6 +28,19 @@ BlitProperties BlitProperties::constructPropertiesForMemoryFill(GraphicsAllocati
.isSystemMemoryPoolUsed = MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())};
}
BlitProperties BlitProperties::constructPropertiesForSystemMemoryFill(uint64_t dstPtr, size_t size, uint32_t *pattern, size_t patternSize, size_t offset) {
return {
.blitDirection = BlitterConstants::BlitDirection::fill,
.dstAllocation = nullptr,
.fillPattern = pattern,
.dstGpuAddress = dstPtr,
.copySize = {size, 1, 1},
.dstOffset = {offset, 0, 0},
.srcOffset = {0, 0, 0},
.fillPatternSize = patternSize,
.isSystemMemoryPoolUsed = true};
}
BlitProperties BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection blitDirection,
CommandStreamReceiver &commandStreamReceiver,
GraphicsAllocation *memObjAllocation,
@@ -129,6 +143,54 @@ BlitProperties BlitProperties::constructPropertiesForCopy(GraphicsAllocation *ds
.isSystemMemoryPoolUsed = MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool(), srcAllocation->getMemoryPool())};
}
BlitProperties BlitProperties::constructPropertiesForSystemCopy(GraphicsAllocation *dstAllocation, GraphicsAllocation *srcAllocation, uint64_t dstPtr, uint64_t srcPtr,
const Vec3<size_t> &dstOffset, const Vec3<size_t> &srcOffset, Vec3<size_t> copySize,
size_t srcRowPitch, size_t srcSlicePitch,
size_t dstRowPitch, size_t dstSlicePitch, GraphicsAllocation *clearColorAllocation) {
copySize.y = copySize.y ? copySize.y : 1;
copySize.z = copySize.z ? copySize.z : 1;
uint64_t dst;
uint64_t src;
if (dstAllocation) {
dst = dstAllocation->getGpuAddress();
} else {
dst = dstPtr;
}
if (srcAllocation) {
src = srcAllocation->getGpuAddress();
} else {
src = srcPtr;
}
bool sysMem;
if ((srcAllocation) && (dstAllocation)) {
sysMem = MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool(), srcAllocation->getMemoryPool());
} else {
sysMem = true;
}
return {
.blitSyncProperties = {},
.csrDependencies = {},
.multiRootDeviceEventSync = nullptr,
.blitDirection = BlitterConstants::BlitDirection::bufferToBuffer,
.auxTranslationDirection = AuxTranslationDirection::none,
.dstAllocation = dstAllocation,
.srcAllocation = srcAllocation,
.clearColorAllocation = clearColorAllocation,
.dstGpuAddress = dst,
.srcGpuAddress = src,
.copySize = copySize,
.dstOffset = dstOffset,
.srcOffset = srcOffset,
.dstRowPitch = dstRowPitch,
.dstSlicePitch = dstSlicePitch,
.srcRowPitch = srcRowPitch,
.srcSlicePitch = srcSlicePitch,
.isSystemMemoryPoolUsed = sysMem};
}
BlitProperties BlitProperties::constructPropertiesForAuxTranslation(AuxTranslationDirection auxTranslationDirection,
GraphicsAllocation *allocation, GraphicsAllocation *clearColorAllocation) {

View File

@@ -47,6 +47,9 @@ struct BlitSyncProperties {
struct BlitProperties {
static BlitProperties constructPropertiesForMemoryFill(GraphicsAllocation *dstAllocation, size_t size, uint32_t *pattern, size_t patternSize, size_t offset);
static BlitProperties constructPropertiesForSystemMemoryFill(uint64_t dstPtr, size_t size, uint32_t *pattern, size_t patternSize, size_t offset);
static BlitProperties constructPropertiesForReadWrite(BlitterConstants::BlitDirection blitDirection,
CommandStreamReceiver &commandStreamReceiver,
GraphicsAllocation *memObjAllocation,
@@ -62,6 +65,11 @@ struct BlitProperties {
size_t srcRowPitch, size_t srcSlicePitch,
size_t dstRowPitch, size_t dstSlicePitch, GraphicsAllocation *clearColorAllocation);
static BlitProperties constructPropertiesForSystemCopy(GraphicsAllocation *dstAllocation, GraphicsAllocation *srcAllocation, uint64_t dstPtr, uint64_t srcPtr,
const Vec3<size_t> &dstOffset, const Vec3<size_t> &srcOffset, Vec3<size_t> copySize,
size_t srcRowPitch, size_t srcSlicePitch,
size_t dstRowPitch, size_t dstSlicePitch, GraphicsAllocation *clearColorAllocation);
static BlitProperties constructPropertiesForAuxTranslation(AuxTranslationDirection auxTranslationDirection,
GraphicsAllocation *allocation, GraphicsAllocation *clearColorAllocation);

View File

@@ -214,16 +214,34 @@ void BlitCommandsHelper<Family>::appendBlitCommandsMemCopy(const BlitProperties
uint8_t compressionFormat = 0;
if (dstAllocation->isCompressionEnabled()) {
auto resourceFormat = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
} else if (srcAllocation->isCompressionEnabled()) {
auto resourceFormat = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
if (dstAllocation) {
if (dstAllocation->isCompressionEnabled()) {
auto resourceFormat = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
}
}
if (compressionFormat == 0) {
if (srcAllocation) {
if (srcAllocation->isCompressionEnabled()) {
auto resourceFormat = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
}
}
}
if (debugManager.flags.EnableStatelessCompressionWithUnifiedMemory.get()) {
if (!MemoryPoolHelper::isSystemMemoryPool(srcAllocation->getMemoryPool()) || !MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())) {
bool enable = false;
if (srcAllocation) {
if (!MemoryPoolHelper::isSystemMemoryPool(srcAllocation->getMemoryPool())) {
enable = true;
}
}
if (dstAllocation) {
if (!MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())) {
enable = true;
}
}
if (enable) {
compressionFormat = static_cast<uint8_t>(debugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get());
}
}

View File

@@ -168,16 +168,34 @@ void BlitCommandsHelper<Family>::appendBlitCommandsMemCopy(const BlitProperties
uint8_t compressionFormat = 0;
if (dstAllocation->isCompressionEnabled()) {
auto resourceFormat = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
} else if (srcAllocation->isCompressionEnabled()) {
auto resourceFormat = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
if (dstAllocation) {
if (dstAllocation->isCompressionEnabled()) {
auto resourceFormat = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
}
}
if (compressionFormat == 0) {
if (srcAllocation) {
if (srcAllocation->isCompressionEnabled()) {
auto resourceFormat = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
}
}
}
if (debugManager.flags.EnableStatelessCompressionWithUnifiedMemory.get()) {
if (!MemoryPoolHelper::isSystemMemoryPool(srcAllocation->getMemoryPool()) || !MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())) {
bool enable = false;
if (srcAllocation) {
if (!MemoryPoolHelper::isSystemMemoryPool(srcAllocation->getMemoryPool())) {
enable = true;
}
}
if (dstAllocation) {
if (!MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())) {
enable = true;
}
}
if (enable) {
compressionFormat = static_cast<uint8_t>(debugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get());
}
}

View File

@@ -102,27 +102,35 @@ void BlitCommandsHelper<Family>::appendBlitCommandsMemCopy(const BlitProperties
blitCmd.setDestinationMOCS(mocs);
blitCmd.setSourceMOCS(mocs);
if (dstAllocation->isCompressionEnabled()) {
auto resourceFormat = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
auto compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
blitCmd.setDestinationCompressible(MEM_COPY::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(compressionFormat);
if (dstAllocation) {
if (dstAllocation->isCompressionEnabled()) {
auto resourceFormat = dstAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
auto compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
blitCmd.setDestinationCompressible(MEM_COPY::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(compressionFormat);
}
}
if (srcAllocation->isCompressionEnabled()) {
auto resourceFormat = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
auto compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
blitCmd.setSourceCompressible(MEM_COPY::SOURCE_COMPRESSIBLE::SOURCE_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(compressionFormat);
if (srcAllocation) {
if (srcAllocation->isCompressionEnabled()) {
auto resourceFormat = srcAllocation->getDefaultGmm()->gmmResourceInfo->getResourceFormat();
auto compressionFormat = rootDeviceEnvironment.getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat);
blitCmd.setSourceCompressible(MEM_COPY::SOURCE_COMPRESSIBLE::SOURCE_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(compressionFormat);
}
}
if (debugManager.flags.EnableStatelessCompressionWithUnifiedMemory.get()) {
if (!MemoryPoolHelper::isSystemMemoryPool(srcAllocation->getMemoryPool())) {
blitCmd.setSourceCompressible(MEM_COPY::SOURCE_COMPRESSIBLE::SOURCE_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(debugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get());
if (srcAllocation) {
if (!MemoryPoolHelper::isSystemMemoryPool(srcAllocation->getMemoryPool())) {
blitCmd.setSourceCompressible(MEM_COPY::SOURCE_COMPRESSIBLE::SOURCE_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(debugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get());
}
}
if (!MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())) {
blitCmd.setDestinationCompressible(MEM_COPY::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(debugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get());
if (dstAllocation) {
if (!MemoryPoolHelper::isSystemMemoryPool(dstAllocation->getMemoryPool())) {
blitCmd.setDestinationCompressible(MEM_COPY::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_COMPRESSIBLE);
blitCmd.setCompressionFormat(debugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get());
}
}
}

View File

@@ -655,6 +655,8 @@ PipelinedEuThreadArbitration = -1
ExperimentalUSMAllocationReuseCleaner = -1
DummyPageBackingEnabled = 0
EnableDeferBacking = 0
EmitMemAdvisePriorToCopyForNonUsm = -1
TreatNonUsmForTransfersAsSharedSystem = -1
SetMaxBVHLevels = -1
GetSipBinaryFromExternalLib = -1
LogUsmReuse = 0

View File

@@ -72,6 +72,126 @@ TEST(BlitCommandsHelperTest, GivenBufferParamsWhenConstructingPropertiesForReadW
blitProperties.dstAllocation->hostPtrTaskCountAssignment--;
}
TEST(BlitCommandsHelperTest, GivenTwoGraphicAllocationsConstructPropertiesForSystemCopyCreatedCorrectly) {
uint32_t src[] = {1, 2, 3, 4};
uint32_t dst[] = {4, 3, 2, 1};
uint32_t clear[] = {5, 6, 7, 8};
uint64_t srcGpuAddr = 0x12345;
uint64_t dstGpuAddr = 0x54321;
uint64_t clearGpuAddr = 0x5678;
std::unique_ptr<MockGraphicsAllocation> srcAlloc(new MockGraphicsAllocation(src, srcGpuAddr, sizeof(src)));
std::unique_ptr<MockGraphicsAllocation> dstAlloc(new MockGraphicsAllocation(dst, dstGpuAddr, sizeof(dst)));
std::unique_ptr<GraphicsAllocation> clearColorAllocation(new MockGraphicsAllocation(clear, clearGpuAddr, sizeof(clear)));
Vec3<size_t> srcOffsets{1, 2, 3};
Vec3<size_t> dstOffsets{3, 2, 1};
Vec3<size_t> copySize{2, 2, 2};
size_t srcRowPitch = 2;
size_t srcSlicePitch = 3;
size_t dstRowPitch = 2;
size_t dstSlicePitch = 3;
auto blitProperties = NEO::BlitProperties::constructPropertiesForSystemCopy(dstAlloc.get(), srcAlloc.get(), dstGpuAddr, srcGpuAddr,
dstOffsets, srcOffsets, copySize, srcRowPitch, srcSlicePitch,
dstRowPitch, dstSlicePitch, clearColorAllocation.get());
EXPECT_EQ(blitProperties.blitDirection, BlitterConstants::BlitDirection::bufferToBuffer);
EXPECT_EQ(blitProperties.dstAllocation, dstAlloc.get());
EXPECT_EQ(blitProperties.srcAllocation, srcAlloc.get());
EXPECT_EQ(blitProperties.clearColorAllocation, clearColorAllocation.get());
EXPECT_EQ(blitProperties.dstGpuAddress, dstGpuAddr);
EXPECT_EQ(blitProperties.srcGpuAddress, srcGpuAddr);
EXPECT_EQ(blitProperties.copySize, copySize);
EXPECT_EQ(blitProperties.dstOffset, dstOffsets);
EXPECT_EQ(blitProperties.srcOffset, srcOffsets);
EXPECT_EQ(blitProperties.dstRowPitch, dstRowPitch);
EXPECT_EQ(blitProperties.dstSlicePitch, dstSlicePitch);
EXPECT_EQ(blitProperties.srcRowPitch, srcRowPitch);
EXPECT_EQ(blitProperties.srcSlicePitch, srcSlicePitch);
EXPECT_FALSE(blitProperties.isSystemMemoryPoolUsed);
}
TEST(BlitCommandsHelperTest, GivenSourceGraphicAllocationConstructPropertiesForSystemCopyCreatedCorrectly) {
uint32_t src[] = {1, 2, 3, 4};
uint32_t clear[] = {5, 6, 7, 8};
uint64_t srcGpuAddr = 0x12345;
uint64_t dstGpuAddr = 0x54321;
uint64_t clearGpuAddr = 0x5678;
std::unique_ptr<MockGraphicsAllocation> srcAlloc(new MockGraphicsAllocation(src, srcGpuAddr, sizeof(src)));
GraphicsAllocation *dstAlloc = nullptr;
std::unique_ptr<GraphicsAllocation> clearColorAllocation(new MockGraphicsAllocation(clear, clearGpuAddr, sizeof(clear)));
Vec3<size_t> srcOffsets{1, 2, 3};
Vec3<size_t> dstOffsets{0, 0, 0};
Vec3<size_t> copySize{2, 0, 0};
size_t srcRowPitch = 0;
size_t srcSlicePitch = 0;
size_t dstRowPitch = 0;
size_t dstSlicePitch = 0;
auto blitProperties = NEO::BlitProperties::constructPropertiesForSystemCopy(dstAlloc, srcAlloc.get(), dstGpuAddr, srcGpuAddr,
dstOffsets, srcOffsets, copySize, srcRowPitch, srcSlicePitch,
dstRowPitch, dstSlicePitch, clearColorAllocation.get());
EXPECT_EQ(blitProperties.blitDirection, BlitterConstants::BlitDirection::bufferToBuffer);
EXPECT_EQ(blitProperties.dstAllocation, nullptr);
EXPECT_EQ(blitProperties.srcAllocation, srcAlloc.get());
EXPECT_EQ(blitProperties.clearColorAllocation, clearColorAllocation.get());
EXPECT_EQ(blitProperties.dstGpuAddress, dstGpuAddr);
EXPECT_EQ(blitProperties.srcGpuAddress, srcGpuAddr);
EXPECT_EQ(blitProperties.dstOffset, dstOffsets);
EXPECT_EQ(blitProperties.srcOffset, srcOffsets);
EXPECT_EQ(blitProperties.dstRowPitch, dstRowPitch);
EXPECT_EQ(blitProperties.dstSlicePitch, dstSlicePitch);
EXPECT_EQ(blitProperties.srcRowPitch, srcRowPitch);
EXPECT_EQ(blitProperties.srcSlicePitch, srcSlicePitch);
EXPECT_TRUE(blitProperties.isSystemMemoryPoolUsed);
}
TEST(BlitCommandsHelperTest, GivenDestinationGraphicAllocationConstructPropertiesForSystemCopyCreatedCorrectly) {
uint32_t dst[] = {1, 2, 3, 4};
uint32_t clear[] = {5, 6, 7, 8};
uint64_t srcGpuAddr = 0x12345;
uint64_t dstGpuAddr = 0x54321;
uint64_t clearGpuAddr = 0x5678;
GraphicsAllocation *srcAlloc = nullptr;
std::unique_ptr<MockGraphicsAllocation> dstAlloc(new MockGraphicsAllocation(dst, dstGpuAddr, sizeof(dst)));
std::unique_ptr<GraphicsAllocation> clearColorAllocation(new MockGraphicsAllocation(clear, clearGpuAddr, sizeof(clear)));
Vec3<size_t> srcOffsets{0, 0, 0};
Vec3<size_t> dstOffsets{3, 2, 1};
Vec3<size_t> copySize{2, 2, 2};
size_t srcRowPitch = 2;
size_t srcSlicePitch = 3;
size_t dstRowPitch = 2;
size_t dstSlicePitch = 3;
auto blitProperties = NEO::BlitProperties::constructPropertiesForSystemCopy(dstAlloc.get(), srcAlloc, dstGpuAddr, srcGpuAddr,
dstOffsets, srcOffsets, copySize, srcRowPitch, srcSlicePitch,
dstRowPitch, dstSlicePitch, clearColorAllocation.get());
EXPECT_EQ(blitProperties.blitDirection, BlitterConstants::BlitDirection::bufferToBuffer);
EXPECT_EQ(blitProperties.dstAllocation, dstAlloc.get());
EXPECT_EQ(blitProperties.srcAllocation, nullptr);
EXPECT_EQ(blitProperties.clearColorAllocation, clearColorAllocation.get());
EXPECT_EQ(blitProperties.dstGpuAddress, dstGpuAddr);
EXPECT_EQ(blitProperties.srcGpuAddress, srcGpuAddr);
EXPECT_EQ(blitProperties.copySize, copySize);
EXPECT_EQ(blitProperties.dstOffset, dstOffsets);
EXPECT_EQ(blitProperties.srcOffset, srcOffsets);
EXPECT_EQ(blitProperties.dstRowPitch, dstRowPitch);
EXPECT_EQ(blitProperties.dstSlicePitch, dstSlicePitch);
EXPECT_EQ(blitProperties.srcRowPitch, srcRowPitch);
EXPECT_EQ(blitProperties.srcSlicePitch, srcSlicePitch);
EXPECT_TRUE(blitProperties.isSystemMemoryPoolUsed);
}
TEST(BlitCommandsHelperTest, GivenBufferParamsWhenConstructingPropertiesForBufferRegionsThenPropertiesCreatedCorrectly) {
uint32_t src[] = {1, 2, 3, 4};
uint32_t dst[] = {4, 3, 2, 1};
@@ -278,6 +398,18 @@ HWTEST_F(BlitTests, givenMemoryWhenFillPatternWithBlitThenCommandIsProgrammed) {
EXPECT_NE(cmdList.end(), itor);
}
HWTEST_F(BlitTests, givenConstructPropertiesForSystemMemoryFillCreatedSuccessfully) {
uint32_t pattern[4] = {1, 0, 0, 0};
uint64_t dstPtr = 0x1234;
size_t size = 0x1000;
auto blitProperties = BlitProperties::constructPropertiesForSystemMemoryFill(dstPtr, size, pattern, sizeof(uint32_t), 0);
EXPECT_EQ(blitProperties.dstAllocation, nullptr);
EXPECT_EQ(blitProperties.dstGpuAddress, dstPtr);
EXPECT_EQ(blitProperties.isSystemMemoryPoolUsed, true);
}
HWTEST_F(BlitTests, givenUnalignedPatternSizeWhenDispatchingBlitFillThenSetCorrectColorDepth) {
using XY_COLOR_BLT = typename FamilyType::XY_COLOR_BLT;
uint32_t pattern[4] = {1, 0, 0, 0};
@@ -419,6 +551,24 @@ HWTEST_F(BlitTests, givenXyCopyBltCommandWhenAppendBlitCommandsMemCopyIsCalledTh
EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0);
}
HWTEST2_F(BlitTests, givenXe2HpgCoreWhenAppendBlitCommandsMemCopyIsCalledThenNothingChanged, IsXe2HpgCore) {
auto bltCmd = FamilyType::cmdInitXyCopyBlt;
BlitProperties properties = {};
properties.dstAllocation = nullptr;
properties.srcAllocation = nullptr;
NEO::BlitCommandsHelper<FamilyType>::appendBlitCommandsMemCopy(properties, bltCmd, pDevice->getRootDeviceEnvironment());
EXPECT_EQ(bltCmd.getCompressionFormat(), 0);
}
HWTEST2_F(BlitTests, givenXe3CoreWhenAppendBlitCommandsMemCopyIsCalledThenNothingChanged, IsXe3Core) {
auto bltCmd = FamilyType::cmdInitXyCopyBlt;
BlitProperties properties = {};
properties.dstAllocation = nullptr;
properties.srcAllocation = nullptr;
NEO::BlitCommandsHelper<FamilyType>::appendBlitCommandsMemCopy(properties, bltCmd, pDevice->getRootDeviceEnvironment());
EXPECT_EQ(bltCmd.getCompressionFormat(), 0);
}
HWTEST_F(BlitTests, givenXyBlockCopyBltCommandAndSliceIndex0WhenAppendBaseAddressOffsetIsCalledThenNothingChanged) {
using XY_BLOCK_COPY_BLT = typename FamilyType::XY_BLOCK_COPY_BLT;
auto bltCmd = FamilyType::cmdInitXyBlockCopyBlt;
@@ -958,6 +1108,45 @@ HWTEST2_F(BlitTests, givenPlatformWithBlitSyncPropertiesWithAndWithoutUseAdditio
EXPECT_EQ(0, memcmp(ptrOffset(stream.getCpuBase(), 0), ptrOffset(stream3.getCpuBase(), 0), std::min(stream.getUsed(), stream3.getUsed())));
}
HWTEST2_F(BlitTests, givenSystemMemoryPlatformWithBlitSyncPropertiesWithAndWithoutUseAdditionalPropertiesWhenCallingDispatchBlitMemoryFillThenTheResultsAreTheSame, MatchAny) {
size_t maxBlitWidth = static_cast<size_t>(BlitCommandsHelper<FamilyType>::getMaxBlitWidth(pDevice->getRootDeviceEnvironmentRef()));
size_t maxBlitHeight = static_cast<size_t>(BlitCommandsHelper<FamilyType>::getMaxBlitHeight(pDevice->getRootDeviceEnvironmentRef(), true));
size_t dstSize = 2 * sizeof(uint32_t) * (maxBlitWidth * maxBlitHeight) + sizeof(uint32_t);
void *dstPtr = malloc(dstSize);
uint32_t pattern[4] = {};
pattern[0] = 0x4567;
auto blitProperties = BlitProperties::constructPropertiesForSystemMemoryFill(reinterpret_cast<uint64_t>(dstPtr), dstSize, pattern, sizeof(uint32_t), 0);
ASSERT_TRUE(blitProperties.isSystemMemoryPoolUsed);
auto nBlitsColorFill = NEO::BlitCommandsHelper<FamilyType>::getNumberOfBlitsForColorFill(blitProperties.copySize, sizeof(uint32_t), pDevice->getRootDeviceEnvironmentRef(), blitProperties.isSystemMemoryPoolUsed);
auto nBlitsFill = NEO::BlitCommandsHelper<FamilyType>::getNumberOfBlitsForFill(blitProperties.copySize, sizeof(uint32_t), pDevice->getRootDeviceEnvironmentRef(), blitProperties.isSystemMemoryPoolUsed);
EXPECT_EQ(3u, nBlitsColorFill);
EXPECT_EQ(nBlitsFill, nBlitsColorFill);
uint32_t streamBuffer[1200] = {};
LinearStream stream(streamBuffer, sizeof(streamBuffer));
NEO::BlitCommandsHelper<FamilyType>::dispatchBlitMemoryFill(blitProperties, stream, pDevice->getRootDeviceEnvironmentRef());
uint32_t streamBuffer2[1200] = {};
LinearStream stream2(streamBuffer2, sizeof(streamBuffer2));
auto blitResult2 = NEO::BlitCommandsHelper<FamilyType>::dispatchBlitMemoryFill(blitProperties, stream2, pDevice->getRootDeviceEnvironmentRef());
EXPECT_NE(nullptr, blitResult2.lastBlitCommand);
// change productHelper to return true
pDevice->getRootDeviceEnvironmentRef().productHelper.reset(new MockProductHelperHw<productFamily>);
auto *mockProductHelper = static_cast<MockProductHelperHw<productFamily> *>(pDevice->getRootDeviceEnvironmentRef().productHelper.get());
mockProductHelper->enableAdditionalBlitProperties = true;
uint32_t streamBuffer3[1300] = {};
LinearStream stream3(streamBuffer3, sizeof(streamBuffer3));
NEO::BlitCommandsHelper<FamilyType>::dispatchBlitMemoryFill(blitProperties, stream3, pDevice->getRootDeviceEnvironmentRef());
EXPECT_EQ(stream.getUsed(), stream3.getUsed());
EXPECT_EQ(0, memcmp(ptrOffset(stream.getCpuBase(), 0), ptrOffset(stream3.getCpuBase(), 0), std::min(stream.getUsed(), stream3.getUsed())));
free(dstPtr);
}
HWTEST_F(BlitTests, givenBlitPropertieswithImageOperationWhenCallingEstimateBlitCommandSizeThenBlockCopySizeIsReturned) {
size_t maxBlitWidth = static_cast<size_t>(BlitCommandsHelper<FamilyType>::getMaxBlitWidth(pDevice->getRootDeviceEnvironmentRef()));
Vec3<size_t> copySize{maxBlitWidth - 1, 1, 1};

View File

@@ -36,6 +36,24 @@ HWTEST2_F(BlitTests, givenOneBytePatternWhenFillPatternWithBlitThenCommandIsProg
EXPECT_NE(cmdList.end(), itor);
}
HWTEST2_F(BlitTests, givenOneBytePatternWhenFillPatternWithSystemMemoryBlitThenCommandIsProgrammed, IsPVC) {
using MEM_SET = typename FamilyType::MEM_SET;
uint32_t pattern = 1;
void *dstPtr = malloc(4);
uint32_t streamBuffer[100] = {};
LinearStream stream(streamBuffer, sizeof(streamBuffer));
auto blitProperties = BlitProperties::constructPropertiesForSystemMemoryFill(reinterpret_cast<uint64_t>(dstPtr), sizeof(uint32_t), &pattern, sizeof(uint8_t), 0);
BlitCommandsHelper<FamilyType>::dispatchBlitMemoryColorFill(blitProperties, stream, pDevice->getRootDeviceEnvironmentRef());
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(
cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed()));
auto itor = find<MEM_SET *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
free(dstPtr);
}
HWTEST2_F(BlitTests, givenDeviceWithoutDefaultGmmWhenAppendBlitCommandsForVillBufferThenDstCompressionDisabled, IsPVC) {
using MEM_SET = typename FamilyType::MEM_SET;
uint32_t pattern = 1;