Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nv50/nv50_context.h
4574 views
#ifndef __NV50_CONTEXT_H__1#define __NV50_CONTEXT_H__23#include "pipe/p_context.h"4#include "pipe/p_defines.h"5#include "pipe/p_state.h"67#include "util/u_memory.h"8#include "util/u_math.h"9#include "util/u_inlines.h"10#include "util/u_dynarray.h"1112#include "nv50/nv50_winsys.h"13#include "nv50/nv50_stateobj.h"14#include "nv50/nv50_screen.h"15#include "nv50/nv50_program.h"16#include "nv50/nv50_resource.h"17#include "nv50/nv50_transfer.h"18#include "nv50/nv50_query.h"1920#include "nouveau_context.h"21#include "nouveau_debug.h"22#include "nv_object.xml.h"23#include "nv_m2mf.xml.h"24#include "nv50/nv50_3ddefs.xml.h"25#include "nv50/nv50_3d.xml.h"26#include "nv50/nv50_2d.xml.h"27#include "nv50/nv50_compute.xml.h"2829// NOTE: the VS/GS/FS order is based on how command methods are laid out for30// TSC/TIC setting.31#define NV50_SHADER_STAGE_VERTEX 032#define NV50_SHADER_STAGE_GEOMETRY 133#define NV50_SHADER_STAGE_FRAGMENT 234#define NV50_SHADER_STAGE_COMPUTE 335#define NV50_MAX_SHADER_STAGES 43637#define NV50_MAX_3D_SHADER_STAGES 33839#define NV50_NEW_3D_BLEND (1 << 0)40#define NV50_NEW_3D_RASTERIZER (1 << 1)41#define NV50_NEW_3D_ZSA (1 << 2)42#define NV50_NEW_3D_VERTPROG (1 << 3)43#define NV50_NEW_3D_GMTYPROG (1 << 6)44#define NV50_NEW_3D_FRAGPROG (1 << 7)45#define NV50_NEW_3D_BLEND_COLOUR (1 << 8)46#define NV50_NEW_3D_STENCIL_REF (1 << 9)47#define NV50_NEW_3D_CLIP (1 << 10)48#define NV50_NEW_3D_SAMPLE_MASK (1 << 11)49#define NV50_NEW_3D_FRAMEBUFFER (1 << 12)50#define NV50_NEW_3D_STIPPLE (1 << 13)51#define NV50_NEW_3D_SCISSOR (1 << 14)52#define NV50_NEW_3D_VIEWPORT (1 << 15)53#define NV50_NEW_3D_ARRAYS (1 << 16)54#define NV50_NEW_3D_VERTEX (1 << 17)55#define NV50_NEW_3D_CONSTBUF (1 << 18)56#define NV50_NEW_3D_TEXTURES (1 << 19)57#define NV50_NEW_3D_SAMPLERS (1 << 20)58#define NV50_NEW_3D_STRMOUT (1 << 21)59#define NV50_NEW_3D_MIN_SAMPLES (1 << 22)60#define NV50_NEW_3D_WINDOW_RECTS (1 << 23)6162#define NV50_NEW_CP_PROGRAM (1 << 0)63#define NV50_NEW_CP_SURFACES (1 << 1)64#define NV50_NEW_CP_TEXTURES (1 << 2)65#define NV50_NEW_CP_SAMPLERS (1 << 3)66#define NV50_NEW_CP_CONSTBUF (1 << 4)67#define NV50_NEW_CP_GLOBALS (1 << 5)68#define NV50_NEW_CP_DRIVERCONST (1 << 6)69#define NV50_NEW_CP_BUFFERS (1 << 7)7071/* 3d bufctx (during draw_vbo, blit_3d) */72#define NV50_BIND_3D_FB 073#define NV50_BIND_3D_VERTEX 174#define NV50_BIND_3D_VERTEX_TMP 275#define NV50_BIND_3D_INDEX 376#define NV50_BIND_3D_TEXTURES 477#define NV50_BIND_3D_CB(s, i) (5 + 16 * (s) + (i))78#define NV50_BIND_3D_SO 5379#define NV50_BIND_3D_SCREEN 5480#define NV50_BIND_3D_TLS 5581#define NV50_BIND_3D_COUNT 568283/* compute bufctx (during launch_grid) */84#define NV50_BIND_CP_CB(i) ( 0 + (i))85#define NV50_BIND_CP_TEXTURES 1686#define NV50_BIND_CP_SUF 1787#define NV50_BIND_CP_BUF 1888#define NV50_BIND_CP_GLOBAL 1989#define NV50_BIND_CP_SCREEN 2090#define NV50_BIND_CP_QUERY 2191#define NV50_BIND_CP_COUNT 229293/* bufctx for other operations */94#define NV50_BIND_2D 095#define NV50_BIND_M2MF 096#define NV50_BIND_FENCE 19798/* fixed constant buffer binding points - low indices for user's constbufs */99#define NV50_CB_PVP 123100#define NV50_CB_PGP 124101#define NV50_CB_PFP 125102#define NV50_CB_PCP 126103/* constant buffer permanently mapped in as c15[] */104#define NV50_CB_AUX 127105/* size of the buffer: 64k. not all taken up, can be reduced if needed. */106#define NV50_CB_AUX_SIZE (1 << 16)107/* 8 user clip planes, at 4 32-bit floats each */108#define NV50_CB_AUX_UCP_OFFSET 0x0000109#define NV50_CB_AUX_UCP_SIZE (8 * 4 * 4)110/* 16 textures * NV50_MAX_SHADER_STAGES shaders, each with ms_x, ms_y u32 pairs */111#define NV50_CB_AUX_TEX_MS_OFFSET 0x0080112#define NV50_CB_AUX_TEX_MS_SIZE (16 * NV50_MAX_SHADER_STAGES * 2 * 4)113/* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */114#define NV50_CB_AUX_MS_OFFSET 0x280115#define NV50_CB_AUX_MS_SIZE (4 * 8 * 4 * 2)116/* Sample position pairs for the current output MS level */117#define NV50_CB_AUX_SAMPLE_OFFSET 0x380118#define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)119/* Alpha test ref value */120#define NV50_CB_AUX_ALPHATEST_OFFSET 0x3c0121#define NV50_CB_AUX_ALPHATEST_SIZE (4)122/* Compute buffer info: 16 surfaces, 12 32-bit integers each */123#define NV50_CB_AUX_BUF_INFO(i) (0x3c4 + (i) * 12 * 4)124#define NV50_CB_AUX_BUF_SIZE (NV50_MAX_GLOBALS * 12 * 4)125/* Compute membar mapped area */126#define NV50_CB_AUX_MEMBAR_OFFSET 0x6c4127/* next spot: 0x6c8 */128/* 0x800 from the end for compute shader membars, reads only. */129#define NV50_CB_AUX_MEMBAR (NV50_CB_AUX_SIZE - 0x800)130/* 4 32-bit floats for the vertex runout, put at the end */131#define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)132133134135struct nv50_blitctx;136137bool nv50_blitctx_create(struct nv50_context *);138139struct nv50_context {140struct nouveau_context base;141142struct nv50_screen *screen;143144struct nouveau_bufctx *bufctx_3d;145struct nouveau_bufctx *bufctx;146struct nouveau_bufctx *bufctx_cp;147148uint32_t dirty_3d; /* dirty flags for 3d state */149uint32_t dirty_cp; /* dirty flags for compute state */150bool cb_dirty;151152struct nv50_graph_state state;153154struct nv50_blend_stateobj *blend;155struct nv50_rasterizer_stateobj *rast;156struct nv50_zsa_stateobj *zsa;157struct nv50_vertex_stateobj *vertex;158159struct nv50_program *vertprog;160struct nv50_program *gmtyprog;161struct nv50_program *fragprog;162struct nv50_program *compprog;163164struct nv50_constbuf constbuf[NV50_MAX_SHADER_STAGES][NV50_MAX_PIPE_CONSTBUFS];165uint16_t constbuf_dirty[NV50_MAX_SHADER_STAGES];166uint16_t constbuf_valid[NV50_MAX_SHADER_STAGES];167uint16_t constbuf_coherent[NV50_MAX_SHADER_STAGES];168169struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];170unsigned num_vtxbufs;171uint32_t vtxbufs_coherent;172uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */173uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */174uint32_t vbo_constant; /* bitmask of user buffers with stride 0 */175uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */176uint32_t vb_elt_limit; /* max - min element (count - 1) */177uint32_t instance_off; /* base vertex for instanced arrays */178uint32_t instance_max; /* max instance for current draw call */179180struct pipe_sampler_view *textures[NV50_MAX_SHADER_STAGES][PIPE_MAX_SAMPLERS];181unsigned num_textures[NV50_MAX_SHADER_STAGES];182uint32_t textures_coherent[NV50_MAX_SHADER_STAGES];183struct nv50_tsc_entry *samplers[NV50_MAX_SHADER_STAGES][PIPE_MAX_SAMPLERS];184unsigned num_samplers[NV50_MAX_SHADER_STAGES];185bool seamless_cube_map;186187uint8_t num_so_targets;188uint8_t so_targets_dirty;189struct pipe_stream_output_target *so_target[4];190/* keeps track of how much of an SO is used. normally this doesn't work in191* the presence of GS, but this only needs to work for ES 3.0 which doesn't192* have GS or any other oddities. only used pre-NVA0.193*/194uint32_t so_used[4];195196struct pipe_framebuffer_state framebuffer;197struct pipe_blend_color blend_colour;198struct pipe_stencil_ref stencil_ref;199struct pipe_poly_stipple stipple;200struct pipe_scissor_state scissors[NV50_MAX_VIEWPORTS];201unsigned scissors_dirty;202struct pipe_viewport_state viewports[NV50_MAX_VIEWPORTS];203unsigned viewports_dirty;204struct pipe_clip_state clip;205struct nv50_window_rect_stateobj window_rect;206207unsigned sample_mask;208unsigned min_samples;209210bool vbo_push_hint;211212uint32_t rt_array_mode;213214struct pipe_query *cond_query;215bool cond_cond; /* inverted rendering condition */216uint cond_mode;217uint32_t cond_condmode; /* the calculated condition */218219struct nv50_blitctx *blit;220221/* compute stage only */222struct pipe_shader_buffer buffers[NV50_MAX_GLOBALS];223uint16_t buffers_dirty;224uint16_t buffers_valid;225226struct pipe_image_view images[NV50_MAX_GLOBALS];227uint16_t images_dirty;228uint16_t images_valid;229230struct util_dynarray global_residents;231232uint64_t compute_invocations;233};234235static inline struct nv50_context *236nv50_context(struct pipe_context *pipe)237{238return (struct nv50_context *)pipe;239}240241/* return index used in nv50_context arrays for a specific shader type */242static inline unsigned243nv50_context_shader_stage(unsigned pipe)244{245switch (pipe) {246case PIPE_SHADER_VERTEX: return NV50_SHADER_STAGE_VERTEX;247case PIPE_SHADER_FRAGMENT: return NV50_SHADER_STAGE_FRAGMENT;248case PIPE_SHADER_GEOMETRY: return NV50_SHADER_STAGE_GEOMETRY;249case PIPE_SHADER_COMPUTE: return NV50_SHADER_STAGE_COMPUTE;250default:251assert(!"invalid/unhandled shader type");252return 0;253}254}255256/* nv50_context.c */257struct pipe_context *nv50_create(struct pipe_screen *, void *, unsigned flags);258259void nv50_bufctx_fence(struct nouveau_bufctx *, bool on_flush);260261void nv50_default_kick_notify(struct nouveau_pushbuf *);262263/* nv50_draw.c */264extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);265266/* nv50_shader_state.c */267void nv50_vertprog_validate(struct nv50_context *);268void nv50_gmtyprog_validate(struct nv50_context *);269void nv50_fragprog_validate(struct nv50_context *);270void nv50_compprog_validate(struct nv50_context *);271void nv50_fp_linkage_validate(struct nv50_context *);272void nv50_gp_linkage_validate(struct nv50_context *);273void nv50_constbufs_validate(struct nv50_context *);274void nv50_validate_derived_rs(struct nv50_context *);275void nv50_stream_output_validate(struct nv50_context *);276277/* nv50_state.c */278extern void nv50_init_state_functions(struct nv50_context *);279280/* nv50_state_validate.c */281struct nv50_state_validate {282void (*func)(struct nv50_context *);283uint32_t states;284};285286bool nv50_state_validate(struct nv50_context *, uint32_t,287struct nv50_state_validate *, int, uint32_t *,288struct nouveau_bufctx *);289bool nv50_state_validate_3d(struct nv50_context *, uint32_t);290291/* nv50_surface.c */292extern void nv50_clear(struct pipe_context *, unsigned buffers,293const struct pipe_scissor_state *scissor_state,294const union pipe_color_union *color,295double depth, unsigned stencil);296extern void nv50_init_surface_functions(struct nv50_context *);297298/* nv50_tex.c */299bool nv50_validate_tic(struct nv50_context *nv50, int s);300void nv50_validate_textures(struct nv50_context *);301bool nv50_validate_tsc(struct nv50_context *nv50, int s);302void nv50_validate_samplers(struct nv50_context *);303void nv50_upload_ms_info(struct nouveau_pushbuf *);304void nv50_upload_tsc0(struct nv50_context *);305306struct pipe_sampler_view *307nv50_create_texture_view(struct pipe_context *,308struct pipe_resource *,309const struct pipe_sampler_view *,310uint32_t flags);311struct pipe_sampler_view *312nv50_create_sampler_view(struct pipe_context *,313struct pipe_resource *,314const struct pipe_sampler_view *);315316/* nv50_transfer.c */317void318nv50_m2mf_transfer_rect(struct nv50_context *,319const struct nv50_m2mf_rect *dst,320const struct nv50_m2mf_rect *src,321uint32_t nblocksx, uint32_t nblocksy);322void323nv50_sifc_linear_u8(struct nouveau_context *pipe,324struct nouveau_bo *dst, unsigned offset, unsigned domain,325unsigned size, const void *data);326void327nv50_m2mf_copy_linear(struct nouveau_context *pipe,328struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,329struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,330unsigned size);331void332nv50_cb_push(struct nouveau_context *nv,333struct nv04_resource *res,334unsigned offset, unsigned words, const uint32_t *data);335336/* nv50_vbo.c */337void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *, unsigned,338const struct pipe_draw_indirect_info *indirect,339const struct pipe_draw_start_count_bias *draws,340unsigned num_draws);341342void *343nv50_vertex_state_create(struct pipe_context *pipe,344unsigned num_elements,345const struct pipe_vertex_element *elements);346void347nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);348349void nv50_vertex_arrays_validate(struct nv50_context *nv50);350351/* nv50_push.c */352void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *,353const struct pipe_draw_indirect_info *indirect,354const struct pipe_draw_start_count_bias *draw);355356/* nv84_video.c */357struct pipe_video_codec *358nv84_create_decoder(struct pipe_context *context,359const struct pipe_video_codec *templ);360361struct pipe_video_buffer *362nv84_video_buffer_create(struct pipe_context *pipe,363const struct pipe_video_buffer *template);364365int366nv84_screen_get_video_param(struct pipe_screen *pscreen,367enum pipe_video_profile profile,368enum pipe_video_entrypoint entrypoint,369enum pipe_video_cap param);370371bool372nv84_screen_video_supported(struct pipe_screen *screen,373enum pipe_format format,374enum pipe_video_profile profile,375enum pipe_video_entrypoint entrypoint);376377/* nv98_video.c */378struct pipe_video_codec *379nv98_create_decoder(struct pipe_context *context,380const struct pipe_video_codec *templ);381382struct pipe_video_buffer *383nv98_video_buffer_create(struct pipe_context *pipe,384const struct pipe_video_buffer *template);385386/* nv50_compute.c */387void388nv50_launch_grid(struct pipe_context *, const struct pipe_grid_info *);389390#endif391392393