1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
26 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "pipe/draw/draw_context.h"
33 #include "pipe/p_defines.h"
34 #include "pipe/p_util.h"
36 #include "sp_context.h"
38 #include "sp_prim_setup.h"
39 #include "sp_region.h"
41 #include "sp_surface.h"
42 #include "sp_tile_cache.h"
43 #include "sp_texture.h"
44 #include "sp_winsys.h"
49 * Query format support.
50 * If we find texture and drawable support differs, add a selector
51 * parameter or another function.
54 softpipe_is_format_supported( struct pipe_context
*pipe
, uint format
)
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
);
63 * Map any drawing surfaces which aren't already mapped
66 softpipe_map_surfaces(struct softpipe_context
*sp
)
68 struct pipe_context
*pipe
= &sp
->pipe
;
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
);
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
);
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
);
95 softpipe_map_texture_surfaces(struct softpipe_context
*sp
)
97 struct pipe_context
*pipe
= &sp
->pipe
;
100 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
101 struct softpipe_texture
*spt
= sp
->texture
[i
];
103 pipe
->region_map(pipe
, spt
->region
);
110 * Unmap any mapped drawing surfaces
113 softpipe_unmap_surfaces(struct softpipe_context
*sp
)
115 struct pipe_context
*pipe
= &sp
->pipe
;
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
);
123 for (i
= 0; i
< sp
->framebuffer
.num_cbufs
; i
++) {
124 struct pipe_surface
*ps
= sp
->framebuffer
.cbufs
[i
];
126 pipe
->region_unmap(pipe
, ps
->region
);
129 if (sp
->framebuffer
.zbuf
) {
130 struct pipe_surface
*ps
= sp
->framebuffer
.zbuf
;
132 pipe
->region_unmap(pipe
, ps
->region
);
135 if (sp
->framebuffer
.sbuf
&& sp
->framebuffer
.sbuf
!= sp
->framebuffer
.zbuf
) {
136 struct pipe_surface
*ps
= sp
->framebuffer
.sbuf
;
138 pipe
->region_unmap(pipe
, ps
->region
);
144 softpipe_unmap_texture_surfaces(struct softpipe_context
*sp
)
146 struct pipe_context
*pipe
= &sp
->pipe
;
148 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
149 struct softpipe_texture
*spt
= sp
->texture
[i
];
151 pipe
->region_unmap(pipe
, spt
->region
);
157 static void softpipe_destroy( struct pipe_context
*pipe
)
159 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
161 draw_destroy( softpipe
->draw
);
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
);
181 softpipe_begin_query(struct pipe_context
*pipe
, struct pipe_query_object
*q
)
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
;
191 softpipe_end_query(struct pipe_context
*pipe
, struct pipe_query_object
*q
)
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
;
202 softpipe_wait_query(struct pipe_context
*pipe
, struct pipe_query_object
*q
)
204 /* Should never get here since we indicated that the result was
205 * ready in softpipe_end_query().
211 static const char *softpipe_get_name( struct pipe_context
*pipe
)
216 static const char *softpipe_get_vendor( struct pipe_context
*pipe
)
218 return "Tungsten Graphics, Inc.";
221 static int softpipe_get_param(struct pipe_context
*pipe
, int param
)
224 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
226 case PIPE_CAP_NPOT_TEXTURES
:
228 case PIPE_CAP_TWO_SIDED_STENCIL
:
234 case PIPE_CAP_ANISOTROPIC_FILTER
:
236 case PIPE_CAP_POINT_SPRITE
:
238 case PIPE_CAP_MAX_RENDER_TARGETS
:
240 case PIPE_CAP_OCCLUSION_QUERY
:
242 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
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 */
255 static float softpipe_get_paramf(struct pipe_context
*pipe
, int param
)
258 case PIPE_CAP_MAX_LINE_WIDTH
:
260 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
261 return 255.0; /* arbitrary */
263 case PIPE_CAP_MAX_POINT_WIDTH
:
265 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
266 return 255.0; /* arbitrary */
268 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
271 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
272 return 16.0; /* arbitrary */
279 struct pipe_context
*softpipe_create( struct pipe_winsys
*pipe_winsys
,
280 struct softpipe_winsys
*softpipe_winsys
)
282 struct softpipe_context
*softpipe
= CALLOC_STRUCT(softpipe_context
);
285 #if defined(__i386__) || defined(__386__)
286 softpipe
->use_sse
= GETENV( "GALLIUM_SSE" ) != NULL
;
288 softpipe
->use_sse
= FALSE
;
291 softpipe
->dump_fs
= GETENV( "GALLIUM_DUMP_FS" ) != NULL
;
293 softpipe
->pipe
.winsys
= pipe_winsys
;
294 softpipe
->pipe
.destroy
= softpipe_destroy
;
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
;
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
;
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
;
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
;
340 softpipe
->pipe
.draw_arrays
= softpipe_draw_arrays
;
341 softpipe
->pipe
.draw_elements
= softpipe_draw_elements
;
343 softpipe
->pipe
.clear
= softpipe_clear
;
344 softpipe
->pipe
.flush
= softpipe_flush
;
346 softpipe
->pipe
.begin_query
= softpipe_begin_query
;
347 softpipe
->pipe
.end_query
= softpipe_end_query
;
348 softpipe
->pipe
.wait_query
= softpipe_wait_query
;
350 softpipe
->pipe
.get_name
= softpipe_get_name
;
351 softpipe
->pipe
.get_vendor
= softpipe_get_vendor
;
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
;
359 * Alloc caches for accessing drawing surfaces and textures.
360 * Must be before quad stage setup!
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 */
368 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++)
369 softpipe
->tex_cache
[i
] = sp_create_tile_cache();
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
);
386 softpipe
->winsys
= softpipe_winsys
;
389 * Create drawing context and plug our rendering stage into it.
391 softpipe
->draw
= draw_create();
392 assert(softpipe
->draw
);
393 softpipe
->setup
= sp_draw_render_stage(softpipe
);
395 if (GETENV( "SP_VBUF" ) != NULL
) {
396 softpipe
->vbuf
= sp_draw_vbuf_stage(softpipe
->draw
,
400 draw_set_rasterize_stage(softpipe
->draw
, softpipe
->vbuf
);
403 draw_set_rasterize_stage(softpipe
->draw
, softpipe
->setup
);
407 sp_init_region_functions(softpipe
);
408 sp_init_surface_functions(softpipe
);
410 return &softpipe
->pipe
;