nv50: allow vert_count to be >255
[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 <libdrm/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 boolean vbo_dirty;
17 boolean cb_dirty;
18
19 void (*copy_data)(struct nouveau_context *,
20 struct nouveau_bo *dst, unsigned, unsigned,
21 struct nouveau_bo *src, unsigned, unsigned, unsigned);
22 void (*push_data)(struct nouveau_context *,
23 struct nouveau_bo *dst, unsigned, unsigned,
24 unsigned, const void *);
25 /* base, size refer to the whole constant buffer */
26 void (*push_cb)(struct nouveau_context *,
27 struct nouveau_bo *, unsigned domain,
28 unsigned base, unsigned size,
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 nouveau_bo **runout;
45 unsigned nr_runout;
46 unsigned bo_size;
47 } scratch;
48
49 struct {
50 uint32_t buf_cache_count;
51 uint32_t buf_cache_frame;
52 } stats;
53 };
54
55 static INLINE struct nouveau_context *
56 nouveau_context(struct pipe_context *pipe)
57 {
58 return (struct nouveau_context *)pipe;
59 }
60
61 void
62 nouveau_context_init_vdec(struct nouveau_context *);
63
64 void
65 nouveau_scratch_runout_release(struct nouveau_context *);
66
67 /* This is needed because we don't hold references outside of context::scratch,
68 * because we don't want to un-bo_ref each allocation every time. This is less
69 * work, and we need the wrap index anyway for extreme situations.
70 */
71 static INLINE void
72 nouveau_scratch_done(struct nouveau_context *nv)
73 {
74 nv->scratch.wrap = nv->scratch.id;
75 if (unlikely(nv->scratch.nr_runout))
76 nouveau_scratch_runout_release(nv);
77 }
78
79 /* Get pointer to scratch buffer.
80 * The returned nouveau_bo is only referenced by the context, don't un-ref it !
81 */
82 void *
83 nouveau_scratch_get(struct nouveau_context *, unsigned size, uint64_t *gpu_addr,
84 struct nouveau_bo **);
85
86 static INLINE void
87 nouveau_context_destroy(struct nouveau_context *ctx)
88 {
89 int i;
90
91 for (i = 0; i < NOUVEAU_MAX_SCRATCH_BUFS; ++i)
92 if (ctx->scratch.bo[i])
93 nouveau_bo_ref(NULL, &ctx->scratch.bo[i]);
94
95 FREE(ctx);
96 }
97
98 static INLINE void
99 nouveau_context_update_frame_stats(struct nouveau_context *nv)
100 {
101 nv->stats.buf_cache_frame <<= 1;
102 if (nv->stats.buf_cache_count) {
103 nv->stats.buf_cache_count = 0;
104 nv->stats.buf_cache_frame |= 1;
105 if ((nv->stats.buf_cache_frame & 0xf) == 0xf)
106 nv->screen->hint_buf_keep_sysmem_copy = TRUE;
107 }
108 }
109
110 #endif