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