"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/drivers/lima/lima_context.h" (16 Sep 2020, 8304 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lima_context.h" see the Fossies "Dox" file reference documentation.

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