1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_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_stateobj.h"
17 #include "nouveau/nouveau_context.h"
19 #include "nv50_screen.h"
20 #include "nv50_program.h"
22 #define NOUVEAU_ERR(fmt, args...) \
23 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
24 #define NOUVEAU_MSG(fmt, args...) \
25 fprintf(stderr, "nouveau: "fmt, ##args);
27 /* Constant buffer assignment */
28 #define NV50_CB_PMISC 0
34 #define NV50_CB_PUPLOAD 6
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_ARRAYS (1 << 12)
49 #define NV50_NEW_SAMPLER (1 << 13)
50 #define NV50_NEW_TEXTURE (1 << 14)
52 struct nv50_blend_stateobj
{
53 struct pipe_blend_state pipe
;
54 struct nouveau_stateobj
*so
;
57 struct nv50_zsa_stateobj
{
58 struct pipe_depth_stencil_alpha_state pipe
;
59 struct nouveau_stateobj
*so
;
62 struct nv50_rasterizer_stateobj
{
63 struct pipe_rasterizer_state pipe
;
64 struct nouveau_stateobj
*so
;
67 struct nv50_sampler_stateobj
{
72 static INLINE
unsigned
73 get_tile_height(uint32_t tile_mode
)
75 return 1 << ((tile_mode
& 0xf) + 2);
78 static INLINE
unsigned
79 get_tile_depth(uint32_t tile_mode
)
81 return 1 << (tile_mode
>> 4);
84 struct nv50_miptree_level
{
91 struct nouveau_miptree base
;
93 struct nv50_miptree_level level
[PIPE_MAX_TEXTURE_LEVELS
];
98 static INLINE
struct nv50_miptree
*
99 nv50_miptree(struct pipe_texture
*pt
)
101 return (struct nv50_miptree
*)pt
;
104 struct nv50_surface
{
105 struct pipe_surface base
;
108 static INLINE
struct nv50_surface
*
109 nv50_surface(struct pipe_surface
*pt
)
111 return (struct nv50_surface
*)pt
;
117 struct nouveau_stateobj
*fb
;
118 struct nouveau_stateobj
*blend
;
119 struct nouveau_stateobj
*blend_colour
;
120 struct nouveau_stateobj
*zsa
;
121 struct nouveau_stateobj
*rast
;
122 struct nouveau_stateobj
*stipple
;
123 struct nouveau_stateobj
*scissor
;
124 unsigned scissor_enabled
;
125 struct nouveau_stateobj
*viewport
;
126 unsigned viewport_bypass
;
127 struct nouveau_stateobj
*tsc_upload
;
128 struct nouveau_stateobj
*tic_upload
;
130 struct nouveau_stateobj
*vertprog
;
131 struct nouveau_stateobj
*fragprog
;
132 struct nouveau_stateobj
*programs
;
133 struct nouveau_stateobj
*vtxfmt
;
134 struct nouveau_stateobj
*vtxbuf
;
135 struct nouveau_stateobj
*vtxattr
;
139 struct nv50_context
{
140 struct pipe_context pipe
;
142 struct nv50_screen
*screen
;
145 struct draw_context
*draw
;
147 struct nv50_state state
;
150 struct nv50_blend_stateobj
*blend
;
151 struct nv50_zsa_stateobj
*zsa
;
152 struct nv50_rasterizer_stateobj
*rasterizer
;
153 struct pipe_blend_color blend_colour
;
154 struct pipe_poly_stipple stipple
;
155 struct pipe_scissor_state scissor
;
156 struct pipe_viewport_state viewport
;
157 struct pipe_framebuffer_state framebuffer
;
158 struct nv50_program
*vertprog
;
159 struct nv50_program
*fragprog
;
160 struct pipe_buffer
*constbuf
[PIPE_SHADER_TYPES
];
161 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
163 struct pipe_vertex_element vtxelt
[PIPE_MAX_ATTRIBS
];
165 struct nv50_sampler_stateobj
*sampler
[PIPE_MAX_SAMPLERS
];
167 struct nv50_miptree
*miptree
[PIPE_MAX_SAMPLERS
];
173 static INLINE
struct nv50_context
*
174 nv50_context(struct pipe_context
*pipe
)
176 return (struct nv50_context
*)pipe
;
179 extern void nv50_init_surface_functions(struct nv50_context
*nv50
);
180 extern void nv50_init_state_functions(struct nv50_context
*nv50
);
181 extern void nv50_init_query_functions(struct nv50_context
*nv50
);
183 extern void nv50_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
186 nv50_surface_do_copy(struct nv50_screen
*screen
, struct pipe_surface
*dst
,
187 int dx
, int dy
, struct pipe_surface
*src
, int sx
, int sy
,
191 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*nv50
);
194 extern boolean
nv50_draw_arrays(struct pipe_context
*, unsigned mode
,
195 unsigned start
, unsigned count
);
196 extern boolean
nv50_draw_elements(struct pipe_context
*pipe
,
197 struct pipe_buffer
*indexBuffer
,
199 unsigned mode
, unsigned start
,
201 extern void nv50_vbo_validate(struct nv50_context
*nv50
);
204 extern void nv50_clear(struct pipe_context
*pipe
, unsigned buffers
,
205 const float *rgba
, double depth
, unsigned stencil
);
208 extern void nv50_vertprog_validate(struct nv50_context
*nv50
);
209 extern void nv50_fragprog_validate(struct nv50_context
*nv50
);
210 extern void nv50_linkage_validate(struct nv50_context
*nv50
);
211 extern void nv50_program_destroy(struct nv50_context
*nv50
,
212 struct nv50_program
*p
);
214 /* nv50_state_validate.c */
215 extern boolean
nv50_state_validate(struct nv50_context
*nv50
);
216 extern void nv50_state_flush_notify(struct nouveau_channel
*chan
);
218 extern void nv50_so_init_sifc(struct nv50_context
*nv50
,
219 struct nouveau_stateobj
*so
,
220 struct nouveau_bo
*bo
, unsigned reloc
,
224 extern void nv50_tex_validate(struct nv50_context
*);
226 /* nv50_transfer.c */
228 nv50_upload_sifc(struct nv50_context
*nv50
,
229 struct nouveau_bo
*bo
, unsigned dst_offset
, unsigned reloc
,
230 unsigned dst_format
, int dst_w
, int dst_h
, int dst_pitch
,
231 void *src
, unsigned src_format
, int src_pitch
,
232 int x
, int y
, int w
, int h
, int cpp
);