Verify that compression is applied

To query which compression was applied, if any, once a VkImage has been created, use a VkImageCompressionPropertiesEXT structure. Add VkImageCompressionPropertiesEXT to the pNext chain of VkImageSubresource2EXT , and then call vkGetImageSubresourceLayout2EXT :

    

        
        
            VkImageCompressionPropertiesEXT applied_compression_properties{VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_PROPERTIES_EXT};

VkSubresourceLayout2EXT subresource_layout{VK_STRUCTURE_TYPE_SUBRESOURCE_LAYOUT_2_KHR};
subresource_layout.pNext = &applied_compression_properties;

VkImageSubresource2EXT image_subresource{VK_STRUCTURE_TYPE_IMAGE_SUBRESOURCE_2_KHR};
image_subresource.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
image_subresource.imageSubresource.mipLevel   = 0;
image_subresource.imageSubresource.arrayLayer = 0;

vkGetImageSubresourceLayout2EXT(get_device().get_handle(), image_handle, &image_subresource, &subresource_layout);
        
    

Inspect the values written to the imageCompressionFlags and imageCompressionFixedRateFlags components of VkImageCompressionPropertiesEXT:

    

        
        
            LOGI("Created image reports {}", compression_to_string(applied_compression_properties.imageCompressionFlags));
LOGI("Created image reports {}", fixed_rate_flags_to_string(applied_compression_properties.imageCompressionFixedRateFlags));
        
    

The output may then look like this:

    

        
        I/VulkanSamples: [info] Created image reports VK_IMAGE_COMPRESSION_FIXED_RATE_EXPLICIT_EXT
I/VulkanSamples: [info] Created image reports VK_IMAGE_COMPRESSION_FIXED_RATE_5BPC_BIT_EXT

        
    

You have now successfully added fixed-rate compression to your image, saving both memory and bandwidth.

Back
Next