Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
4574 views
#ifndef __NVC0_CONTEXT_H__1#define __NVC0_CONTEXT_H__23#include "pipe/p_context.h"4#include "pipe/p_defines.h"5#include "pipe/p_state.h"67#include "util/list.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"1213#include "nvc0/nvc0_winsys.h"14#include "nvc0/nvc0_stateobj.h"15#include "nvc0/nvc0_screen.h"16#include "nvc0/nvc0_program.h"17#include "nvc0/nvc0_resource.h"18#include "nvc0/nvc0_query.h"1920#include "nv50/nv50_transfer.h"2122#include "nouveau_context.h"23#include "nouveau_debug.h"2425#include "nv50/nv50_3ddefs.xml.h"26#include "nvc0/nvc0_3d.xml.h"27#include "nv50/nv50_2d.xml.h"28#include "nvc0/nvc0_m2mf.xml.h"29#include "nvc0/nve4_copy.xml.h"30#include "nvc0/nve4_p2mf.xml.h"31#include "nvc0/nvc0_compute.xml.h"32#include "nvc0/nvc0_macros.h"3334/* NOTE: must keep NVC0_NEW_3D_...PROG in consecutive bits in this order */35#define NVC0_NEW_3D_BLEND (1 << 0)36#define NVC0_NEW_3D_RASTERIZER (1 << 1)37#define NVC0_NEW_3D_ZSA (1 << 2)38#define NVC0_NEW_3D_VERTPROG (1 << 3)39#define NVC0_NEW_3D_TCTLPROG (1 << 4)40#define NVC0_NEW_3D_TEVLPROG (1 << 5)41#define NVC0_NEW_3D_GMTYPROG (1 << 6)42#define NVC0_NEW_3D_FRAGPROG (1 << 7)43#define NVC0_NEW_3D_BLEND_COLOUR (1 << 8)44#define NVC0_NEW_3D_STENCIL_REF (1 << 9)45#define NVC0_NEW_3D_CLIP (1 << 10)46#define NVC0_NEW_3D_SAMPLE_MASK (1 << 11)47#define NVC0_NEW_3D_FRAMEBUFFER (1 << 12)48#define NVC0_NEW_3D_STIPPLE (1 << 13)49#define NVC0_NEW_3D_SCISSOR (1 << 14)50#define NVC0_NEW_3D_VIEWPORT (1 << 15)51#define NVC0_NEW_3D_ARRAYS (1 << 16)52#define NVC0_NEW_3D_VERTEX (1 << 17)53#define NVC0_NEW_3D_CONSTBUF (1 << 18)54#define NVC0_NEW_3D_TEXTURES (1 << 19)55#define NVC0_NEW_3D_SAMPLERS (1 << 20)56#define NVC0_NEW_3D_TFB_TARGETS (1 << 21)5758#define NVC0_NEW_3D_SURFACES (1 << 23)59#define NVC0_NEW_3D_MIN_SAMPLES (1 << 24)60#define NVC0_NEW_3D_TESSFACTOR (1 << 25)61#define NVC0_NEW_3D_BUFFERS (1 << 26)62#define NVC0_NEW_3D_DRIVERCONST (1 << 27)63#define NVC0_NEW_3D_WINDOW_RECTS (1 << 28)6465#define NVC0_NEW_3D_SAMPLE_LOCATIONS (1 << 29)6667#define NVC0_NEW_CP_PROGRAM (1 << 0)68#define NVC0_NEW_CP_SURFACES (1 << 1)69#define NVC0_NEW_CP_TEXTURES (1 << 2)70#define NVC0_NEW_CP_SAMPLERS (1 << 3)71#define NVC0_NEW_CP_CONSTBUF (1 << 4)72#define NVC0_NEW_CP_GLOBALS (1 << 5)73#define NVC0_NEW_CP_DRIVERCONST (1 << 6)74#define NVC0_NEW_CP_BUFFERS (1 << 7)7576/* 3d bufctx (during draw_vbo, blit_3d) */77#define NVC0_BIND_3D_FB 078#define NVC0_BIND_3D_VTX 179#define NVC0_BIND_3D_VTX_TMP 280#define NVC0_BIND_3D_IDX 381#define NVC0_BIND_3D_TEX(s, i) ( 4 + 32 * (s) + (i))82#define NVC0_BIND_3D_CB(s, i) (164 + 16 * (s) + (i))83#define NVC0_BIND_3D_TFB 24484#define NVC0_BIND_3D_SUF 24585#define NVC0_BIND_3D_BUF 24686#define NVC0_BIND_3D_SCREEN 24787#define NVC0_BIND_3D_BINDLESS 24888#define NVC0_BIND_3D_TLS 24989#define NVC0_BIND_3D_TEXT 25090#define NVC0_BIND_3D_COUNT 2519192/* compute bufctx (during launch_grid) */93#define NVC0_BIND_CP_CB(i) ( 0 + (i))94#define NVC0_BIND_CP_TEX(i) ( 16 + (i))95#define NVC0_BIND_CP_SUF 4896#define NVC0_BIND_CP_GLOBAL 4997#define NVC0_BIND_CP_DESC 5098#define NVC0_BIND_CP_SCREEN 5199#define NVC0_BIND_CP_QUERY 52100#define NVC0_BIND_CP_BUF 53101#define NVC0_BIND_CP_TEXT 54102#define NVC0_BIND_CP_BINDLESS 55103#define NVC0_BIND_CP_COUNT 56104105/* bufctx for other operations */106#define NVC0_BIND_2D 0107#define NVC0_BIND_M2MF 0108#define NVC0_BIND_FENCE 1109110/* 6 user uniform buffers, at 64K each */111#define NVC0_CB_USR_INFO(s) (s << 16)112#define NVC0_CB_USR_SIZE (6 << 16)113/* 6 driver constbuts, at 64K each */114#define NVC0_CB_AUX_INFO(s) NVC0_CB_USR_SIZE + (s << 16)115#define NVC0_CB_AUX_SIZE (1 << 16)116/* XXX: Figure out what this UNK data is. */117#define NVC0_CB_AUX_UNK_INFO 0x000118#define NVC0_CB_AUX_UNK_SIZE (8 * 4)119/* 40 textures handles (8 for GM107+ images only), at 1 32-bits integer each */120#define NVC0_CB_AUX_TEX_INFO(i) 0x020 + (i) * 4121#define NVC0_CB_AUX_TEX_SIZE (40 * 4)122/* 8 sets of 32-bits coordinate offsets */123#define NVC0_CB_AUX_MS_INFO 0x0c0124#define NVC0_CB_AUX_MS_SIZE (8 * 2 * 4)125/* block/grid size, at 3 32-bits integers each, gridid and work_dim */126#define NVC0_CB_AUX_GRID_INFO(i) 0x100 + (i) * 4 /* CP */127#define NVC0_CB_AUX_GRID_SIZE (8 * 4)128/* FB texture handle */129#define NVC0_CB_AUX_FB_TEX_INFO 0x100 /* FP */130#define NVC0_CB_AUX_FB_TEX_SIZE (4)131/* 8 user clip planes, at 4 32-bits floats each */132#define NVC0_CB_AUX_UCP_INFO 0x120133#define NVC0_CB_AUX_UCP_SIZE (PIPE_MAX_CLIP_PLANES * 4 * 4)134/* 13 ubos, at 4 32-bits integer each */135#define NVC0_CB_AUX_UBO_INFO(i) 0x120 + (i) * 4 * 4 /* CP */136#define NVC0_CB_AUX_UBO_SIZE ((NVC0_MAX_PIPE_CONSTBUFS - 1) * 4 * 4)137/* 8 sets of 32-bits integer pairs sample offsets */138#define NVC0_CB_AUX_SAMPLE_INFO 0x1a0 /* FP */139/* 256 bytes, though only 64 bytes used before GM200 */140#define NVC0_CB_AUX_SAMPLE_SIZE (8 * 2 * 4 * 4)141/* draw parameters (index bias, base instance, drawid)142* be sure to update the indirect draw macros in com9097.mme when changing this143*/144#define NVC0_CB_AUX_DRAW_INFO 0x1a0 /* VP */145/* 32 user buffers, at 4 32-bits integers each */146#define NVC0_CB_AUX_BUF_INFO(i) 0x2a0 + (i) * 4 * 4147#define NVC0_CB_AUX_BUF_SIZE (NVC0_MAX_BUFFERS * 4 * 4)148/* 8 surfaces, at 16 32-bits integers each */149#define NVC0_CB_AUX_SU_INFO(i) 0x4a0 + (i) * 16 * 4150#define NVC0_CB_AUX_SU_SIZE (NVC0_MAX_IMAGES * 16 * 4)151/* 1 64-bits address and 1 32-bits sequence152* be sure to update the shaders in nvc0_query_hw_sm.c when changing this153*/154#define NVC0_CB_AUX_MP_INFO 0x6a0155#define NVC0_CB_AUX_MP_SIZE 3 * 4156/* 512 64-byte blocks for bindless image handles */157#define NVC0_CB_AUX_BINDLESS_INFO(i) 0x6b0 + (i) * 16 * 4158#define NVC0_CB_AUX_BINDLESS_SIZE (NVE4_IMG_MAX_HANDLES * 16 * 4)159/* 4 32-bits floats for the vertex runout, put at the end */160#define NVC0_CB_AUX_RUNOUT_INFO NVC0_CB_USR_SIZE + (NVC0_CB_AUX_SIZE * 6)161162struct nvc0_blitctx;163164bool nvc0_blitctx_create(struct nvc0_context *);165void nvc0_blitctx_destroy(struct nvc0_context *);166167struct nvc0_resident {168struct list_head list;169uint64_t handle;170struct nv04_resource *buf;171uint32_t flags;172};173174struct nvc0_context {175struct nouveau_context base;176177struct nouveau_bufctx *bufctx_3d;178struct nouveau_bufctx *bufctx;179struct nouveau_bufctx *bufctx_cp;180181struct nvc0_screen *screen;182183void (*m2mf_copy_rect)(struct nvc0_context *,184const struct nv50_m2mf_rect *dst,185const struct nv50_m2mf_rect *src,186uint32_t nblocksx, uint32_t nblocksy);187188uint32_t dirty_3d; /* dirty flags for 3d state */189uint32_t dirty_cp; /* dirty flags for compute state */190191struct nvc0_graph_state state;192193struct nvc0_blend_stateobj *blend;194struct nvc0_rasterizer_stateobj *rast;195struct nvc0_zsa_stateobj *zsa;196struct nvc0_vertex_stateobj *vertex;197198struct nvc0_program *vertprog;199struct nvc0_program *tctlprog;200struct nvc0_program *tevlprog;201struct nvc0_program *gmtyprog;202struct nvc0_program *fragprog;203struct nvc0_program *compprog;204205struct nvc0_program *tcp_empty;206207struct nvc0_constbuf constbuf[6][NVC0_MAX_PIPE_CONSTBUFS];208uint16_t constbuf_dirty[6];209uint16_t constbuf_valid[6];210uint16_t constbuf_coherent[6];211bool cb_dirty;212213struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];214unsigned num_vtxbufs;215uint32_t vtxbufs_coherent;216uint32_t constant_vbos;217uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */218uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */219uint32_t vb_elt_limit; /* max - min element (count - 1) */220uint32_t instance_off; /* current base vertex for instanced arrays */221uint32_t instance_max; /* last instance for current draw call */222223struct pipe_sampler_view *textures[6][PIPE_MAX_SAMPLERS];224unsigned num_textures[6];225uint32_t textures_dirty[6];226uint32_t textures_coherent[6];227struct nv50_tsc_entry *samplers[6][PIPE_MAX_SAMPLERS];228unsigned num_samplers[6];229uint32_t samplers_dirty[6];230bool seamless_cube_map;231struct pipe_sampler_view *fbtexture;232233uint32_t tex_handles[6][PIPE_MAX_SAMPLERS]; /* for nve4 */234235struct list_head tex_head;236struct list_head img_head;237238struct pipe_framebuffer_state framebuffer;239bool sample_locations_enabled;240uint8_t sample_locations[2 * 4 * 8];241struct pipe_blend_color blend_colour;242struct pipe_stencil_ref stencil_ref;243struct pipe_poly_stipple stipple;244struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS];245unsigned scissors_dirty;246struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];247unsigned viewports_dirty;248struct pipe_clip_state clip;249struct nvc0_window_rect_stateobj window_rect;250251unsigned sample_mask;252unsigned min_samples;253254float default_tess_outer[4];255float default_tess_inner[2];256257bool vbo_push_hint;258259uint8_t tfbbuf_dirty;260struct pipe_stream_output_target *tfbbuf[4];261unsigned num_tfbbufs;262263struct pipe_query *cond_query;264bool cond_cond; /* inverted rendering condition */265uint cond_mode;266uint32_t cond_condmode; /* the calculated condition */267268struct nvc0_blitctx *blit;269270/* NOTE: some of these surfaces may reference buffers */271struct pipe_surface *surfaces[2][NVC0_MAX_SURFACE_SLOTS];272uint16_t surfaces_dirty[2];273uint16_t surfaces_valid[2];274275struct pipe_shader_buffer buffers[6][NVC0_MAX_BUFFERS];276uint32_t buffers_dirty[6];277uint32_t buffers_valid[6];278279struct pipe_image_view images[6][NVC0_MAX_IMAGES];280struct pipe_sampler_view *images_tic[6][NVC0_MAX_IMAGES]; /* GM107+ */281uint16_t images_dirty[6];282uint16_t images_valid[6];283284struct util_dynarray global_residents;285286uint64_t compute_invocations;287};288289static inline struct nvc0_context *290nvc0_context(struct pipe_context *pipe)291{292return (struct nvc0_context *)pipe;293}294295static inline unsigned296nvc0_shader_stage(unsigned pipe)297{298switch (pipe) {299case PIPE_SHADER_VERTEX: return 0;300case PIPE_SHADER_TESS_CTRL: return 1;301case PIPE_SHADER_TESS_EVAL: return 2;302case PIPE_SHADER_GEOMETRY: return 3;303case PIPE_SHADER_FRAGMENT: return 4;304case PIPE_SHADER_COMPUTE: return 5;305default:306assert(!"invalid PIPE_SHADER type");307return 0;308}309}310311312/* nvc0_context.c */313struct pipe_context *nvc0_create(struct pipe_screen *, void *, unsigned flags);314void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,315bool on_flush);316void nvc0_default_kick_notify(struct nouveau_pushbuf *);317const void *nvc0_get_sample_locations(unsigned);318319/* nvc0_draw.c */320extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);321322/* nvc0_program.c */323bool nvc0_program_translate(struct nvc0_program *, uint16_t chipset,324struct disk_cache *,325struct pipe_debug_callback *);326bool nvc0_program_upload(struct nvc0_context *, struct nvc0_program *);327void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);328void nvc0_program_library_upload(struct nvc0_context *);329void nvc0_program_init_tcp_empty(struct nvc0_context *);330331/* nvc0_shader_state.c */332void nvc0_vertprog_validate(struct nvc0_context *);333void nvc0_tctlprog_validate(struct nvc0_context *);334void nvc0_tevlprog_validate(struct nvc0_context *);335void nvc0_gmtyprog_validate(struct nvc0_context *);336void nvc0_fragprog_validate(struct nvc0_context *);337void nvc0_compprog_validate(struct nvc0_context *);338339void nvc0_tfb_validate(struct nvc0_context *);340void nvc0_layer_validate(struct nvc0_context *);341342/* nvc0_state.c */343extern void nvc0_init_state_functions(struct nvc0_context *);344345/* nvc0_state_validate.c */346struct nvc0_state_validate {347void (*func)(struct nvc0_context *);348uint32_t states;349};350351bool nvc0_state_validate(struct nvc0_context *, uint32_t,352struct nvc0_state_validate *, int, uint32_t *,353struct nouveau_bufctx *);354bool nvc0_state_validate_3d(struct nvc0_context *, uint32_t);355356/* nvc0_surface.c */357extern void nvc0_clear(struct pipe_context *, unsigned buffers,358const struct pipe_scissor_state *scissor_state,359const union pipe_color_union *color,360double depth, unsigned stencil);361extern void nvc0_init_surface_functions(struct nvc0_context *);362363/* nvc0_tex.c */364bool nvc0_validate_tic(struct nvc0_context *nvc0, int s);365bool nvc0_validate_tsc(struct nvc0_context *nvc0, int s);366bool nve4_validate_tsc(struct nvc0_context *nvc0, int s);367void nvc0_validate_suf(struct nvc0_context *nvc0, int s);368void nvc0_validate_textures(struct nvc0_context *);369void nvc0_validate_samplers(struct nvc0_context *);370void nvc0_upload_tsc0(struct nvc0_context *);371void nve4_set_tex_handles(struct nvc0_context *);372void nvc0_validate_surfaces(struct nvc0_context *);373void nve4_set_surface_info(struct nouveau_pushbuf *,374const struct pipe_image_view *,375struct nvc0_context *);376void nvc0_mark_image_range_valid(const struct pipe_image_view *);377bool nvc0_update_tic(struct nvc0_context *, struct nv50_tic_entry *,378struct nv04_resource *);379380struct pipe_sampler_view *381nvc0_create_texture_view(struct pipe_context *,382struct pipe_resource *,383const struct pipe_sampler_view *,384uint32_t flags);385struct pipe_sampler_view *386nvc0_create_sampler_view(struct pipe_context *,387struct pipe_resource *,388const struct pipe_sampler_view *);389struct pipe_sampler_view *390gm107_create_texture_view_from_image(struct pipe_context *,391const struct pipe_image_view *);392393void nvc0_init_bindless_functions(struct pipe_context *);394395/* nvc0_transfer.c */396void397nvc0_init_transfer_functions(struct nvc0_context *);398399void400nvc0_m2mf_push_linear(struct nouveau_context *nv,401struct nouveau_bo *dst, unsigned offset, unsigned domain,402unsigned size, const void *data);403void404nve4_p2mf_push_linear(struct nouveau_context *nv,405struct nouveau_bo *dst, unsigned offset, unsigned domain,406unsigned size, const void *data);407void408nvc0_cb_bo_push(struct nouveau_context *,409struct nouveau_bo *bo, unsigned domain,410unsigned base, unsigned size,411unsigned offset, unsigned words, const uint32_t *data);412413/* nvc0_vbo.c */414void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *, unsigned,415const struct pipe_draw_indirect_info *indirect,416const struct pipe_draw_start_count_bias *draws,417unsigned num_draws);418419void *420nvc0_vertex_state_create(struct pipe_context *pipe,421unsigned num_elements,422const struct pipe_vertex_element *elements);423void424nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);425426void nvc0_vertex_arrays_validate(struct nvc0_context *);427428void nvc0_idxbuf_validate(struct nvc0_context *);429430/* nvc0_video.c */431struct pipe_video_codec *432nvc0_create_decoder(struct pipe_context *context,433const struct pipe_video_codec *templ);434435struct pipe_video_buffer *436nvc0_video_buffer_create(struct pipe_context *pipe,437const struct pipe_video_buffer *templat);438439/* nvc0_push.c */440void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *,441const struct pipe_draw_indirect_info *indirect,442const struct pipe_draw_start_count_bias *draw);443void nvc0_push_vbo_indirect(struct nvc0_context *, const struct pipe_draw_info *,444unsigned drawid_offset,445const struct pipe_draw_indirect_info *indirect,446const struct pipe_draw_start_count_bias *draw);447448/* nve4_compute.c */449void nve4_launch_grid(struct pipe_context *, const struct pipe_grid_info *);450451/* nvc0_compute.c */452void nvc0_launch_grid(struct pipe_context *, const struct pipe_grid_info *);453void nvc0_compute_validate_globals(struct nvc0_context *);454void nvc0_update_compute_invocations_counter(struct nvc0_context *nvc0,455const struct pipe_grid_info *info);456457#endif458459460