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 "os/os_thread.h"
32 #include "util/u_format.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 */
90 uint8_t *color_tiles
[PIPE_MAX_COLOR_BUFS
];
94 struct lp_rasterizer
*rast
;
97 unsigned thread_index
;
99 /* occlude counter for visible pixels */
100 struct lp_jit_thread_data thread_data
;
101 uint64_t query_start
;
102 struct llvmpipe_query
*query
[PIPE_QUERY_TYPES
];
104 pipe_semaphore work_ready
;
105 pipe_semaphore work_done
;
110 * This is the state required while rasterizing tiles.
111 * Note that this contains per-thread information too.
112 * The tile size is TILE_SIZE x TILE_SIZE pixels.
117 boolean no_rast
; /**< For debugging/profiling */
119 /** The incoming queue of scenes ready to rasterize */
120 struct lp_scene_queue
*full_scenes
;
122 /** The scene currently being rasterized by the threads */
123 struct lp_scene
*curr_scene
;
125 /** A task object for each rasterization thread */
126 struct lp_rasterizer_task tasks
[LP_MAX_THREADS
];
128 unsigned num_threads
;
129 pipe_thread threads
[LP_MAX_THREADS
];
131 /** For synchronizing the rasterization threads */
132 pipe_barrier barrier
;
137 lp_rast_shade_quads_mask(struct lp_rasterizer_task
*task
,
138 const struct lp_rast_shader_inputs
*inputs
,
139 unsigned x
, unsigned y
,
145 * Get pointer to the unswizzled color tile
147 static INLINE
uint8_t *
148 lp_rast_get_unswizzled_color_tile_pointer(struct lp_rasterizer_task
*task
,
149 unsigned buf
, enum lp_texture_usage usage
)
151 const struct lp_scene
*scene
= task
->scene
;
152 unsigned format_bytes
;
154 assert(task
->x
< scene
->tiles_x
* TILE_SIZE
);
155 assert(task
->y
< scene
->tiles_y
* TILE_SIZE
);
156 assert(task
->x
% TILE_SIZE
== 0);
157 assert(task
->y
% TILE_SIZE
== 0);
158 assert(buf
< scene
->fb
.nr_cbufs
);
160 if (!task
->color_tiles
[buf
]) {
161 struct pipe_surface
*cbuf
= scene
->fb
.cbufs
[buf
];
164 format_bytes
= util_format_get_blocksize(cbuf
->format
);
165 task
->color_tiles
[buf
] = scene
->cbufs
[buf
].map
+ scene
->cbufs
[buf
].stride
* task
->y
+ format_bytes
* task
->x
;
168 return task
->color_tiles
[buf
];
173 * Get pointer to the unswizzled depth tile
175 static INLINE
uint8_t *
176 lp_rast_get_unswizzled_depth_tile_pointer(struct lp_rasterizer_task
*task
,
177 enum lp_texture_usage usage
)
179 const struct lp_scene
*scene
= task
->scene
;
180 unsigned format_bytes
;
182 assert(task
->x
< scene
->tiles_x
* TILE_SIZE
);
183 assert(task
->y
< scene
->tiles_y
* TILE_SIZE
);
184 assert(task
->x
% TILE_SIZE
== 0);
185 assert(task
->y
% TILE_SIZE
== 0);
187 if (!task
->depth_tile
) {
188 struct pipe_surface
*dbuf
= scene
->fb
.zsbuf
;
191 format_bytes
= util_format_get_blocksize(dbuf
->format
);
192 task
->depth_tile
= scene
->zsbuf
.map
+ scene
->zsbuf
.stride
* task
->y
+ format_bytes
* task
->x
;
195 return task
->depth_tile
;
200 * Get the pointer to an unswizzled 4x4 color block (within an unswizzled 64x64 tile).
201 * \param x, y location of 4x4 block in window coords
203 static INLINE
uint8_t *
204 lp_rast_get_unswizzled_color_block_pointer(struct lp_rasterizer_task
*task
,
205 unsigned buf
, unsigned x
, unsigned y
)
207 unsigned px
, py
, pixel_offset
, format_bytes
;
210 assert(x
< task
->scene
->tiles_x
* TILE_SIZE
);
211 assert(y
< task
->scene
->tiles_y
* TILE_SIZE
);
212 assert((x
% TILE_VECTOR_WIDTH
) == 0);
213 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
214 assert(buf
< task
->scene
->fb
.nr_cbufs
);
216 format_bytes
= util_format_get_blocksize(task
->scene
->fb
.cbufs
[buf
]->format
);
218 color
= lp_rast_get_unswizzled_color_tile_pointer(task
, buf
, LP_TEX_USAGE_READ_WRITE
);
223 pixel_offset
= px
* format_bytes
+ py
* task
->scene
->cbufs
[buf
].stride
;
225 color
= color
+ pixel_offset
;
227 assert(lp_check_alignment(color
, llvmpipe_get_format_alignment(task
->scene
->fb
.cbufs
[buf
]->format
)));
233 * Get the pointer to an unswizzled 4x4 depth block (within an unswizzled 64x64 tile).
234 * \param x, y location of 4x4 block in window coords
236 static INLINE
uint8_t *
237 lp_rast_get_unswizzled_depth_block_pointer(struct lp_rasterizer_task
*task
,
238 unsigned x
, unsigned y
)
240 unsigned px
, py
, pixel_offset
, format_bytes
;
243 assert(x
< task
->scene
->tiles_x
* TILE_SIZE
);
244 assert(y
< task
->scene
->tiles_y
* TILE_SIZE
);
245 assert((x
% TILE_VECTOR_WIDTH
) == 0);
246 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
248 format_bytes
= util_format_get_blocksize(task
->scene
->fb
.zsbuf
->format
);
250 depth
= lp_rast_get_unswizzled_depth_tile_pointer(task
, LP_TEX_USAGE_READ_WRITE
);
255 pixel_offset
= px
* format_bytes
+ py
* task
->scene
->zsbuf
.stride
;
257 depth
= depth
+ pixel_offset
;
259 assert(lp_check_alignment(depth
, llvmpipe_get_format_alignment(task
->scene
->fb
.zsbuf
->format
)));
266 * Shade all pixels in a 4x4 block. The fragment code omits the
267 * triangle in/out tests.
268 * \param x, y location of 4x4 block in window coords
271 lp_rast_shade_quads_all( struct lp_rasterizer_task
*task
,
272 const struct lp_rast_shader_inputs
*inputs
,
273 unsigned x
, unsigned y
)
275 const struct lp_scene
*scene
= task
->scene
;
276 const struct lp_rast_state
*state
= task
->state
;
277 struct lp_fragment_shader_variant
*variant
= state
->variant
;
278 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
279 unsigned stride
[PIPE_MAX_COLOR_BUFS
];
281 unsigned depth_stride
= 0;
285 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++) {
286 stride
[i
] = scene
->cbufs
[i
].stride
;
288 color
[i
] = lp_rast_get_unswizzled_color_block_pointer(task
, i
, x
, y
);
291 if (scene
->zsbuf
.map
) {
292 depth
= lp_rast_get_unswizzled_depth_block_pointer(task
, x
, y
);
293 depth_stride
= scene
->zsbuf
.stride
;
296 /* run shader on 4x4 block */
297 BEGIN_JIT_CALL(state
, task
);
298 variant
->jit_function
[RAST_WHOLE
]( &state
->jit_context
,
313 void lp_rast_triangle_1( struct lp_rasterizer_task
*,
314 const union lp_rast_cmd_arg
);
315 void lp_rast_triangle_2( struct lp_rasterizer_task
*,
316 const union lp_rast_cmd_arg
);
317 void lp_rast_triangle_3( struct lp_rasterizer_task
*,
318 const union lp_rast_cmd_arg
);
319 void lp_rast_triangle_4( struct lp_rasterizer_task
*,
320 const union lp_rast_cmd_arg
);
321 void lp_rast_triangle_5( struct lp_rasterizer_task
*,
322 const union lp_rast_cmd_arg
);
323 void lp_rast_triangle_6( struct lp_rasterizer_task
*,
324 const union lp_rast_cmd_arg
);
325 void lp_rast_triangle_7( struct lp_rasterizer_task
*,
326 const union lp_rast_cmd_arg
);
327 void lp_rast_triangle_8( struct lp_rasterizer_task
*,
328 const union lp_rast_cmd_arg
);
330 void lp_rast_triangle_3_4(struct lp_rasterizer_task
*,
331 const union lp_rast_cmd_arg
);
333 void lp_rast_triangle_3_16( struct lp_rasterizer_task
*,
334 const union lp_rast_cmd_arg
);
336 void lp_rast_triangle_4_16( struct lp_rasterizer_task
*,
337 const union lp_rast_cmd_arg
);
340 lp_rast_set_state(struct lp_rasterizer_task
*task
,
341 const union lp_rast_cmd_arg arg
);
344 lp_debug_bin( const struct cmd_bin
*bin
);