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