sp_context.h revision 9f464c52
186d9c6cdSmaya/**************************************************************************
286d9c6cdSmaya *
386d9c6cdSmaya * Copyright 2007 VMware, Inc.
486d9c6cdSmaya * All Rights Reserved.
586d9c6cdSmaya *
686d9c6cdSmaya * Permission is hereby granted, free of charge, to any person obtaining a
786d9c6cdSmaya * copy of this software and associated documentation files (the
886d9c6cdSmaya * "Software"), to deal in the Software without restriction, including
986d9c6cdSmaya * without limitation the rights to use, copy, modify, merge, publish,
1086d9c6cdSmaya * distribute, sub license, and/or sell copies of the Software, and to
1186d9c6cdSmaya * permit persons to whom the Software is furnished to do so, subject to
1286d9c6cdSmaya * the following conditions:
1386d9c6cdSmaya *
1486d9c6cdSmaya * The above copyright notice and this permission notice (including the
1586d9c6cdSmaya * next paragraph) shall be included in all copies or substantial portions
1686d9c6cdSmaya * of the Software.
1786d9c6cdSmaya *
1886d9c6cdSmaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1986d9c6cdSmaya * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2086d9c6cdSmaya * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2186d9c6cdSmaya * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
2286d9c6cdSmaya * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2386d9c6cdSmaya * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2486d9c6cdSmaya * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2586d9c6cdSmaya *
2686d9c6cdSmaya **************************************************************************/
2786d9c6cdSmaya
2886d9c6cdSmaya/* Authors:  Keith Whitwell <keithw@vmware.com>
2986d9c6cdSmaya */
3086d9c6cdSmaya
3186d9c6cdSmaya#ifndef SP_CONTEXT_H
3286d9c6cdSmaya#define SP_CONTEXT_H
3386d9c6cdSmaya
3486d9c6cdSmaya#include "pipe/p_context.h"
3586d9c6cdSmaya#include "util/u_blitter.h"
3686d9c6cdSmaya
3786d9c6cdSmaya#include "draw/draw_vertex.h"
3886d9c6cdSmaya
3986d9c6cdSmaya#include "sp_quad_pipe.h"
4086d9c6cdSmaya#include "sp_setup.h"
4186d9c6cdSmaya
4286d9c6cdSmaya
4386d9c6cdSmaya/** Do polygon stipple in the draw module? */
4486d9c6cdSmaya#define DO_PSTIPPLE_IN_DRAW_MODULE 0
4586d9c6cdSmaya
4686d9c6cdSmaya/** Do polygon stipple with the util module? */
4786d9c6cdSmaya#define DO_PSTIPPLE_IN_HELPER_MODULE 1
4886d9c6cdSmaya
4986d9c6cdSmaya
5086d9c6cdSmayastruct softpipe_vbuf_render;
5186d9c6cdSmayastruct draw_context;
5286d9c6cdSmayastruct draw_stage;
5386d9c6cdSmayastruct softpipe_tile_cache;
5486d9c6cdSmayastruct softpipe_tex_tile_cache;
5586d9c6cdSmayastruct sp_fragment_shader;
5686d9c6cdSmayastruct sp_vertex_shader;
5786d9c6cdSmayastruct sp_velems_state;
5886d9c6cdSmayastruct sp_so_state;
5986d9c6cdSmaya
6086d9c6cdSmayastruct softpipe_context {
6186d9c6cdSmaya   struct pipe_context pipe;  /**< base class */
6286d9c6cdSmaya
6386d9c6cdSmaya   /** Constant state objects */
6486d9c6cdSmaya   struct pipe_blend_state *blend;
6586d9c6cdSmaya   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
6686d9c6cdSmaya   struct pipe_depth_stencil_alpha_state *depth_stencil;
6786d9c6cdSmaya   struct pipe_rasterizer_state *rasterizer;
6886d9c6cdSmaya   struct sp_fragment_shader *fs;
6986d9c6cdSmaya   struct sp_fragment_shader_variant *fs_variant;
7086d9c6cdSmaya   struct sp_vertex_shader *vs;
7186d9c6cdSmaya   struct sp_geometry_shader *gs;
7286d9c6cdSmaya   struct sp_velems_state *velems;
7386d9c6cdSmaya   struct sp_so_state *so;
7486d9c6cdSmaya   struct sp_compute_shader *cs;
7586d9c6cdSmaya
7686d9c6cdSmaya   /** Other rendering state */
7786d9c6cdSmaya   struct pipe_blend_color blend_color;
7886d9c6cdSmaya   struct pipe_blend_color blend_color_clamped;
7986d9c6cdSmaya   struct pipe_stencil_ref stencil_ref;
8086d9c6cdSmaya   struct pipe_clip_state clip;
8186d9c6cdSmaya   struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
8286d9c6cdSmaya   struct pipe_framebuffer_state framebuffer;
8386d9c6cdSmaya   struct pipe_poly_stipple poly_stipple;
8486d9c6cdSmaya   struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
8586d9c6cdSmaya   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
8686d9c6cdSmaya
8786d9c6cdSmaya   struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
8886d9c6cdSmaya   struct pipe_shader_buffer buffers[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
8986d9c6cdSmaya   struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
9086d9c6cdSmaya   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
9186d9c6cdSmaya   struct pipe_resource *mapped_vs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
9286d9c6cdSmaya   struct pipe_resource *mapped_gs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
9386d9c6cdSmaya
9486d9c6cdSmaya   struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
9586d9c6cdSmaya   unsigned num_so_targets;
9686d9c6cdSmaya
9786d9c6cdSmaya   struct pipe_query_data_so_statistics so_stats[PIPE_MAX_VERTEX_STREAMS];
9886d9c6cdSmaya
9986d9c6cdSmaya   struct pipe_query_data_pipeline_statistics pipeline_statistics;
10086d9c6cdSmaya   unsigned active_statistics_queries;
10186d9c6cdSmaya
10286d9c6cdSmaya   unsigned num_samplers[PIPE_SHADER_TYPES];
10386d9c6cdSmaya   unsigned num_sampler_views[PIPE_SHADER_TYPES];
10486d9c6cdSmaya
10586d9c6cdSmaya   unsigned num_vertex_buffers;
10686d9c6cdSmaya
10786d9c6cdSmaya   unsigned dirty; /**< Mask of SP_NEW_x flags */
10886d9c6cdSmaya
10986d9c6cdSmaya   /* Counter for occlusion queries.  Note this supports overlapping
11086d9c6cdSmaya    * queries.
11186d9c6cdSmaya    */
11286d9c6cdSmaya   uint64_t occlusion_count;
11386d9c6cdSmaya   unsigned active_query_count;
11486d9c6cdSmaya
11586d9c6cdSmaya   /** Mapped vertex buffers */
11686d9c6cdSmaya   ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
11786d9c6cdSmaya
11886d9c6cdSmaya   /** Mapped constant buffers */
11986d9c6cdSmaya   const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
12086d9c6cdSmaya   unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
12186d9c6cdSmaya
12286d9c6cdSmaya   /** Vertex format */
12386d9c6cdSmaya   struct sp_setup_info setup_info;
12486d9c6cdSmaya   struct vertex_info vertex_info;
12586d9c6cdSmaya
12686d9c6cdSmaya   /** Which vertex shader output slot contains point size */
12786d9c6cdSmaya   int8_t psize_slot;
12886d9c6cdSmaya
12986d9c6cdSmaya   /** Which vertex shader output slot contains viewport index */
13086d9c6cdSmaya   int8_t viewport_index_slot;
13186d9c6cdSmaya
13286d9c6cdSmaya   /** Which vertex shader output slot contains layer */
13386d9c6cdSmaya   int8_t layer_slot;
13486d9c6cdSmaya
13586d9c6cdSmaya   /** The reduced version of the primitive supplied by the state tracker */
13686d9c6cdSmaya   unsigned reduced_api_prim;
13786d9c6cdSmaya
13886d9c6cdSmaya   /** Derived information about which winding orders to cull */
13986d9c6cdSmaya   unsigned cull_mode;
14086d9c6cdSmaya
14186d9c6cdSmaya   /**
14286d9c6cdSmaya    * The reduced primitive after unfilled triangles, wide-line decomposition,
14386d9c6cdSmaya    * etc, are taken into account.  This is the primitive type that's actually
14486d9c6cdSmaya    * rasterized.
14586d9c6cdSmaya    */
14686d9c6cdSmaya   unsigned reduced_prim;
14786d9c6cdSmaya
14886d9c6cdSmaya   /** Derived from scissor and surface bounds: */
14986d9c6cdSmaya   struct pipe_scissor_state cliprect[PIPE_MAX_VIEWPORTS];
15086d9c6cdSmaya
15186d9c6cdSmaya   /** Conditional query object and mode */
15286d9c6cdSmaya   struct pipe_query *render_cond_query;
15386d9c6cdSmaya   enum pipe_render_cond_flag render_cond_mode;
15486d9c6cdSmaya   boolean render_cond_cond;
15586d9c6cdSmaya
15686d9c6cdSmaya   /** Polygon stipple items */
15786d9c6cdSmaya   struct {
15886d9c6cdSmaya      struct pipe_resource *texture;
15986d9c6cdSmaya      struct pipe_sampler_state *sampler;
16086d9c6cdSmaya      struct pipe_sampler_view *sampler_view;
16186d9c6cdSmaya   } pstipple;
16286d9c6cdSmaya
16386d9c6cdSmaya   /** Software quad rendering pipeline */
16486d9c6cdSmaya   struct {
16586d9c6cdSmaya      struct quad_stage *shade;
16686d9c6cdSmaya      struct quad_stage *depth_test;
16786d9c6cdSmaya      struct quad_stage *blend;
16886d9c6cdSmaya      struct quad_stage *pstipple;
16986d9c6cdSmaya      struct quad_stage *first; /**< points to one of the above stages */
17086d9c6cdSmaya   } quad;
17186d9c6cdSmaya
17286d9c6cdSmaya   /** TGSI exec things */
17386d9c6cdSmaya   struct {
17486d9c6cdSmaya      struct sp_tgsi_sampler *sampler[PIPE_SHADER_TYPES];
17586d9c6cdSmaya      struct sp_tgsi_image *image[PIPE_SHADER_TYPES];
17686d9c6cdSmaya      struct sp_tgsi_buffer *buffer[PIPE_SHADER_TYPES];
17786d9c6cdSmaya   } tgsi;
17886d9c6cdSmaya
17986d9c6cdSmaya   struct tgsi_exec_machine *fs_machine;
18086d9c6cdSmaya   /** whether early depth testing is enabled */
18186d9c6cdSmaya   bool early_depth;
18286d9c6cdSmaya
18386d9c6cdSmaya   /** The primitive drawing context */
18486d9c6cdSmaya   struct draw_context *draw;
18586d9c6cdSmaya
18686d9c6cdSmaya   /** Draw module backend */
18786d9c6cdSmaya   struct vbuf_render *vbuf_backend;
18886d9c6cdSmaya   struct draw_stage *vbuf;
18986d9c6cdSmaya
19086d9c6cdSmaya   struct blitter_context *blitter;
19186d9c6cdSmaya
19286d9c6cdSmaya   boolean dirty_render_cache;
19386d9c6cdSmaya
19486d9c6cdSmaya   struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
19586d9c6cdSmaya   struct softpipe_tile_cache *zsbuf_cache;
19686d9c6cdSmaya
19786d9c6cdSmaya   unsigned tex_timestamp;
19886d9c6cdSmaya
19986d9c6cdSmaya   /*
20086d9c6cdSmaya    * Texture caches for vertex, fragment, geometry stages.
20186d9c6cdSmaya    * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
20286d9c6cdSmaya    * for compute shaders.
20386d9c6cdSmaya    * XXX wouldn't it make more sense for the tile cache to just be part
20486d9c6cdSmaya    * of sp_sampler_view?
20586d9c6cdSmaya    */
20686d9c6cdSmaya   struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
20786d9c6cdSmaya
20886d9c6cdSmaya   unsigned dump_fs : 1;
20986d9c6cdSmaya   unsigned dump_gs : 1;
21086d9c6cdSmaya   unsigned dump_cs : 1;
21186d9c6cdSmaya   unsigned no_rast : 1;
21286d9c6cdSmaya};
21386d9c6cdSmaya
21486d9c6cdSmaya
21586d9c6cdSmayastatic inline struct softpipe_context *
21686d9c6cdSmayasoftpipe_context( struct pipe_context *pipe )
21786d9c6cdSmaya{
21886d9c6cdSmaya   return (struct softpipe_context *)pipe;
21986d9c6cdSmaya}
22086d9c6cdSmaya
22186d9c6cdSmaya
22286d9c6cdSmayastruct pipe_context *
22386d9c6cdSmayasoftpipe_create_context(struct pipe_screen *, void *priv, unsigned flags);
22486d9c6cdSmaya
22586d9c6cdSmayastruct pipe_resource *
22686d9c6cdSmayasoftpipe_user_buffer_create(struct pipe_screen *screen,
22786d9c6cdSmaya                            void *ptr,
22886d9c6cdSmaya                            unsigned bytes,
22986d9c6cdSmaya			    unsigned bind_flags);
23086d9c6cdSmaya
23186d9c6cdSmaya#define SP_UNREFERENCED         0
23286d9c6cdSmaya#define SP_REFERENCED_FOR_READ  (1 << 0)
23386d9c6cdSmaya#define SP_REFERENCED_FOR_WRITE (1 << 1)
23486d9c6cdSmaya
23586d9c6cdSmayaunsigned int
23686d9c6cdSmayasoftpipe_is_resource_referenced( struct pipe_context *pipe,
23786d9c6cdSmaya                                 struct pipe_resource *texture,
23886d9c6cdSmaya                                 unsigned level, int layer);
23986d9c6cdSmaya
24086d9c6cdSmaya#endif /* SP_CONTEXT_H */
24186d9c6cdSmaya