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 union { 72 struct { 73 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; 74 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; 75 }; 76 const void *residency; 77 }; 78 uint8_t first_level; 79 uint8_t last_level; /* contains num_samples for multisample */ 80 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]; /* sample stride is in mip_offsets[15] */ 81 uint32_t sampler_index; 82 }; 83 84 enum { 85 LP_JIT_TEXTURE_BASE = 0, 86 LP_JIT_TEXTURE_WIDTH, 87 LP_JIT_TEXTURE_HEIGHT, 88 LP_JIT_TEXTURE_DEPTH, 89 LP_JIT_TEXTURE_ROW_STRIDE, 90 LP_JIT_TEXTURE_IMG_STRIDE, 91 LP_JIT_TEXTURE_FIRST_LEVEL, 92 LP_JIT_TEXTURE_LAST_LEVEL, 93 LP_JIT_TEXTURE_MIP_OFFSETS, 94 LP_JIT_SAMPLER_INDEX_DUMMY, 95 LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ 96 }; 97 98 struct lp_jit_sampler 99 { 100 float min_lod; 101 float max_lod; 102 float lod_bias; 103 float border_color[4]; 104 float max_aniso; 105 }; 106 107 enum { 108 LP_JIT_SAMPLER_MIN_LOD, 109 LP_JIT_SAMPLER_MAX_LOD, 110 LP_JIT_SAMPLER_LOD_BIAS, 111 LP_JIT_SAMPLER_BORDER_COLOR, 112 LP_JIT_SAMPLER_MAX_ANISO, 113 LP_JIT_SAMPLER_NUM_FIELDS /* number of fields above */ 114 }; 115 116 struct lp_jit_image 117 { 118 const void *base; 119 uint32_t width; /* same as number of elements */ 120 uint16_t height; 121 uint16_t depth; 122 uint8_t num_samples; 123 uint32_t sample_stride; 124 uint32_t row_stride; 125 uint32_t img_stride; 126 const void *residency; 127 uint32_t base_offset; 128 }; 129 130 enum { 131 LP_JIT_IMAGE_BASE = 0, 132 LP_JIT_IMAGE_WIDTH, 133 LP_JIT_IMAGE_HEIGHT, 134 LP_JIT_IMAGE_DEPTH, 135 LP_JIT_IMAGE_NUM_SAMPLES, 136 LP_JIT_IMAGE_SAMPLE_STRIDE, 137 LP_JIT_IMAGE_ROW_STRIDE, 138 LP_JIT_IMAGE_IMG_STRIDE, 139 LP_JIT_IMAGE_RESIDENCY, 140 LP_JIT_IMAGE_BASE_OFFSET, 141 LP_JIT_IMAGE_NUM_FIELDS /* number of fields above */ 142 }; 143 144 struct lp_jit_resources { 145 struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; 146 struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; 147 struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 148 struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; 149 struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; 150 const float *aniso_filter_table; 151 }; 152 153 enum { 154 LP_JIT_RES_CONSTANTS = 0, 155 LP_JIT_RES_SSBOS, 156 LP_JIT_RES_TEXTURES, 157 LP_JIT_RES_SAMPLERS, 158 LP_JIT_RES_IMAGES, 159 LP_JIT_RES_ANISO_FILTER_TABLE, 160 LP_JIT_RES_COUNT, 161 }; 162 163 #define lp_jit_resources_constants(_gallivm, _type, _ptr) \ 164 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_CONSTANTS, "constants") 165 166 #define lp_jit_resources_ssbos(_gallivm, _type, _ptr) \ 167 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_SSBOS, "ssbos") 168 169 #define lp_jit_resources_textures(_gallivm, _type, _ptr) \ 170 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_TEXTURES, "textures") 171 172 #define lp_jit_resources_samplers(_gallivm, _type, _ptr) \ 173 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_SAMPLERS, "samplers") 174 175 #define lp_jit_resources_images(_gallivm, _type, _ptr) \ 176 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_RES_IMAGES, "images") 177 178 #define lp_jit_resources_aniso_filter_table(_gallivm, _type, _ptr) \ 179 lp_build_struct_get2(_gallivm, _type, _ptr, LP_JIT_RES_ANISO_FILTER_TABLE, "aniso_filter_table") 180 181 LLVMTypeRef 182 lp_build_jit_resources_type(struct gallivm_state *gallivm); 183 184 enum { 185 LP_JIT_VERTEX_HEADER_VERTEX_ID = 0, 186 LP_JIT_VERTEX_HEADER_CLIP_POS, 187 LP_JIT_VERTEX_HEADER_DATA 188 }; 189 190 #define lp_jit_vertex_header_id(_gallivm, _type, _ptr) \ 191 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_VERTEX_ID, "id") 192 193 #define lp_jit_vertex_header_clip_pos(_gallivm, _type, _ptr) \ 194 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_CLIP_POS, "clip_pos") 195 196 #define lp_jit_vertex_header_data(_gallivm, _type, _ptr) \ 197 lp_build_struct_get_ptr2(_gallivm, _type, _ptr, LP_JIT_VERTEX_HEADER_DATA, "data") 198 199 LLVMTypeRef 200 lp_build_create_jit_vertex_header_type(struct gallivm_state *gallivm, int data_elems); 201 202 void 203 lp_build_jit_fill_sampler_dynamic_state(struct lp_sampler_dynamic_state *state); 204 void 205 lp_build_jit_fill_image_dynamic_state(struct lp_sampler_dynamic_state *state); 206 207 LLVMTypeRef lp_build_sample_function_type(struct gallivm_state *gallivm, uint32_t sample_key); 208 209 LLVMTypeRef lp_build_size_function_type(struct gallivm_state *gallivm, 210 const struct lp_sampler_size_query_params *params); 211 212 LLVMTypeRef lp_build_image_function_type(struct gallivm_state *gallivm, 213 const struct lp_img_params *params, bool ms); 214 215 struct lp_texture_functions { 216 void ***sample_functions; 217 uint32_t sampler_count; 218 219 void **fetch_functions; 220 221 void *size_function; 222 void *samples_function; 223 224 void **image_functions; 225 226 struct lp_static_texture_state state; 227 228 bool sampled; 229 bool storage; 230 231 void *matrix; 232 }; 233 234 struct lp_texture_handle { 235 void *functions; 236 uint32_t sampler_index; 237 }; 238 239 struct lp_descriptor { 240 union { 241 struct { 242 struct lp_jit_texture texture; 243 struct lp_jit_sampler sampler; 244 }; 245 struct { 246 struct lp_jit_image image; 247 }; 248 struct lp_jit_buffer buffer; 249 uint64_t accel_struct; 250 }; 251 252 /* Store sample/image functions in the same location since some d3d12 games 253 * rely on mismatched descriptor types with null descriptors. 254 */ 255 void *functions; 256 }; 257 258 #define LP_MAX_TEX_FUNC_ARGS 32 259 260 #endif 261 262