Path: blob/21.2-virgl/src/broadcom/vulkan/v3dvx_descriptor_set.c
4560 views
/*1* Copyright © 2021 Raspberry Pi2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "v3dv_private.h"24#include "broadcom/common/v3d_macros.h"25#include "broadcom/cle/v3dx_pack.h"26#include "broadcom/compiler/v3d_compiler.h"2728/*29* Returns how much space a given descriptor type needs on a bo (GPU30* memory).31*/32uint32_t33v3dX(descriptor_bo_size)(VkDescriptorType type)34{35switch(type) {36case VK_DESCRIPTOR_TYPE_SAMPLER:37return cl_aligned_packet_length(SAMPLER_STATE, 32);38case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:39return cl_aligned_packet_length(SAMPLER_STATE, 32) +40cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);41case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:42case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:43case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:44case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:45case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:46return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);47default:48return 0;49}50}5152/* To compute the max_bo_size we want to iterate through the descriptor53* types. Unfourtunately we can't just use the descriptor type enum values, as54* the values are not defined consecutively (so extensions could add new55* descriptor types), and VK_DESCRIPTOR_TYPE_MAX_ENUM is also a really big56* number.57*/58static const uint32_t supported_descriptor_types[] = {59VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,60VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,61VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,62VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,63VK_DESCRIPTOR_TYPE_SAMPLER,64VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,65VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,66VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,67VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,68VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,69VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,70};7172uint32_t73v3dX(max_descriptor_bo_size)(void)74{75static uint32_t max = 0;7677if (max == 0) {78for (uint32_t i = 0; i < ARRAY_SIZE(supported_descriptor_types); i++)79max = MAX2(max, v3dX(descriptor_bo_size)(supported_descriptor_types[i]));80}81assert(max != 0);8283return max;84}858687uint32_t88v3dX(combined_image_sampler_texture_state_offset)(void)89{90return 0;91}9293uint32_t94v3dX(combined_image_sampler_sampler_state_offset)(void)95{96return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);97}9899100