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"
15 #include "draw/draw_vertex.h"
17 #include "nouveau/nouveau_winsys.h"
18 #include "nouveau/nouveau_gldefs.h"
19 #include "nouveau/nouveau_context.h"
20 #include "nouveau/nouveau_stateobj.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 enum nvfx_state_index {
31 NVFX_STATE_VIEWPORT = 1,
37 NVFX_STATE_SCISSOR = 7,
38 NVFX_STATE_STIPPLE = 8,
39 NVFX_STATE_FRAGPROG = 9,
40 NVFX_STATE_VERTPROG = 10,
41 NVFX_STATE_FRAGTEX0 = 11,
42 NVFX_STATE_FRAGTEX1 = 12,
43 NVFX_STATE_FRAGTEX2 = 13,
44 NVFX_STATE_FRAGTEX3 = 14,
45 NVFX_STATE_FRAGTEX4 = 15,
46 NVFX_STATE_FRAGTEX5 = 16,
47 NVFX_STATE_FRAGTEX6 = 17,
48 NVFX_STATE_FRAGTEX7 = 18,
49 NVFX_STATE_FRAGTEX8 = 19,
50 NVFX_STATE_FRAGTEX9 = 20,
51 NVFX_STATE_FRAGTEX10 = 21,
52 NVFX_STATE_FRAGTEX11 = 22,
53 NVFX_STATE_FRAGTEX12 = 23,
54 NVFX_STATE_FRAGTEX13 = 24,
55 NVFX_STATE_FRAGTEX14 = 25,
56 NVFX_STATE_FRAGTEX15 = 26,
57 NVFX_STATE_VERTTEX0 = 27,
58 NVFX_STATE_VERTTEX1 = 28,
59 NVFX_STATE_VERTTEX2 = 29,
60 NVFX_STATE_VERTTEX3 = 30,
61 NVFX_STATE_VTXBUF = 31,
62 NVFX_STATE_VTXFMT = 32,
63 NVFX_STATE_VTXATTR = 33,
68 #include "nvfx_screen.h"
70 #define NVFX_NEW_BLEND (1 << 0)
71 #define NVFX_NEW_RAST (1 << 1)
72 #define NVFX_NEW_ZSA (1 << 2)
73 #define NVFX_NEW_SAMPLER (1 << 3)
74 #define NVFX_NEW_FB (1 << 4)
75 #define NVFX_NEW_STIPPLE (1 << 5)
76 #define NVFX_NEW_SCISSOR (1 << 6)
77 #define NVFX_NEW_VIEWPORT (1 << 7)
78 #define NVFX_NEW_BCOL (1 << 8)
79 #define NVFX_NEW_VERTPROG (1 << 9)
80 #define NVFX_NEW_FRAGPROG (1 << 10)
81 #define NVFX_NEW_ARRAYS (1 << 11)
82 #define NVFX_NEW_UCP (1 << 12)
83 #define NVFX_NEW_SR (1 << 13)
85 struct nvfx_rasterizer_state {
86 struct pipe_rasterizer_state pipe;
87 struct nouveau_stateobj *so;
90 struct nvfx_zsa_state {
91 struct pipe_depth_stencil_alpha_state pipe;
92 struct nouveau_stateobj *so;
95 struct nvfx_blend_state {
96 struct pipe_blend_state pipe;
97 struct nouveau_stateobj *so;
102 unsigned scissor_enabled;
103 unsigned stipple_enabled;
104 unsigned fp_samplers;
107 struct nouveau_stateobj *hw[NVFX_STATE_MAX];
110 struct nvfx_vtxelt_state {
111 struct pipe_vertex_element pipe[16];
112 unsigned num_elements;
115 struct nvfx_context {
116 struct pipe_context pipe;
118 struct nouveau_winsys *nvws;
119 struct nvfx_screen *screen;
121 unsigned is_nv4x; /* either 0 or ~0 */
123 struct draw_context *draw;
125 /* HW state derived from pipe states */
126 struct nvfx_state state;
128 struct nvfx_vertex_program *vertprog;
131 unsigned hw[PIPE_MAX_SHADER_INPUTS];
132 unsigned draw[PIPE_MAX_SHADER_INPUTS];
133 unsigned emit[PIPE_MAX_SHADER_INPUTS];
139 unsigned fallback_swtnl;
140 unsigned fallback_swrast;
143 unsigned dirty, draw_dirty;
144 struct pipe_scissor_state scissor;
145 unsigned stipple[32];
146 struct pipe_clip_state clip;
147 struct nvfx_vertex_program *vertprog;
148 struct nvfx_fragment_program *fragprog;
149 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
150 unsigned constbuf_nr[PIPE_SHADER_TYPES];
151 struct nvfx_rasterizer_state *rasterizer;
152 struct nvfx_zsa_state *zsa;
153 struct nvfx_blend_state *blend;
154 struct pipe_blend_color blend_colour;
155 struct pipe_stencil_ref stencil_ref;
156 struct pipe_viewport_state viewport;
157 struct pipe_framebuffer_state framebuffer;
158 struct pipe_buffer *idxbuf;
159 unsigned idxbuf_format;
160 struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
161 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
162 unsigned nr_samplers;
163 unsigned nr_textures;
164 unsigned dirty_samplers;
165 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
167 struct nvfx_vtxelt_state *vtxelt;
170 static INLINE struct nvfx_context *
171 nvfx_context(struct pipe_context *pipe)
173 return (struct nvfx_context *)pipe;
176 struct nvfx_state_entry {
177 boolean (*validate)(struct nvfx_context *nvfx);
184 extern struct nvfx_state_entry nvfx_state_blend;
185 extern struct nvfx_state_entry nvfx_state_blend_colour;
186 extern struct nvfx_state_entry nvfx_state_fragprog;
187 extern struct nvfx_state_entry nvfx_state_fragtex;
188 extern struct nvfx_state_entry nvfx_state_framebuffer;
189 extern struct nvfx_state_entry nvfx_state_rasterizer;
190 extern struct nvfx_state_entry nvfx_state_scissor;
191 extern struct nvfx_state_entry nvfx_state_sr;
192 extern struct nvfx_state_entry nvfx_state_stipple;
193 extern struct nvfx_state_entry nvfx_state_vbo;
194 extern struct nvfx_state_entry nvfx_state_vertprog;
195 extern struct nvfx_state_entry nvfx_state_viewport;
196 extern struct nvfx_state_entry nvfx_state_vtxfmt;
197 extern struct nvfx_state_entry nvfx_state_zsa;
199 extern void nvfx_init_query_functions(struct nvfx_context *nvfx);
200 extern void nvfx_init_surface_functions(struct nvfx_context *nvfx);
203 struct pipe_context *
204 nvfx_create(struct pipe_screen *pscreen, void *priv);
207 extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers,
208 const float *rgba, double depth, unsigned stencil);
211 extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
212 extern void nvfx_draw_elements_swtnl(struct pipe_context *pipe,
213 struct pipe_buffer *idxbuf,
214 unsigned ib_size, unsigned mode,
215 unsigned start, unsigned count);
217 /* nvfx_fragprog.c */
218 extern void nvfx_fragprog_destroy(struct nvfx_context *,
219 struct nvfx_fragment_program *);
223 nv30_sampler_state_init(struct pipe_context *pipe,
224 struct nvfx_sampler_state *ps,
225 const struct pipe_sampler_state *cso);
226 extern void nv30_fragtex_bind(struct nvfx_context *);
227 extern struct nouveau_stateobj *
228 nv30_fragtex_build(struct nvfx_context *nvfx, int unit);
232 nv40_sampler_state_init(struct pipe_context *pipe,
233 struct nvfx_sampler_state *ps,
234 const struct pipe_sampler_state *cso);
235 extern void nv40_fragtex_bind(struct nvfx_context *);
236 extern struct nouveau_stateobj *
237 nv40_fragtex_build(struct nvfx_context *nvfx, int unit);
240 extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
242 /* nvfx_state_emit.c */
243 extern void nvfx_state_flush_notify(struct nouveau_channel *chan);
244 extern boolean nvfx_state_validate(struct nvfx_context *nvfx);
245 extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx);
246 extern void nvfx_state_emit(struct nvfx_context *nvfx);
248 /* nvfx_transfer.c */
249 extern void nvfx_init_transfer_functions(struct nvfx_context *nvfx);
252 extern void nvfx_draw_arrays(struct pipe_context *, unsigned mode,
253 unsigned start, unsigned count);
254 extern void nvfx_draw_elements(struct pipe_context *pipe,
255 struct pipe_buffer *indexBuffer,
257 unsigned mode, unsigned start,
260 /* nvfx_vertprog.c */
261 extern void nvfx_vertprog_destroy(struct nvfx_context *,
262 struct nvfx_vertex_program *);