Merge branch '7.8'
[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_resource *idxbuf;
125 unsigned idxbuf_format;
126 struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
127 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
128 unsigned nr_samplers;
129 unsigned nr_textures;
130 unsigned dirty_samplers;
131 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
132 unsigned vtxbuf_nr;
133 struct nvfx_vtxelt_state *vtxelt;
134
135 unsigned vbo_bo;
136 unsigned hw_vtxelt_nr;
137 uint8_t hw_samplers;
138 uint32_t hw_txf[8];
139 struct nvfx_render_target hw_rt[4];
140 struct nvfx_render_target hw_zeta;
141 };
142
143 static INLINE struct nvfx_context *
144 nvfx_context(struct pipe_context *pipe)
145 {
146 return (struct nvfx_context *)pipe;
147 }
148
149 extern struct nvfx_state_entry nvfx_state_blend;
150 extern struct nvfx_state_entry nvfx_state_blend_colour;
151 extern struct nvfx_state_entry nvfx_state_fragprog;
152 extern struct nvfx_state_entry nvfx_state_fragtex;
153 extern struct nvfx_state_entry nvfx_state_framebuffer;
154 extern struct nvfx_state_entry nvfx_state_rasterizer;
155 extern struct nvfx_state_entry nvfx_state_scissor;
156 extern struct nvfx_state_entry nvfx_state_sr;
157 extern struct nvfx_state_entry nvfx_state_stipple;
158 extern struct nvfx_state_entry nvfx_state_vbo;
159 extern struct nvfx_state_entry nvfx_state_vertprog;
160 extern struct nvfx_state_entry nvfx_state_viewport;
161 extern struct nvfx_state_entry nvfx_state_vtxfmt;
162 extern struct nvfx_state_entry nvfx_state_zsa;
163
164 extern void nvfx_init_query_functions(struct nvfx_context *nvfx);
165 extern void nvfx_init_surface_functions(struct nvfx_context *nvfx);
166
167 /* nvfx_context.c */
168 struct pipe_context *
169 nvfx_create(struct pipe_screen *pscreen, void *priv);
170
171 /* nvfx_clear.c */
172 extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers,
173 const float *rgba, double depth, unsigned stencil);
174
175 /* nvfx_draw.c */
176 extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
177 extern void nvfx_draw_elements_swtnl(struct pipe_context *pipe,
178 struct pipe_resource *idxbuf,
179 unsigned ib_size, int ib_bias,
180 unsigned mode,
181 unsigned start, unsigned count);
182 extern void nvfx_vtxfmt_validate(struct nvfx_context *nvfx);
183
184 /* nvfx_fb.c */
185 extern void nvfx_state_framebuffer_validate(struct nvfx_context *nvfx);
186 void
187 nvfx_framebuffer_relocate(struct nvfx_context *nvfx);
188
189 /* nvfx_fragprog.c */
190 extern void nvfx_fragprog_destroy(struct nvfx_context *,
191 struct nvfx_fragment_program *);
192 extern void nvfx_fragprog_validate(struct nvfx_context *nvfx);
193 extern void
194 nvfx_fragprog_relocate(struct nvfx_context *nvfx);
195
196 /* nvfx_fragtex.c */
197 extern void nvfx_fragtex_validate(struct nvfx_context *nvfx);
198 extern void
199 nvfx_fragtex_relocate(struct nvfx_context *nvfx);
200
201 /* nv30_fragtex.c */
202 extern void
203 nv30_sampler_state_init(struct pipe_context *pipe,
204 struct nvfx_sampler_state *ps,
205 const struct pipe_sampler_state *cso);
206 extern void nv30_fragtex_set(struct nvfx_context *nvfx, int unit);
207
208 /* nv40_fragtex.c */
209 extern void
210 nv40_sampler_state_init(struct pipe_context *pipe,
211 struct nvfx_sampler_state *ps,
212 const struct pipe_sampler_state *cso);
213 extern void nv40_fragtex_set(struct nvfx_context *nvfx, int unit);
214
215 /* nvfx_state.c */
216 extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
217 extern void nvfx_state_scissor_validate(struct nvfx_context *nvfx);
218 extern void nvfx_state_stipple_validate(struct nvfx_context *nvfx);
219 extern void nvfx_state_blend_validate(struct nvfx_context *nvfx);
220 extern void nvfx_state_blend_colour_validate(struct nvfx_context *nvfx);
221 extern void nvfx_state_viewport_validate(struct nvfx_context *nvfx);
222 extern void nvfx_state_rasterizer_validate(struct nvfx_context *nvfx);
223 extern void nvfx_state_sr_validate(struct nvfx_context *nvfx);
224 extern void nvfx_state_zsa_validate(struct nvfx_context *nvfx);
225
226 /* nvfx_state_emit.c */
227 extern void nvfx_state_relocate(struct nvfx_context *nvfx);
228 extern boolean nvfx_state_validate(struct nvfx_context *nvfx);
229 extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx);
230 extern void nvfx_state_emit(struct nvfx_context *nvfx);
231
232 /* nvfx_transfer.c */
233 extern void nvfx_init_transfer_functions(struct nvfx_context *nvfx);
234
235 /* nvfx_vbo.c */
236 extern boolean nvfx_vbo_validate(struct nvfx_context *nvfx);
237 extern void nvfx_vbo_relocate(struct nvfx_context *nvfx);
238 extern void nvfx_draw_arrays(struct pipe_context *, unsigned mode,
239 unsigned start, unsigned count);
240 extern void nvfx_draw_elements(struct pipe_context *pipe,
241 struct pipe_resource *indexBuffer,
242 unsigned indexSize, int indexBias,
243 unsigned mode, unsigned start,
244 unsigned count);
245
246 /* nvfx_vertprog.c */
247 extern boolean nvfx_vertprog_validate(struct nvfx_context *nvfx);
248 extern void nvfx_vertprog_destroy(struct nvfx_context *,
249 struct nvfx_vertex_program *);
250
251 #endif