Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.h
1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_CONTEXT_H__
3
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7 #include "pipe/p_compiler.h"
8
9 #include "util/u_memory.h"
10 #include "util/u_math.h"
11
12 #include "draw/draw_vertex.h"
13
14 #include "nouveau/nouveau_winsys.h"
15 #include "nouveau/nouveau_gldefs.h"
16 #include "nouveau/nouveau_stateobj.h"
17 #include "nouveau/nouveau_context.h"
18
19 #include "nv50_screen.h"
20 #include "nv50_program.h"
21
22 #define NOUVEAU_ERR(fmt, args...) \
23 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
24 #define NOUVEAU_MSG(fmt, args...) \
25 fprintf(stderr, "nouveau: "fmt, ##args);
26
27 /* Constant buffer assignment */
28 #define NV50_CB_PMISC 0
29 #define NV50_CB_PVP 1
30 #define NV50_CB_PFP 2
31 #define NV50_CB_PGP 3
32 #define NV50_CB_AUX 4
33
34 #define NV50_NEW_BLEND (1 << 0)
35 #define NV50_NEW_ZSA (1 << 1)
36 #define NV50_NEW_BLEND_COLOUR (1 << 2)
37 #define NV50_NEW_STIPPLE (1 << 3)
38 #define NV50_NEW_SCISSOR (1 << 4)
39 #define NV50_NEW_VIEWPORT (1 << 5)
40 #define NV50_NEW_RASTERIZER (1 << 6)
41 #define NV50_NEW_FRAMEBUFFER (1 << 7)
42 #define NV50_NEW_VERTPROG (1 << 8)
43 #define NV50_NEW_VERTPROG_CB (1 << 9)
44 #define NV50_NEW_FRAGPROG (1 << 10)
45 #define NV50_NEW_FRAGPROG_CB (1 << 11)
46 #define NV50_NEW_GEOMPROG (1 << 12)
47 #define NV50_NEW_GEOMPROG_CB (1 << 13)
48 #define NV50_NEW_ARRAYS (1 << 14)
49 #define NV50_NEW_SAMPLER (1 << 15)
50 #define NV50_NEW_TEXTURE (1 << 16)
51
52 struct nv50_blend_stateobj {
53 struct pipe_blend_state pipe;
54 struct nouveau_stateobj *so;
55 };
56
57 struct nv50_zsa_stateobj {
58 struct pipe_depth_stencil_alpha_state pipe;
59 struct nouveau_stateobj *so;
60 };
61
62 struct nv50_rasterizer_stateobj {
63 struct pipe_rasterizer_state pipe;
64 struct nouveau_stateobj *so;
65 };
66
67 struct nv50_sampler_stateobj {
68 boolean normalized;
69 unsigned tsc[8];
70 };
71
72 static INLINE unsigned
73 get_tile_height(uint32_t tile_mode)
74 {
75 return 1 << ((tile_mode & 0xf) + 2);
76 }
77
78 static INLINE unsigned
79 get_tile_depth(uint32_t tile_mode)
80 {
81 return 1 << (tile_mode >> 4);
82 }
83
84 struct nv50_miptree_level {
85 int *image_offset;
86 unsigned pitch;
87 unsigned tile_mode;
88 };
89
90 struct nv50_miptree {
91 struct nouveau_miptree base;
92
93 struct nv50_miptree_level level[PIPE_MAX_TEXTURE_LEVELS];
94 int image_nr;
95 int total_size;
96 };
97
98 static INLINE struct nv50_miptree *
99 nv50_miptree(struct pipe_texture *pt)
100 {
101 return (struct nv50_miptree *)pt;
102 }
103
104 struct nv50_surface {
105 struct pipe_surface base;
106 };
107
108 static INLINE struct nv50_surface *
109 nv50_surface(struct pipe_surface *pt)
110 {
111 return (struct nv50_surface *)pt;
112 }
113
114 struct nv50_state {
115 unsigned dirty;
116
117 struct nouveau_stateobj *fb;
118 struct nouveau_stateobj *blend;
119 struct nouveau_stateobj *blend_colour;
120 struct nouveau_stateobj *zsa;
121 struct nouveau_stateobj *rast;
122 struct nouveau_stateobj *stipple;
123 struct nouveau_stateobj *scissor;
124 unsigned scissor_enabled;
125 struct nouveau_stateobj *viewport;
126 unsigned viewport_bypass;
127 struct nouveau_stateobj *tsc_upload;
128 struct nouveau_stateobj *tic_upload;
129 unsigned miptree_nr[PIPE_SHADER_TYPES];
130 struct nouveau_stateobj *vertprog;
131 struct nouveau_stateobj *fragprog;
132 struct nouveau_stateobj *geomprog;
133 struct nouveau_stateobj *fp_linkage;
134 struct nouveau_stateobj *gp_linkage;
135 struct nouveau_stateobj *vtxfmt;
136 struct nouveau_stateobj *vtxbuf;
137 struct nouveau_stateobj *vtxattr;
138 struct nouveau_stateobj *instbuf;
139 unsigned vtxelt_nr;
140 };
141
142 struct nv50_context {
143 struct pipe_context pipe;
144
145 struct nv50_screen *screen;
146 unsigned pctx_id;
147
148 struct draw_context *draw;
149
150 struct nv50_state state;
151
152 unsigned dirty;
153 struct nv50_blend_stateobj *blend;
154 struct nv50_zsa_stateobj *zsa;
155 struct nv50_rasterizer_stateobj *rasterizer;
156 struct pipe_blend_color blend_colour;
157 struct pipe_poly_stipple stipple;
158 struct pipe_scissor_state scissor;
159 struct pipe_viewport_state viewport;
160 struct pipe_framebuffer_state framebuffer;
161 struct nv50_program *vertprog;
162 struct nv50_program *fragprog;
163 struct nv50_program *geomprog;
164 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
165 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
166 unsigned vtxbuf_nr;
167 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
168 unsigned vtxelt_nr;
169 struct nv50_sampler_stateobj *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
170 unsigned sampler_nr[PIPE_SHADER_TYPES];
171 struct nv50_miptree *miptree[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
172 unsigned miptree_nr[PIPE_SHADER_TYPES];
173
174 uint16_t vbo_fifo;
175 };
176
177 static INLINE struct nv50_context *
178 nv50_context(struct pipe_context *pipe)
179 {
180 return (struct nv50_context *)pipe;
181 }
182
183 extern void nv50_init_surface_functions(struct nv50_context *nv50);
184 extern void nv50_init_state_functions(struct nv50_context *nv50);
185 extern void nv50_init_query_functions(struct nv50_context *nv50);
186
187 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
188
189 extern int
190 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
191 int dx, int dy, struct pipe_surface *src, int sx, int sy,
192 int w, int h);
193
194 /* nv50_draw.c */
195 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
196
197 /* nv50_vbo.c */
198 extern void nv50_draw_arrays(struct pipe_context *, unsigned mode,
199 unsigned start, unsigned count);
200 extern void nv50_draw_arrays_instanced(struct pipe_context *, unsigned mode,
201 unsigned start, unsigned count,
202 unsigned startInstance,
203 unsigned instanceCount);
204 extern void nv50_draw_elements(struct pipe_context *pipe,
205 struct pipe_buffer *indexBuffer,
206 unsigned indexSize,
207 unsigned mode, unsigned start,
208 unsigned count);
209 extern void nv50_draw_elements_instanced(struct pipe_context *pipe,
210 struct pipe_buffer *indexBuffer,
211 unsigned indexSize,
212 unsigned mode, unsigned start,
213 unsigned count,
214 unsigned startInstance,
215 unsigned instanceCount);
216 extern void nv50_vbo_validate(struct nv50_context *nv50);
217
218 /* nv50_clear.c */
219 extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
220 const float *rgba, double depth, unsigned stencil);
221
222 /* nv50_program.c */
223 extern void nv50_vertprog_validate(struct nv50_context *nv50);
224 extern void nv50_fragprog_validate(struct nv50_context *nv50);
225 extern void nv50_geomprog_validate(struct nv50_context *nv50);
226 extern void nv50_fp_linkage_validate(struct nv50_context *nv50);
227 extern void nv50_gp_linkage_validate(struct nv50_context *nv50);
228 extern void nv50_program_destroy(struct nv50_context *nv50,
229 struct nv50_program *p);
230
231 /* nv50_state_validate.c */
232 extern boolean nv50_state_validate(struct nv50_context *nv50);
233 extern void nv50_state_flush_notify(struct nouveau_channel *chan);
234
235 extern void nv50_so_init_sifc(struct nv50_context *nv50,
236 struct nouveau_stateobj *so,
237 struct nouveau_bo *bo, unsigned reloc,
238 unsigned offset, unsigned size);
239
240 /* nv50_tex.c */
241 extern void nv50_tex_validate(struct nv50_context *);
242
243 /* nv50_transfer.c */
244 extern void
245 nv50_upload_sifc(struct nv50_context *nv50,
246 struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc,
247 unsigned dst_format, int dst_w, int dst_h, int dst_pitch,
248 void *src, unsigned src_format, int src_pitch,
249 int x, int y, int w, int h, int cpp);
250
251 #endif