1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_CONTEXT_H__
5 #include "pipe/p_context.h"
6 #include "pipe/p_defines.h"
7 #include "pipe/p_state.h"
8 #include "pipe/p_compiler.h"
10 #include "util/u_memory.h"
11 #include "util/u_math.h"
12 #include "util/u_inlines.h"
14 #include "draw/draw_vertex.h"
16 #include "nouveau/nouveau_winsys.h"
17 #include "nouveau/nouveau_gldefs.h"
18 #include "nouveau/nouveau_stateobj.h"
19 #include "nouveau/nouveau_context.h"
21 #include "nv50_screen.h"
22 #include "nv50_program.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 /* Constant buffer assignment */
30 #define NV50_CB_PMISC 0
36 #define NV50_NEW_BLEND (1 << 0)
37 #define NV50_NEW_ZSA (1 << 1)
38 #define NV50_NEW_BLEND_COLOUR (1 << 2)
39 #define NV50_NEW_STIPPLE (1 << 3)
40 #define NV50_NEW_SCISSOR (1 << 4)
41 #define NV50_NEW_VIEWPORT (1 << 5)
42 #define NV50_NEW_RASTERIZER (1 << 6)
43 #define NV50_NEW_FRAMEBUFFER (1 << 7)
44 #define NV50_NEW_VERTPROG (1 << 8)
45 #define NV50_NEW_VERTPROG_CB (1 << 9)
46 #define NV50_NEW_FRAGPROG (1 << 10)
47 #define NV50_NEW_FRAGPROG_CB (1 << 11)
48 #define NV50_NEW_GEOMPROG (1 << 12)
49 #define NV50_NEW_GEOMPROG_CB (1 << 13)
50 #define NV50_NEW_ARRAYS (1 << 14)
51 #define NV50_NEW_SAMPLER (1 << 15)
52 #define NV50_NEW_TEXTURE (1 << 16)
53 #define NV50_NEW_STENCIL_REF (1 << 17)
55 struct nv50_blend_stateobj
{
56 struct pipe_blend_state pipe
;
57 struct nouveau_stateobj
*so
;
60 struct nv50_zsa_stateobj
{
61 struct pipe_depth_stencil_alpha_state pipe
;
62 struct nouveau_stateobj
*so
;
65 struct nv50_rasterizer_stateobj
{
66 struct pipe_rasterizer_state pipe
;
67 struct nouveau_stateobj
*so
;
70 struct nv50_sampler_stateobj
{
75 struct nv50_vtxelt_stateobj
{
76 struct pipe_vertex_element pipe
[16];
77 unsigned num_elements
;
81 static INLINE
unsigned
82 get_tile_height(uint32_t tile_mode
)
84 return 1 << ((tile_mode
& 0xf) + 2);
87 static INLINE
unsigned
88 get_tile_depth(uint32_t tile_mode
)
90 return 1 << (tile_mode
>> 4);
93 struct nv50_miptree_level
{
99 #define NV50_MAX_TEXTURE_LEVELS 16
101 struct nv50_miptree
{
102 struct nouveau_miptree base
;
104 struct nv50_miptree_level level
[NV50_MAX_TEXTURE_LEVELS
];
109 static INLINE
struct nv50_miptree
*
110 nv50_miptree(struct pipe_texture
*pt
)
112 return (struct nv50_miptree
*)pt
;
115 struct nv50_surface
{
116 struct pipe_surface base
;
119 static INLINE
struct nv50_surface
*
120 nv50_surface(struct pipe_surface
*pt
)
122 return (struct nv50_surface
*)pt
;
128 struct nouveau_stateobj
*fb
;
129 struct nouveau_stateobj
*blend
;
130 struct nouveau_stateobj
*blend_colour
;
131 struct nouveau_stateobj
*zsa
;
132 struct nouveau_stateobj
*stencil_ref
;
133 struct nouveau_stateobj
*rast
;
134 struct nouveau_stateobj
*stipple
;
135 struct nouveau_stateobj
*scissor
;
136 unsigned scissor_enabled
;
137 struct nouveau_stateobj
*viewport
;
138 struct nouveau_stateobj
*tsc_upload
;
139 struct nouveau_stateobj
*tic_upload
;
140 unsigned miptree_nr
[PIPE_SHADER_TYPES
];
141 struct nouveau_stateobj
*vertprog
;
142 struct nouveau_stateobj
*fragprog
;
143 struct nouveau_stateobj
*geomprog
;
144 struct nouveau_stateobj
*fp_linkage
;
145 struct nouveau_stateobj
*gp_linkage
;
146 struct nouveau_stateobj
*vtxfmt
;
147 struct nouveau_stateobj
*vtxbuf
;
148 struct nouveau_stateobj
*vtxattr
;
149 struct nouveau_stateobj
*instbuf
;
153 struct nv50_context
{
154 struct pipe_context pipe
;
156 struct nv50_screen
*screen
;
158 struct draw_context
*draw
;
160 struct nv50_state state
;
163 struct nv50_blend_stateobj
*blend
;
164 struct nv50_zsa_stateobj
*zsa
;
165 struct nv50_rasterizer_stateobj
*rasterizer
;
166 struct pipe_blend_color blend_colour
;
167 struct pipe_stencil_ref stencil_ref
;
168 struct pipe_poly_stipple stipple
;
169 struct pipe_scissor_state scissor
;
170 struct pipe_viewport_state viewport
;
171 struct pipe_framebuffer_state framebuffer
;
172 struct nv50_program
*vertprog
;
173 struct nv50_program
*fragprog
;
174 struct nv50_program
*geomprog
;
175 struct pipe_buffer
*constbuf
[PIPE_SHADER_TYPES
];
176 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
178 struct nv50_vtxelt_stateobj
*vtxelt
;
179 struct nv50_sampler_stateobj
*sampler
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
180 unsigned sampler_nr
[PIPE_SHADER_TYPES
];
181 struct nv50_miptree
*miptree
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
182 unsigned miptree_nr
[PIPE_SHADER_TYPES
];
187 static INLINE
struct nv50_context
*
188 nv50_context(struct pipe_context
*pipe
)
190 return (struct nv50_context
*)pipe
;
193 extern void nv50_init_surface_functions(struct nv50_context
*nv50
);
194 extern void nv50_init_state_functions(struct nv50_context
*nv50
);
195 extern void nv50_init_query_functions(struct nv50_context
*nv50
);
197 extern void nv50_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
200 nv50_surface_do_copy(struct nv50_screen
*screen
, struct pipe_surface
*dst
,
201 int dx
, int dy
, struct pipe_surface
*src
, int sx
, int sy
,
205 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*nv50
);
208 extern void nv50_draw_arrays(struct pipe_context
*, unsigned mode
,
209 unsigned start
, unsigned count
);
210 extern void nv50_draw_arrays_instanced(struct pipe_context
*, unsigned mode
,
211 unsigned start
, unsigned count
,
212 unsigned startInstance
,
213 unsigned instanceCount
);
214 extern void nv50_draw_elements(struct pipe_context
*pipe
,
215 struct pipe_buffer
*indexBuffer
,
217 unsigned mode
, unsigned start
,
219 extern void nv50_draw_elements_instanced(struct pipe_context
*pipe
,
220 struct pipe_buffer
*indexBuffer
,
222 unsigned mode
, unsigned start
,
224 unsigned startInstance
,
225 unsigned instanceCount
);
226 extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj
*cso
);
227 extern void nv50_vbo_validate(struct nv50_context
*nv50
);
230 extern void nv50_clear(struct pipe_context
*pipe
, unsigned buffers
,
231 const float *rgba
, double depth
, unsigned stencil
);
234 extern void nv50_vertprog_validate(struct nv50_context
*nv50
);
235 extern void nv50_fragprog_validate(struct nv50_context
*nv50
);
236 extern void nv50_geomprog_validate(struct nv50_context
*nv50
);
237 extern void nv50_fp_linkage_validate(struct nv50_context
*nv50
);
238 extern void nv50_gp_linkage_validate(struct nv50_context
*nv50
);
239 extern void nv50_program_destroy(struct nv50_context
*nv50
,
240 struct nv50_program
*p
);
242 /* nv50_state_validate.c */
243 extern boolean
nv50_state_validate(struct nv50_context
*nv50
);
244 extern void nv50_state_flush_notify(struct nouveau_channel
*chan
);
246 extern void nv50_so_init_sifc(struct nv50_context
*nv50
,
247 struct nouveau_stateobj
*so
,
248 struct nouveau_bo
*bo
, unsigned reloc
,
249 unsigned offset
, unsigned size
);
252 extern void nv50_tex_validate(struct nv50_context
*);
254 /* nv50_transfer.c */
256 nv50_upload_sifc(struct nv50_context
*nv50
,
257 struct nouveau_bo
*bo
, unsigned dst_offset
, unsigned reloc
,
258 unsigned dst_format
, int dst_w
, int dst_h
, int dst_pitch
,
259 void *src
, unsigned src_format
, int src_pitch
,
260 int x
, int y
, int w
, int h
, int cpp
);
263 struct pipe_context
*
264 nv50_create(struct pipe_screen
*pscreen
, void *priv
);