gallium: Keep only pipe_context::draw_vbo.
[mesa.git] / src / gallium / drivers / nvfx / nvfx_context.h
1 #ifndef __NVFX_CONTEXT_H__
2 #define __NVFX_CONTEXT_H__
3
4 #include <stdio.h>
5
6 #include "pipe/p_context.h"
7 #include "pipe/p_defines.h"
8 #include "pipe/p_state.h"
9 #include "pipe/p_compiler.h"
10
11 #include "util/u_memory.h"
12 #include "util/u_math.h"
13 #include "util/u_inlines.h"
14
15 #include "draw/draw_vertex.h"
16
17 #include "nouveau/nouveau_winsys.h"
18 #include "nouveau/nouveau_gldefs.h"
19
20 #include "nvfx_state.h"
21
22 #define NOUVEAU_ERR(fmt, args...) \
23 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
24 #define NOUVEAU_MSG(fmt, args...) \
25 fprintf(stderr, "nouveau: "fmt, ##args);
26
27 #include "nvfx_screen.h"
28
29 #define NVFX_NEW_BLEND (1 << 0)
30 #define NVFX_NEW_RAST (1 << 1)
31 #define NVFX_NEW_ZSA (1 << 2)
32 #define NVFX_NEW_SAMPLER (1 << 3)
33 #define NVFX_NEW_FB (1 << 4)
34 #define NVFX_NEW_STIPPLE (1 << 5)
35 #define NVFX_NEW_SCISSOR (1 << 6)
36 #define NVFX_NEW_VIEWPORT (1 << 7)
37 #define NVFX_NEW_BCOL (1 << 8)
38 #define NVFX_NEW_VERTPROG (1 << 9)
39 #define NVFX_NEW_FRAGPROG (1 << 10)
40 #define NVFX_NEW_ARRAYS (1 << 11)
41 #define NVFX_NEW_UCP (1 << 12)
42 #define NVFX_NEW_SR (1 << 13)
43 #define NVFX_NEW_VERTCONST (1 << 14)
44 #define NVFX_NEW_FRAGCONST (1 << 15)
45
46 struct nvfx_rasterizer_state {
47 struct pipe_rasterizer_state pipe;
48 unsigned sb_len;
49 uint32_t sb[32];
50 };
51
52 struct nvfx_zsa_state {
53 struct pipe_depth_stencil_alpha_state pipe;
54 unsigned sb_len;
55 uint32_t sb[26];
56 };
57
58 struct nvfx_blend_state {
59 struct pipe_blend_state pipe;
60 unsigned sb_len;
61 uint32_t sb[13];
62 };
63
64
65 struct nvfx_state {
66 unsigned scissor_enabled;
67 unsigned stipple_enabled;
68 unsigned fp_samplers;
69 };
70
71 struct nvfx_vtxelt_state {
72 struct pipe_vertex_element pipe[16];
73 unsigned num_elements;
74 };
75
76 struct nvfx_render_target {
77 struct nouveau_bo* bo;
78 unsigned offset;
79 unsigned pitch;
80 };
81
82 struct nvfx_context {
83 struct pipe_context pipe;
84
85 struct nouveau_winsys *nvws;
86 struct nvfx_screen *screen;
87
88 unsigned is_nv4x; /* either 0 or ~0 */
89
90 struct draw_context *draw;
91
92 /* HW state derived from pipe states */
93 struct nvfx_state state;
94 struct {
95 struct nvfx_vertex_program *vertprog;
96
97 unsigned nr_attribs;
98 unsigned hw[PIPE_MAX_SHADER_INPUTS];
99 unsigned draw[PIPE_MAX_SHADER_INPUTS];
100 unsigned emit[PIPE_MAX_SHADER_INPUTS];
101 } swtnl;
102
103 enum {
104 HW, SWTNL, SWRAST
105 } render_mode;
106 unsigned fallback_swtnl;
107
108 /* Context state */
109 unsigned dirty, draw_dirty;
110 struct pipe_scissor_state scissor;
111 unsigned stipple[32];
112 struct pipe_clip_state clip;
113 struct nvfx_vertex_program *vertprog;
114 struct nvfx_fragment_program *fragprog;
115 struct pipe_resource *constbuf[PIPE_SHADER_TYPES];
116 unsigned constbuf_nr[PIPE_SHADER_TYPES];
117 struct nvfx_rasterizer_state *rasterizer;
118 struct nvfx_zsa_state *zsa;
119 struct nvfx_blend_state *blend;
120 struct pipe_blend_color blend_colour;
121 struct pipe_stencil_ref stencil_ref;
122 struct pipe_viewport_state viewport;
123 struct pipe_framebuffer_state framebuffer;
124 struct pipe_index_buffer idxbuf;
125 struct pipe_resource *idxbuf_buffer;
126 unsigned idxbuf_format;
127 struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
128 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
129 unsigned nr_samplers;
130 unsigned nr_textures;
131 unsigned dirty_samplers;
132 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
133 unsigned vtxbuf_nr;
134 struct nvfx_vtxelt_state *vtxelt;
135
136 unsigned vbo_bo;
137 unsigned hw_vtxelt_nr;
138 uint8_t hw_samplers;
139 uint32_t hw_txf[8];
140 struct nvfx_render_target hw_rt[4];
141 struct nvfx_render_target hw_zeta;
142 };
143
144 static INLINE struct nvfx_context *
145 nvfx_context(struct pipe_context *pipe)
146 {
147 return (struct nvfx_context *)pipe;
148 }
149
150 extern struct nvfx_state_entry nvfx_state_blend;
151 extern struct nvfx_state_entry nvfx_state_blend_colour;
152 extern struct nvfx_state_entry nvfx_state_fragprog;
153 extern struct nvfx_state_entry nvfx_state_fragtex;
154 extern struct nvfx_state_entry nvfx_state_framebuffer;
155 extern struct nvfx_state_entry nvfx_state_rasterizer;
156 extern struct nvfx_state_entry nvfx_state_scissor;
157 extern struct nvfx_state_entry nvfx_state_sr;
158 extern struct nvfx_state_entry nvfx_state_stipple;
159 extern struct nvfx_state_entry nvfx_state_vbo;
160 extern struct nvfx_state_entry nvfx_state_vertprog;
161 extern struct nvfx_state_entry nvfx_state_viewport;
162 extern struct nvfx_state_entry nvfx_state_vtxfmt;
163 extern struct nvfx_state_entry nvfx_state_zsa;
164
165 extern void nvfx_init_query_functions(struct nvfx_context *nvfx);
166 extern void nvfx_init_surface_functions(struct nvfx_context *nvfx);
167
168 /* nvfx_context.c */
169 struct pipe_context *
170 nvfx_create(struct pipe_screen *pscreen, void *priv);
171
172 /* nvfx_clear.c */
173 extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers,
174 const float *rgba, double depth, unsigned stencil);
175
176 /* nvfx_draw.c */
177 extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
178 extern void nvfx_draw_elements_swtnl(struct pipe_context *pipe,
179 struct pipe_resource *idxbuf,
180 unsigned ib_size, int ib_bias,
181 unsigned mode,
182 unsigned start, unsigned count);
183 extern void nvfx_vtxfmt_validate(struct nvfx_context *nvfx);
184
185 /* nvfx_fb.c */
186 extern void nvfx_state_framebuffer_validate(struct nvfx_context *nvfx);
187 void
188 nvfx_framebuffer_relocate(struct nvfx_context *nvfx);
189
190 /* nvfx_fragprog.c */
191 extern void nvfx_fragprog_destroy(struct nvfx_context *,
192 struct nvfx_fragment_program *);
193 extern void nvfx_fragprog_validate(struct nvfx_context *nvfx);
194 extern void
195 nvfx_fragprog_relocate(struct nvfx_context *nvfx);
196
197 /* nvfx_fragtex.c */
198 extern void nvfx_fragtex_validate(struct nvfx_context *nvfx);
199 extern void
200 nvfx_fragtex_relocate(struct nvfx_context *nvfx);
201
202 /* nv30_fragtex.c */
203 extern void
204 nv30_sampler_state_init(struct pipe_context *pipe,
205 struct nvfx_sampler_state *ps,
206 const struct pipe_sampler_state *cso);
207 extern void nv30_fragtex_set(struct nvfx_context *nvfx, int unit);
208
209 /* nv40_fragtex.c */
210 extern void
211 nv40_sampler_state_init(struct pipe_context *pipe,
212 struct nvfx_sampler_state *ps,
213 const struct pipe_sampler_state *cso);
214 extern void nv40_fragtex_set(struct nvfx_context *nvfx, int unit);
215
216 /* nvfx_state.c */
217 extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
218 extern void nvfx_state_scissor_validate(struct nvfx_context *nvfx);
219 extern void nvfx_state_stipple_validate(struct nvfx_context *nvfx);
220 extern void nvfx_state_blend_validate(struct nvfx_context *nvfx);
221 extern void nvfx_state_blend_colour_validate(struct nvfx_context *nvfx);
222 extern void nvfx_state_viewport_validate(struct nvfx_context *nvfx);
223 extern void nvfx_state_rasterizer_validate(struct nvfx_context *nvfx);
224 extern void nvfx_state_sr_validate(struct nvfx_context *nvfx);
225 extern void nvfx_state_zsa_validate(struct nvfx_context *nvfx);
226
227 /* nvfx_state_emit.c */
228 extern void nvfx_state_relocate(struct nvfx_context *nvfx);
229 extern boolean nvfx_state_validate(struct nvfx_context *nvfx);
230 extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx);
231 extern void nvfx_state_emit(struct nvfx_context *nvfx);
232
233 /* nvfx_transfer.c */
234 extern void nvfx_init_transfer_functions(struct nvfx_context *nvfx);
235
236 /* nvfx_vbo.c */
237 extern boolean nvfx_vbo_validate(struct nvfx_context *nvfx);
238 extern void nvfx_vbo_relocate(struct nvfx_context *nvfx);
239 extern void nvfx_draw_vbo(struct pipe_context *pipe,
240 const struct pipe_draw_info *info);
241
242 /* nvfx_vertprog.c */
243 extern boolean nvfx_vertprog_validate(struct nvfx_context *nvfx);
244 extern void nvfx_vertprog_destroy(struct nvfx_context *,
245 struct nvfx_vertex_program *);
246
247 #endif