softpipe: implement fragment shader variants
[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 driver here, or in the draw module? */
42 #define DO_PSTIPPLE_IN_DRAW_MODULE 1
43
44
45 struct softpipe_vbuf_render;
46 struct draw_context;
47 struct draw_stage;
48 struct softpipe_tile_cache;
49 struct softpipe_tex_tile_cache;
50 struct sp_fragment_shader;
51 struct sp_vertex_shader;
52 struct sp_velems_state;
53 struct sp_so_state;
54
55
56 struct softpipe_context {
57 struct pipe_context pipe; /**< base class */
58
59 /** Constant state objects */
60 struct pipe_blend_state *blend;
61 struct pipe_sampler_state *fragment_samplers[PIPE_MAX_SAMPLERS];
62 struct pipe_sampler_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS];
63 struct pipe_sampler_state *geometry_samplers[PIPE_MAX_GEOMETRY_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_stencil_ref stencil_ref;
76 struct pipe_clip_state clip;
77 struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
78 struct pipe_framebuffer_state framebuffer;
79 struct pipe_poly_stipple poly_stipple;
80 struct pipe_scissor_state scissor;
81 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
82 struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
83 struct pipe_sampler_view *geometry_sampler_views[PIPE_MAX_GEOMETRY_SAMPLERS];
84 struct pipe_viewport_state viewport;
85 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
86 struct pipe_index_buffer index_buffer;
87 struct {
88 struct softpipe_resource *buffer[PIPE_MAX_SO_BUFFERS];
89 int offset[PIPE_MAX_SO_BUFFERS];
90 int so_count[PIPE_MAX_SO_BUFFERS];
91 int num_buffers;
92 } so_target;
93 struct pipe_query_data_so_statistics so_stats;
94
95 unsigned num_fragment_samplers;
96 unsigned num_fragment_sampler_views;
97 unsigned num_vertex_samplers;
98 unsigned num_vertex_sampler_views;
99 unsigned num_geometry_samplers;
100 unsigned num_geometry_sampler_views;
101 unsigned num_vertex_buffers;
102
103 unsigned dirty; /**< Mask of SP_NEW_x flags */
104
105 /* Counter for occlusion queries. Note this supports overlapping
106 * queries.
107 */
108 uint64_t occlusion_count;
109 unsigned active_query_count;
110
111 /** Mapped vertex buffers */
112 ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
113
114 /** Mapped constant buffers */
115 const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
116 unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
117
118 /** Vertex format */
119 struct vertex_info vertex_info;
120 struct vertex_info vertex_info_vbuf;
121
122 /** Which vertex shader output slot contains point size */
123 int psize_slot;
124
125 /** The reduced version of the primitive supplied by the state tracker */
126 unsigned reduced_api_prim;
127
128 /** Derived information about which winding orders to cull */
129 unsigned cull_mode;
130
131 /**
132 * The reduced primitive after unfilled triangles, wide-line decomposition,
133 * etc, are taken into account. This is the primitive type that's actually
134 * rasterized.
135 */
136 unsigned reduced_prim;
137
138 /** Derived from scissor and surface bounds: */
139 struct pipe_scissor_state cliprect;
140
141 unsigned line_stipple_counter;
142
143 /** Conditional query object and mode */
144 struct pipe_query *render_cond_query;
145 uint render_cond_mode;
146
147 /** Software quad rendering pipeline */
148 struct {
149 struct quad_stage *shade;
150 struct quad_stage *depth_test;
151 struct quad_stage *blend;
152 struct quad_stage *pstipple;
153 struct quad_stage *first; /**< points to one of the above stages */
154 } quad;
155
156 /** TGSI exec things */
157 struct {
158 struct sp_sampler_variant *geom_samplers_list[PIPE_MAX_GEOMETRY_SAMPLERS];
159 struct sp_sampler_variant *vert_samplers_list[PIPE_MAX_VERTEX_SAMPLERS];
160 struct sp_sampler_variant *frag_samplers_list[PIPE_MAX_SAMPLERS];
161 } tgsi;
162
163 struct tgsi_exec_machine *fs_machine;
164
165 /** The primitive drawing context */
166 struct draw_context *draw;
167
168 /** Draw module backend */
169 struct vbuf_render *vbuf_backend;
170 struct draw_stage *vbuf;
171
172 boolean dirty_render_cache;
173
174 struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
175 struct softpipe_tile_cache *zsbuf_cache;
176
177 unsigned tex_timestamp;
178 struct softpipe_tex_tile_cache *fragment_tex_cache[PIPE_MAX_SAMPLERS];
179 struct softpipe_tex_tile_cache *vertex_tex_cache[PIPE_MAX_VERTEX_SAMPLERS];
180 struct softpipe_tex_tile_cache *geometry_tex_cache[PIPE_MAX_GEOMETRY_SAMPLERS];
181
182 unsigned use_sse : 1;
183 unsigned dump_fs : 1;
184 unsigned dump_gs : 1;
185 unsigned no_rast : 1;
186 };
187
188
189 static INLINE struct softpipe_context *
190 softpipe_context( struct pipe_context *pipe )
191 {
192 return (struct softpipe_context *)pipe;
193 }
194
195 void
196 softpipe_reset_sampler_variants(struct softpipe_context *softpipe);
197
198 struct pipe_context *
199 softpipe_create_context( struct pipe_screen *, void *priv );
200
201
202 #define SP_UNREFERENCED 0
203 #define SP_REFERENCED_FOR_READ (1 << 0)
204 #define SP_REFERENCED_FOR_WRITE (1 << 1)
205
206 unsigned int
207 softpipe_is_resource_referenced( struct pipe_context *pipe,
208 struct pipe_resource *texture,
209 unsigned level, int layer);
210
211 #endif /* SP_CONTEXT_H */