diff --git a/build-android/android-generate.bat b/build-android/android-generate.bat index fb5e393ae8f37113942640726e2976804a04f968..cb87283c65ccf8fb910e38fb635227a96f872649 100644 --- a/build-android/android-generate.bat +++ b/build-android/android-generate.bat @@ -35,6 +35,7 @@ cd ../.. copy /Y ..\layers\vk_layer_config.cpp generated\common\ copy /Y ..\layers\vk_layer_extension_utils.cpp generated\common\ copy /Y ..\layers\vk_layer_utils.cpp generated\common\ +copy /Y ..\layers\vk_format_utils.cpp generated\common\ copy /Y ..\layers\vk_layer_table.cpp generated\common\ copy /Y ..\layers\descriptor_sets.cpp generated\common\ copy /Y ..\layers\buffer_validation.cpp generated\common\ diff --git a/build-android/android-generate.sh b/build-android/android-generate.sh index dcd6162364292b0a84a3b849c69b947730ed7725..4a2727aa0c5df866acdbd6cc60d98d0dbca07f1c 100755 --- a/build-android/android-generate.sh +++ b/build-android/android-generate.sh @@ -37,6 +37,7 @@ mkdir -p generated/include generated/common cp -f ../layers/vk_layer_config.cpp generated/common/ cp -f ../layers/vk_layer_extension_utils.cpp generated/common/ cp -f ../layers/vk_layer_utils.cpp generated/common/ +cp -f ../layers/vk_format_utils.cpp generated/common/ cp -f ../layers/vk_layer_table.cpp generated/common/ cp -f ../layers/descriptor_sets.cpp generated/common/ cp -f ../layers/buffer_validation.cpp generated/common/ diff --git a/build-android/jni/Android.mk b/build-android/jni/Android.mk index 0c8f10d47e9565162a06cd01f7b2d41767b06871..10c58ce1e72bdfeea7e331e2c03f51576d041fd3 100644 --- a/build-android/jni/Android.mk +++ b/build-android/jni/Android.mk @@ -23,6 +23,7 @@ LOCAL_MODULE := layer_utils LOCAL_SRC_FILES += $(LAYER_DIR)/common/vk_layer_config.cpp LOCAL_SRC_FILES += $(LAYER_DIR)/common/vk_layer_extension_utils.cpp LOCAL_SRC_FILES += $(LAYER_DIR)/common/vk_layer_utils.cpp +LOCAL_SRC_FILES += $(LAYER_DIR)/common/vk_format_utils.cpp LOCAL_C_INCLUDES += $(SRC_DIR)/include \ $(LAYER_DIR)/include \ $(SRC_DIR)/layers \ diff --git a/layers/CMakeLists.txt b/layers/CMakeLists.txt index b755a315bc336c306b83339fa8b602bc7db15b6e..7a35df7ecf752663d861305930b4958e2e53f78c 100644 --- a/layers/CMakeLists.txt +++ b/layers/CMakeLists.txt @@ -147,9 +147,9 @@ run_vk_xml_generate(dispatch_table_helper_generator.py vk_dispatch_table_helper. # For Windows, we use a static lib because the Windows loader has a fairly restrictive loader search # path that can't be easily modified to point it to the same directory that contains the layers. if (WIN32) - add_library(VkLayer_utils STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp) + add_library(VkLayer_utils STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp vk_format_utils.cpp) else() - add_library(VkLayer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp) + add_library(VkLayer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp vk_format_utils.cpp) install(TARGETS VkLayer_utils DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() add_dependencies(VkLayer_utils generate_helper_files) diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 9685dfba2ef3019d8f1d988eed62e05f3ad3f71f..5386ed7d3c5991611efa35ae1c186f57235d14f5 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -240,7 +240,7 @@ void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAG // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both // are used. Verify that the extra implicit layout is OK for descriptor set layout validation if (image_subresource_range.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { - if (vk_format_is_depth_and_stencil(image_state->createInfo.format)) { + if (VkFormatIsDepthAndStencil(image_state->createInfo.format)) { sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); } } @@ -301,7 +301,7 @@ bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NO if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) { // If ImageView was created with depth or stencil, transition both aspects if it's a DS image if (subRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { - if (vk_format_is_depth_and_stencil(view_state->create_info.format)) { + if (VkFormatIsDepthAndStencil(view_state->create_info.format)) { sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); } } @@ -397,13 +397,13 @@ void TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, c bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) { if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) { - if (!vk_format_is_color(format)) return false; + if (!VkFormatIsColor(format)) return false; } if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) { - if (!vk_format_has_depth(format)) return false; + if (!VkFormatHasDepth(format)) return false; } if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) { - if (!vk_format_has_stencil(format)) return false; + if (!VkFormatHasStencil(format)) return false; } return true; } @@ -694,7 +694,7 @@ bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * - (uint64_t)pCreateInfo->samples * (uint64_t)vk_format_get_size(pCreateInfo->format) + + (uint64_t)pCreateInfo->samples * (uint64_t)VkFormatGetSize(pCreateInfo->format) + (uint64_t)imageGranularity) & ~(uint64_t)imageGranularity; @@ -811,12 +811,12 @@ bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); } - if (vk_format_is_depth_or_stencil(image_state->createInfo.format)) { + if (VkFormatIsDepthOrStencil(image_state->createInfo.format)) { char const str[] = "vkCmdClearColorImage called with depth/stencil image."; skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, validation_error_map[VALIDATION_ERROR_01088]); - } else if (vk_format_is_compressed(image_state->createInfo.format)) { + } else if (VkFormatIsCompressed(image_state->createInfo.format)) { char const str[] = "vkCmdClearColorImage called with compressed image."; skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, @@ -995,7 +995,7 @@ bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommand (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); } } - if (image_state && !vk_format_is_depth_or_stencil(image_state->createInfo.format)) { + if (image_state && !VkFormatIsDepthOrStencil(image_state->createInfo.format)) { char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str, @@ -1100,8 +1100,8 @@ static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_N if (pPool) { granularity = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity; - if (vk_format_is_compressed(img->createInfo.format)) { - auto block_size = vk_format_compressed_texel_block_extents(img->createInfo.format); + if (VkFormatIsCompressed(img->createInfo.format)) { + auto block_size = VkFormatCompressedTexelBlockExtent(img->createInfo.format); granularity.width *= block_size.width; granularity.height *= block_size.height; } @@ -1112,8 +1112,8 @@ static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_N // Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) { bool valid = true; - if ((vk_safe_modulo(extent->depth, granularity->depth) != 0) || (vk_safe_modulo(extent->width, granularity->width) != 0) || - (vk_safe_modulo(extent->height, granularity->height) != 0)) { + if ((VkSafeModulo(extent->depth, granularity->depth) != 0) || (VkSafeModulo(extent->width, granularity->width) != 0) || + (VkSafeModulo(extent->height, granularity->height) != 0)) { valid = false; } return valid; @@ -1200,7 +1200,7 @@ static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb const debug_report_data *report_data = core_validation::GetReportData(device_data); bool skip = false; - if (vk_safe_modulo(value, granularity) != 0) { + if (VkSafeModulo(value, granularity) != 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image " @@ -1215,7 +1215,7 @@ static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *c const uint32_t granularity, const uint32_t i, const char *function, const char *member) { const debug_report_data *report_data = core_validation::GetReportData(device_data); bool skip = false; - if (vk_safe_modulo(value, granularity) != 0) { + if (VkSafeModulo(value, granularity) != 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", "%s: pRegion[%d].%s (%" PRIdLEAST64 @@ -1231,7 +1231,7 @@ bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_d const IMAGE_STATE *img, const VkBufferImageCopy *region, const uint32_t i, const char *function) { bool skip = false; - if (vk_format_is_compressed(img->createInfo.format) == true) { + if (VkFormatIsCompressed(img->createInfo.format) == true) { // TODO: Add granularity checking for compressed formats // bufferRowLength must be a multiple of the compressed texel block width @@ -1450,8 +1450,8 @@ bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because // because both texels are 4 bytes in size. Depth/stencil formats must match exactly. - if (vk_format_is_depth_or_stencil(src_image_state->createInfo.format) || - vk_format_is_depth_or_stencil(dst_image_state->createInfo.format)) { + if (VkFormatIsDepthOrStencil(src_image_state->createInfo.format) || + VkFormatIsDepthOrStencil(dst_image_state->createInfo.format)) { if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats."; skip |= @@ -1459,8 +1459,8 @@ bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); } } else { - size_t srcSize = vk_format_get_size(src_image_state->createInfo.format); - size_t destSize = vk_format_get_size(dst_image_state->createInfo.format); + size_t srcSize = VkFormatGetSize(src_image_state->createInfo.format); + size_t destSize = VkFormatGetSize(dst_image_state->createInfo.format); if (srcSize != destSize) { char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, @@ -1826,7 +1826,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod VkFormat dst_format = dst_image_state->createInfo.format; // Validate consistency for unsigned formats - if (vk_format_is_uint(src_format) != vk_format_is_uint(dst_format)) { + if (VkFormatIsUInt(src_format) != VkFormatIsUInt(dst_format)) { std::stringstream ss; ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " << "the other one must also have unsigned integer format. " @@ -1837,7 +1837,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod } // Validate consistency for signed formats - if (vk_format_is_sint(src_format) != vk_format_is_sint(dst_format)) { + if (VkFormatIsSInt(src_format) != VkFormatIsSInt(dst_format)) { std::stringstream ss; ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " << "the other one must also have signed integer format. " @@ -1848,7 +1848,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod } // Validate aspect bits and formats for depth/stencil images - if (vk_format_is_depth_or_stencil(src_format) || vk_format_is_depth_or_stencil(dst_format)) { + if (VkFormatIsDepthOrStencil(src_format) || VkFormatIsDepthOrStencil(dst_format)) { if (src_format != dst_format) { std::stringstream ss; ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " @@ -1863,7 +1863,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod for (uint32_t i = 0; i < regionCount; i++) { VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; - if (vk_format_is_depth_and_stencil(src_format)) { + if (VkFormatIsDepthAndStencil(src_format)) { if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { std::stringstream ss; ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " @@ -1873,7 +1873,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); } - } else if (vk_format_is_stencil_only(src_format)) { + } else if (VkFormatIsStencilOnly(src_format)) { if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { std::stringstream ss; ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " @@ -1882,7 +1882,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); } - } else if (vk_format_is_depth_only(src_format)) { + } else if (VkFormatIsDepthOnly(src_format)) { if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { std::stringstream ss; ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " @@ -1896,7 +1896,7 @@ bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod } // Validate filter - if (vk_format_is_depth_or_stencil(src_format) && (filter != VK_FILTER_NEAREST)) { + if (VkFormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) { std::stringstream ss; ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " << "then filter must be VK_FILTER_NEAREST."; @@ -2364,7 +2364,7 @@ bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat fo const char *func_name) { const debug_report_data *report_data = core_validation::GetReportData(device_data); bool skip = false; - if (vk_format_is_color(format)) { + if (VkFormatIsColor(format)) { if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE", @@ -2376,7 +2376,7 @@ bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat fo "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, validation_error_map[VALIDATION_ERROR_00741]); } - } else if (vk_format_is_depth_and_stencil(format)) { + } else if (VkFormatIsDepthAndStencil(format)) { if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE", @@ -2391,7 +2391,7 @@ bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat fo "VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, validation_error_map[VALIDATION_ERROR_00741]); } - } else if (vk_format_is_depth_only(format)) { + } else if (VkFormatIsDepthOnly(format)) { if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE", @@ -2403,7 +2403,7 @@ bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat fo "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, validation_error_map[VALIDATION_ERROR_00741]); } - } else if (vk_format_is_stencil_only(format)) { + } else if (VkFormatIsStencilOnly(format)) { if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE", @@ -2480,7 +2480,7 @@ bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCr // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { // Format MUST be compatible (in the same format compatibility class) as the format the image was created with - if (vk_format_get_compatibility_class(image_format) != vk_format_get_compatibility_class(view_format)) { + if (VkFormatGetCompatibilityClass(image_format) != VkFormatGetCompatibilityClass(view_format)) { std::stringstream ss; ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) << " is not in the same format compatibility class as image (" << (uint64_t)create_info->image << ") format " @@ -2698,9 +2698,9 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t // If the the calling command's VkImage parameter's format is not a depth/stencil format, // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size - auto texel_size = vk_format_get_size(image_state->createInfo.format); - if (!vk_format_is_depth_and_stencil(image_state->createInfo.format) && - vk_safe_modulo(pRegions[i].bufferOffset, texel_size) != 0) { + auto texel_size = VkFormatGetSize(image_state->createInfo.format); + if (!VkFormatIsDepthAndStencil(image_state->createInfo.format) && + VkSafeModulo(pRegions[i].bufferOffset, texel_size) != 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01263, "IMAGE", "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 @@ -2709,7 +2709,7 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t } // BufferOffset must be a multiple of 4 - if (vk_safe_modulo(pRegions[i].bufferOffset, 4) != 0) { + if (VkSafeModulo(pRegions[i].bufferOffset, 4) != 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01264, "IMAGE", "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i, @@ -2760,11 +2760,11 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that // reserves a place for these compressed image checks. This block of code could move there once the image // stuff is moved into core validation. - if (vk_format_is_compressed(image_state->createInfo.format)) { - auto block_size = vk_format_compressed_texel_block_extents(image_state->createInfo.format); + if (VkFormatIsCompressed(image_state->createInfo.format)) { + auto block_size = VkFormatCompressedTexelBlockExtent(image_state->createInfo.format); // BufferRowLength must be a multiple of block width - if (vk_safe_modulo(pRegions[i].bufferRowLength, block_size.width) != 0) { + if (VkSafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) { skip |= log_msg( report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01271, "IMAGE", @@ -2773,7 +2773,7 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t } // BufferRowHeight must be a multiple of block height - if (vk_safe_modulo(pRegions[i].bufferImageHeight, block_size.height) != 0) { + if (VkSafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01272, "IMAGE", "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel " @@ -2783,9 +2783,9 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t } // image offsets must be multiples of block dimensions - if ((vk_safe_modulo(pRegions[i].imageOffset.x, block_size.width) != 0) || - (vk_safe_modulo(pRegions[i].imageOffset.y, block_size.height) != 0) || - (vk_safe_modulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) { + if ((VkSafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) || + (VkSafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) || + (VkSafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01273, "IMAGE", "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel " @@ -2795,8 +2795,8 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t } // bufferOffset must be a multiple of block size (linear bytes) - size_t block_size_in_bytes = vk_format_get_size(image_state->createInfo.format); - if (vk_safe_modulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) { + size_t block_size_in_bytes = VkFormatGetSize(image_state->createInfo.format); + if (VkSafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01274, "IMAGE", "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64 @@ -2808,7 +2808,7 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); - if ((vk_safe_modulo(pRegions[i].imageExtent.width, block_size.width) != 0) && + if ((VkSafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) && (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01275, "IMAGE", @@ -2819,7 +2819,7 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t } // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height - if ((vk_safe_modulo(pRegions[i].imageExtent.height, block_size.height) != 0) && + if ((VkSafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) && (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01276, "IMAGE", @@ -2830,7 +2830,7 @@ bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t } // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth - if ((vk_safe_modulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) && + if ((VkSafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) && (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01277, "IMAGE", @@ -2865,8 +2865,8 @@ static bool ValidateImageBounds(const debug_report_data *report_data, const IMAG VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); // If we're using a compressed format, valid extent is rounded up to multiple of block size (per 18.1) - if (vk_format_is_compressed(image_info->format)) { - auto block_extent = vk_format_compressed_texel_block_extents(image_info->format); + if (VkFormatIsCompressed(image_info->format)) { + auto block_extent = VkFormatCompressedTexelBlockExtent(image_info->format); if (image_extent.width % block_extent.width) { image_extent.width += (block_extent.width - (image_extent.width % block_extent.width)); } @@ -2900,18 +2900,18 @@ static inline bool ValidtateBufferBounds(const debug_report_data *report_data, I VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength); VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight); - VkDeviceSize unit_size = vk_format_get_size(image_state->createInfo.format); // size (bytes) of texel or block + VkDeviceSize unit_size = VkFormatGetSize(image_state->createInfo.format); // size (bytes) of texel or block // Handle special buffer packing rules for specific depth/stencil formats if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { - unit_size = vk_format_get_size(VK_FORMAT_S8_UINT); + unit_size = VkFormatGetSize(VK_FORMAT_S8_UINT); } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { switch (image_state->createInfo.format) { case VK_FORMAT_D16_UNORM_S8_UINT: - unit_size = vk_format_get_size(VK_FORMAT_D16_UNORM); + unit_size = VkFormatGetSize(VK_FORMAT_D16_UNORM); break; case VK_FORMAT_D32_SFLOAT_S8_UINT: - unit_size = vk_format_get_size(VK_FORMAT_D32_SFLOAT); + unit_size = VkFormatGetSize(VK_FORMAT_D32_SFLOAT); break; case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through case VK_FORMAT_D24_UNORM_S8_UINT: @@ -2922,9 +2922,9 @@ static inline bool ValidtateBufferBounds(const debug_report_data *report_data, I } } - if (vk_format_is_compressed(image_state->createInfo.format)) { + if (VkFormatIsCompressed(image_state->createInfo.format)) { // Switch to texel block units, rounding up for any partially-used blocks - auto block_dim = vk_format_compressed_texel_block_extents(image_state->createInfo.format); + auto block_dim = VkFormatCompressedTexelBlockExtent(image_state->createInfo.format); buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width; buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height; @@ -3147,7 +3147,7 @@ bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage i // VU 00741: subresource's aspect must be compatible with image's format. const VkFormat img_format = image_entry->createInfo.format; - if (vk_format_is_color(img_format)) { + if (VkFormatIsColor(img_format)) { if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) { skip |= log_msg( report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, @@ -3155,7 +3155,7 @@ bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage i "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s", validation_error_map[VALIDATION_ERROR_00741]); } - } else if (vk_format_is_depth_or_stencil(img_format)) { + } else if (VkFormatIsDepthOrStencil(img_format)) { if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE", diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index a2d5b3a5118a79967f296f83e638a0be99e4199e..954f7edd05e85f34ab968e501397ef90595b2cce 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -4845,7 +4845,7 @@ static void initializeAndTrackMemory(layer_data *dev_data, VkDeviceMemory mem, V size = mem_info->alloc_info.allocationSize - offset; } mem_info->shadow_pad_size = dev_data->phys_dev_properties.properties.limits.minMemoryMapAlignment; - assert(vk_safe_modulo(mem_info->shadow_pad_size, + assert(VkSafeModulo(mem_info->shadow_pad_size, dev_data->phys_dev_properties.properties.limits.minMemoryMapAlignment) == 0); // Ensure start of mapped region reflects hardware alignment constraints uint64_t map_alignment = dev_data->phys_dev_properties.properties.limits.minMemoryMapAlignment; @@ -4860,7 +4860,7 @@ static void initializeAndTrackMemory(layer_data *dev_data, VkDeviceMemory mem, V reinterpret_cast<char *>((reinterpret_cast<uintptr_t>(mem_info->shadow_copy_base) + map_alignment) & ~(map_alignment - 1)) + start_offset; - assert(vk_safe_modulo(reinterpret_cast<uintptr_t>(mem_info->shadow_copy) + mem_info->shadow_pad_size - start_offset, + assert(VkSafeModulo(reinterpret_cast<uintptr_t>(mem_info->shadow_copy) + mem_info->shadow_pad_size - start_offset, map_alignment) == 0); memset(mem_info->shadow_copy, NoncoherentMemoryFillValue, static_cast<size_t>(2 * mem_info->shadow_pad_size + size)); @@ -5558,7 +5558,7 @@ static bool PreCallValidateBindBufferMemory(layer_data *dev_data, VkBuffer buffe } // Validate memory requirements alignment - if (vk_safe_modulo(memoryOffset, buffer_state->requirements.alignment) != 0) { + if (VkSafeModulo(memoryOffset, buffer_state->requirements.alignment) != 0) { skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, buffer_handle, __LINE__, VALIDATION_ERROR_02174, "DS", "vkBindBufferMemory(): memoryOffset is 0x%" PRIxLEAST64 @@ -5603,7 +5603,7 @@ static bool PreCallValidateBindBufferMemory(layer_data *dev_data, VkBuffer buffe for (int i = 0; i < 3; i++) { if (usage & usage_list[i]) { - if (vk_safe_modulo(memoryOffset, offset_requirement[i]) != 0) { + if (VkSafeModulo(memoryOffset, offset_requirement[i]) != 0) { skip |= log_msg( dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, buffer_handle, __LINE__, msgCode[i], "DS", "vkBindBufferMemory(): %s memoryOffset is 0x%" PRIxLEAST64 @@ -7376,7 +7376,7 @@ VKAPI_ATTR void VKAPI_CALL CmdBindDescriptorSets(VkCommandBuffer commandBuffer, uint32_t cur_dyn_offset = total_dynamic_descriptors; for (uint32_t d = 0; d < descriptor_set->GetTotalDescriptorCount(); d++) { if (descriptor_set->GetTypeFromGlobalIndex(d) == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { - if (vk_safe_modulo( + if (VkSafeModulo( pDynamicOffsets[cur_dyn_offset], dev_data->phys_dev_properties.properties.limits.minUniformBufferOffsetAlignment) != 0) { skip |= log_msg( @@ -7390,7 +7390,7 @@ VKAPI_ATTR void VKAPI_CALL CmdBindDescriptorSets(VkCommandBuffer commandBuffer, } cur_dyn_offset++; } else if (descriptor_set->GetTypeFromGlobalIndex(d) == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { - if (vk_safe_modulo( + if (VkSafeModulo( pDynamicOffsets[cur_dyn_offset], dev_data->phys_dev_properties.properties.limits.minStorageBufferOffsetAlignment) != 0) { skip |= log_msg( @@ -9486,8 +9486,8 @@ static bool FormatSpecificLoadAndStoreOpSettings(VkFormat format, T color_depth_ if (color_depth_op != op && stencil_op != op) { return false; } - bool check_color_depth_load_op = !vk_format_is_stencil_only(format); - bool check_stencil_load_op = vk_format_is_depth_and_stencil(format) || !check_color_depth_load_op; + bool check_color_depth_load_op = !VkFormatIsStencilOnly(format); + bool check_stencil_load_op = VkFormatIsDepthAndStencil(format) || !check_color_depth_load_op; return (((check_color_depth_load_op == true) && (color_depth_op == op)) || ((check_stencil_load_op == true) && (stencil_op == op))); @@ -10153,14 +10153,14 @@ static bool ValidateMappedMemoryRangeDeviceLimits(layer_data *dev_data, const ch bool skip = false; for (uint32_t i = 0; i < mem_range_count; ++i) { uint64_t atom_size = dev_data->phys_dev_properties.properties.limits.nonCoherentAtomSize; - if (vk_safe_modulo(mem_ranges[i].offset, atom_size) != 0) { + if (VkSafeModulo(mem_ranges[i].offset, atom_size) != 0) { skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, reinterpret_cast<const uint64_t &>(mem_ranges->memory), __LINE__, VALIDATION_ERROR_00644, "MEM", "%s: Offset in pMemRanges[%d] is 0x%" PRIxLEAST64 ", which is not a multiple of VkPhysicalDeviceLimits::nonCoherentAtomSize (0x%" PRIxLEAST64 "). %s", func_name, i, mem_ranges[i].offset, atom_size, validation_error_map[VALIDATION_ERROR_00644]); } - if ((mem_ranges[i].size != VK_WHOLE_SIZE) && (vk_safe_modulo(mem_ranges[i].size, atom_size) != 0)) { + if ((mem_ranges[i].size != VK_WHOLE_SIZE) && (VkSafeModulo(mem_ranges[i].size, atom_size) != 0)) { skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, reinterpret_cast<const uint64_t &>(mem_ranges->memory), __LINE__, VALIDATION_ERROR_00645, "MEM", "%s: Size in pMemRanges[%d] is 0x%" PRIxLEAST64 @@ -10253,7 +10253,7 @@ static bool PreCallValidateBindImageMemory(layer_data *dev_data, VkImage image, } // Validate memory requirements alignment - if (vk_safe_modulo(memoryOffset, image_state->requirements.alignment) != 0) { + if (VkSafeModulo(memoryOffset, image_state->requirements.alignment) != 0) { skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, __LINE__, VALIDATION_ERROR_02178, "DS", "vkBindImageMemory(): memoryOffset is 0x%" PRIxLEAST64 diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp index 086e75f458cfb7322bb6ecde264b77c76f60443b..fbaa2dc02293f578181247912207dbf8e3a9f9ec 100644 --- a/layers/descriptor_sets.cpp +++ b/layers/descriptor_sets.cpp @@ -785,7 +785,7 @@ bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout } // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under // vkCreateImageView(). What's the best way to create unique id for these cases? - bool ds = vk_format_is_depth_or_stencil(format); + bool ds = VkFormatIsDepthOrStencil(format); switch (image_layout) { case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: // Only Color bit must be set diff --git a/layers/parameter_validation.cpp b/layers/parameter_validation.cpp index 8794144a418705b687b928dfa78db9b85dcbb6b7..a11c3d45004253653bbc93bc3b5ad5b29e2e52b5 100644 --- a/layers/parameter_validation.cpp +++ b/layers/parameter_validation.cpp @@ -2543,7 +2543,7 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateI if (pCreateInfo != nullptr) { if ((device_data->physical_device_features.textureCompressionETC2 == false) && - vk_format_is_compressed_ETC2_EAC(pCreateInfo->format)) { + VkFormatIsCompressed_ETC2_EAC(pCreateInfo->format)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DEVICE_FEATURE, LayerName, "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is " @@ -2552,7 +2552,7 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateI } if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) && - vk_format_is_compressed_ASTC_LDR(pCreateInfo->format)) { + VkFormatIsCompressed_ASTC_LDR(pCreateInfo->format)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DEVICE_FEATURE, LayerName, @@ -2562,7 +2562,7 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateI } if ((device_data->physical_device_features.textureCompressionBC == false) && - vk_format_is_compressed_BC(pCreateInfo->format)) { + VkFormatIsCompressed_BC(pCreateInfo->format)) { skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DEVICE_FEATURE, LayerName, "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is " @@ -3875,7 +3875,7 @@ VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descri VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment; for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) { if (pDescriptorWrites[i].pBufferInfo != NULL) { - if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) { + if (VkSafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) { skip |= log_msg( device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_00944, LayerName, @@ -3891,7 +3891,7 @@ VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t descri VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment; for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) { if (pDescriptorWrites[i].pBufferInfo != NULL) { - if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) { + if (VkSafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) { skip |= log_msg( device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_00945, LayerName, diff --git a/layers/vk_format_utils.cpp b/layers/vk_format_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5b133174e5a640f9b52b64f9f565d37298b6909 --- /dev/null +++ b/layers/vk_format_utils.cpp @@ -0,0 +1,924 @@ +/* Copyright (c) 2015-2016 The Khronos Group Inc. + * Copyright (c) 2015-2016 Valve Corporation + * Copyright (c) 2015-2016 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Author: Mark Lobodzinski <mark@lunarg.com> + * Author: Dave Houlton <daveh@lunarg.com> + * + */ + +#include <string.h> +#include <string> +#include <vector> +#include <map> +#include "vulkan/vulkan.h" +#include "vk_format_utils.h" + +struct VULKAN_FORMAT_INFO { + size_t size; + uint32_t channel_count; + VkFormatCompatibilityClass format_class; +}; + +// Disable auto-formatting for this large table +// clang-format off + +// Set up data structure with number of bytes and number of channels for each Vulkan format +const std::map<VkFormat, VULKAN_FORMAT_INFO> vk_format_table = { + {VK_FORMAT_UNDEFINED, {0, 0, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT }}, + {VK_FORMAT_R4G4_UNORM_PACK8, {1, 2, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R4G4B4A4_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_B4G4R4A4_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R5G6B5_UNORM_PACK16, {2, 3, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_B5G6R5_UNORM_PACK16, {2, 3, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R5G5B5A1_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_B5G5R5A1_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_A1R5G5B5_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8_UNORM, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8_SNORM, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8_USCALED, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8_SSCALED, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8_UINT, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8_SINT, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8_SRGB, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, + {VK_FORMAT_R8G8_UNORM, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8_SNORM, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8_USCALED, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8_SSCALED, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8_UINT, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8_SINT, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8_SRGB, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R8G8B8_UNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8_SNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8_USCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8_SSCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8_UINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8_SINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8_SRGB, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_UNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_SNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_USCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_SSCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_UINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_SINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_B8G8R8_SRGB, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, + {VK_FORMAT_R8G8B8A8_UNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R8G8B8A8_SNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R8G8B8A8_USCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R8G8B8A8_SSCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R8G8B8A8_UINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R8G8B8A8_SINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R8G8B8A8_SRGB, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_UNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_SNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_USCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_SSCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_UINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_SINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_B8G8R8A8_SRGB, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_UNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_SNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_USCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_SSCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_UINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_SINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A8B8G8R8_SRGB_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2R10G10B10_UNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2R10G10B10_SNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2R10G10B10_USCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2R10G10B10_SSCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2R10G10B10_UINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2R10G10B10_SINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2B10G10R10_UNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2B10G10R10_SNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2B10G10R10_USCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2B10G10R10_SSCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2B10G10R10_UINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_A2B10G10R10_SINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16_UNORM, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16_SNORM, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16_USCALED, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16_SSCALED, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16_UINT, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16_SINT, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16_SFLOAT, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, + {VK_FORMAT_R16G16_UNORM, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16_SNORM, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16_USCALED, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16_SSCALED, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16_UINT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16_SINT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16_SFLOAT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R16G16B16_UNORM, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16_SNORM, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16_USCALED, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16_SSCALED, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16_UINT, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16_SINT, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16_SFLOAT, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, + {VK_FORMAT_R16G16B16A16_UNORM, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R16G16B16A16_SNORM, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R16G16B16A16_USCALED, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R16G16B16A16_SSCALED, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R16G16B16A16_UINT, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R16G16B16A16_SINT, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R16G16B16A16_SFLOAT, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R32_UINT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R32_SINT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R32_SFLOAT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_R32G32_UINT, {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R32G32_SINT, {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R32G32_SFLOAT, {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R32G32B32_UINT, {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}}, + {VK_FORMAT_R32G32B32_SINT, {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}}, + {VK_FORMAT_R32G32B32_SFLOAT, {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}}, + {VK_FORMAT_R32G32B32A32_UINT, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, + {VK_FORMAT_R32G32B32A32_SINT, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, + {VK_FORMAT_R32G32B32A32_SFLOAT, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, + {VK_FORMAT_R64_UINT, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R64_SINT, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R64_SFLOAT, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, + {VK_FORMAT_R64G64_UINT, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, + {VK_FORMAT_R64G64_SINT, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, + {VK_FORMAT_R64G64_SFLOAT, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, + {VK_FORMAT_R64G64B64_UINT, {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}}, + {VK_FORMAT_R64G64B64_SINT, {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}}, + {VK_FORMAT_R64G64B64_SFLOAT, {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}}, + {VK_FORMAT_R64G64B64A64_UINT, {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}}, + {VK_FORMAT_R64G64B64A64_SINT, {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}}, + {VK_FORMAT_R64G64B64A64_SFLOAT, {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}}, + {VK_FORMAT_B10G11R11_UFLOAT_PACK32, {4, 3, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, {4, 3, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, + {VK_FORMAT_D16_UNORM, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_X8_D24_UNORM_PACK32, {3, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_D32_SFLOAT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_S8_UINT, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_D16_UNORM_S8_UINT, {3, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_D24_UNORM_S8_UINT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_D32_SFLOAT_S8_UINT, {5, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, + {VK_FORMAT_BC1_RGB_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}}, + {VK_FORMAT_BC1_RGB_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}}, + {VK_FORMAT_BC1_RGBA_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}}, + {VK_FORMAT_BC1_RGBA_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}}, + {VK_FORMAT_BC2_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT}}, + {VK_FORMAT_BC2_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT}}, + {VK_FORMAT_BC3_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT}}, + {VK_FORMAT_BC3_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT}}, + {VK_FORMAT_BC4_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT}}, + {VK_FORMAT_BC4_SNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT}}, + {VK_FORMAT_BC5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT}}, + {VK_FORMAT_BC5_SNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT}}, + {VK_FORMAT_BC6H_UFLOAT_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT}}, + {VK_FORMAT_BC6H_SFLOAT_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT}}, + {VK_FORMAT_BC7_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT}}, + {VK_FORMAT_BC7_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT}}, + {VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, {8, 3, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT}}, + {VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, {8, 3, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT}}, + {VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT}}, + {VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT}}, + {VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT}}, + {VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT}}, + {VK_FORMAT_EAC_R11_UNORM_BLOCK, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT}}, + {VK_FORMAT_EAC_R11_SNORM_BLOCK, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT}}, + {VK_FORMAT_EAC_R11G11_UNORM_BLOCK, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT}}, + {VK_FORMAT_EAC_R11G11_SNORM_BLOCK, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT}}, + {VK_FORMAT_ASTC_4x4_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT}}, + {VK_FORMAT_ASTC_4x4_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT}}, + {VK_FORMAT_ASTC_5x4_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT}}, + {VK_FORMAT_ASTC_5x4_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT}}, + {VK_FORMAT_ASTC_5x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT}}, + {VK_FORMAT_ASTC_5x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT}}, + {VK_FORMAT_ASTC_6x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT}}, + {VK_FORMAT_ASTC_6x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT}}, + {VK_FORMAT_ASTC_6x6_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT}}, + {VK_FORMAT_ASTC_6x6_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT}}, + {VK_FORMAT_ASTC_8x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT}}, + {VK_FORMAT_ASTC_8x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT}}, + {VK_FORMAT_ASTC_8x6_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT}}, + {VK_FORMAT_ASTC_8x6_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT}}, + {VK_FORMAT_ASTC_8x8_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT}}, + {VK_FORMAT_ASTC_8x8_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT}}, + {VK_FORMAT_ASTC_10x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT}}, + {VK_FORMAT_ASTC_10x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT}}, + {VK_FORMAT_ASTC_10x6_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}}, + {VK_FORMAT_ASTC_10x6_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}}, + {VK_FORMAT_ASTC_10x8_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, + {VK_FORMAT_ASTC_10x8_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, + {VK_FORMAT_ASTC_10x10_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, + {VK_FORMAT_ASTC_10x10_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, + {VK_FORMAT_ASTC_12x10_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, + {VK_FORMAT_ASTC_12x10_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, + {VK_FORMAT_ASTC_12x12_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT}}, + {VK_FORMAT_ASTC_12x12_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT}}, + {VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT }}, + {VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}}, + {VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, + {VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, + {VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, + {VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, + {VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, + {VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, +}; + +// Renable formatting +// clang-format on + +// Return true if format is an ETC2 or EAC compressed texture format +VK_LAYER_EXPORT bool VkFormatIsCompressed_ETC2_EAC(VkFormat format) { + bool found = false; + + switch (format) { + case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + case VK_FORMAT_EAC_R11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11_SNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: + found = true; + break; + default: + break; + } + return found; +} + +// Return true if format is an ETC2 or EAC compressed texture format +VK_LAYER_EXPORT bool VkFormatIsCompressed_ASTC_LDR(VkFormat format) { + bool found = false; + + switch (format) { + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + found = true; + break; + default: + break; + } + return found; +} + +// Return true if format is a BC compressed texture format +VK_LAYER_EXPORT bool VkFormatIsCompressed_BC(VkFormat format) { + bool found = false; + + switch (format) { + case VK_FORMAT_BC1_RGB_UNORM_BLOCK: + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: + case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: + case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: + case VK_FORMAT_BC2_UNORM_BLOCK: + case VK_FORMAT_BC2_SRGB_BLOCK: + case VK_FORMAT_BC3_UNORM_BLOCK: + case VK_FORMAT_BC3_SRGB_BLOCK: + case VK_FORMAT_BC4_UNORM_BLOCK: + case VK_FORMAT_BC4_SNORM_BLOCK: + case VK_FORMAT_BC5_UNORM_BLOCK: + case VK_FORMAT_BC5_SNORM_BLOCK: + case VK_FORMAT_BC6H_UFLOAT_BLOCK: + case VK_FORMAT_BC6H_SFLOAT_BLOCK: + case VK_FORMAT_BC7_UNORM_BLOCK: + case VK_FORMAT_BC7_SRGB_BLOCK: + found = true; + break; + default: + break; + } + return found; +} + +// Return true if format is a depth or stencil format +VK_LAYER_EXPORT bool VkFormatIsDepthOrStencil(VkFormat format) { + return (VkFormatIsDepthAndStencil(format) || VkFormatIsDepthOnly(format) || VkFormatIsStencilOnly(format)); +} + +// Return true if format contains depth and stencil information +VK_LAYER_EXPORT bool VkFormatIsDepthAndStencil(VkFormat format) { + bool is_ds = false; + + switch (format) { + case VK_FORMAT_D16_UNORM_S8_UINT: + case VK_FORMAT_D24_UNORM_S8_UINT: + case VK_FORMAT_D32_SFLOAT_S8_UINT: + is_ds = true; + break; + default: + break; + } + return is_ds; +} + +// Return true if format is a stencil-only format +VK_LAYER_EXPORT bool VkFormatIsStencilOnly(VkFormat format) { return (format == VK_FORMAT_S8_UINT); } + +// Return true if format is a depth-only format +VK_LAYER_EXPORT bool VkFormatIsDepthOnly(VkFormat format) { + bool is_depth = false; + + switch (format) { + case VK_FORMAT_D16_UNORM: + case VK_FORMAT_X8_D24_UNORM_PACK32: + case VK_FORMAT_D32_SFLOAT: + is_depth = true; + break; + default: + break; + } + + return is_depth; +} + +// Return true if format is of type NORM +VK_LAYER_EXPORT bool VkFormatIsNorm(VkFormat format) { + bool is_norm = false; + + switch (format) { + case VK_FORMAT_R4G4_UNORM_PACK8: + case VK_FORMAT_R4G4B4A4_UNORM_PACK16: + case VK_FORMAT_R5G6B5_UNORM_PACK16: + case VK_FORMAT_R5G5B5A1_UNORM_PACK16: + case VK_FORMAT_A1R5G5B5_UNORM_PACK16: + case VK_FORMAT_R8_UNORM: + case VK_FORMAT_R8_SNORM: + case VK_FORMAT_R8G8_UNORM: + case VK_FORMAT_R8G8_SNORM: + case VK_FORMAT_R8G8B8_UNORM: + case VK_FORMAT_R8G8B8_SNORM: + case VK_FORMAT_R8G8B8A8_UNORM: + case VK_FORMAT_R8G8B8A8_SNORM: + case VK_FORMAT_A8B8G8R8_UNORM_PACK32: + case VK_FORMAT_A8B8G8R8_SNORM_PACK32: + case VK_FORMAT_A2B10G10R10_UNORM_PACK32: + case VK_FORMAT_A2B10G10R10_SNORM_PACK32: + case VK_FORMAT_R16_UNORM: + case VK_FORMAT_R16_SNORM: + case VK_FORMAT_R16G16_UNORM: + case VK_FORMAT_R16G16_SNORM: + case VK_FORMAT_R16G16B16_UNORM: + case VK_FORMAT_R16G16B16_SNORM: + case VK_FORMAT_R16G16B16A16_UNORM: + case VK_FORMAT_R16G16B16A16_SNORM: + case VK_FORMAT_BC1_RGB_UNORM_BLOCK: + case VK_FORMAT_BC2_UNORM_BLOCK: + case VK_FORMAT_BC3_UNORM_BLOCK: + case VK_FORMAT_BC4_UNORM_BLOCK: + case VK_FORMAT_BC4_SNORM_BLOCK: + case VK_FORMAT_BC5_UNORM_BLOCK: + case VK_FORMAT_BC5_SNORM_BLOCK: + case VK_FORMAT_BC7_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: + case VK_FORMAT_EAC_R11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11_SNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_B5G6R5_UNORM_PACK16: + case VK_FORMAT_B8G8R8_UNORM: + case VK_FORMAT_B8G8R8_SNORM: + case VK_FORMAT_B8G8R8A8_UNORM: + case VK_FORMAT_B8G8R8A8_SNORM: + case VK_FORMAT_A2R10G10B10_UNORM_PACK32: + case VK_FORMAT_A2R10G10B10_SNORM_PACK32: + is_norm = true; + break; + default: + break; + } + + return is_norm; +}; + +// Return true if format is of type UNORM +VK_LAYER_EXPORT bool VkFormatIsUNorm(VkFormat format) { + bool is_unorm = false; + + switch (format) { + case VK_FORMAT_R4G4_UNORM_PACK8: + case VK_FORMAT_R4G4B4A4_UNORM_PACK16: + case VK_FORMAT_R5G6B5_UNORM_PACK16: + case VK_FORMAT_R5G5B5A1_UNORM_PACK16: + case VK_FORMAT_A1R5G5B5_UNORM_PACK16: + case VK_FORMAT_R8_UNORM: + case VK_FORMAT_R8G8_UNORM: + case VK_FORMAT_R8G8B8_UNORM: + case VK_FORMAT_R8G8B8A8_UNORM: + case VK_FORMAT_A8B8G8R8_UNORM_PACK32: + case VK_FORMAT_A2B10G10R10_UNORM_PACK32: + case VK_FORMAT_R16_UNORM: + case VK_FORMAT_R16G16_UNORM: + case VK_FORMAT_R16G16B16_UNORM: + case VK_FORMAT_R16G16B16A16_UNORM: + case VK_FORMAT_BC1_RGB_UNORM_BLOCK: + case VK_FORMAT_BC2_UNORM_BLOCK: + case VK_FORMAT_BC3_UNORM_BLOCK: + case VK_FORMAT_BC4_UNORM_BLOCK: + case VK_FORMAT_BC5_UNORM_BLOCK: + case VK_FORMAT_BC7_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: + case VK_FORMAT_EAC_R11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_B5G6R5_UNORM_PACK16: + case VK_FORMAT_B8G8R8_UNORM: + case VK_FORMAT_B8G8R8A8_UNORM: + case VK_FORMAT_A2R10G10B10_UNORM_PACK32: + is_unorm = true; + break; + default: + break; + } + + return is_unorm; +}; + +// Return true if format is of type SNORM +VK_LAYER_EXPORT bool VkFormatIsSNorm(VkFormat format) { + bool is_snorm = false; + + switch (format) { + case VK_FORMAT_R8_SNORM: + case VK_FORMAT_R8G8_SNORM: + case VK_FORMAT_R8G8B8_SNORM: + case VK_FORMAT_R8G8B8A8_SNORM: + case VK_FORMAT_A8B8G8R8_SNORM_PACK32: + case VK_FORMAT_A2B10G10R10_SNORM_PACK32: + case VK_FORMAT_R16_SNORM: + case VK_FORMAT_R16G16_SNORM: + case VK_FORMAT_R16G16B16_SNORM: + case VK_FORMAT_R16G16B16A16_SNORM: + case VK_FORMAT_BC4_SNORM_BLOCK: + case VK_FORMAT_BC5_SNORM_BLOCK: + case VK_FORMAT_EAC_R11_SNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: + case VK_FORMAT_B8G8R8_SNORM: + case VK_FORMAT_B8G8R8A8_SNORM: + case VK_FORMAT_A2R10G10B10_SNORM_PACK32: + is_snorm = true; + break; + default: + break; + } + + return is_snorm; +}; + +// Return true if format is an integer format +VK_LAYER_EXPORT bool VkFormatIsInt(VkFormat format) { return (VkFormatIsSInt(format) || VkFormatIsUInt(format)); } + +// Return true if format is an unsigned integer format +VK_LAYER_EXPORT bool VkFormatIsUInt(VkFormat format) { + bool is_uint = false; + + switch (format) { + case VK_FORMAT_R8_UINT: + case VK_FORMAT_R8G8_UINT: + case VK_FORMAT_R8G8B8_UINT: + case VK_FORMAT_R8G8B8A8_UINT: + case VK_FORMAT_A8B8G8R8_UINT_PACK32: + case VK_FORMAT_A2B10G10R10_UINT_PACK32: + case VK_FORMAT_R16_UINT: + case VK_FORMAT_R16G16_UINT: + case VK_FORMAT_R16G16B16_UINT: + case VK_FORMAT_R16G16B16A16_UINT: + case VK_FORMAT_R32_UINT: + case VK_FORMAT_R32G32_UINT: + case VK_FORMAT_R32G32B32_UINT: + case VK_FORMAT_R32G32B32A32_UINT: + case VK_FORMAT_R64_UINT: + case VK_FORMAT_R64G64_UINT: + case VK_FORMAT_R64G64B64_UINT: + case VK_FORMAT_R64G64B64A64_UINT: + case VK_FORMAT_B8G8R8_UINT: + case VK_FORMAT_B8G8R8A8_UINT: + case VK_FORMAT_A2R10G10B10_UINT_PACK32: + is_uint = true; + break; + default: + break; + } + + return is_uint; +} + +// Return true if format is a signed integer format +VK_LAYER_EXPORT bool VkFormatIsSInt(VkFormat format) { + bool is_sint = false; + + switch (format) { + case VK_FORMAT_R8_SINT: + case VK_FORMAT_R8G8_SINT: + case VK_FORMAT_R8G8B8_SINT: + case VK_FORMAT_R8G8B8A8_SINT: + case VK_FORMAT_A8B8G8R8_SINT_PACK32: + case VK_FORMAT_A2B10G10R10_SINT_PACK32: + case VK_FORMAT_R16_SINT: + case VK_FORMAT_R16G16_SINT: + case VK_FORMAT_R16G16B16_SINT: + case VK_FORMAT_R16G16B16A16_SINT: + case VK_FORMAT_R32_SINT: + case VK_FORMAT_R32G32_SINT: + case VK_FORMAT_R32G32B32_SINT: + case VK_FORMAT_R32G32B32A32_SINT: + case VK_FORMAT_R64_SINT: + case VK_FORMAT_R64G64_SINT: + case VK_FORMAT_R64G64B64_SINT: + case VK_FORMAT_R64G64B64A64_SINT: + case VK_FORMAT_B8G8R8_SINT: + case VK_FORMAT_B8G8R8A8_SINT: + case VK_FORMAT_A2R10G10B10_SINT_PACK32: + is_sint = true; + break; + default: + break; + } + + return is_sint; +} + +// Return true if format is a floating-point format +VK_LAYER_EXPORT bool VkFormatIsFloat(VkFormat format) { + bool is_float = false; + + switch (format) { + case VK_FORMAT_R16_SFLOAT: + case VK_FORMAT_R16G16_SFLOAT: + case VK_FORMAT_R16G16B16_SFLOAT: + case VK_FORMAT_R16G16B16A16_SFLOAT: + case VK_FORMAT_R32_SFLOAT: + case VK_FORMAT_R32G32_SFLOAT: + case VK_FORMAT_R32G32B32_SFLOAT: + case VK_FORMAT_R32G32B32A32_SFLOAT: + case VK_FORMAT_R64_SFLOAT: + case VK_FORMAT_R64G64_SFLOAT: + case VK_FORMAT_R64G64B64_SFLOAT: + case VK_FORMAT_R64G64B64A64_SFLOAT: + case VK_FORMAT_B10G11R11_UFLOAT_PACK32: + case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32: + case VK_FORMAT_BC6H_UFLOAT_BLOCK: + case VK_FORMAT_BC6H_SFLOAT_BLOCK: + is_float = true; + break; + default: + break; + } + + return is_float; +} + +// Return true if format is in the SRGB colorspace +VK_LAYER_EXPORT bool VkFormatIsSRGB(VkFormat format) { + bool is_srgb = false; + + switch (format) { + case VK_FORMAT_R8_SRGB: + case VK_FORMAT_R8G8_SRGB: + case VK_FORMAT_R8G8B8_SRGB: + case VK_FORMAT_R8G8B8A8_SRGB: + case VK_FORMAT_A8B8G8R8_SRGB_PACK32: + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: + case VK_FORMAT_BC2_SRGB_BLOCK: + case VK_FORMAT_BC3_SRGB_BLOCK: + case VK_FORMAT_BC7_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + case VK_FORMAT_B8G8R8_SRGB: + case VK_FORMAT_B8G8R8A8_SRGB: + is_srgb = true; + break; + default: + break; + } + + return is_srgb; +} + +// Return true if format is in the USCALED colorspace +VK_LAYER_EXPORT bool VkFormatIsUScaled(VkFormat format) { + bool is_uscaled = false; + + switch (format) { + case VK_FORMAT_R8_USCALED: + case VK_FORMAT_R8G8_USCALED: + case VK_FORMAT_R8G8B8_USCALED: + case VK_FORMAT_B8G8R8_USCALED: + case VK_FORMAT_R8G8B8A8_USCALED: + case VK_FORMAT_B8G8R8A8_USCALED: + case VK_FORMAT_A8B8G8R8_USCALED_PACK32: + case VK_FORMAT_A2R10G10B10_USCALED_PACK32: + case VK_FORMAT_A2B10G10R10_USCALED_PACK32: + case VK_FORMAT_R16_USCALED: + case VK_FORMAT_R16G16_USCALED: + case VK_FORMAT_R16G16B16_USCALED: + case VK_FORMAT_R16G16B16A16_USCALED: + is_uscaled = true; + break; + default: + break; + } + + return is_uscaled; +} + +// Return true if format is in the SSCALED colorspace +VK_LAYER_EXPORT bool VkFormatIsSScaled(VkFormat format) { + bool is_sscaled = false; + + switch (format) { + case VK_FORMAT_R8_SSCALED: + case VK_FORMAT_R8G8_SSCALED: + case VK_FORMAT_R8G8B8_SSCALED: + case VK_FORMAT_B8G8R8_SSCALED: + case VK_FORMAT_R8G8B8A8_SSCALED: + case VK_FORMAT_B8G8R8A8_SSCALED: + case VK_FORMAT_A8B8G8R8_SSCALED_PACK32: + case VK_FORMAT_A2R10G10B10_SSCALED_PACK32: + case VK_FORMAT_A2B10G10R10_SSCALED_PACK32: + case VK_FORMAT_R16_SSCALED: + case VK_FORMAT_R16G16_SSCALED: + case VK_FORMAT_R16G16B16_SSCALED: + case VK_FORMAT_R16G16B16A16_SSCALED: + is_sscaled = true; + break; + default: + break; + } + + return is_sscaled; +} + +// Return true if format is compressed +VK_LAYER_EXPORT bool VkFormatIsCompressed(VkFormat format) { + switch (format) { + case VK_FORMAT_BC1_RGB_UNORM_BLOCK: + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: + case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: + case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: + case VK_FORMAT_BC2_UNORM_BLOCK: + case VK_FORMAT_BC2_SRGB_BLOCK: + case VK_FORMAT_BC3_UNORM_BLOCK: + case VK_FORMAT_BC3_SRGB_BLOCK: + case VK_FORMAT_BC4_UNORM_BLOCK: + case VK_FORMAT_BC4_SNORM_BLOCK: + case VK_FORMAT_BC5_UNORM_BLOCK: + case VK_FORMAT_BC5_SNORM_BLOCK: + case VK_FORMAT_BC6H_UFLOAT_BLOCK: + case VK_FORMAT_BC6H_SFLOAT_BLOCK: + case VK_FORMAT_BC7_UNORM_BLOCK: + case VK_FORMAT_BC7_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + case VK_FORMAT_EAC_R11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11_SNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + return true; + default: + return false; + } +} + +// Return compressed texel block sizes for block compressed formats +VK_LAYER_EXPORT VkExtent3D VkFormatCompressedTexelBlockExtent(VkFormat format) { + VkExtent3D block_size = {1, 1, 1}; + switch (format) { + case VK_FORMAT_BC1_RGB_UNORM_BLOCK: + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: + case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: + case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: + case VK_FORMAT_BC2_UNORM_BLOCK: + case VK_FORMAT_BC2_SRGB_BLOCK: + case VK_FORMAT_BC3_UNORM_BLOCK: + case VK_FORMAT_BC3_SRGB_BLOCK: + case VK_FORMAT_BC4_UNORM_BLOCK: + case VK_FORMAT_BC4_SNORM_BLOCK: + case VK_FORMAT_BC5_UNORM_BLOCK: + case VK_FORMAT_BC5_SNORM_BLOCK: + case VK_FORMAT_BC6H_UFLOAT_BLOCK: + case VK_FORMAT_BC6H_SFLOAT_BLOCK: + case VK_FORMAT_BC7_UNORM_BLOCK: + case VK_FORMAT_BC7_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + case VK_FORMAT_EAC_R11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11_SNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + block_size = {4, 4, 1}; + break; + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + block_size = {5, 4, 1}; + break; + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + block_size = {5, 5, 1}; + break; + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + block_size = {6, 5, 1}; + break; + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + block_size = {6, 6, 1}; + break; + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + block_size = {8, 5, 1}; + break; + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + block_size = {8, 6, 1}; + break; + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + block_size = {8, 8, 1}; + break; + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + block_size = {10, 5, 1}; + break; + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + block_size = {10, 6, 1}; + break; + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + block_size = {10, 8, 1}; + break; + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + block_size = {10, 10, 1}; + break; + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + block_size = {12, 10, 1}; + break; + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + block_size = {12, 12, 1}; + break; + default: + break; + } + return block_size; +} + +// Return format class of the specified format +VK_LAYER_EXPORT VkFormatCompatibilityClass VkFormatGetCompatibilityClass(VkFormat format) { + auto item = vk_format_table.find(format); + if (item != vk_format_table.end()) { + return item->second.format_class; + } + return VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT; +} + +// Return size, in bytes, of a pixel of the specified format +VK_LAYER_EXPORT size_t VkFormatGetSize(VkFormat format) { + auto item = vk_format_table.find(format); + if (item != vk_format_table.end()) { + return item->second.size; + } + return 0; +} + +// Return the number of channels for a given format +unsigned int VkFormatGetChannelCount(VkFormat format) { + auto item = vk_format_table.find(format); + if (item != vk_format_table.end()) { + return item->second.channel_count; + } + return 0; +} + +// Perform a zero-tolerant modulo operation +VK_LAYER_EXPORT VkDeviceSize VkSafeModulo(VkDeviceSize dividend, VkDeviceSize divisor) { + VkDeviceSize result = 0; + if (divisor != 0) { + result = dividend % divisor; + } + return result; +} diff --git a/layers/vk_format_utils.h b/layers/vk_format_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..a87ae0de92ddeb060843e1566f8dc1a82cac936e --- /dev/null +++ b/layers/vk_format_utils.h @@ -0,0 +1,132 @@ +/* Copyright (c) 2015-2017 The Khronos Group Inc. + * Copyright (c) 2015-2017 Valve Corporation + * Copyright (c) 2015-2017 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Author: Mark Lobodzinski <mark@lunarg.com> + * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> + * Author: Dave Houlton <daveh@lunarg.com> + */ + +#pragma once +#include <stdbool.h> +#include <vector> +#include "vulkan/vulkan.h" + +#if !defined(VK_LAYER_EXPORT) +#if defined(__GNUC__) && __GNUC__ >= 4 +#define VK_LAYER_EXPORT __attribute__((visibility("default"))) +#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) +#define VK_LAYER_EXPORT __attribute__((visibility("default"))) +#else +#define VK_LAYER_EXPORT +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum VkFormatCompatibilityClass { + VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT = 0, + VK_FORMAT_COMPATIBILITY_CLASS_8_BIT = 1, + VK_FORMAT_COMPATIBILITY_CLASS_16_BIT = 2, + VK_FORMAT_COMPATIBILITY_CLASS_24_BIT = 3, + VK_FORMAT_COMPATIBILITY_CLASS_32_BIT = 4, + VK_FORMAT_COMPATIBILITY_CLASS_48_BIT = 5, + VK_FORMAT_COMPATIBILITY_CLASS_64_BIT = 6, + VK_FORMAT_COMPATIBILITY_CLASS_96_BIT = 7, + VK_FORMAT_COMPATIBILITY_CLASS_128_BIT = 8, + VK_FORMAT_COMPATIBILITY_CLASS_192_BIT = 9, + VK_FORMAT_COMPATIBILITY_CLASS_256_BIT = 10, + VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT = 11, + VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT = 12, + VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT = 13, + VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT = 14, + VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT = 15, + VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT = 16, + VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT = 17, + VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT = 18, + VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT = 19, + VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT = 20, + VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT = 21, + VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT = 22, + VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT = 23, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT = 24, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT = 25, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT = 26, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT = 27, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT = 28, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT = 29, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT = 20, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT = 31, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT = 32, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT = 33, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT = 34, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT = 35, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT = 36, + VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT = 37, + VK_FORMAT_COMPATIBILITY_CLASS_D16_BIT = 38, + VK_FORMAT_COMPATIBILITY_CLASS_D24_BIT = 39, + VK_FORMAT_COMPATIBILITY_CLASS_D32_BIT = 30, + VK_FORMAT_COMPATIBILITY_CLASS_S8_BIT = 41, + VK_FORMAT_COMPATIBILITY_CLASS_D16S8_BIT = 42, + VK_FORMAT_COMPATIBILITY_CLASS_D24S8_BIT = 43, + VK_FORMAT_COMPATIBILITY_CLASS_D32S8_BIT = 44, + VK_FORMAT_COMPATIBILITY_CLASS_MAX_ENUM = 45 +} VkFormatCompatibilityClass; + +static inline bool VkFormatIsUndef(VkFormat format) { return (format == VK_FORMAT_UNDEFINED); } + +VK_LAYER_EXPORT bool VkFormatIsDepthOrStencil(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsDepthAndStencil(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsDepthOnly(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsStencilOnly(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsCompressed_ETC2_EAC(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsCompressed_ASTC_LDR(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsCompressed_BC(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsNorm(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsUNorm(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsSNorm(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsInt(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsSInt(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsUInt(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsFloat(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsSRGB(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsUScaled(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsSScaled(VkFormat format); +VK_LAYER_EXPORT bool VkFormatIsCompressed(VkFormat format); + +static inline bool VkFormatIsColor(VkFormat format) { + return !(VkFormatIsUndef(format) || VkFormatIsDepthOrStencil(format)); +} + +static inline bool VkFormatHasDepth(VkFormat format) { + return (VkFormatIsDepthOnly(format) || VkFormatIsDepthAndStencil(format)); +} + +static inline bool VkFormatHasStencil(VkFormat format) { + return (VkFormatIsStencilOnly(format) || VkFormatIsDepthAndStencil(format)); +} + +VK_LAYER_EXPORT VkExtent3D VkFormatCompressedTexelBlockExtent(VkFormat format); +VK_LAYER_EXPORT size_t VkFormatGetSize(VkFormat format); +VK_LAYER_EXPORT unsigned int VkFormatGetChannelCount(VkFormat format); +VK_LAYER_EXPORT VkFormatCompatibilityClass VkFormatGetCompatibilityClass(VkFormat format); + +VK_LAYER_EXPORT VkDeviceSize VkSafeModulo(VkDeviceSize dividend, VkDeviceSize divisor); + +#ifdef __cplusplus +} +#endif diff --git a/layers/vk_layer_utils.cpp b/layers/vk_layer_utils.cpp index 5436b820b9de46d550379435160c4397626f6071..31bedd8d222cb57a6d3181809639708f8c080a80 100644 --- a/layers/vk_layer_utils.cpp +++ b/layers/vk_layer_utils.cpp @@ -15,6 +15,7 @@ * limitations under the License. * * Author: Mark Lobodzinski <mark@lunarg.com> + * Author: Dave Houlton <daveh@lunarg.com> * */ @@ -26,903 +27,6 @@ #include "vk_layer_config.h" #include "vk_layer_utils.h" -struct VULKAN_FORMAT_INFO { - size_t size; - uint32_t channel_count; - VkFormatCompatibilityClass format_class; -}; - -// Disable auto-formatting for this large table -// clang-format off - -// Set up data structure with number of bytes and number of channels for each Vulkan format -const std::map<VkFormat, VULKAN_FORMAT_INFO> vk_format_table = { - {VK_FORMAT_UNDEFINED, {0, 0, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT }}, - {VK_FORMAT_R4G4_UNORM_PACK8, {1, 2, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R4G4B4A4_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_B4G4R4A4_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R5G6B5_UNORM_PACK16, {2, 3, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_B5G6R5_UNORM_PACK16, {2, 3, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R5G5B5A1_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_B5G5R5A1_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_A1R5G5B5_UNORM_PACK16, {2, 4, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8_UNORM, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8_SNORM, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8_USCALED, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8_SSCALED, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8_UINT, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8_SINT, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8_SRGB, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_8_BIT}}, - {VK_FORMAT_R8G8_UNORM, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8_SNORM, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8_USCALED, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8_SSCALED, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8_UINT, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8_SINT, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8_SRGB, {2, 2, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R8G8B8_UNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8_SNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8_USCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8_SSCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8_UINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8_SINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8_SRGB, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_UNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_SNORM, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_USCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_SSCALED, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_UINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_SINT, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_B8G8R8_SRGB, {3, 3, VK_FORMAT_COMPATIBILITY_CLASS_24_BIT}}, - {VK_FORMAT_R8G8B8A8_UNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R8G8B8A8_SNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R8G8B8A8_USCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R8G8B8A8_SSCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R8G8B8A8_UINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R8G8B8A8_SINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R8G8B8A8_SRGB, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_UNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_SNORM, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_USCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_SSCALED, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_UINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_SINT, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_B8G8R8A8_SRGB, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_UNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_SNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_USCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_SSCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_UINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_SINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A8B8G8R8_SRGB_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2R10G10B10_UNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2R10G10B10_SNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2R10G10B10_USCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2R10G10B10_SSCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2R10G10B10_UINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2R10G10B10_SINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2B10G10R10_UNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2B10G10R10_SNORM_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2B10G10R10_USCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2B10G10R10_SSCALED_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2B10G10R10_UINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_A2B10G10R10_SINT_PACK32, {4, 4, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16_UNORM, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16_SNORM, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16_USCALED, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16_SSCALED, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16_UINT, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16_SINT, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16_SFLOAT, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_16_BIT}}, - {VK_FORMAT_R16G16_UNORM, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16_SNORM, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16_USCALED, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16_SSCALED, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16_UINT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16_SINT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16_SFLOAT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R16G16B16_UNORM, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16_SNORM, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16_USCALED, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16_SSCALED, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16_UINT, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16_SINT, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16_SFLOAT, {6, 3, VK_FORMAT_COMPATIBILITY_CLASS_48_BIT}}, - {VK_FORMAT_R16G16B16A16_UNORM, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R16G16B16A16_SNORM, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R16G16B16A16_USCALED, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R16G16B16A16_SSCALED, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R16G16B16A16_UINT, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R16G16B16A16_SINT, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R16G16B16A16_SFLOAT, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R32_UINT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R32_SINT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R32_SFLOAT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_R32G32_UINT, {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R32G32_SINT, {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R32G32_SFLOAT, {8, 2, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R32G32B32_UINT, {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}}, - {VK_FORMAT_R32G32B32_SINT, {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}}, - {VK_FORMAT_R32G32B32_SFLOAT, {12, 3, VK_FORMAT_COMPATIBILITY_CLASS_96_BIT}}, - {VK_FORMAT_R32G32B32A32_UINT, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, - {VK_FORMAT_R32G32B32A32_SINT, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, - {VK_FORMAT_R32G32B32A32_SFLOAT, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, - {VK_FORMAT_R64_UINT, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R64_SINT, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R64_SFLOAT, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_64_BIT}}, - {VK_FORMAT_R64G64_UINT, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, - {VK_FORMAT_R64G64_SINT, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, - {VK_FORMAT_R64G64_SFLOAT, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_128_BIT}}, - {VK_FORMAT_R64G64B64_UINT, {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}}, - {VK_FORMAT_R64G64B64_SINT, {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}}, - {VK_FORMAT_R64G64B64_SFLOAT, {24, 3, VK_FORMAT_COMPATIBILITY_CLASS_192_BIT}}, - {VK_FORMAT_R64G64B64A64_UINT, {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}}, - {VK_FORMAT_R64G64B64A64_SINT, {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}}, - {VK_FORMAT_R64G64B64A64_SFLOAT, {32, 4, VK_FORMAT_COMPATIBILITY_CLASS_256_BIT}}, - {VK_FORMAT_B10G11R11_UFLOAT_PACK32, {4, 3, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, {4, 3, VK_FORMAT_COMPATIBILITY_CLASS_32_BIT}}, - {VK_FORMAT_D16_UNORM, {2, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_X8_D24_UNORM_PACK32, {3, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_D32_SFLOAT, {4, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_S8_UINT, {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_D16_UNORM_S8_UINT, {3, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_D24_UNORM_S8_UINT, {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_D32_SFLOAT_S8_UINT, {5, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}}, - {VK_FORMAT_BC1_RGB_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}}, - {VK_FORMAT_BC1_RGB_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}}, - {VK_FORMAT_BC1_RGBA_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}}, - {VK_FORMAT_BC1_RGBA_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}}, - {VK_FORMAT_BC2_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT}}, - {VK_FORMAT_BC2_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT}}, - {VK_FORMAT_BC3_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT}}, - {VK_FORMAT_BC3_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT}}, - {VK_FORMAT_BC4_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT}}, - {VK_FORMAT_BC4_SNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT}}, - {VK_FORMAT_BC5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT}}, - {VK_FORMAT_BC5_SNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT}}, - {VK_FORMAT_BC6H_UFLOAT_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT}}, - {VK_FORMAT_BC6H_SFLOAT_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT}}, - {VK_FORMAT_BC7_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT}}, - {VK_FORMAT_BC7_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT}}, - {VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, {8, 3, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT}}, - {VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, {8, 3, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT}}, - {VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT}}, - {VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT}}, - {VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT}}, - {VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT}}, - {VK_FORMAT_EAC_R11_UNORM_BLOCK, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT}}, - {VK_FORMAT_EAC_R11_SNORM_BLOCK, {8, 1, VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT}}, - {VK_FORMAT_EAC_R11G11_UNORM_BLOCK, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT}}, - {VK_FORMAT_EAC_R11G11_SNORM_BLOCK, {16, 2, VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT}}, - {VK_FORMAT_ASTC_4x4_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT}}, - {VK_FORMAT_ASTC_4x4_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT}}, - {VK_FORMAT_ASTC_5x4_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT}}, - {VK_FORMAT_ASTC_5x4_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT}}, - {VK_FORMAT_ASTC_5x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT}}, - {VK_FORMAT_ASTC_5x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT}}, - {VK_FORMAT_ASTC_6x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT}}, - {VK_FORMAT_ASTC_6x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT}}, - {VK_FORMAT_ASTC_6x6_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT}}, - {VK_FORMAT_ASTC_6x6_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT}}, - {VK_FORMAT_ASTC_8x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT}}, - {VK_FORMAT_ASTC_8x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT}}, - {VK_FORMAT_ASTC_8x6_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT}}, - {VK_FORMAT_ASTC_8x6_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT}}, - {VK_FORMAT_ASTC_8x8_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT}}, - {VK_FORMAT_ASTC_8x8_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT}}, - {VK_FORMAT_ASTC_10x5_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT}}, - {VK_FORMAT_ASTC_10x5_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT}}, - {VK_FORMAT_ASTC_10x6_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}}, - {VK_FORMAT_ASTC_10x6_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}}, - {VK_FORMAT_ASTC_10x8_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, - {VK_FORMAT_ASTC_10x8_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, - {VK_FORMAT_ASTC_10x10_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, - {VK_FORMAT_ASTC_10x10_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, - {VK_FORMAT_ASTC_12x10_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, - {VK_FORMAT_ASTC_12x10_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, - {VK_FORMAT_ASTC_12x12_UNORM_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT}}, - {VK_FORMAT_ASTC_12x12_SRGB_BLOCK, {16, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT}}, - {VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT }}, - {VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT}}, - {VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, - {VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT}}, - {VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, - {VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT}}, - {VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, - {VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG, {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT}}, -}; - -// Renable formatting -// clang-format on - -// Return true if format is an ETC2 or EAC compressed texture format -VK_LAYER_EXPORT bool vk_format_is_compressed_ETC2_EAC(VkFormat format) { - bool found = false; - - switch (format) { - case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: - case VK_FORMAT_EAC_R11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11_SNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: - found = true; - break; - default: - break; - } - return found; -} - -// Return true if format is an ETC2 or EAC compressed texture format -VK_LAYER_EXPORT bool vk_format_is_compressed_ASTC_LDR(VkFormat format) { - bool found = false; - - switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - found = true; - break; - default: - break; - } - return found; -} - -// Return true if format is a BC compressed texture format -VK_LAYER_EXPORT bool vk_format_is_compressed_BC(VkFormat format) { - bool found = false; - - switch (format) { - case VK_FORMAT_BC1_RGB_UNORM_BLOCK: - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: - case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: - case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: - case VK_FORMAT_BC2_UNORM_BLOCK: - case VK_FORMAT_BC2_SRGB_BLOCK: - case VK_FORMAT_BC3_UNORM_BLOCK: - case VK_FORMAT_BC3_SRGB_BLOCK: - case VK_FORMAT_BC4_UNORM_BLOCK: - case VK_FORMAT_BC4_SNORM_BLOCK: - case VK_FORMAT_BC5_UNORM_BLOCK: - case VK_FORMAT_BC5_SNORM_BLOCK: - case VK_FORMAT_BC6H_UFLOAT_BLOCK: - case VK_FORMAT_BC6H_SFLOAT_BLOCK: - case VK_FORMAT_BC7_UNORM_BLOCK: - case VK_FORMAT_BC7_SRGB_BLOCK: - found = true; - break; - default: - break; - } - return found; -} - -// Return true if format is a depth or stencil format -VK_LAYER_EXPORT bool vk_format_is_depth_or_stencil(VkFormat format) { - return (vk_format_is_depth_and_stencil(format) || vk_format_is_depth_only(format) || vk_format_is_stencil_only(format)); -} - -// Return true if format contains depth and stencil information -VK_LAYER_EXPORT bool vk_format_is_depth_and_stencil(VkFormat format) { - bool is_ds = false; - - switch (format) { - case VK_FORMAT_D16_UNORM_S8_UINT: - case VK_FORMAT_D24_UNORM_S8_UINT: - case VK_FORMAT_D32_SFLOAT_S8_UINT: - is_ds = true; - break; - default: - break; - } - return is_ds; -} - -// Return true if format is a stencil-only format -VK_LAYER_EXPORT bool vk_format_is_stencil_only(VkFormat format) { return (format == VK_FORMAT_S8_UINT); } - -// Return true if format is a depth-only format -VK_LAYER_EXPORT bool vk_format_is_depth_only(VkFormat format) { - bool is_depth = false; - - switch (format) { - case VK_FORMAT_D16_UNORM: - case VK_FORMAT_X8_D24_UNORM_PACK32: - case VK_FORMAT_D32_SFLOAT: - is_depth = true; - break; - default: - break; - } - - return is_depth; -} - -// Return true if format is of type NORM -VK_LAYER_EXPORT bool vk_format_is_norm(VkFormat format) { - bool is_norm = false; - - switch (format) { - case VK_FORMAT_R4G4_UNORM_PACK8: - case VK_FORMAT_R4G4B4A4_UNORM_PACK16: - case VK_FORMAT_R5G6B5_UNORM_PACK16: - case VK_FORMAT_R5G5B5A1_UNORM_PACK16: - case VK_FORMAT_A1R5G5B5_UNORM_PACK16: - case VK_FORMAT_R8_UNORM: - case VK_FORMAT_R8_SNORM: - case VK_FORMAT_R8G8_UNORM: - case VK_FORMAT_R8G8_SNORM: - case VK_FORMAT_R8G8B8_UNORM: - case VK_FORMAT_R8G8B8_SNORM: - case VK_FORMAT_R8G8B8A8_UNORM: - case VK_FORMAT_R8G8B8A8_SNORM: - case VK_FORMAT_A8B8G8R8_UNORM_PACK32: - case VK_FORMAT_A8B8G8R8_SNORM_PACK32: - case VK_FORMAT_A2B10G10R10_UNORM_PACK32: - case VK_FORMAT_A2B10G10R10_SNORM_PACK32: - case VK_FORMAT_R16_UNORM: - case VK_FORMAT_R16_SNORM: - case VK_FORMAT_R16G16_UNORM: - case VK_FORMAT_R16G16_SNORM: - case VK_FORMAT_R16G16B16_UNORM: - case VK_FORMAT_R16G16B16_SNORM: - case VK_FORMAT_R16G16B16A16_UNORM: - case VK_FORMAT_R16G16B16A16_SNORM: - case VK_FORMAT_BC1_RGB_UNORM_BLOCK: - case VK_FORMAT_BC2_UNORM_BLOCK: - case VK_FORMAT_BC3_UNORM_BLOCK: - case VK_FORMAT_BC4_UNORM_BLOCK: - case VK_FORMAT_BC4_SNORM_BLOCK: - case VK_FORMAT_BC5_UNORM_BLOCK: - case VK_FORMAT_BC5_SNORM_BLOCK: - case VK_FORMAT_BC7_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: - case VK_FORMAT_EAC_R11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11_SNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_B5G6R5_UNORM_PACK16: - case VK_FORMAT_B8G8R8_UNORM: - case VK_FORMAT_B8G8R8_SNORM: - case VK_FORMAT_B8G8R8A8_UNORM: - case VK_FORMAT_B8G8R8A8_SNORM: - case VK_FORMAT_A2R10G10B10_UNORM_PACK32: - case VK_FORMAT_A2R10G10B10_SNORM_PACK32: - is_norm = true; - break; - default: - break; - } - - return is_norm; -}; - -// Return true if format is of type UNORM -VK_LAYER_EXPORT bool vk_format_is_unorm(VkFormat format) { - bool is_unorm = false; - - switch (format) { - case VK_FORMAT_R4G4_UNORM_PACK8: - case VK_FORMAT_R4G4B4A4_UNORM_PACK16: - case VK_FORMAT_R5G6B5_UNORM_PACK16: - case VK_FORMAT_R5G5B5A1_UNORM_PACK16: - case VK_FORMAT_A1R5G5B5_UNORM_PACK16: - case VK_FORMAT_R8_UNORM: - case VK_FORMAT_R8G8_UNORM: - case VK_FORMAT_R8G8B8_UNORM: - case VK_FORMAT_R8G8B8A8_UNORM: - case VK_FORMAT_A8B8G8R8_UNORM_PACK32: - case VK_FORMAT_A2B10G10R10_UNORM_PACK32: - case VK_FORMAT_R16_UNORM: - case VK_FORMAT_R16G16_UNORM: - case VK_FORMAT_R16G16B16_UNORM: - case VK_FORMAT_R16G16B16A16_UNORM: - case VK_FORMAT_BC1_RGB_UNORM_BLOCK: - case VK_FORMAT_BC2_UNORM_BLOCK: - case VK_FORMAT_BC3_UNORM_BLOCK: - case VK_FORMAT_BC4_UNORM_BLOCK: - case VK_FORMAT_BC5_UNORM_BLOCK: - case VK_FORMAT_BC7_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: - case VK_FORMAT_EAC_R11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_B5G6R5_UNORM_PACK16: - case VK_FORMAT_B8G8R8_UNORM: - case VK_FORMAT_B8G8R8A8_UNORM: - case VK_FORMAT_A2R10G10B10_UNORM_PACK32: - is_unorm = true; - break; - default: - break; - } - - return is_unorm; -}; - -// Return true if format is of type SNORM -VK_LAYER_EXPORT bool vk_format_is_snorm(VkFormat format) { - bool is_snorm = false; - - switch (format) { - case VK_FORMAT_R8_SNORM: - case VK_FORMAT_R8G8_SNORM: - case VK_FORMAT_R8G8B8_SNORM: - case VK_FORMAT_R8G8B8A8_SNORM: - case VK_FORMAT_A8B8G8R8_SNORM_PACK32: - case VK_FORMAT_A2B10G10R10_SNORM_PACK32: - case VK_FORMAT_R16_SNORM: - case VK_FORMAT_R16G16_SNORM: - case VK_FORMAT_R16G16B16_SNORM: - case VK_FORMAT_R16G16B16A16_SNORM: - case VK_FORMAT_BC4_SNORM_BLOCK: - case VK_FORMAT_BC5_SNORM_BLOCK: - case VK_FORMAT_EAC_R11_SNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: - case VK_FORMAT_B8G8R8_SNORM: - case VK_FORMAT_B8G8R8A8_SNORM: - case VK_FORMAT_A2R10G10B10_SNORM_PACK32: - is_snorm = true; - break; - default: - break; - } - - return is_snorm; -}; - -// Return true if format is an integer format -VK_LAYER_EXPORT bool vk_format_is_int(VkFormat format) { return (vk_format_is_sint(format) || vk_format_is_uint(format)); } - -// Return true if format is an unsigned integer format -VK_LAYER_EXPORT bool vk_format_is_uint(VkFormat format) { - bool is_uint = false; - - switch (format) { - case VK_FORMAT_R8_UINT: - case VK_FORMAT_R8G8_UINT: - case VK_FORMAT_R8G8B8_UINT: - case VK_FORMAT_R8G8B8A8_UINT: - case VK_FORMAT_A8B8G8R8_UINT_PACK32: - case VK_FORMAT_A2B10G10R10_UINT_PACK32: - case VK_FORMAT_R16_UINT: - case VK_FORMAT_R16G16_UINT: - case VK_FORMAT_R16G16B16_UINT: - case VK_FORMAT_R16G16B16A16_UINT: - case VK_FORMAT_R32_UINT: - case VK_FORMAT_R32G32_UINT: - case VK_FORMAT_R32G32B32_UINT: - case VK_FORMAT_R32G32B32A32_UINT: - case VK_FORMAT_R64_UINT: - case VK_FORMAT_R64G64_UINT: - case VK_FORMAT_R64G64B64_UINT: - case VK_FORMAT_R64G64B64A64_UINT: - case VK_FORMAT_B8G8R8_UINT: - case VK_FORMAT_B8G8R8A8_UINT: - case VK_FORMAT_A2R10G10B10_UINT_PACK32: - is_uint = true; - break; - default: - break; - } - - return is_uint; -} - -// Return true if format is a signed integer format -VK_LAYER_EXPORT bool vk_format_is_sint(VkFormat format) { - bool is_sint = false; - - switch (format) { - case VK_FORMAT_R8_SINT: - case VK_FORMAT_R8G8_SINT: - case VK_FORMAT_R8G8B8_SINT: - case VK_FORMAT_R8G8B8A8_SINT: - case VK_FORMAT_A8B8G8R8_SINT_PACK32: - case VK_FORMAT_A2B10G10R10_SINT_PACK32: - case VK_FORMAT_R16_SINT: - case VK_FORMAT_R16G16_SINT: - case VK_FORMAT_R16G16B16_SINT: - case VK_FORMAT_R16G16B16A16_SINT: - case VK_FORMAT_R32_SINT: - case VK_FORMAT_R32G32_SINT: - case VK_FORMAT_R32G32B32_SINT: - case VK_FORMAT_R32G32B32A32_SINT: - case VK_FORMAT_R64_SINT: - case VK_FORMAT_R64G64_SINT: - case VK_FORMAT_R64G64B64_SINT: - case VK_FORMAT_R64G64B64A64_SINT: - case VK_FORMAT_B8G8R8_SINT: - case VK_FORMAT_B8G8R8A8_SINT: - case VK_FORMAT_A2R10G10B10_SINT_PACK32: - is_sint = true; - break; - default: - break; - } - - return is_sint; -} - -// Return true if format is a floating-point format -VK_LAYER_EXPORT bool vk_format_is_float(VkFormat format) { - bool is_float = false; - - switch (format) { - case VK_FORMAT_R16_SFLOAT: - case VK_FORMAT_R16G16_SFLOAT: - case VK_FORMAT_R16G16B16_SFLOAT: - case VK_FORMAT_R16G16B16A16_SFLOAT: - case VK_FORMAT_R32_SFLOAT: - case VK_FORMAT_R32G32_SFLOAT: - case VK_FORMAT_R32G32B32_SFLOAT: - case VK_FORMAT_R32G32B32A32_SFLOAT: - case VK_FORMAT_R64_SFLOAT: - case VK_FORMAT_R64G64_SFLOAT: - case VK_FORMAT_R64G64B64_SFLOAT: - case VK_FORMAT_R64G64B64A64_SFLOAT: - case VK_FORMAT_B10G11R11_UFLOAT_PACK32: - case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32: - case VK_FORMAT_BC6H_UFLOAT_BLOCK: - case VK_FORMAT_BC6H_SFLOAT_BLOCK: - is_float = true; - break; - default: - break; - } - - return is_float; -} - -// Return true if format is in the SRGB colorspace -VK_LAYER_EXPORT bool vk_format_is_srgb(VkFormat format) { - bool is_srgb = false; - - switch (format) { - case VK_FORMAT_R8_SRGB: - case VK_FORMAT_R8G8_SRGB: - case VK_FORMAT_R8G8B8_SRGB: - case VK_FORMAT_R8G8B8A8_SRGB: - case VK_FORMAT_A8B8G8R8_SRGB_PACK32: - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: - case VK_FORMAT_BC2_SRGB_BLOCK: - case VK_FORMAT_BC3_SRGB_BLOCK: - case VK_FORMAT_BC7_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - case VK_FORMAT_B8G8R8_SRGB: - case VK_FORMAT_B8G8R8A8_SRGB: - is_srgb = true; - break; - default: - break; - } - - return is_srgb; -} - -// Return true if format is in the USCALED colorspace -VK_LAYER_EXPORT bool vk_format_is_uscaled(VkFormat format) { - bool is_uscaled = false; - - switch (format) { - case VK_FORMAT_R8_USCALED: - case VK_FORMAT_R8G8_USCALED: - case VK_FORMAT_R8G8B8_USCALED: - case VK_FORMAT_B8G8R8_USCALED: - case VK_FORMAT_R8G8B8A8_USCALED: - case VK_FORMAT_B8G8R8A8_USCALED: - case VK_FORMAT_A8B8G8R8_USCALED_PACK32: - case VK_FORMAT_A2R10G10B10_USCALED_PACK32: - case VK_FORMAT_A2B10G10R10_USCALED_PACK32: - case VK_FORMAT_R16_USCALED: - case VK_FORMAT_R16G16_USCALED: - case VK_FORMAT_R16G16B16_USCALED: - case VK_FORMAT_R16G16B16A16_USCALED: - is_uscaled = true; - break; - default: - break; - } - - return is_uscaled; -} - -// Return true if format is in the SSCALED colorspace -VK_LAYER_EXPORT bool vk_format_is_sscaled(VkFormat format) { - bool is_sscaled = false; - - switch (format) { - case VK_FORMAT_R8_SSCALED: - case VK_FORMAT_R8G8_SSCALED: - case VK_FORMAT_R8G8B8_SSCALED: - case VK_FORMAT_B8G8R8_SSCALED: - case VK_FORMAT_R8G8B8A8_SSCALED: - case VK_FORMAT_B8G8R8A8_SSCALED: - case VK_FORMAT_A8B8G8R8_SSCALED_PACK32: - case VK_FORMAT_A2R10G10B10_SSCALED_PACK32: - case VK_FORMAT_A2B10G10R10_SSCALED_PACK32: - case VK_FORMAT_R16_SSCALED: - case VK_FORMAT_R16G16_SSCALED: - case VK_FORMAT_R16G16B16_SSCALED: - case VK_FORMAT_R16G16B16A16_SSCALED: - is_sscaled = true; - break; - default: - break; - } - - return is_sscaled; -} - -// Return true if format is compressed -VK_LAYER_EXPORT bool vk_format_is_compressed(VkFormat format) { - switch (format) { - case VK_FORMAT_BC1_RGB_UNORM_BLOCK: - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: - case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: - case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: - case VK_FORMAT_BC2_UNORM_BLOCK: - case VK_FORMAT_BC2_SRGB_BLOCK: - case VK_FORMAT_BC3_UNORM_BLOCK: - case VK_FORMAT_BC3_SRGB_BLOCK: - case VK_FORMAT_BC4_UNORM_BLOCK: - case VK_FORMAT_BC4_SNORM_BLOCK: - case VK_FORMAT_BC5_UNORM_BLOCK: - case VK_FORMAT_BC5_SNORM_BLOCK: - case VK_FORMAT_BC6H_UFLOAT_BLOCK: - case VK_FORMAT_BC6H_SFLOAT_BLOCK: - case VK_FORMAT_BC7_UNORM_BLOCK: - case VK_FORMAT_BC7_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: - case VK_FORMAT_EAC_R11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11_SNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - return true; - default: - return false; - } -} - -// Return compressed texel block sizes for block compressed formats -VK_LAYER_EXPORT VkExtent3D vk_format_compressed_texel_block_extents(VkFormat format) { - VkExtent3D block_size = {1, 1, 1}; - switch (format) { - case VK_FORMAT_BC1_RGB_UNORM_BLOCK: - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: - case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: - case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: - case VK_FORMAT_BC2_UNORM_BLOCK: - case VK_FORMAT_BC2_SRGB_BLOCK: - case VK_FORMAT_BC3_UNORM_BLOCK: - case VK_FORMAT_BC3_SRGB_BLOCK: - case VK_FORMAT_BC4_UNORM_BLOCK: - case VK_FORMAT_BC4_SNORM_BLOCK: - case VK_FORMAT_BC5_UNORM_BLOCK: - case VK_FORMAT_BC5_SNORM_BLOCK: - case VK_FORMAT_BC6H_UFLOAT_BLOCK: - case VK_FORMAT_BC6H_SFLOAT_BLOCK: - case VK_FORMAT_BC7_UNORM_BLOCK: - case VK_FORMAT_BC7_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: - case VK_FORMAT_EAC_R11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11_SNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - block_size = {4, 4, 1}; - break; - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - block_size = {5, 4, 1}; - break; - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - block_size = {5, 5, 1}; - break; - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - block_size = {6, 5, 1}; - break; - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - block_size = {6, 6, 1}; - break; - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - block_size = {8, 5, 1}; - break; - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - block_size = {8, 6, 1}; - break; - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - block_size = {8, 8, 1}; - break; - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - block_size = {10, 5, 1}; - break; - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - block_size = {10, 6, 1}; - break; - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - block_size = {10, 8, 1}; - break; - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - block_size = {10, 10, 1}; - break; - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - block_size = {12, 10, 1}; - break; - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - block_size = {12, 12, 1}; - break; - default: - break; - } - return block_size; -} - -// Return format class of the specified format -VK_LAYER_EXPORT VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format) { - auto item = vk_format_table.find(format); - if (item != vk_format_table.end()) { - return item->second.format_class; - } - return VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT; -} - -// Return size, in bytes, of a pixel of the specified format -VK_LAYER_EXPORT size_t vk_format_get_size(VkFormat format) { - auto item = vk_format_table.find(format); - if (item != vk_format_table.end()) { - return item->second.size; - } - return 0; -} - -// Return the number of channels for a given format -unsigned int vk_format_get_channel_count(VkFormat format) { - auto item = vk_format_table.find(format); - if (item != vk_format_table.end()) { - return item->second.channel_count; - } - return 0; -} - -// Perform a zero-tolerant modulo operation -VK_LAYER_EXPORT VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor) { - VkDeviceSize result = 0; - if (divisor != 0) { - result = dividend % divisor; - } - return result; -} - static const uint8_t UTF8_ONE_BYTE_CODE = 0xC0; static const uint8_t UTF8_ONE_BYTE_MASK = 0xE0; static const uint8_t UTF8_TWO_BYTE_CODE = 0xE0; diff --git a/layers/vk_layer_utils.h b/layers/vk_layer_utils.h index 98107ff17d661511313a38fc8b0d9e7b02d0ce82..888983a01b8237d03ce5e2c1589841ee9a87ddbe 100644 --- a/layers/vk_layer_utils.h +++ b/layers/vk_layer_utils.h @@ -22,6 +22,7 @@ #pragma once #include <stdbool.h> #include <vector> +#include "vk_format_utils.h" #include "vk_layer_logging.h" #ifndef WIN32 @@ -35,54 +36,6 @@ extern "C" { #endif #define VK_LAYER_API_VERSION VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION) -typedef enum VkFormatCompatibilityClass { - VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT = 0, - VK_FORMAT_COMPATIBILITY_CLASS_8_BIT = 1, - VK_FORMAT_COMPATIBILITY_CLASS_16_BIT = 2, - VK_FORMAT_COMPATIBILITY_CLASS_24_BIT = 3, - VK_FORMAT_COMPATIBILITY_CLASS_32_BIT = 4, - VK_FORMAT_COMPATIBILITY_CLASS_48_BIT = 5, - VK_FORMAT_COMPATIBILITY_CLASS_64_BIT = 6, - VK_FORMAT_COMPATIBILITY_CLASS_96_BIT = 7, - VK_FORMAT_COMPATIBILITY_CLASS_128_BIT = 8, - VK_FORMAT_COMPATIBILITY_CLASS_192_BIT = 9, - VK_FORMAT_COMPATIBILITY_CLASS_256_BIT = 10, - VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT = 11, - VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT = 12, - VK_FORMAT_COMPATIBILITY_CLASS_BC2_BIT = 13, - VK_FORMAT_COMPATIBILITY_CLASS_BC3_BIT = 14, - VK_FORMAT_COMPATIBILITY_CLASS_BC4_BIT = 15, - VK_FORMAT_COMPATIBILITY_CLASS_BC5_BIT = 16, - VK_FORMAT_COMPATIBILITY_CLASS_BC6H_BIT = 17, - VK_FORMAT_COMPATIBILITY_CLASS_BC7_BIT = 18, - VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGB_BIT = 19, - VK_FORMAT_COMPATIBILITY_CLASS_ETC2_RGBA_BIT = 20, - VK_FORMAT_COMPATIBILITY_CLASS_ETC2_EAC_RGBA_BIT = 21, - VK_FORMAT_COMPATIBILITY_CLASS_EAC_R_BIT = 22, - VK_FORMAT_COMPATIBILITY_CLASS_EAC_RG_BIT = 23, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_4X4_BIT = 24, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X4_BIT = 25, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_5X5_BIT = 26, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X5_BIT = 27, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_6X6_BIT = 28, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X5_BIT = 29, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X6_BIT = 20, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_8X8_BIT = 31, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X5_BIT = 32, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X6_BIT = 33, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X8_BIT = 34, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_10X10_BIT = 35, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X10_BIT = 36, - VK_FORMAT_COMPATIBILITY_CLASS_ASTC_12X12_BIT = 37, - VK_FORMAT_COMPATIBILITY_CLASS_D16_BIT = 38, - VK_FORMAT_COMPATIBILITY_CLASS_D24_BIT = 39, - VK_FORMAT_COMPATIBILITY_CLASS_D32_BIT = 30, - VK_FORMAT_COMPATIBILITY_CLASS_S8_BIT = 41, - VK_FORMAT_COMPATIBILITY_CLASS_D16S8_BIT = 42, - VK_FORMAT_COMPATIBILITY_CLASS_D24S8_BIT = 43, - VK_FORMAT_COMPATIBILITY_CLASS_D32S8_BIT = 44, - VK_FORMAT_COMPATIBILITY_CLASS_MAX_ENUM = 45 -} VkFormatCompatibilityClass; typedef enum VkStringErrorFlagBits { VK_STRING_ERROR_NONE = 0x00000000, @@ -94,44 +47,6 @@ typedef VkFlags VkStringErrorFlags; VK_LAYER_EXPORT void layer_debug_actions(debug_report_data *report_data, std::vector<VkDebugReportCallbackEXT> &logging_callback, const VkAllocationCallbacks *pAllocator, const char *layer_identifier); -static inline bool vk_format_is_undef(VkFormat format) { return (format == VK_FORMAT_UNDEFINED); } - -bool vk_format_is_depth_or_stencil(VkFormat format); -bool vk_format_is_depth_and_stencil(VkFormat format); -bool vk_format_is_depth_only(VkFormat format); -bool vk_format_is_stencil_only(VkFormat format); - -static inline bool vk_format_is_color(VkFormat format) { - return !(vk_format_is_undef(format) || vk_format_is_depth_or_stencil(format)); -} - -static inline bool vk_format_has_depth(VkFormat format) { - return (vk_format_is_depth_only(format) || vk_format_is_depth_and_stencil(format)); -} - -static inline bool vk_format_has_stencil(VkFormat format) { - return (vk_format_is_stencil_only(format) || vk_format_is_depth_and_stencil(format)); -} - -VK_LAYER_EXPORT bool vk_format_is_compressed_ETC2_EAC(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_compressed_ASTC_LDR(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_compressed_BC(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_norm(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_unorm(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_snorm(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_int(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_sint(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_uint(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_float(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_srgb(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_uscaled(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_sscaled(VkFormat format); -VK_LAYER_EXPORT bool vk_format_is_compressed(VkFormat format); -VK_LAYER_EXPORT VkExtent3D vk_format_compressed_texel_block_extents(VkFormat format); -VK_LAYER_EXPORT size_t vk_format_get_size(VkFormat format); -VK_LAYER_EXPORT unsigned int vk_format_get_channel_count(VkFormat format); -VK_LAYER_EXPORT VkFormatCompatibilityClass vk_format_get_compatibility_class(VkFormat format); -VK_LAYER_EXPORT VkDeviceSize vk_safe_modulo(VkDeviceSize dividend, VkDeviceSize divisor); VK_LAYER_EXPORT VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array); VK_LAYER_EXPORT bool white_list(const char *item, const char *whitelist); diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp index aea592aa53fd43c099558a3335cfc3f32a7197c3..b4ea72e9e432f33e01f905fbc30d1e66d49414d3 100644 --- a/tests/layer_validation_tests.cpp +++ b/tests/layer_validation_tests.cpp @@ -35,6 +35,7 @@ #include "icd-spv.h" #include "test_common.h" #include "vk_layer_config.h" +#include "vk_format_utils.h" #include "vk_validation_error_messages.h" #include "vkrenderframework.h" @@ -356,7 +357,6 @@ class VkLayerTest : public VkRenderFramework { InitState(features, flags); } - protected: ErrorMonitor *m_errorMonitor; bool m_enableWSI; @@ -1346,7 +1346,8 @@ TEST_F(VkLayerTest, SparseBindingImageBufferCreate) { TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) { TEST_DESCRIPTION("Create images with sparse residency with unsupported types"); - ASSERT_NO_FATAL_FAILURE(InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE( + InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor)); // Determine which device feature are available VkPhysicalDeviceFeatures available_features = {}; @@ -1413,7 +1414,8 @@ TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) { TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) { TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts"); - ASSERT_NO_FATAL_FAILURE(InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE( + InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor)); // Determine which device feature are available VkPhysicalDeviceFeatures available_features = {}; @@ -2167,8 +2169,7 @@ TEST_F(VkLayerTest, InvalidUsageBits) { m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image "); ASSERT_NO_FATAL_FAILURE(Init()); - - auto format = find_depth_stencil_format(m_device); + auto format = FindDepthStencilFormat(gpu()); if (!format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -8757,7 +8758,7 @@ TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { ASSERT_NO_FATAL_FAILURE(Init()); ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -8908,7 +8909,7 @@ TEST_F(VkLayerTest, InvalidBarriers) { m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -9984,7 +9985,7 @@ TEST_F(VkLayerTest, DSAspectBitsErrors) { VkResult err; ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -11720,7 +11721,7 @@ TEST_F(VkLayerTest, InvalidImageLayout) { // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -15953,7 +15954,7 @@ TEST_F(VkLayerTest, ImageLayerViewTests) { TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { return; } @@ -17054,7 +17055,7 @@ TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { "vkCmdCopyImage called with unmatched source and dest image depth"); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { return; } @@ -17240,7 +17241,7 @@ TEST_F(VkLayerTest, CopyImageSampleCountMismatch) { TEST_F(VkLayerTest, CopyImageAspectMismatch) { TEST_DESCRIPTION("Image copies with aspect mask errors"); ASSERT_NO_FATAL_FAILURE(Init()); - auto ds_format = find_depth_stencil_format(m_device); + auto ds_format = FindDepthStencilFormat(gpu()); if (!ds_format) { return; } @@ -17268,8 +17269,10 @@ TEST_F(VkLayerTest, CopyImageAspectMismatch) { copyRegion.extent = {64, 128, 1}; // Submitting command before command buffer is in recording state - m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You must call vkBeginCommandBuffer");// VALIDATION_ERROR_01192); - vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); + m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, + "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192); + vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(), + VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); m_errorMonitor->VerifyFound(); m_commandBuffer->BeginCommandBuffer(); @@ -17277,25 +17280,28 @@ TEST_F(VkLayerTest, CopyImageAspectMismatch) { // Src and dest aspect masks don't match copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197); - vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); + vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(), + VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); m_errorMonitor->VerifyFound(); copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; // Illegal combinations of aspect bits - VU 01221 - copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone + copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221); // These aspect/format mismatches are redundant but unavoidable here m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200); m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201); - vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); + vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(), + VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); m_errorMonitor->VerifyFound(); // Metadata aspect is illegal - VU 01222 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222); // These aspect/format mismatches are redundant but unavoidable here - vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); + vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(), + VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); m_errorMonitor->VerifyFound(); copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; @@ -17743,7 +17749,7 @@ TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { "Combination depth/stencil image formats can have only the "); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { return; } @@ -17866,7 +17872,7 @@ TEST_F(VkLayerTest, ClearImageErrors) { "ClearDepthStencilImage with a color image."); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { return; } @@ -17951,7 +17957,7 @@ TEST_F(VkLayerTest, CommandQueueFlags) { ASSERT_NO_FATAL_FAILURE(Init()); uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT); - if(queueFamilyIndex == UINT32_MAX) { + if (queueFamilyIndex == UINT32_MAX) { printf(" Non-graphics queue family not found; skipped.\n"); return; } else { @@ -18357,7 +18363,7 @@ TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) { VkResult err; m_errorMonitor->ExpectSuccess(); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { return; } @@ -20304,7 +20310,7 @@ TEST_F(VkPositiveLayerTest, StencilLoadOp) { "CLEAR. stencil[Load|Store]Op used to be ignored."); VkResult result = VK_SUCCESS; ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -20478,7 +20484,7 @@ TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) { m_errorMonitor->ExpectSuccess(); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -21885,7 +21891,7 @@ TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) { "valid *READ_ONLY* layout."); m_errorMonitor->ExpectSuccess(); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; @@ -21933,7 +21939,7 @@ TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) { "transition has correctly occurred at queue submit time with no validation errors."); ASSERT_NO_FATAL_FAILURE(Init()); - auto depth_format = find_depth_stencil_format(m_device); + auto depth_format = FindDepthStencilFormat(gpu()); if (!depth_format) { printf(" No Depth + Stencil format found. Skipped.\n"); return; diff --git a/tests/vkrenderframework.cpp b/tests/vkrenderframework.cpp index 161216b46c191d0f066b02106ef00f912a49eb05..ff7b50c0f7038e8a753ff4361b0011152823da31 100644 --- a/tests/vkrenderframework.cpp +++ b/tests/vkrenderframework.cpp @@ -21,6 +21,7 @@ */ #include "vkrenderframework.h" +#include "vk_format_utils.h" #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define GET_DEVICE_PROC_ADDR(dev, entrypoint) \ @@ -29,47 +30,13 @@ assert(fp##entrypoint != NULL); \ } -// TODO : These functions are duplicated is vk_layer_utils.cpp, share code -// Return true if format contains depth and stencil information -bool vk_format_is_depth_and_stencil(VkFormat format) { - bool is_ds = false; - - switch (format) { - case VK_FORMAT_D16_UNORM_S8_UINT: - case VK_FORMAT_D24_UNORM_S8_UINT: - case VK_FORMAT_D32_SFLOAT_S8_UINT: - is_ds = true; - break; - default: - break; - } - return is_ds; -} - -// Return true if format is a stencil-only format -bool vk_format_is_stencil_only(VkFormat format) { return (format == VK_FORMAT_S8_UINT); } - -// Return true if format is a depth-only format -bool vk_format_is_depth_only(VkFormat format) { - bool is_depth = false; - - switch (format) { - case VK_FORMAT_D16_UNORM: - case VK_FORMAT_X8_D24_UNORM_PACK32: - case VK_FORMAT_D32_SFLOAT: - is_depth = true; - break; - default: - break; - } - - return is_depth; -} - -VkFormat find_depth_stencil_format(VkDeviceObj *device) { +// Format search helpers +VkFormat FindDepthStencilFormat(VkPhysicalDevice phy) { VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT}; for (uint32_t i = 0; i < sizeof(ds_formats); i++) { - VkFormatProperties format_props = device->format_properties(ds_formats[i]); + VkFormatProperties format_props; + vkGetPhysicalDeviceFormatProperties(phy, ds_formats[i], &format_props); + if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { return ds_formats[i]; } @@ -414,8 +381,7 @@ VkDeviceObj::VkDeviceObj(uint32_t id, VkPhysicalDevice obj, std::vector<const ch queue_props = phy().queue_properties(); } -uint32_t VkDeviceObj::QueueFamilyWithoutCapabilities(VkQueueFlags capabilities) -{ +uint32_t VkDeviceObj::QueueFamilyWithoutCapabilities(VkQueueFlags capabilities) { // Find a queue family without desired capabilities for (uint32_t i = 0; i < queue_props.size(); i++) { if ((queue_props[i].queueFlags & capabilities) == 0) { @@ -425,13 +391,11 @@ uint32_t VkDeviceObj::QueueFamilyWithoutCapabilities(VkQueueFlags capabilities) return UINT32_MAX; } - void VkDeviceObj::get_device_queue() { ASSERT_NE(true, graphics_queues().empty()); m_queue = graphics_queues()[0]->handle(); } - VkDescriptorSetObj::VkDescriptorSetObj(VkDeviceObj *device) : m_device(device), m_nextSlot(0) {} VkDescriptorSetObj::~VkDescriptorSetObj() { @@ -601,7 +565,8 @@ void VkImageObj::ImageMemoryBarrier(VkCommandBufferObj *cmd_buf, VkImageAspectFl VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | - VK_MEMORY_INPUT_COPY_BIT*/, VkImageLayout image_layout) { + VK_MEMORY_INPUT_COPY_BIT*/, + VkImageLayout image_layout) { const VkImageSubresourceRange subresourceRange = subresource_range(aspect, 0, 1, 0, 1); VkImageMemoryBarrier barrier; barrier = image_memory_barrier(output_mask, input_mask, layout(), image_layout, subresourceRange); @@ -759,11 +724,11 @@ void VkImageObj::init(uint32_t w, uint32_t h, VkFormat fmt, VkFlags usage, VkIma newLayout = m_descriptorImageInfo.imageLayout; VkImageAspectFlags image_aspect = 0; - if (vk_format_is_depth_and_stencil(fmt)) { + if (VkFormatIsDepthAndStencil(fmt)) { image_aspect = VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; - } else if (vk_format_is_depth_only(fmt)) { + } else if (VkFormatIsDepthOnly(fmt)) { image_aspect = VK_IMAGE_ASPECT_DEPTH_BIT; - } else if (vk_format_is_stencil_only(fmt)) { + } else if (VkFormatIsStencilOnly(fmt)) { image_aspect = VK_IMAGE_ASPECT_STENCIL_BIT; } else { // color image_aspect = VK_IMAGE_ASPECT_COLOR_BIT; @@ -794,11 +759,11 @@ void VkImageObj::init(const VkImageCreateInfo *create_info) { vk_testing::Image::init(*m_device, *create_info, 0); VkImageAspectFlags image_aspect = 0; - if (vk_format_is_depth_and_stencil(create_info->format)) { + if (VkFormatIsDepthAndStencil(create_info->format)) { image_aspect = VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; - } else if (vk_format_is_depth_only(create_info->format)) { + } else if (VkFormatIsDepthOnly(create_info->format)) { image_aspect = VK_IMAGE_ASPECT_DEPTH_BIT; - } else if (vk_format_is_stencil_only(create_info->format)) { + } else if (VkFormatIsStencilOnly(create_info->format)) { image_aspect = VK_IMAGE_ASPECT_STENCIL_BIT; } else { // color image_aspect = VK_IMAGE_ASPECT_COLOR_BIT; @@ -998,7 +963,8 @@ void VkConstantBufferObj::BufferMemoryBarrier(VkFlags srcAccessMask /*= VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | - VK_MEMORY_OUTPUT_COPY_BIT*/, VkFlags dstAccessMask /*= + VK_MEMORY_OUTPUT_COPY_BIT*/, + VkFlags dstAccessMask /*= VK_ACCESS_HOST_READ_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT | VK_ACCESS_INDEX_READ_BIT | @@ -1333,8 +1299,7 @@ void VkPipelineObj::InitGraphicsPipelineCreateInfo(VkGraphicsPipelineCreateInfo } } -VkResult VkPipelineObj::CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass, - VkGraphicsPipelineCreateInfo *gp_ci) { +VkResult VkPipelineObj::CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass, VkGraphicsPipelineCreateInfo *gp_ci) { VkGraphicsPipelineCreateInfo info = {}; // if not given a CreateInfo, create and initialize a local one. @@ -1631,9 +1596,9 @@ void VkDepthStencilObj::Init(VkDeviceObj *device, int32_t width, int32_t height, init(width, height, m_depth_stencil_fmt, usage, VK_IMAGE_TILING_OPTIMAL); VkImageAspectFlags aspect = VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; - if (vk_format_is_depth_only(format)) + if (VkFormatIsDepthOnly(format)) aspect = VK_IMAGE_ASPECT_DEPTH_BIT; - else if (vk_format_is_stencil_only(format)) + else if (VkFormatIsStencilOnly(format)) aspect = VK_IMAGE_ASPECT_STENCIL_BIT; SetLayout(aspect, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); diff --git a/tests/vkrenderframework.h b/tests/vkrenderframework.h index a693038a12ffb04843afd5e8f2a8cfd811d83b2b..f15d19b1726e487c7dec3f8904ff5e122e7d1d07 100644 --- a/tests/vkrenderframework.h +++ b/tests/vkrenderframework.h @@ -445,5 +445,7 @@ class VkPipelineObj : public vk_testing::Pipeline { vector<VkPipelineColorBlendAttachmentState> m_colorAttachments; int m_vertexBufferCount; }; -VkFormat find_depth_stencil_format(VkDeviceObj *device); + +VkFormat FindDepthStencilFormat(VkPhysicalDevice); + #endif // VKRENDERFRAMEWORK_H