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