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_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
];
134 struct nvfx_vtxelt_state
*vtxelt
;
137 unsigned hw_vtxelt_nr
;
140 struct nvfx_render_target hw_rt
[4];
141 struct nvfx_render_target hw_zeta
;
144 static INLINE
struct nvfx_context
*
145 nvfx_context(struct pipe_context
*pipe
)
147 return (struct nvfx_context
*)pipe
;
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
;
165 extern void nvfx_init_query_functions(struct nvfx_context
*nvfx
);
166 extern void nvfx_init_surface_functions(struct nvfx_context
*nvfx
);
169 struct pipe_context
*
170 nvfx_create(struct pipe_screen
*pscreen
, void *priv
);
173 extern void nvfx_clear(struct pipe_context
*pipe
, unsigned buffers
,
174 const float *rgba
, double depth
, unsigned stencil
);
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
,
182 unsigned start
, unsigned count
);
183 extern void nvfx_vtxfmt_validate(struct nvfx_context
*nvfx
);
186 extern void nvfx_state_framebuffer_validate(struct nvfx_context
*nvfx
);
188 nvfx_framebuffer_relocate(struct nvfx_context
*nvfx
);
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
);
195 nvfx_fragprog_relocate(struct nvfx_context
*nvfx
);
198 extern void nvfx_fragtex_validate(struct nvfx_context
*nvfx
);
200 nvfx_fragtex_relocate(struct nvfx_context
*nvfx
);
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
);
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
);
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
);
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
);
233 /* nvfx_transfer.c */
234 extern void nvfx_init_transfer_functions(struct nvfx_context
*nvfx
);
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
);
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
*);