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"
36 #include "ilo_state_zs.h"
41 #define ILO_MAX_DRAW_BUFFERS 8
42 #define ILO_MAX_CONST_BUFFERS (1 + 12)
43 #define ILO_MAX_SAMPLER_VIEWS 16
44 #define ILO_MAX_SAMPLERS 16
45 #define ILO_MAX_SO_BINDINGS 64
46 #define ILO_MAX_SO_BUFFERS 4
47 #define ILO_MAX_VIEWPORTS 1
49 #define ILO_MAX_SURFACES 256
54 struct ilo_shader_state
;
57 struct pipe_vertex_buffer states
[PIPE_MAX_ATTRIBS
];
58 uint32_t enabled_mask
;
62 struct pipe_resource
*buffer
;
63 const void *user_buffer
;
67 /* these are not valid until the state is finalized */
68 struct pipe_resource
*hw_resource
;
69 unsigned hw_index_size
;
70 /* an offset to be added to pipe_draw_info::start */
71 int64_t draw_start_offset
;
75 /* VERTEX_ELEMENT_STATE */
80 struct ilo_ve_cso cso
[PIPE_MAX_ATTRIBS
];
83 unsigned instance_divisors
[PIPE_MAX_ATTRIBS
];
84 unsigned vb_mapping
[PIPE_MAX_ATTRIBS
];
87 /* these are not valid until the state is finalized */
88 struct ilo_ve_cso edgeflag_cso
;
89 bool last_cso_edgeflag
;
91 struct ilo_ve_cso nosrc_cso
;
92 bool prepend_nosrc_cso
;
96 struct pipe_stream_output_target
*states
[ILO_MAX_SO_BUFFERS
];
98 unsigned append_bitmask
;
103 struct ilo_viewport_cso
{
105 float m00
, m11
, m22
, m30
, m31
, m32
;
107 /* guardband in NDC space */
108 float min_gbx
, min_gby
, max_gbx
, max_gby
;
110 /* viewport in screen space */
111 float min_x
, min_y
, min_z
;
112 float max_x
, max_y
, max_z
;
115 struct ilo_viewport_state
{
116 struct ilo_viewport_cso cso
[ILO_MAX_VIEWPORTS
];
119 struct pipe_viewport_state viewport0
;
122 struct ilo_scissor_state
{
124 uint32_t payload
[ILO_MAX_VIEWPORTS
* 2];
126 struct pipe_scissor_state scissor0
;
129 struct ilo_rasterizer_clip
{
133 uint32_t can_enable_guardband
;
136 struct ilo_rasterizer_sf
{
141 /* Global Depth Offset Constant/Scale/Clamp */
142 uint32_t dw_depth_offset_const
;
143 uint32_t dw_depth_offset_scale
;
144 uint32_t dw_depth_offset_clamp
;
146 /* Gen8+ 3DSTATE_RASTER */
150 struct ilo_rasterizer_wm
{
153 uint32_t dw_msaa_rast
;
154 uint32_t dw_msaa_disp
;
157 struct ilo_rasterizer_state
{
158 struct pipe_rasterizer_state state
;
160 struct ilo_rasterizer_clip clip
;
161 struct ilo_rasterizer_sf sf
;
162 struct ilo_rasterizer_wm wm
;
165 struct ilo_dsa_state
{
166 /* DEPTH_STENCIL_STATE or Gen8+ 3DSTATE_WM_DEPTH_STENCIL */
169 uint32_t dw_blend_alpha
;
170 uint32_t dw_ps_blend_alpha
;
174 struct ilo_blend_cso
{
179 uint32_t dw_blend_dst_alpha_forced_one
;
182 struct ilo_blend_state
{
183 struct ilo_blend_cso cso
[ILO_MAX_DRAW_BUFFERS
];
186 bool alpha_to_coverage
;
189 uint32_t dw_alpha_mod
;
192 /* a part of 3DSTATE_PS_BLEND */
193 uint32_t dw_ps_blend
;
194 uint32_t dw_ps_blend_dst_alpha_forced_one
;
197 struct ilo_sampler_cso
{
198 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
199 uint32_t payload
[15];
202 uint32_t dw_filter_aniso
;
205 uint32_t dw_wrap_cube
;
213 struct ilo_sampler_state
{
214 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
217 struct ilo_view_surface
{
219 uint32_t payload
[13];
225 struct ilo_view_cso
{
226 struct pipe_sampler_view base
;
228 struct ilo_view_surface surface
;
231 struct ilo_view_state
{
232 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
236 struct ilo_cbuf_cso
{
237 struct pipe_resource
*resource
;
238 struct ilo_view_surface surface
;
241 * this CSO is not so constant because user buffer needs to be uploaded in
242 * finalize_constant_buffers()
244 const void *user_buffer
;
245 unsigned user_buffer_size
;
248 struct ilo_cbuf_state
{
249 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
250 uint32_t enabled_mask
;
253 struct ilo_resource_state
{
254 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
258 struct ilo_surface_cso
{
259 struct pipe_surface base
;
263 struct ilo_view_surface rt
;
264 struct ilo_state_zs zs
;
268 struct ilo_fb_state
{
269 struct pipe_framebuffer_state state
;
271 struct ilo_view_surface null_rt
;
272 struct ilo_state_zs null_zs
;
274 struct ilo_fb_blend_caps
{
278 bool dst_alpha_forced_one
;
279 } blend_caps
[PIPE_MAX_COLOR_BUFS
];
281 unsigned num_samples
;
284 struct ilo_shader_cso
{
289 * Translate a pipe texture target to the matching hardware surface type.
292 ilo_gpe_gen6_translate_texture(enum pipe_texture_target target
)
296 return GEN6_SURFTYPE_BUFFER
;
297 case PIPE_TEXTURE_1D
:
298 case PIPE_TEXTURE_1D_ARRAY
:
299 return GEN6_SURFTYPE_1D
;
300 case PIPE_TEXTURE_2D
:
301 case PIPE_TEXTURE_RECT
:
302 case PIPE_TEXTURE_2D_ARRAY
:
303 return GEN6_SURFTYPE_2D
;
304 case PIPE_TEXTURE_3D
:
305 return GEN6_SURFTYPE_3D
;
306 case PIPE_TEXTURE_CUBE
:
307 case PIPE_TEXTURE_CUBE_ARRAY
:
308 return GEN6_SURFTYPE_CUBE
;
310 assert(!"unknown texture target");
311 return GEN6_SURFTYPE_BUFFER
;
316 ilo_gpe_init_ve(const struct ilo_dev
*dev
,
318 const struct pipe_vertex_element
*states
,
319 struct ilo_ve_state
*ve
);
322 ilo_gpe_set_ve_edgeflag(const struct ilo_dev
*dev
,
323 struct ilo_ve_cso
*cso
);
326 ilo_gpe_init_ve_nosrc(const struct ilo_dev
*dev
,
327 int comp0
, int comp1
, int comp2
, int comp3
,
328 struct ilo_ve_cso
*cso
);
331 ilo_gpe_set_viewport_cso(const struct ilo_dev
*dev
,
332 const struct pipe_viewport_state
*state
,
333 struct ilo_viewport_cso
*vp
);
336 ilo_gpe_set_scissor(const struct ilo_dev
*dev
,
339 const struct pipe_scissor_state
*states
,
340 struct ilo_scissor_state
*scissor
);
343 ilo_gpe_set_scissor_null(const struct ilo_dev
*dev
,
344 struct ilo_scissor_state
*scissor
);
347 ilo_gpe_init_rasterizer(const struct ilo_dev
*dev
,
348 const struct pipe_rasterizer_state
*state
,
349 struct ilo_rasterizer_state
*rasterizer
);
351 ilo_gpe_init_dsa(const struct ilo_dev
*dev
,
352 const struct pipe_depth_stencil_alpha_state
*state
,
353 struct ilo_dsa_state
*dsa
);
356 ilo_gpe_init_blend(const struct ilo_dev
*dev
,
357 const struct pipe_blend_state
*state
,
358 struct ilo_blend_state
*blend
);
361 ilo_gpe_init_sampler_cso(const struct ilo_dev
*dev
,
362 const struct pipe_sampler_state
*state
,
363 struct ilo_sampler_cso
*sampler
);
366 ilo_gpe_init_view_surface_null(const struct ilo_dev
*dev
,
367 unsigned width
, unsigned height
,
368 unsigned depth
, unsigned level
,
369 struct ilo_view_surface
*surf
);
372 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev
*dev
,
373 const struct ilo_buffer
*buf
,
374 unsigned offset
, unsigned size
,
375 unsigned struct_size
,
376 enum pipe_format elem_format
,
378 struct ilo_view_surface
*surf
);
381 ilo_gpe_init_view_surface_for_image(const struct ilo_dev
*dev
,
382 const struct ilo_image
*img
,
383 enum pipe_format format
,
384 unsigned first_level
,
386 unsigned first_layer
,
389 struct ilo_view_surface
*surf
);
392 ilo_gpe_init_vs_cso(const struct ilo_dev
*dev
,
393 const struct ilo_shader_state
*vs
,
394 struct ilo_shader_cso
*cso
);
397 ilo_gpe_init_gs_cso(const struct ilo_dev
*dev
,
398 const struct ilo_shader_state
*gs
,
399 struct ilo_shader_cso
*cso
);
402 ilo_gpe_init_fs_cso(const struct ilo_dev
*dev
,
403 const struct ilo_shader_state
*fs
,
404 struct ilo_shader_cso
*cso
);
407 ilo_gpe_set_fb(const struct ilo_dev
*dev
,
408 const struct pipe_framebuffer_state
*state
,
409 struct ilo_fb_state
*fb
);
411 #endif /* ILO_STATE_3D_H */