1 #ifndef __NOUVEAU_CONTEXT_H__
2 #define __NOUVEAU_CONTEXT_H__
4 #include "pipe/p_context.h"
7 #define NOUVEAU_MAX_SCRATCH_BUFS 4
11 struct nouveau_context
{
12 struct pipe_context pipe
;
13 struct nouveau_screen
*screen
;
15 struct nouveau_client
*client
;
16 struct nouveau_pushbuf
*pushbuf
;
17 struct pipe_debug_callback debug
;
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 *);
32 /* @return: @ref reduced by nr of references found in context */
33 int (*invalidate_resource_storage
)(struct nouveau_context
*,
34 struct pipe_resource
*,
43 struct nouveau_bo
*bo
[NOUVEAU_MAX_SCRATCH_BUFS
];
44 struct nouveau_bo
*current
;
47 struct nouveau_bo
*bo
[0];
53 uint32_t buf_cache_count
;
54 uint32_t buf_cache_frame
;
58 static inline struct nouveau_context
*
59 nouveau_context(struct pipe_context
*pipe
)
61 return (struct nouveau_context
*)pipe
;
65 nouveau_context_init_vdec(struct nouveau_context
*);
68 nouveau_context_init(struct nouveau_context
*);
71 nouveau_scratch_runout_release(struct nouveau_context
*);
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.
78 nouveau_scratch_done(struct nouveau_context
*nv
)
80 nv
->scratch
.wrap
= nv
->scratch
.id
;
81 if (unlikely(nv
->scratch
.runout
))
82 nouveau_scratch_runout_release(nv
);
85 /* Get pointer to scratch buffer.
86 * The returned nouveau_bo is only referenced by the context, don't un-ref it !
89 nouveau_scratch_get(struct nouveau_context
*, unsigned size
, uint64_t *gpu_addr
,
90 struct nouveau_bo
**);
93 nouveau_context_destroy(struct nouveau_context
*ctx
)
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
]);
105 nouveau_context_update_frame_stats(struct nouveau_context
*nv
)
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;