docs: Update status of GL 3.x related extensions
[mesa.git] / src / gallium / drivers / nvfx / nvfx_context.h
1 #ifndef __NVFX_CONTEXT_H__
2 #define __NVFX_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 #include "util/u_double_list.h"
15
16 #include "draw/draw_vertex.h"
17 #include "util/u_blitter.h"
18
19 #include "nouveau/nouveau_winsys.h"
20 #include "nouveau/nouveau_gldefs.h"
21 #include "nv30-40_3d.xml.h"
22 #include "nvfx_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 #include "nvfx_screen.h"
30
31 #define NVFX_NEW_BLEND (1 << 0)
32 #define NVFX_NEW_RAST (1 << 1)
33 #define NVFX_NEW_ZSA (1 << 2)
34 #define NVFX_NEW_SAMPLER (1 << 3)
35 #define NVFX_NEW_FB (1 << 4)
36 #define NVFX_NEW_STIPPLE (1 << 5)
37 #define NVFX_NEW_SCISSOR (1 << 6)
38 #define NVFX_NEW_VIEWPORT (1 << 7)
39 #define NVFX_NEW_BCOL (1 << 8)
40 #define NVFX_NEW_VERTPROG (1 << 9)
41 #define NVFX_NEW_FRAGPROG (1 << 10)
42 #define NVFX_NEW_ARRAYS (1 << 11)
43 #define NVFX_NEW_UCP (1 << 12)
44 #define NVFX_NEW_SR (1 << 13)
45 #define NVFX_NEW_VERTCONST (1 << 14)
46 #define NVFX_NEW_FRAGCONST (1 << 15)
47 #define NVFX_NEW_INDEX (1 << 16)
48 #define NVFX_NEW_SPRITE (1 << 17)
49
50 #define NVFX_RELOCATE_FRAMEBUFFER (1 << 0)
51 #define NVFX_RELOCATE_FRAGTEX (1 << 1)
52 #define NVFX_RELOCATE_FRAGPROG (1 << 2)
53 #define NVFX_RELOCATE_VTXBUF (1 << 3)
54 #define NVFX_RELOCATE_IDXBUF (1 << 4)
55 #define NVFX_RELOCATE_ALL 0x1f
56
57 struct nvfx_rasterizer_state {
58 struct pipe_rasterizer_state pipe;
59 unsigned sb_len;
60 uint32_t sb[34];
61 };
62
63 struct nvfx_zsa_state {
64 struct pipe_depth_stencil_alpha_state pipe;
65 unsigned sb_len;
66 uint32_t sb[24];
67 };
68
69 struct nvfx_blend_state {
70 struct pipe_blend_state pipe;
71 unsigned sb_len;
72 uint32_t sb[13];
73 };
74
75
76 struct nvfx_state {
77 unsigned scissor_enabled;
78 unsigned fp_samplers;
79 unsigned render_temps;
80 };
81
82 struct nvfx_per_vertex_element {
83 unsigned idx;
84 unsigned vertex_buffer_index;
85 unsigned src_offset;
86 };
87
88 struct nvfx_low_frequency_element {
89 unsigned idx;
90 unsigned vertex_buffer_index;
91 unsigned src_offset;
92 void (*fetch_rgba_float)(float *dst, const uint8_t *src, unsigned i, unsigned j);
93 unsigned ncomp;
94 };
95
96 struct nvfx_per_instance_element {
97 struct nvfx_low_frequency_element base;
98 unsigned instance_divisor;
99 };
100
101 struct nvfx_per_vertex_buffer_info
102 {
103 unsigned vertex_buffer_index;
104 unsigned per_vertex_size;
105 };
106
107 struct nvfx_vtxelt_state {
108 struct pipe_vertex_element pipe[16];
109 unsigned num_elements;
110 unsigned vtxfmt[16];
111
112 unsigned num_per_vertex_buffer_infos;
113 struct nvfx_per_vertex_buffer_info per_vertex_buffer_info[16];
114
115 unsigned num_per_vertex;
116 struct nvfx_per_vertex_element per_vertex[16];
117
118 unsigned num_per_instance;
119 struct nvfx_per_instance_element per_instance[16];
120
121 unsigned num_constant;
122 struct nvfx_low_frequency_element constant[16];
123
124 boolean needs_translate;
125 struct translate* translate;
126
127 unsigned vertex_length;
128 unsigned max_vertices_per_packet;
129 };
130
131 struct nvfx_render_target {
132 struct nouveau_bo* bo;
133 unsigned offset;
134 unsigned pitch;
135 };
136
137 struct nvfx_context {
138 struct pipe_context pipe;
139
140 struct nouveau_winsys *nvws;
141 struct nvfx_screen *screen;
142
143 unsigned is_nv4x; /* either 0 or ~0 */
144 unsigned use_nv4x; /* either 0 or ~0 */
145 boolean use_vp_clipping;
146
147 struct draw_context *draw;
148 /* one is for user-requested operations, the other is for temporary copying inside them */
149 struct blitter_context* blitter[2];
150 unsigned blitters_in_use;
151 struct list_head render_cache;
152
153 /* HW state derived from pipe states */
154 struct nvfx_state state;
155
156 enum {
157 HW, SWTNL, SWRAST
158 } render_mode;
159 unsigned fallback_swtnl;
160
161 /* Context state */
162 unsigned dirty, draw_dirty;
163 struct pipe_scissor_state scissor;
164 unsigned stipple[32];
165 struct pipe_clip_state clip;
166 struct nvfx_pipe_vertex_program *vertprog;
167 struct nvfx_pipe_fragment_program *fragprog;
168 struct pipe_resource *constbuf[PIPE_SHADER_TYPES];
169 unsigned constbuf_nr[PIPE_SHADER_TYPES];
170 struct nvfx_rasterizer_state *rasterizer;
171 struct nvfx_zsa_state *zsa;
172 struct nvfx_blend_state *blend;
173 struct pipe_blend_color blend_colour;
174 struct pipe_stencil_ref stencil_ref;
175 struct pipe_viewport_state viewport;
176 struct pipe_framebuffer_state framebuffer;
177 struct pipe_index_buffer idxbuf;
178 struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
179 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
180 struct nvfx_pipe_fragment_program* dummy_fs;
181 struct pipe_query* query;
182
183 unsigned nr_samplers;
184 unsigned nr_textures;
185 unsigned dirty_samplers;
186 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
187 unsigned vtxbuf_nr;
188 struct nvfx_vtxelt_state *vtxelt;
189 int base_vertex;
190 boolean use_index_buffer;
191 /* -1 = hardware input setup is outdated
192 * 0 = hardware input setup is for inline vertices
193 * 1 = hardware input setup is for hardware vertices
194 */
195 int use_vertex_buffers;
196
197 unsigned hw_vtxelt_nr;
198 unsigned hw_samplers;
199 uint32_t hw_txf[16];
200 struct nvfx_render_target hw_rt[4];
201 struct nvfx_render_target hw_zeta;
202 int hw_pointsprite_control;
203 int hw_vp_output;
204 struct nvfx_fragment_program* hw_fragprog;
205 struct nvfx_vertex_program* hw_vertprog;
206
207 unsigned relocs_needed;
208 };
209
210 static INLINE struct nvfx_context *
211 nvfx_context(struct pipe_context *pipe)
212 {
213 return (struct nvfx_context *)pipe;
214 }
215
216 extern struct nvfx_state_entry nvfx_state_blend;
217 extern struct nvfx_state_entry nvfx_state_blend_colour;
218 extern struct nvfx_state_entry nvfx_state_fragprog;
219 extern struct nvfx_state_entry nvfx_state_fragtex;
220 extern struct nvfx_state_entry nvfx_state_framebuffer;
221 extern struct nvfx_state_entry nvfx_state_rasterizer;
222 extern struct nvfx_state_entry nvfx_state_scissor;
223 extern struct nvfx_state_entry nvfx_state_sr;
224 extern struct nvfx_state_entry nvfx_state_stipple;
225 extern struct nvfx_state_entry nvfx_state_vbo;
226 extern struct nvfx_state_entry nvfx_state_vertprog;
227 extern struct nvfx_state_entry nvfx_state_viewport;
228 extern struct nvfx_state_entry nvfx_state_vtxfmt;
229 extern struct nvfx_state_entry nvfx_state_zsa;
230
231 extern void nvfx_init_query_functions(struct nvfx_context *nvfx);
232 extern void nvfx_init_surface_functions(struct nvfx_context *nvfx);
233
234 /* nvfx_context.c */
235 struct pipe_context *
236 nvfx_create(struct pipe_screen *pscreen, void *priv);
237
238 /* nvfx_clear.c */
239 extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers,
240 const float *rgba, double depth, unsigned stencil);
241
242 /* nvfx_draw.c */
243 extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
244 extern void nvfx_draw_vbo_swtnl(struct pipe_context *pipe, const struct pipe_draw_info* info);
245 extern void nvfx_vtxfmt_validate(struct nvfx_context *nvfx);
246
247 /* nvfx_fb.c */
248 extern int nvfx_framebuffer_prepare(struct nvfx_context *nvfx);
249 extern void nvfx_framebuffer_validate(struct nvfx_context *nvfx, unsigned prepare_result);
250 void
251 nvfx_framebuffer_relocate(struct nvfx_context *nvfx);
252
253 /* nvfx_fragprog.c */
254 extern void nvfx_fragprog_destroy(struct nvfx_context *,
255 struct nvfx_fragment_program *);
256 extern void nvfx_fragprog_validate(struct nvfx_context *nvfx);
257 extern void nvfx_fragprog_relocate(struct nvfx_context *nvfx);
258 extern void nvfx_init_fragprog_functions(struct nvfx_context *nvfx);
259
260 /* nvfx_fragtex.c */
261 extern void nvfx_init_sampling_functions(struct nvfx_context *nvfx);
262 extern void nvfx_fragtex_validate(struct nvfx_context *nvfx);
263 extern void nvfx_fragtex_relocate(struct nvfx_context *nvfx);
264
265 struct nvfx_sampler_view;
266
267 /* nv30_fragtex.c */
268 extern void
269 nv30_sampler_state_init(struct pipe_context *pipe,
270 struct nvfx_sampler_state *ps,
271 const struct pipe_sampler_state *cso);
272 extern void
273 nv30_sampler_view_init(struct pipe_context *pipe,
274 struct nvfx_sampler_view *sv);
275 extern void nv30_fragtex_set(struct nvfx_context *nvfx, int unit);
276
277 /* nv40_fragtex.c */
278 extern void
279 nv40_sampler_state_init(struct pipe_context *pipe,
280 struct nvfx_sampler_state *ps,
281 const struct pipe_sampler_state *cso);
282 extern void
283 nv40_sampler_view_init(struct pipe_context *pipe,
284 struct nvfx_sampler_view *sv);
285 extern void nv40_fragtex_set(struct nvfx_context *nvfx, int unit);
286
287 /* nvfx_state.c */
288 extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
289 extern void nvfx_state_scissor_validate(struct nvfx_context *nvfx);
290 extern void nvfx_state_stipple_validate(struct nvfx_context *nvfx);
291 extern void nvfx_state_blend_validate(struct nvfx_context *nvfx);
292 extern void nvfx_state_blend_colour_validate(struct nvfx_context *nvfx);
293 extern void nvfx_state_viewport_validate(struct nvfx_context *nvfx);
294 extern void nvfx_state_rasterizer_validate(struct nvfx_context *nvfx);
295 extern void nvfx_state_sr_validate(struct nvfx_context *nvfx);
296 extern void nvfx_state_zsa_validate(struct nvfx_context *nvfx);
297
298 /* nvfx_state_emit.c */
299 extern void nvfx_state_relocate(struct nvfx_context *nvfx, unsigned relocs);
300 extern boolean nvfx_state_validate(struct nvfx_context *nvfx);
301 extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx);
302
303 static inline void
304 nvfx_state_emit(struct nvfx_context *nvfx)
305 {
306 unsigned relocs = NVFX_RELOCATE_FRAMEBUFFER | NVFX_RELOCATE_FRAGTEX | NVFX_RELOCATE_FRAGPROG;
307 if (nvfx->render_mode == HW)
308 {
309 relocs |= NVFX_RELOCATE_VTXBUF;
310 if(nvfx->use_index_buffer)
311 relocs |= NVFX_RELOCATE_IDXBUF;
312 }
313
314 relocs &= nvfx->relocs_needed;
315 if(relocs)
316 nvfx_state_relocate(nvfx, relocs);
317 }
318
319 /* nvfx_transfer.c */
320 extern void nvfx_init_transfer_functions(struct pipe_context *pipe);
321
322 /* nvfx_vbo.c */
323 extern boolean nvfx_vbo_validate(struct nvfx_context *nvfx);
324 extern void nvfx_vbo_swtnl_validate(struct nvfx_context *nvfx);
325 extern void nvfx_vbo_relocate(struct nvfx_context *nvfx);
326 extern void nvfx_idxbuf_validate(struct nvfx_context* nvfx);
327 extern void nvfx_idxbuf_relocate(struct nvfx_context* nvfx);
328 extern void nvfx_draw_vbo(struct pipe_context *pipe,
329 const struct pipe_draw_info *info);
330 extern void nvfx_init_vbo_functions(struct nvfx_context *nvfx);
331 extern unsigned nvfx_vertex_formats[];
332
333 /* nvfx_vertprog.c */
334 extern boolean nvfx_vertprog_validate(struct nvfx_context *nvfx);
335 extern void nvfx_vertprog_destroy(struct nvfx_context *,
336 struct nvfx_vertex_program *);
337 extern void nvfx_init_vertprog_functions(struct nvfx_context *nvfx);
338
339 /* nvfx_push.c */
340 extern void nvfx_push_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info);
341
342 /* must WAIT_RING(chan, ncomp + 1) or equivalent beforehand! */
343 static inline void nvfx_emit_vtx_attr(struct nouveau_channel* chan, unsigned attrib, const float* v, unsigned ncomp)
344 {
345 switch (ncomp) {
346 case 4:
347 OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_4F_X(attrib), 4));
348 OUT_RING(chan, fui(v[0]));
349 OUT_RING(chan, fui(v[1]));
350 OUT_RING(chan, fui(v[2]));
351 OUT_RING(chan, fui(v[3]));
352 break;
353 case 3:
354 OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_3F_X(attrib), 3));
355 OUT_RING(chan, fui(v[0]));
356 OUT_RING(chan, fui(v[1]));
357 OUT_RING(chan, fui(v[2]));
358 break;
359 case 2:
360 OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_2F_X(attrib), 2));
361 OUT_RING(chan, fui(v[0]));
362 OUT_RING(chan, fui(v[1]));
363 break;
364 case 1:
365 OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_1F(attrib), 1));
366 OUT_RING(chan, fui(v[0]));
367 break;
368 }
369 }
370
371 #endif