Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nouveau_context.h
4570 views
#ifndef __NOUVEAU_CONTEXT_H__1#define __NOUVEAU_CONTEXT_H__23#include "pipe/p_context.h"4#include "pipe/p_state.h"5#include <nouveau.h>67#define NOUVEAU_MAX_SCRATCH_BUFS 489struct nv04_resource;1011struct nouveau_context {12struct pipe_context pipe;13struct nouveau_screen *screen;1415struct nouveau_client *client;16struct nouveau_pushbuf *pushbuf;17struct pipe_debug_callback debug;1819bool vbo_dirty;2021void (*copy_data)(struct nouveau_context *,22struct nouveau_bo *dst, unsigned, unsigned,23struct nouveau_bo *src, unsigned, unsigned, unsigned);24void (*push_data)(struct nouveau_context *,25struct nouveau_bo *dst, unsigned, unsigned,26unsigned, const void *);27/* base, size refer to the whole constant buffer */28void (*push_cb)(struct nouveau_context *,29struct nv04_resource *,30unsigned offset, unsigned words, const uint32_t *);3132/* @return: @ref reduced by nr of references found in context */33int (*invalidate_resource_storage)(struct nouveau_context *,34struct pipe_resource *,35int ref);3637struct {38uint8_t *map;39unsigned id;40unsigned wrap;41unsigned offset;42unsigned end;43struct nouveau_bo *bo[NOUVEAU_MAX_SCRATCH_BUFS];44struct nouveau_bo *current;45struct runout {46unsigned nr;47struct nouveau_bo *bo[0];48} *runout;49unsigned bo_size;50} scratch;5152struct {53uint32_t buf_cache_count;54uint32_t buf_cache_frame;55} stats;56};5758static inline struct nouveau_context *59nouveau_context(struct pipe_context *pipe)60{61return (struct nouveau_context *)pipe;62}6364void65nouveau_context_init_vdec(struct nouveau_context *);6667void68nouveau_context_init(struct nouveau_context *);6970void71nouveau_scratch_runout_release(struct nouveau_context *);7273/* 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 less75* work, and we need the wrap index anyway for extreme situations.76*/77static inline void78nouveau_scratch_done(struct nouveau_context *nv)79{80nv->scratch.wrap = nv->scratch.id;81if (unlikely(nv->scratch.runout))82nouveau_scratch_runout_release(nv);83}8485/* Get pointer to scratch buffer.86* The returned nouveau_bo is only referenced by the context, don't un-ref it !87*/88void *89nouveau_scratch_get(struct nouveau_context *, unsigned size, uint64_t *gpu_addr,90struct nouveau_bo **);9192static inline void93nouveau_context_destroy(struct nouveau_context *ctx)94{95int i;9697for (i = 0; i < NOUVEAU_MAX_SCRATCH_BUFS; ++i)98if (ctx->scratch.bo[i])99nouveau_bo_ref(NULL, &ctx->scratch.bo[i]);100101FREE(ctx);102}103104static inline void105nouveau_context_update_frame_stats(struct nouveau_context *nv)106{107nv->stats.buf_cache_frame <<= 1;108if (nv->stats.buf_cache_count) {109nv->stats.buf_cache_count = 0;110nv->stats.buf_cache_frame |= 1;111if ((nv->stats.buf_cache_frame & 0xf) == 0xf)112nv->screen->hint_buf_keep_sysmem_copy = true;113}114}115116#endif117118119