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