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"
35 #include "lp_tile_soa.h"
38 #define MAX_THREADS 8 /* XXX probably temporary here */
45 * A tile's color and depth memory.
46 * We can choose whatever layout for the internal tile storage we prefer.
50 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
55 * Per-thread rasterization state
57 struct lp_rasterizer_task
59 struct lp_rast_tile tile
; /** Tile color/z/stencil memory */
61 unsigned x
, y
; /**< Pos of this tile in framebuffer, in pixels */
63 const struct lp_rast_state
*current_state
;
66 struct lp_rasterizer
*rast
;
69 unsigned thread_index
;
71 pipe_semaphore work_ready
;
72 pipe_semaphore work_done
;
77 * This is the state required while rasterizing tiles.
78 * Note that this contains per-thread information too.
79 * The tile size is TILE_SIZE x TILE_SIZE pixels.
92 enum pipe_format format
;
93 } cbuf
[PIPE_MAX_COLOR_BUFS
];
104 boolean write_zstencil
;
105 unsigned clear_color
;
106 unsigned clear_depth
;
110 /** The incoming queue of scenes ready to rasterize */
111 struct lp_scene_queue
*full_scenes
;
114 * The outgoing queue of processed scenes to return to setup module
116 * XXX: while scenes are per-context but the rasterizer is
117 * (potentially) shared, these empty scenes should be returned to
118 * the context which created them rather than retained here.
120 struct lp_scene_queue
*empty_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
[MAX_THREADS
];
128 unsigned num_threads
;
129 pipe_thread threads
[MAX_THREADS
];
131 /** For synchronizing the rasterization threads */
132 pipe_barrier barrier
;
136 void lp_rast_shade_quads( struct lp_rasterizer_task
*task
,
137 const struct lp_rast_shader_inputs
*inputs
,
138 unsigned x
, unsigned y
,
139 int32_t c1
, int32_t c2
, int32_t c3
);
143 * Get the pointer to the depth buffer for a block.
144 * \param x, y location of 4x4 block in window coords
147 lp_rast_depth_pointer( struct lp_rasterizer
*rast
,
148 unsigned x
, unsigned y
)
152 assert((x
% TILE_VECTOR_WIDTH
) == 0);
153 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
155 if (!rast
->zsbuf
.map
)
158 depth
= (rast
->zsbuf
.map
+
159 rast
->zsbuf
.stride
* y
+
160 rast
->zsbuf
.blocksize
* x
* TILE_VECTOR_HEIGHT
);
162 assert(lp_check_alignment(depth
, 16));
169 * Shade all pixels in a 4x4 block. The fragment code omits the
170 * triangle in/out tests.
171 * \param x, y location of 4x4 block in window coords
174 lp_rast_shade_quads_all( struct lp_rasterizer_task
*task
,
175 const struct lp_rast_shader_inputs
*inputs
,
176 unsigned x
, unsigned y
)
178 struct lp_rasterizer
*rast
= task
->rast
;
179 const struct lp_rast_state
*state
= task
->current_state
;
180 struct lp_rast_tile
*tile
= &task
->tile
;
181 const unsigned ix
= x
% TILE_SIZE
, iy
= y
% TILE_SIZE
;
182 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
184 unsigned block_offset
, i
;
186 /* offset of the containing 16x16 pixel block within the tile */
187 block_offset
= (iy
/ 4) * (16 * 16) + (ix
/ 4) * 16;
190 for (i
= 0; i
< rast
->state
.nr_cbufs
; i
++)
191 color
[i
] = tile
->color
[i
] + 4 * block_offset
;
193 depth
= lp_rast_depth_pointer(rast
, x
, y
);
196 state
->jit_function
[0]( &state
->jit_context
,
204 INT_MIN
, INT_MIN
, INT_MIN
,