Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_jit.h
4570 views
/**************************************************************************1*2* Copyright 2009 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/**28* @file29* C - JIT interfaces30*31* @author Jose Fonseca <[email protected]>32*/3334#ifndef LP_JIT_H35#define LP_JIT_H363738#include "gallivm/lp_bld_struct.h"39#include "gallivm/lp_bld_limits.h"4041#include "pipe/p_state.h"42#include "lp_texture.h"434445struct lp_build_format_cache;46struct lp_fragment_shader_variant;47struct lp_compute_shader_variant;48struct llvmpipe_screen;495051struct lp_jit_texture52{53uint32_t width; /* same as number of elements */54uint32_t height;55uint32_t depth; /* doubles as array size */56const void *base;57uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];58uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];59uint32_t first_level;60uint32_t last_level;61uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];62uint32_t num_samples;63uint32_t sample_stride;64};656667struct lp_jit_sampler68{69float min_lod;70float max_lod;71float lod_bias;72float border_color[4];73};747576struct lp_jit_viewport77{78float min_depth;79float max_depth;80};818283struct lp_jit_image84{85uint32_t width; /* same as number of elements */86uint32_t height;87uint32_t depth;88const void *base;89uint32_t row_stride;90uint32_t img_stride;91uint32_t num_samples;92uint32_t sample_stride;93};9495enum {96LP_JIT_TEXTURE_WIDTH = 0,97LP_JIT_TEXTURE_HEIGHT,98LP_JIT_TEXTURE_DEPTH,99LP_JIT_TEXTURE_BASE,100LP_JIT_TEXTURE_ROW_STRIDE,101LP_JIT_TEXTURE_IMG_STRIDE,102LP_JIT_TEXTURE_FIRST_LEVEL,103LP_JIT_TEXTURE_LAST_LEVEL,104LP_JIT_TEXTURE_MIP_OFFSETS,105LP_JIT_TEXTURE_NUM_SAMPLES,106LP_JIT_TEXTURE_SAMPLE_STRIDE,107LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */108};109110111enum {112LP_JIT_SAMPLER_MIN_LOD,113LP_JIT_SAMPLER_MAX_LOD,114LP_JIT_SAMPLER_LOD_BIAS,115LP_JIT_SAMPLER_BORDER_COLOR,116LP_JIT_SAMPLER_NUM_FIELDS /* number of fields above */117};118119120enum {121LP_JIT_VIEWPORT_MIN_DEPTH,122LP_JIT_VIEWPORT_MAX_DEPTH,123LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */124};125126enum {127LP_JIT_IMAGE_WIDTH = 0,128LP_JIT_IMAGE_HEIGHT,129LP_JIT_IMAGE_DEPTH,130LP_JIT_IMAGE_BASE,131LP_JIT_IMAGE_ROW_STRIDE,132LP_JIT_IMAGE_IMG_STRIDE,133LP_JIT_IMAGE_NUM_SAMPLES,134LP_JIT_IMAGE_SAMPLE_STRIDE,135LP_JIT_IMAGE_NUM_FIELDS /* number of fields above */136};137/**138* This structure is passed directly to the generated fragment shader.139*140* It contains the derived state.141*142* Changes here must be reflected in the lp_jit_context_* macros and143* lp_jit_init_types function. Changes to the ordering should be avoided.144*145* Only use types with a clear size and padding here, in particular prefer the146* stdint.h types to the basic integer types.147*/148struct lp_jit_context149{150const float *constants[LP_MAX_TGSI_CONST_BUFFERS];151int num_constants[LP_MAX_TGSI_CONST_BUFFERS];152153struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];154struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];155struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES];156157float alpha_ref_value;158159uint32_t stencil_ref_front, stencil_ref_back;160161uint8_t *u8_blend_color;162float *f_blend_color;163164struct lp_jit_viewport *viewports;165166const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];167int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];168169uint32_t sample_mask;170};171172173/**174* These enum values must match the position of the fields in the175* lp_jit_context struct above.176*/177enum {178LP_JIT_CTX_CONSTANTS = 0,179LP_JIT_CTX_NUM_CONSTANTS,180LP_JIT_CTX_TEXTURES,181LP_JIT_CTX_SAMPLERS,182LP_JIT_CTX_IMAGES,183LP_JIT_CTX_ALPHA_REF,184LP_JIT_CTX_STENCIL_REF_FRONT,185LP_JIT_CTX_STENCIL_REF_BACK,186LP_JIT_CTX_U8_BLEND_COLOR,187LP_JIT_CTX_F_BLEND_COLOR,188LP_JIT_CTX_VIEWPORTS,189LP_JIT_CTX_SSBOS,190LP_JIT_CTX_NUM_SSBOS,191LP_JIT_CTX_SAMPLE_MASK,192LP_JIT_CTX_COUNT193};194195196#define lp_jit_context_constants(_gallivm, _ptr) \197lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")198199#define lp_jit_context_num_constants(_gallivm, _ptr) \200lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")201202#define lp_jit_context_textures(_gallivm, _ptr) \203lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")204205#define lp_jit_context_samplers(_gallivm, _ptr) \206lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")207208#define lp_jit_context_images(_gallivm, _ptr) \209lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_IMAGES, "images")210211#define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \212lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")213214#define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \215lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")216217#define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \218lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")219220#define lp_jit_context_u8_blend_color(_gallivm, _ptr) \221lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")222223#define lp_jit_context_f_blend_color(_gallivm, _ptr) \224lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")225226#define lp_jit_context_viewports(_gallivm, _ptr) \227lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")228229#define lp_jit_context_ssbos(_gallivm, _ptr) \230lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")231232#define lp_jit_context_num_ssbos(_gallivm, _ptr) \233lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")234235#define lp_jit_context_sample_mask(_gallivm, _ptr) \236lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLE_MASK, "sample_mask")237238struct lp_jit_thread_data239{240struct lp_build_format_cache *cache;241uint64_t vis_counter;242uint64_t ps_invocations;243244/*245* Non-interpolated rasterizer state passed through to the fragment shader.246*/247struct {248uint32_t viewport_index;249uint32_t view_index;250} raster_state;251};252253254enum {255LP_JIT_THREAD_DATA_CACHE = 0,256LP_JIT_THREAD_DATA_COUNTER,257LP_JIT_THREAD_DATA_INVOCATIONS,258LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX,259LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX,260LP_JIT_THREAD_DATA_COUNT261};262263264#define lp_jit_thread_data_cache(_gallivm, _ptr) \265lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")266267#define lp_jit_thread_data_counter(_gallivm, _ptr) \268lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")269270#define lp_jit_thread_data_invocations(_gallivm, _ptr) \271lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")272273#define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \274lp_build_struct_get(_gallivm, _ptr, \275LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \276"raster_state.viewport_index")277278#define lp_jit_thread_data_raster_state_view_index(_gallivm, _ptr) \279lp_build_struct_get(_gallivm, _ptr, \280LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX, \281"raster_state.view_index")282283/**284* typedef for fragment shader function285*286* @param context jit context287* @param x block start x288* @param y block start y289* @param facing is front facing290* @param a0 shader input a0291* @param dadx shader input dadx292* @param dady shader input dady293* @param color color buffer294* @param depth depth buffer295* @param mask mask of visible pixels in block (16-bits per sample)296* @param thread_data task thread data297* @param stride color buffer row stride in bytes298* @param depth_stride depth buffer row stride in bytes299*/300typedef void301(*lp_jit_frag_func)(const struct lp_jit_context *context,302uint32_t x,303uint32_t y,304uint32_t facing,305const void *a0,306const void *dadx,307const void *dady,308uint8_t **color,309uint8_t *depth,310uint64_t mask,311struct lp_jit_thread_data *thread_data,312unsigned *stride,313unsigned depth_stride,314unsigned *color_sample_stride,315unsigned depth_sample_stride);316317318struct lp_jit_cs_thread_data319{320struct lp_build_format_cache *cache;321void *shared;322};323324enum {325LP_JIT_CS_THREAD_DATA_CACHE = 0,326LP_JIT_CS_THREAD_DATA_SHARED = 1,327LP_JIT_CS_THREAD_DATA_COUNT328};329330331#define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \332lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache")333334#define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \335lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared")336337struct lp_jit_cs_context338{339const float *constants[LP_MAX_TGSI_CONST_BUFFERS];340int num_constants[LP_MAX_TGSI_CONST_BUFFERS];341342struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];343struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];344struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES];345346const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];347int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];348349void *kernel_args;350351uint32_t shared_size;352};353354/**355* These enum values must match the position of the fields in the356* lp_jit_context struct above.357*/358enum {359LP_JIT_CS_CTX_CONSTANTS = 0,360LP_JIT_CS_CTX_NUM_CONSTANTS,361LP_JIT_CS_CTX_TEXTURES, /* must match the LP_JIT_CTX_TEXTURES */362LP_JIT_CS_CTX_SAMPLERS,363LP_JIT_CS_CTX_IMAGES,364LP_JIT_CS_CTX_SSBOS,365LP_JIT_CS_CTX_NUM_SSBOS,366LP_JIT_CS_CTX_KERNEL_ARGS,367LP_JIT_CS_CTX_SHARED_SIZE,368LP_JIT_CS_CTX_COUNT369};370371#define lp_jit_cs_context_constants(_gallivm, _ptr) \372lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants")373374#define lp_jit_cs_context_num_constants(_gallivm, _ptr) \375lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants")376377#define lp_jit_cs_context_textures(_gallivm, _ptr) \378lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures")379380#define lp_jit_cs_context_samplers(_gallivm, _ptr) \381lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers")382383#define lp_jit_cs_context_images(_gallivm, _ptr) \384lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images")385386#define lp_jit_cs_context_ssbos(_gallivm, _ptr) \387lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos")388389#define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \390lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos")391392#define lp_jit_cs_context_shared_size(_gallivm, _ptr) \393lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size")394395#define lp_jit_cs_context_kernel_args(_gallivm, _ptr) \396lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_KERNEL_ARGS, "kernel_args")397398399typedef void400(*lp_jit_cs_func)(const struct lp_jit_cs_context *context,401uint32_t x,402uint32_t y,403uint32_t z,404uint32_t grid_x,405uint32_t grid_y,406uint32_t grid_z,407uint32_t grid_size_x,408uint32_t grid_size_y,409uint32_t grid_size_z,410uint32_t work_dim,411struct lp_jit_cs_thread_data *thread_data);412413void414lp_jit_screen_cleanup(struct llvmpipe_screen *screen);415416417boolean418lp_jit_screen_init(struct llvmpipe_screen *screen);419420421void422lp_jit_init_types(struct lp_fragment_shader_variant *lp);423424void425lp_jit_init_cs_types(struct lp_compute_shader_variant *lp);426#endif /* LP_JIT_H */427428429