Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / drivers / nv30 / nv30_context.h
1 #ifndef __NV30_CONTEXT_H__
2 #define __NV30_CONTEXT_H__
3
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7
8 #include "draw/draw_vertex.h"
9
10 #include "nouveau/nouveau_winsys.h"
11 #include "nouveau/nouveau_gldefs.h"
12
13 #define NOUVEAU_PUSH_CONTEXT(ctx) \
14 struct nv30_screen *ctx = nv30->screen
15 #include "nouveau/nouveau_push.h"
16 #include "nouveau/nouveau_stateobj.h"
17
18 #include "nv30_state.h"
19
20 #define NOUVEAU_ERR(fmt, args...) \
21 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
22 #define NOUVEAU_MSG(fmt, args...) \
23 fprintf(stderr, "nouveau: "fmt, ##args);
24
25 enum nv30_state_index {
26 NV30_STATE_FB = 0,
27 NV30_STATE_VIEWPORT = 1,
28 NV30_STATE_BLEND = 2,
29 NV30_STATE_RAST = 3,
30 NV30_STATE_ZSA = 4,
31 NV30_STATE_BCOL = 5,
32 NV30_STATE_CLIP = 6,
33 NV30_STATE_SCISSOR = 7,
34 NV30_STATE_STIPPLE = 8,
35 NV30_STATE_FRAGPROG = 9,
36 NV30_STATE_VERTPROG = 10,
37 NV30_STATE_FRAGTEX0 = 11,
38 NV30_STATE_FRAGTEX1 = 12,
39 NV30_STATE_FRAGTEX2 = 13,
40 NV30_STATE_FRAGTEX3 = 14,
41 NV30_STATE_FRAGTEX4 = 15,
42 NV30_STATE_FRAGTEX5 = 16,
43 NV30_STATE_FRAGTEX6 = 17,
44 NV30_STATE_FRAGTEX7 = 18,
45 NV30_STATE_FRAGTEX8 = 19,
46 NV30_STATE_FRAGTEX9 = 20,
47 NV30_STATE_FRAGTEX10 = 21,
48 NV30_STATE_FRAGTEX11 = 22,
49 NV30_STATE_FRAGTEX12 = 23,
50 NV30_STATE_FRAGTEX13 = 24,
51 NV30_STATE_FRAGTEX14 = 25,
52 NV30_STATE_FRAGTEX15 = 26,
53 NV30_STATE_VERTTEX0 = 27,
54 NV30_STATE_VERTTEX1 = 28,
55 NV30_STATE_VERTTEX2 = 29,
56 NV30_STATE_VERTTEX3 = 30,
57 NV30_STATE_VTXBUF = 31,
58 NV30_STATE_VTXFMT = 32,
59 NV30_STATE_VTXATTR = 33,
60 NV30_STATE_MAX = 34
61 };
62
63 #include "nv30_screen.h"
64
65 #define NV30_NEW_BLEND (1 << 0)
66 #define NV30_NEW_RAST (1 << 1)
67 #define NV30_NEW_ZSA (1 << 2)
68 #define NV30_NEW_SAMPLER (1 << 3)
69 #define NV30_NEW_FB (1 << 4)
70 #define NV30_NEW_STIPPLE (1 << 5)
71 #define NV30_NEW_SCISSOR (1 << 6)
72 #define NV30_NEW_VIEWPORT (1 << 7)
73 #define NV30_NEW_BCOL (1 << 8)
74 #define NV30_NEW_VERTPROG (1 << 9)
75 #define NV30_NEW_FRAGPROG (1 << 10)
76 #define NV30_NEW_ARRAYS (1 << 11)
77 #define NV30_NEW_UCP (1 << 12)
78
79 struct nv30_rasterizer_state {
80 struct pipe_rasterizer_state pipe;
81 struct nouveau_stateobj *so;
82 };
83
84 struct nv30_zsa_state {
85 struct pipe_depth_stencil_alpha_state pipe;
86 struct nouveau_stateobj *so;
87 };
88
89 struct nv30_blend_state {
90 struct pipe_blend_state pipe;
91 struct nouveau_stateobj *so;
92 };
93
94
95 struct nv30_state {
96 unsigned scissor_enabled;
97 unsigned stipple_enabled;
98 unsigned viewport_bypass;
99 unsigned fp_samplers;
100
101 uint64_t dirty;
102 struct nouveau_stateobj *hw[NV30_STATE_MAX];
103 };
104
105 struct nv30_context {
106 struct pipe_context pipe;
107
108 struct nouveau_winsys *nvws;
109 struct nv30_screen *screen;
110 unsigned pctx_id;
111
112 struct draw_context *draw;
113
114 /* HW state derived from pipe states */
115 struct nv30_state state;
116
117 /* Context state */
118 unsigned dirty;
119 struct pipe_scissor_state scissor;
120 unsigned stipple[32];
121 struct nv30_vertex_program *vertprog;
122 struct nv30_fragment_program *fragprog;
123 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
124 unsigned constbuf_nr[PIPE_SHADER_TYPES];
125 struct nv30_rasterizer_state *rasterizer;
126 struct nv30_zsa_state *zsa;
127 struct nv30_blend_state *blend;
128 struct pipe_blend_color blend_colour;
129 struct pipe_viewport_state viewport;
130 struct pipe_framebuffer_state framebuffer;
131 struct pipe_buffer *idxbuf;
132 unsigned idxbuf_format;
133 struct nv30_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
134 struct nv30_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
135 unsigned nr_samplers;
136 unsigned nr_textures;
137 unsigned dirty_samplers;
138 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
139 unsigned vtxbuf_nr;
140 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
141 unsigned vtxelt_nr;
142 const unsigned *edgeflags;
143 };
144
145 static INLINE struct nv30_context *
146 nv30_context(struct pipe_context *pipe)
147 {
148 return (struct nv30_context *)pipe;
149 }
150
151 struct nv30_state_entry {
152 boolean (*validate)(struct nv30_context *nv30);
153 struct {
154 unsigned pipe;
155 unsigned hw;
156 } dirty;
157 };
158
159 extern void nv30_init_state_functions(struct nv30_context *nv30);
160 extern void nv30_init_surface_functions(struct nv30_context *nv30);
161 extern void nv30_init_query_functions(struct nv30_context *nv30);
162
163 extern void nv30_screen_init_miptree_functions(struct pipe_screen *pscreen);
164
165 /* nv30_draw.c */
166 extern struct draw_stage *nv30_draw_render_stage(struct nv30_context *nv30);
167
168 /* nv30_vertprog.c */
169 extern void nv30_vertprog_destroy(struct nv30_context *,
170 struct nv30_vertex_program *);
171
172 /* nv30_fragprog.c */
173 extern void nv30_fragprog_destroy(struct nv30_context *,
174 struct nv30_fragment_program *);
175
176 /* nv30_fragtex.c */
177 extern void nv30_fragtex_bind(struct nv30_context *);
178
179 /* nv30_state.c and friends */
180 extern boolean nv30_state_validate(struct nv30_context *nv30);
181 extern void nv30_state_emit(struct nv30_context *nv30);
182 extern struct nv30_state_entry nv30_state_rasterizer;
183 extern struct nv30_state_entry nv30_state_scissor;
184 extern struct nv30_state_entry nv30_state_stipple;
185 extern struct nv30_state_entry nv30_state_fragprog;
186 extern struct nv30_state_entry nv30_state_vertprog;
187 extern struct nv30_state_entry nv30_state_blend;
188 extern struct nv30_state_entry nv30_state_blend_colour;
189 extern struct nv30_state_entry nv30_state_zsa;
190 extern struct nv30_state_entry nv30_state_viewport;
191 extern struct nv30_state_entry nv30_state_framebuffer;
192 extern struct nv30_state_entry nv30_state_fragtex;
193 extern struct nv30_state_entry nv30_state_vbo;
194
195 /* nv30_vbo.c */
196 extern boolean nv30_draw_arrays(struct pipe_context *, unsigned mode,
197 unsigned start, unsigned count);
198 extern boolean nv30_draw_elements(struct pipe_context *pipe,
199 struct pipe_buffer *indexBuffer,
200 unsigned indexSize,
201 unsigned mode, unsigned start,
202 unsigned count);
203
204 /* nv30_clear.c */
205 extern void nv30_clear(struct pipe_context *pipe, struct pipe_surface *ps,
206 unsigned clearValue);
207
208 #endif