nvc0: add preliminary support for images
[mesa.git] / src / gallium / drivers / nouveau / nvc0 / nvc0_screen.h
1 #ifndef __NVC0_SCREEN_H__
2 #define __NVC0_SCREEN_H__
3
4 #include "nouveau_screen.h"
5 #include "nouveau_mm.h"
6 #include "nouveau_fence.h"
7 #include "nouveau_heap.h"
8
9 #include "nv_object.xml.h"
10
11 #include "nvc0/nvc0_winsys.h"
12 #include "nvc0/nvc0_stateobj.h"
13
14 #define NVC0_TIC_MAX_ENTRIES 2048
15 #define NVC0_TSC_MAX_ENTRIES 2048
16
17 /* doesn't count reserved slots (for auxiliary constants, immediates, etc.) */
18 #define NVC0_MAX_PIPE_CONSTBUFS 14
19
20 #define NVC0_MAX_SURFACE_SLOTS 16
21
22 #define NVC0_MAX_VIEWPORTS 16
23
24 #define NVC0_MAX_BUFFERS 32
25
26 #define NVC0_MAX_IMAGES 8
27
28 struct nvc0_context;
29
30 struct nvc0_blitter;
31
32 struct nvc0_graph_state {
33 bool flushed;
34 bool rasterizer_discard;
35 bool early_z_forced;
36 bool prim_restart;
37 uint32_t instance_elts; /* bitmask of per-instance elements */
38 uint32_t instance_base;
39 uint32_t constant_vbos;
40 uint32_t constant_elts;
41 int32_t index_bias;
42 uint16_t scissor;
43 bool flatshade;
44 uint8_t patch_vertices;
45 uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
46 uint8_t num_vtxbufs;
47 uint8_t num_vtxelts;
48 uint8_t num_textures[6];
49 uint8_t num_samplers[6];
50 uint8_t tls_required; /* bitmask of shader types using l[] */
51 uint8_t c14_bound; /* whether immediate array constbuf is bound */
52 uint8_t clip_enable;
53 uint32_t clip_mode;
54 uint32_t uniform_buffer_bound[6];
55 struct nvc0_transform_feedback_state *tfb;
56 bool seamless_cube_map;
57 };
58
59 struct nvc0_screen {
60 struct nouveau_screen base;
61
62 struct nvc0_context *cur_ctx;
63 struct nvc0_graph_state save_state;
64
65 int num_occlusion_queries_active;
66
67 struct nouveau_bo *text;
68 struct nouveau_bo *parm; /* for COMPUTE */
69 struct nouveau_bo *uniform_bo;
70 struct nouveau_bo *tls;
71 struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
72 struct nouveau_bo *poly_cache;
73
74 uint8_t gpc_count;
75 uint16_t mp_count;
76 uint16_t mp_count_compute; /* magic reg can make compute use fewer MPs */
77
78 struct nouveau_heap *text_heap;
79 struct nouveau_heap *lib_code; /* allocated from text_heap */
80
81 struct nvc0_blitter *blitter;
82
83 struct {
84 void **entries;
85 int next;
86 uint32_t lock[NVC0_TIC_MAX_ENTRIES / 32];
87 bool maxwell;
88 } tic;
89
90 struct {
91 void **entries;
92 int next;
93 uint32_t lock[NVC0_TSC_MAX_ENTRIES / 32];
94 } tsc;
95
96 struct {
97 struct nouveau_bo *bo;
98 uint32_t *map;
99 } fence;
100
101 struct {
102 struct nvc0_program *prog; /* compute state object to read MP counters */
103 struct nvc0_hw_sm_query *mp_counter[8]; /* counter to query allocation */
104 uint8_t num_hw_sm_active[2];
105 bool mp_counters_enabled;
106 } pm;
107
108 struct nouveau_object *eng3d; /* sqrt(1/2)|kepler> + sqrt(1/2)|fermi> */
109 struct nouveau_object *eng2d;
110 struct nouveau_object *m2mf;
111 struct nouveau_object *compute;
112 struct nouveau_object *nvsw;
113 };
114
115 static inline struct nvc0_screen *
116 nvc0_screen(struct pipe_screen *screen)
117 {
118 return (struct nvc0_screen *)screen;
119 }
120
121 int nvc0_screen_get_driver_query_info(struct pipe_screen *, unsigned,
122 struct pipe_driver_query_info *);
123
124 int nvc0_screen_get_driver_query_group_info(struct pipe_screen *, unsigned,
125 struct pipe_driver_query_group_info *);
126
127 bool nvc0_blitter_create(struct nvc0_screen *);
128 void nvc0_blitter_destroy(struct nvc0_screen *);
129
130 void nvc0_screen_make_buffers_resident(struct nvc0_screen *);
131
132 int nvc0_screen_tic_alloc(struct nvc0_screen *, void *);
133 int nvc0_screen_tsc_alloc(struct nvc0_screen *, void *);
134
135 int nve4_screen_compute_setup(struct nvc0_screen *, struct nouveau_pushbuf *);
136 int nvc0_screen_compute_setup(struct nvc0_screen *, struct nouveau_pushbuf *);
137
138 bool nvc0_screen_resize_tls_area(struct nvc0_screen *, uint32_t lpos,
139 uint32_t lneg, uint32_t cstack);
140
141 static inline void
142 nvc0_resource_fence(struct nv04_resource *res, uint32_t flags)
143 {
144 struct nvc0_screen *screen = nvc0_screen(res->base.screen);
145
146 if (res->mm) {
147 nouveau_fence_ref(screen->base.fence.current, &res->fence);
148 if (flags & NOUVEAU_BO_WR)
149 nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
150 }
151 }
152
153 static inline void
154 nvc0_resource_validate(struct nv04_resource *res, uint32_t flags)
155 {
156 if (likely(res->bo)) {
157 if (flags & NOUVEAU_BO_WR)
158 res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
159 NOUVEAU_BUFFER_STATUS_DIRTY;
160 if (flags & NOUVEAU_BO_RD)
161 res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
162
163 nvc0_resource_fence(res, flags);
164 }
165 }
166
167 struct nvc0_format {
168 uint32_t rt;
169 struct {
170 unsigned format:7;
171 unsigned type_r:3;
172 unsigned type_g:3;
173 unsigned type_b:3;
174 unsigned type_a:3;
175 unsigned src_x:3;
176 unsigned src_y:3;
177 unsigned src_z:3;
178 unsigned src_w:3;
179 } tic;
180 uint32_t usage;
181 };
182
183 struct nvc0_vertex_format {
184 uint32_t vtx;
185 uint32_t usage;
186 };
187
188 extern const struct nvc0_format nvc0_format_table[];
189 extern const struct nvc0_vertex_format nvc0_vertex_format[];
190
191 static inline void
192 nvc0_screen_tic_unlock(struct nvc0_screen *screen, struct nv50_tic_entry *tic)
193 {
194 if (tic->id >= 0)
195 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
196 }
197
198 static inline void
199 nvc0_screen_tsc_unlock(struct nvc0_screen *screen, struct nv50_tsc_entry *tsc)
200 {
201 if (tsc->id >= 0)
202 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
203 }
204
205 static inline void
206 nvc0_screen_tic_free(struct nvc0_screen *screen, struct nv50_tic_entry *tic)
207 {
208 if (tic->id >= 0) {
209 screen->tic.entries[tic->id] = NULL;
210 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
211 }
212 }
213
214 static inline void
215 nvc0_screen_tsc_free(struct nvc0_screen *screen, struct nv50_tsc_entry *tsc)
216 {
217 if (tsc->id >= 0) {
218 screen->tsc.entries[tsc->id] = NULL;
219 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
220 }
221 }
222
223 #endif