From c94cd1235f436098d3b0a27ad5d13b9d3ac830c3 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 8 Apr 2024 16:33:29 +0300 Subject: [PATCH] anv: implement VK_EXT_image_compression_control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Limited to vkd3d right now, there are specific use cases there. We don't want any app to disable compression, it should be mostly transparent and we better be aware of potential bugs. Signed-off-by: Lionel Landwerlin Reviewed-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_device.c | 7 +++++++ src/intel/vulkan/anv_formats.c | 22 +++++++++++++++++++++- src/intel/vulkan/anv_image.c | 26 +++++++++++++++++++++++--- src/intel/vulkan/anv_private.h | 4 +++- src/util/00-mesa-defaults.conf | 4 ++++ src/util/driconf.h | 3 +++ 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 426cf5238239e..b5c2ac427fc2a 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -91,6 +91,7 @@ static const driOptionDescription anv_dri_options[] = { DRI_CONF_ANV_FORCE_INDIRECT_DESCRIPTORS(false) DRI_CONF_SHADER_SPILLING_RATE(0) DRI_CONF_OPT_B(intel_tbimr, true, "Enable TBIMR tiled rendering") + DRI_CONF_ANV_COMPRESSION_CONTROL_ENABLED(false) DRI_CONF_SECTION_END DRI_CONF_SECTION_DEBUG @@ -362,6 +363,7 @@ get_device_extensions(const struct anv_physical_device *device, .EXT_graphics_pipeline_library = !debug_get_bool_option("ANV_NO_GPL", false), .EXT_host_query_reset = true, .EXT_image_2d_view_of_3d = true, + .EXT_image_compression_control = device->instance->compression_control_enabled, .EXT_image_robustness = true, .EXT_image_drm_format_modifier = true, .EXT_image_sliced_view_of_3d = true, @@ -923,6 +925,9 @@ get_features(const struct anv_physical_device *pdevice, /* VK_EXT_swapchain_maintenance1 */ .swapchainMaintenance1 = true, #endif + + /* VK_EXT_image_compression_control */ + .imageCompressionControl = true, }; /* The new DOOM and Wolfenstein games require depthBounds without @@ -2628,6 +2633,8 @@ anv_init_dri_options(struct anv_instance *instance) driQueryOptionb(&instance->dri_options, "anv_disable_fcv"); instance->external_memory_implicit_sync = driQueryOptionb(&instance->dri_options, "anv_external_memory_implicit_sync"); + instance->compression_control_enabled = + driQueryOptionb(&instance->dri_options, "compression_control_enabled"); } VkResult anv_CreateInstance( diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index a72297dc3dbaa..1d285e3891d74 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -1285,6 +1285,7 @@ anv_get_image_format_properties( VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL; VkAndroidHardwareBufferUsageANDROID *android_usage = NULL; VkTextureLODGatherFormatPropertiesAMD *texture_lod_gather_props = NULL; + VkImageCompressionPropertiesEXT *comp_props = NULL; bool from_wsi = false; /* Extract input structs */ @@ -1308,6 +1309,9 @@ anv_get_image_format_properties( case VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR: /* Ignore but don't warn */ break; + case VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT: + /* Ignore but don't warn */ + break; default: anv_debug_ignored_stype(s->sType); break; @@ -1329,6 +1333,9 @@ anv_get_image_format_properties( case VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD: texture_lod_gather_props = (void *) s; break; + case VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_PROPERTIES_EXT: + comp_props = (void *) s; + break; default: anv_debug_ignored_stype(s->sType); break; @@ -1744,6 +1751,18 @@ anv_get_image_format_properties( } } + if (comp_props) { + bool ccs_supported = + anv_formats_ccs_e_compatible(devinfo, info->flags, info->format, + info->tiling, info->usage, + format_list_info); + comp_props->imageCompressionFixedRateFlags = + VK_IMAGE_COMPRESSION_FIXED_RATE_NONE_EXT; + comp_props->imageCompressionFlags = ccs_supported ? + VK_IMAGE_COMPRESSION_DEFAULT_EXT : + VK_IMAGE_COMPRESSION_DISABLED_EXT; + } + return VK_SUCCESS; unsupported: @@ -1845,7 +1864,8 @@ void anv_GetPhysicalDeviceSparseImageFormatProperties2( isl_surf_usage_flags_t isl_usage = anv_image_choose_isl_surf_usage(physical_device, vk_create_flags, pFormatInfo->usage, - 0, aspect); + 0, aspect, + VK_IMAGE_COMPRESSION_DEFAULT_EXT); const enum isl_surf_dim isl_surf_dim = pFormatInfo->type == VK_IMAGE_TYPE_1D ? ISL_SURF_DIM_1D : diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 82d72e698266f..a7dd949c5358e 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -207,7 +207,8 @@ anv_image_choose_isl_surf_usage(struct anv_physical_device *device, VkImageCreateFlags vk_create_flags, VkImageUsageFlags vk_usage, isl_surf_usage_flags_t isl_extra_usage, - VkImageAspectFlagBits aspect) + VkImageAspectFlagBits aspect, + VkImageCompressionFlagsEXT comp_flags) { isl_surf_usage_flags_t isl_usage = isl_extra_usage; @@ -283,6 +284,9 @@ anv_image_choose_isl_surf_usage(struct anv_physical_device *device, isl_usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT; } + if (comp_flags & VK_IMAGE_COMPRESSION_DISABLED_EXT) + isl_usage |= ISL_SURF_USAGE_DISABLE_AUX_BIT; + return isl_usage; } @@ -1324,7 +1328,8 @@ add_all_surfaces_implicit_layout( isl_surf_usage_flags_t isl_usage = anv_image_choose_isl_surf_usage(device->physical, image->vk.create_flags, vk_usage, - isl_extra_usage_flags, aspect); + isl_extra_usage_flags, aspect, + image->vk.compr_flags); result = add_primary_surface(device, image, plane, plane_format, ANV_OFFSET_IMPLICIT, plane_stride, @@ -1722,7 +1727,8 @@ anv_image_init(struct anv_device *device, struct anv_image *image, isl_surf_usage_flags_t isl_usage = anv_image_choose_isl_surf_usage( device->physical, image->vk.create_flags, image->vk.usage, - isl_extra_usage_flags, VK_IMAGE_ASPECT_COLOR_BIT); + isl_extra_usage_flags, VK_IMAGE_ASPECT_COLOR_BIT, + image->vk.compr_flags); r = add_primary_surface(device, image, plane, plane_format, ANV_OFFSET_IMPLICIT, 0, @@ -2646,6 +2652,20 @@ anv_get_image_subresource_layout(const struct anv_image *image, } else { layout->subresourceLayout.size = mem_range->size; } + + VkImageCompressionPropertiesEXT *comp_props = + vk_find_struct(layout->pNext, IMAGE_COMPRESSION_PROPERTIES_EXT); + if (comp_props) { + comp_props->imageCompressionFixedRateFlags = + VK_IMAGE_COMPRESSION_FIXED_RATE_NONE_EXT; + comp_props->imageCompressionFlags = VK_IMAGE_COMPRESSION_DISABLED_EXT; + for (uint32_t p = 0; p < image->n_planes; p++) { + if (image->planes[p].aux_usage != ISL_AUX_USAGE_NONE) { + comp_props->imageCompressionFlags = VK_IMAGE_COMPRESSION_DEFAULT_EXT; + break; + } + } + } } void anv_GetDeviceImageSubresourceLayoutKHR( diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index e22dbb65c74ce..6c4ad4b317474 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1270,6 +1270,7 @@ struct anv_instance { unsigned force_vk_vendor; bool has_fake_sparse; bool disable_fcv; + bool compression_control_enabled; /* HW workarounds */ bool no_16bit; @@ -5491,7 +5492,8 @@ anv_image_choose_isl_surf_usage(struct anv_physical_device *device, VkImageCreateFlags vk_create_flags, VkImageUsageFlags vk_usage, isl_surf_usage_flags_t isl_extra_usage, - VkImageAspectFlagBits aspect); + VkImageAspectFlagBits aspect, + VkImageCompressionFlagsEXT comp_flags); void anv_cmd_buffer_fill_area(struct anv_cmd_buffer *cmd_buffer, diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index 1c74695d88089..fc95b9fedbad3 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -1262,6 +1262,10 @@ TODO: document the other workarounds.