radeonsi: use shader_info::cs::local_size_variable to clean up some code
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_compiler.h
1 /*
2 * Copyright (c) 2012-2015 Etnaviv Project
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Wladimir J. van der Laan <laanwj@gmail.com>
25 */
26
27 #ifndef H_ETNAVIV_COMPILER
28 #define H_ETNAVIV_COMPILER
29
30 #include "etnaviv_context.h"
31 #include "etnaviv_internal.h"
32 #include "etnaviv_shader.h"
33 #include "pipe/p_compiler.h"
34 #include "pipe/p_shader_tokens.h"
35 #include "compiler/shader_enums.h"
36
37 /* XXX some of these are pretty arbitrary limits, may be better to switch
38 * to dynamic allocation at some point.
39 */
40 #define ETNA_MAX_TEMPS (64) /* max temp register count of all Vivante hw */
41 #define ETNA_MAX_TOKENS (2048)
42 #define ETNA_MAX_IMM (1024) /* max const+imm in 32-bit words */
43 #define ETNA_MAX_DECL (2048) /* max declarations */
44 #define ETNA_MAX_DEPTH (32)
45 #define ETNA_MAX_INSTRUCTIONS (2048)
46
47 /**
48 * Compiler state saved across compiler invocations, for any expensive global
49 * setup.
50 */
51 struct etna_compiler {
52 uint32_t shader_count;
53 struct ra_regs *regs;
54 };
55
56 /* compiler output per input/output */
57 struct etna_shader_inout {
58 int reg; /* native register */
59 struct tgsi_declaration_semantic semantic; /* tgsi semantic name and index */
60 int slot; /* nir: gl_varying_slot or gl_vert_attrib */
61 int num_components;
62 };
63
64 struct etna_shader_io_file {
65 size_t num_reg;
66 struct etna_shader_inout reg[ETNA_NUM_INPUTS];
67 };
68
69 /* shader object, for linking */
70 struct etna_shader_variant {
71 uint32_t id; /* for debug */
72
73 gl_shader_stage stage;
74 uint32_t code_size; /* code size in uint32 words */
75 uint32_t *code;
76 unsigned num_loops;
77 unsigned num_temps;
78
79 struct etna_shader_uniform_info uniforms;
80
81 /* ETNA_DIRTY_* flags that, when set in context dirty, mean that the
82 * uniforms have to get (partial) reloaded. */
83 uint32_t uniforms_dirty_bits;
84
85 /* inputs (for linking) for fs, the inputs must be in register 1..N */
86 struct etna_shader_io_file infile;
87
88 /* outputs (for linking) */
89 struct etna_shader_io_file outfile;
90
91 /* index into outputs (for linking) - only for TGSI compiler */
92 int output_count_per_semantic[TGSI_SEMANTIC_COUNT];
93 struct etna_shader_inout * *output_per_semantic_list; /* list of pointers to outputs */
94 struct etna_shader_inout **output_per_semantic[TGSI_SEMANTIC_COUNT];
95
96 /* special inputs/outputs (vs only) */
97 int vs_id_in_reg; /* vertexid+instanceid input */
98 int vs_pos_out_reg; /* VS position output */
99 int vs_pointsize_out_reg; /* VS point size output */
100 uint32_t vs_load_balancing;
101
102 /* special outputs (ps only) */
103 int ps_color_out_reg; /* color output register */
104 int ps_depth_out_reg; /* depth output register */
105
106 /* unknown input property (XX_INPUT_COUNT, field UNK8) */
107 uint32_t input_count_unk8;
108
109 /* shader is larger than GPU instruction limit, thus needs icache */
110 bool needs_icache;
111
112 /* shader variants form a linked list */
113 struct etna_shader_variant *next;
114
115 /* replicated here to avoid passing extra ptrs everywhere */
116 struct etna_shader *shader;
117 struct etna_shader_key key;
118
119 struct etna_bo *bo; /* cached code memory bo handle (for icache) */
120 };
121
122 struct etna_varying {
123 uint32_t pa_attributes;
124 uint8_t num_components;
125 uint8_t use[4];
126 uint8_t reg;
127 };
128
129 struct etna_shader_link_info {
130 /* each PS input is annotated with the VS output reg */
131 unsigned num_varyings;
132 struct etna_varying varyings[ETNA_NUM_INPUTS];
133 int pcoord_varying_comp_ofs;
134 };
135
136 struct etna_compiler *
137 etna_compiler_create(void);
138
139 void
140 etna_compiler_destroy(const struct etna_compiler *compiler);
141
142 bool
143 etna_compile_shader(struct etna_shader_variant *shader);
144
145 void
146 etna_dump_shader(const struct etna_shader_variant *shader);
147
148 bool
149 etna_link_shader(struct etna_shader_link_info *info,
150 const struct etna_shader_variant *vs, const struct etna_shader_variant *fs);
151
152 void
153 etna_destroy_shader(struct etna_shader_variant *shader);
154
155 /* NIR compiler */
156
157 bool
158 etna_compile_shader_nir(struct etna_shader_variant *shader);
159
160 void
161 etna_dump_shader_nir(const struct etna_shader_variant *shader);
162
163 bool
164 etna_link_shader_nir(struct etna_shader_link_info *info,
165 const struct etna_shader_variant *vs,
166 const struct etna_shader_variant *fs);
167
168 void
169 etna_destroy_shader_nir(struct etna_shader_variant *shader);
170
171 #endif