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