• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Collabora Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef ZINK_COMPILER_H
25 #define ZINK_COMPILER_H
26 
27 #include "pipe/p_defines.h"
28 #include "pipe/p_state.h"
29 
30 #include "compiler/nir/nir.h"
31 #include "compiler/shader_info.h"
32 #include "util/u_live_shader_cache.h"
33 
34 #include <vulkan/vulkan.h>
35 #include "zink_descriptors.h"
36 
37 #define ZINK_WORKGROUP_SIZE_X 1
38 #define ZINK_WORKGROUP_SIZE_Y 2
39 #define ZINK_WORKGROUP_SIZE_Z 3
40 
41 /* stop inlining shaders if they have >limit ssa vals after inlining:
42  * recompile time isn't worth the inline
43  */
44 #define ZINK_ALWAYS_INLINE_LIMIT 1500
45 
46 struct pipe_screen;
47 struct zink_context;
48 struct zink_screen;
49 struct zink_shader_key;
50 struct zink_shader_module;
51 struct zink_gfx_program;
52 struct spirv_shader;
53 
54 struct nir_shader_compiler_options;
55 struct nir_shader;
56 
57 struct set;
58 
59 struct tgsi_token;
60 struct zink_shader_info {
61    struct pipe_stream_output_info so_info;
62    unsigned so_info_slots[PIPE_MAX_SO_OUTPUTS];
63    uint32_t so_propagate; //left shifted by 32
64    bool last_vertex;
65    bool have_xfb;
66    bool have_sparse;
67    bool have_vulkan_memory_model;
68 };
69 
70 
71 const void *
72 zink_get_compiler_options(struct pipe_screen *screen,
73                           enum pipe_shader_ir ir,
74                           enum pipe_shader_type shader);
75 
76 struct nir_shader *
77 zink_tgsi_to_nir(struct pipe_screen *screen, const struct tgsi_token *tokens);
78 
79 struct zink_shader {
80    struct util_live_shader base;
81    uint32_t hash;
82    struct nir_shader *nir;
83    enum pipe_prim_type reduced_prim; // PIPE_PRIM_MAX for vs
84 
85    struct zink_shader_info sinfo;
86 
87    struct {
88       int index;
89       int binding;
90       VkDescriptorType type;
91       unsigned char size;
92    } bindings[ZINK_DESCRIPTOR_TYPES][ZINK_MAX_DESCRIPTORS_PER_TYPE];
93    size_t num_bindings[ZINK_DESCRIPTOR_TYPES];
94    unsigned num_texel_buffers;
95    uint32_t ubos_used; // bitfield of which ubo indices are used
96    uint32_t ssbos_used; // bitfield of which ssbo indices are used
97    bool bindless;
98    bool can_inline;
99    struct spirv_shader *spirv;
100 
101    simple_mtx_t lock;
102    struct set *programs;
103 
104    union {
105       struct zink_shader *generated; // a generated shader that this shader "owns"
106       bool is_generated; // if this is a driver-created shader (e.g., tcs)
107       nir_variable *fbfetch; //for fs output
108    };
109 };
110 
111 void
112 zink_screen_init_compiler(struct zink_screen *screen);
113 void
114 zink_compiler_assign_io(nir_shader *producer, nir_shader *consumer);
115 VkShaderModule
116 zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, nir_shader *nir, const struct zink_shader_key *key);
117 VkShaderModule
118 zink_shader_spirv_compile(struct zink_screen *screen, struct zink_shader *zs, struct spirv_shader *spirv);
119 struct zink_shader *
120 zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
121                  const struct pipe_stream_output_info *so_info);
122 
123 char *
124 zink_shader_finalize(struct pipe_screen *pscreen, void *nirptr);
125 
126 void
127 zink_shader_free(struct zink_context *ctx, struct zink_shader *shader);
128 
129 VkShaderModule
130 zink_shader_tcs_compile(struct zink_screen *screen, struct zink_shader *zs, unsigned patch_vertices);
131 struct zink_shader *
132 zink_shader_tcs_create(struct zink_screen *screen, struct zink_shader *vs, unsigned vertices_per_patch);
133 
134 static inline bool
zink_shader_descriptor_is_buffer(struct zink_shader * zs,enum zink_descriptor_type type,unsigned i)135 zink_shader_descriptor_is_buffer(struct zink_shader *zs, enum zink_descriptor_type type, unsigned i)
136 {
137    return zs->bindings[type][i].type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER ||
138           zs->bindings[type][i].type == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
139 }
140 
141 #endif
142