ilo: use emit_SURFACE_STATE() for render targets
[mesa.git] / src / gallium / drivers / ilo / ilo_gpe.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_GPE_H
29 #define ILO_GPE_H
30
31 #include "ilo_common.h"
32
33 /**
34 * \see brw_context.h
35 */
36 #define ILO_MAX_DRAW_BUFFERS 8
37 #define ILO_MAX_CONST_BUFFERS (1 + 12)
38 #define ILO_MAX_SAMPLER_VIEWS 16
39 #define ILO_MAX_SAMPLERS 16
40 #define ILO_MAX_SO_BINDINGS 64
41 #define ILO_MAX_SO_BUFFERS 4
42 #define ILO_MAX_VIEWPORTS 1
43
44 #define ILO_MAX_VS_SURFACES (ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
45 #define ILO_VS_CONST_SURFACE(i) (i)
46 #define ILO_VS_TEXTURE_SURFACE(i) (ILO_MAX_CONST_BUFFERS + i)
47
48 #define ILO_MAX_GS_SURFACES (ILO_MAX_SO_BINDINGS)
49 #define ILO_GS_SO_SURFACE(i) (i)
50
51 #define ILO_MAX_WM_SURFACES (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
52 #define ILO_WM_DRAW_SURFACE(i) (i)
53 #define ILO_WM_CONST_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + i)
54 #define ILO_WM_TEXTURE_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + i)
55
56 struct ilo_buffer;
57 struct ilo_texture;
58
59 struct ilo_vb_state {
60 struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS];
61 uint32_t enabled_mask;
62 };
63
64 struct ilo_ib_state {
65 struct pipe_index_buffer state;
66 };
67
68 struct ilo_ve_cso {
69 /* VERTEX_ELEMENT_STATE */
70 uint32_t payload[2];
71 };
72
73 struct ilo_ve_state {
74 struct ilo_ve_cso cso[PIPE_MAX_ATTRIBS];
75 unsigned count;
76
77 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
78 unsigned vb_mapping[PIPE_MAX_ATTRIBS];
79 unsigned vb_count;
80 };
81
82 struct ilo_so_state {
83 struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS];
84 unsigned count;
85 unsigned append_bitmask;
86
87 bool enabled;
88 };
89
90 struct ilo_viewport_cso {
91 /* matrix form */
92 float m00, m11, m22, m30, m31, m32;
93
94 /* guardband in NDC space */
95 float min_gbx, min_gby, max_gbx, max_gby;
96
97 /* viewport in screen space */
98 float min_x, min_y, min_z;
99 float max_x, max_y, max_z;
100 };
101
102 struct ilo_viewport_state {
103 struct ilo_viewport_cso cso[ILO_MAX_VIEWPORTS];
104 unsigned count;
105
106 struct pipe_viewport_state viewport0;
107 };
108
109 struct ilo_scissor_state {
110 /* SCISSOR_RECT */
111 uint32_t payload[ILO_MAX_VIEWPORTS * 2];
112 };
113
114 struct ilo_rasterizer_state {
115 struct pipe_rasterizer_state state;
116 };
117
118 struct ilo_dsa_state {
119 /* DEPTH_STENCIL_STATE */
120 uint32_t payload[3];
121
122 struct pipe_alpha_state alpha;
123 };
124
125 struct ilo_blend_cso {
126 /* BLEND_STATE */
127 uint32_t payload[2];
128
129 uint32_t dw_blend;
130 uint32_t dw_blend_dst_alpha_forced_one;
131
132 uint32_t dw_logicop;
133 uint32_t dw_alpha_mod;
134 };
135
136 struct ilo_blend_state {
137 struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
138
139 bool independent_blend_enable;
140 bool dual_blend;
141 bool alpha_to_coverage;
142 };
143
144 struct ilo_sampler_cso {
145 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
146 uint32_t payload[15];
147
148 uint32_t dw_filter;
149 uint32_t dw_filter_aniso;
150 uint32_t dw_wrap;
151 uint32_t dw_wrap_1d;
152 uint32_t dw_wrap_cube;
153
154 bool anisotropic;
155 bool saturate_r;
156 bool saturate_s;
157 bool saturate_t;
158 };
159
160 struct ilo_sampler_state {
161 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
162 unsigned count;
163 };
164
165 struct ilo_view_surface {
166 /* SURFACE_STATE */
167 uint32_t payload[8];
168 struct intel_bo *bo;
169 };
170
171 struct ilo_view_cso {
172 struct pipe_sampler_view base;
173
174 struct ilo_view_surface surface;
175 };
176
177 struct ilo_view_state {
178 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
179 unsigned count;
180 };
181
182 struct ilo_cbuf_cso {
183 struct pipe_resource *resource;
184 struct ilo_view_surface surface;
185 };
186
187 struct ilo_cbuf_state {
188 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
189 unsigned count;
190 };
191
192 struct ilo_resource_state {
193 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
194 unsigned count;
195 };
196
197 struct ilo_surface_cso {
198 struct pipe_surface base;
199
200 bool is_rt;
201 union {
202 struct ilo_view_surface rt;
203 } u;
204 };
205
206 struct ilo_fb_state {
207 struct pipe_framebuffer_state state;
208
209 unsigned num_samples;
210 };
211
212 struct ilo_global_binding {
213 /*
214 * XXX These should not be treated as real resources (and there could be
215 * thousands of them). They should be treated as regions in GLOBAL
216 * resource, which is the only real resource.
217 *
218 * That is, a resource here should instead be
219 *
220 * struct ilo_global_region {
221 * struct pipe_resource base;
222 * int offset;
223 * int size;
224 * };
225 *
226 * and it describes the region [offset, offset + size) in GLOBAL
227 * resource.
228 */
229 struct pipe_resource *resources[PIPE_MAX_SHADER_RESOURCES];
230 uint32_t *handles[PIPE_MAX_SHADER_RESOURCES];
231 unsigned count;
232 };
233
234 void
235 ilo_gpe_init_ve(const struct ilo_dev_info *dev,
236 unsigned num_states,
237 const struct pipe_vertex_element *states,
238 struct ilo_ve_state *ve);
239
240 void
241 ilo_gpe_set_viewport_cso(const struct ilo_dev_info *dev,
242 const struct pipe_viewport_state *state,
243 struct ilo_viewport_cso *vp);
244
245 void
246 ilo_gpe_set_scissor(const struct ilo_dev_info *dev,
247 unsigned start_slot,
248 unsigned num_states,
249 const struct pipe_scissor_state *states,
250 struct ilo_scissor_state *scissor);
251
252 void
253 ilo_gpe_set_scissor_null(const struct ilo_dev_info *dev,
254 struct ilo_scissor_state *scissor);
255
256 void
257 ilo_gpe_init_dsa(const struct ilo_dev_info *dev,
258 const struct pipe_depth_stencil_alpha_state *state,
259 struct ilo_dsa_state *dsa);
260
261 void
262 ilo_gpe_init_blend(const struct ilo_dev_info *dev,
263 const struct pipe_blend_state *state,
264 struct ilo_blend_state *blend);
265
266 void
267 ilo_gpe_init_sampler_cso(const struct ilo_dev_info *dev,
268 const struct pipe_sampler_state *state,
269 struct ilo_sampler_cso *sampler);
270
271 void
272 ilo_gpe_init_view_surface_null_gen6(const struct ilo_dev_info *dev,
273 unsigned width, unsigned height,
274 unsigned depth, unsigned level,
275 struct ilo_view_surface *surf);
276
277 void
278 ilo_gpe_init_view_surface_for_buffer_gen6(const struct ilo_dev_info *dev,
279 const struct ilo_buffer *buf,
280 unsigned offset, unsigned size,
281 unsigned struct_size,
282 enum pipe_format elem_format,
283 bool is_rt, bool render_cache_rw,
284 struct ilo_view_surface *surf);
285
286 void
287 ilo_gpe_init_view_surface_for_texture_gen6(const struct ilo_dev_info *dev,
288 const struct ilo_texture *tex,
289 enum pipe_format format,
290 unsigned first_level,
291 unsigned num_levels,
292 unsigned first_layer,
293 unsigned num_layers,
294 bool is_rt, bool render_cache_rw,
295 struct ilo_view_surface *surf);
296
297 void
298 ilo_gpe_init_view_surface_null_gen7(const struct ilo_dev_info *dev,
299 unsigned width, unsigned height,
300 unsigned depth, unsigned level,
301 struct ilo_view_surface *surf);
302
303 void
304 ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info *dev,
305 const struct ilo_buffer *buf,
306 unsigned offset, unsigned size,
307 unsigned struct_size,
308 enum pipe_format elem_format,
309 bool is_rt, bool render_cache_rw,
310 struct ilo_view_surface *surf);
311
312 void
313 ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info *dev,
314 const struct ilo_texture *tex,
315 enum pipe_format format,
316 unsigned first_level,
317 unsigned num_levels,
318 unsigned first_layer,
319 unsigned num_layers,
320 bool is_rt, bool render_cache_rw,
321 struct ilo_view_surface *surf);
322
323 static inline void
324 ilo_gpe_init_view_surface_null(const struct ilo_dev_info *dev,
325 unsigned width, unsigned height,
326 unsigned depth, unsigned level,
327 struct ilo_view_surface *surf)
328 {
329 if (dev->gen >= ILO_GEN(7)) {
330 ilo_gpe_init_view_surface_null_gen7(dev,
331 width, height, depth, level, surf);
332 }
333 else {
334 ilo_gpe_init_view_surface_null_gen6(dev,
335 width, height, depth, level, surf);
336 }
337 }
338
339 static inline void
340 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev_info *dev,
341 const struct ilo_buffer *buf,
342 unsigned offset, unsigned size,
343 unsigned struct_size,
344 enum pipe_format elem_format,
345 bool is_rt, bool render_cache_rw,
346 struct ilo_view_surface *surf)
347 {
348 if (dev->gen >= ILO_GEN(7)) {
349 ilo_gpe_init_view_surface_for_buffer_gen7(dev, buf, offset, size,
350 struct_size, elem_format, is_rt, render_cache_rw, surf);
351 }
352 else {
353 ilo_gpe_init_view_surface_for_buffer_gen6(dev, buf, offset, size,
354 struct_size, elem_format, is_rt, render_cache_rw, surf);
355 }
356 }
357
358 static inline void
359 ilo_gpe_init_view_surface_for_texture(const struct ilo_dev_info *dev,
360 const struct ilo_texture *tex,
361 enum pipe_format format,
362 unsigned first_level,
363 unsigned num_levels,
364 unsigned first_layer,
365 unsigned num_layers,
366 bool is_rt, bool render_cache_rw,
367 struct ilo_view_surface *surf)
368 {
369 if (dev->gen >= ILO_GEN(7)) {
370 ilo_gpe_init_view_surface_for_texture_gen7(dev, tex, format,
371 first_level, num_levels, first_layer, num_layers,
372 is_rt, render_cache_rw, surf);
373 }
374 else {
375 ilo_gpe_init_view_surface_for_texture_gen6(dev, tex, format,
376 first_level, num_levels, first_layer, num_layers,
377 is_rt, render_cache_rw, surf);
378 }
379 }
380
381 #endif /* ILO_GPE_H */