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