OSDN Git Service

62d5a3c5796595e9fa90bd79f50b1625745f6d2a
[android-x86/external-mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_context.h
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
46 #define LP_SETUP_NEW_FS          0x01
47 #define LP_SETUP_NEW_CONSTANTS   0x02
48 #define LP_SETUP_NEW_BLEND_COLOR 0x04
49 #define LP_SETUP_NEW_SCISSOR     0x08
50
51
52 struct lp_setup_variant;
53
54
55 /** Max number of scenes */
56 #define MAX_SCENES 2
57
58
59
60 /**
61  * Point/line/triangle setup context.
62  * Note: "stored" below indicates data which is stored in the bins,
63  * not arbitrary malloc'd memory.
64  *
65  *
66  * Subclass of vbuf_render, plugged directly into the draw module as
67  * the rendering backend.
68  */
69 struct lp_setup_context
70 {
71    struct vbuf_render base;
72
73    struct pipe_context *pipe;
74    struct vertex_info *vertex_info;
75    uint prim;
76    uint vertex_size;
77    uint nr_vertices;
78    uint sprite_coord_enable, sprite_coord_origin;
79    uint vertex_buffer_size;
80    void *vertex_buffer;
81
82    /* Final pipeline stage for draw module.  Draw module should
83     * create/install this itself now.
84     */
85    struct draw_stage *vbuf;
86    unsigned num_threads;
87    unsigned scene_idx;
88    struct lp_scene *scenes[MAX_SCENES];  /**< all the scenes */
89    struct lp_scene *scene;               /**< current scene being built */
90
91    struct lp_fence *last_fence;
92    struct llvmpipe_query *active_query[PIPE_QUERY_TYPES];
93
94    boolean subdivide_large_triangles;
95    boolean flatshade_first;
96    boolean ccw_is_frontface;
97    boolean scissor_test;
98    boolean point_size_per_vertex;
99    boolean rasterizer_discard;
100    unsigned cullmode;
101    unsigned bottom_edge_rule;
102    float pixel_offset;
103    float line_width;
104    float point_size;
105    float psize;
106    unsigned viewport_index_slot;
107
108    struct pipe_framebuffer_state fb;
109    struct u_rect framebuffer;
110    struct u_rect scissors[PIPE_MAX_VIEWPORTS];
111    struct u_rect draw_regions[PIPE_MAX_VIEWPORTS];   /* intersection of fb & scissor */
112
113    struct {
114       unsigned flags;
115       union lp_rast_cmd_arg color;    /**< lp_rast_clear_color() cmd */
116       uint64_t zsmask;
117       uint64_t zsvalue;               /**< lp_rast_clear_zstencil() cmd */
118    } clear;
119
120    enum setup_state {
121       SETUP_FLUSHED,    /**< scene is null */
122       SETUP_CLEARED,    /**< scene exists but has only clears */
123       SETUP_ACTIVE      /**< scene exists and has at least one draw/query */
124    } state;
125    
126    struct {
127       const struct lp_rast_state *stored; /**< what's in the scene */
128       struct lp_rast_state current;  /**< currently set state */
129       struct pipe_resource *current_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
130    } fs;
131
132    /** fragment shader constants */
133    struct {
134       struct pipe_constant_buffer current;
135       unsigned stored_size;
136       const void *stored_data;
137    } constants[LP_MAX_TGSI_CONST_BUFFERS];
138
139    struct {
140       struct pipe_blend_color current;
141       uint8_t *stored;
142    } blend_color;
143
144
145    struct {
146       const struct lp_setup_variant *variant;
147    } setup;
148
149    unsigned dirty;   /**< bitmask of LP_SETUP_NEW_x bits */
150
151    void (*point)( struct lp_setup_context *,
152                   const float (*v0)[4]);
153
154    void (*line)( struct lp_setup_context *,
155                  const float (*v0)[4],
156                  const float (*v1)[4]);
157
158    void (*triangle)( struct lp_setup_context *,
159                      const float (*v0)[4],
160                      const float (*v1)[4],
161                      const float (*v2)[4]);
162 };
163
164 void lp_setup_choose_triangle( struct lp_setup_context *setup );
165 void lp_setup_choose_line( struct lp_setup_context *setup );
166 void lp_setup_choose_point( struct lp_setup_context *setup );
167
168 void lp_setup_init_vbuf(struct lp_setup_context *setup);
169
170 boolean lp_setup_update_state( struct lp_setup_context *setup,
171                             boolean update_scene);
172
173 void lp_setup_destroy( struct lp_setup_context *setup );
174
175 boolean lp_setup_flush_and_restart(struct lp_setup_context *setup);
176
177 void
178 lp_setup_print_triangle(struct lp_setup_context *setup,
179                         const float (*v0)[4],
180                         const float (*v1)[4],
181                         const float (*v2)[4]);
182
183 void
184 lp_setup_print_vertex(struct lp_setup_context *setup,
185                       const char *name,
186                       const float (*v)[4]);
187
188
189 struct lp_rast_triangle *
190 lp_setup_alloc_triangle(struct lp_scene *scene,
191                         unsigned num_inputs,
192                         unsigned nr_planes,
193                         unsigned *tri_size);
194
195 boolean
196 lp_setup_bin_triangle( struct lp_setup_context *setup,
197                        struct lp_rast_triangle *tri,
198                        const struct u_rect *bbox,
199                        int nr_planes,
200                        unsigned scissor_index );
201
202 #endif