2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2014 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>
28 #ifndef ILO_STATE_3D_H
29 #define ILO_STATE_3D_H
31 #include "genhw/genhw.h"
32 #include "pipe/p_state.h"
40 #define ILO_MAX_DRAW_BUFFERS 8
41 #define ILO_MAX_CONST_BUFFERS (1 + 12)
42 #define ILO_MAX_SAMPLER_VIEWS 16
43 #define ILO_MAX_SAMPLERS 16
44 #define ILO_MAX_SO_BINDINGS 64
45 #define ILO_MAX_SO_BUFFERS 4
46 #define ILO_MAX_VIEWPORTS 1
48 #define ILO_MAX_SURFACES 256
53 struct ilo_shader_state
;
56 struct pipe_vertex_buffer states
[PIPE_MAX_ATTRIBS
];
57 uint32_t enabled_mask
;
61 struct pipe_resource
*buffer
;
62 const void *user_buffer
;
66 /* these are not valid until the state is finalized */
67 struct pipe_resource
*hw_resource
;
68 unsigned hw_index_size
;
69 /* an offset to be added to pipe_draw_info::start */
70 int64_t draw_start_offset
;
74 /* VERTEX_ELEMENT_STATE */
79 struct ilo_ve_cso cso
[PIPE_MAX_ATTRIBS
];
82 unsigned instance_divisors
[PIPE_MAX_ATTRIBS
];
83 unsigned vb_mapping
[PIPE_MAX_ATTRIBS
];
86 /* these are not valid until the state is finalized */
87 struct ilo_ve_cso edgeflag_cso
;
88 bool last_cso_edgeflag
;
90 struct ilo_ve_cso nosrc_cso
;
91 bool prepend_nosrc_cso
;
95 struct pipe_stream_output_target
*states
[ILO_MAX_SO_BUFFERS
];
97 unsigned append_bitmask
;
102 struct ilo_viewport_cso
{
104 float m00
, m11
, m22
, m30
, m31
, m32
;
106 /* guardband in NDC space */
107 float min_gbx
, min_gby
, max_gbx
, max_gby
;
109 /* viewport in screen space */
110 float min_x
, min_y
, min_z
;
111 float max_x
, max_y
, max_z
;
114 struct ilo_viewport_state
{
115 struct ilo_viewport_cso cso
[ILO_MAX_VIEWPORTS
];
118 struct pipe_viewport_state viewport0
;
121 struct ilo_scissor_state
{
123 uint32_t payload
[ILO_MAX_VIEWPORTS
* 2];
125 struct pipe_scissor_state scissor0
;
128 struct ilo_rasterizer_clip
{
132 uint32_t can_enable_guardband
;
135 struct ilo_rasterizer_sf
{
140 /* Global Depth Offset Constant/Scale/Clamp */
141 uint32_t dw_depth_offset_const
;
142 uint32_t dw_depth_offset_scale
;
143 uint32_t dw_depth_offset_clamp
;
145 /* Gen8+ 3DSTATE_RASTER */
149 struct ilo_rasterizer_wm
{
152 uint32_t dw_msaa_rast
;
153 uint32_t dw_msaa_disp
;
156 struct ilo_rasterizer_state
{
157 struct pipe_rasterizer_state state
;
159 struct ilo_rasterizer_clip clip
;
160 struct ilo_rasterizer_sf sf
;
161 struct ilo_rasterizer_wm wm
;
164 struct ilo_dsa_state
{
165 /* DEPTH_STENCIL_STATE or Gen8+ 3DSTATE_WM_DEPTH_STENCIL */
168 uint32_t dw_blend_alpha
;
169 uint32_t dw_ps_blend_alpha
;
173 struct ilo_blend_cso
{
178 uint32_t dw_blend_dst_alpha_forced_one
;
181 struct ilo_blend_state
{
182 struct ilo_blend_cso cso
[ILO_MAX_DRAW_BUFFERS
];
185 bool alpha_to_coverage
;
188 uint32_t dw_alpha_mod
;
191 /* a part of 3DSTATE_PS_BLEND */
192 uint32_t dw_ps_blend
;
193 uint32_t dw_ps_blend_dst_alpha_forced_one
;
196 struct ilo_sampler_cso
{
197 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
198 uint32_t payload
[15];
201 uint32_t dw_filter_aniso
;
204 uint32_t dw_wrap_cube
;
212 struct ilo_sampler_state
{
213 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
216 struct ilo_view_surface
{
218 uint32_t payload
[13];
224 struct ilo_view_cso
{
225 struct pipe_sampler_view base
;
227 struct ilo_view_surface surface
;
230 struct ilo_view_state
{
231 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
235 struct ilo_cbuf_cso
{
236 struct pipe_resource
*resource
;
237 struct ilo_view_surface surface
;
240 * this CSO is not so constant because user buffer needs to be uploaded in
241 * finalize_constant_buffers()
243 const void *user_buffer
;
244 unsigned user_buffer_size
;
247 struct ilo_cbuf_state
{
248 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
249 uint32_t enabled_mask
;
252 struct ilo_resource_state
{
253 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
257 struct ilo_surface_cso
{
258 struct pipe_surface base
;
262 struct ilo_view_surface rt
;
263 struct ilo_zs_surface
{
264 uint32_t payload
[12];
265 uint32_t dw_aligned_8x4
;
268 struct intel_bo
*hiz_bo
;
269 struct intel_bo
*separate_s8_bo
;
274 struct ilo_fb_state
{
275 struct pipe_framebuffer_state state
;
277 struct ilo_view_surface null_rt
;
278 struct ilo_zs_surface null_zs
;
280 struct ilo_fb_blend_caps
{
284 bool dst_alpha_forced_one
;
285 } blend_caps
[PIPE_MAX_COLOR_BUFS
];
287 unsigned num_samples
;
290 struct ilo_shader_cso
{
295 * Translate a pipe texture target to the matching hardware surface type.
298 ilo_gpe_gen6_translate_texture(enum pipe_texture_target target
)
302 return GEN6_SURFTYPE_BUFFER
;
303 case PIPE_TEXTURE_1D
:
304 case PIPE_TEXTURE_1D_ARRAY
:
305 return GEN6_SURFTYPE_1D
;
306 case PIPE_TEXTURE_2D
:
307 case PIPE_TEXTURE_RECT
:
308 case PIPE_TEXTURE_2D_ARRAY
:
309 return GEN6_SURFTYPE_2D
;
310 case PIPE_TEXTURE_3D
:
311 return GEN6_SURFTYPE_3D
;
312 case PIPE_TEXTURE_CUBE
:
313 case PIPE_TEXTURE_CUBE_ARRAY
:
314 return GEN6_SURFTYPE_CUBE
;
316 assert(!"unknown texture target");
317 return GEN6_SURFTYPE_BUFFER
;
322 ilo_gpe_init_ve(const struct ilo_dev
*dev
,
324 const struct pipe_vertex_element
*states
,
325 struct ilo_ve_state
*ve
);
328 ilo_gpe_set_ve_edgeflag(const struct ilo_dev
*dev
,
329 struct ilo_ve_cso
*cso
);
332 ilo_gpe_init_ve_nosrc(const struct ilo_dev
*dev
,
333 int comp0
, int comp1
, int comp2
, int comp3
,
334 struct ilo_ve_cso
*cso
);
337 ilo_gpe_set_viewport_cso(const struct ilo_dev
*dev
,
338 const struct pipe_viewport_state
*state
,
339 struct ilo_viewport_cso
*vp
);
342 ilo_gpe_set_scissor(const struct ilo_dev
*dev
,
345 const struct pipe_scissor_state
*states
,
346 struct ilo_scissor_state
*scissor
);
349 ilo_gpe_set_scissor_null(const struct ilo_dev
*dev
,
350 struct ilo_scissor_state
*scissor
);
353 ilo_gpe_init_rasterizer(const struct ilo_dev
*dev
,
354 const struct pipe_rasterizer_state
*state
,
355 struct ilo_rasterizer_state
*rasterizer
);
357 ilo_gpe_init_dsa(const struct ilo_dev
*dev
,
358 const struct pipe_depth_stencil_alpha_state
*state
,
359 struct ilo_dsa_state
*dsa
);
362 ilo_gpe_init_blend(const struct ilo_dev
*dev
,
363 const struct pipe_blend_state
*state
,
364 struct ilo_blend_state
*blend
);
367 ilo_gpe_init_sampler_cso(const struct ilo_dev
*dev
,
368 const struct pipe_sampler_state
*state
,
369 struct ilo_sampler_cso
*sampler
);
372 ilo_gpe_init_view_surface_null(const struct ilo_dev
*dev
,
373 unsigned width
, unsigned height
,
374 unsigned depth
, unsigned level
,
375 struct ilo_view_surface
*surf
);
378 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev
*dev
,
379 const struct ilo_buffer
*buf
,
380 unsigned offset
, unsigned size
,
381 unsigned struct_size
,
382 enum pipe_format elem_format
,
383 bool is_rt
, bool render_cache_rw
,
384 struct ilo_view_surface
*surf
);
387 ilo_gpe_init_view_surface_for_image(const struct ilo_dev
*dev
,
388 const struct ilo_image
*img
,
389 enum pipe_texture_target target
,
390 enum pipe_format format
,
391 unsigned first_level
,
393 unsigned first_layer
,
396 struct ilo_view_surface
*surf
);
399 ilo_gpe_init_zs_surface(const struct ilo_dev
*dev
,
400 const struct ilo_image
*img
,
401 const struct ilo_image
*s8_img
,
402 enum pipe_texture_target target
,
403 enum pipe_format format
, unsigned level
,
404 unsigned first_layer
, unsigned num_layers
,
405 struct ilo_zs_surface
*zs
);
408 ilo_gpe_init_vs_cso(const struct ilo_dev
*dev
,
409 const struct ilo_shader_state
*vs
,
410 struct ilo_shader_cso
*cso
);
413 ilo_gpe_init_gs_cso(const struct ilo_dev
*dev
,
414 const struct ilo_shader_state
*gs
,
415 struct ilo_shader_cso
*cso
);
418 ilo_gpe_init_fs_cso(const struct ilo_dev
*dev
,
419 const struct ilo_shader_state
*fs
,
420 struct ilo_shader_cso
*cso
);
423 ilo_gpe_set_fb(const struct ilo_dev
*dev
,
424 const struct pipe_framebuffer_state
*state
,
425 struct ilo_fb_state
*fb
);
427 #endif /* ILO_STATE_3D_H */