1 #ifndef __NV40_CONTEXT_H__
2 #define __NV40_CONTEXT_H__
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7 #include "pipe/p_compiler.h"
9 #include "util/u_memory.h"
10 #include "util/u_math.h"
12 #include "draw/draw_vertex.h"
14 #include "nouveau/nouveau_winsys.h"
15 #include "nouveau/nouveau_gldefs.h"
16 #include "nouveau/nouveau_context.h"
17 #include "nouveau/nouveau_stateobj.h"
19 #include "nv40_state.h"
21 #define NOUVEAU_ERR(fmt, args...) \
22 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
23 #define NOUVEAU_MSG(fmt, args...) \
24 fprintf(stderr, "nouveau: "fmt, ##args);
26 enum nv40_state_index
{
28 NV40_STATE_VIEWPORT
= 1,
34 NV40_STATE_SCISSOR
= 7,
35 NV40_STATE_STIPPLE
= 8,
36 NV40_STATE_FRAGPROG
= 9,
37 NV40_STATE_VERTPROG
= 10,
38 NV40_STATE_FRAGTEX0
= 11,
39 NV40_STATE_FRAGTEX1
= 12,
40 NV40_STATE_FRAGTEX2
= 13,
41 NV40_STATE_FRAGTEX3
= 14,
42 NV40_STATE_FRAGTEX4
= 15,
43 NV40_STATE_FRAGTEX5
= 16,
44 NV40_STATE_FRAGTEX6
= 17,
45 NV40_STATE_FRAGTEX7
= 18,
46 NV40_STATE_FRAGTEX8
= 19,
47 NV40_STATE_FRAGTEX9
= 20,
48 NV40_STATE_FRAGTEX10
= 21,
49 NV40_STATE_FRAGTEX11
= 22,
50 NV40_STATE_FRAGTEX12
= 23,
51 NV40_STATE_FRAGTEX13
= 24,
52 NV40_STATE_FRAGTEX14
= 25,
53 NV40_STATE_FRAGTEX15
= 26,
54 NV40_STATE_VERTTEX0
= 27,
55 NV40_STATE_VERTTEX1
= 28,
56 NV40_STATE_VERTTEX2
= 29,
57 NV40_STATE_VERTTEX3
= 30,
58 NV40_STATE_VTXBUF
= 31,
59 NV40_STATE_VTXFMT
= 32,
60 NV40_STATE_VTXATTR
= 33,
64 #include "nv40_screen.h"
66 #define NV40_NEW_BLEND (1 << 0)
67 #define NV40_NEW_RAST (1 << 1)
68 #define NV40_NEW_ZSA (1 << 2)
69 #define NV40_NEW_SAMPLER (1 << 3)
70 #define NV40_NEW_FB (1 << 4)
71 #define NV40_NEW_STIPPLE (1 << 5)
72 #define NV40_NEW_SCISSOR (1 << 6)
73 #define NV40_NEW_VIEWPORT (1 << 7)
74 #define NV40_NEW_BCOL (1 << 8)
75 #define NV40_NEW_VERTPROG (1 << 9)
76 #define NV40_NEW_FRAGPROG (1 << 10)
77 #define NV40_NEW_ARRAYS (1 << 11)
78 #define NV40_NEW_UCP (1 << 12)
80 struct nv40_rasterizer_state
{
81 struct pipe_rasterizer_state pipe
;
82 struct nouveau_stateobj
*so
;
85 struct nv40_zsa_state
{
86 struct pipe_depth_stencil_alpha_state pipe
;
87 struct nouveau_stateobj
*so
;
90 struct nv40_blend_state
{
91 struct pipe_blend_state pipe
;
92 struct nouveau_stateobj
*so
;
97 unsigned scissor_enabled
;
98 unsigned stipple_enabled
;
99 unsigned viewport_bypass
;
100 unsigned fp_samplers
;
103 struct nouveau_stateobj
*hw
[NV40_STATE_MAX
];
106 struct nv40_context
{
107 struct pipe_context pipe
;
109 struct nouveau_winsys
*nvws
;
110 struct nv40_screen
*screen
;
113 struct draw_context
*draw
;
115 /* HW state derived from pipe states */
116 struct nv40_state state
;
118 struct nv40_vertex_program
*vertprog
;
121 unsigned hw
[PIPE_MAX_SHADER_INPUTS
];
122 unsigned draw
[PIPE_MAX_SHADER_INPUTS
];
123 unsigned emit
[PIPE_MAX_SHADER_INPUTS
];
129 unsigned fallback_swtnl
;
130 unsigned fallback_swrast
;
133 unsigned dirty
, draw_dirty
;
134 struct pipe_scissor_state scissor
;
135 unsigned stipple
[32];
136 struct pipe_clip_state clip
;
137 struct nv40_vertex_program
*vertprog
;
138 struct nv40_fragment_program
*fragprog
;
139 struct pipe_buffer
*constbuf
[PIPE_SHADER_TYPES
];
140 unsigned constbuf_nr
[PIPE_SHADER_TYPES
];
141 struct nv40_rasterizer_state
*rasterizer
;
142 struct nv40_zsa_state
*zsa
;
143 struct nv40_blend_state
*blend
;
144 struct pipe_blend_color blend_colour
;
145 struct pipe_viewport_state viewport
;
146 struct pipe_framebuffer_state framebuffer
;
147 struct pipe_buffer
*idxbuf
;
148 unsigned idxbuf_format
;
149 struct nv40_sampler_state
*tex_sampler
[PIPE_MAX_SAMPLERS
];
150 struct nv40_miptree
*tex_miptree
[PIPE_MAX_SAMPLERS
];
151 unsigned nr_samplers
;
152 unsigned nr_textures
;
153 unsigned dirty_samplers
;
154 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
156 struct pipe_vertex_element vtxelt
[PIPE_MAX_ATTRIBS
];
160 static INLINE
struct nv40_context
*
161 nv40_context(struct pipe_context
*pipe
)
163 return (struct nv40_context
*)pipe
;
166 struct nv40_state_entry
{
167 boolean (*validate
)(struct nv40_context
*nv40
);
174 extern void nv40_init_state_functions(struct nv40_context
*nv40
);
175 extern void nv40_init_surface_functions(struct nv40_context
*nv40
);
176 extern void nv40_init_query_functions(struct nv40_context
*nv40
);
178 extern void nv40_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
181 extern struct draw_stage
*nv40_draw_render_stage(struct nv40_context
*nv40
);
182 extern void nv40_draw_elements_swtnl(struct pipe_context
*pipe
,
183 struct pipe_buffer
*idxbuf
,
184 unsigned ib_size
, unsigned mode
,
185 unsigned start
, unsigned count
);
187 /* nv40_vertprog.c */
188 extern void nv40_vertprog_destroy(struct nv40_context
*,
189 struct nv40_vertex_program
*);
191 /* nv40_fragprog.c */
192 extern void nv40_fragprog_destroy(struct nv40_context
*,
193 struct nv40_fragment_program
*);
196 extern void nv40_fragtex_bind(struct nv40_context
*);
198 /* nv40_state.c and friends */
199 extern boolean
nv40_state_validate(struct nv40_context
*nv40
);
200 extern boolean
nv40_state_validate_swtnl(struct nv40_context
*nv40
);
201 extern void nv40_state_emit(struct nv40_context
*nv40
);
202 extern void nv40_state_flush_notify(struct nouveau_channel
*chan
);
203 extern struct nv40_state_entry nv40_state_rasterizer
;
204 extern struct nv40_state_entry nv40_state_scissor
;
205 extern struct nv40_state_entry nv40_state_stipple
;
206 extern struct nv40_state_entry nv40_state_fragprog
;
207 extern struct nv40_state_entry nv40_state_vertprog
;
208 extern struct nv40_state_entry nv40_state_blend
;
209 extern struct nv40_state_entry nv40_state_blend_colour
;
210 extern struct nv40_state_entry nv40_state_zsa
;
211 extern struct nv40_state_entry nv40_state_viewport
;
212 extern struct nv40_state_entry nv40_state_framebuffer
;
213 extern struct nv40_state_entry nv40_state_fragtex
;
214 extern struct nv40_state_entry nv40_state_vbo
;
215 extern struct nv40_state_entry nv40_state_vtxfmt
;
218 extern void nv40_draw_arrays(struct pipe_context
*, unsigned mode
,
219 unsigned start
, unsigned count
);
220 extern void nv40_draw_elements(struct pipe_context
*pipe
,
221 struct pipe_buffer
*indexBuffer
,
223 unsigned mode
, unsigned start
,
227 extern void nv40_clear(struct pipe_context
*pipe
, unsigned buffers
,
228 const float *rgba
, double depth
, unsigned stencil
);