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