nv40: fb state
[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_channel_context *ctx = nv40->hw
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_MAX = 31
58 };
59
60 #define NV40_NEW_BLEND (1 << 0)
61 #define NV40_NEW_RAST (1 << 1)
62 #define NV40_NEW_ZSA (1 << 2)
63 #define NV40_NEW_SAMPLER (1 << 3)
64 #define NV40_NEW_FB (1 << 4)
65 #define NV40_NEW_STIPPLE (1 << 5)
66 #define NV40_NEW_SCISSOR (1 << 6)
67 #define NV40_NEW_VIEWPORT (1 << 7)
68 #define NV40_NEW_BCOL (1 << 8)
69 #define NV40_NEW_VERTPROG (1 << 9)
70 #define NV40_NEW_FRAGPROG (1 << 10)
71 #define NV40_NEW_ARRAYS (1 << 11)
72 #define NV40_NEW_UCP (1 << 12)
73
74 #define NV40_FALLBACK_TNL (1 << 0)
75 #define NV40_FALLBACK_RAST (1 << 1)
76
77 struct nv40_channel_context {
78 struct nouveau_winsys *nvws;
79 unsigned refcount;
80
81 unsigned chipset;
82
83 /* HW graphics objects */
84 struct nouveau_grobj *curie;
85 struct nouveau_notifier *sync;
86
87 /* Query object resources */
88 struct nouveau_notifier *query;
89 struct nouveau_resource *query_heap;
90
91 /* Vtxprog resources */
92 struct nouveau_resource *vp_exec_heap;
93 struct nouveau_resource *vp_data_heap;
94
95 /* Current 3D state of channel */
96 struct nouveau_stateobj *state[NV40_STATE_MAX];
97 };
98
99 struct nv40_rasterizer_state {
100 struct pipe_rasterizer_state pipe;
101 struct nouveau_stateobj *so;
102 };
103
104 struct nv40_zsa_state {
105 struct pipe_depth_stencil_alpha_state pipe;
106 struct nouveau_stateobj *so;
107 };
108
109 struct nv40_blend_state {
110 struct pipe_blend_state pipe;
111 struct nouveau_stateobj *so;
112 };
113
114
115 struct nv40_state {
116 unsigned scissor_enabled;
117 unsigned stipple_enabled;
118
119 struct nouveau_stateobj *hw[NV40_STATE_MAX];
120 };
121
122 struct nv40_context {
123 struct pipe_context pipe;
124 struct nouveau_winsys *nvws;
125
126 struct nv40_channel_context *hw;
127 struct draw_context *draw;
128
129 int chipset;
130
131 unsigned dirty;
132 unsigned hw_dirty;
133
134 struct nv40_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
135 struct nv40_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
136 unsigned dirty_samplers;
137 unsigned fp_samplers;
138 unsigned vp_samplers;
139
140 struct {
141 struct pipe_scissor_state scissor;
142 unsigned stipple[32];
143 struct pipe_clip_state clip;
144 struct nv40_vertex_program *vertprog;
145 struct nv40_fragment_program *fragprog;
146 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
147 struct nv40_rasterizer_state *rasterizer;
148 struct nv40_zsa_state *zsa;
149 struct nv40_blend_state *blend;
150 struct pipe_blend_color blend_colour;
151 struct pipe_viewport_state viewport;
152 struct pipe_framebuffer_state framebuffer;
153 } pipe_state;
154
155 struct nv40_state state;
156 unsigned fallback;
157
158 struct nouveau_stateobj *so_fragtex[16];
159 struct nouveau_stateobj *so_vtxbuf;
160
161 struct pipe_vertex_buffer vtxbuf[PIPE_ATTRIB_MAX];
162 struct pipe_vertex_element vtxelt[PIPE_ATTRIB_MAX];
163 };
164
165 static INLINE struct nv40_context *
166 nv40_context(struct pipe_context *pipe)
167 {
168 return (struct nv40_context *)pipe;
169 }
170
171 struct nv40_state_entry {
172 boolean (*validate)(struct nv40_context *nv40);
173 struct {
174 unsigned pipe;
175 unsigned hw;
176 } dirty;
177 };
178
179 extern void nv40_init_state_functions(struct nv40_context *nv40);
180 extern void nv40_init_surface_functions(struct nv40_context *nv40);
181 extern void nv40_init_miptree_functions(struct nv40_context *nv40);
182 extern void nv40_init_query_functions(struct nv40_context *nv40);
183
184 /* nv40_draw.c */
185 extern struct draw_stage *nv40_draw_render_stage(struct nv40_context *nv40);
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 void nv40_emit_hw_state(struct nv40_context *nv40);
200 extern void nv40_state_tex_update(struct nv40_context *nv40);
201 extern struct nv40_state_entry nv40_state_clip;
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
213 /* nv40_vbo.c */
214 extern boolean nv40_draw_arrays(struct pipe_context *, unsigned mode,
215 unsigned start, unsigned count);
216 extern boolean nv40_draw_elements(struct pipe_context *pipe,
217 struct pipe_buffer *indexBuffer,
218 unsigned indexSize,
219 unsigned mode, unsigned start,
220 unsigned count);
221
222 /* nv40_clear.c */
223 extern void nv40_clear(struct pipe_context *pipe, struct pipe_surface *ps,
224 unsigned clearValue);
225
226 #endif