Squashed commit of the following:
[profile/ivi/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
20 #include "nv50_screen.h"
21 #include "nv50_program.h"
22
23 #define NOUVEAU_ERR(fmt, args...) \
24         fprintf(stderr, "%s:%d -  "fmt, __func__, __LINE__, ##args);
25 #define NOUVEAU_MSG(fmt, args...) \
26         fprintf(stderr, "nouveau: "fmt, ##args);
27
28 /* Constant buffer assignment */
29 #define NV50_CB_PMISC           0
30 #define NV50_CB_PVP             1
31 #define NV50_CB_PFP             2
32 #define NV50_CB_PGP             3
33 #define NV50_CB_AUX             4
34
35 #define NV50_NEW_BLEND          (1 << 0)
36 #define NV50_NEW_ZSA            (1 << 1)
37 #define NV50_NEW_BLEND_COLOUR   (1 << 2)
38 #define NV50_NEW_STIPPLE        (1 << 3)
39 #define NV50_NEW_SCISSOR        (1 << 4)
40 #define NV50_NEW_VIEWPORT       (1 << 5)
41 #define NV50_NEW_RASTERIZER     (1 << 6)
42 #define NV50_NEW_FRAMEBUFFER    (1 << 7)
43 #define NV50_NEW_VERTPROG       (1 << 8)
44 #define NV50_NEW_VERTPROG_CB    (1 << 9)
45 #define NV50_NEW_FRAGPROG       (1 << 10)
46 #define NV50_NEW_FRAGPROG_CB    (1 << 11)
47 #define NV50_NEW_GEOMPROG       (1 << 12)
48 #define NV50_NEW_GEOMPROG_CB    (1 << 13)
49 #define NV50_NEW_ARRAYS         (1 << 14)
50 #define NV50_NEW_SAMPLER        (1 << 15)
51 #define NV50_NEW_TEXTURE        (1 << 16)
52 #define NV50_NEW_STENCIL_REF    (1 << 17)
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 struct nv50_sampler_view {
75         struct pipe_sampler_view pipe;
76         uint32_t tic[8];
77 };
78
79 struct nv50_vtxelt_stateobj {
80         struct pipe_vertex_element pipe[16];
81         unsigned num_elements;
82         uint32_t hw[16];
83 };
84
85 static INLINE struct nv50_sampler_view *
86 nv50_sampler_view(struct pipe_sampler_view *view)
87 {
88         return (struct nv50_sampler_view *)view;
89 }
90
91 static INLINE unsigned
92 get_tile_height(uint32_t tile_mode)
93 {
94         return 1 << ((tile_mode & 0xf) + 2);
95 }
96
97 static INLINE unsigned
98 get_tile_depth(uint32_t tile_mode)
99 {
100         return 1 << (tile_mode >> 4);
101 }
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         struct nouveau_stateobj *hw[64];
116         uint64_t hw_dirty;
117
118         unsigned sampler_view_nr[3];
119         struct nouveau_stateobj *vtxbuf;
120         struct nouveau_stateobj *vtxattr;
121         unsigned vtxelt_nr;
122 };
123
124 struct nv50_context {
125         struct pipe_context pipe;
126
127         struct nv50_screen *screen;
128
129         struct draw_context *draw;
130
131         struct nv50_state state;
132
133         unsigned dirty;
134         struct nv50_blend_stateobj *blend;
135         struct nv50_zsa_stateobj *zsa;
136         struct nv50_rasterizer_stateobj *rasterizer;
137         struct pipe_blend_color blend_colour;
138         struct pipe_stencil_ref stencil_ref;
139         struct pipe_poly_stipple stipple;
140         struct pipe_scissor_state scissor;
141         struct pipe_viewport_state viewport;
142         struct pipe_framebuffer_state framebuffer;
143         struct nv50_program *vertprog;
144         struct nv50_program *fragprog;
145         struct nv50_program *geomprog;
146         struct pipe_resource *constbuf[PIPE_SHADER_TYPES];
147         struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
148         unsigned vtxbuf_nr;
149         struct nv50_vtxelt_stateobj *vtxelt;
150         struct nv50_sampler_stateobj *sampler[3][PIPE_MAX_SAMPLERS];
151         unsigned sampler_nr[3];
152         struct pipe_sampler_view *sampler_views[3][PIPE_MAX_SAMPLERS];
153         unsigned sampler_view_nr[3];
154
155         unsigned vbo_fifo;
156 };
157
158 static INLINE struct nv50_context *
159 nv50_context(struct pipe_context *pipe)
160 {
161         return (struct nv50_context *)pipe;
162 }
163
164 extern void nv50_init_surface_functions(struct nv50_context *nv50);
165 extern void nv50_init_state_functions(struct nv50_context *nv50);
166 extern void nv50_init_query_functions(struct nv50_context *nv50);
167 extern void nv50_init_transfer_functions(struct nv50_context *nv50);
168
169 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
170
171 extern int
172 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
173                      int dx, int dy, struct pipe_surface *src, int sx, int sy,
174                      int w, int h);
175
176 /* nv50_draw.c */
177 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
178
179 /* nv50_vbo.c */
180 extern void nv50_draw_arrays(struct pipe_context *, unsigned mode,
181                                 unsigned start, unsigned count);
182 extern void nv50_draw_arrays_instanced(struct pipe_context *, unsigned mode,
183                                         unsigned start, unsigned count,
184                                         unsigned startInstance,
185                                         unsigned instanceCount);
186 extern void nv50_draw_elements(struct pipe_context *pipe,
187                                   struct pipe_resource *indexBuffer,
188                                   unsigned indexSize,
189                                   unsigned mode, unsigned start,
190                                   unsigned count);
191 extern void nv50_draw_elements_instanced(struct pipe_context *pipe,
192                                          struct pipe_resource *indexBuffer,
193                                          unsigned indexSize,
194                                          unsigned mode, unsigned start,
195                                          unsigned count,
196                                          unsigned startInstance,
197                                          unsigned instanceCount);
198 extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj *cso);
199 extern struct nouveau_stateobj *nv50_vbo_validate(struct nv50_context *nv50);
200
201 /* nv50_push.c */
202 extern void
203 nv50_push_elements_instanced(struct pipe_context *, struct pipe_resource *,
204                              unsigned idxsize, unsigned mode, unsigned start,
205                              unsigned count, unsigned i_start,
206                              unsigned i_count);
207
208 /* nv50_clear.c */
209 extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
210                        const float *rgba, double depth, unsigned stencil);
211
212 /* nv50_program.c */
213 extern struct nouveau_stateobj *
214 nv50_vertprog_validate(struct nv50_context *nv50);
215 extern struct nouveau_stateobj *
216 nv50_fragprog_validate(struct nv50_context *nv50);
217 extern struct nouveau_stateobj *
218 nv50_geomprog_validate(struct nv50_context *nv50);
219 extern struct nouveau_stateobj *
220 nv50_fp_linkage_validate(struct nv50_context *nv50);
221 extern struct nouveau_stateobj *
222 nv50_gp_linkage_validate(struct nv50_context *nv50);
223 extern void nv50_program_destroy(struct nv50_context *nv50,
224                                  struct nv50_program *p);
225
226 /* nv50_state_validate.c */
227 extern boolean nv50_state_validate(struct nv50_context *nv50, unsigned dwords);
228
229 extern void nv50_so_init_sifc(struct nv50_context *nv50,
230                               struct nouveau_stateobj *so,
231                               struct nouveau_bo *bo, unsigned reloc,
232                               unsigned offset, unsigned size);
233
234 /* nv50_tex.c */
235 extern boolean nv50_tex_construct(struct nv50_sampler_view *view);
236 extern void nv50_tex_relocs(struct nv50_context *);
237 extern struct nouveau_stateobj *nv50_tex_validate(struct nv50_context *);
238
239
240 /* nv50_context.c */
241 struct pipe_context *
242 nv50_create(struct pipe_screen *pscreen, void *priv);
243
244 static INLINE unsigned
245 nv50_prim(unsigned mode)
246 {
247         switch (mode) {
248         case PIPE_PRIM_POINTS: return NV50TCL_VERTEX_BEGIN_POINTS;
249         case PIPE_PRIM_LINES: return NV50TCL_VERTEX_BEGIN_LINES;
250         case PIPE_PRIM_LINE_LOOP: return NV50TCL_VERTEX_BEGIN_LINE_LOOP;
251         case PIPE_PRIM_LINE_STRIP: return NV50TCL_VERTEX_BEGIN_LINE_STRIP;
252         case PIPE_PRIM_TRIANGLES: return NV50TCL_VERTEX_BEGIN_TRIANGLES;
253         case PIPE_PRIM_TRIANGLE_STRIP:
254                 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP;
255         case PIPE_PRIM_TRIANGLE_FAN: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN;
256         case PIPE_PRIM_QUADS: return NV50TCL_VERTEX_BEGIN_QUADS;
257         case PIPE_PRIM_QUAD_STRIP: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP;
258         case PIPE_PRIM_POLYGON: return NV50TCL_VERTEX_BEGIN_POLYGON;
259         case PIPE_PRIM_LINES_ADJACENCY:
260                 return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY;
261         case PIPE_PRIM_LINE_STRIP_ADJACENCY:
262                 return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY;
263         case PIPE_PRIM_TRIANGLES_ADJACENCY:
264                 return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY;
265         case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
266                 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY;
267         default:
268                 break;
269         }
270
271         NOUVEAU_ERR("invalid primitive type %d\n", mode);
272         return NV50TCL_VERTEX_BEGIN_POINTS;
273 }
274
275 #endif