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"
37 #include "lp_texture.h"
38 #include "lp_tile_soa.h"
39 #include "lp_limits.h"
46 * Per-thread rasterization state
48 struct lp_rasterizer_task
50 unsigned x
, y
; /**< Pos of this tile in framebuffer, in pixels */
52 uint8_t *color_tiles
[PIPE_MAX_COLOR_BUFS
];
55 const struct lp_rast_state
*current_state
;
58 struct lp_rasterizer
*rast
;
61 unsigned thread_index
;
63 /* occlude counter for visiable pixels */
66 pipe_semaphore work_ready
;
67 pipe_semaphore work_done
;
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.
95 /** The incoming queue of scenes ready to rasterize */
96 struct lp_scene_queue
*full_scenes
;
99 * The outgoing queue of processed scenes to return to setup module
101 * XXX: while scenes are per-context but the rasterizer is
102 * (potentially) shared, these empty scenes should be returned to
103 * the context which created them rather than retained here.
105 /* struct lp_scene_queue *empty_scenes; */
107 /** The scene currently being rasterized by the threads */
108 struct lp_scene
*curr_scene
;
110 /** A task object for each rasterization thread */
111 struct lp_rasterizer_task tasks
[LP_MAX_THREADS
];
113 unsigned num_threads
;
114 pipe_thread threads
[LP_MAX_THREADS
];
116 /** For synchronizing the rasterization threads */
117 pipe_barrier barrier
;
121 void lp_rast_shade_quads( struct lp_rasterizer_task
*task
,
122 const struct lp_rast_shader_inputs
*inputs
,
123 unsigned x
, unsigned y
,
124 int32_t c1
, int32_t c2
, int32_t c3
);
128 * Get the pointer to a 4x4 depth/stencil block.
129 * We'll map the z/stencil buffer on demand here.
130 * Note that this may be called even when there's no z/stencil buffer - return
132 * \param x, y location of 4x4 block in window coords
135 lp_rast_get_depth_block_pointer(const struct lp_rasterizer
*rast
,
136 unsigned x
, unsigned y
)
140 assert((x
% TILE_VECTOR_WIDTH
) == 0);
141 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
143 assert(rast
->zsbuf
.map
|| !rast
->curr_scene
->fb
.zsbuf
);
145 if (!rast
->zsbuf
.map
)
148 depth
= (rast
->zsbuf
.map
+
149 rast
->zsbuf
.stride
* y
+
150 rast
->zsbuf
.blocksize
* x
* TILE_VECTOR_HEIGHT
);
152 assert(lp_check_alignment(depth
, 16));
158 * Get the pointer to a 4x4 color block (within a 64x64 tile).
159 * We'll map the color buffer on demand here.
160 * Note that this may be called even when there's no color buffers - return
162 * \param x, y location of 4x4 block in window coords
164 static INLINE
uint8_t *
165 lp_rast_get_color_block_pointer(struct lp_rasterizer_task
*task
,
166 unsigned buf
, unsigned x
, unsigned y
)
168 unsigned px
, py
, pixel_offset
;
171 assert((x
% TILE_VECTOR_WIDTH
) == 0);
172 assert((y
% TILE_VECTOR_HEIGHT
) == 0);
174 color
= task
->color_tiles
[buf
];
179 pixel_offset
= tile_pixel_offset(px
, py
, 0);
181 color
= color
+ pixel_offset
;
183 assert(lp_check_alignment(color
, 16));
190 * Shade all pixels in a 4x4 block. The fragment code omits the
191 * triangle in/out tests.
192 * \param x, y location of 4x4 block in window coords
195 lp_rast_shade_quads_all( struct lp_rasterizer_task
*task
,
196 const struct lp_rast_shader_inputs
*inputs
,
197 unsigned x
, unsigned y
)
199 struct lp_rasterizer
*rast
= task
->rast
;
200 const struct lp_rast_state
*state
= task
->current_state
;
201 struct lp_fragment_shader_variant
*variant
= state
->variant
;
202 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
207 for (i
= 0; i
< rast
->state
.nr_cbufs
; i
++)
208 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, x
, y
);
210 depth
= lp_rast_get_depth_block_pointer(rast
, x
, y
);
212 /* run shader on 4x4 block */
213 variant
->jit_function
[RAST_WHOLE
]( &state
->jit_context
,
221 INT_MIN
, INT_MIN
, INT_MIN
,
222 NULL
, NULL
, NULL
, &task
->vis_counter
);