Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / drivers / nv40 / nv40_context.h
1 #ifndef __NV40_CONTEXT_H__
2 #define __NV40_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 nv40_screen *ctx = nv40->screen
15 #include "nouveau/nouveau_push.h"
16 #include "nouveau/nouveau_stateobj.h"
17
18 #include "nv40_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 nv40_state_index {
26 NV40_STATE_FB = 0,
27 NV40_STATE_VIEWPORT = 1,
28 NV40_STATE_BLEND = 2,
29 NV40_STATE_RAST = 3,
30 NV40_STATE_ZSA = 4,
31 NV40_STATE_BCOL = 5,
32 NV40_STATE_CLIP = 6,
33 NV40_STATE_SCISSOR = 7,
34 NV40_STATE_STIPPLE = 8,
35 NV40_STATE_FRAGPROG = 9,
36 NV40_STATE_VERTPROG = 10,
37 NV40_STATE_FRAGTEX0 = 11,
38 NV40_STATE_FRAGTEX1 = 12,
39 NV40_STATE_FRAGTEX2 = 13,
40 NV40_STATE_FRAGTEX3 = 14,
41 NV40_STATE_FRAGTEX4 = 15,
42 NV40_STATE_FRAGTEX5 = 16,
43 NV40_STATE_FRAGTEX6 = 17,
44 NV40_STATE_FRAGTEX7 = 18,
45 NV40_STATE_FRAGTEX8 = 19,
46 NV40_STATE_FRAGTEX9 = 20,
47 NV40_STATE_FRAGTEX10 = 21,
48 NV40_STATE_FRAGTEX11 = 22,
49 NV40_STATE_FRAGTEX12 = 23,
50 NV40_STATE_FRAGTEX13 = 24,
51 NV40_STATE_FRAGTEX14 = 25,
52 NV40_STATE_FRAGTEX15 = 26,
53 NV40_STATE_VERTTEX0 = 27,
54 NV40_STATE_VERTTEX1 = 28,
55 NV40_STATE_VERTTEX2 = 29,
56 NV40_STATE_VERTTEX3 = 30,
57 NV40_STATE_VTXBUF = 31,
58 NV40_STATE_VTXFMT = 32,
59 NV40_STATE_VTXATTR = 33,
60 NV40_STATE_MAX = 34
61 };
62
63 #include "nv40_screen.h"
64
65 #define NV40_NEW_BLEND (1 << 0)
66 #define NV40_NEW_RAST (1 << 1)
67 #define NV40_NEW_ZSA (1 << 2)
68 #define NV40_NEW_SAMPLER (1 << 3)
69 #define NV40_NEW_FB (1 << 4)
70 #define NV40_NEW_STIPPLE (1 << 5)
71 #define NV40_NEW_SCISSOR (1 << 6)
72 #define NV40_NEW_VIEWPORT (1 << 7)
73 #define NV40_NEW_BCOL (1 << 8)
74 #define NV40_NEW_VERTPROG (1 << 9)
75 #define NV40_NEW_FRAGPROG (1 << 10)
76 #define NV40_NEW_ARRAYS (1 << 11)
77 #define NV40_NEW_UCP (1 << 12)
78
79 struct nv40_rasterizer_state {
80 struct pipe_rasterizer_state pipe;
81 struct nouveau_stateobj *so;
82 };
83
84 struct nv40_zsa_state {
85 struct pipe_depth_stencil_alpha_state pipe;
86 struct nouveau_stateobj *so;
87 };
88
89 struct nv40_blend_state {
90 struct pipe_blend_state pipe;
91 struct nouveau_stateobj *so;
92 };
93
94
95 struct nv40_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[NV40_STATE_MAX];
103 };
104
105 struct nv40_context {
106 struct pipe_context pipe;
107
108 struct nouveau_winsys *nvws;
109 struct nv40_screen *screen;
110 unsigned pctx_id;
111
112 struct draw_context *draw;
113
114 /* HW state derived from pipe states */
115 struct nv40_state state;
116 struct {
117 struct nv40_vertex_program *vertprog;
118
119 unsigned nr_attribs;
120 unsigned hw[PIPE_MAX_SHADER_INPUTS];
121 unsigned draw[PIPE_MAX_SHADER_INPUTS];
122 unsigned emit[PIPE_MAX_SHADER_INPUTS];
123 } swtnl;
124
125 enum {
126 HW, SWTNL, SWRAST
127 } render_mode;
128 unsigned fallback_swtnl;
129 unsigned fallback_swrast;
130
131 /* Context state */
132 unsigned dirty, draw_dirty;
133 struct pipe_scissor_state scissor;
134 unsigned stipple[32];
135 struct pipe_clip_state clip;
136 struct nv40_vertex_program *vertprog;
137 struct nv40_fragment_program *fragprog;
138 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
139 struct nv40_rasterizer_state *rasterizer;
140 struct nv40_zsa_state *zsa;
141 struct nv40_blend_state *blend;
142 struct pipe_blend_color blend_colour;
143 struct pipe_viewport_state viewport;
144 struct pipe_framebuffer_state framebuffer;
145 struct pipe_buffer *idxbuf;
146 unsigned idxbuf_format;
147 struct nv40_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
148 struct nv40_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
149 unsigned nr_samplers;
150 unsigned nr_textures;
151 unsigned dirty_samplers;
152 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
153 unsigned vtxbuf_nr;
154 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
155 unsigned vtxelt_nr;
156 const unsigned *edgeflags;
157 };
158
159 static INLINE struct nv40_context *
160 nv40_context(struct pipe_context *pipe)
161 {
162 return (struct nv40_context *)pipe;
163 }
164
165 struct nv40_state_entry {
166 boolean (*validate)(struct nv40_context *nv40);
167 struct {
168 unsigned pipe;
169 unsigned hw;
170 } dirty;
171 };
172
173 extern void nv40_init_state_functions(struct nv40_context *nv40);
174 extern void nv40_init_surface_functions(struct nv40_context *nv40);
175 extern void nv40_init_miptree_functions(struct nv40_context *nv40);
176 extern void nv40_init_query_functions(struct nv40_context *nv40);
177
178 extern void nv40_screen_init_miptree_functions(struct pipe_screen *pscreen);
179
180 /* nv40_draw.c */
181 extern struct draw_stage *nv40_draw_render_stage(struct nv40_context *nv40);
182 extern boolean nv40_draw_elements_swtnl(struct pipe_context *pipe,
183 struct pipe_buffer *idxbuf,
184 unsigned ib_size, unsigned mode,
185 unsigned start, unsigned count);
186
187 /* nv40_vertprog.c */
188 extern void nv40_vertprog_destroy(struct nv40_context *,
189 struct nv40_vertex_program *);
190
191 /* nv40_fragprog.c */
192 extern void nv40_fragprog_destroy(struct nv40_context *,
193 struct nv40_fragment_program *);
194
195 /* nv40_fragtex.c */
196 extern void nv40_fragtex_bind(struct nv40_context *);
197
198 /* nv40_state.c and friends */
199 extern boolean nv40_state_validate(struct nv40_context *nv40);
200 extern boolean nv40_state_validate_swtnl(struct nv40_context *nv40);
201 extern void nv40_state_emit(struct nv40_context *nv40);
202 extern struct nv40_state_entry nv40_state_rasterizer;
203 extern struct nv40_state_entry nv40_state_scissor;
204 extern struct nv40_state_entry nv40_state_stipple;
205 extern struct nv40_state_entry nv40_state_fragprog;
206 extern struct nv40_state_entry nv40_state_vertprog;
207 extern struct nv40_state_entry nv40_state_blend;
208 extern struct nv40_state_entry nv40_state_blend_colour;
209 extern struct nv40_state_entry nv40_state_zsa;
210 extern struct nv40_state_entry nv40_state_viewport;
211 extern struct nv40_state_entry nv40_state_framebuffer;
212 extern struct nv40_state_entry nv40_state_fragtex;
213 extern struct nv40_state_entry nv40_state_vbo;
214 extern struct nv40_state_entry nv40_state_vtxfmt;
215
216 /* nv40_vbo.c */
217 extern boolean nv40_draw_arrays(struct pipe_context *, unsigned mode,
218 unsigned start, unsigned count);
219 extern boolean nv40_draw_elements(struct pipe_context *pipe,
220 struct pipe_buffer *indexBuffer,
221 unsigned indexSize,
222 unsigned mode, unsigned start,
223 unsigned count);
224
225 /* nv40_clear.c */
226 extern void nv40_clear(struct pipe_context *pipe, struct pipe_surface *ps,
227 unsigned clearValue);
228
229 #endif