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 /** Do polygon stipple in the draw module? */
44 #define DO_PSTIPPLE_IN_DRAW_MODULE 0
45
46 /** Do polygon stipple with the util module? */
47 #define DO_PSTIPPLE_IN_HELPER_MODULE 1
48
49
50 struct softpipe_vbuf_render;
51 struct draw_context;
52 struct draw_stage;
53 struct softpipe_tile_cache;
54 struct softpipe_tex_tile_cache;
55 struct sp_fragment_shader;
56 struct sp_vertex_shader;
57 struct sp_velems_state;
58 struct sp_so_state;
59
60 struct softpipe_context {
61 struct pipe_context pipe; /**< base class */
62
63 /** Constant state objects */
64 struct pipe_blend_state *blend;
65 struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
66 struct pipe_depth_stencil_alpha_state *depth_stencil;
67 struct pipe_rasterizer_state *rasterizer;
68 struct sp_fragment_shader *fs;
69 struct sp_fragment_shader_variant *fs_variant;
70 struct sp_vertex_shader *vs;
71 struct sp_geometry_shader *gs;
72 struct sp_velems_state *velems;
73 struct sp_so_state *so;
74 struct sp_compute_shader *cs;
75
76 /** Other rendering state */
77 struct pipe_blend_color blend_color;
78 struct pipe_blend_color blend_color_clamped;
79 struct pipe_stencil_ref stencil_ref;
80 struct pipe_clip_state clip;
81 struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
82 struct pipe_framebuffer_state framebuffer;
83 struct pipe_poly_stipple poly_stipple;
84 struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
85 struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
86
87 struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
88 struct pipe_shader_buffer buffers[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
89 struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
90 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
91 struct pipe_index_buffer index_buffer;
92 struct pipe_resource *mapped_vs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
93 struct pipe_resource *mapped_gs_tex[PIPE_MAX_SHADER_SAMPLER_VIEWS];
94
95 struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
96 unsigned num_so_targets;
97
98 struct pipe_query_data_so_statistics so_stats;
99
100 struct pipe_query_data_pipeline_statistics pipeline_statistics;
101 unsigned active_statistics_queries;
102
103 unsigned num_samplers[PIPE_SHADER_TYPES];
104 unsigned num_sampler_views[PIPE_SHADER_TYPES];
105
106 unsigned num_vertex_buffers;
107
108 unsigned dirty; /**< Mask of SP_NEW_x flags */
109
110 /* Counter for occlusion queries. Note this supports overlapping
111 * queries.
112 */
113 uint64_t occlusion_count;
114 unsigned active_query_count;
115
116 /** Mapped vertex buffers */
117 ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
118
119 /** Mapped constant buffers */
120 const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
121 unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
122
123 /** Vertex format */
124 struct sp_setup_info setup_info;
125 struct vertex_info vertex_info;
126
127 /** Which vertex shader output slot contains point size */
128 int8_t psize_slot;
129
130 /** Which vertex shader output slot contains viewport index */
131 int8_t viewport_index_slot;
132
133 /** Which vertex shader output slot contains layer */
134 int8_t layer_slot;
135
136 /** The reduced version of the primitive supplied by the state tracker */
137 unsigned reduced_api_prim;
138
139 /** Derived information about which winding orders to cull */
140 unsigned cull_mode;
141
142 /**
143 * The reduced primitive after unfilled triangles, wide-line decomposition,
144 * etc, are taken into account. This is the primitive type that's actually
145 * rasterized.
146 */
147 unsigned reduced_prim;
148
149 /** Derived from scissor and surface bounds: */
150 struct pipe_scissor_state cliprect[PIPE_MAX_VIEWPORTS];
151
152 unsigned line_stipple_counter;
153
154 /** Conditional query object and mode */
155 struct pipe_query *render_cond_query;
156 uint render_cond_mode;
157 boolean render_cond_cond;
158
159 /** Polygon stipple items */
160 struct {
161 struct pipe_resource *texture;
162 struct pipe_sampler_state *sampler;
163 struct pipe_sampler_view *sampler_view;
164 } pstipple;
165
166 /** Software quad rendering pipeline */
167 struct {
168 struct quad_stage *shade;
169 struct quad_stage *depth_test;
170 struct quad_stage *blend;
171 struct quad_stage *pstipple;
172 struct quad_stage *first; /**< points to one of the above stages */
173 } quad;
174
175 /** TGSI exec things */
176 struct {
177 struct sp_tgsi_sampler *sampler[PIPE_SHADER_TYPES];
178 struct sp_tgsi_image *image[PIPE_SHADER_TYPES];
179 struct sp_tgsi_buffer *buffer[PIPE_SHADER_TYPES];
180 } tgsi;
181
182 struct tgsi_exec_machine *fs_machine;
183 /** whether early depth testing is enabled */
184 bool early_depth;
185
186 /** The primitive drawing context */
187 struct draw_context *draw;
188
189 /** Draw module backend */
190 struct vbuf_render *vbuf_backend;
191 struct draw_stage *vbuf;
192
193 struct blitter_context *blitter;
194
195 boolean dirty_render_cache;
196
197 struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
198 struct softpipe_tile_cache *zsbuf_cache;
199
200 unsigned tex_timestamp;
201
202 /*
203 * Texture caches for vertex, fragment, geometry stages.
204 * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
205 * for compute shaders.
206 * XXX wouldn't it make more sense for the tile cache to just be part
207 * of sp_sampler_view?
208 */
209 struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
210
211 unsigned dump_fs : 1;
212 unsigned dump_gs : 1;
213 unsigned dump_cs : 1;
214 unsigned no_rast : 1;
215 };
216
217
218 static inline struct softpipe_context *
softpipe_context(struct pipe_context * pipe)219 softpipe_context( struct pipe_context *pipe )
220 {
221 return (struct softpipe_context *)pipe;
222 }
223
224
225 struct pipe_context *
226 softpipe_create_context(struct pipe_screen *, void *priv, unsigned flags);
227
228 struct pipe_resource *
229 softpipe_user_buffer_create(struct pipe_screen *screen,
230 void *ptr,
231 unsigned bytes,
232 unsigned bind_flags);
233
234 #define SP_UNREFERENCED 0
235 #define SP_REFERENCED_FOR_READ (1 << 0)
236 #define SP_REFERENCED_FOR_WRITE (1 << 1)
237
238 unsigned int
239 softpipe_is_resource_referenced( struct pipe_context *pipe,
240 struct pipe_resource *texture,
241 unsigned level, int layer);
242
243 #endif /* SP_CONTEXT_H */
244