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