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