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