From b06aa9824667bb9a22258c851a8d2be16cfaf96d Mon Sep 17 00:00:00 2001 From: Daivik Bhatia Date: Mon, 1 Dec 2025 04:35:36 +0530 Subject: [PATCH] v3dv: move format helpers to new v3dv format table header files. Move tfu_supports_tex_format() and get_internal_type_bpp_for_output_format() from v3dvx_private.h to v3dvx_format_table.h. Move v3dv_format_plane and v3dv_format struct from v3dv_private.h to v3dv_format_table.h. Reviewed-by: Juan A. Suarez Part-of: --- src/broadcom/vulkan/v3dv_cmd_buffer.c | 3 + src/broadcom/vulkan/v3dv_device.c | 3 + src/broadcom/vulkan/v3dv_format_table.h | 80 ++++++++++++++++++++++++ src/broadcom/vulkan/v3dv_formats.c | 3 + src/broadcom/vulkan/v3dv_image.c | 3 + src/broadcom/vulkan/v3dv_meta_clear.c | 3 + src/broadcom/vulkan/v3dv_meta_copy.c | 3 + src/broadcom/vulkan/v3dv_pass.c | 3 + src/broadcom/vulkan/v3dv_private.h | 35 +---------- src/broadcom/vulkan/v3dvx_cmd_buffer.c | 3 +- src/broadcom/vulkan/v3dvx_device.c | 4 +- src/broadcom/vulkan/v3dvx_format_table.h | 38 +++++++++++ src/broadcom/vulkan/v3dvx_formats.c | 4 +- src/broadcom/vulkan/v3dvx_image.c | 3 +- src/broadcom/vulkan/v3dvx_meta_common.c | 1 + src/broadcom/vulkan/v3dvx_pipeline.c | 3 +- src/broadcom/vulkan/v3dvx_private.h | 12 ---- 17 files changed, 149 insertions(+), 55 deletions(-) create mode 100644 src/broadcom/vulkan/v3dv_format_table.h create mode 100644 src/broadcom/vulkan/v3dvx_format_table.h diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index f33c99f0f1d..0212f4ff26a 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -28,6 +28,9 @@ #include "vk_common_entrypoints.h" #include "vk_util.h" +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + float v3dv_get_aa_line_width(struct v3dv_pipeline *pipeline, struct v3dv_cmd_buffer *buffer) diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index 8481b4f16b4..ae3be22436c 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -71,6 +71,9 @@ #include #endif +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + #define V3DV_API_VERSION VK_MAKE_VERSION(1, 3, VK_HEADER_VERSION) #ifdef ANDROID_STRICT diff --git a/src/broadcom/vulkan/v3dv_format_table.h b/src/broadcom/vulkan/v3dv_format_table.h new file mode 100644 index 00000000000..33f8ab1e06e --- /dev/null +++ b/src/broadcom/vulkan/v3dv_format_table.h @@ -0,0 +1,80 @@ +/* + * Copyright © 2025 Raspberry Pi Ltd + * + * based in part on anv driver which is: + * Copyright © 2015 Intel Corporation + * + * based in part on radv driver which is: + * Copyright © 2016 Red Hat. + * Copyright © 2016 Bas Nieuwenhuizen + * + * 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. + */ + + +#include +#include + + +#ifdef v3dX +# include "broadcom/cle/v3dx_pack.h" +#else +# define v3dX(x) v3d42_##x +# include "v3dvx_format_table.h" +# undef v3dX + +# define v3dX(x) v3d71_##x +# include "v3dvx_format_table.h" +# undef v3dX +#endif + +struct v3dv_format_plane { + /* One of V3D42_OUTPUT_IMAGE_FORMAT_*, or OUTPUT_IMAGE_FORMAT_NO */ + uint8_t rt_type; + + /* One of V3D42_TEXTURE_DATA_FORMAT_*. */ + uint8_t tex_type; + + /* Swizzle to apply to the RGBA shader output for storing to the tile + * buffer, to the RGBA tile buffer to produce shader input (for + * blending), and for turning the rgba8888 texture sampler return + * value into shader rgba values. + */ + uint8_t swizzle[4]; + + /* Whether the return value is 16F/I/UI or 32F/I/UI. */ + uint8_t return_size; + + /* Needs software unorm packing */ + bool unorm; + + /* Needs software snorm packing */ + bool snorm; +}; + +struct v3dv_format { + /* Non 0 plane count implies supported */ + uint8_t plane_count; + + struct v3dv_format_plane planes[V3DV_MAX_PLANE_COUNT]; + + /* If the format supports (linear) filtering when texturing. */ + bool supports_filtering; +}; diff --git a/src/broadcom/vulkan/v3dv_formats.c b/src/broadcom/vulkan/v3dv_formats.c index 0234d4fa918..75b38b6a9dd 100644 --- a/src/broadcom/vulkan/v3dv_formats.c +++ b/src/broadcom/vulkan/v3dv_formats.c @@ -33,6 +33,9 @@ #include +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + const uint8_t * v3dv_get_format_swizzle(struct v3dv_device *device, VkFormat f, uint8_t plane) { diff --git a/src/broadcom/vulkan/v3dv_image.c b/src/broadcom/vulkan/v3dv_image.c index d9faf761e8e..6993cf1ac71 100644 --- a/src/broadcom/vulkan/v3dv_image.c +++ b/src/broadcom/vulkan/v3dv_image.c @@ -30,6 +30,9 @@ #include "vulkan/wsi/wsi_common.h" #include "vk_android.h" +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + /** * Computes the HW's UIFblock padding for a given height/cpp. * diff --git a/src/broadcom/vulkan/v3dv_meta_clear.c b/src/broadcom/vulkan/v3dv_meta_clear.c index 3190967566a..4b785afc882 100644 --- a/src/broadcom/vulkan/v3dv_meta_clear.c +++ b/src/broadcom/vulkan/v3dv_meta_clear.c @@ -28,6 +28,9 @@ #include "util/u_pack_color.h" #include "vk_common_entrypoints.h" +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + static void get_hw_clear_color(struct v3dv_device *device, const VkClearColorValue *color, diff --git a/src/broadcom/vulkan/v3dv_meta_copy.c b/src/broadcom/vulkan/v3dv_meta_copy.c index adbb6393960..0e554df6ea3 100644 --- a/src/broadcom/vulkan/v3dv_meta_copy.c +++ b/src/broadcom/vulkan/v3dv_meta_copy.c @@ -28,6 +28,9 @@ #include "util/u_pack_color.h" #include "vk_common_entrypoints.h" +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + static uint32_t meta_blit_key_hash(const void *key) { diff --git a/src/broadcom/vulkan/v3dv_pass.c b/src/broadcom/vulkan/v3dv_pass.c index 6e2fd9898d5..b5ecaa3cfc8 100644 --- a/src/broadcom/vulkan/v3dv_pass.c +++ b/src/broadcom/vulkan/v3dv_pass.c @@ -23,6 +23,9 @@ #include "v3dv_private.h" +#define V3D_VERSION 42 +#include "v3dv_format_table.h" + static uint32_t num_subpass_attachments(const VkSubpassDescription2 *desc) { diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 62787181894..c7c23a8c734 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -116,6 +116,8 @@ struct v3dv_instance; struct v3dv_image; +struct v3dv_format_plane; +struct v3dv_format; struct v3d_simulator_file; /* Minimum required by the Vulkan 1.1 spec */ @@ -618,39 +620,6 @@ struct v3dv_device_memory { #define TEXTURE_DATA_FORMAT_NO 255 #define V3DV_MAX_PLANE_COUNT 3 -struct v3dv_format_plane { - /* One of V3D42_OUTPUT_IMAGE_FORMAT_*, or OUTPUT_IMAGE_FORMAT_NO */ - uint8_t rt_type; - - /* One of V3D42_TEXTURE_DATA_FORMAT_*. */ - uint8_t tex_type; - - /* Swizzle to apply to the RGBA shader output for storing to the tile - * buffer, to the RGBA tile buffer to produce shader input (for - * blending), and for turning the rgba8888 texture sampler return - * value into shader rgba values. - */ - uint8_t swizzle[4]; - - /* Whether the return value is 16F/I/UI or 32F/I/UI. */ - uint8_t return_size; - - /* Needs software unorm packing */ - bool unorm; - - /* Needs software snorm packing */ - bool snorm; -}; - -struct v3dv_format { - /* Non 0 plane count implies supported */ - uint8_t plane_count; - - struct v3dv_format_plane planes[V3DV_MAX_PLANE_COUNT]; - - /* If the format supports (linear) filtering when texturing. */ - bool supports_filtering; -}; /* Note that although VkImageAspectFlags would allow to combine more than one * PLANE bit, for all the use cases we implement that use VkImageAspectFlags, diff --git a/src/broadcom/vulkan/v3dvx_cmd_buffer.c b/src/broadcom/vulkan/v3dvx_cmd_buffer.c index 7bc0996a8b0..de2b20607a3 100644 --- a/src/broadcom/vulkan/v3dvx_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dvx_cmd_buffer.c @@ -22,9 +22,8 @@ */ #include "v3dv_private.h" -#include "broadcom/common/v3d_macros.h" +#include "v3dv_format_table.h" #include "broadcom/common/v3d_util.h" -#include "broadcom/cle/v3dx_pack.h" #include "broadcom/compiler/v3d_compiler.h" #include "util/half_float.h" diff --git a/src/broadcom/vulkan/v3dvx_device.c b/src/broadcom/vulkan/v3dvx_device.c index bd3477b95ab..a163f24481b 100644 --- a/src/broadcom/vulkan/v3dvx_device.c +++ b/src/broadcom/vulkan/v3dvx_device.c @@ -22,9 +22,9 @@ */ #include "v3dv_private.h" +#include "v3dv_format_table.h" +#include "v3dvx_format_table.h" -#include "broadcom/common/v3d_macros.h" -#include "broadcom/cle/v3dx_pack.h" #include "broadcom/compiler/v3d_compiler.h" #include "util/u_pack_color.h" #include "util/half_float.h" diff --git a/src/broadcom/vulkan/v3dvx_format_table.h b/src/broadcom/vulkan/v3dvx_format_table.h new file mode 100644 index 00000000000..34c11f5dcc3 --- /dev/null +++ b/src/broadcom/vulkan/v3dvx_format_table.h @@ -0,0 +1,38 @@ +/* + * Copyright © 2025 Raspberry Pi Ltd + * + * 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. + */ + +/* This file generates the per-v3d-version function prototypes. It must only + * be included from v3dv_private.h. + */ + +#include "broadcom/common/v3d_macros.h" +#include "broadcom/cle/v3dx_pack.h" + +/* FIXME: tex_format should be `enum V3DX(Texture_Data_Formats)`, but using + * that enum type in the header requires including v3dx_pack.h, which triggers + * circular include dependencies issues, so we're using a `uint32_t` for now. + */ +bool v3dX(tfu_supports_tex_format)(uint32_t tex_format); + +void v3dX(get_internal_type_bpp_for_output_format)(uint32_t format, + uint32_t *type, uint32_t *bpp); diff --git a/src/broadcom/vulkan/v3dvx_formats.c b/src/broadcom/vulkan/v3dvx_formats.c index 875025f7d18..1ad216600e0 100644 --- a/src/broadcom/vulkan/v3dvx_formats.c +++ b/src/broadcom/vulkan/v3dvx_formats.c @@ -22,8 +22,8 @@ */ #include "v3dv_private.h" -#include "broadcom/common/v3d_macros.h" -#include "broadcom/cle/v3dx_pack.h" +#include "v3dv_format_table.h" +#include "v3dvx_format_table.h" #include "util/format/u_format.h" #include "vk_enum_to_str.h" diff --git a/src/broadcom/vulkan/v3dvx_image.c b/src/broadcom/vulkan/v3dvx_image.c index de984e81220..d92272578ca 100644 --- a/src/broadcom/vulkan/v3dvx_image.c +++ b/src/broadcom/vulkan/v3dvx_image.c @@ -22,8 +22,7 @@ */ #include "v3dv_private.h" -#include "broadcom/common/v3d_macros.h" -#include "broadcom/cle/v3dx_pack.h" +#include "v3dv_format_table.h" #include "broadcom/compiler/v3d_compiler.h" /* diff --git a/src/broadcom/vulkan/v3dvx_meta_common.c b/src/broadcom/vulkan/v3dvx_meta_common.c index 321ee981da1..0190d070529 100644 --- a/src/broadcom/vulkan/v3dvx_meta_common.c +++ b/src/broadcom/vulkan/v3dvx_meta_common.c @@ -22,6 +22,7 @@ */ #include "v3dv_private.h" +#include "v3dv_format_table.h" #include "v3dv_meta_common.h" #include "broadcom/common/v3d_macros.h" diff --git a/src/broadcom/vulkan/v3dvx_pipeline.c b/src/broadcom/vulkan/v3dvx_pipeline.c index 9aba15b9139..fbbc5b6797a 100644 --- a/src/broadcom/vulkan/v3dvx_pipeline.c +++ b/src/broadcom/vulkan/v3dvx_pipeline.c @@ -22,8 +22,7 @@ */ #include "v3dv_private.h" -#include "broadcom/common/v3d_macros.h" -#include "broadcom/cle/v3dx_pack.h" +#include "v3dv_format_table.h" #include "broadcom/compiler/v3d_compiler.h" static uint8_t diff --git a/src/broadcom/vulkan/v3dvx_private.h b/src/broadcom/vulkan/v3dvx_private.h index f99163d627d..5d320bea009 100644 --- a/src/broadcom/vulkan/v3dvx_private.h +++ b/src/broadcom/vulkan/v3dvx_private.h @@ -166,24 +166,12 @@ v3dX(device_check_prepacked_sizes)(void); const struct v3dv_format * v3dX(get_format)(VkFormat); -void -v3dX(get_internal_type_bpp_for_output_format)(uint32_t format, - uint32_t *type, - uint32_t *bpp); - bool v3dX(format_supports_tlb_resolve)(const struct v3dv_format *format); bool v3dX(format_supports_blending)(const struct v3dv_format *format); -/* FIXME: tex_format should be `enum V3DX(Texture_Data_Formats)`, but using - * that enum type in the header requires including v3dx_pack.h, which triggers - * circular include dependencies issues, so we're using a `uint32_t` for now. - */ -bool -v3dX(tfu_supports_tex_format)(uint32_t tex_format); - /* Used at v3dv_image */ void