llvmpipe: raise dirty flag on transfers to bound constbuf
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast_priv.h
1 /**************************************************************************
2 *
3 * Copyright 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 #ifndef LP_RAST_PRIV_H
29 #define LP_RAST_PRIV_H
30
31 #include "os/os_thread.h"
32 #include "util/u_format.h"
33 #include "gallivm/lp_bld_debug.h"
34 #include "lp_memory.h"
35 #include "lp_rast.h"
36 #include "lp_scene.h"
37 #include "lp_state.h"
38 #include "lp_texture.h"
39 #include "lp_tile_soa.h"
40 #include "lp_limits.h"
41
42
43 /* If we crash in a jitted function, we can examine jit_line and jit_state
44 * to get some info. This is not thread-safe, however.
45 */
46 #ifdef DEBUG
47
48 extern int jit_line;
49 extern const struct lp_rast_state *jit_state;
50
51 #define BEGIN_JIT_CALL(state) \
52 do { \
53 jit_line = __LINE__; \
54 jit_state = state; \
55 } while (0)
56
57 #define END_JIT_CALL() \
58 do { \
59 jit_line = 0; \
60 jit_state = NULL; \
61 } while (0)
62
63 #else
64
65 #define BEGIN_JIT_CALL(X)
66 #define END_JIT_CALL()
67
68 #endif
69
70
71 struct lp_rasterizer;
72 struct cmd_bin;
73
74 /**
75 * Per-thread rasterization state
76 */
77 struct lp_rasterizer_task
78 {
79 const struct cmd_bin *bin;
80 const struct lp_rast_state *state;
81
82 struct lp_scene *scene;
83 unsigned x, y; /**< Pos of this tile in framebuffer, in pixels */
84
85 uint8_t *color_tiles[PIPE_MAX_COLOR_BUFS];
86 uint8_t *depth_tile;
87
88 /** "back" pointer */
89 struct lp_rasterizer *rast;
90
91 /** "my" index */
92 unsigned thread_index;
93
94 /* occlude counter for visiable pixels */
95 uint32_t vis_counter;
96 struct llvmpipe_query *query;
97
98 pipe_semaphore work_ready;
99 pipe_semaphore work_done;
100 };
101
102
103 /**
104 * This is the state required while rasterizing tiles.
105 * Note that this contains per-thread information too.
106 * The tile size is TILE_SIZE x TILE_SIZE pixels.
107 */
108 struct lp_rasterizer
109 {
110 boolean exit_flag;
111
112 /** The incoming queue of scenes ready to rasterize */
113 struct lp_scene_queue *full_scenes;
114
115 /** The scene currently being rasterized by the threads */
116 struct lp_scene *curr_scene;
117
118 /** A task object for each rasterization thread */
119 struct lp_rasterizer_task tasks[LP_MAX_THREADS];
120
121 unsigned num_threads;
122 pipe_thread threads[LP_MAX_THREADS];
123
124 /** For synchronizing the rasterization threads */
125 pipe_barrier barrier;
126 };
127
128
129 void
130 lp_rast_shade_quads_mask(struct lp_rasterizer_task *task,
131 const struct lp_rast_shader_inputs *inputs,
132 unsigned x, unsigned y,
133 unsigned mask);
134
135
136
137 /**
138 * Get the pointer to a 4x4 depth/stencil block.
139 * We'll map the z/stencil buffer on demand here.
140 * Note that this may be called even when there's no z/stencil buffer - return
141 * NULL in that case.
142 * \param x, y location of 4x4 block in window coords
143 */
144 static INLINE void *
145 lp_rast_get_depth_block_pointer(struct lp_rasterizer_task *task,
146 unsigned x, unsigned y)
147 {
148 const struct lp_scene *scene = task->scene;
149 void *depth;
150
151 assert((x % TILE_VECTOR_WIDTH) == 0);
152 assert((y % TILE_VECTOR_HEIGHT) == 0);
153
154 if (!scene->zsbuf.map) {
155 /* Either out of memory or no zsbuf. Can't tell without access
156 * to the state. Just use dummy tile memory, but don't print
157 * the oom warning as this most likely because there is no
158 * zsbuf.
159 */
160 return lp_dummy_tile;
161 }
162
163 depth = (scene->zsbuf.map +
164 scene->zsbuf.stride * y +
165 scene->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT);
166
167 assert(lp_check_alignment(depth, 16));
168 return depth;
169 }
170
171
172 /**
173 * Get pointer to the swizzled color tile
174 */
175 static INLINE uint8_t *
176 lp_rast_get_color_tile_pointer(struct lp_rasterizer_task *task,
177 unsigned buf, enum lp_texture_usage usage)
178 {
179 const struct lp_scene *scene = task->scene;
180
181 assert(task->x % TILE_SIZE == 0);
182 assert(task->y % TILE_SIZE == 0);
183 assert(buf < scene->fb.nr_cbufs);
184
185 if (!task->color_tiles[buf]) {
186 struct pipe_surface *cbuf = scene->fb.cbufs[buf];
187 struct llvmpipe_resource *lpt;
188 assert(cbuf);
189 lpt = llvmpipe_resource(cbuf->texture);
190 task->color_tiles[buf] = lp_swizzled_cbuf[task->thread_index][buf];
191
192 if (usage != LP_TEX_USAGE_WRITE_ALL) {
193 llvmpipe_swizzle_cbuf_tile(lpt,
194 cbuf->face + cbuf->zslice,
195 cbuf->level,
196 task->x, task->y,
197 task->color_tiles[buf]);
198 }
199 }
200
201 return task->color_tiles[buf];
202 }
203
204
205 /**
206 * Get the pointer to a 4x4 color block (within a 64x64 tile).
207 * We'll map the color buffer on demand here.
208 * Note that this may be called even when there's no color buffers - return
209 * NULL in that case.
210 * \param x, y location of 4x4 block in window coords
211 */
212 static INLINE uint8_t *
213 lp_rast_get_color_block_pointer(struct lp_rasterizer_task *task,
214 unsigned buf, unsigned x, unsigned y)
215 {
216 unsigned px, py, pixel_offset;
217 uint8_t *color;
218
219 assert((x % TILE_VECTOR_WIDTH) == 0);
220 assert((y % TILE_VECTOR_HEIGHT) == 0);
221
222 color = lp_rast_get_color_tile_pointer(task, buf, LP_TEX_USAGE_READ_WRITE);
223 assert(color);
224
225 px = x % TILE_SIZE;
226 py = y % TILE_SIZE;
227 pixel_offset = tile_pixel_offset(px, py, 0);
228
229 color = color + pixel_offset;
230
231 assert(lp_check_alignment(color, 16));
232 return color;
233 }
234
235
236
237 /**
238 * Shade all pixels in a 4x4 block. The fragment code omits the
239 * triangle in/out tests.
240 * \param x, y location of 4x4 block in window coords
241 */
242 static INLINE void
243 lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
244 const struct lp_rast_shader_inputs *inputs,
245 unsigned x, unsigned y )
246 {
247 const struct lp_scene *scene = task->scene;
248 const struct lp_rast_state *state = task->state;
249 struct lp_fragment_shader_variant *variant = state->variant;
250 uint8_t *color[PIPE_MAX_COLOR_BUFS];
251 void *depth;
252 unsigned i;
253
254 /* color buffer */
255 for (i = 0; i < scene->fb.nr_cbufs; i++)
256 color[i] = lp_rast_get_color_block_pointer(task, i, x, y);
257
258 depth = lp_rast_get_depth_block_pointer(task, x, y);
259
260 /* run shader on 4x4 block */
261 BEGIN_JIT_CALL(state);
262 variant->jit_function[RAST_WHOLE]( &state->jit_context,
263 x, y,
264 inputs->frontfacing,
265 GET_A0(inputs),
266 GET_DADX(inputs),
267 GET_DADY(inputs),
268 color,
269 depth,
270 0xffff,
271 &task->vis_counter );
272 END_JIT_CALL();
273 }
274
275 void lp_rast_triangle_1( struct lp_rasterizer_task *,
276 const union lp_rast_cmd_arg );
277 void lp_rast_triangle_2( struct lp_rasterizer_task *,
278 const union lp_rast_cmd_arg );
279 void lp_rast_triangle_3( struct lp_rasterizer_task *,
280 const union lp_rast_cmd_arg );
281 void lp_rast_triangle_4( struct lp_rasterizer_task *,
282 const union lp_rast_cmd_arg );
283 void lp_rast_triangle_5( struct lp_rasterizer_task *,
284 const union lp_rast_cmd_arg );
285 void lp_rast_triangle_6( struct lp_rasterizer_task *,
286 const union lp_rast_cmd_arg );
287 void lp_rast_triangle_7( struct lp_rasterizer_task *,
288 const union lp_rast_cmd_arg );
289 void lp_rast_triangle_8( struct lp_rasterizer_task *,
290 const union lp_rast_cmd_arg );
291
292 void lp_rast_triangle_3_4(struct lp_rasterizer_task *,
293 const union lp_rast_cmd_arg );
294
295 void lp_rast_triangle_3_16( struct lp_rasterizer_task *,
296 const union lp_rast_cmd_arg );
297
298 void lp_rast_triangle_4_16( struct lp_rasterizer_task *,
299 const union lp_rast_cmd_arg );
300
301 void
302 lp_rast_set_state(struct lp_rasterizer_task *task,
303 const union lp_rast_cmd_arg arg);
304
305 void
306 lp_debug_bin( const struct cmd_bin *bin );
307
308 #endif