diff --git a/src/broadcom/vulkan/v3dv_descriptor_set.c b/src/broadcom/vulkan/v3dv_descriptor_set.c index beead086bdf..1d777ba08d4 100644 --- a/src/broadcom/vulkan/v3dv_descriptor_set.c +++ b/src/broadcom/vulkan/v3dv_descriptor_set.c @@ -292,7 +292,7 @@ v3dv_descriptor_map_get_texture_shader_state(struct v3dv_device *device, static void sha1_update_ycbcr_conversion(struct mesa_sha1 *ctx, - const struct vk_ycbcr_conversion *conversion) + const struct vk_ycbcr_conversion_state *conversion) { SHA1_UPDATE_VALUE(ctx, conversion->format); SHA1_UPDATE_VALUE(ctx, conversion->ycbcr_model); @@ -323,7 +323,7 @@ sha1_update_descriptor_set_binding_layout(struct mesa_sha1 *ctx, for (unsigned i = 0; i < layout->array_size; i++) { const struct v3dv_sampler *sampler = &immutable_samplers[i]; if (sampler->conversion) - sha1_update_ycbcr_conversion(ctx, sampler->conversion); + sha1_update_ycbcr_conversion(ctx, &sampler->conversion->state); } } } diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index ad082d5c714..6fedb663238 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -3060,7 +3060,7 @@ v3dv_CreateSampler(VkDevice _device, if (ycbcr_conv_info) { VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, ycbcr_conv_info->conversion); - ycbcr_info = vk_format_get_ycbcr_info(conversion->format); + ycbcr_info = vk_format_get_ycbcr_info(conversion->state.format); if (ycbcr_info) { sampler->plane_count = ycbcr_info->n_planes; sampler->conversion = conversion; diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 4f942a60450..cbffa53bfe3 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -247,7 +247,7 @@ v3dv_pipeline_get_nir_options(void) return &v3dv_nir_options; } -static const struct vk_ycbcr_conversion * +static const struct vk_ycbcr_conversion_state * lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set, uint32_t binding, uint32_t array_index) { @@ -266,7 +266,7 @@ lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set, const struct v3dv_sampler *immutable_samplers = v3dv_immutable_samplers(set_layout, bind_layout); const struct v3dv_sampler *sampler = &immutable_samplers[array_index]; - return sampler->conversion; + return sampler->conversion ? &sampler->conversion->state : NULL; } else { return NULL; } diff --git a/src/compiler/nir/nir_convert_ycbcr.c b/src/compiler/nir/nir_convert_ycbcr.c index 60027b4f1c7..14013b6bdbf 100644 --- a/src/compiler/nir/nir_convert_ycbcr.c +++ b/src/compiler/nir/nir_convert_ycbcr.c @@ -148,7 +148,7 @@ struct ycbcr_state { nir_ssa_def *image_size; nir_tex_instr *origin_tex; nir_deref_instr *tex_deref; - const struct vk_ycbcr_conversion *conversion; + const struct vk_ycbcr_conversion_state *conversion; const struct vk_format_ycbcr_info *format_ycbcr_info; }; @@ -202,7 +202,7 @@ implicit_downsampled_coords(struct ycbcr_state *state, const struct vk_format_ycbcr_plane *format_plane) { nir_builder *b = state->builder; - const struct vk_ycbcr_conversion *conversion = state->conversion; + const struct vk_ycbcr_conversion_state *conversion = state->conversion; nir_ssa_def *image_size = get_texture_size(state, state->tex_deref); nir_ssa_def *comp[4] = { NULL, }; int c; @@ -231,7 +231,7 @@ create_plane_tex_instr_implicit(struct ycbcr_state *state, uint32_t plane) { nir_builder *b = state->builder; - const struct vk_ycbcr_conversion *conversion = state->conversion; + const struct vk_ycbcr_conversion_state *conversion = state->conversion; const struct vk_format_ycbcr_plane *format_plane = &state->format_ycbcr_info->planes[plane]; nir_tex_instr *old_tex = state->origin_tex; @@ -337,7 +337,7 @@ lower_ycbcr_tex_instr(nir_builder *b, nir_instr *instr, void *_state) array_index = nir_src_as_uint(deref->arr.index); } - const struct vk_ycbcr_conversion *conversion = + const struct vk_ycbcr_conversion_state *conversion = state->cb(state->cb_data, set, binding, array_index); if (conversion == NULL) return false; diff --git a/src/compiler/nir/nir_vulkan.h b/src/compiler/nir/nir_vulkan.h index 06c1e174602..0d84a7a2938 100644 --- a/src/compiler/nir/nir_vulkan.h +++ b/src/compiler/nir/nir_vulkan.h @@ -41,7 +41,7 @@ nir_convert_ycbcr_to_rgb(nir_builder *b, struct vk_ycbcr_conversion; -typedef const struct vk_ycbcr_conversion * +typedef const struct vk_ycbcr_conversion_state * (*nir_vk_ycbcr_conversion_lookup_cb)(const void *data, uint32_t set, uint32_t binding, uint32_t array_index); diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 0cda5122586..4926c58fd36 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -2541,7 +2541,7 @@ anv_CreateImageView(VkDevice _device, if (conv_info) { VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, conv_info->conversion); - conv_format = conversion->format; + conv_format = conversion->state.format; } #ifdef ANDROID diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 75f82de9132..5677c725945 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -772,7 +772,7 @@ anv_pipeline_stage_get_nir(struct anv_pipeline *pipeline, return NULL; } -static const struct vk_ycbcr_conversion * +static const struct vk_ycbcr_conversion_state * lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set, uint32_t binding, uint32_t array_index) { @@ -791,7 +791,7 @@ lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set, const struct anv_sampler *sampler = bind_layout->immutable_samplers[array_index]; - return sampler ? sampler->conversion : NULL; + return sampler && sampler->conversion ? &sampler->conversion->state : NULL; } static void diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c index e0e24c4afc5..f8305deb52b 100644 --- a/src/intel/vulkan/genX_state.c +++ b/src/intel/vulkan/genX_state.c @@ -852,7 +852,7 @@ VkResult genX(CreateSampler)( if (conversion == NULL) break; - ycbcr_info = vk_format_get_ycbcr_info(conversion->format); + ycbcr_info = vk_format_get_ycbcr_info(conversion->state.format); if (ycbcr_info == NULL) break; @@ -926,16 +926,16 @@ VkResult genX(CreateSampler)( const bool plane_has_chroma = ycbcr_info && ycbcr_info->planes[p].has_chroma; const VkFilter min_filter = - plane_has_chroma ? sampler->conversion->chroma_filter : pCreateInfo->minFilter; + plane_has_chroma ? sampler->conversion->state.chroma_filter : pCreateInfo->minFilter; const VkFilter mag_filter = - plane_has_chroma ? sampler->conversion->chroma_filter : pCreateInfo->magFilter; + plane_has_chroma ? sampler->conversion->state.chroma_filter : pCreateInfo->magFilter; const bool enable_min_filter_addr_rounding = min_filter != VK_FILTER_NEAREST; const bool enable_mag_filter_addr_rounding = mag_filter != VK_FILTER_NEAREST; /* From Broadwell PRM, SAMPLER_STATE: * "Mip Mode Filter must be set to MIPFILTER_NONE for Planar YUV surfaces." */ enum isl_format plane0_isl_format = sampler->conversion ? - anv_get_format(sampler->conversion->format)->planes[0].isl_format : + anv_get_format(sampler->conversion->state.format)->planes[0].isl_format : ISL_FORMAT_UNSUPPORTED; const bool isl_format_is_planar_yuv = plane0_isl_format != ISL_FORMAT_UNSUPPORTED && diff --git a/src/vulkan/runtime/vk_ycbcr_conversion.c b/src/vulkan/runtime/vk_ycbcr_conversion.c index e461a597fa7..9c1da39c357 100644 --- a/src/vulkan/runtime/vk_ycbcr_conversion.c +++ b/src/vulkan/runtime/vk_ycbcr_conversion.c @@ -46,9 +46,11 @@ vk_common_CreateSamplerYcbcrConversion(VkDevice _device, if (!conversion) return VK_ERROR_OUT_OF_HOST_MEMORY; - conversion->format = pCreateInfo->format; - conversion->ycbcr_model = pCreateInfo->ycbcrModel; - conversion->ycbcr_range = pCreateInfo->ycbcrRange; + struct vk_ycbcr_conversion_state *state = &conversion->state; + + state->format = pCreateInfo->format; + state->ycbcr_model = pCreateInfo->ycbcrModel; + state->ycbcr_range = pCreateInfo->ycbcrRange; /* Search for VkExternalFormatANDROID and resolve the format. */ const VkExternalFormatANDROID *android_ext_info = @@ -57,25 +59,25 @@ vk_common_CreateSamplerYcbcrConversion(VkDevice _device, /* We assume that Android externalFormat is just a VkFormat */ if (android_ext_info && android_ext_info->externalFormat) { assert(pCreateInfo->format == VK_FORMAT_UNDEFINED); - conversion->format = android_ext_info->externalFormat; + state->format = android_ext_info->externalFormat; } else { /* The Vulkan 1.1.95 spec says: * * "When creating an external format conversion, the value of * components if ignored." */ - conversion->mapping[0] = pCreateInfo->components.r; - conversion->mapping[1] = pCreateInfo->components.g; - conversion->mapping[2] = pCreateInfo->components.b; - conversion->mapping[3] = pCreateInfo->components.a; + state->mapping[0] = pCreateInfo->components.r; + state->mapping[1] = pCreateInfo->components.g; + state->mapping[2] = pCreateInfo->components.b; + state->mapping[3] = pCreateInfo->components.a; } - conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset; - conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset; - conversion->chroma_filter = pCreateInfo->chromaFilter; + state->chroma_offsets[0] = pCreateInfo->xChromaOffset; + state->chroma_offsets[1] = pCreateInfo->yChromaOffset; + state->chroma_filter = pCreateInfo->chromaFilter; const struct vk_format_ycbcr_info *ycbcr_info = - vk_format_get_ycbcr_info(conversion->format); + vk_format_get_ycbcr_info(state->format); bool has_chroma_subsampled = false; if (ycbcr_info) { @@ -86,9 +88,9 @@ vk_common_CreateSamplerYcbcrConversion(VkDevice _device, has_chroma_subsampled = true; } } - conversion->chroma_reconstruction = has_chroma_subsampled && - (conversion->chroma_offsets[0] == VK_CHROMA_LOCATION_COSITED_EVEN || - conversion->chroma_offsets[1] == VK_CHROMA_LOCATION_COSITED_EVEN); + state->chroma_reconstruction = has_chroma_subsampled && + (state->chroma_offsets[0] == VK_CHROMA_LOCATION_COSITED_EVEN || + state->chroma_offsets[1] == VK_CHROMA_LOCATION_COSITED_EVEN); *pYcbcrConversion = vk_ycbcr_conversion_to_handle(conversion); diff --git a/src/vulkan/runtime/vk_ycbcr_conversion.h b/src/vulkan/runtime/vk_ycbcr_conversion.h index c16a5c4cc1a..cc4ed3eb22b 100644 --- a/src/vulkan/runtime/vk_ycbcr_conversion.h +++ b/src/vulkan/runtime/vk_ycbcr_conversion.h @@ -29,9 +29,7 @@ extern "C" { #endif -struct vk_ycbcr_conversion { - struct vk_object_base base; - +struct vk_ycbcr_conversion_state { VkFormat format; VkSamplerYcbcrModelConversion ycbcr_model; VkSamplerYcbcrRange ycbcr_range; @@ -41,6 +39,11 @@ struct vk_ycbcr_conversion { bool chroma_reconstruction; }; +struct vk_ycbcr_conversion { + struct vk_object_base base; + struct vk_ycbcr_conversion_state state; +}; + VK_DEFINE_NONDISP_HANDLE_CASTS(vk_ycbcr_conversion, base, VkSamplerYcbcrConversion, VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION)