1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2007-2009 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci/**
30bf215546Sopenharmony_ci * The setup code is concerned with point/line/triangle setup and
31bf215546Sopenharmony_ci * putting commands/data into the bins.
32bf215546Sopenharmony_ci */
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#ifndef LP_SETUP_CONTEXT_H
36bf215546Sopenharmony_ci#define LP_SETUP_CONTEXT_H
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#include "lp_setup.h"
39bf215546Sopenharmony_ci#include "lp_rast.h"
40bf215546Sopenharmony_ci#include "lp_scene.h"
41bf215546Sopenharmony_ci#include "lp_bld_interp.h"	/* for struct lp_shader_input */
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci#include "draw/draw_vbuf.h"
44bf215546Sopenharmony_ci#include "util/u_rect.h"
45bf215546Sopenharmony_ci#include "util/u_pack_color.h"
46bf215546Sopenharmony_ci#include "util/slab.h"
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci#define LP_SETUP_NEW_FS          0x01
49bf215546Sopenharmony_ci#define LP_SETUP_NEW_CONSTANTS   0x02
50bf215546Sopenharmony_ci#define LP_SETUP_NEW_BLEND_COLOR 0x04
51bf215546Sopenharmony_ci#define LP_SETUP_NEW_SCISSOR     0x08
52bf215546Sopenharmony_ci#define LP_SETUP_NEW_VIEWPORTS   0x10
53bf215546Sopenharmony_ci#define LP_SETUP_NEW_SSBOS       0x20
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cistruct lp_setup_variant;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci/** Max number of scenes */
59bf215546Sopenharmony_ci#define INITIAL_SCENES 4
60bf215546Sopenharmony_ci#define MAX_SCENES 64
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci/**
65bf215546Sopenharmony_ci * Point/line/triangle setup context.
66bf215546Sopenharmony_ci * Note: "stored" below indicates data which is stored in the bins,
67bf215546Sopenharmony_ci * not arbitrary malloc'd memory.
68bf215546Sopenharmony_ci *
69bf215546Sopenharmony_ci *
70bf215546Sopenharmony_ci * Subclass of vbuf_render, plugged directly into the draw module as
71bf215546Sopenharmony_ci * the rendering backend.
72bf215546Sopenharmony_ci */
73bf215546Sopenharmony_cistruct lp_setup_context
74bf215546Sopenharmony_ci{
75bf215546Sopenharmony_ci   struct vbuf_render base;
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci   struct pipe_context *pipe;
78bf215546Sopenharmony_ci   struct vertex_info *vertex_info;
79bf215546Sopenharmony_ci   uint view_index;
80bf215546Sopenharmony_ci   uint prim;
81bf215546Sopenharmony_ci   uint vertex_size;
82bf215546Sopenharmony_ci   uint nr_vertices;
83bf215546Sopenharmony_ci   uint sprite_coord_enable, sprite_coord_origin;
84bf215546Sopenharmony_ci   uint vertex_buffer_size;
85bf215546Sopenharmony_ci   void *vertex_buffer;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   /* Final pipeline stage for draw module.  Draw module should
88bf215546Sopenharmony_ci    * create/install this itself now.
89bf215546Sopenharmony_ci    */
90bf215546Sopenharmony_ci   struct draw_stage *vbuf;
91bf215546Sopenharmony_ci   unsigned num_threads;
92bf215546Sopenharmony_ci   unsigned scene_idx;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   struct slab_mempool scene_slab;
95bf215546Sopenharmony_ci   int num_active_scenes;
96bf215546Sopenharmony_ci   struct lp_scene *scenes[MAX_SCENES];  /**< all the scenes */
97bf215546Sopenharmony_ci   struct lp_scene *scene;               /**< current scene being built */
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   struct llvmpipe_query *active_queries[LP_MAX_ACTIVE_BINNED_QUERIES];
100bf215546Sopenharmony_ci   unsigned active_binned_queries;
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   unsigned flatshade_first:1;
103bf215546Sopenharmony_ci   unsigned ccw_is_frontface:1;
104bf215546Sopenharmony_ci   unsigned scissor_test:1;
105bf215546Sopenharmony_ci   unsigned point_tri_clip:1;
106bf215546Sopenharmony_ci   unsigned point_size_per_vertex:1;
107bf215546Sopenharmony_ci   unsigned legacy_points:1;
108bf215546Sopenharmony_ci   unsigned rasterizer_discard:1;
109bf215546Sopenharmony_ci   unsigned permit_linear_rasterizer:1;
110bf215546Sopenharmony_ci   unsigned multisample:1;
111bf215546Sopenharmony_ci   unsigned rectangular_lines:1;
112bf215546Sopenharmony_ci   unsigned cullmode:2; /**< PIPE_FACE_x */
113bf215546Sopenharmony_ci   unsigned bottom_edge_rule;
114bf215546Sopenharmony_ci   float pixel_offset;
115bf215546Sopenharmony_ci   float line_width;
116bf215546Sopenharmony_ci   float point_size;
117bf215546Sopenharmony_ci   int8_t psize_slot;
118bf215546Sopenharmony_ci   int8_t viewport_index_slot;
119bf215546Sopenharmony_ci   int8_t layer_slot;
120bf215546Sopenharmony_ci   int8_t face_slot;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci   struct pipe_framebuffer_state fb;
123bf215546Sopenharmony_ci   struct u_rect framebuffer;
124bf215546Sopenharmony_ci   struct u_rect scissors[PIPE_MAX_VIEWPORTS];
125bf215546Sopenharmony_ci   struct u_rect vpwh;
126bf215546Sopenharmony_ci   struct u_rect draw_regions[PIPE_MAX_VIEWPORTS];   /* intersection of fb & scissor */
127bf215546Sopenharmony_ci   struct lp_jit_viewport viewports[PIPE_MAX_VIEWPORTS];
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   struct {
130bf215546Sopenharmony_ci      unsigned flags;
131bf215546Sopenharmony_ci      union util_color color_val[PIPE_MAX_COLOR_BUFS];
132bf215546Sopenharmony_ci      uint64_t zsmask;
133bf215546Sopenharmony_ci      uint64_t zsvalue;               /**< lp_rast_clear_zstencil() cmd */
134bf215546Sopenharmony_ci   } clear;
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci   enum setup_state {
137bf215546Sopenharmony_ci      SETUP_FLUSHED,    /**< scene is null */
138bf215546Sopenharmony_ci      SETUP_CLEARED,    /**< scene exists but has only clears */
139bf215546Sopenharmony_ci      SETUP_ACTIVE      /**< scene exists and has at least one draw/query */
140bf215546Sopenharmony_ci   } state;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   struct {
143bf215546Sopenharmony_ci      const struct lp_rast_state *stored; /**< what's in the scene */
144bf215546Sopenharmony_ci      struct lp_rast_state current;  /**< currently set state */
145bf215546Sopenharmony_ci      struct pipe_resource *current_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
146bf215546Sopenharmony_ci      unsigned current_tex_num;
147bf215546Sopenharmony_ci   } fs;
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci   /** fragment shader constants */
150bf215546Sopenharmony_ci   struct {
151bf215546Sopenharmony_ci      struct pipe_constant_buffer current;
152bf215546Sopenharmony_ci      unsigned stored_size;
153bf215546Sopenharmony_ci      const void *stored_data;
154bf215546Sopenharmony_ci   } constants[LP_MAX_TGSI_CONST_BUFFERS];
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   /** fragment shader buffers */
157bf215546Sopenharmony_ci   struct {
158bf215546Sopenharmony_ci      struct pipe_shader_buffer current;
159bf215546Sopenharmony_ci   } ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
160bf215546Sopenharmony_ci   uint32_t ssbo_write_mask;
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci   struct {
163bf215546Sopenharmony_ci      struct pipe_image_view current;
164bf215546Sopenharmony_ci   } images[LP_MAX_TGSI_SHADER_IMAGES];
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ci   struct {
167bf215546Sopenharmony_ci      struct pipe_blend_color current;
168bf215546Sopenharmony_ci      uint8_t *stored;
169bf215546Sopenharmony_ci   } blend_color;
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci   struct {
172bf215546Sopenharmony_ci      const struct lp_setup_variant *variant;
173bf215546Sopenharmony_ci   } setup;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   unsigned dirty;   /**< bitmask of LP_SETUP_NEW_x bits */
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   void (*point)(struct lp_setup_context *,
178bf215546Sopenharmony_ci                 const float (*v0)[4]);
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci   void (*line)(struct lp_setup_context *,
181bf215546Sopenharmony_ci                const float (*v0)[4],
182bf215546Sopenharmony_ci                const float (*v1)[4]);
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci   void (*triangle)(struct lp_setup_context *,
185bf215546Sopenharmony_ci                    const float (*v0)[4],
186bf215546Sopenharmony_ci                    const float (*v1)[4],
187bf215546Sopenharmony_ci                    const float (*v2)[4]);
188bf215546Sopenharmony_ci
189bf215546Sopenharmony_ci   boolean
190bf215546Sopenharmony_ci   (*rect)(struct lp_setup_context *,
191bf215546Sopenharmony_ci           const float (*v0)[4],
192bf215546Sopenharmony_ci           const float (*v1)[4],
193bf215546Sopenharmony_ci           const float (*v2)[4],
194bf215546Sopenharmony_ci           const float (*v3)[4],
195bf215546Sopenharmony_ci           const float (*v4)[4],
196bf215546Sopenharmony_ci           const float (*v5)[4]);
197bf215546Sopenharmony_ci};
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_cistatic inline void
201bf215546Sopenharmony_ciscissor_planes_needed(boolean scis_planes[4], const struct u_rect *bbox,
202bf215546Sopenharmony_ci                      const struct u_rect *scissor)
203bf215546Sopenharmony_ci{
204bf215546Sopenharmony_ci   /* left */
205bf215546Sopenharmony_ci   scis_planes[0] = (bbox->x0 < scissor->x0);
206bf215546Sopenharmony_ci   /* right */
207bf215546Sopenharmony_ci   scis_planes[1] = (bbox->x1 > scissor->x1);
208bf215546Sopenharmony_ci   /* top */
209bf215546Sopenharmony_ci   scis_planes[2] = (bbox->y0 < scissor->y0);
210bf215546Sopenharmony_ci   /* bottom */
211bf215546Sopenharmony_ci   scis_planes[3] = (bbox->y1 > scissor->y1);
212bf215546Sopenharmony_ci}
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_civoid
216bf215546Sopenharmony_cilp_setup_add_scissor_planes(const struct u_rect *scissor,
217bf215546Sopenharmony_ci                            struct lp_rast_plane *plane_s,
218bf215546Sopenharmony_ci                            boolean s_planes[4], bool multisample);
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_civoid
221bf215546Sopenharmony_cilp_setup_choose_triangle(struct lp_setup_context *setup);
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_civoid
224bf215546Sopenharmony_cilp_setup_choose_line(struct lp_setup_context *setup);
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_civoid
227bf215546Sopenharmony_cilp_setup_choose_point(struct lp_setup_context *setup);
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_civoid
230bf215546Sopenharmony_cilp_setup_choose_rect(struct lp_setup_context *setup);
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_civoid
233bf215546Sopenharmony_cilp_setup_init_vbuf(struct lp_setup_context *setup);
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ciboolean
236bf215546Sopenharmony_cilp_setup_update_state(struct lp_setup_context *setup,
237bf215546Sopenharmony_ci                      boolean update_scene);
238bf215546Sopenharmony_ci
239bf215546Sopenharmony_civoid
240bf215546Sopenharmony_cilp_setup_destroy(struct lp_setup_context *setup);
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ciboolean
243bf215546Sopenharmony_cilp_setup_flush_and_restart(struct lp_setup_context *setup);
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ciboolean
246bf215546Sopenharmony_cilp_setup_whole_tile(struct lp_setup_context *setup,
247bf215546Sopenharmony_ci                    const struct lp_rast_shader_inputs *inputs,
248bf215546Sopenharmony_ci                    int tx, int ty, boolean opaque);
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ciboolean
251bf215546Sopenharmony_cilp_setup_is_blit(const struct lp_setup_context *setup,
252bf215546Sopenharmony_ci                 const struct lp_rast_shader_inputs *inputs);
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_civoid
255bf215546Sopenharmony_cilp_setup_print_triangle(struct lp_setup_context *setup,
256bf215546Sopenharmony_ci                        const float (*v0)[4],
257bf215546Sopenharmony_ci                        const float (*v1)[4],
258bf215546Sopenharmony_ci                        const float (*v2)[4]);
259bf215546Sopenharmony_ci
260bf215546Sopenharmony_civoid
261bf215546Sopenharmony_cilp_setup_print_vertex(struct lp_setup_context *setup,
262bf215546Sopenharmony_ci                      const char *name,
263bf215546Sopenharmony_ci                      const float (*v)[4]);
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_civoid
266bf215546Sopenharmony_cilp_rect_cw(struct lp_setup_context *setup,
267bf215546Sopenharmony_ci           const float (*v0)[4],
268bf215546Sopenharmony_ci           const float (*v1)[4],
269bf215546Sopenharmony_ci           const float (*v2)[4],
270bf215546Sopenharmony_ci           boolean frontfacing);
271bf215546Sopenharmony_ci
272bf215546Sopenharmony_civoid
273bf215546Sopenharmony_cilp_setup_triangle_ccw(struct lp_setup_context *setup,
274bf215546Sopenharmony_ci                      const float (*v0)[4],
275bf215546Sopenharmony_ci                      const float (*v1)[4],
276bf215546Sopenharmony_ci                      const float (*v2)[4],
277bf215546Sopenharmony_ci                      boolean front);
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_cistruct lp_rast_triangle *
280bf215546Sopenharmony_cilp_setup_alloc_triangle(struct lp_scene *scene,
281bf215546Sopenharmony_ci                        unsigned num_inputs,
282bf215546Sopenharmony_ci                        unsigned nr_planes,
283bf215546Sopenharmony_ci                        unsigned *tri_size);
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_cistruct lp_rast_rectangle *
286bf215546Sopenharmony_cilp_setup_alloc_rectangle(struct lp_scene *scene,
287bf215546Sopenharmony_ci                         unsigned nr_inputs);
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_ciboolean
290bf215546Sopenharmony_cilp_setup_analyse_triangles(struct lp_setup_context *setup,
291bf215546Sopenharmony_ci                           const void *vb,
292bf215546Sopenharmony_ci                           int stride,
293bf215546Sopenharmony_ci                           int nr);
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ciboolean
296bf215546Sopenharmony_cilp_setup_bin_triangle(struct lp_setup_context *setup,
297bf215546Sopenharmony_ci                      struct lp_rast_triangle *tri,
298bf215546Sopenharmony_ci                      boolean use_32bits,
299bf215546Sopenharmony_ci                      boolean opaque,
300bf215546Sopenharmony_ci                      const struct u_rect *bbox,
301bf215546Sopenharmony_ci                      int nr_planes,
302bf215546Sopenharmony_ci                      unsigned scissor_index);
303bf215546Sopenharmony_ci
304bf215546Sopenharmony_ciboolean
305bf215546Sopenharmony_cilp_setup_bin_rectangle(struct lp_setup_context *setup,
306bf215546Sopenharmony_ci                       struct lp_rast_rectangle *rect,
307bf215546Sopenharmony_ci                       boolean opaque);
308bf215546Sopenharmony_ci
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci#endif
311