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
18 #include "nv50_screen.h"
19 #include "nv50_program.h"
20
21 #define NOUVEAU_ERR(fmt, args...) \
22 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
23 #define NOUVEAU_MSG(fmt, args...) \
24 fprintf(stderr, "nouveau: "fmt, ##args);
25
26 /* Constant buffer assignment */
27 #define NV50_CB_PMISC 0
28 #define NV50_CB_PVP 1
29 #define NV50_CB_PFP 2
30 #define NV50_CB_PGP 3
31 #define NV50_CB_TIC 4
32 #define NV50_CB_TSC 5
33 #define NV50_CB_PUPLOAD 6
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_ARRAYS (1 << 12)
48 #define NV50_NEW_SAMPLER (1 << 13)
49 #define NV50_NEW_TEXTURE (1 << 14)
50
51 struct nv50_blend_stateobj {
52 struct pipe_blend_state pipe;
53 struct nouveau_stateobj *so;
54 };
55
56 struct nv50_zsa_stateobj {
57 struct pipe_depth_stencil_alpha_state pipe;
58 struct nouveau_stateobj *so;
59 };
60
61 struct nv50_rasterizer_stateobj {
62 struct pipe_rasterizer_state pipe;
63 struct nouveau_stateobj *so;
64 };
65
66 struct nv50_sampler_stateobj {
67 bool normalized;
68 unsigned tsc[8];
69 };
70
71 struct nv50_miptree_level {
72 int *image_offset;
73 unsigned pitch;
74 unsigned tile_mode;
75 };
76
77 struct nv50_miptree {
78 struct nouveau_miptree base;
79
80 struct nv50_miptree_level level[PIPE_MAX_TEXTURE_LEVELS];
81 int image_nr;
82 int total_size;
83 };
84
85 static INLINE struct nv50_miptree *
86 nv50_miptree(struct pipe_texture *pt)
87 {
88 return (struct nv50_miptree *)pt;
89 }
90
91 struct nv50_surface {
92 struct pipe_surface base;
93 };
94
95 static INLINE struct nv50_surface *
96 nv50_surface(struct pipe_surface *pt)
97 {
98 return (struct nv50_surface *)pt;
99 }
100
101 struct nv50_state {
102 unsigned dirty;
103
104 struct nouveau_stateobj *fb;
105 struct nouveau_stateobj *blend;
106 struct nouveau_stateobj *blend_colour;
107 struct nouveau_stateobj *zsa;
108 struct nouveau_stateobj *rast;
109 struct nouveau_stateobj *stipple;
110 struct nouveau_stateobj *scissor;
111 unsigned scissor_enabled;
112 struct nouveau_stateobj *viewport;
113 unsigned viewport_bypass;
114 struct nouveau_stateobj *tsc_upload;
115 struct nouveau_stateobj *tic_upload;
116 unsigned miptree_nr;
117 struct nouveau_stateobj *vertprog;
118 struct nouveau_stateobj *fragprog;
119 struct nouveau_stateobj *programs;
120 struct nouveau_stateobj *vtxfmt;
121 struct nouveau_stateobj *vtxbuf;
122 struct nouveau_stateobj *vtxattr;
123 };
124
125 struct nv50_context {
126 struct pipe_context pipe;
127
128 struct nv50_screen *screen;
129 unsigned pctx_id;
130
131 struct draw_context *draw;
132
133 struct nv50_state state;
134
135 unsigned dirty;
136 struct nv50_blend_stateobj *blend;
137 struct nv50_zsa_stateobj *zsa;
138 struct nv50_rasterizer_stateobj *rasterizer;
139 struct pipe_blend_color blend_colour;
140 struct pipe_poly_stipple stipple;
141 struct pipe_scissor_state scissor;
142 struct pipe_viewport_state viewport;
143 struct pipe_framebuffer_state framebuffer;
144 struct nv50_program *vertprog;
145 struct nv50_program *fragprog;
146 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
147 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
148 unsigned vtxbuf_nr;
149 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
150 unsigned vtxelt_nr;
151 struct nv50_sampler_stateobj *sampler[PIPE_MAX_SAMPLERS];
152 unsigned sampler_nr;
153 struct nv50_miptree *miptree[PIPE_MAX_SAMPLERS];
154 unsigned miptree_nr;
155 };
156
157 static INLINE struct nv50_context *
158 nv50_context(struct pipe_context *pipe)
159 {
160 return (struct nv50_context *)pipe;
161 }
162
163 extern void nv50_init_surface_functions(struct nv50_context *nv50);
164 extern void nv50_init_state_functions(struct nv50_context *nv50);
165 extern void nv50_init_query_functions(struct nv50_context *nv50);
166
167 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
168
169 extern int
170 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
171 int dx, int dy, struct pipe_surface *src, int sx, int sy,
172 int w, int h);
173
174 /* nv50_draw.c */
175 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
176
177 /* nv50_vbo.c */
178 extern boolean nv50_draw_arrays(struct pipe_context *, unsigned mode,
179 unsigned start, unsigned count);
180 extern boolean nv50_draw_elements(struct pipe_context *pipe,
181 struct pipe_buffer *indexBuffer,
182 unsigned indexSize,
183 unsigned mode, unsigned start,
184 unsigned count);
185 extern void nv50_vbo_validate(struct nv50_context *nv50);
186
187 /* nv50_clear.c */
188 extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
189 const float *rgba, double depth, unsigned stencil);
190
191 /* nv50_program.c */
192 extern void nv50_vertprog_validate(struct nv50_context *nv50);
193 extern void nv50_fragprog_validate(struct nv50_context *nv50);
194 extern void nv50_linkage_validate(struct nv50_context *nv50);
195 extern void nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p);
196
197 /* nv50_state_validate.c */
198 extern boolean nv50_state_validate(struct nv50_context *nv50);
199 extern void nv50_state_flush_notify(struct nouveau_channel *chan);
200
201 /* nv50_tex.c */
202 extern void nv50_tex_validate(struct nv50_context *);
203
204 #endif