summaryrefslogtreecommitdiff
path: root/src/intel/vulkan
diff options
context:
space:
mode:
authorJason Ekstrand <jason@jlekstrand.net>2021-03-30 23:18:41 -0500
committerMarge Bot <emma+marge@anholt.net>2023-01-16 14:10:21 +0000
commit30a91d333d1e253c221835879f245574d48de2f8 (patch)
tree75b2f1ebd4ca5983f67d9d36a8adf89012f78053 /src/intel/vulkan
parent1cc342f5e1754e7e9b1ed8685aa73520b2122e62 (diff)
anv: Use the common vk_ycbcr_conversion object
Acked-by: Alejandro PiƱeiro <apinheiro@igalia.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19950>
Diffstat (limited to 'src/intel/vulkan')
-rw-r--r--src/intel/vulkan/anv_formats.c73
-rw-r--r--src/intel/vulkan/anv_image.c6
-rw-r--r--src/intel/vulkan/anv_nir_lower_ycbcr_textures.c10
-rw-r--r--src/intel/vulkan/anv_private.h18
-rw-r--r--src/intel/vulkan/genX_state.c25
5 files changed, 27 insertions, 105 deletions
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index efe85db2b93..cf0f437c3a2 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -1659,76 +1659,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);
-}
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index a6950d13cfe..f02f467d77f 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -2515,7 +2515,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);
@@ -2528,7 +2528,7 @@ anv_CreateImageView(VkDevice _device,
#endif
if (conv_info) {
- ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion, conv_info->conversion);
+ VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, conv_info->conversion);
conv_format = conversion->format;
}
@@ -2542,7 +2542,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.
diff --git a/src/intel/vulkan/anv_nir_lower_ycbcr_textures.c b/src/intel/vulkan/anv_nir_lower_ycbcr_textures.c
index e82cd032e20..4e073e44704 100644
--- a/src/intel/vulkan/anv_nir_lower_ycbcr_textures.c
+++ b/src/intel/vulkan/anv_nir_lower_ycbcr_textures.c
@@ -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,7 +85,7 @@ 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;
@@ -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->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);
@@ -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->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)
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 5e3ed13d4b2..aaf54e46b2d 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -88,6 +88,7 @@
#include "vk_util.h"
#include "vk_queue.h"
#include "vk_log.h"
+#include "vk_ycbcr_conversion.h"
#ifdef __cplusplus
extern "C" {
@@ -4024,24 +4025,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.
@@ -4230,9 +4219,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)
diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c
index ae9ec5b5ca5..da25a2ad99e 100644
--- a/src/intel/vulkan/genX_state.c
+++ b/src/intel/vulkan/genX_state.c
@@ -42,6 +42,7 @@
#endif
#include "vk_util.h"
+#include "vk_format.h"
static void
genX(emit_slice_hashing_state)(struct anv_device *device,
@@ -834,23 +835,28 @@ VkResult genX(CreateSampler)(
unsigned sampler_reduction_mode = STD_FILTER;
bool enable_sampler_reduction = false;
+ 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->format);
+ if (ycbcr_info == NULL)
+ break;
+
+ sampler->n_planes = ycbcr_info->n_planes;
sampler->conversion = conversion;
break;
}
@@ -918,7 +924,7 @@ 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;
const VkFilter mag_filter =
@@ -928,9 +934,12 @@ VkResult genX(CreateSampler)(
/* 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->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 ?