nvc0: improve vertex state validation
[mesa.git] / src / gallium / drivers / nvc0 / nvc0_context.h
1 #ifndef __NVC0_CONTEXT_H__
2 #define __NVC0_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 #include "draw/draw_vertex.h"
14
15 #include "nv50/nv50_debug.h"
16 #include "nvc0_winsys.h"
17 #include "nvc0_stateobj.h"
18 #include "nvc0_screen.h"
19 #include "nvc0_program.h"
20 #include "nvc0_resource.h"
21
22 #include "nv50/nv50_transfer.h"
23
24 #include "nouveau/nouveau_context.h"
25
26 #include "nvc0_3ddefs.xml.h"
27 #include "nvc0_3d.xml.h"
28 #include "nvc0_2d.xml.h"
29 #include "nvc0_m2mf.xml.h"
30
31 #define NVC0_NEW_BLEND (1 << 0)
32 #define NVC0_NEW_RASTERIZER (1 << 1)
33 #define NVC0_NEW_ZSA (1 << 2)
34 #define NVC0_NEW_VERTPROG (1 << 3)
35 #define NVC0_NEW_TCTLPROG (1 << 4)
36 #define NVC0_NEW_TEVLPROG (1 << 5)
37 #define NVC0_NEW_GMTYPROG (1 << 6)
38 #define NVC0_NEW_FRAGPROG (1 << 7)
39 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
40 #define NVC0_NEW_STENCIL_REF (1 << 9)
41 #define NVC0_NEW_CLIP (1 << 10)
42 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
43 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
44 #define NVC0_NEW_STIPPLE (1 << 13)
45 #define NVC0_NEW_SCISSOR (1 << 14)
46 #define NVC0_NEW_VIEWPORT (1 << 15)
47 #define NVC0_NEW_ARRAYS (1 << 16)
48 #define NVC0_NEW_VERTEX (1 << 17)
49 #define NVC0_NEW_CONSTBUF (1 << 18)
50 #define NVC0_NEW_TEXTURES (1 << 19)
51 #define NVC0_NEW_SAMPLERS (1 << 20)
52 #define NVC0_NEW_TFB_TARGETS (1 << 21)
53 #define NVC0_NEW_IDXBUF (1 << 22)
54
55 #define NVC0_BIND_FB 0
56 #define NVC0_BIND_VTX 1
57 #define NVC0_BIND_VTX_TMP 2
58 #define NVC0_BIND_IDX 3
59 #define NVC0_BIND_TEX(s, i) ( 4 + 32 * (s) + (i))
60 #define NVC0_BIND_CB(s, i) (164 + 16 * (s) + (i))
61 #define NVC0_BIND_TFB 244
62 #define NVC0_BIND_SCREEN 245
63 #define NVC0_BIND_TLS 246
64 #define NVC0_BIND_COUNT 247
65
66 #define NVC0_BIND_2D 0
67 #define NVC0_BIND_M2MF 0
68 #define NVC0_BIND_FENCE 1
69
70 struct nvc0_context {
71 struct nouveau_context base;
72
73 struct nouveau_bufctx *bufctx_3d;
74 struct nouveau_bufctx *bufctx;
75
76 struct nvc0_screen *screen;
77
78 uint32_t dirty;
79
80 struct {
81 boolean flushed;
82 boolean rasterizer_discard;
83 boolean early_z_forced;
84 boolean prim_restart;
85 uint32_t instance_elts; /* bitmask of per-instance elements */
86 uint32_t instance_base;
87 uint32_t constant_vbos;
88 uint32_t constant_elts;
89 int32_t index_bias;
90 uint16_t scissor;
91 uint8_t num_vtxbufs;
92 uint8_t num_vtxelts;
93 uint8_t num_textures[5];
94 uint8_t num_samplers[5];
95 uint8_t tls_required; /* bitmask of shader types using l[] */
96 uint8_t c14_bound; /* whether immediate array constbuf is bound */
97 uint8_t clip_enable;
98 uint32_t clip_mode;
99 uint32_t uniform_buffer_bound[5];
100 struct nvc0_transform_feedback_state *tfb;
101 } state;
102
103 struct nvc0_blend_stateobj *blend;
104 struct nvc0_rasterizer_stateobj *rast;
105 struct nvc0_zsa_stateobj *zsa;
106 struct nvc0_vertex_stateobj *vertex;
107
108 struct nvc0_program *vertprog;
109 struct nvc0_program *tctlprog;
110 struct nvc0_program *tevlprog;
111 struct nvc0_program *gmtyprog;
112 struct nvc0_program *fragprog;
113
114 struct pipe_resource *constbuf[5][16];
115 uint16_t constbuf_dirty[5];
116
117 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
118 unsigned num_vtxbufs;
119 struct pipe_index_buffer idxbuf;
120 uint32_t constant_vbos;
121 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
122 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
123 unsigned vbo_min_index; /* from pipe_draw_info, for vertex upload */
124 unsigned vbo_max_index;
125
126 struct pipe_sampler_view *textures[5][PIPE_MAX_SAMPLERS];
127 unsigned num_textures[5];
128 uint32_t textures_dirty[5];
129 struct nv50_tsc_entry *samplers[5][PIPE_MAX_SAMPLERS];
130 unsigned num_samplers[5];
131 uint16_t samplers_dirty[5];
132
133 struct pipe_framebuffer_state framebuffer;
134 struct pipe_blend_color blend_colour;
135 struct pipe_stencil_ref stencil_ref;
136 struct pipe_poly_stipple stipple;
137 struct pipe_scissor_state scissor;
138 struct pipe_viewport_state viewport;
139 struct pipe_clip_state clip;
140
141 unsigned sample_mask;
142
143 boolean vbo_push_hint;
144
145 uint8_t tfbbuf_dirty;
146 struct pipe_stream_output_target *tfbbuf[4];
147 unsigned num_tfbbufs;
148
149 struct draw_context *draw;
150 };
151
152 static INLINE struct nvc0_context *
153 nvc0_context(struct pipe_context *pipe)
154 {
155 return (struct nvc0_context *)pipe;
156 }
157
158 /* nvc0_context.c */
159 struct pipe_context *nvc0_create(struct pipe_screen *, void *);
160 void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
161 boolean on_flush);
162 void nvc0_default_kick_notify(struct nouveau_pushbuf *);
163
164 /* nvc0_draw.c */
165 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
166
167 /* nvc0_program.c */
168 boolean nvc0_program_translate(struct nvc0_program *);
169 boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
170 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
171 void nvc0_program_library_upload(struct nvc0_context *);
172
173 /* nvc0_query.c */
174 void nvc0_init_query_functions(struct nvc0_context *);
175 void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *,
176 struct pipe_query *, unsigned result_offset);
177 void nvc0_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
178 void nvc0_so_target_save_offset(struct pipe_context *,
179 struct pipe_stream_output_target *, unsigned i,
180 boolean *serialize);
181
182 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
183
184 /* nvc0_shader_state.c */
185 void nvc0_vertprog_validate(struct nvc0_context *);
186 void nvc0_tctlprog_validate(struct nvc0_context *);
187 void nvc0_tevlprog_validate(struct nvc0_context *);
188 void nvc0_gmtyprog_validate(struct nvc0_context *);
189 void nvc0_fragprog_validate(struct nvc0_context *);
190
191 void nvc0_tfb_validate(struct nvc0_context *);
192
193 /* nvc0_state.c */
194 extern void nvc0_init_state_functions(struct nvc0_context *);
195
196 /* nvc0_state_validate.c */
197 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
198 unsigned space_words);
199
200 /* nvc0_surface.c */
201 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
202 const union pipe_color_union *color,
203 double depth, unsigned stencil);
204 extern void nvc0_init_surface_functions(struct nvc0_context *);
205
206 /* nvc0_tex.c */
207 void nvc0_validate_textures(struct nvc0_context *);
208 void nvc0_validate_samplers(struct nvc0_context *);
209
210 struct pipe_sampler_view *
211 nvc0_create_sampler_view(struct pipe_context *,
212 struct pipe_resource *,
213 const struct pipe_sampler_view *);
214
215 /* nvc0_transfer.c */
216 void
217 nvc0_m2mf_transfer_rect(struct nvc0_context *,
218 const struct nv50_m2mf_rect *dst,
219 const struct nv50_m2mf_rect *src,
220 uint32_t nblocksx, uint32_t nblocksy);
221 void
222 nvc0_m2mf_push_linear(struct nouveau_context *nv,
223 struct nouveau_bo *dst, unsigned offset, unsigned domain,
224 unsigned size, const void *data);
225 void
226 nvc0_m2mf_copy_linear(struct nouveau_context *nv,
227 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
228 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
229 unsigned size);
230 void
231 nvc0_cb_push(struct nouveau_context *,
232 struct nouveau_bo *bo, unsigned domain,
233 unsigned base, unsigned size,
234 unsigned offset, unsigned words, const uint32_t *data);
235
236 /* nvc0_vbo.c */
237 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
238
239 void *
240 nvc0_vertex_state_create(struct pipe_context *pipe,
241 unsigned num_elements,
242 const struct pipe_vertex_element *elements);
243 void
244 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
245
246 void nvc0_vertex_arrays_validate(struct nvc0_context *);
247
248 void nvc0_idxbuf_validate(struct nvc0_context *);
249
250 /* nvc0_push.c */
251 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
252
253 #endif