nv50: hook up to new shader code generator
[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
8 #include "util/u_memory.h"
9 #include "util/u_math.h"
10 #include "util/u_inlines.h"
11 #include "util/u_dynarray.h"
12
13 #include "draw/draw_vertex.h"
14
15 #include "nv50_debug.h"
16 #include "nv50_winsys.h"
17 #include "nv50_stateobj.h"
18 #include "nv50_screen.h"
19 #include "nv50_program.h"
20 #include "nv50_resource.h"
21 #include "nv50_transfer.h"
22
23 #include "nouveau/nouveau_context.h"
24 #include "nouveau/nv_object.xml.h"
25 #include "nouveau/nv_m2mf.xml.h"
26 #include "nv50_3ddefs.xml.h"
27 #include "nv50_3d.xml.h"
28 #include "nv50_2d.xml.h"
29
30 #define NV50_NEW_BLEND (1 << 0)
31 #define NV50_NEW_RASTERIZER (1 << 1)
32 #define NV50_NEW_ZSA (1 << 2)
33 #define NV50_NEW_VERTPROG (1 << 3)
34 #define NV50_NEW_GMTYPROG (1 << 6)
35 #define NV50_NEW_FRAGPROG (1 << 7)
36 #define NV50_NEW_BLEND_COLOUR (1 << 8)
37 #define NV50_NEW_STENCIL_REF (1 << 9)
38 #define NV50_NEW_CLIP (1 << 10)
39 #define NV50_NEW_SAMPLE_MASK (1 << 11)
40 #define NV50_NEW_FRAMEBUFFER (1 << 12)
41 #define NV50_NEW_STIPPLE (1 << 13)
42 #define NV50_NEW_SCISSOR (1 << 14)
43 #define NV50_NEW_VIEWPORT (1 << 15)
44 #define NV50_NEW_ARRAYS (1 << 16)
45 #define NV50_NEW_VERTEX (1 << 17)
46 #define NV50_NEW_CONSTBUF (1 << 18)
47 #define NV50_NEW_TEXTURES (1 << 19)
48 #define NV50_NEW_SAMPLERS (1 << 20)
49 #define NV50_NEW_CONTEXT (1 << 31)
50
51 #define NV50_BIND_FB 0
52 #define NV50_BIND_VERTEX 1
53 #define NV50_BIND_VERTEX_TMP 2
54 #define NV50_BIND_INDEX 3
55 #define NV50_BIND_TEXTURES 4
56 #define NV50_BIND_CB(s, i) (5 + 16 * (s) + (i))
57 #define NV50_BIND_SCREEN 53
58 #define NV50_BIND_TLS 54
59 #define NV50_BIND_COUNT 55
60 #define NV50_BIND_2D 0
61 #define NV50_BIND_M2MF 0
62 #define NV50_BIND_FENCE 1
63
64 #define NV50_CB_TMP 123
65 /* fixed constant buffer binding points - low indices for user's constbufs */
66 #define NV50_CB_PVP 124
67 #define NV50_CB_PGP 126
68 #define NV50_CB_PFP 125
69 #define NV50_CB_AUX 127
70
71
72 struct nv50_context {
73 struct nouveau_context base;
74
75 struct nv50_screen *screen;
76
77 struct nouveau_bufctx *bufctx_3d;
78 struct nouveau_bufctx *bufctx;
79
80 uint32_t dirty;
81
82 struct {
83 uint32_t instance_elts; /* bitmask of per-instance elements */
84 uint32_t instance_base;
85 uint32_t interpolant_ctrl;
86 uint32_t semantic_color;
87 uint32_t semantic_psize;
88 int32_t index_bias;
89 boolean prim_restart;
90 boolean point_sprite;
91 boolean rt_serialize;
92 boolean flushed;
93 uint8_t tls_required;
94 uint8_t num_vtxbufs;
95 uint8_t num_vtxelts;
96 uint8_t num_textures[3];
97 uint8_t num_samplers[3];
98 uint16_t scissor;
99 } state;
100
101 struct nv50_blend_stateobj *blend;
102 struct nv50_rasterizer_stateobj *rast;
103 struct nv50_zsa_stateobj *zsa;
104 struct nv50_vertex_stateobj *vertex;
105
106 struct nv50_program *vertprog;
107 struct nv50_program *gmtyprog;
108 struct nv50_program *fragprog;
109
110 struct pipe_resource *constbuf[3][16];
111 uint16_t constbuf_dirty[3];
112 uint16_t constbuf_valid[3];
113
114 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
115 unsigned num_vtxbufs;
116 struct pipe_index_buffer idxbuf;
117 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
118 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
119 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
120 uint32_t vb_elt_limit; /* max - min element (count - 1) */
121
122 struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS];
123 unsigned num_textures[3];
124 struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
125 unsigned num_samplers[3];
126
127 struct pipe_framebuffer_state framebuffer;
128 struct pipe_blend_color blend_colour;
129 struct pipe_stencil_ref stencil_ref;
130 struct pipe_poly_stipple stipple;
131 struct pipe_scissor_state scissor;
132 struct pipe_viewport_state viewport;
133 struct pipe_clip_state clip;
134
135 unsigned sample_mask;
136
137 boolean vbo_push_hint;
138
139 struct draw_context *draw;
140 };
141
142 static INLINE struct nv50_context *
143 nv50_context(struct pipe_context *pipe)
144 {
145 return (struct nv50_context *)pipe;
146 }
147
148 static INLINE struct nv50_screen *
149 nv50_context_screen(struct nv50_context *nv50)
150 {
151 return nv50_screen(&nv50->base.screen->base);
152 }
153
154
155 /* nv50_context.c */
156 struct pipe_context *nv50_create(struct pipe_screen *, void *);
157
158 void nv50_bufctx_fence(struct nouveau_bufctx *, boolean on_flush);
159
160 void nv50_default_kick_notify(struct nouveau_pushbuf *);
161
162 /* nv50_draw.c */
163 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
164
165 /* nv50_query.c */
166 void nv50_init_query_functions(struct nv50_context *);
167
168 /* nv50_shader_state.c */
169 void nv50_vertprog_validate(struct nv50_context *);
170 void nv50_gmtyprog_validate(struct nv50_context *);
171 void nv50_fragprog_validate(struct nv50_context *);
172 void nv50_fp_linkage_validate(struct nv50_context *);
173 void nv50_gp_linkage_validate(struct nv50_context *);
174 void nv50_constbufs_validate(struct nv50_context *);
175 void nv50_validate_derived_rs(struct nv50_context *);
176
177 /* nv50_state.c */
178 extern void nv50_init_state_functions(struct nv50_context *);
179
180 /* nv50_state_validate.c */
181 /* @words: check for space before emitting relocs */
182 extern boolean nv50_state_validate(struct nv50_context *, uint32_t state_mask,
183 unsigned space_words);
184
185 /* nv50_surface.c */
186 extern void nv50_clear(struct pipe_context *, unsigned buffers,
187 const union pipe_color_union *color,
188 double depth, unsigned stencil);
189 extern void nv50_init_surface_functions(struct nv50_context *);
190
191 /* nv50_tex.c */
192 void nv50_validate_textures(struct nv50_context *);
193 void nv50_validate_samplers(struct nv50_context *);
194
195 struct pipe_sampler_view *
196 nv50_create_sampler_view(struct pipe_context *,
197 struct pipe_resource *,
198 const struct pipe_sampler_view *);
199
200 /* nv50_transfer.c */
201 void
202 nv50_m2mf_transfer_rect(struct nv50_context *,
203 const struct nv50_m2mf_rect *dst,
204 const struct nv50_m2mf_rect *src,
205 uint32_t nblocksx, uint32_t nblocksy);
206 void
207 nv50_sifc_linear_u8(struct nouveau_context *pipe,
208 struct nouveau_bo *dst, unsigned offset, unsigned domain,
209 unsigned size, const void *data);
210 void
211 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
212 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
213 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
214 unsigned size);
215 void
216 nv50_cb_push(struct nouveau_context *nv,
217 struct nouveau_bo *bo, unsigned domain,
218 unsigned base, unsigned size,
219 unsigned offset, unsigned words, const uint32_t *data);
220
221 /* nv50_vbo.c */
222 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
223
224 void *
225 nv50_vertex_state_create(struct pipe_context *pipe,
226 unsigned num_elements,
227 const struct pipe_vertex_element *elements);
228 void
229 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
230
231 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
232
233 /* nv50_push.c */
234 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
235
236 #endif