1 #ifndef __NV40_CONTEXT_H__
2 #define __NV40_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 "nv40_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 nv40_state_index
{
31 NV40_STATE_VIEWPORT
= 1,
37 NV40_STATE_SCISSOR
= 7,
38 NV40_STATE_STIPPLE
= 8,
39 NV40_STATE_FRAGPROG
= 9,
40 NV40_STATE_VERTPROG
= 10,
41 NV40_STATE_FRAGTEX0
= 11,
42 NV40_STATE_FRAGTEX1
= 12,
43 NV40_STATE_FRAGTEX2
= 13,
44 NV40_STATE_FRAGTEX3
= 14,
45 NV40_STATE_FRAGTEX4
= 15,
46 NV40_STATE_FRAGTEX5
= 16,
47 NV40_STATE_FRAGTEX6
= 17,
48 NV40_STATE_FRAGTEX7
= 18,
49 NV40_STATE_FRAGTEX8
= 19,
50 NV40_STATE_FRAGTEX9
= 20,
51 NV40_STATE_FRAGTEX10
= 21,
52 NV40_STATE_FRAGTEX11
= 22,
53 NV40_STATE_FRAGTEX12
= 23,
54 NV40_STATE_FRAGTEX13
= 24,
55 NV40_STATE_FRAGTEX14
= 25,
56 NV40_STATE_FRAGTEX15
= 26,
57 NV40_STATE_VERTTEX0
= 27,
58 NV40_STATE_VERTTEX1
= 28,
59 NV40_STATE_VERTTEX2
= 29,
60 NV40_STATE_VERTTEX3
= 30,
61 NV40_STATE_VTXBUF
= 31,
62 NV40_STATE_VTXFMT
= 32,
63 NV40_STATE_VTXATTR
= 33,
68 #include "nv40_screen.h"
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 #define NV40_NEW_SR (1 << 13)
85 struct nv40_rasterizer_state
{
86 struct pipe_rasterizer_state pipe
;
87 struct nouveau_stateobj
*so
;
90 struct nv40_zsa_state
{
91 struct pipe_depth_stencil_alpha_state pipe
;
92 struct nouveau_stateobj
*so
;
95 struct nv40_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
[NV40_STATE_MAX
];
111 struct nv40_vtxelt_state
{
112 struct pipe_vertex_element pipe
[16];
113 unsigned num_elements
;
116 struct nv40_context
{
117 struct pipe_context pipe
;
119 struct nouveau_winsys
*nvws
;
120 struct nv40_screen
*screen
;
122 struct draw_context
*draw
;
124 /* HW state derived from pipe states */
125 struct nv40_state state
;
127 struct nv40_vertex_program
*vertprog
;
130 unsigned hw
[PIPE_MAX_SHADER_INPUTS
];
131 unsigned draw
[PIPE_MAX_SHADER_INPUTS
];
132 unsigned emit
[PIPE_MAX_SHADER_INPUTS
];
138 unsigned fallback_swtnl
;
139 unsigned fallback_swrast
;
142 unsigned dirty
, draw_dirty
;
143 struct pipe_scissor_state scissor
;
144 unsigned stipple
[32];
145 struct pipe_clip_state clip
;
146 struct nv40_vertex_program
*vertprog
;
147 struct nv40_fragment_program
*fragprog
;
148 struct pipe_buffer
*constbuf
[PIPE_SHADER_TYPES
];
149 unsigned constbuf_nr
[PIPE_SHADER_TYPES
];
150 struct nv40_rasterizer_state
*rasterizer
;
151 struct nv40_zsa_state
*zsa
;
152 struct nv40_blend_state
*blend
;
153 struct pipe_blend_color blend_colour
;
154 struct pipe_stencil_ref stencil_ref
;
155 struct pipe_viewport_state viewport
;
156 struct pipe_framebuffer_state framebuffer
;
157 struct pipe_buffer
*idxbuf
;
158 unsigned idxbuf_format
;
159 struct nv40_sampler_state
*tex_sampler
[PIPE_MAX_SAMPLERS
];
160 struct nv40_miptree
*tex_miptree
[PIPE_MAX_SAMPLERS
];
161 unsigned nr_samplers
;
162 unsigned nr_textures
;
163 unsigned dirty_samplers
;
164 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
166 struct nv40_vtxelt_state
*vtxelt
;
169 static INLINE
struct nv40_context
*
170 nv40_context(struct pipe_context
*pipe
)
172 return (struct nv40_context
*)pipe
;
175 struct nv40_state_entry
{
176 boolean (*validate
)(struct nv40_context
*nv40
);
183 extern void nv40_init_state_functions(struct nv40_context
*nv40
);
184 extern void nv40_init_surface_functions(struct nv40_context
*nv40
);
185 extern void nv40_init_query_functions(struct nv40_context
*nv40
);
187 extern void nv40_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
190 extern struct draw_stage
*nv40_draw_render_stage(struct nv40_context
*nv40
);
191 extern void nv40_draw_elements_swtnl(struct pipe_context
*pipe
,
192 struct pipe_buffer
*idxbuf
,
193 unsigned ib_size
, unsigned mode
,
194 unsigned start
, unsigned count
);
196 /* nv40_vertprog.c */
197 extern void nv40_vertprog_destroy(struct nv40_context
*,
198 struct nv40_vertex_program
*);
200 /* nv40_fragprog.c */
201 extern void nv40_fragprog_destroy(struct nv40_context
*,
202 struct nv40_fragment_program
*);
205 extern void nv40_fragtex_bind(struct nv40_context
*);
207 /* nv40_state.c and friends */
208 extern boolean
nv40_state_validate(struct nv40_context
*nv40
);
209 extern boolean
nv40_state_validate_swtnl(struct nv40_context
*nv40
);
210 extern void nv40_state_emit(struct nv40_context
*nv40
);
211 extern void nv40_state_flush_notify(struct nouveau_channel
*chan
);
212 extern struct nv40_state_entry nv40_state_rasterizer
;
213 extern struct nv40_state_entry nv40_state_scissor
;
214 extern struct nv40_state_entry nv40_state_stipple
;
215 extern struct nv40_state_entry nv40_state_fragprog
;
216 extern struct nv40_state_entry nv40_state_vertprog
;
217 extern struct nv40_state_entry nv40_state_blend
;
218 extern struct nv40_state_entry nv40_state_blend_colour
;
219 extern struct nv40_state_entry nv40_state_zsa
;
220 extern struct nv40_state_entry nv40_state_viewport
;
221 extern struct nv40_state_entry nv40_state_framebuffer
;
222 extern struct nv40_state_entry nv40_state_fragtex
;
223 extern struct nv40_state_entry nv40_state_vbo
;
224 extern struct nv40_state_entry nv40_state_vtxfmt
;
225 extern struct nv40_state_entry nv40_state_sr
;
228 extern void nv40_draw_arrays(struct pipe_context
*, unsigned mode
,
229 unsigned start
, unsigned count
);
230 extern void nv40_draw_elements(struct pipe_context
*pipe
,
231 struct pipe_buffer
*indexBuffer
,
233 unsigned mode
, unsigned start
,
237 extern void nv40_clear(struct pipe_context
*pipe
, unsigned buffers
,
238 const float *rgba
, double depth
, unsigned stencil
);
241 struct pipe_context
*
242 nv40_create(struct pipe_screen
*pscreen
, void *priv
);