17ec681f3Smrg/* 27ec681f3Smrg * Copyright 2018 Collabora Ltd. 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom 97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#ifndef ZINK_COMPILER_H 257ec681f3Smrg#define ZINK_COMPILER_H 267ec681f3Smrg 277ec681f3Smrg#include "pipe/p_defines.h" 287ec681f3Smrg#include "pipe/p_state.h" 297ec681f3Smrg 307ec681f3Smrg#include "compiler/nir/nir.h" 317ec681f3Smrg#include "compiler/shader_info.h" 327ec681f3Smrg#include "util/u_live_shader_cache.h" 337ec681f3Smrg 347ec681f3Smrg#include <vulkan/vulkan.h> 357ec681f3Smrg#include "zink_descriptors.h" 367ec681f3Smrg 377ec681f3Smrg#define ZINK_WORKGROUP_SIZE_X 1 387ec681f3Smrg#define ZINK_WORKGROUP_SIZE_Y 2 397ec681f3Smrg#define ZINK_WORKGROUP_SIZE_Z 3 407ec681f3Smrg 417ec681f3Smrgstruct pipe_screen; 427ec681f3Smrgstruct zink_context; 437ec681f3Smrgstruct zink_screen; 447ec681f3Smrgstruct zink_shader_key; 457ec681f3Smrgstruct zink_shader_module; 467ec681f3Smrgstruct zink_gfx_program; 477ec681f3Smrg 487ec681f3Smrgstruct nir_shader_compiler_options; 497ec681f3Smrgstruct nir_shader; 507ec681f3Smrg 517ec681f3Smrgstruct set; 527ec681f3Smrg 537ec681f3Smrgstruct tgsi_token; 547ec681f3Smrgstruct zink_so_info { 557ec681f3Smrg struct pipe_stream_output_info so_info; 567ec681f3Smrg unsigned so_info_slots[PIPE_MAX_SO_OUTPUTS]; 577ec681f3Smrg bool have_xfb; 587ec681f3Smrg}; 597ec681f3Smrg 607ec681f3Smrg 617ec681f3Smrgconst void * 627ec681f3Smrgzink_get_compiler_options(struct pipe_screen *screen, 637ec681f3Smrg enum pipe_shader_ir ir, 647ec681f3Smrg enum pipe_shader_type shader); 657ec681f3Smrg 667ec681f3Smrgstruct nir_shader * 677ec681f3Smrgzink_tgsi_to_nir(struct pipe_screen *screen, const struct tgsi_token *tokens); 687ec681f3Smrg 697ec681f3Smrgstruct zink_shader { 707ec681f3Smrg struct util_live_shader base; 717ec681f3Smrg uint32_t hash; 727ec681f3Smrg struct nir_shader *nir; 737ec681f3Smrg enum pipe_prim_type reduced_prim; // PIPE_PRIM_MAX for vs 747ec681f3Smrg 757ec681f3Smrg struct zink_so_info streamout; 767ec681f3Smrg 777ec681f3Smrg struct { 787ec681f3Smrg int index; 797ec681f3Smrg int binding; 807ec681f3Smrg VkDescriptorType type; 817ec681f3Smrg unsigned char size; 827ec681f3Smrg } bindings[ZINK_DESCRIPTOR_TYPES][ZINK_MAX_DESCRIPTORS_PER_TYPE]; 837ec681f3Smrg size_t num_bindings[ZINK_DESCRIPTOR_TYPES]; 847ec681f3Smrg unsigned num_texel_buffers; 857ec681f3Smrg uint32_t ubos_used; // bitfield of which ubo indices are used 867ec681f3Smrg uint32_t ssbos_used; // bitfield of which ssbo indices are used 877ec681f3Smrg bool bindless; 887ec681f3Smrg 897ec681f3Smrg simple_mtx_t lock; 907ec681f3Smrg struct set *programs; 917ec681f3Smrg 927ec681f3Smrg union { 937ec681f3Smrg struct zink_shader *generated; // a generated shader that this shader "owns" 947ec681f3Smrg bool is_generated; // if this is a driver-created shader (e.g., tcs) 957ec681f3Smrg nir_variable *fbfetch; //for fs output 967ec681f3Smrg }; 977ec681f3Smrg}; 987ec681f3Smrg 997ec681f3Smrgvoid 1007ec681f3Smrgzink_screen_init_compiler(struct zink_screen *screen); 1017ec681f3Smrgvoid 1027ec681f3Smrgzink_compiler_assign_io(nir_shader *producer, nir_shader *consumer); 1037ec681f3SmrgVkShaderModule 1047ec681f3Smrgzink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, nir_shader *nir, const struct zink_shader_key *key); 1057ec681f3Smrg 1067ec681f3Smrgstruct zink_shader * 1077ec681f3Smrgzink_shader_create(struct zink_screen *screen, struct nir_shader *nir, 1087ec681f3Smrg const struct pipe_stream_output_info *so_info); 1097ec681f3Smrg 1107ec681f3Smrgchar * 1117ec681f3Smrgzink_shader_finalize(struct pipe_screen *pscreen, void *nirptr); 1127ec681f3Smrg 1137ec681f3Smrgvoid 1147ec681f3Smrgzink_shader_free(struct zink_context *ctx, struct zink_shader *shader); 1157ec681f3Smrg 1167ec681f3Smrgstruct zink_shader * 1177ec681f3Smrgzink_shader_tcs_create(struct zink_screen *screen, struct zink_shader *vs, unsigned vertices_per_patch); 1187ec681f3Smrg 1197ec681f3Smrgstatic inline bool 1207ec681f3Smrgzink_shader_descriptor_is_buffer(struct zink_shader *zs, enum zink_descriptor_type type, unsigned i) 1217ec681f3Smrg{ 1227ec681f3Smrg return zs->bindings[type][i].type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER || 1237ec681f3Smrg zs->bindings[type][i].type == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; 1247ec681f3Smrg} 1257ec681f3Smrg 1267ec681f3Smrg#endif 127