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