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)
49 struct nvfx_rasterizer_state
{
50 struct pipe_rasterizer_state pipe
;
55 struct nvfx_zsa_state
{
56 struct pipe_depth_stencil_alpha_state pipe
;
61 struct nvfx_blend_state
{
62 struct pipe_blend_state pipe
;
69 unsigned scissor_enabled
;
70 unsigned stipple_enabled
;
72 unsigned render_temps
;
75 struct nvfx_per_vertex_element
{
77 unsigned vertex_buffer_index
;
81 struct nvfx_low_frequency_element
{
83 unsigned vertex_buffer_index
;
85 void (*fetch_rgba_float
)(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
);
89 struct nvfx_per_instance_element
{
90 struct nvfx_low_frequency_element base
;
91 unsigned instance_divisor
;
94 struct nvfx_per_vertex_buffer_info
96 unsigned vertex_buffer_index
;
97 unsigned per_vertex_size
;
100 struct nvfx_vtxelt_state
{
101 struct pipe_vertex_element pipe
[16];
102 unsigned num_elements
;
105 unsigned num_per_vertex_buffer_infos
;
106 struct nvfx_per_vertex_buffer_info per_vertex_buffer_info
[16];
108 unsigned num_per_vertex
;
109 struct nvfx_per_vertex_element per_vertex
[16];
111 unsigned num_per_instance
;
112 struct nvfx_per_instance_element per_instance
[16];
114 unsigned num_constant
;
115 struct nvfx_low_frequency_element constant
[16];
117 boolean needs_translate
;
118 struct translate
* translate
;
120 unsigned vertex_length
;
121 unsigned max_vertices_per_packet
;
124 struct nvfx_render_target
{
125 struct nouveau_bo
* bo
;
130 struct nvfx_context
{
131 struct pipe_context pipe
;
133 struct nouveau_winsys
*nvws
;
134 struct nvfx_screen
*screen
;
136 unsigned is_nv4x
; /* either 0 or ~0 */
138 struct draw_context
*draw
;
139 struct blitter_context
* blitter
;
140 struct list_head render_cache
;
142 /* HW state derived from pipe states */
143 struct nvfx_state state
;
145 struct nvfx_vertex_program
*vertprog
;
148 unsigned hw
[PIPE_MAX_SHADER_INPUTS
];
149 unsigned draw
[PIPE_MAX_SHADER_INPUTS
];
150 unsigned emit
[PIPE_MAX_SHADER_INPUTS
];
156 unsigned fallback_swtnl
;
159 unsigned dirty
, draw_dirty
;
160 struct pipe_scissor_state scissor
;
161 unsigned stipple
[32];
162 struct pipe_clip_state clip
;
163 struct nvfx_vertex_program
*vertprog
;
164 struct nvfx_fragment_program
*fragprog
;
165 struct pipe_resource
*constbuf
[PIPE_SHADER_TYPES
];
166 unsigned constbuf_nr
[PIPE_SHADER_TYPES
];
167 struct nvfx_rasterizer_state
*rasterizer
;
168 struct nvfx_zsa_state
*zsa
;
169 struct nvfx_blend_state
*blend
;
170 struct pipe_blend_color blend_colour
;
171 struct pipe_stencil_ref stencil_ref
;
172 struct pipe_viewport_state viewport
;
173 struct pipe_framebuffer_state framebuffer
;
174 struct pipe_index_buffer idxbuf
;
175 struct nvfx_sampler_state
*tex_sampler
[PIPE_MAX_SAMPLERS
];
176 struct pipe_sampler_view
*fragment_sampler_views
[PIPE_MAX_SAMPLERS
];
177 unsigned nr_samplers
;
178 unsigned nr_textures
;
179 unsigned dirty_samplers
;
180 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
182 struct nvfx_vtxelt_state
*vtxelt
;
184 boolean use_index_buffer
;
185 /* -1 = hardware input setup is outdated
186 * 0 = hardware input setup is for inline vertices
187 * 1 = hardware input setup is for hardware vertices
189 int use_vertex_buffers
;
191 unsigned hw_vtxelt_nr
;
194 struct nvfx_render_target hw_rt
[4];
195 struct nvfx_render_target hw_zeta
;
198 static INLINE
struct nvfx_context
*
199 nvfx_context(struct pipe_context
*pipe
)
201 return (struct nvfx_context
*)pipe
;
204 extern struct nvfx_state_entry nvfx_state_blend
;
205 extern struct nvfx_state_entry nvfx_state_blend_colour
;
206 extern struct nvfx_state_entry nvfx_state_fragprog
;
207 extern struct nvfx_state_entry nvfx_state_fragtex
;
208 extern struct nvfx_state_entry nvfx_state_framebuffer
;
209 extern struct nvfx_state_entry nvfx_state_rasterizer
;
210 extern struct nvfx_state_entry nvfx_state_scissor
;
211 extern struct nvfx_state_entry nvfx_state_sr
;
212 extern struct nvfx_state_entry nvfx_state_stipple
;
213 extern struct nvfx_state_entry nvfx_state_vbo
;
214 extern struct nvfx_state_entry nvfx_state_vertprog
;
215 extern struct nvfx_state_entry nvfx_state_viewport
;
216 extern struct nvfx_state_entry nvfx_state_vtxfmt
;
217 extern struct nvfx_state_entry nvfx_state_zsa
;
219 extern void nvfx_init_query_functions(struct nvfx_context
*nvfx
);
220 extern void nvfx_init_surface_functions(struct nvfx_context
*nvfx
);
223 struct pipe_context
*
224 nvfx_create(struct pipe_screen
*pscreen
, void *priv
);
227 extern void nvfx_clear(struct pipe_context
*pipe
, unsigned buffers
,
228 const float *rgba
, double depth
, unsigned stencil
);
231 extern struct draw_stage
*nvfx_draw_render_stage(struct nvfx_context
*nvfx
);
232 extern void nvfx_draw_vbo_swtnl(struct pipe_context
*pipe
, const struct pipe_draw_info
* info
);
233 extern void nvfx_vtxfmt_validate(struct nvfx_context
*nvfx
);
236 extern int nvfx_framebuffer_prepare(struct nvfx_context
*nvfx
);
237 extern void nvfx_framebuffer_validate(struct nvfx_context
*nvfx
, unsigned prepare_result
);
239 nvfx_framebuffer_relocate(struct nvfx_context
*nvfx
);
241 /* nvfx_fragprog.c */
242 extern void nvfx_fragprog_destroy(struct nvfx_context
*,
243 struct nvfx_fragment_program
*);
244 extern void nvfx_fragprog_validate(struct nvfx_context
*nvfx
);
246 nvfx_fragprog_relocate(struct nvfx_context
*nvfx
);
249 extern void nvfx_init_sampling_functions(struct nvfx_context
*nvfx
);
250 extern void nvfx_fragtex_validate(struct nvfx_context
*nvfx
);
251 extern void nvfx_fragtex_relocate(struct nvfx_context
*nvfx
);
253 struct nvfx_sampler_view
;
257 nv30_sampler_state_init(struct pipe_context
*pipe
,
258 struct nvfx_sampler_state
*ps
,
259 const struct pipe_sampler_state
*cso
);
261 nv30_sampler_view_init(struct pipe_context
*pipe
,
262 struct nvfx_sampler_view
*sv
);
263 extern void nv30_fragtex_set(struct nvfx_context
*nvfx
, int unit
);
267 nv40_sampler_state_init(struct pipe_context
*pipe
,
268 struct nvfx_sampler_state
*ps
,
269 const struct pipe_sampler_state
*cso
);
271 nv40_sampler_view_init(struct pipe_context
*pipe
,
272 struct nvfx_sampler_view
*sv
);
273 extern void nv40_fragtex_set(struct nvfx_context
*nvfx
, int unit
);
276 extern void nvfx_init_state_functions(struct nvfx_context
*nvfx
);
277 extern void nvfx_state_scissor_validate(struct nvfx_context
*nvfx
);
278 extern void nvfx_state_stipple_validate(struct nvfx_context
*nvfx
);
279 extern void nvfx_state_blend_validate(struct nvfx_context
*nvfx
);
280 extern void nvfx_state_blend_colour_validate(struct nvfx_context
*nvfx
);
281 extern void nvfx_state_viewport_validate(struct nvfx_context
*nvfx
);
282 extern void nvfx_state_rasterizer_validate(struct nvfx_context
*nvfx
);
283 extern void nvfx_state_sr_validate(struct nvfx_context
*nvfx
);
284 extern void nvfx_state_zsa_validate(struct nvfx_context
*nvfx
);
286 /* nvfx_state_emit.c */
287 extern void nvfx_state_relocate(struct nvfx_context
*nvfx
);
288 extern boolean
nvfx_state_validate(struct nvfx_context
*nvfx
);
289 extern boolean
nvfx_state_validate_swtnl(struct nvfx_context
*nvfx
);
290 extern void nvfx_state_emit(struct nvfx_context
*nvfx
);
292 /* nvfx_transfer.c */
293 extern void nvfx_init_transfer_functions(struct pipe_context
*pipe
);
296 extern boolean
nvfx_vbo_validate(struct nvfx_context
*nvfx
);
297 extern void nvfx_vbo_relocate(struct nvfx_context
*nvfx
);
298 extern void nvfx_idxbuf_validate(struct nvfx_context
* nvfx
);
299 extern void nvfx_idxbuf_relocate(struct nvfx_context
* nvfx
);
300 extern void nvfx_draw_vbo(struct pipe_context
*pipe
,
301 const struct pipe_draw_info
*info
);
302 extern void nvfx_init_vbo_functions(struct nvfx_context
*nvfx
);
303 extern unsigned nvfx_vertex_formats
[];
305 /* nvfx_vertprog.c */
306 extern boolean
nvfx_vertprog_validate(struct nvfx_context
*nvfx
);
307 extern void nvfx_vertprog_destroy(struct nvfx_context
*,
308 struct nvfx_vertex_program
*);
311 extern void nvfx_push_vbo(struct pipe_context
*pipe
, const struct pipe_draw_info
*info
);
313 /* must WAIT_RING(chan, ncomp + 1) or equivalent beforehand! */
314 static inline void nvfx_emit_vtx_attr(struct nouveau_channel
* chan
, unsigned attrib
, float* v
, unsigned ncomp
)
318 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_4F_X(attrib
), 4));
319 OUT_RING(chan
, fui(v
[0]));
320 OUT_RING(chan
, fui(v
[1]));
321 OUT_RING(chan
, fui(v
[2]));
322 OUT_RING(chan
, fui(v
[3]));
325 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_3F_X(attrib
), 3));
326 OUT_RING(chan
, fui(v
[0]));
327 OUT_RING(chan
, fui(v
[1]));
328 OUT_RING(chan
, fui(v
[2]));
331 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_2F_X(attrib
), 2));
332 OUT_RING(chan
, fui(v
[0]));
333 OUT_RING(chan
, fui(v
[1]));
336 OUT_RING(chan
, RING_3D(NV34TCL_VTX_ATTR_1F(attrib
), 1));
337 OUT_RING(chan
, fui(v
[0]));