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_CONTEXT (1 << 31)
52 #define NV50_NEW_CP_PROGRAM (1 << 0)
53 #define NV50_NEW_CP_GLOBALS (1 << 1)
55 /* 3d bufctx (during draw_vbo, blit_3d) */
56 #define NV50_BIND_3D_FB 0
57 #define NV50_BIND_3D_VERTEX 1
58 #define NV50_BIND_3D_VERTEX_TMP 2
59 #define NV50_BIND_3D_INDEX 3
60 #define NV50_BIND_3D_TEXTURES 4
61 #define NV50_BIND_3D_CB(s, i) (5 + 16 * (s) + (i))
62 #define NV50_BIND_3D_SO 53
63 #define NV50_BIND_3D_SCREEN 54
64 #define NV50_BIND_3D_TLS 55
65 #define NV50_BIND_3D_COUNT 56
67 /* compute bufctx (during launch_grid) */
68 #define NV50_BIND_CP_GLOBAL 0
69 #define NV50_BIND_CP_SCREEN 1
70 #define NV50_BIND_CP_QUERY 2
71 #define NV50_BIND_CP_COUNT 3
73 /* bufctx for other operations */
74 #define NV50_BIND_2D 0
75 #define NV50_BIND_M2MF 0
76 #define NV50_BIND_FENCE 1
78 #define NV50_CB_TMP 123
79 /* fixed constant buffer binding points - low indices for user's constbufs */
80 #define NV50_CB_PVP 124
81 #define NV50_CB_PGP 126
82 #define NV50_CB_PFP 125
83 /* constant buffer permanently mapped in as c15[] */
84 #define NV50_CB_AUX 127
85 /* size of the buffer: 64k. not all taken up, can be reduced if needed. */
86 #define NV50_CB_AUX_SIZE (1 << 16)
87 /* 8 user clip planes, at 4 32-bit floats each */
88 #define NV50_CB_AUX_UCP_OFFSET 0x0000
89 #define NV50_CB_AUX_UCP_SIZE (8 * 4 * 4)
90 /* 16 textures * 3 shaders, each with ms_x, ms_y u32 pairs */
91 #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080
92 #define NV50_CB_AUX_TEX_MS_SIZE (16 * 3 * 2 * 4)
93 /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */
94 #define NV50_CB_AUX_MS_OFFSET 0x200
95 #define NV50_CB_AUX_MS_SIZE (4 * 8 * 4 * 2)
96 /* Sample position pairs for the current output MS level */
97 #define NV50_CB_AUX_SAMPLE_OFFSET 0x300
98 #define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)
99 /* next spot: 0x340 */
100 /* 4 32-bit floats for the vertex runout, put at the end */
101 #define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)
107 bool nv50_blitctx_create(struct nv50_context
*);
109 struct nv50_context
{
110 struct nouveau_context base
;
112 struct nv50_screen
*screen
;
114 struct nouveau_bufctx
*bufctx_3d
;
115 struct nouveau_bufctx
*bufctx
;
116 struct nouveau_bufctx
*bufctx_cp
;
118 uint32_t dirty_3d
; /* dirty flags for 3d state */
119 uint32_t dirty_cp
; /* dirty flags for compute state */
122 struct nv50_graph_state state
;
124 struct nv50_blend_stateobj
*blend
;
125 struct nv50_rasterizer_stateobj
*rast
;
126 struct nv50_zsa_stateobj
*zsa
;
127 struct nv50_vertex_stateobj
*vertex
;
129 struct nv50_program
*vertprog
;
130 struct nv50_program
*gmtyprog
;
131 struct nv50_program
*fragprog
;
132 struct nv50_program
*compprog
;
134 struct nv50_constbuf constbuf
[3][NV50_MAX_PIPE_CONSTBUFS
];
135 uint16_t constbuf_dirty
[3];
136 uint16_t constbuf_valid
[3];
137 uint16_t constbuf_coherent
[3];
139 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
140 unsigned num_vtxbufs
;
141 uint32_t vtxbufs_coherent
;
142 struct pipe_index_buffer idxbuf
;
143 uint32_t vbo_fifo
; /* bitmask of vertex elements to be pushed to FIFO */
144 uint32_t vbo_user
; /* bitmask of vertex buffers pointing to user memory */
145 uint32_t vbo_constant
; /* bitmask of user buffers with stride 0 */
146 uint32_t vb_elt_first
; /* from pipe_draw_info, for vertex upload */
147 uint32_t vb_elt_limit
; /* max - min element (count - 1) */
148 uint32_t instance_off
; /* base vertex for instanced arrays */
149 uint32_t instance_max
; /* max instance for current draw call */
151 struct pipe_sampler_view
*textures
[3][PIPE_MAX_SAMPLERS
];
152 unsigned num_textures
[3];
153 uint32_t textures_coherent
[3];
154 struct nv50_tsc_entry
*samplers
[3][PIPE_MAX_SAMPLERS
];
155 unsigned num_samplers
[3];
156 bool seamless_cube_map
;
158 uint8_t num_so_targets
;
159 uint8_t so_targets_dirty
;
160 struct pipe_stream_output_target
*so_target
[4];
162 struct pipe_framebuffer_state framebuffer
;
163 struct pipe_blend_color blend_colour
;
164 struct pipe_stencil_ref stencil_ref
;
165 struct pipe_poly_stipple stipple
;
166 struct pipe_scissor_state scissors
[NV50_MAX_VIEWPORTS
];
167 unsigned scissors_dirty
;
168 struct pipe_viewport_state viewports
[NV50_MAX_VIEWPORTS
];
169 unsigned viewports_dirty
;
170 struct pipe_clip_state clip
;
172 unsigned sample_mask
;
173 unsigned min_samples
;
177 uint32_t rt_array_mode
;
179 struct pipe_query
*cond_query
;
180 bool cond_cond
; /* inverted rendering condition */
182 uint32_t cond_condmode
; /* the calculated condition */
184 struct nv50_blitctx
*blit
;
186 struct util_dynarray global_residents
;
189 static inline struct nv50_context
*
190 nv50_context(struct pipe_context
*pipe
)
192 return (struct nv50_context
*)pipe
;
195 /* return index used in nv50_context arrays for a specific shader type */
196 static inline unsigned
197 nv50_context_shader_stage(unsigned pipe
)
200 case PIPE_SHADER_VERTEX
: return 0;
201 case PIPE_SHADER_FRAGMENT
: return 1;
202 case PIPE_SHADER_GEOMETRY
: return 2;
203 case PIPE_SHADER_COMPUTE
: return 3;
205 assert(!"invalid/unhandled shader type");
211 struct pipe_context
*nv50_create(struct pipe_screen
*, void *, unsigned flags
);
213 void nv50_bufctx_fence(struct nouveau_bufctx
*, bool on_flush
);
215 void nv50_default_kick_notify(struct nouveau_pushbuf
*);
218 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*);
220 /* nv50_shader_state.c */
221 void nv50_vertprog_validate(struct nv50_context
*);
222 void nv50_gmtyprog_validate(struct nv50_context
*);
223 void nv50_fragprog_validate(struct nv50_context
*);
224 void nv50_compprog_validate(struct nv50_context
*);
225 void nv50_fp_linkage_validate(struct nv50_context
*);
226 void nv50_gp_linkage_validate(struct nv50_context
*);
227 void nv50_constbufs_validate(struct nv50_context
*);
228 void nv50_validate_derived_rs(struct nv50_context
*);
229 void nv50_stream_output_validate(struct nv50_context
*);
232 extern void nv50_init_state_functions(struct nv50_context
*);
234 /* nv50_state_validate.c */
235 struct nv50_state_validate
{
236 void (*func
)(struct nv50_context
*);
240 bool nv50_state_validate(struct nv50_context
*, uint32_t,
241 struct nv50_state_validate
*, int, uint32_t *,
242 struct nouveau_bufctx
*);
243 bool nv50_state_validate_3d(struct nv50_context
*, uint32_t);
246 extern void nv50_clear(struct pipe_context
*, unsigned buffers
,
247 const union pipe_color_union
*color
,
248 double depth
, unsigned stencil
);
249 extern void nv50_init_surface_functions(struct nv50_context
*);
252 void nv50_validate_textures(struct nv50_context
*);
253 void nv50_validate_samplers(struct nv50_context
*);
254 void nv50_upload_ms_info(struct nouveau_pushbuf
*);
256 struct pipe_sampler_view
*
257 nv50_create_texture_view(struct pipe_context
*,
258 struct pipe_resource
*,
259 const struct pipe_sampler_view
*,
261 enum pipe_texture_target
);
262 struct pipe_sampler_view
*
263 nv50_create_sampler_view(struct pipe_context
*,
264 struct pipe_resource
*,
265 const struct pipe_sampler_view
*);
267 /* nv50_transfer.c */
269 nv50_m2mf_transfer_rect(struct nv50_context
*,
270 const struct nv50_m2mf_rect
*dst
,
271 const struct nv50_m2mf_rect
*src
,
272 uint32_t nblocksx
, uint32_t nblocksy
);
274 nv50_sifc_linear_u8(struct nouveau_context
*pipe
,
275 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
276 unsigned size
, const void *data
);
278 nv50_m2mf_copy_linear(struct nouveau_context
*pipe
,
279 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
280 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
283 nv50_cb_push(struct nouveau_context
*nv
,
284 struct nouveau_bo
*bo
, unsigned domain
,
285 unsigned base
, unsigned size
,
286 unsigned offset
, unsigned words
, const uint32_t *data
);
289 void nv50_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
292 nv50_vertex_state_create(struct pipe_context
*pipe
,
293 unsigned num_elements
,
294 const struct pipe_vertex_element
*elements
);
296 nv50_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
298 void nv50_vertex_arrays_validate(struct nv50_context
*nv50
);
301 void nv50_push_vbo(struct nv50_context
*, const struct pipe_draw_info
*);
304 struct pipe_video_codec
*
305 nv84_create_decoder(struct pipe_context
*context
,
306 const struct pipe_video_codec
*templ
);
308 struct pipe_video_buffer
*
309 nv84_video_buffer_create(struct pipe_context
*pipe
,
310 const struct pipe_video_buffer
*template);
313 nv84_screen_get_video_param(struct pipe_screen
*pscreen
,
314 enum pipe_video_profile profile
,
315 enum pipe_video_entrypoint entrypoint
,
316 enum pipe_video_cap param
);
319 nv84_screen_video_supported(struct pipe_screen
*screen
,
320 enum pipe_format format
,
321 enum pipe_video_profile profile
,
322 enum pipe_video_entrypoint entrypoint
);
325 struct pipe_video_codec
*
326 nv98_create_decoder(struct pipe_context
*context
,
327 const struct pipe_video_codec
*templ
);
329 struct pipe_video_buffer
*
330 nv98_video_buffer_create(struct pipe_context
*pipe
,
331 const struct pipe_video_buffer
*template);
335 nv50_launch_grid(struct pipe_context
*, const struct pipe_grid_info
*);