1 #ifndef __NV30_CONTEXT_H__
2 #define __NV30_CONTEXT_H__
3
4 #include "pipe/p_format.h"
5 #include "util/u_blitter.h"
6
7 #include "nv30/nv30_screen.h"
8 #include "nv30/nv30_state.h"
9
10 #include "nouveau_context.h"
11
12 #define BUFCTX_FB 0
13 #define BUFCTX_VTXTMP 1
14 #define BUFCTX_VTXBUF 2
15 #define BUFCTX_IDXBUF 3
16 #define BUFCTX_VERTTEX(n) (4 + (n))
17 #define BUFCTX_FRAGPROG 8
18 #define BUFCTX_FRAGTEX(n) (9 + (n))
19
20 #define NV30_NEW_BLEND (1 << 0)
21 #define NV30_NEW_RASTERIZER (1 << 1)
22 #define NV30_NEW_ZSA (1 << 2)
23 #define NV30_NEW_VERTPROG (1 << 3)
24 #define NV30_NEW_VERTCONST (1 << 4)
25 #define NV30_NEW_FRAGPROG (1 << 5)
26 #define NV30_NEW_FRAGCONST (1 << 6)
27 #define NV30_NEW_BLEND_COLOUR (1 << 7)
28 #define NV30_NEW_STENCIL_REF (1 << 8)
29 #define NV30_NEW_CLIP (1 << 9)
30 #define NV30_NEW_SAMPLE_MASK (1 << 10)
31 #define NV30_NEW_FRAMEBUFFER (1 << 11)
32 #define NV30_NEW_STIPPLE (1 << 12)
33 #define NV30_NEW_SCISSOR (1 << 13)
34 #define NV30_NEW_VIEWPORT (1 << 14)
35 #define NV30_NEW_ARRAYS (1 << 15)
36 #define NV30_NEW_VERTEX (1 << 16)
37 #define NV30_NEW_CONSTBUF (1 << 17)
38 #define NV30_NEW_FRAGTEX (1 << 18)
39 #define NV30_NEW_VERTTEX (1 << 19)
40 #define NV30_NEW_SWTNL (1 << 31)
41 #define NV30_NEW_ALL 0x000fffff
42
43 struct nv30_context {
44 struct nouveau_context base;
45 struct nv30_screen *screen;
46 struct blitter_context *blitter;
47
48 struct nouveau_bufctx *bufctx;
49
50 struct {
51 unsigned rt_enable;
52 unsigned scissor_off;
53 unsigned num_vtxelts;
54 int index_bias;
55 bool prim_restart;
56 struct nv30_fragprog *fragprog;
57 } state;
58
59 uint32_t dirty;
60
61 struct draw_context *draw;
62 uint32_t draw_flags;
63 uint32_t draw_dirty;
64
65 struct nv30_blend_stateobj *blend;
66 struct nv30_rasterizer_stateobj *rast;
67 struct nv30_zsa_stateobj *zsa;
68 struct nv30_vertex_stateobj *vertex;
69
70 struct {
71 unsigned filter;
72 unsigned aniso;
73 } config;
74
75 struct {
76 struct nv30_vertprog *program;
77
78 struct pipe_resource *constbuf;
79 unsigned constbuf_nr;
80
81 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
82 unsigned num_textures;
83 struct nv30_sampler_state *samplers[PIPE_MAX_SAMPLERS];
84 unsigned num_samplers;
85 unsigned dirty_samplers;
86 } vertprog;
87
88 struct {
89 struct nv30_fragprog *program;
90
91 struct pipe_resource *constbuf;
92 unsigned constbuf_nr;
93
94 struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];
95 unsigned num_textures;
96 struct nv30_sampler_state *samplers[PIPE_MAX_SAMPLERS];
97 unsigned num_samplers;
98 unsigned dirty_samplers;
99 } fragprog;
100
101 struct pipe_framebuffer_state framebuffer;
102 struct pipe_blend_color blend_colour;
103 struct pipe_stencil_ref stencil_ref;
104 struct pipe_poly_stipple stipple;
105 struct pipe_scissor_state scissor;
106 struct pipe_viewport_state viewport;
107 struct pipe_clip_state clip;
108
109 unsigned sample_mask;
110
111 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
112 unsigned num_vtxbufs;
113 struct pipe_index_buffer idxbuf;
114 uint32_t vbo_fifo;
115 uint32_t vbo_user;
116 unsigned vbo_min_index;
117 unsigned vbo_max_index;
118 bool vbo_push_hint;
119
120 struct nouveau_heap *blit_vp;
121 struct pipe_resource *blit_fp;
122
123 struct pipe_query *render_cond_query;
124 unsigned render_cond_mode;
125 bool render_cond_cond;
126 };
127
128 static inline struct nv30_context *
nv30_context(struct pipe_context * pipe)129 nv30_context(struct pipe_context *pipe)
130 {
131 return (struct nv30_context *)pipe;
132 }
133
134 struct pipe_context *
135 nv30_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
136
137 void
138 nv30_vbo_init(struct pipe_context *pipe);
139
140 void
141 nv30_vbo_validate(struct nv30_context *nv30);
142
143 void
144 nv30_query_init(struct pipe_context *pipe);
145
146 void
147 nv30_state_init(struct pipe_context *pipe);
148
149 void
150 nv30_clear_init(struct pipe_context *pipe);
151
152 void
153 nv30_vertprog_init(struct pipe_context *pipe);
154
155 void
156 nv30_vertprog_validate(struct nv30_context *nv30);
157
158 void
159 nv30_fragprog_init(struct pipe_context *pipe);
160
161 void
162 nv30_fragprog_validate(struct nv30_context *nv30);
163
164 void
165 nv30_texture_init(struct pipe_context *pipe);
166
167 void
168 nv30_texture_validate(struct nv30_context *nv30);
169
170 void
171 nv30_fragtex_init(struct pipe_context *pipe);
172
173 void
174 nv30_fragtex_validate(struct nv30_context *nv30);
175
176 void
177 nv40_verttex_init(struct pipe_context *pipe);
178
179 void
180 nv40_verttex_validate(struct nv30_context *nv30);
181
182 void
183 nv30_fragtex_sampler_states_bind(struct pipe_context *pipe,
184 unsigned nr, void **hwcso);
185
186 void
187 nv40_verttex_sampler_states_bind(struct pipe_context *pipe,
188 unsigned nr, void **hwcso);
189
190 void
191 nv40_verttex_set_sampler_views(struct pipe_context *pipe, unsigned nr,
192 struct pipe_sampler_view **views);
193
194 void
195 nv30_fragtex_set_sampler_views(struct pipe_context *pipe,
196 unsigned nr, struct pipe_sampler_view **views);
197
198 void
199 nv30_push_vbo(struct nv30_context *nv30, const struct pipe_draw_info *info);
200
201 void
202 nv30_draw_init(struct pipe_context *pipe);
203
204 void
205 nv30_render_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info);
206
207 bool
208 nv30_state_validate(struct nv30_context *nv30, uint32_t mask, bool hwtnl);
209
210 void
211 nv30_state_release(struct nv30_context *nv30);
212
213 #ifdef NV30_3D_VERTEX_BEGIN_END
214 #define NV30_PRIM_GL_CASE(n) \
215 case PIPE_PRIM_##n: return NV30_3D_VERTEX_BEGIN_END_##n
216
217 static inline unsigned
nv30_prim_gl(unsigned prim)218 nv30_prim_gl(unsigned prim)
219 {
220 switch (prim) {
221 NV30_PRIM_GL_CASE(POINTS);
222 NV30_PRIM_GL_CASE(LINES);
223 NV30_PRIM_GL_CASE(LINE_LOOP);
224 NV30_PRIM_GL_CASE(LINE_STRIP);
225 NV30_PRIM_GL_CASE(TRIANGLES);
226 NV30_PRIM_GL_CASE(TRIANGLE_STRIP);
227 NV30_PRIM_GL_CASE(TRIANGLE_FAN);
228 NV30_PRIM_GL_CASE(QUADS);
229 NV30_PRIM_GL_CASE(QUAD_STRIP);
230 NV30_PRIM_GL_CASE(POLYGON);
231 default:
232 return NV30_3D_VERTEX_BEGIN_END_POINTS;
233 break;
234 }
235 }
236 #endif
237
238 #endif
239