Home | History | Annotate | Download | only in nouveau
      1 #ifndef __NOUVEAU_CONTEXT_H__
      2 #define __NOUVEAU_CONTEXT_H__
      3 
      4 #include "pipe/p_context.h"
      5 #include <libdrm/nouveau.h>
      6 
      7 #define NOUVEAU_MAX_SCRATCH_BUFS 4
      8 
      9 struct nouveau_context {
     10    struct pipe_context pipe;
     11    struct nouveau_screen *screen;
     12 
     13    struct nouveau_client *client;
     14    struct nouveau_pushbuf *pushbuf;
     15 
     16    boolean vbo_dirty;
     17    boolean cb_dirty;
     18 
     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 *);
     30 
     31    struct {
     32       uint8_t *map;
     33       unsigned id;
     34       unsigned wrap;
     35       unsigned offset;
     36       unsigned end;
     37       struct nouveau_bo *bo[NOUVEAU_MAX_SCRATCH_BUFS];
     38       struct nouveau_bo *current;
     39       struct nouveau_bo **runout;
     40       unsigned nr_runout;
     41       unsigned bo_size;
     42    } scratch;
     43 };
     44 
     45 static INLINE struct nouveau_context *
     46 nouveau_context(struct pipe_context *pipe)
     47 {
     48    return (struct nouveau_context *)pipe;
     49 }
     50 
     51 void
     52 nouveau_context_init_vdec(struct nouveau_context *);
     53 
     54 void
     55 nouveau_scratch_runout_release(struct nouveau_context *);
     56 
     57 /* This is needed because we don't hold references outside of context::scratch,
     58  * because we don't want to un-bo_ref each allocation every time. This is less
     59  * work, and we need the wrap index anyway for extreme situations.
     60  */
     61 static INLINE void
     62 nouveau_scratch_done(struct nouveau_context *nv)
     63 {
     64    nv->scratch.wrap = nv->scratch.id;
     65    if (unlikely(nv->scratch.nr_runout))
     66       nouveau_scratch_runout_release(nv);
     67 }
     68 
     69 /* Get pointer to scratch buffer.
     70  * The returned nouveau_bo is only referenced by the context, don't un-ref it !
     71  */
     72 void *
     73 nouveau_scratch_get(struct nouveau_context *, unsigned size, uint64_t *gpu_addr,
     74                     struct nouveau_bo **);
     75 
     76 static INLINE void
     77 nouveau_context_destroy(struct nouveau_context *ctx)
     78 {
     79    int i;
     80 
     81    for (i = 0; i < NOUVEAU_MAX_SCRATCH_BUFS; ++i)
     82       if (ctx->scratch.bo[i])
     83          nouveau_bo_ref(NULL, &ctx->scratch.bo[i]);
     84 
     85    FREE(ctx);
     86 }
     87 #endif
     88