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