Path: blob/21.2-virgl/src/gallium/drivers/lima/lima_context.h
4565 views
/*1* Copyright (c) 2017-2019 Lima Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sub license,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the11* next paragraph) shall be included in all copies or substantial portions12* of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*22*/2324#ifndef H_LIMA_CONTEXT25#define H_LIMA_CONTEXT2627#include "util/list.h"28#include "util/slab.h"2930#include "pipe/p_context.h"31#include "pipe/p_state.h"3233struct lima_context_framebuffer {34struct pipe_framebuffer_state base;35int tiled_w, tiled_h;36int shift_w, shift_h;37int block_w, block_h;38int shift_min;39};4041struct lima_depth_stencil_alpha_state {42struct pipe_depth_stencil_alpha_state base;43};4445struct lima_fs_compiled_shader {46struct lima_bo *bo;47void *shader;48struct {49int shader_size;50int stack_size;51bool uses_discard;52} state;53};5455struct lima_fs_uncompiled_shader {56struct pipe_shader_state base;57unsigned char nir_sha1[20];58};5960struct lima_fs_key {61unsigned char nir_sha1[20];62struct {63uint8_t swizzle[4];64} tex[PIPE_MAX_SAMPLERS];65};6667#define LIMA_MAX_VARYING_NUM 136869struct lima_varying_info {70int components;71int component_size;72int offset;73};7475struct lima_vs_compiled_shader {76struct lima_bo *bo;77void *shader;78void *constant;79struct {80int shader_size;81int prefetch;82int uniform_size;83int constant_size;84struct lima_varying_info varying[LIMA_MAX_VARYING_NUM];85int varying_stride;86int num_outputs;87int num_varyings;88int gl_pos_idx;89int point_size_idx;90} state;91};9293struct lima_vs_uncompiled_shader {94struct pipe_shader_state base;95unsigned char nir_sha1[20];96};9798struct lima_vs_key {99unsigned char nir_sha1[20];100};101102struct lima_rasterizer_state {103struct pipe_rasterizer_state base;104};105106struct lima_blend_state {107struct pipe_blend_state base;108};109110struct lima_vertex_element_state {111struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];112unsigned num_elements;113};114115struct lima_context_vertex_buffer {116struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];117unsigned count;118uint32_t enabled_mask;119};120121struct lima_context_viewport_state {122struct pipe_viewport_state transform;123float left, right, bottom, top;124float near, far;125};126127struct lima_context_constant_buffer {128const void *buffer;129uint32_t size;130bool dirty;131};132133enum lima_ctx_buff {134lima_ctx_buff_gp_varying_info,135lima_ctx_buff_gp_attribute_info,136lima_ctx_buff_gp_uniform,137lima_ctx_buff_pp_plb_rsw,138lima_ctx_buff_pp_uniform_array,139lima_ctx_buff_pp_uniform,140lima_ctx_buff_pp_tex_desc,141lima_ctx_buff_num,142lima_ctx_buff_num_gp = lima_ctx_buff_pp_plb_rsw,143};144145struct lima_ctx_buff_state {146struct pipe_resource *res;147unsigned offset;148unsigned size;149};150151struct lima_texture_stateobj {152struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS];153unsigned num_textures;154struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];155unsigned num_samplers;156};157158struct lima_ctx_plb_pp_stream_key {159uint16_t plb_index;160/* Coordinates are in tiles */161uint16_t minx, miny, maxx, maxy;162/* FB params */163uint16_t shift_w, shift_h;164uint16_t block_w, block_h;165};166167struct lima_ctx_plb_pp_stream {168struct list_head lru_list;169struct lima_ctx_plb_pp_stream_key key;170struct lima_bo *bo;171uint32_t offset[8];172};173174struct lima_pp_stream_state {175void *map;176uint32_t va;177uint32_t offset[8];178};179180struct lima_context {181struct pipe_context base;182183enum {184LIMA_CONTEXT_DIRTY_FRAMEBUFFER = (1 << 0),185LIMA_CONTEXT_DIRTY_CLEAR = (1 << 1),186LIMA_CONTEXT_DIRTY_COMPILED_VS = (1 << 2),187LIMA_CONTEXT_DIRTY_COMPILED_FS = (1 << 3),188LIMA_CONTEXT_DIRTY_VERTEX_ELEM = (1 << 4),189LIMA_CONTEXT_DIRTY_VERTEX_BUFF = (1 << 5),190LIMA_CONTEXT_DIRTY_VIEWPORT = (1 << 6),191LIMA_CONTEXT_DIRTY_SCISSOR = (1 << 7),192LIMA_CONTEXT_DIRTY_RASTERIZER = (1 << 8),193LIMA_CONTEXT_DIRTY_ZSA = (1 << 9),194LIMA_CONTEXT_DIRTY_BLEND_COLOR = (1 << 10),195LIMA_CONTEXT_DIRTY_BLEND = (1 << 11),196LIMA_CONTEXT_DIRTY_STENCIL_REF = (1 << 12),197LIMA_CONTEXT_DIRTY_CONST_BUFF = (1 << 13),198LIMA_CONTEXT_DIRTY_TEXTURES = (1 << 14),199LIMA_CONTEXT_DIRTY_CLIP = (1 << 15),200LIMA_CONTEXT_DIRTY_UNCOMPILED_VS = (1 << 16),201LIMA_CONTEXT_DIRTY_UNCOMPILED_FS = (1 << 17),202} dirty;203204struct u_upload_mgr *uploader;205struct blitter_context *blitter;206207struct slab_child_pool transfer_pool;208209struct lima_context_framebuffer framebuffer;210struct lima_context_viewport_state viewport;211struct pipe_scissor_state scissor;212struct pipe_scissor_state clipped_scissor;213struct lima_vs_compiled_shader *vs;214struct lima_fs_compiled_shader *fs;215struct lima_vs_uncompiled_shader *uncomp_vs;216struct lima_fs_uncompiled_shader *uncomp_fs;217struct lima_vertex_element_state *vertex_elements;218struct lima_context_vertex_buffer vertex_buffers;219struct lima_rasterizer_state *rasterizer;220struct lima_depth_stencil_alpha_state *zsa;221struct pipe_blend_color blend_color;222struct lima_blend_state *blend;223struct pipe_stencil_ref stencil_ref;224struct pipe_clip_state clip;225struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES];226struct lima_texture_stateobj tex_stateobj;227struct lima_pp_stream_state pp_stream;228229unsigned min_index;230unsigned max_index;231232#define LIMA_CTX_PLB_MIN_NUM 1233#define LIMA_CTX_PLB_MAX_NUM 4234#define LIMA_CTX_PLB_DEF_NUM 2235#define LIMA_CTX_PLB_BLK_SIZE 512236unsigned plb_size;237unsigned plb_gp_size;238239struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM];240struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM];241uint32_t gp_tile_heap_size;242struct lima_bo *plb_gp_stream;243struct lima_bo *gp_output;244uint32_t gp_output_varyings_offt;245uint32_t gp_output_point_size_offt;246247struct hash_table *plb_pp_stream;248struct list_head plb_pp_stream_lru_list;249uint32_t plb_index;250size_t plb_stream_cache_size;251252struct hash_table *fs_cache;253struct hash_table *vs_cache;254255struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num];256257/* current job */258struct lima_job *job;259260/* map from lima_job_key to lima_job */261struct hash_table *jobs;262263/* map from pipe_resource to lima_job which write to it */264struct hash_table *write_jobs;265266int in_sync_fd;267uint32_t in_sync[2];268uint32_t out_sync[2];269270int id;271272struct pipe_debug_callback debug;273274unsigned index_offset;275struct lima_resource *index_res;276};277278static inline struct lima_context *279lima_context(struct pipe_context *pctx)280{281return (struct lima_context *)pctx;282}283284struct lima_sampler_state {285struct pipe_sampler_state base;286};287288static inline struct lima_sampler_state *289lima_sampler_state(struct pipe_sampler_state *psstate)290{291return (struct lima_sampler_state *)psstate;292}293294struct lima_sampler_view {295struct pipe_sampler_view base;296uint8_t swizzle[4];297};298299static inline struct lima_sampler_view *300lima_sampler_view(struct pipe_sampler_view *psview)301{302return (struct lima_sampler_view *)psview;303}304305uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff);306void *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff);307void *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff,308unsigned size);309310void lima_state_init(struct lima_context *ctx);311void lima_state_fini(struct lima_context *ctx);312void lima_draw_init(struct lima_context *ctx);313void lima_program_init(struct lima_context *ctx);314void lima_program_fini(struct lima_context *ctx);315void lima_query_init(struct lima_context *ctx);316317struct pipe_context *318lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);319320void lima_flush(struct lima_context *ctx);321void lima_flush_job_accessing_bo(322struct lima_context *ctx, struct lima_bo *bo, bool write);323void lima_flush_previous_job_writing_resource(324struct lima_context *ctx, struct pipe_resource *prsc);325326#endif327328329