From 3e4e1bde69dde03e24da98935f9d56bc9cd1eec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Oct 2024 17:45:23 +0200 Subject: [PATCH] Vk: make image tight packing check more robust. The check for memory size was enough for llvmpipe, but not for SwiftShader. And now it wasn't enough for NVidia either, so let's just do it properly. Ideally of course this would compare always. Don't feel like doing that right now tho, so it's just a TODO. --- src/Magnum/Vk/Test/ImageVkTest.cpp | 45 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Magnum/Vk/Test/ImageVkTest.cpp b/src/Magnum/Vk/Test/ImageVkTest.cpp index 8cc5bd5fc..f28993350 100644 --- a/src/Magnum/Vk/Test/ImageVkTest.cpp +++ b/src/Magnum/Vk/Test/ImageVkTest.cpp @@ -376,8 +376,21 @@ void ImageVkTest::cmdClearColorImageFloat() { .end(); queue().submit({SubmitInfo{}.setCommandBuffers({cmd})}).wait(); - CORRADE_EXPECT_FAIL_IF(a.dedicatedMemory().size() != 4*4*4 && !device().properties().name().hasPrefix("SwiftShader"), + /* Check if the image is actually tightly packed for the comparison */ + /** @todo make this a builtin, returning a StridedArrayView for pixels */ + VkSubresourceLayout layout; + { + VkImageSubresource subresource{}; + subresource.arrayLayer = 0; + subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + subresource.mipLevel = 0; + device()->GetImageSubresourceLayout(device(), a, &subresource, &layout); + } + CORRADE_EXPECT_FAIL_IF(layout.rowPitch != 4*4, "The image doesn't have a tightly-packed memory, the following check won't work."); + + /* The image memory may be tightly packed but still actually larger than + what was requested. Compare just the prefix. */ CORRADE_COMPARE_AS(Containers::arrayCast(a.dedicatedMemory().mapRead().prefix(4*4*4)), Containers::arrayView({ 0xdeadc0de_rgba, 0xdeadc0de_rgba, 0xdeadc0de_rgba, 0xdeadc0de_rgba, 0xdeadc0de_rgba, 0xdeadc0de_rgba, 0xdeadc0de_rgba, 0xdeadc0de_rgba, @@ -416,8 +429,21 @@ void ImageVkTest::cmdClearColorImageSignedIntegral() { .end(); queue().submit({SubmitInfo{}.setCommandBuffers({cmd})}).wait(); - CORRADE_EXPECT_FAIL_IF(a.dedicatedMemory().size() != 4*4*4 && !device().properties().name().hasPrefix("SwiftShader"), + /* Check if the image is actually tightly packed for the comparison */ + /** @todo make this a builtin, returning a StridedArrayView for pixels */ + VkSubresourceLayout layout; + { + VkImageSubresource subresource{}; + subresource.arrayLayer = 0; + subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + subresource.mipLevel = 0; + device()->GetImageSubresourceLayout(device(), a, &subresource, &layout); + } + CORRADE_EXPECT_FAIL_IF(layout.rowPitch != 4*4, "The image doesn't have a tightly-packed memory, the following check won't work."); + + /* The image memory may be tightly packed but still actually larger than + what was requested. Compare just the prefix. */ CORRADE_COMPARE_AS(Containers::arrayCast(a.dedicatedMemory().mapRead().prefix(4*4*4)), Containers::arrayView({ {15, -7, 2, -1}, {15, -7, 2, -1}, {15, -7, 2, -1}, {15, -7, 2, -1}, {15, -7, 2, -1}, {15, -7, 2, -1}, {15, -7, 2, -1}, {15, -7, 2, -1}, @@ -456,8 +482,21 @@ void ImageVkTest::cmdClearColorImageUnsignedIntegral() { .end(); queue().submit({SubmitInfo{}.setCommandBuffers({cmd})}).wait(); - CORRADE_EXPECT_FAIL_IF(a.dedicatedMemory().size() != 4*4*4 && !device().properties().name().hasPrefix("SwiftShader"), + /* Check if the image is actually tightly packed for the comparison */ + /** @todo make this a builtin, returning a StridedArrayView for pixels */ + VkSubresourceLayout layout; + { + VkImageSubresource subresource{}; + subresource.arrayLayer = 0; + subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + subresource.mipLevel = 0; + device()->GetImageSubresourceLayout(device(), a, &subresource, &layout); + } + CORRADE_EXPECT_FAIL_IF(layout.rowPitch != 4*4, "The image doesn't have a tightly-packed memory, the following check won't work."); + + /* The image memory may be tightly packed but still actually larger than + what was requested. Compare just the prefix. */ CORRADE_COMPARE_AS(Containers::arrayCast(a.dedicatedMemory().mapRead().prefix(4*4*4)), Containers::arrayView({ {15, 37, 2, 1}, {15, 37, 2, 1}, {15, 37, 2, 1}, {15, 37, 2, 1}, {15, 37, 2, 1}, {15, 37, 2, 1}, {15, 37, 2, 1}, {15, 37, 2, 1},