@ -32,8 +32,11 @@
# include <Corrade/Utility/Algorithms.h>
# include <Corrade/Utility/DebugStl.h>
# include "Magnum/ImageView.h"
# include "Magnum/PixelFormat.h"
# include "Magnum/Math/Color.h"
# include "Magnum/Math/Range.h"
# include "Magnum/DebugTools/CompareImage.h"
# include "Magnum/Vk/BufferCreateInfo.h"
# include "Magnum/Vk/CommandPoolCreateInfo.h"
# include "Magnum/Vk/CommandBuffer.h"
@ -376,8 +379,11 @@ void ImageVkTest::cmdClearColorImageFloat() {
. end ( ) ;
queue ( ) . submit ( { SubmitInfo { } . setCommandBuffers ( { cmd } ) } ) . wait ( ) ;
/* Check if the image is actually tightly packed for the comparison */
/** @todo make this a builtin, returning a StridedArrayView for pixels */
/* The image memory may be linear but still with some extra row padding, or
with extra data at the end . Fetch its layout properties and use the
image comparator for robustness . */
/** @todo make this a builtin, returning an ImageView or StridedArrayView
for pixels */
VkSubresourceLayout layout ;
{
VkImageSubresource subresource { } ;
@ -386,17 +392,19 @@ void ImageVkTest::cmdClearColorImageFloat() {
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 < const Color4ub > ( a . dedicatedMemory ( ) . mapRead ( ) . prefix ( 4 * 4 * 4 ) ) , Containers : : arrayView ( {
const Containers : : Array < const char , Vk : : MemoryMapDeleter > actual = a . dedicatedMemory ( ) . mapRead ( ) ;
const Color4ub expected [ ] {
0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba ,
0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba ,
0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba ,
0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba , 0xdeadc0de _rgba
} ) , TestSuite : : Compare : : Container ) ;
} ;
CORRADE_COMPARE_AS (
( ImageView2D {
PixelStorage { } . setRowLength ( layout . rowPitch / 4 ) ,
Magnum : : PixelFormat : : RGBA8Unorm , { 4 , 4 } , actual } ) ,
( ImageView2D { Magnum : : PixelFormat : : RGBA8Unorm , { 4 , 4 } , expected } ) ,
DebugTools : : CompareImage ) ;
}
void ImageVkTest : : cmdClearColorImageSignedIntegral ( ) {
@ -429,8 +437,11 @@ void ImageVkTest::cmdClearColorImageSignedIntegral() {
. end ( ) ;
queue ( ) . submit ( { SubmitInfo { } . setCommandBuffers ( { cmd } ) } ) . wait ( ) ;
/* Check if the image is actually tightly packed for the comparison */
/** @todo make this a builtin, returning a StridedArrayView for pixels */
/* The image memory may be linear but still with some extra row padding, or
with extra data at the end . Fetch its layout properties and use the
image comparator for robustness . */
/** @todo make this a builtin, returning an ImageView or StridedArrayView
for pixels */
VkSubresourceLayout layout ;
{
VkImageSubresource subresource { } ;
@ -439,17 +450,19 @@ void ImageVkTest::cmdClearColorImageSignedIntegral() {
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 < const Vector4b > ( a . dedicatedMemory ( ) . mapRead ( ) . prefix ( 4 * 4 * 4 ) ) , Containers : : arrayView < Vector4b > ( {
const Containers : : Array < const char , Vk : : MemoryMapDeleter > actual = a . dedicatedMemory ( ) . mapRead ( ) ;
const Vector4b expected [ ] {
{ 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 } ,
{ 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 } ,
} ) , TestSuite : : Compare : : Container ) ;
} ;
CORRADE_COMPARE_AS (
( ImageView2D {
PixelStorage { } . setRowLength ( layout . rowPitch / 4 ) ,
Magnum : : PixelFormat : : RGBA8I , { 4 , 4 } , actual } ) ,
( ImageView2D { Magnum : : PixelFormat : : RGBA8I , { 4 , 4 } , expected } ) ,
DebugTools : : CompareImage ) ;
}
void ImageVkTest : : cmdClearColorImageUnsignedIntegral ( ) {
@ -492,17 +505,19 @@ void ImageVkTest::cmdClearColorImageUnsignedIntegral() {
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 < const Vector4ub > ( a . dedicatedMemory ( ) . mapRead ( ) . prefix ( 4 * 4 * 4 ) ) , Containers : : arrayView < Vector4ub > ( {
const Containers : : Array < const char , Vk : : MemoryMapDeleter > actual = a . dedicatedMemory ( ) . mapRead ( ) ;
const Vector4ub expected [ ] {
{ 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 } ,
{ 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 } ,
} ) , TestSuite : : Compare : : Container ) ;
} ;
CORRADE_COMPARE_AS (
( ImageView2D {
PixelStorage { } . setRowLength ( layout . rowPitch / 4 ) ,
Magnum : : PixelFormat : : RGBA8I , { 4 , 4 } , actual } ) ,
( ImageView2D { Magnum : : PixelFormat : : RGBA8I , { 4 , 4 } , expected } ) ,
DebugTools : : CompareImage ) ;
}
void ImageVkTest : : cmdClearDepthStencilImage ( ) {
@ -661,28 +676,40 @@ void ImageVkTest::cmdCopyImage2D() {
device ( ) . properties ( ) . pickQueueFamily ( QueueFlag : : Graphics ) } } ;
CommandBuffer cmd = pool . allocate ( ) ;
/* To avoid going through a buffer which can guarantee the packing we want,
the tests uses a linear tiling image . These are poorly supported , have
weird paddings and the required allocation size is usually much larger
than expected . To prevent issues as much as possible , we ' ll thus create
images with non - insane sizes ( so not 6 or 7 pixels wide , but 8 ) , 4 - byte
pixel format and explicitly slice the mapped memory . */
/* Source image */
ImageCreateInfo2D aInfo { ImageUsage : : TransferSource ,
PixelFormat : : RGBA8UI , { 8 , 10 } , 1 , 1 , ImageLayout : : Preinitialized } ;
aInfo - > tiling = VK_IMAGE_TILING_LINEAR ;
Image a { device ( ) , aInfo , MemoryFlag : : HostVisible } ;
Utility : : copy ( " ________________________________ "
" ________________________________ "
" ________________________________ "
" ________________________________ "
" ____________AaaaAaaaAaaaAaaa____ "
" ____________BbbbBbbbBbbbBbbb____ "
" ____________CcccCcccCcccCccc____ "
" ____________DdddDdddDdddDddd____ "
" ________________________________ "
" ________________________________ " _s , a . dedicatedMemory ( ) . map ( ) . prefix ( 8 * 10 * 4 ) ) ;
/* The image memory may be linear but still with some extra row padding, or
with extra data at the end . Fetch its layout properties and create an
appropriate strided array view for the copy . */
/** @todo make this a builtin, returning an ImageView or StridedArrayView
for pixels */
VkSubresourceLayout aLayout ;
{
VkImageSubresource subresource { } ;
subresource . arrayLayer = 0 ;
subresource . aspectMask = VK_IMAGE_ASPECT_COLOR_BIT ;
subresource . mipLevel = 0 ;
device ( ) - > GetImageSubresourceLayout ( device ( ) , a , & subresource , & aLayout ) ;
}
Utility : : copy ( Containers : : stridedArrayView (
" ________________________________ "
" ________________________________ "
" ________________________________ "
" ________________________________ "
" ____________AaaaAaaaAaaaAaaa____ "
" ____________BbbbBbbbBbbbBbbb____ "
" ____________CcccCcccCcccCccc____ "
" ____________DdddDdddDdddDddd____ "
" ________________________________ "
" ________________________________ " _s ) . expanded < 0 , 2 > ( { 10 , 8 * 4 } ) ,
Containers : : StridedArrayView2D < char > { a . dedicatedMemory ( ) . map ( ) ,
{ 10 , 8 * 4 } ,
{ std : : ptrdiff_t ( aLayout . rowPitch ) , 1 } ,
} ) ;
/* Destination image */
ImageCreateInfo2D bInfo { ImageUsage : : TransferDestination ,
@ -712,14 +739,31 @@ void ImageVkTest::cmdCopyImage2D() {
. end ( ) ;
queue ( ) . submit ( { SubmitInfo { } . setCommandBuffers ( { cmd } ) } ) . wait ( ) ;
CORRADE_EXPECT_FAIL_IF ( b . dedicatedMemory ( ) . size ( ) ! = 8 * 5 * 4 & & ! device ( ) . properties ( ) . name ( ) . hasPrefix ( " SwiftShader " ) ,
" The image doesn't have a tightly-packed memory, the following check won't work. " ) ;
CORRADE_COMPARE ( b . dedicatedMemory ( ) . mapRead ( ) . prefix ( 8 * 5 * 4 ) ,
" -------------------------------- "
" ----AaaaAaaaAaaaAaaa------------ "
" ----BbbbBbbbBbbbBbbb------------ "
" ----CcccCcccCcccCccc------------ "
" ----DdddDdddDdddDddd------------ " _s ) ;
/* The image memory may be linear but still with some extra row padding, or
with extra data at the end . Fetch its layout properties and use the
image comparator for robustness . */
/** @todo make this a builtin, returning an ImageView or StridedArrayView
for pixels */
VkSubresourceLayout bLayout ;
{
VkImageSubresource subresource { } ;
subresource . arrayLayer = 0 ;
subresource . aspectMask = VK_IMAGE_ASPECT_COLOR_BIT ;
subresource . mipLevel = 0 ;
device ( ) - > GetImageSubresourceLayout ( device ( ) , b , & subresource , & bLayout ) ;
}
const Containers : : Array < const char , Vk : : MemoryMapDeleter > data = b . dedicatedMemory ( ) . mapRead ( ) ;
CORRADE_COMPARE_AS (
( ImageView2D {
PixelStorage { } . setRowLength ( bLayout . rowPitch / 4 ) ,
Magnum : : PixelFormat : : RGBA8UI , { 8 , 5 } , data } ) ,
( ImageView2D { Magnum : : PixelFormat : : RGBA8UI , { 8 , 5 } ,
" -------------------------------- "
" ----AaaaAaaaAaaaAaaa------------ "
" ----BbbbBbbbBbbbBbbb------------ "
" ----CcccCcccCcccCccc------------ "
" ----DdddDdddDdddDddd------------ " } ) ,
DebugTools : : CompareImage ) ;
}
void ImageVkTest : : cmdCopyImage2DArrayTo3D ( ) {