1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2017-2019 Lima Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 12bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 13bf215546Sopenharmony_ci * of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#ifndef H_LIMA_CONTEXT 26bf215546Sopenharmony_ci#define H_LIMA_CONTEXT 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "util/list.h" 29bf215546Sopenharmony_ci#include "util/slab.h" 30bf215546Sopenharmony_ci#include "util/u_debug.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "pipe/p_context.h" 33bf215546Sopenharmony_ci#include "pipe/p_state.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_cistruct lima_context_framebuffer { 36bf215546Sopenharmony_ci struct pipe_framebuffer_state base; 37bf215546Sopenharmony_ci int tiled_w, tiled_h; 38bf215546Sopenharmony_ci int shift_w, shift_h; 39bf215546Sopenharmony_ci int block_w, block_h; 40bf215546Sopenharmony_ci int shift_min; 41bf215546Sopenharmony_ci}; 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_cistruct lima_depth_stencil_alpha_state { 44bf215546Sopenharmony_ci struct pipe_depth_stencil_alpha_state base; 45bf215546Sopenharmony_ci}; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_cistruct lima_fs_compiled_shader { 48bf215546Sopenharmony_ci struct lima_bo *bo; 49bf215546Sopenharmony_ci void *shader; 50bf215546Sopenharmony_ci struct { 51bf215546Sopenharmony_ci int shader_size; 52bf215546Sopenharmony_ci int stack_size; 53bf215546Sopenharmony_ci int frag_color0_reg; 54bf215546Sopenharmony_ci int frag_color1_reg; 55bf215546Sopenharmony_ci int frag_depth_reg; 56bf215546Sopenharmony_ci bool uses_discard; 57bf215546Sopenharmony_ci } state; 58bf215546Sopenharmony_ci}; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_cistruct lima_fs_uncompiled_shader { 61bf215546Sopenharmony_ci struct pipe_shader_state base; 62bf215546Sopenharmony_ci unsigned char nir_sha1[20]; 63bf215546Sopenharmony_ci}; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_cistruct lima_fs_key { 66bf215546Sopenharmony_ci unsigned char nir_sha1[20]; 67bf215546Sopenharmony_ci struct { 68bf215546Sopenharmony_ci uint8_t swizzle[4]; 69bf215546Sopenharmony_ci } tex[PIPE_MAX_SAMPLERS]; 70bf215546Sopenharmony_ci}; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci#define LIMA_MAX_VARYING_NUM 13 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_cistruct lima_varying_info { 75bf215546Sopenharmony_ci int components; 76bf215546Sopenharmony_ci int component_size; 77bf215546Sopenharmony_ci int offset; 78bf215546Sopenharmony_ci}; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_cistruct lima_vs_compiled_shader { 81bf215546Sopenharmony_ci struct lima_bo *bo; 82bf215546Sopenharmony_ci void *shader; 83bf215546Sopenharmony_ci void *constant; 84bf215546Sopenharmony_ci struct { 85bf215546Sopenharmony_ci int shader_size; 86bf215546Sopenharmony_ci int prefetch; 87bf215546Sopenharmony_ci int uniform_size; 88bf215546Sopenharmony_ci int constant_size; 89bf215546Sopenharmony_ci struct lima_varying_info varying[LIMA_MAX_VARYING_NUM]; 90bf215546Sopenharmony_ci int varying_stride; 91bf215546Sopenharmony_ci int num_outputs; 92bf215546Sopenharmony_ci int num_varyings; 93bf215546Sopenharmony_ci int gl_pos_idx; 94bf215546Sopenharmony_ci int point_size_idx; 95bf215546Sopenharmony_ci } state; 96bf215546Sopenharmony_ci}; 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_cistruct lima_vs_uncompiled_shader { 99bf215546Sopenharmony_ci struct pipe_shader_state base; 100bf215546Sopenharmony_ci unsigned char nir_sha1[20]; 101bf215546Sopenharmony_ci}; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_cistruct lima_vs_key { 104bf215546Sopenharmony_ci unsigned char nir_sha1[20]; 105bf215546Sopenharmony_ci}; 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_cistruct lima_rasterizer_state { 108bf215546Sopenharmony_ci struct pipe_rasterizer_state base; 109bf215546Sopenharmony_ci}; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_cistruct lima_blend_state { 112bf215546Sopenharmony_ci struct pipe_blend_state base; 113bf215546Sopenharmony_ci}; 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_cistruct lima_vertex_element_state { 116bf215546Sopenharmony_ci struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS]; 117bf215546Sopenharmony_ci unsigned num_elements; 118bf215546Sopenharmony_ci}; 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_cistruct lima_context_vertex_buffer { 121bf215546Sopenharmony_ci struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS]; 122bf215546Sopenharmony_ci unsigned count; 123bf215546Sopenharmony_ci uint32_t enabled_mask; 124bf215546Sopenharmony_ci}; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_cistruct lima_context_viewport_state { 127bf215546Sopenharmony_ci struct pipe_viewport_state transform; 128bf215546Sopenharmony_ci float left, right, bottom, top; 129bf215546Sopenharmony_ci float near, far; 130bf215546Sopenharmony_ci}; 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_cistruct lima_context_constant_buffer { 133bf215546Sopenharmony_ci const void *buffer; 134bf215546Sopenharmony_ci uint32_t size; 135bf215546Sopenharmony_ci bool dirty; 136bf215546Sopenharmony_ci}; 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_cienum lima_ctx_buff { 139bf215546Sopenharmony_ci lima_ctx_buff_gp_varying_info, 140bf215546Sopenharmony_ci lima_ctx_buff_gp_attribute_info, 141bf215546Sopenharmony_ci lima_ctx_buff_gp_uniform, 142bf215546Sopenharmony_ci lima_ctx_buff_pp_plb_rsw, 143bf215546Sopenharmony_ci lima_ctx_buff_pp_uniform_array, 144bf215546Sopenharmony_ci lima_ctx_buff_pp_uniform, 145bf215546Sopenharmony_ci lima_ctx_buff_pp_tex_desc, 146bf215546Sopenharmony_ci lima_ctx_buff_num, 147bf215546Sopenharmony_ci lima_ctx_buff_num_gp = lima_ctx_buff_pp_plb_rsw, 148bf215546Sopenharmony_ci}; 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_cistruct lima_ctx_buff_state { 151bf215546Sopenharmony_ci struct pipe_resource *res; 152bf215546Sopenharmony_ci unsigned offset; 153bf215546Sopenharmony_ci unsigned size; 154bf215546Sopenharmony_ci}; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_cistruct lima_texture_stateobj { 157bf215546Sopenharmony_ci struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS]; 158bf215546Sopenharmony_ci unsigned num_textures; 159bf215546Sopenharmony_ci struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; 160bf215546Sopenharmony_ci unsigned num_samplers; 161bf215546Sopenharmony_ci}; 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_cistruct lima_ctx_plb_pp_stream_key { 164bf215546Sopenharmony_ci uint16_t plb_index; 165bf215546Sopenharmony_ci /* Coordinates are in tiles */ 166bf215546Sopenharmony_ci uint16_t minx, miny, maxx, maxy; 167bf215546Sopenharmony_ci /* FB params */ 168bf215546Sopenharmony_ci uint16_t shift_w, shift_h; 169bf215546Sopenharmony_ci uint16_t block_w, block_h; 170bf215546Sopenharmony_ci}; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_cistruct lima_ctx_plb_pp_stream { 173bf215546Sopenharmony_ci struct list_head lru_list; 174bf215546Sopenharmony_ci struct lima_ctx_plb_pp_stream_key key; 175bf215546Sopenharmony_ci struct lima_bo *bo; 176bf215546Sopenharmony_ci uint32_t offset[8]; 177bf215546Sopenharmony_ci}; 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_cistruct lima_pp_stream_state { 180bf215546Sopenharmony_ci void *map; 181bf215546Sopenharmony_ci uint32_t va; 182bf215546Sopenharmony_ci uint32_t offset[8]; 183bf215546Sopenharmony_ci}; 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_cistruct lima_context { 186bf215546Sopenharmony_ci struct pipe_context base; 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci enum { 189bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_FRAMEBUFFER = (1 << 0), 190bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_CLEAR = (1 << 1), 191bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_COMPILED_VS = (1 << 2), 192bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_COMPILED_FS = (1 << 3), 193bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_VERTEX_ELEM = (1 << 4), 194bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_VERTEX_BUFF = (1 << 5), 195bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_VIEWPORT = (1 << 6), 196bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_SCISSOR = (1 << 7), 197bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_RASTERIZER = (1 << 8), 198bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_ZSA = (1 << 9), 199bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_BLEND_COLOR = (1 << 10), 200bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_BLEND = (1 << 11), 201bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_STENCIL_REF = (1 << 12), 202bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_CONST_BUFF = (1 << 13), 203bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_TEXTURES = (1 << 14), 204bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_CLIP = (1 << 15), 205bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_UNCOMPILED_VS = (1 << 16), 206bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_UNCOMPILED_FS = (1 << 17), 207bf215546Sopenharmony_ci LIMA_CONTEXT_DIRTY_SAMPLE_MASK = (1 << 18), 208bf215546Sopenharmony_ci } dirty; 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci struct u_upload_mgr *uploader; 211bf215546Sopenharmony_ci struct blitter_context *blitter; 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ci struct slab_child_pool transfer_pool; 214bf215546Sopenharmony_ci 215bf215546Sopenharmony_ci struct lima_context_framebuffer framebuffer; 216bf215546Sopenharmony_ci struct lima_context_viewport_state viewport; 217bf215546Sopenharmony_ci /* input for PLBU_CMD_VIEWPORT_* */ 218bf215546Sopenharmony_ci struct lima_context_viewport_state ext_viewport; 219bf215546Sopenharmony_ci struct pipe_scissor_state scissor; 220bf215546Sopenharmony_ci struct pipe_scissor_state clipped_scissor; 221bf215546Sopenharmony_ci struct lima_vs_compiled_shader *vs; 222bf215546Sopenharmony_ci struct lima_fs_compiled_shader *fs; 223bf215546Sopenharmony_ci struct lima_vs_uncompiled_shader *uncomp_vs; 224bf215546Sopenharmony_ci struct lima_fs_uncompiled_shader *uncomp_fs; 225bf215546Sopenharmony_ci struct lima_vertex_element_state *vertex_elements; 226bf215546Sopenharmony_ci struct lima_context_vertex_buffer vertex_buffers; 227bf215546Sopenharmony_ci struct lima_rasterizer_state *rasterizer; 228bf215546Sopenharmony_ci struct lima_depth_stencil_alpha_state *zsa; 229bf215546Sopenharmony_ci struct pipe_blend_color blend_color; 230bf215546Sopenharmony_ci struct lima_blend_state *blend; 231bf215546Sopenharmony_ci struct pipe_stencil_ref stencil_ref; 232bf215546Sopenharmony_ci struct pipe_clip_state clip; 233bf215546Sopenharmony_ci struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES]; 234bf215546Sopenharmony_ci struct lima_texture_stateobj tex_stateobj; 235bf215546Sopenharmony_ci struct lima_pp_stream_state pp_stream; 236bf215546Sopenharmony_ci 237bf215546Sopenharmony_ci #define LIMA_MAX_SAMPLES 4 238bf215546Sopenharmony_ci unsigned sample_mask; 239bf215546Sopenharmony_ci 240bf215546Sopenharmony_ci unsigned min_index; 241bf215546Sopenharmony_ci unsigned max_index; 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ci #define LIMA_CTX_PLB_MIN_NUM 1 244bf215546Sopenharmony_ci #define LIMA_CTX_PLB_MAX_NUM 4 245bf215546Sopenharmony_ci #define LIMA_CTX_PLB_DEF_NUM 2 246bf215546Sopenharmony_ci #define LIMA_CTX_PLB_BLK_SIZE 512 247bf215546Sopenharmony_ci unsigned plb_size; 248bf215546Sopenharmony_ci unsigned plb_gp_size; 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM]; 251bf215546Sopenharmony_ci struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM]; 252bf215546Sopenharmony_ci uint32_t gp_tile_heap_size; 253bf215546Sopenharmony_ci struct lima_bo *plb_gp_stream; 254bf215546Sopenharmony_ci struct lima_bo *gp_output; 255bf215546Sopenharmony_ci uint32_t gp_output_varyings_offt; 256bf215546Sopenharmony_ci uint32_t gp_output_point_size_offt; 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ci struct hash_table *plb_pp_stream; 259bf215546Sopenharmony_ci struct list_head plb_pp_stream_lru_list; 260bf215546Sopenharmony_ci uint32_t plb_index; 261bf215546Sopenharmony_ci size_t plb_stream_cache_size; 262bf215546Sopenharmony_ci 263bf215546Sopenharmony_ci struct hash_table *fs_cache; 264bf215546Sopenharmony_ci struct hash_table *vs_cache; 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num]; 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci /* current job */ 269bf215546Sopenharmony_ci struct lima_job *job; 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_ci /* map from lima_job_key to lima_job */ 272bf215546Sopenharmony_ci struct hash_table *jobs; 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_ci /* map from pipe_resource to lima_job which write to it */ 275bf215546Sopenharmony_ci struct hash_table *write_jobs; 276bf215546Sopenharmony_ci 277bf215546Sopenharmony_ci int in_sync_fd; 278bf215546Sopenharmony_ci uint32_t in_sync[2]; 279bf215546Sopenharmony_ci uint32_t out_sync[2]; 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_ci int id; 282bf215546Sopenharmony_ci 283bf215546Sopenharmony_ci struct util_debug_callback debug; 284bf215546Sopenharmony_ci 285bf215546Sopenharmony_ci unsigned index_offset; 286bf215546Sopenharmony_ci struct lima_resource *index_res; 287bf215546Sopenharmony_ci}; 288bf215546Sopenharmony_ci 289bf215546Sopenharmony_cistatic inline struct lima_context * 290bf215546Sopenharmony_cilima_context(struct pipe_context *pctx) 291bf215546Sopenharmony_ci{ 292bf215546Sopenharmony_ci return (struct lima_context *)pctx; 293bf215546Sopenharmony_ci} 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_cistruct lima_sampler_state { 296bf215546Sopenharmony_ci struct pipe_sampler_state base; 297bf215546Sopenharmony_ci}; 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_cistatic inline struct lima_sampler_state * 300bf215546Sopenharmony_cilima_sampler_state(struct pipe_sampler_state *psstate) 301bf215546Sopenharmony_ci{ 302bf215546Sopenharmony_ci return (struct lima_sampler_state *)psstate; 303bf215546Sopenharmony_ci} 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_cistruct lima_sampler_view { 306bf215546Sopenharmony_ci struct pipe_sampler_view base; 307bf215546Sopenharmony_ci uint8_t swizzle[4]; 308bf215546Sopenharmony_ci}; 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_cistatic inline struct lima_sampler_view * 311bf215546Sopenharmony_cilima_sampler_view(struct pipe_sampler_view *psview) 312bf215546Sopenharmony_ci{ 313bf215546Sopenharmony_ci return (struct lima_sampler_view *)psview; 314bf215546Sopenharmony_ci} 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_ciuint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff); 317bf215546Sopenharmony_civoid *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff); 318bf215546Sopenharmony_civoid *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff, 319bf215546Sopenharmony_ci unsigned size); 320bf215546Sopenharmony_ci 321bf215546Sopenharmony_civoid lima_state_init(struct lima_context *ctx); 322bf215546Sopenharmony_civoid lima_state_fini(struct lima_context *ctx); 323bf215546Sopenharmony_civoid lima_draw_init(struct lima_context *ctx); 324bf215546Sopenharmony_civoid lima_program_init(struct lima_context *ctx); 325bf215546Sopenharmony_civoid lima_program_fini(struct lima_context *ctx); 326bf215546Sopenharmony_civoid lima_query_init(struct lima_context *ctx); 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_cistruct pipe_context * 329bf215546Sopenharmony_cilima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags); 330bf215546Sopenharmony_ci 331bf215546Sopenharmony_civoid lima_flush(struct lima_context *ctx); 332bf215546Sopenharmony_civoid lima_flush_job_accessing_bo( 333bf215546Sopenharmony_ci struct lima_context *ctx, struct lima_bo *bo, bool write); 334bf215546Sopenharmony_civoid lima_flush_previous_job_writing_resource( 335bf215546Sopenharmony_ci struct lima_context *ctx, struct pipe_resource *prsc); 336bf215546Sopenharmony_ci 337bf215546Sopenharmony_ci#endif 338