1 #ifndef __NOUVEAU_CONTEXT_H__
2 #define __NOUVEAU_CONTEXT_H__
4 #include "pipe/p_context.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
;
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 *);
30 /* @return: @ref reduced by nr of references found in context */
31 int (*invalidate_resource_storage
)(struct nouveau_context
*,
32 struct pipe_resource
*,
41 struct nouveau_bo
*bo
[NOUVEAU_MAX_SCRATCH_BUFS
];
42 struct nouveau_bo
*current
;
45 struct nouveau_bo
*bo
[0];
51 uint32_t buf_cache_count
;
52 uint32_t buf_cache_frame
;
56 static inline struct nouveau_context
*
57 nouveau_context(struct pipe_context
*pipe
)
59 return (struct nouveau_context
*)pipe
;
63 nouveau_context_init_vdec(struct nouveau_context
*);
66 nouveau_scratch_runout_release(struct nouveau_context
*);
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.
73 nouveau_scratch_done(struct nouveau_context
*nv
)
75 nv
->scratch
.wrap
= nv
->scratch
.id
;
76 if (unlikely(nv
->scratch
.runout
))
77 nouveau_scratch_runout_release(nv
);
80 /* Get pointer to scratch buffer.
81 * The returned nouveau_bo is only referenced by the context, don't un-ref it !
84 nouveau_scratch_get(struct nouveau_context
*, unsigned size
, uint64_t *gpu_addr
,
85 struct nouveau_bo
**);
88 nouveau_context_destroy(struct nouveau_context
*ctx
)
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
]);
100 nouveau_context_update_frame_stats(struct nouveau_context
*nv
)
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;