14a49301eSmrg/**************************************************************************
24a49301eSmrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
134a49301eSmrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
174a49301eSmrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254a49301eSmrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
28af69d88dSmrg/* Authors:  Keith Whitwell <keithw@vmware.com>
294a49301eSmrg */
304a49301eSmrg
314a49301eSmrg#ifndef SP_CONTEXT_H
324a49301eSmrg#define SP_CONTEXT_H
334a49301eSmrg
344a49301eSmrg#include "pipe/p_context.h"
35af69d88dSmrg#include "util/u_blitter.h"
364a49301eSmrg
374a49301eSmrg#include "draw/draw_vertex.h"
384a49301eSmrg
394a49301eSmrg#include "sp_quad_pipe.h"
4001e04c3fSmrg#include "sp_setup.h"
414a49301eSmrg
424a49301eSmrg
43af69d88dSmrg/** Do polygon stipple in the draw module? */
44af69d88dSmrg#define DO_PSTIPPLE_IN_DRAW_MODULE 0
45af69d88dSmrg
46af69d88dSmrg/** Do polygon stipple with the util module? */
47af69d88dSmrg#define DO_PSTIPPLE_IN_HELPER_MODULE 1
483464ebd5Sriastradh
493464ebd5Sriastradh
504a49301eSmrgstruct softpipe_vbuf_render;
514a49301eSmrgstruct draw_context;
524a49301eSmrgstruct draw_stage;
534a49301eSmrgstruct softpipe_tile_cache;
544a49301eSmrgstruct softpipe_tex_tile_cache;
554a49301eSmrgstruct sp_fragment_shader;
564a49301eSmrgstruct sp_vertex_shader;
573464ebd5Sriastradhstruct sp_velems_state;
583464ebd5Sriastradhstruct sp_so_state;
594a49301eSmrg
604a49301eSmrgstruct softpipe_context {
614a49301eSmrg   struct pipe_context pipe;  /**< base class */
624a49301eSmrg
634a49301eSmrg   /** Constant state objects */
644a49301eSmrg   struct pipe_blend_state *blend;
65af69d88dSmrg   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
664a49301eSmrg   struct pipe_depth_stencil_alpha_state *depth_stencil;
674a49301eSmrg   struct pipe_rasterizer_state *rasterizer;
684a49301eSmrg   struct sp_fragment_shader *fs;
69af69d88dSmrg   struct sp_fragment_shader_variant *fs_variant;
704a49301eSmrg   struct sp_vertex_shader *vs;
71cdc920a0Smrg   struct sp_geometry_shader *gs;
723464ebd5Sriastradh   struct sp_velems_state *velems;
733464ebd5Sriastradh   struct sp_so_state *so;
7401e04c3fSmrg   struct sp_compute_shader *cs;
754a49301eSmrg
764a49301eSmrg   /** Other rendering state */
774a49301eSmrg   struct pipe_blend_color blend_color;
78af69d88dSmrg   struct pipe_blend_color blend_color_clamped;
79cdc920a0Smrg   struct pipe_stencil_ref stencil_ref;
804a49301eSmrg   struct pipe_clip_state clip;
813464ebd5Sriastradh   struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
824a49301eSmrg   struct pipe_framebuffer_state framebuffer;
834a49301eSmrg   struct pipe_poly_stipple poly_stipple;
8401e04c3fSmrg   struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
85af69d88dSmrg   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
86af69d88dSmrg
8701e04c3fSmrg   struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
8801e04c3fSmrg   struct pipe_shader_buffer buffers[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
8901e04c3fSmrg   struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
904a49301eSmrg   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
9101e04c3fSmrg   struct pipe_resource *mapped_vs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
9201e04c3fSmrg   struct pipe_resource *mapped_gs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
93af69d88dSmrg
94af69d88dSmrg   struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
95af69d88dSmrg   unsigned num_so_targets;
96af69d88dSmrg
979f464c52Smaya   struct pipe_query_data_so_statistics so_stats[PIPE_MAX_VERTEX_STREAMS];
983464ebd5Sriastradh
99af69d88dSmrg   struct pipe_query_data_pipeline_statistics pipeline_statistics;
100af69d88dSmrg   unsigned active_statistics_queries;
101af69d88dSmrg
102af69d88dSmrg   unsigned num_samplers[PIPE_SHADER_TYPES];
103af69d88dSmrg   unsigned num_sampler_views[PIPE_SHADER_TYPES];
104af69d88dSmrg
1054a49301eSmrg   unsigned num_vertex_buffers;
1064a49301eSmrg
1074a49301eSmrg   unsigned dirty; /**< Mask of SP_NEW_x flags */
1084a49301eSmrg
1094a49301eSmrg   /* Counter for occlusion queries.  Note this supports overlapping
1104a49301eSmrg    * queries.
1114a49301eSmrg    */
1124a49301eSmrg   uint64_t occlusion_count;
1134a49301eSmrg   unsigned active_query_count;
1144a49301eSmrg
1154a49301eSmrg   /** Mapped vertex buffers */
1164a49301eSmrg   ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
1174a49301eSmrg
1184a49301eSmrg   /** Mapped constant buffers */
1193464ebd5Sriastradh   const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
1203464ebd5Sriastradh   unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
1214a49301eSmrg
1224a49301eSmrg   /** Vertex format */
12301e04c3fSmrg   struct sp_setup_info setup_info;
1244a49301eSmrg   struct vertex_info vertex_info;
1254a49301eSmrg
1264a49301eSmrg   /** Which vertex shader output slot contains point size */
12701e04c3fSmrg   int8_t psize_slot;
12801e04c3fSmrg
12901e04c3fSmrg   /** Which vertex shader output slot contains viewport index */
13001e04c3fSmrg   int8_t viewport_index_slot;
1314a49301eSmrg
132af69d88dSmrg   /** Which vertex shader output slot contains layer */
13301e04c3fSmrg   int8_t layer_slot;
134af69d88dSmrg
1357ec681f3Smrg   /** The reduced version of the primitive supplied by the gallium frontend */
1364a49301eSmrg   unsigned reduced_api_prim;
1374a49301eSmrg
1383464ebd5Sriastradh   /** Derived information about which winding orders to cull */
1393464ebd5Sriastradh   unsigned cull_mode;
1403464ebd5Sriastradh
1414a49301eSmrg   /**
1424a49301eSmrg    * The reduced primitive after unfilled triangles, wide-line decomposition,
1434a49301eSmrg    * etc, are taken into account.  This is the primitive type that's actually
1444a49301eSmrg    * rasterized.
1454a49301eSmrg    */
1464a49301eSmrg   unsigned reduced_prim;
1474a49301eSmrg
1484a49301eSmrg   /** Derived from scissor and surface bounds: */
14901e04c3fSmrg   struct pipe_scissor_state cliprect[PIPE_MAX_VIEWPORTS];
1504a49301eSmrg
151cdc920a0Smrg   /** Conditional query object and mode */
152cdc920a0Smrg   struct pipe_query *render_cond_query;
15301e04c3fSmrg   enum pipe_render_cond_flag render_cond_mode;
1547ec681f3Smrg   bool render_cond_cond;
155af69d88dSmrg
156af69d88dSmrg   /** Polygon stipple items */
157af69d88dSmrg   struct {
158af69d88dSmrg      struct pipe_resource *texture;
159af69d88dSmrg      struct pipe_sampler_state *sampler;
160af69d88dSmrg      struct pipe_sampler_view *sampler_view;
161af69d88dSmrg   } pstipple;
162cdc920a0Smrg
1634a49301eSmrg   /** Software quad rendering pipeline */
1644a49301eSmrg   struct {
1654a49301eSmrg      struct quad_stage *shade;
1664a49301eSmrg      struct quad_stage *depth_test;
1674a49301eSmrg      struct quad_stage *blend;
1683464ebd5Sriastradh      struct quad_stage *pstipple;
1694a49301eSmrg      struct quad_stage *first; /**< points to one of the above stages */
1704a49301eSmrg   } quad;
1714a49301eSmrg
1724a49301eSmrg   /** TGSI exec things */
1734a49301eSmrg   struct {
174af69d88dSmrg      struct sp_tgsi_sampler *sampler[PIPE_SHADER_TYPES];
17501e04c3fSmrg      struct sp_tgsi_image *image[PIPE_SHADER_TYPES];
17601e04c3fSmrg      struct sp_tgsi_buffer *buffer[PIPE_SHADER_TYPES];
1774a49301eSmrg   } tgsi;
1784a49301eSmrg
1793464ebd5Sriastradh   struct tgsi_exec_machine *fs_machine;
18001e04c3fSmrg   /** whether early depth testing is enabled */
18101e04c3fSmrg   bool early_depth;
1823464ebd5Sriastradh
1834a49301eSmrg   /** The primitive drawing context */
1844a49301eSmrg   struct draw_context *draw;
1854a49301eSmrg
1864a49301eSmrg   /** Draw module backend */
1874a49301eSmrg   struct vbuf_render *vbuf_backend;
1884a49301eSmrg   struct draw_stage *vbuf;
1894a49301eSmrg
190af69d88dSmrg   struct blitter_context *blitter;
191af69d88dSmrg
1924a49301eSmrg   boolean dirty_render_cache;
1934a49301eSmrg
1944a49301eSmrg   struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
1954a49301eSmrg   struct softpipe_tile_cache *zsbuf_cache;
1964a49301eSmrg
1974a49301eSmrg   unsigned tex_timestamp;
1984a49301eSmrg
199af69d88dSmrg   /*
200af69d88dSmrg    * Texture caches for vertex, fragment, geometry stages.
201af69d88dSmrg    * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
202af69d88dSmrg    * for compute shaders.
203af69d88dSmrg    * XXX wouldn't it make more sense for the tile cache to just be part
204af69d88dSmrg    * of sp_sampler_view?
205af69d88dSmrg    */
20601e04c3fSmrg   struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
207af69d88dSmrg
2087ec681f3Smrg   struct pipe_debug_callback debug;
2094a49301eSmrg};
2104a49301eSmrg
2114a49301eSmrg
21201e04c3fSmrgstatic inline struct softpipe_context *
2134a49301eSmrgsoftpipe_context( struct pipe_context *pipe )
2144a49301eSmrg{
2154a49301eSmrg   return (struct softpipe_context *)pipe;
2164a49301eSmrg}
2174a49301eSmrg
2184a49301eSmrg
219cdc920a0Smrgstruct pipe_context *
22001e04c3fSmrgsoftpipe_create_context(struct pipe_screen *, void *priv, unsigned flags);
221cdc920a0Smrg
222af69d88dSmrgstruct pipe_resource *
223af69d88dSmrgsoftpipe_user_buffer_create(struct pipe_screen *screen,
224af69d88dSmrg                            void *ptr,
225af69d88dSmrg                            unsigned bytes,
226af69d88dSmrg			    unsigned bind_flags);
2274a49301eSmrg
2283464ebd5Sriastradh#define SP_UNREFERENCED         0
2293464ebd5Sriastradh#define SP_REFERENCED_FOR_READ  (1 << 0)
2303464ebd5Sriastradh#define SP_REFERENCED_FOR_WRITE (1 << 1)
2313464ebd5Sriastradh
2323464ebd5Sriastradhunsigned int
2333464ebd5Sriastradhsoftpipe_is_resource_referenced( struct pipe_context *pipe,
2343464ebd5Sriastradh                                 struct pipe_resource *texture,
2353464ebd5Sriastradh                                 unsigned level, int layer);
2363464ebd5Sriastradh
2374a49301eSmrg#endif /* SP_CONTEXT_H */
238