• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * All Rights Reserved.
5  *
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:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
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.
25  *
26  **************************************************************************/
27 
28 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
29  */
30 
31 #ifndef SP_CONTEXT_H
32 #define SP_CONTEXT_H
33 
34 #include "pipe/p_context.h"
35 
36 #include "draw/draw_vertex.h"
37 
38 #include "sp_quad_pipe.h"
39 
40 
41 /** Do polygon stipple in the draw module? */
42 #define DO_PSTIPPLE_IN_DRAW_MODULE 0
43 
44 /** Do polygon stipple with the util module? */
45 #define DO_PSTIPPLE_IN_HELPER_MODULE 1
46 
47 
48 struct softpipe_vbuf_render;
49 struct draw_context;
50 struct draw_stage;
51 struct softpipe_tile_cache;
52 struct softpipe_tex_tile_cache;
53 struct sp_fragment_shader;
54 struct sp_vertex_shader;
55 struct sp_velems_state;
56 struct sp_so_state;
57 
58 struct softpipe_context {
59    struct pipe_context pipe;  /**< base class */
60 
61    /** Constant state objects */
62    struct pipe_blend_state *blend;
63    struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
64    struct pipe_depth_stencil_alpha_state *depth_stencil;
65    struct pipe_rasterizer_state *rasterizer;
66    struct sp_fragment_shader *fs;
67    struct sp_fragment_shader_variant *fs_variant;
68    struct sp_vertex_shader *vs;
69    struct sp_geometry_shader *gs;
70    struct sp_velems_state *velems;
71    struct sp_so_state *so;
72 
73    /** Other rendering state */
74    struct pipe_blend_color blend_color;
75    struct pipe_blend_color blend_color_clamped;
76    struct pipe_stencil_ref stencil_ref;
77    struct pipe_clip_state clip;
78    struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
79    struct pipe_framebuffer_state framebuffer;
80    struct pipe_poly_stipple poly_stipple;
81    struct pipe_scissor_state scissor;
82    struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
83 
84    struct pipe_viewport_state viewport;
85    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
86    struct pipe_index_buffer index_buffer;
87 
88    struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
89    int num_so_targets;
90 
91    struct pipe_query_data_so_statistics so_stats;
92    unsigned num_primitives_generated;
93 
94    unsigned num_samplers[PIPE_SHADER_TYPES];
95    unsigned num_sampler_views[PIPE_SHADER_TYPES];
96 
97    unsigned num_vertex_buffers;
98 
99    unsigned dirty; /**< Mask of SP_NEW_x flags */
100 
101    /* Counter for occlusion queries.  Note this supports overlapping
102     * queries.
103     */
104    uint64_t occlusion_count;
105    unsigned active_query_count;
106 
107    /** Mapped vertex buffers */
108    ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
109 
110    /** Mapped constant buffers */
111    const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
112    unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
113 
114    /** Vertex format */
115    struct vertex_info vertex_info;
116    struct vertex_info vertex_info_vbuf;
117 
118    /** Which vertex shader output slot contains point size */
119    int psize_slot;
120 
121    /** The reduced version of the primitive supplied by the state tracker */
122    unsigned reduced_api_prim;
123 
124    /** Derived information about which winding orders to cull */
125    unsigned cull_mode;
126 
127    /**
128     * The reduced primitive after unfilled triangles, wide-line decomposition,
129     * etc, are taken into account.  This is the primitive type that's actually
130     * rasterized.
131     */
132    unsigned reduced_prim;
133 
134    /** Derived from scissor and surface bounds: */
135    struct pipe_scissor_state cliprect;
136 
137    unsigned line_stipple_counter;
138 
139    /** Conditional query object and mode */
140    struct pipe_query *render_cond_query;
141    uint render_cond_mode;
142 
143    /** Polygon stipple items */
144    struct {
145       struct pipe_resource *texture;
146       struct pipe_sampler_state *sampler;
147       struct pipe_sampler_view *sampler_view;
148    } pstipple;
149 
150    /** Software quad rendering pipeline */
151    struct {
152       struct quad_stage *shade;
153       struct quad_stage *depth_test;
154       struct quad_stage *blend;
155       struct quad_stage *pstipple;
156       struct quad_stage *first; /**< points to one of the above stages */
157    } quad;
158 
159    /** TGSI exec things */
160    struct {
161       struct sp_sampler_variant *samplers_list[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
162    } tgsi;
163 
164    struct tgsi_exec_machine *fs_machine;
165 
166    /** The primitive drawing context */
167    struct draw_context *draw;
168 
169    /** Draw module backend */
170    struct vbuf_render *vbuf_backend;
171    struct draw_stage *vbuf;
172 
173    boolean dirty_render_cache;
174 
175    struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
176    struct softpipe_tile_cache *zsbuf_cache;
177 
178    unsigned tex_timestamp;
179 
180    /*
181     * Texture caches for vertex, fragment, geometry stages.
182     * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
183     * for compute shaders.
184     */
185    struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_GEOMETRY+1][PIPE_MAX_SAMPLERS];
186 
187    unsigned dump_fs : 1;
188    unsigned dump_gs : 1;
189    unsigned no_rast : 1;
190 };
191 
192 
193 static INLINE struct softpipe_context *
softpipe_context(struct pipe_context * pipe)194 softpipe_context( struct pipe_context *pipe )
195 {
196    return (struct softpipe_context *)pipe;
197 }
198 
199 void
200 softpipe_reset_sampler_variants(struct softpipe_context *softpipe);
201 
202 struct pipe_context *
203 softpipe_create_context( struct pipe_screen *, void *priv );
204 
205 struct pipe_resource *
206 softpipe_user_buffer_create(struct pipe_screen *screen,
207                             void *ptr,
208                             unsigned bytes,
209 			    unsigned bind_flags);
210 
211 #define SP_UNREFERENCED         0
212 #define SP_REFERENCED_FOR_READ  (1 << 0)
213 #define SP_REFERENCED_FOR_WRITE (1 << 1)
214 
215 unsigned int
216 softpipe_is_resource_referenced( struct pipe_context *pipe,
217                                  struct pipe_resource *texture,
218                                  unsigned level, int layer);
219 
220 #endif /* SP_CONTEXT_H */
221