1 /* 2 * Copyright 2022 Red Hat. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef LP_BLD_JIT_TYPES_H 25 #define LP_BLD_JIT_TYPES_H 26 27 #include "gallivm/lp_bld_limits.h" 28 #include "gallivm/lp_bld_sample.h" 29 #include "gallivm/lp_bld_struct.h" 30 31 struct lp_sampler_dynamic_state; 32 33 struct lp_jit_buffer 34 { 35 union { 36 const uint32_t *u; 37 const float *f; 38 }; 39 uint32_t num_elements; 40 }; 41 42 enum { 43 LP_JIT_BUFFER_BASE = 0, 44 LP_JIT_BUFFER_NUM_ELEMENTS, 45 LP_JIT_BUFFER_NUM_FIELDS, 46 }; 47 48 LLVMValueRef 49 lp_llvm_descriptor_base(struct gallivm_state *gallivm, 50 LLVMValueRef buffers_ptr, 51 LLVMValueRef index, unsigned buffers_limit); 52 53 LLVMValueRef 54 lp_llvm_buffer_base(struct gallivm_state *gallivm, 55 LLVMValueRef buffers_ptr, 56 LLVMValueRef buffers_offset, unsigned buffers_limit); 57 58 LLVMValueRef 59 lp_llvm_buffer_num_elements(struct gallivm_state *gallivm, 60 LLVMValueRef buffers_ptr, 61 LLVMValueRef buffers_offset, unsigned buffers_limit); 62 63 #define LP_JIT_TEXTURE_SAMPLE_STRIDE 15 /* mip_offsets[15] */ 64 65 struct lp_jit_texture 66 { 67 const void *base; 68 uint32_t width; /* same as number of elements */ 69 uint16_t height; 70 uint16_t depth; /* doubles as array size */ 71 uint8_t first_level; 72 uint8_t last_level; /* contains num_samples for multisample */ 73 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; 74 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; 75 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]; /* sample stride is in mip_offsets[15] */ 76 uint32_t sampler_index; 77 }; 78 79 enum { 80 LP_JIT_TEXTURE_BASE = 0, 81 LP_JIT_TEXTURE_WIDTH, 82 LP_JIT_TEXTURE_HEIGHT, 83 LP_JIT_TEXTURE_DEPTH, 84 LP_JIT_TEXTURE_FIRST_LEVEL, 85 LP_JIT_TEXTURE_LAST_LEVEL, 86 LP_JIT_TEXTURE_ROW_STRIDE, 87 LP_JIT_TEXTURE_IMG_STRIDE, 88 LP_JIT_TEXTURE_MIP_OFFSETS, 89 LP_JIT_SAMPLER_INDEX_DUMMY, 90 LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ 91 }; 92 93 struct lp_jit_sampler 94 { 95 float min_lod; 96 float max_lod; 97 float lod_bias; 98 float border_color[4]; 99 float max_aniso; 100 }; 101 102 enum { 103 LP_JIT_SAMPLER_MIN_LOD, 104 LP_JIT_SAMPLER_MAX_LOD, 105 LP_JIT_SAMPLER_LOD_BIAS, 106 LP_JIT_SAMPLER_BORDER_COLOR, 107 LP_JIT_SAMPLER_MAX_ANISO, 108 LP_JIT_SAMPLER_NUM_FIELDS /* number of fields above */ 109 }; 110 111 struct lp_jit_image 112 { 113 const void *base; 114 uint32_t width; /* same as number of elements */ 115 uint16_t height; 116 uint16_t depth; 117 uint8_t num_samples; 118 uint32_t sample_stride; 119 uint32_t row_stride; 120 uint32_t img_stride; 121 }; 122 123 enum { 124 LP_JIT_IMAGE_BASE = 0, 125 LP_JIT_IMAGE_WIDTH, 126 LP_JIT_IMAGE_HEIGHT, 127 LP_JIT_IMAGE_DEPTH, 128 LP_JIT_IMAGE_NUM_SAMPLES, 129 LP_JIT_IMAGE_SAMPLE_STRIDE, 130 LP_JIT_IMAGE_ROW_STRIDE, 131 LP_JIT_IMAGE_IMG_STRIDE, 132 LP_JIT_IMAGE_NUM_FIELDS /* number of fields above */ 133 }; 134 135 struct lp_jit_resources { 136 struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; 137 struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; 138 struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 139 struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; 140 struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; 141 const float *aniso_filter_table; 142 }; 143 144 enum { 145 LP_JIT_RES_CONSTANTS = 0, 146 LP_JIT_RES_SSBOS, 147 LP_JIT_RES_TEXTURES, 148 LP_JIT_RES_SAMPLERS, 149 LP_JIT_RES_IMAGES, 150 LP_JIT_RES_ANISO_FILTER_TABLE, 151 LP_JIT_RES_COUNT, 152 }; 153 154 #define lp_jit_resources_constants(_gallivm, _type, _ptr) \ 155 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_CONSTANTS, "constants") 156 157 #define lp_jit_resources_ssbos(_gallivm, _type, _ptr) \ 158 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_SSBOS, "ssbos") 159 160 #define lp_jit_resources_textures(_gallivm, _type, _ptr) \ 161 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_TEXTURES, "textures") 162 163 #define lp_jit_resources_samplers(_gallivm, _type, _ptr) \ 164 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_SAMPLERS, "samplers") 165 166 #define lp_jit_resources_images(_gallivm, _type, _ptr) \ 167 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_IMAGES, "images") 168 169 #define lp_jit_resources_aniso_filter_table(_gallivm, _type, _ptr) \ 170 lp_build_struct_get2(_gallivm, _type, _ptr, LP_JIT_RES_ANISO_FILTER_TABLE, "aniso_filter_table") 171 172 LLVMTypeRef 173 lp_build_jit_resources_type(struct gallivm_state *gallivm); 174 175 enum { 176 LP_JIT_VERTEX_HEADER_VERTEX_ID = 0, 177 LP_JIT_VERTEX_HEADER_CLIP_POS, 178 LP_JIT_VERTEX_HEADER_DATA 179 }; 180 181 #define lp_jit_vertex_header_id(_gallivm, _type, _ptr) \ 182 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_VERTEX_ID, "id") 183 184 #define lp_jit_vertex_header_clip_pos(_gallivm, _type, _ptr) \ 185 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_CLIP_POS, "clip_pos") 186 187 #define lp_jit_vertex_header_data(_gallivm, _type, _ptr) \ 188 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_DATA, "data") 189 190 LLVMTypeRef 191 lp_build_create_jit_vertex_header_type(struct gallivm_state *gallivm, int data_elems); 192 193 void 194 lp_build_jit_fill_sampler_dynamic_state(struct lp_sampler_dynamic_state *state); 195 void 196 lp_build_jit_fill_image_dynamic_state(struct lp_sampler_dynamic_state *state); 197 198 LLVMTypeRef lp_build_sample_function_type(struct gallivm_state *gallivm, uint32_t sample_key); 199 200 LLVMTypeRef lp_build_size_function_type(struct gallivm_state *gallivm, 201 const struct lp_sampler_size_query_params *params); 202 203 LLVMTypeRef lp_build_image_function_type(struct gallivm_state *gallivm, 204 const struct lp_img_params *params, bool ms); 205 206 struct lp_texture_functions { 207 void ***sample_functions; 208 uint32_t sampler_count; 209 210 void **fetch_functions; 211 212 void *size_function; 213 void *samples_function; 214 215 void **image_functions; 216 217 struct lp_static_texture_state state; 218 219 bool sampled; 220 bool storage; 221 222 void *matrix; 223 }; 224 225 struct lp_texture_handle { 226 void *functions; 227 uint32_t sampler_index; 228 }; 229 230 struct lp_descriptor { 231 union { 232 struct { 233 struct lp_jit_texture texture; 234 struct lp_jit_sampler sampler; 235 }; 236 struct { 237 struct lp_jit_image image; 238 }; 239 struct lp_jit_buffer buffer; 240 }; 241 242 /* Store sample/image functions in the same location since some d3d12 games 243 * rely on mismatched descriptor types with null descriptors. 244 */ 245 void *functions; 246 }; 247 248 #define LP_MAX_TEX_FUNC_ARGS 32 249 250 #endif 251 252