1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2009 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg/** 29848b8605Smrg * @file 30848b8605Smrg * C - JIT interfaces 31848b8605Smrg * 32848b8605Smrg * @author Jose Fonseca <jfonseca@vmware.com> 33848b8605Smrg */ 34848b8605Smrg 35848b8605Smrg#ifndef LP_JIT_H 36848b8605Smrg#define LP_JIT_H 37848b8605Smrg 38848b8605Smrg 39848b8605Smrg#include "gallivm/lp_bld_struct.h" 40848b8605Smrg#include "gallivm/lp_bld_limits.h" 41848b8605Smrg 42848b8605Smrg#include "pipe/p_state.h" 43848b8605Smrg#include "lp_texture.h" 44848b8605Smrg 45848b8605Smrg 46b8e80941Smrgstruct lp_build_format_cache; 47848b8605Smrgstruct lp_fragment_shader_variant; 48848b8605Smrgstruct llvmpipe_screen; 49848b8605Smrg 50848b8605Smrg 51848b8605Smrgstruct lp_jit_texture 52848b8605Smrg{ 53848b8605Smrg uint32_t width; /* same as number of elements */ 54848b8605Smrg uint32_t height; 55848b8605Smrg uint32_t depth; /* doubles as array size */ 56848b8605Smrg uint32_t first_level; 57848b8605Smrg uint32_t last_level; 58848b8605Smrg const void *base; 59848b8605Smrg uint32_t row_stride[LP_MAX_TEXTURE_LEVELS]; 60848b8605Smrg uint32_t img_stride[LP_MAX_TEXTURE_LEVELS]; 61848b8605Smrg uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS]; 62848b8605Smrg}; 63848b8605Smrg 64848b8605Smrg 65848b8605Smrgstruct lp_jit_sampler 66848b8605Smrg{ 67848b8605Smrg float min_lod; 68848b8605Smrg float max_lod; 69848b8605Smrg float lod_bias; 70848b8605Smrg float border_color[4]; 71848b8605Smrg}; 72848b8605Smrg 73848b8605Smrg 74848b8605Smrgstruct lp_jit_viewport 75848b8605Smrg{ 76848b8605Smrg float min_depth; 77848b8605Smrg float max_depth; 78848b8605Smrg}; 79848b8605Smrg 80848b8605Smrg 81848b8605Smrgenum { 82848b8605Smrg LP_JIT_TEXTURE_WIDTH = 0, 83848b8605Smrg LP_JIT_TEXTURE_HEIGHT, 84848b8605Smrg LP_JIT_TEXTURE_DEPTH, 85848b8605Smrg LP_JIT_TEXTURE_FIRST_LEVEL, 86848b8605Smrg LP_JIT_TEXTURE_LAST_LEVEL, 87848b8605Smrg LP_JIT_TEXTURE_BASE, 88848b8605Smrg LP_JIT_TEXTURE_ROW_STRIDE, 89848b8605Smrg LP_JIT_TEXTURE_IMG_STRIDE, 90848b8605Smrg LP_JIT_TEXTURE_MIP_OFFSETS, 91848b8605Smrg LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ 92848b8605Smrg}; 93848b8605Smrg 94848b8605Smrg 95848b8605Smrgenum { 96848b8605Smrg LP_JIT_SAMPLER_MIN_LOD, 97848b8605Smrg LP_JIT_SAMPLER_MAX_LOD, 98848b8605Smrg LP_JIT_SAMPLER_LOD_BIAS, 99848b8605Smrg LP_JIT_SAMPLER_BORDER_COLOR, 100848b8605Smrg LP_JIT_SAMPLER_NUM_FIELDS /* number of fields above */ 101848b8605Smrg}; 102848b8605Smrg 103848b8605Smrg 104848b8605Smrgenum { 105848b8605Smrg LP_JIT_VIEWPORT_MIN_DEPTH, 106848b8605Smrg LP_JIT_VIEWPORT_MAX_DEPTH, 107848b8605Smrg LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */ 108848b8605Smrg}; 109848b8605Smrg 110848b8605Smrg 111848b8605Smrg/** 112848b8605Smrg * This structure is passed directly to the generated fragment shader. 113848b8605Smrg * 114848b8605Smrg * It contains the derived state. 115848b8605Smrg * 116848b8605Smrg * Changes here must be reflected in the lp_jit_context_* macros and 117848b8605Smrg * lp_jit_init_types function. Changes to the ordering should be avoided. 118848b8605Smrg * 119848b8605Smrg * Only use types with a clear size and padding here, in particular prefer the 120848b8605Smrg * stdint.h types to the basic integer types. 121848b8605Smrg */ 122848b8605Smrgstruct lp_jit_context 123848b8605Smrg{ 124848b8605Smrg const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; 125848b8605Smrg int num_constants[LP_MAX_TGSI_CONST_BUFFERS]; 126848b8605Smrg 127848b8605Smrg float alpha_ref_value; 128848b8605Smrg 129848b8605Smrg uint32_t stencil_ref_front, stencil_ref_back; 130848b8605Smrg 131848b8605Smrg uint8_t *u8_blend_color; 132848b8605Smrg float *f_blend_color; 133848b8605Smrg 134848b8605Smrg struct lp_jit_viewport *viewports; 135848b8605Smrg 136848b8605Smrg struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 137848b8605Smrg struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; 138848b8605Smrg}; 139848b8605Smrg 140848b8605Smrg 141848b8605Smrg/** 142848b8605Smrg * These enum values must match the position of the fields in the 143848b8605Smrg * lp_jit_context struct above. 144848b8605Smrg */ 145848b8605Smrgenum { 146848b8605Smrg LP_JIT_CTX_CONSTANTS = 0, 147848b8605Smrg LP_JIT_CTX_NUM_CONSTANTS, 148848b8605Smrg LP_JIT_CTX_ALPHA_REF, 149848b8605Smrg LP_JIT_CTX_STENCIL_REF_FRONT, 150848b8605Smrg LP_JIT_CTX_STENCIL_REF_BACK, 151848b8605Smrg LP_JIT_CTX_U8_BLEND_COLOR, 152848b8605Smrg LP_JIT_CTX_F_BLEND_COLOR, 153848b8605Smrg LP_JIT_CTX_VIEWPORTS, 154848b8605Smrg LP_JIT_CTX_TEXTURES, 155848b8605Smrg LP_JIT_CTX_SAMPLERS, 156848b8605Smrg LP_JIT_CTX_COUNT 157848b8605Smrg}; 158848b8605Smrg 159848b8605Smrg 160848b8605Smrg#define lp_jit_context_constants(_gallivm, _ptr) \ 161848b8605Smrg lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants") 162848b8605Smrg 163848b8605Smrg#define lp_jit_context_num_constants(_gallivm, _ptr) \ 164848b8605Smrg lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants") 165848b8605Smrg 166848b8605Smrg#define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \ 167848b8605Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value") 168848b8605Smrg 169848b8605Smrg#define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \ 170848b8605Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front") 171848b8605Smrg 172848b8605Smrg#define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \ 173848b8605Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back") 174848b8605Smrg 175848b8605Smrg#define lp_jit_context_u8_blend_color(_gallivm, _ptr) \ 176848b8605Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color") 177848b8605Smrg 178848b8605Smrg#define lp_jit_context_f_blend_color(_gallivm, _ptr) \ 179848b8605Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color") 180848b8605Smrg 181848b8605Smrg#define lp_jit_context_viewports(_gallivm, _ptr) \ 182848b8605Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports") 183848b8605Smrg 184848b8605Smrg#define lp_jit_context_textures(_gallivm, _ptr) \ 185848b8605Smrg lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures") 186848b8605Smrg 187848b8605Smrg#define lp_jit_context_samplers(_gallivm, _ptr) \ 188848b8605Smrg lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers") 189848b8605Smrg 190848b8605Smrg 191848b8605Smrgstruct lp_jit_thread_data 192848b8605Smrg{ 193b8e80941Smrg struct lp_build_format_cache *cache; 194848b8605Smrg uint64_t vis_counter; 195b8e80941Smrg uint64_t ps_invocations; 196848b8605Smrg 197848b8605Smrg /* 198848b8605Smrg * Non-interpolated rasterizer state passed through to the fragment shader. 199848b8605Smrg */ 200848b8605Smrg struct { 201848b8605Smrg uint32_t viewport_index; 202848b8605Smrg } raster_state; 203848b8605Smrg}; 204848b8605Smrg 205848b8605Smrg 206848b8605Smrgenum { 207b8e80941Smrg LP_JIT_THREAD_DATA_CACHE = 0, 208b8e80941Smrg LP_JIT_THREAD_DATA_COUNTER, 209b8e80941Smrg LP_JIT_THREAD_DATA_INVOCATIONS, 210848b8605Smrg LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, 211848b8605Smrg LP_JIT_THREAD_DATA_COUNT 212848b8605Smrg}; 213848b8605Smrg 214848b8605Smrg 215b8e80941Smrg#define lp_jit_thread_data_cache(_gallivm, _ptr) \ 216b8e80941Smrg lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache") 217b8e80941Smrg 218848b8605Smrg#define lp_jit_thread_data_counter(_gallivm, _ptr) \ 219848b8605Smrg lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter") 220848b8605Smrg 221b8e80941Smrg#define lp_jit_thread_data_invocations(_gallivm, _ptr) \ 222b8e80941Smrg lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs") 223b8e80941Smrg 224848b8605Smrg#define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \ 225848b8605Smrg lp_build_struct_get(_gallivm, _ptr, \ 226848b8605Smrg LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \ 227848b8605Smrg "raster_state.viewport_index") 228848b8605Smrg 229848b8605Smrg/** 230848b8605Smrg * typedef for fragment shader function 231848b8605Smrg * 232848b8605Smrg * @param context jit context 233848b8605Smrg * @param x block start x 234848b8605Smrg * @param y block start y 235848b8605Smrg * @param facing is front facing 236848b8605Smrg * @param a0 shader input a0 237848b8605Smrg * @param dadx shader input dadx 238848b8605Smrg * @param dady shader input dady 239848b8605Smrg * @param color color buffer 240848b8605Smrg * @param depth depth buffer 241848b8605Smrg * @param mask mask of visible pixels in block 242848b8605Smrg * @param thread_data task thread data 243848b8605Smrg * @param stride color buffer row stride in bytes 244848b8605Smrg * @param depth_stride depth buffer row stride in bytes 245848b8605Smrg */ 246848b8605Smrgtypedef void 247848b8605Smrg(*lp_jit_frag_func)(const struct lp_jit_context *context, 248848b8605Smrg uint32_t x, 249848b8605Smrg uint32_t y, 250848b8605Smrg uint32_t facing, 251848b8605Smrg const void *a0, 252848b8605Smrg const void *dadx, 253848b8605Smrg const void *dady, 254848b8605Smrg uint8_t **color, 255848b8605Smrg uint8_t *depth, 256848b8605Smrg uint32_t mask, 257848b8605Smrg struct lp_jit_thread_data *thread_data, 258848b8605Smrg unsigned *stride, 259848b8605Smrg unsigned depth_stride); 260848b8605Smrg 261848b8605Smrg 262848b8605Smrgvoid 263848b8605Smrglp_jit_screen_cleanup(struct llvmpipe_screen *screen); 264848b8605Smrg 265848b8605Smrg 266b8e80941Smrgboolean 267848b8605Smrglp_jit_screen_init(struct llvmpipe_screen *screen); 268848b8605Smrg 269848b8605Smrg 270848b8605Smrgvoid 271848b8605Smrglp_jit_init_types(struct lp_fragment_shader_variant *lp); 272848b8605Smrg 273848b8605Smrg 274848b8605Smrg#endif /* LP_JIT_H */ 275