mesa/src/broadcom/vulkan/v3dvx_descriptor_set.c
Alejandro Piñeiro 70728fce57 v3dv: split v3dv_private.h into smaller headers
Split the monolithic v3dv_private.h (~2600 lines) into self-contained
sub-headers so each .c file only includes what it needs:

  v3dv_common.h, v3dv_device.h, v3dv_image.h, v3dv_pass.h,
  v3dv_query.h, v3dv_pipeline.h, v3dv_descriptor_set.h,
  v3dv_cmd_buffer.h, v3dv_version_dispatch.h

As part of this commit we remove v3dv_private.h.

We keep v3dvx_private.h as it is, because the gain would be really
small (a lot of really small sub-headers).

In addition to keep things more tidy, we made a quick performance
check. We measured how many files are re-compiled and the performance
difference when touching one of the headers, compared with keeping
just one monolithic header.

  Header touch (incremental)    Split        Monolithic  Speedup
  --------------------------    -----        ----------  -------
  v3dv_image.h                 2369 (24f)    2436 (33f)    1.03x
  v3dv_query.h                 2357 (20f)    2436 (33f)    1.03x
  v3dv_pass.h                  2352 (20f)    2436 (33f)    1.04x
  v3dv_cmd_buffer.h            2354 (20f)    2436 (33f)    1.03x
  v3dv_descriptor_set.h        2436 (33f)    2436 (33f)    1.00x
  v3dv_pipeline.h              2437 (33f)    2436 (33f)    1.00x
  v3dv_device.h                2418 (31f)    2436 (33f)    1.01x
  v3dv_common.h                2419 (33f)    2436 (33f)    1.01x
  v3dv_version_dispatch.h      2371 (26f)    2436 (33f)    1.03x

  Header touch (incremental)   Split         Monolithic  Speedup
  --------------------------   ----------    ----------  -------
  v3dv_image.h                 2377 (24f)    2443 (33f)    1.03x
  v3dv_query.h                 2346 (20f)    2443 (33f)    1.04x
  v3dv_pass.h                  2360 (20f)    2443 (33f)    1.04x
  v3dv_cmd_buffer.h            2351 (20f)    2443 (33f)    1.04x
  v3dv_descriptor_set.h        2438 (33f)    2443 (33f)    1.00x
  v3dv_pipeline.h              2429 (33f)    2443 (33f)    1.01x
  v3dv_device.h                2418 (31f)    2443 (33f)    1.01x
  v3dv_common.h                2432 (33f)    2443 (33f)    1.00x
  v3dv_version_dispatch.h      2373 (26f)    2443 (33f)    1.03x

The bigger gain is on the files recompiled for some headers (going
from 33 down to 20 in some cases). The performance gain is not so
relevant though.

Acked-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40169>
2026-03-25 02:04:57 +00:00

102 lines
3.5 KiB
C

/*
* Copyright © 2021 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.
*/
#include "v3dv_device.h"
#include "v3dv_image.h"
#include "v3dv_version_dispatch.h"
#include "broadcom/common/v3d_macros.h"
#include "broadcom/cle/v3dx_pack.h"
#include "broadcom/compiler/v3d_compiler.h"
/*
* Returns how much space a given descriptor type needs on a bo (GPU
* memory).
*/
uint32_t
v3dX(descriptor_bo_size)(VkDescriptorType type)
{
switch(type) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
return cl_aligned_packet_length(SAMPLER_STATE, 32);
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
return cl_aligned_packet_length(SAMPLER_STATE, 32) +
cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
default:
return 0;
}
}
/* To compute the max_bo_size we want to iterate through the descriptor
* types. Unfortunately we can't just use the descriptor type enum values, as
* the values are not defined consecutively (so extensions could add new
* descriptor types), and VK_DESCRIPTOR_TYPE_MAX_ENUM is also a really big
* number.
*/
static const uint32_t supported_descriptor_types[] = {
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,
VK_DESCRIPTOR_TYPE_SAMPLER,
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
};
uint32_t
v3dX(max_descriptor_bo_size)(void)
{
static uint32_t max = 0;
if (max == 0) {
for (uint32_t i = 0; i < ARRAY_SIZE(supported_descriptor_types); i++)
max = MAX2(max, v3dX(descriptor_bo_size)(supported_descriptor_types[i]));
}
assert(max != 0);
return max;
}
uint32_t
v3dX(combined_image_sampler_texture_state_offset)(uint8_t plane)
{
return v3dX(descriptor_bo_size)(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) *
plane;
}
uint32_t
v3dX(combined_image_sampler_sampler_state_offset)(uint8_t plane)
{
return v3dX(combined_image_sampler_texture_state_offset)(plane) +
cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
}