1 #ifndef __NVC0_CONTEXT_H__
2 #define __NVC0_CONTEXT_H__
5 #include "pipe/p_context.h"
6 #include "pipe/p_defines.h"
7 #include "pipe/p_state.h"
9 #include "util/u_memory.h"
10 #include "util/u_math.h"
11 #include "util/u_inlines.h"
12 #include "util/u_dynarray.h"
14 #include "draw/draw_vertex.h"
16 #include "nvc0_winsys.h"
17 #include "nvc0_stateobj.h"
18 #include "nvc0_screen.h"
19 #include "nvc0_program.h"
20 #include "nvc0_resource.h"
22 #include "nvc0_3ddefs.xml.h"
23 #include "nvc0_3d.xml.h"
24 #include "nvc0_2d.xml.h"
25 #include "nvc0_m2mf.xml.h"
27 #define NOUVEAU_ERR(fmt, args...) \
28 fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args);
31 # define NOUVEAU_DBG(args...) printf(args);
33 # define NOUVEAU_DBG(args...)
36 #define NVC0_NEW_BLEND (1 << 0)
37 #define NVC0_NEW_RASTERIZER (1 << 1)
38 #define NVC0_NEW_ZSA (1 << 2)
39 #define NVC0_NEW_VERTPROG (1 << 3)
40 #define NVC0_NEW_TCTLPROG (1 << 4)
41 #define NVC0_NEW_TEVLPROG (1 << 5)
42 #define NVC0_NEW_GMTYPROG (1 << 6)
43 #define NVC0_NEW_FRAGPROG (1 << 7)
44 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
45 #define NVC0_NEW_STENCIL_REF (1 << 9)
46 #define NVC0_NEW_CLIP (1 << 10)
47 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
48 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
49 #define NVC0_NEW_STIPPLE (1 << 13)
50 #define NVC0_NEW_SCISSOR (1 << 14)
51 #define NVC0_NEW_VIEWPORT (1 << 15)
52 #define NVC0_NEW_ARRAYS (1 << 16)
53 #define NVC0_NEW_VERTEX (1 << 17)
54 #define NVC0_NEW_CONSTBUF (1 << 18)
55 #define NVC0_NEW_TEXTURES (1 << 19)
56 #define NVC0_NEW_SAMPLERS (1 << 20)
57 #define NVC0_NEW_TFB (1 << 21)
58 #define NVC0_NEW_TFB_BUFFERS (1 << 22)
60 #define NVC0_BUFCTX_CONSTANT 0
61 #define NVC0_BUFCTX_FRAME 1
62 #define NVC0_BUFCTX_VERTEX 2
63 #define NVC0_BUFCTX_TEXTURES 3
64 #define NVC0_BUFCTX_COUNT 4
67 struct pipe_context pipe
;
69 struct nvc0_screen
*screen
;
71 struct util_dynarray residents
[NVC0_BUFCTX_COUNT
];
76 uint32_t instance_elts
; /* bitmask of per-instance elements */
77 uint32_t instance_base
;
82 uint8_t num_textures
[5];
83 uint8_t num_samplers
[5];
84 uint8_t tls_required
; /* bitmask of shader types using l[] */
86 uint32_t uniform_buffer_bound
[5];
89 struct nvc0_blend_stateobj
*blend
;
90 struct nvc0_rasterizer_stateobj
*rast
;
91 struct nvc0_zsa_stateobj
*zsa
;
92 struct nvc0_vertex_stateobj
*vertex
;
94 struct nvc0_program
*vertprog
;
95 struct nvc0_program
*tctlprog
;
96 struct nvc0_program
*tevlprog
;
97 struct nvc0_program
*gmtyprog
;
98 struct nvc0_program
*fragprog
;
100 struct pipe_resource
*constbuf
[5][16];
101 uint16_t constbuf_dirty
[5];
103 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
104 unsigned num_vtxbufs
;
105 struct pipe_index_buffer idxbuf
;
106 uint32_t vbo_fifo
; /* bitmask of vertex elements to be pushed to FIFO */
107 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
108 unsigned vbo_min_index
; /* from pipe_draw_info, for vertex upload */
109 unsigned vbo_max_index
;
111 struct pipe_sampler_view
*textures
[5][PIPE_MAX_SAMPLERS
];
112 unsigned num_textures
[5];
113 struct nvc0_tsc_entry
*samplers
[5][PIPE_MAX_SAMPLERS
];
114 unsigned num_samplers
[5];
116 struct pipe_framebuffer_state framebuffer
;
117 struct pipe_blend_color blend_colour
;
118 struct pipe_stencil_ref stencil_ref
;
119 struct pipe_poly_stipple stipple
;
120 struct pipe_scissor_state scissor
;
121 struct pipe_viewport_state viewport
;
122 struct pipe_clip_state clip
;
124 unsigned sample_mask
;
127 boolean vbo_push_hint
;
129 struct nvc0_transform_feedback_state
*tfb
;
130 struct pipe_resource
*tfbbuf
[4];
131 unsigned num_tfbbufs
;
132 unsigned tfb_offset
[4];
134 struct draw_context
*draw
;
137 static INLINE
struct nvc0_context
*
138 nvc0_context(struct pipe_context
*pipe
)
140 return (struct nvc0_context
*)pipe
;
143 struct nvc0_surface
{
144 struct pipe_surface base
;
151 static INLINE
struct nvc0_surface
*
152 nvc0_surface(struct pipe_surface
*ps
)
154 return (struct nvc0_surface
*)ps
;
158 struct pipe_context
*nvc0_create(struct pipe_screen
*, void *);
160 void nvc0_default_flush_notify(struct nouveau_channel
*);
162 void nvc0_bufctx_emit_relocs(struct nvc0_context
*);
163 void nvc0_bufctx_add_resident(struct nvc0_context
*, int ctx
,
164 struct nvc0_resource
*, uint32_t flags
);
165 void nvc0_bufctx_del_resident(struct nvc0_context
*, int ctx
,
166 struct nvc0_resource
*);
168 nvc0_bufctx_reset(struct nvc0_context
*nvc0
, int ctx
)
170 util_dynarray_resize(&nvc0
->residents
[ctx
], 0);
174 extern struct draw_stage
*nvc0_draw_render_stage(struct nvc0_context
*);
177 boolean
nvc0_program_translate(struct nvc0_program
*);
178 void nvc0_program_destroy(struct nvc0_context
*, struct nvc0_program
*);
181 void nvc0_init_query_functions(struct nvc0_context
*);
183 /* nvc0_shader_state.c */
184 void nvc0_vertprog_validate(struct nvc0_context
*);
185 void nvc0_tctlprog_validate(struct nvc0_context
*);
186 void nvc0_tevlprog_validate(struct nvc0_context
*);
187 void nvc0_gmtyprog_validate(struct nvc0_context
*);
188 void nvc0_fragprog_validate(struct nvc0_context
*);
190 void nvc0_tfb_validate(struct nvc0_context
*);
193 extern void nvc0_init_state_functions(struct nvc0_context
*);
195 /* nvc0_state_validate.c */
196 extern boolean
nvc0_state_validate(struct nvc0_context
*);
199 extern void nvc0_clear(struct pipe_context
*, unsigned buffers
,
200 const float *rgba
, double depth
, unsigned stencil
);
201 extern void nvc0_init_surface_functions(struct nvc0_context
*);
204 void nvc0_validate_textures(struct nvc0_context
*);
205 void nvc0_validate_samplers(struct nvc0_context
*);
207 struct pipe_sampler_view
*
208 nvc0_create_sampler_view(struct pipe_context
*,
209 struct pipe_resource
*,
210 const struct pipe_sampler_view
*);
212 /* nvc0_transfer.c */
214 nvc0_m2mf_push_linear(struct nvc0_context
*nvc0
,
215 struct nouveau_bo
*dst
, unsigned domain
, int offset
,
216 unsigned size
, void *data
);
218 nvc0_m2mf_copy_linear(struct nvc0_context
*nvc0
,
219 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
220 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
224 void nvc0_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
227 nvc0_vertex_state_create(struct pipe_context
*pipe
,
228 unsigned num_elements
,
229 const struct pipe_vertex_element
*elements
);
231 nvc0_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
233 void nvc0_vertex_arrays_validate(struct nvc0_context
*nvc0
);
236 void nvc0_push_vbo(struct nvc0_context
*, const struct pipe_draw_info
*);
237 void nvc0_push_vbo2(struct nvc0_context
*, const struct pipe_draw_info
*);