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 #ifdef NVC0_WITH_DRAW_MODULE
14 #include "draw/draw_vertex.h"
17 #include "nv50/nv50_debug.h"
18 #include "nvc0_winsys.h"
19 #include "nvc0_stateobj.h"
20 #include "nvc0_screen.h"
21 #include "nvc0_program.h"
22 #include "nvc0_resource.h"
24 #include "nv50/nv50_transfer.h"
26 #include "nouveau/nouveau_context.h"
28 #include "nvc0_3ddefs.xml.h"
29 #include "nvc0_3d.xml.h"
30 #include "nvc0_2d.xml.h"
31 #include "nvc0_m2mf.xml.h"
32 #include "nve4_p2mf.xml.h"
34 /* NOTE: must keep NVC0_NEW_...PROG in consecutive bits in this order */
35 #define NVC0_NEW_BLEND (1 << 0)
36 #define NVC0_NEW_RASTERIZER (1 << 1)
37 #define NVC0_NEW_ZSA (1 << 2)
38 #define NVC0_NEW_VERTPROG (1 << 3)
39 #define NVC0_NEW_TCTLPROG (1 << 4)
40 #define NVC0_NEW_TEVLPROG (1 << 5)
41 #define NVC0_NEW_GMTYPROG (1 << 6)
42 #define NVC0_NEW_FRAGPROG (1 << 7)
43 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
44 #define NVC0_NEW_STENCIL_REF (1 << 9)
45 #define NVC0_NEW_CLIP (1 << 10)
46 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
47 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
48 #define NVC0_NEW_STIPPLE (1 << 13)
49 #define NVC0_NEW_SCISSOR (1 << 14)
50 #define NVC0_NEW_VIEWPORT (1 << 15)
51 #define NVC0_NEW_ARRAYS (1 << 16)
52 #define NVC0_NEW_VERTEX (1 << 17)
53 #define NVC0_NEW_CONSTBUF (1 << 18)
54 #define NVC0_NEW_TEXTURES (1 << 19)
55 #define NVC0_NEW_SAMPLERS (1 << 20)
56 #define NVC0_NEW_TFB_TARGETS (1 << 21)
57 #define NVC0_NEW_IDXBUF (1 << 22)
59 #define NVC0_BIND_FB 0
60 #define NVC0_BIND_VTX 1
61 #define NVC0_BIND_VTX_TMP 2
62 #define NVC0_BIND_IDX 3
63 #define NVC0_BIND_TEX(s, i) ( 4 + 32 * (s) + (i))
64 #define NVC0_BIND_CB(s, i) (164 + 16 * (s) + (i))
65 #define NVC0_BIND_TFB 244
66 #define NVC0_BIND_SCREEN 245
67 #define NVC0_BIND_TLS 246
68 #define NVC0_BIND_COUNT 247
70 #define NVC0_BIND_2D 0
71 #define NVC0_BIND_M2MF 0
72 #define NVC0_BIND_FENCE 1
77 boolean
nvc0_blitctx_create(struct nvc0_context
*);
80 struct nouveau_context base
;
82 struct nouveau_bufctx
*bufctx_3d
;
83 struct nouveau_bufctx
*bufctx
;
85 struct nvc0_screen
*screen
;
87 void (*m2mf_copy_rect
)(struct nvc0_context
*,
88 const struct nv50_m2mf_rect
*dst
,
89 const struct nv50_m2mf_rect
*src
,
90 uint32_t nblocksx
, uint32_t nblocksy
);
96 boolean rasterizer_discard
;
97 boolean early_z_forced
;
99 uint32_t instance_elts
; /* bitmask of per-instance elements */
100 uint32_t instance_base
;
101 uint32_t constant_vbos
;
102 uint32_t constant_elts
;
105 uint8_t vbo_mode
; /* 0 = normal, 1 = translate, 3 = translate, forced */
108 uint8_t num_textures
[5];
109 uint8_t num_samplers
[5];
110 uint8_t tls_required
; /* bitmask of shader types using l[] */
111 uint8_t c14_bound
; /* whether immediate array constbuf is bound */
114 uint32_t uniform_buffer_bound
[5];
115 struct nvc0_transform_feedback_state
*tfb
;
118 struct nvc0_blend_stateobj
*blend
;
119 struct nvc0_rasterizer_stateobj
*rast
;
120 struct nvc0_zsa_stateobj
*zsa
;
121 struct nvc0_vertex_stateobj
*vertex
;
123 struct nvc0_program
*vertprog
;
124 struct nvc0_program
*tctlprog
;
125 struct nvc0_program
*tevlprog
;
126 struct nvc0_program
*gmtyprog
;
127 struct nvc0_program
*fragprog
;
129 struct nvc0_constbuf constbuf
[5][NVC0_MAX_PIPE_CONSTBUFS
];
130 uint16_t constbuf_dirty
[5];
132 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
133 unsigned num_vtxbufs
;
134 struct pipe_index_buffer idxbuf
;
135 uint32_t constant_vbos
;
136 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
137 uint32_t vb_elt_first
; /* from pipe_draw_info, for vertex upload */
138 uint32_t vb_elt_limit
; /* max - min element (count - 1) */
139 uint32_t instance_off
; /* current base vertex for instanced arrays */
140 uint32_t instance_max
; /* last instance for current draw call */
142 struct pipe_sampler_view
*textures
[5][PIPE_MAX_SAMPLERS
];
143 unsigned num_textures
[5];
144 uint32_t textures_dirty
[5];
145 struct nv50_tsc_entry
*samplers
[5][PIPE_MAX_SAMPLERS
];
146 unsigned num_samplers
[5];
147 uint16_t samplers_dirty
[5];
149 uint32_t tex_handles
[5][PIPE_MAX_SAMPLERS
]; /* for nve4 */
151 struct pipe_framebuffer_state framebuffer
;
152 struct pipe_blend_color blend_colour
;
153 struct pipe_stencil_ref stencil_ref
;
154 struct pipe_poly_stipple stipple
;
155 struct pipe_scissor_state scissor
;
156 struct pipe_viewport_state viewport
;
157 struct pipe_clip_state clip
;
159 unsigned sample_mask
;
161 boolean vbo_push_hint
;
163 uint8_t tfbbuf_dirty
;
164 struct pipe_stream_output_target
*tfbbuf
[4];
165 unsigned num_tfbbufs
;
167 struct pipe_query
*cond_query
;
170 struct nvc0_blitctx
*blit
;
172 #ifdef NVC0_WITH_DRAW_MODULE
173 struct draw_context
*draw
;
177 static INLINE
struct nvc0_context
*
178 nvc0_context(struct pipe_context
*pipe
)
180 return (struct nvc0_context
*)pipe
;
183 static INLINE
unsigned
184 nvc0_shader_stage(unsigned pipe
)
187 case PIPE_SHADER_VERTEX
: return 0;
188 /* case PIPE_SHADER_TESSELLATION_CONTROL: return 1; */
189 /* case PIPE_SHADER_TESSELLATION_EVALUATION: return 2; */
190 case PIPE_SHADER_GEOMETRY
: return 3;
191 case PIPE_SHADER_FRAGMENT
: return 4;
192 case PIPE_SHADER_COMPUTE
: return 5;
194 assert(!"invalid PIPE_SHADER type");
201 struct pipe_context
*nvc0_create(struct pipe_screen
*, void *);
202 void nvc0_bufctx_fence(struct nvc0_context
*, struct nouveau_bufctx
*,
204 void nvc0_default_kick_notify(struct nouveau_pushbuf
*);
207 extern struct draw_stage
*nvc0_draw_render_stage(struct nvc0_context
*);
210 boolean
nvc0_program_translate(struct nvc0_program
*, uint16_t chipset
);
211 boolean
nvc0_program_upload_code(struct nvc0_context
*, struct nvc0_program
*);
212 void nvc0_program_destroy(struct nvc0_context
*, struct nvc0_program
*);
213 void nvc0_program_library_upload(struct nvc0_context
*);
216 void nvc0_init_query_functions(struct nvc0_context
*);
217 void nvc0_query_pushbuf_submit(struct nouveau_pushbuf
*,
218 struct pipe_query
*, unsigned result_offset
);
219 void nvc0_query_fifo_wait(struct nouveau_pushbuf
*, struct pipe_query
*);
220 void nvc0_so_target_save_offset(struct pipe_context
*,
221 struct pipe_stream_output_target
*, unsigned i
,
224 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
226 /* nvc0_shader_state.c */
227 void nvc0_vertprog_validate(struct nvc0_context
*);
228 void nvc0_tctlprog_validate(struct nvc0_context
*);
229 void nvc0_tevlprog_validate(struct nvc0_context
*);
230 void nvc0_gmtyprog_validate(struct nvc0_context
*);
231 void nvc0_fragprog_validate(struct nvc0_context
*);
233 void nvc0_tfb_validate(struct nvc0_context
*);
236 extern void nvc0_init_state_functions(struct nvc0_context
*);
238 /* nvc0_state_validate.c */
239 extern boolean
nvc0_state_validate(struct nvc0_context
*, uint32_t state_mask
,
240 unsigned space_words
);
243 extern void nvc0_clear(struct pipe_context
*, unsigned buffers
,
244 const union pipe_color_union
*color
,
245 double depth
, unsigned stencil
);
246 extern void nvc0_init_surface_functions(struct nvc0_context
*);
249 void nvc0_validate_textures(struct nvc0_context
*);
250 void nvc0_validate_samplers(struct nvc0_context
*);
251 void nve4_set_tex_handles(struct nvc0_context
*);
253 struct pipe_sampler_view
*
254 nvc0_create_texture_view(struct pipe_context
*,
255 struct pipe_resource
*,
256 const struct pipe_sampler_view
*,
258 enum pipe_texture_target
);
259 struct pipe_sampler_view
*
260 nvc0_create_sampler_view(struct pipe_context
*,
261 struct pipe_resource
*,
262 const struct pipe_sampler_view
*);
264 /* nvc0_transfer.c */
266 nvc0_init_transfer_functions(struct nvc0_context
*);
269 nvc0_m2mf_push_linear(struct nouveau_context
*nv
,
270 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
271 unsigned size
, const void *data
);
273 nve4_p2mf_push_linear(struct nouveau_context
*nv
,
274 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
275 unsigned size
, const void *data
);
277 nvc0_cb_push(struct nouveau_context
*,
278 struct nouveau_bo
*bo
, unsigned domain
,
279 unsigned base
, unsigned size
,
280 unsigned offset
, unsigned words
, const uint32_t *data
);
283 void nvc0_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
286 nvc0_vertex_state_create(struct pipe_context
*pipe
,
287 unsigned num_elements
,
288 const struct pipe_vertex_element
*elements
);
290 nvc0_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
292 void nvc0_vertex_arrays_validate(struct nvc0_context
*);
294 void nvc0_idxbuf_validate(struct nvc0_context
*);
297 void nvc0_push_vbo(struct nvc0_context
*, const struct pipe_draw_info
*);