nvc0: keep track of cb bindings per buffer, use for upload settings
[mesa.git] / src / gallium / drivers / nouveau / nouveau_context.h
1 #ifndef __NOUVEAU_CONTEXT_H__
2 #define __NOUVEAU_CONTEXT_H__
3
4 #include "pipe/p_context.h"
5 #include <nouveau.h>
6
7 #define NOUVEAU_MAX_SCRATCH_BUFS 4
8
9 struct nv04_resource;
10
11 struct nouveau_context {
12 struct pipe_context pipe;
13 struct nouveau_screen *screen;
14
15 struct nouveau_client *client;
16 struct nouveau_pushbuf *pushbuf;
17
18 bool vbo_dirty;
19
20 void (*copy_data)(struct nouveau_context *,
21 struct nouveau_bo *dst, unsigned, unsigned,
22 struct nouveau_bo *src, unsigned, unsigned, unsigned);
23 void (*push_data)(struct nouveau_context *,
24 struct nouveau_bo *dst, unsigned, unsigned,
25 unsigned, const void *);
26 /* base, size refer to the whole constant buffer */
27 void (*push_cb)(struct nouveau_context *,
28 struct nv04_resource *,
29 unsigned offset, unsigned words, const uint32_t *);
30
31 /* @return: @ref reduced by nr of references found in context */
32 int (*invalidate_resource_storage)(struct nouveau_context *,
33 struct pipe_resource *,
34 int ref);
35
36 struct {
37 uint8_t *map;
38 unsigned id;
39 unsigned wrap;
40 unsigned offset;
41 unsigned end;
42 struct nouveau_bo *bo[NOUVEAU_MAX_SCRATCH_BUFS];
43 struct nouveau_bo *current;
44 struct runout {
45 unsigned nr;
46 struct nouveau_bo *bo[0];
47 } *runout;
48 unsigned bo_size;
49 } scratch;
50
51 struct {
52 uint32_t buf_cache_count;
53 uint32_t buf_cache_frame;
54 } stats;
55 };
56
57 static inline struct nouveau_context *
58 nouveau_context(struct pipe_context *pipe)
59 {
60 return (struct nouveau_context *)pipe;
61 }
62
63 void
64 nouveau_context_init_vdec(struct nouveau_context *);
65
66 void
67 nouveau_scratch_runout_release(struct nouveau_context *);
68
69 /* This is needed because we don't hold references outside of context::scratch,
70 * because we don't want to un-bo_ref each allocation every time. This is less
71 * work, and we need the wrap index anyway for extreme situations.
72 */
73 static inline void
74 nouveau_scratch_done(struct nouveau_context *nv)
75 {
76 nv->scratch.wrap = nv->scratch.id;
77 if (unlikely(nv->scratch.runout))
78 nouveau_scratch_runout_release(nv);
79 }
80
81 /* Get pointer to scratch buffer.
82 * The returned nouveau_bo is only referenced by the context, don't un-ref it !
83 */
84 void *
85 nouveau_scratch_get(struct nouveau_context *, unsigned size, uint64_t *gpu_addr,
86 struct nouveau_bo **);
87
88 static inline void
89 nouveau_context_destroy(struct nouveau_context *ctx)
90 {
91 int i;
92
93 for (i = 0; i < NOUVEAU_MAX_SCRATCH_BUFS; ++i)
94 if (ctx->scratch.bo[i])
95 nouveau_bo_ref(NULL, &ctx->scratch.bo[i]);
96
97 FREE(ctx);
98 }
99
100 static inline void
101 nouveau_context_update_frame_stats(struct nouveau_context *nv)
102 {
103 nv->stats.buf_cache_frame <<= 1;
104 if (nv->stats.buf_cache_count) {
105 nv->stats.buf_cache_count = 0;
106 nv->stats.buf_cache_frame |= 1;
107 if ((nv->stats.buf_cache_frame & 0xf) == 0xf)
108 nv->screen->hint_buf_keep_sysmem_copy = true;
109 }
110 }
111
112 #endif