etnaviv: upgrade DISCARD_RANGE to DISCARD_WHOLE_RESOURCE if possible
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_internal.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
24 #ifndef H_ETNA_INTERNAL
25 #define H_ETNA_INTERNAL
26
27 #include <assert.h>
28 #include <stdbool.h>
29 #include <stdint.h>
30
31 #include "hw/state.xml.h"
32 #include "hw/state_3d.xml.h"
33
34 #include <etnaviv_drmif.h>
35
36 #define ETNA_NUM_INPUTS (16)
37 #define ETNA_NUM_VARYINGS 8
38 #define ETNA_NUM_LOD (14)
39 #define ETNA_NUM_LAYERS (6)
40 #define ETNA_MAX_UNIFORMS (256)
41 #define ETNA_MAX_PIXELPIPES 2
42
43 /* All RS operations must have width%16 = 0 */
44 #define ETNA_RS_WIDTH_MASK (16 - 1)
45 /* RS tiled operations must have height%4 = 0 */
46 #define ETNA_RS_HEIGHT_MASK (3)
47 /* PE render targets must be aligned to 64 bytes */
48 #define ETNA_PE_ALIGNMENT (64)
49
50 /* These demarcate the margin (fixp16) between the computed sizes and the
51 value sent to the chip. These have been set to the numbers used by the
52 Vivante driver on gc2000. They used to be -1 for scissor right and bottom. I
53 am not sure whether older hardware was relying on these or they were just a
54 guess. But if so, these need to be moved to the _specs structure.
55 */
56 #define ETNA_SE_SCISSOR_MARGIN_RIGHT (0x1119)
57 #define ETNA_SE_SCISSOR_MARGIN_BOTTOM (0x1111)
58 #define ETNA_SE_CLIP_MARGIN_RIGHT (0xffff)
59 #define ETNA_SE_CLIP_MARGIN_BOTTOM (0xffff)
60
61 /* GPU chip 3D specs */
62 struct etna_specs {
63 /* supports SUPERTILE (64x64) tiling? */
64 unsigned can_supertile : 1;
65 /* needs z=(z+w)/2, for older GCxxx */
66 unsigned vs_need_z_div : 1;
67 /* supports trigonometric instructions */
68 unsigned has_sin_cos_sqrt : 1;
69 /* has SIGN/FLOOR/CEIL instructions */
70 unsigned has_sign_floor_ceil : 1;
71 /* can use VS_RANGE, PS_RANGE registers*/
72 unsigned has_shader_range_registers : 1;
73 /* has the new sin/cos functions */
74 unsigned has_new_sin_cos : 1;
75 /* supports single-buffer rendering with multiple pixel pipes */
76 unsigned single_buffer : 1;
77 /* can use any kind of wrapping mode on npot textures */
78 unsigned npot_tex_any_wrap;
79 /* number of bits per TS tile */
80 unsigned bits_per_tile;
81 /* clear value for TS (dependent on bits_per_tile) */
82 uint32_t ts_clear_value;
83 /* base of vertex texture units */
84 unsigned vertex_sampler_offset;
85 /* number of fragment sampler units */
86 unsigned fragment_sampler_count;
87 /* number of vertex sampler units */
88 unsigned vertex_sampler_count;
89 /* size of vertex shader output buffer */
90 unsigned vertex_output_buffer_size;
91 /* maximum number of vertex element configurations */
92 unsigned vertex_max_elements;
93 /* size of a cached vertex (?) */
94 unsigned vertex_cache_size;
95 /* number of shader cores */
96 unsigned shader_core_count;
97 /* number of vertex streams */
98 unsigned stream_count;
99 /* vertex shader memory address*/
100 uint32_t vs_offset;
101 /* pixel shader memory address*/
102 uint32_t ps_offset;
103 /* vertex/fragment shader max instructions */
104 uint32_t max_instructions;
105 /* maximum number of varyings */
106 unsigned max_varyings;
107 /* maximum number of registers */
108 unsigned max_registers;
109 /* maximum vertex uniforms */
110 unsigned max_vs_uniforms;
111 /* maximum pixel uniforms */
112 unsigned max_ps_uniforms;
113 /* maximum texture size */
114 unsigned max_texture_size;
115 /* maximum texture size */
116 unsigned max_rendertarget_size;
117 /* available pixel pipes */
118 unsigned pixel_pipes;
119 /* number of constants */
120 unsigned num_constants;
121 };
122
123 /* Compiled Gallium state. All the different compiled state atoms are woven
124 * together and uploaded only when it is necessary to synchronize the state,
125 * for example before rendering. */
126
127 /* Compiled pipe_blend_color */
128 struct compiled_blend_color {
129 uint32_t PE_ALPHA_BLEND_COLOR;
130 };
131
132 /* Compiled pipe_stencil_ref */
133 struct compiled_stencil_ref {
134 uint32_t PE_STENCIL_CONFIG;
135 uint32_t PE_STENCIL_CONFIG_EXT;
136 };
137
138 /* Compiled pipe_scissor_state */
139 struct compiled_scissor_state {
140 uint32_t SE_SCISSOR_LEFT;
141 uint32_t SE_SCISSOR_TOP;
142 uint32_t SE_SCISSOR_RIGHT;
143 uint32_t SE_SCISSOR_BOTTOM;
144 uint32_t SE_CLIP_RIGHT;
145 uint32_t SE_CLIP_BOTTOM;
146 };
147
148 /* Compiled pipe_viewport_state */
149 struct compiled_viewport_state {
150 uint32_t PA_VIEWPORT_SCALE_X;
151 uint32_t PA_VIEWPORT_SCALE_Y;
152 uint32_t PA_VIEWPORT_SCALE_Z;
153 uint32_t PA_VIEWPORT_OFFSET_X;
154 uint32_t PA_VIEWPORT_OFFSET_Y;
155 uint32_t PA_VIEWPORT_OFFSET_Z;
156 uint32_t SE_SCISSOR_LEFT;
157 uint32_t SE_SCISSOR_TOP;
158 uint32_t SE_SCISSOR_RIGHT;
159 uint32_t SE_SCISSOR_BOTTOM;
160 uint32_t SE_CLIP_RIGHT;
161 uint32_t SE_CLIP_BOTTOM;
162 uint32_t PE_DEPTH_NEAR;
163 uint32_t PE_DEPTH_FAR;
164 };
165
166 /* Compiled pipe_framebuffer_state */
167 struct compiled_framebuffer_state {
168 struct pipe_surface *cbuf, *zsbuf; /* keep reference to surfaces */
169 uint32_t GL_MULTI_SAMPLE_CONFIG;
170 uint32_t PE_COLOR_FORMAT;
171 uint32_t PE_DEPTH_CONFIG;
172 struct etna_reloc PE_DEPTH_ADDR;
173 struct etna_reloc PE_PIPE_DEPTH_ADDR[ETNA_MAX_PIXELPIPES];
174 uint32_t PE_DEPTH_STRIDE;
175 uint32_t PE_HDEPTH_CONTROL;
176 uint32_t PE_DEPTH_NORMALIZE;
177 struct etna_reloc PE_COLOR_ADDR;
178 struct etna_reloc PE_PIPE_COLOR_ADDR[ETNA_MAX_PIXELPIPES];
179 uint32_t PE_COLOR_STRIDE;
180 uint32_t SE_SCISSOR_LEFT;
181 uint32_t SE_SCISSOR_TOP;
182 uint32_t SE_SCISSOR_RIGHT;
183 uint32_t SE_SCISSOR_BOTTOM;
184 uint32_t SE_CLIP_RIGHT;
185 uint32_t SE_CLIP_BOTTOM;
186 uint32_t RA_MULTISAMPLE_UNK00E04;
187 uint32_t RA_MULTISAMPLE_UNK00E10[VIVS_RA_MULTISAMPLE_UNK00E10__LEN];
188 uint32_t RA_CENTROID_TABLE[VIVS_RA_CENTROID_TABLE__LEN];
189 uint32_t TS_MEM_CONFIG;
190 uint32_t TS_DEPTH_CLEAR_VALUE;
191 struct etna_reloc TS_DEPTH_STATUS_BASE;
192 struct etna_reloc TS_DEPTH_SURFACE_BASE;
193 uint32_t TS_COLOR_CLEAR_VALUE;
194 struct etna_reloc TS_COLOR_STATUS_BASE;
195 struct etna_reloc TS_COLOR_SURFACE_BASE;
196 uint32_t PE_LOGIC_OP;
197 bool msaa_mode; /* adds input (and possible temp) to PS */
198 };
199
200 /* Compiled context->create_vertex_elements_state */
201 struct compiled_vertex_elements_state {
202 unsigned num_elements;
203 uint32_t FE_VERTEX_ELEMENT_CONFIG[VIVS_FE_VERTEX_ELEMENT_CONFIG__LEN];
204 };
205
206 /* Compiled context->set_vertex_buffer result */
207 struct compiled_set_vertex_buffer {
208 uint32_t FE_VERTEX_STREAM_CONTROL;
209 struct etna_reloc FE_VERTEX_STREAM_BASE_ADDR;
210 };
211
212 /* Compiled linked VS+PS shader state */
213 struct compiled_shader_state {
214 uint32_t RA_CONTROL;
215 uint32_t PA_ATTRIBUTE_ELEMENT_COUNT;
216 uint32_t PA_CONFIG;
217 uint32_t PA_SHADER_ATTRIBUTES[VIVS_PA_SHADER_ATTRIBUTES__LEN];
218 uint32_t VS_END_PC;
219 uint32_t VS_OUTPUT_COUNT; /* number of outputs if point size per vertex disabled */
220 uint32_t VS_OUTPUT_COUNT_PSIZE; /* number of outputs of point size per vertex enabled */
221 uint32_t VS_INPUT_COUNT;
222 uint32_t VS_TEMP_REGISTER_CONTROL;
223 uint32_t VS_OUTPUT[4];
224 uint32_t VS_INPUT[4];
225 uint32_t VS_LOAD_BALANCING;
226 uint32_t VS_START_PC;
227 uint32_t PS_END_PC;
228 uint32_t PS_OUTPUT_REG;
229 uint32_t PS_INPUT_COUNT;
230 uint32_t PS_INPUT_COUNT_MSAA; /* Adds an input */
231 uint32_t PS_TEMP_REGISTER_CONTROL;
232 uint32_t PS_TEMP_REGISTER_CONTROL_MSAA; /* Adds a temporary if needed to make space for extra input */
233 uint32_t PS_CONTROL;
234 uint32_t PS_START_PC;
235 uint32_t GL_VARYING_TOTAL_COMPONENTS;
236 uint32_t GL_VARYING_NUM_COMPONENTS;
237 uint32_t GL_VARYING_COMPONENT_USE[2];
238 unsigned vs_inst_mem_size;
239 unsigned vs_uniforms_size;
240 unsigned ps_inst_mem_size;
241 unsigned ps_uniforms_size;
242 uint32_t *VS_INST_MEM;
243 uint32_t VS_UNIFORMS[ETNA_MAX_UNIFORMS * 4];
244 uint32_t *PS_INST_MEM;
245 uint32_t PS_UNIFORMS[ETNA_MAX_UNIFORMS * 4];
246 };
247
248 /* state of some 3d and common registers relevant to etna driver */
249 struct etna_3d_state {
250 unsigned vs_uniforms_size;
251 unsigned ps_uniforms_size;
252
253 uint32_t /*01008*/ PS_INPUT_COUNT;
254 uint32_t /*0100C*/ PS_TEMP_REGISTER_CONTROL;
255 uint32_t /*03818*/ GL_MULTI_SAMPLE_CONFIG;
256 uint32_t /*05000*/ VS_UNIFORMS[VIVS_VS_UNIFORMS__LEN];
257 uint32_t /*07000*/ PS_UNIFORMS[VIVS_PS_UNIFORMS__LEN];
258 };
259
260 /* Helpers to assist creating and setting bitarrays (eg, for varyings).
261 * field_size must be a power of two, and <= 32. */
262 #define DEFINE_ETNA_BITARRAY(name, num, field_size) \
263 uint32_t name[(num) * (field_size) / 32]
264
265 static inline void
266 etna_bitarray_set(uint32_t *array, size_t array_size, size_t field_size,
267 size_t index, uint32_t value)
268 {
269 size_t shift = (index * field_size) % 32;
270 size_t offset = (index * field_size) / 32;
271
272 assert(index < array_size * 32 / field_size);
273 assert(value < 1 << field_size);
274
275 array[offset] |= value << shift;
276 }
277
278 #define etna_bitarray_set(array, field_size, index, value) \
279 etna_bitarray_set((array), ARRAY_SIZE(array), field_size, index, value)
280
281 #endif