gallium: expose ARB_map_buffer_alignment on Radeon
[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 #ifdef NVC0_WITH_DRAW_MODULE
14 #include "draw/draw_vertex.h"
15 #endif
16
17 #include "nv50/nv50_debug.h"
18 #include "nvc0_winsys.h"
19 #include "nvc0_stateobj.h"
20 #include "nvc0_screen.h"
21 #include "nvc0_program.h"
22 #include "nvc0_resource.h"
23
24 #include "nv50/nv50_transfer.h"
25
26 #include "nouveau/nouveau_context.h"
27
28 #include "nvc0_3ddefs.xml.h"
29 #include "nvc0_3d.xml.h"
30 #include "nvc0_2d.xml.h"
31 #include "nvc0_m2mf.xml.h"
32 #include "nve4_p2mf.xml.h"
33
34 /* NOTE: must keep NVC0_NEW_...PROG in consecutive bits in this order */
35 #define NVC0_NEW_BLEND (1 << 0)
36 #define NVC0_NEW_RASTERIZER (1 << 1)
37 #define NVC0_NEW_ZSA (1 << 2)
38 #define NVC0_NEW_VERTPROG (1 << 3)
39 #define NVC0_NEW_TCTLPROG (1 << 4)
40 #define NVC0_NEW_TEVLPROG (1 << 5)
41 #define NVC0_NEW_GMTYPROG (1 << 6)
42 #define NVC0_NEW_FRAGPROG (1 << 7)
43 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
44 #define NVC0_NEW_STENCIL_REF (1 << 9)
45 #define NVC0_NEW_CLIP (1 << 10)
46 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
47 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
48 #define NVC0_NEW_STIPPLE (1 << 13)
49 #define NVC0_NEW_SCISSOR (1 << 14)
50 #define NVC0_NEW_VIEWPORT (1 << 15)
51 #define NVC0_NEW_ARRAYS (1 << 16)
52 #define NVC0_NEW_VERTEX (1 << 17)
53 #define NVC0_NEW_CONSTBUF (1 << 18)
54 #define NVC0_NEW_TEXTURES (1 << 19)
55 #define NVC0_NEW_SAMPLERS (1 << 20)
56 #define NVC0_NEW_TFB_TARGETS (1 << 21)
57 #define NVC0_NEW_IDXBUF (1 << 22)
58
59 #define NVC0_BIND_FB 0
60 #define NVC0_BIND_VTX 1
61 #define NVC0_BIND_VTX_TMP 2
62 #define NVC0_BIND_IDX 3
63 #define NVC0_BIND_TEX(s, i) ( 4 + 32 * (s) + (i))
64 #define NVC0_BIND_CB(s, i) (164 + 16 * (s) + (i))
65 #define NVC0_BIND_TFB 244
66 #define NVC0_BIND_SCREEN 245
67 #define NVC0_BIND_TLS 246
68 #define NVC0_BIND_COUNT 247
69
70 #define NVC0_BIND_2D 0
71 #define NVC0_BIND_M2MF 0
72 #define NVC0_BIND_FENCE 1
73
74
75 struct nvc0_blitctx;
76
77 boolean nvc0_blitctx_create(struct nvc0_context *);
78
79 struct nvc0_context {
80 struct nouveau_context base;
81
82 struct nouveau_bufctx *bufctx_3d;
83 struct nouveau_bufctx *bufctx;
84
85 struct nvc0_screen *screen;
86
87 void (*m2mf_copy_rect)(struct nvc0_context *,
88 const struct nv50_m2mf_rect *dst,
89 const struct nv50_m2mf_rect *src,
90 uint32_t nblocksx, uint32_t nblocksy);
91
92 uint32_t dirty;
93
94 struct {
95 boolean flushed;
96 boolean rasterizer_discard;
97 boolean early_z_forced;
98 boolean prim_restart;
99 uint32_t instance_elts; /* bitmask of per-instance elements */
100 uint32_t instance_base;
101 uint32_t constant_vbos;
102 uint32_t constant_elts;
103 int32_t index_bias;
104 uint16_t scissor;
105 uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
106 uint8_t num_vtxbufs;
107 uint8_t num_vtxelts;
108 uint8_t num_textures[5];
109 uint8_t num_samplers[5];
110 uint8_t tls_required; /* bitmask of shader types using l[] */
111 uint8_t c14_bound; /* whether immediate array constbuf is bound */
112 uint8_t clip_enable;
113 uint32_t clip_mode;
114 uint32_t uniform_buffer_bound[5];
115 struct nvc0_transform_feedback_state *tfb;
116 } state;
117
118 struct nvc0_blend_stateobj *blend;
119 struct nvc0_rasterizer_stateobj *rast;
120 struct nvc0_zsa_stateobj *zsa;
121 struct nvc0_vertex_stateobj *vertex;
122
123 struct nvc0_program *vertprog;
124 struct nvc0_program *tctlprog;
125 struct nvc0_program *tevlprog;
126 struct nvc0_program *gmtyprog;
127 struct nvc0_program *fragprog;
128
129 struct nvc0_constbuf constbuf[5][NVC0_MAX_PIPE_CONSTBUFS];
130 uint16_t constbuf_dirty[5];
131
132 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
133 unsigned num_vtxbufs;
134 struct pipe_index_buffer idxbuf;
135 uint32_t constant_vbos;
136 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
137 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
138 uint32_t vb_elt_limit; /* max - min element (count - 1) */
139 uint32_t instance_off; /* current base vertex for instanced arrays */
140 uint32_t instance_max; /* last instance for current draw call */
141
142 struct pipe_sampler_view *textures[5][PIPE_MAX_SAMPLERS];
143 unsigned num_textures[5];
144 uint32_t textures_dirty[5];
145 struct nv50_tsc_entry *samplers[5][PIPE_MAX_SAMPLERS];
146 unsigned num_samplers[5];
147 uint16_t samplers_dirty[5];
148
149 uint32_t tex_handles[5][PIPE_MAX_SAMPLERS]; /* for nve4 */
150
151 struct pipe_framebuffer_state framebuffer;
152 struct pipe_blend_color blend_colour;
153 struct pipe_stencil_ref stencil_ref;
154 struct pipe_poly_stipple stipple;
155 struct pipe_scissor_state scissor;
156 struct pipe_viewport_state viewport;
157 struct pipe_clip_state clip;
158
159 unsigned sample_mask;
160
161 boolean vbo_push_hint;
162
163 uint8_t tfbbuf_dirty;
164 struct pipe_stream_output_target *tfbbuf[4];
165 unsigned num_tfbbufs;
166
167 struct pipe_query *cond_query;
168 uint cond_mode;
169
170 struct nvc0_blitctx *blit;
171
172 #ifdef NVC0_WITH_DRAW_MODULE
173 struct draw_context *draw;
174 #endif
175 };
176
177 static INLINE struct nvc0_context *
178 nvc0_context(struct pipe_context *pipe)
179 {
180 return (struct nvc0_context *)pipe;
181 }
182
183 static INLINE unsigned
184 nvc0_shader_stage(unsigned pipe)
185 {
186 switch (pipe) {
187 case PIPE_SHADER_VERTEX: return 0;
188 /* case PIPE_SHADER_TESSELLATION_CONTROL: return 1; */
189 /* case PIPE_SHADER_TESSELLATION_EVALUATION: return 2; */
190 case PIPE_SHADER_GEOMETRY: return 3;
191 case PIPE_SHADER_FRAGMENT: return 4;
192 case PIPE_SHADER_COMPUTE: return 5;
193 default:
194 assert(!"invalid PIPE_SHADER type");
195 return 0;
196 }
197 }
198
199
200 /* nvc0_context.c */
201 struct pipe_context *nvc0_create(struct pipe_screen *, void *);
202 void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
203 boolean on_flush);
204 void nvc0_default_kick_notify(struct nouveau_pushbuf *);
205
206 /* nvc0_draw.c */
207 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
208
209 /* nvc0_program.c */
210 boolean nvc0_program_translate(struct nvc0_program *, uint16_t chipset);
211 boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
212 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
213 void nvc0_program_library_upload(struct nvc0_context *);
214
215 /* nvc0_query.c */
216 void nvc0_init_query_functions(struct nvc0_context *);
217 void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *,
218 struct pipe_query *, unsigned result_offset);
219 void nvc0_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
220 void nvc0_so_target_save_offset(struct pipe_context *,
221 struct pipe_stream_output_target *, unsigned i,
222 boolean *serialize);
223
224 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
225
226 /* nvc0_shader_state.c */
227 void nvc0_vertprog_validate(struct nvc0_context *);
228 void nvc0_tctlprog_validate(struct nvc0_context *);
229 void nvc0_tevlprog_validate(struct nvc0_context *);
230 void nvc0_gmtyprog_validate(struct nvc0_context *);
231 void nvc0_fragprog_validate(struct nvc0_context *);
232
233 void nvc0_tfb_validate(struct nvc0_context *);
234
235 /* nvc0_state.c */
236 extern void nvc0_init_state_functions(struct nvc0_context *);
237
238 /* nvc0_state_validate.c */
239 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
240 unsigned space_words);
241
242 /* nvc0_surface.c */
243 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
244 const union pipe_color_union *color,
245 double depth, unsigned stencil);
246 extern void nvc0_init_surface_functions(struct nvc0_context *);
247
248 /* nvc0_tex.c */
249 void nvc0_validate_textures(struct nvc0_context *);
250 void nvc0_validate_samplers(struct nvc0_context *);
251 void nve4_set_tex_handles(struct nvc0_context *);
252
253 struct pipe_sampler_view *
254 nvc0_create_texture_view(struct pipe_context *,
255 struct pipe_resource *,
256 const struct pipe_sampler_view *,
257 uint32_t flags,
258 enum pipe_texture_target);
259 struct pipe_sampler_view *
260 nvc0_create_sampler_view(struct pipe_context *,
261 struct pipe_resource *,
262 const struct pipe_sampler_view *);
263
264 /* nvc0_transfer.c */
265 void
266 nvc0_init_transfer_functions(struct nvc0_context *);
267
268 void
269 nvc0_m2mf_push_linear(struct nouveau_context *nv,
270 struct nouveau_bo *dst, unsigned offset, unsigned domain,
271 unsigned size, const void *data);
272 void
273 nve4_p2mf_push_linear(struct nouveau_context *nv,
274 struct nouveau_bo *dst, unsigned offset, unsigned domain,
275 unsigned size, const void *data);
276 void
277 nvc0_cb_push(struct nouveau_context *,
278 struct nouveau_bo *bo, unsigned domain,
279 unsigned base, unsigned size,
280 unsigned offset, unsigned words, const uint32_t *data);
281
282 /* nvc0_vbo.c */
283 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
284
285 void *
286 nvc0_vertex_state_create(struct pipe_context *pipe,
287 unsigned num_elements,
288 const struct pipe_vertex_element *elements);
289 void
290 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
291
292 void nvc0_vertex_arrays_validate(struct nvc0_context *);
293
294 void nvc0_idxbuf_validate(struct nvc0_context *);
295
296 /* nvc0_push.c */
297 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
298
299 #endif