1 #ifndef __NVFX_CONTEXT_H__
2 #define __NVFX_CONTEXT_H__
6 #include "pipe/p_context.h"
7 #include "pipe/p_defines.h"
8 #include "pipe/p_state.h"
9 #include "pipe/p_compiler.h"
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"
16 #include "draw/draw_vertex.h"
17 #include "util/u_blitter.h"
19 #include "nouveau/nouveau_winsys.h"
20 #include "nouveau/nouveau_gldefs.h"
22 #include "nvfx_state.h"
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);
29 #include "nvfx_screen.h"
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)
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
57 struct nvfx_rasterizer_state
{
58 struct pipe_rasterizer_state pipe
;
63 struct nvfx_zsa_state
{
64 struct pipe_depth_stencil_alpha_state pipe
;
69 struct nvfx_blend_state
{
70 struct pipe_blend_state pipe
;
77 unsigned scissor_enabled
;
79 unsigned render_temps
;
82 struct nvfx_per_vertex_element
{
84 unsigned vertex_buffer_index
;
88 struct nvfx_low_frequency_element
{
90 unsigned vertex_buffer_index
;
92 void (*fetch_rgba_float
)(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
);
96 struct nvfx_per_instance_element
{
97 struct nvfx_low_frequency_element base
;
98 unsigned instance_divisor
;
101 struct nvfx_per_vertex_buffer_info
103 unsigned vertex_buffer_index
;
104 unsigned per_vertex_size
;
107 struct nvfx_vtxelt_state
{
108 struct pipe_vertex_element pipe
[16];
109 unsigned num_elements
;
112 unsigned num_per_vertex_buffer_infos
;
113 struct nvfx_per_vertex_buffer_info per_vertex_buffer_info
[16];
115 unsigned num_per_vertex
;
116 struct nvfx_per_vertex_element per_vertex
[16];
118 unsigned num_per_instance
;
119 struct nvfx_per_instance_element per_instance
[16];
121 unsigned num_constant
;
122 struct nvfx_low_frequency_element constant
[16];
124 boolean needs_translate
;
125 struct translate
* translate
;
127 unsigned vertex_length
;
128 unsigned max_vertices_per_packet
;
131 struct nvfx_render_target
{
132 struct nouveau_bo
* bo
;
137 struct nvfx_context
{
138 struct pipe_context pipe
;
140 struct nouveau_winsys
*nvws
;
141 struct nvfx_screen
*screen
;
143 unsigned is_nv4x
; /* either 0 or ~0 */
144 boolean use_vp_clipping
;
146 struct draw_context
*draw
;
147 struct blitter_context
* blitter
;
148 struct list_head render_cache
;
150 /* HW state derived from pipe states */
151 struct nvfx_state state
;
153 struct nvfx_vertex_program
*vertprog
;
156 unsigned hw
[PIPE_MAX_SHADER_INPUTS
];
157 unsigned draw
[PIPE_MAX_SHADER_INPUTS
];
158 unsigned emit
[PIPE_MAX_SHADER_INPUTS
];
164 unsigned fallback_swtnl
;
167 unsigned dirty
, draw_dirty
;
168 struct pipe_scissor_state scissor
;
169 unsigned stipple
[32];
170 struct pipe_clip_state clip
;
171 struct nvfx_vertex_program
*vertprog
;
172 struct nvfx_pipe_fragment_program
*fragprog
;
173 struct pipe_resource
*constbuf
[PIPE_SHADER_TYPES
];
174 unsigned constbuf_nr
[PIPE_SHADER_TYPES
];
175 struct nvfx_rasterizer_state
*rasterizer
;
176 struct nvfx_zsa_state
*zsa
;
177 struct nvfx_blend_state
*blend
;
178 struct pipe_blend_color blend_colour
;
179 struct pipe_stencil_ref stencil_ref
;
180 struct pipe_viewport_state viewport
;
181 struct pipe_framebuffer_state framebuffer
;
182 struct pipe_index_buffer idxbuf
;
183 struct nvfx_sampler_state
*tex_sampler
[PIPE_MAX_SAMPLERS
];
184 struct pipe_sampler_view
*fragment_sampler_views
[PIPE_MAX_SAMPLERS
];
185 struct nvfx_pipe_fragment_program
* dummy_fs
;
187 unsigned nr_samplers
;
188 unsigned nr_textures
;
189 unsigned dirty_samplers
;
190 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
192 struct nvfx_vtxelt_state
*vtxelt
;
194 boolean use_index_buffer
;
195 /* -1 = hardware input setup is outdated
196 * 0 = hardware input setup is for inline vertices
197 * 1 = hardware input setup is for hardware vertices
199 int use_vertex_buffers
;
201 unsigned hw_vtxelt_nr
;
204 struct nvfx_render_target hw_rt
[4];
205 struct nvfx_render_target hw_zeta
;
206 int hw_pointsprite_control
;
208 struct nvfx_fragment_program
* hw_fragprog
;
210 unsigned relocs_needed
;
213 static INLINE
struct nvfx_context
*
214 nvfx_context(struct pipe_context
*pipe
)
216 return (struct nvfx_context
*)pipe
;
219 extern struct nvfx_state_entry nvfx_state_blend
;
220 extern struct nvfx_state_entry nvfx_state_blend_colour
;
221 extern struct nvfx_state_entry nvfx_state_fragprog
;
222 extern struct nvfx_state_entry nvfx_state_fragtex
;
223 extern struct nvfx_state_entry nvfx_state_framebuffer
;
224 extern struct nvfx_state_entry nvfx_state_rasterizer
;
225 extern struct nvfx_state_entry nvfx_state_scissor
;
226 extern struct nvfx_state_entry nvfx_state_sr
;
227 extern struct nvfx_state_entry nvfx_state_stipple
;
228 extern struct nvfx_state_entry nvfx_state_vbo
;
229 extern struct nvfx_state_entry nvfx_state_vertprog
;
230 extern struct nvfx_state_entry nvfx_state_viewport
;
231 extern struct nvfx_state_entry nvfx_state_vtxfmt
;
232 extern struct nvfx_state_entry nvfx_state_zsa
;
234 extern void nvfx_init_query_functions(struct nvfx_context
*nvfx
);
235 extern void nvfx_init_surface_functions(struct nvfx_context
*nvfx
);
238 struct pipe_context
*
239 nvfx_create(struct pipe_screen
*pscreen
, void *priv
);
242 extern void nvfx_clear(struct pipe_context
*pipe
, unsigned buffers
,
243 const float *rgba
, double depth
, unsigned stencil
);
246 extern struct draw_stage
*nvfx_draw_render_stage(struct nvfx_context
*nvfx
);
247 extern void nvfx_draw_vbo_swtnl(struct pipe_context
*pipe
, const struct pipe_draw_info
* info
);
248 extern void nvfx_vtxfmt_validate(struct nvfx_context
*nvfx
);
251 extern int nvfx_framebuffer_prepare(struct nvfx_context
*nvfx
);
252 extern void nvfx_framebuffer_validate(struct nvfx_context
*nvfx
, unsigned prepare_result
);
254 nvfx_framebuffer_relocate(struct nvfx_context
*nvfx
);
256 /* nvfx_fragprog.c */
257 extern void nvfx_fragprog_destroy(struct nvfx_context
*,
258 struct nvfx_fragment_program
*);
259 extern void nvfx_fragprog_validate(struct nvfx_context
*nvfx
);
260 extern void nvfx_fragprog_relocate(struct nvfx_context
*nvfx
);
261 extern void nvfx_init_fragprog_functions(struct nvfx_context
*nvfx
);
264 extern void nvfx_init_sampling_functions(struct nvfx_context
*nvfx
);
265 extern void nvfx_fragtex_validate(struct nvfx_context
*nvfx
);
266 extern void nvfx_fragtex_relocate(struct nvfx_context
*nvfx
);
268 struct nvfx_sampler_view
;
272 nv30_sampler_state_init(struct pipe_context
*pipe
,
273 struct nvfx_sampler_state
*ps
,
274 const struct pipe_sampler_state
*cso
);
276 nv30_sampler_view_init(struct pipe_context
*pipe
,
277 struct nvfx_sampler_view
*sv
);
278 extern void nv30_fragtex_set(struct nvfx_context
*nvfx
, int unit
);
282 nv40_sampler_state_init(struct pipe_context
*pipe
,
283 struct nvfx_sampler_state
*ps
,
284 const struct pipe_sampler_state
*cso
);
286 nv40_sampler_view_init(struct pipe_context
*pipe
,
287 struct nvfx_sampler_view
*sv
);
288 extern void nv40_fragtex_set(struct nvfx_context
*nvfx
, int unit
);
291 extern void nvfx_init_state_functions(struct nvfx_context
*nvfx
);
292 extern void nvfx_state_scissor_validate(struct nvfx_context
*nvfx
);
293 extern void nvfx_state_stipple_validate(struct nvfx_context
*nvfx
);
294 extern void nvfx_state_blend_validate(struct nvfx_context
*nvfx
);
295 extern void nvfx_state_blend_colour_validate(struct nvfx_context
*nvfx
);
296 extern void nvfx_state_viewport_validate(struct nvfx_context
*nvfx
);
297 extern void nvfx_state_rasterizer_validate(struct nvfx_context
*nvfx
);
298 extern void nvfx_state_sr_validate(struct nvfx_context
*nvfx
);
299 extern void nvfx_state_zsa_validate(struct nvfx_context
*nvfx
);
301 /* nvfx_state_emit.c */
302 extern void nvfx_state_relocate(struct nvfx_context
*nvfx
, unsigned relocs
);
303 extern boolean
nvfx_state_validate(struct nvfx_context
*nvfx
);
304 extern boolean
nvfx_state_validate_swtnl(struct nvfx_context
*nvfx
);
307 nvfx_state_emit(struct nvfx_context
*nvfx
)
309 unsigned relocs
= NVFX_RELOCATE_FRAMEBUFFER
| NVFX_RELOCATE_FRAGTEX
| NVFX_RELOCATE_FRAGPROG
;
310 if (nvfx
->render_mode
== HW
)
312 relocs
|= NVFX_RELOCATE_VTXBUF
;
313 if(nvfx
->use_index_buffer
)
314 relocs
|= NVFX_RELOCATE_IDXBUF
;
317 relocs
&= nvfx
->relocs_needed
;
319 nvfx_state_relocate(nvfx
, relocs
);
322 /* nvfx_transfer.c */
323 extern void nvfx_init_transfer_functions(struct pipe_context
*pipe
);
326 extern boolean
nvfx_vbo_validate(struct nvfx_context
*nvfx
);
327 extern void nvfx_vbo_relocate(struct nvfx_context
*nvfx
);
328 extern void nvfx_idxbuf_validate(struct nvfx_context
* nvfx
);
329 extern void nvfx_idxbuf_relocate(struct nvfx_context
* nvfx
);
330 extern void nvfx_draw_vbo(struct pipe_context
*pipe
,
331 const struct pipe_draw_info
*info
);
332 extern void nvfx_init_vbo_functions(struct nvfx_context
*nvfx
);
333 extern unsigned nvfx_vertex_formats
[];
335 /* nvfx_vertprog.c */
336 extern boolean
nvfx_vertprog_validate(struct nvfx_context
*nvfx
);
337 extern void nvfx_vertprog_destroy(struct nvfx_context
*,
338 struct nvfx_vertex_program
*);
339 extern void nvfx_init_vertprog_functions(struct nvfx_context
*nvfx
);
342 extern void nvfx_push_vbo(struct pipe_context
*pipe
, const struct pipe_draw_info
*info
);
344 /* must WAIT_RING(chan, ncomp + 1) or equivalent beforehand! */
345 static inline void nvfx_emit_vtx_attr(struct nouveau_channel
* chan
, unsigned attrib
, const float* v
, unsigned ncomp
)
349 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_4F_X(attrib
), 4));
350 OUT_RING(chan
, fui(v
[0]));
351 OUT_RING(chan
, fui(v
[1]));
352 OUT_RING(chan
, fui(v
[2]));
353 OUT_RING(chan
, fui(v
[3]));
356 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_3F_X(attrib
), 3));
357 OUT_RING(chan
, fui(v
[0]));
358 OUT_RING(chan
, fui(v
[1]));
359 OUT_RING(chan
, fui(v
[2]));
362 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_2F_X(attrib
), 2));
363 OUT_RING(chan
, fui(v
[0]));
364 OUT_RING(chan
, fui(v
[1]));
367 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_1F(attrib
), 1));
368 OUT_RING(chan
, fui(v
[0]));