• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
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 VMWARE 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 <keithw@vmware.com>
29  */
30 
31 #ifndef SP_CONTEXT_H
32 #define SP_CONTEXT_H
33 
34 #include "pipe/p_context.h"
35 #include "util/u_blitter.h"
36 
37 #include "draw/draw_vertex.h"
38 
39 #include "sp_quad_pipe.h"
40 #include "sp_setup.h"
41 
42 
43 struct softpipe_vbuf_render;
44 struct draw_context;
45 struct draw_stage;
46 struct softpipe_tile_cache;
47 struct softpipe_tex_tile_cache;
48 struct sp_fragment_shader;
49 struct sp_vertex_shader;
50 struct sp_velems_state;
51 struct sp_so_state;
52 
53 struct softpipe_context {
54    struct pipe_context pipe;  /**< base class */
55 
56    /** Constant state objects */
57    struct pipe_blend_state *blend;
58    struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
59    struct pipe_depth_stencil_alpha_state *depth_stencil;
60    struct pipe_rasterizer_state *rasterizer;
61    struct sp_fragment_shader *fs;
62    struct sp_fragment_shader_variant *fs_variant;
63    struct sp_vertex_shader *vs;
64    struct sp_geometry_shader *gs;
65    struct sp_velems_state *velems;
66    struct sp_so_state *so;
67    struct sp_compute_shader *cs;
68 
69    /** Other rendering state */
70    struct pipe_blend_color blend_color;
71    struct pipe_blend_color blend_color_clamped;
72    struct pipe_stencil_ref stencil_ref;
73    struct pipe_clip_state clip;
74    struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
75    struct pipe_framebuffer_state framebuffer;
76    struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
77    struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
78 
79    struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
80    struct pipe_shader_buffer buffers[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
81    struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
82    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
83    struct pipe_resource *mapped_vs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
84    struct pipe_resource *mapped_gs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
85 
86    struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
87    unsigned num_so_targets;
88 
89    struct pipe_query_data_so_statistics so_stats[PIPE_MAX_VERTEX_STREAMS];
90 
91    struct pipe_query_data_pipeline_statistics pipeline_statistics;
92    unsigned active_statistics_queries;
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 sp_setup_info setup_info;
116    struct vertex_info vertex_info;
117 
118    /** Which vertex shader output slot contains point size */
119    int8_t psize_slot;
120 
121    /** Which vertex shader output slot contains viewport index */
122    int8_t viewport_index_slot;
123 
124    /** Which vertex shader output slot contains layer */
125    int8_t layer_slot;
126 
127    /** The reduced version of the primitive supplied by the gallium frontend */
128    unsigned reduced_api_prim;
129 
130    /** Derived information about which winding orders to cull */
131    unsigned cull_mode;
132 
133    /**
134     * The reduced primitive after unfilled triangles, wide-line decomposition,
135     * etc, are taken into account.  This is the primitive type that's actually
136     * rasterized.
137     */
138    unsigned reduced_prim;
139 
140    /** Derived from scissor and surface bounds: */
141    struct pipe_scissor_state cliprect[PIPE_MAX_VIEWPORTS];
142 
143    /** Conditional query object and mode */
144    struct pipe_query *render_cond_query;
145    enum pipe_render_cond_flag render_cond_mode;
146    bool render_cond_cond;
147 
148    /** Software quad rendering pipeline */
149    struct {
150       struct quad_stage *shade;
151       struct quad_stage *depth_test;
152       struct quad_stage *blend;
153       struct quad_stage *first; /**< points to one of the above stages */
154    } quad;
155 
156    /** TGSI exec things */
157    struct {
158       struct sp_tgsi_sampler *sampler[PIPE_SHADER_TYPES];
159       struct sp_tgsi_image *image[PIPE_SHADER_TYPES];
160       struct sp_tgsi_buffer *buffer[PIPE_SHADER_TYPES];
161    } tgsi;
162 
163    struct tgsi_exec_machine *fs_machine;
164    /** whether early depth testing is enabled */
165    bool early_depth;
166 
167    /** The primitive drawing context */
168    struct draw_context *draw;
169 
170    /** Draw module backend */
171    struct vbuf_render *vbuf_backend;
172    struct draw_stage *vbuf;
173 
174    struct blitter_context *blitter;
175 
176    boolean dirty_render_cache;
177 
178    struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
179    struct softpipe_tile_cache *zsbuf_cache;
180 
181    unsigned tex_timestamp;
182 
183    /*
184     * Texture caches for vertex, fragment, geometry stages.
185     * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
186     * for compute shaders.
187     * XXX wouldn't it make more sense for the tile cache to just be part
188     * of sp_sampler_view?
189     */
190    struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
191 
192    struct util_debug_callback debug;
193 };
194 
195 
196 static inline struct softpipe_context *
softpipe_context(struct pipe_context * pipe)197 softpipe_context( struct pipe_context *pipe )
198 {
199    return (struct softpipe_context *)pipe;
200 }
201 
202 
203 struct pipe_context *
204 softpipe_create_context(struct pipe_screen *, void *priv, unsigned flags);
205 
206 struct pipe_resource *
207 softpipe_user_buffer_create(struct pipe_screen *screen,
208                             void *ptr,
209                             unsigned bytes,
210 			    unsigned bind_flags);
211 
212 #define SP_UNREFERENCED         0
213 #define SP_REFERENCED_FOR_READ  (1 << 0)
214 #define SP_REFERENCED_FOR_WRITE (1 << 1)
215 
216 unsigned int
217 softpipe_is_resource_referenced( struct pipe_context *pipe,
218                                  struct pipe_resource *texture,
219                                  unsigned level, int layer);
220 
221 #endif /* SP_CONTEXT_H */
222