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_BLEND (1 << 0)
30 #define NV50_NEW_RASTERIZER (1 << 1)
31 #define NV50_NEW_ZSA (1 << 2)
32 #define NV50_NEW_VERTPROG (1 << 3)
33 #define NV50_NEW_GMTYPROG (1 << 6)
34 #define NV50_NEW_FRAGPROG (1 << 7)
35 #define NV50_NEW_BLEND_COLOUR (1 << 8)
36 #define NV50_NEW_STENCIL_REF (1 << 9)
37 #define NV50_NEW_CLIP (1 << 10)
38 #define NV50_NEW_SAMPLE_MASK (1 << 11)
39 #define NV50_NEW_FRAMEBUFFER (1 << 12)
40 #define NV50_NEW_STIPPLE (1 << 13)
41 #define NV50_NEW_SCISSOR (1 << 14)
42 #define NV50_NEW_VIEWPORT (1 << 15)
43 #define NV50_NEW_ARRAYS (1 << 16)
44 #define NV50_NEW_VERTEX (1 << 17)
45 #define NV50_NEW_CONSTBUF (1 << 18)
46 #define NV50_NEW_TEXTURES (1 << 19)
47 #define NV50_NEW_SAMPLERS (1 << 20)
48 #define NV50_NEW_STRMOUT (1 << 21)
49 #define NV50_NEW_MIN_SAMPLES (1 << 22)
50 #define NV50_NEW_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_FB 0
57 #define NV50_BIND_VERTEX 1
58 #define NV50_BIND_VERTEX_TMP 2
59 #define NV50_BIND_INDEX 3
60 #define NV50_BIND_TEXTURES 4
61 #define NV50_BIND_CB(s, i) (5 + 16 * (s) + (i))
62 #define NV50_BIND_SO 53
63 #define NV50_BIND_SCREEN 54
64 #define NV50_BIND_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
;
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];
157 uint8_t num_so_targets
;
158 uint8_t so_targets_dirty
;
159 struct pipe_stream_output_target
*so_target
[4];
161 struct pipe_framebuffer_state framebuffer
;
162 struct pipe_blend_color blend_colour
;
163 struct pipe_stencil_ref stencil_ref
;
164 struct pipe_poly_stipple stipple
;
165 struct pipe_scissor_state scissors
[NV50_MAX_VIEWPORTS
];
166 unsigned scissors_dirty
;
167 struct pipe_viewport_state viewports
[NV50_MAX_VIEWPORTS
];
168 unsigned viewports_dirty
;
169 struct pipe_clip_state clip
;
171 unsigned sample_mask
;
172 unsigned min_samples
;
176 uint32_t rt_array_mode
;
178 struct pipe_query
*cond_query
;
179 bool cond_cond
; /* inverted rendering condition */
181 uint32_t cond_condmode
; /* the calculated condition */
183 struct nv50_blitctx
*blit
;
185 struct util_dynarray global_residents
;
188 static inline struct nv50_context
*
189 nv50_context(struct pipe_context
*pipe
)
191 return (struct nv50_context
*)pipe
;
194 /* return index used in nv50_context arrays for a specific shader type */
195 static inline unsigned
196 nv50_context_shader_stage(unsigned pipe
)
199 case PIPE_SHADER_VERTEX
: return 0;
200 case PIPE_SHADER_FRAGMENT
: return 1;
201 case PIPE_SHADER_GEOMETRY
: return 2;
202 case PIPE_SHADER_COMPUTE
: return 3;
204 assert(!"invalid/unhandled shader type");
210 struct pipe_context
*nv50_create(struct pipe_screen
*, void *, unsigned flags
);
212 void nv50_bufctx_fence(struct nouveau_bufctx
*, bool on_flush
);
214 void nv50_default_kick_notify(struct nouveau_pushbuf
*);
217 extern struct draw_stage
*nv50_draw_render_stage(struct nv50_context
*);
219 /* nv50_shader_state.c */
220 void nv50_vertprog_validate(struct nv50_context
*);
221 void nv50_gmtyprog_validate(struct nv50_context
*);
222 void nv50_fragprog_validate(struct nv50_context
*);
223 void nv50_fp_linkage_validate(struct nv50_context
*);
224 void nv50_gp_linkage_validate(struct nv50_context
*);
225 void nv50_constbufs_validate(struct nv50_context
*);
226 void nv50_validate_derived_rs(struct nv50_context
*);
227 void nv50_stream_output_validate(struct nv50_context
*);
230 extern void nv50_init_state_functions(struct nv50_context
*);
232 /* nv50_state_validate.c */
233 bool nv50_state_validate(struct nv50_context
*, uint32_t state_mask
);
236 extern void nv50_clear(struct pipe_context
*, unsigned buffers
,
237 const union pipe_color_union
*color
,
238 double depth
, unsigned stencil
);
239 extern void nv50_init_surface_functions(struct nv50_context
*);
242 void nv50_validate_textures(struct nv50_context
*);
243 void nv50_validate_samplers(struct nv50_context
*);
244 void nv50_upload_ms_info(struct nouveau_pushbuf
*);
246 struct pipe_sampler_view
*
247 nv50_create_texture_view(struct pipe_context
*,
248 struct pipe_resource
*,
249 const struct pipe_sampler_view
*,
251 enum pipe_texture_target
);
252 struct pipe_sampler_view
*
253 nv50_create_sampler_view(struct pipe_context
*,
254 struct pipe_resource
*,
255 const struct pipe_sampler_view
*);
257 /* nv50_transfer.c */
259 nv50_m2mf_transfer_rect(struct nv50_context
*,
260 const struct nv50_m2mf_rect
*dst
,
261 const struct nv50_m2mf_rect
*src
,
262 uint32_t nblocksx
, uint32_t nblocksy
);
264 nv50_sifc_linear_u8(struct nouveau_context
*pipe
,
265 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
266 unsigned size
, const void *data
);
268 nv50_m2mf_copy_linear(struct nouveau_context
*pipe
,
269 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
270 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
273 nv50_cb_push(struct nouveau_context
*nv
,
274 struct nouveau_bo
*bo
, unsigned domain
,
275 unsigned base
, unsigned size
,
276 unsigned offset
, unsigned words
, const uint32_t *data
);
279 void nv50_draw_vbo(struct pipe_context
*, const struct pipe_draw_info
*);
282 nv50_vertex_state_create(struct pipe_context
*pipe
,
283 unsigned num_elements
,
284 const struct pipe_vertex_element
*elements
);
286 nv50_vertex_state_delete(struct pipe_context
*pipe
, void *hwcso
);
288 void nv50_vertex_arrays_validate(struct nv50_context
*nv50
);
291 void nv50_push_vbo(struct nv50_context
*, const struct pipe_draw_info
*);
294 struct pipe_video_codec
*
295 nv84_create_decoder(struct pipe_context
*context
,
296 const struct pipe_video_codec
*templ
);
298 struct pipe_video_buffer
*
299 nv84_video_buffer_create(struct pipe_context
*pipe
,
300 const struct pipe_video_buffer
*template);
303 nv84_screen_get_video_param(struct pipe_screen
*pscreen
,
304 enum pipe_video_profile profile
,
305 enum pipe_video_entrypoint entrypoint
,
306 enum pipe_video_cap param
);
309 nv84_screen_video_supported(struct pipe_screen
*screen
,
310 enum pipe_format format
,
311 enum pipe_video_profile profile
,
312 enum pipe_video_entrypoint entrypoint
);
315 struct pipe_video_codec
*
316 nv98_create_decoder(struct pipe_context
*context
,
317 const struct pipe_video_codec
*templ
);
319 struct pipe_video_buffer
*
320 nv98_video_buffer_create(struct pipe_context
*pipe
,
321 const struct pipe_video_buffer
*template);
325 nv50_launch_grid(struct pipe_context
*, const struct pipe_grid_info
*);