Skip to content

Commit

Permalink
tests: Add test for CopyImageToImageEXT
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyBarbour committed Aug 8, 2023
1 parent dddab54 commit 355a52d
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/unit/host_image_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,79 @@ TEST_F(NegativeHostImageCopy, HostCopyImageToFromMemory) {
region_to_image.imageExtent.height = height;
region_from_image.imageExtent.height = height;
}

TEST_F(NegativeHostImageCopy, HostCopyImageToImage) {
TEST_DESCRIPTION("Use VK_EXT_host_image_copy to copy from an image to another image");

VkFormat compressed_format = VK_FORMAT_UNDEFINED;
InitHostImageCopyTest(compressed_format);
if (::testing::Test::IsSkipped()) return;

uint32_t width = 32;
uint32_t height = 32;
VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

auto image_ci = VkImageObj::ImageCreateInfo2D(
width, height, 1, 1, format,
VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
VK_IMAGE_TILING_OPTIMAL);
VkImageFormatProperties img_prop = {};
if (VK_SUCCESS != vk::GetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), image_ci.format, image_ci.imageType,
image_ci.tiling, image_ci.usage, image_ci.flags, &img_prop)) {
GTEST_SKIP() << "Required formats/features not supported";
}

auto host_image_copy_props = LvlInitStruct<VkPhysicalDeviceHostImageCopyPropertiesEXT>();
GetPhysicalDeviceProperties2(host_image_copy_props);
std::vector<VkImageLayout> copy_src_layouts;
std::vector<VkImageLayout> copy_dst_layouts;
copy_src_layouts.resize(host_image_copy_props.copySrcLayoutCount);
copy_dst_layouts.resize(host_image_copy_props.copyDstLayoutCount);
host_image_copy_props.pCopySrcLayouts = copy_src_layouts.data();
host_image_copy_props.pCopyDstLayouts = copy_dst_layouts.data();
GetPhysicalDeviceProperties2(host_image_copy_props);
if (!copy_layout_supported(copy_src_layouts, copy_dst_layouts, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) ||
!copy_layout_supported(copy_src_layouts, copy_dst_layouts, VK_IMAGE_LAYOUT_GENERAL)) {
GTEST_SKIP() << "Required formats/features not supported";
}

auto image_copy_2 = LvlInitStruct<VkImageCopy2>();
image_copy_2.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
image_copy_2.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
image_copy_2.extent = {width, height, 1};
auto copy_image_to_image_info = LvlInitStruct<VkCopyImageToImageInfoEXT>();
copy_image_to_image_info.regionCount = 1;
copy_image_to_image_info.pRegions = &image_copy_2;
copy_image_to_image_info.srcImageLayout = layout;
copy_image_to_image_info.dstImageLayout = layout;

VkFormat no_hic_feature_format =
FindFormatWithoutFeatures2(gpu(), image_ci.tiling, VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT);
if (no_hic_feature_format != VK_FORMAT_UNDEFINED) {
// If VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT, then format features must have VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT
image_ci.format = no_hic_feature_format;
// Can't use VkImageObj because it does error checking
VkImage image_no_feature;
// Any invalid usage will get 02251
m_errorMonitor->SetUnexpectedError("VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImageCreateInfo-imageCreateFormatFeatures-09048");
vk::CreateImage(m_device->device(), &image_ci, NULL, &image_no_feature);
m_errorMonitor->VerifyFound();
image_ci.format = format;
}

VkImageObj image(m_device);
image.Init(image_ci);
image_ci.extent.width = image_ci.extent.width / 2;
VkImageObj skinny_image(m_device);
skinny_image.Init(image_ci);
copy_image_to_image_info.dstImage = image;
copy_image_to_image_info.srcImage = skinny_image;
image_copy_2.extent.width = image_ci.extent.width;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCopyImageToImageInfoEXT-srcImage-09069");
vk::CopyImageToImageEXT(*m_device, &copy_image_to_image_info);
m_errorMonitor->VerifyFound();
image_ci.extent.width = width;
image_copy_2.extent.width = width;
}

0 comments on commit 355a52d

Please sign in to comment.