Merge branch '7.8'
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.h
1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_CONTEXT_H__
3
4 #include <stdio.h>
5 #include "pipe/p_context.h"
6 #include "pipe/p_defines.h"
7 #include "pipe/p_state.h"
8 #include "pipe/p_compiler.h"
9
10 #include "util/u_memory.h"
11 #include "util/u_math.h"
12 #include "util/u_inlines.h"
13
14 #include "draw/draw_vertex.h"
15
16 #include "nouveau/nouveau_winsys.h"
17 #include "nouveau/nouveau_gldefs.h"
18 #include "nouveau/nouveau_stateobj.h"
19 #include "nouveau/nouveau_context.h"
20
21 #include "nv50_screen.h"
22 #include "nv50_program.h"
23
24 #define NOUVEAU_ERR(fmt, args...) \
25 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
26 #define NOUVEAU_MSG(fmt, args...) \
27 fprintf(stderr, "nouveau: "fmt, ##args);
28
29 /* Constant buffer assignment */
30 #define NV50_CB_PMISC 0
31 #define NV50_CB_PVP 1
32 #define NV50_CB_PFP 2
33 #define NV50_CB_PGP 3
34 #define NV50_CB_AUX 4
35
36 #define NV50_NEW_BLEND (1 << 0)
37 #define NV50_NEW_ZSA (1 << 1)
38 #define NV50_NEW_BLEND_COLOUR (1 << 2)
39 #define NV50_NEW_STIPPLE (1 << 3)
40 #define NV50_NEW_SCISSOR (1 << 4)
41 #define NV50_NEW_VIEWPORT (1 << 5)
42 #define NV50_NEW_RASTERIZER (1 << 6)
43 #define NV50_NEW_FRAMEBUFFER (1 << 7)
44 #define NV50_NEW_VERTPROG (1 << 8)
45 #define NV50_NEW_VERTPROG_CB (1 << 9)
46 #define NV50_NEW_FRAGPROG (1 << 10)
47 #define NV50_NEW_FRAGPROG_CB (1 << 11)
48 #define NV50_NEW_GEOMPROG (1 << 12)
49 #define NV50_NEW_GEOMPROG_CB (1 << 13)
50 #define NV50_NEW_ARRAYS (1 << 14)
51 #define NV50_NEW_SAMPLER (1 << 15)
52 #define NV50_NEW_TEXTURE (1 << 16)
53 #define NV50_NEW_STENCIL_REF (1 << 17)
54
55 struct nv50_blend_stateobj {
56 struct pipe_blend_state pipe;
57 struct nouveau_stateobj *so;
58 };
59
60 struct nv50_zsa_stateobj {
61 struct pipe_depth_stencil_alpha_state pipe;
62 struct nouveau_stateobj *so;
63 };
64
65 struct nv50_rasterizer_stateobj {
66 struct pipe_rasterizer_state pipe;
67 struct nouveau_stateobj *so;
68 };
69
70 struct nv50_sampler_stateobj {
71 boolean normalized;
72 unsigned tsc[8];
73 };
74
75 struct nv50_sampler_view {
76 struct pipe_sampler_view pipe;
77 uint32_t tic[8];
78 };
79
80 struct nv50_vtxelt_stateobj {
81 struct pipe_vertex_element pipe[16];
82 unsigned num_elements;
83 uint32_t hw[16];
84 };
85
86 static INLINE struct nv50_sampler_view *
87 nv50_sampler_view(struct pipe_sampler_view *view)
88 {
89 return (struct nv50_sampler_view *)view;
90 }
91
92 static INLINE unsigned
93 get_tile_height(uint32_t tile_mode)
94 {
95 return 1 << ((tile_mode & 0xf) + 2);
96 }
97
98 static INLINE unsigned
99 get_tile_depth(uint32_t tile_mode)
100 {
101 return 1 << (tile_mode >> 4);
102 }
103
104 struct nv50_miptree_level {
105 int *image_offset;
106 unsigned pitch;
107 unsigned tile_mode;
108 };
109
110 #define NV50_MAX_TEXTURE_LEVELS 16
111
112 struct nv50_miptree {
113 struct nouveau_miptree base;
114
115 struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
116 int image_nr;
117 int total_size;
118 };
119
120 static INLINE struct nv50_miptree *
121 nv50_miptree(struct pipe_texture *pt)
122 {
123 return (struct nv50_miptree *)pt;
124 }
125
126 struct nv50_surface {
127 struct pipe_surface base;
128 };
129
130 static INLINE struct nv50_surface *
131 nv50_surface(struct pipe_surface *pt)
132 {
133 return (struct nv50_surface *)pt;
134 }
135
136 struct nv50_state {
137 struct nouveau_stateobj *hw[64];
138 uint64_t hw_dirty;
139
140 unsigned sampler_view_nr[3];
141 struct nouveau_stateobj *vtxbuf;
142 struct nouveau_stateobj *vtxattr;
143 unsigned vtxelt_nr;
144 };
145
146 struct nv50_context {
147 struct pipe_context pipe;
148
149 struct nv50_screen *screen;
150
151 struct draw_context *draw;
152
153 struct nv50_state state;
154
155 unsigned dirty;
156 struct nv50_blend_stateobj *blend;
157 struct nv50_zsa_stateobj *zsa;
158 struct nv50_rasterizer_stateobj *rasterizer;
159 struct pipe_blend_color blend_colour;
160 struct pipe_stencil_ref stencil_ref;
161 struct pipe_poly_stipple stipple;
162 struct pipe_scissor_state scissor;
163 struct pipe_viewport_state viewport;
164 struct pipe_framebuffer_state framebuffer;
165 struct nv50_program *vertprog;
166 struct nv50_program *fragprog;
167 struct nv50_program *geomprog;
168 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
169 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
170 unsigned vtxbuf_nr;
171 struct nv50_vtxelt_stateobj *vtxelt;
172 struct nv50_sampler_stateobj *sampler[3][PIPE_MAX_SAMPLERS];
173 unsigned sampler_nr[3];
174 struct pipe_sampler_view *sampler_views[3][PIPE_MAX_SAMPLERS];
175 unsigned sampler_view_nr[3];
176
177 unsigned vbo_fifo;
178 };
179
180 static INLINE struct nv50_context *
181 nv50_context(struct pipe_context *pipe)
182 {
183 return (struct nv50_context *)pipe;
184 }
185
186 extern void nv50_init_surface_functions(struct nv50_context *nv50);
187 extern void nv50_init_state_functions(struct nv50_context *nv50);
188 extern void nv50_init_query_functions(struct nv50_context *nv50);
189 extern void nv50_init_transfer_functions(struct nv50_context *nv50);
190
191 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
192
193 extern int
194 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
195 int dx, int dy, struct pipe_surface *src, int sx, int sy,
196 int w, int h);
197
198 /* nv50_draw.c */
199 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
200
201 /* nv50_vbo.c */
202 extern void nv50_draw_arrays(struct pipe_context *, unsigned mode,
203 unsigned start, unsigned count);
204 extern void nv50_draw_arrays_instanced(struct pipe_context *, unsigned mode,
205 unsigned start, unsigned count,
206 unsigned startInstance,
207 unsigned instanceCount);
208 extern void nv50_draw_elements(struct pipe_context *pipe,
209 struct pipe_buffer *indexBuffer,
210 unsigned indexSize,
211 unsigned mode, unsigned start,
212 unsigned count);
213 extern void nv50_draw_elements_instanced(struct pipe_context *pipe,
214 struct pipe_buffer *indexBuffer,
215 unsigned indexSize,
216 unsigned mode, unsigned start,
217 unsigned count,
218 unsigned startInstance,
219 unsigned instanceCount);
220 extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj *cso);
221 extern struct nouveau_stateobj *nv50_vbo_validate(struct nv50_context *nv50);
222
223 /* nv50_push.c */
224 extern void
225 nv50_push_elements_instanced(struct pipe_context *, struct pipe_buffer *,
226 unsigned idxsize, unsigned mode, unsigned start,
227 unsigned count, unsigned i_start,
228 unsigned i_count);
229
230 /* nv50_clear.c */
231 extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
232 const float *rgba, double depth, unsigned stencil);
233
234 /* nv50_program.c */
235 extern struct nouveau_stateobj *
236 nv50_vertprog_validate(struct nv50_context *nv50);
237 extern struct nouveau_stateobj *
238 nv50_fragprog_validate(struct nv50_context *nv50);
239 extern struct nouveau_stateobj *
240 nv50_geomprog_validate(struct nv50_context *nv50);
241 extern struct nouveau_stateobj *
242 nv50_fp_linkage_validate(struct nv50_context *nv50);
243 extern struct nouveau_stateobj *
244 nv50_gp_linkage_validate(struct nv50_context *nv50);
245 extern void nv50_program_destroy(struct nv50_context *nv50,
246 struct nv50_program *p);
247
248 /* nv50_state_validate.c */
249 extern boolean nv50_state_validate(struct nv50_context *nv50, unsigned dwords);
250
251 extern void nv50_so_init_sifc(struct nv50_context *nv50,
252 struct nouveau_stateobj *so,
253 struct nouveau_bo *bo, unsigned reloc,
254 unsigned offset, unsigned size);
255
256 /* nv50_tex.c */
257 extern boolean nv50_tex_construct(struct nv50_sampler_view *view);
258 extern void nv50_tex_relocs(struct nv50_context *);
259 extern struct nouveau_stateobj *nv50_tex_validate(struct nv50_context *);
260
261 /* nv50_transfer.c */
262 extern void
263 nv50_upload_sifc(struct nv50_context *nv50,
264 struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc,
265 unsigned dst_format, int dst_w, int dst_h, int dst_pitch,
266 void *src, unsigned src_format, int src_pitch,
267 int x, int y, int w, int h, int cpp);
268
269 /* nv50_context.c */
270 struct pipe_context *
271 nv50_create(struct pipe_screen *pscreen, void *priv);
272
273 static INLINE unsigned
274 nv50_prim(unsigned mode)
275 {
276 switch (mode) {
277 case PIPE_PRIM_POINTS: return NV50TCL_VERTEX_BEGIN_POINTS;
278 case PIPE_PRIM_LINES: return NV50TCL_VERTEX_BEGIN_LINES;
279 case PIPE_PRIM_LINE_LOOP: return NV50TCL_VERTEX_BEGIN_LINE_LOOP;
280 case PIPE_PRIM_LINE_STRIP: return NV50TCL_VERTEX_BEGIN_LINE_STRIP;
281 case PIPE_PRIM_TRIANGLES: return NV50TCL_VERTEX_BEGIN_TRIANGLES;
282 case PIPE_PRIM_TRIANGLE_STRIP:
283 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP;
284 case PIPE_PRIM_TRIANGLE_FAN: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN;
285 case PIPE_PRIM_QUADS: return NV50TCL_VERTEX_BEGIN_QUADS;
286 case PIPE_PRIM_QUAD_STRIP: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP;
287 case PIPE_PRIM_POLYGON: return NV50TCL_VERTEX_BEGIN_POLYGON;
288 case PIPE_PRIM_LINES_ADJACENCY:
289 return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY;
290 case PIPE_PRIM_LINE_STRIP_ADJACENCY:
291 return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY;
292 case PIPE_PRIM_TRIANGLES_ADJACENCY:
293 return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY;
294 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
295 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY;
296 default:
297 break;
298 }
299
300 NOUVEAU_ERR("invalid primitive type %d\n", mode);
301 return NV50TCL_VERTEX_BEGIN_POINTS;
302 }
303
304 #endif