"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/auxiliary/draw/draw_llvm.h" (16 Sep 2020, 29565 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 "draw_llvm.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 20.1.5_vs_20.2.0-rc1.

    1 /**************************************************************************
    2  *
    3  * Copyright 2010 VMware, Inc.
    4  * All Rights Reserved.
    5  *
    6  * Permission is hereby granted, free of charge, to any person obtaining a
    7  * copy of this software and associated documentation files (the
    8  * "Software"), to deal in the Software without restriction, including
    9  * without limitation the rights to use, copy, modify, merge, publish,
   10  * distribute, sub license, and/or sell copies of the Software, and to
   11  * permit persons to whom the Software is furnished to do so, subject to
   12  * the following conditions:
   13  *
   14  * The above copyright notice and this permission notice (including the
   15  * next paragraph) shall be included in all copies or substantial portions
   16  * of the Software.
   17  *
   18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
   21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
   22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   25  *
   26  **************************************************************************/
   27 
   28 #ifndef DRAW_LLVM_H
   29 #define DRAW_LLVM_H
   30 
   31 #include "draw/draw_private.h"
   32 
   33 #include "draw/draw_vs.h"
   34 #include "draw/draw_gs.h"
   35 #include "draw/draw_tess.h"
   36 
   37 #include "gallivm/lp_bld_sample.h"
   38 #include "gallivm/lp_bld_limits.h"
   39 
   40 #include "pipe/p_context.h"
   41 #include "util/simple_list.h"
   42 
   43 
   44 struct draw_llvm;
   45 struct llvm_vertex_shader;
   46 struct llvm_geometry_shader;
   47 struct llvm_tess_ctrl_shader;
   48 struct llvm_tess_eval_shader;
   49 
   50 struct draw_jit_texture
   51 {
   52    uint32_t width;
   53    uint32_t height;
   54    uint32_t depth;
   55    const void *base;
   56    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
   57    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
   58    uint32_t first_level;
   59    uint32_t last_level;
   60    uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
   61 };
   62 
   63 
   64 struct draw_sampler_static_state
   65 {
   66    /*
   67     * These attributes are effectively interleaved for more sane key handling.
   68     * However, there might be lots of null space if the amount of samplers and
   69     * textures isn't the same.
   70     */
   71    struct lp_static_sampler_state sampler_state;
   72    struct lp_static_texture_state texture_state;
   73 };
   74 
   75 struct draw_image_static_state
   76 {
   77    struct lp_static_texture_state image_state;
   78 };
   79 
   80 
   81 struct draw_jit_sampler
   82 {
   83    float min_lod;
   84    float max_lod;
   85    float lod_bias;
   86    float border_color[4];
   87 };
   88 
   89 
   90 struct draw_jit_image
   91 {
   92    uint32_t width;
   93    uint32_t height;
   94    uint32_t depth;
   95    const void *base;
   96    uint32_t row_stride;
   97    uint32_t img_stride;
   98 };
   99 
  100 enum {
  101    DRAW_JIT_TEXTURE_WIDTH = 0,
  102    DRAW_JIT_TEXTURE_HEIGHT,
  103    DRAW_JIT_TEXTURE_DEPTH,
  104    DRAW_JIT_TEXTURE_BASE,
  105    DRAW_JIT_TEXTURE_ROW_STRIDE,
  106    DRAW_JIT_TEXTURE_IMG_STRIDE,
  107    DRAW_JIT_TEXTURE_FIRST_LEVEL,
  108    DRAW_JIT_TEXTURE_LAST_LEVEL,
  109    DRAW_JIT_TEXTURE_MIP_OFFSETS,
  110    DRAW_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
  111 };
  112 
  113 
  114 enum {
  115    DRAW_JIT_SAMPLER_MIN_LOD,
  116    DRAW_JIT_SAMPLER_MAX_LOD,
  117    DRAW_JIT_SAMPLER_LOD_BIAS,
  118    DRAW_JIT_SAMPLER_BORDER_COLOR,
  119    DRAW_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
  120 };
  121 
  122 
  123 enum {
  124    DRAW_JIT_VERTEX_VERTEX_ID = 0,
  125    DRAW_JIT_VERTEX_CLIP_POS,
  126    DRAW_JIT_VERTEX_DATA
  127 };
  128 
  129 enum {
  130    DRAW_JIT_IMAGE_WIDTH = 0,
  131    DRAW_JIT_IMAGE_HEIGHT,
  132    DRAW_JIT_IMAGE_DEPTH,
  133    DRAW_JIT_IMAGE_BASE,
  134    DRAW_JIT_IMAGE_ROW_STRIDE,
  135    DRAW_JIT_IMAGE_IMG_STRIDE,
  136    DRAW_JIT_IMAGE_NUM_FIELDS  /* number of fields above */
  137 };
  138 
  139 /**
  140  * This structure is passed directly to the generated vertex shader.
  141  *
  142  * It contains the derived state.
  143  *
  144  * Changes here must be reflected in the draw_jit_context_* macros.
  145  * Changes to the ordering should be avoided.
  146  *
  147  * Only use types with a clear size and padding here, in particular prefer the
  148  * stdint.h types to the basic integer types.
  149  */
  150 struct draw_jit_context
  151 {
  152    const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
  153    int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
  154    float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
  155    struct pipe_viewport_state *viewports;
  156 
  157    struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  158    struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
  159    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
  160 
  161    const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  162    int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  163 };
  164 
  165 enum {
  166    DRAW_JIT_CTX_CONSTANTS            = 0,
  167    DRAW_JIT_CTX_NUM_CONSTANTS        = 1,
  168    DRAW_JIT_CTX_PLANES               = 2,
  169    DRAW_JIT_CTX_VIEWPORT             = 3,
  170    DRAW_JIT_CTX_TEXTURES             = 4,
  171    DRAW_JIT_CTX_SAMPLERS             = 5,
  172    DRAW_JIT_CTX_IMAGES               = 6,
  173    DRAW_JIT_CTX_SSBOS                = 7,
  174    DRAW_JIT_CTX_NUM_SSBOS            = 8,
  175    DRAW_JIT_CTX_NUM_FIELDS
  176 };
  177 
  178 #define draw_jit_context_vs_constants(_gallivm, _ptr) \
  179    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
  180 
  181 #define draw_jit_context_num_vs_constants(_gallivm, _ptr) \
  182    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
  183 
  184 #define draw_jit_context_planes(_gallivm, _ptr) \
  185    lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
  186 
  187 #define draw_jit_context_viewports(_gallivm, _ptr) \
  188    lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
  189 
  190 #define draw_jit_context_textures(_gallivm, _ptr) \
  191    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
  192 
  193 #define draw_jit_context_samplers(_gallivm, _ptr) \
  194    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
  195 
  196 #define draw_jit_context_images(_gallivm, _ptr) \
  197    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
  198 
  199 #define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
  200    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
  201 
  202 #define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \
  203    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
  204 
  205 
  206 #define draw_jit_header_id(_gallivm, _ptr)              \
  207    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
  208 
  209 #define draw_jit_header_clip_pos(_gallivm, _ptr) \
  210    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
  211 
  212 #define draw_jit_header_data(_gallivm, _ptr)            \
  213    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")
  214 
  215 
  216 #define draw_jit_vbuffer_stride(_gallivm, _ptr)         \
  217    lp_build_struct_get(_gallivm, _ptr, 0, "stride")
  218 
  219 #define draw_jit_vbuffer_offset(_gallivm, _ptr)         \
  220    lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
  221 
  222 enum {
  223    DRAW_JIT_DVBUFFER_MAP = 0,
  224    DRAW_JIT_DVBUFFER_SIZE,
  225    DRAW_JIT_DVBUFFER_NUM_FIELDS  /* number of fields above */
  226 };
  227 
  228 #define draw_jit_dvbuffer_map(_gallivm, _ptr)         \
  229    lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
  230 
  231 #define draw_jit_dvbuffer_size(_gallivm, _ptr)        \
  232    lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")
  233 
  234 
  235 /**
  236  * This structure is passed directly to the generated geometry shader.
  237  *
  238  * It contains the derived state.
  239  *
  240  * Changes here must be reflected in the draw_gs_jit_context_* macros.
  241  * Changes to the ordering should be avoided.
  242  *
  243  * Only use types with a clear size and padding here, in particular prefer the
  244  * stdint.h types to the basic integer types.
  245  */
  246 struct draw_gs_jit_context
  247 {
  248    const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
  249    int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
  250    float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
  251    struct pipe_viewport_state *viewports;
  252 
  253    /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
  254     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
  255    struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  256    struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
  257    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
  258 
  259    int **prim_lengths;
  260    int *emitted_vertices;
  261    int *emitted_prims;
  262    const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  263    int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  264 
  265 };
  266 
  267 enum {
  268    DRAW_GS_JIT_CTX_CONSTANTS = 0,
  269    DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1,
  270    DRAW_GS_JIT_CTX_PLANES = 2,
  271    DRAW_GS_JIT_CTX_VIEWPORT = 3,
  272    /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
  273     * and DRAW_JIT_CTX_SAMPLERS, because they both need
  274     * to be at exactly the same locations as they are in the
  275     * VS ctx structure for sampling to work. */
  276    DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
  277    DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
  278    DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
  279    DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7,
  280    DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8,
  281    DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9,
  282    DRAW_GS_JIT_CTX_SSBOS = 10,
  283    DRAW_GS_JIT_CTX_NUM_SSBOS = 11,
  284    DRAW_GS_JIT_CTX_NUM_FIELDS = 12
  285 };
  286 
  287 #define draw_gs_jit_context_constants(_gallivm, _ptr) \
  288    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
  289 
  290 #define draw_gs_jit_context_num_constants(_gallivm, _ptr) \
  291    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")
  292 
  293 #define draw_gs_jit_context_planes(_gallivm, _ptr) \
  294    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
  295 
  296 #define draw_gs_jit_context_viewports(_gallivm, _ptr) \
  297    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")
  298 
  299 #define draw_gs_jit_context_textures(_gallivm, _ptr) \
  300    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
  301 
  302 #define draw_gs_jit_context_samplers(_gallivm, _ptr) \
  303    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
  304 
  305 #define draw_gs_jit_context_images(_gallivm, _ptr)                      \
  306    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
  307 
  308 #define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
  309    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
  310 
  311 #define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
  312    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
  313 
  314 #define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
  315    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
  316 
  317 #define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
  318    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
  319 
  320 #define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \
  321    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
  322 
  323 
  324 struct draw_tcs_jit_context {
  325    const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
  326    int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
  327 
  328    int dummy1;
  329    int dummy2;
  330    /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
  331     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
  332    struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  333    struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
  334    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
  335 
  336    const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  337    int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  338 };
  339 
  340 enum {
  341    DRAW_TCS_JIT_CTX_CONSTANTS = 0,
  342    DRAW_TCS_JIT_CTX_NUM_CONSTANTS = 1,
  343    DRAW_TCS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
  344    DRAW_TCS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
  345    DRAW_TCS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
  346    DRAW_TCS_JIT_CTX_SSBOS = 7,
  347    DRAW_TCS_JIT_CTX_NUM_SSBOS = 8,
  348    DRAW_TCS_JIT_CTX_NUM_FIELDS = 9,
  349 };
  350 
  351 #define draw_tcs_jit_context_constants(_gallivm, _ptr) \
  352    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
  353 
  354 #define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \
  355    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants")
  356 
  357 #define draw_tcs_jit_context_textures(_gallivm, _ptr) \
  358    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")
  359 
  360 #define draw_tcs_jit_context_samplers(_gallivm, _ptr) \
  361    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")
  362 
  363 #define draw_tcs_jit_context_images(_gallivm, _ptr)                      \
  364    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")
  365 
  366 #define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \
  367    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
  368 
  369 #define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \
  370    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")
  371 
  372 struct draw_tes_jit_context {
  373    const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
  374    int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
  375 
  376    int dummy1;
  377    int dummy2;
  378    /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
  379     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
  380    struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  381    struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
  382    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
  383 
  384    const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  385    int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  386 };
  387 
  388 enum {
  389    DRAW_TES_JIT_CTX_CONSTANTS = 0,
  390    DRAW_TES_JIT_CTX_NUM_CONSTANTS = 1,
  391    DRAW_TES_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
  392    DRAW_TES_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
  393    DRAW_TES_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
  394    DRAW_TES_JIT_CTX_SSBOS = 7,
  395    DRAW_TES_JIT_CTX_NUM_SSBOS = 8,
  396    DRAW_TES_JIT_CTX_NUM_FIELDS = 9,
  397 };
  398 
  399 #define draw_tes_jit_context_constants(_gallivm, _ptr) \
  400    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
  401 
  402 #define draw_tes_jit_context_num_constants(_gallivm, _ptr) \
  403    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants")
  404 
  405 #define draw_tes_jit_context_textures(_gallivm, _ptr) \
  406    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")
  407 
  408 #define draw_tes_jit_context_samplers(_gallivm, _ptr) \
  409    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")
  410 
  411 #define draw_tes_jit_context_images(_gallivm, _ptr)                      \
  412    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")
  413 
  414 #define draw_tes_jit_context_ssbos(_gallivm, _ptr) \
  415    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
  416 
  417 #define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \
  418    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")
  419 
  420 typedef boolean
  421 (*draw_jit_vert_func)(struct draw_jit_context *context,
  422                       struct vertex_header *io,
  423                       const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],
  424                       unsigned count,
  425                       unsigned start_or_maxelt,
  426                       unsigned stride,
  427                       struct pipe_vertex_buffer *vertex_buffers,
  428                       unsigned instance_id,
  429                       unsigned vertex_id_offset,
  430                       unsigned start_instance,
  431                       const unsigned *fetch_elts,
  432                       unsigned draw_id);
  433 
  434 
  435 typedef int
  436 (*draw_gs_jit_func)(struct draw_gs_jit_context *context,
  437                     float inputs[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS],
  438                     struct vertex_header **output,
  439                     unsigned num_prims,
  440                     unsigned instance_id,
  441                     int *prim_ids,
  442                     unsigned invocation_id);
  443 
  444 typedef int
  445 (*draw_tcs_jit_func)(struct draw_tcs_jit_context *context,
  446                      float inputs[32][NUM_TCS_INPUTS][TGSI_NUM_CHANNELS],
  447                      float outputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
  448                      uint32_t prim_id, uint32_t patch_vertices_in);
  449 
  450 typedef int
  451 (*draw_tes_jit_func)(struct draw_tes_jit_context *context,
  452                      float inputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
  453                      struct vertex_header *io,
  454                      uint32_t prim_id, uint32_t num_tess_coord,
  455                      float *tess_coord_x, float *tess_coord_y, float *tess_outer,
  456                      float *tess_inner, uint32_t patch_vertices_in);
  457 
  458 
  459 struct draw_llvm_variant_key
  460 {
  461    unsigned nr_vertex_elements:8;
  462    unsigned nr_samplers:8;
  463    unsigned nr_sampler_views:8;
  464    unsigned nr_images:8;
  465    unsigned clamp_vertex_color:1;
  466    unsigned clip_xy:1;
  467    unsigned clip_z:1;
  468    unsigned clip_user:1;
  469    unsigned clip_halfz:1;
  470    unsigned bypass_viewport:1;
  471    unsigned need_edgeflags:1;
  472    unsigned has_gs_or_tes:1;
  473    unsigned num_outputs:8;
  474    unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;
  475    /* note padding here - must use memset */
  476 
  477    /* Variable number of vertex elements:
  478     */
  479    struct pipe_vertex_element vertex_element[1];
  480 
  481    /* Followed by variable number of samplers:
  482     */
  483 /*   struct draw_sampler_static_state sampler; */
  484    /* Followed by variable number of images
  485     */
  486 };
  487 
  488 struct draw_gs_llvm_variant_key
  489 {
  490    unsigned nr_samplers:8;
  491    unsigned nr_sampler_views:8;
  492    unsigned nr_images:8;
  493    unsigned num_outputs:8;
  494    /* note padding here - must use memset */
  495 
  496    struct draw_sampler_static_state samplers[1];
  497    /* Followed by variable number of images.*/
  498 };
  499 
  500 struct draw_tcs_llvm_variant_key
  501 {
  502    unsigned nr_samplers:8;
  503    unsigned nr_sampler_views:8;
  504    unsigned nr_images:8;
  505    struct draw_sampler_static_state samplers[1];
  506    /* Followed by variable number of images.*/
  507 };
  508 
  509 struct draw_tes_llvm_variant_key
  510 {
  511    unsigned nr_samplers:8;
  512    unsigned nr_sampler_views:8;
  513    unsigned nr_images:8;
  514    struct draw_sampler_static_state samplers[1];
  515    /* Followed by variable number of images.*/
  516 };
  517 
  518 #define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \
  519    (sizeof(struct draw_llvm_variant_key) +  \
  520     PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) +  \
  521     PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
  522     (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))
  523 
  524 #define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \
  525    (sizeof(struct draw_gs_llvm_variant_key) +   \
  526     PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
  527     PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
  528 
  529 #define DRAW_TCS_LLVM_MAX_VARIANT_KEY_SIZE \
  530    (sizeof(struct draw_tcs_llvm_variant_key) +  \
  531     PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
  532     PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
  533 
  534 #define DRAW_TES_LLVM_MAX_VARIANT_KEY_SIZE \
  535    (sizeof(struct draw_tes_llvm_variant_key) +  \
  536     PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
  537     PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
  538 
  539 
  540 static inline size_t
  541 draw_llvm_variant_key_size(unsigned nr_vertex_elements,
  542                            unsigned nr_samplers, unsigned nr_images)
  543 {
  544    return (sizeof(struct draw_llvm_variant_key) +
  545            nr_samplers * sizeof(struct draw_sampler_static_state) +
  546            nr_images * sizeof(struct draw_image_static_state) +
  547            (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));
  548 }
  549 
  550 
  551 static inline size_t
  552 draw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
  553 {
  554    return (sizeof(struct draw_gs_llvm_variant_key) +
  555            (nr_images) * sizeof(struct draw_sampler_static_state) +
  556            (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
  557 }
  558 
  559 static inline size_t
  560 draw_tcs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
  561 {
  562    return (sizeof(struct draw_tcs_llvm_variant_key) +
  563            (nr_images) * sizeof(struct draw_sampler_static_state) +
  564            (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
  565 }
  566 
  567 static inline size_t
  568 draw_tes_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
  569 {
  570    return (sizeof(struct draw_tes_llvm_variant_key) +
  571            (nr_images) * sizeof(struct draw_sampler_static_state) +
  572            (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
  573 }
  574 
  575 static inline struct draw_sampler_static_state *
  576 draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)
  577 {
  578    return (struct draw_sampler_static_state *)
  579       &key->vertex_element[key->nr_vertex_elements];
  580 }
  581 
  582 static inline struct draw_image_static_state *
  583 draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
  584 {
  585    struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
  586       (&key->vertex_element[key->nr_vertex_elements]);
  587    return (struct draw_image_static_state *)
  588       &samplers[key->nr_samplers];
  589 }
  590 
  591 static inline struct draw_image_static_state *
  592 draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
  593 {
  594    return (struct draw_image_static_state *)
  595       &key->samplers[key->nr_samplers];
  596 }
  597 
  598 static inline struct draw_image_static_state *
  599 draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key *key)
  600 {
  601    return (struct draw_image_static_state *)
  602       &key->samplers[key->nr_samplers];
  603 }
  604 
  605 static inline struct draw_image_static_state *
  606 draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key *key)
  607 {
  608    return (struct draw_image_static_state *)
  609       &key->samplers[key->nr_samplers];
  610 }
  611 
  612 struct draw_llvm_variant_list_item
  613 {
  614    struct draw_llvm_variant *base;
  615    struct draw_llvm_variant_list_item *next, *prev;
  616 };
  617 
  618 struct draw_gs_llvm_variant_list_item
  619 {
  620    struct draw_gs_llvm_variant *base;
  621    struct draw_gs_llvm_variant_list_item *next, *prev;
  622 };
  623 
  624 struct draw_tcs_llvm_variant_list_item
  625 {
  626    struct draw_tcs_llvm_variant *base;
  627    struct draw_tcs_llvm_variant_list_item *next, *prev;
  628 };
  629 
  630 struct draw_tes_llvm_variant_list_item
  631 {
  632    struct draw_tes_llvm_variant *base;
  633    struct draw_tes_llvm_variant_list_item *next, *prev;
  634 };
  635 
  636 struct draw_llvm_variant
  637 {
  638    struct gallivm_state *gallivm;
  639 
  640    /* LLVM JIT builder types */
  641    LLVMTypeRef context_ptr_type;
  642    LLVMTypeRef buffer_ptr_type;
  643    LLVMTypeRef vb_ptr_type;
  644    LLVMTypeRef vertex_header_ptr_type;
  645 
  646    LLVMValueRef function;
  647    draw_jit_vert_func jit_func;
  648 
  649    struct llvm_vertex_shader *shader;
  650 
  651    struct draw_llvm *llvm;
  652    struct draw_llvm_variant_list_item list_item_global;
  653    struct draw_llvm_variant_list_item list_item_local;
  654 
  655    /* key is variable-sized, must be last */
  656    struct draw_llvm_variant_key key;
  657 };
  658 
  659 
  660 struct draw_gs_llvm_variant
  661 {
  662    struct gallivm_state *gallivm;
  663 
  664    /* LLVM JIT builder types */
  665    LLVMTypeRef context_ptr_type;
  666    LLVMTypeRef vertex_header_ptr_type;
  667    LLVMTypeRef input_array_type;
  668 
  669    LLVMValueRef context_ptr;
  670    LLVMValueRef io_ptr;
  671    LLVMValueRef num_prims;
  672    LLVMValueRef function;
  673    draw_gs_jit_func jit_func;
  674 
  675    struct llvm_geometry_shader *shader;
  676 
  677    struct draw_llvm *llvm;
  678    struct draw_gs_llvm_variant_list_item list_item_global;
  679    struct draw_gs_llvm_variant_list_item list_item_local;
  680 
  681    /* key is variable-sized, must be last */
  682    struct draw_gs_llvm_variant_key key;
  683 };
  684 
  685 struct draw_tcs_llvm_variant
  686 {
  687    struct gallivm_state *gallivm;
  688 
  689    /* LLVM JIT builder types */
  690    LLVMTypeRef context_ptr_type;
  691    LLVMTypeRef input_array_type;
  692    LLVMTypeRef output_array_type;
  693 
  694    LLVMValueRef context_ptr;
  695    LLVMValueRef io_ptr;
  696    LLVMValueRef num_prims;
  697    LLVMValueRef function;
  698    draw_tcs_jit_func jit_func;
  699 
  700    struct llvm_tess_ctrl_shader *shader;
  701 
  702    struct draw_llvm *llvm;
  703    struct draw_tcs_llvm_variant_list_item list_item_global;
  704    struct draw_tcs_llvm_variant_list_item list_item_local;
  705 
  706    /* key is variable-sized, must be last */
  707    struct draw_tcs_llvm_variant_key key;
  708 };
  709 
  710 struct draw_tes_llvm_variant
  711 {
  712    struct gallivm_state *gallivm;
  713 
  714    /* LLVM JIT builder types */
  715    LLVMTypeRef context_ptr_type;
  716    LLVMTypeRef vertex_header_ptr_type;
  717    LLVMTypeRef input_array_type;
  718    LLVMTypeRef patch_input_array_type;
  719 
  720    LLVMValueRef context_ptr;
  721    LLVMValueRef io_ptr;
  722    LLVMValueRef num_prims;
  723    LLVMValueRef function;
  724    draw_tes_jit_func jit_func;
  725 
  726    struct llvm_tess_eval_shader *shader;
  727 
  728    struct draw_llvm *llvm;
  729    struct draw_tes_llvm_variant_list_item list_item_global;
  730    struct draw_tes_llvm_variant_list_item list_item_local;
  731 
  732    /* key is variable-sized, must be last */
  733    struct draw_tes_llvm_variant_key key;
  734 };
  735 
  736 struct llvm_vertex_shader {
  737    struct draw_vertex_shader base;
  738 
  739    unsigned variant_key_size;
  740    struct draw_llvm_variant_list_item variants;
  741    unsigned variants_created;
  742    unsigned variants_cached;
  743 };
  744 
  745 struct llvm_geometry_shader {
  746    struct draw_geometry_shader base;
  747 
  748    unsigned variant_key_size;
  749    struct draw_gs_llvm_variant_list_item variants;
  750    unsigned variants_created;
  751    unsigned variants_cached;
  752 };
  753 
  754 struct llvm_tess_ctrl_shader {
  755    struct draw_tess_ctrl_shader base;
  756 
  757    unsigned variant_key_size;
  758    struct draw_tcs_llvm_variant_list_item variants;
  759    unsigned variants_created;
  760    unsigned variants_cached;
  761 };
  762 
  763 struct llvm_tess_eval_shader {
  764    struct draw_tess_eval_shader base;
  765 
  766    unsigned variant_key_size;
  767    struct draw_tes_llvm_variant_list_item variants;
  768    unsigned variants_created;
  769    unsigned variants_cached;
  770 };
  771 
  772 struct draw_llvm {
  773    struct draw_context *draw;
  774 
  775    LLVMContextRef context;
  776    boolean context_owned;
  777 
  778    struct draw_jit_context jit_context;
  779    struct draw_gs_jit_context gs_jit_context;
  780    struct draw_tcs_jit_context tcs_jit_context;
  781    struct draw_tes_jit_context tes_jit_context;
  782 
  783    struct draw_llvm_variant_list_item vs_variants_list;
  784    int nr_variants;
  785 
  786    struct draw_gs_llvm_variant_list_item gs_variants_list;
  787    int nr_gs_variants;
  788 
  789    struct draw_tcs_llvm_variant_list_item tcs_variants_list;
  790    int nr_tcs_variants;
  791 
  792    struct draw_tes_llvm_variant_list_item tes_variants_list;
  793    int nr_tes_variants;
  794 };
  795 
  796 
  797 static inline struct llvm_vertex_shader *
  798 llvm_vertex_shader(struct draw_vertex_shader *vs)
  799 {
  800    return (struct llvm_vertex_shader *)vs;
  801 }
  802 
  803 static inline struct llvm_geometry_shader *
  804 llvm_geometry_shader(struct draw_geometry_shader *gs)
  805 {
  806    return (struct llvm_geometry_shader *)gs;
  807 }
  808 
  809 static inline struct llvm_tess_ctrl_shader *
  810 llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader *tcs)
  811 {
  812    return (struct llvm_tess_ctrl_shader *)tcs;
  813 }
  814 
  815 static inline struct llvm_tess_eval_shader *
  816 llvm_tess_eval_shader(struct draw_tess_eval_shader *tes)
  817 {
  818    return (struct llvm_tess_eval_shader *)tes;
  819 }
  820 
  821 struct draw_llvm *
  822 draw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);
  823 
  824 void
  825 draw_llvm_destroy(struct draw_llvm *llvm);
  826 
  827 struct draw_llvm_variant *
  828 draw_llvm_create_variant(struct draw_llvm *llvm,
  829                          unsigned num_vertex_header_attribs,
  830                          const struct draw_llvm_variant_key *key);
  831 
  832 void
  833 draw_llvm_destroy_variant(struct draw_llvm_variant *variant);
  834 
  835 struct draw_llvm_variant_key *
  836 draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
  837 
  838 void
  839 draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key);
  840 
  841 
  842 struct draw_gs_llvm_variant *
  843 draw_gs_llvm_create_variant(struct draw_llvm *llvm,
  844                             unsigned num_vertex_header_attribs,
  845                             const struct draw_gs_llvm_variant_key *key);
  846 
  847 void
  848 draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant);
  849 
  850 struct draw_gs_llvm_variant_key *
  851 draw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
  852 
  853 void
  854 draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
  855 
  856 struct draw_tcs_llvm_variant *
  857 draw_tcs_llvm_create_variant(struct draw_llvm *llvm,
  858                              unsigned num_vertex_header_attribs,
  859                              const struct draw_tcs_llvm_variant_key *key);
  860 
  861 void
  862 draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant);
  863 
  864 struct draw_tcs_llvm_variant_key *
  865 draw_tcs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
  866 
  867 void
  868 draw_tcs_llvm_dump_variant_key(struct draw_tcs_llvm_variant_key *key);
  869 
  870 struct draw_tes_llvm_variant *
  871 draw_tes_llvm_create_variant(struct draw_llvm *llvm,
  872                              unsigned num_vertex_header_attribs,
  873                              const struct draw_tes_llvm_variant_key *key);
  874 
  875 void
  876 draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant);
  877 
  878 struct draw_tes_llvm_variant_key *
  879 draw_tes_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
  880 
  881 void
  882 draw_tes_llvm_dump_variant_key(struct draw_tes_llvm_variant_key *key);
  883 
  884 struct lp_build_sampler_soa *
  885 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state);
  886 
  887 struct lp_build_image_soa *
  888 draw_llvm_image_soa_create(const struct draw_image_static_state *static_state);
  889 
  890 void
  891 draw_llvm_set_sampler_state(struct draw_context *draw,
  892                             enum pipe_shader_type shader_stage);
  893 
  894 void
  895 draw_llvm_set_mapped_texture(struct draw_context *draw,
  896                              enum pipe_shader_type shader_stage,
  897                              unsigned sview_idx,
  898                              uint32_t width, uint32_t height, uint32_t depth,
  899                              uint32_t first_level, uint32_t last_level,
  900                              const void *base_ptr,
  901                              uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
  902                              uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
  903                              uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
  904 
  905 void
  906 draw_llvm_set_mapped_image(struct draw_context *draw,
  907                            enum pipe_shader_type shader_stage,
  908                            unsigned idx,
  909                            uint32_t width, uint32_t height, uint32_t depth,
  910                            const void *base_ptr,
  911                            uint32_t row_stride,
  912                            uint32_t img_stride);
  913 #endif