Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_descriptors.h
4570 views
/*1* Copyright © 2020 Mike Blumenkrantz2*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*22* Authors:23* Mike Blumenkrantz <[email protected]>24*/2526#ifndef ZINK_DESCRIPTOR_H27# define ZINK_DESCRIPTOR_H28#include <vulkan/vulkan.h>29#include "util/u_dynarray.h"30#include "util/u_inlines.h"31#include "util/simple_mtx.h"3233#include "zink_batch.h"34#ifdef __cplusplus35extern "C" {36#endif3738#ifndef ZINK_SHADER_COUNT39#define ZINK_SHADER_COUNT (PIPE_SHADER_TYPES - 1)40#endif4142enum zink_descriptor_type {43ZINK_DESCRIPTOR_TYPE_UBO,44ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW,45ZINK_DESCRIPTOR_TYPE_SSBO,46ZINK_DESCRIPTOR_TYPE_IMAGE,47ZINK_DESCRIPTOR_TYPES,48};4950#define ZINK_MAX_DESCRIPTORS_PER_TYPE 325152struct zink_descriptor_refs {53struct util_dynarray refs;54};555657/* hashes of all the named types in a given state */58struct zink_descriptor_state {59bool valid[ZINK_DESCRIPTOR_TYPES];60uint32_t state[ZINK_DESCRIPTOR_TYPES];61};6263enum zink_descriptor_size_index {64ZDS_INDEX_UBO,65ZDS_INDEX_COMBINED_SAMPLER,66ZDS_INDEX_UNIFORM_TEXELS,67ZDS_INDEX_STORAGE_BUFFER,68ZDS_INDEX_STORAGE_IMAGE,69ZDS_INDEX_STORAGE_TEXELS,70};7172struct hash_table;7374struct zink_context;75struct zink_image_view;76struct zink_program;77struct zink_resource;78struct zink_sampler;79struct zink_sampler_view;80struct zink_shader;81struct zink_screen;828384struct zink_descriptor_state_key {85bool exists[ZINK_SHADER_COUNT];86uint32_t state[ZINK_SHADER_COUNT];87};8889struct zink_descriptor_layout_key {90unsigned num_descriptors;91VkDescriptorSetLayoutBinding *bindings;92unsigned use_count;93};9495struct zink_descriptor_layout {96VkDescriptorSetLayout layout;97VkDescriptorUpdateTemplateKHR desc_template;98};99100struct zink_descriptor_pool_key {101struct zink_descriptor_layout_key *layout;102unsigned num_type_sizes;103VkDescriptorPoolSize *sizes;104};105106struct zink_descriptor_reference {107void **ref;108bool *invalid;109};110111112struct zink_descriptor_data {113struct zink_descriptor_state gfx_descriptor_states[ZINK_SHADER_COUNT]; // keep incremental hashes here114struct zink_descriptor_state descriptor_states[2]; // gfx, compute115struct hash_table *descriptor_pools[ZINK_DESCRIPTOR_TYPES];116117struct zink_descriptor_layout_key *push_layout_keys[2]; //gfx, compute118struct zink_descriptor_pool *push_pool[2]; //gfx, compute119struct zink_descriptor_layout *push_dsl[2]; //gfx, compute120uint8_t last_push_usage[2];121bool push_valid[2];122uint32_t push_state[2];123bool gfx_push_valid[ZINK_SHADER_COUNT];124uint32_t gfx_push_state[ZINK_SHADER_COUNT];125struct zink_descriptor_set *last_set[2];126127VkDescriptorPool dummy_pool;128struct zink_descriptor_layout *dummy_dsl;129VkDescriptorSet dummy_set;130131bool changed[2][ZINK_DESCRIPTOR_TYPES + 1];132struct zink_program *pg[2]; //gfx, compute133};134135struct zink_program_descriptor_data {136uint8_t push_usage;137VkDescriptorPoolSize sizes[6]; //zink_descriptor_size_index138struct zink_descriptor_layout_key *layout_key[ZINK_DESCRIPTOR_TYPES]; //push set doesn't need one139uint8_t binding_usage;140struct zink_descriptor_layout *layouts[ZINK_DESCRIPTOR_TYPES + 1];141VkDescriptorUpdateTemplateKHR push_template;142};143144struct zink_batch_descriptor_data {145struct set *desc_sets;146};147148static inline enum zink_descriptor_size_index149zink_vktype_to_size_idx(VkDescriptorType type)150{151switch (type) {152case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:153case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:154return ZDS_INDEX_UBO;155case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:156return ZDS_INDEX_COMBINED_SAMPLER;157case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:158return ZDS_INDEX_UNIFORM_TEXELS;159case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:160return ZDS_INDEX_STORAGE_BUFFER;161case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:162return ZDS_INDEX_STORAGE_IMAGE;163case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:164return ZDS_INDEX_STORAGE_TEXELS;165default: break;166}167unreachable("unknown type");168}169170static inline enum zink_descriptor_size_index171zink_descriptor_type_to_size_idx(enum zink_descriptor_type type)172{173switch (type) {174case ZINK_DESCRIPTOR_TYPE_UBO:175return ZDS_INDEX_UBO;176case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:177return ZDS_INDEX_COMBINED_SAMPLER;178case ZINK_DESCRIPTOR_TYPE_SSBO:179return ZDS_INDEX_STORAGE_BUFFER;180case ZINK_DESCRIPTOR_TYPE_IMAGE:181return ZDS_INDEX_STORAGE_IMAGE;182default: break;183}184unreachable("unknown type");185}186unsigned187zink_descriptor_program_num_sizes(struct zink_program *pg, enum zink_descriptor_type type);188bool189zink_descriptor_layouts_init(struct zink_context *ctx);190191void192zink_descriptor_layouts_deinit(struct zink_context *ctx);193194uint32_t195zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);196uint32_t197zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);198bool199zink_descriptor_util_alloc_sets(struct zink_screen *screen, VkDescriptorSetLayout dsl, VkDescriptorPool pool, VkDescriptorSet *sets, unsigned num_sets);200struct zink_descriptor_layout *201zink_descriptor_util_layout_get(struct zink_context *ctx, enum zink_descriptor_type type,202VkDescriptorSetLayoutBinding *bindings, unsigned num_bindings,203struct zink_descriptor_layout_key **layout_key);204bool205zink_descriptor_util_push_layouts_get(struct zink_context *ctx, struct zink_descriptor_layout **dsls, struct zink_descriptor_layout_key **layout_keys);206void207zink_descriptor_util_init_null_set(struct zink_context *ctx, VkDescriptorSet desc_set);208struct zink_resource *209zink_get_resource_for_descriptor(struct zink_context *ctx, enum zink_descriptor_type type, enum pipe_shader_type shader, int idx);210VkImageLayout211zink_descriptor_util_image_layout_eval(const struct zink_resource *res, bool is_compute);212213/* these two can't be called in lazy mode */214void215zink_descriptor_set_refs_clear(struct zink_descriptor_refs *refs, void *ptr);216void217zink_descriptor_set_recycle(struct zink_descriptor_set *zds);218219220221222223bool224zink_descriptor_program_init(struct zink_context *ctx, struct zink_program *pg);225226void227zink_descriptor_program_deinit(struct zink_screen *screen, struct zink_program *pg);228229void230zink_descriptors_update(struct zink_context *ctx, bool is_compute);231232233void234zink_context_invalidate_descriptor_state(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);235236uint32_t237zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);238uint32_t239zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);240struct zink_resource *241zink_get_resource_for_descriptor(struct zink_context *ctx, enum zink_descriptor_type type, enum pipe_shader_type shader, int idx);242243void244zink_batch_descriptor_deinit(struct zink_screen *screen, struct zink_batch_state *bs);245void246zink_batch_descriptor_reset(struct zink_screen *screen, struct zink_batch_state *bs);247bool248zink_batch_descriptor_init(struct zink_screen *screen, struct zink_batch_state *bs);249250bool251zink_descriptors_init(struct zink_context *ctx);252253void254zink_descriptors_deinit(struct zink_context *ctx);255256//LAZY257bool258zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program *pg);259260void261zink_descriptor_program_deinit_lazy(struct zink_screen *screen, struct zink_program *pg);262263void264zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute);265266267void268zink_context_invalidate_descriptor_state_lazy(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);269270void271zink_batch_descriptor_deinit_lazy(struct zink_screen *screen, struct zink_batch_state *bs);272void273zink_batch_descriptor_reset_lazy(struct zink_screen *screen, struct zink_batch_state *bs);274bool275zink_batch_descriptor_init_lazy(struct zink_screen *screen, struct zink_batch_state *bs);276277bool278zink_descriptors_init_lazy(struct zink_context *ctx);279280void281zink_descriptors_deinit_lazy(struct zink_context *ctx);282283void284zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, VkDescriptorSet set);285#ifdef __cplusplus286}287#endif288289#endif290291292