-/**************************************************************************\r
- * \r
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.\r
- * All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the\r
- * "Software"), to deal in the Software without restriction, including\r
- * without limitation the rights to use, copy, modify, merge, publish,\r
- * distribute, sub license, and/or sell copies of the Software, and to\r
- * permit persons to whom the Software is furnished to do so, subject to\r
- * the following conditions:\r
- * \r
- * The above copyright notice and this permission notice (including the\r
- * next paragraph) shall be included in all copies or substantial portions\r
- * of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR\r
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- * \r
- **************************************************************************/\r
-\r
-/* Author:\r
- * Keith Whitwell <keith@tungstengraphics.com>\r
- */\r
-\r
-#include "draw/draw_context.h"\r
-#include "pipe/p_defines.h"\r
-#include "pipe/p_inlines.h"\r
-#include "pipe/p_util.h"\r
-#include "sp_clear.h"\r
-#include "sp_context.h"\r
-#include "sp_flush.h"\r
-#include "sp_prim_setup.h"\r
-#include "sp_prim_vbuf.h"\r
-#include "sp_state.h"\r
-#include "sp_surface.h"\r
-#include "sp_tile_cache.h"\r
-#include "sp_texture.h"\r
-#include "sp_winsys.h"\r
-#include "sp_query.h"\r
-\r
-\r
-\r
-/**\r
- * Map any drawing surfaces which aren't already mapped\r
- */\r
-void\r
-softpipe_map_surfaces(struct softpipe_context *sp)\r
-{\r
- unsigned i;\r
-\r
- for (i = 0; i < sp->framebuffer.num_cbufs; i++) {\r
- sp_tile_cache_map_surfaces(sp->cbuf_cache[i]);\r
- }\r
-\r
- sp_tile_cache_map_surfaces(sp->zsbuf_cache);\r
-}\r
-\r
-\r
-/**\r
- * Unmap any mapped drawing surfaces\r
- */\r
-void\r
-softpipe_unmap_surfaces(struct softpipe_context *sp)\r
-{\r
- uint i;\r
-\r
- for (i = 0; i < sp->framebuffer.num_cbufs; i++)\r
- sp_flush_tile_cache(sp, sp->cbuf_cache[i]);\r
- sp_flush_tile_cache(sp, sp->zsbuf_cache);\r
-\r
- for (i = 0; i < sp->framebuffer.num_cbufs; i++) {\r
- sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]);\r
- }\r
- sp_tile_cache_unmap_surfaces(sp->zsbuf_cache);\r
-}\r
-\r
-\r
-static void softpipe_destroy( struct pipe_context *pipe )\r
-{\r
- struct softpipe_context *softpipe = softpipe_context( pipe );\r
- struct pipe_winsys *ws = pipe->winsys;\r
- uint i;\r
-\r
- draw_destroy( softpipe->draw );\r
-\r
- softpipe->quad.polygon_stipple->destroy( softpipe->quad.polygon_stipple );\r
- softpipe->quad.earlyz->destroy( softpipe->quad.earlyz );\r
- softpipe->quad.shade->destroy( softpipe->quad.shade );\r
- softpipe->quad.alpha_test->destroy( softpipe->quad.alpha_test );\r
- softpipe->quad.depth_test->destroy( softpipe->quad.depth_test );\r
- softpipe->quad.stencil_test->destroy( softpipe->quad.stencil_test );\r
- softpipe->quad.occlusion->destroy( softpipe->quad.occlusion );\r
- softpipe->quad.coverage->destroy( softpipe->quad.coverage );\r
- softpipe->quad.bufloop->destroy( softpipe->quad.bufloop );\r
- softpipe->quad.blend->destroy( softpipe->quad.blend );\r
- softpipe->quad.colormask->destroy( softpipe->quad.colormask );\r
- softpipe->quad.output->destroy( softpipe->quad.output );\r
-\r
- for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)\r
- sp_destroy_tile_cache(softpipe->cbuf_cache[i]);\r
- sp_destroy_tile_cache(softpipe->zsbuf_cache);\r
-\r
- for (i = 0; i < PIPE_MAX_SAMPLERS; i++)\r
- sp_destroy_tile_cache(softpipe->tex_cache[i]);\r
-\r
- for (i = 0; i < Elements(softpipe->constants); i++) {\r
- if (softpipe->constants[i].buffer) {\r
- pipe_buffer_reference(ws, &softpipe->constants[i].buffer, NULL);\r
- }\r
- }\r
-\r
- FREE( softpipe );\r
-}\r
-\r
-\r
-struct pipe_context *\r
-softpipe_create( struct pipe_screen *screen,\r
- struct pipe_winsys *pipe_winsys,\r
- struct softpipe_winsys *softpipe_winsys )\r
-{\r
- struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);\r
- uint i;\r
-\r
-#if defined(__i386__) || defined(__386__)\r
- softpipe->use_sse = GETENV( "GALLIUM_NOSSE" ) == NULL;\r
-#else\r
- softpipe->use_sse = FALSE;\r
-#endif\r
-\r
- softpipe->dump_fs = GETENV( "GALLIUM_DUMP_FS" ) != NULL;\r
-\r
- softpipe->pipe.winsys = pipe_winsys;\r
- softpipe->pipe.screen = screen;\r
- softpipe->pipe.destroy = softpipe_destroy;\r
-\r
- /* state setters */\r
- softpipe->pipe.create_blend_state = softpipe_create_blend_state;\r
- softpipe->pipe.bind_blend_state = softpipe_bind_blend_state;\r
- softpipe->pipe.delete_blend_state = softpipe_delete_blend_state;\r
-\r
- softpipe->pipe.create_sampler_state = softpipe_create_sampler_state;\r
- softpipe->pipe.bind_sampler_states = softpipe_bind_sampler_states;\r
- softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state;\r
-\r
- softpipe->pipe.create_depth_stencil_alpha_state = softpipe_create_depth_stencil_state;\r
- softpipe->pipe.bind_depth_stencil_alpha_state = softpipe_bind_depth_stencil_state;\r
- softpipe->pipe.delete_depth_stencil_alpha_state = softpipe_delete_depth_stencil_state;\r
-\r
- softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state;\r
- softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state;\r
- softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state;\r
-\r
- softpipe->pipe.create_fs_state = softpipe_create_fs_state;\r
- softpipe->pipe.bind_fs_state = softpipe_bind_fs_state;\r
- softpipe->pipe.delete_fs_state = softpipe_delete_fs_state;\r
-\r
- softpipe->pipe.create_vs_state = softpipe_create_vs_state;\r
- softpipe->pipe.bind_vs_state = softpipe_bind_vs_state;\r
- softpipe->pipe.delete_vs_state = softpipe_delete_vs_state;\r
-\r
- softpipe->pipe.set_blend_color = softpipe_set_blend_color;\r
- softpipe->pipe.set_clip_state = softpipe_set_clip_state;\r
- softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer;\r
- softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;\r
- softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;\r
- softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;\r
- softpipe->pipe.set_sampler_textures = softpipe_set_sampler_textures;\r
- softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;\r
-\r
- softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer;\r
- softpipe->pipe.set_vertex_element = softpipe_set_vertex_element;\r
-\r
- softpipe->pipe.draw_arrays = softpipe_draw_arrays;\r
- softpipe->pipe.draw_elements = softpipe_draw_elements;\r
-\r
- softpipe->pipe.clear = softpipe_clear;\r
- softpipe->pipe.flush = softpipe_flush;\r
-\r
- softpipe_init_query_funcs( softpipe );\r
- softpipe_init_texture_funcs( softpipe );\r
-\r
- /*\r
- * Alloc caches for accessing drawing surfaces and textures.\r
- * Must be before quad stage setup!\r
- */\r
- for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)\r
- softpipe->cbuf_cache[i] = sp_create_tile_cache();\r
- softpipe->zsbuf_cache = sp_create_tile_cache();\r
-\r
- for (i = 0; i < PIPE_MAX_SAMPLERS; i++)\r
- softpipe->tex_cache[i] = sp_create_tile_cache();\r
-\r
-\r
- /* setup quad rendering stages */\r
- softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);\r
- softpipe->quad.earlyz = sp_quad_earlyz_stage(softpipe);\r
- softpipe->quad.shade = sp_quad_shade_stage(softpipe);\r
- softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);\r
- softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);\r
- softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);\r
- softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);\r
- softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);\r
- softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);\r
- softpipe->quad.blend = sp_quad_blend_stage(softpipe);\r
- softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);\r
- softpipe->quad.output = sp_quad_output_stage(softpipe);\r
-\r
- softpipe->winsys = softpipe_winsys;\r
-\r
- /*\r
- * Create drawing context and plug our rendering stage into it.\r
- */\r
- softpipe->draw = draw_create();\r
- assert(softpipe->draw);\r
- softpipe->setup = sp_draw_render_stage(softpipe);\r
-\r
- if (GETENV( "SP_VBUF" ) != NULL) {\r
- sp_init_vbuf(softpipe);\r
- }\r
- else {\r
- draw_set_rasterize_stage(softpipe->draw, softpipe->setup);\r
- }\r
-\r
- /* plug in AA line/point stages */\r
- draw_install_aaline_stage(softpipe->draw, &softpipe->pipe);\r
- draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe);\r
-\r
-#if USE_DRAW_STAGE_PSTIPPLE\r
- /* Do polygon stipple w/ texture map + frag prog? */\r
- draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe);\r
-#endif\r
-\r
- sp_init_surface_functions(softpipe);\r
-\r
- return &softpipe->pipe;\r
-}\r
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Author:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "draw/draw_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_util.h"
+#include "sp_clear.h"
+#include "sp_context.h"
+#include "sp_flush.h"
+#include "sp_prim_setup.h"
+#include "sp_prim_vbuf.h"
+#include "sp_state.h"
+#include "sp_surface.h"
+#include "sp_tile_cache.h"
+#include "sp_texture.h"
+#include "sp_winsys.h"
+#include "sp_query.h"
+
+
+
+/**
+ * Map any drawing surfaces which aren't already mapped
+ */
+void
+softpipe_map_surfaces(struct softpipe_context *sp)
+{
+ unsigned i;
+
+ for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
+ sp_tile_cache_map_surfaces(sp->cbuf_cache[i]);
+ }
+
+ sp_tile_cache_map_surfaces(sp->zsbuf_cache);
+}
+
+
+/**
+ * Unmap any mapped drawing surfaces
+ */
+void
+softpipe_unmap_surfaces(struct softpipe_context *sp)
+{
+ uint i;
+
+ for (i = 0; i < sp->framebuffer.num_cbufs; i++)
+ sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
+ sp_flush_tile_cache(sp, sp->zsbuf_cache);
+
+ for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
+ sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]);
+ }
+ sp_tile_cache_unmap_surfaces(sp->zsbuf_cache);
+}
+
+
+static void softpipe_destroy( struct pipe_context *pipe )
+{
+ struct softpipe_context *softpipe = softpipe_context( pipe );
+ struct pipe_winsys *ws = pipe->winsys;
+ uint i;
+
+ draw_destroy( softpipe->draw );
+
+ softpipe->quad.polygon_stipple->destroy( softpipe->quad.polygon_stipple );
+ softpipe->quad.earlyz->destroy( softpipe->quad.earlyz );
+ softpipe->quad.shade->destroy( softpipe->quad.shade );
+ softpipe->quad.alpha_test->destroy( softpipe->quad.alpha_test );
+ softpipe->quad.depth_test->destroy( softpipe->quad.depth_test );
+ softpipe->quad.stencil_test->destroy( softpipe->quad.stencil_test );
+ softpipe->quad.occlusion->destroy( softpipe->quad.occlusion );
+ softpipe->quad.coverage->destroy( softpipe->quad.coverage );
+ softpipe->quad.bufloop->destroy( softpipe->quad.bufloop );
+ softpipe->quad.blend->destroy( softpipe->quad.blend );
+ softpipe->quad.colormask->destroy( softpipe->quad.colormask );
+ softpipe->quad.output->destroy( softpipe->quad.output );
+
+ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
+ sp_destroy_tile_cache(softpipe->cbuf_cache[i]);
+ sp_destroy_tile_cache(softpipe->zsbuf_cache);
+
+ for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
+ sp_destroy_tile_cache(softpipe->tex_cache[i]);
+
+ for (i = 0; i < Elements(softpipe->constants); i++) {
+ if (softpipe->constants[i].buffer) {
+ pipe_buffer_reference(ws, &softpipe->constants[i].buffer, NULL);
+ }
+ }
+
+ FREE( softpipe );
+}
+
+
+struct pipe_context *
+softpipe_create( struct pipe_screen *screen,
+ struct pipe_winsys *pipe_winsys,
+ struct softpipe_winsys *softpipe_winsys )
+{
+ struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
+ uint i;
+
+#if defined(__i386__) || defined(__386__)
+ softpipe->use_sse = GETENV( "GALLIUM_NOSSE" ) == NULL;
+#else
+ softpipe->use_sse = FALSE;
+#endif
+
+ softpipe->dump_fs = GETENV( "GALLIUM_DUMP_FS" ) != NULL;
+
+ softpipe->pipe.winsys = pipe_winsys;
+ softpipe->pipe.screen = screen;
+ softpipe->pipe.destroy = softpipe_destroy;
+
+ /* state setters */
+ softpipe->pipe.create_blend_state = softpipe_create_blend_state;
+ softpipe->pipe.bind_blend_state = softpipe_bind_blend_state;
+ softpipe->pipe.delete_blend_state = softpipe_delete_blend_state;
+
+ softpipe->pipe.create_sampler_state = softpipe_create_sampler_state;
+ softpipe->pipe.bind_sampler_states = softpipe_bind_sampler_states;
+ softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state;
+
+ softpipe->pipe.create_depth_stencil_alpha_state = softpipe_create_depth_stencil_state;
+ softpipe->pipe.bind_depth_stencil_alpha_state = softpipe_bind_depth_stencil_state;
+ softpipe->pipe.delete_depth_stencil_alpha_state = softpipe_delete_depth_stencil_state;
+
+ softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state;
+ softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state;
+ softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state;
+
+ softpipe->pipe.create_fs_state = softpipe_create_fs_state;
+ softpipe->pipe.bind_fs_state = softpipe_bind_fs_state;
+ softpipe->pipe.delete_fs_state = softpipe_delete_fs_state;
+
+ softpipe->pipe.create_vs_state = softpipe_create_vs_state;
+ softpipe->pipe.bind_vs_state = softpipe_bind_vs_state;
+ softpipe->pipe.delete_vs_state = softpipe_delete_vs_state;
+
+ softpipe->pipe.set_blend_color = softpipe_set_blend_color;
+ softpipe->pipe.set_clip_state = softpipe_set_clip_state;
+ softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer;
+ softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
+ softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
+ softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;
+ softpipe->pipe.set_sampler_textures = softpipe_set_sampler_textures;
+ softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
+
+ softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer;
+ softpipe->pipe.set_vertex_element = softpipe_set_vertex_element;
+
+ softpipe->pipe.draw_arrays = softpipe_draw_arrays;
+ softpipe->pipe.draw_elements = softpipe_draw_elements;
+
+ softpipe->pipe.clear = softpipe_clear;
+ softpipe->pipe.flush = softpipe_flush;
+
+ softpipe_init_query_funcs( softpipe );
+ softpipe_init_texture_funcs( softpipe );
+
+ /*
+ * Alloc caches for accessing drawing surfaces and textures.
+ * Must be before quad stage setup!
+ */
+ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
+ softpipe->cbuf_cache[i] = sp_create_tile_cache();
+ softpipe->zsbuf_cache = sp_create_tile_cache();
+
+ for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
+ softpipe->tex_cache[i] = sp_create_tile_cache();
+
+
+ /* setup quad rendering stages */
+ softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);
+ softpipe->quad.earlyz = sp_quad_earlyz_stage(softpipe);
+ softpipe->quad.shade = sp_quad_shade_stage(softpipe);
+ softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);
+ softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
+ softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
+ softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);
+ softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);
+ softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
+ softpipe->quad.blend = sp_quad_blend_stage(softpipe);
+ softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
+ softpipe->quad.output = sp_quad_output_stage(softpipe);
+
+ softpipe->winsys = softpipe_winsys;
+
+ /*
+ * Create drawing context and plug our rendering stage into it.
+ */
+ softpipe->draw = draw_create();
+ assert(softpipe->draw);
+ softpipe->setup = sp_draw_render_stage(softpipe);
+
+ if (GETENV( "SP_VBUF" ) != NULL) {
+ sp_init_vbuf(softpipe);
+ }
+ else {
+ draw_set_rasterize_stage(softpipe->draw, softpipe->setup);
+ }
+
+ /* plug in AA line/point stages */
+ draw_install_aaline_stage(softpipe->draw, &softpipe->pipe);
+ draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe);
+
+#if USE_DRAW_STAGE_PSTIPPLE
+ /* Do polygon stipple w/ texture map + frag prog? */
+ draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe);
+#endif
+
+ sp_init_surface_functions(softpipe);
+
+ return &softpipe->pipe;
+}
-/**************************************************************************\r
- * \r
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.\r
- * All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the\r
- * "Software"), to deal in the Software without restriction, including\r
- * without limitation the rights to use, copy, modify, merge, publish,\r
- * distribute, sub license, and/or sell copies of the Software, and to\r
- * permit persons to whom the Software is furnished to do so, subject to\r
- * the following conditions:\r
- * \r
- * The above copyright notice and this permission notice (including the\r
- * next paragraph) shall be included in all copies or substantial portions\r
- * of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR\r
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- * \r
- **************************************************************************/\r
-\r
-/* Vertices are just an array of floats, with all the attributes\r
- * packed. We currently assume a layout like:\r
- *\r
- * attr[0][0..3] - window position\r
- * attr[1..n][0..3] - remaining attributes.\r
- *\r
- * Attributes are assumed to be 4 floats wide but are packed so that\r
- * all the enabled attributes run contiguously.\r
- */\r
-\r
-#include "pipe/p_util.h"\r
-#include "pipe/p_defines.h"\r
-#include "pipe/p_shader_tokens.h"\r
-\r
-#include "sp_context.h"\r
-#include "sp_state.h"\r
-#include "sp_headers.h"\r
-#include "sp_quad.h"\r
-#include "sp_texture.h"\r
-#include "sp_tex_sample.h"\r
-\r
-\r
-struct quad_shade_stage\r
-{\r
- struct quad_stage stage;\r
- struct tgsi_sampler samplers[PIPE_MAX_SAMPLERS];\r
- struct tgsi_exec_machine machine;\r
- struct tgsi_exec_vector *inputs, *outputs;\r
- int colorOutSlot, depthOutSlot;\r
-};\r
-\r
-\r
-/** cast wrapper */\r
-static INLINE struct quad_shade_stage *\r
-quad_shade_stage(struct quad_stage *qs)\r
-{\r
- return (struct quad_shade_stage *) qs;\r
-}\r
-\r
-\r
-\r
-/**\r
- * Execute fragment shader for the four fragments in the quad.\r
- */\r
-static void\r
-shade_quad(\r
- struct quad_stage *qs,\r
- struct quad_header *quad )\r
-{\r
- struct quad_shade_stage *qss = quad_shade_stage( qs );\r
- struct softpipe_context *softpipe = qs->softpipe;\r
- struct tgsi_exec_machine *machine = &qss->machine;\r
-\r
- /* Consts do not require 16 byte alignment. */\r
- machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT];\r
-\r
- machine->InterpCoefs = quad->coef;\r
-\r
- /* run shader */\r
- quad->mask &= softpipe->fs->run( softpipe->fs, \r
- &qss->machine,\r
- quad );\r
-\r
- /* store result color */\r
- if (qss->colorOutSlot >= 0) {\r
- /* XXX need to handle multiple color outputs someday */\r
- assert(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot]\r
- == TGSI_SEMANTIC_COLOR);\r
- memcpy(\r
- quad->outputs.color,\r
- &machine->Outputs[qss->colorOutSlot].xyzw[0].f[0],\r
- sizeof( quad->outputs.color ) );\r
- }\r
-\r
- /*\r
- * XXX the following code for updating quad->outputs.depth\r
- * isn't really needed if we did early z testing.\r
- */\r
-\r
- /* store result Z */\r
- if (qss->depthOutSlot >= 0) {\r
- /* output[slot] is new Z */\r
- uint i;\r
- for (i = 0; i < 4; i++) {\r
- quad->outputs.depth[i] = machine->Outputs[0].xyzw[2].f[i];\r
- }\r
- }\r
- else {\r
- /* copy input Z (which was interpolated by the executor) to output Z */\r
- uint i;\r
- for (i = 0; i < 4; i++) {\r
- quad->outputs.depth[i] = machine->Inputs[0].xyzw[2].f[i];\r
- /* XXX not sure the above line is always correct. The following\r
- * might be better:\r
- quad->outputs.depth[i] = machine->QuadPos.xyzw[2].f[i];\r
- */\r
- }\r
- }\r
-\r
- /* shader may cull fragments */\r
- if( quad->mask ) {\r
- qs->next->run( qs->next, quad );\r
- }\r
-}\r
-\r
-/**\r
- * Per-primitive (or per-begin?) setup\r
- */\r
-static void shade_begin(struct quad_stage *qs)\r
-{\r
- struct quad_shade_stage *qss = quad_shade_stage(qs);\r
- struct softpipe_context *softpipe = qs->softpipe;\r
- unsigned i;\r
- unsigned num = MAX2(softpipe->num_textures, softpipe->num_samplers);\r
-\r
- /* set TGSI sampler state that varies */\r
- for (i = 0; i < num; i++) {\r
- qss->samplers[i].state = softpipe->sampler[i];\r
- qss->samplers[i].texture = softpipe->texture[i];\r
- }\r
-\r
- /* find output slots for depth, color */\r
- qss->colorOutSlot = -1;\r
- qss->depthOutSlot = -1;\r
- for (i = 0; i < qss->stage.softpipe->fs->info.num_outputs; i++) {\r
- switch (qss->stage.softpipe->fs->info.output_semantic_name[i]) {\r
- case TGSI_SEMANTIC_POSITION:\r
- qss->depthOutSlot = i;\r
- break;\r
- case TGSI_SEMANTIC_COLOR:\r
- qss->colorOutSlot = i;\r
- break;\r
- }\r
- }\r
- \r
- softpipe->fs->prepare( softpipe->fs, \r
- &qss->machine,\r
- qss->samplers );\r
-\r
- qs->next->begin(qs->next);\r
-}\r
-\r
-\r
-static void shade_destroy(struct quad_stage *qs)\r
-{\r
- struct quad_shade_stage *qss = (struct quad_shade_stage *) qs;\r
-\r
- tgsi_exec_machine_free_data(&qss->machine);\r
- FREE( qss->inputs );\r
- FREE( qss->outputs );\r
- FREE( qs );\r
-}\r
-\r
-\r
-struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe )\r
-{\r
- struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage);\r
- uint i;\r
-\r
- /* allocate storage for program inputs/outputs, aligned to 16 bytes */\r
- qss->inputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->inputs) + 16);\r
- qss->outputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->outputs) + 16);\r
- qss->machine.Inputs = align16(qss->inputs);\r
- qss->machine.Outputs = align16(qss->outputs);\r
-\r
- qss->stage.softpipe = softpipe;\r
- qss->stage.begin = shade_begin;\r
- qss->stage.run = shade_quad;\r
- qss->stage.destroy = shade_destroy;\r
-\r
- /* set TGSI sampler state that's constant */\r
- for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {\r
- assert(softpipe->tex_cache[i]);\r
- qss->samplers[i].get_samples = sp_get_samples;\r
- qss->samplers[i].pipe = &softpipe->pipe;\r
- qss->samplers[i].cache = softpipe->tex_cache[i];\r
- }\r
-\r
- tgsi_exec_machine_init( &qss->machine );\r
-\r
- return &qss->stage;\r
-}\r
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Vertices are just an array of floats, with all the attributes
+ * packed. We currently assume a layout like:
+ *
+ * attr[0][0..3] - window position
+ * attr[1..n][0..3] - remaining attributes.
+ *
+ * Attributes are assumed to be 4 floats wide but are packed so that
+ * all the enabled attributes run contiguously.
+ */
+
+#include "pipe/p_util.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_shader_tokens.h"
+
+#include "sp_context.h"
+#include "sp_state.h"
+#include "sp_headers.h"
+#include "sp_quad.h"
+#include "sp_texture.h"
+#include "sp_tex_sample.h"
+
+
+struct quad_shade_stage
+{
+ struct quad_stage stage;
+ struct tgsi_sampler samplers[PIPE_MAX_SAMPLERS];
+ struct tgsi_exec_machine machine;
+ struct tgsi_exec_vector *inputs, *outputs;
+ int colorOutSlot, depthOutSlot;
+};
+
+
+/** cast wrapper */
+static INLINE struct quad_shade_stage *
+quad_shade_stage(struct quad_stage *qs)
+{
+ return (struct quad_shade_stage *) qs;
+}
+
+
+
+/**
+ * Execute fragment shader for the four fragments in the quad.
+ */
+static void
+shade_quad(
+ struct quad_stage *qs,
+ struct quad_header *quad )
+{
+ struct quad_shade_stage *qss = quad_shade_stage( qs );
+ struct softpipe_context *softpipe = qs->softpipe;
+ struct tgsi_exec_machine *machine = &qss->machine;
+
+ /* Consts do not require 16 byte alignment. */
+ machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT];
+
+ machine->InterpCoefs = quad->coef;
+
+ /* run shader */
+ quad->mask &= softpipe->fs->run( softpipe->fs,
+ &qss->machine,
+ quad );
+
+ /* store result color */
+ if (qss->colorOutSlot >= 0) {
+ /* XXX need to handle multiple color outputs someday */
+ assert(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot]
+ == TGSI_SEMANTIC_COLOR);
+ memcpy(
+ quad->outputs.color,
+ &machine->Outputs[qss->colorOutSlot].xyzw[0].f[0],
+ sizeof( quad->outputs.color ) );
+ }
+
+ /*
+ * XXX the following code for updating quad->outputs.depth
+ * isn't really needed if we did early z testing.
+ */
+
+ /* store result Z */
+ if (qss->depthOutSlot >= 0) {
+ /* output[slot] is new Z */
+ uint i;
+ for (i = 0; i < 4; i++) {
+ quad->outputs.depth[i] = machine->Outputs[0].xyzw[2].f[i];
+ }
+ }
+ else {
+ /* copy input Z (which was interpolated by the executor) to output Z */
+ uint i;
+ for (i = 0; i < 4; i++) {
+ quad->outputs.depth[i] = machine->Inputs[0].xyzw[2].f[i];
+ /* XXX not sure the above line is always correct. The following
+ * might be better:
+ quad->outputs.depth[i] = machine->QuadPos.xyzw[2].f[i];
+ */
+ }
+ }
+
+ /* shader may cull fragments */
+ if( quad->mask ) {
+ qs->next->run( qs->next, quad );
+ }
+}
+
+/**
+ * Per-primitive (or per-begin?) setup
+ */
+static void shade_begin(struct quad_stage *qs)
+{
+ struct quad_shade_stage *qss = quad_shade_stage(qs);
+ struct softpipe_context *softpipe = qs->softpipe;
+ unsigned i;
+ unsigned num = MAX2(softpipe->num_textures, softpipe->num_samplers);
+
+ /* set TGSI sampler state that varies */
+ for (i = 0; i < num; i++) {
+ qss->samplers[i].state = softpipe->sampler[i];
+ qss->samplers[i].texture = softpipe->texture[i];
+ }
+
+ /* find output slots for depth, color */
+ qss->colorOutSlot = -1;
+ qss->depthOutSlot = -1;
+ for (i = 0; i < qss->stage.softpipe->fs->info.num_outputs; i++) {
+ switch (qss->stage.softpipe->fs->info.output_semantic_name[i]) {
+ case TGSI_SEMANTIC_POSITION:
+ qss->depthOutSlot = i;
+ break;
+ case TGSI_SEMANTIC_COLOR:
+ qss->colorOutSlot = i;
+ break;
+ }
+ }
+
+ softpipe->fs->prepare( softpipe->fs,
+ &qss->machine,
+ qss->samplers );
+
+ qs->next->begin(qs->next);
+}
+
+
+static void shade_destroy(struct quad_stage *qs)
+{
+ struct quad_shade_stage *qss = (struct quad_shade_stage *) qs;
+
+ tgsi_exec_machine_free_data(&qss->machine);
+ FREE( qss->inputs );
+ FREE( qss->outputs );
+ FREE( qs );
+}
+
+
+struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe )
+{
+ struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage);
+ uint i;
+
+ /* allocate storage for program inputs/outputs, aligned to 16 bytes */
+ qss->inputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->inputs) + 16);
+ qss->outputs = MALLOC(PIPE_ATTRIB_MAX * sizeof(*qss->outputs) + 16);
+ qss->machine.Inputs = align16(qss->inputs);
+ qss->machine.Outputs = align16(qss->outputs);
+
+ qss->stage.softpipe = softpipe;
+ qss->stage.begin = shade_begin;
+ qss->stage.run = shade_quad;
+ qss->stage.destroy = shade_destroy;
+
+ /* set TGSI sampler state that's constant */
+ for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
+ assert(softpipe->tex_cache[i]);
+ qss->samplers[i].get_samples = sp_get_samples;
+ qss->samplers[i].pipe = &softpipe->pipe;
+ qss->samplers[i].cache = softpipe->tex_cache[i];
+ }
+
+ tgsi_exec_machine_init( &qss->machine );
+
+ return &qss->stage;
+}
-/**************************************************************************\r
- * \r
- * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.\r
- * All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the\r
- * "Software"), to deal in the Software without restriction, including\r
- * without limitation the rights to use, copy, modify, merge, publish,\r
- * distribute, sub license, and/or sell copies of the Software, and to\r
- * permit persons to whom the Software is furnished to do so, subject to\r
- * the following conditions:\r
- * \r
- * The above copyright notice and this permission notice (including the\r
- * next paragraph) shall be included in all copies or substantial portions\r
- * of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR\r
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- * \r
- **************************************************************************/\r
- /*\r
- * Authors:\r
- * Keith Whitwell <keith@tungstengraphics.com>\r
- * Michel Dänzer <michel@tungstengraphics.com>\r
- */\r
-\r
-#include "pipe/p_context.h"\r
-#include "pipe/p_defines.h"\r
-#include "pipe/p_inlines.h"\r
-#include "pipe/p_util.h"\r
-#include "pipe/p_winsys.h"\r
-\r
-#include "sp_context.h"\r
-#include "sp_state.h"\r
-#include "sp_texture.h"\r
-#include "sp_tile_cache.h"\r
-\r
-\r
-/* Simple, maximally packed layout.\r
- */\r
-\r
-static unsigned minify( unsigned d )\r
-{\r
- return MAX2(1, d>>1);\r
-}\r
-\r
-\r
-static void\r
-softpipe_texture_layout(struct softpipe_texture * spt)\r
-{\r
- struct pipe_texture *pt = &spt->base;\r
- unsigned level;\r
- unsigned width = pt->width[0];\r
- unsigned height = pt->height[0];\r
- unsigned depth = pt->depth[0];\r
-\r
- spt->buffer_size = 0;\r
-\r
- for (level = 0; level <= pt->last_level; level++) {\r
- pt->width[level] = width;\r
- pt->height[level] = height;\r
- pt->depth[level] = depth;\r
-\r
- spt->level_offset[level] = spt->buffer_size;\r
-\r
- spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) *\r
- ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) *\r
- width * pt->cpp;\r
-\r
- width = minify(width);\r
- height = minify(height);\r
- depth = minify(depth);\r
- }\r
-}\r
-\r
-\r
-static struct pipe_texture *\r
-softpipe_texture_create_screen(struct pipe_screen *screen,\r
- const struct pipe_texture *templat)\r
-{\r
- struct pipe_winsys *ws = screen->winsys;\r
- struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);\r
- if (!spt)\r
- return NULL;\r
-\r
- spt->base = *templat;\r
- spt->base.refcount = 1;\r
- spt->base.screen = screen;\r
-\r
- softpipe_texture_layout(spt);\r
-\r
- spt->buffer = ws->buffer_create(ws, 32,\r
- PIPE_BUFFER_USAGE_PIXEL,\r
- spt->buffer_size);\r
- if (!spt->buffer) {\r
- FREE(spt);\r
- return NULL;\r
- }\r
-\r
- assert(spt->base.refcount == 1);\r
-\r
- return &spt->base;\r
-}\r
-\r
-\r
-static void\r
-softpipe_texture_release_screen(struct pipe_screen *screen,\r
- struct pipe_texture **pt)\r
-{\r
- if (!*pt)\r
- return;\r
-\r
- /*\r
- DBG("%s %p refcount will be %d\n",\r
- __FUNCTION__, (void *) *pt, (*pt)->refcount - 1);\r
- */\r
- if (--(*pt)->refcount <= 0) {\r
- struct softpipe_texture *spt = softpipe_texture(*pt);\r
-\r
- /*\r
- DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);\r
- */\r
-\r
- pipe_buffer_reference(screen->winsys, &spt->buffer, NULL);\r
-\r
- FREE(spt);\r
- }\r
- *pt = NULL;\r
-}\r
-\r
-\r
-static struct pipe_surface *\r
-softpipe_get_tex_surface_screen(struct pipe_screen *screen,\r
- struct pipe_texture *pt,\r
- unsigned face, unsigned level, unsigned zslice)\r
-{\r
- struct pipe_winsys *ws = screen->winsys;\r
- struct softpipe_texture *spt = softpipe_texture(pt);\r
- struct pipe_surface *ps;\r
-\r
- assert(level <= pt->last_level);\r
-\r
- ps = ws->surface_alloc(ws);\r
- if (ps) {\r
- assert(ps->refcount);\r
- assert(ps->winsys);\r
- pipe_buffer_reference(ws, &ps->buffer, spt->buffer);\r
- ps->format = pt->format;\r
- ps->cpp = pt->cpp;\r
- ps->width = pt->width[level];\r
- ps->height = pt->height[level];\r
- ps->pitch = ps->width;\r
- ps->offset = spt->level_offset[level];\r
-\r
- if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) {\r
- ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *\r
- (pt->compressed ? ps->height/4 : ps->height) *\r
- ps->width * ps->cpp;\r
- }\r
- else {\r
- assert(face == 0);\r
- assert(zslice == 0);\r
- }\r
- }\r
- return ps;\r
-}\r
-\r
-\r
-static void\r
-softpipe_texture_update(struct pipe_context *pipe,\r
- struct pipe_texture *texture)\r
-{\r
- struct softpipe_context *softpipe = softpipe_context(pipe);\r
- uint unit;\r
- for (unit = 0; unit < softpipe->num_textures; unit++) {\r
- if (softpipe->texture[unit] == texture) {\r
- sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]);\r
- }\r
- }\r
-}\r
-\r
-\r
-void\r
-softpipe_init_texture_funcs( struct softpipe_context *softpipe )\r
-{\r
- softpipe->pipe.texture_update = softpipe_texture_update;\r
-}\r
-\r
-\r
-void\r
-softpipe_init_screen_texture_funcs(struct pipe_screen *screen)\r
-{\r
- screen->texture_create = softpipe_texture_create_screen;\r
- screen->texture_release = softpipe_texture_release_screen;\r
- screen->get_tex_surface = softpipe_get_tex_surface_screen;\r
-}\r
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ * Michel Dänzer <michel@tungstengraphics.com>
+ */
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_util.h"
+#include "pipe/p_winsys.h"
+
+#include "sp_context.h"
+#include "sp_state.h"
+#include "sp_texture.h"
+#include "sp_tile_cache.h"
+
+
+/* Simple, maximally packed layout.
+ */
+
+static unsigned minify( unsigned d )
+{
+ return MAX2(1, d>>1);
+}
+
+
+static void
+softpipe_texture_layout(struct softpipe_texture * spt)
+{
+ struct pipe_texture *pt = &spt->base;
+ unsigned level;
+ unsigned width = pt->width[0];
+ unsigned height = pt->height[0];
+ unsigned depth = pt->depth[0];
+
+ spt->buffer_size = 0;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ pt->width[level] = width;
+ pt->height[level] = height;
+ pt->depth[level] = depth;
+
+ spt->level_offset[level] = spt->buffer_size;
+
+ spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) *
+ ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) *
+ width * pt->cpp;
+
+ width = minify(width);
+ height = minify(height);
+ depth = minify(depth);
+ }
+}
+
+
+static struct pipe_texture *
+softpipe_texture_create_screen(struct pipe_screen *screen,
+ const struct pipe_texture *templat)
+{
+ struct pipe_winsys *ws = screen->winsys;
+ struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);
+ if (!spt)
+ return NULL;
+
+ spt->base = *templat;
+ spt->base.refcount = 1;
+ spt->base.screen = screen;
+
+ softpipe_texture_layout(spt);
+
+ spt->buffer = ws->buffer_create(ws, 32,
+ PIPE_BUFFER_USAGE_PIXEL,
+ spt->buffer_size);
+ if (!spt->buffer) {
+ FREE(spt);
+ return NULL;
+ }
+
+ assert(spt->base.refcount == 1);
+
+ return &spt->base;
+}
+
+
+static void
+softpipe_texture_release_screen(struct pipe_screen *screen,
+ struct pipe_texture **pt)
+{
+ if (!*pt)
+ return;
+
+ /*
+ DBG("%s %p refcount will be %d\n",
+ __FUNCTION__, (void *) *pt, (*pt)->refcount - 1);
+ */
+ if (--(*pt)->refcount <= 0) {
+ struct softpipe_texture *spt = softpipe_texture(*pt);
+
+ /*
+ DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);
+ */
+
+ pipe_buffer_reference(screen->winsys, &spt->buffer, NULL);
+
+ FREE(spt);
+ }
+ *pt = NULL;
+}
+
+
+static struct pipe_surface *
+softpipe_get_tex_surface_screen(struct pipe_screen *screen,
+ struct pipe_texture *pt,
+ unsigned face, unsigned level, unsigned zslice)
+{
+ struct pipe_winsys *ws = screen->winsys;
+ struct softpipe_texture *spt = softpipe_texture(pt);
+ struct pipe_surface *ps;
+
+ assert(level <= pt->last_level);
+
+ ps = ws->surface_alloc(ws);
+ if (ps) {
+ assert(ps->refcount);
+ assert(ps->winsys);
+ pipe_buffer_reference(ws, &ps->buffer, spt->buffer);
+ ps->format = pt->format;
+ ps->cpp = pt->cpp;
+ ps->width = pt->width[level];
+ ps->height = pt->height[level];
+ ps->pitch = ps->width;
+ ps->offset = spt->level_offset[level];
+
+ if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) {
+ ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *
+ (pt->compressed ? ps->height/4 : ps->height) *
+ ps->width * ps->cpp;
+ }
+ else {
+ assert(face == 0);
+ assert(zslice == 0);
+ }
+ }
+ return ps;
+}
+
+
+static void
+softpipe_texture_update(struct pipe_context *pipe,
+ struct pipe_texture *texture)
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+ uint unit;
+ for (unit = 0; unit < softpipe->num_textures; unit++) {
+ if (softpipe->texture[unit] == texture) {
+ sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]);
+ }
+ }
+}
+
+
+void
+softpipe_init_texture_funcs( struct softpipe_context *softpipe )
+{
+ softpipe->pipe.texture_update = softpipe_texture_update;
+}
+
+
+void
+softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
+{
+ screen->texture_create = softpipe_texture_create_screen;
+ screen->texture_release = softpipe_texture_release_screen;
+ screen->get_tex_surface = softpipe_get_tex_surface_screen;
+}