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