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_TARGETS (1 << 21)
54 #define NVC0_BUFCTX_CONSTANT 0
55 #define NVC0_BUFCTX_FRAME 1
56 #define NVC0_BUFCTX_VERTEX 2
57 #define NVC0_BUFCTX_TEXTURES 3
58 #define NVC0_BUFCTX_TFB 4
59 #define NVC0_BUFCTX_COUNT 5
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
;
78 boolean rasterizer_discard
;
81 uint8_t num_textures
[5];
82 uint8_t num_samplers
[5];
83 uint8_t tls_required
; /* bitmask of shader types using l[] */
84 uint8_t c14_bound
; /* whether immediate array constbuf is bound */
87 uint32_t uniform_buffer_bound
[5];
88 struct nvc0_transform_feedback_state
*tfb
;
91 struct nvc0_blend_stateobj
*blend
;
92 struct nvc0_rasterizer_stateobj
*rast
;
93 struct nvc0_zsa_stateobj
*zsa
;
94 struct nvc0_vertex_stateobj
*vertex
;
96 struct nvc0_program
*vertprog
;
97 struct nvc0_program
*tctlprog
;
98 struct nvc0_program
*tevlprog
;
99 struct nvc0_program
*gmtyprog
;
100 struct nvc0_program
*fragprog
;
102 struct pipe_resource
*constbuf
[5][16];
103 uint16_t constbuf_dirty
[5];
105 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
106 unsigned num_vtxbufs
;
107 struct pipe_index_buffer idxbuf
;
108 uint32_t vbo_fifo
; /* bitmask of vertex elements to be pushed to FIFO */
109 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
110 unsigned vbo_min_index
; /* from pipe_draw_info, for vertex upload */
111 unsigned vbo_max_index
;
113 struct pipe_sampler_view
*textures
[5][PIPE_MAX_SAMPLERS
];
114 unsigned num_textures
[5];
115 struct nv50_tsc_entry
*samplers
[5][PIPE_MAX_SAMPLERS
];
116 unsigned num_samplers
[5];
118 struct pipe_framebuffer_state framebuffer
;
119 struct pipe_blend_color blend_colour
;
120 struct pipe_stencil_ref stencil_ref
;
121 struct pipe_poly_stipple stipple
;
122 struct pipe_scissor_state scissor
;
123 struct pipe_viewport_state viewport
;
124 struct pipe_clip_state clip
;
126 unsigned sample_mask
;
128 boolean vbo_push_hint
;
130 uint8_t tfbbuf_dirty
;
131 struct pipe_stream_output_target
*tfbbuf
[4];
132 unsigned num_tfbbufs
;
134 struct draw_context
*draw
;
137 #define NVC0_USING_EDGEFLAG(ctx) \
138 ((ctx)->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)
140 static INLINE
struct nvc0_context
*
141 nvc0_context(struct pipe_context
*pipe
)
143 return (struct nvc0_context
*)pipe
;
147 struct pipe_context
*nvc0_create(struct pipe_screen
*, void *);
149 void nvc0_default_flush_notify(struct nouveau_channel
*);
151 void nvc0_bufctx_emit_relocs(struct nvc0_context
*);
152 void nvc0_bufctx_add_resident(struct nvc0_context
*, int ctx
,
153 struct nv04_resource
*, uint32_t flags
);
154 void nvc0_bufctx_del_resident(struct nvc0_context
*, int ctx
,
155 struct nv04_resource
*);
157 nvc0_bufctx_reset(struct nvc0_context
*nvc0
, int ctx
)
159 nvc0
->residents_size
-= nvc0
->residents
[ctx
].size
;
160 util_dynarray_resize(&nvc0
->residents
[ctx
], 0);
164 extern struct draw_stage
*nvc0_draw_render_stage(struct nvc0_context
*);
167 boolean
nvc0_program_translate(struct nvc0_program
*);
168 boolean
nvc0_program_upload_code(struct nvc0_context
*, struct nvc0_program
*);
169 void nvc0_program_destroy(struct nvc0_context
*, struct nvc0_program
*);
170 void nvc0_program_library_upload(struct nvc0_context
*);
173 void nvc0_init_query_functions(struct nvc0_context
*);
174 void nvc0_query_pushbuf_submit(struct nouveau_channel
*,
175 struct pipe_query
*, unsigned result_offset
);
176 void nvc0_query_fifo_wait(struct nouveau_channel
*, struct pipe_query
*);
177 void nvc0_so_target_save_offset(struct pipe_context
*,
178 struct pipe_stream_output_target
*, unsigned i
,
181 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
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
*, uint32_t state_mask
,
197 unsigned space_words
);
200 extern void nvc0_clear(struct pipe_context
*, unsigned buffers
,
201 const union pipe_color_union
*color
,
202 double depth
, unsigned stencil
);
203 extern void nvc0_init_surface_functions(struct nvc0_context
*);
206 void nvc0_validate_textures(struct nvc0_context
*);
207 void nvc0_validate_samplers(struct nvc0_context
*);
209 struct pipe_sampler_view
*
210 nvc0_create_sampler_view(struct pipe_context
*,
211 struct pipe_resource
*,
212 const struct pipe_sampler_view
*);
214 /* nvc0_transfer.c */
216 nvc0_m2mf_transfer_rect(struct pipe_screen
*pscreen
,
217 const struct nv50_m2mf_rect
*dst
,
218 const struct nv50_m2mf_rect
*src
,
219 uint32_t nblocksx
, uint32_t nblocksy
);
221 nvc0_m2mf_push_linear(struct nouveau_context
*nv
,
222 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
223 unsigned size
, const void *data
);
225 nvc0_m2mf_copy_linear(struct nouveau_context
*nv
,
226 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
227 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
230 nvc0_cb_push(struct nouveau_context
*,
231 struct nouveau_bo
*bo
, unsigned domain
,
232 unsigned base
, unsigned size
,
233 unsigned offset
, unsigned words
, const uint32_t *data
);
236 void nvc0_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
239 nvc0_vertex_state_create(struct pipe_context
*pipe
,
240 unsigned num_elements
,
241 const struct pipe_vertex_element
*elements
);
243 nvc0_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
245 void nvc0_vertex_arrays_validate(struct nvc0_context
*nvc0
);
248 void nvc0_push_vbo(struct nvc0_context
*, const struct pipe_draw_info
*);
249 void nvc0_push_vbo2(struct nvc0_context
*, const struct pipe_draw_info
*);