tu: Switch to vk_ycbcr_conversion

Drop tu_sampler_ycbcr_conversion in favor of the common vk_ycbcr_conversion.
This allows using CreateSamplerYcbcrConversion and DestroySamplerYcbcrConversion
from the common runtime and will be required for vk_sampler and for using the
common ycbcr lowering later.

Signed-off-by: Valentine Burley <valentine.burley@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29808>
This commit is contained in:
Valentine Burley 2024-05-25 21:05:38 +00:00 committed by Marge Bot
parent ee751a26fc
commit 75a6d185a0
7 changed files with 27 additions and 78 deletions

View file

@ -178,7 +178,6 @@ struct tu_query_pool;
struct tu_queue;
struct tu_render_pass;
struct tu_sampler;
struct tu_sampler_ycbcr_conversion;
struct breadcrumbs_context;
struct tu_bo;

View file

@ -159,7 +159,7 @@ tu_CreateDescriptorSetLayout(
* but using struct tu_sampler makes things simpler */
uint32_t size = samplers_offset +
immutable_sampler_count * sizeof(struct tu_sampler) +
ycbcr_sampler_count * sizeof(struct tu_sampler_ycbcr_conversion);
ycbcr_sampler_count * sizeof(struct vk_ycbcr_conversion);
set_layout =
(struct tu_descriptor_set_layout *) vk_descriptor_set_layout_zalloc(
@ -173,8 +173,8 @@ tu_CreateDescriptorSetLayout(
/* We just allocate all the immutable samplers at the end of the struct */
struct tu_sampler *samplers =
(struct tu_sampler *) &set_layout->binding[num_bindings];
struct tu_sampler_ycbcr_conversion *ycbcr_samplers =
(struct tu_sampler_ycbcr_conversion *) &samplers[immutable_sampler_count];
struct vk_ycbcr_conversion_state *ycbcr_samplers =
(struct vk_ycbcr_conversion_state *) &samplers[immutable_sampler_count];
VkDescriptorSetLayoutBinding *bindings = NULL;
VkResult result = vk_create_sorted_bindings(
@ -252,7 +252,7 @@ tu_CreateDescriptorSetLayout(
for (uint32_t i = 0; i < binding->descriptorCount; i++) {
struct tu_sampler *sampler = tu_sampler_from_handle(binding->pImmutableSamplers[i]);
if (sampler->ycbcr_sampler)
ycbcr_samplers[i] = *sampler->ycbcr_sampler;
ycbcr_samplers[i] = sampler->ycbcr_sampler->state;
else
ycbcr_samplers[i].ycbcr_model = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
}
@ -445,7 +445,7 @@ tu_GetDescriptorSetLayoutBindingOffsetEXT(
static void
sha1_update_ycbcr_sampler(struct mesa_sha1 *ctx,
const struct tu_sampler_ycbcr_conversion *sampler)
const struct vk_ycbcr_conversion_state *sampler)
{
SHA1_UPDATE_VALUE(ctx, sampler->ycbcr_model);
SHA1_UPDATE_VALUE(ctx, sampler->ycbcr_range);
@ -464,7 +464,7 @@ sha1_update_descriptor_set_binding_layout(struct mesa_sha1 *ctx,
SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_offset);
SHA1_UPDATE_VALUE(ctx, layout->immutable_samplers_offset);
const struct tu_sampler_ycbcr_conversion *ycbcr_samplers =
const struct vk_ycbcr_conversion_state *ycbcr_samplers =
tu_immutable_ycbcr_samplers(set_layout, layout);
if (ycbcr_samplers) {
@ -1653,47 +1653,3 @@ tu_UpdateDescriptorSetWithTemplate(
tu_update_descriptor_set_with_template(device, set, descriptorUpdateTemplate, pData);
}
VKAPI_ATTR VkResult VKAPI_CALL
tu_CreateSamplerYcbcrConversion(
VkDevice _device,
const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSamplerYcbcrConversion *pYcbcrConversion)
{
VK_FROM_HANDLE(tu_device, device, _device);
struct tu_sampler_ycbcr_conversion *conversion;
conversion = (struct tu_sampler_ycbcr_conversion *) vk_object_alloc(
&device->vk, pAllocator, sizeof(*conversion),
VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION);
if (!conversion)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
conversion->format =
vk_select_android_external_format(pCreateInfo->pNext, pCreateInfo->format);
conversion->ycbcr_model = pCreateInfo->ycbcrModel;
conversion->ycbcr_range = pCreateInfo->ycbcrRange;
conversion->components = pCreateInfo->components;
conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset;
conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset;
conversion->chroma_filter = pCreateInfo->chromaFilter;
*pYcbcrConversion = tu_sampler_ycbcr_conversion_to_handle(conversion);
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL
tu_DestroySamplerYcbcrConversion(VkDevice _device,
VkSamplerYcbcrConversion ycbcrConversion,
const VkAllocationCallbacks *pAllocator)
{
VK_FROM_HANDLE(tu_device, device, _device);
VK_FROM_HANDLE(tu_sampler_ycbcr_conversion, ycbcr_conversion, ycbcrConversion);
if (!ycbcr_conversion)
return;
vk_object_free(&device->vk, pAllocator, ycbcr_conversion);
}

View file

@ -198,19 +198,6 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template, base,
VkDescriptorUpdateTemplate,
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
struct tu_sampler_ycbcr_conversion {
struct vk_object_base base;
VkFormat format;
VkSamplerYcbcrModelConversion ycbcr_model;
VkSamplerYcbcrRange ycbcr_range;
VkComponentMapping components;
VkChromaLocation chroma_offsets[2];
VkFilter chroma_filter;
};
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler_ycbcr_conversion, base, VkSamplerYcbcrConversion,
VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION)
void
tu_update_descriptor_sets(const struct tu_device *device,
VkDescriptorSet overrideSet,
@ -234,7 +221,7 @@ tu_immutable_samplers(const struct tu_descriptor_set_layout *set,
binding->immutable_samplers_offset);
}
static inline const struct tu_sampler_ycbcr_conversion *
static inline const struct vk_ycbcr_conversion_state *
tu_immutable_ycbcr_samplers(const struct tu_descriptor_set_layout *set,
const struct tu_descriptor_set_binding_layout *binding)
{
@ -242,8 +229,8 @@ tu_immutable_ycbcr_samplers(const struct tu_descriptor_set_layout *set,
return NULL;
return (
struct tu_sampler_ycbcr_conversion *) ((const char *) set +
binding->ycbcr_samplers_offset);
struct vk_ycbcr_conversion_state *) ((const char *) set +
binding->ycbcr_samplers_offset);
}
#endif /* TU_DESCRIPTOR_SET_H */

View file

@ -3273,10 +3273,10 @@ tu_init_sampler(struct tu_device *device,
}
sampler->ycbcr_sampler = ycbcr_conversion ?
tu_sampler_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
vk_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
if (sampler->ycbcr_sampler &&
sampler->ycbcr_sampler->chroma_filter == VK_FILTER_LINEAR) {
sampler->ycbcr_sampler->state.chroma_filter == VK_FILTER_LINEAR) {
sampler->descriptor[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR;
}

View file

@ -14,6 +14,7 @@
#include "vk_buffer.h"
#include "vk_device_memory.h"
#include "vk_ycbcr_conversion.h"
#include "tu_autotune.h"
#include "tu_pass.h"
@ -481,7 +482,7 @@ struct tu_sampler {
struct vk_object_base base;
uint32_t descriptor[A6XX_TEX_SAMP_DWORDS];
struct tu_sampler_ycbcr_conversion *ycbcr_sampler;
struct vk_ycbcr_conversion *ycbcr_sampler;
};
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler, base, VkSampler,
VK_OBJECT_TYPE_SAMPLER)

View file

@ -187,8 +187,8 @@ tu_image_view_init(struct tu_device *device,
const struct VkSamplerYcbcrConversionInfo *ycbcr_conversion =
vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO);
const struct tu_sampler_ycbcr_conversion *conversion = ycbcr_conversion ?
tu_sampler_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
const struct vk_ycbcr_conversion *conversion = ycbcr_conversion ?
vk_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
vk_image_view_init(&device->vk, &iview->vk, false, pCreateInfo);
@ -240,8 +240,14 @@ tu_image_view_init(struct tu_device *device,
if (conversion) {
unsigned char conversion_swiz[4], create_swiz[4];
memcpy(create_swiz, args.swiz, sizeof(create_swiz));
vk_component_mapping_to_pipe_swizzle(conversion->components,
conversion_swiz);
VkComponentMapping component = {
.r = conversion->state.mapping[0],
.g = conversion->state.mapping[1],
.b = conversion->state.mapping[2],
.a = conversion->state.mapping[3]
};
vk_component_mapping_to_pipe_swizzle(component, conversion_swiz);
util_format_compose_swizzles(create_swiz, conversion_swiz, args.swiz);
}
@ -268,8 +274,8 @@ tu_image_view_init(struct tu_device *device,
STATIC_ASSERT((unsigned)VK_CHROMA_LOCATION_COSITED_EVEN == (unsigned)FDL_CHROMA_LOCATION_COSITED_EVEN);
STATIC_ASSERT((unsigned)VK_CHROMA_LOCATION_MIDPOINT == (unsigned)FDL_CHROMA_LOCATION_MIDPOINT);
if (conversion) {
args.chroma_offsets[0] = (enum fdl_chroma_location) conversion->chroma_offsets[0];
args.chroma_offsets[1] = (enum fdl_chroma_location) conversion->chroma_offsets[1];
args.chroma_offsets[0] = (enum fdl_chroma_location) conversion->state.chroma_offsets[0];
args.chroma_offsets[1] = (enum fdl_chroma_location) conversion->state.chroma_offsets[1];
}
fdl6_view_init(&iview->view, layouts, &args, has_z24uint_s8uint);

View file

@ -509,7 +509,7 @@ lower_tex_ycbcr(const struct tu_pipeline_layout *layout,
layout->set[var->data.descriptor_set].layout;
const struct tu_descriptor_set_binding_layout *binding =
&set_layout->binding[var->data.binding];
const struct tu_sampler_ycbcr_conversion *ycbcr_samplers =
const struct vk_ycbcr_conversion_state *ycbcr_samplers =
tu_immutable_ycbcr_samplers(set_layout, binding);
if (!ycbcr_samplers)
@ -530,7 +530,7 @@ lower_tex_ycbcr(const struct tu_pipeline_layout *layout,
array_index = nir_src_as_uint(deref->arr.index);
array_index = MIN2(array_index, binding->array_size - 1);
}
const struct tu_sampler_ycbcr_conversion *ycbcr_sampler = ycbcr_samplers + array_index;
const struct vk_ycbcr_conversion_state *ycbcr_sampler = ycbcr_samplers + array_index;
if (ycbcr_sampler->ycbcr_model == VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY)
return;