2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
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:
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
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. */
23 #ifndef R300_CONTEXT_H
24 #define R300_CONTEXT_H
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"
32 #include "r300_clear.h"
33 #include "r300_screen.h"
34 #include "r300_winsys.h"
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 */
43 struct r300_blend_color_state
{
44 /* RV515 and earlier */
45 uint32_t blend_color
; /* R300_RB3D_BLEND_COLOR: 0x4e10 */
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 */
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 */
61 struct r300_rs_state
{
62 /* XXX icky as fucking hell */
63 struct pipe_rasterizer_state rs
;
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 */
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] */
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 */
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 */
97 struct r300_texture_state
{
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
115 /* The next several objects are not pure Radeon state; they inherit from
116 * various Gallium classes. */
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 */
124 /* Total number of constants */
128 struct r3xx_fragment_shader
{
130 struct pipe_shader_state state
;
131 struct tgsi_shader_info info
;
133 /* Has this shader been translated yet? */
136 /* Pixel stack size */
140 struct r300_fragment_shader
{
142 struct r3xx_fragment_shader shader
;
144 /* Number of ALU instructions */
145 int alu_instruction_count
;
147 /* Number of texture instructions */
148 int tex_instruction_count
;
150 /* Number of texture indirections */
153 /* Indirection node offsets */
159 /* Machine instructions */
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 */
168 struct r500_fragment_shader
{
170 struct r3xx_fragment_shader shader
;
172 /* Number of used instructions */
173 int instruction_count
;
175 /* Machine instructions */
183 } instructions
[256]; /*< XXX magic number */
186 struct r300_texture
{
188 struct pipe_texture tex
;
190 /* Offsets into the buffer. */
191 unsigned offset
[PIPE_MAX_TEXTURE_LEVELS
];
193 /* Stride (pitch?) of this texture in bytes */
196 /* Total size of this texture, in bytes. */
199 /* Pipe buffer backing this texture. */
200 struct pipe_buffer
* buffer
;
203 struct r300_vertex_format
{
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];
212 struct r300_context
{
214 struct pipe_context context
;
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
;
221 /* Various CSO state objects. */
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];
242 struct r300_scissor_state
* scissor_state
;
243 /* Texture states. */
244 struct r300_texture
* textures
[8];
245 struct r300_texture_state
* texture_states
[8];
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. */
258 /* Convenience cast wrapper. */
259 static struct r300_context
* r300_context(struct pipe_context
* context
) {
260 return (struct r300_context
*)context
;
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
);
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
);
275 #endif /* R300_CONTEXT_H */