abc5a9ad8997e2409f331a96ee38377ce4bb6082
[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_tile_soa.h"
36
37
38 #define MAX_THREADS 8 /* XXX probably temporary here */
39
40
41 struct pipe_transfer;
42 struct pipe_screen;
43 struct lp_rasterizer;
44
45
46 /**
47 * A tile's color and depth memory.
48 * We can choose whatever layout for the internal tile storage we prefer.
49 */
50 struct lp_rast_tile
51 {
52 uint8_t *color[PIPE_MAX_COLOR_BUFS];
53 };
54
55
56 /**
57 * Per-thread rasterization state
58 */
59 struct lp_rasterizer_task
60 {
61 struct lp_rast_tile tile; /** Tile color/z/stencil memory */
62
63 unsigned x, y; /**< Pos of this tile in framebuffer, in pixels */
64
65 const struct lp_rast_state *current_state;
66
67 /** "back" pointer */
68 struct lp_rasterizer *rast;
69
70 /** "my" index */
71 unsigned thread_index;
72
73 pipe_semaphore work_ready;
74 pipe_semaphore work_done;
75 };
76
77
78 /**
79 * This is the state required while rasterizing tiles.
80 * Note that this contains per-thread information too.
81 * The tile size is TILE_SIZE x TILE_SIZE pixels.
82 */
83 struct lp_rasterizer
84 {
85 boolean clipped_tile;
86 boolean check_for_clipped_tiles;
87 boolean exit_flag;
88
89 /* Framebuffer stuff
90 */
91 struct pipe_screen *screen;
92 struct pipe_transfer *cbuf_transfer[PIPE_MAX_COLOR_BUFS];
93 struct pipe_transfer *zsbuf_transfer;
94 void *cbuf_map[PIPE_MAX_COLOR_BUFS];
95 uint8_t *zsbuf_map;
96
97 struct {
98 struct pipe_framebuffer_state fb;
99 boolean write_color;
100 boolean write_zstencil;
101 unsigned clear_color;
102 unsigned clear_depth;
103 char clear_stencil;
104 } state;
105
106 /** The incoming queue of scenes ready to rasterize */
107 struct lp_scene_queue *full_scenes;
108 /** The outgoing queue of processed scenes to return to setup modulee */
109 struct lp_scene_queue *empty_scenes;
110
111 /** The scene currently being rasterized by the threads */
112 struct lp_scene *curr_scene;
113
114 /** A task object for each rasterization thread */
115 struct lp_rasterizer_task tasks[MAX_THREADS];
116
117 unsigned num_threads;
118 pipe_thread threads[MAX_THREADS];
119
120 /** For synchronizing the rasterization threads */
121 pipe_barrier barrier;
122 };
123
124
125 void lp_rast_shade_quads( struct lp_rasterizer_task *task,
126 const struct lp_rast_shader_inputs *inputs,
127 unsigned x, unsigned y,
128 int32_t c1, int32_t c2, int32_t c3);
129
130
131 /**
132 * Get the pointer to the depth buffer for a block.
133 * \param x, y location of 4x4 block in window coords
134 */
135 static INLINE void *
136 lp_rast_depth_pointer( struct lp_rasterizer *rast,
137 unsigned x, unsigned y )
138 {
139 void * depth;
140 assert((x % TILE_VECTOR_WIDTH) == 0);
141 assert((y % TILE_VECTOR_HEIGHT) == 0);
142 if(!rast->zsbuf_map)
143 return NULL;
144 assert(rast->zsbuf_transfer);
145 depth = rast->zsbuf_map +
146 y*rast->zsbuf_transfer->stride +
147 TILE_VECTOR_HEIGHT*x*util_format_get_blocksize(rast->zsbuf_transfer->texture->format);
148 #ifdef DEBUG
149 assert(lp_check_alignment(depth, 16));
150 #endif
151 return depth;
152 }
153
154
155
156 /**
157 * Shade all pixels in a 4x4 block. The fragment code omits the
158 * triangle in/out tests.
159 * \param x, y location of 4x4 block in window coords
160 */
161 static INLINE void
162 lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
163 const struct lp_rast_shader_inputs *inputs,
164 unsigned x, unsigned y )
165 {
166 struct lp_rasterizer *rast = task->rast;
167 const struct lp_rast_state *state = task->current_state;
168 struct lp_rast_tile *tile = &task->tile;
169 const unsigned ix = x % TILE_SIZE, iy = y % TILE_SIZE;
170 uint8_t *color[PIPE_MAX_COLOR_BUFS];
171 void *depth;
172 unsigned block_offset, i;
173
174 /* offset of the containing 16x16 pixel block within the tile */
175 block_offset = (iy / 4) * (16 * 16) + (ix / 4) * 16;
176
177 /* color buffer */
178 for (i = 0; i < rast->state.fb.nr_cbufs; i++)
179 color[i] = tile->color[i] + 4 * block_offset;
180
181 depth = lp_rast_depth_pointer(rast, x, y);
182
183 /* run shader */
184 state->jit_function[0]( &state->jit_context,
185 x, y,
186 inputs->a0,
187 inputs->dadx,
188 inputs->dady,
189 color,
190 depth,
191 INT_MIN, INT_MIN, INT_MIN,
192 NULL, NULL, NULL );
193 }
194
195
196 #endif