anv: implement VK_EXT_image_compression_control

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 <lionel.g.landwerlin@intel.com>
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28632>
This commit is contained in:
Lionel Landwerlin 2024-04-08 16:33:29 +03:00 committed by Marge Bot
parent db6ee2e1bb
commit c94cd1235f
6 changed files with 61 additions and 5 deletions

View File

@ -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(

View File

@ -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 :

View File

@ -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(

View File

@ -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,

View File

@ -1262,6 +1262,10 @@ TODO: document the other workarounds.
<option name="anv_disable_fcv" value="true" />
<option name="anv_assume_full_subgroups" value="16" />
</engine>
<!-- We trust vkd3d to not disable compression all the time. -->
<engine engine_name_match="vkd3d">
<option name="compression_control_enabled" value="true" />
</engine>
</device>
<device driver="dzn">
<application name="DOOMEternal" executable="DOOMEternalx64vk.exe">

View File

@ -787,6 +787,9 @@
#define DRI_CONF_ANV_EXTERNAL_MEMORY_IMPLICIT_SYNC(def) \
DRI_CONF_OPT_B(anv_external_memory_implicit_sync, def, "Implicit sync on external BOs")
#define DRI_CONF_ANV_COMPRESSION_CONTROL_ENABLED(def) \
DRI_CONF_OPT_B(compression_control_enabled, def, "Enable VK_EXT_image_compression_control support")
/**
* \brief HASVK specific configuration options
*/