Path: blob/21.2-virgl/src/gallium/auxiliary/draw/draw_llvm.h
4565 views
/**************************************************************************1*2* Copyright 2010 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef DRAW_LLVM_H28#define DRAW_LLVM_H2930#include "draw/draw_private.h"3132#include "draw/draw_vs.h"33#include "draw/draw_gs.h"34#include "draw/draw_tess.h"3536#include "gallivm/lp_bld_sample.h"37#include "gallivm/lp_bld_limits.h"3839#include "pipe/p_context.h"40#include "util/simple_list.h"414243struct draw_llvm;44struct llvm_vertex_shader;45struct llvm_geometry_shader;46struct llvm_tess_ctrl_shader;47struct llvm_tess_eval_shader;4849struct draw_jit_texture50{51uint32_t width;52uint32_t height;53uint32_t depth;54const void *base;55uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];56uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];57uint32_t first_level;58uint32_t last_level;59uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];60uint32_t num_samples;61uint32_t sample_stride;62};636465struct draw_sampler_static_state66{67/*68* These attributes are effectively interleaved for more sane key handling.69* However, there might be lots of null space if the amount of samplers and70* textures isn't the same.71*/72struct lp_static_sampler_state sampler_state;73struct lp_static_texture_state texture_state;74};7576struct draw_image_static_state77{78struct lp_static_texture_state image_state;79};808182struct draw_jit_sampler83{84float min_lod;85float max_lod;86float lod_bias;87float border_color[4];88};899091struct draw_jit_image92{93uint32_t width;94uint32_t height;95uint32_t depth;96const void *base;97uint32_t row_stride;98uint32_t img_stride;99uint32_t num_samples;100uint32_t sample_stride;101};102103enum {104DRAW_JIT_TEXTURE_WIDTH = 0,105DRAW_JIT_TEXTURE_HEIGHT,106DRAW_JIT_TEXTURE_DEPTH,107DRAW_JIT_TEXTURE_BASE,108DRAW_JIT_TEXTURE_ROW_STRIDE,109DRAW_JIT_TEXTURE_IMG_STRIDE,110DRAW_JIT_TEXTURE_FIRST_LEVEL,111DRAW_JIT_TEXTURE_LAST_LEVEL,112DRAW_JIT_TEXTURE_MIP_OFFSETS,113DRAW_JIT_TEXTURE_NUM_SAMPLES,114DRAW_JIT_TEXTURE_SAMPLE_STRIDE,115DRAW_JIT_TEXTURE_NUM_FIELDS /* number of fields above */116};117118119enum {120DRAW_JIT_SAMPLER_MIN_LOD,121DRAW_JIT_SAMPLER_MAX_LOD,122DRAW_JIT_SAMPLER_LOD_BIAS,123DRAW_JIT_SAMPLER_BORDER_COLOR,124DRAW_JIT_SAMPLER_NUM_FIELDS /* number of fields above */125};126127128enum {129DRAW_JIT_VERTEX_VERTEX_ID = 0,130DRAW_JIT_VERTEX_CLIP_POS,131DRAW_JIT_VERTEX_DATA132};133134enum {135DRAW_JIT_IMAGE_WIDTH = 0,136DRAW_JIT_IMAGE_HEIGHT,137DRAW_JIT_IMAGE_DEPTH,138DRAW_JIT_IMAGE_BASE,139DRAW_JIT_IMAGE_ROW_STRIDE,140DRAW_JIT_IMAGE_IMG_STRIDE,141DRAW_JIT_IMAGE_NUM_SAMPLES,142DRAW_JIT_IMAGE_SAMPLE_STRIDE,143DRAW_JIT_IMAGE_NUM_FIELDS /* number of fields above */144};145146/**147* This structure is passed directly to the generated vertex shader.148*149* It contains the derived state.150*151* Changes here must be reflected in the draw_jit_context_* macros.152* Changes to the ordering should be avoided.153*154* Only use types with a clear size and padding here, in particular prefer the155* stdint.h types to the basic integer types.156*/157struct draw_jit_context158{159const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];160int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS];161float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];162struct pipe_viewport_state *viewports;163164struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];165struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];166struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];167168const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];169int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];170};171172enum {173DRAW_JIT_CTX_CONSTANTS = 0,174DRAW_JIT_CTX_NUM_CONSTANTS = 1,175DRAW_JIT_CTX_PLANES = 2,176DRAW_JIT_CTX_VIEWPORT = 3,177DRAW_JIT_CTX_TEXTURES = 4,178DRAW_JIT_CTX_SAMPLERS = 5,179DRAW_JIT_CTX_IMAGES = 6,180DRAW_JIT_CTX_SSBOS = 7,181DRAW_JIT_CTX_NUM_SSBOS = 8,182DRAW_JIT_CTX_NUM_FIELDS183};184185#define draw_jit_context_vs_constants(_gallivm, _ptr) \186lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")187188#define draw_jit_context_num_vs_constants(_gallivm, _ptr) \189lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")190191#define draw_jit_context_planes(_gallivm, _ptr) \192lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")193194#define draw_jit_context_viewports(_gallivm, _ptr) \195lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports")196197#define draw_jit_context_textures(_gallivm, _ptr) \198lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")199200#define draw_jit_context_samplers(_gallivm, _ptr) \201lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")202203#define draw_jit_context_images(_gallivm, _ptr) \204lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")205206#define draw_jit_context_vs_ssbos(_gallivm, _ptr) \207lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")208209#define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \210lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")211212213#define draw_jit_header_id(_gallivm, _ptr) \214lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")215216#define draw_jit_header_clip_pos(_gallivm, _ptr) \217lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")218219#define draw_jit_header_data(_gallivm, _ptr) \220lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data")221222223#define draw_jit_vbuffer_stride(_gallivm, _ptr) \224lp_build_struct_get(_gallivm, _ptr, 0, "stride")225226#define draw_jit_vbuffer_offset(_gallivm, _ptr) \227lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")228229enum {230DRAW_JIT_DVBUFFER_MAP = 0,231DRAW_JIT_DVBUFFER_SIZE,232DRAW_JIT_DVBUFFER_NUM_FIELDS /* number of fields above */233};234235#define draw_jit_dvbuffer_map(_gallivm, _ptr) \236lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map")237238#define draw_jit_dvbuffer_size(_gallivm, _ptr) \239lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size")240241242/**243* This structure is passed directly to the generated geometry shader.244*245* It contains the derived state.246*247* Changes here must be reflected in the draw_gs_jit_context_* macros.248* Changes to the ordering should be avoided.249*250* Only use types with a clear size and padding here, in particular prefer the251* stdint.h types to the basic integer types.252*/253struct draw_gs_jit_context254{255const float *constants[LP_MAX_TGSI_CONST_BUFFERS];256int num_constants[LP_MAX_TGSI_CONST_BUFFERS];257float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];258struct pipe_viewport_state *viewports;259260/* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and261* DRAW_JIT_CTX_SAMPLERS positions in the struct */262struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];263struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];264struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];265266int **prim_lengths;267int *emitted_vertices;268int *emitted_prims;269const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];270int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];271272};273274enum {275DRAW_GS_JIT_CTX_CONSTANTS = 0,276DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1,277DRAW_GS_JIT_CTX_PLANES = 2,278DRAW_GS_JIT_CTX_VIEWPORT = 3,279/* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES280* and DRAW_JIT_CTX_SAMPLERS, because they both need281* to be at exactly the same locations as they are in the282* VS ctx structure for sampling to work. */283DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,284DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,285DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,286DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7,287DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8,288DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9,289DRAW_GS_JIT_CTX_SSBOS = 10,290DRAW_GS_JIT_CTX_NUM_SSBOS = 11,291DRAW_GS_JIT_CTX_NUM_FIELDS = 12292};293294#define draw_gs_jit_context_constants(_gallivm, _ptr) \295lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")296297#define draw_gs_jit_context_num_constants(_gallivm, _ptr) \298lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")299300#define draw_gs_jit_context_planes(_gallivm, _ptr) \301lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")302303#define draw_gs_jit_context_viewports(_gallivm, _ptr) \304lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports")305306#define draw_gs_jit_context_textures(_gallivm, _ptr) \307lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures")308309#define draw_gs_jit_context_samplers(_gallivm, _ptr) \310lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")311312#define draw_gs_jit_context_images(_gallivm, _ptr) \313lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")314315#define draw_gs_jit_prim_lengths(_gallivm, _ptr) \316lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")317318#define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \319lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices")320321#define draw_gs_jit_emitted_prims(_gallivm, _ptr) \322lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")323324#define draw_gs_jit_context_ssbos(_gallivm, _ptr) \325lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")326327#define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \328lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")329330331struct draw_tcs_jit_context {332const float *constants[LP_MAX_TGSI_CONST_BUFFERS];333int num_constants[LP_MAX_TGSI_CONST_BUFFERS];334335int dummy1;336int dummy2;337/* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and338* DRAW_JIT_CTX_SAMPLERS positions in the struct */339struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];340struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];341struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];342343const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];344int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];345};346347enum {348DRAW_TCS_JIT_CTX_CONSTANTS = 0,349DRAW_TCS_JIT_CTX_NUM_CONSTANTS = 1,350DRAW_TCS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,351DRAW_TCS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,352DRAW_TCS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,353DRAW_TCS_JIT_CTX_SSBOS = 7,354DRAW_TCS_JIT_CTX_NUM_SSBOS = 8,355DRAW_TCS_JIT_CTX_NUM_FIELDS = 9,356};357358#define draw_tcs_jit_context_constants(_gallivm, _ptr) \359lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants")360361#define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \362lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants")363364#define draw_tcs_jit_context_textures(_gallivm, _ptr) \365lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures")366367#define draw_tcs_jit_context_samplers(_gallivm, _ptr) \368lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers")369370#define draw_tcs_jit_context_images(_gallivm, _ptr) \371lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images")372373#define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \374lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos")375376#define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \377lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos")378379struct draw_tes_jit_context {380const float *constants[LP_MAX_TGSI_CONST_BUFFERS];381int num_constants[LP_MAX_TGSI_CONST_BUFFERS];382383int dummy1;384int dummy2;385/* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and386* DRAW_JIT_CTX_SAMPLERS positions in the struct */387struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];388struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];389struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];390391const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];392int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];393};394395enum {396DRAW_TES_JIT_CTX_CONSTANTS = 0,397DRAW_TES_JIT_CTX_NUM_CONSTANTS = 1,398DRAW_TES_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,399DRAW_TES_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,400DRAW_TES_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,401DRAW_TES_JIT_CTX_SSBOS = 7,402DRAW_TES_JIT_CTX_NUM_SSBOS = 8,403DRAW_TES_JIT_CTX_NUM_FIELDS = 9,404};405406#define draw_tes_jit_context_constants(_gallivm, _ptr) \407lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants")408409#define draw_tes_jit_context_num_constants(_gallivm, _ptr) \410lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants")411412#define draw_tes_jit_context_textures(_gallivm, _ptr) \413lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures")414415#define draw_tes_jit_context_samplers(_gallivm, _ptr) \416lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers")417418#define draw_tes_jit_context_images(_gallivm, _ptr) \419lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images")420421#define draw_tes_jit_context_ssbos(_gallivm, _ptr) \422lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos")423424#define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \425lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos")426427typedef boolean428(*draw_jit_vert_func)(struct draw_jit_context *context,429struct vertex_header *io,430const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],431unsigned count,432unsigned start_or_maxelt,433unsigned stride,434struct pipe_vertex_buffer *vertex_buffers,435unsigned instance_id,436unsigned vertex_id_offset,437unsigned start_instance,438const unsigned *fetch_elts,439unsigned draw_id, unsigned view_id);440441442typedef int443(*draw_gs_jit_func)(struct draw_gs_jit_context *context,444float inputs[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS],445struct vertex_header **output,446unsigned num_prims,447unsigned instance_id,448int *prim_ids,449unsigned invocation_id,450unsigned view_id);451452typedef int453(*draw_tcs_jit_func)(struct draw_tcs_jit_context *context,454float inputs[32][NUM_TCS_INPUTS][TGSI_NUM_CHANNELS],455float outputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],456uint32_t prim_id, uint32_t patch_vertices_in,457unsigned view_id);458459typedef int460(*draw_tes_jit_func)(struct draw_tes_jit_context *context,461float inputs[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS],462struct vertex_header *io,463uint32_t prim_id, uint32_t num_tess_coord,464float *tess_coord_x, float *tess_coord_y, float *tess_outer,465float *tess_inner, uint32_t patch_vertices_in,466unsigned view_id);467468469struct draw_llvm_variant_key470{471unsigned nr_vertex_elements:8;472unsigned nr_samplers:8;473unsigned nr_sampler_views:8;474unsigned nr_images:8;475unsigned clamp_vertex_color:1;476unsigned clip_xy:1;477unsigned clip_z:1;478unsigned clip_user:1;479unsigned clip_halfz:1;480unsigned bypass_viewport:1;481unsigned need_edgeflags:1;482unsigned has_gs_or_tes:1;483unsigned num_outputs:8;484unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;485/* note padding here - must use memset */486487/* Variable number of vertex elements:488*/489struct pipe_vertex_element vertex_element[1];490491/* Followed by variable number of samplers:492*/493/* struct draw_sampler_static_state sampler; */494/* Followed by variable number of images495*/496};497498struct draw_gs_llvm_variant_key499{500unsigned nr_samplers:8;501unsigned nr_sampler_views:8;502unsigned nr_images:8;503unsigned num_outputs:8;504/* note padding here - must use memset */505506struct draw_sampler_static_state samplers[1];507/* Followed by variable number of images.*/508};509510struct draw_tcs_llvm_variant_key511{512unsigned nr_samplers:8;513unsigned nr_sampler_views:8;514unsigned nr_images:8;515struct draw_sampler_static_state samplers[1];516/* Followed by variable number of images.*/517};518519struct draw_tes_llvm_variant_key520{521unsigned nr_samplers:8;522unsigned nr_sampler_views:8;523unsigned nr_images:8;524unsigned primid_output:7;525unsigned primid_needed:1;526struct draw_sampler_static_state samplers[1];527/* Followed by variable number of images.*/528};529530#define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \531(sizeof(struct draw_llvm_variant_key) + \532PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) + \533PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \534(PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))535536#define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \537(sizeof(struct draw_gs_llvm_variant_key) + \538PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \539PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))540541#define DRAW_TCS_LLVM_MAX_VARIANT_KEY_SIZE \542(sizeof(struct draw_tcs_llvm_variant_key) + \543PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \544PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))545546#define DRAW_TES_LLVM_MAX_VARIANT_KEY_SIZE \547(sizeof(struct draw_tes_llvm_variant_key) + \548PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \549PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))550551552static inline size_t553draw_llvm_variant_key_size(unsigned nr_vertex_elements,554unsigned nr_samplers, unsigned nr_images)555{556return (sizeof(struct draw_llvm_variant_key) +557nr_samplers * sizeof(struct draw_sampler_static_state) +558nr_images * sizeof(struct draw_image_static_state) +559(nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));560}561562563static inline size_t564draw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)565{566return (sizeof(struct draw_gs_llvm_variant_key) +567(nr_images) * sizeof(struct draw_sampler_static_state) +568(nr_samplers - 1) * sizeof(struct draw_sampler_static_state));569}570571static inline size_t572draw_tcs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)573{574return (sizeof(struct draw_tcs_llvm_variant_key) +575(nr_images) * sizeof(struct draw_sampler_static_state) +576(nr_samplers - 1) * sizeof(struct draw_sampler_static_state));577}578579static inline size_t580draw_tes_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)581{582return (sizeof(struct draw_tes_llvm_variant_key) +583(nr_images) * sizeof(struct draw_sampler_static_state) +584(nr_samplers - 1) * sizeof(struct draw_sampler_static_state));585}586587static inline struct draw_sampler_static_state *588draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)589{590return (struct draw_sampler_static_state *)591&key->vertex_element[key->nr_vertex_elements];592}593594static inline struct draw_image_static_state *595draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)596{597struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)598(&key->vertex_element[key->nr_vertex_elements]);599return (struct draw_image_static_state *)600&samplers[key->nr_samplers];601}602603static inline struct draw_image_static_state *604draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)605{606return (struct draw_image_static_state *)607&key->samplers[key->nr_samplers];608}609610static inline struct draw_image_static_state *611draw_tcs_llvm_variant_key_images(struct draw_tcs_llvm_variant_key *key)612{613return (struct draw_image_static_state *)614&key->samplers[key->nr_samplers];615}616617static inline struct draw_image_static_state *618draw_tes_llvm_variant_key_images(struct draw_tes_llvm_variant_key *key)619{620return (struct draw_image_static_state *)621&key->samplers[key->nr_samplers];622}623624struct draw_llvm_variant_list_item625{626struct draw_llvm_variant *base;627struct draw_llvm_variant_list_item *next, *prev;628};629630struct draw_gs_llvm_variant_list_item631{632struct draw_gs_llvm_variant *base;633struct draw_gs_llvm_variant_list_item *next, *prev;634};635636struct draw_tcs_llvm_variant_list_item637{638struct draw_tcs_llvm_variant *base;639struct draw_tcs_llvm_variant_list_item *next, *prev;640};641642struct draw_tes_llvm_variant_list_item643{644struct draw_tes_llvm_variant *base;645struct draw_tes_llvm_variant_list_item *next, *prev;646};647648struct draw_llvm_variant649{650struct gallivm_state *gallivm;651652/* LLVM JIT builder types */653LLVMTypeRef context_ptr_type;654LLVMTypeRef buffer_ptr_type;655LLVMTypeRef vb_ptr_type;656LLVMTypeRef vertex_header_ptr_type;657658LLVMValueRef function;659draw_jit_vert_func jit_func;660661struct llvm_vertex_shader *shader;662663struct draw_llvm *llvm;664struct draw_llvm_variant_list_item list_item_global;665struct draw_llvm_variant_list_item list_item_local;666667/* key is variable-sized, must be last */668struct draw_llvm_variant_key key;669};670671672struct draw_gs_llvm_variant673{674struct gallivm_state *gallivm;675676/* LLVM JIT builder types */677LLVMTypeRef context_ptr_type;678LLVMTypeRef vertex_header_ptr_type;679LLVMTypeRef input_array_type;680681LLVMValueRef context_ptr;682LLVMValueRef io_ptr;683LLVMValueRef num_prims;684LLVMValueRef function;685draw_gs_jit_func jit_func;686687struct llvm_geometry_shader *shader;688689struct draw_llvm *llvm;690struct draw_gs_llvm_variant_list_item list_item_global;691struct draw_gs_llvm_variant_list_item list_item_local;692693/* key is variable-sized, must be last */694struct draw_gs_llvm_variant_key key;695};696697struct draw_tcs_llvm_variant698{699struct gallivm_state *gallivm;700701/* LLVM JIT builder types */702LLVMTypeRef context_ptr_type;703LLVMTypeRef input_array_type;704LLVMTypeRef output_array_type;705706LLVMValueRef context_ptr;707LLVMValueRef io_ptr;708LLVMValueRef num_prims;709LLVMValueRef function;710draw_tcs_jit_func jit_func;711712struct llvm_tess_ctrl_shader *shader;713714struct draw_llvm *llvm;715struct draw_tcs_llvm_variant_list_item list_item_global;716struct draw_tcs_llvm_variant_list_item list_item_local;717718/* key is variable-sized, must be last */719struct draw_tcs_llvm_variant_key key;720};721722struct draw_tes_llvm_variant723{724struct gallivm_state *gallivm;725726/* LLVM JIT builder types */727LLVMTypeRef context_ptr_type;728LLVMTypeRef vertex_header_ptr_type;729LLVMTypeRef input_array_type;730LLVMTypeRef patch_input_array_type;731732LLVMValueRef context_ptr;733LLVMValueRef io_ptr;734LLVMValueRef num_prims;735LLVMValueRef function;736draw_tes_jit_func jit_func;737738struct llvm_tess_eval_shader *shader;739740struct draw_llvm *llvm;741struct draw_tes_llvm_variant_list_item list_item_global;742struct draw_tes_llvm_variant_list_item list_item_local;743744/* key is variable-sized, must be last */745struct draw_tes_llvm_variant_key key;746};747748struct llvm_vertex_shader {749struct draw_vertex_shader base;750751unsigned variant_key_size;752struct draw_llvm_variant_list_item variants;753unsigned variants_created;754unsigned variants_cached;755};756757struct llvm_geometry_shader {758struct draw_geometry_shader base;759760unsigned variant_key_size;761struct draw_gs_llvm_variant_list_item variants;762unsigned variants_created;763unsigned variants_cached;764};765766struct llvm_tess_ctrl_shader {767struct draw_tess_ctrl_shader base;768769unsigned variant_key_size;770struct draw_tcs_llvm_variant_list_item variants;771unsigned variants_created;772unsigned variants_cached;773};774775struct llvm_tess_eval_shader {776struct draw_tess_eval_shader base;777778unsigned variant_key_size;779struct draw_tes_llvm_variant_list_item variants;780unsigned variants_created;781unsigned variants_cached;782};783784struct draw_llvm {785struct draw_context *draw;786787LLVMContextRef context;788boolean context_owned;789790struct draw_jit_context jit_context;791struct draw_gs_jit_context gs_jit_context;792struct draw_tcs_jit_context tcs_jit_context;793struct draw_tes_jit_context tes_jit_context;794795struct draw_llvm_variant_list_item vs_variants_list;796int nr_variants;797798struct draw_gs_llvm_variant_list_item gs_variants_list;799int nr_gs_variants;800801struct draw_tcs_llvm_variant_list_item tcs_variants_list;802int nr_tcs_variants;803804struct draw_tes_llvm_variant_list_item tes_variants_list;805int nr_tes_variants;806};807808809static inline struct llvm_vertex_shader *810llvm_vertex_shader(struct draw_vertex_shader *vs)811{812return (struct llvm_vertex_shader *)vs;813}814815static inline struct llvm_geometry_shader *816llvm_geometry_shader(struct draw_geometry_shader *gs)817{818return (struct llvm_geometry_shader *)gs;819}820821static inline struct llvm_tess_ctrl_shader *822llvm_tess_ctrl_shader(struct draw_tess_ctrl_shader *tcs)823{824return (struct llvm_tess_ctrl_shader *)tcs;825}826827static inline struct llvm_tess_eval_shader *828llvm_tess_eval_shader(struct draw_tess_eval_shader *tes)829{830return (struct llvm_tess_eval_shader *)tes;831}832833struct draw_llvm *834draw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);835836void837draw_llvm_destroy(struct draw_llvm *llvm);838839struct draw_llvm_variant *840draw_llvm_create_variant(struct draw_llvm *llvm,841unsigned num_vertex_header_attribs,842const struct draw_llvm_variant_key *key);843844void845draw_llvm_destroy_variant(struct draw_llvm_variant *variant);846847struct draw_llvm_variant_key *848draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);849850void851draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key);852853854struct draw_gs_llvm_variant *855draw_gs_llvm_create_variant(struct draw_llvm *llvm,856unsigned num_vertex_header_attribs,857const struct draw_gs_llvm_variant_key *key);858859void860draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant);861862struct draw_gs_llvm_variant_key *863draw_gs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);864865void866draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);867868struct draw_tcs_llvm_variant *869draw_tcs_llvm_create_variant(struct draw_llvm *llvm,870unsigned num_vertex_header_attribs,871const struct draw_tcs_llvm_variant_key *key);872873void874draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant);875876struct draw_tcs_llvm_variant_key *877draw_tcs_llvm_make_variant_key(struct draw_llvm *llvm, char *store);878879void880draw_tcs_llvm_dump_variant_key(struct draw_tcs_llvm_variant_key *key);881882struct draw_tes_llvm_variant *883draw_tes_llvm_create_variant(struct draw_llvm *llvm,884unsigned num_vertex_header_attribs,885const struct draw_tes_llvm_variant_key *key);886887void888draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant);889890struct draw_tes_llvm_variant_key *891draw_tes_llvm_make_variant_key(struct draw_llvm *llvm, char *store);892893void894draw_tes_llvm_dump_variant_key(struct draw_tes_llvm_variant_key *key);895896struct lp_build_sampler_soa *897draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,898unsigned nr_samplers);899900struct lp_build_image_soa *901draw_llvm_image_soa_create(const struct draw_image_static_state *static_state,902unsigned nr_images);903904void905draw_llvm_set_sampler_state(struct draw_context *draw,906enum pipe_shader_type shader_stage);907908void909draw_llvm_set_mapped_texture(struct draw_context *draw,910enum pipe_shader_type shader_stage,911unsigned sview_idx,912uint32_t width, uint32_t height, uint32_t depth,913uint32_t first_level, uint32_t last_level,914uint32_t num_samples,915uint32_t sample_stride,916const void *base_ptr,917uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],918uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],919uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);920921void922draw_llvm_set_mapped_image(struct draw_context *draw,923enum pipe_shader_type shader_stage,924unsigned idx,925uint32_t width, uint32_t height, uint32_t depth,926const void *base_ptr,927uint32_t row_stride,928uint32_t img_stride,929uint32_t num_samples,930uint32_t sample_stride);931#endif932933934