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