r300-gallium: Pick up a few more bits of rs_state.
[mesa.git] / src / gallium / drivers / r300 / r300_context.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef R300_CONTEXT_H
24 #define R300_CONTEXT_H
25
26 #include "draw/draw_context.h"
27 #include "draw/draw_vertex.h"
28 #include "pipe/p_context.h"
29 #include "tgsi/tgsi_scan.h"
30 #include "util/u_memory.h"
31
32 #include "r300_clear.h"
33 #include "r300_screen.h"
34 #include "r300_winsys.h"
35
36 struct r300_blend_state {
37 uint32_t blend_control; /* R300_RB3D_CBLEND: 0x4e04 */
38 uint32_t alpha_blend_control; /* R300_RB3D_ABLEND: 0x4e08 */
39 uint32_t rop; /* R300_RB3D_ROPCNTL: 0x4e18 */
40 uint32_t dither; /* R300_RB3D_DITHER_CTL: 0x4e50 */
41 };
42
43 struct r300_blend_color_state {
44 /* RV515 and earlier */
45 uint32_t blend_color; /* R300_RB3D_BLEND_COLOR: 0x4e10 */
46 /* R520 and newer */
47 uint32_t blend_color_red_alpha; /* R500_RB3D_CONSTANT_COLOR_AR: 0x4ef8 */
48 uint32_t blend_color_green_blue; /* R500_RB3D_CONSTANT_COLOR_GB: 0x4efc */
49 };
50
51 struct r300_dsa_state {
52 uint32_t alpha_function; /* R300_FG_ALPHA_FUNC: 0x4bd4 */
53 uint32_t alpha_reference; /* R500_FG_ALPHA_VALUE: 0x4be0 */
54 uint32_t z_buffer_control; /* R300_ZB_CNTL: 0x4f00 */
55 uint32_t z_stencil_control; /* R300_ZB_ZSTENCILCNTL: 0x4f04 */
56 uint32_t stencil_ref_mask; /* R300_ZB_STENCILREFMASK: 0x4f08 */
57 uint32_t z_buffer_top; /* R300_ZB_ZTOP: 0x4f14 */
58 uint32_t stencil_ref_bf; /* R500_ZB_STENCILREFMASK_BF: 0x4fd4 */
59 };
60
61 struct r300_rs_state {
62 /* XXX icky as fucking hell */
63 struct pipe_rasterizer_state rs;
64
65 uint32_t vap_control_status; /* R300_VAP_CNTL_STATUS: 0x2140 */
66 uint32_t point_size; /* R300_GA_POINT_SIZE: 0x421c */
67 uint32_t point_minmax; /* R300_GA_POINT_MINMAX: 0x4230 */
68 uint32_t line_control; /* R300_GA_LINE_CNTL: 0x4234 */
69 uint32_t depth_scale_front; /* R300_SU_POLY_OFFSET_FRONT_SCALE: 0x42a4 */
70 uint32_t depth_offset_front;/* R300_SU_POLY_OFFSET_FRONT_OFFSET: 0x42a8 */
71 uint32_t depth_scale_back; /* R300_SU_POLY_OFFSET_BACK_SCALE: 0x42ac */
72 uint32_t depth_offset_back; /* R300_SU_POLY_OFFSET_BACK_OFFSET: 0x42b0 */
73 uint32_t polygon_offset_enable; /* R300_SU_POLY_OFFSET_ENABLE: 0x42b4 */
74 uint32_t cull_mode; /* R300_SU_CULL_MODE: 0x42b8 */
75 uint32_t line_stipple_config; /* R300_GA_LINE_STIPPLE_CONFIG: 0x4328 */
76 uint32_t line_stipple_value; /* R300_GA_LINE_STIPPLE_VALUE: 0x4260 */
77 };
78
79 struct r300_rs_block {
80 uint32_t ip[8]; /* R300_RS_IP_[0-7], R500_RS_IP_[0-7] */
81 uint32_t count; /* R300_RS_COUNT */
82 uint32_t inst_count; /* R300_RS_INST_COUNT */
83 uint32_t inst[8]; /* R300_RS_INST_[0-7] */
84 };
85
86 struct r300_sampler_state {
87 uint32_t filter0; /* R300_TX_FILTER0: 0x4400 */
88 uint32_t filter1; /* R300_TX_FILTER1: 0x4440 */
89 uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */
90 };
91
92 struct r300_scissor_state {
93 uint32_t scissor_top_left; /* R300_SC_SCISSORS_TL: 0x43e0 */
94 uint32_t scissor_bottom_right; /* R300_SC_SCISSORS_BR: 0x43e4 */
95 };
96
97 struct r300_texture_state {
98 };
99
100 #define R300_NEW_BLEND 0x0000001
101 #define R300_NEW_BLEND_COLOR 0x0000002
102 #define R300_NEW_CONSTANTS 0x0000004
103 #define R300_NEW_DSA 0x0000008
104 #define R300_NEW_FRAMEBUFFERS 0x0000010
105 #define R300_NEW_FRAGMENT_SHADER 0x0000020
106 #define R300_NEW_RASTERIZER 0x0000040
107 #define R300_NEW_RS_BLOCK 0x0000080
108 #define R300_NEW_SAMPLER 0x0000100
109 #define R300_NEW_SCISSOR 0x0010000
110 #define R300_NEW_TEXTURE 0x0020000
111 #define R300_NEW_VERTEX_FORMAT 0x2000000
112 #define R300_NEW_VERTEX_SHADER 0x4000000
113 #define R300_NEW_KITCHEN_SINK 0x7ffffff
114
115 /* The next several objects are not pure Radeon state; they inherit from
116 * various Gallium classes. */
117
118 struct r300_constant_buffer {
119 /* Buffer of constants */
120 /* XXX first number should be raised */
121 float constants[8][4];
122 /* Number of user-defined constants */
123 int user_count;
124 /* Total number of constants */
125 int count;
126 };
127
128 struct r3xx_fragment_shader {
129 /* Parent class */
130 struct pipe_shader_state state;
131 struct tgsi_shader_info info;
132
133 /* Has this shader been translated yet? */
134 boolean translated;
135
136 /* Pixel stack size */
137 int stack_size;
138 };
139
140 struct r300_fragment_shader {
141 /* Parent class */
142 struct r3xx_fragment_shader shader;
143
144 /* Number of ALU instructions */
145 int alu_instruction_count;
146
147 /* Number of texture instructions */
148 int tex_instruction_count;
149
150 /* Number of texture indirections */
151 int indirections;
152
153 /* Indirection node offsets */
154 int offset0;
155 int offset1;
156 int offset2;
157 int offset3;
158
159 /* Machine instructions */
160 struct {
161 uint32_t alu_rgb_inst;
162 uint32_t alu_rgb_addr;
163 uint32_t alu_alpha_inst;
164 uint32_t alu_alpha_addr;
165 } instructions[64]; /* XXX magic num */
166 };
167
168 struct r500_fragment_shader {
169 /* Parent class */
170 struct r3xx_fragment_shader shader;
171
172 /* Number of used instructions */
173 int instruction_count;
174
175 /* Machine instructions */
176 struct {
177 uint32_t inst0;
178 uint32_t inst1;
179 uint32_t inst2;
180 uint32_t inst3;
181 uint32_t inst4;
182 uint32_t inst5;
183 } instructions[256]; /*< XXX magic number */
184 };
185
186 struct r300_texture {
187 /* Parent class */
188 struct pipe_texture tex;
189
190 /* Offsets into the buffer. */
191 unsigned offset[PIPE_MAX_TEXTURE_LEVELS];
192
193 /* Stride (pitch?) of this texture in bytes */
194 unsigned stride;
195
196 /* Total size of this texture, in bytes. */
197 unsigned size;
198
199 /* Pipe buffer backing this texture. */
200 struct pipe_buffer* buffer;
201 };
202
203 struct r300_vertex_format {
204 /* Parent class */
205 struct vertex_info vinfo;
206 /* R300_VAP_PROG_STREAK_CNTL_[0-7] */
207 uint32_t vap_prog_stream_cntl[8];
208 /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */
209 uint32_t vap_prog_stream_cntl_ext[8];
210 };
211
212 struct r300_context {
213 /* Parent class */
214 struct pipe_context context;
215
216 /* The interface to the windowing system, etc. */
217 struct r300_winsys* winsys;
218 /* Draw module. Used mostly for SW TCL. */
219 struct draw_context* draw;
220
221 /* Various CSO state objects. */
222 /* Blend state. */
223 struct r300_blend_state* blend_state;
224 /* Blend color state. */
225 struct r300_blend_color_state* blend_color_state;
226 /* Shader constants. */
227 struct r300_constant_buffer shader_constants[PIPE_SHADER_TYPES];
228 /* Depth, stencil, and alpha state. */
229 struct r300_dsa_state* dsa_state;
230 /* Fragment shader. */
231 struct r3xx_fragment_shader* fs;
232 /* Framebuffer state. We currently don't need our own version of this. */
233 struct pipe_framebuffer_state framebuffer_state;
234 /* Rasterizer state. */
235 struct r300_rs_state* rs_state;
236 /* RS block state. */
237 struct r300_rs_block* rs_block;
238 /* Sampler states. */
239 struct r300_sampler_state* sampler_states[8];
240 int sampler_count;
241 /* Scissor state. */
242 struct r300_scissor_state* scissor_state;
243 /* Texture states. */
244 struct r300_texture* textures[8];
245 struct r300_texture_state* texture_states[8];
246 int texture_count;
247 /* Vertex buffers. */
248 struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
249 int vertex_buffer_count;
250 /* Vertex information. */
251 struct r300_vertex_format vertex_info;
252 /* Bitmask of dirty state objects. */
253 uint32_t dirty_state;
254 /* Flag indicating whether or not the HW is dirty. */
255 uint32_t dirty_hw;
256 };
257
258 /* Convenience cast wrapper. */
259 static struct r300_context* r300_context(struct pipe_context* context) {
260 return (struct r300_context*)context;
261 }
262
263 /* Context initialization. */
264 struct draw_stage* r300_draw_swtcl_stage(struct r300_context* r300);
265 void r300_init_state_functions(struct r300_context* r300);
266 void r300_init_surface_functions(struct r300_context* r300);
267
268 /* Fun with includes: r300_winsys also declares this prototype.
269 * We'll just step out in that case... */
270 #ifndef R300_WINSYS_H
271 struct pipe_context* r300_create_context(struct pipe_screen* screen,
272 struct r300_winsys* r300_winsys);
273 #endif
274
275 #endif /* R300_CONTEXT_H */