19f464c52Smaya/* 29f464c52Smaya * Copyright (c) 2017-2019 Lima Project 39f464c52Smaya * 49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a 59f464c52Smaya * copy of this software and associated documentation files (the "Software"), 69f464c52Smaya * to deal in the Software without restriction, including without limitation 79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sub license, 89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the 99f464c52Smaya * Software is furnished to do so, subject to the following conditions: 109f464c52Smaya * 119f464c52Smaya * The above copyright notice and this permission notice (including the 129f464c52Smaya * next paragraph) shall be included in all copies or substantial portions 139f464c52Smaya * of the Software. 149f464c52Smaya * 159f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 169f464c52Smaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 179f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 189f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 199f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 209f464c52Smaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 219f464c52Smaya * DEALINGS IN THE SOFTWARE. 229f464c52Smaya * 239f464c52Smaya */ 249f464c52Smaya 259f464c52Smaya#ifndef H_LIMA_CONTEXT 269f464c52Smaya#define H_LIMA_CONTEXT 279f464c52Smaya 287ec681f3Smrg#include "util/list.h" 299f464c52Smaya#include "util/slab.h" 309f464c52Smaya 319f464c52Smaya#include "pipe/p_context.h" 329f464c52Smaya#include "pipe/p_state.h" 339f464c52Smaya 349f464c52Smayastruct lima_context_framebuffer { 359f464c52Smaya struct pipe_framebuffer_state base; 369f464c52Smaya int tiled_w, tiled_h; 379f464c52Smaya int shift_w, shift_h; 389f464c52Smaya int block_w, block_h; 399f464c52Smaya int shift_min; 409f464c52Smaya}; 419f464c52Smaya 429f464c52Smayastruct lima_depth_stencil_alpha_state { 439f464c52Smaya struct pipe_depth_stencil_alpha_state base; 449f464c52Smaya}; 459f464c52Smaya 467ec681f3Smrgstruct lima_fs_compiled_shader { 479f464c52Smaya struct lima_bo *bo; 487ec681f3Smrg void *shader; 497ec681f3Smrg struct { 507ec681f3Smrg int shader_size; 517ec681f3Smrg int stack_size; 527ec681f3Smrg bool uses_discard; 537ec681f3Smrg } state; 547ec681f3Smrg}; 557ec681f3Smrg 567ec681f3Smrgstruct lima_fs_uncompiled_shader { 577ec681f3Smrg struct pipe_shader_state base; 587ec681f3Smrg unsigned char nir_sha1[20]; 597ec681f3Smrg}; 607ec681f3Smrg 617ec681f3Smrgstruct lima_fs_key { 627ec681f3Smrg unsigned char nir_sha1[20]; 637ec681f3Smrg struct { 647ec681f3Smrg uint8_t swizzle[4]; 657ec681f3Smrg } tex[PIPE_MAX_SAMPLERS]; 669f464c52Smaya}; 679f464c52Smaya 689f464c52Smaya#define LIMA_MAX_VARYING_NUM 13 699f464c52Smaya 709f464c52Smayastruct lima_varying_info { 719f464c52Smaya int components; 729f464c52Smaya int component_size; 739f464c52Smaya int offset; 749f464c52Smaya}; 759f464c52Smaya 767ec681f3Smrgstruct lima_vs_compiled_shader { 777ec681f3Smrg struct lima_bo *bo; 789f464c52Smaya void *shader; 799f464c52Smaya void *constant; 807ec681f3Smrg struct { 817ec681f3Smrg int shader_size; 827ec681f3Smrg int prefetch; 837ec681f3Smrg int uniform_size; 847ec681f3Smrg int constant_size; 857ec681f3Smrg struct lima_varying_info varying[LIMA_MAX_VARYING_NUM]; 867ec681f3Smrg int varying_stride; 877ec681f3Smrg int num_outputs; 887ec681f3Smrg int num_varyings; 897ec681f3Smrg int gl_pos_idx; 907ec681f3Smrg int point_size_idx; 917ec681f3Smrg } state; 927ec681f3Smrg}; 939f464c52Smaya 947ec681f3Smrgstruct lima_vs_uncompiled_shader { 957ec681f3Smrg struct pipe_shader_state base; 967ec681f3Smrg unsigned char nir_sha1[20]; 977ec681f3Smrg}; 989f464c52Smaya 997ec681f3Smrgstruct lima_vs_key { 1007ec681f3Smrg unsigned char nir_sha1[20]; 1019f464c52Smaya}; 1029f464c52Smaya 1039f464c52Smayastruct lima_rasterizer_state { 1049f464c52Smaya struct pipe_rasterizer_state base; 1059f464c52Smaya}; 1069f464c52Smaya 1079f464c52Smayastruct lima_blend_state { 1089f464c52Smaya struct pipe_blend_state base; 1099f464c52Smaya}; 1109f464c52Smaya 1119f464c52Smayastruct lima_vertex_element_state { 1129f464c52Smaya struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS]; 1139f464c52Smaya unsigned num_elements; 1149f464c52Smaya}; 1159f464c52Smaya 1169f464c52Smayastruct lima_context_vertex_buffer { 1179f464c52Smaya struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS]; 1189f464c52Smaya unsigned count; 1199f464c52Smaya uint32_t enabled_mask; 1209f464c52Smaya}; 1219f464c52Smaya 1229f464c52Smayastruct lima_context_viewport_state { 1239f464c52Smaya struct pipe_viewport_state transform; 1247ec681f3Smrg float left, right, bottom, top; 1259f464c52Smaya float near, far; 1269f464c52Smaya}; 1279f464c52Smaya 1289f464c52Smayastruct lima_context_constant_buffer { 1299f464c52Smaya const void *buffer; 1309f464c52Smaya uint32_t size; 1319f464c52Smaya bool dirty; 1329f464c52Smaya}; 1339f464c52Smaya 1349f464c52Smayaenum lima_ctx_buff { 1359f464c52Smaya lima_ctx_buff_gp_varying_info, 1369f464c52Smaya lima_ctx_buff_gp_attribute_info, 1379f464c52Smaya lima_ctx_buff_gp_uniform, 1389f464c52Smaya lima_ctx_buff_pp_plb_rsw, 1399f464c52Smaya lima_ctx_buff_pp_uniform_array, 1409f464c52Smaya lima_ctx_buff_pp_uniform, 1419f464c52Smaya lima_ctx_buff_pp_tex_desc, 1429f464c52Smaya lima_ctx_buff_num, 1437ec681f3Smrg lima_ctx_buff_num_gp = lima_ctx_buff_pp_plb_rsw, 1449f464c52Smaya}; 1459f464c52Smaya 1469f464c52Smayastruct lima_ctx_buff_state { 1479f464c52Smaya struct pipe_resource *res; 1489f464c52Smaya unsigned offset; 1499f464c52Smaya unsigned size; 1509f464c52Smaya}; 1519f464c52Smaya 1529f464c52Smayastruct lima_texture_stateobj { 1539f464c52Smaya struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS]; 1549f464c52Smaya unsigned num_textures; 1559f464c52Smaya struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; 1569f464c52Smaya unsigned num_samplers; 1579f464c52Smaya}; 1589f464c52Smaya 1599f464c52Smayastruct lima_ctx_plb_pp_stream_key { 1607ec681f3Smrg uint16_t plb_index; 1617ec681f3Smrg /* Coordinates are in tiles */ 1627ec681f3Smrg uint16_t minx, miny, maxx, maxy; 1637ec681f3Smrg /* FB params */ 1647ec681f3Smrg uint16_t shift_w, shift_h; 1657ec681f3Smrg uint16_t block_w, block_h; 1669f464c52Smaya}; 1679f464c52Smaya 1689f464c52Smayastruct lima_ctx_plb_pp_stream { 1697ec681f3Smrg struct list_head lru_list; 1709f464c52Smaya struct lima_ctx_plb_pp_stream_key key; 1719f464c52Smaya struct lima_bo *bo; 1727ec681f3Smrg uint32_t offset[8]; 1739f464c52Smaya}; 1749f464c52Smaya 1759f464c52Smayastruct lima_pp_stream_state { 1767ec681f3Smrg void *map; 1777ec681f3Smrg uint32_t va; 1789f464c52Smaya uint32_t offset[8]; 1799f464c52Smaya}; 1809f464c52Smaya 1819f464c52Smayastruct lima_context { 1829f464c52Smaya struct pipe_context base; 1839f464c52Smaya 1849f464c52Smaya enum { 1859f464c52Smaya LIMA_CONTEXT_DIRTY_FRAMEBUFFER = (1 << 0), 1869f464c52Smaya LIMA_CONTEXT_DIRTY_CLEAR = (1 << 1), 1877ec681f3Smrg LIMA_CONTEXT_DIRTY_COMPILED_VS = (1 << 2), 1887ec681f3Smrg LIMA_CONTEXT_DIRTY_COMPILED_FS = (1 << 3), 1899f464c52Smaya LIMA_CONTEXT_DIRTY_VERTEX_ELEM = (1 << 4), 1909f464c52Smaya LIMA_CONTEXT_DIRTY_VERTEX_BUFF = (1 << 5), 1919f464c52Smaya LIMA_CONTEXT_DIRTY_VIEWPORT = (1 << 6), 1929f464c52Smaya LIMA_CONTEXT_DIRTY_SCISSOR = (1 << 7), 1939f464c52Smaya LIMA_CONTEXT_DIRTY_RASTERIZER = (1 << 8), 1949f464c52Smaya LIMA_CONTEXT_DIRTY_ZSA = (1 << 9), 1959f464c52Smaya LIMA_CONTEXT_DIRTY_BLEND_COLOR = (1 << 10), 1969f464c52Smaya LIMA_CONTEXT_DIRTY_BLEND = (1 << 11), 1979f464c52Smaya LIMA_CONTEXT_DIRTY_STENCIL_REF = (1 << 12), 1989f464c52Smaya LIMA_CONTEXT_DIRTY_CONST_BUFF = (1 << 13), 1999f464c52Smaya LIMA_CONTEXT_DIRTY_TEXTURES = (1 << 14), 2007ec681f3Smrg LIMA_CONTEXT_DIRTY_CLIP = (1 << 15), 2017ec681f3Smrg LIMA_CONTEXT_DIRTY_UNCOMPILED_VS = (1 << 16), 2027ec681f3Smrg LIMA_CONTEXT_DIRTY_UNCOMPILED_FS = (1 << 17), 2039f464c52Smaya } dirty; 2049f464c52Smaya 2059f464c52Smaya struct u_upload_mgr *uploader; 2069f464c52Smaya struct blitter_context *blitter; 2079f464c52Smaya 2089f464c52Smaya struct slab_child_pool transfer_pool; 2099f464c52Smaya 2109f464c52Smaya struct lima_context_framebuffer framebuffer; 2119f464c52Smaya struct lima_context_viewport_state viewport; 2129f464c52Smaya struct pipe_scissor_state scissor; 2137ec681f3Smrg struct pipe_scissor_state clipped_scissor; 2147ec681f3Smrg struct lima_vs_compiled_shader *vs; 2157ec681f3Smrg struct lima_fs_compiled_shader *fs; 2167ec681f3Smrg struct lima_vs_uncompiled_shader *uncomp_vs; 2177ec681f3Smrg struct lima_fs_uncompiled_shader *uncomp_fs; 2189f464c52Smaya struct lima_vertex_element_state *vertex_elements; 2199f464c52Smaya struct lima_context_vertex_buffer vertex_buffers; 2209f464c52Smaya struct lima_rasterizer_state *rasterizer; 2219f464c52Smaya struct lima_depth_stencil_alpha_state *zsa; 2229f464c52Smaya struct pipe_blend_color blend_color; 2239f464c52Smaya struct lima_blend_state *blend; 2249f464c52Smaya struct pipe_stencil_ref stencil_ref; 2257ec681f3Smrg struct pipe_clip_state clip; 2269f464c52Smaya struct lima_context_constant_buffer const_buffer[PIPE_SHADER_TYPES]; 2279f464c52Smaya struct lima_texture_stateobj tex_stateobj; 2289f464c52Smaya struct lima_pp_stream_state pp_stream; 2299f464c52Smaya 2309f464c52Smaya unsigned min_index; 2319f464c52Smaya unsigned max_index; 2329f464c52Smaya 2339f464c52Smaya #define LIMA_CTX_PLB_MIN_NUM 1 2349f464c52Smaya #define LIMA_CTX_PLB_MAX_NUM 4 2359f464c52Smaya #define LIMA_CTX_PLB_DEF_NUM 2 2369f464c52Smaya #define LIMA_CTX_PLB_BLK_SIZE 512 2379f464c52Smaya unsigned plb_size; 2389f464c52Smaya unsigned plb_gp_size; 2399f464c52Smaya 2409f464c52Smaya struct lima_bo *plb[LIMA_CTX_PLB_MAX_NUM]; 2419f464c52Smaya struct lima_bo *gp_tile_heap[LIMA_CTX_PLB_MAX_NUM]; 2427ec681f3Smrg uint32_t gp_tile_heap_size; 2439f464c52Smaya struct lima_bo *plb_gp_stream; 2447ec681f3Smrg struct lima_bo *gp_output; 2457ec681f3Smrg uint32_t gp_output_varyings_offt; 2467ec681f3Smrg uint32_t gp_output_point_size_offt; 2479f464c52Smaya 2489f464c52Smaya struct hash_table *plb_pp_stream; 2497ec681f3Smrg struct list_head plb_pp_stream_lru_list; 2509f464c52Smaya uint32_t plb_index; 2517ec681f3Smrg size_t plb_stream_cache_size; 2527ec681f3Smrg 2537ec681f3Smrg struct hash_table *fs_cache; 2547ec681f3Smrg struct hash_table *vs_cache; 2559f464c52Smaya 2569f464c52Smaya struct lima_ctx_buff_state buffer_state[lima_ctx_buff_num]; 2579f464c52Smaya 2587ec681f3Smrg /* current job */ 2597ec681f3Smrg struct lima_job *job; 2609f464c52Smaya 2617ec681f3Smrg /* map from lima_job_key to lima_job */ 2627ec681f3Smrg struct hash_table *jobs; 2637ec681f3Smrg 2647ec681f3Smrg /* map from pipe_resource to lima_job which write to it */ 2657ec681f3Smrg struct hash_table *write_jobs; 2667ec681f3Smrg 2677ec681f3Smrg int in_sync_fd; 2687ec681f3Smrg uint32_t in_sync[2]; 2697ec681f3Smrg uint32_t out_sync[2]; 2709f464c52Smaya 2719f464c52Smaya int id; 2727ec681f3Smrg 2737ec681f3Smrg struct pipe_debug_callback debug; 2747ec681f3Smrg 2757ec681f3Smrg unsigned index_offset; 2767ec681f3Smrg struct lima_resource *index_res; 2779f464c52Smaya}; 2789f464c52Smaya 2799f464c52Smayastatic inline struct lima_context * 2809f464c52Smayalima_context(struct pipe_context *pctx) 2819f464c52Smaya{ 2829f464c52Smaya return (struct lima_context *)pctx; 2839f464c52Smaya} 2849f464c52Smaya 2859f464c52Smayastruct lima_sampler_state { 2869f464c52Smaya struct pipe_sampler_state base; 2879f464c52Smaya}; 2889f464c52Smaya 2899f464c52Smayastatic inline struct lima_sampler_state * 2909f464c52Smayalima_sampler_state(struct pipe_sampler_state *psstate) 2919f464c52Smaya{ 2929f464c52Smaya return (struct lima_sampler_state *)psstate; 2939f464c52Smaya} 2949f464c52Smaya 2959f464c52Smayastruct lima_sampler_view { 2969f464c52Smaya struct pipe_sampler_view base; 2977ec681f3Smrg uint8_t swizzle[4]; 2989f464c52Smaya}; 2999f464c52Smaya 3009f464c52Smayastatic inline struct lima_sampler_view * 3019f464c52Smayalima_sampler_view(struct pipe_sampler_view *psview) 3029f464c52Smaya{ 3039f464c52Smaya return (struct lima_sampler_view *)psview; 3049f464c52Smaya} 3059f464c52Smaya 3067ec681f3Smrguint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff); 3079f464c52Smayavoid *lima_ctx_buff_map(struct lima_context *ctx, enum lima_ctx_buff buff); 3089f464c52Smayavoid *lima_ctx_buff_alloc(struct lima_context *ctx, enum lima_ctx_buff buff, 3097ec681f3Smrg unsigned size); 3109f464c52Smaya 3119f464c52Smayavoid lima_state_init(struct lima_context *ctx); 3129f464c52Smayavoid lima_state_fini(struct lima_context *ctx); 3139f464c52Smayavoid lima_draw_init(struct lima_context *ctx); 3149f464c52Smayavoid lima_program_init(struct lima_context *ctx); 3157ec681f3Smrgvoid lima_program_fini(struct lima_context *ctx); 3169f464c52Smayavoid lima_query_init(struct lima_context *ctx); 3179f464c52Smaya 3189f464c52Smayastruct pipe_context * 3199f464c52Smayalima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags); 3209f464c52Smaya 3219f464c52Smayavoid lima_flush(struct lima_context *ctx); 3227ec681f3Smrgvoid lima_flush_job_accessing_bo( 3237ec681f3Smrg struct lima_context *ctx, struct lima_bo *bo, bool write); 3247ec681f3Smrgvoid lima_flush_previous_job_writing_resource( 3257ec681f3Smrg struct lima_context *ctx, struct pipe_resource *prsc); 3269f464c52Smaya 3279f464c52Smaya#endif 328