Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_program.h
4570 views
/*1* Copyright 2018 Collabora Ltd.2*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* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the 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 NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef ZINK_PROGRAM_H24#define ZINK_PROGRAM_H2526#include <vulkan/vulkan.h>2728#include "compiler/shader_enums.h"29#include "pipe/p_state.h"30#include "util/u_inlines.h"3132#include "zink_context.h"33#include "zink_compiler.h"34#include "zink_shader_keys.h"35#ifdef __cplusplus36extern "C" {37#endif3839struct zink_screen;40struct zink_shader;41struct zink_gfx_pipeline_state;42struct zink_descriptor_set;4344struct hash_table;45struct set;46struct util_dynarray;4748struct zink_program;4950struct zink_gfx_push_constant {51unsigned draw_mode_is_indexed;52unsigned draw_id;53float default_inner_level[2];54float default_outer_level[4];55};5657struct zink_cs_push_constant {58unsigned work_dim;59};6061/* a shader module is used for directly reusing a shader module between programs,62* e.g., in the case where we're swapping out only one shader,63* allowing us to skip going through shader keys64*/65struct zink_shader_module {66VkShaderModule shader;67bool default_variant;68};6970struct zink_program {71struct pipe_reference reference;72unsigned char sha1[20];73struct util_queue_fence cache_fence;74VkPipelineCache pipeline_cache;75size_t pipeline_cache_size;76struct zink_batch_usage *batch_uses;77bool is_compute;7879struct zink_program_descriptor_data *dd;8081VkPipelineLayout layout;82VkDescriptorSetLayout dsl[ZINK_DESCRIPTOR_TYPES + 1]; // one for each type + push83unsigned num_dsl;8485/* the shader cache stores a mapping of zink_shader_key::VkShaderModule */86struct hash_table shader_cache[ZINK_SHADER_COUNT];87};8889struct zink_gfx_program {90struct zink_program base;9192uint32_t stages_present; //mask of stages present in this program93struct nir_shader *nir[ZINK_SHADER_COUNT];9495struct zink_shader_module *modules[ZINK_SHADER_COUNT]; // compute stage doesn't belong here9697struct zink_shader_module *default_variants[ZINK_SHADER_COUNT][2]; //[default, no streamout]98const void *default_variant_key[ZINK_SHADER_COUNT];99struct zink_shader *last_vertex_stage;100101struct zink_shader *shaders[ZINK_SHADER_COUNT];102struct hash_table *pipelines[11]; // number of draw modes we support103uint32_t default_variant_hash;104};105106struct zink_compute_program {107struct zink_program base;108109struct zink_shader_module *module;110struct zink_shader *shader;111struct hash_table *pipelines;112};113114static inline enum zink_descriptor_type115zink_desc_type_from_vktype(VkDescriptorType type)116{117switch (type) {118case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:119case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:120return ZINK_DESCRIPTOR_TYPE_UBO;121case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:122case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:123return ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW;124case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:125return ZINK_DESCRIPTOR_TYPE_SSBO;126case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:127case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:128return ZINK_DESCRIPTOR_TYPE_IMAGE;129default:130unreachable("unhandled descriptor type");131}132}133134void135zink_delete_shader_state(struct pipe_context *pctx, void *cso);136void *137zink_create_gfx_shader_state(struct pipe_context *pctx, const struct pipe_shader_state *shader);138139unsigned140zink_program_num_bindings_typed(const struct zink_program *pg, enum zink_descriptor_type type, bool is_compute);141142unsigned143zink_program_num_bindings(const struct zink_program *pg, bool is_compute);144145bool146zink_program_descriptor_is_buffer(struct zink_context *ctx, enum pipe_shader_type stage, enum zink_descriptor_type type, unsigned i);147148void149zink_update_gfx_program(struct zink_context *ctx, struct zink_gfx_program *prog);150151struct zink_gfx_program *152zink_create_gfx_program(struct zink_context *ctx,153struct zink_shader *stages[ZINK_SHADER_COUNT]);154155void156zink_destroy_gfx_program(struct zink_screen *screen,157struct zink_gfx_program *prog);158159VkPipeline160zink_get_gfx_pipeline(struct zink_context *ctx,161struct zink_gfx_program *prog,162struct zink_gfx_pipeline_state *state,163enum pipe_prim_type mode);164165void166zink_program_init(struct zink_context *ctx);167168uint32_t169zink_program_get_descriptor_usage(struct zink_context *ctx, enum pipe_shader_type stage, enum zink_descriptor_type type);170171void172debug_describe_zink_gfx_program(char* buf, const struct zink_gfx_program *ptr);173174static inline bool175zink_gfx_program_reference(struct zink_screen *screen,176struct zink_gfx_program **dst,177struct zink_gfx_program *src)178{179struct zink_gfx_program *old_dst = dst ? *dst : NULL;180bool ret = false;181182if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL, &src->base.reference,183(debug_reference_descriptor)debug_describe_zink_gfx_program)) {184zink_destroy_gfx_program(screen, old_dst);185ret = true;186}187if (dst) *dst = src;188return ret;189}190191struct zink_compute_program *192zink_create_compute_program(struct zink_context *ctx, struct zink_shader *shader);193void194zink_destroy_compute_program(struct zink_screen *screen,195struct zink_compute_program *comp);196197void198debug_describe_zink_compute_program(char* buf, const struct zink_compute_program *ptr);199200static inline bool201zink_compute_program_reference(struct zink_screen *screen,202struct zink_compute_program **dst,203struct zink_compute_program *src)204{205struct zink_compute_program *old_dst = dst ? *dst : NULL;206bool ret = false;207208if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL, &src->base.reference,209(debug_reference_descriptor)debug_describe_zink_compute_program)) {210zink_destroy_compute_program(screen, old_dst);211ret = true;212}213if (dst) *dst = src;214return ret;215}216217VkPipelineLayout218zink_pipeline_layout_create(struct zink_screen *screen, struct zink_program *pg);219220void221zink_program_update_compute_pipeline_state(struct zink_context *ctx, struct zink_compute_program *comp, const uint block[3]);222223VkPipeline224zink_get_compute_pipeline(struct zink_screen *screen,225struct zink_compute_program *comp,226struct zink_compute_pipeline_state *state);227228static inline bool229zink_program_has_descriptors(const struct zink_program *pg)230{231return pg->num_dsl > 0;232}233#ifdef __cplusplus234}235#endif236237#endif238239240