nv50,nvc0: handle user constbufs without wrapping them in a resource
[mesa.git] / src / gallium / drivers / nv50 / nv50_screen.h
1 #ifndef __NV50_SCREEN_H__
2 #define __NV50_SCREEN_H__
3
4 #include "nouveau/nouveau_screen.h"
5 #include "nouveau/nouveau_fence.h"
6 #include "nouveau/nouveau_mm.h"
7 #include "nouveau/nouveau_heap.h"
8
9 #include "nv50_winsys.h"
10 #include "nv50_stateobj.h"
11
12 #define NV50_TIC_MAX_ENTRIES 2048
13 #define NV50_TSC_MAX_ENTRIES 2048
14
15 /* doesn't count reserved slots (for auxiliary constants, immediates, etc.) */
16 #define NV50_MAX_PIPE_CONSTBUFS 14
17
18 struct nv50_context;
19
20 #define NV50_CODE_BO_SIZE_LOG2 19
21
22 #define NV50_SCREEN_RESIDENT_BO_COUNT 5
23
24 struct nv50_blitctx;
25
26 struct nv50_screen {
27 struct nouveau_screen base;
28
29 struct nv50_context *cur_ctx;
30
31 struct nouveau_bo *code;
32 struct nouveau_bo *uniforms;
33 struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
34 struct nouveau_bo *stack_bo;
35 struct nouveau_bo *tls_bo;
36
37 uint64_t tls_size;
38
39 struct nouveau_heap *vp_code_heap;
40 struct nouveau_heap *gp_code_heap;
41 struct nouveau_heap *fp_code_heap;
42
43 struct nv50_blitctx *blitctx;
44
45 struct {
46 void **entries;
47 int next;
48 uint32_t lock[NV50_TIC_MAX_ENTRIES / 32];
49 } tic;
50
51 struct {
52 void **entries;
53 int next;
54 uint32_t lock[NV50_TSC_MAX_ENTRIES / 32];
55 } tsc;
56
57 struct {
58 uint32_t *map;
59 struct nouveau_bo *bo;
60 } fence;
61
62 struct nouveau_object *sync;
63
64 struct nouveau_object *tesla;
65 struct nouveau_object *eng2d;
66 struct nouveau_object *m2mf;
67 };
68
69 static INLINE struct nv50_screen *
70 nv50_screen(struct pipe_screen *screen)
71 {
72 return (struct nv50_screen *)screen;
73 }
74
75 boolean nv50_blitctx_create(struct nv50_screen *);
76
77 int nv50_screen_tic_alloc(struct nv50_screen *, void *);
78 int nv50_screen_tsc_alloc(struct nv50_screen *, void *);
79
80 static INLINE void
81 nv50_resource_fence(struct nv04_resource *res, uint32_t flags)
82 {
83 struct nv50_screen *screen = nv50_screen(res->base.screen);
84
85 if (res->mm) {
86 nouveau_fence_ref(screen->base.fence.current, &res->fence);
87 if (flags & NOUVEAU_BO_WR)
88 nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
89 }
90 }
91
92 static INLINE void
93 nv50_resource_validate(struct nv04_resource *res, uint32_t flags)
94 {
95 if (likely(res->bo)) {
96 if (flags & NOUVEAU_BO_WR)
97 res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
98 if (flags & NOUVEAU_BO_RD)
99 res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
100
101 nv50_resource_fence(res, flags);
102 }
103 }
104
105 struct nv50_format {
106 uint32_t rt;
107 uint32_t tic;
108 uint32_t vtx;
109 uint32_t usage;
110 };
111
112 extern const struct nv50_format nv50_format_table[];
113
114 static INLINE void
115 nv50_screen_tic_unlock(struct nv50_screen *screen, struct nv50_tic_entry *tic)
116 {
117 if (tic->id >= 0)
118 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
119 }
120
121 static INLINE void
122 nv50_screen_tsc_unlock(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
123 {
124 if (tsc->id >= 0)
125 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
126 }
127
128 static INLINE void
129 nv50_screen_tic_free(struct nv50_screen *screen, struct nv50_tic_entry *tic)
130 {
131 if (tic->id >= 0) {
132 screen->tic.entries[tic->id] = NULL;
133 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
134 }
135 }
136
137 static INLINE void
138 nv50_screen_tsc_free(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
139 {
140 if (tsc->id >= 0) {
141 screen->tsc.entries[tsc->id] = NULL;
142 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
143 }
144 }
145
146 #endif