2 * Mesa 3-D graphics library
4 * Copyright (C) 2013 LunarG, Inc.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 * Chia-I Wu <olv@lunarg.com>
31 #include "ilo_common.h"
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
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)
48 #define ILO_MAX_GS_SURFACES (ILO_MAX_SO_BINDINGS)
49 #define ILO_GS_SO_SURFACE(i) (i)
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)
58 struct ilo_shader_state
;
61 struct pipe_vertex_buffer states
[PIPE_MAX_ATTRIBS
];
62 uint32_t enabled_mask
;
66 struct pipe_index_buffer state
;
70 /* VERTEX_ELEMENT_STATE */
75 struct ilo_ve_cso cso
[PIPE_MAX_ATTRIBS
];
78 unsigned instance_divisors
[PIPE_MAX_ATTRIBS
];
79 unsigned vb_mapping
[PIPE_MAX_ATTRIBS
];
84 struct pipe_stream_output_target
*states
[ILO_MAX_SO_BUFFERS
];
86 unsigned append_bitmask
;
91 struct ilo_viewport_cso
{
93 float m00
, m11
, m22
, m30
, m31
, m32
;
95 /* guardband in NDC space */
96 float min_gbx
, min_gby
, max_gbx
, max_gby
;
98 /* viewport in screen space */
99 float min_x
, min_y
, min_z
;
100 float max_x
, max_y
, max_z
;
103 struct ilo_viewport_state
{
104 struct ilo_viewport_cso cso
[ILO_MAX_VIEWPORTS
];
107 struct pipe_viewport_state viewport0
;
110 struct ilo_scissor_state
{
112 uint32_t payload
[ILO_MAX_VIEWPORTS
* 2];
115 struct ilo_rasterizer_clip
{
119 uint32_t can_enable_guardband
;
122 struct ilo_rasterizer_sf
{
128 struct ilo_rasterizer_wm
{
131 uint32_t dw_msaa_rast
;
132 uint32_t dw_msaa_disp
;
135 struct ilo_rasterizer_state
{
136 struct pipe_rasterizer_state state
;
138 struct ilo_rasterizer_clip clip
;
139 struct ilo_rasterizer_sf sf
;
140 struct ilo_rasterizer_wm wm
;
143 struct ilo_dsa_state
{
144 /* DEPTH_STENCIL_STATE */
147 struct pipe_alpha_state alpha
;
150 struct ilo_blend_cso
{
155 uint32_t dw_blend_dst_alpha_forced_one
;
158 uint32_t dw_alpha_mod
;
161 struct ilo_blend_state
{
162 struct ilo_blend_cso cso
[ILO_MAX_DRAW_BUFFERS
];
164 bool independent_blend_enable
;
166 bool alpha_to_coverage
;
169 struct ilo_sampler_cso
{
170 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
171 uint32_t payload
[15];
174 uint32_t dw_filter_aniso
;
177 uint32_t dw_wrap_cube
;
185 struct ilo_sampler_state
{
186 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
190 struct ilo_view_surface
{
196 struct ilo_view_cso
{
197 struct pipe_sampler_view base
;
199 struct ilo_view_surface surface
;
202 struct ilo_view_state
{
203 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
207 struct ilo_cbuf_cso
{
208 struct pipe_resource
*resource
;
209 struct ilo_view_surface surface
;
212 struct ilo_cbuf_state
{
213 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
217 struct ilo_resource_state
{
218 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
222 struct ilo_surface_cso
{
223 struct pipe_surface base
;
227 struct ilo_view_surface rt
;
228 struct ilo_zs_surface
{
229 uint32_t payload
[10];
231 struct intel_bo
*hiz_bo
;
232 struct intel_bo
*separate_s8_bo
;
237 struct ilo_fb_state
{
238 struct pipe_framebuffer_state state
;
240 struct ilo_zs_surface null_zs
;
241 unsigned num_samples
;
244 struct ilo_global_binding
{
246 * XXX These should not be treated as real resources (and there could be
247 * thousands of them). They should be treated as regions in GLOBAL
248 * resource, which is the only real resource.
250 * That is, a resource here should instead be
252 * struct ilo_global_region {
253 * struct pipe_resource base;
258 * and it describes the region [offset, offset + size) in GLOBAL
261 struct pipe_resource
*resources
[PIPE_MAX_SHADER_RESOURCES
];
262 uint32_t *handles
[PIPE_MAX_SHADER_RESOURCES
];
266 struct ilo_shader_cso
{
271 ilo_gpe_init_ve(const struct ilo_dev_info
*dev
,
273 const struct pipe_vertex_element
*states
,
274 struct ilo_ve_state
*ve
);
277 ilo_gpe_set_viewport_cso(const struct ilo_dev_info
*dev
,
278 const struct pipe_viewport_state
*state
,
279 struct ilo_viewport_cso
*vp
);
282 ilo_gpe_set_scissor(const struct ilo_dev_info
*dev
,
285 const struct pipe_scissor_state
*states
,
286 struct ilo_scissor_state
*scissor
);
289 ilo_gpe_set_scissor_null(const struct ilo_dev_info
*dev
,
290 struct ilo_scissor_state
*scissor
);
293 ilo_gpe_init_rasterizer_clip(const struct ilo_dev_info
*dev
,
294 const struct pipe_rasterizer_state
*state
,
295 struct ilo_rasterizer_clip
*clip
);
298 ilo_gpe_init_rasterizer_sf(const struct ilo_dev_info
*dev
,
299 const struct pipe_rasterizer_state
*state
,
300 struct ilo_rasterizer_sf
*sf
);
303 ilo_gpe_init_rasterizer_wm_gen6(const struct ilo_dev_info
*dev
,
304 const struct pipe_rasterizer_state
*state
,
305 struct ilo_rasterizer_wm
*wm
);
308 ilo_gpe_init_rasterizer_wm_gen7(const struct ilo_dev_info
*dev
,
309 const struct pipe_rasterizer_state
*state
,
310 struct ilo_rasterizer_wm
*wm
);
313 ilo_gpe_init_rasterizer(const struct ilo_dev_info
*dev
,
314 const struct pipe_rasterizer_state
*state
,
315 struct ilo_rasterizer_state
*rasterizer
)
317 ilo_gpe_init_rasterizer_clip(dev
, state
, &rasterizer
->clip
);
318 ilo_gpe_init_rasterizer_sf(dev
, state
, &rasterizer
->sf
);
320 if (dev
->gen
>= ILO_GEN(7))
321 ilo_gpe_init_rasterizer_wm_gen7(dev
, state
, &rasterizer
->wm
);
323 ilo_gpe_init_rasterizer_wm_gen6(dev
, state
, &rasterizer
->wm
);
327 ilo_gpe_init_dsa(const struct ilo_dev_info
*dev
,
328 const struct pipe_depth_stencil_alpha_state
*state
,
329 struct ilo_dsa_state
*dsa
);
332 ilo_gpe_init_blend(const struct ilo_dev_info
*dev
,
333 const struct pipe_blend_state
*state
,
334 struct ilo_blend_state
*blend
);
337 ilo_gpe_init_sampler_cso(const struct ilo_dev_info
*dev
,
338 const struct pipe_sampler_state
*state
,
339 struct ilo_sampler_cso
*sampler
);
342 ilo_gpe_init_view_surface_null_gen6(const struct ilo_dev_info
*dev
,
343 unsigned width
, unsigned height
,
344 unsigned depth
, unsigned level
,
345 struct ilo_view_surface
*surf
);
348 ilo_gpe_init_view_surface_for_buffer_gen6(const struct ilo_dev_info
*dev
,
349 const struct ilo_buffer
*buf
,
350 unsigned offset
, unsigned size
,
351 unsigned struct_size
,
352 enum pipe_format elem_format
,
353 bool is_rt
, bool render_cache_rw
,
354 struct ilo_view_surface
*surf
);
357 ilo_gpe_init_view_surface_for_texture_gen6(const struct ilo_dev_info
*dev
,
358 const struct ilo_texture
*tex
,
359 enum pipe_format format
,
360 unsigned first_level
,
362 unsigned first_layer
,
364 bool is_rt
, bool render_cache_rw
,
365 struct ilo_view_surface
*surf
);
368 ilo_gpe_init_view_surface_null_gen7(const struct ilo_dev_info
*dev
,
369 unsigned width
, unsigned height
,
370 unsigned depth
, unsigned level
,
371 struct ilo_view_surface
*surf
);
374 ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info
*dev
,
375 const struct ilo_buffer
*buf
,
376 unsigned offset
, unsigned size
,
377 unsigned struct_size
,
378 enum pipe_format elem_format
,
379 bool is_rt
, bool render_cache_rw
,
380 struct ilo_view_surface
*surf
);
383 ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info
*dev
,
384 const struct ilo_texture
*tex
,
385 enum pipe_format format
,
386 unsigned first_level
,
388 unsigned first_layer
,
390 bool is_rt
, bool render_cache_rw
,
391 struct ilo_view_surface
*surf
);
394 ilo_gpe_init_view_surface_null(const struct ilo_dev_info
*dev
,
395 unsigned width
, unsigned height
,
396 unsigned depth
, unsigned level
,
397 struct ilo_view_surface
*surf
)
399 if (dev
->gen
>= ILO_GEN(7)) {
400 ilo_gpe_init_view_surface_null_gen7(dev
,
401 width
, height
, depth
, level
, surf
);
404 ilo_gpe_init_view_surface_null_gen6(dev
,
405 width
, height
, depth
, level
, surf
);
410 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev_info
*dev
,
411 const struct ilo_buffer
*buf
,
412 unsigned offset
, unsigned size
,
413 unsigned struct_size
,
414 enum pipe_format elem_format
,
415 bool is_rt
, bool render_cache_rw
,
416 struct ilo_view_surface
*surf
)
418 if (dev
->gen
>= ILO_GEN(7)) {
419 ilo_gpe_init_view_surface_for_buffer_gen7(dev
, buf
, offset
, size
,
420 struct_size
, elem_format
, is_rt
, render_cache_rw
, surf
);
423 ilo_gpe_init_view_surface_for_buffer_gen6(dev
, buf
, offset
, size
,
424 struct_size
, elem_format
, is_rt
, render_cache_rw
, surf
);
429 ilo_gpe_init_view_surface_for_texture(const struct ilo_dev_info
*dev
,
430 const struct ilo_texture
*tex
,
431 enum pipe_format format
,
432 unsigned first_level
,
434 unsigned first_layer
,
436 bool is_rt
, bool render_cache_rw
,
437 struct ilo_view_surface
*surf
)
439 if (dev
->gen
>= ILO_GEN(7)) {
440 ilo_gpe_init_view_surface_for_texture_gen7(dev
, tex
, format
,
441 first_level
, num_levels
, first_layer
, num_layers
,
442 is_rt
, render_cache_rw
, surf
);
445 ilo_gpe_init_view_surface_for_texture_gen6(dev
, tex
, format
,
446 first_level
, num_levels
, first_layer
, num_layers
,
447 is_rt
, render_cache_rw
, surf
);
452 ilo_gpe_init_zs_surface(const struct ilo_dev_info
*dev
,
453 const struct ilo_texture
*tex
,
454 enum pipe_format format
,
456 unsigned first_layer
, unsigned num_layers
,
457 struct ilo_zs_surface
*zs
);
460 ilo_gpe_init_vs_cso(const struct ilo_dev_info
*dev
,
461 const struct ilo_shader_state
*vs
,
462 struct ilo_shader_cso
*cso
);
465 ilo_gpe_init_gs_cso_gen6(const struct ilo_dev_info
*dev
,
466 const struct ilo_shader_state
*gs
,
467 struct ilo_shader_cso
*cso
);
470 ilo_gpe_init_gs_cso_gen7(const struct ilo_dev_info
*dev
,
471 const struct ilo_shader_state
*gs
,
472 struct ilo_shader_cso
*cso
);
475 ilo_gpe_init_gs_cso(const struct ilo_dev_info
*dev
,
476 const struct ilo_shader_state
*gs
,
477 struct ilo_shader_cso
*cso
)
479 if (dev
->gen
>= ILO_GEN(7)) {
480 ilo_gpe_init_gs_cso_gen7(dev
, gs
, cso
);
483 ilo_gpe_init_gs_cso_gen6(dev
, gs
, cso
);
488 ilo_gpe_init_fs_cso_gen6(const struct ilo_dev_info
*dev
,
489 const struct ilo_shader_state
*fs
,
490 struct ilo_shader_cso
*cso
);
493 ilo_gpe_init_fs_cso_gen7(const struct ilo_dev_info
*dev
,
494 const struct ilo_shader_state
*fs
,
495 struct ilo_shader_cso
*cso
);
498 ilo_gpe_init_fs_cso(const struct ilo_dev_info
*dev
,
499 const struct ilo_shader_state
*fs
,
500 struct ilo_shader_cso
*cso
)
502 if (dev
->gen
>= ILO_GEN(7)) {
503 ilo_gpe_init_fs_cso_gen7(dev
, fs
, cso
);
506 ilo_gpe_init_fs_cso_gen6(dev
, fs
, cso
);
510 #endif /* ILO_GPE_H */