nouveau: improve buffer transfers
[mesa.git] / src / gallium / drivers / nouveau / nouveau_buffer.h
1 #ifndef __NOUVEAU_BUFFER_H__
2 #define __NOUVEAU_BUFFER_H__
3
4 #include "util/u_transfer.h"
5 #include "util/u_double_list.h"
6
7 struct pipe_resource;
8 struct nouveau_context;
9 struct nouveau_bo;
10
11 /* DIRTY: buffer was (or will be after the next flush) written to by GPU and
12 * resource->data has not been updated to reflect modified VRAM contents
13 *
14 * USER_MEMORY: resource->data is a pointer to client memory and may change
15 * between GL calls
16 */
17 #define NOUVEAU_BUFFER_STATUS_GPU_READING (1 << 0)
18 #define NOUVEAU_BUFFER_STATUS_GPU_WRITING (1 << 1)
19 #define NOUVEAU_BUFFER_STATUS_DIRTY (1 << 2)
20 #define NOUVEAU_BUFFER_STATUS_USER_MEMORY (1 << 7)
21
22 #define NOUVEAU_BUFFER_STATUS_REALLOC_MASK NOUVEAU_BUFFER_STATUS_USER_MEMORY
23
24 /* Resources, if mapped into the GPU's address space, are guaranteed to
25 * have constant virtual addresses (nv50+).
26 *
27 * The address of a resource will lie within the nouveau_bo referenced,
28 * and this bo should be added to the memory manager's validation list.
29 */
30 struct nv04_resource {
31 struct pipe_resource base;
32 const struct u_resource_vtbl *vtbl;
33
34 uint64_t address; /* virtual address (nv50+) */
35
36 uint8_t *data;
37 struct nouveau_bo *bo;
38 uint32_t offset;
39
40 uint8_t status;
41 uint8_t domain;
42
43 struct nouveau_fence *fence;
44 struct nouveau_fence *fence_wr;
45
46 struct nouveau_mm_allocation *mm;
47 };
48
49 void
50 nouveau_buffer_release_gpu_storage(struct nv04_resource *);
51
52 boolean
53 nouveau_buffer_download(struct nouveau_context *, struct nv04_resource *,
54 unsigned start, unsigned size);
55
56 boolean
57 nouveau_buffer_migrate(struct nouveau_context *,
58 struct nv04_resource *, unsigned domain);
59
60 void *
61 nouveau_resource_map_offset(struct nouveau_context *, struct nv04_resource *,
62 uint32_t offset, uint32_t flags);
63
64 static INLINE void
65 nouveau_resource_unmap(struct nv04_resource *res)
66 {
67 /* no-op */
68 }
69
70 static INLINE struct nv04_resource *
71 nv04_resource(struct pipe_resource *resource)
72 {
73 return (struct nv04_resource *)resource;
74 }
75
76 /* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */
77 static INLINE boolean
78 nouveau_resource_mapped_by_gpu(struct pipe_resource *resource)
79 {
80 return nv04_resource(resource)->domain != 0;
81 }
82
83 struct pipe_resource *
84 nouveau_buffer_create(struct pipe_screen *pscreen,
85 const struct pipe_resource *templ);
86
87 struct pipe_resource *
88 nouveau_user_buffer_create(struct pipe_screen *screen, void *ptr,
89 unsigned bytes, unsigned usage);
90
91 boolean
92 nouveau_user_buffer_upload(struct nouveau_context *, struct nv04_resource *,
93 unsigned base, unsigned size);
94
95 /* Copy data to a scratch buffer and return address & bo the data resides in.
96 * Returns 0 on failure.
97 */
98 uint64_t
99 nouveau_scratch_data(struct nouveau_context *,
100 const void *data, unsigned base, unsigned size,
101 struct nouveau_bo **);
102
103 #endif