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