Module: Mesa Branch: main Commit: 4d95a7f80080515963112f634a12ad7ca3be0878 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4d95a7f80080515963112f634a12ad7ca3be0878
Author: Renato Pereyra <[email protected]> Date: Tue Jan 18 18:35:56 2022 -0800 anv: add helper methods related to enabling CCS for external images Also, clarify/improve related comments Signed-off-by: Renato Pereyra <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14416> --- src/intel/vulkan/anv_image.c | 37 ++++++++++++++++++++----------------- src/intel/vulkan/anv_private.h | 16 ++++++++++++++++ src/intel/vulkan/genX_cmd_buffer.c | 8 ++++---- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 9a24e65d1e7..4f74f7f750e 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -536,13 +536,14 @@ add_aux_state_tracking_buffer(struct anv_device *device, enum anv_image_memory_binding binding = ANV_IMAGE_MEMORY_BINDING_PLANE_0 + plane; - /* Ensure that AUX state is stored outside the buffer memory for any images - * externally sharable. This prevents corruptions arising due to disjoint - * processes working with the same image. + /* If an auxiliary surface is used for an externally-shareable image, + * we have to hide this from the memory of the image since other + * processes with access to the memory may not be aware of it or of + * its current state. So put that auxiliary data into a separate + * buffer (ANV_IMAGE_MEMORY_BINDING_PRIVATE). */ - if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID || - image->vk.external_handle_types != 0) { - binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; + if (anv_image_is_externally_shared(image)) { + binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; } /* We believe that 256B alignment may be sufficient, but we choose 4K due to @@ -950,13 +951,14 @@ check_memory_bindings(const struct anv_device *device, if (anv_surface_is_valid(&plane->aux_surface)) { enum anv_image_memory_binding binding = primary_binding; - /* Ensure that AUX state is stored outside the buffer memory for any - * images externally sharable. This prevents corruptions arising due - * to disjoint processes working with the same image. + /* If an auxiliary surface is used for an externally-shareable image, + * we have to hide this from the memory of the image since other + * processes with access to the memory may not be aware of it or of + * its current state. So put that auxiliary data into a separate + * buffer (ANV_IMAGE_MEMORY_BINDING_PRIVATE). */ - if ((image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID && - !isl_drm_modifier_has_aux(image->vk.drm_format_mod)) || - (image->vk.external_handle_types != 0)) { + if (anv_image_is_externally_shared(image) && + !isl_drm_modifier_has_aux(image->vk.drm_format_mod)) { binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; } @@ -974,12 +976,13 @@ check_memory_bindings(const struct anv_device *device, if (plane->fast_clear_memory_range.size > 0) { enum anv_image_memory_binding binding = primary_binding; - /* Ensure that clear state is stored outside the buffer memory for any - * images externally sharable. This prevents corruptions arising due - * to disjoint processes working with the same image. + /* If an auxiliary surface is used for an externally-shareable image, + * we have to hide this from the memory of the image since other + * processes with access to the memory may not be aware of it or of + * its current state. So put that auxiliary data into a separate + * buffer (ANV_IMAGE_MEMORY_BINDING_PRIVATE). */ - if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID || - image->vk.external_handle_types != 0) { + if (anv_image_is_externally_shared(image)) { binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index e2ae3957625..89fa19b6cde 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -31,6 +31,7 @@ #include <assert.h> #include <stdint.h> #include "drm-uapi/i915_drm.h" +#include "drm-uapi/drm_fourcc.h" #ifdef HAVE_VALGRIND #include <valgrind.h> @@ -3840,6 +3841,21 @@ struct anv_image { } planes[3]; }; +static inline bool +anv_image_is_externally_shared(const struct anv_image *image) +{ + return image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID || + image->vk.external_handle_types != 0; +} + +static inline bool +anv_image_has_private_binding(const struct anv_image *image) +{ + const struct anv_image_binding private_binding = + image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE]; + return private_binding.memory_range.size != 0; +} + /* The ordering of this enum is important */ enum anv_fast_clear_type { /** Image does not have/support any fast-clear blocks */ diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 73692c12141..40ae1b75754 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -1216,13 +1216,13 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer, */ const bool private_binding_acquire = src_queue_external && - (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT || - image->vk.external_handle_types != 0); + anv_image_is_externally_shared(image) && + anv_image_has_private_binding(image); const bool private_binding_release = dst_queue_external && - (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT || - image->vk.external_handle_types != 0); + anv_image_is_externally_shared(image) && + anv_image_has_private_binding(image); if (initial_layout == final_layout && !private_binding_acquire && !private_binding_release) {
