1 #ifndef __NOUVEAU_CONTEXT_H__
2 #define __NOUVEAU_CONTEXT_H__
4 #include "pipe/p_context.h"
5 #include <libdrm/nouveau.h>
7 #define NOUVEAU_MAX_SCRATCH_BUFS 4
9 struct nouveau_context
{
10 struct pipe_context pipe
;
11 struct nouveau_screen
*screen
;
13 struct nouveau_client
*client
;
14 struct nouveau_pushbuf
*pushbuf
;
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 *);
31 /* @return: @ref reduced by nr of references found in context */
32 int (*invalidate_resource_storage
)(struct nouveau_context
*,
33 struct pipe_resource
*,
42 struct nouveau_bo
*bo
[NOUVEAU_MAX_SCRATCH_BUFS
];
43 struct nouveau_bo
*current
;
44 struct nouveau_bo
**runout
;
50 uint32_t buf_cache_count
;
51 uint32_t buf_cache_frame
;
55 static INLINE
struct nouveau_context
*
56 nouveau_context(struct pipe_context
*pipe
)
58 return (struct nouveau_context
*)pipe
;
62 nouveau_context_init_vdec(struct nouveau_context
*);
65 nouveau_scratch_runout_release(struct nouveau_context
*);
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.
72 nouveau_scratch_done(struct nouveau_context
*nv
)
74 nv
->scratch
.wrap
= nv
->scratch
.id
;
75 if (unlikely(nv
->scratch
.nr_runout
))
76 nouveau_scratch_runout_release(nv
);
79 /* Get pointer to scratch buffer.
80 * The returned nouveau_bo is only referenced by the context, don't un-ref it !
83 nouveau_scratch_get(struct nouveau_context
*, unsigned size
, uint64_t *gpu_addr
,
84 struct nouveau_bo
**);
87 nouveau_context_destroy(struct nouveau_context
*ctx
)
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
]);
99 nouveau_context_update_frame_stats(struct nouveau_context
*nv
)
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
;