1 #ifndef __NVFX_CONTEXT_H__
2 #define __NVFX_CONTEXT_H__
6 #include "pipe/p_context.h"
7 #include "pipe/p_defines.h"
8 #include "pipe/p_state.h"
9 #include "pipe/p_compiler.h"
11 #include "util/u_memory.h"
12 #include "util/u_math.h"
13 #include "util/u_inlines.h"
15 #include "draw/draw_vertex.h"
17 #include "nouveau/nouveau_winsys.h"
18 #include "nouveau/nouveau_gldefs.h"
20 #include "nvfx_state.h"
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);
27 #include "nvfx_screen.h"
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)
46 struct nvfx_rasterizer_state
{
47 struct pipe_rasterizer_state pipe
;
52 struct nvfx_zsa_state
{
53 struct pipe_depth_stencil_alpha_state pipe
;
58 struct nvfx_blend_state
{
59 struct pipe_blend_state pipe
;
66 unsigned scissor_enabled
;
67 unsigned stipple_enabled
;
71 struct nvfx_vtxelt_state
{
72 struct pipe_vertex_element pipe
[16];
73 unsigned num_elements
;
76 struct nvfx_render_target
{
77 struct nouveau_bo
* bo
;
83 struct pipe_context pipe
;
85 struct nouveau_winsys
*nvws
;
86 struct nvfx_screen
*screen
;
88 unsigned is_nv4x
; /* either 0 or ~0 */
90 struct draw_context
*draw
;
92 /* HW state derived from pipe states */
93 struct nvfx_state state
;
95 struct nvfx_vertex_program
*vertprog
;
98 unsigned hw
[PIPE_MAX_SHADER_INPUTS
];
99 unsigned draw
[PIPE_MAX_SHADER_INPUTS
];
100 unsigned emit
[PIPE_MAX_SHADER_INPUTS
];
106 unsigned fallback_swtnl
;
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
];
133 struct nvfx_vtxelt_state
*vtxelt
;
136 unsigned hw_vtxelt_nr
;
139 struct nvfx_render_target hw_rt
[4];
140 struct nvfx_render_target hw_zeta
;
143 static INLINE
struct nvfx_context
*
144 nvfx_context(struct pipe_context
*pipe
)
146 return (struct nvfx_context
*)pipe
;
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
;
164 extern void nvfx_init_query_functions(struct nvfx_context
*nvfx
);
165 extern void nvfx_init_surface_functions(struct nvfx_context
*nvfx
);
168 struct pipe_context
*
169 nvfx_create(struct pipe_screen
*pscreen
, void *priv
);
172 extern void nvfx_clear(struct pipe_context
*pipe
, unsigned buffers
,
173 const float *rgba
, double depth
, unsigned stencil
);
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
,
181 unsigned start
, unsigned count
);
182 extern void nvfx_vtxfmt_validate(struct nvfx_context
*nvfx
);
185 extern void nvfx_state_framebuffer_validate(struct nvfx_context
*nvfx
);
187 nvfx_framebuffer_relocate(struct nvfx_context
*nvfx
);
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
);
194 nvfx_fragprog_relocate(struct nvfx_context
*nvfx
);
197 extern void nvfx_fragtex_validate(struct nvfx_context
*nvfx
);
199 nvfx_fragtex_relocate(struct nvfx_context
*nvfx
);
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
);
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
);
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
);
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
);
232 /* nvfx_transfer.c */
233 extern void nvfx_init_transfer_functions(struct nvfx_context
*nvfx
);
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
,
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
*);