vulkan: move common format helpers to vk_format

v3dv, radv, and turnip are using several C&P format helpers (most of
them wrappers over util_format_description based helpers).  methods.

This commit moves the common helpers to the already existing common
vk_format.h. For the case of v3dv we were able to remove the vk_format
header. For turnip and radv, a local vk_format.h header remains, with
methods that are only used for those drivers.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13858>
This commit is contained in:
Alejandro Piñeiro 2021-11-18 12:16:43 +01:00
parent 04c90f292e
commit ff89dc3523
18 changed files with 80 additions and 275 deletions

View file

@ -32,12 +32,6 @@
#include <vulkan/util/vk_format.h>
#include <vulkan/vulkan.h>
static inline const struct util_format_description *
vk_format_description(VkFormat format)
{
return util_format_description(vk_format_to_pipe_format(format));
}
/**
* Return total bits needed for the pixel format per block.
*/
@ -47,27 +41,6 @@ vk_format_get_blocksizebits(VkFormat format)
return util_format_get_blocksizebits(vk_format_to_pipe_format(format));
}
/**
* Return bytes per block (not pixel) for the given format.
*/
static inline unsigned
vk_format_get_blocksize(VkFormat format)
{
return util_format_get_blocksize(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockwidth(VkFormat format)
{
return util_format_get_blockwidth(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockheight(VkFormat format)
{
return util_format_get_blockheight(vk_format_to_pipe_format(format));
}
/**
* Return the index of the first non-void channel
* -1 if no non-void channels
@ -109,48 +82,12 @@ vk_format_compose_swizzles(const VkComponentMapping *mapping, const unsigned cha
dst[3] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_A, swz, mapping->a);
}
static inline bool
vk_format_is_compressed(VkFormat format)
{
return util_format_is_compressed(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_subsampled(VkFormat format)
{
return util_format_is_subsampled_422(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_int(VkFormat format)
{
return util_format_is_pure_integer(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_uint(VkFormat format)
{
return util_format_is_pure_uint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_sint(VkFormat format)
{
return util_format_is_pure_sint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_unorm(VkFormat format)
{
return util_format_is_unorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_srgb(VkFormat format)
{
return util_format_is_srgb(vk_format_to_pipe_format(format));
}
static inline VkFormat
vk_format_no_srgb(VkFormat format)
{
@ -256,12 +193,6 @@ vk_to_non_srgb_format(VkFormat format)
}
}
static inline unsigned
vk_format_get_nr_components(VkFormat format)
{
return util_format_get_nr_components(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_plane_count(VkFormat format)
{

View file

@ -23,7 +23,6 @@
#include "v3dv_private.h"
#include "util/u_pack_color.h"
#include "vk_format_info.h"
#include "vk_util.h"
void

View file

@ -23,7 +23,6 @@
#include "v3dv_private.h"
#include "vk_util.h"
#include "vk_format_info.h"
#include "drm-uapi/drm_fourcc.h"
#include "util/format/u_format.h"

View file

@ -26,7 +26,6 @@
#include "drm-uapi/drm_fourcc.h"
#include "util/format/u_format.h"
#include "util/u_math.h"
#include "vk_format_info.h"
#include "vk_util.h"
#include "vulkan/wsi/wsi_common.h"

View file

@ -25,7 +25,6 @@
#include "v3dv_meta_common.h"
#include "compiler/nir/nir_builder.h"
#include "vk_format_info.h"
#include "util/u_pack_color.h"
static void

View file

@ -25,7 +25,6 @@
#include "v3dv_meta_common.h"
#include "compiler/nir/nir_builder.h"
#include "vk_format_info.h"
#include "util/u_pack_color.h"
#include "vulkan/runtime/vk_common_entrypoints.h"

View file

@ -26,8 +26,6 @@
#include "v3dv_debug.h"
#include "v3dv_private.h"
#include "vk_format_info.h"
#include "common/v3d_debug.h"
#include "compiler/nir/nir_builder.h"

View file

@ -37,6 +37,7 @@
#include <vk_enum_to_str.h>
#include "vk_device.h"
#include "vk_format.h"
#include "vk_instance.h"
#include "vk_image.h"
#include "vk_log.h"

View file

@ -26,7 +26,6 @@
*/
#include "v3dv_private.h"
#include "vk_format_info.h"
/* The only version specific structure that we need is
* TMU_CONFIG_PARAMETER_1. This didn't seem to change significantly from

View file

@ -26,7 +26,6 @@
#include "v3dv_private.h"
#include "drm-uapi/drm_fourcc.h"
#include "wsi_common_entrypoints.h"
#include "vk_format_info.h"
#include "vk_util.h"
#include "wsi_common.h"

View file

@ -30,8 +30,6 @@
#include "vulkan/util/vk_format.h"
#include "util/u_pack_color.h"
#include "vk_format_info.h"
void
v3dX(job_emit_binning_flush)(struct v3dv_job *job)
{

View file

@ -26,7 +26,6 @@
#include "broadcom/common/v3d_macros.h"
#include "broadcom/cle/v3dx_pack.h"
#include "broadcom/compiler/v3d_compiler.h"
#include "vk_format_info.h"
#include "util/u_pack_color.h"
#include "util/half_float.h"

View file

@ -26,8 +26,6 @@
#include "broadcom/cle/v3dx_pack.h"
#include "broadcom/compiler/v3d_compiler.h"
#include "vk_format_info.h"
/*
* This method translates pipe_swizzle to the swizzle values used at the
* packet TEXTURE_SHADER_STATE

View file

@ -29,8 +29,6 @@
#include "broadcom/cle/v3dx_pack.h"
#include "broadcom/compiler/v3d_compiler.h"
#include "vk_format_info.h"
struct rcl_clear_info {
const union v3dv_clear_value *clear_value;
struct v3dv_image *image;

View file

@ -26,8 +26,6 @@
#include "broadcom/cle/v3dx_pack.h"
#include "broadcom/compiler/v3d_compiler.h"
#include "vk_format_info.h"
static uint8_t
blend_factor(VkBlendFactor factor, bool dst_alpha_one, bool *needs_constants)
{

View file

@ -1,106 +0,0 @@
/*
* Copyright © 2016 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef VK_FORMAT_INFO_H
#define VK_FORMAT_INFO_H
#include <stdbool.h>
#include <vulkan/vulkan.h>
#include "util/format/u_format.h"
#include "vulkan/util/vk_format.h"
/* FIXME: from freedreno vk_format.h, common place?*/
static inline bool
vk_format_is_int(VkFormat format)
{
return util_format_is_pure_integer(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_sint(VkFormat format)
{
return util_format_is_pure_sint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_uint(VkFormat format)
{
return util_format_is_pure_uint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_unorm(VkFormat format)
{
return util_format_is_unorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_snorm(VkFormat format)
{
return util_format_is_snorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_float(VkFormat format)
{
return util_format_is_float(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_srgb(VkFormat format)
{
return util_format_is_srgb(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blocksize(VkFormat format)
{
return util_format_get_blocksize(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockwidth(VkFormat format)
{
return util_format_get_blockwidth(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockheight(VkFormat format)
{
return util_format_get_blockheight(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_compressed(VkFormat format)
{
return util_format_is_compressed(vk_format_to_pipe_format(format));
}
static inline const struct util_format_description *
vk_format_description(VkFormat format)
{
return util_format_description(vk_format_to_pipe_format(format));
}
#endif /* VK_FORMAT_INFO_H */

View file

@ -34,88 +34,12 @@
#include <vulkan/vulkan.h>
static inline const struct util_format_description *
vk_format_description(VkFormat format)
{
return util_format_description(vk_format_to_pipe_format(format));
}
/**
* Return bytes per block (not pixel) for the given format.
*/
static inline unsigned
vk_format_get_blocksize(VkFormat format)
{
return util_format_get_blocksize(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockwidth(VkFormat format)
{
return util_format_get_blockwidth(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockheight(VkFormat format)
{
return util_format_get_blockheight(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_compressed(VkFormat format)
{
/* this includes 4:2:2 formats, which are compressed formats for vulkan */
return vk_format_get_blockwidth(format) > 1;
}
static inline bool
vk_format_has_alpha(VkFormat format)
{
return util_format_has_alpha(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_int(VkFormat format)
{
return util_format_is_pure_integer(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_uint(VkFormat format)
{
return util_format_is_pure_uint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_sint(VkFormat format)
{
return util_format_is_pure_sint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_srgb(VkFormat format)
{
return util_format_is_srgb(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_unorm(VkFormat format)
{
return util_format_is_unorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_snorm(VkFormat format)
{
return util_format_is_snorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_float(VkFormat format)
{
return util_format_is_float(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_component_bits(VkFormat format,
enum util_format_colorspace colorspace,
@ -136,10 +60,4 @@ vk_format_get_component_bits(VkFormat format,
colorspace, component);
}
static inline unsigned
vk_format_get_nr_components(VkFormat format)
{
return util_format_get_nr_components(vk_format_to_pipe_format(format));
}
#endif /* VK_FORMAT_H */

View file

@ -91,6 +91,85 @@ vk_format_stencil_only(VkFormat format)
void vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
unsigned char out_swizzle[4]);
static inline bool
vk_format_is_int(VkFormat format)
{
return util_format_is_pure_integer(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_sint(VkFormat format)
{
return util_format_is_pure_sint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_uint(VkFormat format)
{
return util_format_is_pure_uint(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_unorm(VkFormat format)
{
return util_format_is_unorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_snorm(VkFormat format)
{
return util_format_is_snorm(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_float(VkFormat format)
{
return util_format_is_float(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_srgb(VkFormat format)
{
return util_format_is_srgb(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blocksize(VkFormat format)
{
return util_format_get_blocksize(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockwidth(VkFormat format)
{
return util_format_get_blockwidth(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_blockheight(VkFormat format)
{
return util_format_get_blockheight(vk_format_to_pipe_format(format));
}
static inline bool
vk_format_is_compressed(VkFormat format)
{
/* this includes 4:2:2 formats, which are compressed formats for vulkan */
return vk_format_get_blockwidth(format) > 1;
}
static inline const struct util_format_description *
vk_format_description(VkFormat format)
{
return util_format_description(vk_format_to_pipe_format(format));
}
static inline unsigned
vk_format_get_nr_components(VkFormat format)
{
return util_format_get_nr_components(vk_format_to_pipe_format(format));
}
#ifdef __cplusplus
}
#endif