Merge branch 'gallium-nopointsizeminmax'
[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
54 struct nv50_blend_stateobj {
55 struct pipe_blend_state pipe;
56 struct nouveau_stateobj *so;
57 };
58
59 struct nv50_zsa_stateobj {
60 struct pipe_depth_stencil_alpha_state pipe;
61 struct nouveau_stateobj *so;
62 };
63
64 struct nv50_rasterizer_stateobj {
65 struct pipe_rasterizer_state pipe;
66 struct nouveau_stateobj *so;
67 };
68
69 struct nv50_sampler_stateobj {
70 boolean normalized;
71 unsigned tsc[8];
72 };
73
74 static INLINE unsigned
75 get_tile_height(uint32_t tile_mode)
76 {
77 return 1 << ((tile_mode & 0xf) + 2);
78 }
79
80 static INLINE unsigned
81 get_tile_depth(uint32_t tile_mode)
82 {
83 return 1 << (tile_mode >> 4);
84 }
85
86 struct nv50_miptree_level {
87 int *image_offset;
88 unsigned pitch;
89 unsigned tile_mode;
90 };
91
92 struct nv50_miptree {
93 struct nouveau_miptree base;
94
95 struct nv50_miptree_level level[PIPE_MAX_TEXTURE_LEVELS];
96 int image_nr;
97 int total_size;
98 };
99
100 static INLINE struct nv50_miptree *
101 nv50_miptree(struct pipe_texture *pt)
102 {
103 return (struct nv50_miptree *)pt;
104 }
105
106 struct nv50_surface {
107 struct pipe_surface base;
108 };
109
110 static INLINE struct nv50_surface *
111 nv50_surface(struct pipe_surface *pt)
112 {
113 return (struct nv50_surface *)pt;
114 }
115
116 struct nv50_state {
117 unsigned dirty;
118
119 struct nouveau_stateobj *fb;
120 struct nouveau_stateobj *blend;
121 struct nouveau_stateobj *blend_colour;
122 struct nouveau_stateobj *zsa;
123 struct nouveau_stateobj *rast;
124 struct nouveau_stateobj *stipple;
125 struct nouveau_stateobj *scissor;
126 unsigned scissor_enabled;
127 struct nouveau_stateobj *viewport;
128 unsigned viewport_bypass;
129 struct nouveau_stateobj *tsc_upload;
130 struct nouveau_stateobj *tic_upload;
131 unsigned miptree_nr[PIPE_SHADER_TYPES];
132 struct nouveau_stateobj *vertprog;
133 struct nouveau_stateobj *fragprog;
134 struct nouveau_stateobj *geomprog;
135 struct nouveau_stateobj *fp_linkage;
136 struct nouveau_stateobj *gp_linkage;
137 struct nouveau_stateobj *vtxfmt;
138 struct nouveau_stateobj *vtxbuf;
139 struct nouveau_stateobj *vtxattr;
140 struct nouveau_stateobj *instbuf;
141 unsigned vtxelt_nr;
142 };
143
144 struct nv50_context {
145 struct pipe_context pipe;
146
147 struct nv50_screen *screen;
148
149 struct draw_context *draw;
150
151 struct nv50_state state;
152
153 unsigned dirty;
154 struct nv50_blend_stateobj *blend;
155 struct nv50_zsa_stateobj *zsa;
156 struct nv50_rasterizer_stateobj *rasterizer;
157 struct pipe_blend_color blend_colour;
158 struct pipe_poly_stipple stipple;
159 struct pipe_scissor_state scissor;
160 struct pipe_viewport_state viewport;
161 struct pipe_framebuffer_state framebuffer;
162 struct nv50_program *vertprog;
163 struct nv50_program *fragprog;
164 struct nv50_program *geomprog;
165 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
166 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
167 unsigned vtxbuf_nr;
168 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
169 unsigned vtxelt_nr;
170 struct nv50_sampler_stateobj *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
171 unsigned sampler_nr[PIPE_SHADER_TYPES];
172 struct nv50_miptree *miptree[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
173 unsigned miptree_nr[PIPE_SHADER_TYPES];
174
175 uint16_t vbo_fifo;
176 };
177
178 static INLINE struct nv50_context *
179 nv50_context(struct pipe_context *pipe)
180 {
181 return (struct nv50_context *)pipe;
182 }
183
184 extern void nv50_init_surface_functions(struct nv50_context *nv50);
185 extern void nv50_init_state_functions(struct nv50_context *nv50);
186 extern void nv50_init_query_functions(struct nv50_context *nv50);
187
188 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
189
190 extern int
191 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
192 int dx, int dy, struct pipe_surface *src, int sx, int sy,
193 int w, int h);
194
195 /* nv50_draw.c */
196 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
197
198 /* nv50_vbo.c */
199 extern void nv50_draw_arrays(struct pipe_context *, unsigned mode,
200 unsigned start, unsigned count);
201 extern void nv50_draw_arrays_instanced(struct pipe_context *, unsigned mode,
202 unsigned start, unsigned count,
203 unsigned startInstance,
204 unsigned instanceCount);
205 extern void nv50_draw_elements(struct pipe_context *pipe,
206 struct pipe_buffer *indexBuffer,
207 unsigned indexSize,
208 unsigned mode, unsigned start,
209 unsigned count);
210 extern void nv50_draw_elements_instanced(struct pipe_context *pipe,
211 struct pipe_buffer *indexBuffer,
212 unsigned indexSize,
213 unsigned mode, unsigned start,
214 unsigned count,
215 unsigned startInstance,
216 unsigned instanceCount);
217 extern void nv50_vbo_validate(struct nv50_context *nv50);
218
219 /* nv50_clear.c */
220 extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
221 const float *rgba, double depth, unsigned stencil);
222
223 /* nv50_program.c */
224 extern void nv50_vertprog_validate(struct nv50_context *nv50);
225 extern void nv50_fragprog_validate(struct nv50_context *nv50);
226 extern void nv50_geomprog_validate(struct nv50_context *nv50);
227 extern void nv50_fp_linkage_validate(struct nv50_context *nv50);
228 extern void nv50_gp_linkage_validate(struct nv50_context *nv50);
229 extern void nv50_program_destroy(struct nv50_context *nv50,
230 struct nv50_program *p);
231
232 /* nv50_state_validate.c */
233 extern boolean nv50_state_validate(struct nv50_context *nv50);
234 extern void nv50_state_flush_notify(struct nouveau_channel *chan);
235
236 extern void nv50_so_init_sifc(struct nv50_context *nv50,
237 struct nouveau_stateobj *so,
238 struct nouveau_bo *bo, unsigned reloc,
239 unsigned offset, unsigned size);
240
241 /* nv50_tex.c */
242 extern void nv50_tex_validate(struct nv50_context *);
243
244 /* nv50_transfer.c */
245 extern void
246 nv50_upload_sifc(struct nv50_context *nv50,
247 struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc,
248 unsigned dst_format, int dst_w, int dst_h, int dst_pitch,
249 void *src, unsigned src_format, int src_pitch,
250 int x, int y, int w, int h, int cpp);
251
252 /* nv50_context.c */
253 struct pipe_context *
254 nv50_create(struct pipe_screen *pscreen, void *priv);
255
256 #endif