From 2ae0260c7dde4ead562112cb17e57bf10f1a0078 Mon Sep 17 00:00:00 2001 From: "Spruit, Neil R" Date: Wed, 8 Jul 2020 18:04:18 +0000 Subject: [PATCH] Fix Image Copy with null region to handle invalid height/depth in descriptor Change-Id: Ida41570c1ee12f68f5630bacb357447b6d4dd171 Signed-off-by: Spruit, Neil R --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 16 ++ .../sources/cmdlist/test_cmdlist.cpp | 217 ++++++++++++++++++ 2 files changed, 233 insertions(+) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 1f202fe18f..4283966c11 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -245,6 +245,14 @@ ze_result_t CommandListCoreFamily::appendImageCopyFromMemory(ze_i ze_image_region_t tmpRegion; if (pDstRegion == nullptr) { + // If this is a 1D or 2D image, then the height or depth is ignored and must be set to 1. + // Internally, all dimensions must be >= 1. + if (image->getImageDesc().type == ZE_IMAGE_TYPE_1D || image->getImageDesc().type == ZE_IMAGE_TYPE_1DARRAY) { + imgSize.y = 1; + } + if (image->getImageDesc().type != ZE_IMAGE_TYPE_3D) { + imgSize.z = 1; + } tmpRegion = {0, 0, 0, @@ -351,6 +359,14 @@ ze_result_t CommandListCoreFamily::appendImageCopyToMemory(void * ze_image_region_t tmpRegion; if (pSrcRegion == nullptr) { + // If this is a 1D or 2D image, then the height or depth is ignored and must be set to 1. + // Internally, all dimensions must be >= 1. + if (image->getImageDesc().type == ZE_IMAGE_TYPE_1D || image->getImageDesc().type == ZE_IMAGE_TYPE_1DARRAY) { + imgSize.y = 1; + } + if (image->getImageDesc().type != ZE_IMAGE_TYPE_3D) { + imgSize.z = 1; + } tmpRegion = {0, 0, 0, diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist.cpp index 8fad07f3b5..045d1c5bc0 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist.cpp @@ -757,6 +757,9 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhenIma auto imageHW = std::make_unique>>(); imageHW->initialize(device, &zeDesc); + zeDesc.height = 1; + zeDesc.depth = 1; + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; Vec3 expectedRegionOrigin = {0, 0, 0}; cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, nullptr, nullptr, 0, nullptr); @@ -773,6 +776,9 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhenIma auto imageHW = std::make_unique>>(); imageHW->initialize(device, &zeDesc); + zeDesc.height = 1; + zeDesc.depth = 1; + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; Vec3 expectedRegionOrigin = {0, 0, 0}; cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), nullptr, nullptr, 0, nullptr); @@ -780,6 +786,217 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhenIma EXPECT_EQ(cmdList.appendImageRegionSrcOrigin, expectedRegionOrigin); } +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen1DImageCopyFromMemoryWithInvalidHeightAndDepthThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *srcPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_1D; + zeDesc.height = 9; + zeDesc.depth = 9; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.height = 1; + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionDstOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen1DImageCopyToMemoryWithInvalidHeightAndDepthThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *dstPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_1D; + zeDesc.height = 9; + zeDesc.depth = 9; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.height = 1; + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionSrcOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen1DArrayImageCopyFromMemoryWithInvalidHeightAndDepthThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *srcPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_1DARRAY; + zeDesc.height = 9; + zeDesc.depth = 9; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.height = 1; + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionDstOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen1DArrayImageCopyToMemoryWithInvalidHeightAndDepthThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *dstPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_1DARRAY; + zeDesc.height = 9; + zeDesc.depth = 9; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.height = 1; + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionSrcOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen2DImageCopyToMemoryThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *dstPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_2D; + zeDesc.height = 2; + + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionSrcOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen2DImageCopyFromMemoryThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *srcPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_2D; + zeDesc.height = 2; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionDstOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen2DImageCopyToMemoryWithInvalidDepthThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *dstPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_2D; + zeDesc.height = 2; + zeDesc.depth = 9; + + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionSrcOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen2DImageCopyFromMemoryWithInvalidDepthThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *srcPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_2D; + zeDesc.height = 2; + zeDesc.depth = 9; + + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + zeDesc.depth = 1; + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionDstOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen3DImageCopyToMemoryThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *dstPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_3D; + zeDesc.height = 2; + zeDesc.depth = 2; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionSrcOrigin, expectedRegionOrigin); +} + +HWTEST2_F(CommandListCreate, givenCopyCommandListAndNullDestinationRegionWhen3DImageCopyFromMemoryThenBlitImageCopyCalledWithCorrectImageSize, ImageSupport) { + MockCommandList cmdList; + cmdList.initialize(device, true); + void *srcPtr = reinterpret_cast(0x1234); + + ze_image_desc_t zeDesc = {}; + zeDesc.type = ZE_IMAGE_TYPE_3D; + zeDesc.height = 2; + zeDesc.depth = 2; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + + Vec3 expectedRegionCopySize = {zeDesc.width, zeDesc.height, zeDesc.depth}; + Vec3 expectedRegionOrigin = {0, 0, 0}; + cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, nullptr, nullptr, 0, nullptr); + EXPECT_EQ(cmdList.appendImageRegionCopySize, expectedRegionCopySize); + EXPECT_EQ(cmdList.appendImageRegionDstOrigin, expectedRegionOrigin); +} + HWTEST2_F(CommandListCreate, givenCopyCommandListWhenCopyFromImageToMemoryThenBlitImageCopyCalled, ImageSupport) { MockCommandList cmdList; cmdList.initialize(device, true);