Merge commit 'origin/gallium-master-merge'
[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 #include "pipe/p_defines.h"
36
37 #include "draw/draw_vertex.h"
38
39 #include "sp_quad.h"
40 #include "sp_tex_sample.h"
41
42
43 /**
44 * This is a temporary variable for testing draw-stage polygon stipple.
45 * If zero, do stipple in sp_quad_stipple.c
46 */
47 #define USE_DRAW_STAGE_PSTIPPLE 1
48
49 /* Number of threads working on individual quads.
50 * Setting to 1 disables this feature.
51 */
52 #define SP_NUM_QUAD_THREADS 1
53
54 struct softpipe_winsys;
55 struct softpipe_vbuf_render;
56 struct draw_context;
57 struct draw_stage;
58 struct softpipe_tile_cache;
59 struct sp_fragment_shader;
60 struct sp_vertex_shader;
61
62
63 struct softpipe_context {
64 struct pipe_context pipe; /**< base class */
65
66 /* The most recent drawing state as set by the driver:
67 */
68 const struct pipe_blend_state *blend;
69 const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
70 const struct pipe_depth_stencil_alpha_state *depth_stencil;
71 const struct pipe_rasterizer_state *rasterizer;
72 const struct sp_fragment_shader *fs;
73 const struct sp_vertex_shader *vs;
74
75 struct pipe_blend_color blend_color;
76 struct pipe_clip_state clip;
77 struct pipe_constant_buffer constants[PIPE_SHADER_TYPES];
78 struct pipe_framebuffer_state framebuffer;
79 struct pipe_poly_stipple poly_stipple;
80 struct pipe_scissor_state scissor;
81 struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
82 struct pipe_viewport_state viewport;
83 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
84 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
85 unsigned dirty;
86
87 unsigned num_samplers;
88 unsigned num_textures;
89 unsigned num_vertex_elements;
90 unsigned num_vertex_buffers;
91
92 boolean no_rast;
93
94 /* Counter for occlusion queries. Note this supports overlapping
95 * queries.
96 */
97 uint64_t occlusion_count;
98
99 /*
100 * Mapped vertex buffers
101 */
102 ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
103
104 /** Mapped constant buffers */
105 void *mapped_constants[PIPE_SHADER_TYPES];
106
107 /** Vertex format */
108 struct vertex_info vertex_info;
109 struct vertex_info vertex_info_vbuf;
110
111 int psize_slot;
112
113 unsigned reduced_api_prim; /**< PIPE_PRIM_POINTS, _LINES or _TRIANGLES */
114
115 #if 0
116 /* Stipple derived state:
117 */
118 ubyte stipple_masks[16][16];
119 #endif
120
121 /** Derived from scissor and surface bounds: */
122 struct pipe_scissor_state cliprect;
123
124 unsigned line_stipple_counter;
125
126 /** Software quad rendering pipeline */
127 struct {
128 struct quad_stage *polygon_stipple;
129 struct quad_stage *earlyz;
130 struct quad_stage *shade;
131 struct quad_stage *alpha_test;
132 struct quad_stage *stencil_test;
133 struct quad_stage *depth_test;
134 struct quad_stage *occlusion;
135 struct quad_stage *coverage;
136 struct quad_stage *blend;
137 struct quad_stage *colormask;
138 struct quad_stage *output;
139
140 struct quad_stage *first; /**< points to one of the above stages */
141 } quad[SP_NUM_QUAD_THREADS];
142
143 /** TGSI exec things */
144 struct {
145 struct sp_shader_sampler vert_samplers[PIPE_MAX_SAMPLERS];
146 struct sp_shader_sampler *vert_samplers_list[PIPE_MAX_SAMPLERS];
147 struct sp_shader_sampler frag_samplers[PIPE_MAX_SAMPLERS];
148 struct sp_shader_sampler *frag_samplers_list[PIPE_MAX_SAMPLERS];
149 } tgsi;
150
151 /** The primitive drawing context */
152 struct draw_context *draw;
153 struct draw_stage *setup;
154 struct draw_stage *vbuf;
155 struct softpipe_vbuf_render *vbuf_render;
156
157 struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS];
158 struct softpipe_tile_cache *zsbuf_cache;
159
160 struct softpipe_tile_cache *tex_cache[PIPE_MAX_SAMPLERS];
161
162 int use_sse : 1;
163 int dump_fs : 1;
164 };
165
166
167 static INLINE struct softpipe_context *
168 softpipe_context( struct pipe_context *pipe )
169 {
170 return (struct softpipe_context *)pipe;
171 }
172
173 #endif /* SP_CONTEXT_H */
174