nvc0_screen.h revision 6de94e1012498b6859d9796f2836a162bb0ca4bc
1#ifndef __NVC0_SCREEN_H__
2#define __NVC0_SCREEN_H__
3
4#define NOUVEAU_NVC0
5#include "nouveau/nouveau_screen.h"
6#undef NOUVEAU_NVC0
7#include "nvc0_winsys.h"
8#include "nvc0_stateobj.h"
9
10#define NVC0_TIC_MAX_ENTRIES 2048
11#define NVC0_TSC_MAX_ENTRIES 2048
12
13struct nvc0_mman;
14struct nvc0_context;
15struct nvc0_fence;
16
17#define NVC0_SCRATCH_SIZE (2 << 20)
18#define NVC0_SCRATCH_NR_BUFFERS 2
19
20struct nvc0_screen {
21   struct nouveau_screen base;
22   struct nouveau_winsys *nvws;
23
24   struct nvc0_context *cur_ctx;
25
26   struct nouveau_bo *text;
27   struct nouveau_bo *uniforms;
28   struct nouveau_bo *tls;
29   struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
30   struct nouveau_bo *mp_stack_bo;
31
32   uint64_t tls_size;
33
34   struct nouveau_resource *text_heap;
35
36   struct {
37      struct nouveau_bo *bo[NVC0_SCRATCH_NR_BUFFERS];
38      uint8_t *buf;
39      int index;
40      uint32_t offset;
41   } scratch;
42
43   struct {
44      void **entries;
45      int next;
46      uint32_t lock[NVC0_TIC_MAX_ENTRIES / 32];
47   } tic;
48
49   struct {
50      void **entries;
51      int next;
52      uint32_t lock[NVC0_TSC_MAX_ENTRIES / 32];
53   } tsc;
54
55   struct {
56      uint32_t *map;
57      struct nvc0_fence *head;
58      struct nvc0_fence *tail;
59      struct nvc0_fence *current;
60      uint32_t sequence;
61      uint32_t sequence_ack;
62      struct nouveau_bo *bo;
63   } fence;
64
65   struct nvc0_mman *mm_GART;
66   struct nvc0_mman *mm_VRAM;
67   struct nvc0_mman *mm_VRAM_fe0;
68
69   struct nouveau_grobj *fermi;
70   struct nouveau_grobj *eng2d;
71   struct nouveau_grobj *m2mf;
72};
73
74static INLINE struct nvc0_screen *
75nvc0_screen(struct pipe_screen *screen)
76{
77   return (struct nvc0_screen *)screen;
78}
79
80/* Since a resource can be migrated, we need to decouple allocations from
81 * them. This struct is linked with fences for delayed freeing of allocs.
82 */
83struct nvc0_mm_allocation {
84   struct nvc0_mm_allocation *next;
85   void *priv;
86   uint32_t offset;
87};
88
89extern struct nvc0_mman *
90nvc0_mm_create(struct nouveau_device *, uint32_t domain, uint32_t storage_type);
91
92extern void
93nvc0_mm_destroy(struct nvc0_mman *);
94
95extern struct nvc0_mm_allocation *
96nvc0_mm_allocate(struct nvc0_mman *,
97                 uint32_t size, struct nouveau_bo **, uint32_t *offset);
98extern void
99nvc0_mm_free(struct nvc0_mm_allocation *);
100
101void nvc0_screen_make_buffers_resident(struct nvc0_screen *);
102
103int nvc0_screen_tic_alloc(struct nvc0_screen *, void *);
104int nvc0_screen_tsc_alloc(struct nvc0_screen *, void *);
105
106static INLINE void
107nvc0_resource_fence(struct nvc0_resource *res, uint32_t flags)
108{
109   struct nvc0_screen *screen = nvc0_screen(res->base.screen);
110
111   if (res->mm) {
112      nvc0_fence_reference(&res->fence, screen->fence.current);
113
114      if (flags & NOUVEAU_BO_WR)
115         nvc0_fence_reference(&res->fence_wr, screen->fence.current);
116   }
117}
118
119static INLINE void
120nvc0_resource_validate(struct nvc0_resource *res, uint32_t flags)
121{
122   struct nvc0_screen *screen = nvc0_screen(res->base.screen);
123
124   nouveau_bo_validate(screen->base.channel, res->bo, flags);
125
126   nvc0_resource_fence(res, flags);
127}
128
129
130boolean
131nvc0_screen_fence_new(struct nvc0_screen *, struct nvc0_fence **, boolean emit);
132
133void
134nvc0_screen_fence_next(struct nvc0_screen *);
135
136static INLINE boolean
137nvc0_screen_fence_emit(struct nvc0_screen *screen)
138{
139   nvc0_fence_emit(screen->fence.current);
140
141   return nvc0_screen_fence_new(screen, &screen->fence.current, FALSE);
142}
143
144struct nvc0_format {
145   uint32_t rt;
146   uint32_t tic;
147   uint32_t vtx;
148   uint32_t usage;
149};
150
151extern const struct nvc0_format nvc0_format_table[];
152
153static INLINE void
154nvc0_screen_tic_unlock(struct nvc0_screen *screen, struct nvc0_tic_entry *tic)
155{
156   if (tic->id >= 0)
157      screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
158}
159
160static INLINE void
161nvc0_screen_tsc_unlock(struct nvc0_screen *screen, struct nvc0_tsc_entry *tsc)
162{
163   if (tsc->id >= 0)
164      screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
165}
166
167static INLINE void
168nvc0_screen_tic_free(struct nvc0_screen *screen, struct nvc0_tic_entry *tic)
169{
170   if (tic->id >= 0) {
171      screen->tic.entries[tic->id] = NULL;
172      screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
173   }
174}
175
176static INLINE void
177nvc0_screen_tsc_free(struct nvc0_screen *screen, struct nvc0_tsc_entry *tsc)
178{
179   if (tsc->id >= 0) {
180      screen->tsc.entries[tsc->id] = NULL;
181      screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
182   }
183}
184
185#endif
186