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