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