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    uint32_t vbo_fifo;
114    uint32_t vbo_user;
115    unsigned vbo_min_index;
116    unsigned vbo_max_index;
117    bool vbo_push_hint;
118 
119    struct nouveau_heap  *blit_vp;
120    struct pipe_resource *blit_fp;
121 
122    struct pipe_query *render_cond_query;
123    unsigned render_cond_mode;
124    bool render_cond_cond;
125 };
126 
127 static inline struct nv30_context *
nv30_context(struct pipe_context * pipe)128 nv30_context(struct pipe_context *pipe)
129 {
130    return (struct nv30_context *)pipe;
131 }
132 
133 struct pipe_context *
134 nv30_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
135 
136 void
137 nv30_vbo_init(struct pipe_context *pipe);
138 
139 void
140 nv30_vbo_validate(struct nv30_context *nv30);
141 
142 void
143 nv30_query_init(struct pipe_context *pipe);
144 
145 void
146 nv30_state_init(struct pipe_context *pipe);
147 
148 void
149 nv30_clear_init(struct pipe_context *pipe);
150 
151 void
152 nv30_vertprog_init(struct pipe_context *pipe);
153 
154 void
155 nv30_vertprog_validate(struct nv30_context *nv30);
156 
157 void
158 nv30_fragprog_init(struct pipe_context *pipe);
159 
160 void
161 nv30_fragprog_validate(struct nv30_context *nv30);
162 
163 void
164 nv30_texture_init(struct pipe_context *pipe);
165 
166 void
167 nv30_texture_validate(struct nv30_context *nv30);
168 
169 void
170 nv30_fragtex_init(struct pipe_context *pipe);
171 
172 void
173 nv30_fragtex_validate(struct nv30_context *nv30);
174 
175 void
176 nv40_verttex_init(struct pipe_context *pipe);
177 
178 void
179 nv40_verttex_validate(struct nv30_context *nv30);
180 
181 void
182 nv30_fragtex_sampler_states_bind(struct pipe_context *pipe,
183                                  unsigned nr, void **hwcso);
184 
185 void
186 nv40_verttex_sampler_states_bind(struct pipe_context *pipe,
187                                  unsigned nr, void **hwcso);
188 
189 void
190 nv40_verttex_set_sampler_views(struct pipe_context *pipe, unsigned nr,
191                                bool take_ownership,
192                                struct pipe_sampler_view **views);
193 
194 void
195 nv30_fragtex_set_sampler_views(struct pipe_context *pipe,
196                                unsigned nr, bool take_ownership,
197                                struct pipe_sampler_view **views);
198 
199 void
200 nv30_push_vbo(struct nv30_context *nv30, const struct pipe_draw_info *info,
201               const struct pipe_draw_start_count_bias *draw);
202 
203 void
204 nv30_draw_init(struct pipe_context *pipe);
205 
206 void
207 nv30_render_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
208                 unsigned drawid_offset,
209                 const struct pipe_draw_start_count_bias *draw);
210 
211 bool
212 nv30_state_validate(struct nv30_context *nv30, uint32_t mask, bool hwtnl);
213 
214 void
215 nv30_state_release(struct nv30_context *nv30);
216 
217 #ifdef NV30_3D_VERTEX_BEGIN_END
218 #define NV30_PRIM_GL_CASE(n) \
219    case PIPE_PRIM_##n: return NV30_3D_VERTEX_BEGIN_END_##n
220 
221 static inline unsigned
nv30_prim_gl(unsigned prim)222 nv30_prim_gl(unsigned prim)
223 {
224    switch (prim) {
225    NV30_PRIM_GL_CASE(POINTS);
226    NV30_PRIM_GL_CASE(LINES);
227    NV30_PRIM_GL_CASE(LINE_LOOP);
228    NV30_PRIM_GL_CASE(LINE_STRIP);
229    NV30_PRIM_GL_CASE(TRIANGLES);
230    NV30_PRIM_GL_CASE(TRIANGLE_STRIP);
231    NV30_PRIM_GL_CASE(TRIANGLE_FAN);
232    NV30_PRIM_GL_CASE(QUADS);
233    NV30_PRIM_GL_CASE(QUAD_STRIP);
234    NV30_PRIM_GL_CASE(POLYGON);
235    default:
236       return NV30_3D_VERTEX_BEGIN_END_POINTS;
237       break;
238    }
239 }
240 #endif
241 
242 #endif
243