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_tile_soa.h"
40 #include "lp_limits.h"
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.
48 struct lp_rasterizer_task
;
50 extern const struct lp_rast_state
*jit_state
;
51 extern const struct lp_rasterizer_task
*jit_task
;
53 #define BEGIN_JIT_CALL(state, task) \
55 jit_line = __LINE__; \
60 #define END_JIT_CALL() \
68 #define BEGIN_JIT_CALL(X, Y)
69 #define END_JIT_CALL()
78 * Per-thread rasterization state
80 struct lp_rasterizer_task
82 const struct cmd_bin
*bin
;
83 const struct lp_rast_state
*state
;
85 struct lp_scene
*scene
;
86 unsigned x
, y
; /**< Pos of this tile in framebuffer, in pixels */
88 uint8_t *color_tiles
[PIPE_MAX_COLOR_BUFS
];
92 struct lp_rasterizer
*rast
;
95 unsigned thread_index
;
97 /* occlude counter for visiable pixels */
99 struct llvmpipe_query
*query
;
101 pipe_semaphore work_ready
;
102 pipe_semaphore work_done
;
107 * This is the state required while rasterizing tiles.
108 * Note that this contains per-thread information too.
109 * The tile size is TILE_SIZE x TILE_SIZE pixels.
114 boolean no_rast
; /**< For debugging/profiling */
116 /** The incoming queue of scenes ready to rasterize */
117 struct lp_scene_queue
*full_scenes
;
119 /** The scene currently being rasterized by the threads */
120 struct lp_scene
*curr_scene
;
122 /** A task object for each rasterization thread */
123 struct lp_rasterizer_task tasks
[LP_MAX_THREADS
];
125 unsigned num_threads
;
126 pipe_thread threads
[LP_MAX_THREADS
];
128 /** For synchronizing the rasterization threads */
129 pipe_barrier barrier
;
134 lp_rast_shade_quads_mask(struct lp_rasterizer_task
*task
,
135 const struct lp_rast_shader_inputs
*inputs
,
136 unsigned x
, unsigned y
,
142 * Get the pointer to a 4x4 depth/stencil block.
143 * We'll map the z/stencil buffer on demand here.
144 * Note that this may be called even when there's no z/stencil buffer - return
146 * \param x, y location of 4x4 block in window coords
149 lp_rast_get_depth_block_pointer(struct lp_rasterizer_task
*task
,
150 unsigned x
, unsigned y
)
152 const struct lp_scene
*scene
= task
->scene
;
155 assert(x
< scene
->tiles_x
* TILE_SIZE
);
156 assert(y
< scene
->tiles_y
* TILE_SIZE
);
157 assert((x
% TILE_VECTOR_WIDTH
) == 0);
158 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
160 if (!scene
->zsbuf
.map
) {
161 /* Either out of memory or no zsbuf. Can't tell without access
162 * to the state. Just use dummy tile memory, but don't print
163 * the oom warning as this most likely because there is no
166 return lp_dummy_tile
;
169 depth
= (scene
->zsbuf
.map
+
170 scene
->zsbuf
.stride
* y
+
171 scene
->zsbuf
.blocksize
* x
* TILE_VECTOR_HEIGHT
);
173 assert(lp_check_alignment(depth
, 16));
179 * Get pointer to the swizzled color tile
181 static INLINE
uint8_t *
182 lp_rast_get_color_tile_pointer(struct lp_rasterizer_task
*task
,
183 unsigned buf
, enum lp_texture_usage usage
)
185 const struct lp_scene
*scene
= task
->scene
;
187 assert(task
->x
< scene
->tiles_x
* TILE_SIZE
);
188 assert(task
->y
< scene
->tiles_y
* TILE_SIZE
);
189 assert(task
->x
% TILE_SIZE
== 0);
190 assert(task
->y
% TILE_SIZE
== 0);
191 assert(buf
< scene
->fb
.nr_cbufs
);
193 if (!task
->color_tiles
[buf
]) {
194 struct pipe_surface
*cbuf
= scene
->fb
.cbufs
[buf
];
195 struct llvmpipe_resource
*lpt
;
197 lpt
= llvmpipe_resource(cbuf
->texture
);
198 task
->color_tiles
[buf
] = lp_swizzled_cbuf
[task
->thread_index
][buf
];
200 if (usage
!= LP_TEX_USAGE_WRITE_ALL
) {
201 llvmpipe_swizzle_cbuf_tile(lpt
,
202 cbuf
->u
.tex
.first_layer
,
205 task
->color_tiles
[buf
]);
209 return task
->color_tiles
[buf
];
214 * Get the pointer to a 4x4 color block (within a 64x64 tile).
215 * We'll map the color buffer on demand here.
216 * Note that this may be called even when there's no color buffers - return
218 * \param x, y location of 4x4 block in window coords
220 static INLINE
uint8_t *
221 lp_rast_get_color_block_pointer(struct lp_rasterizer_task
*task
,
222 unsigned buf
, unsigned x
, unsigned y
)
224 unsigned px
, py
, pixel_offset
;
227 assert(x
< task
->scene
->tiles_x
* TILE_SIZE
);
228 assert(y
< task
->scene
->tiles_y
* TILE_SIZE
);
229 assert((x
% TILE_VECTOR_WIDTH
) == 0);
230 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
232 color
= lp_rast_get_color_tile_pointer(task
, buf
, LP_TEX_USAGE_READ_WRITE
);
237 pixel_offset
= tile_pixel_offset(px
, py
, 0);
239 color
= color
+ pixel_offset
;
241 assert(lp_check_alignment(color
, 16));
248 * Shade all pixels in a 4x4 block. The fragment code omits the
249 * triangle in/out tests.
250 * \param x, y location of 4x4 block in window coords
253 lp_rast_shade_quads_all( struct lp_rasterizer_task
*task
,
254 const struct lp_rast_shader_inputs
*inputs
,
255 unsigned x
, unsigned y
)
257 const struct lp_scene
*scene
= task
->scene
;
258 const struct lp_rast_state
*state
= task
->state
;
259 struct lp_fragment_shader_variant
*variant
= state
->variant
;
260 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
265 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++)
266 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, x
, y
);
268 depth
= lp_rast_get_depth_block_pointer(task
, x
, y
);
270 /* run shader on 4x4 block */
271 BEGIN_JIT_CALL(state
, task
);
272 variant
->jit_function
[RAST_WHOLE
]( &state
->jit_context
,
281 &task
->vis_counter
);
285 void lp_rast_triangle_1( struct lp_rasterizer_task
*,
286 const union lp_rast_cmd_arg
);
287 void lp_rast_triangle_2( struct lp_rasterizer_task
*,
288 const union lp_rast_cmd_arg
);
289 void lp_rast_triangle_3( struct lp_rasterizer_task
*,
290 const union lp_rast_cmd_arg
);
291 void lp_rast_triangle_4( struct lp_rasterizer_task
*,
292 const union lp_rast_cmd_arg
);
293 void lp_rast_triangle_5( struct lp_rasterizer_task
*,
294 const union lp_rast_cmd_arg
);
295 void lp_rast_triangle_6( struct lp_rasterizer_task
*,
296 const union lp_rast_cmd_arg
);
297 void lp_rast_triangle_7( struct lp_rasterizer_task
*,
298 const union lp_rast_cmd_arg
);
299 void lp_rast_triangle_8( struct lp_rasterizer_task
*,
300 const union lp_rast_cmd_arg
);
302 void lp_rast_triangle_3_4(struct lp_rasterizer_task
*,
303 const union lp_rast_cmd_arg
);
305 void lp_rast_triangle_3_16( struct lp_rasterizer_task
*,
306 const union lp_rast_cmd_arg
);
308 void lp_rast_triangle_4_16( struct lp_rasterizer_task
*,
309 const union lp_rast_cmd_arg
);
312 lp_rast_set_state(struct lp_rasterizer_task
*task
,
313 const union lp_rast_cmd_arg arg
);
316 lp_debug_bin( const struct cmd_bin
*bin
);