b8f0d92b6b4244da51bc6c01025a02ceaeb6eaf7
[mesa.git] / src / gallium / drivers / nvc0 / nvc0_context.h
1 #ifndef __NVC0_CONTEXT_H__
2 #define __NVC0_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/nv50_debug.h"
16 #include "nvc0_winsys.h"
17 #include "nvc0_stateobj.h"
18 #include "nvc0_screen.h"
19 #include "nvc0_program.h"
20 #include "nvc0_resource.h"
21
22 #include "nv50/nv50_transfer.h"
23
24 #include "nouveau/nouveau_context.h"
25
26 #include "nvc0_3ddefs.xml.h"
27 #include "nvc0_3d.xml.h"
28 #include "nvc0_2d.xml.h"
29 #include "nvc0_m2mf.xml.h"
30
31 #define NVC0_NEW_BLEND (1 << 0)
32 #define NVC0_NEW_RASTERIZER (1 << 1)
33 #define NVC0_NEW_ZSA (1 << 2)
34 #define NVC0_NEW_VERTPROG (1 << 3)
35 #define NVC0_NEW_TCTLPROG (1 << 4)
36 #define NVC0_NEW_TEVLPROG (1 << 5)
37 #define NVC0_NEW_GMTYPROG (1 << 6)
38 #define NVC0_NEW_FRAGPROG (1 << 7)
39 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
40 #define NVC0_NEW_STENCIL_REF (1 << 9)
41 #define NVC0_NEW_CLIP (1 << 10)
42 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
43 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
44 #define NVC0_NEW_STIPPLE (1 << 13)
45 #define NVC0_NEW_SCISSOR (1 << 14)
46 #define NVC0_NEW_VIEWPORT (1 << 15)
47 #define NVC0_NEW_ARRAYS (1 << 16)
48 #define NVC0_NEW_VERTEX (1 << 17)
49 #define NVC0_NEW_CONSTBUF (1 << 18)
50 #define NVC0_NEW_TEXTURES (1 << 19)
51 #define NVC0_NEW_SAMPLERS (1 << 20)
52 #define NVC0_NEW_TFB_TARGETS (1 << 21)
53
54 #define NVC0_BUFCTX_CONSTANT 0
55 #define NVC0_BUFCTX_FRAME 1
56 #define NVC0_BUFCTX_VERTEX 2
57 #define NVC0_BUFCTX_TEXTURES 3
58 #define NVC0_BUFCTX_TFB 4
59 #define NVC0_BUFCTX_COUNT 5
60
61 struct nvc0_context {
62 struct nouveau_context base;
63
64 struct nvc0_screen *screen;
65
66 struct util_dynarray residents[NVC0_BUFCTX_COUNT];
67 unsigned residents_size;
68
69 uint32_t dirty;
70
71 struct {
72 uint32_t instance_elts; /* bitmask of per-instance elements */
73 uint32_t instance_base;
74 int32_t index_bias;
75 boolean prim_restart;
76 boolean early_z;
77 uint16_t scissor;
78 boolean rasterizer_discard;
79 uint8_t num_vtxbufs;
80 uint8_t num_vtxelts;
81 uint8_t num_textures[5];
82 uint8_t num_samplers[5];
83 uint8_t tls_required; /* bitmask of shader types using l[] */
84 uint8_t c14_bound; /* whether immediate array constbuf is bound */
85 uint8_t clip_enable;
86 uint32_t clip_mode;
87 uint32_t uniform_buffer_bound[5];
88 struct nvc0_transform_feedback_state *tfb;
89 } state;
90
91 struct nvc0_blend_stateobj *blend;
92 struct nvc0_rasterizer_stateobj *rast;
93 struct nvc0_zsa_stateobj *zsa;
94 struct nvc0_vertex_stateobj *vertex;
95
96 struct nvc0_program *vertprog;
97 struct nvc0_program *tctlprog;
98 struct nvc0_program *tevlprog;
99 struct nvc0_program *gmtyprog;
100 struct nvc0_program *fragprog;
101
102 struct pipe_resource *constbuf[5][16];
103 uint16_t constbuf_dirty[5];
104
105 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
106 unsigned num_vtxbufs;
107 struct pipe_index_buffer idxbuf;
108 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
109 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
110 unsigned vbo_min_index; /* from pipe_draw_info, for vertex upload */
111 unsigned vbo_max_index;
112
113 struct pipe_sampler_view *textures[5][PIPE_MAX_SAMPLERS];
114 unsigned num_textures[5];
115 struct nv50_tsc_entry *samplers[5][PIPE_MAX_SAMPLERS];
116 unsigned num_samplers[5];
117
118 struct pipe_framebuffer_state framebuffer;
119 struct pipe_blend_color blend_colour;
120 struct pipe_stencil_ref stencil_ref;
121 struct pipe_poly_stipple stipple;
122 struct pipe_scissor_state scissor;
123 struct pipe_viewport_state viewport;
124 struct pipe_clip_state clip;
125
126 unsigned sample_mask;
127
128 boolean vbo_push_hint;
129
130 uint8_t tfbbuf_dirty;
131 struct pipe_stream_output_target *tfbbuf[4];
132 unsigned num_tfbbufs;
133
134 struct draw_context *draw;
135 };
136
137 static INLINE struct nvc0_context *
138 nvc0_context(struct pipe_context *pipe)
139 {
140 return (struct nvc0_context *)pipe;
141 }
142
143 /* nvc0_context.c */
144 struct pipe_context *nvc0_create(struct pipe_screen *, void *);
145
146 void nvc0_default_flush_notify(struct nouveau_channel *);
147
148 void nvc0_bufctx_emit_relocs(struct nvc0_context *);
149 void nvc0_bufctx_add_resident(struct nvc0_context *, int ctx,
150 struct nv04_resource *, uint32_t flags);
151 void nvc0_bufctx_del_resident(struct nvc0_context *, int ctx,
152 struct nv04_resource *);
153 static INLINE void
154 nvc0_bufctx_reset(struct nvc0_context *nvc0, int ctx)
155 {
156 nvc0->residents_size -= nvc0->residents[ctx].size;
157 util_dynarray_resize(&nvc0->residents[ctx], 0);
158 }
159
160 /* nvc0_draw.c */
161 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
162
163 /* nvc0_program.c */
164 boolean nvc0_program_translate(struct nvc0_program *);
165 boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
166 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
167 void nvc0_program_library_upload(struct nvc0_context *);
168
169 /* nvc0_query.c */
170 void nvc0_init_query_functions(struct nvc0_context *);
171 void nvc0_query_pushbuf_submit(struct nouveau_channel *,
172 struct pipe_query *, unsigned result_offset);
173 void nvc0_query_fifo_wait(struct nouveau_channel *, struct pipe_query *);
174 void nvc0_so_target_save_offset(struct pipe_context *,
175 struct pipe_stream_output_target *, unsigned i,
176 boolean *serialize);
177
178 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
179
180 /* nvc0_shader_state.c */
181 void nvc0_vertprog_validate(struct nvc0_context *);
182 void nvc0_tctlprog_validate(struct nvc0_context *);
183 void nvc0_tevlprog_validate(struct nvc0_context *);
184 void nvc0_gmtyprog_validate(struct nvc0_context *);
185 void nvc0_fragprog_validate(struct nvc0_context *);
186
187 void nvc0_tfb_validate(struct nvc0_context *);
188
189 /* nvc0_state.c */
190 extern void nvc0_init_state_functions(struct nvc0_context *);
191
192 /* nvc0_state_validate.c */
193 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
194 unsigned space_words);
195
196 /* nvc0_surface.c */
197 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
198 const union pipe_color_union *color,
199 double depth, unsigned stencil);
200 extern void nvc0_init_surface_functions(struct nvc0_context *);
201
202 /* nvc0_tex.c */
203 void nvc0_validate_textures(struct nvc0_context *);
204 void nvc0_validate_samplers(struct nvc0_context *);
205
206 struct pipe_sampler_view *
207 nvc0_create_sampler_view(struct pipe_context *,
208 struct pipe_resource *,
209 const struct pipe_sampler_view *);
210
211 /* nvc0_transfer.c */
212 void
213 nvc0_m2mf_transfer_rect(struct pipe_screen *pscreen,
214 const struct nv50_m2mf_rect *dst,
215 const struct nv50_m2mf_rect *src,
216 uint32_t nblocksx, uint32_t nblocksy);
217 void
218 nvc0_m2mf_push_linear(struct nouveau_context *nv,
219 struct nouveau_bo *dst, unsigned offset, unsigned domain,
220 unsigned size, const void *data);
221 void
222 nvc0_m2mf_copy_linear(struct nouveau_context *nv,
223 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
224 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
225 unsigned size);
226 void
227 nvc0_cb_push(struct nouveau_context *,
228 struct nouveau_bo *bo, unsigned domain,
229 unsigned base, unsigned size,
230 unsigned offset, unsigned words, const uint32_t *data);
231
232 /* nvc0_vbo.c */
233 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
234
235 void *
236 nvc0_vertex_state_create(struct pipe_context *pipe,
237 unsigned num_elements,
238 const struct pipe_vertex_element *elements);
239 void
240 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
241
242 void nvc0_vertex_arrays_validate(struct nvc0_context *nvc0);
243
244 /* nvc0_push.c */
245 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
246 void nvc0_push_vbo2(struct nvc0_context *, const struct pipe_draw_info *);
247
248 #endif