1 #ifndef __NV50_CONTEXT_H__ 2 #define __NV50_CONTEXT_H__ 3 4 #include "pipe/p_context.h" 5 #include "pipe/p_defines.h" 6 #include "pipe/p_state.h" 7 8 #include "util/u_memory.h" 9 #include "util/u_math.h" 10 #include "util/u_inlines.h" 11 #include "util/u_dynarray.h" 12 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" 20 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" 28 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) 52 53 #define NV50_NEW_CP_PROGRAM (1 << 0) 54 #define NV50_NEW_CP_GLOBALS (1 << 1) 55 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 67 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 73 74 /* bufctx for other operations */ 75 #define NV50_BIND_2D 0 76 #define NV50_BIND_M2MF 0 77 #define NV50_BIND_FENCE 1 78 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) 106 107 108 109 struct nv50_blitctx; 110 111 bool nv50_blitctx_create(struct nv50_context *); 112 113 struct nv50_context { 114 struct nouveau_context base; 115 116 struct nv50_screen *screen; 117 118 struct nouveau_bufctx *bufctx_3d; 119 struct nouveau_bufctx *bufctx; 120 struct nouveau_bufctx *bufctx_cp; 121 122 uint32_t dirty_3d; /* dirty flags for 3d state */ 123 uint32_t dirty_cp; /* dirty flags for compute state */ 124 bool cb_dirty; 125 126 struct nv50_graph_state state; 127 128 struct nv50_blend_stateobj *blend; 129 struct nv50_rasterizer_stateobj *rast; 130 struct nv50_zsa_stateobj *zsa; 131 struct nv50_vertex_stateobj *vertex; 132 133 struct nv50_program *vertprog; 134 struct nv50_program *gmtyprog; 135 struct nv50_program *fragprog; 136 struct nv50_program *compprog; 137 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]; 142 143 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; 144 unsigned num_vtxbufs; 145 uint32_t vtxbufs_coherent; 146 struct pipe_index_buffer idxbuf; 147 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */ 148 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */ 149 uint32_t vbo_constant; /* bitmask of user buffers with stride 0 */ 150 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */ 151 uint32_t vb_elt_limit; /* max - min element (count - 1) */ 152 uint32_t instance_off; /* base vertex for instanced arrays */ 153 uint32_t instance_max; /* max instance for current draw call */ 154 155 struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS]; 156 unsigned num_textures[3]; 157 uint32_t textures_coherent[3]; 158 struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS]; 159 unsigned num_samplers[3]; 160 bool seamless_cube_map; 161 162 uint8_t num_so_targets; 163 uint8_t so_targets_dirty; 164 struct pipe_stream_output_target *so_target[4]; 165 166 struct pipe_framebuffer_state framebuffer; 167 struct pipe_blend_color blend_colour; 168 struct pipe_stencil_ref stencil_ref; 169 struct pipe_poly_stipple stipple; 170 struct pipe_scissor_state scissors[NV50_MAX_VIEWPORTS]; 171 unsigned scissors_dirty; 172 struct pipe_viewport_state viewports[NV50_MAX_VIEWPORTS]; 173 unsigned viewports_dirty; 174 struct pipe_clip_state clip; 175 struct nv50_window_rect_stateobj window_rect; 176 177 unsigned sample_mask; 178 unsigned min_samples; 179 180 bool vbo_push_hint; 181 182 uint32_t rt_array_mode; 183 184 struct pipe_query *cond_query; 185 bool cond_cond; /* inverted rendering condition */ 186 uint cond_mode; 187 uint32_t cond_condmode; /* the calculated condition */ 188 189 struct nv50_blitctx *blit; 190 191 struct util_dynarray global_residents; 192 }; 193 194 static inline struct nv50_context * 195 nv50_context(struct pipe_context *pipe) 196 { 197 return (struct nv50_context *)pipe; 198 } 199 200 /* return index used in nv50_context arrays for a specific shader type */ 201 static inline unsigned 202 nv50_context_shader_stage(unsigned pipe) 203 { 204 switch (pipe) { 205 case PIPE_SHADER_VERTEX: return 0; 206 case PIPE_SHADER_FRAGMENT: return 1; 207 case PIPE_SHADER_GEOMETRY: return 2; 208 case PIPE_SHADER_COMPUTE: return 3; 209 default: 210 assert(!"invalid/unhandled shader type"); 211 return 0; 212 } 213 } 214 215 /* nv50_context.c */ 216 struct pipe_context *nv50_create(struct pipe_screen *, void *, unsigned flags); 217 218 void nv50_bufctx_fence(struct nouveau_bufctx *, bool on_flush); 219 220 void nv50_default_kick_notify(struct nouveau_pushbuf *); 221 222 /* nv50_draw.c */ 223 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *); 224 225 /* nv50_shader_state.c */ 226 void nv50_vertprog_validate(struct nv50_context *); 227 void nv50_gmtyprog_validate(struct nv50_context *); 228 void nv50_fragprog_validate(struct nv50_context *); 229 void nv50_compprog_validate(struct nv50_context *); 230 void nv50_fp_linkage_validate(struct nv50_context *); 231 void nv50_gp_linkage_validate(struct nv50_context *); 232 void nv50_constbufs_validate(struct nv50_context *); 233 void nv50_validate_derived_rs(struct nv50_context *); 234 void nv50_stream_output_validate(struct nv50_context *); 235 236 /* nv50_state.c */ 237 extern void nv50_init_state_functions(struct nv50_context *); 238 239 /* nv50_state_validate.c */ 240 struct nv50_state_validate { 241 void (*func)(struct nv50_context *); 242 uint32_t states; 243 }; 244 245 bool nv50_state_validate(struct nv50_context *, uint32_t, 246 struct nv50_state_validate *, int, uint32_t *, 247 struct nouveau_bufctx *); 248 bool nv50_state_validate_3d(struct nv50_context *, uint32_t); 249 250 /* nv50_surface.c */ 251 extern void nv50_clear(struct pipe_context *, unsigned buffers, 252 const union pipe_color_union *color, 253 double depth, unsigned stencil); 254 extern void nv50_init_surface_functions(struct nv50_context *); 255 256 /* nv50_tex.c */ 257 void nv50_validate_textures(struct nv50_context *); 258 void nv50_validate_samplers(struct nv50_context *); 259 void nv50_upload_ms_info(struct nouveau_pushbuf *); 260 261 struct pipe_sampler_view * 262 nv50_create_texture_view(struct pipe_context *, 263 struct pipe_resource *, 264 const struct pipe_sampler_view *, 265 uint32_t flags, 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 *); 271 272 /* nv50_transfer.c */ 273 void 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); 278 void 279 nv50_sifc_linear_u8(struct nouveau_context *pipe, 280 struct nouveau_bo *dst, unsigned offset, unsigned domain, 281 unsigned size, const void *data); 282 void 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, 286 unsigned size); 287 void 288 nv50_cb_push(struct nouveau_context *nv, 289 struct nv04_resource *res, 290 unsigned offset, unsigned words, const uint32_t *data); 291 292 /* nv50_vbo.c */ 293 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *); 294 295 void * 296 nv50_vertex_state_create(struct pipe_context *pipe, 297 unsigned num_elements, 298 const struct pipe_vertex_element *elements); 299 void 300 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso); 301 302 void nv50_vertex_arrays_validate(struct nv50_context *nv50); 303 304 /* nv50_push.c */ 305 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *); 306 307 /* nv84_video.c */ 308 struct pipe_video_codec * 309 nv84_create_decoder(struct pipe_context *context, 310 const struct pipe_video_codec *templ); 311 312 struct pipe_video_buffer * 313 nv84_video_buffer_create(struct pipe_context *pipe, 314 const struct pipe_video_buffer *template); 315 316 int 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); 321 322 boolean 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); 327 328 /* nv98_video.c */ 329 struct pipe_video_codec * 330 nv98_create_decoder(struct pipe_context *context, 331 const struct pipe_video_codec *templ); 332 333 struct pipe_video_buffer * 334 nv98_video_buffer_create(struct pipe_context *pipe, 335 const struct pipe_video_buffer *template); 336 337 /* nv50_compute.c */ 338 void 339 nv50_launch_grid(struct pipe_context *, const struct pipe_grid_info *); 340 341 #endif 342