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"
21 #include "nv50_screen.h"
22 #include "nv50_program.h"
24 #define NOUVEAU_ERR(fmt, args...) \
25 fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __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)
54 #define NV50_NEW_CLIP (1 << 18)
56 struct nv50_blend_stateobj
{
57 struct pipe_blend_state pipe
;
58 struct nouveau_stateobj
*so
;
61 struct nv50_zsa_stateobj
{
62 struct pipe_depth_stencil_alpha_state pipe
;
63 struct nouveau_stateobj
*so
;
66 struct nv50_rasterizer_stateobj
{
67 struct pipe_rasterizer_state pipe
;
68 struct nouveau_stateobj
*so
;
71 struct nv50_sampler_stateobj
{
76 struct nv50_sampler_view
{
77 struct pipe_sampler_view pipe
;
81 struct nv50_vtxelt_stateobj
{
82 struct pipe_vertex_element pipe
[16];
83 unsigned num_elements
;
87 static INLINE
struct nv50_sampler_view
*
88 nv50_sampler_view(struct pipe_sampler_view
*view
)
90 return (struct nv50_sampler_view
*)view
;
93 static INLINE
unsigned
94 get_tile_height(uint32_t tile_mode
)
96 return 1 << ((tile_mode
& 0xf) + 2);
99 static INLINE
unsigned
100 get_tile_depth(uint32_t tile_mode
)
102 return 1 << (tile_mode
>> 4);
106 struct nv50_surface
{
107 struct pipe_surface base
;
110 static INLINE
struct nv50_surface
*
111 nv50_surface(struct pipe_surface
*pt
)
113 return (struct nv50_surface
*)pt
;
117 struct nouveau_stateobj
*hw
[64];
120 unsigned sampler_view_nr
[3];
121 struct nouveau_stateobj
*vtxbuf
;
122 struct nouveau_stateobj
*vtxattr
;
126 struct nv50_context
{
127 struct pipe_context pipe
;
129 struct nv50_screen
*screen
;
131 struct draw_context
*draw
;
133 struct nv50_state state
;
136 struct nv50_blend_stateobj
*blend
;
137 struct nv50_zsa_stateobj
*zsa
;
138 struct nv50_rasterizer_stateobj
*rasterizer
;
139 struct pipe_blend_color blend_colour
;
140 struct pipe_stencil_ref stencil_ref
;
141 struct pipe_poly_stipple stipple
;
142 struct pipe_scissor_state scissor
;
143 struct pipe_viewport_state viewport
;
144 struct pipe_framebuffer_state framebuffer
;
145 struct pipe_clip_state clip
;
146 struct nv50_program
*vertprog
;
147 struct nv50_program
*fragprog
;
148 struct nv50_program
*geomprog
;
149 struct pipe_resource
*constbuf
[PIPE_SHADER_TYPES
];
150 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
152 struct pipe_index_buffer idxbuf
;
153 struct nv50_vtxelt_stateobj
*vtxelt
;
154 struct nv50_sampler_stateobj
*sampler
[3][PIPE_MAX_SAMPLERS
];
155 unsigned sampler_nr
[3];
156 struct pipe_sampler_view
*sampler_views
[3][PIPE_MAX_SAMPLERS
];
157 unsigned sampler_view_nr
[3];
162 static INLINE
struct nv50_context
*
163 nv50_context(struct pipe_context
*pipe
)
165 return (struct nv50_context
*)pipe
;
168 extern void nv50_init_surface_functions(struct nv50_context
*nv50
);
169 extern void nv50_init_state_functions(struct nv50_context
*nv50
);
170 extern void nv50_init_query_functions(struct nv50_context
*nv50
);
171 extern void nv50_init_transfer_functions(struct nv50_context
*nv50
);
173 extern void nv50_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
176 nv50_surface_do_copy(struct nv50_screen
*screen
, struct pipe_surface
*dst
,
177 int dx
, int dy
, struct pipe_surface
*src
, int sx
, int sy
,
181 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*nv50
);
184 extern void nv50_draw_vbo(struct pipe_context
*pipe
,
185 const struct pipe_draw_info
*info
);
186 extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj
*cso
);
187 extern struct nouveau_stateobj
*nv50_vbo_validate(struct nv50_context
*nv50
);
191 nv50_push_elements_instanced(struct pipe_context
*, struct pipe_resource
*,
192 unsigned idxsize
, int idxbias
,
193 unsigned mode
, unsigned start
,
194 unsigned count
, unsigned i_start
,
198 extern void nv50_clear(struct pipe_context
*pipe
, unsigned buffers
,
199 const float *rgba
, double depth
, unsigned stencil
);
202 extern struct nouveau_stateobj
*
203 nv50_vertprog_validate(struct nv50_context
*nv50
);
204 extern struct nouveau_stateobj
*
205 nv50_fragprog_validate(struct nv50_context
*nv50
);
206 extern struct nouveau_stateobj
*
207 nv50_geomprog_validate(struct nv50_context
*nv50
);
208 extern struct nouveau_stateobj
*
209 nv50_fp_linkage_validate(struct nv50_context
*nv50
);
210 extern struct nouveau_stateobj
*
211 nv50_gp_linkage_validate(struct nv50_context
*nv50
);
212 extern void nv50_program_destroy(struct nv50_context
*nv50
,
213 struct nv50_program
*p
);
215 /* nv50_state_validate.c */
216 extern boolean
nv50_state_validate(struct nv50_context
*nv50
, unsigned dwords
);
218 extern void nv50_so_init_sifc(struct nv50_context
*nv50
,
219 struct nouveau_stateobj
*so
,
220 struct nouveau_bo
*bo
, unsigned reloc
,
221 unsigned offset
, unsigned size
);
224 extern boolean
nv50_tex_construct(struct nv50_sampler_view
*view
);
225 extern void nv50_tex_relocs(struct nv50_context
*);
226 extern struct nouveau_stateobj
*nv50_tex_validate(struct nv50_context
*);
230 struct pipe_context
*
231 nv50_create(struct pipe_screen
*pscreen
, void *priv
);
233 static INLINE
unsigned
234 nv50_prim(unsigned mode
)
237 case PIPE_PRIM_POINTS
: return NV50TCL_VERTEX_BEGIN_POINTS
;
238 case PIPE_PRIM_LINES
: return NV50TCL_VERTEX_BEGIN_LINES
;
239 case PIPE_PRIM_LINE_LOOP
: return NV50TCL_VERTEX_BEGIN_LINE_LOOP
;
240 case PIPE_PRIM_LINE_STRIP
: return NV50TCL_VERTEX_BEGIN_LINE_STRIP
;
241 case PIPE_PRIM_TRIANGLES
: return NV50TCL_VERTEX_BEGIN_TRIANGLES
;
242 case PIPE_PRIM_TRIANGLE_STRIP
:
243 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP
;
244 case PIPE_PRIM_TRIANGLE_FAN
: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN
;
245 case PIPE_PRIM_QUADS
: return NV50TCL_VERTEX_BEGIN_QUADS
;
246 case PIPE_PRIM_QUAD_STRIP
: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP
;
247 case PIPE_PRIM_POLYGON
: return NV50TCL_VERTEX_BEGIN_POLYGON
;
248 case PIPE_PRIM_LINES_ADJACENCY
:
249 return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY
;
250 case PIPE_PRIM_LINE_STRIP_ADJACENCY
:
251 return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY
;
252 case PIPE_PRIM_TRIANGLES_ADJACENCY
:
253 return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY
;
254 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
:
255 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY
;
260 NOUVEAU_ERR("invalid primitive type %d\n", mode
);
261 return NV50TCL_VERTEX_BEGIN_POINTS
;