Remove remnants of 'intel' from active state tracker code.
[mesa.git] / src / mesa / pipe / softpipe / sp_context.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 /* Author:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "pipe/draw/draw_context.h"
33 #include "pipe/p_defines.h"
34 #include "pipe/p_util.h"
35 #include "sp_clear.h"
36 #include "sp_context.h"
37 #include "sp_flush.h"
38 #include "sp_prim_setup.h"
39 #include "sp_region.h"
40 #include "sp_state.h"
41 #include "sp_surface.h"
42 #include "sp_tile_cache.h"
43 #include "sp_texture.h"
44 #include "sp_winsys.h"
45
46
47
48 /**
49 * Query format support.
50 * If we find texture and drawable support differs, add a selector
51 * parameter or another function.
52 */
53 static boolean
54 softpipe_is_format_supported( struct pipe_context *pipe, uint format )
55 {
56 struct softpipe_context *softpipe = softpipe_context( pipe );
57 /* ask winsys if the format is supported */
58 return softpipe->winsys->is_format_supported( softpipe->winsys, format );
59 }
60
61
62 /**
63 * Map any drawing surfaces which aren't already mapped
64 */
65 void
66 softpipe_map_surfaces(struct softpipe_context *sp)
67 {
68 struct pipe_context *pipe = &sp->pipe;
69 unsigned i;
70
71 for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
72 struct pipe_surface *ps = sp->framebuffer.cbufs[i];
73 if (ps->region && !ps->region->map) {
74 pipe->region_map(pipe, ps->region);
75 }
76 }
77
78 if (sp->framebuffer.zbuf) {
79 struct pipe_surface *ps = sp->framebuffer.zbuf;
80 if (ps->region && !ps->region->map) {
81 pipe->region_map(pipe, ps->region);
82 }
83 }
84
85 if (sp->framebuffer.sbuf) {
86 struct pipe_surface *ps = sp->framebuffer.sbuf;
87 if (ps->region && !ps->region->map) {
88 pipe->region_map(pipe, ps->region);
89 }
90 }
91 }
92
93
94 void
95 softpipe_map_texture_surfaces(struct softpipe_context *sp)
96 {
97 struct pipe_context *pipe = &sp->pipe;
98 uint i;
99
100 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
101 struct softpipe_texture *spt = sp->texture[i];
102 if (spt) {
103 pipe->region_map(pipe, spt->region);
104 }
105 }
106 }
107
108
109 /**
110 * Unmap any mapped drawing surfaces
111 */
112 void
113 softpipe_unmap_surfaces(struct softpipe_context *sp)
114 {
115 struct pipe_context *pipe = &sp->pipe;
116 uint i;
117
118 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
119 sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
120 sp_flush_tile_cache(sp, sp->zbuf_cache);
121 sp_flush_tile_cache(sp, sp->sbuf_cache);
122
123 for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
124 struct pipe_surface *ps = sp->framebuffer.cbufs[i];
125 if (ps->region)
126 pipe->region_unmap(pipe, ps->region);
127 }
128
129 if (sp->framebuffer.zbuf) {
130 struct pipe_surface *ps = sp->framebuffer.zbuf;
131 if (ps->region)
132 pipe->region_unmap(pipe, ps->region);
133 }
134
135 if (sp->framebuffer.sbuf && sp->framebuffer.sbuf != sp->framebuffer.zbuf) {
136 struct pipe_surface *ps = sp->framebuffer.sbuf;
137 if (ps->region)
138 pipe->region_unmap(pipe, ps->region);
139 }
140 }
141
142
143 void
144 softpipe_unmap_texture_surfaces(struct softpipe_context *sp)
145 {
146 struct pipe_context *pipe = &sp->pipe;
147 uint i;
148 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
149 struct softpipe_texture *spt = sp->texture[i];
150 if (spt) {
151 pipe->region_unmap(pipe, spt->region);
152 }
153 }
154 }
155
156
157 static void softpipe_destroy( struct pipe_context *pipe )
158 {
159 struct softpipe_context *softpipe = softpipe_context( pipe );
160
161 draw_destroy( softpipe->draw );
162
163 softpipe->quad.polygon_stipple->destroy( softpipe->quad.polygon_stipple );
164 softpipe->quad.earlyz->destroy( softpipe->quad.earlyz );
165 softpipe->quad.shade->destroy( softpipe->quad.shade );
166 softpipe->quad.alpha_test->destroy( softpipe->quad.alpha_test );
167 softpipe->quad.depth_test->destroy( softpipe->quad.depth_test );
168 softpipe->quad.stencil_test->destroy( softpipe->quad.stencil_test );
169 softpipe->quad.occlusion->destroy( softpipe->quad.occlusion );
170 softpipe->quad.coverage->destroy( softpipe->quad.coverage );
171 softpipe->quad.bufloop->destroy( softpipe->quad.bufloop );
172 softpipe->quad.blend->destroy( softpipe->quad.blend );
173 softpipe->quad.colormask->destroy( softpipe->quad.colormask );
174 softpipe->quad.output->destroy( softpipe->quad.output );
175
176 FREE( softpipe );
177 }
178
179
180 static void
181 softpipe_begin_query(struct pipe_context *pipe, struct pipe_query_object *q)
182 {
183 struct softpipe_context *softpipe = softpipe_context( pipe );
184 assert(q->type < PIPE_QUERY_TYPES);
185 assert(!softpipe->queries[q->type]);
186 softpipe->queries[q->type] = q;
187 }
188
189
190 static void
191 softpipe_end_query(struct pipe_context *pipe, struct pipe_query_object *q)
192 {
193 struct softpipe_context *softpipe = softpipe_context( pipe );
194 assert(q->type < PIPE_QUERY_TYPES);
195 assert(softpipe->queries[q->type]);
196 q->ready = 1; /* software rendering is synchronous */
197 softpipe->queries[q->type] = NULL;
198 }
199
200
201 static void
202 softpipe_wait_query(struct pipe_context *pipe, struct pipe_query_object *q)
203 {
204 /* Should never get here since we indicated that the result was
205 * ready in softpipe_end_query().
206 */
207 assert(0);
208 }
209
210
211 static const char *softpipe_get_name( struct pipe_context *pipe )
212 {
213 return "softpipe";
214 }
215
216 static const char *softpipe_get_vendor( struct pipe_context *pipe )
217 {
218 return "Tungsten Graphics, Inc.";
219 }
220
221 static int softpipe_get_param(struct pipe_context *pipe, int param)
222 {
223 switch (param) {
224 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
225 return 8;
226 case PIPE_CAP_NPOT_TEXTURES:
227 return 1;
228 case PIPE_CAP_TWO_SIDED_STENCIL:
229 return 1;
230 case PIPE_CAP_GLSL:
231 return 1;
232 case PIPE_CAP_S3TC:
233 return 0;
234 case PIPE_CAP_ANISOTROPIC_FILTER:
235 return 0;
236 case PIPE_CAP_POINT_SPRITE:
237 return 1;
238 case PIPE_CAP_MAX_RENDER_TARGETS:
239 return 1;
240 case PIPE_CAP_OCCLUSION_QUERY:
241 return 1;
242 case PIPE_CAP_TEXTURE_SHADOW_MAP:
243 return 1;
244 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
245 return 12; /* max 2Kx2K */
246 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
247 return 8; /* max 128x128x128 */
248 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
249 return 12; /* max 2Kx2K */
250 default:
251 return 0;
252 }
253 }
254
255 static float softpipe_get_paramf(struct pipe_context *pipe, int param)
256 {
257 switch (param) {
258 case PIPE_CAP_MAX_LINE_WIDTH:
259 /* fall-through */
260 case PIPE_CAP_MAX_LINE_WIDTH_AA:
261 return 255.0; /* arbitrary */
262
263 case PIPE_CAP_MAX_POINT_WIDTH:
264 /* fall-through */
265 case PIPE_CAP_MAX_POINT_WIDTH_AA:
266 return 255.0; /* arbitrary */
267
268 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
269 return 0.0;
270
271 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
272 return 16.0; /* arbitrary */
273
274 default:
275 return 0;
276 }
277 }
278
279 struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
280 struct softpipe_winsys *softpipe_winsys )
281 {
282 struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
283 uint i;
284
285 #if defined(__i386__) || defined(__386__)
286 softpipe->use_sse = GETENV( "GALLIUM_SSE" ) != NULL;
287 #else
288 softpipe->use_sse = FALSE;
289 #endif
290
291 softpipe->dump_fs = GETENV( "GALLIUM_DUMP_FS" ) != NULL;
292
293 softpipe->pipe.winsys = pipe_winsys;
294 softpipe->pipe.destroy = softpipe_destroy;
295
296 /* queries */
297 softpipe->pipe.is_format_supported = softpipe_is_format_supported;
298 softpipe->pipe.get_param = softpipe_get_param;
299 softpipe->pipe.get_paramf = softpipe_get_paramf;
300
301 /* state setters */
302 softpipe->pipe.create_alpha_test_state = softpipe_create_alpha_test_state;
303 softpipe->pipe.bind_alpha_test_state = softpipe_bind_alpha_test_state;
304 softpipe->pipe.delete_alpha_test_state = softpipe_delete_alpha_test_state;
305 softpipe->pipe.create_blend_state = softpipe_create_blend_state;
306 softpipe->pipe.bind_blend_state = softpipe_bind_blend_state;
307 softpipe->pipe.delete_blend_state = softpipe_delete_blend_state;
308 softpipe->pipe.create_sampler_state = softpipe_create_sampler_state;
309 softpipe->pipe.bind_sampler_state = softpipe_bind_sampler_state;
310 softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state;
311 softpipe->pipe.create_depth_stencil_state = softpipe_create_depth_stencil_state;
312 softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state;
313 softpipe->pipe.delete_depth_stencil_state = softpipe_delete_depth_stencil_state;
314 softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state;
315 softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state;
316 softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state;
317 softpipe->pipe.create_fs_state = softpipe_create_fs_state;
318 softpipe->pipe.bind_fs_state = softpipe_bind_fs_state;
319 softpipe->pipe.delete_fs_state = softpipe_delete_fs_state;
320 softpipe->pipe.create_vs_state = softpipe_create_vs_state;
321 softpipe->pipe.bind_vs_state = softpipe_bind_vs_state;
322 softpipe->pipe.delete_vs_state = softpipe_delete_vs_state;
323
324 softpipe->pipe.set_blend_color = softpipe_set_blend_color;
325 softpipe->pipe.set_clip_state = softpipe_set_clip_state;
326 softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
327 softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer;
328 softpipe->pipe.set_feedback_state = softpipe_set_feedback_state;
329 softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
330 softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
331 softpipe->pipe.set_sampler_units = softpipe_set_sampler_units;
332 softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;
333 softpipe->pipe.set_texture_state = softpipe_set_texture_state;
334 softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
335
336 softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer;
337 softpipe->pipe.set_vertex_element = softpipe_set_vertex_element;
338 softpipe->pipe.set_feedback_buffer = softpipe_set_feedback_buffer;
339
340 softpipe->pipe.draw_arrays = softpipe_draw_arrays;
341 softpipe->pipe.draw_elements = softpipe_draw_elements;
342
343 softpipe->pipe.clear = softpipe_clear;
344 softpipe->pipe.flush = softpipe_flush;
345
346 softpipe->pipe.begin_query = softpipe_begin_query;
347 softpipe->pipe.end_query = softpipe_end_query;
348 softpipe->pipe.wait_query = softpipe_wait_query;
349
350 softpipe->pipe.get_name = softpipe_get_name;
351 softpipe->pipe.get_vendor = softpipe_get_vendor;
352
353 /* textures */
354 softpipe->pipe.texture_create = softpipe_texture_create;
355 softpipe->pipe.texture_release = softpipe_texture_release;
356 softpipe->pipe.get_tex_surface = softpipe_get_tex_surface;
357
358 /*
359 * Alloc caches for accessing drawing surfaces and textures.
360 * Must be before quad stage setup!
361 */
362 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
363 softpipe->cbuf_cache[i] = sp_create_tile_cache();
364 softpipe->zbuf_cache = sp_create_tile_cache();
365 softpipe->sbuf_cache_sep = sp_create_tile_cache();
366 softpipe->sbuf_cache = softpipe->sbuf_cache_sep; /* initial value */
367
368 for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
369 softpipe->tex_cache[i] = sp_create_tile_cache();
370
371
372 /* setup quad rendering stages */
373 softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);
374 softpipe->quad.earlyz = sp_quad_earlyz_stage(softpipe);
375 softpipe->quad.shade = sp_quad_shade_stage(softpipe);
376 softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);
377 softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
378 softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
379 softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);
380 softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);
381 softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
382 softpipe->quad.blend = sp_quad_blend_stage(softpipe);
383 softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
384 softpipe->quad.output = sp_quad_output_stage(softpipe);
385
386 softpipe->winsys = softpipe_winsys;
387
388 /*
389 * Create drawing context and plug our rendering stage into it.
390 */
391 softpipe->draw = draw_create();
392 assert(softpipe->draw);
393 softpipe->setup = sp_draw_render_stage(softpipe);
394
395 if (GETENV( "SP_VBUF" ) != NULL) {
396 softpipe->vbuf = sp_draw_vbuf_stage(softpipe->draw,
397 &softpipe->pipe,
398 sp_vbuf_setup_draw);
399
400 draw_set_rasterize_stage(softpipe->draw, softpipe->vbuf);
401 }
402 else {
403 draw_set_rasterize_stage(softpipe->draw, softpipe->setup);
404 }
405
406
407 sp_init_region_functions(softpipe);
408 sp_init_surface_functions(softpipe);
409
410 return &softpipe->pipe;
411 }