llvmpipe: generate two shader varients, one omits triangle in/out testing
[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 "pipe/p_thread.h"
32 #include "lp_rast.h"
33 #include "lp_tile_soa.h"
34
35
36 #define MAX_THREADS 8 /* XXX probably temporary here */
37
38
39 struct pipe_transfer;
40 struct pipe_screen;
41 struct lp_rasterizer;
42
43
44 /**
45 * A tile's color and depth memory.
46 * We can choose whatever layout for the internal tile storage we prefer.
47 */
48 struct lp_rast_tile
49 {
50 uint8_t *color[PIPE_MAX_COLOR_BUFS];
51
52 uint32_t *depth;
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
88 /* Framebuffer stuff
89 */
90 struct pipe_screen *screen;
91 struct pipe_transfer *cbuf_transfer[PIPE_MAX_COLOR_BUFS];
92 struct pipe_transfer *zsbuf_transfer;
93 void *cbuf_map[PIPE_MAX_COLOR_BUFS];
94 void *zsbuf_map;
95
96 struct {
97 struct pipe_framebuffer_state fb;
98 boolean write_color;
99 boolean write_zstencil;
100 unsigned clear_color;
101 unsigned clear_depth;
102 char clear_stencil;
103 } state;
104
105 /** The incoming queue of scenes ready to rasterize */
106 struct lp_scene_queue *full_scenes;
107 /** The outgoing queue of processed scenes to return to setup modulee */
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[MAX_THREADS];
115
116 unsigned num_threads;
117 pipe_thread threads[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 *rast,
125 unsigned thread_index,
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 * Shade all pixels in a 4x4 block. The fragment code omits the
133 * triangle in/out tests.
134 * \param x, y location of 4x4 block in window coords
135 */
136 static INLINE void
137 lp_rast_shade_quads_all( struct lp_rasterizer *rast,
138 unsigned thread_index,
139 const struct lp_rast_shader_inputs *inputs,
140 unsigned x, unsigned y )
141 {
142 const struct lp_rast_state *state = rast->tasks[thread_index].current_state;
143 struct lp_rast_tile *tile = &rast->tasks[thread_index].tile;
144 const unsigned ix = x % TILE_SIZE, iy = y % TILE_SIZE;
145 uint8_t *color[PIPE_MAX_COLOR_BUFS];
146 void *depth;
147 unsigned block_offset, i;
148
149 /* offset of the containing 16x16 pixel block within the tile */
150 block_offset = (iy / 4) * (16 * 16) + (ix / 4) * 16;
151
152 /* color buffer */
153 for (i = 0; i < rast->state.fb.nr_cbufs; i++)
154 color[i] = tile->color[i] + 4 * block_offset;
155
156 /* depth buffer */
157 depth = tile->depth + block_offset;
158
159 /* run shader */
160 state->jit_function[0]( &state->jit_context,
161 x, y,
162 inputs->a0,
163 inputs->dadx,
164 inputs->dady,
165 color,
166 depth,
167 INT_MIN, INT_MIN, INT_MIN,
168 NULL, NULL, NULL );
169 }
170
171
172 #endif