hasvk: Use the common vk_ycbcr_conversion object

Based on commit 30a91d333d ("anv: Use the common vk_ycbcr_conversion
object").

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22619>
This commit is contained in:
Chia-I Wu 2023-04-20 22:07:05 -07:00 committed by Marge Bot
parent cb6d655f53
commit 0a4c92b646
5 changed files with 38 additions and 116 deletions

View file

@ -1660,76 +1660,3 @@ void anv_GetPhysicalDeviceExternalBufferProperties(
.compatibleHandleTypes = pExternalBufferInfo->handleType,
};
}
VkResult anv_CreateSamplerYcbcrConversion(
VkDevice _device,
const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSamplerYcbcrConversion* pYcbcrConversion)
{
ANV_FROM_HANDLE(anv_device, device, _device);
struct anv_ycbcr_conversion *conversion;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO);
conversion = vk_object_zalloc(&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 = anv_get_format(pCreateInfo->format);
conversion->ycbcr_model = pCreateInfo->ycbcrModel;
conversion->ycbcr_range = pCreateInfo->ycbcrRange;
/* Search for VkExternalFormatANDROID and resolve the format. */
const VkExternalFormatANDROID *ext_info =
vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_FORMAT_ANDROID);
if (ext_info && ext_info->externalFormat) {
assert(pCreateInfo->format == VK_FORMAT_UNDEFINED);
conversion->format = anv_get_format(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;
}
conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset;
conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset;
conversion->chroma_filter = pCreateInfo->chromaFilter;
bool has_chroma_subsampled = false;
for (uint32_t p = 0; p < conversion->format->n_planes; p++) {
if (conversion->format->planes[p].has_chroma &&
(conversion->format->planes[p].denominator_scales[0] > 1 ||
conversion->format->planes[p].denominator_scales[1] > 1))
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);
*pYcbcrConversion = anv_ycbcr_conversion_to_handle(conversion);
return VK_SUCCESS;
}
void anv_DestroySamplerYcbcrConversion(
VkDevice _device,
VkSamplerYcbcrConversion YcbcrConversion,
const VkAllocationCallbacks* pAllocator)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion, YcbcrConversion);
if (!conversion)
return;
vk_object_free(&device->vk, pAllocator, conversion);
}

View file

@ -2405,7 +2405,7 @@ anv_CreateImageView(VkDevice _device,
iview->n_planes = anv_image_aspect_get_planes(iview->vk.aspects);
/* Check if a conversion info was passed. */
const struct anv_format *conv_format = NULL;
VkFormat conv_format = VK_FORMAT_UNDEFINED;
const VkSamplerYcbcrConversionInfo *conv_info =
vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO);
@ -2418,8 +2418,8 @@ anv_CreateImageView(VkDevice _device,
#endif
if (conv_info) {
ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion, conv_info->conversion);
conv_format = conversion->format;
VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, conv_info->conversion);
conv_format = conversion->state.format;
}
#ifdef ANDROID
@ -2432,7 +2432,7 @@ anv_CreateImageView(VkDevice _device,
* view format from the passed conversion info.
*/
if (iview->vk.view_format == VK_FORMAT_UNDEFINED && conv_format)
iview->vk.view_format = conv_format->vk_format;
iview->vk.view_format = conv_format;
/* Now go through the underlying image selected planes and map them to
* planes in the image view.

View file

@ -32,7 +32,7 @@ struct ycbcr_state {
nir_ssa_def *image_size;
nir_tex_instr *origin_tex;
nir_deref_instr *tex_deref;
struct anv_ycbcr_conversion *conversion;
const struct vk_ycbcr_conversion *conversion;
};
/* TODO: we should probably replace this with a push constant/uniform. */
@ -85,14 +85,14 @@ implicit_downsampled_coords(struct ycbcr_state *state,
const struct anv_format_plane *plane_format)
{
nir_builder *b = state->builder;
struct anv_ycbcr_conversion *conversion = state->conversion;
const struct vk_ycbcr_conversion *conversion = state->conversion;
nir_ssa_def *image_size = get_texture_size(state, state->tex_deref);
nir_ssa_def *comp[4] = { NULL, };
int c;
for (c = 0; c < ARRAY_SIZE(conversion->chroma_offsets); c++) {
for (c = 0; c < ARRAY_SIZE(conversion->state.chroma_offsets); c++) {
if (plane_format->denominator_scales[c] > 1 &&
conversion->chroma_offsets[c] == VK_CHROMA_LOCATION_COSITED_EVEN) {
conversion->state.chroma_offsets[c] == VK_CHROMA_LOCATION_COSITED_EVEN) {
comp[c] = implicit_downsampled_coord(b,
nir_channel(b, old_coords, c),
nir_channel(b, image_size, c),
@ -114,9 +114,9 @@ create_plane_tex_instr_implicit(struct ycbcr_state *state,
uint32_t plane)
{
nir_builder *b = state->builder;
struct anv_ycbcr_conversion *conversion = state->conversion;
const struct vk_ycbcr_conversion *conversion = state->conversion;
const struct anv_format_plane *plane_format =
&conversion->format->planes[plane];
&anv_get_format(conversion->state.format)->planes[plane];
nir_tex_instr *old_tex = state->origin_tex;
nir_tex_instr *tex = nir_tex_instr_create(b->shader, old_tex->num_srcs + 1);
@ -125,7 +125,7 @@ create_plane_tex_instr_implicit(struct ycbcr_state *state,
switch (old_tex->src[i].src_type) {
case nir_tex_src_coord:
if (plane_format->has_chroma && conversion->chroma_reconstruction) {
if (plane_format->has_chroma && conversion->state.chroma_reconstruction) {
assert(old_tex->src[i].src.is_ssa);
tex->src[i].src =
nir_src_for_ssa(implicit_downsampled_coords(state,
@ -254,7 +254,7 @@ anv_nir_lower_ycbcr_textures_instr(nir_builder *builder,
builder->cursor = nir_before_instr(&tex->instr);
const struct anv_format *format = state.conversion->format;
const struct anv_format *format = anv_get_format(state.conversion->state.format);
const struct isl_format_layout *y_isl_layout = NULL;
for (uint32_t p = 0; p < format->n_planes; p++) {
if (!format->planes[p].has_chroma)
@ -301,7 +301,7 @@ anv_nir_lower_ycbcr_textures_instr(nir_builder *builder,
nir_ssa_def *swizzled_comp[4] = { NULL, };
uint32_t swizzled_bpcs[4] = { 0, };
for (uint32_t i = 0; i < ARRAY_SIZE(state.conversion->mapping); i++) {
for (uint32_t i = 0; i < ARRAY_SIZE(state.conversion->state.mapping); i++) {
/* Maps to components in |ycbcr_comp| */
static const uint32_t swizzle_mapping[] = {
[VK_COMPONENT_SWIZZLE_ZERO] = 4,
@ -311,7 +311,7 @@ anv_nir_lower_ycbcr_textures_instr(nir_builder *builder,
[VK_COMPONENT_SWIZZLE_B] = 2,
[VK_COMPONENT_SWIZZLE_A] = 3,
};
const VkComponentSwizzle m = state.conversion->mapping[i];
const VkComponentSwizzle m = state.conversion->state.mapping[i];
if (m == VK_COMPONENT_SWIZZLE_IDENTITY) {
swizzled_comp[i] = ycbcr_comp[i];
@ -323,10 +323,10 @@ anv_nir_lower_ycbcr_textures_instr(nir_builder *builder,
}
nir_ssa_def *result = nir_vec(builder, swizzled_comp, 4);
if (state.conversion->ycbcr_model != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY) {
if (state.conversion->state.ycbcr_model != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY) {
result = nir_convert_ycbcr_to_rgb(builder,
state.conversion->ycbcr_model,
state.conversion->ycbcr_range,
state.conversion->state.ycbcr_model,
state.conversion->state.ycbcr_range,
result,
swizzled_bpcs);
}

View file

@ -88,6 +88,7 @@
#include "vk_util.h"
#include "vk_queue.h"
#include "vk_log.h"
#include "vk_ycbcr_conversion.h"
/* Pre-declarations needed for WSI entrypoints */
struct wl_surface;
@ -3702,24 +3703,12 @@ struct gfx8_border_color {
uint32_t _pad[12];
};
struct anv_ycbcr_conversion {
struct vk_object_base base;
const struct anv_format * format;
VkSamplerYcbcrModelConversion ycbcr_model;
VkSamplerYcbcrRange ycbcr_range;
VkComponentSwizzle mapping[4];
VkChromaLocation chroma_offsets[2];
VkFilter chroma_filter;
bool chroma_reconstruction;
};
struct anv_sampler {
struct vk_object_base base;
uint32_t state[3][4];
uint32_t n_planes;
struct anv_ycbcr_conversion *conversion;
struct vk_ycbcr_conversion *conversion;
/* Blob of sampler state data which is guaranteed to be 32-byte aligned
* and with a 32-byte stride for use as bindless samplers.
@ -3886,9 +3875,6 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, base, VkQueryPool,
VK_OBJECT_TYPE_QUERY_POOL)
VK_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, base, VkSampler,
VK_OBJECT_TYPE_SAMPLER)
VK_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion, base,
VkSamplerYcbcrConversion,
VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION)
VK_DEFINE_NONDISP_HANDLE_CASTS(anv_performance_configuration_intel, base,
VkPerformanceConfigurationINTEL,
VK_OBJECT_TYPE_PERFORMANCE_CONFIGURATION_INTEL)

View file

@ -37,6 +37,7 @@
#include "vk_standard_sample_locations.h"
#include "vk_util.h"
#include "vk_format.h"
static VkResult
init_render_queue_state(struct anv_queue *queue)
@ -439,23 +440,28 @@ VkResult genX(CreateSampler)(
border_color_offset = sampler->custom_border_color.offset;
}
const struct vk_format_ycbcr_info *ycbcr_info = NULL;
vk_foreach_struct_const(ext, pCreateInfo->pNext) {
switch (ext->sType) {
case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO: {
VkSamplerYcbcrConversionInfo *pSamplerConversion =
(VkSamplerYcbcrConversionInfo *) ext;
ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion,
pSamplerConversion->conversion);
VK_FROM_HANDLE(vk_ycbcr_conversion, conversion,
pSamplerConversion->conversion);
/* Ignore conversion for non-YUV formats. This fulfills a requirement
* for clients that want to utilize same code path for images with
* external formats (VK_FORMAT_UNDEFINED) and "regular" RGBA images
* where format is known.
*/
if (conversion == NULL || !conversion->format->can_ycbcr)
if (conversion == NULL)
break;
sampler->n_planes = conversion->format->n_planes;
ycbcr_info = vk_format_get_ycbcr_info(conversion->state.format);
if (ycbcr_info == NULL)
break;
sampler->n_planes = ycbcr_info->n_planes;
sampler->conversion = conversion;
break;
}
@ -517,19 +523,22 @@ VkResult genX(CreateSampler)(
for (unsigned p = 0; p < sampler->n_planes; p++) {
const bool plane_has_chroma =
sampler->conversion && sampler->conversion->format->planes[p].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."
*/
const bool isl_format_is_planar_yuv = sampler->conversion &&
isl_format_is_yuv(sampler->conversion->format->planes[0].isl_format) &&
isl_format_is_planar(sampler->conversion->format->planes[0].isl_format);
enum isl_format plane0_isl_format = sampler->conversion ?
anv_get_format(sampler->conversion->state.format)->planes[0].isl_format :
ISL_FORMAT_UNSUPPORTED;
const bool isl_format_is_planar_yuv =
isl_format_is_yuv(plane0_isl_format) &&
isl_format_is_planar(plane0_isl_format);
const uint32_t mip_filter_mode =
isl_format_is_planar_yuv ?