mesa/src/broadcom/vulkan/v3dvx_descriptor_set.c
Ella Stanforth 18319a236c v3dv: add support for multi-planar formats, enable YCbCr
Original patches wrote by Ella Stanforth.

Alejandro Piñeiro main changes (skipping the small fixes/typos):
  * Reduced the list of supported formats to
    VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM and
    VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, that are the two only
    mandatory by the spec.
  * Fix format features exposed with YCbCr:
    * Disallow some features not supported with YCbCr (like blitting)
    * Disallow storage image support. Not clear if really useful. Even
      if there are CTS tests, there is an ongoing discussion about the
      possibility to remove them.
    * Expose VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT, that is
      mandatory for the formats supported.
    * Not expose VK_FORMAT_FEATURE_2_MIDPOINT_CHROMA_SAMPLES_BIT. Some
      CTS tests are failing right now, and it is not mandatory. Likely
      to be revisit later.
    * We are keeping VK_FORMAT_FEATURE_2_DISJOINT_BIT and
      VK_FORMAT_FEATURE_2_MIDPOINT_CHROMA_SAMPLES_BIT. Even if they
      are optional, it is working with the two formats that we are
      exposing. Likely that will need to be refined if we start to
      expose more formats.
  * create_image_view: don't use hardcoded 0x70, but instead doing an
    explicit bit or of VK_IMAGE_ASPECT_PLANE_0/1/2_BIT
  * image_format_plane_features: keep how supported aspects and
    separate stencil check is done. Even if the change introduced was
    correct (not sure about that though), that change is unrelated to
    this work
  * write_image_descriptor: add additional checks for descriptor type,
    to compute properly the offset.
  * Cosmetic changes (don't use // for comments, capital letters, etc)
  * Main changes coming from the review:
     * Not use image aliases. All the info is already on the image
       planes, and some points of the code were confusing as it was
       using always a hardcoded plane 0.
     * Squashed the two original main patches. YCbCr conversion was
       leaking on the multi-planar support, as some support needed
       info coming from the ycbcr structs.
     * Not expose the extension on Android, and explicitly assert that
       we expect plane_count to be 1 always.
  * For a full list of review changes  see MR#19950

Signed-off-by: Ella Stanforth <estanforth@igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19950>
2023-01-16 14:10:21 +00:00

100 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_private.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);
}