nvc0: add support for clip distance shader outputs
[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 uint16_t scissor;
78 uint8_t num_vtxbufs;
79 uint8_t num_vtxelts;
80 uint8_t num_textures[5];
81 uint8_t num_samplers[5];
82 uint8_t tls_required; /* bitmask of shader types using l[] */
83 uint8_t c14_bound; /* whether immediate array constbuf is bound */
84 uint8_t clip_enable;
85 uint32_t clip_mode;
86 uint32_t uniform_buffer_bound[5];
87 } state;
88
89 struct nvc0_blend_stateobj *blend;
90 struct nvc0_rasterizer_stateobj *rast;
91 struct nvc0_zsa_stateobj *zsa;
92 struct nvc0_vertex_stateobj *vertex;
93
94 struct nvc0_program *vertprog;
95 struct nvc0_program *tctlprog;
96 struct nvc0_program *tevlprog;
97 struct nvc0_program *gmtyprog;
98 struct nvc0_program *fragprog;
99
100 struct pipe_resource *constbuf[5][16];
101 uint16_t constbuf_dirty[5];
102
103 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
104 unsigned num_vtxbufs;
105 struct pipe_index_buffer idxbuf;
106 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
107 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
108 unsigned vbo_min_index; /* from pipe_draw_info, for vertex upload */
109 unsigned vbo_max_index;
110
111 struct pipe_sampler_view *textures[5][PIPE_MAX_SAMPLERS];
112 unsigned num_textures[5];
113 struct nv50_tsc_entry *samplers[5][PIPE_MAX_SAMPLERS];
114 unsigned num_samplers[5];
115
116 struct pipe_framebuffer_state framebuffer;
117 struct pipe_blend_color blend_colour;
118 struct pipe_stencil_ref stencil_ref;
119 struct pipe_poly_stipple stipple;
120 struct pipe_scissor_state scissor;
121 struct pipe_viewport_state viewport;
122 struct pipe_clip_state clip;
123
124 unsigned sample_mask;
125
126 boolean vbo_push_hint;
127
128 struct nvc0_transform_feedback_state *tfb;
129 struct pipe_resource *tfbbuf[4];
130 unsigned num_tfbbufs;
131 unsigned tfb_offset[4];
132
133 struct draw_context *draw;
134 };
135
136 #define NVC0_USING_EDGEFLAG(ctx) \
137 ((ctx)->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)
138
139 static INLINE struct nvc0_context *
140 nvc0_context(struct pipe_context *pipe)
141 {
142 return (struct nvc0_context *)pipe;
143 }
144
145 /* nvc0_context.c */
146 struct pipe_context *nvc0_create(struct pipe_screen *, void *);
147
148 void nvc0_default_flush_notify(struct nouveau_channel *);
149
150 void nvc0_bufctx_emit_relocs(struct nvc0_context *);
151 void nvc0_bufctx_add_resident(struct nvc0_context *, int ctx,
152 struct nv04_resource *, uint32_t flags);
153 void nvc0_bufctx_del_resident(struct nvc0_context *, int ctx,
154 struct nv04_resource *);
155 static INLINE void
156 nvc0_bufctx_reset(struct nvc0_context *nvc0, int ctx)
157 {
158 nvc0->residents_size -= nvc0->residents[ctx].size;
159 util_dynarray_resize(&nvc0->residents[ctx], 0);
160 }
161
162 /* nvc0_draw.c */
163 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
164
165 /* nvc0_program.c */
166 boolean nvc0_program_translate(struct nvc0_program *);
167 boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
168 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
169 void nvc0_program_library_upload(struct nvc0_context *);
170
171 /* nvc0_query.c */
172 void nvc0_init_query_functions(struct nvc0_context *);
173 void nvc0_query_pushbuf_submit(struct nvc0_context *nvc0,
174 struct pipe_query *pq, unsigned result_offset);
175
176 #define NVC0_QUERY_TFB_BUFFER_OFFSETS (PIPE_QUERY_TYPES + 0)
177
178 /* nvc0_shader_state.c */
179 void nvc0_vertprog_validate(struct nvc0_context *);
180 void nvc0_tctlprog_validate(struct nvc0_context *);
181 void nvc0_tevlprog_validate(struct nvc0_context *);
182 void nvc0_gmtyprog_validate(struct nvc0_context *);
183 void nvc0_fragprog_validate(struct nvc0_context *);
184
185 void nvc0_tfb_validate(struct nvc0_context *);
186
187 /* nvc0_state.c */
188 extern void nvc0_init_state_functions(struct nvc0_context *);
189
190 /* nvc0_state_validate.c */
191 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
192 unsigned space_words);
193
194 /* nvc0_surface.c */
195 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
196 const union pipe_color_union *color,
197 double depth, unsigned stencil);
198 extern void nvc0_init_surface_functions(struct nvc0_context *);
199
200 /* nvc0_tex.c */
201 void nvc0_validate_textures(struct nvc0_context *);
202 void nvc0_validate_samplers(struct nvc0_context *);
203
204 struct pipe_sampler_view *
205 nvc0_create_sampler_view(struct pipe_context *,
206 struct pipe_resource *,
207 const struct pipe_sampler_view *);
208
209 /* nvc0_transfer.c */
210 void
211 nvc0_m2mf_transfer_rect(struct pipe_screen *pscreen,
212 const struct nv50_m2mf_rect *dst,
213 const struct nv50_m2mf_rect *src,
214 uint32_t nblocksx, uint32_t nblocksy);
215 void
216 nvc0_m2mf_push_linear(struct nouveau_context *nv,
217 struct nouveau_bo *dst, unsigned offset, unsigned domain,
218 unsigned size, const void *data);
219 void
220 nvc0_m2mf_copy_linear(struct nouveau_context *nv,
221 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
222 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
223 unsigned size);
224
225 /* nvc0_vbo.c */
226 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
227
228 void *
229 nvc0_vertex_state_create(struct pipe_context *pipe,
230 unsigned num_elements,
231 const struct pipe_vertex_element *elements);
232 void
233 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
234
235 void nvc0_vertex_arrays_validate(struct nvc0_context *nvc0);
236
237 /* nvc0_push.c */
238 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
239 void nvc0_push_vbo2(struct nvc0_context *, const struct pipe_draw_info *);
240
241 #endif