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