Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / drivers / nv50 / nv50_context.h
1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_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_debug.h"
16 #include "nv50_winsys.h"
17 #include "nv50_stateobj.h"
18 #include "nv50_screen.h"
19 #include "nv50_program.h"
20 #include "nv50_resource.h"
21
22 #include "nouveau/nouveau_context.h"
23 #include "nouveau/nv_object.xml.h"
24 #include "nouveau/nv_m2mf.xml.h"
25 #include "nv50_3ddefs.xml.h"
26 #include "nv50_3d.xml.h"
27 #include "nv50_2d.xml.h"
28
29 #define NV50_NEW_BLEND        (1 << 0)
30 #define NV50_NEW_RASTERIZER   (1 << 1)
31 #define NV50_NEW_ZSA          (1 << 2)
32 #define NV50_NEW_VERTPROG     (1 << 3)
33 #define NV50_NEW_GMTYPROG     (1 << 6)
34 #define NV50_NEW_FRAGPROG     (1 << 7)
35 #define NV50_NEW_BLEND_COLOUR (1 << 8)
36 #define NV50_NEW_STENCIL_REF  (1 << 9)
37 #define NV50_NEW_CLIP         (1 << 10)
38 #define NV50_NEW_SAMPLE_MASK  (1 << 11)
39 #define NV50_NEW_FRAMEBUFFER  (1 << 12)
40 #define NV50_NEW_STIPPLE      (1 << 13)
41 #define NV50_NEW_SCISSOR      (1 << 14)
42 #define NV50_NEW_VIEWPORT     (1 << 15)
43 #define NV50_NEW_ARRAYS       (1 << 16)
44 #define NV50_NEW_VERTEX       (1 << 17)
45 #define NV50_NEW_CONSTBUF     (1 << 18)
46 #define NV50_NEW_TEXTURES     (1 << 19)
47 #define NV50_NEW_SAMPLERS     (1 << 20)
48
49 #define NV50_BUFCTX_CONSTANT 0
50 #define NV50_BUFCTX_FRAME    1
51 #define NV50_BUFCTX_VERTEX   2
52 #define NV50_BUFCTX_TEXTURES 3
53 #define NV50_BUFCTX_COUNT    4
54
55 /* fixed constant buffer binding points - low indices for user's constbufs */
56 #define NV50_CB_PVP 124
57 #define NV50_CB_PGP 126
58 #define NV50_CB_PFP 125
59 #define NV50_CB_AUX 127
60
61 struct nv50_context {
62    struct nouveau_context base;
63
64    struct nv50_screen *screen;
65
66    struct util_dynarray residents[NV50_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       uint32_t interpolant_ctrl;
75       uint32_t semantic_color;
76       uint32_t semantic_psize;
77       int32_t index_bias;
78       boolean prim_restart;
79       boolean point_sprite;
80       uint8_t num_vtxbufs;
81       uint8_t num_vtxelts;
82       uint8_t num_textures[3];
83       uint8_t num_samplers[3];
84       uint16_t scissor;
85    } state;
86
87    struct nv50_blend_stateobj *blend;
88    struct nv50_rasterizer_stateobj *rast;
89    struct nv50_zsa_stateobj *zsa;
90    struct nv50_vertex_stateobj *vertex;
91
92    struct nv50_program *vertprog;
93    struct nv50_program *gmtyprog;
94    struct nv50_program *fragprog;
95
96    struct pipe_resource *constbuf[3][16];
97    uint16_t constbuf_dirty[3];
98
99    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
100    unsigned num_vtxbufs;
101    struct pipe_index_buffer idxbuf;
102    uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
103    uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
104    unsigned vbo_min_index; /* from pipe_draw_info, for vertex upload */
105    unsigned vbo_max_index;
106
107    struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS];
108    unsigned num_textures[3];
109    struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS];
110    unsigned num_samplers[3];
111
112    struct pipe_framebuffer_state framebuffer;
113    struct pipe_blend_color blend_colour;
114    struct pipe_stencil_ref stencil_ref;
115    struct pipe_poly_stipple stipple;
116    struct pipe_scissor_state scissor;
117    struct pipe_viewport_state viewport;
118    struct pipe_clip_state clip;
119
120    unsigned sample_mask;
121
122    boolean vbo_push_hint;
123
124    struct draw_context *draw;
125 };
126
127 static INLINE struct nv50_context *
128 nv50_context(struct pipe_context *pipe)
129 {
130    return (struct nv50_context *)pipe;
131 }
132
133 struct nv50_surface {
134    struct pipe_surface base;
135    uint32_t offset;
136    uint32_t width;
137    uint16_t height;
138    uint16_t depth;
139 };
140
141 static INLINE struct nv50_surface *
142 nv50_surface(struct pipe_surface *ps)
143 {
144    return (struct nv50_surface *)ps;
145 }
146
147 /* nv50_context.c */
148 struct pipe_context *nv50_create(struct pipe_screen *, void *);
149
150 void nv50_default_flush_notify(struct nouveau_channel *);
151
152 void nv50_bufctx_emit_relocs(struct nv50_context *);
153 void nv50_bufctx_add_resident(struct nv50_context *, int ctx,
154                               struct nv04_resource *, uint32_t flags);
155 void nv50_bufctx_del_resident(struct nv50_context *, int ctx,
156                               struct nv04_resource *);
157 static INLINE void
158 nv50_bufctx_reset(struct nv50_context *nv50, int ctx)
159 {
160    nv50->residents_size -= nv50->residents[ctx].size;
161    util_dynarray_resize(&nv50->residents[ctx], 0);
162 }
163
164 /* nv50_draw.c */
165 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
166
167 /* nv50_program.c */
168 boolean nv50_program_translate(struct nv50_program *);
169 void nv50_program_destroy(struct nv50_context *, struct nv50_program *);
170
171 /* nv50_query.c */
172 void nv50_init_query_functions(struct nv50_context *);
173
174 /* nv50_shader_state.c */
175 void nv50_vertprog_validate(struct nv50_context *);
176 void nv50_gmtyprog_validate(struct nv50_context *);
177 void nv50_fragprog_validate(struct nv50_context *);
178 void nv50_fp_linkage_validate(struct nv50_context *);
179 void nv50_gp_linkage_validate(struct nv50_context *);
180 void nv50_constbufs_validate(struct nv50_context *);
181 void nv50_validate_derived_rs(struct nv50_context *);
182
183 /* nv50_state.c */
184 extern void nv50_init_state_functions(struct nv50_context *);
185
186 /* nv50_state_validate.c */
187 extern boolean nv50_state_validate(struct nv50_context *);
188
189 /* nv50_surface.c */
190 extern void nv50_clear(struct pipe_context *, unsigned buffers,
191                        const float *rgba, double depth, unsigned stencil);
192 extern void nv50_init_surface_functions(struct nv50_context *);
193
194 /* nv50_tex.c */
195 void nv50_validate_textures(struct nv50_context *);
196 void nv50_validate_samplers(struct nv50_context *);
197
198 struct pipe_sampler_view *
199 nv50_create_sampler_view(struct pipe_context *,
200                          struct pipe_resource *,
201                          const struct pipe_sampler_view *);
202
203 /* nv50_transfer.c */
204 void
205 nv50_sifc_linear_u8(struct nouveau_context *pipe,
206                     struct nouveau_bo *dst, unsigned offset, unsigned domain,
207                     unsigned size, void *data);
208 void
209 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
210                       struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
211                       struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
212                       unsigned size);
213
214 /* nv50_vbo.c */
215 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
216
217 void *
218 nv50_vertex_state_create(struct pipe_context *pipe,
219                          unsigned num_elements,
220                          const struct pipe_vertex_element *elements);
221 void
222 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
223
224 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
225
226 /* nv50_push.c */
227 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *);
228
229 #endif