13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
33464ebd5Sriastradh * Copyright 2010 VMware, Inc.
43464ebd5Sriastradh * All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the
83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
123464ebd5Sriastradh * the following conditions:
133464ebd5Sriastradh *
143464ebd5Sriastradh * The above copyright notice and this permission notice (including the
153464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
163464ebd5Sriastradh * of the Software.
173464ebd5Sriastradh *
183464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
193464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
203464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
213464ebd5Sriastradh * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
223464ebd5Sriastradh * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233464ebd5Sriastradh * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
243464ebd5Sriastradh * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
253464ebd5Sriastradh *
263464ebd5Sriastradh **************************************************************************/
273464ebd5Sriastradh
283464ebd5Sriastradh#ifndef DRAW_LLVM_H
293464ebd5Sriastradh#define DRAW_LLVM_H
303464ebd5Sriastradh
313464ebd5Sriastradh#include "draw/draw_private.h"
323464ebd5Sriastradh
333464ebd5Sriastradh#include "draw/draw_vs.h"
34af69d88dSmrg#include "draw/draw_gs.h"
357ec681f3Smrg#include "draw/draw_tess.h"
36af69d88dSmrg
373464ebd5Sriastradh#include "gallivm/lp_bld_sample.h"
38af69d88dSmrg#include "gallivm/lp_bld_limits.h"
393464ebd5Sriastradh
403464ebd5Sriastradh#include "pipe/p_context.h"
4101e04c3fSmrg#include "util/simple_list.h"
423464ebd5Sriastradh
433464ebd5Sriastradh
443464ebd5Sriastradhstruct draw_llvm;
453464ebd5Sriastradhstruct llvm_vertex_shader;
46af69d88dSmrgstruct llvm_geometry_shader;
477ec681f3Smrgstruct llvm_tess_ctrl_shader;
487ec681f3Smrgstruct llvm_tess_eval_shader;
493464ebd5Sriastradh
503464ebd5Sriastradhstruct draw_jit_texture
513464ebd5Sriastradh{
523464ebd5Sriastradh   uint32_t width;
533464ebd5Sriastradh   uint32_t height;
543464ebd5Sriastradh   uint32_t depth;
55af69d88dSmrg   const void *base;
563464ebd5Sriastradh   uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
573464ebd5Sriastradh   uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
587ec681f3Smrg   uint32_t first_level;
597ec681f3Smrg   uint32_t last_level;
60af69d88dSmrg   uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
617ec681f3Smrg   uint32_t num_samples;
627ec681f3Smrg   uint32_t sample_stride;
63af69d88dSmrg};
64af69d88dSmrg
65af69d88dSmrg
66af69d88dSmrgstruct draw_sampler_static_state
67af69d88dSmrg{
68af69d88dSmrg   /*
69af69d88dSmrg    * These attributes are effectively interleaved for more sane key handling.
70af69d88dSmrg    * However, there might be lots of null space if the amount of samplers and
71af69d88dSmrg    * textures isn't the same.
72af69d88dSmrg    */
73af69d88dSmrg   struct lp_static_sampler_state sampler_state;
74af69d88dSmrg   struct lp_static_texture_state texture_state;
75af69d88dSmrg};
76af69d88dSmrg
777ec681f3Smrgstruct draw_image_static_state
787ec681f3Smrg{
797ec681f3Smrg   struct lp_static_texture_state image_state;
807ec681f3Smrg};
817ec681f3Smrg
82af69d88dSmrg
83af69d88dSmrgstruct draw_jit_sampler
84af69d88dSmrg{
853464ebd5Sriastradh   float min_lod;
863464ebd5Sriastradh   float max_lod;
873464ebd5Sriastradh   float lod_bias;
883464ebd5Sriastradh   float border_color[4];
897ec681f3Smrg   float max_aniso;
903464ebd5Sriastradh};
913464ebd5Sriastradh
92af69d88dSmrg
937ec681f3Smrgstruct draw_jit_image
947ec681f3Smrg{
957ec681f3Smrg   uint32_t width;
967ec681f3Smrg   uint32_t height;
977ec681f3Smrg   uint32_t depth;
987ec681f3Smrg   const void *base;
997ec681f3Smrg   uint32_t row_stride;
1007ec681f3Smrg   uint32_t img_stride;
1017ec681f3Smrg   uint32_t num_samples;
1027ec681f3Smrg   uint32_t sample_stride;
1037ec681f3Smrg};
1047ec681f3Smrg
1053464ebd5Sriastradhenum {
1063464ebd5Sriastradh   DRAW_JIT_TEXTURE_WIDTH = 0,
1073464ebd5Sriastradh   DRAW_JIT_TEXTURE_HEIGHT,
1083464ebd5Sriastradh   DRAW_JIT_TEXTURE_DEPTH,
109af69d88dSmrg   DRAW_JIT_TEXTURE_BASE,
1103464ebd5Sriastradh   DRAW_JIT_TEXTURE_ROW_STRIDE,
1113464ebd5Sriastradh   DRAW_JIT_TEXTURE_IMG_STRIDE,
1127ec681f3Smrg   DRAW_JIT_TEXTURE_FIRST_LEVEL,
1137ec681f3Smrg   DRAW_JIT_TEXTURE_LAST_LEVEL,
114af69d88dSmrg   DRAW_JIT_TEXTURE_MIP_OFFSETS,
1157ec681f3Smrg   DRAW_JIT_TEXTURE_NUM_SAMPLES,
1167ec681f3Smrg   DRAW_JIT_TEXTURE_SAMPLE_STRIDE,
1173464ebd5Sriastradh   DRAW_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
1183464ebd5Sriastradh};
1193464ebd5Sriastradh
120af69d88dSmrg
121af69d88dSmrgenum {
122af69d88dSmrg   DRAW_JIT_SAMPLER_MIN_LOD,
123af69d88dSmrg   DRAW_JIT_SAMPLER_MAX_LOD,
124af69d88dSmrg   DRAW_JIT_SAMPLER_LOD_BIAS,
125af69d88dSmrg   DRAW_JIT_SAMPLER_BORDER_COLOR,
1267ec681f3Smrg   DRAW_JIT_SAMPLER_MAX_ANISO,
127af69d88dSmrg   DRAW_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
128af69d88dSmrg};
129af69d88dSmrg
130af69d88dSmrg
1313464ebd5Sriastradhenum {
1323464ebd5Sriastradh   DRAW_JIT_VERTEX_VERTEX_ID = 0,
13301e04c3fSmrg   DRAW_JIT_VERTEX_CLIP_POS,
1343464ebd5Sriastradh   DRAW_JIT_VERTEX_DATA
1353464ebd5Sriastradh};
1363464ebd5Sriastradh
1377ec681f3Smrgenum {
1387ec681f3Smrg   DRAW_JIT_IMAGE_WIDTH = 0,
1397ec681f3Smrg   DRAW_JIT_IMAGE_HEIGHT,
1407ec681f3Smrg   DRAW_JIT_IMAGE_DEPTH,
1417ec681f3Smrg   DRAW_JIT_IMAGE_BASE,
1427ec681f3Smrg   DRAW_JIT_IMAGE_ROW_STRIDE,
1437ec681f3Smrg   DRAW_JIT_IMAGE_IMG_STRIDE,
1447ec681f3Smrg   DRAW_JIT_IMAGE_NUM_SAMPLES,
1457ec681f3Smrg   DRAW_JIT_IMAGE_SAMPLE_STRIDE,
1467ec681f3Smrg   DRAW_JIT_IMAGE_NUM_FIELDS  /* number of fields above */
1477ec681f3Smrg};
1487ec681f3Smrg
1493464ebd5Sriastradh/**
1503464ebd5Sriastradh * This structure is passed directly to the generated vertex shader.
1513464ebd5Sriastradh *
1523464ebd5Sriastradh * It contains the derived state.
1533464ebd5Sriastradh *
1543464ebd5Sriastradh * Changes here must be reflected in the draw_jit_context_* macros.
1553464ebd5Sriastradh * Changes to the ordering should be avoided.
1563464ebd5Sriastradh *
1573464ebd5Sriastradh * Only use types with a clear size and padding here, in particular prefer the
1583464ebd5Sriastradh * stdint.h types to the basic integer types.
1593464ebd5Sriastradh */
1603464ebd5Sriastradhstruct draw_jit_context
1613464ebd5Sriastradh{
162af69d88dSmrg   const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
163af69d88dSmrg   int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
164af69d88dSmrg   float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
16501e04c3fSmrg   struct pipe_viewport_state *viewports;
1663464ebd5Sriastradh
167af69d88dSmrg   struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
168af69d88dSmrg   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
1697ec681f3Smrg   struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
1707ec681f3Smrg
1717ec681f3Smrg   const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
1727ec681f3Smrg   int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
1737ec681f3Smrg
1747ec681f3Smrg   const float *aniso_filter_table;
1753464ebd5Sriastradh};
1763464ebd5Sriastradh
177af69d88dSmrgenum {
178af69d88dSmrg   DRAW_JIT_CTX_CONSTANTS            = 0,
179af69d88dSmrg   DRAW_JIT_CTX_NUM_CONSTANTS        = 1,
180af69d88dSmrg   DRAW_JIT_CTX_PLANES               = 2,
181af69d88dSmrg   DRAW_JIT_CTX_VIEWPORT             = 3,
182af69d88dSmrg   DRAW_JIT_CTX_TEXTURES             = 4,
183af69d88dSmrg   DRAW_JIT_CTX_SAMPLERS             = 5,
1847ec681f3Smrg   DRAW_JIT_CTX_IMAGES               = 6,
1857ec681f3Smrg   DRAW_JIT_CTX_SSBOS                = 7,
1867ec681f3Smrg   DRAW_JIT_CTX_NUM_SSBOS            = 8,
1877ec681f3Smrg   DRAW_JIT_CTX_ANISO_FILTER_TABLE   = 9,
188af69d88dSmrg   DRAW_JIT_CTX_NUM_FIELDS
189af69d88dSmrg};
1903464ebd5Sriastradh
1913464ebd5Sriastradh#define draw_jit_context_vs_constants(_gallivm, _ptr) \
192af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
1933464ebd5Sriastradh
194af69d88dSmrg#define draw_jit_context_num_vs_constants(_gallivm, _ptr) \
195af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
1963464ebd5Sriastradh
1973464ebd5Sriastradh#define draw_jit_context_planes(_gallivm, _ptr) \
198af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
1993464ebd5Sriastradh
20001e04c3fSmrg#define draw_jit_context_viewports(_gallivm, _ptr) \
20101e04c3fSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")
2023464ebd5Sriastradh
2033464ebd5Sriastradh#define draw_jit_context_textures(_gallivm, _ptr) \
2043464ebd5Sriastradh   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
2053464ebd5Sriastradh
206af69d88dSmrg#define draw_jit_context_samplers(_gallivm, _ptr) \
207af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
208af69d88dSmrg
2097ec681f3Smrg#define draw_jit_context_images(_gallivm, _ptr) \
2107ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
2117ec681f3Smrg
2127ec681f3Smrg#define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
2137ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
2147ec681f3Smrg
2157ec681f3Smrg#define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \
2167ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
2177ec681f3Smrg
2187ec681f3Smrg#define draw_jit_context_aniso_filter_table(_gallivm, _ptr) \
2197ec681f3Smrg   lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
2207ec681f3Smrg
2217ec681f3Smrg
2223464ebd5Sriastradh#define draw_jit_header_id(_gallivm, _ptr)              \
223af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
2243464ebd5Sriastradh
22501e04c3fSmrg#define draw_jit_header_clip_pos(_gallivm, _ptr) \
22601e04c3fSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
2273464ebd5Sriastradh
2283464ebd5Sriastradh#define draw_jit_header_data(_gallivm, _ptr)            \
229af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")
2303464ebd5Sriastradh
2313464ebd5Sriastradh
2323464ebd5Sriastradh#define draw_jit_vbuffer_stride(_gallivm, _ptr)         \
2333464ebd5Sriastradh   lp_build_struct_get(_gallivm, _ptr, 0, "stride")
2343464ebd5Sriastradh
2353464ebd5Sriastradh#define draw_jit_vbuffer_offset(_gallivm, _ptr)         \
23601e04c3fSmrg   lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
2373464ebd5Sriastradh
238af69d88dSmrgenum {
239af69d88dSmrg   DRAW_JIT_DVBUFFER_MAP = 0,
240af69d88dSmrg   DRAW_JIT_DVBUFFER_SIZE,
241af69d88dSmrg   DRAW_JIT_DVBUFFER_NUM_FIELDS  /* number of fields above */
242af69d88dSmrg};
243af69d88dSmrg
244af69d88dSmrg#define draw_jit_dvbuffer_map(_gallivm, _ptr)         \
245af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")
246af69d88dSmrg
247af69d88dSmrg#define draw_jit_dvbuffer_size(_gallivm, _ptr)        \
248af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")
249af69d88dSmrg
250af69d88dSmrg
251af69d88dSmrg/**
252af69d88dSmrg * This structure is passed directly to the generated geometry shader.
253af69d88dSmrg *
254af69d88dSmrg * It contains the derived state.
255af69d88dSmrg *
256af69d88dSmrg * Changes here must be reflected in the draw_gs_jit_context_* macros.
257af69d88dSmrg * Changes to the ordering should be avoided.
258af69d88dSmrg *
259af69d88dSmrg * Only use types with a clear size and padding here, in particular prefer the
260af69d88dSmrg * stdint.h types to the basic integer types.
261af69d88dSmrg */
262af69d88dSmrgstruct draw_gs_jit_context
263af69d88dSmrg{
264af69d88dSmrg   const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
265af69d88dSmrg   int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
266af69d88dSmrg   float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
26701e04c3fSmrg   struct pipe_viewport_state *viewports;
268af69d88dSmrg
269af69d88dSmrg   /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
270af69d88dSmrg    * DRAW_JIT_CTX_SAMPLERS positions in the struct */
271af69d88dSmrg   struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
272af69d88dSmrg   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
2737ec681f3Smrg   struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
2747ec681f3Smrg
275af69d88dSmrg   int **prim_lengths;
276af69d88dSmrg   int *emitted_vertices;
277af69d88dSmrg   int *emitted_prims;
2787ec681f3Smrg   const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
2797ec681f3Smrg   int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
2807ec681f3Smrg
2817ec681f3Smrg   const float *aniso_filter_table;
282af69d88dSmrg};
283af69d88dSmrg
284af69d88dSmrgenum {
285af69d88dSmrg   DRAW_GS_JIT_CTX_CONSTANTS = 0,
286af69d88dSmrg   DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1,
287af69d88dSmrg   DRAW_GS_JIT_CTX_PLANES = 2,
288af69d88dSmrg   DRAW_GS_JIT_CTX_VIEWPORT = 3,
289af69d88dSmrg   /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
290af69d88dSmrg    * and DRAW_JIT_CTX_SAMPLERS, because they both need
291af69d88dSmrg    * to be at exactly the same locations as they are in the
292af69d88dSmrg    * VS ctx structure for sampling to work. */
293af69d88dSmrg   DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
294af69d88dSmrg   DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
2957ec681f3Smrg   DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
2967ec681f3Smrg   DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7,
2977ec681f3Smrg   DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8,
2987ec681f3Smrg   DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9,
2997ec681f3Smrg   DRAW_GS_JIT_CTX_SSBOS = 10,
3007ec681f3Smrg   DRAW_GS_JIT_CTX_NUM_SSBOS = 11,
3017ec681f3Smrg   DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE = 12,
3027ec681f3Smrg   DRAW_GS_JIT_CTX_NUM_FIELDS = 13
303af69d88dSmrg};
304af69d88dSmrg
305af69d88dSmrg#define draw_gs_jit_context_constants(_gallivm, _ptr) \
306af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
307af69d88dSmrg
308af69d88dSmrg#define draw_gs_jit_context_num_constants(_gallivm, _ptr) \
309af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")
310af69d88dSmrg
311af69d88dSmrg#define draw_gs_jit_context_planes(_gallivm, _ptr) \
312af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")
313af69d88dSmrg
31401e04c3fSmrg#define draw_gs_jit_context_viewports(_gallivm, _ptr) \
31501e04c3fSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")
316af69d88dSmrg
317af69d88dSmrg#define draw_gs_jit_context_textures(_gallivm, _ptr) \
318af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")
319af69d88dSmrg
320af69d88dSmrg#define draw_gs_jit_context_samplers(_gallivm, _ptr) \
321af69d88dSmrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
322af69d88dSmrg
3237ec681f3Smrg#define draw_gs_jit_context_images(_gallivm, _ptr)                      \
3247ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
3257ec681f3Smrg
326af69d88dSmrg#define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
327af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
328af69d88dSmrg
329af69d88dSmrg#define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \
330af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")
331af69d88dSmrg
332af69d88dSmrg#define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
333af69d88dSmrg   lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
334af69d88dSmrg
3357ec681f3Smrg#define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
3367ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
3377ec681f3Smrg
3387ec681f3Smrg#define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \
3397ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
3407ec681f3Smrg
3417ec681f3Smrg#define draw_gs_jit_context_aniso_filter_table(_gallivm, _ptr) \
3427ec681f3Smrg   lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
3437ec681f3Smrg
3447ec681f3Smrgstruct draw_tcs_jit_context {
3457ec681f3Smrg   const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
3467ec681f3Smrg   int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
3477ec681f3Smrg
3487ec681f3Smrg   int dummy1;
3497ec681f3Smrg   int dummy2;
3507ec681f3Smrg   /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
3517ec681f3Smrg    * DRAW_JIT_CTX_SAMPLERS positions in the struct */
3527ec681f3Smrg   struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
3537ec681f3Smrg   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
3547ec681f3Smrg   struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
3557ec681f3Smrg
3567ec681f3Smrg   const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
3577ec681f3Smrg   int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
3587ec681f3Smrg
3597ec681f3Smrg   const float *aniso_filter_table;
3607ec681f3Smrg};
3617ec681f3Smrg
3627ec681f3Smrgenum {
3637ec681f3Smrg   DRAW_TCS_JIT_CTX_CONSTANTS = 0,
3647ec681f3Smrg   DRAW_TCS_JIT_CTX_NUM_CONSTANTS = 1,
3657ec681f3Smrg   DRAW_TCS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
3667ec681f3Smrg   DRAW_TCS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
3677ec681f3Smrg   DRAW_TCS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
3687ec681f3Smrg   DRAW_TCS_JIT_CTX_SSBOS = 7,
3697ec681f3Smrg   DRAW_TCS_JIT_CTX_NUM_SSBOS = 8,
3707ec681f3Smrg   DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE = 9,
3717ec681f3Smrg   DRAW_TCS_JIT_CTX_NUM_FIELDS = 10,
3727ec681f3Smrg};
3737ec681f3Smrg
3747ec681f3Smrg#define draw_tcs_jit_context_constants(_gallivm, _ptr) \
3757ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")
3767ec681f3Smrg
3777ec681f3Smrg#define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \
3787ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants")
379af69d88dSmrg
3807ec681f3Smrg#define draw_tcs_jit_context_textures(_gallivm, _ptr) \
3817ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")
3827ec681f3Smrg
3837ec681f3Smrg#define draw_tcs_jit_context_samplers(_gallivm, _ptr) \
3847ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")
3857ec681f3Smrg
3867ec681f3Smrg#define draw_tcs_jit_context_images(_gallivm, _ptr)                      \
3877ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")
3887ec681f3Smrg
3897ec681f3Smrg#define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \
3907ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")
3917ec681f3Smrg
3927ec681f3Smrg#define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \
3937ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")
3947ec681f3Smrg
3957ec681f3Smrg#define draw_tcs_jit_context_aniso_filter_table(_gallivm, _ptr) \
3967ec681f3Smrg   lp_build_struct_get(_gallivm, _ptr, DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
3977ec681f3Smrg
3987ec681f3Smrgstruct draw_tes_jit_context {
3997ec681f3Smrg   const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
4007ec681f3Smrg   int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
4017ec681f3Smrg
4027ec681f3Smrg   int dummy1;
4037ec681f3Smrg   int dummy2;
4047ec681f3Smrg   /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
4057ec681f3Smrg    * DRAW_JIT_CTX_SAMPLERS positions in the struct */
4067ec681f3Smrg   struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
4077ec681f3Smrg   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
4087ec681f3Smrg   struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
4097ec681f3Smrg
4107ec681f3Smrg   const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
4117ec681f3Smrg   int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
4127ec681f3Smrg
4137ec681f3Smrg   const float *aniso_filter_table;
4147ec681f3Smrg};
4157ec681f3Smrg
4167ec681f3Smrgenum {
4177ec681f3Smrg   DRAW_TES_JIT_CTX_CONSTANTS = 0,
4187ec681f3Smrg   DRAW_TES_JIT_CTX_NUM_CONSTANTS = 1,
4197ec681f3Smrg   DRAW_TES_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
4207ec681f3Smrg   DRAW_TES_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
4217ec681f3Smrg   DRAW_TES_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
4227ec681f3Smrg   DRAW_TES_JIT_CTX_SSBOS = 7,
4237ec681f3Smrg   DRAW_TES_JIT_CTX_NUM_SSBOS = 8,
4247ec681f3Smrg   DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE = 9,
4257ec681f3Smrg   DRAW_TES_JIT_CTX_NUM_FIELDS = 10,
4267ec681f3Smrg};
4277ec681f3Smrg
4287ec681f3Smrg#define draw_tes_jit_context_constants(_gallivm, _ptr) \
4297ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")
4307ec681f3Smrg
4317ec681f3Smrg#define draw_tes_jit_context_num_constants(_gallivm, _ptr) \
4327ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants")
4337ec681f3Smrg
4347ec681f3Smrg#define draw_tes_jit_context_textures(_gallivm, _ptr) \
4357ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")
4367ec681f3Smrg
4377ec681f3Smrg#define draw_tes_jit_context_samplers(_gallivm, _ptr) \
4387ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")
4397ec681f3Smrg
4407ec681f3Smrg#define draw_tes_jit_context_images(_gallivm, _ptr)                      \
4417ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")
4427ec681f3Smrg
4437ec681f3Smrg#define draw_tes_jit_context_ssbos(_gallivm, _ptr) \
4447ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")
4457ec681f3Smrg
4467ec681f3Smrg#define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \
4477ec681f3Smrg   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")
4487ec681f3Smrg
4497ec681f3Smrg#define draw_tes_jit_context_aniso_filter_table(_gallivm, _ptr) \
4507ec681f3Smrg   lp_build_struct_get(_gallivm, _ptr, DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
4513464ebd5Sriastradh
45201e04c3fSmrgtypedef boolean
4533464ebd5Sriastradh(*draw_jit_vert_func)(struct draw_jit_context *context,
4543464ebd5Sriastradh                      struct vertex_header *io,
455af69d88dSmrg                      const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],
4563464ebd5Sriastradh                      unsigned count,
45701e04c3fSmrg                      unsigned start_or_maxelt,
4583464ebd5Sriastradh                      unsigned stride,
4593464ebd5Sriastradh                      struct pipe_vertex_buffer *vertex_buffers,
460af69d88dSmrg                      unsigned instance_id,
46101e04c3fSmrg                      unsigned vertex_id_offset,
46201e04c3fSmrg                      unsigned start_instance,
4637ec681f3Smrg                      const unsigned *fetch_elts,
4647ec681f3Smrg                      unsigned draw_id, unsigned view_id);
465af69d88dSmrg
466af69d88dSmrg
467af69d88dSmrgtypedef int
468af69d88dSmrg(*draw_gs_jit_func)(struct draw_gs_jit_context *context,
469af69d88dSmrg                    float inputs[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS],
4707ec681f3Smrg                    struct vertex_header **output,
471af69d88dSmrg                    unsigned num_prims,
472af69d88dSmrg                    unsigned instance_id,
47301e04c3fSmrg                    int *prim_ids,
4747ec681f3Smrg                    unsigned invocation_id,
4757ec681f3Smrg                    unsigned view_id);
4767ec681f3Smrg
4777ec681f3Smrgtypedef int
4787ec681f3Smrg(*draw_tcs_jit_func)(struct draw_tcs_jit_context *context,
4797ec681f3Smrg                     float inputs[32][NUM_TCS_INPUTS][TGSI_NUM_CHANNELS],
4807ec681f3Smrg                     float outputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
4817ec681f3Smrg                     uint32_t prim_id, uint32_t patch_vertices_in,
4827ec681f3Smrg                     unsigned view_id);
4837ec681f3Smrg
4847ec681f3Smrgtypedef int
4857ec681f3Smrg(*draw_tes_jit_func)(struct draw_tes_jit_context *context,
4867ec681f3Smrg                     float inputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],
4877ec681f3Smrg                     struct vertex_header *io,
4887ec681f3Smrg                     uint32_t prim_id, uint32_t num_tess_coord,
4897ec681f3Smrg                     float *tess_coord_x, float *tess_coord_y, float *tess_outer,
4907ec681f3Smrg                     float *tess_inner, uint32_t patch_vertices_in,
4917ec681f3Smrg                     unsigned view_id);
4927ec681f3Smrg
4933464ebd5Sriastradh
4943464ebd5Sriastradhstruct draw_llvm_variant_key
4953464ebd5Sriastradh{
4963464ebd5Sriastradh   unsigned nr_vertex_elements:8;
4973464ebd5Sriastradh   unsigned nr_samplers:8;
498af69d88dSmrg   unsigned nr_sampler_views:8;
4997ec681f3Smrg   unsigned nr_images:8;
5003464ebd5Sriastradh   unsigned clamp_vertex_color:1;
5013464ebd5Sriastradh   unsigned clip_xy:1;
5023464ebd5Sriastradh   unsigned clip_z:1;
5033464ebd5Sriastradh   unsigned clip_user:1;
5043464ebd5Sriastradh   unsigned clip_halfz:1;
5053464ebd5Sriastradh   unsigned bypass_viewport:1;
5063464ebd5Sriastradh   unsigned need_edgeflags:1;
5077ec681f3Smrg   unsigned has_gs_or_tes:1;
508af69d88dSmrg   unsigned num_outputs:8;
509af69d88dSmrg   unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;
51001e04c3fSmrg   /* note padding here - must use memset */
5113464ebd5Sriastradh
5123464ebd5Sriastradh   /* Variable number of vertex elements:
5133464ebd5Sriastradh    */
5143464ebd5Sriastradh   struct pipe_vertex_element vertex_element[1];
5153464ebd5Sriastradh
5163464ebd5Sriastradh   /* Followed by variable number of samplers:
5173464ebd5Sriastradh    */
518af69d88dSmrg/*   struct draw_sampler_static_state sampler; */
5197ec681f3Smrg   /* Followed by variable number of images
5207ec681f3Smrg    */
521af69d88dSmrg};
522af69d88dSmrg
523af69d88dSmrgstruct draw_gs_llvm_variant_key
524af69d88dSmrg{
525af69d88dSmrg   unsigned nr_samplers:8;
526af69d88dSmrg   unsigned nr_sampler_views:8;
5277ec681f3Smrg   unsigned nr_images:8;
528af69d88dSmrg   unsigned num_outputs:8;
52901e04c3fSmrg   /* note padding here - must use memset */
5307ec681f3Smrg   unsigned clamp_vertex_color:1;
5317ec681f3Smrg   struct draw_sampler_static_state samplers[1];
5327ec681f3Smrg   /* Followed by variable number of images.*/
5337ec681f3Smrg};
534af69d88dSmrg
5357ec681f3Smrgstruct draw_tcs_llvm_variant_key
5367ec681f3Smrg{
5377ec681f3Smrg   unsigned nr_samplers:8;
5387ec681f3Smrg   unsigned nr_sampler_views:8;
5397ec681f3Smrg   unsigned nr_images:8;
5407ec681f3Smrg   struct draw_sampler_static_state samplers[1];
5417ec681f3Smrg   /* Followed by variable number of images.*/
5427ec681f3Smrg};
5437ec681f3Smrg
5447ec681f3Smrgstruct draw_tes_llvm_variant_key
5457ec681f3Smrg{
5467ec681f3Smrg   unsigned nr_samplers:8;
5477ec681f3Smrg   unsigned nr_sampler_views:8;
5487ec681f3Smrg   unsigned nr_images:8;
5497ec681f3Smrg   unsigned primid_output:7;
5507ec681f3Smrg   unsigned primid_needed:1;
5517ec681f3Smrg   unsigned clamp_vertex_color:1;
552af69d88dSmrg   struct draw_sampler_static_state samplers[1];
5537ec681f3Smrg   /* Followed by variable number of images.*/
5543464ebd5Sriastradh};
5553464ebd5Sriastradh
5563464ebd5Sriastradh#define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \
5573464ebd5Sriastradh   (sizeof(struct draw_llvm_variant_key) +	\
558af69d88dSmrg    PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) +	\
5597ec681f3Smrg    PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
5603464ebd5Sriastradh    (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))
5613464ebd5Sriastradh
562af69d88dSmrg#define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \
563af69d88dSmrg   (sizeof(struct draw_gs_llvm_variant_key) +	\
5647ec681f3Smrg    PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
5657ec681f3Smrg    PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
5667ec681f3Smrg
5677ec681f3Smrg#define DRAW_TCS_LLVM_MAX_VARIANT_KEY_SIZE \
5687ec681f3Smrg   (sizeof(struct draw_tcs_llvm_variant_key) +	\
5697ec681f3Smrg    PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
5707ec681f3Smrg    PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
5717ec681f3Smrg
5727ec681f3Smrg#define DRAW_TES_LLVM_MAX_VARIANT_KEY_SIZE \
5737ec681f3Smrg   (sizeof(struct draw_tes_llvm_variant_key) +	\
5747ec681f3Smrg    PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
575af69d88dSmrg    PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
576af69d88dSmrg
5773464ebd5Sriastradh
57801e04c3fSmrgstatic inline size_t
5793464ebd5Sriastradhdraw_llvm_variant_key_size(unsigned nr_vertex_elements,
5807ec681f3Smrg                           unsigned nr_samplers, unsigned nr_images)
5813464ebd5Sriastradh{
5823464ebd5Sriastradh   return (sizeof(struct draw_llvm_variant_key) +
583af69d88dSmrg           nr_samplers * sizeof(struct draw_sampler_static_state) +
5847ec681f3Smrg           nr_images * sizeof(struct draw_image_static_state) +
585af69d88dSmrg           (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));
586af69d88dSmrg}
587af69d88dSmrg
588af69d88dSmrg
58901e04c3fSmrgstatic inline size_t
5907ec681f3Smrgdraw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
591af69d88dSmrg{
592af69d88dSmrg   return (sizeof(struct draw_gs_llvm_variant_key) +
5937ec681f3Smrg           (nr_images) * sizeof(struct draw_sampler_static_state) +
5947ec681f3Smrg           (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
5957ec681f3Smrg}
5967ec681f3Smrg
5977ec681f3Smrgstatic inline size_t
5987ec681f3Smrgdraw_tcs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
5997ec681f3Smrg{
6007ec681f3Smrg   return (sizeof(struct draw_tcs_llvm_variant_key) +
6017ec681f3Smrg           (nr_images) * sizeof(struct draw_sampler_static_state) +
602af69d88dSmrg           (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
6033464ebd5Sriastradh}
6043464ebd5Sriastradh
6057ec681f3Smrgstatic inline size_t
6067ec681f3Smrgdraw_tes_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
6077ec681f3Smrg{
6087ec681f3Smrg   return (sizeof(struct draw_tes_llvm_variant_key) +
6097ec681f3Smrg           (nr_images) * sizeof(struct draw_sampler_static_state) +
6107ec681f3Smrg           (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
6117ec681f3Smrg}
6123464ebd5Sriastradh
61301e04c3fSmrgstatic inline struct draw_sampler_static_state *
6143464ebd5Sriastradhdraw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)
6153464ebd5Sriastradh{
616af69d88dSmrg   return (struct draw_sampler_static_state *)
6173464ebd5Sriastradh      &key->vertex_element[key->nr_vertex_elements];
6183464ebd5Sriastradh}
6193464ebd5Sriastradh
6207ec681f3Smrgstatic inline struct draw_image_static_state *
6217ec681f3Smrgdraw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
6227ec681f3Smrg{
6237ec681f3Smrg   struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
6247ec681f3Smrg      (&key->vertex_element[key->nr_vertex_elements]);
6257ec681f3Smrg   return (struct draw_image_static_state *)
6267ec681f3Smrg      &samplers[key->nr_samplers];
6277ec681f3Smrg}
6287ec681f3Smrg
6297ec681f3Smrgstatic inline struct draw_image_static_state *
6307ec681f3Smrgdraw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
6317ec681f3Smrg{
6327ec681f3Smrg   return (struct draw_image_static_state *)
6337ec681f3Smrg      &key->samplers[key->nr_samplers];
6347ec681f3Smrg}
6357ec681f3Smrg
6367ec681f3Smrgstatic inline struct draw_image_static_state *
6377ec681f3Smrgdraw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key *key)
6387ec681f3Smrg{
6397ec681f3Smrg   return (struct draw_image_static_state *)
6407ec681f3Smrg      &key->samplers[key->nr_samplers];
6417ec681f3Smrg}
6427ec681f3Smrg
6437ec681f3Smrgstatic inline struct draw_image_static_state *
6447ec681f3Smrgdraw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key *key)
6457ec681f3Smrg{
6467ec681f3Smrg   return (struct draw_image_static_state *)
6477ec681f3Smrg      &key->samplers[key->nr_samplers];
6487ec681f3Smrg}
6493464ebd5Sriastradh
6503464ebd5Sriastradhstruct draw_llvm_variant_list_item
6513464ebd5Sriastradh{
6523464ebd5Sriastradh   struct draw_llvm_variant *base;
6533464ebd5Sriastradh   struct draw_llvm_variant_list_item *next, *prev;
6543464ebd5Sriastradh};
6553464ebd5Sriastradh
656af69d88dSmrgstruct draw_gs_llvm_variant_list_item
657af69d88dSmrg{
658af69d88dSmrg   struct draw_gs_llvm_variant *base;
659af69d88dSmrg   struct draw_gs_llvm_variant_list_item *next, *prev;
660af69d88dSmrg};
661af69d88dSmrg
6627ec681f3Smrgstruct draw_tcs_llvm_variant_list_item
6637ec681f3Smrg{
6647ec681f3Smrg   struct draw_tcs_llvm_variant *base;
6657ec681f3Smrg   struct draw_tcs_llvm_variant_list_item *next, *prev;
6667ec681f3Smrg};
6677ec681f3Smrg
6687ec681f3Smrgstruct draw_tes_llvm_variant_list_item
6697ec681f3Smrg{
6707ec681f3Smrg   struct draw_tes_llvm_variant *base;
6717ec681f3Smrg   struct draw_tes_llvm_variant_list_item *next, *prev;
6727ec681f3Smrg};
673af69d88dSmrg
6743464ebd5Sriastradhstruct draw_llvm_variant
6753464ebd5Sriastradh{
676af69d88dSmrg   struct gallivm_state *gallivm;
677af69d88dSmrg
678af69d88dSmrg   /* LLVM JIT builder types */
679af69d88dSmrg   LLVMTypeRef context_ptr_type;
680af69d88dSmrg   LLVMTypeRef buffer_ptr_type;
681af69d88dSmrg   LLVMTypeRef vb_ptr_type;
682af69d88dSmrg   LLVMTypeRef vertex_header_ptr_type;
683af69d88dSmrg
6843464ebd5Sriastradh   LLVMValueRef function;
6853464ebd5Sriastradh   draw_jit_vert_func jit_func;
6863464ebd5Sriastradh
6873464ebd5Sriastradh   struct llvm_vertex_shader *shader;
6883464ebd5Sriastradh
6893464ebd5Sriastradh   struct draw_llvm *llvm;
6903464ebd5Sriastradh   struct draw_llvm_variant_list_item list_item_global;
6913464ebd5Sriastradh   struct draw_llvm_variant_list_item list_item_local;
6923464ebd5Sriastradh
6933464ebd5Sriastradh   /* key is variable-sized, must be last */
6943464ebd5Sriastradh   struct draw_llvm_variant_key key;
6953464ebd5Sriastradh};
6963464ebd5Sriastradh
697af69d88dSmrg
698af69d88dSmrgstruct draw_gs_llvm_variant
699af69d88dSmrg{
700af69d88dSmrg   struct gallivm_state *gallivm;
701af69d88dSmrg
702af69d88dSmrg   /* LLVM JIT builder types */
703af69d88dSmrg   LLVMTypeRef context_ptr_type;
704af69d88dSmrg   LLVMTypeRef vertex_header_ptr_type;
705af69d88dSmrg   LLVMTypeRef input_array_type;
706af69d88dSmrg
707af69d88dSmrg   LLVMValueRef context_ptr;
708af69d88dSmrg   LLVMValueRef io_ptr;
709af69d88dSmrg   LLVMValueRef num_prims;
710af69d88dSmrg   LLVMValueRef function;
711af69d88dSmrg   draw_gs_jit_func jit_func;
712af69d88dSmrg
713af69d88dSmrg   struct llvm_geometry_shader *shader;
714af69d88dSmrg
715af69d88dSmrg   struct draw_llvm *llvm;
716af69d88dSmrg   struct draw_gs_llvm_variant_list_item list_item_global;
717af69d88dSmrg   struct draw_gs_llvm_variant_list_item list_item_local;
718af69d88dSmrg
719af69d88dSmrg   /* key is variable-sized, must be last */
720af69d88dSmrg   struct draw_gs_llvm_variant_key key;
721af69d88dSmrg};
722af69d88dSmrg
7237ec681f3Smrgstruct draw_tcs_llvm_variant
7247ec681f3Smrg{
7257ec681f3Smrg   struct gallivm_state *gallivm;
7267ec681f3Smrg
7277ec681f3Smrg   /* LLVM JIT builder types */
7287ec681f3Smrg   LLVMTypeRef context_ptr_type;
7297ec681f3Smrg   LLVMTypeRef input_array_type;
7307ec681f3Smrg   LLVMTypeRef output_array_type;
7317ec681f3Smrg
7327ec681f3Smrg   LLVMValueRef context_ptr;
7337ec681f3Smrg   LLVMValueRef io_ptr;
7347ec681f3Smrg   LLVMValueRef num_prims;
7357ec681f3Smrg   LLVMValueRef function;
7367ec681f3Smrg   draw_tcs_jit_func jit_func;
7377ec681f3Smrg
7387ec681f3Smrg   struct llvm_tess_ctrl_shader *shader;
7397ec681f3Smrg
7407ec681f3Smrg   struct draw_llvm *llvm;
7417ec681f3Smrg   struct draw_tcs_llvm_variant_list_item list_item_global;
7427ec681f3Smrg   struct draw_tcs_llvm_variant_list_item list_item_local;
7437ec681f3Smrg
7447ec681f3Smrg   /* key is variable-sized, must be last */
7457ec681f3Smrg   struct draw_tcs_llvm_variant_key key;
7467ec681f3Smrg};
7477ec681f3Smrg
7487ec681f3Smrgstruct draw_tes_llvm_variant
7497ec681f3Smrg{
7507ec681f3Smrg   struct gallivm_state *gallivm;
7517ec681f3Smrg
7527ec681f3Smrg   /* LLVM JIT builder types */
7537ec681f3Smrg   LLVMTypeRef context_ptr_type;
7547ec681f3Smrg   LLVMTypeRef vertex_header_ptr_type;
7557ec681f3Smrg   LLVMTypeRef input_array_type;
7567ec681f3Smrg   LLVMTypeRef patch_input_array_type;
7577ec681f3Smrg
7587ec681f3Smrg   LLVMValueRef context_ptr;
7597ec681f3Smrg   LLVMValueRef io_ptr;
7607ec681f3Smrg   LLVMValueRef num_prims;
7617ec681f3Smrg   LLVMValueRef function;
7627ec681f3Smrg   draw_tes_jit_func jit_func;
7637ec681f3Smrg
7647ec681f3Smrg   struct llvm_tess_eval_shader *shader;
7657ec681f3Smrg
7667ec681f3Smrg   struct draw_llvm *llvm;
7677ec681f3Smrg   struct draw_tes_llvm_variant_list_item list_item_global;
7687ec681f3Smrg   struct draw_tes_llvm_variant_list_item list_item_local;
7697ec681f3Smrg
7707ec681f3Smrg   /* key is variable-sized, must be last */
7717ec681f3Smrg   struct draw_tes_llvm_variant_key key;
7727ec681f3Smrg};
7737ec681f3Smrg
7743464ebd5Sriastradhstruct llvm_vertex_shader {
7753464ebd5Sriastradh   struct draw_vertex_shader base;
7763464ebd5Sriastradh
7773464ebd5Sriastradh   unsigned variant_key_size;
7783464ebd5Sriastradh   struct draw_llvm_variant_list_item variants;
7793464ebd5Sriastradh   unsigned variants_created;
7803464ebd5Sriastradh   unsigned variants_cached;
7813464ebd5Sriastradh};
7823464ebd5Sriastradh
783af69d88dSmrgstruct llvm_geometry_shader {
784af69d88dSmrg   struct draw_geometry_shader base;
785af69d88dSmrg
786af69d88dSmrg   unsigned variant_key_size;
787af69d88dSmrg   struct draw_gs_llvm_variant_list_item variants;
788af69d88dSmrg   unsigned variants_created;
789af69d88dSmrg   unsigned variants_cached;
790af69d88dSmrg};
791af69d88dSmrg
7927ec681f3Smrgstruct llvm_tess_ctrl_shader {
7937ec681f3Smrg   struct draw_tess_ctrl_shader base;
7947ec681f3Smrg
7957ec681f3Smrg   unsigned variant_key_size;
7967ec681f3Smrg   struct draw_tcs_llvm_variant_list_item variants;
7977ec681f3Smrg   unsigned variants_created;
7987ec681f3Smrg   unsigned variants_cached;
7997ec681f3Smrg};
8007ec681f3Smrg
8017ec681f3Smrgstruct llvm_tess_eval_shader {
8027ec681f3Smrg   struct draw_tess_eval_shader base;
8037ec681f3Smrg
8047ec681f3Smrg   unsigned variant_key_size;
8057ec681f3Smrg   struct draw_tes_llvm_variant_list_item variants;
8067ec681f3Smrg   unsigned variants_created;
8077ec681f3Smrg   unsigned variants_cached;
8087ec681f3Smrg};
809af69d88dSmrg
8103464ebd5Sriastradhstruct draw_llvm {
8113464ebd5Sriastradh   struct draw_context *draw;
8123464ebd5Sriastradh
81301e04c3fSmrg   LLVMContextRef context;
81401e04c3fSmrg   boolean context_owned;
81501e04c3fSmrg
8163464ebd5Sriastradh   struct draw_jit_context jit_context;
817af69d88dSmrg   struct draw_gs_jit_context gs_jit_context;
8187ec681f3Smrg   struct draw_tcs_jit_context tcs_jit_context;
8197ec681f3Smrg   struct draw_tes_jit_context tes_jit_context;
8203464ebd5Sriastradh
8213464ebd5Sriastradh   struct draw_llvm_variant_list_item vs_variants_list;
8223464ebd5Sriastradh   int nr_variants;
8233464ebd5Sriastradh
824af69d88dSmrg   struct draw_gs_llvm_variant_list_item gs_variants_list;
825af69d88dSmrg   int nr_gs_variants;
8267ec681f3Smrg
8277ec681f3Smrg   struct draw_tcs_llvm_variant_list_item tcs_variants_list;
8287ec681f3Smrg   int nr_tcs_variants;
8297ec681f3Smrg
8307ec681f3Smrg   struct draw_tes_llvm_variant_list_item tes_variants_list;
8317ec681f3Smrg   int nr_tes_variants;
8323464ebd5Sriastradh};
8333464ebd5Sriastradh
8343464ebd5Sriastradh
83501e04c3fSmrgstatic inline struct llvm_vertex_shader *
8363464ebd5Sriastradhllvm_vertex_shader(struct draw_vertex_shader *vs)
8373464ebd5Sriastradh{
8383464ebd5Sriastradh   return (struct llvm_vertex_shader *)vs;
8393464ebd5Sriastradh}
8403464ebd5Sriastradh
84101e04c3fSmrgstatic inline struct llvm_geometry_shader *
842af69d88dSmrgllvm_geometry_shader(struct draw_geometry_shader *gs)
843af69d88dSmrg{
844af69d88dSmrg   return (struct llvm_geometry_shader *)gs;
845af69d88dSmrg}
846af69d88dSmrg
8477ec681f3Smrgstatic inline struct llvm_tess_ctrl_shader *
8487ec681f3Smrgllvm_tess_ctrl_shader(struct draw_tess_ctrl_shader *tcs)
8497ec681f3Smrg{
8507ec681f3Smrg   return (struct llvm_tess_ctrl_shader *)tcs;
8517ec681f3Smrg}
852af69d88dSmrg
8537ec681f3Smrgstatic inline struct llvm_tess_eval_shader *
8547ec681f3Smrgllvm_tess_eval_shader(struct draw_tess_eval_shader *tes)
8557ec681f3Smrg{
8567ec681f3Smrg   return (struct llvm_tess_eval_shader *)tes;
8577ec681f3Smrg}
8583464ebd5Sriastradh
8593464ebd5Sriastradhstruct draw_llvm *
86001e04c3fSmrgdraw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);
8613464ebd5Sriastradh
8623464ebd5Sriastradhvoid
8633464ebd5Sriastradhdraw_llvm_destroy(struct draw_llvm *llvm);
8643464ebd5Sriastradh
8653464ebd5Sriastradhstruct draw_llvm_variant *
8663464ebd5Sriastradhdraw_llvm_create_variant(struct draw_llvm *llvm,
867af69d88dSmrg                         unsigned num_vertex_header_attribs,
868af69d88dSmrg                         const struct draw_llvm_variant_key *key);
8693464ebd5Sriastradh
8703464ebd5Sriastradhvoid
8713464ebd5Sriastradhdraw_llvm_destroy_variant(struct draw_llvm_variant *variant);
8723464ebd5Sriastradh
8733464ebd5Sriastradhstruct draw_llvm_variant_key *
8743464ebd5Sriastradhdraw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
8753464ebd5Sriastradh
876af69d88dSmrgvoid
877af69d88dSmrgdraw_llvm_dump_variant_key(struct draw_llvm_variant_key *key);
878af69d88dSmrg
879af69d88dSmrg
880af69d88dSmrgstruct draw_gs_llvm_variant *
881af69d88dSmrgdraw_gs_llvm_create_variant(struct draw_llvm *llvm,
882af69d88dSmrg                            unsigned num_vertex_header_attribs,
883af69d88dSmrg                            const struct draw_gs_llvm_variant_key *key);
884af69d88dSmrg
885af69d88dSmrgvoid
886af69d88dSmrgdraw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant);
887af69d88dSmrg
888af69d88dSmrgstruct draw_gs_llvm_variant_key *
889af69d88dSmrgdraw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
890af69d88dSmrg
891af69d88dSmrgvoid
892af69d88dSmrgdraw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
8933464ebd5Sriastradh
8947ec681f3Smrgstruct draw_tcs_llvm_variant *
8957ec681f3Smrgdraw_tcs_llvm_create_variant(struct draw_llvm *llvm,
8967ec681f3Smrg                             unsigned num_vertex_header_attribs,
8977ec681f3Smrg                             const struct draw_tcs_llvm_variant_key *key);
8987ec681f3Smrg
8997ec681f3Smrgvoid
9007ec681f3Smrgdraw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant);
9017ec681f3Smrg
9027ec681f3Smrgstruct draw_tcs_llvm_variant_key *
9037ec681f3Smrgdraw_tcs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
9047ec681f3Smrg
9057ec681f3Smrgvoid
9067ec681f3Smrgdraw_tcs_llvm_dump_variant_key(struct draw_tcs_llvm_variant_key *key);
9077ec681f3Smrg
9087ec681f3Smrgstruct draw_tes_llvm_variant *
9097ec681f3Smrgdraw_tes_llvm_create_variant(struct draw_llvm *llvm,
9107ec681f3Smrg                             unsigned num_vertex_header_attribs,
9117ec681f3Smrg                             const struct draw_tes_llvm_variant_key *key);
9127ec681f3Smrg
9137ec681f3Smrgvoid
9147ec681f3Smrgdraw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant);
9157ec681f3Smrg
9167ec681f3Smrgstruct draw_tes_llvm_variant_key *
9177ec681f3Smrgdraw_tes_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
9187ec681f3Smrg
9197ec681f3Smrgvoid
9207ec681f3Smrgdraw_tes_llvm_dump_variant_key(struct draw_tes_llvm_variant_key *key);
9217ec681f3Smrg
9223464ebd5Sriastradhstruct lp_build_sampler_soa *
9237ec681f3Smrgdraw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,
9247ec681f3Smrg                             unsigned nr_samplers);
9257ec681f3Smrg
9267ec681f3Smrgstruct lp_build_image_soa *
9277ec681f3Smrgdraw_llvm_image_soa_create(const struct draw_image_static_state *static_state,
9287ec681f3Smrg                           unsigned nr_images);
9293464ebd5Sriastradh
9303464ebd5Sriastradhvoid
93101e04c3fSmrgdraw_llvm_set_sampler_state(struct draw_context *draw,
93201e04c3fSmrg                            enum pipe_shader_type shader_stage);
9333464ebd5Sriastradh
9343464ebd5Sriastradhvoid
9353464ebd5Sriastradhdraw_llvm_set_mapped_texture(struct draw_context *draw,
93601e04c3fSmrg                             enum pipe_shader_type shader_stage,
937af69d88dSmrg                             unsigned sview_idx,
9383464ebd5Sriastradh                             uint32_t width, uint32_t height, uint32_t depth,
9393464ebd5Sriastradh                             uint32_t first_level, uint32_t last_level,
9407ec681f3Smrg                             uint32_t num_samples,
9417ec681f3Smrg                             uint32_t sample_stride,
942af69d88dSmrg                             const void *base_ptr,
9433464ebd5Sriastradh                             uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
9443464ebd5Sriastradh                             uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
945af69d88dSmrg                             uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
9463464ebd5Sriastradh
9477ec681f3Smrgvoid
9487ec681f3Smrgdraw_llvm_set_mapped_image(struct draw_context *draw,
9497ec681f3Smrg                           enum pipe_shader_type shader_stage,
9507ec681f3Smrg                           unsigned idx,
9517ec681f3Smrg                           uint32_t width, uint32_t height, uint32_t depth,
9527ec681f3Smrg                           const void *base_ptr,
9537ec681f3Smrg                           uint32_t row_stride,
9547ec681f3Smrg                           uint32_t img_stride,
9557ec681f3Smrg                           uint32_t num_samples,
9567ec681f3Smrg                           uint32_t sample_stride);
9573464ebd5Sriastradh#endif
958