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 #define nouveau_bo_tile_layout(nvbo) \
30 ((nvbo)->tile_flags & NOUVEAU_BO_TILE_LAYOUT_MASK)
32 /* Constant buffer assignment */
33 #define NV50_CB_PMISC 0
39 #define NV50_NEW_BLEND (1 << 0)
40 #define NV50_NEW_ZSA (1 << 1)
41 #define NV50_NEW_BLEND_COLOUR (1 << 2)
42 #define NV50_NEW_STIPPLE (1 << 3)
43 #define NV50_NEW_SCISSOR (1 << 4)
44 #define NV50_NEW_VIEWPORT (1 << 5)
45 #define NV50_NEW_RASTERIZER (1 << 6)
46 #define NV50_NEW_FRAMEBUFFER (1 << 7)
47 #define NV50_NEW_VERTPROG (1 << 8)
48 #define NV50_NEW_VERTPROG_CB (1 << 9)
49 #define NV50_NEW_FRAGPROG (1 << 10)
50 #define NV50_NEW_FRAGPROG_CB (1 << 11)
51 #define NV50_NEW_GEOMPROG (1 << 12)
52 #define NV50_NEW_GEOMPROG_CB (1 << 13)
53 #define NV50_NEW_ARRAYS (1 << 14)
54 #define NV50_NEW_SAMPLER (1 << 15)
55 #define NV50_NEW_TEXTURE (1 << 16)
56 #define NV50_NEW_STENCIL_REF (1 << 17)
57 #define NV50_NEW_CLIP (1 << 18)
59 struct nv50_blend_stateobj
{
60 struct pipe_blend_state pipe
;
61 struct nouveau_stateobj
*so
;
64 struct nv50_zsa_stateobj
{
65 struct pipe_depth_stencil_alpha_state pipe
;
66 struct nouveau_stateobj
*so
;
69 struct nv50_rasterizer_stateobj
{
70 struct pipe_rasterizer_state pipe
;
71 struct nouveau_stateobj
*so
;
74 struct nv50_sampler_stateobj
{
79 struct nv50_sampler_view
{
80 struct pipe_sampler_view pipe
;
84 struct nv50_vtxelt_stateobj
{
85 struct pipe_vertex_element pipe
[16];
86 unsigned num_elements
;
90 static INLINE
struct nv50_sampler_view
*
91 nv50_sampler_view(struct pipe_sampler_view
*view
)
93 return (struct nv50_sampler_view
*)view
;
96 static INLINE
unsigned
97 get_tile_height(uint32_t tile_mode
)
99 return 1 << ((tile_mode
& 0xf) + 2);
102 static INLINE
unsigned
103 get_tile_depth(uint32_t tile_mode
)
105 return 1 << (tile_mode
>> 4);
109 struct nv50_surface
{
110 struct pipe_surface base
;
114 static INLINE
struct nv50_surface
*
115 nv50_surface(struct pipe_surface
*pt
)
117 return (struct nv50_surface
*)pt
;
121 struct nouveau_stateobj
*hw
[64];
124 unsigned sampler_view_nr
[3];
125 struct nouveau_stateobj
*vtxbuf
;
126 struct nouveau_stateobj
*vtxattr
;
130 struct nv50_context
{
131 struct pipe_context pipe
;
133 struct nv50_screen
*screen
;
135 struct draw_context
*draw
;
137 struct nv50_state state
;
140 struct nv50_blend_stateobj
*blend
;
141 struct nv50_zsa_stateobj
*zsa
;
142 struct nv50_rasterizer_stateobj
*rasterizer
;
143 struct pipe_blend_color blend_colour
;
144 struct pipe_stencil_ref stencil_ref
;
145 struct pipe_poly_stipple stipple
;
146 struct pipe_scissor_state scissor
;
147 struct pipe_viewport_state viewport
;
148 struct pipe_framebuffer_state framebuffer
;
149 struct pipe_clip_state clip
;
150 struct nv50_program
*vertprog
;
151 struct nv50_program
*fragprog
;
152 struct nv50_program
*geomprog
;
153 struct pipe_resource
*constbuf
[PIPE_SHADER_TYPES
];
154 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
156 struct pipe_index_buffer idxbuf
;
157 struct nv50_vtxelt_stateobj
*vtxelt
;
158 struct nv50_sampler_stateobj
*sampler
[3][PIPE_MAX_SAMPLERS
];
159 unsigned sampler_nr
[3];
160 struct pipe_sampler_view
*sampler_views
[3][PIPE_MAX_SAMPLERS
];
161 unsigned sampler_view_nr
[3];
167 static INLINE
struct nv50_context
*
168 nv50_context(struct pipe_context
*pipe
)
170 return (struct nv50_context
*)pipe
;
173 extern void nv50_init_surface_functions(struct nv50_context
*nv50
);
174 extern void nv50_init_state_functions(struct nv50_context
*nv50
);
175 extern void nv50_init_query_functions(struct nv50_context
*nv50
);
176 extern void nv50_init_transfer_functions(struct nv50_context
*nv50
);
178 extern void nv50_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
181 nv50_surface_do_copy(struct nv50_screen
*screen
, struct pipe_surface
*dst
,
182 int dx
, int dy
, struct pipe_surface
*src
, int sx
, int sy
,
186 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*nv50
);
189 extern void nv50_draw_vbo(struct pipe_context
*pipe
,
190 const struct pipe_draw_info
*info
);
191 extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj
*cso
);
192 extern struct nouveau_stateobj
*nv50_vbo_validate(struct nv50_context
*nv50
);
196 nv50_push_elements_instanced(struct pipe_context
*, struct pipe_resource
*,
197 unsigned idxsize
, int idxbias
,
198 unsigned mode
, unsigned start
,
199 unsigned count
, unsigned i_start
,
203 extern void nv50_clear(struct pipe_context
*pipe
, unsigned buffers
,
204 const float *rgba
, double depth
, unsigned stencil
);
207 extern struct nouveau_stateobj
*
208 nv50_vertprog_validate(struct nv50_context
*nv50
);
209 extern struct nouveau_stateobj
*
210 nv50_fragprog_validate(struct nv50_context
*nv50
);
211 extern struct nouveau_stateobj
*
212 nv50_geomprog_validate(struct nv50_context
*nv50
);
213 extern struct nouveau_stateobj
*
214 nv50_fp_linkage_validate(struct nv50_context
*nv50
);
215 extern struct nouveau_stateobj
*
216 nv50_gp_linkage_validate(struct nv50_context
*nv50
);
217 extern void nv50_program_destroy(struct nv50_context
*nv50
,
218 struct nv50_program
*p
);
220 /* nv50_state_validate.c */
221 extern boolean
nv50_state_validate(struct nv50_context
*nv50
, unsigned dwords
);
223 extern void nv50_so_init_sifc(struct nv50_context
*nv50
,
224 struct nouveau_stateobj
*so
,
225 struct nouveau_bo
*bo
, unsigned reloc
,
226 unsigned offset
, unsigned size
);
229 extern boolean
nv50_tex_construct(struct nv50_sampler_view
*view
);
230 extern void nv50_tex_relocs(struct nv50_context
*);
231 extern struct nouveau_stateobj
*nv50_tex_validate(struct nv50_context
*);
235 struct pipe_context
*
236 nv50_create(struct pipe_screen
*pscreen
, void *priv
);
238 static INLINE
unsigned
239 nv50_prim(unsigned mode
)
242 case PIPE_PRIM_POINTS
: return NV50TCL_VERTEX_BEGIN_POINTS
;
243 case PIPE_PRIM_LINES
: return NV50TCL_VERTEX_BEGIN_LINES
;
244 case PIPE_PRIM_LINE_LOOP
: return NV50TCL_VERTEX_BEGIN_LINE_LOOP
;
245 case PIPE_PRIM_LINE_STRIP
: return NV50TCL_VERTEX_BEGIN_LINE_STRIP
;
246 case PIPE_PRIM_TRIANGLES
: return NV50TCL_VERTEX_BEGIN_TRIANGLES
;
247 case PIPE_PRIM_TRIANGLE_STRIP
:
248 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP
;
249 case PIPE_PRIM_TRIANGLE_FAN
: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN
;
250 case PIPE_PRIM_QUADS
: return NV50TCL_VERTEX_BEGIN_QUADS
;
251 case PIPE_PRIM_QUAD_STRIP
: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP
;
252 case PIPE_PRIM_POLYGON
: return NV50TCL_VERTEX_BEGIN_POLYGON
;
253 case PIPE_PRIM_LINES_ADJACENCY
:
254 return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY
;
255 case PIPE_PRIM_LINE_STRIP_ADJACENCY
:
256 return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY
;
257 case PIPE_PRIM_TRIANGLES_ADJACENCY
:
258 return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY
;
259 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
:
260 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY
;
265 NOUVEAU_ERR("invalid primitive type %d\n", mode
);
266 return NV50TCL_VERTEX_BEGIN_POINTS
;