llvmpipe: remove some old sampler support structs
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast.c
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 #include "util/u_memory.h"
29
30 #include "lp_state.h"
31 #include "lp_quad.h"
32 #include "lp_rast.h"
33 #include "lp_rast_priv.h"
34 #include "lp_tile_soa.h"
35 #include "lp_bld_debug.h"
36
37
38 struct lp_rasterizer *lp_rast_create( void )
39 {
40 return CALLOC_STRUCT(lp_rasterizer);
41 }
42
43 void lp_rast_bind_surfaces( struct lp_rasterizer *rast,
44 struct pipe_surface *color,
45 struct pipe_surface *zstencil,
46 const float *clear_color,
47 double clear_depth,
48 unsigned clear_stencil)
49 {
50 pipe_surface_reference(&rast->state.color, color);
51 pipe_surface_reference(&rast->state.depth, depth);
52 }
53
54
55 /* Begining of each tile:
56 */
57 void lp_rast_start_tile( struct lp_rasterizer *,
58 unsigned x,
59 unsigned y )
60 {
61 rast->x = x;
62 rast->y = y;
63 }
64
65 void lp_rast_clear_color( struct lp_rasterizer *rast,
66 const union lp_rast_cmd_arg *arg )
67 {
68 const unsigned clear_color = arg->clear.clear_color;
69 unsigned i, j;
70
71 for (i = 0; i < TILESIZE; i++)
72 for (j = 0; j < TILESIZE; j++)
73 rast->tile[i][j] = clear_color;
74 }
75
76 void lp_rast_clear_zstencil( struct lp_rasterizer *rast,
77 const union lp_rast_cmd_arg *arg)
78 {
79 const unsigned clear_color = arg->clear.clear_zstencil;
80 unsigned i, j;
81
82 for (i = 0; i < TILESIZE; i++)
83 for (j = 0; j < TILESIZE; j++)
84 rast->tile[i][j] = clear_depth;
85 }
86
87
88 void lp_rast_load_color( struct lp_rasterizer *rast,
89 const union lp_rast_cmd_arg *arg)
90 {
91 /* call u_tile func to load colors from surface */
92 }
93
94 void lp_rast_load_zstencil( struct lp_rasterizer *rast,
95 const union lp_rast_cmd_arg *arg )
96 {
97 /* call u_tile func to load depth (and stencil?) from surface */
98 }
99
100 /* Within a tile:
101 */
102 void lp_rast_set_state( struct lp_rasterizer *rast,
103 const union lp_rast_cmd_arg *arg )
104 {
105 rast->shader_state = arg->state;
106
107 }
108
109
110 void lp_rast_shade_tile( struct lp_rasterizer *rast,
111 const union lp_rast_cmd_arg *arg )
112 const struct lp_rast_shader_inputs *inputs )
113 {
114 /* Set up the silly quad coef pointers
115 */
116 for (i = 0; i < 4; i++) {
117 rast->quads[i].posCoef = &inputs->posCoef;
118 rast->quads[i].coef = inputs->coef;
119 }
120
121 /* Use the existing preference for 8x2 (four quads) shading:
122 */
123 for (i = 0; i < TILESIZE; i += 8) {
124 for (j = 0; j < TILESIZE; j += 2) {
125 rast->shader_state.shade( inputs->jc,
126 rast->x + i,
127 rast->y + j,
128 rast->quads, 4 );
129 }
130 }
131 }
132
133
134 void lp_rast_shade_quads( const struct lp_rast_state *state,
135 struct lp_rast_tile *tile,
136 struct quad_header **quads,
137 unsigned nr )
138 {
139 struct quad_header *quad = quads[0];
140 const unsigned x = quad->input.x0;
141 const unsigned y = quad->input.y0;
142 uint8_t *color;
143 uint8_t *depth;
144 uint32_t ALIGN16_ATTRIB mask[4][NUM_CHANNELS];
145 unsigned chan_index;
146 unsigned q;
147
148 /* Sanity checks */
149 assert(nr * QUAD_SIZE == TILE_VECTOR_HEIGHT * TILE_VECTOR_WIDTH);
150 assert(x % TILE_VECTOR_WIDTH == 0);
151 assert(y % TILE_VECTOR_HEIGHT == 0);
152 for (q = 0; q < nr; ++q) {
153 assert(quads[q]->input.x0 == x + q*2);
154 assert(quads[q]->input.y0 == y);
155 }
156
157 /* mask */
158 for (q = 0; q < 4; ++q)
159 for (chan_index = 0; chan_index < NUM_CHANNELS; ++chan_index)
160 mask[q][chan_index] = quads[q]->inout.mask & (1 << chan_index) ? ~0 : 0;
161
162 /* color buffer */
163 color = &TILE_PIXEL(tile->color, x, y, 0);
164
165 /* depth buffer */
166 assert((x % 2) == 0);
167 assert((y % 2) == 0);
168 depth = (uint8_t *)tile->depth + y*TILE_SIZE*4 + 2*x*4;
169
170 /* XXX: This will most likely fail on 32bit x86 without -mstackrealign */
171 assert(lp_check_alignment(mask, 16));
172
173 assert(lp_check_alignment(depth, 16));
174 assert(lp_check_alignment(color, 16));
175 assert(lp_check_alignment(state->jc.blend_color, 16));
176
177 /* run shader */
178 state->shader( &state->jc,
179 x, y,
180 quad->coef->a0,
181 quad->coef->dadx,
182 quad->coef->dady,
183 &mask[0][0],
184 color,
185 depth);
186
187 }
188
189
190 /* End of tile:
191 */
192 void lp_rast_end_tile( struct lp_rasterizer *rast,
193 boolean write_depth )
194 {
195 /* call u_tile func to store colors to surface */
196
197 if (write_depth) {
198 /* call u_tile func to store depth/stencil to surface */
199 }
200 }
201
202 /* Shutdown:
203 */
204 void lp_rast_destroy( struct lp_rasterizer *rast )
205 {
206 FREE(rast);
207 }
208