f8ce365135a33c701b6e62b654d07efedd9dd6c8
[mesa.git] / src / gallium / drivers / nouveau / nv50 / nv50_screen.h
1 #ifndef __NV50_SCREEN_H__
2 #define __NV50_SCREEN_H__
3
4 #include "nouveau_screen.h"
5 #include "nouveau_fence.h"
6 #include "nouveau_mm.h"
7 #include "nouveau_heap.h"
8
9 #include "nv50/nv50_winsys.h"
10 #include "nv50/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 #define NV50_MAX_VIEWPORTS 16
25
26 struct nv50_blitter;
27
28 struct nv50_screen {
29 struct nouveau_screen base;
30
31 struct nv50_context *cur_ctx;
32
33 struct nouveau_bo *code;
34 struct nouveau_bo *uniforms;
35 struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
36 struct nouveau_bo *stack_bo;
37 struct nouveau_bo *tls_bo;
38
39 unsigned TPs;
40 unsigned MPsInTP;
41 unsigned max_tls_space;
42 unsigned cur_tls_space;
43
44 struct nouveau_heap *vp_code_heap;
45 struct nouveau_heap *gp_code_heap;
46 struct nouveau_heap *fp_code_heap;
47
48 struct nv50_blitter *blitter;
49
50 struct {
51 void **entries;
52 int next;
53 uint32_t lock[NV50_TIC_MAX_ENTRIES / 32];
54 } tic;
55
56 struct {
57 void **entries;
58 int next;
59 uint32_t lock[NV50_TSC_MAX_ENTRIES / 32];
60 } tsc;
61
62 struct {
63 uint32_t *map;
64 struct nouveau_bo *bo;
65 } fence;
66
67 struct nouveau_object *sync;
68
69 struct nouveau_object *tesla;
70 struct nouveau_object *eng2d;
71 struct nouveau_object *m2mf;
72 };
73
74 static INLINE struct nv50_screen *
75 nv50_screen(struct pipe_screen *screen)
76 {
77 return (struct nv50_screen *)screen;
78 }
79
80 boolean nv50_blitter_create(struct nv50_screen *);
81 void nv50_blitter_destroy(struct nv50_screen *);
82
83 int nv50_screen_tic_alloc(struct nv50_screen *, void *);
84 int nv50_screen_tsc_alloc(struct nv50_screen *, void *);
85
86 static INLINE void
87 nv50_resource_fence(struct nv04_resource *res, uint32_t flags)
88 {
89 struct nv50_screen *screen = nv50_screen(res->base.screen);
90
91 if (res->mm) {
92 nouveau_fence_ref(screen->base.fence.current, &res->fence);
93 if (flags & NOUVEAU_BO_WR)
94 nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
95 }
96 }
97
98 static INLINE void
99 nv50_resource_validate(struct nv04_resource *res, uint32_t flags)
100 {
101 if (likely(res->bo)) {
102 if (flags & NOUVEAU_BO_WR)
103 res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
104 NOUVEAU_BUFFER_STATUS_DIRTY;
105 if (flags & NOUVEAU_BO_RD)
106 res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
107
108 nv50_resource_fence(res, flags);
109 }
110 }
111
112 struct nv50_format {
113 uint32_t rt;
114 uint32_t tic;
115 uint32_t vtx;
116 uint32_t usage;
117 };
118
119 extern const struct nv50_format nv50_format_table[];
120
121 static INLINE void
122 nv50_screen_tic_unlock(struct nv50_screen *screen, struct nv50_tic_entry *tic)
123 {
124 if (tic->id >= 0)
125 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
126 }
127
128 static INLINE void
129 nv50_screen_tsc_unlock(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
130 {
131 if (tsc->id >= 0)
132 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
133 }
134
135 static INLINE void
136 nv50_screen_tic_free(struct nv50_screen *screen, struct nv50_tic_entry *tic)
137 {
138 if (tic->id >= 0) {
139 screen->tic.entries[tic->id] = NULL;
140 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
141 }
142 }
143
144 static INLINE void
145 nv50_screen_tsc_free(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
146 {
147 if (tsc->id >= 0) {
148 screen->tsc.entries[tsc->id] = NULL;
149 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
150 }
151 }
152
153 extern int nv50_tls_realloc(struct nv50_screen *screen, unsigned tls_space);
154
155 #endif