Merge branch 'mesa_7_6_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_TIC 4
33 #define NV50_CB_TSC 5
34 #define NV50_CB_PUPLOAD 6
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_ARRAYS (1 << 12)
49 #define NV50_NEW_SAMPLER (1 << 13)
50 #define NV50_NEW_TEXTURE (1 << 14)
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 bool normalized;
69 unsigned tsc[8];
70 };
71
72 struct nv50_miptree_level {
73 int *image_offset;
74 unsigned pitch;
75 unsigned tile_mode;
76 };
77
78 struct nv50_miptree {
79 struct nouveau_miptree base;
80
81 struct nv50_miptree_level level[PIPE_MAX_TEXTURE_LEVELS];
82 int image_nr;
83 int total_size;
84 };
85
86 static INLINE struct nv50_miptree *
87 nv50_miptree(struct pipe_texture *pt)
88 {
89 return (struct nv50_miptree *)pt;
90 }
91
92 struct nv50_surface {
93 struct pipe_surface base;
94 };
95
96 static INLINE struct nv50_surface *
97 nv50_surface(struct pipe_surface *pt)
98 {
99 return (struct nv50_surface *)pt;
100 }
101
102 struct nv50_state {
103 unsigned dirty;
104
105 struct nouveau_stateobj *fb;
106 struct nouveau_stateobj *blend;
107 struct nouveau_stateobj *blend_colour;
108 struct nouveau_stateobj *zsa;
109 struct nouveau_stateobj *rast;
110 struct nouveau_stateobj *stipple;
111 struct nouveau_stateobj *scissor;
112 unsigned scissor_enabled;
113 struct nouveau_stateobj *viewport;
114 unsigned viewport_bypass;
115 struct nouveau_stateobj *tsc_upload;
116 struct nouveau_stateobj *tic_upload;
117 unsigned miptree_nr;
118 struct nouveau_stateobj *vertprog;
119 struct nouveau_stateobj *fragprog;
120 struct nouveau_stateobj *programs;
121 struct nouveau_stateobj *vtxfmt;
122 struct nouveau_stateobj *vtxbuf;
123 struct nouveau_stateobj *vtxattr;
124 unsigned vtxelt_nr;
125 };
126
127 struct nv50_context {
128 struct pipe_context pipe;
129
130 struct nv50_screen *screen;
131 unsigned pctx_id;
132
133 struct draw_context *draw;
134
135 struct nv50_state state;
136
137 unsigned dirty;
138 struct nv50_blend_stateobj *blend;
139 struct nv50_zsa_stateobj *zsa;
140 struct nv50_rasterizer_stateobj *rasterizer;
141 struct pipe_blend_color blend_colour;
142 struct pipe_poly_stipple stipple;
143 struct pipe_scissor_state scissor;
144 struct pipe_viewport_state viewport;
145 struct pipe_framebuffer_state framebuffer;
146 struct nv50_program *vertprog;
147 struct nv50_program *fragprog;
148 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
149 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
150 unsigned vtxbuf_nr;
151 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
152 unsigned vtxelt_nr;
153 struct nv50_sampler_stateobj *sampler[PIPE_MAX_SAMPLERS];
154 unsigned sampler_nr;
155 struct nv50_miptree *miptree[PIPE_MAX_SAMPLERS];
156 unsigned miptree_nr;
157
158 uint16_t vbo_fifo;
159 };
160
161 static INLINE struct nv50_context *
162 nv50_context(struct pipe_context *pipe)
163 {
164 return (struct nv50_context *)pipe;
165 }
166
167 extern void nv50_init_surface_functions(struct nv50_context *nv50);
168 extern void nv50_init_state_functions(struct nv50_context *nv50);
169 extern void nv50_init_query_functions(struct nv50_context *nv50);
170
171 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
172
173 extern int
174 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
175 int dx, int dy, struct pipe_surface *src, int sx, int sy,
176 int w, int h);
177
178 /* nv50_draw.c */
179 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
180
181 /* nv50_vbo.c */
182 extern boolean nv50_draw_arrays(struct pipe_context *, unsigned mode,
183 unsigned start, unsigned count);
184 extern boolean nv50_draw_elements(struct pipe_context *pipe,
185 struct pipe_buffer *indexBuffer,
186 unsigned indexSize,
187 unsigned mode, unsigned start,
188 unsigned count);
189 extern void nv50_vbo_validate(struct nv50_context *nv50);
190
191 /* nv50_clear.c */
192 extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
193 const float *rgba, double depth, unsigned stencil);
194
195 /* nv50_program.c */
196 extern void nv50_vertprog_validate(struct nv50_context *nv50);
197 extern void nv50_fragprog_validate(struct nv50_context *nv50);
198 extern void nv50_linkage_validate(struct nv50_context *nv50);
199 extern void nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p);
200
201 /* nv50_state_validate.c */
202 extern boolean nv50_state_validate(struct nv50_context *nv50);
203 extern void nv50_state_flush_notify(struct nouveau_channel *chan);
204
205 extern void nv50_so_init_sifc(struct nv50_context *nv50,
206 struct nouveau_stateobj *so,
207 struct nouveau_bo *bo, unsigned reloc,
208 unsigned size);
209
210 /* nv50_tex.c */
211 extern void nv50_tex_validate(struct nv50_context *);
212
213 #endif