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