• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_3D_BLEND        (1 << 0)
30 #define NV50_NEW_3D_RASTERIZER   (1 << 1)
31 #define NV50_NEW_3D_ZSA          (1 << 2)
32 #define NV50_NEW_3D_VERTPROG     (1 << 3)
33 #define NV50_NEW_3D_GMTYPROG     (1 << 6)
34 #define NV50_NEW_3D_FRAGPROG     (1 << 7)
35 #define NV50_NEW_3D_BLEND_COLOUR (1 << 8)
36 #define NV50_NEW_3D_STENCIL_REF  (1 << 9)
37 #define NV50_NEW_3D_CLIP         (1 << 10)
38 #define NV50_NEW_3D_SAMPLE_MASK  (1 << 11)
39 #define NV50_NEW_3D_FRAMEBUFFER  (1 << 12)
40 #define NV50_NEW_3D_STIPPLE      (1 << 13)
41 #define NV50_NEW_3D_SCISSOR      (1 << 14)
42 #define NV50_NEW_3D_VIEWPORT     (1 << 15)
43 #define NV50_NEW_3D_ARRAYS       (1 << 16)
44 #define NV50_NEW_3D_VERTEX       (1 << 17)
45 #define NV50_NEW_3D_CONSTBUF     (1 << 18)
46 #define NV50_NEW_3D_TEXTURES     (1 << 19)
47 #define NV50_NEW_3D_SAMPLERS     (1 << 20)
48 #define NV50_NEW_3D_STRMOUT      (1 << 21)
49 #define NV50_NEW_3D_MIN_SAMPLES  (1 << 22)
50 #define NV50_NEW_3D_WINDOW_RECTS (1 << 23)
51 #define NV50_NEW_3D_CONTEXT      (1 << 31)
52 
53 #define NV50_NEW_CP_PROGRAM   (1 << 0)
54 #define NV50_NEW_CP_GLOBALS   (1 << 1)
55 
56 /* 3d bufctx (during draw_vbo, blit_3d) */
57 #define NV50_BIND_3D_FB          0
58 #define NV50_BIND_3D_VERTEX      1
59 #define NV50_BIND_3D_VERTEX_TMP  2
60 #define NV50_BIND_3D_INDEX       3
61 #define NV50_BIND_3D_TEXTURES    4
62 #define NV50_BIND_3D_CB(s, i)   (5 + 16 * (s) + (i))
63 #define NV50_BIND_3D_SO         53
64 #define NV50_BIND_3D_SCREEN     54
65 #define NV50_BIND_3D_TLS        55
66 #define NV50_BIND_3D_COUNT      56
67 
68 /* compute bufctx (during launch_grid) */
69 #define NV50_BIND_CP_GLOBAL   0
70 #define NV50_BIND_CP_SCREEN   1
71 #define NV50_BIND_CP_QUERY    2
72 #define NV50_BIND_CP_COUNT    3
73 
74 /* bufctx for other operations */
75 #define NV50_BIND_2D          0
76 #define NV50_BIND_M2MF        0
77 #define NV50_BIND_FENCE       1
78 
79 #define NV50_CB_TMP 123
80 /* fixed constant buffer binding points - low indices for user's constbufs */
81 #define NV50_CB_PVP 124
82 #define NV50_CB_PGP 126
83 #define NV50_CB_PFP 125
84 /* constant buffer permanently mapped in as c15[] */
85 #define NV50_CB_AUX 127
86 /* size of the buffer: 64k. not all taken up, can be reduced if needed. */
87 #define NV50_CB_AUX_SIZE          (1 << 16)
88 /* 8 user clip planes, at 4 32-bit floats each */
89 #define NV50_CB_AUX_UCP_OFFSET    0x0000
90 #define NV50_CB_AUX_UCP_SIZE      (8 * 4 * 4)
91 /* 16 textures * 3 shaders, each with ms_x, ms_y u32 pairs */
92 #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080
93 #define NV50_CB_AUX_TEX_MS_SIZE   (16 * 3 * 2 * 4)
94 /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */
95 #define NV50_CB_AUX_MS_OFFSET     0x200
96 #define NV50_CB_AUX_MS_SIZE       (4 * 8 * 4 * 2)
97 /* Sample position pairs for the current output MS level */
98 #define NV50_CB_AUX_SAMPLE_OFFSET 0x300
99 #define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)
100 /* Alpha test ref value */
101 #define NV50_CB_AUX_ALPHATEST_OFFSET 0x340
102 #define NV50_CB_AUX_ALPHATEST_SIZE (4)
103 /* next spot: 0x344 */
104 /* 4 32-bit floats for the vertex runout, put at the end */
105 #define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)
106 
107 
108 
109 struct nv50_blitctx;
110 
111 bool nv50_blitctx_create(struct nv50_context *);
112 
113 struct nv50_context {
114    struct nouveau_context base;
115 
116    struct nv50_screen *screen;
117 
118    struct nouveau_bufctx *bufctx_3d;
119    struct nouveau_bufctx *bufctx;
120    struct nouveau_bufctx *bufctx_cp;
121 
122    uint32_t dirty_3d; /* dirty flags for 3d state */
123    uint32_t dirty_cp; /* dirty flags for compute state */
124    bool cb_dirty;
125 
126    struct nv50_graph_state state;
127 
128    struct nv50_blend_stateobj *blend;
129    struct nv50_rasterizer_stateobj *rast;
130    struct nv50_zsa_stateobj *zsa;
131    struct nv50_vertex_stateobj *vertex;
132 
133    struct nv50_program *vertprog;
134    struct nv50_program *gmtyprog;
135    struct nv50_program *fragprog;
136    struct nv50_program *compprog;
137 
138    struct nv50_constbuf constbuf[3][NV50_MAX_PIPE_CONSTBUFS];
139    uint16_t constbuf_dirty[3];
140    uint16_t constbuf_valid[3];
141    uint16_t constbuf_coherent[3];
142 
143    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
144    unsigned num_vtxbufs;
145    uint32_t vtxbufs_coherent;
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    uint32_t textures_coherent[3];
157    struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
158    unsigned num_samplers[3];
159    bool seamless_cube_map;
160 
161    uint8_t num_so_targets;
162    uint8_t so_targets_dirty;
163    struct pipe_stream_output_target *so_target[4];
164 
165    struct pipe_framebuffer_state framebuffer;
166    struct pipe_blend_color blend_colour;
167    struct pipe_stencil_ref stencil_ref;
168    struct pipe_poly_stipple stipple;
169    struct pipe_scissor_state scissors[NV50_MAX_VIEWPORTS];
170    unsigned scissors_dirty;
171    struct pipe_viewport_state viewports[NV50_MAX_VIEWPORTS];
172    unsigned viewports_dirty;
173    struct pipe_clip_state clip;
174    struct nv50_window_rect_stateobj window_rect;
175 
176    unsigned sample_mask;
177    unsigned min_samples;
178 
179    bool vbo_push_hint;
180 
181    uint32_t rt_array_mode;
182 
183    struct pipe_query *cond_query;
184    bool cond_cond; /* inverted rendering condition */
185    uint cond_mode;
186    uint32_t cond_condmode; /* the calculated condition */
187 
188    struct nv50_blitctx *blit;
189 
190    struct util_dynarray global_residents;
191 };
192 
193 static inline struct nv50_context *
nv50_context(struct pipe_context * pipe)194 nv50_context(struct pipe_context *pipe)
195 {
196    return (struct nv50_context *)pipe;
197 }
198 
199 /* return index used in nv50_context arrays for a specific shader type */
200 static inline unsigned
nv50_context_shader_stage(unsigned pipe)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 *, unsigned flags);
216 
217 void nv50_bufctx_fence(struct nouveau_bufctx *, bool 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_shader_state.c */
225 void nv50_vertprog_validate(struct nv50_context *);
226 void nv50_gmtyprog_validate(struct nv50_context *);
227 void nv50_fragprog_validate(struct nv50_context *);
228 void nv50_compprog_validate(struct nv50_context *);
229 void nv50_fp_linkage_validate(struct nv50_context *);
230 void nv50_gp_linkage_validate(struct nv50_context *);
231 void nv50_constbufs_validate(struct nv50_context *);
232 void nv50_validate_derived_rs(struct nv50_context *);
233 void nv50_stream_output_validate(struct nv50_context *);
234 
235 /* nv50_state.c */
236 extern void nv50_init_state_functions(struct nv50_context *);
237 
238 /* nv50_state_validate.c */
239 struct nv50_state_validate {
240    void (*func)(struct nv50_context *);
241    uint32_t states;
242 };
243 
244 bool nv50_state_validate(struct nv50_context *, uint32_t,
245                          struct nv50_state_validate *, int, uint32_t *,
246                          struct nouveau_bufctx *);
247 bool nv50_state_validate_3d(struct nv50_context *, uint32_t);
248 
249 /* nv50_surface.c */
250 extern void nv50_clear(struct pipe_context *, unsigned buffers,
251                        const union pipe_color_union *color,
252                        double depth, unsigned stencil);
253 extern void nv50_init_surface_functions(struct nv50_context *);
254 
255 /* nv50_tex.c */
256 void nv50_validate_textures(struct nv50_context *);
257 void nv50_validate_samplers(struct nv50_context *);
258 void nv50_upload_ms_info(struct nouveau_pushbuf *);
259 
260 struct pipe_sampler_view *
261 nv50_create_texture_view(struct pipe_context *,
262                          struct pipe_resource *,
263                          const struct pipe_sampler_view *,
264                          uint32_t flags,
265                          enum pipe_texture_target);
266 struct pipe_sampler_view *
267 nv50_create_sampler_view(struct pipe_context *,
268                          struct pipe_resource *,
269                          const struct pipe_sampler_view *);
270 
271 /* nv50_transfer.c */
272 void
273 nv50_m2mf_transfer_rect(struct nv50_context *,
274                         const struct nv50_m2mf_rect *dst,
275                         const struct nv50_m2mf_rect *src,
276                         uint32_t nblocksx, uint32_t nblocksy);
277 void
278 nv50_sifc_linear_u8(struct nouveau_context *pipe,
279                     struct nouveau_bo *dst, unsigned offset, unsigned domain,
280                     unsigned size, const void *data);
281 void
282 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
283                       struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
284                       struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
285                       unsigned size);
286 void
287 nv50_cb_push(struct nouveau_context *nv,
288              struct nv04_resource *res,
289              unsigned offset, unsigned words, const uint32_t *data);
290 
291 /* nv50_vbo.c */
292 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
293 
294 void *
295 nv50_vertex_state_create(struct pipe_context *pipe,
296                          unsigned num_elements,
297                          const struct pipe_vertex_element *elements);
298 void
299 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
300 
301 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
302 
303 /* nv50_push.c */
304 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
305 
306 /* nv84_video.c */
307 struct pipe_video_codec *
308 nv84_create_decoder(struct pipe_context *context,
309                     const struct pipe_video_codec *templ);
310 
311 struct pipe_video_buffer *
312 nv84_video_buffer_create(struct pipe_context *pipe,
313                          const struct pipe_video_buffer *template);
314 
315 int
316 nv84_screen_get_video_param(struct pipe_screen *pscreen,
317                             enum pipe_video_profile profile,
318                             enum pipe_video_entrypoint entrypoint,
319                             enum pipe_video_cap param);
320 
321 boolean
322 nv84_screen_video_supported(struct pipe_screen *screen,
323                             enum pipe_format format,
324                             enum pipe_video_profile profile,
325                             enum pipe_video_entrypoint entrypoint);
326 
327 /* nv98_video.c */
328 struct pipe_video_codec *
329 nv98_create_decoder(struct pipe_context *context,
330                     const struct pipe_video_codec *templ);
331 
332 struct pipe_video_buffer *
333 nv98_video_buffer_create(struct pipe_context *pipe,
334                          const struct pipe_video_buffer *template);
335 
336 /* nv50_compute.c */
337 void
338 nv50_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
339 
340 #endif
341