1bf215546Sopenharmony_ci#ifndef __NOUVEAU_BUFFER_H__
2bf215546Sopenharmony_ci#define __NOUVEAU_BUFFER_H__
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_ci#include "util/u_range.h"
5bf215546Sopenharmony_ci#include "util/u_transfer.h"
6bf215546Sopenharmony_ci#include "util/list.h"
7bf215546Sopenharmony_ci
8bf215546Sopenharmony_cistruct pipe_resource;
9bf215546Sopenharmony_cistruct nouveau_context;
10bf215546Sopenharmony_cistruct nouveau_bo;
11bf215546Sopenharmony_ci
12bf215546Sopenharmony_ci/* DIRTY: buffer was (or will be after the next flush) written to by GPU and
13bf215546Sopenharmony_ci *  resource->data has not been updated to reflect modified VRAM contents
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * USER_MEMORY: resource->data is a pointer to client memory and may change
16bf215546Sopenharmony_ci *  between GL calls
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * USER_PTR: bo is backed by user memory mapped into the GPUs VM
19bf215546Sopenharmony_ci */
20bf215546Sopenharmony_ci#define NOUVEAU_BUFFER_STATUS_GPU_READING (1 << 0)
21bf215546Sopenharmony_ci#define NOUVEAU_BUFFER_STATUS_GPU_WRITING (1 << 1)
22bf215546Sopenharmony_ci#define NOUVEAU_BUFFER_STATUS_DIRTY       (1 << 2)
23bf215546Sopenharmony_ci#define NOUVEAU_BUFFER_STATUS_USER_PTR    (1 << 6)
24bf215546Sopenharmony_ci#define NOUVEAU_BUFFER_STATUS_USER_MEMORY (1 << 7)
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#define NOUVEAU_BUFFER_STATUS_REALLOC_MASK NOUVEAU_BUFFER_STATUS_USER_MEMORY
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/* Resources, if mapped into the GPU's address space, are guaranteed to
29bf215546Sopenharmony_ci * have constant virtual addresses (nv50+).
30bf215546Sopenharmony_ci *
31bf215546Sopenharmony_ci * The address of a resource will lie within the nouveau_bo referenced,
32bf215546Sopenharmony_ci * and this bo should be added to the memory manager's validation list.
33bf215546Sopenharmony_ci */
34bf215546Sopenharmony_cistruct nv04_resource {
35bf215546Sopenharmony_ci   struct pipe_resource base;
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci   uint64_t address; /* virtual address (nv50+) */
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci   uint8_t *data; /* resource's contents, if domain == 0, or cached */
40bf215546Sopenharmony_ci   struct nouveau_bo *bo;
41bf215546Sopenharmony_ci   uint32_t offset; /* offset into the data/bo */
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci   uint8_t status;
44bf215546Sopenharmony_ci   uint8_t domain;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci   uint16_t cb_bindings[6]; /* per-shader per-slot bindings */
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   struct nouveau_fence *fence;
49bf215546Sopenharmony_ci   struct nouveau_fence *fence_wr;
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   struct nouveau_mm_allocation *mm;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   /* buffer range that has been initialized */
54bf215546Sopenharmony_ci   struct util_range valid_buffer_range;
55bf215546Sopenharmony_ci};
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_civoid
58bf215546Sopenharmony_cinouveau_buffer_release_gpu_storage(struct nv04_resource *);
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_civoid
61bf215546Sopenharmony_cinouveau_copy_buffer(struct nouveau_context *,
62bf215546Sopenharmony_ci                    struct nv04_resource *dst, unsigned dst_pos,
63bf215546Sopenharmony_ci                    struct nv04_resource *src, unsigned src_pos, unsigned size);
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_cibool
66bf215546Sopenharmony_cinouveau_buffer_migrate(struct nouveau_context *,
67bf215546Sopenharmony_ci                       struct nv04_resource *, unsigned domain);
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_civoid *
70bf215546Sopenharmony_cinouveau_resource_map_offset(struct nouveau_context *, struct nv04_resource *,
71bf215546Sopenharmony_ci                            uint32_t offset, uint32_t flags);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_civoid
74bf215546Sopenharmony_cinouveau_buffer_destroy(struct pipe_screen *pscreen,
75bf215546Sopenharmony_ci                       struct pipe_resource *presource);
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_civoid
78bf215546Sopenharmony_cinouveau_buffer_transfer_flush_region(struct pipe_context *pipe,
79bf215546Sopenharmony_ci                                     struct pipe_transfer *transfer,
80bf215546Sopenharmony_ci                                     const struct pipe_box *box);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_cistatic inline void
83bf215546Sopenharmony_cinouveau_resource_unmap(struct nv04_resource *res)
84bf215546Sopenharmony_ci{
85bf215546Sopenharmony_ci   /* no-op */
86bf215546Sopenharmony_ci}
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_cistatic inline struct nv04_resource *
89bf215546Sopenharmony_cinv04_resource(struct pipe_resource *resource)
90bf215546Sopenharmony_ci{
91bf215546Sopenharmony_ci   return (struct nv04_resource *)resource;
92bf215546Sopenharmony_ci}
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci/* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */
95bf215546Sopenharmony_cistatic inline bool
96bf215546Sopenharmony_cinouveau_resource_mapped_by_gpu(struct pipe_resource *resource)
97bf215546Sopenharmony_ci{
98bf215546Sopenharmony_ci   return nv04_resource(resource)->domain != 0;
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_cistruct pipe_resource *
102bf215546Sopenharmony_cinouveau_buffer_create(struct pipe_screen *pscreen,
103bf215546Sopenharmony_ci                      const struct pipe_resource *templ);
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_cistruct pipe_resource *
106bf215546Sopenharmony_cinouveau_buffer_create_from_user(struct pipe_screen *pscreen,
107bf215546Sopenharmony_ci                                const struct pipe_resource *templ,
108bf215546Sopenharmony_ci                                void *user_ptr);
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_cistruct pipe_resource *
111bf215546Sopenharmony_cinouveau_user_buffer_create(struct pipe_screen *screen, void *ptr,
112bf215546Sopenharmony_ci                           unsigned bytes, unsigned usage);
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_cibool
115bf215546Sopenharmony_cinouveau_user_buffer_upload(struct nouveau_context *, struct nv04_resource *,
116bf215546Sopenharmony_ci                           unsigned base, unsigned size);
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_civoid
119bf215546Sopenharmony_cinouveau_buffer_invalidate(struct pipe_context *pipe,
120bf215546Sopenharmony_ci                          struct pipe_resource *resource);
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci/* Copy data to a scratch buffer and return address & bo the data resides in.
123bf215546Sopenharmony_ci * Returns 0 on failure.
124bf215546Sopenharmony_ci */
125bf215546Sopenharmony_ciuint64_t
126bf215546Sopenharmony_cinouveau_scratch_data(struct nouveau_context *,
127bf215546Sopenharmony_ci                     const void *data, unsigned base, unsigned size,
128bf215546Sopenharmony_ci                     struct nouveau_bo **);
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_civoid *
131bf215546Sopenharmony_cinouveau_buffer_transfer_map(struct pipe_context *pipe,
132bf215546Sopenharmony_ci                            struct pipe_resource *resource,
133bf215546Sopenharmony_ci                            unsigned level, unsigned usage,
134bf215546Sopenharmony_ci                            const struct pipe_box *box,
135bf215546Sopenharmony_ci                            struct pipe_transfer **ptransfer);
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_civoid
138bf215546Sopenharmony_cinouveau_buffer_transfer_unmap(struct pipe_context *pipe,
139bf215546Sopenharmony_ci                              struct pipe_transfer *transfer);
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci#endif
142