svga: check for and skip null vertex buffer pointers
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.h
1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_CONTEXT_H__
3
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7
8 #include "util/u_memory.h"
9 #include "util/u_math.h"
10 #include "util/u_inlines.h"
11 #include "util/u_dynarray.h"
12
13 #ifdef NV50_WITH_DRAW_MODULE
14 #include "draw/draw_vertex.h"
15 #endif
16
17 #include "nv50_debug.h"
18 #include "nv50_winsys.h"
19 #include "nv50_stateobj.h"
20 #include "nv50_screen.h"
21 #include "nv50_program.h"
22 #include "nv50_resource.h"
23 #include "nv50_transfer.h"
24
25 #include "nouveau/nouveau_context.h"
26 #include "nouveau/nv_object.xml.h"
27 #include "nouveau/nv_m2mf.xml.h"
28 #include "nv50_3ddefs.xml.h"
29 #include "nv50_3d.xml.h"
30 #include "nv50_2d.xml.h"
31
32 #define NV50_NEW_BLEND (1 << 0)
33 #define NV50_NEW_RASTERIZER (1 << 1)
34 #define NV50_NEW_ZSA (1 << 2)
35 #define NV50_NEW_VERTPROG (1 << 3)
36 #define NV50_NEW_GMTYPROG (1 << 6)
37 #define NV50_NEW_FRAGPROG (1 << 7)
38 #define NV50_NEW_BLEND_COLOUR (1 << 8)
39 #define NV50_NEW_STENCIL_REF (1 << 9)
40 #define NV50_NEW_CLIP (1 << 10)
41 #define NV50_NEW_SAMPLE_MASK (1 << 11)
42 #define NV50_NEW_FRAMEBUFFER (1 << 12)
43 #define NV50_NEW_STIPPLE (1 << 13)
44 #define NV50_NEW_SCISSOR (1 << 14)
45 #define NV50_NEW_VIEWPORT (1 << 15)
46 #define NV50_NEW_ARRAYS (1 << 16)
47 #define NV50_NEW_VERTEX (1 << 17)
48 #define NV50_NEW_CONSTBUF (1 << 18)
49 #define NV50_NEW_TEXTURES (1 << 19)
50 #define NV50_NEW_SAMPLERS (1 << 20)
51 #define NV50_NEW_CONTEXT (1 << 31)
52
53 #define NV50_BIND_FB 0
54 #define NV50_BIND_VERTEX 1
55 #define NV50_BIND_VERTEX_TMP 2
56 #define NV50_BIND_INDEX 3
57 #define NV50_BIND_TEXTURES 4
58 #define NV50_BIND_CB(s, i) (5 + 16 * (s) + (i))
59 #define NV50_BIND_SCREEN 53
60 #define NV50_BIND_TLS 54
61 #define NV50_BIND_COUNT 55
62 #define NV50_BIND_2D 0
63 #define NV50_BIND_M2MF 0
64 #define NV50_BIND_FENCE 1
65
66 #define NV50_CB_TMP 123
67 /* fixed constant buffer binding points - low indices for user's constbufs */
68 #define NV50_CB_PVP 124
69 #define NV50_CB_PGP 126
70 #define NV50_CB_PFP 125
71 #define NV50_CB_AUX 127
72
73
74 struct nv50_context {
75 struct nouveau_context base;
76
77 struct nv50_screen *screen;
78
79 struct nouveau_bufctx *bufctx_3d;
80 struct nouveau_bufctx *bufctx;
81
82 uint32_t dirty;
83
84 struct {
85 uint32_t instance_elts; /* bitmask of per-instance elements */
86 uint32_t instance_base;
87 uint32_t interpolant_ctrl;
88 uint32_t semantic_color;
89 uint32_t semantic_psize;
90 int32_t index_bias;
91 boolean prim_restart;
92 boolean point_sprite;
93 boolean rt_serialize;
94 boolean flushed;
95 uint8_t tls_required;
96 uint8_t num_vtxbufs;
97 uint8_t num_vtxelts;
98 uint8_t num_textures[3];
99 uint8_t num_samplers[3];
100 uint16_t scissor;
101 } state;
102
103 struct nv50_blend_stateobj *blend;
104 struct nv50_rasterizer_stateobj *rast;
105 struct nv50_zsa_stateobj *zsa;
106 struct nv50_vertex_stateobj *vertex;
107
108 struct nv50_program *vertprog;
109 struct nv50_program *gmtyprog;
110 struct nv50_program *fragprog;
111
112 struct pipe_resource *constbuf[3][16];
113 uint16_t constbuf_dirty[3];
114 uint16_t constbuf_valid[3];
115
116 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
117 unsigned num_vtxbufs;
118 struct pipe_index_buffer idxbuf;
119 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
120 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
121 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
122 uint32_t vb_elt_limit; /* max - min element (count - 1) */
123
124 struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS];
125 unsigned num_textures[3];
126 struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
127 unsigned num_samplers[3];
128
129 struct pipe_framebuffer_state framebuffer;
130 struct pipe_blend_color blend_colour;
131 struct pipe_stencil_ref stencil_ref;
132 struct pipe_poly_stipple stipple;
133 struct pipe_scissor_state scissor;
134 struct pipe_viewport_state viewport;
135 struct pipe_clip_state clip;
136
137 unsigned sample_mask;
138
139 boolean vbo_push_hint;
140
141 #ifdef NV50_WITH_DRAW_MODULE
142 struct draw_context *draw;
143 #endif
144 };
145
146 static INLINE struct nv50_context *
147 nv50_context(struct pipe_context *pipe)
148 {
149 return (struct nv50_context *)pipe;
150 }
151
152 static INLINE struct nv50_screen *
153 nv50_context_screen(struct nv50_context *nv50)
154 {
155 return nv50_screen(&nv50->base.screen->base);
156 }
157
158
159 /* nv50_context.c */
160 struct pipe_context *nv50_create(struct pipe_screen *, void *);
161
162 void nv50_bufctx_fence(struct nouveau_bufctx *, boolean on_flush);
163
164 void nv50_default_kick_notify(struct nouveau_pushbuf *);
165
166 /* nv50_draw.c */
167 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
168
169 /* nv50_query.c */
170 void nv50_init_query_functions(struct nv50_context *);
171
172 /* nv50_shader_state.c */
173 void nv50_vertprog_validate(struct nv50_context *);
174 void nv50_gmtyprog_validate(struct nv50_context *);
175 void nv50_fragprog_validate(struct nv50_context *);
176 void nv50_fp_linkage_validate(struct nv50_context *);
177 void nv50_gp_linkage_validate(struct nv50_context *);
178 void nv50_constbufs_validate(struct nv50_context *);
179 void nv50_validate_derived_rs(struct nv50_context *);
180
181 /* nv50_state.c */
182 extern void nv50_init_state_functions(struct nv50_context *);
183
184 /* nv50_state_validate.c */
185 /* @words: check for space before emitting relocs */
186 extern boolean nv50_state_validate(struct nv50_context *, uint32_t state_mask,
187 unsigned space_words);
188
189 /* nv50_surface.c */
190 extern void nv50_clear(struct pipe_context *, unsigned buffers,
191 const union pipe_color_union *color,
192 double depth, unsigned stencil);
193 extern void nv50_init_surface_functions(struct nv50_context *);
194
195 /* nv50_tex.c */
196 void nv50_validate_textures(struct nv50_context *);
197 void nv50_validate_samplers(struct nv50_context *);
198
199 struct pipe_sampler_view *
200 nv50_create_sampler_view(struct pipe_context *,
201 struct pipe_resource *,
202 const struct pipe_sampler_view *);
203
204 /* nv50_transfer.c */
205 void
206 nv50_m2mf_transfer_rect(struct nv50_context *,
207 const struct nv50_m2mf_rect *dst,
208 const struct nv50_m2mf_rect *src,
209 uint32_t nblocksx, uint32_t nblocksy);
210 void
211 nv50_sifc_linear_u8(struct nouveau_context *pipe,
212 struct nouveau_bo *dst, unsigned offset, unsigned domain,
213 unsigned size, const void *data);
214 void
215 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
216 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
217 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
218 unsigned size);
219 void
220 nv50_cb_push(struct nouveau_context *nv,
221 struct nouveau_bo *bo, unsigned domain,
222 unsigned base, unsigned size,
223 unsigned offset, unsigned words, const uint32_t *data);
224
225 /* nv50_vbo.c */
226 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
227
228 void *
229 nv50_vertex_state_create(struct pipe_context *pipe,
230 unsigned num_elements,
231 const struct pipe_vertex_element *elements);
232 void
233 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
234
235 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
236
237 /* nv50_push.c */
238 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
239
240 #endif