1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef LP_RAST_PRIV_H
29 #define LP_RAST_PRIV_H
31 #include "util/format/u_format.h"
32 #include "util/u_thread.h"
33 #include "gallivm/lp_bld_debug.h"
34 #include "lp_memory.h"
38 #include "lp_texture.h"
39 #include "lp_limits.h"
42 #define TILE_VECTOR_HEIGHT 4
43 #define TILE_VECTOR_WIDTH 4
45 /* If we crash in a jitted function, we can examine jit_line and jit_state
46 * to get some info. This is not thread-safe, however.
50 struct lp_rasterizer_task
;
52 extern const struct lp_rast_state
*jit_state
;
53 extern const struct lp_rasterizer_task
*jit_task
;
55 #define BEGIN_JIT_CALL(state, task) \
57 jit_line = __LINE__; \
62 #define END_JIT_CALL() \
70 #define BEGIN_JIT_CALL(X, Y)
71 #define END_JIT_CALL()
80 * Per-thread rasterization state
82 struct lp_rasterizer_task
84 const struct cmd_bin
*bin
;
85 const struct lp_rast_state
*state
;
87 struct lp_scene
*scene
;
88 unsigned x
, y
; /**< Pos of this tile in framebuffer, in pixels */
89 unsigned width
, height
; /**< width, height of current tile, in pixels */
91 uint8_t *color_tiles
[PIPE_MAX_COLOR_BUFS
];
95 struct lp_rasterizer
*rast
;
98 unsigned thread_index
;
100 /** Non-interpolated passthru state and occlude counter for visible pixels */
101 struct lp_jit_thread_data thread_data
;
103 pipe_semaphore work_ready
;
104 pipe_semaphore work_done
;
109 * This is the state required while rasterizing tiles.
110 * Note that this contains per-thread information too.
111 * The tile size is TILE_SIZE x TILE_SIZE pixels.
116 boolean no_rast
; /**< For debugging/profiling */
118 /** The incoming queue of scenes ready to rasterize */
119 struct lp_scene_queue
*full_scenes
;
121 /** The scene currently being rasterized by the threads */
122 struct lp_scene
*curr_scene
;
124 /** A task object for each rasterization thread */
125 struct lp_rasterizer_task tasks
[LP_MAX_THREADS
];
127 unsigned num_threads
;
128 thrd_t threads
[LP_MAX_THREADS
];
130 /** For synchronizing the rasterization threads */
131 util_barrier barrier
;
135 lp_rast_shade_quads_mask_sample(struct lp_rasterizer_task
*task
,
136 const struct lp_rast_shader_inputs
*inputs
,
137 unsigned x
, unsigned y
,
140 lp_rast_shade_quads_mask(struct lp_rasterizer_task
*task
,
141 const struct lp_rast_shader_inputs
*inputs
,
142 unsigned x
, unsigned y
,
147 * Get the pointer to a 4x4 color block (within a 64x64 tile).
148 * \param x, y location of 4x4 block in window coords
150 static inline uint8_t *
151 lp_rast_get_color_block_pointer(struct lp_rasterizer_task
*task
,
152 unsigned buf
, unsigned x
, unsigned y
,
155 unsigned px
, py
, pixel_offset
;
158 assert(x
< task
->scene
->tiles_x
* TILE_SIZE
);
159 assert(y
< task
->scene
->tiles_y
* TILE_SIZE
);
160 assert((x
% TILE_VECTOR_WIDTH
) == 0);
161 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
162 assert(buf
< task
->scene
->fb
.nr_cbufs
);
164 assert(task
->color_tiles
[buf
]);
167 * We don't actually benefit from having per tile cbuf/zsbuf pointers,
168 * it's just extra work - the mul/add would be exactly the same anyway.
169 * Fortunately the extra work (modulo) here is very cheap at least...
174 pixel_offset
= px
* task
->scene
->cbufs
[buf
].format_bytes
+
175 py
* task
->scene
->cbufs
[buf
].stride
;
176 color
= task
->color_tiles
[buf
] + pixel_offset
;
179 color
+= layer
* task
->scene
->cbufs
[buf
].layer_stride
;
182 assert(lp_check_alignment(color
, llvmpipe_get_format_alignment(task
->scene
->fb
.cbufs
[buf
]->format
)));
188 * Get the pointer to a 4x4 depth block (within a 64x64 tile).
189 * \param x, y location of 4x4 block in window coords
191 static inline uint8_t *
192 lp_rast_get_depth_block_pointer(struct lp_rasterizer_task
*task
,
193 unsigned x
, unsigned y
, unsigned layer
)
195 unsigned px
, py
, pixel_offset
;
198 assert(x
< task
->scene
->tiles_x
* TILE_SIZE
);
199 assert(y
< task
->scene
->tiles_y
* TILE_SIZE
);
200 assert((x
% TILE_VECTOR_WIDTH
) == 0);
201 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
203 assert(task
->depth_tile
);
208 pixel_offset
= px
* task
->scene
->zsbuf
.format_bytes
+
209 py
* task
->scene
->zsbuf
.stride
;
210 depth
= task
->depth_tile
+ pixel_offset
;
213 depth
+= layer
* task
->scene
->zsbuf
.layer_stride
;
216 assert(lp_check_alignment(depth
, llvmpipe_get_format_alignment(task
->scene
->fb
.zsbuf
->format
)));
223 * Shade all pixels in a 4x4 block. The fragment code omits the
224 * triangle in/out tests.
225 * \param x, y location of 4x4 block in window coords
228 lp_rast_shade_quads_all( struct lp_rasterizer_task
*task
,
229 const struct lp_rast_shader_inputs
*inputs
,
230 unsigned x
, unsigned y
)
232 const struct lp_scene
*scene
= task
->scene
;
233 const struct lp_rast_state
*state
= task
->state
;
234 struct lp_fragment_shader_variant
*variant
= state
->variant
;
235 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
236 unsigned stride
[PIPE_MAX_COLOR_BUFS
];
237 unsigned sample_stride
[PIPE_MAX_COLOR_BUFS
];
238 uint8_t *depth
= NULL
;
239 unsigned depth_stride
= 0;
240 unsigned depth_sample_stride
= 0;
244 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++) {
245 if (scene
->fb
.cbufs
[i
]) {
246 stride
[i
] = scene
->cbufs
[i
].stride
;
247 sample_stride
[i
] = scene
->cbufs
[i
].sample_stride
;
248 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, x
, y
,
253 sample_stride
[i
] = 0;
258 if (scene
->zsbuf
.map
) {
259 depth
= lp_rast_get_depth_block_pointer(task
, x
, y
, inputs
->layer
);
260 depth_sample_stride
= scene
->zsbuf
.sample_stride
;
261 depth_stride
= scene
->zsbuf
.stride
;
265 for (unsigned i
= 0; i
< scene
->fb_max_samples
; i
++)
266 mask
|= (uint64_t)0xffff << (16 * i
);
269 * The rasterizer may produce fragments outside our
270 * allocated 4x4 blocks hence need to filter them out here.
272 if ((x
% TILE_SIZE
) < task
->width
&& (y
% TILE_SIZE
) < task
->height
) {
273 /* Propagate non-interpolated raster state. */
274 task
->thread_data
.raster_state
.viewport_index
= inputs
->viewport_index
;
276 /* run shader on 4x4 block */
277 BEGIN_JIT_CALL(state
, task
);
278 variant
->jit_function
[RAST_WHOLE
]( &state
->jit_context
,
291 depth_sample_stride
);
296 void lp_rast_triangle_1( struct lp_rasterizer_task
*,
297 const union lp_rast_cmd_arg
);
298 void lp_rast_triangle_2( struct lp_rasterizer_task
*,
299 const union lp_rast_cmd_arg
);
300 void lp_rast_triangle_3( struct lp_rasterizer_task
*,
301 const union lp_rast_cmd_arg
);
302 void lp_rast_triangle_4( struct lp_rasterizer_task
*,
303 const union lp_rast_cmd_arg
);
304 void lp_rast_triangle_5( struct lp_rasterizer_task
*,
305 const union lp_rast_cmd_arg
);
306 void lp_rast_triangle_6( struct lp_rasterizer_task
*,
307 const union lp_rast_cmd_arg
);
308 void lp_rast_triangle_7( struct lp_rasterizer_task
*,
309 const union lp_rast_cmd_arg
);
310 void lp_rast_triangle_8( struct lp_rasterizer_task
*,
311 const union lp_rast_cmd_arg
);
313 void lp_rast_triangle_3_4(struct lp_rasterizer_task
*,
314 const union lp_rast_cmd_arg
);
316 void lp_rast_triangle_3_16( struct lp_rasterizer_task
*,
317 const union lp_rast_cmd_arg
);
319 void lp_rast_triangle_4_16( struct lp_rasterizer_task
*,
320 const union lp_rast_cmd_arg
);
323 void lp_rast_triangle_32_1( struct lp_rasterizer_task
*,
324 const union lp_rast_cmd_arg
);
325 void lp_rast_triangle_32_2( struct lp_rasterizer_task
*,
326 const union lp_rast_cmd_arg
);
327 void lp_rast_triangle_32_3( struct lp_rasterizer_task
*,
328 const union lp_rast_cmd_arg
);
329 void lp_rast_triangle_32_4( struct lp_rasterizer_task
*,
330 const union lp_rast_cmd_arg
);
331 void lp_rast_triangle_32_5( struct lp_rasterizer_task
*,
332 const union lp_rast_cmd_arg
);
333 void lp_rast_triangle_32_6( struct lp_rasterizer_task
*,
334 const union lp_rast_cmd_arg
);
335 void lp_rast_triangle_32_7( struct lp_rasterizer_task
*,
336 const union lp_rast_cmd_arg
);
337 void lp_rast_triangle_32_8( struct lp_rasterizer_task
*,
338 const union lp_rast_cmd_arg
);
340 void lp_rast_triangle_32_3_4(struct lp_rasterizer_task
*,
341 const union lp_rast_cmd_arg
);
343 void lp_rast_triangle_32_3_16( struct lp_rasterizer_task
*,
344 const union lp_rast_cmd_arg
);
346 void lp_rast_triangle_32_4_16( struct lp_rasterizer_task
*,
347 const union lp_rast_cmd_arg
);
349 void lp_rast_triangle_ms_1( struct lp_rasterizer_task
*,
350 const union lp_rast_cmd_arg
);
351 void lp_rast_triangle_ms_2( struct lp_rasterizer_task
*,
352 const union lp_rast_cmd_arg
);
353 void lp_rast_triangle_ms_3( struct lp_rasterizer_task
*,
354 const union lp_rast_cmd_arg
);
355 void lp_rast_triangle_ms_4( struct lp_rasterizer_task
*,
356 const union lp_rast_cmd_arg
);
357 void lp_rast_triangle_ms_5( struct lp_rasterizer_task
*,
358 const union lp_rast_cmd_arg
);
359 void lp_rast_triangle_ms_6( struct lp_rasterizer_task
*,
360 const union lp_rast_cmd_arg
);
361 void lp_rast_triangle_ms_7( struct lp_rasterizer_task
*,
362 const union lp_rast_cmd_arg
);
363 void lp_rast_triangle_ms_8( struct lp_rasterizer_task
*,
364 const union lp_rast_cmd_arg
);
366 void lp_rast_triangle_ms_3_4(struct lp_rasterizer_task
*,
367 const union lp_rast_cmd_arg
);
369 void lp_rast_triangle_ms_3_16( struct lp_rasterizer_task
*,
370 const union lp_rast_cmd_arg
);
372 void lp_rast_triangle_ms_4_16( struct lp_rasterizer_task
*,
373 const union lp_rast_cmd_arg
);
375 void lp_rast_triangle_ms_32_1( struct lp_rasterizer_task
*,
376 const union lp_rast_cmd_arg
);
377 void lp_rast_triangle_ms_32_2( struct lp_rasterizer_task
*,
378 const union lp_rast_cmd_arg
);
379 void lp_rast_triangle_ms_32_3( struct lp_rasterizer_task
*,
380 const union lp_rast_cmd_arg
);
381 void lp_rast_triangle_ms_32_4( struct lp_rasterizer_task
*,
382 const union lp_rast_cmd_arg
);
383 void lp_rast_triangle_ms_32_5( struct lp_rasterizer_task
*,
384 const union lp_rast_cmd_arg
);
385 void lp_rast_triangle_ms_32_6( struct lp_rasterizer_task
*,
386 const union lp_rast_cmd_arg
);
387 void lp_rast_triangle_ms_32_7( struct lp_rasterizer_task
*,
388 const union lp_rast_cmd_arg
);
389 void lp_rast_triangle_ms_32_8( struct lp_rasterizer_task
*,
390 const union lp_rast_cmd_arg
);
392 void lp_rast_triangle_ms_32_3_4(struct lp_rasterizer_task
*,
393 const union lp_rast_cmd_arg
);
395 void lp_rast_triangle_ms_32_3_16( struct lp_rasterizer_task
*,
396 const union lp_rast_cmd_arg
);
398 void lp_rast_triangle_ms_32_4_16( struct lp_rasterizer_task
*,
399 const union lp_rast_cmd_arg
);
402 lp_rast_set_state(struct lp_rasterizer_task
*task
,
403 const union lp_rast_cmd_arg arg
);
406 lp_debug_bin( const struct cmd_bin
*bin
, int x
, int y
);