Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_context.h
4570 views
/*1* Copyright © 2014 Broadcom2* Copyright (C) 2012 Rob Clark <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS21* IN THE SOFTWARE.22*/2324#ifndef VC4_CONTEXT_H25#define VC4_CONTEXT_H2627#include <stdio.h>2829#include "pipe/p_context.h"30#include "pipe/p_state.h"31#include "util/slab.h"32#include "xf86drm.h"3334#define __user35#include "drm-uapi/vc4_drm.h"36#include "vc4_bufmgr.h"37#include "vc4_resource.h"38#include "vc4_cl.h"39#include "vc4_qir.h"4041#ifndef DRM_VC4_PARAM_SUPPORTS_ETC142#define DRM_VC4_PARAM_SUPPORTS_ETC1 443#endif44#ifndef DRM_VC4_PARAM_SUPPORTS_THREADED_FS45#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 546#endif4748#ifdef USE_VC4_SIMULATOR49#define using_vc4_simulator true50#else51#define using_vc4_simulator false52#endif5354#define VC4_DIRTY_BLEND (1 << 0)55#define VC4_DIRTY_RASTERIZER (1 << 1)56#define VC4_DIRTY_ZSA (1 << 2)57#define VC4_DIRTY_FRAGTEX (1 << 3)58#define VC4_DIRTY_VERTTEX (1 << 4)5960#define VC4_DIRTY_BLEND_COLOR (1 << 7)61#define VC4_DIRTY_STENCIL_REF (1 << 8)62#define VC4_DIRTY_SAMPLE_MASK (1 << 9)63#define VC4_DIRTY_FRAMEBUFFER (1 << 10)64#define VC4_DIRTY_STIPPLE (1 << 11)65#define VC4_DIRTY_VIEWPORT (1 << 12)66#define VC4_DIRTY_CONSTBUF (1 << 13)67#define VC4_DIRTY_VTXSTATE (1 << 14)68#define VC4_DIRTY_VTXBUF (1 << 15)6970#define VC4_DIRTY_SCISSOR (1 << 17)71#define VC4_DIRTY_FLAT_SHADE_FLAGS (1 << 18)72#define VC4_DIRTY_PRIM_MODE (1 << 19)73#define VC4_DIRTY_CLIP (1 << 20)74#define VC4_DIRTY_UNCOMPILED_VS (1 << 21)75#define VC4_DIRTY_UNCOMPILED_FS (1 << 22)76#define VC4_DIRTY_COMPILED_CS (1 << 23)77#define VC4_DIRTY_COMPILED_VS (1 << 24)78#define VC4_DIRTY_COMPILED_FS (1 << 25)79#define VC4_DIRTY_FS_INPUTS (1 << 26)80#define VC4_DIRTY_UBO_1_SIZE (1 << 27)8182struct vc4_sampler_view {83struct pipe_sampler_view base;84uint32_t texture_p0;85uint32_t texture_p1;86bool force_first_level;87/**88* Resource containing the actual texture that will be sampled.89*90* We may need to rebase the .base.texture resource to work around the91* lack of GL_TEXTURE_BASE_LEVEL, or to upload the texture as tiled.92*/93struct pipe_resource *texture;94};9596struct vc4_sampler_state {97struct pipe_sampler_state base;98uint32_t texture_p1;99};100101struct vc4_texture_stateobj {102struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];103unsigned num_textures;104struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];105unsigned num_samplers;106};107108struct vc4_shader_uniform_info {109enum quniform_contents *contents;110uint32_t *data;111uint32_t count;112uint32_t num_texture_samples;113};114115struct vc4_uncompiled_shader {116/** A name for this program, so you can track it in shader-db output. */117uint32_t program_id;118/** How many variants of this program were compiled, for shader-db. */119uint32_t compiled_variant_count;120struct pipe_shader_state base;121};122123struct vc4_fs_inputs {124/**125* Array of the meanings of the VPM inputs this shader needs.126*127* It doesn't include those that aren't part of the VPM, like128* point/line coordinates.129*/130struct vc4_varying_slot *input_slots;131uint32_t num_inputs;132};133134struct vc4_compiled_shader {135uint64_t program_id;136struct vc4_bo *bo;137138struct vc4_shader_uniform_info uniforms;139140/**141* VC4_DIRTY_* flags that, when set in vc4->dirty, mean that the142* uniforms have to be rewritten (and therefore the shader state143* reemitted).144*/145uint32_t uniform_dirty_bits;146147/** bitmask of which inputs are color inputs, for flat shade handling. */148uint32_t color_inputs;149150bool disable_early_z;151152/* Set if the compile failed, likely due to register allocation153* failure. In this case, we have no shader to run and should not try154* to do any draws.155*/156bool failed;157158bool fs_threaded;159160uint8_t num_inputs;161162/* Byte offsets for the start of the vertex attributes 0-7, and the163* total size as "attribute" 8.164*/165uint8_t vattr_offsets[9];166uint8_t vattrs_live;167168const struct vc4_fs_inputs *fs_inputs;169};170171struct vc4_program_stateobj {172struct vc4_uncompiled_shader *bind_vs, *bind_fs;173struct vc4_compiled_shader *cs, *vs, *fs;174};175176struct vc4_constbuf_stateobj {177struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];178uint32_t enabled_mask;179uint32_t dirty_mask;180};181182struct vc4_vertexbuf_stateobj {183struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];184unsigned count;185uint32_t enabled_mask;186uint32_t dirty_mask;187};188189struct vc4_vertex_stateobj {190struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];191unsigned num_elements;192};193194/* Hash table key for vc4->jobs */195struct vc4_job_key {196struct pipe_surface *cbuf;197struct pipe_surface *zsbuf;198};199200struct vc4_hwperfmon {201uint32_t id;202uint64_t last_seqno;203uint8_t events[DRM_VC4_MAX_PERF_COUNTERS];204uint64_t counters[DRM_VC4_MAX_PERF_COUNTERS];205};206207/**208* A complete bin/render job.209*210* This is all of the state necessary to submit a bin/render to the kernel.211* We want to be able to have multiple in progress at a time, so that we don't212* need to flush an existing CL just to switch to rendering to a new render213* target (which would mean reading back from the old render target when214* starting to render to it again).215*/216struct vc4_job {217struct vc4_cl bcl;218struct vc4_cl shader_rec;219struct vc4_cl uniforms;220struct vc4_cl bo_handles;221struct vc4_cl bo_pointers;222uint32_t shader_rec_count;223/**224* Amount of memory used by the BOs in bo_pointers.225*226* Used for checking when we should flush the job early so we don't227* OOM.228*/229uint32_t bo_space;230231/* Last BO hindex referenced from VC4_PACKET_GEM_HANDLES. */232uint32_t last_gem_handle_hindex;233234/** @{ Surfaces to submit rendering for. */235struct pipe_surface *color_read;236struct pipe_surface *color_write;237struct pipe_surface *zs_read;238struct pipe_surface *zs_write;239struct pipe_surface *msaa_color_write;240struct pipe_surface *msaa_zs_write;241/** @} */242/** @{243* Bounding box of the scissor across all queued drawing.244*245* Note that the max values are exclusive.246*/247uint32_t draw_min_x;248uint32_t draw_min_y;249uint32_t draw_max_x;250uint32_t draw_max_y;251/** @} */252/** @{253* Width/height of the color framebuffer being rendered to,254* for VC4_TILE_RENDERING_MODE_CONFIG.255*/256uint32_t draw_width;257uint32_t draw_height;258/** @} */259/** @{ Tile information, depending on MSAA and float color buffer. */260uint32_t draw_tiles_x; /** @< Number of tiles wide for framebuffer. */261uint32_t draw_tiles_y; /** @< Number of tiles high for framebuffer. */262263uint32_t tile_width; /** @< Width of a tile. */264uint32_t tile_height; /** @< Height of a tile. */265/** Whether the current rendering is in a 4X MSAA tile buffer. */266bool msaa;267/** @} */268269/* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the270* first rendering.271*/272uint32_t cleared;273/* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to274* (either clears or draws).275*/276uint32_t resolve;277uint32_t clear_color[2];278uint32_t clear_depth; /**< 24-bit unorm depth */279uint8_t clear_stencil;280281/**282* Set if some drawing (triangles, blits, or just a glClear()) has283* been done to the FBO, meaning that we need to284* DRM_IOCTL_VC4_SUBMIT_CL.285*/286bool needs_flush;287288/**289* Number of draw calls (not counting full buffer clears) queued in290* the current job.291*/292uint32_t draw_calls_queued;293294/** Any flags to be passed in drm_vc4_submit_cl.flags. */295uint32_t flags;296297/* Performance monitor attached to this job. */298struct vc4_hwperfmon *perfmon;299300struct vc4_job_key key;301};302303struct vc4_context {304struct pipe_context base;305306int fd;307struct vc4_screen *screen;308309/** The 3D rendering job for the currently bound FBO. */310struct vc4_job *job;311312/* Map from struct vc4_job_key to the job for that FBO.313*/314struct hash_table *jobs;315316/**317* Map from vc4_resource to a job writing to that resource.318*319* Primarily for flushing jobs rendering to textures that are now320* being read from.321*/322struct hash_table *write_jobs;323324struct slab_child_pool transfer_pool;325struct blitter_context *blitter;326327/** bitfield of VC4_DIRTY_* */328uint32_t dirty;329330struct primconvert_context *primconvert;331332struct hash_table *fs_cache, *vs_cache;333struct set *fs_inputs_set;334uint32_t next_uncompiled_program_id;335uint64_t next_compiled_program_id;336337struct ra_regs *regs;338struct ra_class *reg_class_any[2];339struct ra_class *reg_class_a_or_b[2];340struct ra_class *reg_class_a_or_b_or_acc[2];341struct ra_class *reg_class_r0_r3;342struct ra_class *reg_class_r4_or_a[2];343struct ra_class *reg_class_a[2];344345uint8_t prim_mode;346347/** Maximum index buffer valid for the current shader_rec. */348uint32_t max_index;349/** Last index bias baked into the current shader_rec. */350uint32_t last_index_bias;351352/** Seqno of the last CL flush's job. */353uint64_t last_emit_seqno;354355struct u_upload_mgr *uploader;356357struct pipe_shader_state *yuv_linear_blit_vs;358struct pipe_shader_state *yuv_linear_blit_fs_8bit;359struct pipe_shader_state *yuv_linear_blit_fs_16bit;360361/** @{ Current pipeline state objects */362struct pipe_scissor_state scissor;363struct pipe_blend_state *blend;364struct vc4_rasterizer_state *rasterizer;365struct vc4_depth_stencil_alpha_state *zsa;366367struct vc4_texture_stateobj verttex, fragtex;368369struct vc4_program_stateobj prog;370371struct vc4_vertex_stateobj *vtx;372373struct {374struct pipe_blend_color f;375uint8_t ub[4];376} blend_color;377struct pipe_stencil_ref stencil_ref;378unsigned sample_mask;379struct pipe_framebuffer_state framebuffer;380struct pipe_poly_stipple stipple;381struct pipe_clip_state clip;382struct pipe_viewport_state viewport;383struct vc4_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];384struct vc4_vertexbuf_stateobj vertexbuf;385struct pipe_debug_callback debug;386387struct vc4_hwperfmon *perfmon;388/** @} */389390/** Handle of syncobj containing the last submitted job fence. */391uint32_t job_syncobj;392393int in_fence_fd;394/** Handle of the syncobj that holds in_fence_fd for submission. */395uint32_t in_syncobj;396};397398struct vc4_rasterizer_state {399struct pipe_rasterizer_state base;400401/* VC4_CONFIGURATION_BITS */402uint8_t config_bits[V3D21_CONFIGURATION_BITS_length];403404struct PACKED {405uint8_t depth_offset[V3D21_DEPTH_OFFSET_length];406uint8_t point_size[V3D21_POINT_SIZE_length];407uint8_t line_width[V3D21_LINE_WIDTH_length];408} packed;409410/** Raster order flags to be passed in struct drm_vc4_submit_cl.flags. */411uint32_t tile_raster_order_flags;412};413414struct vc4_depth_stencil_alpha_state {415struct pipe_depth_stencil_alpha_state base;416417/* VC4_CONFIGURATION_BITS */418uint8_t config_bits[V3D21_CONFIGURATION_BITS_length];419420/** Uniforms for stencil state.421*422* Index 0 is either the front config, or the front-and-back config.423* Index 1 is the back config if doing separate back stencil.424* Index 2 is the writemask config if it's not a common mask value.425*/426uint32_t stencil_uniforms[3];427};428429#define perf_debug(...) do { \430if (unlikely(vc4_debug & VC4_DEBUG_PERF)) \431fprintf(stderr, __VA_ARGS__); \432if (unlikely(vc4->debug.debug_message)) \433pipe_debug_message(&vc4->debug, PERF_INFO, __VA_ARGS__); \434} while (0)435436static inline struct vc4_context *437vc4_context(struct pipe_context *pcontext)438{439return (struct vc4_context *)pcontext;440}441442static inline struct vc4_sampler_view *443vc4_sampler_view(struct pipe_sampler_view *psview)444{445return (struct vc4_sampler_view *)psview;446}447448static inline struct vc4_sampler_state *449vc4_sampler_state(struct pipe_sampler_state *psampler)450{451return (struct vc4_sampler_state *)psampler;452}453454int vc4_get_driver_query_group_info(struct pipe_screen *pscreen,455unsigned index,456struct pipe_driver_query_group_info *info);457int vc4_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,458struct pipe_driver_query_info *info);459460struct pipe_context *vc4_context_create(struct pipe_screen *pscreen,461void *priv, unsigned flags);462void vc4_draw_init(struct pipe_context *pctx);463void vc4_state_init(struct pipe_context *pctx);464void vc4_program_init(struct pipe_context *pctx);465void vc4_program_fini(struct pipe_context *pctx);466void vc4_query_init(struct pipe_context *pctx);467void vc4_simulator_init(struct vc4_screen *screen);468void vc4_simulator_destroy(struct vc4_screen *screen);469int vc4_simulator_ioctl(int fd, unsigned long request, void *arg);470void vc4_simulator_open_from_handle(int fd, int handle, uint32_t size);471472static inline int473vc4_ioctl(int fd, unsigned long request, void *arg)474{475if (using_vc4_simulator)476return vc4_simulator_ioctl(fd, request, arg);477else478return drmIoctl(fd, request, arg);479}480481void vc4_set_shader_uniform_dirty_flags(struct vc4_compiled_shader *shader);482void vc4_write_uniforms(struct vc4_context *vc4,483struct vc4_compiled_shader *shader,484struct vc4_constbuf_stateobj *cb,485struct vc4_texture_stateobj *texstate);486487void vc4_flush(struct pipe_context *pctx);488int vc4_job_init(struct vc4_context *vc4);489int vc4_fence_context_init(struct vc4_context *vc4);490struct vc4_job *vc4_get_job(struct vc4_context *vc4,491struct pipe_surface *cbuf,492struct pipe_surface *zsbuf);493struct vc4_job *vc4_get_job_for_fbo(struct vc4_context *vc4);494495void vc4_job_submit(struct vc4_context *vc4, struct vc4_job *job);496void vc4_flush_jobs_writing_resource(struct vc4_context *vc4,497struct pipe_resource *prsc);498void vc4_flush_jobs_reading_resource(struct vc4_context *vc4,499struct pipe_resource *prsc);500void vc4_emit_state(struct pipe_context *pctx);501void vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c);502struct qpu_reg *vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c);503bool vc4_update_compiled_shaders(struct vc4_context *vc4, uint8_t prim_mode);504505bool vc4_rt_format_supported(enum pipe_format f);506bool vc4_rt_format_is_565(enum pipe_format f);507bool vc4_tex_format_supported(enum pipe_format f);508uint8_t vc4_get_tex_format(enum pipe_format f);509const uint8_t *vc4_get_format_swizzle(enum pipe_format f);510void vc4_init_query_functions(struct vc4_context *vc4);511void vc4_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info);512void vc4_blitter_save(struct vc4_context *vc4);513#endif /* VC4_CONTEXT_H */514515516