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