nv30: add state scissor, based on nv40 one
[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 /* TODO: rename when removing the old state emitter */
80 struct nv30_rasterizer_state_new {
81 struct pipe_rasterizer_state pipe;
82 struct nouveau_stateobj *so;
83 };
84
85 /* TODO: rename when removing the old state emitter */
86 struct nv30_blend_state_new {
87 struct pipe_blend_state pipe;
88 struct nouveau_stateobj *so;
89 };
90
91
92 struct nv30_state {
93 unsigned scissor_enabled;
94
95 struct nouveau_stateobj *hw[NV30_STATE_MAX];
96 };
97
98 struct nv30_context {
99 struct pipe_context pipe;
100
101 struct nouveau_winsys *nvws;
102 struct nv30_screen *screen;
103 unsigned pctx_id;
104
105 struct draw_context *draw;
106
107 /* HW state derived from pipe states */
108 struct nv30_state state;
109 struct pipe_scissor_state scissor;
110
111 uint32_t dirty;
112
113 struct nv30_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
114 struct nv30_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
115 unsigned dirty_samplers;
116 unsigned fp_samplers;
117 unsigned vp_samplers;
118
119 /* Context state */
120 struct nv30_blend_state_new *blend;
121 struct pipe_blend_color blend_colour;
122 struct pipe_framebuffer_state framebuffer;
123 struct nv30_rasterizer_state_new *rasterizer;
124
125 uint32_t rt_enable;
126 struct pipe_buffer *rt[2];
127 struct pipe_buffer *zeta;
128
129 /*struct {
130 struct pipe_buffer *buffer;
131 uint32_t format;
132 } tex[16];*/
133
134 unsigned vb_enable;
135 struct {
136 struct pipe_buffer *buffer;
137 unsigned delta;
138 } vb[16];
139
140 struct {
141 struct nv30_vertex_program *active;
142
143 struct nv30_vertex_program *current;
144 struct pipe_buffer *constant_buf;
145 } vertprog;
146
147 struct {
148 struct nv30_fragment_program *active;
149
150 struct nv30_fragment_program *current;
151 struct pipe_buffer *constant_buf;
152 } fragprog;
153
154 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
155 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
156 };
157
158 static INLINE struct nv30_context *
159 nv30_context(struct pipe_context *pipe)
160 {
161 return (struct nv30_context *)pipe;
162 }
163
164 struct nv30_state_entry {
165 boolean (*validate)(struct nv30_context *nv30);
166 struct {
167 unsigned pipe;
168 unsigned hw;
169 } dirty;
170 };
171
172 extern void nv30_init_state_functions(struct nv30_context *nv30);
173 extern void nv30_init_surface_functions(struct nv30_context *nv30);
174 extern void nv30_init_query_functions(struct nv30_context *nv30);
175
176 extern void nv30_screen_init_miptree_functions(struct pipe_screen *pscreen);
177
178 /* nv30_draw.c */
179 extern struct draw_stage *nv30_draw_render_stage(struct nv30_context *nv30);
180
181 /* nv30_vertprog.c */
182 extern void nv30_vertprog_translate(struct nv30_context *,
183 struct nv30_vertex_program *);
184 extern void nv30_vertprog_bind(struct nv30_context *,
185 struct nv30_vertex_program *);
186 extern void nv30_vertprog_destroy(struct nv30_context *,
187 struct nv30_vertex_program *);
188
189 /* nv30_fragprog.c */
190 extern void nv30_fragprog_translate(struct nv30_context *,
191 struct nv30_fragment_program *);
192 extern void nv30_fragprog_bind(struct nv30_context *,
193 struct nv30_fragment_program *);
194 extern void nv30_fragprog_destroy(struct nv30_context *,
195 struct nv30_fragment_program *);
196
197 /* nv30_fragtex.c */
198 extern void nv30_fragtex_bind(struct nv30_context *);
199
200 /* nv30_state.c and friends */
201 extern void nv30_emit_hw_state(struct nv30_context *nv30);
202 extern void nv30_state_tex_update(struct nv30_context *nv30);
203
204 /* nv30_vbo.c */
205 extern boolean nv30_draw_arrays(struct pipe_context *, unsigned mode,
206 unsigned start, unsigned count);
207 extern boolean nv30_draw_elements(struct pipe_context *pipe,
208 struct pipe_buffer *indexBuffer,
209 unsigned indexSize,
210 unsigned mode, unsigned start,
211 unsigned count);
212
213 /* nv30_clear.c */
214 extern void nv30_clear(struct pipe_context *pipe, struct pipe_surface *ps,
215 unsigned clearValue);
216
217 #endif