Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / gallium / drivers / softpipe / sp_context.h
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 *fragment_samplers[PIPE_MAX_SAMPLERS];
64 struct pipe_sampler_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS];
65 struct pipe_sampler_state *geometry_samplers[PIPE_MAX_GEOMETRY_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
75 /** Other rendering state */
76 struct pipe_blend_color blend_color;
77 struct pipe_blend_color blend_color_clamped;
78 struct pipe_stencil_ref stencil_ref;
79 struct pipe_clip_state clip;
80 struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
81 struct pipe_framebuffer_state framebuffer;
82 struct pipe_poly_stipple poly_stipple;
83 struct pipe_scissor_state scissor;
84 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
85 struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
86 struct pipe_sampler_view *geometry_sampler_views[PIPE_MAX_GEOMETRY_SAMPLERS];
87 struct pipe_viewport_state viewport;
88 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
89 struct pipe_index_buffer index_buffer;
90
91 struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
92 int num_so_targets;
93
94 struct pipe_query_data_so_statistics so_stats;
95 unsigned num_primitives_generated;
96
97 unsigned num_fragment_samplers;
98 unsigned num_fragment_sampler_views;
99 unsigned num_vertex_samplers;
100 unsigned num_vertex_sampler_views;
101 unsigned num_geometry_samplers;
102 unsigned num_geometry_sampler_views;
103 unsigned num_vertex_buffers;
104
105 unsigned dirty; /**< Mask of SP_NEW_x flags */
106
107 /* Counter for occlusion queries. Note this supports overlapping
108 * queries.
109 */
110 uint64_t occlusion_count;
111 unsigned active_query_count;
112
113 /** Mapped vertex buffers */
114 ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
115
116 /** Mapped constant buffers */
117 const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
118 unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
119
120 /** Vertex format */
121 struct vertex_info vertex_info;
122 struct vertex_info vertex_info_vbuf;
123
124 /** Which vertex shader output slot contains point size */
125 int psize_slot;
126
127 /** The reduced version of the primitive supplied by the state tracker */
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;
142
143 unsigned line_stipple_counter;
144
145 /** Conditional query object and mode */
146 struct pipe_query *render_cond_query;
147 uint render_cond_mode;
148
149 /** Polygon stipple items */
150 struct {
151 struct pipe_resource *texture;
152 struct pipe_sampler_state *sampler;
153 struct pipe_sampler_view *sampler_view;
154 } pstipple;
155
156 /** Software quad rendering pipeline */
157 struct {
158 struct quad_stage *shade;
159 struct quad_stage *depth_test;
160 struct quad_stage *blend;
161 struct quad_stage *pstipple;
162 struct quad_stage *first; /**< points to one of the above stages */
163 } quad;
164
165 /** TGSI exec things */
166 struct {
167 struct sp_sampler_variant *geom_samplers_list[PIPE_MAX_GEOMETRY_SAMPLERS];
168 struct sp_sampler_variant *vert_samplers_list[PIPE_MAX_VERTEX_SAMPLERS];
169 struct sp_sampler_variant *frag_samplers_list[PIPE_MAX_SAMPLERS];
170 } tgsi;
171
172 struct tgsi_exec_machine *fs_machine;
173
174 /** The primitive drawing context */
175 struct draw_context *draw;
176
177 /** Draw module backend */
178 struct vbuf_render *vbuf_backend;
179 struct draw_stage *vbuf;
180
181 boolean dirty_render_cache;
182
183 struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
184 struct softpipe_tile_cache *zsbuf_cache;
185
186 unsigned tex_timestamp;
187 struct softpipe_tex_tile_cache *fragment_tex_cache[PIPE_MAX_SAMPLERS];
188 struct softpipe_tex_tile_cache *vertex_tex_cache[PIPE_MAX_VERTEX_SAMPLERS];
189 struct softpipe_tex_tile_cache *geometry_tex_cache[PIPE_MAX_GEOMETRY_SAMPLERS];
190
191 unsigned dump_fs : 1;
192 unsigned dump_gs : 1;
193 unsigned no_rast : 1;
194 };
195
196
197 static INLINE struct softpipe_context *
198 softpipe_context( struct pipe_context *pipe )
199 {
200 return (struct softpipe_context *)pipe;
201 }
202
203 void
204 softpipe_reset_sampler_variants(struct softpipe_context *softpipe);
205
206 struct pipe_context *
207 softpipe_create_context( struct pipe_screen *, void *priv );
208
209 struct pipe_resource *
210 softpipe_user_buffer_create(struct pipe_screen *screen,
211 void *ptr,
212 unsigned bytes,
213 unsigned bind_flags);
214
215 #define SP_UNREFERENCED 0
216 #define SP_REFERENCED_FOR_READ (1 << 0)
217 #define SP_REFERENCED_FOR_WRITE (1 << 1)
218
219 unsigned int
220 softpipe_is_resource_referenced( struct pipe_context *pipe,
221 struct pipe_resource *texture,
222 unsigned level, int layer);
223
224 #endif /* SP_CONTEXT_H */