Merge commit 'origin/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 #include "nouveau/nouveau_stateobj.h"
20
21 #include "nvfx_state.h"
22
23 #define NOUVEAU_ERR(fmt, args...) \
24 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
25 #define NOUVEAU_MSG(fmt, args...) \
26 fprintf(stderr, "nouveau: "fmt, ##args);
27
28 enum nvfx_state_index {
29 NVFX_STATE_FB = 0,
30 NVFX_STATE_VIEWPORT = 1,
31 NVFX_STATE_BLEND = 2,
32 NVFX_STATE_RAST = 3,
33 NVFX_STATE_ZSA = 4,
34 NVFX_STATE_BCOL = 5,
35 NVFX_STATE_CLIP = 6,
36 NVFX_STATE_SCISSOR = 7,
37 NVFX_STATE_STIPPLE = 8,
38 NVFX_STATE_FRAGPROG = 9,
39 NVFX_STATE_VERTPROG = 10,
40 NVFX_STATE_FRAGTEX0 = 11,
41 NVFX_STATE_FRAGTEX1 = 12,
42 NVFX_STATE_FRAGTEX2 = 13,
43 NVFX_STATE_FRAGTEX3 = 14,
44 NVFX_STATE_FRAGTEX4 = 15,
45 NVFX_STATE_FRAGTEX5 = 16,
46 NVFX_STATE_FRAGTEX6 = 17,
47 NVFX_STATE_FRAGTEX7 = 18,
48 NVFX_STATE_FRAGTEX8 = 19,
49 NVFX_STATE_FRAGTEX9 = 20,
50 NVFX_STATE_FRAGTEX10 = 21,
51 NVFX_STATE_FRAGTEX11 = 22,
52 NVFX_STATE_FRAGTEX12 = 23,
53 NVFX_STATE_FRAGTEX13 = 24,
54 NVFX_STATE_FRAGTEX14 = 25,
55 NVFX_STATE_FRAGTEX15 = 26,
56 NVFX_STATE_VERTTEX0 = 27,
57 NVFX_STATE_VERTTEX1 = 28,
58 NVFX_STATE_VERTTEX2 = 29,
59 NVFX_STATE_VERTTEX3 = 30,
60 NVFX_STATE_VTXBUF = 31,
61 NVFX_STATE_VTXFMT = 32,
62 NVFX_STATE_VTXATTR = 33,
63 NVFX_STATE_SR = 34,
64 NVFX_STATE_MAX = 35
65 };
66
67 #include "nvfx_screen.h"
68
69 #define NVFX_NEW_BLEND (1 << 0)
70 #define NVFX_NEW_RAST (1 << 1)
71 #define NVFX_NEW_ZSA (1 << 2)
72 #define NVFX_NEW_SAMPLER (1 << 3)
73 #define NVFX_NEW_FB (1 << 4)
74 #define NVFX_NEW_STIPPLE (1 << 5)
75 #define NVFX_NEW_SCISSOR (1 << 6)
76 #define NVFX_NEW_VIEWPORT (1 << 7)
77 #define NVFX_NEW_BCOL (1 << 8)
78 #define NVFX_NEW_VERTPROG (1 << 9)
79 #define NVFX_NEW_FRAGPROG (1 << 10)
80 #define NVFX_NEW_ARRAYS (1 << 11)
81 #define NVFX_NEW_UCP (1 << 12)
82 #define NVFX_NEW_SR (1 << 13)
83
84 struct nvfx_rasterizer_state {
85 struct pipe_rasterizer_state pipe;
86 struct nouveau_stateobj *so;
87 };
88
89 struct nvfx_zsa_state {
90 struct pipe_depth_stencil_alpha_state pipe;
91 struct nouveau_stateobj *so;
92 };
93
94 struct nvfx_blend_state {
95 struct pipe_blend_state pipe;
96 struct nouveau_stateobj *so;
97 };
98
99
100 struct nvfx_state {
101 unsigned scissor_enabled;
102 unsigned stipple_enabled;
103 unsigned fp_samplers;
104
105 uint64_t dirty;
106 struct nouveau_stateobj *hw[NVFX_STATE_MAX];
107 };
108
109 struct nvfx_vtxelt_state {
110 struct pipe_vertex_element pipe[16];
111 unsigned num_elements;
112 };
113
114 struct nvfx_context {
115 struct pipe_context pipe;
116
117 struct nouveau_winsys *nvws;
118 struct nvfx_screen *screen;
119
120 unsigned is_nv4x; /* either 0 or ~0 */
121
122 struct draw_context *draw;
123
124 /* HW state derived from pipe states */
125 struct nvfx_state state;
126 struct {
127 struct nvfx_vertex_program *vertprog;
128
129 unsigned nr_attribs;
130 unsigned hw[PIPE_MAX_SHADER_INPUTS];
131 unsigned draw[PIPE_MAX_SHADER_INPUTS];
132 unsigned emit[PIPE_MAX_SHADER_INPUTS];
133 } swtnl;
134
135 enum {
136 HW, SWTNL, SWRAST
137 } render_mode;
138 unsigned fallback_swtnl;
139 unsigned fallback_swrast;
140
141 /* Context state */
142 unsigned dirty, draw_dirty;
143 struct pipe_scissor_state scissor;
144 unsigned stipple[32];
145 struct pipe_clip_state clip;
146 struct nvfx_vertex_program *vertprog;
147 struct nvfx_fragment_program *fragprog;
148 struct pipe_resource *constbuf[PIPE_SHADER_TYPES];
149 unsigned constbuf_nr[PIPE_SHADER_TYPES];
150 struct nvfx_rasterizer_state *rasterizer;
151 struct nvfx_zsa_state *zsa;
152 struct nvfx_blend_state *blend;
153 struct pipe_blend_color blend_colour;
154 struct pipe_stencil_ref stencil_ref;
155 struct pipe_viewport_state viewport;
156 struct pipe_framebuffer_state framebuffer;
157 struct pipe_resource *idxbuf;
158 unsigned idxbuf_format;
159 struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
160 struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
161 unsigned nr_samplers;
162 unsigned nr_textures;
163 unsigned dirty_samplers;
164 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
165 unsigned vtxbuf_nr;
166 struct nvfx_vtxelt_state *vtxelt;
167 };
168
169 static INLINE struct nvfx_context *
170 nvfx_context(struct pipe_context *pipe)
171 {
172 return (struct nvfx_context *)pipe;
173 }
174
175 struct nvfx_state_entry {
176 boolean (*validate)(struct nvfx_context *nvfx);
177 struct {
178 unsigned pipe;
179 unsigned hw;
180 } dirty;
181 };
182
183 extern struct nvfx_state_entry nvfx_state_blend;
184 extern struct nvfx_state_entry nvfx_state_blend_colour;
185 extern struct nvfx_state_entry nvfx_state_fragprog;
186 extern struct nvfx_state_entry nvfx_state_fragtex;
187 extern struct nvfx_state_entry nvfx_state_framebuffer;
188 extern struct nvfx_state_entry nvfx_state_rasterizer;
189 extern struct nvfx_state_entry nvfx_state_scissor;
190 extern struct nvfx_state_entry nvfx_state_sr;
191 extern struct nvfx_state_entry nvfx_state_stipple;
192 extern struct nvfx_state_entry nvfx_state_vbo;
193 extern struct nvfx_state_entry nvfx_state_vertprog;
194 extern struct nvfx_state_entry nvfx_state_viewport;
195 extern struct nvfx_state_entry nvfx_state_vtxfmt;
196 extern struct nvfx_state_entry nvfx_state_zsa;
197
198 extern void nvfx_init_query_functions(struct nvfx_context *nvfx);
199 extern void nvfx_init_surface_functions(struct nvfx_context *nvfx);
200
201 /* nvfx_context.c */
202 struct pipe_context *
203 nvfx_create(struct pipe_screen *pscreen, void *priv);
204
205 /* nvfx_clear.c */
206 extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers,
207 const float *rgba, double depth, unsigned stencil);
208
209 /* nvfx_draw.c */
210 extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
211 extern void nvfx_draw_elements_swtnl(struct pipe_context *pipe,
212 struct pipe_resource *idxbuf,
213 unsigned ib_size, unsigned mode,
214 unsigned start, unsigned count);
215
216 /* nvfx_fragprog.c */
217 extern void nvfx_fragprog_destroy(struct nvfx_context *,
218 struct nvfx_fragment_program *);
219
220 /* nv30_fragtex.c */
221 extern void
222 nv30_sampler_state_init(struct pipe_context *pipe,
223 struct nvfx_sampler_state *ps,
224 const struct pipe_sampler_state *cso);
225 extern void nv30_fragtex_bind(struct nvfx_context *);
226 extern struct nouveau_stateobj *
227 nv30_fragtex_build(struct nvfx_context *nvfx, int unit);
228
229 /* nv40_fragtex.c */
230 extern void
231 nv40_sampler_state_init(struct pipe_context *pipe,
232 struct nvfx_sampler_state *ps,
233 const struct pipe_sampler_state *cso);
234 extern void nv40_fragtex_bind(struct nvfx_context *);
235 extern struct nouveau_stateobj *
236 nv40_fragtex_build(struct nvfx_context *nvfx, int unit);
237
238 /* nvfx_state.c */
239 extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
240
241 /* nvfx_state_emit.c */
242 extern void nvfx_state_flush_notify(struct nouveau_channel *chan);
243 extern boolean nvfx_state_validate(struct nvfx_context *nvfx);
244 extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx);
245 extern void nvfx_state_emit(struct nvfx_context *nvfx);
246
247 /* nvfx_transfer.c */
248 extern void nvfx_init_transfer_functions(struct nvfx_context *nvfx);
249
250 /* nvfx_vbo.c */
251 extern void nvfx_draw_arrays(struct pipe_context *, unsigned mode,
252 unsigned start, unsigned count);
253 extern void nvfx_draw_elements(struct pipe_context *pipe,
254 struct pipe_resource *indexBuffer,
255 unsigned indexSize,
256 unsigned mode, unsigned start,
257 unsigned count);
258
259 /* nvfx_vertprog.c */
260 extern void nvfx_vertprog_destroy(struct nvfx_context *,
261 struct nvfx_vertex_program *);
262
263 #endif