gallium: move clear paths from rgba to a pointer to a color union (v2)
[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 (1 << 21)
53 #define NVC0_NEW_TFB_BUFFERS (1 << 22)
54
55 #define NVC0_BUFCTX_CONSTANT 0
56 #define NVC0_BUFCTX_FRAME 1
57 #define NVC0_BUFCTX_VERTEX 2
58 #define NVC0_BUFCTX_TEXTURES 3
59 #define NVC0_BUFCTX_COUNT 4
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 uint8_t num_vtxbufs;
78 uint8_t num_vtxelts;
79 uint8_t num_textures[5];
80 uint8_t num_samplers[5];
81 uint8_t tls_required; /* bitmask of shader types using l[] */
82 uint8_t c14_bound; /* whether immediate array constbuf is bound */
83 uint16_t scissor;
84 uint32_t uniform_buffer_bound[5];
85 } state;
86
87 struct nvc0_blend_stateobj *blend;
88 struct nvc0_rasterizer_stateobj *rast;
89 struct nvc0_zsa_stateobj *zsa;
90 struct nvc0_vertex_stateobj *vertex;
91
92 struct nvc0_program *vertprog;
93 struct nvc0_program *tctlprog;
94 struct nvc0_program *tevlprog;
95 struct nvc0_program *gmtyprog;
96 struct nvc0_program *fragprog;
97
98 struct pipe_resource *constbuf[5][16];
99 uint16_t constbuf_dirty[5];
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[5][PIPE_MAX_SAMPLERS];
110 unsigned num_textures[5];
111 struct nv50_tsc_entry *samplers[5][PIPE_MAX_SAMPLERS];
112 unsigned num_samplers[5];
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 nvc0_transform_feedback_state *tfb;
127 struct pipe_resource *tfbbuf[4];
128 unsigned num_tfbbufs;
129 unsigned tfb_offset[4];
130
131 struct draw_context *draw;
132 };
133
134 #define NVC0_USING_EDGEFLAG(ctx) \
135 ((ctx)->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)
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
172 /* nvc0_shader_state.c */
173 void nvc0_vertprog_validate(struct nvc0_context *);
174 void nvc0_tctlprog_validate(struct nvc0_context *);
175 void nvc0_tevlprog_validate(struct nvc0_context *);
176 void nvc0_gmtyprog_validate(struct nvc0_context *);
177 void nvc0_fragprog_validate(struct nvc0_context *);
178
179 void nvc0_tfb_validate(struct nvc0_context *);
180
181 /* nvc0_state.c */
182 extern void nvc0_init_state_functions(struct nvc0_context *);
183
184 /* nvc0_state_validate.c */
185 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
186 unsigned space_words);
187
188 /* nvc0_surface.c */
189 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
190 const union pipe_color_union *color,
191 double depth, unsigned stencil);
192 extern void nvc0_init_surface_functions(struct nvc0_context *);
193
194 /* nvc0_tex.c */
195 void nvc0_validate_textures(struct nvc0_context *);
196 void nvc0_validate_samplers(struct nvc0_context *);
197
198 struct pipe_sampler_view *
199 nvc0_create_sampler_view(struct pipe_context *,
200 struct pipe_resource *,
201 const struct pipe_sampler_view *);
202
203 /* nvc0_transfer.c */
204 void
205 nvc0_m2mf_transfer_rect(struct pipe_screen *pscreen,
206 const struct nv50_m2mf_rect *dst,
207 const struct nv50_m2mf_rect *src,
208 uint32_t nblocksx, uint32_t nblocksy);
209 void
210 nvc0_m2mf_push_linear(struct nouveau_context *nv,
211 struct nouveau_bo *dst, unsigned offset, unsigned domain,
212 unsigned size, const void *data);
213 void
214 nvc0_m2mf_copy_linear(struct nouveau_context *nv,
215 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
216 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
217 unsigned size);
218
219 /* nvc0_vbo.c */
220 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
221
222 void *
223 nvc0_vertex_state_create(struct pipe_context *pipe,
224 unsigned num_elements,
225 const struct pipe_vertex_element *elements);
226 void
227 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
228
229 void nvc0_vertex_arrays_validate(struct nvc0_context *nvc0);
230
231 /* nvc0_push.c */
232 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
233 void nvc0_push_vbo2(struct nvc0_context *, const struct pipe_draw_info *);
234
235 #endif