1 /**************************************************************************
3 * Copyright 2007-2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * The setup code is concerned with point/line/triangle setup and
31 * putting commands/data into the bins.
35 #ifndef LP_SETUP_CONTEXT_H
36 #define LP_SETUP_CONTEXT_H
41 #include "lp_bld_interp.h" /* for struct lp_shader_input */
43 #include "draw/draw_vbuf.h"
44 #include "util/u_rect.h"
45 #include "util/u_pack_color.h"
47 #define LP_SETUP_NEW_FS 0x01
48 #define LP_SETUP_NEW_CONSTANTS 0x02
49 #define LP_SETUP_NEW_BLEND_COLOR 0x04
50 #define LP_SETUP_NEW_SCISSOR 0x08
51 #define LP_SETUP_NEW_VIEWPORTS 0x10
52 #define LP_SETUP_NEW_SSBOS 0x20
53 #define LP_SETUP_NEW_IMAGES 0x40
55 struct lp_setup_variant
;
58 /** Max number of scenes */
59 /* XXX: make multiple scenes per context work, see lp_setup_rasterize_scene */
65 * Point/line/triangle setup context.
66 * Note: "stored" below indicates data which is stored in the bins,
67 * not arbitrary malloc'd memory.
70 * Subclass of vbuf_render, plugged directly into the draw module as
71 * the rendering backend.
73 struct lp_setup_context
75 struct vbuf_render base
;
77 struct pipe_context
*pipe
;
78 struct vertex_info
*vertex_info
;
82 uint sprite_coord_enable
, sprite_coord_origin
;
83 uint vertex_buffer_size
;
86 /* Final pipeline stage for draw module. Draw module should
87 * create/install this itself now.
89 struct draw_stage
*vbuf
;
92 struct lp_scene
*scenes
[MAX_SCENES
]; /**< all the scenes */
93 struct lp_scene
*scene
; /**< current scene being built */
95 struct lp_fence
*last_fence
;
96 struct llvmpipe_query
*active_queries
[LP_MAX_ACTIVE_BINNED_QUERIES
];
97 unsigned active_binned_queries
;
99 boolean flatshade_first
;
100 boolean ccw_is_frontface
;
101 boolean scissor_test
;
102 boolean point_size_per_vertex
;
103 boolean rasterizer_discard
;
106 unsigned bottom_edge_rule
;
111 int8_t viewport_index_slot
;
115 struct pipe_framebuffer_state fb
;
116 struct u_rect framebuffer
;
117 struct u_rect scissors
[PIPE_MAX_VIEWPORTS
];
118 struct u_rect draw_regions
[PIPE_MAX_VIEWPORTS
]; /* intersection of fb & scissor */
119 struct lp_jit_viewport viewports
[PIPE_MAX_VIEWPORTS
];
123 union util_color color_val
[PIPE_MAX_COLOR_BUFS
];
125 uint64_t zsvalue
; /**< lp_rast_clear_zstencil() cmd */
129 SETUP_FLUSHED
, /**< scene is null */
130 SETUP_CLEARED
, /**< scene exists but has only clears */
131 SETUP_ACTIVE
/**< scene exists and has at least one draw/query */
135 const struct lp_rast_state
*stored
; /**< what's in the scene */
136 struct lp_rast_state current
; /**< currently set state */
137 struct pipe_resource
*current_tex
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
138 unsigned current_tex_num
;
141 /** fragment shader constants */
143 struct pipe_constant_buffer current
;
144 unsigned stored_size
;
145 const void *stored_data
;
146 } constants
[LP_MAX_TGSI_CONST_BUFFERS
];
148 /** fragment shader buffers */
150 struct pipe_shader_buffer current
;
151 } ssbos
[LP_MAX_TGSI_SHADER_BUFFERS
];
154 struct pipe_image_view current
;
155 } images
[LP_MAX_TGSI_SHADER_IMAGES
];
158 struct pipe_blend_color current
;
164 const struct lp_setup_variant
*variant
;
167 unsigned dirty
; /**< bitmask of LP_SETUP_NEW_x bits */
169 void (*point
)( struct lp_setup_context
*,
170 const float (*v0
)[4]);
172 void (*line
)( struct lp_setup_context
*,
173 const float (*v0
)[4],
174 const float (*v1
)[4]);
176 void (*triangle
)( struct lp_setup_context
*,
177 const float (*v0
)[4],
178 const float (*v1
)[4],
179 const float (*v2
)[4]);
183 scissor_planes_needed(boolean scis_planes
[4], const struct u_rect
*bbox
,
184 const struct u_rect
*scissor
)
187 scis_planes
[0] = (bbox
->x0
< scissor
->x0
);
189 scis_planes
[1] = (bbox
->x1
> scissor
->x1
);
191 scis_planes
[2] = (bbox
->y0
< scissor
->y0
);
193 scis_planes
[3] = (bbox
->y1
> scissor
->y1
);
197 void lp_setup_choose_triangle( struct lp_setup_context
*setup
);
198 void lp_setup_choose_line( struct lp_setup_context
*setup
);
199 void lp_setup_choose_point( struct lp_setup_context
*setup
);
201 void lp_setup_init_vbuf(struct lp_setup_context
*setup
);
203 boolean
lp_setup_update_state( struct lp_setup_context
*setup
,
204 boolean update_scene
);
206 void lp_setup_destroy( struct lp_setup_context
*setup
);
208 boolean
lp_setup_flush_and_restart(struct lp_setup_context
*setup
);
211 lp_setup_print_triangle(struct lp_setup_context
*setup
,
212 const float (*v0
)[4],
213 const float (*v1
)[4],
214 const float (*v2
)[4]);
217 lp_setup_print_vertex(struct lp_setup_context
*setup
,
219 const float (*v
)[4]);
222 struct lp_rast_triangle
*
223 lp_setup_alloc_triangle(struct lp_scene
*scene
,
229 lp_setup_bin_triangle(struct lp_setup_context
*setup
,
230 struct lp_rast_triangle
*tri
,
231 const struct u_rect
*bboxorig
,
232 const struct u_rect
*bbox
,
234 unsigned scissor_index
);