diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 5a30f8e5aaa..124b547e807 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -369,6 +369,46 @@ anv_image_plane_needs_shadow_surface(const struct intel_device_info *devinfo, return false; } +/** + * Return true if the storage image could be used with atomics. + * + * If the image was created with an explicit format, we check it for typed + * atomic support. If MUTABLE_FORMAT_BIT is set, then we check the optional + * format list, seeing if /any/ of the formats support typed atomics. If no + * list is supplied, we fall back to using the bpb, as the application could + * make an image view with a format that does use atomics. + */ +static bool +storage_image_format_supports_atomic(const struct intel_device_info *devinfo, + VkImageCreateFlags create_flags, + enum isl_format format, + VkImageTiling vk_tiling, + const VkImageFormatListCreateInfoKHR *fmt_list) +{ + if (isl_format_supports_typed_atomics(devinfo, format)) + return true; + + if (!(create_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) + return false; + + if (fmt_list) { + for (uint32_t i = 0; i < fmt_list->viewFormatCount; i++) { + enum isl_format view_format = + anv_get_isl_format(devinfo, fmt_list->pViewFormats[i], + VK_IMAGE_ASPECT_COLOR_BIT, vk_tiling); + + if (isl_format_supports_typed_atomics(devinfo, view_format)) + return true; + } + + return false; + } + + /* No explicit format list. Any 16/32/64bpp format could be used with atomics. */ + unsigned bpb = isl_format_get_layout(format)->bpb; + return bpb == 16 || bpb == 32 || bpb == 64; +} + static enum isl_format anv_get_isl_format_with_usage(const struct intel_device_info *devinfo, VkFormat vk_format, @@ -451,6 +491,13 @@ anv_formats_ccs_e_compatible(const struct intel_device_info *devinfo, if (!formats_ccs_e_compatible(devinfo, create_flags, format, vk_tiling, VK_IMAGE_USAGE_STORAGE_BIT, fmt_list)) return false; + + /* Disable compression when surface can be potentially used for atomic + * operation. + */ + if (storage_image_format_supports_atomic(devinfo, create_flags, format, + vk_tiling, fmt_list)) + return false; } return true;