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
;
20 void (*copy_data
)(struct nouveau_context
*,
21 struct nouveau_bo
*dst
, unsigned, unsigned,
22 struct nouveau_bo
*src
, unsigned, unsigned, unsigned);
23 void (*push_data
)(struct nouveau_context
*,
24 struct nouveau_bo
*dst
, unsigned, unsigned,
25 unsigned, const void *);
26 /* base, size refer to the whole constant buffer */
27 void (*push_cb
)(struct nouveau_context
*,
28 struct nv04_resource
*,
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
;
46 struct nouveau_bo
*bo
[0];
52 uint32_t buf_cache_count
;
53 uint32_t buf_cache_frame
;
57 static inline struct nouveau_context
*
58 nouveau_context(struct pipe_context
*pipe
)
60 return (struct nouveau_context
*)pipe
;
64 nouveau_context_init_vdec(struct nouveau_context
*);
67 nouveau_scratch_runout_release(struct nouveau_context
*);
69 /* This is needed because we don't hold references outside of context::scratch,
70 * because we don't want to un-bo_ref each allocation every time. This is less
71 * work, and we need the wrap index anyway for extreme situations.
74 nouveau_scratch_done(struct nouveau_context
*nv
)
76 nv
->scratch
.wrap
= nv
->scratch
.id
;
77 if (unlikely(nv
->scratch
.runout
))
78 nouveau_scratch_runout_release(nv
);
81 /* Get pointer to scratch buffer.
82 * The returned nouveau_bo is only referenced by the context, don't un-ref it !
85 nouveau_scratch_get(struct nouveau_context
*, unsigned size
, uint64_t *gpu_addr
,
86 struct nouveau_bo
**);
89 nouveau_context_destroy(struct nouveau_context
*ctx
)
93 for (i
= 0; i
< NOUVEAU_MAX_SCRATCH_BUFS
; ++i
)
94 if (ctx
->scratch
.bo
[i
])
95 nouveau_bo_ref(NULL
, &ctx
->scratch
.bo
[i
]);
101 nouveau_context_update_frame_stats(struct nouveau_context
*nv
)
103 nv
->stats
.buf_cache_frame
<<= 1;
104 if (nv
->stats
.buf_cache_count
) {
105 nv
->stats
.buf_cache_count
= 0;
106 nv
->stats
.buf_cache_frame
|= 1;
107 if ((nv
->stats
.buf_cache_frame
& 0xf) == 0xf)
108 nv
->screen
->hint_buf_keep_sysmem_copy
= true;