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