sp_context.h revision af69d88d
11.45She/**************************************************************************
21.1Sbjh21 *
31.1Sbjh21 * Copyright 2007 VMware, Inc.
41.1Sbjh21 * All Rights Reserved.
51.1Sbjh21 *
61.1Sbjh21 * Permission is hereby granted, free of charge, to any person obtaining a
71.1Sbjh21 * copy of this software and associated documentation files (the
81.1Sbjh21 * "Software"), to deal in the Software without restriction, including
91.1Sbjh21 * without limitation the rights to use, copy, modify, merge, publish,
101.1Sbjh21 * distribute, sub license, and/or sell copies of the Software, and to
111.1Sbjh21 * permit persons to whom the Software is furnished to do so, subject to
121.1Sbjh21 * the following conditions:
131.1Sbjh21 *
141.1Sbjh21 * The above copyright notice and this permission notice (including the
151.1Sbjh21 * next paragraph) shall be included in all copies or substantial portions
161.1Sbjh21 * of the Software.
171.1Sbjh21 *
181.1Sbjh21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
191.1Sbjh21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
201.1Sbjh21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
211.1Sbjh21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
221.1Sbjh21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
231.1Sbjh21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
241.1Sbjh21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
251.1Sbjh21 *
261.1Sbjh21 **************************************************************************/
271.1Sbjh21
281.1Sbjh21/* Authors:  Keith Whitwell <keithw@vmware.com>
291.1Sbjh21 */
301.1Sbjh21
311.1Sbjh21#ifndef SP_CONTEXT_H
321.1Sbjh21#define SP_CONTEXT_H
331.1Sbjh21
341.1Sbjh21#include "pipe/p_context.h"
351.1Sbjh21#include "util/u_blitter.h"
361.1Sbjh21
371.1Sbjh21#include "draw/draw_vertex.h"
381.1Sbjh21
391.1Sbjh21#include "sp_quad_pipe.h"
401.1Sbjh21
411.1Sbjh21
421.1Sbjh21/** Do polygon stipple in the draw module? */
431.38Srtr#define DO_PSTIPPLE_IN_DRAW_MODULE 0
441.1Sbjh21
451.38Srtr/** Do polygon stipple with the util module? */
461.1Sbjh21#define DO_PSTIPPLE_IN_HELPER_MODULE 1
471.14She
481.1Sbjh21
491.1Sbjh21struct softpipe_vbuf_render;
501.1Sbjh21struct draw_context;
511.1Sbjh21struct draw_stage;
521.1Sbjh21struct softpipe_tile_cache;
531.1Sbjh21struct softpipe_tex_tile_cache;
541.1Sbjh21struct sp_fragment_shader;
551.5Sbjh21struct sp_vertex_shader;
561.39Spookastruct sp_velems_state;
571.44Schsstruct sp_so_state;
581.39Spooka
591.39Spookastruct softpipe_context {
601.39Spooka   struct pipe_context pipe;  /**< base class */
611.39Spooka
621.1Sbjh21   /** Constant state objects */
631.39Spooka   struct pipe_blend_state *blend;
641.39Spooka   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
651.1Sbjh21   struct pipe_depth_stencil_alpha_state *depth_stencil;
661.39Spooka   struct pipe_rasterizer_state *rasterizer;
671.39Spooka   struct sp_fragment_shader *fs;
681.39Spooka   struct sp_fragment_shader_variant *fs_variant;
691.39Spooka   struct sp_vertex_shader *vs;
701.1Sbjh21   struct sp_geometry_shader *gs;
711.39Spooka   struct sp_velems_state *velems;
721.39Spooka   struct sp_so_state *so;
731.39Spooka
741.1Sbjh21   /** Other rendering state */
751.39Spooka   struct pipe_blend_color blend_color;
761.39Spooka   struct pipe_blend_color blend_color_clamped;
771.33Snjoly   struct pipe_stencil_ref stencil_ref;
781.1Sbjh21   struct pipe_clip_state clip;
791.1Sbjh21   struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
801.39Spooka   struct pipe_framebuffer_state framebuffer;
811.1Sbjh21   struct pipe_poly_stipple poly_stipple;
821.39Spooka   struct pipe_scissor_state scissor;
831.1Sbjh21   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
841.1Sbjh21
851.39Spooka   struct pipe_viewport_state viewport;
861.39Spooka   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
871.39Spooka   struct pipe_index_buffer index_buffer;
881.39Spooka
891.1Sbjh21   struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
901.39Spooka   unsigned num_so_targets;
911.1Sbjh21
921.39Spooka   struct pipe_query_data_so_statistics so_stats;
931.39Spooka
941.1Sbjh21   struct pipe_query_data_pipeline_statistics pipeline_statistics;
951.1Sbjh21   unsigned active_statistics_queries;
961.1Sbjh21
971.39Spooka   unsigned num_samplers[PIPE_SHADER_TYPES];
981.39Spooka   unsigned num_sampler_views[PIPE_SHADER_TYPES];
991.1Sbjh21
1001.39Spooka   unsigned num_vertex_buffers;
1011.39Spooka
1021.39Spooka   unsigned dirty; /**< Mask of SP_NEW_x flags */
1031.1Sbjh21
1041.39Spooka   /* Counter for occlusion queries.  Note this supports overlapping
1051.39Spooka    * queries.
1061.39Spooka    */
1071.39Spooka   uint64_t occlusion_count;
1081.39Spooka   unsigned active_query_count;
1091.1Sbjh21
1101.39Spooka   /** Mapped vertex buffers */
1111.39Spooka   ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
1121.39Spooka
1131.39Spooka   /** Mapped constant buffers */
1141.1Sbjh21   const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
1151.39Spooka   unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
1161.39Spooka
1171.39Spooka   /** Vertex format */
1181.1Sbjh21   struct vertex_info vertex_info;
1191.1Sbjh21   struct vertex_info vertex_info_vbuf;
1201.39Spooka
1211.28Schristos   /** Which vertex shader output slot contains point size */
1221.39Spooka   int psize_slot;
1231.1Sbjh21
1241.39Spooka   /** Which vertex shader output slot contains layer */
1251.1Sbjh21   int layer_slot;
1261.39Spooka
1271.2Sbjh21   /** The reduced version of the primitive supplied by the state tracker */
1281.39Spooka   unsigned reduced_api_prim;
1291.39Spooka
1301.1Sbjh21   /** Derived information about which winding orders to cull */
1311.39Spooka   unsigned cull_mode;
1321.39Spooka
1331.39Spooka   /**
1341.39Spooka    * The reduced primitive after unfilled triangles, wide-line decomposition,
1351.39Spooka    * etc, are taken into account.  This is the primitive type that's actually
1361.1Sbjh21    * rasterized.
1371.1Sbjh21    */
1381.39Spooka   unsigned reduced_prim;
1391.39Spooka
1401.39Spooka   /** Derived from scissor and surface bounds: */
1411.33Snjoly   struct pipe_scissor_state cliprect;
1421.39Spooka
1431.33Snjoly   unsigned line_stipple_counter;
1441.39Spooka
1451.1Sbjh21   /** Conditional query object and mode */
1461.39Spooka   struct pipe_query *render_cond_query;
1471.39Spooka   uint render_cond_mode;
1481.1Sbjh21   boolean render_cond_cond;
1491.39Spooka
1501.1Sbjh21   /** Polygon stipple items */
1511.39Spooka   struct {
1521.1Sbjh21      struct pipe_resource *texture;
1531.39Spooka      struct pipe_sampler_state *sampler;
1541.40Snjoly      struct pipe_sampler_view *sampler_view;
1551.1Sbjh21   } pstipple;
1561.40Snjoly
1571.1Sbjh21   /** Software quad rendering pipeline */
1581.39Spooka   struct {
1591.33Snjoly      struct quad_stage *shade;
1601.39Spooka      struct quad_stage *depth_test;
1611.33Snjoly      struct quad_stage *blend;
1621.39Spooka      struct quad_stage *pstipple;
1631.39Spooka      struct quad_stage *first; /**< points to one of the above stages */
1641.39Spooka   } quad;
1651.1Sbjh21
1661.39Spooka   /** TGSI exec things */
1671.1Sbjh21   struct {
1681.1Sbjh21      struct sp_tgsi_sampler *sampler[PIPE_SHADER_TYPES];
1691.39Spooka   } tgsi;
1701.1Sbjh21
1711.1Sbjh21   struct tgsi_exec_machine *fs_machine;
1721.1Sbjh21
1731.39Spooka   /** The primitive drawing context */
1741.39Spooka   struct draw_context *draw;
1751.1Sbjh21
1761.39Spooka   /** Draw module backend */
1771.1Sbjh21   struct vbuf_render *vbuf_backend;
1781.39Spooka   struct draw_stage *vbuf;
1791.39Spooka
1801.39Spooka   struct blitter_context *blitter;
1811.1Sbjh21
1821.39Spooka   boolean dirty_render_cache;
1831.39Spooka
1841.39Spooka   struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
1851.33Snjoly   struct softpipe_tile_cache *zsbuf_cache;
1861.39Spooka
1871.39Spooka   unsigned tex_timestamp;
1881.39Spooka
1891.1Sbjh21   /*
1901.39Spooka    * Texture caches for vertex, fragment, geometry stages.
1911.1Sbjh21    * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
1921.39Spooka    * for compute shaders.
1931.1Sbjh21    * XXX wouldn't it make more sense for the tile cache to just be part
1941.1Sbjh21    * of sp_sampler_view?
1951.39Spooka    */
1961.1Sbjh21   struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_GEOMETRY+1][PIPE_MAX_SHADER_SAMPLER_VIEWS];
1971.39Spooka
1981.38Srtr   unsigned dump_fs : 1;
1991.38Srtr   unsigned dump_gs : 1;
2001.39Spooka   unsigned no_rast : 1;
2011.38Srtr};
2021.39Spooka
2031.1Sbjh21
2041.39Spookastatic INLINE struct softpipe_context *
2051.1Sbjh21softpipe_context( struct pipe_context *pipe )
2061.39Spooka{
2071.39Spooka   return (struct softpipe_context *)pipe;
2081.1Sbjh21}
2091.1Sbjh21
2101.1Sbjh21
2111.1Sbjh21struct pipe_context *
2121.39Spookasoftpipe_create_context( struct pipe_screen *, void *priv );
2131.41Snjoly
2141.39Spookastruct pipe_resource *
2151.39Spookasoftpipe_user_buffer_create(struct pipe_screen *screen,
2161.39Spooka                            void *ptr,
2171.28Schristos                            unsigned bytes,
2181.39Spooka			    unsigned bind_flags);
2191.39Spooka
2201.44Schs#define SP_UNREFERENCED         0
2211.44Schs#define SP_REFERENCED_FOR_READ  (1 << 0)
2221.39Spooka#define SP_REFERENCED_FOR_WRITE (1 << 1)
2231.1Sbjh21
2241.39Spookaunsigned int
2251.20Sperrysoftpipe_is_resource_referenced( struct pipe_context *pipe,
2261.1Sbjh21                                 struct pipe_resource *texture,
2271.39Spooka                                 unsigned level, int layer);
2281.9Schristos
2291.39Spooka#endif /* SP_CONTEXT_H */
2301.1Sbjh21