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"
9 #include "util/u_memory.h"
10 #include "util/u_math.h"
11 #include "util/u_inlines.h"
12 #include "util/u_dynarray.h"
14 #include "draw/draw_vertex.h"
16 #include "nv50_winsys.h"
17 #include "nv50_stateobj.h"
18 #include "nv50_screen.h"
19 #include "nv50_program.h"
20 #include "nv50_resource.h"
22 #include "nouveau/nouveau_context.h"
23 #include "nouveau/nv_object.xml.h"
24 #include "nouveau/nv_m2mf.xml.h"
25 #include "nv50_3ddefs.xml.h"
26 #include "nv50_3d.xml.h"
27 #include "nv50_2d.xml.h"
29 #define NOUVEAU_ERR(fmt, args...) \
30 fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args);
33 # define NOUVEAU_DBG(args...) printf(args);
35 # define NOUVEAU_DBG(args...)
38 #define NV50_NEW_BLEND (1 << 0)
39 #define NV50_NEW_RASTERIZER (1 << 1)
40 #define NV50_NEW_ZSA (1 << 2)
41 #define NV50_NEW_VERTPROG (1 << 3)
42 #define NV50_NEW_GMTYPROG (1 << 6)
43 #define NV50_NEW_FRAGPROG (1 << 7)
44 #define NV50_NEW_BLEND_COLOUR (1 << 8)
45 #define NV50_NEW_STENCIL_REF (1 << 9)
46 #define NV50_NEW_CLIP (1 << 10)
47 #define NV50_NEW_SAMPLE_MASK (1 << 11)
48 #define NV50_NEW_FRAMEBUFFER (1 << 12)
49 #define NV50_NEW_STIPPLE (1 << 13)
50 #define NV50_NEW_SCISSOR (1 << 14)
51 #define NV50_NEW_VIEWPORT (1 << 15)
52 #define NV50_NEW_ARRAYS (1 << 16)
53 #define NV50_NEW_VERTEX (1 << 17)
54 #define NV50_NEW_CONSTBUF (1 << 18)
55 #define NV50_NEW_TEXTURES (1 << 19)
56 #define NV50_NEW_SAMPLERS (1 << 20)
58 #define NV50_BUFCTX_CONSTANT 0
59 #define NV50_BUFCTX_FRAME 1
60 #define NV50_BUFCTX_VERTEX 2
61 #define NV50_BUFCTX_TEXTURES 3
62 #define NV50_BUFCTX_COUNT 4
64 /* fixed constant buffer binding points - low indices for user's constbufs */
65 #define NV50_CB_PVP 124
66 #define NV50_CB_PGP 126
67 #define NV50_CB_PFP 125
68 #define NV50_CB_AUX 127
71 struct nouveau_context base
;
73 struct nv50_screen
*screen
;
75 struct util_dynarray residents
[NV50_BUFCTX_COUNT
];
80 uint32_t instance_elts
; /* bitmask of per-instance elements */
81 uint32_t instance_base
;
86 uint8_t num_textures
[3];
87 uint8_t num_samplers
[3];
91 struct nv50_blend_stateobj
*blend
;
92 struct nv50_rasterizer_stateobj
*rast
;
93 struct nv50_zsa_stateobj
*zsa
;
94 struct nv50_vertex_stateobj
*vertex
;
96 struct nv50_program
*vertprog
;
97 struct nv50_program
*gmtyprog
;
98 struct nv50_program
*fragprog
;
100 struct pipe_resource
*constbuf
[3][16];
101 uint16_t constbuf_dirty
[3];
103 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
104 unsigned num_vtxbufs
;
105 struct pipe_index_buffer idxbuf
;
106 uint32_t vbo_fifo
; /* bitmask of vertex elements to be pushed to FIFO */
107 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
108 unsigned vbo_min_index
; /* from pipe_draw_info, for vertex upload */
109 unsigned vbo_max_index
;
111 struct pipe_sampler_view
*textures
[3][PIPE_MAX_SAMPLERS
];
112 unsigned num_textures
[3];
113 struct nv50_tsc_entry
*samplers
[3][PIPE_MAX_SAMPLERS
];
114 unsigned num_samplers
[3];
116 struct pipe_framebuffer_state framebuffer
;
117 struct pipe_blend_color blend_colour
;
118 struct pipe_stencil_ref stencil_ref
;
119 struct pipe_poly_stipple stipple
;
120 struct pipe_scissor_state scissor
;
121 struct pipe_viewport_state viewport
;
122 struct pipe_clip_state clip
;
124 unsigned sample_mask
;
126 boolean vbo_push_hint
;
128 struct draw_context
*draw
;
131 static INLINE
struct nv50_context
*
132 nv50_context(struct pipe_context
*pipe
)
134 return (struct nv50_context
*)pipe
;
137 struct nv50_surface
{
138 struct pipe_surface base
;
145 static INLINE
struct nv50_surface
*
146 nv50_surface(struct pipe_surface
*ps
)
148 return (struct nv50_surface
*)ps
;
152 struct pipe_context
*nv50_create(struct pipe_screen
*, void *);
154 void nv50_default_flush_notify(struct nouveau_channel
*);
156 void nv50_bufctx_emit_relocs(struct nv50_context
*);
157 void nv50_bufctx_add_resident(struct nv50_context
*, int ctx
,
158 struct nv04_resource
*, uint32_t flags
);
159 void nv50_bufctx_del_resident(struct nv50_context
*, int ctx
,
160 struct nv04_resource
*);
162 nv50_bufctx_reset(struct nv50_context
*nv50
, int ctx
)
164 util_dynarray_resize(&nv50
->residents
[ctx
], 0);
168 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*);
171 boolean
nv50_program_translate(struct nv50_program
*);
172 void nv50_program_destroy(struct nv50_context
*, struct nv50_program
*);
175 void nv50_init_query_functions(struct nv50_context
*);
177 /* nv50_shader_state.c */
178 void nv50_vertprog_validate(struct nv50_context
*);
179 void nv50_gmtyprog_validate(struct nv50_context
*);
180 void nv50_fragprog_validate(struct nv50_context
*);
181 void nv50_fp_linkage_validate(struct nv50_context
*);
182 void nv50_gp_linkage_validate(struct nv50_context
*);
183 void nv50_constbufs_validate(struct nv50_context
*);
186 extern void nv50_init_state_functions(struct nv50_context
*);
188 /* nv50_state_validate.c */
189 extern boolean
nv50_state_validate(struct nv50_context
*);
192 extern void nv50_clear(struct pipe_context
*, unsigned buffers
,
193 const float *rgba
, double depth
, unsigned stencil
);
194 extern void nv50_init_surface_functions(struct nv50_context
*);
197 void nv50_validate_textures(struct nv50_context
*);
198 void nv50_validate_samplers(struct nv50_context
*);
200 struct pipe_sampler_view
*
201 nv50_create_sampler_view(struct pipe_context
*,
202 struct pipe_resource
*,
203 const struct pipe_sampler_view
*);
205 /* nv50_transfer.c */
207 nv50_sifc_linear_u8(struct nouveau_context
*pipe
,
208 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
209 unsigned size
, void *data
);
211 nv50_m2mf_copy_linear(struct nouveau_context
*pipe
,
212 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
213 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
217 void nv50_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
220 nv50_vertex_state_create(struct pipe_context
*pipe
,
221 unsigned num_elements
,
222 const struct pipe_vertex_element
*elements
);
224 nv50_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
226 void nv50_vertex_arrays_validate(struct nv50_context
*nv50
);
229 void nv50_push_vbo(struct nv50_context
*, const struct pipe_draw_info
*);