radeonsi: dump init_config IBs
[mesa.git] / src / gallium / drivers / nouveau / 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 #include "nv50/nv50_winsys.h"
14 #include "nv50/nv50_stateobj.h"
15 #include "nv50/nv50_screen.h"
16 #include "nv50/nv50_program.h"
17 #include "nv50/nv50_resource.h"
18 #include "nv50/nv50_transfer.h"
19 #include "nv50/nv50_query.h"
20
21 #include "nouveau_context.h"
22 #include "nouveau_debug.h"
23 #include "nv_object.xml.h"
24 #include "nv_m2mf.xml.h"
25 #include "nv50/nv50_3ddefs.xml.h"
26 #include "nv50/nv50_3d.xml.h"
27 #include "nv50/nv50_2d.xml.h"
28
29 #define NV50_NEW_BLEND (1 << 0)
30 #define NV50_NEW_RASTERIZER (1 << 1)
31 #define NV50_NEW_ZSA (1 << 2)
32 #define NV50_NEW_VERTPROG (1 << 3)
33 #define NV50_NEW_GMTYPROG (1 << 6)
34 #define NV50_NEW_FRAGPROG (1 << 7)
35 #define NV50_NEW_BLEND_COLOUR (1 << 8)
36 #define NV50_NEW_STENCIL_REF (1 << 9)
37 #define NV50_NEW_CLIP (1 << 10)
38 #define NV50_NEW_SAMPLE_MASK (1 << 11)
39 #define NV50_NEW_FRAMEBUFFER (1 << 12)
40 #define NV50_NEW_STIPPLE (1 << 13)
41 #define NV50_NEW_SCISSOR (1 << 14)
42 #define NV50_NEW_VIEWPORT (1 << 15)
43 #define NV50_NEW_ARRAYS (1 << 16)
44 #define NV50_NEW_VERTEX (1 << 17)
45 #define NV50_NEW_CONSTBUF (1 << 18)
46 #define NV50_NEW_TEXTURES (1 << 19)
47 #define NV50_NEW_SAMPLERS (1 << 20)
48 #define NV50_NEW_STRMOUT (1 << 21)
49 #define NV50_NEW_MIN_SAMPLES (1 << 22)
50 #define NV50_NEW_CONTEXT (1 << 31)
51
52 #define NV50_NEW_CP_PROGRAM (1 << 0)
53 #define NV50_NEW_CP_GLOBALS (1 << 1)
54
55 /* 3d bufctx (during draw_vbo, blit_3d) */
56 #define NV50_BIND_FB 0
57 #define NV50_BIND_VERTEX 1
58 #define NV50_BIND_VERTEX_TMP 2
59 #define NV50_BIND_INDEX 3
60 #define NV50_BIND_TEXTURES 4
61 #define NV50_BIND_CB(s, i) (5 + 16 * (s) + (i))
62 #define NV50_BIND_SO 53
63 #define NV50_BIND_SCREEN 54
64 #define NV50_BIND_TLS 55
65 #define NV50_BIND_3D_COUNT 56
66
67 /* compute bufctx (during launch_grid) */
68 #define NV50_BIND_CP_GLOBAL 0
69 #define NV50_BIND_CP_SCREEN 1
70 #define NV50_BIND_CP_QUERY 2
71 #define NV50_BIND_CP_COUNT 3
72
73 /* bufctx for other operations */
74 #define NV50_BIND_2D 0
75 #define NV50_BIND_M2MF 0
76 #define NV50_BIND_FENCE 1
77
78 #define NV50_CB_TMP 123
79 /* fixed constant buffer binding points - low indices for user's constbufs */
80 #define NV50_CB_PVP 124
81 #define NV50_CB_PGP 126
82 #define NV50_CB_PFP 125
83 /* constant buffer permanently mapped in as c15[] */
84 #define NV50_CB_AUX 127
85 /* size of the buffer: 64k. not all taken up, can be reduced if needed. */
86 #define NV50_CB_AUX_SIZE (1 << 16)
87 /* 8 user clip planes, at 4 32-bit floats each */
88 #define NV50_CB_AUX_UCP_OFFSET 0x0000
89 #define NV50_CB_AUX_UCP_SIZE (8 * 4 * 4)
90 /* 16 textures * 3 shaders, each with ms_x, ms_y u32 pairs */
91 #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080
92 #define NV50_CB_AUX_TEX_MS_SIZE (16 * 3 * 2 * 4)
93 /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */
94 #define NV50_CB_AUX_MS_OFFSET 0x200
95 #define NV50_CB_AUX_MS_SIZE (4 * 8 * 4 * 2)
96 /* Sample position pairs for the current output MS level */
97 #define NV50_CB_AUX_SAMPLE_OFFSET 0x300
98 #define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)
99 /* next spot: 0x340 */
100 /* 4 32-bit floats for the vertex runout, put at the end */
101 #define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)
102
103
104
105 struct nv50_blitctx;
106
107 bool nv50_blitctx_create(struct nv50_context *);
108
109 struct nv50_context {
110 struct nouveau_context base;
111
112 struct nv50_screen *screen;
113
114 struct nouveau_bufctx *bufctx_3d;
115 struct nouveau_bufctx *bufctx;
116 struct nouveau_bufctx *bufctx_cp;
117
118 uint32_t dirty;
119 uint32_t dirty_cp; /* dirty flags for compute state */
120 bool cb_dirty;
121
122 struct nv50_graph_state state;
123
124 struct nv50_blend_stateobj *blend;
125 struct nv50_rasterizer_stateobj *rast;
126 struct nv50_zsa_stateobj *zsa;
127 struct nv50_vertex_stateobj *vertex;
128
129 struct nv50_program *vertprog;
130 struct nv50_program *gmtyprog;
131 struct nv50_program *fragprog;
132 struct nv50_program *compprog;
133
134 struct nv50_constbuf constbuf[3][NV50_MAX_PIPE_CONSTBUFS];
135 uint16_t constbuf_dirty[3];
136 uint16_t constbuf_valid[3];
137
138 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
139 unsigned num_vtxbufs;
140 struct pipe_index_buffer idxbuf;
141 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
142 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
143 uint32_t vbo_constant; /* bitmask of user buffers with stride 0 */
144 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
145 uint32_t vb_elt_limit; /* max - min element (count - 1) */
146 uint32_t instance_off; /* base vertex for instanced arrays */
147 uint32_t instance_max; /* max instance for current draw call */
148
149 struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS];
150 unsigned num_textures[3];
151 struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
152 unsigned num_samplers[3];
153
154 uint8_t num_so_targets;
155 uint8_t so_targets_dirty;
156 struct pipe_stream_output_target *so_target[4];
157
158 struct pipe_framebuffer_state framebuffer;
159 struct pipe_blend_color blend_colour;
160 struct pipe_stencil_ref stencil_ref;
161 struct pipe_poly_stipple stipple;
162 struct pipe_scissor_state scissors[NV50_MAX_VIEWPORTS];
163 unsigned scissors_dirty;
164 struct pipe_viewport_state viewports[NV50_MAX_VIEWPORTS];
165 unsigned viewports_dirty;
166 struct pipe_clip_state clip;
167
168 unsigned sample_mask;
169 unsigned min_samples;
170
171 bool vbo_push_hint;
172
173 uint32_t rt_array_mode;
174
175 struct pipe_query *cond_query;
176 bool cond_cond; /* inverted rendering condition */
177 uint cond_mode;
178 uint32_t cond_condmode; /* the calculated condition */
179
180 struct nv50_blitctx *blit;
181
182 struct util_dynarray global_residents;
183 };
184
185 static inline struct nv50_context *
186 nv50_context(struct pipe_context *pipe)
187 {
188 return (struct nv50_context *)pipe;
189 }
190
191 /* return index used in nv50_context arrays for a specific shader type */
192 static inline unsigned
193 nv50_context_shader_stage(unsigned pipe)
194 {
195 switch (pipe) {
196 case PIPE_SHADER_VERTEX: return 0;
197 case PIPE_SHADER_FRAGMENT: return 1;
198 case PIPE_SHADER_GEOMETRY: return 2;
199 case PIPE_SHADER_COMPUTE: return 3;
200 default:
201 assert(!"invalid/unhandled shader type");
202 return 0;
203 }
204 }
205
206 /* nv50_context.c */
207 struct pipe_context *nv50_create(struct pipe_screen *, void *, unsigned flags);
208
209 void nv50_bufctx_fence(struct nouveau_bufctx *, bool on_flush);
210
211 void nv50_default_kick_notify(struct nouveau_pushbuf *);
212
213 /* nv50_draw.c */
214 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
215
216 /* nv50_shader_state.c */
217 void nv50_vertprog_validate(struct nv50_context *);
218 void nv50_gmtyprog_validate(struct nv50_context *);
219 void nv50_fragprog_validate(struct nv50_context *);
220 void nv50_fp_linkage_validate(struct nv50_context *);
221 void nv50_gp_linkage_validate(struct nv50_context *);
222 void nv50_constbufs_validate(struct nv50_context *);
223 void nv50_validate_derived_rs(struct nv50_context *);
224 void nv50_stream_output_validate(struct nv50_context *);
225
226 /* nv50_state.c */
227 extern void nv50_init_state_functions(struct nv50_context *);
228
229 /* nv50_state_validate.c */
230 /* @words: check for space before emitting relocs */
231 extern bool nv50_state_validate(struct nv50_context *, uint32_t state_mask,
232 unsigned space_words);
233
234 /* nv50_surface.c */
235 extern void nv50_clear(struct pipe_context *, unsigned buffers,
236 const union pipe_color_union *color,
237 double depth, unsigned stencil);
238 extern void nv50_init_surface_functions(struct nv50_context *);
239
240 /* nv50_tex.c */
241 void nv50_validate_textures(struct nv50_context *);
242 void nv50_validate_samplers(struct nv50_context *);
243 void nv50_upload_ms_info(struct nouveau_pushbuf *);
244
245 struct pipe_sampler_view *
246 nv50_create_texture_view(struct pipe_context *,
247 struct pipe_resource *,
248 const struct pipe_sampler_view *,
249 uint32_t flags,
250 enum pipe_texture_target);
251 struct pipe_sampler_view *
252 nv50_create_sampler_view(struct pipe_context *,
253 struct pipe_resource *,
254 const struct pipe_sampler_view *);
255
256 /* nv50_transfer.c */
257 void
258 nv50_m2mf_transfer_rect(struct nv50_context *,
259 const struct nv50_m2mf_rect *dst,
260 const struct nv50_m2mf_rect *src,
261 uint32_t nblocksx, uint32_t nblocksy);
262 void
263 nv50_sifc_linear_u8(struct nouveau_context *pipe,
264 struct nouveau_bo *dst, unsigned offset, unsigned domain,
265 unsigned size, const void *data);
266 void
267 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
268 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
269 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
270 unsigned size);
271 void
272 nv50_cb_push(struct nouveau_context *nv,
273 struct nouveau_bo *bo, unsigned domain,
274 unsigned base, unsigned size,
275 unsigned offset, unsigned words, const uint32_t *data);
276
277 /* nv50_vbo.c */
278 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
279
280 void *
281 nv50_vertex_state_create(struct pipe_context *pipe,
282 unsigned num_elements,
283 const struct pipe_vertex_element *elements);
284 void
285 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
286
287 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
288
289 /* nv50_push.c */
290 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
291
292 /* nv84_video.c */
293 struct pipe_video_codec *
294 nv84_create_decoder(struct pipe_context *context,
295 const struct pipe_video_codec *templ);
296
297 struct pipe_video_buffer *
298 nv84_video_buffer_create(struct pipe_context *pipe,
299 const struct pipe_video_buffer *template);
300
301 int
302 nv84_screen_get_video_param(struct pipe_screen *pscreen,
303 enum pipe_video_profile profile,
304 enum pipe_video_entrypoint entrypoint,
305 enum pipe_video_cap param);
306
307 boolean
308 nv84_screen_video_supported(struct pipe_screen *screen,
309 enum pipe_format format,
310 enum pipe_video_profile profile,
311 enum pipe_video_entrypoint entrypoint);
312
313 /* nv98_video.c */
314 struct pipe_video_codec *
315 nv98_create_decoder(struct pipe_context *context,
316 const struct pipe_video_codec *templ);
317
318 struct pipe_video_buffer *
319 nv98_video_buffer_create(struct pipe_context *pipe,
320 const struct pipe_video_buffer *template);
321
322 /* nv50_compute.c */
323 void
324 nv50_launch_grid(struct pipe_context *, const uint *, const uint *,
325 uint32_t, const void *);
326
327 #endif