1 #ifndef __NVC0_CONTEXT_H__
2 #define __NVC0_CONTEXT_H__
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
8 #include "util/u_memory.h"
9 #include "util/u_math.h"
10 #include "util/u_inlines.h"
11 #include "util/u_dynarray.h"
13 #include "draw/draw_vertex.h"
15 #include "nv50/nv50_debug.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 "nv50/nv50_transfer.h"
24 #include "nouveau/nouveau_context.h"
26 #include "nvc0_3ddefs.xml.h"
27 #include "nvc0_3d.xml.h"
28 #include "nvc0_2d.xml.h"
29 #include "nvc0_m2mf.xml.h"
31 #define NVC0_NEW_BLEND (1 << 0)
32 #define NVC0_NEW_RASTERIZER (1 << 1)
33 #define NVC0_NEW_ZSA (1 << 2)
34 #define NVC0_NEW_VERTPROG (1 << 3)
35 #define NVC0_NEW_TCTLPROG (1 << 4)
36 #define NVC0_NEW_TEVLPROG (1 << 5)
37 #define NVC0_NEW_GMTYPROG (1 << 6)
38 #define NVC0_NEW_FRAGPROG (1 << 7)
39 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
40 #define NVC0_NEW_STENCIL_REF (1 << 9)
41 #define NVC0_NEW_CLIP (1 << 10)
42 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
43 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
44 #define NVC0_NEW_STIPPLE (1 << 13)
45 #define NVC0_NEW_SCISSOR (1 << 14)
46 #define NVC0_NEW_VIEWPORT (1 << 15)
47 #define NVC0_NEW_ARRAYS (1 << 16)
48 #define NVC0_NEW_VERTEX (1 << 17)
49 #define NVC0_NEW_CONSTBUF (1 << 18)
50 #define NVC0_NEW_TEXTURES (1 << 19)
51 #define NVC0_NEW_SAMPLERS (1 << 20)
52 #define NVC0_NEW_TFB (1 << 21)
53 #define NVC0_NEW_TFB_BUFFERS (1 << 22)
55 #define NVC0_BUFCTX_CONSTANT 0
56 #define NVC0_BUFCTX_FRAME 1
57 #define NVC0_BUFCTX_VERTEX 2
58 #define NVC0_BUFCTX_TEXTURES 3
59 #define NVC0_BUFCTX_COUNT 4
62 struct nouveau_context base
;
64 struct nvc0_screen
*screen
;
66 struct util_dynarray residents
[NVC0_BUFCTX_COUNT
];
67 unsigned residents_size
;
72 uint32_t instance_elts
; /* bitmask of per-instance elements */
73 uint32_t instance_base
;
79 uint8_t num_textures
[5];
80 uint8_t num_samplers
[5];
81 uint8_t tls_required
; /* bitmask of shader types using l[] */
82 uint8_t c14_bound
; /* whether immediate array constbuf is bound */
84 uint32_t uniform_buffer_bound
[5];
87 struct nvc0_blend_stateobj
*blend
;
88 struct nvc0_rasterizer_stateobj
*rast
;
89 struct nvc0_zsa_stateobj
*zsa
;
90 struct nvc0_vertex_stateobj
*vertex
;
92 struct nvc0_program
*vertprog
;
93 struct nvc0_program
*tctlprog
;
94 struct nvc0_program
*tevlprog
;
95 struct nvc0_program
*gmtyprog
;
96 struct nvc0_program
*fragprog
;
98 struct pipe_resource
*constbuf
[5][16];
99 uint16_t constbuf_dirty
[5];
101 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
102 unsigned num_vtxbufs
;
103 struct pipe_index_buffer idxbuf
;
104 uint32_t vbo_fifo
; /* bitmask of vertex elements to be pushed to FIFO */
105 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
106 unsigned vbo_min_index
; /* from pipe_draw_info, for vertex upload */
107 unsigned vbo_max_index
;
109 struct pipe_sampler_view
*textures
[5][PIPE_MAX_SAMPLERS
];
110 unsigned num_textures
[5];
111 struct nv50_tsc_entry
*samplers
[5][PIPE_MAX_SAMPLERS
];
112 unsigned num_samplers
[5];
114 struct pipe_framebuffer_state framebuffer
;
115 struct pipe_blend_color blend_colour
;
116 struct pipe_stencil_ref stencil_ref
;
117 struct pipe_poly_stipple stipple
;
118 struct pipe_scissor_state scissor
;
119 struct pipe_viewport_state viewport
;
120 struct pipe_clip_state clip
;
122 unsigned sample_mask
;
124 boolean vbo_push_hint
;
126 struct nvc0_transform_feedback_state
*tfb
;
127 struct pipe_resource
*tfbbuf
[4];
128 unsigned num_tfbbufs
;
129 unsigned tfb_offset
[4];
131 struct draw_context
*draw
;
134 #define NVC0_USING_EDGEFLAG(ctx) \
135 ((ctx)->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)
137 static INLINE
struct nvc0_context
*
138 nvc0_context(struct pipe_context
*pipe
)
140 return (struct nvc0_context
*)pipe
;
144 struct pipe_context
*nvc0_create(struct pipe_screen
*, void *);
146 void nvc0_default_flush_notify(struct nouveau_channel
*);
148 void nvc0_bufctx_emit_relocs(struct nvc0_context
*);
149 void nvc0_bufctx_add_resident(struct nvc0_context
*, int ctx
,
150 struct nv04_resource
*, uint32_t flags
);
151 void nvc0_bufctx_del_resident(struct nvc0_context
*, int ctx
,
152 struct nv04_resource
*);
154 nvc0_bufctx_reset(struct nvc0_context
*nvc0
, int ctx
)
156 nvc0
->residents_size
-= nvc0
->residents
[ctx
].size
;
157 util_dynarray_resize(&nvc0
->residents
[ctx
], 0);
161 extern struct draw_stage
*nvc0_draw_render_stage(struct nvc0_context
*);
164 boolean
nvc0_program_translate(struct nvc0_program
*);
165 boolean
nvc0_program_upload_code(struct nvc0_context
*, struct nvc0_program
*);
166 void nvc0_program_destroy(struct nvc0_context
*, struct nvc0_program
*);
167 void nvc0_program_library_upload(struct nvc0_context
*);
170 void nvc0_init_query_functions(struct nvc0_context
*);
172 /* nvc0_shader_state.c */
173 void nvc0_vertprog_validate(struct nvc0_context
*);
174 void nvc0_tctlprog_validate(struct nvc0_context
*);
175 void nvc0_tevlprog_validate(struct nvc0_context
*);
176 void nvc0_gmtyprog_validate(struct nvc0_context
*);
177 void nvc0_fragprog_validate(struct nvc0_context
*);
179 void nvc0_tfb_validate(struct nvc0_context
*);
182 extern void nvc0_init_state_functions(struct nvc0_context
*);
184 /* nvc0_state_validate.c */
185 extern boolean
nvc0_state_validate(struct nvc0_context
*, uint32_t state_mask
,
186 unsigned space_words
);
189 extern void nvc0_clear(struct pipe_context
*, unsigned buffers
,
190 const union pipe_color_union
*color
,
191 double depth
, unsigned stencil
);
192 extern void nvc0_init_surface_functions(struct nvc0_context
*);
195 void nvc0_validate_textures(struct nvc0_context
*);
196 void nvc0_validate_samplers(struct nvc0_context
*);
198 struct pipe_sampler_view
*
199 nvc0_create_sampler_view(struct pipe_context
*,
200 struct pipe_resource
*,
201 const struct pipe_sampler_view
*);
203 /* nvc0_transfer.c */
205 nvc0_m2mf_transfer_rect(struct pipe_screen
*pscreen
,
206 const struct nv50_m2mf_rect
*dst
,
207 const struct nv50_m2mf_rect
*src
,
208 uint32_t nblocksx
, uint32_t nblocksy
);
210 nvc0_m2mf_push_linear(struct nouveau_context
*nv
,
211 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
212 unsigned size
, const void *data
);
214 nvc0_m2mf_copy_linear(struct nouveau_context
*nv
,
215 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
216 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
220 void nvc0_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
223 nvc0_vertex_state_create(struct pipe_context
*pipe
,
224 unsigned num_elements
,
225 const struct pipe_vertex_element
*elements
);
227 nvc0_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
229 void nvc0_vertex_arrays_validate(struct nvc0_context
*nvc0
);
232 void nvc0_push_vbo(struct nvc0_context
*, const struct pipe_draw_info
*);
233 void nvc0_push_vbo2(struct nvc0_context
*, const struct pipe_draw_info
*);