Merge branch 'gallium-msaa'
[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_rast.h"
35 #include "lp_scene.h"
36 #include "lp_state.h"
37 #include "lp_texture.h"
38 #include "lp_tile_soa.h"
39 #include "lp_limits.h"
40
41
42 struct lp_rasterizer;
43
44
45 /**
46 * Per-thread rasterization state
47 */
48 struct lp_rasterizer_task
49 {
50 unsigned x, y; /**< Pos of this tile in framebuffer, in pixels */
51
52 uint8_t *color_tiles[PIPE_MAX_COLOR_BUFS];
53 uint8_t *depth_tile;
54
55 const struct lp_rast_state *current_state;
56
57 /** "back" pointer */
58 struct lp_rasterizer *rast;
59
60 /** "my" index */
61 unsigned thread_index;
62
63 /* occlude counter for visiable pixels */
64 uint32_t vis_counter;
65
66 pipe_semaphore work_ready;
67 pipe_semaphore work_done;
68 };
69
70
71 /**
72 * This is the state required while rasterizing tiles.
73 * Note that this contains per-thread information too.
74 * The tile size is TILE_SIZE x TILE_SIZE pixels.
75 */
76 struct lp_rasterizer
77 {
78 boolean exit_flag;
79
80 /* Framebuffer stuff
81 */
82 struct {
83 void *map;
84 unsigned tiles_per_row;
85 unsigned blocksize;
86 enum pipe_format format;
87 } cbuf[PIPE_MAX_COLOR_BUFS];
88
89 struct {
90 uint8_t *map;
91 unsigned stride;
92 unsigned blocksize;
93 } zsbuf;
94
95 struct {
96 unsigned nr_cbufs;
97 unsigned clear_color;
98 unsigned clear_depth;
99 char clear_stencil;
100 } state;
101
102 /** The incoming queue of scenes ready to rasterize */
103 struct lp_scene_queue *full_scenes;
104
105 /**
106 * The outgoing queue of processed scenes to return to setup module
107 *
108 * XXX: while scenes are per-context but the rasterizer is
109 * (potentially) shared, these empty scenes should be returned to
110 * the context which created them rather than retained here.
111 */
112 /* struct lp_scene_queue *empty_scenes; */
113
114 /** The scene currently being rasterized by the threads */
115 struct lp_scene *curr_scene;
116
117 /** A task object for each rasterization thread */
118 struct lp_rasterizer_task tasks[LP_MAX_THREADS];
119
120 unsigned num_threads;
121 pipe_thread threads[LP_MAX_THREADS];
122
123 /** For synchronizing the rasterization threads */
124 pipe_barrier barrier;
125 };
126
127
128 void lp_rast_shade_quads( struct lp_rasterizer_task *task,
129 const struct lp_rast_shader_inputs *inputs,
130 unsigned x, unsigned y,
131 int32_t c1, int32_t c2, int32_t c3);
132
133
134 /**
135 * Get the pointer to a 4x4 depth/stencil block.
136 * We'll map the z/stencil buffer on demand here.
137 * Note that this may be called even when there's no z/stencil buffer - return
138 * NULL in that case.
139 * \param x, y location of 4x4 block in window coords
140 */
141 static INLINE void *
142 lp_rast_get_depth_block_pointer(const struct lp_rasterizer *rast,
143 unsigned x, unsigned y)
144 {
145 void *depth;
146
147 assert((x % TILE_VECTOR_WIDTH) == 0);
148 assert((y % TILE_VECTOR_HEIGHT) == 0);
149
150 assert(rast->zsbuf.map || !rast->curr_scene->fb.zsbuf);
151
152 if (!rast->zsbuf.map)
153 return NULL;
154
155 depth = (rast->zsbuf.map +
156 rast->zsbuf.stride * y +
157 rast->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT);
158
159 assert(lp_check_alignment(depth, 16));
160 return depth;
161 }
162
163
164 /**
165 * Get the pointer to a 4x4 color block (within a 64x64 tile).
166 * We'll map the color buffer on demand here.
167 * Note that this may be called even when there's no color buffers - return
168 * NULL in that case.
169 * \param x, y location of 4x4 block in window coords
170 */
171 static INLINE uint8_t *
172 lp_rast_get_color_block_pointer(struct lp_rasterizer_task *task,
173 unsigned buf, unsigned x, unsigned y)
174 {
175 unsigned px, py, pixel_offset;
176 uint8_t *color;
177
178 assert((x % TILE_VECTOR_WIDTH) == 0);
179 assert((y % TILE_VECTOR_HEIGHT) == 0);
180
181 color = task->color_tiles[buf];
182 assert(color);
183
184 px = x % TILE_SIZE;
185 py = y % TILE_SIZE;
186 pixel_offset = tile_pixel_offset(px, py, 0);
187
188 color = color + pixel_offset;
189
190 assert(lp_check_alignment(color, 16));
191 return color;
192 }
193
194
195
196 /**
197 * Shade all pixels in a 4x4 block. The fragment code omits the
198 * triangle in/out tests.
199 * \param x, y location of 4x4 block in window coords
200 */
201 static INLINE void
202 lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
203 const struct lp_rast_shader_inputs *inputs,
204 unsigned x, unsigned y )
205 {
206 struct lp_rasterizer *rast = task->rast;
207 const struct lp_rast_state *state = task->current_state;
208 uint8_t *color[PIPE_MAX_COLOR_BUFS];
209 void *depth;
210 unsigned i;
211
212 /* color buffer */
213 for (i = 0; i < rast->state.nr_cbufs; i++)
214 color[i] = lp_rast_get_color_block_pointer(task, i, x, y);
215
216 depth = lp_rast_get_depth_block_pointer(rast, x, y);
217
218 /* run shader on 4x4 block */
219 state->jit_function[RAST_WHOLE]( &state->jit_context,
220 x, y,
221 inputs->facing,
222 inputs->a0,
223 inputs->dadx,
224 inputs->dady,
225 color,
226 depth,
227 INT_MIN, INT_MIN, INT_MIN,
228 NULL, NULL, NULL, &task->vis_counter );
229 }
230
231
232 #endif