2bf634a82376e34ef4ed3078632d83a4244723dd
[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
50 #define NV50_BUFCTX_CONSTANT 0
51 #define NV50_BUFCTX_FRAME 1
52 #define NV50_BUFCTX_VERTEX 2
53 #define NV50_BUFCTX_TEXTURES 3
54 #define NV50_BUFCTX_COUNT 4
55
56 #define NV50_CB_TMP 123
57 /* fixed constant buffer binding points - low indices for user's constbufs */
58 #define NV50_CB_PVP 124
59 #define NV50_CB_PGP 126
60 #define NV50_CB_PFP 125
61 #define NV50_CB_AUX 127
62
63 struct nv50_context {
64 struct nouveau_context base;
65
66 struct nv50_screen *screen;
67
68 struct util_dynarray residents[NV50_BUFCTX_COUNT];
69 unsigned residents_size;
70
71 uint32_t dirty;
72
73 struct {
74 uint32_t instance_elts; /* bitmask of per-instance elements */
75 uint32_t instance_base;
76 uint32_t interpolant_ctrl;
77 uint32_t semantic_color;
78 uint32_t semantic_psize;
79 int32_t index_bias;
80 boolean prim_restart;
81 boolean point_sprite;
82 uint8_t num_vtxbufs;
83 uint8_t num_vtxelts;
84 uint8_t num_textures[3];
85 uint8_t num_samplers[3];
86 uint16_t scissor;
87 } state;
88
89 struct nv50_blend_stateobj *blend;
90 struct nv50_rasterizer_stateobj *rast;
91 struct nv50_zsa_stateobj *zsa;
92 struct nv50_vertex_stateobj *vertex;
93
94 struct nv50_program *vertprog;
95 struct nv50_program *gmtyprog;
96 struct nv50_program *fragprog;
97
98 struct pipe_resource *constbuf[3][16];
99 uint16_t constbuf_dirty[3];
100
101 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
102 unsigned num_vtxbufs;
103 struct pipe_index_buffer idxbuf;
104 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
105 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
106 unsigned vbo_min_index; /* from pipe_draw_info, for vertex upload */
107 unsigned vbo_max_index;
108
109 struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS];
110 unsigned num_textures[3];
111 struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
112 unsigned num_samplers[3];
113
114 struct pipe_framebuffer_state framebuffer;
115 struct pipe_blend_color blend_colour;
116 struct pipe_stencil_ref stencil_ref;
117 struct pipe_poly_stipple stipple;
118 struct pipe_scissor_state scissor;
119 struct pipe_viewport_state viewport;
120 struct pipe_clip_state clip;
121
122 unsigned sample_mask;
123
124 boolean vbo_push_hint;
125
126 struct draw_context *draw;
127 };
128
129 static INLINE struct nv50_context *
130 nv50_context(struct pipe_context *pipe)
131 {
132 return (struct nv50_context *)pipe;
133 }
134
135 /* nv50_context.c */
136 struct pipe_context *nv50_create(struct pipe_screen *, void *);
137
138 void nv50_default_flush_notify(struct nouveau_channel *);
139
140 void nv50_bufctx_emit_relocs(struct nv50_context *);
141 void nv50_bufctx_add_resident(struct nv50_context *, int ctx,
142 struct nv04_resource *, uint32_t flags);
143 void nv50_bufctx_del_resident(struct nv50_context *, int ctx,
144 struct nv04_resource *);
145 static INLINE void
146 nv50_bufctx_reset(struct nv50_context *nv50, int ctx)
147 {
148 nv50->residents_size -= nv50->residents[ctx].size;
149 util_dynarray_resize(&nv50->residents[ctx], 0);
150 }
151
152 /* nv50_draw.c */
153 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
154
155 /* nv50_program.c */
156 boolean nv50_program_translate(struct nv50_program *);
157 boolean nv50_program_translate_new(struct nv50_program *);
158 void nv50_program_destroy(struct nv50_context *, struct nv50_program *);
159
160 /* nv50_query.c */
161 void nv50_init_query_functions(struct nv50_context *);
162
163 /* nv50_shader_state.c */
164 void nv50_vertprog_validate(struct nv50_context *);
165 void nv50_gmtyprog_validate(struct nv50_context *);
166 void nv50_fragprog_validate(struct nv50_context *);
167 void nv50_fp_linkage_validate(struct nv50_context *);
168 void nv50_gp_linkage_validate(struct nv50_context *);
169 void nv50_constbufs_validate(struct nv50_context *);
170 void nv50_validate_derived_rs(struct nv50_context *);
171
172 /* nv50_state.c */
173 extern void nv50_init_state_functions(struct nv50_context *);
174
175 /* nv50_state_validate.c */
176 /* @words: check for space before emitting relocs */
177 extern boolean nv50_state_validate(struct nv50_context *, uint32_t state_mask,
178 unsigned space_words);
179
180 /* nv50_surface.c */
181 extern void nv50_clear(struct pipe_context *, unsigned buffers,
182 const union pipe_color_union *color,
183 double depth, unsigned stencil);
184 extern void nv50_init_surface_functions(struct nv50_context *);
185
186 /* nv50_tex.c */
187 void nv50_validate_textures(struct nv50_context *);
188 void nv50_validate_samplers(struct nv50_context *);
189
190 struct pipe_sampler_view *
191 nv50_create_sampler_view(struct pipe_context *,
192 struct pipe_resource *,
193 const struct pipe_sampler_view *);
194
195 /* nv50_transfer.c */
196 void
197 nv50_m2mf_transfer_rect(struct pipe_screen *pscreen,
198 const struct nv50_m2mf_rect *dst,
199 const struct nv50_m2mf_rect *src,
200 uint32_t nblocksx, uint32_t nblocksy);
201 void
202 nv50_sifc_linear_u8(struct nouveau_context *pipe,
203 struct nouveau_bo *dst, unsigned offset, unsigned domain,
204 unsigned size, const void *data);
205 void
206 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
207 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
208 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
209 unsigned size);
210 void
211 nv50_cb_push(struct nouveau_context *nv,
212 struct nouveau_bo *bo, unsigned domain,
213 unsigned base, unsigned size,
214 unsigned offset, unsigned words, const uint32_t *data);
215
216 /* nv50_vbo.c */
217 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
218
219 void *
220 nv50_vertex_state_create(struct pipe_context *pipe,
221 unsigned num_elements,
222 const struct pipe_vertex_element *elements);
223 void
224 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
225
226 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
227
228 /* nv50_push.c */
229 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
230
231 #endif