1 /**************************************************************************
2 *
3 * Copyright 2007-2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 /**
30 * The setup code is concerned with point/line/triangle setup and
31 * putting commands/data into the bins.
32 */
33
34
35 #ifndef LP_SETUP_CONTEXT_H
36 #define LP_SETUP_CONTEXT_H
37
38 #include "lp_setup.h"
39 #include "lp_rast.h"
40 #include "lp_scene.h"
41 #include "lp_bld_interp.h" /* for struct lp_shader_input */
42
43 #include "draw/draw_vbuf.h"
44 #include "util/u_rect.h"
45 #include "util/u_pack_color.h"
46
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
54 struct lp_setup_variant;
55
56
57 /** Max number of scenes */
58 /* XXX: make multiple scenes per context work, see lp_setup_rasterize_scene */
59 #define MAX_SCENES 1
60
61
62
63 /**
64 * Point/line/triangle setup context.
65 * Note: "stored" below indicates data which is stored in the bins,
66 * not arbitrary malloc'd memory.
67 *
68 *
69 * Subclass of vbuf_render, plugged directly into the draw module as
70 * the rendering backend.
71 */
72 struct lp_setup_context
73 {
74 struct vbuf_render base;
75
76 struct pipe_context *pipe;
77 struct vertex_info *vertex_info;
78 uint view_index;
79 uint prim;
80 uint vertex_size;
81 uint nr_vertices;
82 uint sprite_coord_enable, sprite_coord_origin;
83 uint vertex_buffer_size;
84 void *vertex_buffer;
85
86 /* Final pipeline stage for draw module. Draw module should
87 * create/install this itself now.
88 */
89 struct draw_stage *vbuf;
90 unsigned num_threads;
91 unsigned scene_idx;
92 struct lp_scene *scenes[MAX_SCENES]; /**< all the scenes */
93 struct lp_scene *scene; /**< current scene being built */
94
95 struct lp_fence *last_fence;
96 struct llvmpipe_query *active_queries[LP_MAX_ACTIVE_BINNED_QUERIES];
97 unsigned active_binned_queries;
98
99 unsigned flatshade_first:1;
100 unsigned ccw_is_frontface:1;
101 unsigned scissor_test:1;
102 unsigned point_tri_clip:1;
103 unsigned point_size_per_vertex:1;
104 unsigned legacy_points:1;
105 unsigned rasterizer_discard:1;
106 unsigned permit_linear_rasterizer:1;
107 unsigned multisample:1;
108 unsigned rectangular_lines:1;
109 unsigned cullmode:2; /**< PIPE_FACE_x */
110 unsigned bottom_edge_rule;
111 float pixel_offset;
112 float line_width;
113 float point_size;
114 int8_t psize_slot;
115 int8_t viewport_index_slot;
116 int8_t layer_slot;
117 int8_t face_slot;
118
119 struct pipe_framebuffer_state fb;
120 struct u_rect framebuffer;
121 struct u_rect scissors[PIPE_MAX_VIEWPORTS];
122 struct u_rect vpwh;
123 struct u_rect draw_regions[PIPE_MAX_VIEWPORTS]; /* intersection of fb & scissor */
124 struct lp_jit_viewport viewports[PIPE_MAX_VIEWPORTS];
125
126 struct {
127 unsigned flags;
128 union util_color color_val[PIPE_MAX_COLOR_BUFS];
129 uint64_t zsmask;
130 uint64_t zsvalue; /**< lp_rast_clear_zstencil() cmd */
131 } clear;
132
133 enum setup_state {
134 SETUP_FLUSHED, /**< scene is null */
135 SETUP_CLEARED, /**< scene exists but has only clears */
136 SETUP_ACTIVE /**< scene exists and has at least one draw/query */
137 } state;
138
139 struct {
140 const struct lp_rast_state *stored; /**< what's in the scene */
141 struct lp_rast_state current; /**< currently set state */
142 struct pipe_resource *current_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
143 unsigned current_tex_num;
144 } fs;
145
146 /** fragment shader constants */
147 struct {
148 struct pipe_constant_buffer current;
149 unsigned stored_size;
150 const void *stored_data;
151 } constants[LP_MAX_TGSI_CONST_BUFFERS];
152
153 /** fragment shader buffers */
154 struct {
155 struct pipe_shader_buffer current;
156 } ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
157
158 struct {
159 struct pipe_image_view current;
160 } images[LP_MAX_TGSI_SHADER_IMAGES];
161
162 struct {
163 struct pipe_blend_color current;
164 uint8_t *stored;
165 } blend_color;
166
167
168 struct {
169 const struct lp_setup_variant *variant;
170 } setup;
171
172 unsigned dirty; /**< bitmask of LP_SETUP_NEW_x bits */
173
174 void (*point)( struct lp_setup_context *,
175 const float (*v0)[4]);
176
177 void (*line)( struct lp_setup_context *,
178 const float (*v0)[4],
179 const float (*v1)[4]);
180
181 void (*triangle)( struct lp_setup_context *,
182 const float (*v0)[4],
183 const float (*v1)[4],
184 const float (*v2)[4]);
185
186 boolean
187 (*rect)( struct lp_setup_context *,
188 const float (*v0)[4],
189 const float (*v1)[4],
190 const float (*v2)[4],
191 const float (*v3)[4],
192 const float (*v4)[4],
193 const float (*v5)[4]);
194 };
195
196 static inline void
scissor_planes_needed(boolean scis_planes[4],const struct u_rect * bbox,const struct u_rect * scissor)197 scissor_planes_needed(boolean scis_planes[4], const struct u_rect *bbox,
198 const struct u_rect *scissor)
199 {
200 /* left */
201 scis_planes[0] = (bbox->x0 < scissor->x0);
202 /* right */
203 scis_planes[1] = (bbox->x1 > scissor->x1);
204 /* top */
205 scis_planes[2] = (bbox->y0 < scissor->y0);
206 /* bottom */
207 scis_planes[3] = (bbox->y1 > scissor->y1);
208 }
209
210 void
211 lp_setup_add_scissor_planes(const struct u_rect *scissor,
212 struct lp_rast_plane *plane_s,
213 boolean s_planes[4], bool multisample);
214
215 void lp_setup_choose_triangle( struct lp_setup_context *setup );
216 void lp_setup_choose_line( struct lp_setup_context *setup );
217 void lp_setup_choose_point( struct lp_setup_context *setup );
218 void lp_setup_choose_rect( struct lp_setup_context *setup );
219
220 void lp_setup_init_vbuf(struct lp_setup_context *setup);
221
222 boolean lp_setup_update_state( struct lp_setup_context *setup,
223 boolean update_scene);
224
225 void lp_setup_destroy( struct lp_setup_context *setup );
226
227 boolean lp_setup_flush_and_restart(struct lp_setup_context *setup);
228
229 boolean
230 lp_setup_whole_tile(struct lp_setup_context *setup,
231 const struct lp_rast_shader_inputs *inputs,
232 int tx, int ty);
233
234 boolean
235 lp_setup_is_blit(const struct lp_setup_context *setup,
236 const struct lp_rast_shader_inputs *inputs);
237
238 void
239 lp_setup_print_triangle(struct lp_setup_context *setup,
240 const float (*v0)[4],
241 const float (*v1)[4],
242 const float (*v2)[4]);
243
244 void
245 lp_setup_print_vertex(struct lp_setup_context *setup,
246 const char *name,
247 const float (*v)[4]);
248
249 void
250 lp_rect_cw(struct lp_setup_context *setup,
251 const float (*v0)[4],
252 const float (*v1)[4],
253 const float (*v2)[4],
254 boolean frontfacing);
255
256 void
257 lp_setup_triangle_ccw( struct lp_setup_context *setup,
258 const float (*v0)[4],
259 const float (*v1)[4],
260 const float (*v2)[4],
261 boolean front );
262
263 struct lp_rast_triangle *
264 lp_setup_alloc_triangle(struct lp_scene *scene,
265 unsigned num_inputs,
266 unsigned nr_planes,
267 unsigned *tri_size);
268
269 struct lp_rast_rectangle *
270 lp_setup_alloc_rectangle(struct lp_scene *scene,
271 unsigned nr_inputs);
272
273 boolean
274 lp_setup_analyse_triangles(struct lp_setup_context *setup,
275 const void *vb,
276 int stride,
277 int nr);
278
279 boolean
280 lp_setup_bin_triangle(struct lp_setup_context *setup,
281 struct lp_rast_triangle *tri,
282 const struct u_rect *bboxorig,
283 const struct u_rect *bbox,
284 int nr_planes,
285 unsigned scissor_index);
286
287 boolean
288 lp_setup_bin_rectangle(struct lp_setup_context *setup,
289 struct lp_rast_rectangle *rect);
290
291
292 #endif
293