ce51f0fc254e115b97bfde0077499fc810d341f9
[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_graph_state {
29 uint32_t instance_elts; /* bitmask of per-instance elements */
30 uint32_t instance_base;
31 uint32_t interpolant_ctrl;
32 uint32_t semantic_color;
33 uint32_t semantic_psize;
34 int32_t index_bias;
35 bool uniform_buffer_bound[3];
36 bool prim_restart;
37 bool point_sprite;
38 bool rt_serialize;
39 bool flushed;
40 bool rasterizer_discard;
41 uint8_t tls_required;
42 bool new_tls_space;
43 uint8_t num_vtxbufs;
44 uint8_t num_vtxelts;
45 uint8_t num_textures[3];
46 uint8_t num_samplers[3];
47 uint8_t prim_size;
48 uint16_t scissor;
49 };
50
51 struct nv50_screen {
52 struct nouveau_screen base;
53
54 struct nv50_context *cur_ctx;
55 struct nv50_graph_state save_state;
56
57 int num_occlusion_queries_active;
58
59 struct nouveau_bo *code;
60 struct nouveau_bo *uniforms;
61 struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
62 struct nouveau_bo *stack_bo;
63 struct nouveau_bo *tls_bo;
64
65 unsigned TPs;
66 unsigned MPsInTP;
67 unsigned max_tls_space;
68 unsigned cur_tls_space;
69
70 struct nouveau_heap *vp_code_heap;
71 struct nouveau_heap *gp_code_heap;
72 struct nouveau_heap *fp_code_heap;
73
74 struct nv50_blitter *blitter;
75
76 struct {
77 void **entries;
78 int next;
79 uint32_t lock[NV50_TIC_MAX_ENTRIES / 32];
80 } tic;
81
82 struct {
83 void **entries;
84 int next;
85 uint32_t lock[NV50_TSC_MAX_ENTRIES / 32];
86 } tsc;
87
88 struct {
89 uint32_t *map;
90 struct nouveau_bo *bo;
91 } fence;
92
93 struct nouveau_object *sync;
94
95 struct nouveau_object *tesla;
96 struct nouveau_object *eng2d;
97 struct nouveau_object *m2mf;
98 };
99
100 static inline struct nv50_screen *
101 nv50_screen(struct pipe_screen *screen)
102 {
103 return (struct nv50_screen *)screen;
104 }
105
106 bool nv50_blitter_create(struct nv50_screen *);
107 void nv50_blitter_destroy(struct nv50_screen *);
108
109 int nv50_screen_tic_alloc(struct nv50_screen *, void *);
110 int nv50_screen_tsc_alloc(struct nv50_screen *, void *);
111
112 static inline void
113 nv50_resource_fence(struct nv04_resource *res, uint32_t flags)
114 {
115 struct nv50_screen *screen = nv50_screen(res->base.screen);
116
117 if (res->mm) {
118 nouveau_fence_ref(screen->base.fence.current, &res->fence);
119 if (flags & NOUVEAU_BO_WR)
120 nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
121 }
122 }
123
124 static inline void
125 nv50_resource_validate(struct nv04_resource *res, uint32_t flags)
126 {
127 if (likely(res->bo)) {
128 if (flags & NOUVEAU_BO_WR)
129 res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
130 NOUVEAU_BUFFER_STATUS_DIRTY;
131 if (flags & NOUVEAU_BO_RD)
132 res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
133
134 nv50_resource_fence(res, flags);
135 }
136 }
137
138 struct nv50_format {
139 uint32_t rt;
140 uint32_t tic;
141 uint32_t vtx;
142 uint32_t usage;
143 };
144
145 extern const struct nv50_format nv50_format_table[];
146
147 static inline void
148 nv50_screen_tic_unlock(struct nv50_screen *screen, struct nv50_tic_entry *tic)
149 {
150 if (tic->id >= 0)
151 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
152 }
153
154 static inline void
155 nv50_screen_tsc_unlock(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
156 {
157 if (tsc->id >= 0)
158 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
159 }
160
161 static inline void
162 nv50_screen_tic_free(struct nv50_screen *screen, struct nv50_tic_entry *tic)
163 {
164 if (tic->id >= 0) {
165 screen->tic.entries[tic->id] = NULL;
166 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
167 }
168 }
169
170 static inline void
171 nv50_screen_tsc_free(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
172 {
173 if (tsc->id >= 0) {
174 screen->tsc.entries[tsc->id] = NULL;
175 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
176 }
177 }
178
179 extern int nv50_tls_realloc(struct nv50_screen *screen, unsigned tls_space);
180
181 #endif