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