1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_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 "nv50/nv50_winsys.h"
14 #include "nv50/nv50_stateobj.h"
15 #include "nv50/nv50_screen.h"
16 #include "nv50/nv50_program.h"
17 #include "nv50/nv50_resource.h"
18 #include "nv50/nv50_transfer.h"
19 #include "nv50/nv50_query.h"
21 #include "nouveau_context.h"
22 #include "nouveau_debug.h"
23 #include "nv_object.xml.h"
24 #include "nv_m2mf.xml.h"
25 #include "nv50/nv50_3ddefs.xml.h"
26 #include "nv50/nv50_3d.xml.h"
27 #include "nv50/nv50_2d.xml.h"
29 #define NV50_NEW_3D_BLEND (1 << 0)
30 #define NV50_NEW_3D_RASTERIZER (1 << 1)
31 #define NV50_NEW_3D_ZSA (1 << 2)
32 #define NV50_NEW_3D_VERTPROG (1 << 3)
33 #define NV50_NEW_3D_GMTYPROG (1 << 6)
34 #define NV50_NEW_3D_FRAGPROG (1 << 7)
35 #define NV50_NEW_3D_BLEND_COLOUR (1 << 8)
36 #define NV50_NEW_3D_STENCIL_REF (1 << 9)
37 #define NV50_NEW_3D_CLIP (1 << 10)
38 #define NV50_NEW_3D_SAMPLE_MASK (1 << 11)
39 #define NV50_NEW_3D_FRAMEBUFFER (1 << 12)
40 #define NV50_NEW_3D_STIPPLE (1 << 13)
41 #define NV50_NEW_3D_SCISSOR (1 << 14)
42 #define NV50_NEW_3D_VIEWPORT (1 << 15)
43 #define NV50_NEW_3D_ARRAYS (1 << 16)
44 #define NV50_NEW_3D_VERTEX (1 << 17)
45 #define NV50_NEW_3D_CONSTBUF (1 << 18)
46 #define NV50_NEW_3D_TEXTURES (1 << 19)
47 #define NV50_NEW_3D_SAMPLERS (1 << 20)
48 #define NV50_NEW_3D_STRMOUT (1 << 21)
49 #define NV50_NEW_3D_MIN_SAMPLES (1 << 22)
50 #define NV50_NEW_3D_WINDOW_RECTS (1 << 23)
51 #define NV50_NEW_3D_CONTEXT (1 << 31)
53 #define NV50_NEW_CP_PROGRAM (1 << 0)
54 #define NV50_NEW_CP_GLOBALS (1 << 1)
56 /* 3d bufctx (during draw_vbo, blit_3d) */
57 #define NV50_BIND_3D_FB 0
58 #define NV50_BIND_3D_VERTEX 1
59 #define NV50_BIND_3D_VERTEX_TMP 2
60 #define NV50_BIND_3D_INDEX 3
61 #define NV50_BIND_3D_TEXTURES 4
62 #define NV50_BIND_3D_CB(s, i) (5 + 16 * (s) + (i))
63 #define NV50_BIND_3D_SO 53
64 #define NV50_BIND_3D_SCREEN 54
65 #define NV50_BIND_3D_TLS 55
66 #define NV50_BIND_3D_COUNT 56
68 /* compute bufctx (during launch_grid) */
69 #define NV50_BIND_CP_GLOBAL 0
70 #define NV50_BIND_CP_SCREEN 1
71 #define NV50_BIND_CP_QUERY 2
72 #define NV50_BIND_CP_COUNT 3
74 /* bufctx for other operations */
75 #define NV50_BIND_2D 0
76 #define NV50_BIND_M2MF 0
77 #define NV50_BIND_FENCE 1
79 #define NV50_CB_TMP 123
80 /* fixed constant buffer binding points - low indices for user's constbufs */
81 #define NV50_CB_PVP 124
82 #define NV50_CB_PGP 126
83 #define NV50_CB_PFP 125
84 /* constant buffer permanently mapped in as c15[] */
85 #define NV50_CB_AUX 127
86 /* size of the buffer: 64k. not all taken up, can be reduced if needed. */
87 #define NV50_CB_AUX_SIZE (1 << 16)
88 /* 8 user clip planes, at 4 32-bit floats each */
89 #define NV50_CB_AUX_UCP_OFFSET 0x0000
90 #define NV50_CB_AUX_UCP_SIZE (8 * 4 * 4)
91 /* 16 textures * 3 shaders, each with ms_x, ms_y u32 pairs */
92 #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080
93 #define NV50_CB_AUX_TEX_MS_SIZE (16 * 3 * 2 * 4)
94 /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */
95 #define NV50_CB_AUX_MS_OFFSET 0x200
96 #define NV50_CB_AUX_MS_SIZE (4 * 8 * 4 * 2)
97 /* Sample position pairs for the current output MS level */
98 #define NV50_CB_AUX_SAMPLE_OFFSET 0x300
99 #define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)
100 /* Alpha test ref value */
101 #define NV50_CB_AUX_ALPHATEST_OFFSET 0x340
102 #define NV50_CB_AUX_ALPHATEST_SIZE (4)
103 /* next spot: 0x344 */
104 /* 4 32-bit floats for the vertex runout, put at the end */
105 #define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)
111 bool nv50_blitctx_create(struct nv50_context
*);
113 struct nv50_context
{
114 struct nouveau_context base
;
116 struct nv50_screen
*screen
;
118 struct nouveau_bufctx
*bufctx_3d
;
119 struct nouveau_bufctx
*bufctx
;
120 struct nouveau_bufctx
*bufctx_cp
;
122 uint32_t dirty_3d
; /* dirty flags for 3d state */
123 uint32_t dirty_cp
; /* dirty flags for compute state */
126 struct nv50_graph_state state
;
128 struct nv50_blend_stateobj
*blend
;
129 struct nv50_rasterizer_stateobj
*rast
;
130 struct nv50_zsa_stateobj
*zsa
;
131 struct nv50_vertex_stateobj
*vertex
;
133 struct nv50_program
*vertprog
;
134 struct nv50_program
*gmtyprog
;
135 struct nv50_program
*fragprog
;
136 struct nv50_program
*compprog
;
138 struct nv50_constbuf constbuf
[3][NV50_MAX_PIPE_CONSTBUFS
];
139 uint16_t constbuf_dirty
[3];
140 uint16_t constbuf_valid
[3];
141 uint16_t constbuf_coherent
[3];
143 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
144 unsigned num_vtxbufs
;
145 uint32_t vtxbufs_coherent
;
146 uint32_t vbo_fifo
; /* bitmask of vertex elements to be pushed to FIFO */
147 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
148 uint32_t vbo_constant
; /* bitmask of user buffers with stride 0 */
149 uint32_t vb_elt_first
; /* from pipe_draw_info, for vertex upload */
150 uint32_t vb_elt_limit
; /* max - min element (count - 1) */
151 uint32_t instance_off
; /* base vertex for instanced arrays */
152 uint32_t instance_max
; /* max instance for current draw call */
154 struct pipe_sampler_view
*textures
[3][PIPE_MAX_SAMPLERS
];
155 unsigned num_textures
[3];
156 uint32_t textures_coherent
[3];
157 struct nv50_tsc_entry
*samplers
[3][PIPE_MAX_SAMPLERS
];
158 unsigned num_samplers
[3];
159 bool seamless_cube_map
;
161 uint8_t num_so_targets
;
162 uint8_t so_targets_dirty
;
163 struct pipe_stream_output_target
*so_target
[4];
165 struct pipe_framebuffer_state framebuffer
;
166 struct pipe_blend_color blend_colour
;
167 struct pipe_stencil_ref stencil_ref
;
168 struct pipe_poly_stipple stipple
;
169 struct pipe_scissor_state scissors
[NV50_MAX_VIEWPORTS
];
170 unsigned scissors_dirty
;
171 struct pipe_viewport_state viewports
[NV50_MAX_VIEWPORTS
];
172 unsigned viewports_dirty
;
173 struct pipe_clip_state clip
;
174 struct nv50_window_rect_stateobj window_rect
;
176 unsigned sample_mask
;
177 unsigned min_samples
;
181 uint32_t rt_array_mode
;
183 struct pipe_query
*cond_query
;
184 bool cond_cond
; /* inverted rendering condition */
186 uint32_t cond_condmode
; /* the calculated condition */
188 struct nv50_blitctx
*blit
;
190 struct util_dynarray global_residents
;
193 static inline struct nv50_context
*
194 nv50_context(struct pipe_context
*pipe
)
196 return (struct nv50_context
*)pipe
;
199 /* return index used in nv50_context arrays for a specific shader type */
200 static inline unsigned
201 nv50_context_shader_stage(unsigned pipe
)
204 case PIPE_SHADER_VERTEX
: return 0;
205 case PIPE_SHADER_FRAGMENT
: return 1;
206 case PIPE_SHADER_GEOMETRY
: return 2;
207 case PIPE_SHADER_COMPUTE
: return 3;
209 assert(!"invalid/unhandled shader type");
215 struct pipe_context
*nv50_create(struct pipe_screen
*, void *, unsigned flags
);
217 void nv50_bufctx_fence(struct nouveau_bufctx
*, bool on_flush
);
219 void nv50_default_kick_notify(struct nouveau_pushbuf
*);
222 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*);
224 /* nv50_shader_state.c */
225 void nv50_vertprog_validate(struct nv50_context
*);
226 void nv50_gmtyprog_validate(struct nv50_context
*);
227 void nv50_fragprog_validate(struct nv50_context
*);
228 void nv50_compprog_validate(struct nv50_context
*);
229 void nv50_fp_linkage_validate(struct nv50_context
*);
230 void nv50_gp_linkage_validate(struct nv50_context
*);
231 void nv50_constbufs_validate(struct nv50_context
*);
232 void nv50_validate_derived_rs(struct nv50_context
*);
233 void nv50_stream_output_validate(struct nv50_context
*);
236 extern void nv50_init_state_functions(struct nv50_context
*);
238 /* nv50_state_validate.c */
239 struct nv50_state_validate
{
240 void (*func
)(struct nv50_context
*);
244 bool nv50_state_validate(struct nv50_context
*, uint32_t,
245 struct nv50_state_validate
*, int, uint32_t *,
246 struct nouveau_bufctx
*);
247 bool nv50_state_validate_3d(struct nv50_context
*, uint32_t);
250 extern void nv50_clear(struct pipe_context
*, unsigned buffers
,
251 const union pipe_color_union
*color
,
252 double depth
, unsigned stencil
);
253 extern void nv50_init_surface_functions(struct nv50_context
*);
256 void nv50_validate_textures(struct nv50_context
*);
257 void nv50_validate_samplers(struct nv50_context
*);
258 void nv50_upload_ms_info(struct nouveau_pushbuf
*);
259 void nv50_upload_tsc0(struct nv50_context
*);
261 struct pipe_sampler_view
*
262 nv50_create_texture_view(struct pipe_context
*,
263 struct pipe_resource
*,
264 const struct pipe_sampler_view
*,
266 enum pipe_texture_target
);
267 struct pipe_sampler_view
*
268 nv50_create_sampler_view(struct pipe_context
*,
269 struct pipe_resource
*,
270 const struct pipe_sampler_view
*);
272 /* nv50_transfer.c */
274 nv50_m2mf_transfer_rect(struct nv50_context
*,
275 const struct nv50_m2mf_rect
*dst
,
276 const struct nv50_m2mf_rect
*src
,
277 uint32_t nblocksx
, uint32_t nblocksy
);
279 nv50_sifc_linear_u8(struct nouveau_context
*pipe
,
280 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
281 unsigned size
, const void *data
);
283 nv50_m2mf_copy_linear(struct nouveau_context
*pipe
,
284 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
285 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
288 nv50_cb_push(struct nouveau_context
*nv
,
289 struct nv04_resource
*res
,
290 unsigned offset
, unsigned words
, const uint32_t *data
);
293 void nv50_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
296 nv50_vertex_state_create(struct pipe_context
*pipe
,
297 unsigned num_elements
,
298 const struct pipe_vertex_element
*elements
);
300 nv50_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
302 void nv50_vertex_arrays_validate(struct nv50_context
*nv50
);
305 void nv50_push_vbo(struct nv50_context
*, const struct pipe_draw_info
*);
308 struct pipe_video_codec
*
309 nv84_create_decoder(struct pipe_context
*context
,
310 const struct pipe_video_codec
*templ
);
312 struct pipe_video_buffer
*
313 nv84_video_buffer_create(struct pipe_context
*pipe
,
314 const struct pipe_video_buffer
*template);
317 nv84_screen_get_video_param(struct pipe_screen
*pscreen
,
318 enum pipe_video_profile profile
,
319 enum pipe_video_entrypoint entrypoint
,
320 enum pipe_video_cap param
);
323 nv84_screen_video_supported(struct pipe_screen
*screen
,
324 enum pipe_format format
,
325 enum pipe_video_profile profile
,
326 enum pipe_video_entrypoint entrypoint
);
329 struct pipe_video_codec
*
330 nv98_create_decoder(struct pipe_context
*context
,
331 const struct pipe_video_codec
*templ
);
333 struct pipe_video_buffer
*
334 nv98_video_buffer_create(struct pipe_context
*pipe
,
335 const struct pipe_video_buffer
*template);
339 nv50_launch_grid(struct pipe_context
*, const struct pipe_grid_info
*);