diff options
Diffstat (limited to 'user/mesa/llvm-opaque.patch')
-rw-r--r-- | user/mesa/llvm-opaque.patch | 8467 |
1 files changed, 8467 insertions, 0 deletions
diff --git a/user/mesa/llvm-opaque.patch b/user/mesa/llvm-opaque.patch new file mode 100644 index 000000000..80bd18967 --- /dev/null +++ b/user/mesa/llvm-opaque.patch @@ -0,0 +1,8467 @@ +From af20d46a39e4431b85d593f56912a185a157554e Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:14:48 +0300 +Subject: [PATCH 01/22] gallium: add opaque pointers shim for LLVM < 8.0 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +LLVM is transitioning to "opaque pointers", and as such deprecates +LLVMBuildGEP, LLVMBuildCall, LLVMBuildLoad, replacing them with +LLVMBuildGEP2, LLVMBuildCall2, LLVMBuildLoad2 respectivelly. +These new functions were added in LLVM 8.0; so for LLVM before 8.0 we +simply forward to the non-opaque-pointer variants. + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld.h | 42 ++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h +index 9144428c8e162..5846afa3ce065 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld.h +@@ -87,4 +87,46 @@ + #define GALLIVM_HAVE_CORO 0 + #endif + ++/* LLVM is transitioning to "opaque pointers", and as such deprecates ++ * LLVMBuildGEP, LLVMBuildCall, LLVMBuildLoad, replacing them with ++ * LLVMBuildGEP2, LLVMBuildCall2, LLVMBuildLoad2 respectivelly. ++ * These new functions were added in LLVM 8.0; so for LLVM before 8.0 we ++ * simply forward to the non-opaque-pointer variants. ++ */ ++#if LLVM_VERSION_MAJOR < 8 ++ ++static inline LLVMValueRef ++LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, ++ LLVMValueRef Pointer, LLVMValueRef *Indices, ++ unsigned NumIndices, const char *Name) ++{ ++ return LLVMBuildGEP(B, Pointer, Indices, NumIndices, Name); ++} ++ ++static inline LLVMValueRef ++LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, ++ LLVMValueRef Pointer, LLVMValueRef *Indices, ++ unsigned NumIndices, const char *Name) ++{ ++ return LLVMBuildInBoundsGEP(B, Pointer, Indices, NumIndices, Name); ++} ++ ++static inline LLVMValueRef ++LLVMBuildLoad2(LLVMBuilderRef B, LLVMTypeRef Ty, ++ LLVMValueRef PointerVal, const char *Name) ++{ ++ LLVMValueRef val = LLVMBuildLoad(B, PointerVal, Name); ++ return LLVMTypeOf(val) == Ty ? val : LLVMBuildBitCast(B, val, Ty, Name); ++} ++ ++static inline LLVMValueRef ++LLVMBuildCall2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, ++ LLVMValueRef *Args, unsigned NumArgs, ++ const char *Name) ++{ ++ return LLVMBuildCall(B, Fn, Args, NumArgs, Name); ++} ++ ++#endif /* LLVM_VERSION_MAJOR < 8 */ ++ + #endif /* LP_BLD_H */ +-- +GitLab + + +From eb9a65c91422eb765df80693b2220f625404468c Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:20:01 +0300 +Subject: [PATCH 02/22] gallium: use LLVM opaque pointers in draw_llvm.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/draw/draw_llvm.c | 150 ++++++++++++------------- + src/gallium/auxiliary/draw/draw_llvm.h | 7 ++ + 2 files changed, 81 insertions(+), 76 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c +index 5e5ce53a3ab79..1f68170d99e03 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.c ++++ b/src/gallium/auxiliary/draw/draw_llvm.c +@@ -639,14 +639,13 @@ create_tcs_jit_output_type(struct gallivm_state *gallivm) + } + + static LLVMTypeRef +-create_tes_jit_input_type(struct gallivm_state *gallivm) ++create_tes_jit_input_deref_type(struct gallivm_state *gallivm) + { + LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); + LLVMTypeRef input_array; + + input_array = LLVMArrayType(float_type, TGSI_NUM_CHANNELS); /* num channels */ + input_array = LLVMArrayType(input_array, PIPE_MAX_SHADER_INPUTS); /* num attrs per vertex */ +- input_array = LLVMPointerType(input_array, 0); /* num vertices per prim */ + + return input_array; + } +@@ -721,8 +720,7 @@ static void + create_jit_types(struct draw_llvm_variant *variant) + { + struct gallivm_state *gallivm = variant->gallivm; +- LLVMTypeRef texture_type, sampler_type, context_type, buffer_type, +- vb_type, image_type; ++ LLVMTypeRef texture_type, sampler_type, context_type, image_type; + + texture_type = create_jit_texture_type(gallivm, "texture"); + sampler_type = create_jit_sampler_type(gallivm, "sampler"); +@@ -733,11 +731,11 @@ create_jit_types(struct draw_llvm_variant *variant) + "draw_jit_context"); + variant->context_ptr_type = LLVMPointerType(context_type, 0); + +- buffer_type = create_jit_dvbuffer_type(gallivm, "draw_vertex_buffer"); +- variant->buffer_ptr_type = LLVMPointerType(buffer_type, 0); ++ variant->buffer_type = create_jit_dvbuffer_type(gallivm, "draw_vertex_buffer"); ++ variant->buffer_ptr_type = LLVMPointerType(variant->buffer_type, 0); + +- vb_type = create_jit_vertex_buffer_type(gallivm, "pipe_vertex_buffer"); +- variant->vb_ptr_type = LLVMPointerType(vb_type, 0); ++ variant->vb_type = create_jit_vertex_buffer_type(gallivm, "pipe_vertex_buffer"); ++ variant->vb_ptr_type = LLVMPointerType(variant->vb_type, 0); + } + + +@@ -770,8 +768,7 @@ get_vb_ptr_type(struct draw_llvm_variant *variant) + static LLVMTypeRef + get_vertex_header_ptr_type(struct draw_llvm_variant *variant) + { +- if (!variant->vertex_header_ptr_type) +- create_jit_types(variant); ++ assert(variant->vertex_header_ptr_type); + return variant->vertex_header_ptr_type; + } + +@@ -871,7 +868,6 @@ draw_llvm_create_variant(struct draw_llvm *llvm, + struct draw_llvm_variant *variant; + struct llvm_vertex_shader *shader = + llvm_vertex_shader(llvm->draw->vs.vertex_shader); +- LLVMTypeRef vertex_header; + char module_name[64]; + unsigned char ir_sha1_cache_key[20]; + struct lp_cached_code cached = { 0 }; +@@ -914,9 +910,8 @@ draw_llvm_create_variant(struct draw_llvm *llvm, + draw_llvm_dump_variant_key(&variant->key); + } + +- vertex_header = create_jit_vertex_header(variant->gallivm, num_inputs); +- +- variant->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0); ++ variant->vertex_header_type = create_jit_vertex_header(variant->gallivm, num_inputs); ++ variant->vertex_header_ptr_type = LLVMPointerType(variant->vertex_header_type, 0); + + draw_llvm_generate(llvm, variant); + +@@ -957,7 +952,7 @@ do_clamp_vertex_color(struct gallivm_state *gallivm, + switch (info->output_semantic_name[attrib]) { + case TGSI_SEMANTIC_COLOR: + case TGSI_SEMANTIC_BCOLOR: +- out = LLVMBuildLoad(builder, outputs[attrib][chan], ""); ++ out = LLVMBuildLoad2(builder, LLVMTypeOf(bld.zero), outputs[attrib][chan], ""); + out = lp_build_clamp(&bld, out, bld.zero, bld.one); + LLVMBuildStore(builder, out, outputs[attrib][chan]); + break; +@@ -1393,7 +1388,6 @@ store_clip(struct gallivm_state *gallivm, + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef soa[4]; + LLVMValueRef aos[LP_MAX_VECTOR_LENGTH]; +- LLVMValueRef indices[2]; + LLVMValueRef io_ptrs[LP_MAX_VECTOR_WIDTH / 32]; + LLVMValueRef inds[LP_MAX_VECTOR_WIDTH / 32]; + LLVMValueRef clip_ptrs[LP_MAX_VECTOR_WIDTH / 32]; +@@ -1402,9 +1396,6 @@ store_clip(struct gallivm_state *gallivm, + 4), 0); + int i, j; + +- indices[0] = +- indices[1] = lp_build_const_int32(gallivm, 0); +- + for (i = 0; i < vs_type.length; i++) { + inds[i] = lp_build_const_int32(gallivm, i); + io_ptrs[i] = LLVMBuildGEP(builder, io_ptr, &inds[i], 1, ""); +@@ -1430,8 +1421,7 @@ store_clip(struct gallivm_state *gallivm, + for (j = 0; j < vs_type.length; j++) { + LLVMValueRef clip_ptr; + +- clip_ptr = LLVMBuildGEP(builder, clip_ptrs[j], indices, 2, "clipo"); +- clip_ptr = LLVMBuildPointerCast(builder, clip_ptr, clip_ptr_type, ""); ++ clip_ptr = LLVMBuildPointerCast(builder, clip_ptrs[j], clip_ptr_type, ""); + + /* Unaligned store */ + LLVMSetAlignment(LLVMBuildStore(builder, aos[j], clip_ptr), sizeof(float)); +@@ -1454,7 +1444,7 @@ generate_viewport(struct draw_llvm_variant *variant, + struct lp_type f32_type = vs_type; + const unsigned pos = variant->llvm->draw->vs.position_output; + LLVMTypeRef vs_type_llvm = lp_build_vec_type(gallivm, vs_type); +- LLVMValueRef out3 = LLVMBuildLoad(builder, outputs[pos][3], ""); /*w0 w1 .. wn*/ ++ LLVMValueRef out3 = LLVMBuildLoad2(builder, vs_type_llvm, outputs[pos][3], ""); /*w0 w1 .. wn*/ + LLVMValueRef const1 = lp_build_const_vec(gallivm, f32_type, 1.0); /*1.0 1.0 1.0 1.0*/ + LLVMValueRef vp_ptr = draw_jit_context_viewports(gallivm, context_ptr); + +@@ -1466,9 +1456,11 @@ generate_viewport(struct draw_llvm_variant *variant, + out3 = LLVMBuildFDiv(builder, const1, out3, ""); + LLVMBuildStore(builder, out3, outputs[pos][3]); + ++ LLVMTypeRef elem_type = lp_build_elem_type(gallivm, vs_type); ++ + /* Viewport Mapping */ + for (i=0; i<3; i++) { +- LLVMValueRef out = LLVMBuildLoad(builder, outputs[pos][i], ""); /*x0 x1 .. xn*/ ++ LLVMValueRef out = LLVMBuildLoad2(builder, vs_type_llvm, outputs[pos][i], ""); /*x0 x1 .. xn*/ + LLVMValueRef scale; + LLVMValueRef trans; + LLVMValueRef scale_i; +@@ -1476,15 +1468,15 @@ generate_viewport(struct draw_llvm_variant *variant, + LLVMValueRef index; + + index = lp_build_const_int32(gallivm, i + scale_index_offset); +- scale_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, ""); ++ scale_i = LLVMBuildGEP2(builder, elem_type, vp_ptr, &index, 1, ""); + + index = lp_build_const_int32(gallivm, i + trans_index_offset); +- trans_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, ""); ++ trans_i = LLVMBuildGEP2(builder, elem_type, vp_ptr, &index, 1, ""); + + scale = lp_build_broadcast(gallivm, vs_type_llvm, +- LLVMBuildLoad(builder, scale_i, "scale")); ++ LLVMBuildLoad2(builder, elem_type, scale_i, "scale")); + trans = lp_build_broadcast(gallivm, vs_type_llvm, +- LLVMBuildLoad(builder, trans_i, "trans")); ++ LLVMBuildLoad2(builder, elem_type, trans_i, "trans")); + + /* divide by w */ + out = LLVMBuildFMul(builder, out, out3, ""); +@@ -1543,20 +1535,22 @@ generate_clipmask(struct draw_llvm *llvm, + zero = lp_build_const_vec(gallivm, f32_type, 0); /* 0.0f 0.0f 0.0f 0.0f */ + shift = lp_build_const_int_vec(gallivm, i32_type, 1); /* 1 1 1 1 */ + ++ LLVMTypeRef vec_type = LLVMTypeOf(zero); ++ + /* + * load clipvertex and position from correct locations. + * if they are the same just load them once. + */ +- pos_x = LLVMBuildLoad(builder, outputs[pos][0], ""); /*x0 x1 .. xn */ +- pos_y = LLVMBuildLoad(builder, outputs[pos][1], ""); /*y0 y1 .. yn */ +- pos_z = LLVMBuildLoad(builder, outputs[pos][2], ""); /*z0 z1 .. zn */ +- pos_w = LLVMBuildLoad(builder, outputs[pos][3], ""); /*w0 w1 .. wn */ ++ pos_x = LLVMBuildLoad2(builder, vec_type, outputs[pos][0], ""); /*x0 x1 .. xn */ ++ pos_y = LLVMBuildLoad2(builder, vec_type, outputs[pos][1], ""); /*y0 y1 .. yn */ ++ pos_z = LLVMBuildLoad2(builder, vec_type, outputs[pos][2], ""); /*z0 z1 .. zn */ ++ pos_w = LLVMBuildLoad2(builder, vec_type, outputs[pos][3], ""); /*w0 w1 .. wn */ + + if (clip_user && cv != pos) { +- cv_x = LLVMBuildLoad(builder, outputs[cv][0], ""); /*x0 x1 .. xn */ +- cv_y = LLVMBuildLoad(builder, outputs[cv][1], ""); /*y0 y1 .. yn */ +- cv_z = LLVMBuildLoad(builder, outputs[cv][2], ""); /*z0 z1 .. zn */ +- cv_w = LLVMBuildLoad(builder, outputs[cv][3], ""); /*w0 w1 .. wn */ ++ cv_x = LLVMBuildLoad2(builder, vec_type, outputs[cv][0], ""); /*x0 x1 .. xn */ ++ cv_y = LLVMBuildLoad2(builder, vec_type, outputs[cv][1], ""); /*y0 y1 .. yn */ ++ cv_z = LLVMBuildLoad2(builder, vec_type, outputs[cv][2], ""); /*z0 z1 .. zn */ ++ cv_w = LLVMBuildLoad2(builder, vec_type, outputs[cv][3], ""); /*w0 w1 .. wn */ + } else { + cv_x = pos_x; + cv_y = pos_y; +@@ -1641,9 +1635,9 @@ generate_clipmask(struct draw_llvm *llvm, + + *have_clipdist = TRUE; + if (i < 4) { +- clipdist = LLVMBuildLoad(builder, outputs[cd[0]][i], ""); ++ clipdist = LLVMBuildLoad2(builder, vec_type, outputs[cd[0]][i], ""); + } else { +- clipdist = LLVMBuildLoad(builder, outputs[cd[1]][i-4], ""); ++ clipdist = LLVMBuildLoad2(builder, vec_type, outputs[cd[1]][i-4], ""); + } + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, clipdist); + is_nan_or_inf = lp_build_is_inf_or_nan(gallivm, vs_type, clipdist); +@@ -1652,31 +1646,32 @@ generate_clipmask(struct draw_llvm *llvm, + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + } else { ++ LLVMTypeRef vs_elem_type = lp_build_elem_type(gallivm, vs_type); + LLVMTypeRef vs_type_llvm = lp_build_vec_type(gallivm, vs_type); + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, plane_idx); + + indices[2] = lp_build_const_int32(gallivm, 0); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_x"); ++ plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_x"); + planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); + sum = LLVMBuildFMul(builder, planes, cv_x, ""); + + indices[2] = lp_build_const_int32(gallivm, 1); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_y"); ++ plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_y"); + planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); + sum = lp_build_fmuladd(builder, planes, cv_y, sum); + + indices[2] = lp_build_const_int32(gallivm, 2); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_z"); ++ plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_z"); + planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); + sum = lp_build_fmuladd(builder, planes, cv_z, sum); + + indices[2] = lp_build_const_int32(gallivm, 3); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_w"); ++ plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_w"); + planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); + sum = lp_build_fmuladd(builder, planes, cv_w, sum); + +@@ -1694,7 +1689,7 @@ generate_clipmask(struct draw_llvm *llvm, + */ + unsigned edge_attr = llvm->draw->vs.edgeflag_output; + LLVMValueRef one = lp_build_const_vec(gallivm, f32_type, 1.0); +- LLVMValueRef edgeflag = LLVMBuildLoad(builder, outputs[edge_attr][0], ""); ++ LLVMValueRef edgeflag = LLVMBuildLoad2(builder, vec_type, outputs[edge_attr][0], ""); + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_EQUAL, one, edgeflag); + temp = lp_build_const_int_vec(gallivm, i32_type, + 1LL << DRAW_TOTAL_CLIP_PLANES); +@@ -2062,7 +2057,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + LLVMVectorType(LLVMInt64TypeInContext(context), 4), ""); + fake_buf = LLVMBuildBitCast(builder, fake_buf, + LLVMPointerType(LLVMInt8TypeInContext(context), 0), ""); +- fake_buf_ptr = LLVMBuildGEP(builder, fake_buf, &bld.zero, 1, ""); ++ fake_buf_ptr = LLVMBuildGEP2(builder, LLVMInt8TypeInContext(context), fake_buf, &bld.zero, 1, ""); + + /* code generated texture sampling */ + sampler = draw_llvm_sampler_soa_create(draw_llvm_variant_key_samplers(key), key->nr_samplers); +@@ -2104,8 +2099,8 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + struct lp_build_if_state if_ctx; + + if (velem->src_format != PIPE_FORMAT_NONE) { +- vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr, &vb_index, 1, ""); +- vb_info = LLVMBuildGEP(builder, vb_ptr, &vb_index, 1, ""); ++ vbuffer_ptr = LLVMBuildGEP2(builder, variant->buffer_type, vbuffers_ptr, &vb_index, 1, ""); ++ vb_info = LLVMBuildGEP2(builder, variant->vb_type, vb_ptr, &vb_index, 1, ""); + vb_stride[j] = draw_jit_vbuffer_stride(gallivm, vb_info); + vb_stride[j] = LLVMBuildZExt(gallivm->builder, vb_stride[j], + LLVMInt32TypeInContext(context), ""); +@@ -2157,8 +2152,9 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + buffer_size_adj[j] = LLVMBuildSelect(builder, ofbit, bld.zero, + buffer_size_adj[j], ""); + +- temp_ptr = lp_build_alloca_undef(gallivm, +- LLVMPointerType(LLVMInt8TypeInContext(context), 0), ""); ++ LLVMTypeRef byte_type = LLVMInt8TypeInContext(context); ++ LLVMTypeRef byte_ptr_type = LLVMPointerType(byte_type, 0); ++ temp_ptr = lp_build_alloca_undef(gallivm, byte_ptr_type, ""); + + lp_build_if(&if_ctx, gallivm, ofbit); + { +@@ -2166,11 +2162,11 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + } + lp_build_else(&if_ctx); + { +- map_ptr[j] = LLVMBuildGEP(builder, map_ptr[j], &buf_offset, 1, ""); ++ map_ptr[j] = LLVMBuildGEP2(builder, byte_type, map_ptr[j], &buf_offset, 1, ""); + LLVMBuildStore(builder, map_ptr[j], temp_ptr); + } + lp_build_endif(&if_ctx); +- map_ptr[j] = LLVMBuildLoad(builder, temp_ptr, "map_ptr"); ++ map_ptr[j] = LLVMBuildLoad2(builder, byte_ptr_type, temp_ptr, "map_ptr"); + + if (0) { + lp_build_printf(gallivm, "velem %d, vbuf index = %u, vb_stride = %u\n", +@@ -2196,7 +2192,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + + io_itr = lp_loop.counter; + +- io = LLVMBuildGEP(builder, io_ptr, &io_itr, 1, ""); ++ io = LLVMBuildGEP2(builder, variant->vertex_header_type, io_ptr, &io_itr, 1, ""); + #if DEBUG_STORE + lp_build_printf(gallivm, " --- io %d = %p, loop counter %d\n", + io_itr, io, lp_loop.counter); +@@ -2259,7 +2255,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + } + lp_build_endif(&if_ctx); + +- true_index_array = LLVMBuildLoad(builder, index_store, ""); ++ true_index_array = LLVMBuildLoad2(builder, blduivec.vec_type, index_store, ""); + + for (j = 0; j < key->nr_vertex_elements; ++j) { + struct pipe_vertex_element *velem = &key->vertex_element[j]; +@@ -2329,7 +2325,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + + /* do cliptest */ + if (enable_cliptest) { +- LLVMValueRef temp = LLVMBuildLoad(builder, clipmask_bool_ptr, ""); ++ LLVMValueRef temp = LLVMBuildLoad2(builder, blduivec.vec_type, clipmask_bool_ptr, ""); + /* allocate clipmask, assign it integer type */ + clipmask = generate_clipmask(llvm, + gallivm, +@@ -2788,13 +2784,13 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, + + assert(variant->vertex_header_ptr_type); + ++ LLVMTypeRef prim_id_type = LLVMVectorType(int32_type, vector_length); + arg_types[0] = get_gs_context_ptr_type(variant); /* context */ + arg_types[1] = variant->input_array_type; /* input */ + arg_types[2] = LLVMPointerType(variant->vertex_header_ptr_type, 0); /* vertex_header */ + arg_types[3] = int32_type; /* num_prims */ + arg_types[4] = int32_type; /* instance_id */ +- arg_types[5] = LLVMPointerType( +- LLVMVectorType(int32_type, vector_length), 0); /* prim_id_ptr */ ++ arg_types[5] = LLVMPointerType(prim_id_type, 0); /* prim_id_ptr */ + arg_types[6] = int32_type; + arg_types[7] = int32_type; + +@@ -2874,7 +2870,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, + lp_build_mask_begin(&mask, gallivm, gs_type, mask_val); + + if (gs_info->uses_primid) { +- system_values.prim_id = LLVMBuildLoad(builder, prim_id_ptr, "prim_id"); ++ system_values.prim_id = LLVMBuildLoad2(builder, prim_id_type, prim_id_ptr, "prim_id"); + } + + if (gallivm_debug & (GALLIVM_DEBUG_TGSI | GALLIVM_DEBUG_IR)) { +@@ -3459,15 +3455,15 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, + args[4] = patch_vertices_in; + args[5] = view_index; + args[6] = loop_state[0].counter; +- LLVMValueRef coro_entry = LLVMBuildGEP(builder, coro_hdls, &loop_state[0].counter, 1, ""); +- LLVMValueRef coro_hdl = LLVMBuildLoad(builder, coro_entry, "coro_hdl"); ++ LLVMValueRef coro_entry = LLVMBuildGEP2(builder, hdl_ptr_type, coro_hdls, &loop_state[0].counter, 1, ""); ++ LLVMValueRef coro_hdl = LLVMBuildLoad2(builder, hdl_ptr_type, coro_entry, "coro_hdl"); + + struct lp_build_if_state ifstate; + LLVMValueRef cmp = LLVMBuildICmp(builder, LLVMIntEQ, loop_state[1].counter, + lp_build_const_int32(gallivm, 0), ""); + /* first time here - call the coroutine function entry point */ + lp_build_if(&ifstate, gallivm, cmp); +- LLVMValueRef coro_ret = LLVMBuildCall(builder, variant_coro, args, 7, ""); ++ LLVMValueRef coro_ret = LLVMBuildCall2(builder, coro_func_type, variant_coro, args, 7, ""); + LLVMBuildStore(builder, coro_ret, coro_entry); + lp_build_else(&ifstate); + /* subsequent calls for this invocation - check if done. */ +@@ -3762,7 +3758,8 @@ create_tes_jit_types(struct draw_tes_llvm_variant *var) + "draw_tes_jit_context"); + var->context_ptr_type = LLVMPointerType(context_type, 0); + +- var->input_array_type = create_tes_jit_input_type(gallivm); ++ var->input_array_deref_type = create_tes_jit_input_deref_type(gallivm); ++ var->input_array_type = LLVMPointerType(var->input_array_deref_type, 0); /* num vertices per prim */ + } + + static LLVMTypeRef +@@ -3841,8 +3838,8 @@ draw_tes_llvm_fetch_vertex_input(const struct lp_build_tes_iface *tes_iface, + indices[1] = attr_chan_index; + indices[2] = swiz_chan_index; + +- channel_vec = LLVMBuildGEP(builder, tes->input, indices, 3, ""); +- channel_vec = LLVMBuildLoad(builder, channel_vec, ""); ++ channel_vec = LLVMBuildGEP2(builder, tes->variant->input_array_deref_type, tes->input, indices, 3, ""); ++ channel_vec = LLVMBuildLoad2(builder, LLVMFloatTypeInContext(gallivm->context), channel_vec, ""); + + res = LLVMBuildInsertElement(builder, res, channel_vec, idx, ""); + } +@@ -3851,8 +3848,8 @@ draw_tes_llvm_fetch_vertex_input(const struct lp_build_tes_iface *tes_iface, + indices[1] = attrib_index; + indices[2] = swizzle_index; + +- res = LLVMBuildGEP(builder, tes->input, indices, 3, ""); +- res = LLVMBuildLoad(builder, res, ""); ++ res = LLVMBuildGEP2(builder, tes->variant->input_array_deref_type, tes->input, indices, 3, ""); ++ res = LLVMBuildLoad2(builder, LLVMFloatTypeInContext(gallivm->context), res, ""); + res = lp_build_broadcast_scalar(bld, res); + } + return res; +@@ -3891,8 +3888,8 @@ draw_tes_llvm_fetch_patch_input(const struct lp_build_tes_iface *tes_iface, + indices[1] = attr_chan_index; + indices[2] = swizzle_index; + +- channel_vec = LLVMBuildGEP(builder, tes->input, indices, 3, ""); +- channel_vec = LLVMBuildLoad(builder, channel_vec, ""); ++ channel_vec = LLVMBuildGEP2(builder, tes->variant->input_array_deref_type, tes->input, indices, 3, ""); ++ channel_vec = LLVMBuildLoad2(builder, LLVMFloatTypeInContext(gallivm->context), channel_vec, ""); + + res = LLVMBuildInsertElement(builder, res, channel_vec, idx, ""); + } +@@ -3901,8 +3898,8 @@ draw_tes_llvm_fetch_patch_input(const struct lp_build_tes_iface *tes_iface, + indices[1] = attrib_index; + indices[2] = swizzle_index; + +- res = LLVMBuildGEP(builder, tes->input, indices, 3, ""); +- res = LLVMBuildLoad(builder, res, ""); ++ res = LLVMBuildGEP2(builder, tes->variant->input_array_deref_type, tes->input, indices, 3, ""); ++ res = LLVMBuildLoad2(builder, LLVMFloatTypeInContext(gallivm->context), res, ""); + res = lp_build_broadcast_scalar(bld, res); + } + return res; +@@ -3946,6 +3943,9 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + + snprintf(func_name, sizeof(func_name), "draw_llvm_tes_variant"); + ++ LLVMTypeRef tess_outer_deref_type = LLVMArrayType(flt_type, 4); ++ LLVMTypeRef tess_inner_deref_type = LLVMArrayType(flt_type, 2); ++ + arg_types[0] = get_tes_context_ptr_type(variant); /* context */ + arg_types[1] = variant->input_array_type; /* input */ + arg_types[2] = variant->vertex_header_ptr_type; +@@ -3953,8 +3953,8 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + arg_types[4] = int32_type; + arg_types[5] = LLVMPointerType(flt_type, 0); + arg_types[6] = LLVMPointerType(flt_type, 0); +- arg_types[7] = LLVMPointerType(LLVMArrayType(flt_type, 4), 0); +- arg_types[8] = LLVMPointerType(LLVMArrayType(flt_type, 2), 0); ++ arg_types[7] = LLVMPointerType(tess_outer_deref_type, 0); ++ arg_types[8] = LLVMPointerType(tess_inner_deref_type, 0); + arg_types[9] = int32_type; + arg_types[10] = int32_type; + +@@ -4025,8 +4025,8 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + variant->key.nr_images); + step = lp_build_const_int32(gallivm, vector_length); + +- system_values.tess_outer = LLVMBuildLoad(builder, tess_outer, ""); +- system_values.tess_inner = LLVMBuildLoad(builder, tess_inner, ""); ++ system_values.tess_outer = LLVMBuildLoad2(builder, tess_outer_deref_type, tess_outer, ""); ++ system_values.tess_inner = LLVMBuildLoad2(builder, tess_inner_deref_type, tess_inner, ""); + + system_values.prim_id = lp_build_broadcast_scalar(&bldvec, prim_id); + +@@ -4046,7 +4046,7 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + { + LLVMValueRef io; + +- io = LLVMBuildGEP(builder, io_ptr, &lp_loop.counter, 1, ""); ++ io = LLVMBuildGEP2(builder, variant->vertex_header_type, io_ptr, &lp_loop.counter, 1, ""); + mask_val = generate_tes_mask_value(variant, tes_type, num_tess_coord, lp_loop.counter); + lp_build_mask_begin(&mask, gallivm, tes_type, mask_val); + +@@ -4122,7 +4122,6 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm, + { + struct draw_tes_llvm_variant *variant; + struct llvm_tess_eval_shader *shader = llvm_tess_eval_shader(llvm->draw->tes.tess_eval_shader); +- LLVMTypeRef vertex_header; + char module_name[64]; + unsigned char ir_sha1_cache_key[20]; + struct lp_cached_code cached = { 0 }; +@@ -4157,9 +4156,8 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm, + + create_tes_jit_types(variant); + +- vertex_header = create_jit_vertex_header(variant->gallivm, num_outputs); +- +- variant->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0); ++ variant->vertex_header_type = create_jit_vertex_header(variant->gallivm, num_outputs); ++ variant->vertex_header_ptr_type = LLVMPointerType(variant->vertex_header_type, 0); + + if (gallivm_debug & (GALLIVM_DEBUG_TGSI | GALLIVM_DEBUG_IR)) { + nir_print_shader(llvm->draw->tes.tess_eval_shader->state.ir.nir, stderr); +diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h +index 7506a87161ee8..4e118bef091b9 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.h ++++ b/src/gallium/auxiliary/draw/draw_llvm.h +@@ -681,6 +681,10 @@ struct draw_llvm_variant + LLVMTypeRef vb_ptr_type; + LLVMTypeRef vertex_header_ptr_type; + ++ LLVMTypeRef buffer_type; ++ LLVMTypeRef vb_type; ++ LLVMTypeRef vertex_header_type; ++ + LLVMValueRef function; + draw_jit_vert_func jit_func; + +@@ -755,6 +759,9 @@ struct draw_tes_llvm_variant + LLVMTypeRef input_array_type; + LLVMTypeRef patch_input_array_type; + ++ LLVMTypeRef input_array_deref_type; ++ LLVMTypeRef vertex_header_type; ++ + LLVMValueRef context_ptr; + LLVMValueRef io_ptr; + LLVMValueRef num_prims; +-- +GitLab + + +From f90d71f51831cc04e09466553afa56f5f62aed5d Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:26:25 +0300 +Subject: [PATCH 03/22] gallium/llvmpipe: use LLVM opaque pointers in + lp_bld_interp.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/drivers/llvmpipe/lp_bld_interp.c | 60 +++++++++++--------- + src/gallium/drivers/llvmpipe/lp_bld_interp.h | 1 + + 2 files changed, 34 insertions(+), 27 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c +index a93879c9382f9..e0a57116c5d9d 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c ++++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c +@@ -191,6 +191,20 @@ calc_centroid_offsets(struct lp_build_interp_soa_context *bld, + *centroid_y = lp_build_select(coeff_bld, s_mask_and, pix_center_offset, centroid_y_offset); + } + ++/* Note: this assumes the pointer to elem_type is in address space 0 */ ++static LLVMValueRef ++load_casted(LLVMBuilderRef builder, LLVMTypeRef elem_type, LLVMValueRef ptr, const char *name) { ++ ptr = LLVMBuildBitCast(builder, ptr, LLVMPointerType(elem_type, 0), name); ++ return LLVMBuildLoad2(builder, elem_type, ptr, name); ++} ++ ++static LLVMValueRef ++indexed_load(LLVMBuilderRef builder, LLVMTypeRef gep_type, ++ LLVMTypeRef elem_type, LLVMValueRef ptr, LLVMValueRef index, const char *name) { ++ ptr = LLVMBuildGEP2(builder, gep_type, ptr, &index, 1, name); ++ return load_casted(builder, elem_type, ptr, name); ++} ++ + /* Much easier, and significantly less instructions in the per-stamp + * part (less than half) but overall more instructions so a loss if + * most quads are active. Might be a win though with larger vectors. +@@ -224,36 +238,27 @@ coeffs_init_simple(struct lp_build_interp_soa_context *bld, + const unsigned interp = bld->interp[attrib]; + LLVMValueRef index = lp_build_const_int32(gallivm, + attrib * TGSI_NUM_CHANNELS); +- LLVMValueRef ptr; + LLVMValueRef dadxaos = setup_bld->zero; + LLVMValueRef dadyaos = setup_bld->zero; + LLVMValueRef a0aos = setup_bld->zero; + ++ /* See: lp_state_fs.c / generate_fragment() / fs_elem_type */ ++ LLVMTypeRef fs_elem_type = LLVMFloatTypeInContext(gallivm->context); ++ + switch (interp) { + case LP_INTERP_PERSPECTIVE: + FALLTHROUGH; + + case LP_INTERP_LINEAR: +- ptr = LLVMBuildGEP(builder, dadx_ptr, &index, 1, ""); +- ptr = LLVMBuildBitCast(builder, ptr, +- LLVMPointerType(setup_bld->vec_type, 0), ""); +- dadxaos = LLVMBuildLoad(builder, ptr, ""); +- +- ptr = LLVMBuildGEP(builder, dady_ptr, &index, 1, ""); +- ptr = LLVMBuildBitCast(builder, ptr, +- LLVMPointerType(setup_bld->vec_type, 0), ""); +- dadyaos = LLVMBuildLoad(builder, ptr, ""); +- ++ dadxaos = indexed_load(builder, fs_elem_type, setup_bld->vec_type, dadx_ptr, index, ""); ++ dadyaos = indexed_load(builder, fs_elem_type, setup_bld->vec_type, dady_ptr, index, ""); + attrib_name(dadxaos, attrib, 0, ".dadxaos"); + attrib_name(dadyaos, attrib, 0, ".dadyaos"); + FALLTHROUGH; + + case LP_INTERP_CONSTANT: + case LP_INTERP_FACING: +- ptr = LLVMBuildGEP(builder, a0_ptr, &index, 1, ""); +- ptr = LLVMBuildBitCast(builder, ptr, +- LLVMPointerType(setup_bld->vec_type, 0), ""); +- a0aos = LLVMBuildLoad(builder, ptr, ""); ++ a0aos = indexed_load(builder, fs_elem_type, setup_bld->vec_type, a0_ptr, index, ""); + attrib_name(a0aos, attrib, 0, ".a0aos"); + break; + +@@ -297,10 +302,10 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, + /* could do this with code-generated passed in pixel offsets too */ + + assert(loop_iter); +- ptr = LLVMBuildGEP(builder, bld->xoffset_store, &loop_iter, 1, ""); +- pixoffx = LLVMBuildLoad(builder, ptr, ""); +- ptr = LLVMBuildGEP(builder, bld->yoffset_store, &loop_iter, 1, ""); +- pixoffy = LLVMBuildLoad(builder, ptr, ""); ++ ptr = LLVMBuildGEP2(builder, bld->store_elem_type, bld->xoffset_store, &loop_iter, 1, ""); ++ pixoffx = LLVMBuildLoad2(builder, bld->store_elem_type, ptr, ""); ++ ptr = LLVMBuildGEP2(builder, bld->store_elem_type, bld->yoffset_store, &loop_iter, 1, ""); ++ pixoffy = LLVMBuildLoad2(builder, bld->store_elem_type, ptr, ""); + + pixoffx = LLVMBuildFAdd(builder, pixoffx, + lp_build_broadcast_scalar(coeff_bld, bld->x), ""); +@@ -529,10 +534,10 @@ lp_build_interp_soa(struct lp_build_interp_soa_context *bld, + /* could do this with code-generated passed in pixel offsets too */ + + assert(loop_iter); +- ptr = LLVMBuildGEP(builder, bld->xoffset_store, &loop_iter, 1, ""); +- pixoffx = LLVMBuildLoad(builder, ptr, ""); +- ptr = LLVMBuildGEP(builder, bld->yoffset_store, &loop_iter, 1, ""); +- pixoffy = LLVMBuildLoad(builder, ptr, ""); ++ ptr = LLVMBuildGEP2(builder, bld->store_elem_type, bld->xoffset_store, &loop_iter, 1, ""); ++ pixoffx = LLVMBuildLoad2(builder, bld->store_elem_type, ptr, ""); ++ ptr = LLVMBuildGEP2(builder, bld->store_elem_type, bld->yoffset_store, &loop_iter, 1, ""); ++ pixoffy = LLVMBuildLoad2(builder, bld->store_elem_type, ptr, ""); + + pixoffx = LLVMBuildFAdd(builder, pixoffx, + lp_build_broadcast_scalar(coeff_bld, bld->x), ""); +@@ -769,20 +774,21 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, + LLVMValueRef pixoffx, pixoffy, index; + LLVMValueRef ptr; + ++ bld->store_elem_type = lp_build_vec_type(gallivm, type); + bld->xoffset_store = lp_build_array_alloca(gallivm, +- lp_build_vec_type(gallivm, type), ++ bld->store_elem_type, + lp_build_const_int32(gallivm, num_loops), + ""); + bld->yoffset_store = lp_build_array_alloca(gallivm, +- lp_build_vec_type(gallivm, type), ++ bld->store_elem_type, + lp_build_const_int32(gallivm, num_loops), + ""); + for (i = 0; i < num_loops; i++) { + index = lp_build_const_int32(gallivm, i); + calc_offsets(&bld->coeff_bld, i*type.length/4, &pixoffx, &pixoffy); +- ptr = LLVMBuildGEP(builder, bld->xoffset_store, &index, 1, ""); ++ ptr = LLVMBuildGEP2(builder, bld->store_elem_type, bld->xoffset_store, &index, 1, ""); + LLVMBuildStore(builder, pixoffx, ptr); +- ptr = LLVMBuildGEP(builder, bld->yoffset_store, &index, 1, ""); ++ ptr = LLVMBuildGEP2(builder, bld->store_elem_type, bld->yoffset_store, &index, 1, ""); + LLVMBuildStore(builder, pixoffy, ptr); + } + } +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.h b/src/gallium/drivers/llvmpipe/lp_bld_interp.h +index f77d2192258a6..6525ffb0bf038 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.h ++++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.h +@@ -107,6 +107,7 @@ struct lp_build_interp_soa_context + + LLVMValueRef xoffset_store; + LLVMValueRef yoffset_store; ++ LLVMTypeRef store_elem_type; + + /* + * Convenience pointers. Callers may access this one. +-- +GitLab + + +From d53fe793c38344382a71a89e3790249a31e3d4f3 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:28:22 +0300 +Subject: [PATCH 04/22] gallium/llvmpipe: use LLVM opaque pointers in + lp_bld_depth.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/drivers/llvmpipe/lp_bld_depth.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_depth.c b/src/gallium/drivers/llvmpipe/lp_bld_depth.c +index dc559bc3ffb10..cb4a727fa3cf8 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_depth.c ++++ b/src/gallium/drivers/llvmpipe/lp_bld_depth.c +@@ -510,7 +510,7 @@ lp_build_occlusion_count(struct gallivm_state *gallivm, + count = LLVMBuildZExt(builder, count, LLVMIntTypeInContext(context, 64), ""); + } + } +- newcount = LLVMBuildLoad(builder, counter, "origcount"); ++ newcount = LLVMBuildLoad2(builder, LLVMTypeOf(count), counter, "origcount"); + newcount = LLVMBuildAdd(builder, newcount, count, "newcount"); + LLVMBuildStore(builder, newcount, counter); + } +@@ -551,7 +551,8 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, + struct lp_type zs_load_type = zs_type; + + zs_load_type.length = zs_load_type.length / 2; +- load_ptr_type = LLVMPointerType(lp_build_vec_type(gallivm, zs_load_type), 0); ++ LLVMTypeRef zs_dst_type = lp_build_vec_type(gallivm, zs_load_type); ++ load_ptr_type = LLVMPointerType(zs_dst_type, 0); + + if (z_src_type.length == 4) { + unsigned i; +@@ -590,14 +591,14 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, + /* Load current z/stencil values from z/stencil buffer */ + zs_dst_ptr = LLVMBuildGEP(builder, depth_ptr, &depth_offset1, 1, ""); + zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, load_ptr_type, ""); +- zs_dst1 = LLVMBuildLoad(builder, zs_dst_ptr, ""); ++ zs_dst1 = LLVMBuildLoad2(builder, zs_dst_type, zs_dst_ptr, ""); + if (is_1d) { + zs_dst2 = lp_build_undef(gallivm, zs_load_type); + } + else { + zs_dst_ptr = LLVMBuildGEP(builder, depth_ptr, &depth_offset2, 1, ""); + zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, load_ptr_type, ""); +- zs_dst2 = LLVMBuildLoad(builder, zs_dst_ptr, ""); ++ zs_dst2 = LLVMBuildLoad2(builder, zs_dst_type, zs_dst_ptr, ""); + } + + *z_fb = LLVMBuildShuffleVector(builder, zs_dst1, zs_dst2, +-- +GitLab + + +From 1e1ebbe6df456a4677d64a535bbb553ba4f702ea Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:31:29 +0300 +Subject: [PATCH 05/22] gallivm: use LLVM opaque pointers in lp_bld_arit.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_arit.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c +index 9cff0162b2334..2061902a215a3 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c +@@ -3757,7 +3757,7 @@ lp_build_fpstate_set_denorms_zero(struct gallivm_state *gallivm, + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef mxcsr_ptr = lp_build_fpstate_get(gallivm); + LLVMValueRef mxcsr = +- LLVMBuildLoad(builder, mxcsr_ptr, "mxcsr"); ++ LLVMBuildLoad2(builder, LLVMInt32TypeInContext(gallivm->context), mxcsr_ptr, "mxcsr"); + + if (util_get_cpu_caps()->has_daz) { + /* Enable denormals are zero mode */ +-- +GitLab + + +From 70e9db951d5134546d0115cf773593ec33d5b5d2 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:32:25 +0300 +Subject: [PATCH 06/22] gallivm: use LLVM opaque pointers in lp_bld_assert.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_assert.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.c b/src/gallium/auxiliary/gallivm/lp_bld_assert.c +index 02755765c0eac..f50da3c127e61 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.c +@@ -75,9 +75,11 @@ lp_build_assert(struct gallivm_state *gallivm, + arg_types[0] = LLVMInt32TypeInContext(context); + arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0); + +- function = lp_build_const_func_pointer(gallivm, ++ LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, 2, 0); ++ ++ function = lp_build_const_func_pointer_from_type(gallivm, + func_to_pointer((func_pointer)lp_assert), +- ret_type, arg_types, ARRAY_SIZE(arg_types), ++ function_type, + "assert"); + + /* build function call param list */ +@@ -87,6 +89,5 @@ lp_build_assert(struct gallivm_state *gallivm, + /* check arg types */ + assert(LLVMTypeOf(args[0]) == arg_types[0]); + assert(LLVMTypeOf(args[1]) == arg_types[1]); +- +- LLVMBuildCall(builder, function, args, ARRAY_SIZE(args), ""); ++ LLVMBuildCall2(builder, function_type, function, args, ARRAY_SIZE(args), ""); + } +-- +GitLab + + +From 6867b184cac892e3f6aaf3fab3e0453bd784aaf7 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:41:12 +0300 +Subject: [PATCH 07/22] gallivm: use LLVM opaque pointers in + lp_bld_format_aos.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Also extract lp_build_const_func_pointer_from_type() in lp_bld_const.h +taking explicit function type. + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_const.c | 25 ++++++----- + src/gallium/auxiliary/gallivm/lp_bld_const.h | 6 +++ + .../auxiliary/gallivm/lp_bld_format_aos.c | 45 +++++++++---------- + 3 files changed, 40 insertions(+), 36 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c +index 4f4bddf44b813..7d9f3176ec1bd 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_const.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c +@@ -455,6 +455,17 @@ lp_build_const_string(struct gallivm_state *gallivm, + return string; + } + ++LLVMValueRef ++lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm, ++ const void *ptr, ++ LLVMTypeRef function_type, ++ const char *name) ++{ ++ return LLVMBuildBitCast(gallivm->builder, ++ lp_build_const_int_pointer(gallivm, ptr), ++ LLVMPointerType(function_type, 0), ++ name); ++} + + /** + * Build a callable function pointer. +@@ -470,16 +481,6 @@ lp_build_const_func_pointer(struct gallivm_state *gallivm, + unsigned num_args, + const char *name) + { +- LLVMTypeRef function_type; +- LLVMValueRef function; +- +- function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); +- +- function = lp_build_const_int_pointer(gallivm, ptr); +- +- function = LLVMBuildBitCast(gallivm->builder, function, +- LLVMPointerType(function_type, 0), +- name); +- +- return function; ++ LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); ++ return lp_build_const_func_pointer_from_type(gallivm, ptr, function_type, name); + } +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h +index 385b5b02d038e..d4098765f5e7a 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_const.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h +@@ -176,4 +176,10 @@ lp_build_const_func_pointer(struct gallivm_state *gallivm, + const char *name); + + ++LLVMValueRef ++lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm, ++ const void *ptr, ++ LLVMTypeRef function_type, ++ const char *name); ++ + #endif /* !LP_BLD_CONST_H */ +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c +index 74fe1672b27f8..86cca0bb0e8f1 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c +@@ -820,6 +820,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + * Declare and bind format_desc->fetch_rgba_8unorm(). + */ + ++ LLVMTypeRef function_type; + { + /* + * Function to call looks like: +@@ -827,7 +828,6 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + */ + LLVMTypeRef ret_type; + LLVMTypeRef arg_types[4]; +- LLVMTypeRef function_type; + + ret_type = LLVMVoidTypeInContext(gallivm->context); + arg_types[0] = pi8t; +@@ -836,19 +836,16 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + arg_types[3] = i32t; + function_type = LLVMFunctionType(ret_type, arg_types, + ARRAY_SIZE(arg_types), 0); +- +- if (gallivm->cache) +- gallivm->cache->dont_cache = true; +- /* make const pointer for the C fetch_rgba_8unorm function */ +- function = lp_build_const_int_pointer(gallivm, +- func_to_pointer((func_pointer) unpack->fetch_rgba_8unorm)); +- +- /* cast the callee pointer to the function's type */ +- function = LLVMBuildBitCast(builder, function, +- LLVMPointerType(function_type, 0), +- "cast callee"); + } + ++ if (gallivm->cache) ++ gallivm->cache->dont_cache = true; ++ /* make const pointer for the C fetch_rgba_8unorm function */ ++ function = lp_build_const_int_pointer(gallivm, ++ func_to_pointer((func_pointer) unpack->fetch_rgba_8unorm)); ++ /* cast the callee pointer to the function's type */ ++ function = LLVMBuildBitCast(builder, function, LLVMPointerType(function_type, 0), "cast callee"); ++ + tmp_ptr = lp_build_alloca(gallivm, i32t, ""); + + res = LLVMGetUndef(LLVMVectorType(i32t, num_pixels)); +@@ -875,9 +872,9 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + args[3] = LLVMBuildExtractElement(builder, j, index, ""); + } + +- LLVMBuildCall(builder, function, args, ARRAY_SIZE(args), ""); ++ LLVMBuildCall2(builder, function_type, function, args, ARRAY_SIZE(args), ""); + +- tmp = LLVMBuildLoad(builder, tmp_ptr, ""); ++ tmp = LLVMBuildLoad2(builder, i32t, tmp_ptr, ""); + + if (num_pixels == 1) { + res = tmp; +@@ -929,6 +926,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + * Declare and bind unpack->fetch_rgba_float(). + */ + ++ LLVMTypeRef function_type = NULL; + { + /* + * Function to call looks like: +@@ -942,15 +940,14 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + arg_types[1] = pi8t; + arg_types[2] = i32t; + arg_types[3] = i32t; +- +- if (gallivm->cache) +- gallivm->cache->dont_cache = true; +- function = lp_build_const_func_pointer(gallivm, +- func_to_pointer((func_pointer) fetch_rgba), +- ret_type, +- arg_types, ARRAY_SIZE(arg_types), +- format_desc->short_name); ++ function_type = LLVMFunctionType(ret_type, arg_types, ARRAY_SIZE(arg_types), 0); + } ++ if (gallivm->cache) ++ gallivm->cache->dont_cache = true; ++ function = lp_build_const_func_pointer_from_type(gallivm, ++ func_to_pointer((func_pointer) fetch_rgba), ++ function_type, ++ format_desc->short_name); + + tmp_ptr = lp_build_alloca(gallivm, f32x4t, ""); + +@@ -976,9 +973,9 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + args[3] = LLVMBuildExtractElement(builder, j, index, ""); + } + +- LLVMBuildCall(builder, function, args, ARRAY_SIZE(args), ""); ++ LLVMBuildCall2(builder, function_type, function, args, ARRAY_SIZE(args), ""); + +- tmps[k] = LLVMBuildLoad(builder, tmp_ptr, ""); ++ tmps[k] = LLVMBuildLoad2(builder, f32x4t, tmp_ptr, ""); + } + + lp_build_conv(gallivm, +-- +GitLab + + +From f1fc0bb567e5fdc92abd121a43fe2a632150c91c Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:44:19 +0300 +Subject: [PATCH 08/22] gallivm: use LLVM opaque pointers in lp_bld_conv.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_conv.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.c b/src/gallium/auxiliary/gallivm/lp_bld_conv.c +index 1073ff4fa66c3..69494ed22aaed 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_conv.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.c +@@ -229,7 +229,7 @@ lp_build_float_to_half(struct gallivm_state *gallivm, + */ + LLVMValueRef f16 = lp_build_intrinsic_unary(builder, "llvm.convert.to.fp16", i16t, f32); + #else +- LLVMValueRef f16 = LLVMBuildCall(builder, func, &f32, 1, ""); ++ LLVMValueRef f16 = LLVMBuildCall2(builder, func_type, func, &f32, 1, ""); + #endif + ref_result = LLVMBuildInsertElement(builder, ref_result, f16, index, ""); + } +-- +GitLab + + +From 2a6e9d13fb9e02e88cb9bfc3a89864f72156a91e Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:51:30 +0300 +Subject: [PATCH 09/22] gallivm: use LLVM opaque pointers in lp_bld_coro.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_coro.c | 15 +++++++++++---- + src/gallium/auxiliary/gallivm/lp_bld_init.h | 3 +++ + 2 files changed, 14 insertions(+), 4 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_coro.c b/src/gallium/auxiliary/gallivm/lp_bld_coro.c +index d3d5e6dc9693c..a423f60d939a6 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_coro.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_coro.c +@@ -169,8 +169,10 @@ void lp_build_coro_declare_malloc_hooks(struct gallivm_state *gallivm) + LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); + LLVMTypeRef mem_ptr_type = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0); + LLVMTypeRef malloc_type = LLVMFunctionType(mem_ptr_type, &int32_type, 1, 0); ++ gallivm->coro_malloc_hook_type = malloc_type; + gallivm->coro_malloc_hook = LLVMAddFunction(gallivm->module, "coro_malloc", malloc_type); + LLVMTypeRef free_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), &mem_ptr_type, 1, 0); ++ gallivm->coro_free_hook_type = free_type; + gallivm->coro_free_hook = LLVMAddFunction(gallivm->module, "coro_free", free_type); + } + +@@ -184,7 +186,10 @@ LLVMValueRef lp_build_coro_begin_alloc_mem(struct gallivm_state *gallivm, LLVMVa + LLVMValueRef alloc_mem; + + assert(gallivm->coro_malloc_hook); +- alloc_mem = LLVMBuildCall(gallivm->builder, gallivm->coro_malloc_hook, &coro_size, 1, ""); ++ LLVMTypeRef malloc_type = ++ LLVMFunctionType(mem_ptr_type, ++ (LLVMTypeRef[]){LLVMInt32TypeInContext(gallivm->context)}, 1, 0); ++ alloc_mem = LLVMBuildCall2(gallivm->builder, malloc_type, gallivm->coro_malloc_hook, &coro_size, 1, ""); + lp_build_endif(&if_state_coro); + + LLVMValueRef phi = LLVMBuildPhi(gallivm->builder, mem_ptr_type, ""); +@@ -212,7 +217,8 @@ LLVMValueRef lp_build_coro_alloc_mem_array(struct gallivm_state *gallivm, + LLVMValueRef alloc_mem; + LLVMValueRef alloc_size = LLVMBuildMul(gallivm->builder, coro_num_hdls, coro_size, ""); + assert(gallivm->coro_malloc_hook); +- alloc_mem = LLVMBuildCall(gallivm->builder, gallivm->coro_malloc_hook, &alloc_size, 1, ""); ++ assert(gallivm->coro_malloc_hook_type); ++ alloc_mem = LLVMBuildCall2(gallivm->builder, gallivm->coro_malloc_hook_type, gallivm->coro_malloc_hook, &alloc_size, 1, ""); + LLVMBuildStore(gallivm->builder, alloc_mem, coro_hdl_ptr); + lp_build_endif(&if_state_coro); + +@@ -223,8 +229,9 @@ void lp_build_coro_free_mem(struct gallivm_state *gallivm, LLVMValueRef coro_id, + { + LLVMValueRef alloc_mem = lp_build_coro_free(gallivm, coro_id, coro_hdl); + +- assert(gallivm->coro_malloc_hook); +- alloc_mem = LLVMBuildCall(gallivm->builder, gallivm->coro_free_hook, &alloc_mem, 1, ""); ++ assert(gallivm->coro_free_hook); ++ assert(gallivm->coro_free_hook_type); ++ alloc_mem = LLVMBuildCall2(gallivm->builder, gallivm->coro_free_hook_type, gallivm->coro_free_hook, &alloc_mem, 1, ""); + } + + void lp_build_coro_suspend_switch(struct gallivm_state *gallivm, const struct lp_build_coro_suspend_info *sus_info, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h +index 7c516b2b266d6..7eaaa31745b8f 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h +@@ -57,6 +57,9 @@ struct gallivm_state + LLVMValueRef coro_malloc_hook; + LLVMValueRef coro_free_hook; + LLVMValueRef debug_printf_hook; ++ ++ LLVMTypeRef coro_malloc_hook_type; ++ LLVMTypeRef coro_free_hook_type; + }; + + +-- +GitLab + + +From 1e0ddda79679955f2a3ad9487ce4eab84b0ec7b1 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:53:10 +0300 +Subject: [PATCH 10/22] gallivm: use LLVM opaque pointers in lp_bld_printf.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_printf.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c +index 4db2c09423114..5e08a0c2fe6dc 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c +@@ -63,11 +63,11 @@ lp_build_print_args(struct gallivm_state* gallivm, + args[i] = LLVMBuildFPExt(builder, args[i], LLVMDoubleTypeInContext(context), ""); + } + ++ LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1); + if (!gallivm->debug_printf_hook) { +- LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1); + gallivm->debug_printf_hook = LLVMAddFunction(gallivm->module, "debug_printf", printf_type); + } +- return LLVMBuildCall(builder, gallivm->debug_printf_hook, args, argcount, ""); ++ return LLVMBuildCall2(builder, printf_type, gallivm->debug_printf_hook, args, argcount, ""); + } + + +-- +GitLab + + +From 3143f871ac948cda9608579f08ca059e063882fa Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:54:57 +0300 +Subject: [PATCH 11/22] gallivm: use LLVM opaque pointers in lp_bld_flow.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_flow.c | 19 +++++++++++-------- + src/gallium/auxiliary/gallivm/lp_bld_flow.h | 7 +++++-- + 2 files changed, 16 insertions(+), 10 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c +index d5d903f66f237..8858aac9cb4ff 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c +@@ -168,8 +168,9 @@ lp_build_mask_begin(struct lp_build_mask_context *mask, + memset(mask, 0, sizeof *mask); + + mask->reg_type = LLVMIntTypeInContext(gallivm->context, type.width * type.length); ++ mask->var_type = lp_build_int_vec_type(gallivm, type); + mask->var = lp_build_alloca(gallivm, +- lp_build_int_vec_type(gallivm, type), ++ mask->var_type, + "execution_mask"); + + LLVMBuildStore(gallivm->builder, value, mask->var); +@@ -181,7 +182,7 @@ lp_build_mask_begin(struct lp_build_mask_context *mask, + LLVMValueRef + lp_build_mask_value(struct lp_build_mask_context *mask) + { +- return LLVMBuildLoad(mask->skip.gallivm->builder, mask->var, ""); ++ return LLVMBuildLoad2(mask->skip.gallivm->builder, mask->var_type, mask->var, ""); + } + + +@@ -233,7 +234,8 @@ lp_build_loop_begin(struct lp_build_loop_state *state, + + state->block = lp_build_insert_new_block(gallivm, "loop_begin"); + +- state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter"); ++ state->counter_type = LLVMTypeOf(start); ++ state->counter_var = lp_build_alloca(gallivm, state->counter_type, "loop_counter"); + state->gallivm = gallivm; + + LLVMBuildStore(builder, start, state->counter_var); +@@ -242,7 +244,7 @@ lp_build_loop_begin(struct lp_build_loop_state *state, + + LLVMPositionBuilderAtEnd(builder, state->block); + +- state->counter = LLVMBuildLoad(builder, state->counter_var, ""); ++ state->counter = LLVMBuildLoad2(builder, state->counter_type, state->counter_var, ""); + } + + +@@ -272,7 +274,7 @@ lp_build_loop_end_cond(struct lp_build_loop_state *state, + + LLVMPositionBuilderAtEnd(builder, after_block); + +- state->counter = LLVMBuildLoad(builder, state->counter_var, ""); ++ state->counter = LLVMBuildLoad2(builder, state->counter_type, state->counter_var, ""); + } + + void +@@ -287,7 +289,7 @@ void + lp_build_loop_force_reload_counter(struct lp_build_loop_state *state) + { + LLVMBuilderRef builder = state->gallivm->builder; +- state->counter = LLVMBuildLoad(builder, state->counter_var, ""); ++ state->counter = LLVMBuildLoad2(builder, state->counter_type, state->counter_var, ""); + } + + void +@@ -324,7 +326,8 @@ lp_build_for_loop_begin(struct lp_build_for_loop_state *state, + + state->begin = lp_build_insert_new_block(gallivm, "loop_begin"); + state->step = step; +- state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter"); ++ state->counter_type = LLVMTypeOf(start); ++ state->counter_var = lp_build_alloca(gallivm, state->counter_type, "loop_counter"); + state->gallivm = gallivm; + state->cond = cmp_op; + state->end = end; +@@ -333,7 +336,7 @@ lp_build_for_loop_begin(struct lp_build_for_loop_state *state, + LLVMBuildBr(builder, state->begin); + + LLVMPositionBuilderAtEnd(builder, state->begin); +- state->counter = LLVMBuildLoad(builder, state->counter_var, ""); ++ state->counter = LLVMBuildLoad2(builder, state->counter_type, state->counter_var, ""); + + state->body = lp_build_insert_new_block(gallivm, "loop_body"); + LLVMPositionBuilderAtEnd(builder, state->body); +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h +index c4ffa833e2add..c79502af5c4de 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h +@@ -73,7 +73,8 @@ struct lp_build_mask_context + struct lp_build_skip_context skip; + + LLVMTypeRef reg_type; +- ++ LLVMTypeRef var_type; ++ /* 'var' is a pointer (alloca) pointing to 'var_type' */ + LLVMValueRef var; + }; + +@@ -107,7 +108,7 @@ lp_build_mask_end(struct lp_build_mask_context *mask); + + /** + * LLVM's IR doesn't represent for-loops directly. Furthermore it +- * it requires creating code blocks, branches, phi variables, so it ++ * requires creating code blocks, branches, phi variables, so it + * requires a fair amount of code. + * + * @sa http://www.llvm.org/docs/tutorial/LangImpl5.html#for +@@ -117,6 +118,7 @@ struct lp_build_loop_state + LLVMBasicBlockRef block; + LLVMValueRef counter_var; + LLVMValueRef counter; ++ LLVMTypeRef counter_type; + struct gallivm_state *gallivm; + }; + +@@ -154,6 +156,7 @@ struct lp_build_for_loop_state + LLVMBasicBlockRef exit; + LLVMValueRef counter_var; + LLVMValueRef counter; ++ LLVMTypeRef counter_type; + LLVMValueRef step; + LLVMIntPredicate cond; + LLVMValueRef end; +-- +GitLab + + +From 84ba15ac06285b5851e4363837ba57380c12d07a Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:56:33 +0300 +Subject: [PATCH 12/22] gallivm: use LLVM opaque pointers in lp_bld_intr.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_intr.c | 50 ++++++++++++--------- + src/gallium/auxiliary/gallivm/lp_bld_intr.h | 5 +++ + 2 files changed, 34 insertions(+), 21 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c +index 2ce723c7e5ddc..99f5c77c4f03a 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c +@@ -103,19 +103,13 @@ lp_format_intrinsic(char *name, + + + LLVMValueRef +-lp_declare_intrinsic(LLVMModuleRef module, +- const char *name, +- LLVMTypeRef ret_type, +- LLVMTypeRef *arg_types, +- unsigned num_args) ++lp_declare_intrinsic_with_type(LLVMModuleRef module, ++ const char *name, ++ LLVMTypeRef function_type) + { +- LLVMTypeRef function_type; +- LLVMValueRef function; +- + assert(!LLVMGetNamedFunction(module, name)); + +- function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); +- function = LLVMAddFunction(module, name, function_type); ++ LLVMValueRef function = LLVMAddFunction(module, name, function_type); + + LLVMSetFunctionCallConv(function, LLVMCCallConv); + LLVMSetLinkage(function, LLVMExternalLinkage); +@@ -126,6 +120,18 @@ lp_declare_intrinsic(LLVMModuleRef module, + } + + ++LLVMValueRef ++lp_declare_intrinsic(LLVMModuleRef module, ++ const char *name, ++ LLVMTypeRef ret_type, ++ LLVMTypeRef *arg_types, ++ unsigned num_args) ++{ ++ LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); ++ return lp_declare_intrinsic_with_type(module, name, function_type); ++} ++ ++ + #if LLVM_VERSION_MAJOR < 4 + static LLVMAttribute lp_attr_to_llvm_attr(enum lp_func_attr attr) + { +@@ -232,19 +238,21 @@ lp_build_intrinsic(LLVMBuilderRef builder, + bool set_callsite_attrs = LLVM_VERSION_MAJOR >= 4 && + !(attr_mask & LP_FUNC_ATTR_LEGACY); + +- function = LLVMGetNamedFunction(module, name); +- if(!function) { +- LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS]; +- unsigned i; ++ LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS]; ++ ++ assert(num_args <= LP_MAX_FUNC_ARGS); + +- assert(num_args <= LP_MAX_FUNC_ARGS); ++ for(unsigned i = 0; i < num_args; ++i) { ++ assert(args[i]); ++ arg_types[i] = LLVMTypeOf(args[i]); ++ } + +- for(i = 0; i < num_args; ++i) { +- assert(args[i]); +- arg_types[i] = LLVMTypeOf(args[i]); +- } ++ LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); + +- function = lp_declare_intrinsic(module, name, ret_type, arg_types, num_args); ++ function = LLVMGetNamedFunction(module, name); ++ ++ if(!function) { ++ function = lp_declare_intrinsic_with_type(module, name, function_type); + + /* + * If llvm removes an intrinsic we use, we'll hit this abort (rather +@@ -265,7 +273,7 @@ lp_build_intrinsic(LLVMBuilderRef builder, + } + } + +- call = LLVMBuildCall(builder, function, args, num_args, ""); ++ call = LLVMBuildCall2(builder, function_type, function, args, num_args, ""); + if (set_callsite_attrs) + lp_add_func_attributes(call, attr_mask); + return call; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h +index ed90979f16fbb..98dfb0d0cb31d 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h +@@ -78,6 +78,11 @@ lp_declare_intrinsic(LLVMModuleRef module, + LLVMTypeRef *arg_types, + unsigned num_args); + ++LLVMValueRef ++lp_declare_intrinsic_with_type(LLVMModuleRef module, ++ const char *name, ++ LLVMTypeRef function_type); ++ + void + lp_add_function_attr(LLVMValueRef function_or_call, + int attr_idx, enum lp_func_attr attr); +-- +GitLab + + +From 61da78c31109a44b503c9350794d471a3acc7c7f Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 15:59:55 +0300 +Subject: [PATCH 13/22] gallivm: use LLVM opaque pointers in + lp_bld_format_s3tc.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + .../auxiliary/gallivm/lp_bld_format_s3tc.c | 39 +++++++------------ + 1 file changed, 15 insertions(+), 24 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +index 497d403fad372..8f972b840fa66 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +@@ -1097,13 +1097,12 @@ lp_build_gather_s3tc_simple_scalar(struct gallivm_state *gallivm, + LLVMValueRef elem, shuf; + LLVMTypeRef type32 = LLVMIntTypeInContext(gallivm->context, 32); + LLVMTypeRef src_type = LLVMIntTypeInContext(gallivm->context, block_bits); +- LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0); + LLVMTypeRef type32_4 = LLVMVectorType(type32, 4); + + assert(block_bits == 64 || block_bits == 128); + +- ptr = LLVMBuildBitCast(builder, ptr, src_ptr_type, ""); +- elem = LLVMBuildLoad(builder, ptr, ""); ++ ptr = LLVMBuildBitCast(builder, ptr, LLVMPointerType(src_type, 0), ""); ++ elem = LLVMBuildLoad2(builder, src_type, ptr, ""); + + if (block_bits == 128) { + /* just return block as is */ +@@ -1139,15 +1138,13 @@ s3tc_store_cached_block(struct gallivm_state *gallivm, + LLVMBuildStore(builder, tag_value, ptr); + + indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_DATA); +- hash_index = LLVMBuildMul(builder, hash_index, +- lp_build_const_int32(gallivm, 16), ""); ++ hash_index = LLVMBuildMul(builder, hash_index, lp_build_const_int32(gallivm, 16), ""); + for (count = 0; count < 4; count++) { + indices[2] = hash_index; + ptr = LLVMBuildGEP(builder, cache, indices, ARRAY_SIZE(indices), ""); + ptr = LLVMBuildBitCast(builder, ptr, type_ptr4x32, ""); + LLVMBuildStore(builder, col[count], ptr); +- hash_index = LLVMBuildAdd(builder, hash_index, +- lp_build_const_int32(gallivm, 4), ""); ++ hash_index = LLVMBuildAdd(builder, hash_index, lp_build_const_int32(gallivm, 4), ""); + } + } + +@@ -1177,8 +1174,9 @@ s3tc_lookup_tag_data(struct gallivm_state *gallivm, + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_TAGS); + indices[2] = index; ++ LLVMTypeRef tag_type = LLVMInt64TypeInContext(gallivm->context); + member_ptr = LLVMBuildGEP(builder, ptr, indices, ARRAY_SIZE(indices), ""); +- return LLVMBuildLoad(builder, member_ptr, "tag_data"); ++ return LLVMBuildLoad2(builder, tag_type, member_ptr, "tag_data"); + } + + #if LP_BUILD_FORMAT_CACHE_DEBUG +@@ -1996,24 +1994,17 @@ update_cached_block(struct gallivm_state *gallivm, + format_desc->short_name); + function = LLVMGetNamedFunction(module, name); + +- if (!function) { +- LLVMTypeRef ret_type; +- LLVMTypeRef arg_types[3]; +- LLVMTypeRef function_type; +- unsigned arg; ++ LLVMTypeRef ret_type = LLVMVoidTypeInContext(gallivm->context); ++ LLVMTypeRef arg_types[3]; ++ arg_types[0] = pi8t; ++ arg_types[1] = LLVMInt32TypeInContext(gallivm->context); ++ arg_types[2] = LLVMTypeOf(cache); // XXX: put right type here ++ LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, ARRAY_SIZE(arg_types), 0); + +- /* +- * Generate the function prototype. +- */ +- +- ret_type = LLVMVoidTypeInContext(gallivm->context); +- arg_types[0] = pi8t; +- arg_types[1] = LLVMInt32TypeInContext(gallivm->context); +- arg_types[2] = LLVMTypeOf(cache); // XXX: put right type here +- function_type = LLVMFunctionType(ret_type, arg_types, ARRAY_SIZE(arg_types), 0); ++ if (!function) { + function = LLVMAddFunction(module, name, function_type); + +- for (arg = 0; arg < ARRAY_SIZE(arg_types); ++arg) ++ for (unsigned arg = 0; arg < ARRAY_SIZE(arg_types); ++arg) + if (LLVMGetTypeKind(arg_types[arg]) == LLVMPointerTypeKind) + lp_add_function_attr(function, arg + 1, LP_FUNC_ATTR_NOALIAS); + +@@ -2026,7 +2017,7 @@ update_cached_block(struct gallivm_state *gallivm, + args[1] = hash_index; + args[2] = cache; + +- LLVMBuildCall(builder, function, args, ARRAY_SIZE(args), ""); ++ LLVMBuildCall2(builder, function_type, function, args, ARRAY_SIZE(args), ""); + bb = LLVMGetInsertBlock(builder); + inst = LLVMGetLastInstruction(bb); + LLVMSetInstructionCallConv(inst, LLVMFastCallConv); +-- +GitLab + + +From 36c45736ce03c7e66c8fe5422d0df49b5954a213 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:01:52 +0300 +Subject: [PATCH 14/22] gallivm: use LLVM opaque pointers in lp_bld_gather.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_gather.c | 17 ++++++++--------- + 1 file changed, 8 insertions(+), 9 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.c b/src/gallium/auxiliary/gallivm/lp_bld_gather.c +index 42cc17371a0db..2f2506803cf9a 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.c +@@ -55,7 +55,8 @@ lp_build_gather_elem_ptr(struct gallivm_state *gallivm, + LLVMValueRef offset; + LLVMValueRef ptr; + +- assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0)); ++ ASSERTED LLVMTypeRef element_type = LLVMInt8TypeInContext(gallivm->context); ++ assert(LLVMTypeOf(base_ptr) == LLVMPointerType(element_type, 0)); + + if (length == 1) { + assert(i == 0); +@@ -65,7 +66,7 @@ lp_build_gather_elem_ptr(struct gallivm_state *gallivm, + offset = LLVMBuildExtractElement(gallivm->builder, offsets, index, ""); + } + +- ptr = LLVMBuildGEP(gallivm->builder, base_ptr, &offset, 1, ""); ++ ptr = LLVMBuildGEP2(gallivm->builder, element_type, base_ptr, &offset, 1, ""); + + return ptr; + } +@@ -88,7 +89,6 @@ lp_build_gather_elem(struct gallivm_state *gallivm, + boolean vector_justify) + { + LLVMTypeRef src_type = LLVMIntTypeInContext(gallivm->context, src_width); +- LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0); + LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width); + LLVMValueRef ptr; + LLVMValueRef res; +@@ -96,8 +96,8 @@ lp_build_gather_elem(struct gallivm_state *gallivm, + assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0)); + + ptr = lp_build_gather_elem_ptr(gallivm, length, base_ptr, offsets, i); +- ptr = LLVMBuildBitCast(gallivm->builder, ptr, src_ptr_type, ""); +- res = LLVMBuildLoad(gallivm->builder, ptr, ""); ++ ptr = LLVMBuildBitCast(gallivm->builder, ptr, LLVMPointerType(src_type, 0), ""); ++ res = LLVMBuildLoad2(gallivm->builder, src_type, ptr, ""); + + /* XXX + * On some archs we probably really want to avoid having to deal +@@ -173,12 +173,11 @@ lp_build_gather_elem_vec(struct gallivm_state *gallivm, + boolean vector_justify) + { + LLVMValueRef ptr, res; +- LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0); + assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0)); + + ptr = lp_build_gather_elem_ptr(gallivm, length, base_ptr, offsets, i); +- ptr = LLVMBuildBitCast(gallivm->builder, ptr, src_ptr_type, ""); +- res = LLVMBuildLoad(gallivm->builder, ptr, ""); ++ ptr = LLVMBuildBitCast(gallivm->builder, ptr, LLVMPointerType(src_type, 0), ""); ++ res = LLVMBuildLoad2(gallivm->builder, src_type, ptr, ""); + + /* XXX + * On some archs we probably really want to avoid having to deal +@@ -324,7 +323,7 @@ lp_build_gather_avx2(struct gallivm_state *gallivm, + assert(LLVMTypeOf(offsets) == i32_vec_type); + offsets = LLVMBuildSDiv(builder, offsets, scale, ""); + +- src_ptr = LLVMBuildGEP(builder, base_ptr, &offsets, 1, "vector-gep"); ++ src_ptr = LLVMBuildGEP2(builder, src_type, base_ptr, &offsets, 1, "vector-gep"); + + char intrinsic[64]; + snprintf(intrinsic, sizeof intrinsic, "llvm.masked.gather.v%u%s%u", +-- +GitLab + + +From 2a59fdb96d5a7bfe8c10b6ce7eec621480abd092 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:03:36 +0300 +Subject: [PATCH 15/22] gallivm: use LLVM opaque pointers in lp_bld_nir_soa.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + .../auxiliary/gallivm/lp_bld_nir_soa.c | 89 ++++++++++--------- + 1 file changed, 45 insertions(+), 44 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +index 5a8fd02561bfb..e31faf577077b 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +@@ -282,8 +282,8 @@ build_gather(struct lp_build_nir_context *bld_base, + index = LLVMBuildExtractElement(builder, + indexes, si, ""); + } +- scalar_ptr = LLVMBuildGEP(builder, base_ptr, +- &index, 1, "gather_ptr"); ++ ++ scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "gather_ptr"); + scalar = LLVMBuildLoad(builder, scalar_ptr, ""); + + res = LLVMBuildInsertElement(builder, res, scalar, di, ""); +@@ -324,8 +324,8 @@ emit_mask_scatter(struct lp_build_nir_soa_context *bld, + for (i = 0; i < bld->bld_base.base.type.length; i++) { + LLVMValueRef ii = lp_build_const_int32(gallivm, i); + LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, ""); +- LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr"); + LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val"); ++ LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr"); + LLVMValueRef scalar_pred = pred ? + LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL; + +@@ -335,7 +335,7 @@ emit_mask_scatter(struct lp_build_nir_soa_context *bld, + + if (scalar_pred) { + LLVMValueRef real_val, dst_val; +- dst_val = LLVMBuildLoad(builder, scalar_ptr, ""); ++ dst_val = LLVMBuildLoad2(builder, LLVMTypeOf(val), scalar_ptr, ""); + scalar_pred = LLVMBuildTrunc(builder, scalar_pred, LLVMInt1TypeInContext(gallivm->context), ""); + real_val = LLVMBuildSelect(builder, scalar_pred, val, dst_val, ""); + LLVMBuildStore(builder, real_val, scalar_ptr); +@@ -862,13 +862,13 @@ static void emit_load_global(struct lp_build_nir_context *bld_base, + LLVMValueRef value_ptr = lp_build_pointer_get(builder, addr_ptr, lp_build_const_int32(gallivm, c)); + + LLVMValueRef temp_res; +- temp_res = LLVMBuildLoad(builder, result, ""); ++ temp_res = LLVMBuildLoad2(builder, res_bld->vec_type, result, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, value_ptr, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result); + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); +- outval[c] = LLVMBuildLoad(builder, result, ""); ++ outval[c] = LLVMBuildLoad2(builder, res_bld->vec_type, result, ""); + } + } + +@@ -1007,11 +1007,11 @@ static void emit_atomic_global(struct lp_build_nir_context *bld_base, + LLVMAtomicOrderingSequentiallyConsistent, + false); + } +- temp_res = LLVMBuildLoad(builder, atom_res, ""); ++ temp_res = LLVMBuildLoad2(builder, LLVMTypeOf(val), atom_res, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, scalar, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, atom_res); + lp_build_else(&ifthen); +- temp_res = LLVMBuildLoad(builder, atom_res, ""); ++ temp_res = LLVMBuildLoad2(builder, LLVMTypeOf(val), atom_res, ""); + bool is_float = LLVMTypeOf(val) == bld_base->base.vec_type; + LLVMValueRef zero_val; + if (is_float) { +@@ -1031,7 +1031,7 @@ static void emit_atomic_global(struct lp_build_nir_context *bld_base, + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); +- *result = LLVMBuildLoad(builder, atom_res, ""); ++ *result = LLVMBuildLoad2(builder, LLVMTypeOf(val), atom_res, ""); + } + + static void emit_load_ubo(struct lp_build_nir_context *bld_base, +@@ -1135,7 +1135,7 @@ mem_access_base_pointer(struct lp_build_nir_context *bld_base, + *bounds = NULL; + } + +- /* Cast it to the pointer type of the access this instruciton is doing. */ ++ /* Cast it to the pointer type of the access this instruction is doing. */ + if (bit_size == 32) + return ptr; + else +@@ -1187,7 +1187,7 @@ static void emit_load_mem(struct lp_build_nir_context *bld_base, + LLVMBuildStore(builder, lp_build_pointer_get(builder, mem_ptr, chan_offset), res_store); + lp_build_endif(&ifthen); + +- scalar = LLVMBuildLoad(builder, res_store, ""); ++ scalar = LLVMBuildLoad2(builder, LLVMTypeOf(zero), res_store, ""); + } else { + scalar = lp_build_pointer_get(builder, mem_ptr, chan_offset); + } +@@ -1233,11 +1233,11 @@ static void emit_load_mem(struct lp_build_nir_context *bld_base, + lp_build_if(&ifthen, gallivm, fetch_cond); + LLVMValueRef scalar = lp_build_pointer_get(builder, mem_ptr, loop_index); + +- temp_res = LLVMBuildLoad(builder, result[c], ""); ++ temp_res = LLVMBuildLoad2(builder, load_bld->vec_type, result[c], ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, scalar, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result[c]); + lp_build_else(&ifthen); +- temp_res = LLVMBuildLoad(builder, result[c], ""); ++ temp_res = LLVMBuildLoad2(builder, load_bld->vec_type, result[c], ""); + LLVMValueRef zero = lp_build_zero_bits(gallivm, bit_size); + temp_res = LLVMBuildInsertElement(builder, temp_res, zero, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result[c]); +@@ -1248,7 +1248,7 @@ static void emit_load_mem(struct lp_build_nir_context *bld_base, + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); + for (unsigned c = 0; c < nc; c++) +- outval[c] = LLVMBuildLoad(gallivm->builder, result[c], ""); ++ outval[c] = LLVMBuildLoad2(gallivm->builder, load_bld->vec_type, result[c], ""); + + } + +@@ -1356,7 +1356,7 @@ static void emit_atomic_mem(struct lp_build_nir_context *bld_base, + loop_state.counter, ""); + value_ptr = LLVMBuildBitCast(gallivm->builder, value_ptr, atomic_bld->elem_type, ""); + +- LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, mem_ptr, &loop_offset, 1, ""); ++ LLVMValueRef scalar_ptr = LLVMBuildGEP2(builder, atomic_bld->elem_type, mem_ptr, &loop_offset, 1, ""); + + struct lp_build_if_state ifthen; + LLVMValueRef inner_cond, temp_res; +@@ -1423,11 +1423,11 @@ static void emit_atomic_mem(struct lp_build_nir_context *bld_base, + LLVMAtomicOrderingSequentiallyConsistent, + false); + } +- temp_res = LLVMBuildLoad(builder, atom_res, ""); ++ temp_res = LLVMBuildLoad2(builder, atomic_bld->vec_type, atom_res, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, scalar, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, atom_res); + lp_build_else(&ifthen); +- temp_res = LLVMBuildLoad(builder, atom_res, ""); ++ temp_res = LLVMBuildLoad2(builder, atomic_bld->vec_type, atom_res, ""); + LLVMValueRef zero = lp_build_zero_bits(gallivm, bit_size); + temp_res = LLVMBuildInsertElement(builder, temp_res, zero, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, atom_res); +@@ -1436,7 +1436,7 @@ static void emit_atomic_mem(struct lp_build_nir_context *bld_base, + lp_build_endif(&exec_ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); +- *result = LLVMBuildLoad(builder, atom_res, ""); ++ *result = LLVMBuildLoad2(builder, atomic_bld->vec_type, atom_res, ""); + } + + static void emit_barrier(struct lp_build_nir_context *bld_base) +@@ -1614,7 +1614,7 @@ static void emit_tex(struct lp_build_nir_context *bld_base, + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length), + NULL, LLVMIntUGE); +- LLVMValueRef idx_val = LLVMBuildLoad(builder, res_store, ""); ++ LLVMValueRef idx_val = LLVMBuildLoad2(builder, bld_base->uint_bld.elem_type, res_store, ""); + params->texture_index_offset = idx_val; + } + +@@ -1856,7 +1856,7 @@ increment_vec_ptr_by_mask(struct lp_build_nir_context * bld_base, + LLVMValueRef mask) + { + LLVMBuilderRef builder = bld_base->base.gallivm->builder; +- LLVMValueRef current_vec = LLVMBuildLoad(builder, ptr, ""); ++ LLVMValueRef current_vec = LLVMBuildLoad2(builder, LLVMTypeOf(mask), ptr, ""); + + current_vec = LLVMBuildSub(builder, current_vec, mask, ""); + +@@ -1869,7 +1869,7 @@ clear_uint_vec_ptr_from_mask(struct lp_build_nir_context * bld_base, + LLVMValueRef mask) + { + LLVMBuilderRef builder = bld_base->base.gallivm->builder; +- LLVMValueRef current_vec = LLVMBuildLoad(builder, ptr, ""); ++ LLVMValueRef current_vec = LLVMBuildLoad2(builder, bld_base->uint_bld.vec_type, ptr, ""); + + current_vec = lp_build_select(&bld_base->uint_bld, + mask, +@@ -1902,7 +1902,7 @@ static void emit_vertex(struct lp_build_nir_context *bld_base, uint32_t stream_i + return; + assert(bld->gs_iface->emit_vertex); + LLVMValueRef total_emitted_vertices_vec = +- LLVMBuildLoad(builder, bld->total_emitted_vertices_vec_ptr[stream_id], ""); ++ LLVMBuildLoad2(builder, bld->bld_base.uint_bld.vec_type, bld->total_emitted_vertices_vec_ptr[stream_id], ""); + LLVMValueRef mask = mask_vec(bld_base); + mask = clamp_mask_to_max_output_vertices(bld, mask, + total_emitted_vertices_vec); +@@ -1929,11 +1929,11 @@ end_primitive_masked(struct lp_build_nir_context * bld_base, + return; + struct lp_build_context *uint_bld = &bld_base->uint_bld; + LLVMValueRef emitted_vertices_vec = +- LLVMBuildLoad(builder, bld->emitted_vertices_vec_ptr[stream_id], ""); ++ LLVMBuildLoad2(builder, bld->bld_base.uint_bld.vec_type, bld->emitted_vertices_vec_ptr[stream_id], ""); + LLVMValueRef emitted_prims_vec = +- LLVMBuildLoad(builder, bld->emitted_prims_vec_ptr[stream_id], ""); ++ LLVMBuildLoad2(builder, bld->bld_base.uint_bld.vec_type, bld->emitted_prims_vec_ptr[stream_id], ""); + LLVMValueRef total_emitted_vertices_vec = +- LLVMBuildLoad(builder, bld->total_emitted_vertices_vec_ptr[stream_id], ""); ++ LLVMBuildLoad2(builder, bld->bld_base.uint_bld.vec_type, bld->total_emitted_vertices_vec_ptr[stream_id], ""); + + LLVMValueRef emitted_mask = lp_build_cmp(uint_bld, + PIPE_FUNC_NOTEQUAL, +@@ -1977,8 +1977,7 @@ emit_prologue(struct lp_build_nir_soa_context *bld) + LLVMValueRef lindex = + lp_build_const_int32(gallivm, index * 4 + chan); + LLVMValueRef input_ptr = +- LLVMBuildGEP(gallivm->builder, bld->inputs_array, +- &lindex, 1, ""); ++ LLVMBuildGEP2(gallivm->builder, vec_type, bld->inputs_array, &lindex, 1, ""); + LLVMValueRef value = bld->inputs[index][chan]; + if (value) + LLVMBuildStore(gallivm->builder, value, input_ptr); +@@ -2015,7 +2014,7 @@ static void emit_vote(struct lp_build_nir_context *bld_base, LLVMValueRef src, + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length), + NULL, LLVMIntUGE); +- init_val = LLVMBuildLoad(builder, eq_store, ""); ++ init_val = LLVMBuildLoad2(builder, get_int_bld(bld_base, true, bit_size)->elem_type, eq_store, ""); + } else { + LLVMBuildStore(builder, lp_build_const_int32(gallivm, instr->intrinsic == nir_intrinsic_vote_any ? 0 : -1), res_store); + } +@@ -2029,7 +2028,7 @@ static void emit_vote(struct lp_build_nir_context *bld_base, LLVMValueRef src, + if_cond = LLVMBuildExtractElement(gallivm->builder, outer_cond, loop_state.counter, ""); + + lp_build_if(&ifthen, gallivm, if_cond); +- res = LLVMBuildLoad(builder, res_store, ""); ++ res = LLVMBuildLoad2(builder, bld_base->uint_bld.elem_type, res_store, ""); + + if (instr->intrinsic == nir_intrinsic_vote_feq) { + struct lp_build_context *flt_bld = get_flt_bld(bld_base, bit_size); +@@ -2050,7 +2049,8 @@ static void emit_vote(struct lp_build_nir_context *bld_base, LLVMValueRef src, + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length), + NULL, LLVMIntUGE); +- result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildLoad(builder, res_store, "")); ++ result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, ++ LLVMBuildLoad2(builder, bld_base->uint_bld.elem_type, res_store, "")); + } + + static void emit_ballot(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef result[4]) +@@ -2065,7 +2065,7 @@ static void emit_ballot(struct lp_build_nir_context *bld_base, LLVMValueRef src, + lp_build_loop_begin(&loop_state, gallivm, lp_build_const_int32(gallivm, 0)); + LLVMValueRef value_ptr = LLVMBuildExtractElement(gallivm->builder, src, + loop_state.counter, ""); +- res = LLVMBuildLoad(builder, res_store, ""); ++ res = LLVMBuildLoad2(builder, bld_base->int_bld.elem_type, res_store, ""); + res = LLVMBuildOr(builder, + res, + LLVMBuildAnd(builder, value_ptr, LLVMBuildShl(builder, lp_build_const_int32(gallivm, 1), loop_state.counter, ""), ""), ""); +@@ -2073,7 +2073,8 @@ static void emit_ballot(struct lp_build_nir_context *bld_base, LLVMValueRef src, + + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length), + NULL, LLVMIntUGE); +- result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildLoad(builder, res_store, "")); ++ result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, ++ LLVMBuildLoad2(builder, bld_base->int_bld.elem_type, res_store, "")); + } + + static void emit_elect(struct lp_build_nir_context *bld_base, LLVMValueRef result[4]) +@@ -2094,7 +2095,7 @@ static void emit_elect(struct lp_build_nir_context *bld_base, LLVMValueRef resul + lp_build_const_int32(gallivm, -1), ""); + LLVMValueRef cond2 = LLVMBuildICmp(gallivm->builder, + LLVMIntEQ, +- LLVMBuildLoad(builder, found_store, ""), ++ LLVMBuildLoad2(builder, bld_base->int_bld.elem_type, found_store, ""), + lp_build_const_int32(gallivm, 0), ""); + + cond = LLVMBuildAnd(builder, cond, cond2, ""); +@@ -2108,7 +2109,7 @@ static void emit_elect(struct lp_build_nir_context *bld_base, LLVMValueRef resul + + result[0] = LLVMBuildInsertElement(builder, bld_base->uint_bld.zero, + lp_build_const_int32(gallivm, -1), +- LLVMBuildLoad(builder, idx_store, ""), ++ LLVMBuildLoad2(builder, bld_base->int_bld.elem_type, idx_store, ""), + ""); + } + +@@ -2316,9 +2317,9 @@ static void emit_reduce(struct lp_build_nir_context *bld_base, LLVMValueRef src, + LLVMValueRef value = LLVMBuildExtractElement(gallivm->builder, src, loop_state.counter, ""); + + LLVMValueRef res = NULL; +- LLVMValueRef scan_val = LLVMBuildLoad(gallivm->builder, scan_store, ""); ++ LLVMValueRef scan_val = LLVMBuildLoad2(gallivm->builder, int_bld->elem_type, scan_store, ""); + if (instr->intrinsic != nir_intrinsic_reduce) +- res = LLVMBuildLoad(gallivm->builder, res_store, ""); ++ res = LLVMBuildLoad2(gallivm->builder, int_bld->vec_type, res_store, ""); + + if (instr->intrinsic == nir_intrinsic_exclusive_scan) + res = LLVMBuildInsertElement(builder, res, scan_val, loop_state.counter, ""); +@@ -2374,9 +2375,9 @@ static void emit_reduce(struct lp_build_nir_context *bld_base, LLVMValueRef src, + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length), + NULL, LLVMIntUGE); + if (instr->intrinsic == nir_intrinsic_reduce) +- result[0] = lp_build_broadcast_scalar(int_bld, LLVMBuildLoad(builder, scan_store, "")); ++ result[0] = lp_build_broadcast_scalar(int_bld, LLVMBuildLoad2(builder, int_bld->elem_type, scan_store, "")); + else +- result[0] = LLVMBuildLoad(builder, res_store, ""); ++ result[0] = LLVMBuildLoad2(builder, int_bld->vec_type, res_store, ""); + } + + static void emit_read_invocation(struct lp_build_nir_context *bld_base, +@@ -2409,7 +2410,7 @@ static void emit_read_invocation(struct lp_build_nir_context *bld_base, + + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, -1), + lp_build_const_int32(gallivm, -1), LLVMIntEQ); +- idx = LLVMBuildLoad(builder, res_store, ""); ++ idx = LLVMBuildLoad2(builder, bld_base->int_bld.elem_type, res_store, ""); + + LLVMValueRef value = LLVMBuildExtractElement(gallivm->builder, + src, idx, ""); +@@ -2492,18 +2493,18 @@ emit_load_scratch(struct lp_build_nir_context *bld_base, + LLVMValueRef ptr2 = LLVMBuildBitCast(builder, bld->scratch_ptr, LLVMPointerType(load_bld->elem_type, 0), ""); + scalar = lp_build_pointer_get(builder, ptr2, loop_index); + +- temp_res = LLVMBuildLoad(builder, result, ""); ++ temp_res = LLVMBuildLoad2(builder, load_bld->vec_type, result, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, scalar, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result); + lp_build_else(&ifthen); +- temp_res = LLVMBuildLoad(builder, result, ""); ++ temp_res = LLVMBuildLoad2(builder, load_bld->vec_type, result, ""); + LLVMValueRef zero = lp_build_zero_bits(gallivm, bit_size); + temp_res = LLVMBuildInsertElement(builder, temp_res, zero, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result); + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); +- outval[c] = LLVMBuildLoad(gallivm->builder, result, ""); ++ outval[c] = LLVMBuildLoad2(gallivm->builder, load_bld->vec_type, result, ""); + } + } + +@@ -2737,10 +2738,10 @@ void lp_build_nir_soa(struct gallivm_state *gallivm, + end_primitive_masked(&bld.bld_base, lp_build_mask_value(bld.mask), i); + + total_emitted_vertices_vec = +- LLVMBuildLoad(builder, bld.total_emitted_vertices_vec_ptr[i], ""); ++ LLVMBuildLoad2(builder, bld.bld_base.uint_bld.vec_type, bld.total_emitted_vertices_vec_ptr[i], ""); + + emitted_prims_vec = +- LLVMBuildLoad(builder, bld.emitted_prims_vec_ptr[i], ""); ++ LLVMBuildLoad2(builder, bld.bld_base.uint_bld.vec_type, bld.emitted_prims_vec_ptr[i], ""); + bld.gs_iface->gs_epilogue(bld.gs_iface, + total_emitted_vertices_vec, + emitted_prims_vec, i); +-- +GitLab + + +From 12cac07fe6e02d4557f0b4843e7eb526dc2f2292 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:04:44 +0300 +Subject: [PATCH 16/22] gallivm: use LLVM opaque pointers in lp_bld_sample.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_sample.c | 49 ++++++++----------- + 1 file changed, 20 insertions(+), 29 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +index f04b692204fc7..97f9766798856 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +@@ -1163,6 +1163,16 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + lp_build_name(*lod_fpart_inout, "texture%u_mipweight", texture_unit); + } + ++/** ++ * A helper function that factorizes this common pattern. ++ */ ++static LLVMValueRef ++load_mip(struct gallivm_state *gallivm, LLVMValueRef offsets, LLVMValueRef index1) { ++ LLVMValueRef zero = lp_build_const_int32(gallivm, 0); ++ LLVMValueRef indexes[2] = {zero, index1}; ++ LLVMValueRef ptr = LLVMBuildGEP(gallivm->builder, offsets, indexes, ARRAY_SIZE(indexes), ""); ++ return LLVMBuildLoad(gallivm->builder, ptr, ""); ++} + + /** + * Return pointer to a single mipmap level. +@@ -1172,14 +1182,9 @@ LLVMValueRef + lp_build_get_mipmap_level(struct lp_build_sample_context *bld, + LLVMValueRef level) + { ++ LLVMValueRef mip_offset = load_mip(bld->gallivm, bld->mip_offsets, level); + LLVMBuilderRef builder = bld->gallivm->builder; +- LLVMValueRef indexes[2], data_ptr, mip_offset; +- +- indexes[0] = lp_build_const_int32(bld->gallivm, 0); +- indexes[1] = level; +- mip_offset = LLVMBuildGEP(builder, bld->mip_offsets, indexes, 2, ""); +- mip_offset = LLVMBuildLoad(builder, mip_offset, ""); +- data_ptr = LLVMBuildGEP(builder, bld->base_ptr, &mip_offset, 1, ""); ++ LLVMValueRef data_ptr = LLVMBuildGEP(builder, bld->base_ptr, &mip_offset, 1, ""); + return data_ptr; + } + +@@ -1192,13 +1197,10 @@ lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + LLVMValueRef level) + { + LLVMBuilderRef builder = bld->gallivm->builder; +- LLVMValueRef indexes[2], offsets, offset1; ++ LLVMValueRef offsets, offset1; + +- indexes[0] = lp_build_const_int32(bld->gallivm, 0); + if (bld->num_mips == 1) { +- indexes[1] = level; +- offset1 = LLVMBuildGEP(builder, bld->mip_offsets, indexes, 2, ""); +- offset1 = LLVMBuildLoad(builder, offset1, ""); ++ offset1 = load_mip(bld->gallivm, bld->mip_offsets, level); + offsets = lp_build_broadcast_scalar(&bld->int_coord_bld, offset1); + } + else if (bld->num_mips == bld->coord_bld.type.length / 4) { +@@ -1207,10 +1209,8 @@ lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + offsets = bld->int_coord_bld.undef; + for (i = 0; i < bld->num_mips; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); ++ offset1 = load_mip(bld->gallivm, bld->mip_offsets, LLVMBuildExtractElement(builder, level, indexi, "")); + LLVMValueRef indexo = lp_build_const_int32(bld->gallivm, 4 * i); +- indexes[1] = LLVMBuildExtractElement(builder, level, indexi, ""); +- offset1 = LLVMBuildGEP(builder, bld->mip_offsets, indexes, 2, ""); +- offset1 = LLVMBuildLoad(builder, offset1, ""); + offsets = LLVMBuildInsertElement(builder, offsets, offset1, indexo, ""); + } + offsets = lp_build_swizzle_scalar_aos(&bld->int_coord_bld, offsets, 0, 4); +@@ -1223,9 +1223,7 @@ lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + offsets = bld->int_coord_bld.undef; + for (i = 0; i < bld->num_mips; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); +- indexes[1] = LLVMBuildExtractElement(builder, level, indexi, ""); +- offset1 = LLVMBuildGEP(builder, bld->mip_offsets, indexes, 2, ""); +- offset1 = LLVMBuildLoad(builder, offset1, ""); ++ offset1 = load_mip(bld->gallivm, bld->mip_offsets, LLVMBuildExtractElement(builder, level, indexi, "")); + offsets = LLVMBuildInsertElement(builder, offsets, offset1, indexi, ""); + } + } +@@ -1310,12 +1308,9 @@ lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, + LLVMValueRef stride_array, LLVMValueRef level) + { + LLVMBuilderRef builder = bld->gallivm->builder; +- LLVMValueRef indexes[2], stride, stride1; +- indexes[0] = lp_build_const_int32(bld->gallivm, 0); ++ LLVMValueRef stride, stride1; + if (bld->num_mips == 1) { +- indexes[1] = level; +- stride1 = LLVMBuildGEP(builder, stride_array, indexes, 2, ""); +- stride1 = LLVMBuildLoad(builder, stride1, ""); ++ stride1 = load_mip(bld->gallivm, stride_array, level); + stride = lp_build_broadcast_scalar(&bld->int_coord_bld, stride1); + } + else if (bld->num_mips == bld->coord_bld.type.length / 4) { +@@ -1325,10 +1320,8 @@ lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, + stride = bld->int_coord_bld.undef; + for (i = 0; i < bld->num_mips; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); ++ stride1 = load_mip(bld->gallivm, stride_array, LLVMBuildExtractElement(builder, level, indexi, "")); + LLVMValueRef indexo = lp_build_const_int32(bld->gallivm, 4 * i); +- indexes[1] = LLVMBuildExtractElement(builder, level, indexi, ""); +- stride1 = LLVMBuildGEP(builder, stride_array, indexes, 2, ""); +- stride1 = LLVMBuildLoad(builder, stride1, ""); + stride = LLVMBuildInsertElement(builder, stride, stride1, indexo, ""); + } + stride = lp_build_swizzle_scalar_aos(&bld->int_coord_bld, stride, 0, 4); +@@ -1342,9 +1335,7 @@ lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, + stride = bld->int_coord_bld.undef; + for (i = 0; i < bld->coord_bld.type.length; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); +- indexes[1] = LLVMBuildExtractElement(builder, level, indexi, ""); +- stride1 = LLVMBuildGEP(builder, stride_array, indexes, 2, ""); +- stride1 = LLVMBuildLoad(builder, stride1, ""); ++ stride1 = load_mip(bld->gallivm, stride_array, LLVMBuildExtractElement(builder, level, indexi, "")); + stride = LLVMBuildInsertElement(builder, stride, stride1, indexi, ""); + } + } +-- +GitLab + + +From 1f636e7fb20292a1d377ea89404b8c10f5cf061e Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:06:06 +0300 +Subject: [PATCH 17/22] gallivm: use LLVM opaque pointers in + lp_bld_sample_soa.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + .../auxiliary/gallivm/lp_bld_sample_soa.c | 171 +++++++++--------- + 1 file changed, 86 insertions(+), 85 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +index 8417cdd79fc9d..09f6080fca223 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +@@ -1078,6 +1078,8 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld, + flt_size, + &flt_width_vec, &flt_height_vec, &flt_depth_vec); + ++ LLVMTypeRef int1t = LLVMInt1TypeInContext(bld->gallivm->context); ++ + /* + * Compute integer texcoords. + */ +@@ -1130,7 +1132,6 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld, + } + else { + struct lp_build_if_state edge_if; +- LLVMTypeRef int1t; + LLVMValueRef new_faces[4], new_xcoords[4][2], new_ycoords[4][2]; + LLVMValueRef coord0, coord1, have_edge, have_corner; + LLVMValueRef fall_off_ym_notxm, fall_off_ym_notxp, fall_off_x, fall_off_y; +@@ -1183,7 +1184,6 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld, + have_edge = lp_build_any_true_range(ivec_bld, ivec_bld->type.length, have_edge); + + /* needed for accurate corner filtering branch later, rely on 0 init */ +- int1t = LLVMInt1TypeInContext(bld->gallivm->context); + have_corners = lp_build_alloca(bld->gallivm, int1t, "have_corner"); + + for (texel_index = 0; texel_index < 4; texel_index++) { +@@ -1302,18 +1302,19 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld, + + lp_build_endif(&edge_if); + +- x00 = LLVMBuildLoad(builder, xs[0], ""); +- x01 = LLVMBuildLoad(builder, xs[1], ""); +- x10 = LLVMBuildLoad(builder, xs[2], ""); +- x11 = LLVMBuildLoad(builder, xs[3], ""); +- y00 = LLVMBuildLoad(builder, ys[0], ""); +- y01 = LLVMBuildLoad(builder, ys[1], ""); +- y10 = LLVMBuildLoad(builder, ys[2], ""); +- y11 = LLVMBuildLoad(builder, ys[3], ""); +- z00 = LLVMBuildLoad(builder, zs[0], ""); +- z01 = LLVMBuildLoad(builder, zs[1], ""); +- z10 = LLVMBuildLoad(builder, zs[2], ""); +- z11 = LLVMBuildLoad(builder, zs[3], ""); ++ LLVMTypeRef type = ivec_bld->vec_type; ++ x00 = LLVMBuildLoad2(builder, type, xs[0], ""); ++ x01 = LLVMBuildLoad2(builder, type, xs[1], ""); ++ x10 = LLVMBuildLoad2(builder, type, xs[2], ""); ++ x11 = LLVMBuildLoad2(builder, type, xs[3], ""); ++ y00 = LLVMBuildLoad2(builder, type, ys[0], ""); ++ y01 = LLVMBuildLoad2(builder, type, ys[1], ""); ++ y10 = LLVMBuildLoad2(builder, type, ys[2], ""); ++ y11 = LLVMBuildLoad2(builder, type, ys[3], ""); ++ z00 = LLVMBuildLoad2(builder, type, zs[0], ""); ++ z01 = LLVMBuildLoad2(builder, type, zs[1], ""); ++ z10 = LLVMBuildLoad2(builder, type, zs[2], ""); ++ z11 = LLVMBuildLoad2(builder, type, zs[3], ""); + } + + if (linear_mask) { +@@ -1411,7 +1412,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld, + colorss[2] = lp_build_alloca(bld->gallivm, coord_bld->vec_type, "cs2"); + colorss[3] = lp_build_alloca(bld->gallivm, coord_bld->vec_type, "cs3"); + +- have_corner = LLVMBuildLoad(builder, have_corners, ""); ++ have_corner = LLVMBuildLoad2(builder, int1t, have_corners, ""); + + lp_build_if(&corner_if, bld->gallivm, have_corner); + +@@ -1668,10 +1669,10 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld, + + lp_build_endif(&corner_if); + +- colors0[0] = LLVMBuildLoad(builder, colorss[0], ""); +- colors0[1] = LLVMBuildLoad(builder, colorss[1], ""); +- colors0[2] = LLVMBuildLoad(builder, colorss[2], ""); +- colors0[3] = LLVMBuildLoad(builder, colorss[3], ""); ++ colors0[0] = LLVMBuildLoad2(builder, coord_bld->vec_type, colorss[0], ""); ++ colors0[1] = LLVMBuildLoad2(builder, coord_bld->vec_type, colorss[1], ""); ++ colors0[2] = LLVMBuildLoad2(builder, coord_bld->vec_type, colorss[2], ""); ++ colors0[3] = LLVMBuildLoad2(builder, coord_bld->vec_type, colorss[3], ""); + } + + if (dims == 3) { +@@ -2306,7 +2307,7 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + LLVMBuildBr(builder, v_loop_block); + LLVMPositionBuilderAtEnd(builder, v_loop_block); + +- LLVMValueRef v_val = LLVMBuildLoad(builder, v_limiter, ""); ++ LLVMValueRef v_val = LLVMBuildLoad2(builder, bld->int_coord_bld.vec_type, v_limiter, ""); + LLVMValueRef v_mask = LLVMBuildICmp(builder, + LLVMIntSLE, + v_val, +@@ -2338,7 +2339,7 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + LLVMBuildBr(builder, u_loop_block); + LLVMPositionBuilderAtEnd(builder, u_loop_block); + +- LLVMValueRef u_val = LLVMBuildLoad(builder, u_limiter, ""); ++ LLVMValueRef u_val = LLVMBuildLoad2(builder, bld->int_coord_bld.vec_type, u_limiter, ""); + LLVMValueRef u_mask = LLVMBuildICmp(builder, + LLVMIntSLE, + u_val, +@@ -2347,7 +2348,7 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + /* loop over U values */ + { + /* q = (int)q */ +- q = lp_build_itrunc(coord_bld, LLVMBuildLoad(builder, q_store, "")); ++ q = lp_build_itrunc(coord_bld, LLVMBuildLoad2(builder, bld->coord_bld.vec_type, q_store, "")); + + /* + * avoid OOB access to filter table, generate a mask for q > 1024, +@@ -2403,7 +2404,7 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + temp_colors); + + for (chan = 0; chan < 4; chan++) { +- LLVMValueRef tcolor = LLVMBuildLoad(builder, colors0[chan], ""); ++ LLVMValueRef tcolor = LLVMBuildLoad2(builder, bld->texel_bld.vec_type, colors0[chan], ""); + + tcolor = lp_build_add(&bld->texel_bld, tcolor, lp_build_mul(&bld->texel_bld, temp_colors[chan], weights)); + LLVMBuildStore(builder, tcolor, colors0[chan]); +@@ -2411,22 +2412,22 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + + /* multiple colors by weight and add in. */ + /* den += weight; */ +- LLVMValueRef den = LLVMBuildLoad(builder, den_store, ""); ++ LLVMValueRef den = LLVMBuildLoad2(builder, bld->texel_bld.vec_type, den_store, ""); + den = lp_build_add(&bld->texel_bld, den, weights); + LLVMBuildStore(builder, den, den_store); + + lp_build_endif(&noloadw0); + /* q += dq; */ + /* dq += ddq; */ +- q = LLVMBuildLoad(builder, q_store, ""); +- dq = LLVMBuildLoad(builder, dq_store, ""); ++ q = LLVMBuildLoad2(builder, bld->texel_bld.vec_type, q_store, ""); ++ dq = LLVMBuildLoad2(builder, bld->texel_bld.vec_type, dq_store, ""); + q = lp_build_add(coord_bld, q, dq); + dq = lp_build_add(coord_bld, dq, ddq); + LLVMBuildStore(builder, q, q_store); + LLVMBuildStore(builder, dq, dq_store); + } + /* u += 1 */ +- u_val = LLVMBuildLoad(builder, u_limiter, ""); ++ u_val = LLVMBuildLoad2(builder, bld->int_coord_bld.vec_type, u_limiter, ""); + u_val = lp_build_add(&bld->int_coord_bld, u_val, bld->int_coord_bld.one); + LLVMBuildStore(builder, u_val, u_limiter); + +@@ -2447,7 +2448,7 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + } + + /* v += 1 */ +- v_val = LLVMBuildLoad(builder, v_limiter, ""); ++ v_val = LLVMBuildLoad2(builder, bld->int_coord_bld.vec_type, v_limiter, ""); + v_val = lp_build_add(&bld->int_coord_bld, v_val, bld->int_coord_bld.one); + LLVMBuildStore(builder, v_val, v_limiter); + +@@ -2465,10 +2466,10 @@ lp_build_sample_aniso(struct lp_build_sample_context *bld, + + LLVMPositionBuilderAtEnd(builder, v_end_loop); + +- LLVMValueRef den = LLVMBuildLoad(builder, den_store, ""); ++ LLVMValueRef den = LLVMBuildLoad2(builder, bld->texel_bld.vec_type, den_store, ""); + + for (chan = 0; chan < 4; chan++) +- colors0[chan] = lp_build_div(&bld->texel_bld, LLVMBuildLoad(builder, colors0[chan], ""), den); ++ colors0[chan] = lp_build_div(&bld->texel_bld, LLVMBuildLoad2(builder, bld->texel_bld.vec_type, colors0[chan], ""), den); + LLVMValueRef den0 = lp_build_cmp(&bld->coord_bld, PIPE_FUNC_EQUAL, den, bld->coord_bld.zero); + + LLVMValueRef den0_any = lp_build_any_true_range(&bld->coord_bld, bld->coord_bld.type.length, den0); +@@ -2710,7 +2711,7 @@ lp_build_clamp_border_color(struct lp_build_sample_context *bld, + lp_build_const_int32(gallivm, 0)); + border_color_ptr = LLVMBuildBitCast(builder, border_color_ptr, + LLVMPointerType(vec4_bld.vec_type, 0), ""); +- border_color = LLVMBuildLoad(builder, border_color_ptr, ""); ++ border_color = LLVMBuildLoad2(builder, vec4_bld.vec_type, border_color_ptr, ""); + /* we don't have aligned type in the dynamic state unfortunately */ + LLVMSetAlignment(border_color, 4); + +@@ -3055,7 +3056,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld, + } + + for (chan = 0; chan < 4; ++chan) { +- colors_out[chan] = LLVMBuildLoad(builder, texels[chan], ""); ++ colors_out[chan] = LLVMBuildLoad2(builder, bld->texel_bld.vec_type, texels[chan], ""); + lp_build_name(colors_out[chan], "sampler%u_texel_%c", sampler_unit, "xyzw"[chan]); + } + } +@@ -4116,60 +4117,60 @@ lp_build_sample_soa_func(struct gallivm_state *gallivm, + + function = LLVMGetNamedFunction(module, func_name); + +- if(!function) { +- LLVMTypeRef arg_types[LP_MAX_TEX_FUNC_ARGS]; +- LLVMTypeRef ret_type; +- LLVMTypeRef function_type; +- LLVMTypeRef val_type[4]; +- unsigned num_param = 0; ++ LLVMTypeRef arg_types[LP_MAX_TEX_FUNC_ARGS]; ++ LLVMTypeRef ret_type; ++ LLVMTypeRef val_type[4]; ++ unsigned num_param = 0; + +- /* +- * Generate the function prototype. +- */ ++ /* ++ * Generate the function prototype. ++ */ + +- arg_types[num_param++] = LLVMTypeOf(params->context_ptr); +- if (params->aniso_filter_table) +- arg_types[num_param++] = LLVMTypeOf(params->aniso_filter_table); +- if (need_cache) { +- arg_types[num_param++] = LLVMTypeOf(params->thread_data_ptr); +- } +- for (i = 0; i < num_coords; i++) { +- arg_types[num_param++] = LLVMTypeOf(coords[0]); +- assert(LLVMTypeOf(coords[0]) == LLVMTypeOf(coords[i])); +- } +- if (layer) { +- arg_types[num_param++] = LLVMTypeOf(coords[layer]); +- assert(LLVMTypeOf(coords[0]) == LLVMTypeOf(coords[layer])); +- } +- if (sample_key & LP_SAMPLER_SHADOW) { +- arg_types[num_param++] = LLVMTypeOf(coords[0]); +- } +- if (sample_key & LP_SAMPLER_FETCH_MS) { +- arg_types[num_param++] = LLVMTypeOf(params->ms_index); +- } +- if (sample_key & LP_SAMPLER_OFFSETS) { +- for (i = 0; i < num_offsets; i++) { +- arg_types[num_param++] = LLVMTypeOf(offsets[0]); +- assert(LLVMTypeOf(offsets[0]) == LLVMTypeOf(offsets[i])); +- } +- } +- if (lod_control == LP_SAMPLER_LOD_BIAS || +- lod_control == LP_SAMPLER_LOD_EXPLICIT) { +- arg_types[num_param++] = LLVMTypeOf(params->lod); ++ arg_types[num_param++] = LLVMTypeOf(params->context_ptr); ++ if (params->aniso_filter_table) ++ arg_types[num_param++] = LLVMTypeOf(params->aniso_filter_table); ++ if (need_cache) { ++ arg_types[num_param++] = LLVMTypeOf(params->thread_data_ptr); ++ } ++ for (i = 0; i < num_coords; i++) { ++ arg_types[num_param++] = LLVMTypeOf(coords[0]); ++ assert(LLVMTypeOf(coords[0]) == LLVMTypeOf(coords[i])); ++ } ++ if (layer) { ++ arg_types[num_param++] = LLVMTypeOf(coords[layer]); ++ assert(LLVMTypeOf(coords[0]) == LLVMTypeOf(coords[layer])); ++ } ++ if (sample_key & LP_SAMPLER_SHADOW) { ++ arg_types[num_param++] = LLVMTypeOf(coords[0]); ++ } ++ if (sample_key & LP_SAMPLER_FETCH_MS) { ++ arg_types[num_param++] = LLVMTypeOf(params->ms_index); ++ } ++ if (sample_key & LP_SAMPLER_OFFSETS) { ++ for (i = 0; i < num_offsets; i++) { ++ arg_types[num_param++] = LLVMTypeOf(offsets[0]); ++ assert(LLVMTypeOf(offsets[0]) == LLVMTypeOf(offsets[i])); + } +- else if (lod_control == LP_SAMPLER_LOD_DERIVATIVES) { +- for (i = 0; i < num_derivs; i++) { +- arg_types[num_param++] = LLVMTypeOf(derivs->ddx[i]); +- arg_types[num_param++] = LLVMTypeOf(derivs->ddy[i]); +- assert(LLVMTypeOf(derivs->ddx[0]) == LLVMTypeOf(derivs->ddx[i])); +- assert(LLVMTypeOf(derivs->ddy[0]) == LLVMTypeOf(derivs->ddy[i])); +- } ++ } ++ if (lod_control == LP_SAMPLER_LOD_BIAS || ++ lod_control == LP_SAMPLER_LOD_EXPLICIT) { ++ arg_types[num_param++] = LLVMTypeOf(params->lod); ++ } ++ else if (lod_control == LP_SAMPLER_LOD_DERIVATIVES) { ++ for (i = 0; i < num_derivs; i++) { ++ arg_types[num_param++] = LLVMTypeOf(derivs->ddx[i]); ++ arg_types[num_param++] = LLVMTypeOf(derivs->ddy[i]); ++ assert(LLVMTypeOf(derivs->ddx[0]) == LLVMTypeOf(derivs->ddx[i])); ++ assert(LLVMTypeOf(derivs->ddy[0]) == LLVMTypeOf(derivs->ddy[i])); + } ++ } + +- val_type[0] = val_type[1] = val_type[2] = val_type[3] = ++ val_type[0] = val_type[1] = val_type[2] = val_type[3] = + lp_build_vec_type(gallivm, params->type); +- ret_type = LLVMStructTypeInContext(gallivm->context, val_type, 4, 0); +- function_type = LLVMFunctionType(ret_type, arg_types, num_param, 0); ++ ret_type = LLVMStructTypeInContext(gallivm->context, val_type, 4, 0); ++ LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_param, 0); ++ ++ if(!function) { + function = LLVMAddFunction(module, func_name, function_type); + + for (i = 0; i < num_param; ++i) { +@@ -4232,7 +4233,7 @@ lp_build_sample_soa_func(struct gallivm_state *gallivm, + + assert(num_args <= LP_MAX_TEX_FUNC_ARGS); + +- *tex_ret = LLVMBuildCall(builder, function, args, num_args, ""); ++ *tex_ret = LLVMBuildCall2(builder, function_type, function, args, num_args, ""); + bb = LLVMGetInsertBlock(builder); + inst = LLVMGetLastInstruction(bb); + LLVMSetInstructionCallConv(inst, LLVMFastCallConv); +@@ -4529,8 +4530,8 @@ lp_build_do_atomic_soa(struct gallivm_state *gallivm, + return; + } + +- LLVMValueRef atom_res = lp_build_alloca(gallivm, +- LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), type.length), ""); ++ LLVMTypeRef atom_res_elem_type = LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), type.length); ++ LLVMValueRef atom_res = lp_build_alloca(gallivm, atom_res_elem_type, ""); + + offset = LLVMBuildGEP(gallivm->builder, base_ptr, &offset, 1, ""); + struct lp_build_loop_state loop_state; +@@ -4567,14 +4568,14 @@ lp_build_do_atomic_soa(struct gallivm_state *gallivm, + false); + } + +- LLVMValueRef temp_res = LLVMBuildLoad(gallivm->builder, atom_res, ""); ++ LLVMValueRef temp_res = LLVMBuildLoad2(gallivm->builder, atom_res_elem_type, atom_res, ""); + temp_res = LLVMBuildInsertElement(gallivm->builder, temp_res, data, loop_state.counter, ""); + LLVMBuildStore(gallivm->builder, temp_res, atom_res); + + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, type.length), + NULL, LLVMIntUGE); +- atomic_result[0] = LLVMBuildLoad(gallivm->builder, atom_res, ""); ++ atomic_result[0] = LLVMBuildLoad2(gallivm->builder, atom_res_elem_type, atom_res, ""); + } + + static void +-- +GitLab + + +From c8520c2a8fed749e6c280895748effb589bff79d Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:08:16 +0300 +Subject: [PATCH 18/22] gallivm: use LLVM opaque pointers in lp_bld_struct.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 17 +++++------------ + 1 file changed, 5 insertions(+), 12 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index 067740b5c8853..bd969d4681ae6 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -134,15 +134,7 @@ lp_build_pointer_get(LLVMBuilderRef builder, + LLVMValueRef ptr, + LLVMValueRef index) + { +- LLVMValueRef element_ptr; +- LLVMValueRef res; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); +- res = LLVMBuildLoad(builder, element_ptr, ""); +-#ifdef DEBUG +- lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); +-#endif +- return res; ++ return lp_build_pointer_get_unaligned(builder, ptr, index, 0); + } + + +@@ -157,7 +149,8 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder, + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); + res = LLVMBuildLoad(builder, element_ptr, ""); +- LLVMSetAlignment(res, alignment); ++ if (alignment) ++ LLVMSetAlignment(res, alignment); + #ifdef DEBUG + lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); + #endif +@@ -172,7 +165,7 @@ lp_build_pointer_set(LLVMBuilderRef builder, + LLVMValueRef value) + { + LLVMValueRef element_ptr; +- element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); ++ element_ptr = LLVMBuildGEP2(builder, LLVMTypeOf(value), ptr, &index, 1, ""); + LLVMBuildStore(builder, value, element_ptr); + } + +@@ -186,7 +179,7 @@ lp_build_pointer_set_unaligned(LLVMBuilderRef builder, + { + LLVMValueRef element_ptr; + LLVMValueRef instr; +- element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); ++ element_ptr = LLVMBuildGEP2(builder, LLVMTypeOf(value), ptr, &index, 1, ""); + instr = LLVMBuildStore(builder, value, element_ptr); + LLVMSetAlignment(instr, alignment); + } +-- +GitLab + + +From 32a55651cf4ecb830801acafe6410df3f66afca9 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:09:40 +0300 +Subject: [PATCH 19/22] gallivm: use LLVM opaque pointers in lp_bld_tgsi_soa.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + .../auxiliary/gallivm/lp_bld_tgsi_soa.c | 82 ++++++++++--------- + 1 file changed, 42 insertions(+), 40 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +index afaf35e5b11b7..262fa533b3a29 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +@@ -597,9 +597,10 @@ build_gather(struct lp_build_tgsi_context *bld_base, + index = LLVMBuildExtractElement(builder, + indexes, si, ""); + } +- scalar_ptr = LLVMBuildGEP(builder, base_ptr, ++ LLVMTypeRef scalar_type = LLVMGetElementType(LLVMTypeOf(res)); ++ scalar_ptr = LLVMBuildGEP2(builder, scalar_type, base_ptr, + &index, 1, "gather_ptr"); +- scalar = LLVMBuildLoad(builder, scalar_ptr, ""); ++ scalar = LLVMBuildLoad2(builder, scalar_type, scalar_ptr, ""); + + res = LLVMBuildInsertElement(builder, res, scalar, di, ""); + } +@@ -640,8 +641,8 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld, + for (i = 0; i < bld->bld_base.base.type.length; i++) { + LLVMValueRef ii = lp_build_const_int32(gallivm, i); + LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, ""); +- LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr"); + LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val"); ++ LLVMValueRef scalar_ptr = LLVMBuildGEP2(builder, LLVMTypeOf(val), base_ptr, &index, 1, "scatter_ptr"); + LLVMValueRef scalar_pred = pred ? + LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL; + +@@ -651,7 +652,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld, + + if (scalar_pred) { + LLVMValueRef real_val, dst_val; +- dst_val = LLVMBuildLoad(builder, scalar_ptr, ""); ++ dst_val = LLVMBuildLoad2(builder, LLVMTypeOf(val), scalar_ptr, ""); + real_val = lp_build_select(&bld->elem_bld, scalar_pred, val, dst_val); + LLVMBuildStore(builder, real_val, scalar_ptr); + } +@@ -690,7 +691,7 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld, + assert(swizzle < 4); + switch (indirect_reg->File) { + case TGSI_FILE_ADDRESS: +- rel = LLVMBuildLoad(builder, ++ rel = LLVMBuildLoad2(builder, bld->bld_base.base.int_elem_type, + bld->addr[indirect_reg->Index][swizzle], + "load addr reg"); + /* ADDR LLVM values already have LLVM integer type. */ +@@ -890,23 +891,23 @@ emit_fetch_constant( + res = LLVMBuildInsertElement(builder, res, scalar, shuffles[0], ""); + res = LLVMBuildInsertElement(builder, res, scalar2, shuffles[1], ""); + } else { ++ LLVMTypeRef scalar_type = NULL; + if (stype == TGSI_TYPE_DOUBLE) { +- LLVMTypeRef dptr_type = LLVMPointerType(LLVMDoubleTypeInContext(gallivm->context), 0); +- scalar_ptr = LLVMBuildBitCast(builder, scalar_ptr, dptr_type, ""); ++ scalar_type = LLVMPointerType(LLVMDoubleTypeInContext(gallivm->context), 0); ++ scalar_ptr = LLVMBuildBitCast(builder, scalar_ptr, scalar_type, ""); + bld_broad = &bld_base->dbl_bld; + } else if (stype == TGSI_TYPE_UNSIGNED64) { +- LLVMTypeRef u64ptr_type = LLVMPointerType(LLVMInt64TypeInContext(gallivm->context), 0); +- scalar_ptr = LLVMBuildBitCast(builder, scalar_ptr, u64ptr_type, ""); ++ scalar_type = LLVMPointerType(LLVMInt64TypeInContext(gallivm->context), 0); ++ scalar_ptr = LLVMBuildBitCast(builder, scalar_ptr, scalar_type, ""); + bld_broad = &bld_base->uint64_bld; + } else if (stype == TGSI_TYPE_SIGNED64) { +- LLVMTypeRef i64ptr_type = LLVMPointerType(LLVMInt64TypeInContext(gallivm->context), 0); +- scalar_ptr = LLVMBuildBitCast(builder, scalar_ptr, i64ptr_type, ""); ++ scalar_type = LLVMPointerType(LLVMInt64TypeInContext(gallivm->context), 0); ++ scalar_ptr = LLVMBuildBitCast(builder, scalar_ptr, scalar_type, ""); + bld_broad = &bld_base->int64_bld; + } +- scalar = LLVMBuildLoad(builder, scalar_ptr, ""); ++ scalar = LLVMBuildLoad2(builder, scalar_type, scalar_ptr, ""); + res = lp_build_broadcast_scalar(bld_broad, scalar); + } +- + } + + if (stype == TGSI_TYPE_SIGNED || stype == TGSI_TYPE_UNSIGNED || stype == TGSI_TYPE_DOUBLE || stype == TGSI_TYPE_SIGNED64 || stype == TGSI_TYPE_UNSIGNED64) { +@@ -1003,7 +1004,7 @@ emit_fetch_immediate( + gep[1] = lp_build_const_int32(gallivm, reg->Register.Index * 4 + swizzle); + LLVMValueRef imms_ptr = LLVMBuildGEP(builder, + bld->imms_array, gep, 2, ""); +- res = LLVMBuildLoad(builder, imms_ptr, ""); ++ res = LLVMBuildLoad2(builder, bld_base->base.vec_type, imms_ptr, ""); + + if (tgsi_type_is_64bit(stype)) { + LLVMValueRef imms_ptr2; +@@ -1012,7 +1013,7 @@ emit_fetch_immediate( + reg->Register.Index * 4 + (swizzle_in >> 16)); + imms_ptr2 = LLVMBuildGEP(builder, + bld->imms_array, gep, 2, ""); +- res2 = LLVMBuildLoad(builder, imms_ptr2, ""); ++ res2 = LLVMBuildLoad2(builder, bld_base->base.vec_type, imms_ptr2, ""); + res = emit_fetch_64bit(bld_base, stype, res, res2); + } + } +@@ -1076,10 +1077,10 @@ emit_fetch_input( + if (bld->indirect_files & (1 << TGSI_FILE_INPUT)) { + LLVMValueRef lindex = lp_build_const_int32(gallivm, + reg->Register.Index * 4 + swizzle); +- LLVMValueRef input_ptr = LLVMBuildGEP(builder, ++ LLVMValueRef input_ptr = LLVMBuildGEP2(builder, bld_base->base.vec_type, + bld->inputs_array, &lindex, 1, ""); + +- res = LLVMBuildLoad(builder, input_ptr, ""); ++ res = LLVMBuildLoad2(builder, bld_base->base.vec_type, input_ptr, ""); + if (tgsi_type_is_64bit(stype)) { + LLVMValueRef lindex1; + LLVMValueRef input_ptr2; +@@ -1087,9 +1088,9 @@ emit_fetch_input( + + lindex1 = lp_build_const_int32(gallivm, + reg->Register.Index * 4 + (swizzle_in >> 16)); +- input_ptr2 = LLVMBuildGEP(builder, ++ input_ptr2 = LLVMBuildGEP2(builder, bld_base->base.vec_type, + bld->inputs_array, &lindex1, 1, ""); +- res2 = LLVMBuildLoad(builder, input_ptr2, ""); ++ res2 = LLVMBuildLoad2(builder, bld_base->base.vec_type, input_ptr2, ""); + res = emit_fetch_64bit(bld_base, stype, res, res2); + } + } +@@ -1444,13 +1445,13 @@ emit_fetch_temporary( + else { + LLVMValueRef temp_ptr; + temp_ptr = lp_get_temp_ptr_soa(bld, reg->Register.Index, swizzle); +- res = LLVMBuildLoad(builder, temp_ptr, ""); ++ res = LLVMBuildLoad2(builder, bld->bld_base.base.vec_type, temp_ptr, ""); + + if (tgsi_type_is_64bit(stype)) { + LLVMValueRef temp_ptr2, res2; + + temp_ptr2 = lp_get_temp_ptr_soa(bld, reg->Register.Index, swizzle_in >> 16); +- res2 = LLVMBuildLoad(builder, temp_ptr2, ""); ++ res2 = LLVMBuildLoad2(builder, bld->bld_base.base.vec_type, temp_ptr2, ""); + res = emit_fetch_64bit(bld_base, stype, res, res2); + } + } +@@ -3539,17 +3540,17 @@ load_emit( + lp_build_if(&ifthen, gallivm, cond); + scalar = lp_build_pointer_get(builder, scalar_ptr, loop_index); + +- temp_res = LLVMBuildLoad(builder, result, ""); ++ temp_res = LLVMBuildLoad2(builder, uint_bld->vec_type, result, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, scalar, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result); + lp_build_else(&ifthen); +- temp_res = LLVMBuildLoad(builder, result, ""); ++ temp_res = LLVMBuildLoad2(builder, uint_bld->vec_type, result, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, lp_build_const_int32(gallivm, 0), loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, result); + lp_build_endif(&ifthen); + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); +- emit_data->output[chan_index] = LLVMBuildLoad(gallivm->builder, result, ""); ++ emit_data->output[chan_index] = LLVMBuildLoad2(gallivm->builder, uint_bld->vec_type, result, ""); + } + } + } +@@ -3875,18 +3876,18 @@ atomic_emit( + LLVMAtomicOrderingSequentiallyConsistent, + false); + } +- temp_res = LLVMBuildLoad(builder, atom_res, ""); ++ temp_res = LLVMBuildLoad2(builder, uint_bld->vec_type, atom_res, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, scalar, loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, atom_res); + lp_build_else(&ifthen); +- temp_res = LLVMBuildLoad(builder, atom_res, ""); ++ temp_res = LLVMBuildLoad2(builder, uint_bld->vec_type, atom_res, ""); + temp_res = LLVMBuildInsertElement(builder, temp_res, lp_build_const_int32(gallivm, 0), loop_state.counter, ""); + LLVMBuildStore(builder, temp_res, atom_res); + lp_build_endif(&ifthen); + + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), + NULL, LLVMIntUGE); +- emit_data->output[emit_data->chan] = LLVMBuildLoad(gallivm->builder, atom_res, ""); ++ emit_data->output[emit_data->chan] = LLVMBuildLoad2(gallivm->builder, uint_bld->vec_type, atom_res, ""); + } + } + +@@ -3921,7 +3922,7 @@ increment_vec_ptr_by_mask(struct lp_build_tgsi_context * bld_base, + LLVMValueRef mask) + { + LLVMBuilderRef builder = bld_base->base.gallivm->builder; +- LLVMValueRef current_vec = LLVMBuildLoad(builder, ptr, ""); ++ LLVMValueRef current_vec = LLVMBuildLoad2(builder, LLVMTypeOf(mask), ptr, ""); + + current_vec = LLVMBuildSub(builder, current_vec, mask, ""); + +@@ -3934,7 +3935,7 @@ clear_uint_vec_ptr_from_mask(struct lp_build_tgsi_context * bld_base, + LLVMValueRef mask) + { + LLVMBuilderRef builder = bld_base->base.gallivm->builder; +- LLVMValueRef current_vec = LLVMBuildLoad(builder, ptr, ""); ++ LLVMValueRef current_vec = LLVMBuildLoad2(builder, LLVMTypeOf(mask), ptr, ""); + + current_vec = lp_build_select(&bld_base->uint_bld, + mask, +@@ -3973,7 +3974,7 @@ emit_vertex( + emit_data->inst->Src[0].Register.SwizzleX); + LLVMValueRef mask = mask_vec(bld_base); + LLVMValueRef total_emitted_vertices_vec = +- LLVMBuildLoad(builder, bld->total_emitted_vertices_vec_ptr, ""); ++ LLVMBuildLoad2(builder, LLVMTypeOf(mask), bld->total_emitted_vertices_vec_ptr, ""); + + mask = clamp_mask_to_max_output_vertices(bld, mask, + total_emitted_vertices_vec); +@@ -4009,11 +4010,11 @@ end_primitive_masked(struct lp_build_tgsi_context * bld_base, + if (bld->gs_iface->end_primitive) { + struct lp_build_context *uint_bld = &bld_base->uint_bld; + LLVMValueRef emitted_vertices_vec = +- LLVMBuildLoad(builder, bld->emitted_vertices_vec_ptr, ""); ++ LLVMBuildLoad2(builder, uint_bld->vec_type, bld->emitted_vertices_vec_ptr, ""); + LLVMValueRef emitted_prims_vec = +- LLVMBuildLoad(builder, bld->emitted_prims_vec_ptr, ""); ++ LLVMBuildLoad2(builder, uint_bld->vec_type, bld->emitted_prims_vec_ptr, ""); + LLVMValueRef total_emitted_vertices_vec = +- LLVMBuildLoad(builder, bld->total_emitted_vertices_vec_ptr, ""); ++ LLVMBuildLoad2(builder, uint_bld->vec_type, bld->total_emitted_vertices_vec_ptr, ""); + LLVMValueRef emitted_mask = lp_build_cmp(uint_bld, PIPE_FUNC_NOTEQUAL, + emitted_vertices_vec, + uint_bld->zero); +@@ -4048,7 +4049,7 @@ end_primitive_masked(struct lp_build_tgsi_context * bld_base, + #if DUMP_GS_EMITS + lp_build_print_value(bld->bld_base.base.gallivm, + " +++ end prim emitted verts2 = ", +- LLVMBuildLoad(builder, ++ LLVMBuildLoad2(builder, uint_bld->vec_type, + bld->emitted_vertices_vec_ptr, "")); + #endif + } +@@ -4312,14 +4313,15 @@ static void emit_prologue(struct lp_build_tgsi_context * bld_base) + + for (index = 0; index < bld_base->info->num_inputs; ++index) { + for (chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) { +- LLVMValueRef lindex = +- lp_build_const_int32(gallivm, index * 4 + chan); +- LLVMValueRef input_ptr = +- LLVMBuildGEP(gallivm->builder, bld->inputs_array, +- &lindex, 1, ""); + LLVMValueRef value = bld->inputs[index][chan]; +- if (value) ++ if (value) { ++ LLVMValueRef lindex = ++ lp_build_const_int32(gallivm, index * 4 + chan); ++ LLVMValueRef input_ptr = ++ LLVMBuildGEP2(gallivm->builder, LLVMTypeOf(value), bld->inputs_array, ++ &lindex, 1, ""); + LLVMBuildStore(gallivm->builder, value, input_ptr); ++ } + } + } + } +-- +GitLab + + +From 051f588bfef33169db2162ecf4a0e7d5e063100f Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:10:19 +0300 +Subject: [PATCH 20/22] gallivm: use LLVM opaque pointers in lp_bld_tgsi_aos.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c +index 85b2e8a207ea6..d04b84700c78e 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c +@@ -206,7 +206,8 @@ emit_fetch_temporary( + struct lp_build_tgsi_aos_context * bld = lp_aos_context(bld_base); + LLVMBuilderRef builder = bld_base->base.gallivm->builder; + LLVMValueRef temp_ptr = bld->temps[reg->Register.Index]; +- LLVMValueRef res = LLVMBuildLoad(builder, temp_ptr, ""); ++ LLVMTypeRef vec_type = lp_build_vec_type(bld->bld_base.base.gallivm, bld->bld_base.base.type); ++ LLVMValueRef res = LLVMBuildLoad2(builder, vec_type, temp_ptr, ""); + assert(!reg->Register.Indirect); + if (!res) + return bld->bld_base.base.undef; +@@ -286,8 +287,8 @@ lp_emit_store_aos( + + if (mask) { + LLVMValueRef orig_value; +- +- orig_value = LLVMBuildLoad(builder, ptr, ""); ++ LLVMTypeRef vec_type = lp_build_vec_type(bld->bld_base.base.gallivm, bld->bld_base.base.type); ++ orig_value = LLVMBuildLoad2(builder, vec_type, ptr, ""); + value = lp_build_select(&bld->bld_base.base, + mask, value, orig_value); + } +-- +GitLab + + +From ccbee20f6b4d84240865caa6c4eabcbc6091f0f6 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 2 May 2022 16:11:07 +0300 +Subject: [PATCH 21/22] gallivm: LLVM opaque pointers small changes +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c | 2 +- + src/gallium/auxiliary/gallivm/lp_bld_ir_common.c | 6 +++--- + src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c | 2 +- + 3 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c +index 7d106195d0a56..bc0bd4f4831ae 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c +@@ -80,7 +80,7 @@ lp_build_fetch_rgba_aos_array(struct gallivm_state *gallivm, + */ + ptr = LLVMBuildGEP(builder, base_ptr, &offset, 1, ""); + ptr = LLVMBuildPointerCast(builder, ptr, LLVMPointerType(src_vec_type, 0), ""); +- res = LLVMBuildLoad(builder, ptr, ""); ++ res = LLVMBuildLoad2(builder, src_vec_type, ptr, ""); + LLVMSetAlignment(res, src_type.width / 8); + + /* Truncate doubles to float */ +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c b/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c +index cecc8abc31b88..d127ea0c7ff84 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c +@@ -215,7 +215,7 @@ void lp_exec_mask_store(struct lp_exec_mask *mask, + if (exec_mask) { + LLVMValueRef res, dst; + +- dst = LLVMBuildLoad(builder, dst_ptr, ""); ++ dst = LLVMBuildLoad2(builder, LLVMTypeOf(val), dst_ptr, ""); + if (bld_store->type.width < 32) + exec_mask = LLVMBuildTrunc(builder, exec_mask, bld_store->vec_type, ""); + res = lp_build_select(bld_store, exec_mask, val, dst); +@@ -230,7 +230,7 @@ void lp_exec_bgnloop_post_phi(struct lp_exec_mask *mask) + struct function_ctx *ctx = func_ctx(mask); + + if (ctx->loop_stack_size != ctx->bgnloop_stack_size) { +- mask->break_mask = LLVMBuildLoad(builder, ctx->break_var, ""); ++ mask->break_mask = LLVMBuildLoad2(builder, mask->int_vec_type, ctx->break_var, ""); + lp_exec_mask_update(mask); + ctx->bgnloop_stack_size = ctx->loop_stack_size; + } +@@ -303,7 +303,7 @@ void lp_exec_endloop(struct gallivm_state *gallivm, + LLVMBuildStore(builder, mask->break_mask, ctx->break_var); + + /* Decrement the loop limiter */ +- limiter = LLVMBuildLoad(builder, ctx->loop_limiter, ""); ++ limiter = LLVMBuildLoad2(builder, int_type, ctx->loop_limiter, ""); + + limiter = LLVMBuildSub( + builder, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c +index 0564b156d97cb..b0a9f48e8e016 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c +@@ -1191,7 +1191,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld, + lp_build_endif(&if_ctx); + } + +- packed = LLVMBuildLoad(builder, packed_var, ""); ++ packed = LLVMBuildLoad2(builder, u8n_bld.vec_type, packed_var, ""); + + /* + * Convert to SoA and swizzle. +-- +GitLab + + +From ae6d32c938fc79ff5019806a2592097ca97bd945 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Wed, 20 Apr 2022 14:30:30 +0300 +Subject: [PATCH 22/22] gallium: refactor a channel loop in draw_llvm.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Acked-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893> +--- + src/gallium/auxiliary/draw/draw_llvm.c | 36 ++++++++++---------------- + 1 file changed, 13 insertions(+), 23 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c +index 1f68170d99e03..ee4ff8178a8a5 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.c ++++ b/src/gallium/auxiliary/draw/draw_llvm.c +@@ -1651,29 +1651,19 @@ generate_clipmask(struct draw_llvm *llvm, + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, plane_idx); + +- indices[2] = lp_build_const_int32(gallivm, 0); +- plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_x"); +- planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); +- sum = LLVMBuildFMul(builder, planes, cv_x, ""); +- +- indices[2] = lp_build_const_int32(gallivm, 1); +- plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_y"); +- planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); +- sum = lp_build_fmuladd(builder, planes, cv_y, sum); +- +- indices[2] = lp_build_const_int32(gallivm, 2); +- plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_z"); +- planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); +- sum = lp_build_fmuladd(builder, planes, cv_z, sum); +- +- indices[2] = lp_build_const_int32(gallivm, 3); +- plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); +- plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_w"); +- planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); +- sum = lp_build_fmuladd(builder, planes, cv_w, sum); ++ for (int i = 0; i < 4; ++i) { ++ indices[2] = lp_build_const_int32(gallivm, i); ++ plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); ++ plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, ++ (const char *[]){"plane_x", "plane_y", "plane_z", "plane_w"}[i]); ++ planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1); ++ if (i == 0) { ++ sum = LLVMBuildFMul(builder, planes, cv_x, ""); ++ } else { ++ sum = lp_build_fmuladd(builder, planes, ++ (LLVMValueRef[]){cv_x, cv_y, cv_z, cv_w}[i], sum); ++ } ++ } + + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, sum); + temp = lp_build_const_int_vec(gallivm, i32_type, 1LL << plane_idx); +-- +GitLab + +From b549394992553330f191b589b32a30a1f6fb792f Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Thu, 30 Jun 2022 09:14:02 +0300 +Subject: [PATCH 1/4] gallivm: fix a few llvm non-opaque pointers +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +As LLVM 15 transitions to opaque pointers, we need to update +the deprecated methods dealing with non-opaque pointers. + +Reviewed-by: Brian Paul <brianp@vmware.com> +Acked-by: Marek Olšák <marek.olsak@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17650> +--- + src/gallium/auxiliary/gallivm/lp_bld_coro.c | 2 +- + src/gallium/auxiliary/gallivm/lp_bld_format.c | 10 ++++++---- + src/gallium/auxiliary/gallivm/lp_bld_format.h | 2 ++ + .../auxiliary/gallivm/lp_bld_format_aos_array.c | 3 ++- + src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c | 12 +++++++----- + 5 files changed, 18 insertions(+), 11 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_coro.c b/src/gallium/auxiliary/gallivm/lp_bld_coro.c +index a423f60d939a6..0214dcf674203 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_coro.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_coro.c +@@ -206,7 +206,7 @@ LLVMValueRef lp_build_coro_alloc_mem_array(struct gallivm_state *gallivm, + LLVMValueRef coro_num_hdls) + { + LLVMTypeRef mem_ptr_type = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0); +- LLVMValueRef alloced_ptr = LLVMBuildLoad(gallivm->builder, coro_hdl_ptr, ""); ++ LLVMValueRef alloced_ptr = LLVMBuildLoad2(gallivm->builder, mem_ptr_type, coro_hdl_ptr, ""); + + LLVMValueRef not_alloced = LLVMBuildICmp(gallivm->builder, LLVMIntEQ, alloced_ptr, LLVMConstNull(mem_ptr_type), ""); + LLVMValueRef coro_size = lp_build_coro_size(gallivm); +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.c b/src/gallium/auxiliary/gallivm/lp_bld_format.c +index a82fd8feee815..d26485eb4973a 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format.c +@@ -28,7 +28,10 @@ + + #include "lp_bld_format.h" + +- ++LLVMTypeRef lp_build_format_cache_member_data_type(struct gallivm_state *gallivm) ++{ ++ return LLVMArrayType(LLVMInt32TypeInContext(gallivm->context), LP_BUILD_FORMAT_CACHE_SIZE * 16); ++} + + LLVMTypeRef + lp_build_format_cache_type(struct gallivm_state *gallivm) +@@ -36,9 +39,8 @@ lp_build_format_cache_type(struct gallivm_state *gallivm) + LLVMTypeRef elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_COUNT]; + LLVMTypeRef s; + +- elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_DATA] = +- LLVMArrayType(LLVMInt32TypeInContext(gallivm->context), +- LP_BUILD_FORMAT_CACHE_SIZE * 16); ++ elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_DATA] = lp_build_format_cache_member_data_type(gallivm); ++ + elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_TAGS] = + LLVMArrayType(LLVMInt64TypeInContext(gallivm->context), + LP_BUILD_FORMAT_CACHE_SIZE); +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.h b/src/gallium/auxiliary/gallivm/lp_bld_format.h +index 425b2f572f515..0ed1dca38864c 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format.h +@@ -82,6 +82,8 @@ enum { + LLVMTypeRef + lp_build_format_cache_type(struct gallivm_state *gallivm); + ++LLVMTypeRef ++lp_build_format_cache_member_data_type(struct gallivm_state *gallivm); + + /* + * AoS +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c +index bc0bd4f4831ae..55b5bec53e591 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c +@@ -78,7 +78,8 @@ lp_build_fetch_rgba_aos_array(struct gallivm_state *gallivm, + * (If all callers can guarantee element type alignment, we should + * relax alignment restrictions elsewhere.) + */ +- ptr = LLVMBuildGEP(builder, base_ptr, &offset, 1, ""); ++ LLVMTypeRef byte_type = LLVMInt8TypeInContext(gallivm->context); ++ ptr = LLVMBuildGEP2(builder, byte_type, base_ptr, &offset, 1, ""); + ptr = LLVMBuildPointerCast(builder, ptr, LLVMPointerType(src_vec_type, 0), ""); + res = LLVMBuildLoad2(builder, src_vec_type, ptr, ""); + LLVMSetAlignment(res, src_type.width / 8); +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +index 8f972b840fa66..5d91c779e88d2 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +@@ -1134,14 +1134,15 @@ s3tc_store_cached_block(struct gallivm_state *gallivm, + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_TAGS); + indices[2] = hash_index; +- ptr = LLVMBuildGEP(builder, cache, indices, ARRAY_SIZE(indices), ""); ++ LLVMTypeRef cache_type = lp_build_format_cache_type(gallivm); ++ ptr = LLVMBuildGEP2(builder, cache_type, cache, indices, ARRAY_SIZE(indices), ""); + LLVMBuildStore(builder, tag_value, ptr); + + indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_DATA); + hash_index = LLVMBuildMul(builder, hash_index, lp_build_const_int32(gallivm, 16), ""); + for (count = 0; count < 4; count++) { + indices[2] = hash_index; +- ptr = LLVMBuildGEP(builder, cache, indices, ARRAY_SIZE(indices), ""); ++ ptr = LLVMBuildGEP2(builder, cache_type, cache, indices, ARRAY_SIZE(indices), ""); + ptr = LLVMBuildBitCast(builder, ptr, type_ptr4x32, ""); + LLVMBuildStore(builder, col[count], ptr); + hash_index = LLVMBuildAdd(builder, hash_index, lp_build_const_int32(gallivm, 4), ""); +@@ -1150,7 +1151,7 @@ s3tc_store_cached_block(struct gallivm_state *gallivm, + + static LLVMValueRef + s3tc_lookup_cached_pixel(struct gallivm_state *gallivm, +- LLVMValueRef ptr, ++ LLVMValueRef cache, + LLVMValueRef index) + { + LLVMBuilderRef builder = gallivm->builder; +@@ -1159,8 +1160,9 @@ s3tc_lookup_cached_pixel(struct gallivm_state *gallivm, + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_DATA); + indices[2] = index; +- member_ptr = LLVMBuildGEP(builder, ptr, indices, ARRAY_SIZE(indices), ""); +- return LLVMBuildLoad(builder, member_ptr, "cache_data"); ++ member_ptr = LLVMBuildGEP2(builder, lp_build_format_cache_type(gallivm), cache, indices, ARRAY_SIZE(indices), ""); ++ ++ return LLVMBuildLoad2(builder, lp_build_format_cache_member_data_type(gallivm), member_ptr, "cache_data"); + } + + static LLVMValueRef +-- +GitLab + + +From 8c4aef2abb9170c1f5590a7921383345b4626b1d Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Fri, 1 Jul 2022 12:52:25 +0300 +Subject: [PATCH 2/4] gallivm: refactor a bit the cache access in view of LLVM + opaque pointers +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +LLVM 15 requires transition to opaque pointers; factorize a bit the cache +memthods to help this transition. + +Reviewed-by: Brian Paul <brianp@vmware.com> +Acked-by: Marek Olšák <marek.olsak@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17650> +--- + src/gallium/auxiliary/gallivm/lp_bld_format.c | 30 +++++++++++---- + src/gallium/auxiliary/gallivm/lp_bld_format.h | 7 +++- + .../auxiliary/gallivm/lp_bld_format_s3tc.c | 38 ++++++++++--------- + 3 files changed, 49 insertions(+), 26 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.c b/src/gallium/auxiliary/gallivm/lp_bld_format.c +index d26485eb4973a..796277feee702 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format.c +@@ -28,9 +28,24 @@ + + #include "lp_bld_format.h" + +-LLVMTypeRef lp_build_format_cache_member_data_type(struct gallivm_state *gallivm) +-{ +- return LLVMArrayType(LLVMInt32TypeInContext(gallivm->context), LP_BUILD_FORMAT_CACHE_SIZE * 16); ++LLVMTypeRef lp_build_format_cache_elem_type(struct gallivm_state *gallivm, enum cache_member member) { ++ assert(member == LP_BUILD_FORMAT_CACHE_MEMBER_DATA || member == LP_BUILD_FORMAT_CACHE_MEMBER_TAGS); ++ switch (member) { ++ case LP_BUILD_FORMAT_CACHE_MEMBER_DATA: ++ return LLVMInt32TypeInContext(gallivm->context); ++ case LP_BUILD_FORMAT_CACHE_MEMBER_TAGS: ++ return LLVMInt64TypeInContext(gallivm->context); ++ default: ++ unreachable("lp_build_format_cache_elem_type unhandled member type"); ++ } ++} ++ ++LLVMTypeRef lp_build_format_cache_member_type(struct gallivm_state *gallivm, enum cache_member member) { ++ assert(member == LP_BUILD_FORMAT_CACHE_MEMBER_DATA || member == LP_BUILD_FORMAT_CACHE_MEMBER_TAGS); ++ unsigned elem_count = ++ member == LP_BUILD_FORMAT_CACHE_MEMBER_DATA ? LP_BUILD_FORMAT_CACHE_SIZE * 16 : ++ member == LP_BUILD_FORMAT_CACHE_MEMBER_TAGS ? LP_BUILD_FORMAT_CACHE_SIZE : 0; ++ return LLVMArrayType(lp_build_format_cache_elem_type(gallivm, member), elem_count); + } + + LLVMTypeRef +@@ -39,11 +54,12 @@ lp_build_format_cache_type(struct gallivm_state *gallivm) + LLVMTypeRef elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_COUNT]; + LLVMTypeRef s; + +- elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_DATA] = lp_build_format_cache_member_data_type(gallivm); ++ int members[] = {LP_BUILD_FORMAT_CACHE_MEMBER_DATA, LP_BUILD_FORMAT_CACHE_MEMBER_TAGS}; ++ for (int i = 0; i < ARRAY_SIZE(members); ++i) { ++ int member = members[i]; ++ elem_types[member] = lp_build_format_cache_member_type(gallivm, member); ++ } + +- elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_TAGS] = +- LLVMArrayType(LLVMInt64TypeInContext(gallivm->context), +- LP_BUILD_FORMAT_CACHE_SIZE); + #if LP_BUILD_FORMAT_CACHE_DEBUG + elem_types[LP_BUILD_FORMAT_CACHE_MEMBER_ACCESS_TOTAL] = + LLVMInt64TypeInContext(gallivm->context); +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.h b/src/gallium/auxiliary/gallivm/lp_bld_format.h +index 0ed1dca38864c..74a625dce7292 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format.h +@@ -68,7 +68,7 @@ struct lp_build_format_cache + }; + + +-enum { ++enum cache_member { + LP_BUILD_FORMAT_CACHE_MEMBER_DATA = 0, + LP_BUILD_FORMAT_CACHE_MEMBER_TAGS, + #if LP_BUILD_FORMAT_CACHE_DEBUG +@@ -83,7 +83,10 @@ LLVMTypeRef + lp_build_format_cache_type(struct gallivm_state *gallivm); + + LLVMTypeRef +-lp_build_format_cache_member_data_type(struct gallivm_state *gallivm); ++lp_build_format_cache_member_type(struct gallivm_state *gallivm, enum cache_member member); ++ ++LLVMTypeRef ++lp_build_format_cache_elem_type(struct gallivm_state *gallivm, enum cache_member member); + + /* + * AoS +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +index 5d91c779e88d2..fe44841528cb0 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +@@ -1150,35 +1150,39 @@ s3tc_store_cached_block(struct gallivm_state *gallivm, + } + + static LLVMValueRef +-s3tc_lookup_cached_pixel(struct gallivm_state *gallivm, +- LLVMValueRef cache, +- LLVMValueRef index) +-{ ++lookup_cache_member(struct gallivm_state *gallivm, LLVMValueRef cache, enum cache_member member, LLVMValueRef index) { ++ assert(member == LP_BUILD_FORMAT_CACHE_MEMBER_DATA || member == LP_BUILD_FORMAT_CACHE_MEMBER_TAGS); + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef member_ptr, indices[3]; + + indices[0] = lp_build_const_int32(gallivm, 0); +- indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_DATA); ++ indices[1] = lp_build_const_int32(gallivm, member); + indices[2] = index; +- member_ptr = LLVMBuildGEP2(builder, lp_build_format_cache_type(gallivm), cache, indices, ARRAY_SIZE(indices), ""); + +- return LLVMBuildLoad2(builder, lp_build_format_cache_member_data_type(gallivm), member_ptr, "cache_data"); ++ const char *name = ++ member == LP_BUILD_FORMAT_CACHE_MEMBER_DATA ? "cache_data" : ++ member == LP_BUILD_FORMAT_CACHE_MEMBER_TAGS ? "tag_data" : ""; ++ ++ member_ptr = LLVMBuildGEP2(builder, lp_build_format_cache_type(gallivm), ++ cache, indices, ARRAY_SIZE(indices), "cache_gep"); ++ ++ return LLVMBuildLoad2(builder, lp_build_format_cache_elem_type(gallivm, member), member_ptr, name); ++} ++ ++static LLVMValueRef ++s3tc_lookup_cached_pixel(struct gallivm_state *gallivm, ++ LLVMValueRef cache, ++ LLVMValueRef index) ++{ ++ return lookup_cache_member(gallivm, cache, LP_BUILD_FORMAT_CACHE_MEMBER_DATA, index); + } + + static LLVMValueRef + s3tc_lookup_tag_data(struct gallivm_state *gallivm, +- LLVMValueRef ptr, ++ LLVMValueRef cache, + LLVMValueRef index) + { +- LLVMBuilderRef builder = gallivm->builder; +- LLVMValueRef member_ptr, indices[3]; +- +- indices[0] = lp_build_const_int32(gallivm, 0); +- indices[1] = lp_build_const_int32(gallivm, LP_BUILD_FORMAT_CACHE_MEMBER_TAGS); +- indices[2] = index; +- LLVMTypeRef tag_type = LLVMInt64TypeInContext(gallivm->context); +- member_ptr = LLVMBuildGEP(builder, ptr, indices, ARRAY_SIZE(indices), ""); +- return LLVMBuildLoad2(builder, tag_type, member_ptr, "tag_data"); ++ return lookup_cache_member(gallivm, cache, LP_BUILD_FORMAT_CACHE_MEMBER_TAGS, index); + } + + #if LP_BUILD_FORMAT_CACHE_DEBUG +-- +GitLab + + +From f0fda08739e46dfcb552d4510c387130ee14874d Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 12 Jul 2022 23:21:49 +0300 +Subject: [PATCH 3/4] gallivm: add lp_build_struct_get() variants that take the + LLVM type +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This is needed for LLVM-15 opaque pointers. +The new variants taking the type are named with the suffix "2", using +the same naming pattern LLVM (e.g. LLVMBuildGEP2 vs. LLVMBuildGEP). + +Reviewed-by: Brian Paul <brianp@vmware.com> +Acked-by: Marek Olšák <marek.olsak@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17650> +--- + src/gallium/auxiliary/draw/draw_llvm.c | 165 +++++++++--------- + src/gallium/auxiliary/draw/draw_llvm.h | 145 +++++++-------- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 49 +++++- + src/gallium/auxiliary/gallivm/lp_bld_struct.h | 22 +++ + 4 files changed, 225 insertions(+), 156 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c +index 4f952e0e17c48..4ec2883c2dd0a 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.c ++++ b/src/gallium/auxiliary/draw/draw_llvm.c +@@ -307,37 +307,28 @@ create_jit_image_type(struct gallivm_state *gallivm, const char *struct_name) + * Create LLVM type for struct draw_jit_context + */ + static LLVMTypeRef +-create_jit_context_type(struct gallivm_state *gallivm, +- LLVMTypeRef texture_type, LLVMTypeRef sampler_type, +- LLVMTypeRef image_type, +- const char *struct_name) ++create_jit_context_type(struct gallivm_state *gallivm, const char *struct_name) + { ++ LLVMTypeRef texture_type = create_jit_texture_type(gallivm, "texture"); ++ LLVMTypeRef sampler_type = create_jit_sampler_type(gallivm, "sampler"); ++ LLVMTypeRef image_type = create_jit_image_type(gallivm, "image"); ++ + LLVMTargetDataRef target = gallivm->target; + LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); + LLVMTypeRef int_type = LLVMInt32TypeInContext(gallivm->context); + LLVMTypeRef elem_types[DRAW_JIT_CTX_NUM_FIELDS]; +- LLVMTypeRef context_type; + +- elem_types[0] = LLVMArrayType(LLVMPointerType(float_type, 0), /* vs_constants */ +- LP_MAX_TGSI_CONST_BUFFERS); +- elem_types[1] = LLVMArrayType(int_type, /* num_vs_constants */ +- LP_MAX_TGSI_CONST_BUFFERS); +- elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), +- DRAW_TOTAL_CLIP_PLANES), 0); +- elem_types[3] = LLVMPointerType(float_type, 0); /* viewports */ +- elem_types[4] = LLVMArrayType(texture_type, +- PIPE_MAX_SHADER_SAMPLER_VIEWS); /* textures */ +- elem_types[5] = LLVMArrayType(sampler_type, +- PIPE_MAX_SAMPLERS); /* samplers */ +- elem_types[6] = LLVMArrayType(image_type, +- PIPE_MAX_SHADER_IMAGES); /* images */ +- elem_types[7] = LLVMArrayType(LLVMPointerType(int_type, 0), /* vs_ssbo */ +- LP_MAX_TGSI_SHADER_BUFFERS); +- elem_types[8] = LLVMArrayType(int_type, /* num_vs_ssbos */ +- LP_MAX_TGSI_SHADER_BUFFERS); +- elem_types[9] = LLVMPointerType(float_type, 0); /* aniso table */ +- context_type = LLVMStructTypeInContext(gallivm->context, elem_types, +- ARRAY_SIZE(elem_types), 0); ++ elem_types[DRAW_JIT_CTX_CONSTANTS] = LLVMArrayType(LLVMPointerType(float_type, 0), LP_MAX_TGSI_CONST_BUFFERS); ++ elem_types[DRAW_JIT_CTX_NUM_CONSTANTS] = LLVMArrayType(int_type, LP_MAX_TGSI_CONST_BUFFERS); ++ elem_types[DRAW_JIT_CTX_PLANES] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), DRAW_TOTAL_CLIP_PLANES), 0); ++ elem_types[DRAW_JIT_CTX_VIEWPORT] = LLVMPointerType(float_type, 0); ++ elem_types[DRAW_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type, PIPE_MAX_SHADER_SAMPLER_VIEWS); ++ elem_types[DRAW_JIT_CTX_SAMPLERS] = LLVMArrayType(sampler_type, PIPE_MAX_SAMPLERS); ++ elem_types[DRAW_JIT_CTX_IMAGES] = LLVMArrayType(image_type, PIPE_MAX_SHADER_IMAGES); ++ elem_types[DRAW_JIT_CTX_SSBOS] = LLVMArrayType(LLVMPointerType(int_type, 0), LP_MAX_TGSI_SHADER_BUFFERS); ++ elem_types[DRAW_JIT_CTX_NUM_SSBOS] = LLVMArrayType(int_type, LP_MAX_TGSI_SHADER_BUFFERS); ++ elem_types[DRAW_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(float_type, 0); ++ LLVMTypeRef context_type = LLVMStructTypeInContext(gallivm->context, elem_types, ARRAY_SIZE(elem_types), 0); + + (void) target; /* silence unused var warning for non-debug build */ + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants, +@@ -720,16 +711,9 @@ static void + create_jit_types(struct draw_llvm_variant *variant) + { + struct gallivm_state *gallivm = variant->gallivm; +- LLVMTypeRef texture_type, sampler_type, context_type, image_type; + +- texture_type = create_jit_texture_type(gallivm, "texture"); +- sampler_type = create_jit_sampler_type(gallivm, "sampler"); +- image_type = create_jit_image_type(gallivm, "image"); +- +- context_type = create_jit_context_type(gallivm, texture_type, sampler_type, +- image_type, +- "draw_jit_context"); +- variant->context_ptr_type = LLVMPointerType(context_type, 0); ++ variant->context_type = create_jit_context_type(gallivm, "draw_jit_context"); ++ variant->context_ptr_type = LLVMPointerType(variant->context_type, 0); + + variant->buffer_type = create_jit_dvbuffer_type(gallivm, "draw_vertex_buffer"); + variant->buffer_ptr_type = LLVMPointerType(variant->buffer_type, 0); +@@ -983,13 +967,13 @@ generate_vs(struct draw_llvm_variant *variant, + struct draw_llvm *llvm = variant->llvm; + const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens; + LLVMValueRef consts_ptr = +- draw_jit_context_vs_constants(variant->gallivm, context_ptr); ++ draw_jit_context_vs_constants(variant, context_ptr); + LLVMValueRef num_consts_ptr = +- draw_jit_context_num_vs_constants(variant->gallivm, context_ptr); ++ draw_jit_context_num_vs_constants(variant, context_ptr); + LLVMValueRef ssbos_ptr = +- draw_jit_context_vs_ssbos(variant->gallivm, context_ptr); ++ draw_jit_context_vs_ssbos(variant, context_ptr); + LLVMValueRef num_ssbos_ptr = +- draw_jit_context_num_vs_ssbos(variant->gallivm, context_ptr); ++ draw_jit_context_num_vs_ssbos(variant, context_ptr); + + struct lp_build_tgsi_params params; + memset(¶ms, 0, sizeof(params)); +@@ -1006,7 +990,7 @@ generate_vs(struct draw_llvm_variant *variant, + params.ssbo_ptr = ssbos_ptr; + params.ssbo_sizes_ptr = num_ssbos_ptr; + params.image = draw_image; +- params.aniso_filter_table = draw_jit_context_aniso_filter_table(variant->gallivm, context_ptr); ++ params.aniso_filter_table = draw_jit_context_aniso_filter_table(variant, context_ptr); + + if (llvm->draw->vs.vertex_shader->state.ir.nir && + llvm->draw->vs.vertex_shader->state.type == PIPE_SHADER_IR_NIR) +@@ -1161,13 +1145,14 @@ fetch_vector(struct gallivm_state *gallivm, + + static void + store_aos(struct gallivm_state *gallivm, ++ LLVMTypeRef io_type, + LLVMValueRef io_ptr, + LLVMValueRef index, + LLVMValueRef value) + { + LLVMTypeRef data_ptr_type = LLVMPointerType(lp_build_vec_type(gallivm, lp_float32_vec4_type()), 0); + LLVMBuilderRef builder = gallivm->builder; +- LLVMValueRef data_ptr = draw_jit_header_data(gallivm, io_ptr); ++ LLVMValueRef data_ptr = draw_jit_header_data(gallivm, io_type, io_ptr); + LLVMValueRef indices[3]; + + indices[0] = lp_build_const_int32(gallivm, 0); +@@ -1240,6 +1225,7 @@ adjust_mask(struct gallivm_state *gallivm, + static void + store_aos_array(struct gallivm_state *gallivm, + struct lp_type soa_type, ++ LLVMTypeRef io_type, + LLVMValueRef io_ptr, + LLVMValueRef *indices, + LLVMValueRef* aos, +@@ -1265,7 +1251,7 @@ store_aos_array(struct gallivm_state *gallivm, + } else { + inds[i] = linear_inds[i]; + } +- io_ptrs[i] = LLVMBuildGEP(builder, io_ptr, &inds[i], 1, ""); ++ io_ptrs[i] = LLVMBuildGEP2(builder, io_type, io_ptr, &inds[i], 1, ""); + } + + if (attrib == 0) { +@@ -1289,7 +1275,7 @@ store_aos_array(struct gallivm_state *gallivm, + /* OR with the clipmask */ + cliptmp = LLVMBuildOr(builder, val, clipmask, ""); + for (i = 0; i < vector_length; i++) { +- LLVMValueRef id_ptr = draw_jit_header_id(gallivm, io_ptrs[i]); ++ LLVMValueRef id_ptr = draw_jit_header_id(gallivm, io_type, io_ptrs[i]); + val = LLVMBuildExtractElement(builder, cliptmp, linear_inds[i], ""); + val = adjust_mask(gallivm, val); + #if DEBUG_STORE +@@ -1302,13 +1288,14 @@ store_aos_array(struct gallivm_state *gallivm, + + /* store for each of the n vertices */ + for (i = 0; i < vector_length; i++) { +- store_aos(gallivm, io_ptrs[i], attr_index, aos[i]); ++ store_aos(gallivm, io_type, io_ptrs[i], attr_index, aos[i]); + } + } + + + static void + convert_to_aos(struct gallivm_state *gallivm, ++ LLVMTypeRef io_type, + LLVMValueRef io, + LLVMValueRef *indices, + LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS], +@@ -1367,7 +1354,9 @@ convert_to_aos(struct gallivm_state *gallivm, + + store_aos_array(gallivm, + soa_type, +- io, indices, ++ io_type, ++ io, ++ indices, + aos, + attrib, + num_outputs, +@@ -1386,6 +1375,7 @@ convert_to_aos(struct gallivm_state *gallivm, + static void + store_clip(struct gallivm_state *gallivm, + const struct lp_type vs_type, ++ LLVMTypeRef io_type, + LLVMValueRef io_ptr, + LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS], + int idx) +@@ -1403,7 +1393,7 @@ store_clip(struct gallivm_state *gallivm, + + for (i = 0; i < vs_type.length; i++) { + inds[i] = lp_build_const_int32(gallivm, i); +- io_ptrs[i] = LLVMBuildGEP(builder, io_ptr, &inds[i], 1, ""); ++ io_ptrs[i] = LLVMBuildGEP2(builder, io_type, io_ptr, &inds[i], 1, ""); + } + + soa[0] = LLVMBuildLoad(builder, outputs[idx][0], ""); /*x0 x1 .. xn*/ +@@ -1412,7 +1402,7 @@ store_clip(struct gallivm_state *gallivm, + soa[3] = LLVMBuildLoad(builder, outputs[idx][3], ""); /*w0 w1 .. wn*/ + + for (i = 0; i < vs_type.length; i++) { +- clip_ptrs[i] = draw_jit_header_clip_pos(gallivm, io_ptrs[i]); ++ clip_ptrs[i] = draw_jit_header_clip_pos(gallivm, io_type, io_ptrs[i]); + } + + lp_build_transpose_aos(gallivm, vs_type, soa, soa); +@@ -1451,7 +1441,7 @@ generate_viewport(struct draw_llvm_variant *variant, + LLVMTypeRef vs_type_llvm = lp_build_vec_type(gallivm, vs_type); + LLVMValueRef out3 = LLVMBuildLoad2(builder, vs_type_llvm, outputs[pos][3], ""); /*w0 w1 .. wn*/ + LLVMValueRef const1 = lp_build_const_vec(gallivm, f32_type, 1.0); /*1.0 1.0 1.0 1.0*/ +- LLVMValueRef vp_ptr = draw_jit_context_viewports(gallivm, context_ptr); ++ LLVMValueRef vp_ptr = draw_jit_context_viewports(variant, context_ptr); + + /* We treat pipe_viewport_state as a float array */ + const int scale_index_offset = offsetof(struct pipe_viewport_state, scale) / sizeof(float); +@@ -1504,6 +1494,7 @@ generate_clipmask(struct draw_llvm *llvm, + struct lp_type vs_type, + LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS], + struct draw_llvm_variant_key *key, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + boolean *have_clipdist) + { +@@ -1623,7 +1614,7 @@ generate_clipmask(struct draw_llvm *llvm, + } + + if (clip_user) { +- LLVMValueRef planes_ptr = draw_jit_context_planes(gallivm, context_ptr); ++ LLVMValueRef planes_ptr = draw_jit_context_planes(gallivm, context_type, context_ptr); + LLVMValueRef indices[3]; + LLVMValueRef is_nan_or_inf; + +@@ -1834,7 +1825,8 @@ draw_gs_llvm_emit_vertex(const struct lp_build_gs_iface *gs_base, + do_clamp_vertex_color(gallivm, gs_type, + gs_info, outputs); + } +- convert_to_aos(gallivm, io, indices, ++ convert_to_aos(gallivm, variant->vertex_header_type, ++ io, indices, + outputs, clipmask, + gs_info->num_outputs, gs_type, + FALSE); +@@ -1854,7 +1846,7 @@ draw_gs_llvm_end_primitive(const struct lp_build_gs_iface *gs_base, + struct gallivm_state *gallivm = variant->gallivm; + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef prim_lengts_ptr = +- draw_gs_jit_prim_lengths(variant->gallivm, variant->context_ptr); ++ draw_gs_jit_prim_lengths(variant, variant->context_ptr); + unsigned i; + + LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntNE, mask_vec, lp_build_const_int_vec(gallivm, bld->type, 0), ""); +@@ -1889,9 +1881,9 @@ draw_gs_llvm_epilogue(const struct lp_build_gs_iface *gs_base, + struct gallivm_state *gallivm = variant->gallivm; + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef emitted_verts_ptr = +- draw_gs_jit_emitted_vertices(gallivm, variant->context_ptr); ++ draw_gs_jit_emitted_vertices(variant, variant->context_ptr); + LLVMValueRef emitted_prims_ptr = +- draw_gs_jit_emitted_prims(gallivm, variant->context_ptr); ++ draw_gs_jit_emitted_prims(variant, variant->context_ptr); + LLVMValueRef stream_val = lp_build_const_int32(gallivm, stream); + + emitted_verts_ptr = LLVMBuildGEP(builder, emitted_verts_ptr, &stream_val, 1, ""); +@@ -2097,12 +2089,12 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + if (velem->src_format != PIPE_FORMAT_NONE) { + vbuffer_ptr = LLVMBuildGEP2(builder, variant->buffer_type, vbuffers_ptr, &vb_index, 1, ""); + vb_info = LLVMBuildGEP2(builder, variant->vb_type, vb_ptr, &vb_index, 1, ""); +- vb_stride[j] = draw_jit_vbuffer_stride(gallivm, vb_info); ++ vb_stride[j] = draw_jit_vbuffer_stride(gallivm, variant->vb_type, vb_info); + vb_stride[j] = LLVMBuildZExt(gallivm->builder, vb_stride[j], + LLVMInt32TypeInContext(context), ""); +- vb_buffer_offset = draw_jit_vbuffer_offset(gallivm, vb_info); +- map_ptr[j] = draw_jit_dvbuffer_map(gallivm, vbuffer_ptr); +- buffer_size = draw_jit_dvbuffer_size(gallivm, vbuffer_ptr); ++ vb_buffer_offset = draw_jit_vbuffer_offset(gallivm, variant->vb_type, vb_info); ++ map_ptr[j] = draw_jit_dvbuffer_map(gallivm, variant->buffer_type, vbuffer_ptr); ++ buffer_size = draw_jit_dvbuffer_size(gallivm, variant->buffer_type, vbuffer_ptr); + + ofbit = NULL; + /* +@@ -2317,7 +2309,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + lp_build_mask_end(&mask); + if (pos != -1 && cv != -1) { + /* store original positions in clip before further manipulation */ +- store_clip(gallivm, vs_type, io, outputs, pos); ++ store_clip(gallivm, vs_type, variant->vertex_header_type, io, outputs, pos); + + /* do cliptest */ + if (enable_cliptest) { +@@ -2328,6 +2320,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + vs_type, + outputs, + key, ++ variant->context_type, + context_ptr, &have_clipdist); + temp = LLVMBuildOr(builder, clipmask, temp, ""); + /* store temporary clipping boolean value */ +@@ -2350,7 +2343,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) + * original positions in clip + * and transformed positions in data + */ +- convert_to_aos(gallivm, io, NULL, outputs, clipmask, ++ convert_to_aos(gallivm, variant->vertex_header_type, io, NULL, outputs, clipmask, + vs_info->num_outputs, vs_type, + enable_cliptest && key->need_edgeflags); + } +@@ -2695,18 +2688,18 @@ static void + create_gs_jit_types(struct draw_gs_llvm_variant *var) + { + struct gallivm_state *gallivm = var->gallivm; +- LLVMTypeRef texture_type, sampler_type, image_type, context_type; ++ LLVMTypeRef texture_type, sampler_type, image_type; + + texture_type = create_jit_texture_type(gallivm, "texture"); + sampler_type = create_jit_sampler_type(gallivm, "sampler"); + image_type = create_jit_image_type(gallivm, "image"); + +- context_type = create_gs_jit_context_type(gallivm, ++ var->context_type = create_gs_jit_context_type(gallivm, + var->shader->base.vector_length, + texture_type, sampler_type, + image_type, + "draw_gs_jit_context"); +- var->context_ptr_type = LLVMPointerType(context_type, 0); ++ var->context_ptr_type = LLVMPointerType(var->context_type, 0); + + var->input_array_type = create_gs_jit_input_type(gallivm); + } +@@ -2850,13 +2843,13 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, + gs_type.width = 32; /* 32-bit float */ + gs_type.length = vector_length; + +- consts_ptr = draw_gs_jit_context_constants(variant->gallivm, context_ptr); ++ consts_ptr = draw_gs_jit_context_constants(variant, context_ptr); + num_consts_ptr = +- draw_gs_jit_context_num_constants(variant->gallivm, context_ptr); ++ draw_gs_jit_context_num_constants(variant, context_ptr); + +- ssbos_ptr = draw_gs_jit_context_ssbos(variant->gallivm, context_ptr); ++ ssbos_ptr = draw_gs_jit_context_ssbos(variant, context_ptr); + num_ssbos_ptr = +- draw_gs_jit_context_num_ssbos(variant->gallivm, context_ptr); ++ draw_gs_jit_context_num_ssbos(variant, context_ptr); + + /* code generated texture sampling */ + sampler = draw_llvm_sampler_soa_create(variant->key.samplers, +@@ -2895,7 +2888,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, + params.ssbo_sizes_ptr = num_ssbos_ptr; + params.image = image; + params.gs_vertex_streams = variant->shader->base.num_vertex_streams; +- params.aniso_filter_table = draw_gs_jit_context_aniso_filter_table(gallivm, context_ptr); ++ params.aniso_filter_table = draw_gs_jit_context_aniso_filter_table(variant, context_ptr); + + if (llvm->draw->gs.geometry_shader->state.type == PIPE_SHADER_IR_TGSI) + lp_build_tgsi_soa(variant->gallivm, +@@ -2926,7 +2919,6 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm, + struct draw_gs_llvm_variant *variant; + struct llvm_geometry_shader *shader = + llvm_geometry_shader(llvm->draw->gs.geometry_shader); +- LLVMTypeRef vertex_header; + char module_name[64]; + unsigned char ir_sha1_cache_key[20]; + struct lp_cached_code cached = { 0 }; +@@ -2963,9 +2955,8 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm, + + create_gs_jit_types(variant); + +- vertex_header = create_jit_vertex_header(variant->gallivm, num_outputs); +- +- variant->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0); ++ variant->vertex_header_type = create_jit_vertex_header(variant->gallivm, num_outputs); ++ variant->vertex_header_ptr_type = LLVMPointerType(variant->vertex_header_type, 0); + + draw_gs_llvm_generate(llvm, variant); + +@@ -3083,20 +3074,20 @@ static void + create_tcs_jit_types(struct draw_tcs_llvm_variant *var) + { + struct gallivm_state *gallivm = var->gallivm; +- LLVMTypeRef texture_type, sampler_type, image_type, context_type; ++ LLVMTypeRef texture_type, sampler_type, image_type; + + texture_type = create_jit_texture_type(gallivm, "texture"); + sampler_type = create_jit_sampler_type(gallivm, "sampler"); + image_type = create_jit_image_type(gallivm, "image"); + +- context_type = create_tcs_jit_context_type(gallivm, ++ var->context_type = create_tcs_jit_context_type(gallivm, + 0, + texture_type, sampler_type, + image_type, + "draw_tcs_jit_context"); + var->input_array_type = create_tcs_jit_input_type(gallivm); + var->output_array_type = create_tcs_jit_output_type(gallivm); +- var->context_ptr_type = LLVMPointerType(context_type, 0); ++ var->context_ptr_type = LLVMPointerType(var->context_type, 0); + } + + static LLVMTypeRef +@@ -3496,13 +3487,13 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, + patch_vertices_in = LLVMGetParam(variant_coro, 4); + view_index = LLVMGetParam(variant_coro, 5); + +- consts_ptr = draw_tcs_jit_context_constants(variant->gallivm, context_ptr); ++ consts_ptr = draw_tcs_jit_context_constants(variant, context_ptr); + num_consts_ptr = +- draw_tcs_jit_context_num_constants(variant->gallivm, context_ptr); ++ draw_tcs_jit_context_num_constants(variant, context_ptr); + +- ssbos_ptr = draw_tcs_jit_context_ssbos(variant->gallivm, context_ptr); ++ ssbos_ptr = draw_tcs_jit_context_ssbos(variant, context_ptr); + num_ssbos_ptr = +- draw_tcs_jit_context_num_ssbos(variant->gallivm, context_ptr); ++ draw_tcs_jit_context_num_ssbos(variant, context_ptr); + sampler = draw_llvm_sampler_soa_create(variant->key.samplers, + MAX2(variant->key.nr_samplers, + variant->key.nr_sampler_views)); +@@ -3559,7 +3550,7 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, + params.image = image; + params.coro = &coro_info; + params.tcs_iface = &tcs_iface.base; +- params.aniso_filter_table = draw_tcs_jit_context_aniso_filter_table(gallivm, context_ptr); ++ params.aniso_filter_table = draw_tcs_jit_context_aniso_filter_table(variant, context_ptr); + + lp_build_nir_soa(variant->gallivm, + llvm->draw->tcs.tess_ctrl_shader->state.ir.nir, +@@ -3745,18 +3736,18 @@ static void + create_tes_jit_types(struct draw_tes_llvm_variant *var) + { + struct gallivm_state *gallivm = var->gallivm; +- LLVMTypeRef texture_type, sampler_type, image_type, context_type; ++ LLVMTypeRef texture_type, sampler_type, image_type; + + texture_type = create_jit_texture_type(gallivm, "texture"); + sampler_type = create_jit_sampler_type(gallivm, "sampler"); + image_type = create_jit_image_type(gallivm, "image"); + +- context_type = create_tes_jit_context_type(gallivm, ++ var->context_type = create_tes_jit_context_type(gallivm, + 0, + texture_type, sampler_type, + image_type, + "draw_tes_jit_context"); +- var->context_ptr_type = LLVMPointerType(context_type, 0); ++ var->context_ptr_type = LLVMPointerType(var->context_type, 0); + + var->input_array_deref_type = create_tes_jit_input_deref_type(gallivm); + var->input_array_type = LLVMPointerType(var->input_array_deref_type, 0); /* num vertices per prim */ +@@ -4013,13 +4004,13 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + tes_type.length = vector_length; + + lp_build_context_init(&bldvec, variant->gallivm, lp_int_type(tes_type)); +- consts_ptr = draw_tes_jit_context_constants(variant->gallivm, context_ptr); ++ consts_ptr = draw_tes_jit_context_constants(variant, context_ptr); + num_consts_ptr = +- draw_tes_jit_context_num_constants(variant->gallivm, context_ptr); ++ draw_tes_jit_context_num_constants(variant, context_ptr); + +- ssbos_ptr = draw_tes_jit_context_ssbos(variant->gallivm, context_ptr); ++ ssbos_ptr = draw_tes_jit_context_ssbos(variant, context_ptr); + num_ssbos_ptr = +- draw_tes_jit_context_num_ssbos(variant->gallivm, context_ptr); ++ draw_tes_jit_context_num_ssbos(variant, context_ptr); + sampler = draw_llvm_sampler_soa_create(variant->key.samplers, + MAX2(variant->key.nr_samplers, + variant->key.nr_sampler_views)); +@@ -4088,7 +4079,7 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + params.ssbo_sizes_ptr = num_ssbos_ptr; + params.image = image; + params.tes_iface = &tes_iface.base; +- params.aniso_filter_table = draw_tes_jit_context_aniso_filter_table(variant->gallivm, context_ptr); ++ params.aniso_filter_table = draw_tes_jit_context_aniso_filter_table(variant, context_ptr); + + lp_build_nir_soa(variant->gallivm, + llvm->draw->tes.tess_eval_shader->state.ir.nir, +@@ -4106,7 +4097,7 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + LLVMValueRef clipmask = lp_build_const_int_vec(gallivm, + lp_int_type(tes_type), 0); + +- convert_to_aos(gallivm, io, NULL, outputs, clipmask, ++ convert_to_aos(gallivm, variant->vertex_header_type, io, NULL, outputs, clipmask, + draw_total_tes_outputs(llvm->draw), tes_type, FALSE); + } + lp_build_loop_end_cond(&lp_loop, num_tess_coord, step, LLVMIntUGE); +diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h +index 50525cbd25b05..3e1946a3144f3 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.h ++++ b/src/gallium/auxiliary/draw/draw_llvm.h +@@ -188,17 +188,17 @@ enum { + DRAW_JIT_CTX_NUM_FIELDS + }; + +-#define draw_jit_context_vs_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants") ++#define draw_jit_context_vs_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants") + +-#define draw_jit_context_num_vs_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants") ++#define draw_jit_context_num_vs_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants") + +-#define draw_jit_context_planes(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes") ++#define draw_jit_context_planes(_gallivm, _type, _ptr) \ ++ lp_build_struct_get2(_gallivm, _type, _ptr, DRAW_JIT_CTX_PLANES, "planes") + +-#define draw_jit_context_viewports(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports") ++#define draw_jit_context_viewports(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports") + + #define draw_jit_context_textures(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures") +@@ -209,31 +209,31 @@ enum { + #define draw_jit_context_images(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images") + +-#define draw_jit_context_vs_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos") ++#define draw_jit_context_vs_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos") + +-#define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos") ++#define draw_jit_context_num_vs_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos") + +-#define draw_jit_context_aniso_filter_table(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") ++#define draw_jit_context_aniso_filter_table(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") + + +-#define draw_jit_header_id(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id") ++#define draw_jit_header_id(_gallivm, _type, _ptr) \ ++ lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id") + +-#define draw_jit_header_clip_pos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos") ++#define draw_jit_header_clip_pos(_gallivm, _type, _ptr) \ ++ lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos") + +-#define draw_jit_header_data(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_DATA, "data") ++#define draw_jit_header_data(_gallivm, _type, _ptr) \ ++ lp_build_struct_get_ptr2(_gallivm, _type, _ptr, DRAW_JIT_VERTEX_DATA, "data") + + +-#define draw_jit_vbuffer_stride(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, 0, "stride") ++#define draw_jit_vbuffer_stride(_gallivm, _type, _ptr) \ ++ lp_build_struct_get2(_gallivm, _type, _ptr, 0, "stride") + +-#define draw_jit_vbuffer_offset(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset") ++#define draw_jit_vbuffer_offset(_gallivm, _type, _ptr) \ ++ lp_build_struct_get2(_gallivm, _type, _ptr, 2, "buffer_offset") + + enum { + DRAW_JIT_DVBUFFER_MAP = 0, +@@ -241,11 +241,11 @@ enum { + DRAW_JIT_DVBUFFER_NUM_FIELDS /* number of fields above */ + }; + +-#define draw_jit_dvbuffer_map(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_MAP, "map") ++#define draw_jit_dvbuffer_map(_gallivm, _type, _ptr) \ ++ lp_build_struct_get2(_gallivm, _type, _ptr, DRAW_JIT_DVBUFFER_MAP, "map") + +-#define draw_jit_dvbuffer_size(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size") ++#define draw_jit_dvbuffer_size(_gallivm, _type, _ptr) \ ++ lp_build_struct_get2(_gallivm, _type, _ptr, DRAW_JIT_DVBUFFER_SIZE, "size") + + + /** +@@ -302,11 +302,11 @@ enum { + DRAW_GS_JIT_CTX_NUM_FIELDS = 13 + }; + +-#define draw_gs_jit_context_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants") ++#define draw_gs_jit_context_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants") + +-#define draw_gs_jit_context_num_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants") ++#define draw_gs_jit_context_num_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants") + + #define draw_gs_jit_context_planes(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes") +@@ -323,23 +323,23 @@ enum { + #define draw_gs_jit_context_images(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images") + +-#define draw_gs_jit_prim_lengths(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths") ++#define draw_gs_jit_prim_lengths(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths") + +-#define draw_gs_jit_emitted_vertices(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices") ++#define draw_gs_jit_emitted_vertices(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_EMITTED_VERTICES, "emitted_vertices") + +-#define draw_gs_jit_emitted_prims(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims") ++#define draw_gs_jit_emitted_prims(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims") + +-#define draw_gs_jit_context_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos") ++#define draw_gs_jit_context_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos") + +-#define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos") ++#define draw_gs_jit_context_num_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos") + +-#define draw_gs_jit_context_aniso_filter_table(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") ++#define draw_gs_jit_context_aniso_filter_table(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") + + struct draw_tcs_jit_context { + const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; +@@ -371,11 +371,11 @@ enum { + DRAW_TCS_JIT_CTX_NUM_FIELDS = 10, + }; + +-#define draw_tcs_jit_context_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants") ++#define draw_tcs_jit_context_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants") + +-#define draw_tcs_jit_context_num_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants") ++#define draw_tcs_jit_context_num_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants") + + #define draw_tcs_jit_context_textures(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures") +@@ -386,14 +386,14 @@ enum { + #define draw_tcs_jit_context_images(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images") + +-#define draw_tcs_jit_context_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos") ++#define draw_tcs_jit_context_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos") + +-#define draw_tcs_jit_context_num_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos") ++#define draw_tcs_jit_context_num_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos") + +-#define draw_tcs_jit_context_aniso_filter_table(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") ++#define draw_tcs_jit_context_aniso_filter_table(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") + + struct draw_tes_jit_context { + const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; +@@ -425,11 +425,11 @@ enum { + DRAW_TES_JIT_CTX_NUM_FIELDS = 10, + }; + +-#define draw_tes_jit_context_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants") ++#define draw_tes_jit_context_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants") + +-#define draw_tes_jit_context_num_constants(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants") ++#define draw_tes_jit_context_num_constants(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants") + + #define draw_tes_jit_context_textures(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures") +@@ -440,14 +440,14 @@ enum { + #define draw_tes_jit_context_images(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images") + +-#define draw_tes_jit_context_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos") ++#define draw_tes_jit_context_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos") + +-#define draw_tes_jit_context_num_ssbos(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos") ++#define draw_tes_jit_context_num_ssbos(_variant, _ptr) \ ++ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos") + +-#define draw_tes_jit_context_aniso_filter_table(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") ++#define draw_tes_jit_context_aniso_filter_table(_variant, _ptr) \ ++ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") + + typedef boolean + (*draw_jit_vert_func)(struct draw_jit_context *context, +@@ -688,14 +688,17 @@ struct draw_llvm_variant + struct gallivm_state *gallivm; + + /* LLVM JIT builder types */ ++ LLVMTypeRef context_type; + LLVMTypeRef context_ptr_type; +- LLVMTypeRef buffer_ptr_type; +- LLVMTypeRef vb_ptr_type; +- LLVMTypeRef vertex_header_ptr_type; + + LLVMTypeRef buffer_type; ++ LLVMTypeRef buffer_ptr_type; ++ + LLVMTypeRef vb_type; ++ LLVMTypeRef vb_ptr_type; ++ + LLVMTypeRef vertex_header_type; ++ LLVMTypeRef vertex_header_ptr_type; + + LLVMValueRef function; + draw_jit_vert_func jit_func; +@@ -716,8 +719,12 @@ struct draw_gs_llvm_variant + struct gallivm_state *gallivm; + + /* LLVM JIT builder types */ ++ LLVMTypeRef context_type; + LLVMTypeRef context_ptr_type; ++ ++ LLVMTypeRef vertex_header_type; + LLVMTypeRef vertex_header_ptr_type; ++ + LLVMTypeRef input_array_type; + + LLVMValueRef context_ptr; +@@ -741,12 +748,13 @@ struct draw_tcs_llvm_variant + struct gallivm_state *gallivm; + + /* LLVM JIT builder types */ ++ LLVMTypeRef context_type; + LLVMTypeRef context_ptr_type; + LLVMTypeRef input_array_type; + LLVMTypeRef output_array_type; + + LLVMValueRef context_ptr; +- LLVMValueRef io_ptr; ++ /* LLVMValueRef io_ptr; */ + LLVMValueRef num_prims; + LLVMValueRef function; + draw_tcs_jit_func jit_func; +@@ -766,6 +774,7 @@ struct draw_tes_llvm_variant + struct gallivm_state *gallivm; + + /* LLVM JIT builder types */ ++ LLVMTypeRef context_type; + LLVMTypeRef context_ptr_type; + LLVMTypeRef vertex_header_ptr_type; + LLVMTypeRef input_array_type; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index bd969d4681ae6..1007090410412 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -51,7 +51,12 @@ lp_build_struct_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef indices[2]; + LLVMValueRef member_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++ ++ /* Starting with LLVM 15, we're not supposed to look at pointer element type anymore. */ ++#if LLVM_VERSION_MAJOR < 15 + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); ++#endif ++ + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, member); + member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, ARRAY_SIZE(indices), ""); +@@ -59,7 +64,6 @@ lp_build_struct_get_ptr(struct gallivm_state *gallivm, + return member_ptr; + } + +- + LLVMValueRef + lp_build_struct_get(struct gallivm_state *gallivm, + LLVMValueRef ptr, +@@ -69,13 +73,56 @@ lp_build_struct_get(struct gallivm_state *gallivm, + LLVMValueRef member_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++#if LLVM_VERSION_MAJOR < 15 + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); ++#endif + member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name); + res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); + lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); + return res; + } + ++LLVMValueRef ++lp_build_struct_get_ptr2(struct gallivm_state *gallivm, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ unsigned member, ++ const char *name) ++{ ++ LLVMValueRef indices[2]; ++ LLVMValueRef member_ptr; ++ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++ ++ /* Starting with LLVM 15, we're not supposed to look at pointer element type anymore. */ ++#if LLVM_VERSION_MAJOR < 15 ++ assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); ++#endif ++ ++ indices[0] = lp_build_const_int32(gallivm, 0); ++ indices[1] = lp_build_const_int32(gallivm, member); ++ member_ptr = LLVMBuildGEP2(gallivm->builder, ptr_type, ptr, indices, ARRAY_SIZE(indices), ""); ++ lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name); ++ return member_ptr; ++} ++ ++LLVMValueRef ++lp_build_struct_get2(struct gallivm_state *gallivm, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ unsigned member, ++ const char *name) ++{ ++ LLVMValueRef member_ptr; ++ LLVMValueRef res; ++ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++#if LLVM_VERSION_MAJOR < 15 ++ assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); ++#endif ++ member_ptr = lp_build_struct_get_ptr2(gallivm, ptr_type, ptr, member, name); ++ res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); ++ lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); ++ return res; ++} + + LLVMValueRef + lp_build_array_get_ptr(struct gallivm_state *gallivm, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +index 6b7b4f2a6bf7d..a87519883b4df 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +@@ -71,6 +71,28 @@ lp_build_struct_get(struct gallivm_state *gallivm, + unsigned member, + const char *name); + ++/** ++ * Get value pointer to a structure member. ++ * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. ++ */ ++LLVMValueRef ++lp_build_struct_get_ptr2(struct gallivm_state *gallivm, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ unsigned member, ++ const char *name); ++ ++/** ++ * Get the value of a structure member. ++ * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. ++ */ ++LLVMValueRef ++lp_build_struct_get2(struct gallivm_state *gallivm, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ unsigned member, ++ const char *name); ++ + /** + * Get value pointer to an array element. + */ +-- +GitLab + + +From da9feae7355c15d489b916340ea2b62f9f8c0a7c Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Sat, 23 Jul 2022 08:45:55 +0300 +Subject: [PATCH 4/4] gallivm: push LLVM version guard into assert + +The asserts that check the pointer element type can't be used on LLVM >= 15. +Instead of using precompiler #if, use boolean shortcut in assert. + +Reviewed-by: Brian Paul <brianp@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17650> +--- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 20 ++++--------------- + 1 file changed, 4 insertions(+), 16 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index 1007090410412..be579c4ee25d7 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -51,11 +51,7 @@ lp_build_struct_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef indices[2]; + LLVMValueRef member_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- +- /* Starting with LLVM 15, we're not supposed to look at pointer element type anymore. */ +-#if LLVM_VERSION_MAJOR < 15 +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); +-#endif ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, member); +@@ -73,9 +69,7 @@ lp_build_struct_get(struct gallivm_state *gallivm, + LLVMValueRef member_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +-#if LLVM_VERSION_MAJOR < 15 +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); +-#endif ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name); + res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); + lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); +@@ -92,11 +86,7 @@ lp_build_struct_get_ptr2(struct gallivm_state *gallivm, + LLVMValueRef indices[2]; + LLVMValueRef member_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- +- /* Starting with LLVM 15, we're not supposed to look at pointer element type anymore. */ +-#if LLVM_VERSION_MAJOR < 15 +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); +-#endif ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, member); +@@ -115,9 +105,7 @@ lp_build_struct_get2(struct gallivm_state *gallivm, + LLVMValueRef member_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +-#if LLVM_VERSION_MAJOR < 15 +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); +-#endif ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + member_ptr = lp_build_struct_get_ptr2(gallivm, ptr_type, ptr, member, name); + res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); + lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); +-- +GitLab + +From adf28955162007af80989b65df641b3c7ae6f78c Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Fri, 19 Aug 2022 11:56:35 +0300 +Subject: [PATCH 1/9] gallivm: LLVM-15 opaque pointers: disable + LLVMGetElementType(ptr_type) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +with opaque pointers, we can't query the element type of a pointer type + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/gallivm/lp_bld_ir_common.c | 5 +++-- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 6 +++--- + src/gallium/auxiliary/gallivm/lp_bld_swizzle.c | 2 +- + 3 files changed, 7 insertions(+), 6 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c b/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c +index d127ea0c7ff84..042cd5c814f27 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_ir_common.c +@@ -209,8 +209,9 @@ void lp_exec_mask_store(struct lp_exec_mask *mask, + + assert(lp_check_value(bld_store->type, val)); + assert(LLVMGetTypeKind(LLVMTypeOf(dst_ptr)) == LLVMPointerTypeKind); +- assert(LLVMGetElementType(LLVMTypeOf(dst_ptr)) == LLVMTypeOf(val) || +- LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(dst_ptr))) == LLVMArrayTypeKind); ++ assert(LLVM_VERSION_MAJOR >= 15 ++ || (LLVMGetElementType(LLVMTypeOf(dst_ptr)) == LLVMTypeOf(val) ++ || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(dst_ptr))) == LLVMArrayTypeKind)); + + if (exec_mask) { + LLVMValueRef res, dst; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index be579c4ee25d7..9e3e24cd9e1e7 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -120,7 +120,7 @@ lp_build_array_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef indices[2]; + LLVMValueRef element_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = index; + element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, ARRAY_SIZE(indices), ""); +@@ -140,7 +140,7 @@ lp_build_array_get(struct gallivm_state *gallivm, + LLVMValueRef element_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); + element_ptr = lp_build_array_get_ptr(gallivm, ptr, index); + res = LLVMBuildLoad(gallivm->builder, element_ptr, ""); + #ifdef DEBUG +@@ -158,7 +158,7 @@ lp_build_array_set(struct gallivm_state *gallivm, + { + LLVMValueRef element_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); + element_ptr = lp_build_array_get_ptr(gallivm, ptr, index); + LLVMBuildStore(gallivm->builder, value, element_ptr); + } +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c +index b23c4cbbf02be..904eaa034d6cb 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c +@@ -63,7 +63,7 @@ lp_build_broadcast(struct gallivm_state *gallivm, + LLVMTypeRef i32_type = LLVMInt32TypeInContext(gallivm->context); + LLVMTypeRef i32_vec_type = LLVMVectorType(i32_type, length); + +- assert(LLVMGetElementType(vec_type) == LLVMTypeOf(scalar)); ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetElementType(vec_type) == LLVMTypeOf(scalar)); + + res = LLVMBuildInsertElement(builder, undef, scalar, LLVMConstNull(i32_type), ""); + res = LLVMBuildShuffleVector(builder, res, undef, LLVMConstNull(i32_vec_type), ""); +-- +GitLab + + +From 3668ebf8bd42bd9c9c9a7b8b5d4537198e5a2b4c Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 16 Aug 2022 09:44:53 +0300 +Subject: [PATCH 2/9] gallivm: drop unused "emit_load" in + lp_llvm_buffer_member() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/gallivm/lp_bld_jit_types.c | 13 ++++++------- + 1 file changed, 6 insertions(+), 7 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +index 6e6c63db9f39b..c4bfa2be899ce 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +@@ -60,8 +60,7 @@ lp_llvm_buffer_member(struct gallivm_state *gallivm, + LLVMValueRef buffers_offset, + unsigned buffers_limit, + unsigned member_index, +- const char *member_name, +- boolean emit_load) ++ const char *member_name) + { + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef indices[3]; +@@ -74,7 +73,7 @@ lp_llvm_buffer_member(struct gallivm_state *gallivm, + LLVMValueRef ptr = + LLVMBuildGEP(builder, buffers_ptr, indices, ARRAY_SIZE(indices), ""); + +- LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; ++ LLVMValueRef res = LLVMBuildLoad(builder, ptr, ""); + + lp_build_name(res, "buffer.%s", member_name); + +@@ -90,7 +89,7 @@ lp_llvm_buffer_member(struct gallivm_state *gallivm, + * sampler code generator a reusable module without dependencies to + * llvmpipe internals. + */ +-#define LP_LLVM_BUFFER_MEMBER(_name, _index, _emit_load) \ ++#define LP_LLVM_BUFFER_MEMBER(_name, _index) \ + LLVMValueRef \ + lp_llvm_buffer_##_name(struct gallivm_state *gallivm, \ + LLVMValueRef buffers_ptr, \ +@@ -98,8 +97,8 @@ lp_llvm_buffer_member(struct gallivm_state *gallivm, + { \ + return lp_llvm_buffer_member(gallivm, buffers_ptr, \ + buffers_offset, buffers_limit, \ +- _index, #_name, _emit_load ); \ ++ _index, #_name); \ + } + +-LP_LLVM_BUFFER_MEMBER(base, LP_JIT_BUFFER_BASE, TRUE) +-LP_LLVM_BUFFER_MEMBER(num_elements, LP_JIT_BUFFER_NUM_ELEMENTS, TRUE) ++LP_LLVM_BUFFER_MEMBER(base, LP_JIT_BUFFER_BASE) ++LP_LLVM_BUFFER_MEMBER(num_elements, LP_JIT_BUFFER_NUM_ELEMENTS) +-- +GitLab + + +From 49c6e2fd70aa2db61e784e41f263c19625ca67ba Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 16 Aug 2022 11:11:24 +0300 +Subject: [PATCH 3/9] gallium: drop unused macros in draw_llvm.h +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The reason is that these macros use lp_build_struct_get(), which is +being replaced by lp_build_structure_get2() which takes the explicit +pointer type. Rather than attempt to update these unused macros, simply drop +them. + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/draw/draw_llvm.h | 42 -------------------------- + 1 file changed, 42 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h +index 37052db3175ba..941591ac7fb7a 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.h ++++ b/src/gallium/auxiliary/draw/draw_llvm.h +@@ -194,15 +194,6 @@ enum { + #define draw_jit_context_viewports(_variant, _ptr) \ + lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_VIEWPORT, "viewports") + +-#define draw_jit_context_textures(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures") +- +-#define draw_jit_context_samplers(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers") +- +-#define draw_jit_context_images(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images") +- + #define draw_jit_context_ssbos(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_SSBOS, "ssbos") + +@@ -292,21 +283,6 @@ enum { + #define draw_gs_jit_context_constants(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants") + +-#define draw_gs_jit_context_planes(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes") +- +-#define draw_gs_jit_context_viewports(_gallivm, _ptr) \ +- lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_VIEWPORT, "viewports") +- +-#define draw_gs_jit_context_textures(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_TEXTURES, "textures") +- +-#define draw_gs_jit_context_samplers(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers") +- +-#define draw_gs_jit_context_images(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images") +- + #define draw_gs_jit_prim_lengths(_variant, _ptr) \ + lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths") + +@@ -353,15 +329,6 @@ enum { + #define draw_tcs_jit_context_constants(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants") + +-#define draw_tcs_jit_context_textures(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures") +- +-#define draw_tcs_jit_context_samplers(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_SAMPLERS, "samplers") +- +-#define draw_tcs_jit_context_images(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_IMAGES, "images") +- + #define draw_tcs_jit_context_ssbos(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos") + +@@ -399,15 +366,6 @@ enum { + #define draw_tes_jit_context_constants(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants") + +-#define draw_tes_jit_context_textures(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures") +- +-#define draw_tes_jit_context_samplers(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_SAMPLERS, "samplers") +- +-#define draw_tes_jit_context_images(_gallivm, _ptr) \ +- lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_IMAGES, "images") +- + #define draw_tes_jit_context_ssbos(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos") + +-- +GitLab + + +From 8289ac87a404ff95759ec2a12012c1eae20419e6 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 26 Jul 2022 15:43:30 +0300 +Subject: [PATCH 4/9] gallivm: fixes for LLVM-15 opaque pointers in + lp_bld_nir_aos.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c | 11 +++++------ + 1 file changed, 5 insertions(+), 6 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c +index c449b5de46c77..226bb5e75cf0f 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c +@@ -172,7 +172,7 @@ emit_load_reg(struct lp_build_nir_context *bld_base, + LLVMValueRef reg_storage) + { + struct gallivm_state *gallivm = bld_base->base.gallivm; +- return LLVMBuildLoad(gallivm->builder, reg_storage, ""); ++ return LLVMBuildLoad2(gallivm->builder, reg_bld->vec_type, reg_storage, ""); + } + + +@@ -195,7 +195,7 @@ emit_store_reg(struct lp_build_nir_context *bld_base, + return; + } + +- LLVMValueRef cur = LLVMBuildLoad(gallivm->builder, reg_storage, ""); ++ LLVMValueRef cur = LLVMBuildLoad2(gallivm->builder, reg_bld->vec_type, reg_storage, ""); + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); + LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; + for (unsigned j = 0; j < 16; j++) { +@@ -238,10 +238,9 @@ emit_load_ubo(struct lp_build_nir_context *bld_base, + LLVMValueRef this_offset = lp_build_const_int32(gallivm, + offset_val + chan); + +- LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr, +- &this_offset, 1, ""); +- +- LLVMValueRef scalar = LLVMBuildLoad(builder, scalar_ptr, ""); ++ LLVMTypeRef scalar_type = LLVMInt8TypeInContext(gallivm->context); ++ LLVMValueRef scalar_ptr = LLVMBuildGEP2(builder, scalar_type, bld->consts_ptr, &this_offset, 1, ""); ++ LLVMValueRef scalar = LLVMBuildLoad2(builder, scalar_type, scalar_ptr, ""); + + lp_build_name(scalar, "const[%u].%c", offset_val, "xyzw"[chan]); + +-- +GitLab + + +From f30251ef9bf20274d49848d614c8bf407bec353b Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 26 Jul 2022 16:02:52 +0300 +Subject: [PATCH 5/9] gallivm: fixes for LLVM-15 opaque pointers in + lp_bld_nir_soa.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + .../auxiliary/gallivm/lp_bld_nir_soa.c | 30 +++++++++---------- + 1 file changed, 15 insertions(+), 15 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +index 94dcace50e33f..90836928adee1 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +@@ -223,6 +223,7 @@ get_soa_array_offsets(struct lp_build_context *uint_bld, + static LLVMValueRef + build_gather(struct lp_build_nir_context *bld_base, + struct lp_build_context *bld, ++ LLVMTypeRef base_type, + LLVMValueRef base_ptr, + LLVMValueRef indexes, + LLVMValueRef overflow_mask, +@@ -284,8 +285,8 @@ build_gather(struct lp_build_nir_context *bld_base, + indexes, si, ""); + } + +- scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "gather_ptr"); +- scalar = LLVMBuildLoad(builder, scalar_ptr, ""); ++ scalar_ptr = LLVMBuildGEP2(builder, base_type, base_ptr, &index, 1, "gather_ptr"); ++ scalar = LLVMBuildLoad2(builder, base_type, scalar_ptr, ""); + + res = LLVMBuildInsertElement(builder, res, scalar, di, ""); + } +@@ -326,7 +327,7 @@ emit_mask_scatter(struct lp_build_nir_soa_context *bld, + LLVMValueRef ii = lp_build_const_int32(gallivm, i); + LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, ""); + LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val"); +- LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr"); ++ LLVMValueRef scalar_ptr = LLVMBuildGEP2(builder, LLVMTypeOf(val), base_ptr, &index, 1, "scatter_ptr"); + LLVMValueRef scalar_pred = pred ? + LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL; + +@@ -468,17 +469,15 @@ static void emit_load_var(struct lp_build_nir_context *bld_base, + attrib_index_val, 4, idx, + TRUE); + LLVMValueRef index_vec2 = NULL; +- LLVMTypeRef fptr_type; +- LLVMValueRef inputs_array; +- fptr_type = LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0); +- inputs_array = LLVMBuildBitCast(gallivm->builder, bld->inputs_array, fptr_type, ""); ++ LLVMTypeRef scalar_type = LLVMFloatTypeInContext(gallivm->context); ++ LLVMValueRef inputs_array = LLVMBuildBitCast(gallivm->builder, bld->inputs_array, LLVMPointerType(scalar_type, 0), ""); + + if (bit_size == 64) + index_vec2 = get_soa_array_offsets(&bld_base->uint_bld, + indir_index, 4, idx + 1, TRUE); + + /* Gather values from the input register array */ +- result[i] = build_gather(bld_base, &bld_base->base, inputs_array, index_vec, NULL, index_vec2); ++ result[i] = build_gather(bld_base, &bld_base->base, scalar_type, inputs_array, index_vec, NULL, index_vec2); + } else { + if (bld->indirects & nir_var_shader_in) { + LLVMValueRef lindex = lp_build_const_int32(gallivm, +@@ -706,13 +705,13 @@ static LLVMValueRef emit_load_reg(struct lp_build_nir_context *bld_base, + reg_storage = LLVMBuildBitCast(builder, reg_storage, LLVMPointerType(reg_bld->elem_type, 0), ""); + for (unsigned i = 0; i < nc; i++) { + LLVMValueRef indirect_offset = get_soa_array_offsets(uint_bld, indirect_val, nc, i, TRUE); +- vals[i] = build_gather(bld_base, reg_bld, reg_storage, indirect_offset, NULL, NULL); ++ vals[i] = build_gather(bld_base, reg_bld, reg_bld->elem_type, reg_storage, indirect_offset, NULL, NULL); + } + } else { + for (unsigned i = 0; i < nc; i++) { + LLVMValueRef this_storage = nc == 1 ? reg_storage : lp_build_array_get_ptr(gallivm, reg_storage, + lp_build_const_int32(gallivm, i)); +- vals[i] = LLVMBuildLoad(builder, this_storage, ""); ++ vals[i] = LLVMBuildLoad2(builder, reg_bld->vec_type, this_storage, ""); + } + } + return nc == 1 ? vals[0] : lp_nir_array_build_gather_values(builder, vals, nc); +@@ -1103,7 +1102,7 @@ static void emit_load_ubo(struct lp_build_nir_context *bld_base, + LLVMBuildStore(builder, lp_build_pointer_get(builder, consts_ptr, chan_offset), res_store); + lp_build_endif(&ifthen); + +- scalar = LLVMBuildLoad(builder, res_store, ""); ++ scalar = LLVMBuildLoad2(builder, LLVMTypeOf(zero), res_store, ""); + + result[c] = lp_build_broadcast_scalar(load_bld, scalar); + } +@@ -1122,7 +1121,7 @@ static void emit_load_ubo(struct lp_build_nir_context *bld_base, + LLVMValueRef this_offset = lp_build_add(uint_bld, offset, lp_build_const_int_vec(gallivm, uint_bld->type, c)); + overflow_mask = lp_build_compare(gallivm, uint_bld->type, PIPE_FUNC_GEQUAL, + this_offset, num_consts); +- result[c] = build_gather(bld_base, bld_broad, consts_ptr, this_offset, overflow_mask, NULL); ++ result[c] = build_gather(bld_base, bld_broad, bld_broad->elem_type, consts_ptr, this_offset, overflow_mask, NULL); + } + } + } +@@ -2232,14 +2231,14 @@ static void emit_shuffle(struct lp_build_nir_context *bld_base, LLVMValueRef src + */ + src_value = LLVMBuildFreeze(builder, src_value, ""); + +- LLVMValueRef res = LLVMBuildLoad(builder, res_store, ""); ++ LLVMValueRef res = LLVMBuildLoad2(builder, int_bld->vec_type, res_store, ""); + res = LLVMBuildInsertElement(builder, res, src_value, loop_state.counter, ""); + LLVMBuildStore(builder, res, res_store); + + lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length), + NULL, LLVMIntUGE); + +- result[0] = LLVMBuildLoad(builder, res_store, ""); ++ result[0] = LLVMBuildLoad2(builder, int_bld->vec_type, res_store, ""); + } + } + #endif +@@ -2653,7 +2652,8 @@ emit_clock(struct lp_build_nir_context *bld_base, + + lp_init_clock_hook(gallivm); + +- LLVMValueRef result = LLVMBuildCall(builder, gallivm->get_time_hook, NULL, 0, ""); ++ LLVMTypeRef get_time_type = LLVMFunctionType(LLVMInt64TypeInContext(gallivm->context), NULL, 0, 1); ++ LLVMValueRef result = LLVMBuildCall2(builder, get_time_type, gallivm->get_time_hook, NULL, 0, ""); + + LLVMValueRef hi = LLVMBuildShl(builder, result, lp_build_const_int64(gallivm, 32), ""); + hi = LLVMBuildTrunc(builder, hi, uint_bld->elem_type, ""); +-- +GitLab + + +From 1b8c4931df9d0ec55fc80dc280f27c40c9a2b781 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 16 Aug 2022 22:55:47 +0300 +Subject: [PATCH 6/9] gallivm: fixes for LLVM-15 opaque pointers in + lp_bld_jit_types.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + .../auxiliary/gallivm/lp_bld_jit_types.c | 41 ++++++++----------- + 1 file changed, 17 insertions(+), 24 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +index c4bfa2be899ce..7af92824a5a43 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +@@ -70,35 +70,28 @@ lp_llvm_buffer_member(struct gallivm_state *gallivm, + indices[1] = LLVMBuildSelect(gallivm->builder, cond, buffers_offset, lp_build_const_int32(gallivm, 0), ""); + indices[2] = lp_build_const_int32(gallivm, member_index); + +- LLVMValueRef ptr = +- LLVMBuildGEP(builder, buffers_ptr, indices, ARRAY_SIZE(indices), ""); ++ LLVMTypeRef buffer_type = lp_build_create_jit_buffer_type(gallivm); ++ LLVMTypeRef buffers_type = LLVMArrayType(buffer_type, LP_MAX_TGSI_CONST_BUFFERS); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, buffers_type, buffers_ptr, indices, ARRAY_SIZE(indices), ""); + +- LLVMValueRef res = LLVMBuildLoad(builder, ptr, ""); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(buffer_type, member_index); ++ LLVMValueRef res = LLVMBuildLoad2(builder, res_type, ptr, ""); + + lp_build_name(res, "buffer.%s", member_name); + + return res; + } + +-/** +- * Helper macro to instantiate the functions that generate the code to +- * fetch the members of lp_jit_buffer to fulfill the sampler code +- * generator requests. +- * +- * This complexity is the price we have to pay to keep the image +- * sampler code generator a reusable module without dependencies to +- * llvmpipe internals. +- */ +-#define LP_LLVM_BUFFER_MEMBER(_name, _index) \ +- LLVMValueRef \ +- lp_llvm_buffer_##_name(struct gallivm_state *gallivm, \ +- LLVMValueRef buffers_ptr, \ +- LLVMValueRef buffers_offset, unsigned buffers_limit) \ +- { \ +- return lp_llvm_buffer_member(gallivm, buffers_ptr, \ +- buffers_offset, buffers_limit, \ +- _index, #_name); \ +- } ++LLVMValueRef ++lp_llvm_buffer_base(struct gallivm_state *gallivm, ++ LLVMValueRef buffers_ptr, LLVMValueRef buffers_offset, unsigned buffers_limit) ++{ ++ return lp_llvm_buffer_member(gallivm, buffers_ptr, buffers_offset, buffers_limit, LP_JIT_BUFFER_BASE, "base"); ++} + +-LP_LLVM_BUFFER_MEMBER(base, LP_JIT_BUFFER_BASE) +-LP_LLVM_BUFFER_MEMBER(num_elements, LP_JIT_BUFFER_NUM_ELEMENTS) ++LLVMValueRef ++lp_llvm_buffer_num_elements(struct gallivm_state *gallivm, ++ LLVMValueRef buffers_ptr, LLVMValueRef buffers_offset, unsigned buffers_limit) ++{ ++ return lp_llvm_buffer_member(gallivm, buffers_ptr, buffers_offset, buffers_limit, LP_JIT_BUFFER_NUM_ELEMENTS, "num_elements"); ++} +-- +GitLab + + +From 02b9a8ba12e62cfa40b62af5a338bb9e670de12b Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Sat, 20 Aug 2022 13:50:04 +0300 +Subject: [PATCH 7/9] gallivm: fixes for LLVM-15 opaque pointers in + lp_bld_format_s3tc.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c | 9 ++++----- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 2 ++ + src/gallium/auxiliary/gallivm/lp_bld_struct.h | 2 ++ + 3 files changed, 8 insertions(+), 5 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +index fe44841528cb0..4ea40d14f8cac 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c +@@ -1197,12 +1197,11 @@ s3tc_update_cache_access(struct gallivm_state *gallivm, + + assert(index == LP_BUILD_FORMAT_CACHE_MEMBER_ACCESS_TOTAL || + index == LP_BUILD_FORMAT_CACHE_MEMBER_ACCESS_MISS); +- +- member_ptr = lp_build_struct_get_ptr(gallivm, ptr, index, ""); +- cache_access = LLVMBuildLoad(builder, member_ptr, "cache_access"); ++ LLVMTypeRef cache_type = lp_build_format_cache_type(gallivm); ++ member_ptr = lp_build_struct_get_ptr2(gallivm, cache_type, ptr, index, ""); ++ cache_access = LLVMBuildLoad2(builder, LLVMInt64TypeInContext(gallivm->context), member_ptr, "cache_access"); + cache_access = LLVMBuildAdd(builder, cache_access, +- LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), +- count, 0), ""); ++ LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), count, 0), ""); + LLVMBuildStore(builder, cache_access, member_ptr); + } + #endif +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index 9e3e24cd9e1e7..4259ecfa0d453 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -42,6 +42,7 @@ + #include "lp_bld_struct.h" + + ++/* Deprecated (used only by llvmpipe); use lp_build_struct_get_ptr2() instead. */ + LLVMValueRef + lp_build_struct_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef ptr, +@@ -60,6 +61,7 @@ lp_build_struct_get_ptr(struct gallivm_state *gallivm, + return member_ptr; + } + ++/* Deprecated (used only by llvmpipe); use lp_build_struct_get2() instead. */ + LLVMValueRef + lp_build_struct_get(struct gallivm_state *gallivm, + LLVMValueRef ptr, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +index a87519883b4df..4b1cc79b2aa48 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +@@ -55,6 +55,7 @@ + + /** + * Get value pointer to a structure member. ++ * Deprecated (used only by llvmpipe); use lp_build_struct_get_ptr2() instead. + */ + LLVMValueRef + lp_build_struct_get_ptr(struct gallivm_state *gallivm, +@@ -64,6 +65,7 @@ lp_build_struct_get_ptr(struct gallivm_state *gallivm, + + /** + * Get the value of a structure member. ++ * Deprecated (used only by llvmpipe); use lp_build_struct_get2() instead. + */ + LLVMValueRef + lp_build_struct_get(struct gallivm_state *gallivm, +-- +GitLab + + +From 4ff7e64e81c0b4acb39c841b6d8da7ebc8bdd6dd Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Mon, 22 Aug 2022 16:34:30 +0300 +Subject: [PATCH 8/9] gallivm: fixes for LLVM-15 opaque pointers in + lp_bld_struct.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index 4259ecfa0d453..fa25b4ac3124a 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -109,7 +109,8 @@ lp_build_struct_get2(struct gallivm_state *gallivm, + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + member_ptr = lp_build_struct_get_ptr2(gallivm, ptr_type, ptr, member, name); +- res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); ++ LLVMTypeRef member_type = LLVMStructGetTypeAtIndex(ptr_type, member); ++ res = LLVMBuildLoad2(gallivm->builder, member_type, member_ptr, ""); + lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); + return res; + } +-- +GitLab + + +From 136a26f271b5b846f3808f917267b79d0460e71a Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Wed, 24 Aug 2022 14:22:07 +0300 +Subject: [PATCH 9/9] gallivm: fixes for LLVM-15 opaque pointers in + lp_bld_format_soa.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18334> +--- + src/gallium/auxiliary/gallivm/lp_bld_format_soa.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c +index 6cda6036b37c8..784b8dc66946f 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c +@@ -1099,7 +1099,7 @@ lp_build_store_rgba_soa(struct gallivm_state *gallivm, + struct lp_build_loop_state loop_state; + + LLVMValueRef store_offset = LLVMBuildAdd(gallivm->builder, offset, lp_build_const_int_vec(gallivm, type, i * 4), ""); +- store_offset = LLVMBuildGEP(gallivm->builder, base_ptr, &store_offset, 1, ""); ++ store_offset = LLVMBuildGEP2(gallivm->builder, LLVMInt8TypeInContext(gallivm->context), base_ptr, &store_offset, 1, ""); + + lp_build_loop_begin(&loop_state, gallivm, lp_build_const_int32(gallivm, 0)); + +-- +GitLab + +From 1d741f4c62af71af860eaab35e16633b5d6428ed Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Wed, 31 Aug 2022 15:38:52 +0300 +Subject: [PATCH 1/3] gallivm: LLVM opaque pointer fixes in lp_bld_sample.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +load_mip() + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18721> +--- + src/gallium/auxiliary/gallivm/lp_bld_sample.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +index 5ab732ab765d1..181a6f4e08ff1 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +@@ -1175,7 +1175,7 @@ load_mip(struct gallivm_state *gallivm, LLVMValueRef offsets, LLVMValueRef index + LLVMValueRef zero = lp_build_const_int32(gallivm, 0); + LLVMValueRef indexes[2] = {zero, index1}; + LLVMValueRef ptr = LLVMBuildGEP(gallivm->builder, offsets, indexes, ARRAY_SIZE(indexes), ""); +- return LLVMBuildLoad(gallivm->builder, ptr, ""); ++ return LLVMBuildLoad2(gallivm->builder, LLVMInt32TypeInContext(gallivm->context), ptr, ""); + } + + /** +-- +GitLab + + +From cdd7e8f5cecf137a33430f41f48ae671a52561b6 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 6 Sep 2022 18:57:42 +0300 +Subject: [PATCH 2/3] gallivm: LLVM opaque pointers: add + lp_build_array_get[_ptr]2 in lp_bld_struct.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +i.e. variants taking an explicit LLVM type + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18721> +--- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 39 +++++++++++++++++++ + src/gallium/auxiliary/gallivm/lp_bld_struct.h | 12 ++++++ + 2 files changed, 51 insertions(+) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index fa25b4ac3124a..408ac17e246ea 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -115,6 +115,45 @@ lp_build_struct_get2(struct gallivm_state *gallivm, + return res; + } + ++LLVMValueRef ++lp_build_array_get_ptr2(struct gallivm_state *gallivm, ++ LLVMTypeRef array_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index) ++{ ++ LLVMValueRef indices[2]; ++ LLVMValueRef element_ptr; ++ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); ++ indices[0] = lp_build_const_int32(gallivm, 0); ++ indices[1] = index; ++ element_ptr = LLVMBuildGEP2(gallivm->builder, array_type, ptr, indices, ARRAY_SIZE(indices), ""); ++#ifdef DEBUG ++ lp_build_name(element_ptr, "&%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); ++#endif ++ return element_ptr; ++} ++ ++ ++LLVMValueRef ++lp_build_array_get2(struct gallivm_state *gallivm, ++ LLVMTypeRef array_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index) ++{ ++ LLVMValueRef element_ptr; ++ LLVMValueRef res; ++ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++ assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); ++ element_ptr = lp_build_array_get_ptr2(gallivm, array_type, ptr, index); ++ LLVMTypeRef element_type = LLVMGetElementType(array_type); ++ res = LLVMBuildLoad2(gallivm->builder, element_type, element_ptr, ""); ++#ifdef DEBUG ++ lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); ++#endif ++ return res; ++} ++ + LLVMValueRef + lp_build_array_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef ptr, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +index 4b1cc79b2aa48..d90bdf48d321b 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +@@ -95,6 +95,18 @@ lp_build_struct_get2(struct gallivm_state *gallivm, + unsigned member, + const char *name); + ++LLVMValueRef ++lp_build_array_get_ptr2(struct gallivm_state *gallivm, ++ LLVMTypeRef array_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index); ++ ++LLVMValueRef ++lp_build_array_get2(struct gallivm_state *gallivm, ++ LLVMTypeRef array_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index); ++ + /** + * Get value pointer to an array element. + */ +-- +GitLab + + +From 15e78caf8d38e97183aba6bce65b1bef34869537 Mon Sep 17 00:00:00 2001 +From: Mihai Preda <mhpreda@gmail.com> +Date: Tue, 6 Sep 2022 19:00:30 +0300 +Subject: [PATCH 3/3] gallivm: LLVM opaque pointers: use + lp_build_array_get_ptr2() in lp_bld_nir_soa.c +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Reviewed-by: Marek Olšák <marek.olsak@amd.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18721> +--- + src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +index 6128f90ee16f4..5e1a987049db7 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +@@ -708,9 +708,12 @@ static LLVMValueRef emit_load_reg(struct lp_build_nir_context *bld_base, + vals[i] = build_gather(bld_base, reg_bld, reg_bld->elem_type, reg_storage, indirect_offset, NULL, NULL); + } + } else { ++ LLVMTypeRef array_type = LLVMArrayType(reg_bld->vec_type, nc); + for (unsigned i = 0; i < nc; i++) { +- LLVMValueRef this_storage = nc == 1 ? reg_storage : lp_build_array_get_ptr(gallivm, reg_storage, +- lp_build_const_int32(gallivm, i)); ++ LLVMValueRef index = lp_build_const_int32(gallivm, i); ++ LLVMValueRef this_storage = ++ nc == 1 ? reg_storage ++ : lp_build_array_get_ptr2(gallivm, array_type, reg_storage, index); + vals[i] = LLVMBuildLoad2(builder, reg_bld->vec_type, this_storage, ""); + } + } +@@ -748,9 +751,12 @@ static void emit_store_reg(struct lp_build_nir_context *bld_base, + return; + } + ++ LLVMTypeRef array_type = LLVMArrayType(reg_bld->vec_type, nc); + for (unsigned i = 0; i < nc; i++) { +- LLVMValueRef this_storage = nc == 1 ? reg_storage : lp_build_array_get_ptr(gallivm, reg_storage, +- lp_build_const_int32(gallivm, i)); ++ LLVMValueRef index = lp_build_const_int32(gallivm, i); ++ LLVMValueRef this_storage = ++ nc == 1 ? reg_storage ++ : lp_build_array_get_ptr2(gallivm, array_type, reg_storage, index); + dst[i] = LLVMBuildBitCast(builder, dst[i], reg_bld->vec_type, ""); + lp_exec_mask_store(&bld->exec_mask, reg_bld, dst[i], this_storage); + } +-- +GitLab + +From 25ead8ec5c84028d4c58eff0b203b49f0425d812 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 12:16:48 +1000 +Subject: [PATCH] gallivm: fix buffer_type for LLVM 15 + +Fixes +deqp-vk: /home/airlied/devel/llvm-project/llvm/include/llvm/IR/Instructions.h:961: static llvm::GetElementPtrInst* llvm::GetElementPtrInst::Create(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&, llvm::Instruction*): Assertion `cast<PointerType>(Ptr->getType()->getScalarType()) ->isOpaqueOrPointeeTypeMatches(PointeeType)' failed. + +Fixes: 1b8c4931df9d ("gallivm: fixes for LLVM-15 opaque pointers in lp_bld_jit_types.c") +Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18816> +--- + src/gallium/auxiliary/gallivm/lp_bld_jit_types.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +index 7af92824a5a43..2a4ecf72e711b 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +@@ -71,7 +71,7 @@ lp_llvm_buffer_member(struct gallivm_state *gallivm, + indices[2] = lp_build_const_int32(gallivm, member_index); + + LLVMTypeRef buffer_type = lp_build_create_jit_buffer_type(gallivm); +- LLVMTypeRef buffers_type = LLVMArrayType(buffer_type, LP_MAX_TGSI_CONST_BUFFERS); ++ LLVMTypeRef buffers_type = LLVMArrayType(buffer_type, buffers_limit); + LLVMValueRef ptr = LLVMBuildGEP2(builder, buffers_type, buffers_ptr, indices, ARRAY_SIZE(indices), ""); + + LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(buffer_type, member_index); +-- +GitLab + +From d132625eed474d149ed6372dd5448492675b738e Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Tue, 27 Sep 2022 05:15:26 +1000 +Subject: [PATCH 1/3] lavapipe: add fmin/fmax to image lowering. + +Fixes: 31695f81c925 ("lavapipe: export VK_KHR_shader_atomic_float") + +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18835> +--- + src/gallium/frontends/lavapipe/lvp_lower_vulkan_resource.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/gallium/frontends/lavapipe/lvp_lower_vulkan_resource.c b/src/gallium/frontends/lavapipe/lvp_lower_vulkan_resource.c +index ff7a38bd5e208..16a1567a6ae1b 100644 +--- a/src/gallium/frontends/lavapipe/lvp_lower_vulkan_resource.c ++++ b/src/gallium/frontends/lavapipe/lvp_lower_vulkan_resource.c +@@ -50,6 +50,8 @@ lower_vulkan_resource_index(const nir_instr *instr, const void *data_cb) + case nir_intrinsic_image_deref_atomic_exchange: + case nir_intrinsic_image_deref_atomic_comp_swap: + case nir_intrinsic_image_deref_atomic_fadd: ++ case nir_intrinsic_image_deref_atomic_fmin: ++ case nir_intrinsic_image_deref_atomic_fmax: + case nir_intrinsic_image_deref_size: + case nir_intrinsic_image_deref_samples: + return true; +@@ -339,6 +341,8 @@ static nir_ssa_def *lower_vri_instr(struct nir_builder *b, + case nir_intrinsic_image_deref_atomic_exchange: + case nir_intrinsic_image_deref_atomic_comp_swap: + case nir_intrinsic_image_deref_atomic_fadd: ++ case nir_intrinsic_image_deref_atomic_fmin: ++ case nir_intrinsic_image_deref_atomic_fmax: + case nir_intrinsic_image_deref_size: + case nir_intrinsic_image_deref_samples: + lower_image_intrinsic(b, intrin, data_cb); +-- +GitLab + + +From c642fa122ccd90b11ad54dd50e398373069ae8c7 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Tue, 27 Sep 2022 05:17:39 +1000 +Subject: [PATCH 2/3] gallivm/nir: fix fmin/fmax translation + +Fixes: 203920d4c693 ("gallivm: add atomic 32-bit float support") + +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18835> +--- + src/gallium/auxiliary/gallivm/lp_bld_nir.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c +index 8d71fb304a4a8..4afeebfd06ad1 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c +@@ -1738,10 +1738,10 @@ visit_atomic_image(struct lp_build_nir_context *bld_base, + break; + #if LLVM_VERSION >= 15 + case nir_intrinsic_image_atomic_fmin: +- params.op = LLVMAtomicRMWBinOpMin; ++ params.op = LLVMAtomicRMWBinOpFMin; + break; + case nir_intrinsic_image_atomic_fmax: +- params.op = LLVMAtomicRMWBinOpMax; ++ params.op = LLVMAtomicRMWBinOpFMax; + break; + #endif + default: +-- +GitLab + + +From f2922126156b9bc9fd10bfd3690e7ed3db08184f Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Tue, 27 Sep 2022 15:26:42 +1000 +Subject: [PATCH 3/3] gallivm/nir: bitcast when non-float ptr type. + +This matters more when opaque pointers are used. + +Fixes: 203920d4c693 ("gallivm: add atomic 32-bit float support") + +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18835> +--- + src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +index 5e1a987049db7..b5e401f6132a1 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +@@ -1224,7 +1224,7 @@ mem_access_base_pointer(struct lp_build_nir_context *bld_base, + } + + /* Cast it to the pointer type of the access this instruction is doing. */ +- if (bit_size == 32) ++ if (bit_size == 32 && !mem_bld->type.floating) + return ptr; + else + return LLVMBuildBitCast(gallivm->builder, ptr, LLVMPointerType(mem_bld->elem_type, 0), ""); +-- +GitLab + +From b36160689f430e0845940fb0c3dac9ba22c6608b Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 13:47:15 +1000 +Subject: [PATCH 01/10] gallivm/struct: add opaque ptr friendly pointer + accessors. + +These just add explicit types. + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 29 +++++++++++++++++++ + src/gallium/auxiliary/gallivm/lp_bld_struct.h | 24 +++++++++++++++ + 2 files changed, 53 insertions(+) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index 408ac17e246ea..73c32cebadfb6 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -234,6 +234,35 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder, + return res; + } + ++LLVMValueRef ++lp_build_pointer_get_unaligned2(LLVMBuilderRef builder, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index, ++ unsigned alignment) ++{ ++ LLVMValueRef element_ptr; ++ LLVMValueRef res; ++ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); ++ element_ptr = LLVMBuildGEP2(builder, ptr_type, ptr, &index, 1, ""); ++ res = LLVMBuildLoad2(builder, ptr_type, element_ptr, ""); ++ if (alignment) ++ LLVMSetAlignment(res, alignment); ++#ifdef DEBUG ++ lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); ++#endif ++ return res; ++} ++ ++ ++LLVMValueRef ++lp_build_pointer_get2(LLVMBuilderRef builder, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index) ++{ ++ return lp_build_pointer_get_unaligned2(builder, ptr_type, ptr, index, 0); ++} + + void + lp_build_pointer_set(LLVMBuilderRef builder, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +index d90bdf48d321b..52d6020563bfb 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +@@ -152,6 +152,30 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder, + LLVMValueRef index, + unsigned alignment); + ++/** ++ * Get the value of an array element. ++ * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. ++ */ ++LLVMValueRef ++lp_build_pointer_get2(LLVMBuilderRef builder, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index); ++ ++/** ++ * Get the value of an array element, with explicit alignment, and explicit type, ++ * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. ++ * ++ * If the element size is different from the alignment this will ++ * cause llvm to emit an unaligned load ++ */ ++LLVMValueRef ++lp_build_pointer_get_unaligned2(LLVMBuilderRef builder, ++ LLVMTypeRef ptr_type, ++ LLVMValueRef ptr, ++ LLVMValueRef index, ++ unsigned alignment); ++ + /** + * Set the value of an array element. + */ +-- +GitLab + + +From 637652a97fab5c20959505f17972f6a0a549ef9f Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 13:55:57 +1000 +Subject: [PATCH 02/10] llvmpipe/fs: add mask_type for mask_store accesses. + +This adds and passes around the type for mask stores. + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_state_fs.c | 32 ++++++++++++---------- + 1 file changed, 17 insertions(+), 15 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 53d933cfb0219..42b07bba4f8bc 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -633,6 +633,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + struct lp_build_interp_soa_context *interp, + const struct lp_build_sampler_soa *sampler, + const struct lp_build_image_soa *image, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + LLVMValueRef (*out_color)[4], + LLVMValueRef depth_base_ptr, +@@ -789,7 +790,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + for (unsigned s = 0; s < key->coverage_samples; s++) { + LLVMValueRef s_mask_idx = LLVMBuildMul(builder, num_loop, lp_build_const_int32(gallivm, s), ""); + s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_state.counter, ""); +- LLVMValueRef s_mask = lp_build_pointer_get(builder, mask_store, s_mask_idx); ++ LLVMValueRef s_mask = lp_build_pointer_get2(builder, mask_type, mask_store, s_mask_idx); + if (s == 0) + mask_val = s_mask; + else +@@ -800,9 +801,9 @@ generate_fs_loop(struct gallivm_state *gallivm, + } + } else { + sample_mask_in = lp_build_const_int_vec(gallivm, type, 1); +- mask_ptr = LLVMBuildGEP(builder, mask_store, ++ mask_ptr = LLVMBuildGEP2(builder, mask_type, mask_store, + &loop_state.counter, 1, "mask_ptr"); +- mask_val = LLVMBuildLoad(builder, mask_ptr, ""); ++ mask_val = LLVMBuildLoad2(builder, mask_type, mask_ptr, ""); + + LLVMValueRef mask_in = LLVMBuildAnd(builder, mask_val, lp_build_const_int_vec(gallivm, type, 1), ""); + sample_mask_in = LLVMBuildOr(builder, sample_mask_in, mask_in, ""); +@@ -860,9 +861,9 @@ generate_fs_loop(struct gallivm_state *gallivm, + + LLVMValueRef s_mask_idx = LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""); + s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_state.counter, ""); +- s_mask_ptr = LLVMBuildGEP(builder, mask_store, &s_mask_idx, 1, ""); ++ s_mask_ptr = LLVMBuildGEP2(builder, mask_type, mask_store, &s_mask_idx, 1, ""); + +- s_mask = LLVMBuildLoad(builder, s_mask_ptr, ""); ++ s_mask = LLVMBuildLoad2(builder, mask_type, s_mask_ptr, ""); + s_mask = LLVMBuildAnd(builder, s_mask, mask_val, ""); + } + +@@ -990,8 +991,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + + LLVMValueRef s_mask_idx = LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""); + s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_state.counter, ""); +- s_mask_ptr = LLVMBuildGEP(builder, mask_store, &s_mask_idx, 1, ""); +- s_mask = LLVMBuildLoad(builder, s_mask_ptr, ""); ++ s_mask_ptr = LLVMBuildGEP2(builder, mask_type, mask_store, &s_mask_idx, 1, ""); ++ s_mask = LLVMBuildLoad2(builder, mask_type, s_mask_ptr, ""); + lp_build_mask_force(&mask, s_mask); + lp_build_interp_soa_update_pos_dyn(interp, gallivm, loop_state.counter, sample_loop_state.counter); + system_values.sample_id = sample_loop_state.counter; +@@ -1216,10 +1217,10 @@ generate_fs_loop(struct gallivm_state *gallivm, + /* load the per-sample coverage mask */ + LLVMValueRef s_mask_idx = LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""); + s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_state.counter, ""); +- s_mask_ptr = LLVMBuildGEP(builder, mask_store, &s_mask_idx, 1, ""); ++ s_mask_ptr = LLVMBuildGEP2(builder, mask_type, mask_store, &s_mask_idx, 1, ""); + + /* combine the execution mask post fragment shader with the coverage mask. */ +- s_mask = LLVMBuildLoad(builder, s_mask_ptr, ""); ++ s_mask = LLVMBuildLoad2(builder, mask_type, s_mask_ptr, ""); + if (key->min_samples == 1) + s_mask = LLVMBuildAnd(builder, s_mask, lp_build_mask_value(&mask), ""); + +@@ -3339,8 +3340,8 @@ generate_fragment(struct llvmpipe_context *lp, + LLVMValueRef sindexi = + lp_build_const_int32(gallivm, i + (s * num_fs)); + LLVMValueRef sample_mask_ptr = +- LLVMBuildGEP(builder, mask_store, &sindexi, 1, +- "sample_mask_ptr"); ++ LLVMBuildGEP2(builder, mask_type, mask_store, &sindexi, 1, ++ "sample_mask_ptr"); + LLVMValueRef s_mask = + generate_quad_mask(gallivm, fs_type, + i * fs_type.length / 4, s, mask_input); +@@ -3359,8 +3360,8 @@ generate_fragment(struct llvmpipe_context *lp, + } else { + LLVMValueRef mask; + LLVMValueRef indexi = lp_build_const_int32(gallivm, i); +- LLVMValueRef mask_ptr = LLVMBuildGEP(builder, mask_store, +- &indexi, 1, "mask_ptr"); ++ LLVMValueRef mask_ptr = LLVMBuildGEP2(builder, mask_type, mask_store, ++ &indexi, 1, "mask_ptr"); + + if (partial_mask) { + mask = generate_quad_mask(gallivm, fs_type, +@@ -3383,6 +3384,7 @@ generate_fragment(struct llvmpipe_context *lp, + &interp, + sampler, + image, ++ mask_type, + mask_store, /* output */ + color_store, + depth_ptr, +@@ -3400,9 +3402,9 @@ generate_fragment(struct llvmpipe_context *lp, + for (unsigned s = 0; s < key->coverage_samples; s++) { + int idx = (i + (s * num_fs)); + LLVMValueRef sindexi = lp_build_const_int32(gallivm, idx); +- ptr = LLVMBuildGEP(builder, mask_store, &sindexi, 1, ""); ++ ptr = LLVMBuildGEP2(builder, mask_type, mask_store, &sindexi, 1, ""); + +- fs_mask[idx] = LLVMBuildLoad(builder, ptr, "smask"); ++ fs_mask[idx] = LLVMBuildLoad2(builder, mask_type, ptr, "smask"); + } + + for (unsigned s = 0; s < key->min_samples; s++) { +-- +GitLab + + +From 694104b7761b4fece5b0861fc443a6dc553de5b2 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 17:36:58 +1000 +Subject: [PATCH 03/10] llvmpipe/fs: pass explicit mask_type into interp code. + +This is so it is known for explicit pointer support + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_bld_interp.c | 14 +++++++++----- + src/gallium/drivers/llvmpipe/lp_bld_interp.h | 2 ++ + src/gallium/drivers/llvmpipe/lp_state_fs.c | 7 +++++-- + 3 files changed, 16 insertions(+), 7 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c +index 61d0bfa492fa5..f03da17c4d481 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c ++++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c +@@ -157,6 +157,7 @@ static void + calc_centroid_offsets(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + LLVMValueRef loop_iter, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + LLVMValueRef pix_center_offset, + LLVMValueRef *centroid_x, LLVMValueRef *centroid_y) +@@ -171,7 +172,7 @@ calc_centroid_offsets(struct lp_build_interp_soa_context *bld, + LLVMValueRef s_mask_idx = LLVMBuildMul(builder, bld->num_loop, lp_build_const_int32(gallivm, s), ""); + + s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_iter, ""); +- sample_cov = lp_build_pointer_get(builder, mask_store, s_mask_idx); ++ sample_cov = lp_build_pointer_get2(builder, mask_type, mask_store, s_mask_idx); + if (s == bld->coverage_samples - 1) + s_mask_and = sample_cov; + else +@@ -284,6 +285,7 @@ static void + attribs_update_simple(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + LLVMValueRef loop_iter, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + LLVMValueRef sample_id, + int start, +@@ -376,7 +378,7 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, + xoffset = lp_build_broadcast_scalar(coeff_bld, x_val_idx); + yoffset = lp_build_broadcast_scalar(coeff_bld, y_val_idx); + } else if (loc == TGSI_INTERPOLATE_LOC_CENTROID) { +- calc_centroid_offsets(bld, gallivm, loop_iter, mask_store, ++ calc_centroid_offsets(bld, gallivm, loop_iter, mask_type, mask_store, + pix_center_offset, &xoffset, &yoffset); + } + chan_pixoffx = lp_build_add(coeff_bld, chan_pixoffx, xoffset); +@@ -508,6 +510,7 @@ LLVMValueRef + lp_build_interp_soa(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + LLVMValueRef loop_iter, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + unsigned attrib, unsigned chan, + enum tgsi_interpolate_loc loc, +@@ -579,7 +582,7 @@ lp_build_interp_soa(struct lp_build_interp_soa_context *bld, + /* for centroid find covered samples for this quad. */ + /* if all samples are covered use pixel centers */ + if (bld->coverage_samples > 1) { +- calc_centroid_offsets(bld, gallivm, loop_iter, mask_store, ++ calc_centroid_offsets(bld, gallivm, loop_iter, mask_type, mask_store, + pix_center_offset, ¢roid_x_offset, + ¢roid_y_offset); + +@@ -793,10 +796,11 @@ void + lp_build_interp_soa_update_inputs_dyn(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + LLVMValueRef quad_start_index, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + LLVMValueRef sample_id) + { +- attribs_update_simple(bld, gallivm, quad_start_index, mask_store, sample_id, 1, bld->num_attribs); ++ attribs_update_simple(bld, gallivm, quad_start_index, mask_type, mask_store, sample_id, 1, bld->num_attribs); + } + + void +@@ -805,6 +809,6 @@ lp_build_interp_soa_update_pos_dyn(struct lp_build_interp_soa_context *bld, + LLVMValueRef quad_start_index, + LLVMValueRef sample_id) + { +- attribs_update_simple(bld, gallivm, quad_start_index, NULL, sample_id, 0, 1); ++ attribs_update_simple(bld, gallivm, quad_start_index, NULL, NULL, sample_id, 0, 1); + } + +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.h b/src/gallium/drivers/llvmpipe/lp_bld_interp.h +index f9c9211cbb8d5..acd5546118471 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.h ++++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.h +@@ -138,6 +138,7 @@ void + lp_build_interp_soa_update_inputs_dyn(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + LLVMValueRef quad_start_index, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + LLVMValueRef sample_id); + +@@ -151,6 +152,7 @@ LLVMValueRef + lp_build_interp_soa(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + LLVMValueRef loop_iter, ++ LLVMTypeRef mask_type, + LLVMValueRef mask_store, + unsigned attrib, unsigned chan, + unsigned loc, +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 42b07bba4f8bc..1aef483fd6446 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -434,6 +434,7 @@ struct lp_build_fs_llvm_iface { + struct lp_build_fs_iface base; + struct lp_build_interp_soa_context *interp; + struct lp_build_for_loop_state *loop_state; ++ LLVMTypeRef mask_type; + LLVMValueRef mask_store; + LLVMValueRef sample_id; + LLVMValueRef color_ptr_ptr; +@@ -463,7 +464,7 @@ fs_interp(const struct lp_build_fs_iface *iface, + loc = TGSI_INTERPOLATE_LOC_SAMPLE; + + return lp_build_interp_soa(interp, bld->gallivm, fs_iface->loop_state->counter, +- fs_iface->mask_store, ++ fs_iface->mask_type, fs_iface->mask_store, + attrib, chan, loc, attrib_indir, offsets); + } + +@@ -1005,7 +1006,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + } + system_values.sample_pos = sample_pos_array; + +- lp_build_interp_soa_update_inputs_dyn(interp, gallivm, loop_state.counter, mask_store, sample_loop_state.counter); ++ lp_build_interp_soa_update_inputs_dyn(interp, gallivm, loop_state.counter, ++ mask_type, mask_store, sample_loop_state.counter); + + struct lp_build_fs_llvm_iface fs_iface = { + .base.interp_fn = fs_interp, +@@ -1013,6 +1015,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + .interp = interp, + .loop_state = &loop_state, + .sample_id = system_values.sample_id, ++ .mask_type = mask_type, + .mask_store = mask_store, + .color_ptr_ptr = color_ptr_ptr, + .color_stride_ptr = color_stride_ptr, +-- +GitLab + + +From ff02d042aabd9567e35cf289830bbfd552eaff05 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:15:28 +1000 +Subject: [PATCH 04/10] llvmpipe/fs: port depth code to opaque pointer api + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_bld_depth.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_depth.c b/src/gallium/drivers/llvmpipe/lp_bld_depth.c +index 91bb347e307c3..10bb2d9939266 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_depth.c ++++ b/src/gallium/drivers/llvmpipe/lp_bld_depth.c +@@ -587,8 +587,9 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, + + /* Load current z/stencil values from z/stencil buffer */ + LLVMTypeRef load_ptr_type = LLVMPointerType(zs_dst_type, 0); ++ LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context); + LLVMValueRef zs_dst_ptr = +- LLVMBuildGEP(builder, depth_ptr, &depth_offset1, 1, ""); ++ LLVMBuildGEP2(builder, int8_type, depth_ptr, &depth_offset1, 1, ""); + zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, load_ptr_type, ""); + LLVMValueRef zs_dst1 = LLVMBuildLoad2(builder, zs_dst_type, zs_dst_ptr, ""); + LLVMValueRef zs_dst2; +@@ -596,7 +597,7 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, + zs_dst2 = lp_build_undef(gallivm, zs_load_type); + } + else { +- zs_dst_ptr = LLVMBuildGEP(builder, depth_ptr, &depth_offset2, 1, ""); ++ zs_dst_ptr = LLVMBuildGEP2(builder, int8_type, depth_ptr, &depth_offset2, 1, ""); + zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, load_ptr_type, ""); + zs_dst2 = LLVMBuildLoad2(builder, zs_dst_type, zs_dst_ptr, ""); + } +@@ -733,9 +734,10 @@ lp_build_depth_stencil_write_swizzled(struct gallivm_state *gallivm, + + depth_offset2 = LLVMBuildAdd(builder, depth_offset1, depth_stride, ""); + +- zs_dst_ptr1 = LLVMBuildGEP(builder, depth_ptr, &depth_offset1, 1, ""); ++ LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context); ++ zs_dst_ptr1 = LLVMBuildGEP2(builder, int8_type, depth_ptr, &depth_offset1, 1, ""); + zs_dst_ptr1 = LLVMBuildBitCast(builder, zs_dst_ptr1, load_ptr_type, ""); +- zs_dst_ptr2 = LLVMBuildGEP(builder, depth_ptr, &depth_offset2, 1, ""); ++ zs_dst_ptr2 = LLVMBuildGEP2(builder, int8_type, depth_ptr, &depth_offset2, 1, ""); + zs_dst_ptr2 = LLVMBuildBitCast(builder, zs_dst_ptr2, load_ptr_type, ""); + + if (format_desc->block.bits > 32) { +-- +GitLab + + +From e28db68e53c3e265df5dd66c5b6bfe7cfb762f2a Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:17:35 +1000 +Subject: [PATCH 05/10] llvmpipe/fs: add sample position type to the interp + interface + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_bld_interp.c | 20 ++++++++++++++------ + src/gallium/drivers/llvmpipe/lp_bld_interp.h | 2 ++ + src/gallium/drivers/llvmpipe/lp_state_fs.c | 4 +++- + 3 files changed, 19 insertions(+), 7 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c +index f03da17c4d481..f5c4a2105b4d4 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c ++++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c +@@ -181,8 +181,10 @@ calc_centroid_offsets(struct lp_build_interp_soa_context *bld, + LLVMValueRef x_val_idx = lp_build_const_int32(gallivm, s * 2); + LLVMValueRef y_val_idx = lp_build_const_int32(gallivm, s * 2 + 1); + +- x_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, x_val_idx); +- y_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, y_val_idx); ++ x_val_idx = lp_build_array_get2(gallivm, bld->sample_pos_array_type, ++ bld->sample_pos_array, x_val_idx); ++ y_val_idx = lp_build_array_get2(gallivm, bld->sample_pos_array_type, ++ bld->sample_pos_array, y_val_idx); + x_val_idx = lp_build_broadcast_scalar(coeff_bld, x_val_idx); + y_val_idx = lp_build_broadcast_scalar(coeff_bld, y_val_idx); + centroid_x_offset = lp_build_select(coeff_bld, sample_cov, x_val_idx, centroid_x_offset); +@@ -338,7 +340,8 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, + dadx = coeff_bld->one; + if (sample_id) { + LLVMValueRef x_val_idx = LLVMBuildMul(gallivm->builder, sample_id, lp_build_const_int32(gallivm, 2), ""); +- x_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, x_val_idx); ++ x_val_idx = lp_build_array_get2(gallivm, bld->sample_pos_array_type, ++ bld->sample_pos_array, x_val_idx); + a = lp_build_broadcast_scalar(coeff_bld, x_val_idx); + } else { + a = lp_build_const_vec(gallivm, coeff_bld->type, bld->pos_offset); +@@ -349,7 +352,8 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, + if (sample_id) { + LLVMValueRef y_val_idx = LLVMBuildMul(gallivm->builder, sample_id, lp_build_const_int32(gallivm, 2), ""); + y_val_idx = LLVMBuildAdd(gallivm->builder, y_val_idx, lp_build_const_int32(gallivm, 1), ""); +- y_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, y_val_idx); ++ y_val_idx = lp_build_array_get2(gallivm, bld->sample_pos_array_type, ++ bld->sample_pos_array, y_val_idx); + a = lp_build_broadcast_scalar(coeff_bld, y_val_idx); + } else { + a = lp_build_const_vec(gallivm, coeff_bld->type, bld->pos_offset); +@@ -373,8 +377,10 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, + LLVMValueRef x_val_idx = LLVMBuildMul(gallivm->builder, sample_id, lp_build_const_int32(gallivm, 2), ""); + LLVMValueRef y_val_idx = LLVMBuildAdd(gallivm->builder, x_val_idx, lp_build_const_int32(gallivm, 1), ""); + +- x_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, x_val_idx); +- y_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, y_val_idx); ++ x_val_idx = lp_build_array_get2(gallivm, bld->sample_pos_array_type, ++ bld->sample_pos_array, x_val_idx); ++ y_val_idx = lp_build_array_get2(gallivm, bld->sample_pos_array_type, ++ bld->sample_pos_array, y_val_idx); + xoffset = lp_build_broadcast_scalar(coeff_bld, x_val_idx); + yoffset = lp_build_broadcast_scalar(coeff_bld, y_val_idx); + } else if (loc == TGSI_INTERPOLATE_LOC_CENTROID) { +@@ -678,6 +684,7 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, + const struct lp_shader_input *inputs, + boolean pixel_center_integer, + unsigned coverage_samples, ++ LLVMTypeRef sample_pos_array_type, + LLVMValueRef sample_pos_array, + LLVMValueRef num_loop, + LLVMBuilderRef builder, +@@ -750,6 +757,7 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, + } + bld->coverage_samples = coverage_samples; + bld->num_loop = num_loop; ++ bld->sample_pos_array_type = sample_pos_array_type; + bld->sample_pos_array = sample_pos_array; + + pos_init(bld, x0, y0); +diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.h b/src/gallium/drivers/llvmpipe/lp_bld_interp.h +index acd5546118471..445c8655d4d59 100644 +--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.h ++++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.h +@@ -90,6 +90,7 @@ struct lp_build_interp_soa_context + double pos_offset; + unsigned coverage_samples; + LLVMValueRef num_loop; ++ LLVMTypeRef sample_pos_array_type; + LLVMValueRef sample_pos_array; + + LLVMValueRef x; +@@ -124,6 +125,7 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, + const struct lp_shader_input *inputs, + boolean pixel_center_integer, + unsigned coverage_samples, ++ LLVMTypeRef sample_pos_array_type, + LLVMValueRef sample_pos_array, + LLVMValueRef num_loop, + LLVMBuilderRef builder, +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 1aef483fd6446..7e554662bdd8b 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -3319,7 +3319,9 @@ generate_fragment(struct llvmpipe_context *lp, + shader->info.base.num_inputs, + inputs, + pixel_center_integer, +- key->coverage_samples, glob_sample_pos, ++ key->coverage_samples, ++ LLVMTypeOf(sample_pos_array), ++ glob_sample_pos, + num_loop, + builder, fs_type, + a0_ptr, dadx_ptr, dady_ptr, +-- +GitLab + + +From 38907a40ab0848c9fe8d1b7ad6d0f4047fcf6f5b Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:19:44 +1000 +Subject: [PATCH 06/10] llvmpipe/fs: pass mask type to alpha to coverage + handler + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_state_fs.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 7e554662bdd8b..9dabfcb4a80f3 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -408,6 +408,7 @@ lp_build_sample_alpha_to_coverage(struct gallivm_state *gallivm, + unsigned coverage_samples, + LLVMValueRef num_loop, + LLVMValueRef loop_counter, ++ LLVMTypeRef coverage_mask_type, + LLVMValueRef coverage_mask_store, + LLVMValueRef alpha) + { +@@ -422,8 +423,9 @@ lp_build_sample_alpha_to_coverage(struct gallivm_state *gallivm, + + LLVMValueRef s_mask_idx = LLVMBuildMul(builder, lp_build_const_int32(gallivm, s), num_loop, ""); + s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_counter, ""); +- LLVMValueRef s_mask_ptr = LLVMBuildGEP(builder, coverage_mask_store, &s_mask_idx, 1, ""); +- LLVMValueRef s_mask = LLVMBuildLoad(builder, s_mask_ptr, ""); ++ LLVMValueRef s_mask_ptr = LLVMBuildGEP2(builder, coverage_mask_type, ++ coverage_mask_store, &s_mask_idx, 1, ""); ++ LLVMValueRef s_mask = LLVMBuildLoad2(builder, coverage_mask_type, s_mask_ptr, ""); + s_mask = LLVMBuildAnd(builder, s_mask, test, ""); + LLVMBuildStore(builder, s_mask, s_mask_ptr); + } +@@ -1089,7 +1091,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + } else { + lp_build_sample_alpha_to_coverage(gallivm, type, key->coverage_samples, num_loop, + loop_state.counter, +- mask_store, alpha); ++ mask_type, mask_store, alpha); + } + } + } +-- +GitLab + + +From 3137f4fad15058cc7d16b2438f44b5e581853be8 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:20:25 +1000 +Subject: [PATCH 07/10] llvmpipe/fs: use explicit api in viewport code. + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_state_fs.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 9dabfcb4a80f3..9cbdc9cff037d 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -332,12 +332,13 @@ lp_llvm_viewport(LLVMTypeRef context_type, + LLVMValueRef res; + struct lp_type viewport_type = + lp_type_float_vec(32, 32 * LP_JIT_VIEWPORT_NUM_FIELDS); ++ LLVMTypeRef vtype = lp_build_vec_type(gallivm, viewport_type); + + ptr = lp_jit_context_viewports(gallivm, context_type, context_ptr); + ptr = LLVMBuildPointerCast(builder, ptr, +- LLVMPointerType(lp_build_vec_type(gallivm, viewport_type), 0), ""); ++ LLVMPointerType(vtype, 0), ""); + +- res = lp_build_pointer_get(builder, ptr, viewport_index); ++ res = lp_build_pointer_get2(builder, vtype, ptr, viewport_index); + + return res; + } +-- +GitLab + + +From b9a0ec0c67741cb4b1d2c0d44f747aabe28018e3 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:24:44 +1000 +Subject: [PATCH 08/10] llvmpipe/fs: handle explicit types around blending and + c/zs bufs calcs + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_state_fs.c | 132 +++++++++++++-------- + 1 file changed, 80 insertions(+), 52 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 9cbdc9cff037d..900d2c1e63c3b 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -117,6 +117,7 @@ static unsigned fs_no = 0; + + static void + load_unswizzled_block(struct gallivm_state *gallivm, ++ LLVMTypeRef base_type, + LLVMValueRef base_ptr, + LLVMValueRef stride, + unsigned block_width, +@@ -507,6 +508,9 @@ fs_fb_fetch(const struct lp_build_fs_iface *iface, + struct lp_build_fs_llvm_iface *fs_iface = (struct lp_build_fs_llvm_iface *)iface; + struct gallivm_state *gallivm = bld->gallivm; + LLVMBuilderRef builder = gallivm->builder; ++ LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); ++ LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context); ++ LLVMTypeRef int8p_type = LLVMPointerType(int8_type, 0); + const struct lp_fragment_shader_variant_key *key = fs_iface->key; + + LLVMValueRef buf_ptr; +@@ -524,8 +528,12 @@ fs_fb_fetch(const struct lp_build_fs_iface *iface, + const int cbuf = location - FRAG_RESULT_DATA0; + LLVMValueRef index = lp_build_const_int32(gallivm, cbuf); + +- buf_ptr = LLVMBuildLoad(builder, LLVMBuildGEP(builder, fs_iface->color_ptr_ptr, &index, 1, ""), ""); +- stride = LLVMBuildLoad(builder, LLVMBuildGEP(builder, fs_iface->color_stride_ptr, &index, 1, ""), ""); ++ buf_ptr = LLVMBuildLoad2(builder, int8p_type, ++ LLVMBuildGEP2(builder, int8p_type, ++ fs_iface->color_ptr_ptr, &index, 1, ""), ""); ++ stride = LLVMBuildLoad2(builder, int32_type, ++ LLVMBuildGEP2(builder, int32_type, ++ fs_iface->color_stride_ptr, &index, 1, ""), ""); + buf_format = key->cbuf_format[cbuf]; + } + +@@ -546,13 +554,16 @@ fs_fb_fetch(const struct lp_build_fs_iface *iface, + sample_stride = fs_iface->zs_sample_stride; + } else { + LLVMValueRef index = lp_build_const_int32(gallivm, location - FRAG_RESULT_DATA0); +- sample_stride = LLVMBuildLoad(builder, +- LLVMBuildGEP(builder, fs_iface->color_sample_stride_ptr, +- &index, 1, ""), ""); ++ sample_stride = LLVMBuildLoad2(builder, int32_type, ++ LLVMBuildGEP2(builder, ++ int32_type, ++ fs_iface->color_sample_stride_ptr, ++ &index, 1, ""), ""); + } + + LLVMValueRef sample_offset = LLVMBuildMul(builder, sample_stride, fs_iface->sample_id, ""); +- buf_ptr = LLVMBuildGEP(builder, buf_ptr, &sample_offset, 1, ""); ++ buf_ptr = LLVMBuildGEP2(builder, int8_type, ++ buf_ptr, &sample_offset, 1, ""); + } + + /* fragment shader executes on 4x4 blocks. depending on vector width it can +@@ -883,7 +894,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + LLVMValueRef sample_offset = + LLVMBuildMul(builder, sample_loop_state.counter, + depth_sample_stride, ""); +- depth_ptr = LLVMBuildGEP(builder, depth_ptr, &sample_offset, 1, ""); ++ depth_ptr = LLVMBuildGEP2(builder, LLVMInt8TypeInContext(gallivm->context), ++ depth_ptr, &sample_offset, 1, ""); + } + + if (depth_mode & EARLY_DEPTH_TEST) { +@@ -1248,7 +1260,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + depth_ptr = depth_base_ptr; + if (key->multisample) { + LLVMValueRef sample_offset = LLVMBuildMul(builder, sample_loop_state.counter, depth_sample_stride, ""); +- depth_ptr = LLVMBuildGEP(builder, depth_ptr, &sample_offset, 1, ""); ++ depth_ptr = LLVMBuildGEP2(builder, LLVMInt8TypeInContext(gallivm->context), ++ depth_ptr, &sample_offset, 1, ""); + } + + /* Late Z test */ +@@ -1258,8 +1271,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + if (key->min_samples > 1) + idx = LLVMBuildAdd(builder, idx, + LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""), ""); +- LLVMValueRef ptr = LLVMBuildGEP(builder, z_out, &idx, 1, ""); +- z = LLVMBuildLoad(builder, ptr, "output.z"); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, vec_type, z_out, &idx, 1, ""); ++ z = LLVMBuildLoad2(builder, vec_type, ptr, "output.z"); + } else { + if (key->multisample) { + lp_build_interp_soa_update_pos_dyn(interp, gallivm, loop_state.counter, key->multisample ? sample_loop_state.counter : NULL); +@@ -1280,8 +1293,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + if (key->min_samples > 1) + idx = LLVMBuildAdd(builder, idx, + LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""), ""); +- LLVMValueRef ptr = LLVMBuildGEP(builder, s_out, &idx, 1, ""); +- stencil_refs[0] = LLVMBuildLoad(builder, ptr, "output.s"); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, vec_type, s_out, &idx, 1, ""); ++ stencil_refs[0] = LLVMBuildLoad2(builder, vec_type, ptr, "output.s"); + /* there's only one value, and spec says to discard additional bits */ + LLVMValueRef s_max_mask = lp_build_const_int_vec(gallivm, int_type, 255); + stencil_refs[0] = LLVMBuildBitCast(builder, stencil_refs[0], int_vec_type, ""); +@@ -1322,10 +1335,10 @@ generate_fs_loop(struct gallivm_state *gallivm, + * write that out. + */ + if (key->multisample) { +- z_value = LLVMBuildBitCast(builder, lp_build_pointer_get(builder, z_sample_value_store, sample_loop_state.counter), z_type, "");; +- s_value = lp_build_pointer_get(builder, s_sample_value_store, sample_loop_state.counter); +- z_fb = LLVMBuildBitCast(builder, lp_build_pointer_get(builder, z_fb_store, sample_loop_state.counter), z_fb_type, ""); +- s_fb = lp_build_pointer_get(builder, s_fb_store, sample_loop_state.counter); ++ z_value = LLVMBuildBitCast(builder, lp_build_pointer_get2(builder, int_vec_type, z_sample_value_store, sample_loop_state.counter), z_type, ""); ++ s_value = lp_build_pointer_get2(builder, int_vec_type, s_sample_value_store, sample_loop_state.counter); ++ z_fb = LLVMBuildBitCast(builder, lp_build_pointer_get2(builder, int_vec_type, z_fb_store, sample_loop_state.counter), z_fb_type, ""); ++ s_fb = lp_build_pointer_get2(builder, int_vec_type, s_fb_store, sample_loop_state.counter); + } + lp_build_depth_stencil_write_swizzled(gallivm, type, + zs_format_desc, key->resource_1d, +@@ -1604,6 +1617,7 @@ fs_twiddle_transpose(struct gallivm_state *gallivm, + */ + static void + load_unswizzled_block(struct gallivm_state *gallivm, ++ LLVMTypeRef base_type, + LLVMValueRef base_ptr, + LLVMValueRef stride, + unsigned block_width, +@@ -1632,11 +1646,13 @@ load_unswizzled_block(struct gallivm_state *gallivm, + gep[0] = lp_build_const_int32(gallivm, 0); + gep[1] = LLVMBuildAdd(builder, bx, by, ""); + +- dst_ptr = LLVMBuildGEP(builder, base_ptr, gep, 2, ""); ++ dst_ptr = LLVMBuildGEP2(builder, base_type, base_ptr, gep, 2, ""); + dst_ptr = LLVMBuildBitCast(builder, dst_ptr, + LLVMPointerType(lp_build_vec_type(gallivm, dst_type), 0), ""); + +- dst[i] = LLVMBuildLoad(builder, dst_ptr, ""); ++ dst[i] = LLVMBuildLoad2(builder, ++ lp_build_vec_type(gallivm, dst_type), ++ dst_ptr, ""); + + LLVMSetAlignment(dst[i], dst_alignment); + } +@@ -1648,6 +1664,7 @@ load_unswizzled_block(struct gallivm_state *gallivm, + */ + static void + store_unswizzled_block(struct gallivm_state *gallivm, ++ LLVMTypeRef base_type, + LLVMValueRef base_ptr, + LLVMValueRef stride, + unsigned block_width, +@@ -1676,7 +1693,7 @@ store_unswizzled_block(struct gallivm_state *gallivm, + gep[0] = lp_build_const_int32(gallivm, 0); + gep[1] = LLVMBuildAdd(builder, bx, by, ""); + +- src_ptr = LLVMBuildGEP(builder, base_ptr, gep, 2, ""); ++ src_ptr = LLVMBuildGEP2(builder, base_type, base_ptr, gep, 2, ""); + src_ptr = LLVMBuildBitCast(builder, src_ptr, + LLVMPointerType(lp_build_vec_type(gallivm, src_type), 0), ""); + +@@ -2377,6 +2394,7 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + LLVMValueRef fs_out_color[PIPE_MAX_COLOR_BUFS][TGSI_NUM_CHANNELS][4], + LLVMTypeRef context_type, + LLVMValueRef context_ptr, ++ LLVMTypeRef color_type, + LLVMValueRef color_ptr, + LLVMValueRef stride, + unsigned partial_mask, +@@ -2431,6 +2449,8 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + unsigned num_fullblock_fs = is_1d ? 2 * num_fs : num_fs; + LLVMValueRef fpstate = 0; + ++ LLVMTypeRef fs_vec_type = lp_build_vec_type(gallivm, fs_type); ++ + /* Get type from output format */ + lp_blend_type_from_format_desc(out_format_desc, &row_type); + lp_mem_type_from_format_desc(out_format_desc, &dst_type); +@@ -2550,7 +2570,8 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + /* Always load alpha for use in blending */ + LLVMValueRef alpha; + if (i < num_fs) { +- alpha = LLVMBuildLoad(builder, fs_out_color[rt][alpha_channel][i], ""); ++ alpha = LLVMBuildLoad2(builder, fs_vec_type, ++ fs_out_color[rt][alpha_channel][i], ""); + } else { + alpha = undef_src_val; + } +@@ -2559,8 +2580,8 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + for (unsigned j = 0; j < dst_channels; ++j) { + assert(swizzle[j] < 4); + if (i < num_fs) { +- fs_src[i][j] = LLVMBuildLoad(builder, +- fs_out_color[rt][swizzle[j]][i], ""); ++ fs_src[i][j] = LLVMBuildLoad2(builder, fs_vec_type, ++ fs_out_color[rt][swizzle[j]][i], ""); + } else { + fs_src[i][j] = undef_src_val; + } +@@ -2599,7 +2620,8 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + for (unsigned i = 0; i < num_fullblock_fs; ++i) { + LLVMValueRef alpha; + if (i < num_fs) { +- alpha = LLVMBuildLoad(builder, fs_out_color[1][alpha_channel][i], ""); ++ alpha = LLVMBuildLoad2(builder, fs_vec_type, ++ fs_out_color[1][alpha_channel][i], ""); + } else { + alpha = undef_src_val; + } +@@ -2607,7 +2629,8 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + for (unsigned j = 0; j < dst_channels; ++j) { + assert(swizzle[j] < 4); + if (i < num_fs) { +- fs_src1[i][j] = LLVMBuildLoad(builder, fs_out_color[1][swizzle[j]][i], ""); ++ fs_src1[i][j] = LLVMBuildLoad2(builder, fs_vec_type, ++ fs_out_color[1][swizzle[j]][i], ""); + } else { + fs_src1[i][j] = undef_src_val; + } +@@ -2632,14 +2655,15 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + */ + fs_type.floating = 0; + fs_type.sign = dst_type.sign; ++ fs_vec_type = lp_build_vec_type(gallivm, fs_type); + for (unsigned i = 0; i < num_fullblock_fs; ++i) { + for (unsigned j = 0; j < dst_channels; ++j) { + fs_src[i][j] = LLVMBuildBitCast(builder, fs_src[i][j], +- lp_build_vec_type(gallivm, fs_type), ""); ++ fs_vec_type, ""); + } + if (dst_channels == 3 && !has_alpha) { + fs_src[i][3] = LLVMBuildBitCast(builder, fs_src[i][3], +- lp_build_vec_type(gallivm, fs_type), ""); ++ fs_vec_type, ""); + } + } + } +@@ -2690,6 +2714,7 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + unsigned ds = src_count / (num_fullblock_fs * src_channels); + row_type.length /= ds; + fs_type.length = row_type.length; ++ fs_vec_type = lp_build_vec_type(gallivm, fs_type); + } + + blend_type = row_type; +@@ -2740,9 +2765,9 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + */ + blend_color = lp_jit_context_f_blend_color(gallivm, context_type, context_ptr); + blend_color = LLVMBuildPointerCast(builder, blend_color, +- LLVMPointerType(lp_build_vec_type(gallivm, fs_type), 0), ++ LLVMPointerType(fs_vec_type, 0), + ""); +- blend_color = LLVMBuildLoad(builder, LLVMBuildGEP(builder, blend_color, ++ blend_color = LLVMBuildLoad2(builder, fs_vec_type, LLVMBuildGEP2(builder, fs_vec_type, blend_color, + &i32_zero, 1, ""), ""); + + /* Convert */ +@@ -2932,13 +2957,13 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + } + + if (is_1d) { +- load_unswizzled_block(gallivm, color_ptr, stride, block_width, 1, ++ load_unswizzled_block(gallivm, color_type, color_ptr, stride, block_width, 1, + dst, ls_type, dst_count / 4, dst_alignment); + for (unsigned i = dst_count / 4; i < dst_count; i++) { + dst[i] = lp_build_undef(gallivm, ls_type); + } + } else { +- load_unswizzled_block(gallivm, color_ptr, stride, block_width, ++ load_unswizzled_block(gallivm, color_type, color_ptr, stride, block_width, + block_height, dst, ls_type, dst_count, + dst_alignment); + } +@@ -3047,10 +3072,10 @@ generate_unswizzled_blend(struct gallivm_state *gallivm, + * Store blend result to memory + */ + if (is_1d) { +- store_unswizzled_block(gallivm, color_ptr, stride, block_width, 1, ++ store_unswizzled_block(gallivm, color_type, color_ptr, stride, block_width, 1, + dst, dst_type, dst_count / 4, dst_alignment); + } else { +- store_unswizzled_block(gallivm, color_ptr, stride, block_width, ++ store_unswizzled_block(gallivm, color_type, color_ptr, stride, block_width, + block_height, + dst, dst_type, dst_count, dst_alignment); + } +@@ -3089,6 +3114,7 @@ generate_fragment(struct llvmpipe_context *lp, + LLVMTypeRef func_type; + LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); + LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context); ++ LLVMTypeRef int8p_type = LLVMPointerType(int8_type, 0); + LLVMValueRef context_ptr; + LLVMValueRef x; + LLVMValueRef y; +@@ -3405,6 +3431,7 @@ generate_fragment(struct llvmpipe_context *lp, + variant->jit_thread_data_type, + thread_data_ptr); + ++ LLVMTypeRef fs_vec_type = lp_build_vec_type(gallivm, fs_type); + for (unsigned i = 0; i < num_fs; i++) { + LLVMValueRef ptr; + for (unsigned s = 0; s < key->coverage_samples; s++) { +@@ -3421,9 +3448,9 @@ generate_fragment(struct llvmpipe_context *lp, + LLVMValueRef sindexi = lp_build_const_int32(gallivm, idx); + for (unsigned cbuf = 0; cbuf < key->nr_cbufs; cbuf++) { + for (unsigned chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) { +- ptr = LLVMBuildGEP(builder, +- color_store[cbuf * !cbuf0_write_all][chan], +- &sindexi, 1, ""); ++ ptr = LLVMBuildGEP2(builder, fs_vec_type, ++ color_store[cbuf * !cbuf0_write_all][chan], ++ &sindexi, 1, ""); + fs_out_color[s][cbuf][chan][i] = ptr; + } + } +@@ -3432,9 +3459,9 @@ generate_fragment(struct llvmpipe_context *lp, + * output 1 + */ + for (unsigned chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) { +- ptr = LLVMBuildGEP(builder, +- color_store[1][chan], +- &sindexi, 1, ""); ++ ptr = LLVMBuildGEP2(builder, fs_vec_type, ++ color_store[1][chan], ++ &sindexi, 1, ""); + fs_out_color[s][1][chan][i] = ptr; + } + } +@@ -3458,32 +3485,33 @@ generate_fragment(struct llvmpipe_context *lp, + || key->alpha.enabled) + && !shader->info.base.uses_kill); + +- color_ptr = LLVMBuildLoad(builder, +- LLVMBuildGEP(builder, color_ptr_ptr, +- &index, 1, ""), +- ""); ++ color_ptr = LLVMBuildLoad2(builder, int8p_type, ++ LLVMBuildGEP2(builder, int8p_type, color_ptr_ptr, ++ &index, 1, ""), ++ ""); + +- stride = LLVMBuildLoad(builder, +- LLVMBuildGEP(builder, stride_ptr, ++ stride = LLVMBuildLoad2(builder, int32_type, ++ LLVMBuildGEP2(builder, int32_type, stride_ptr, + &index, 1, ""), +- ""); ++ ""); + + if (key->cbuf_nr_samples[cbuf] > 1) +- sample_stride = LLVMBuildLoad(builder, +- LLVMBuildGEP(builder, +- color_sample_stride_ptr, +- &index, 1, ""), ""); ++ sample_stride = LLVMBuildLoad2(builder, int32_type, ++ LLVMBuildGEP2(builder, ++ int32_type, ++ color_sample_stride_ptr, ++ &index, 1, ""), ""); + + for (unsigned s = 0; s < key->cbuf_nr_samples[cbuf]; s++) { + unsigned mask_idx = num_fs * (key->multisample ? s : 0); + unsigned out_idx = key->min_samples == 1 ? 0 : s; +- LLVMValueRef out_ptr = color_ptr;; ++ LLVMValueRef out_ptr = color_ptr; + + if (sample_stride) { + LLVMValueRef sample_offset = + LLVMBuildMul(builder, sample_stride, + lp_build_const_int32(gallivm, s), ""); +- out_ptr = LLVMBuildGEP(builder, out_ptr, &sample_offset, 1, ""); ++ out_ptr = LLVMBuildGEP2(builder, int8_type, out_ptr, &sample_offset, 1, ""); + } + out_ptr = LLVMBuildBitCast(builder, out_ptr, + LLVMPointerType(blend_vec_type, 0), ""); +@@ -3495,7 +3523,7 @@ generate_fragment(struct llvmpipe_context *lp, + num_fs, fs_type, &fs_mask[mask_idx], + fs_out_color[out_idx], + variant->jit_context_type, +- context_ptr, out_ptr, stride, ++ context_ptr, blend_vec_type, out_ptr, stride, + partial_mask, do_branch); + } + } +-- +GitLab + + +From 5b83357ac5aea1b1735030cd1ece13d1a7e2f402 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:25:42 +1000 +Subject: [PATCH 09/10] llvmpipe/fs: cleanup some remaining mask handling and + reuse types + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_state_fs.c | 33 +++++++++++----------- + 1 file changed, 17 insertions(+), 16 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index 900d2c1e63c3b..d906d83840eff 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -831,8 +831,8 @@ generate_fs_loop(struct gallivm_state *gallivm, + lp_build_mask_check(&mask); + + /* Create storage for recombining sample masks after early Z pass. */ +- LLVMValueRef s_mask_or = lp_build_alloca(gallivm, lp_build_int_vec_type(gallivm, type), "cov_mask_early_depth"); +- LLVMBuildStore(builder, LLVMConstNull(lp_build_int_vec_type(gallivm, type)), s_mask_or); ++ LLVMValueRef s_mask_or = lp_build_alloca(gallivm, int_vec_type, "cov_mask_early_depth"); ++ LLVMBuildStore(builder, LLVMConstNull(int_vec_type), s_mask_or); + + /* Create storage for post depth sample mask */ + LLVMValueRef post_depth_sample_mask_in = NULL; +@@ -953,13 +953,13 @@ generate_fs_loop(struct gallivm_state *gallivm, + * Recombine the resulting coverage masks post early Z into the fragment + * shader execution mask. + */ +- LLVMValueRef tmp_s_mask_or = LLVMBuildLoad(builder, s_mask_or, ""); ++ LLVMValueRef tmp_s_mask_or = LLVMBuildLoad2(builder, int_vec_type, s_mask_or, ""); + tmp_s_mask_or = LLVMBuildOr(builder, tmp_s_mask_or, s_mask, ""); + LLVMBuildStore(builder, tmp_s_mask_or, s_mask_or); + + if (post_depth_coverage) { + LLVMValueRef mask_bit_idx = LLVMBuildShl(builder, lp_build_const_int32(gallivm, 1), sample_loop_state.counter, ""); +- LLVMValueRef post_depth_mask_in = LLVMBuildLoad(builder, post_depth_sample_mask_in, ""); ++ LLVMValueRef post_depth_mask_in = LLVMBuildLoad2(builder, int_vec_type, post_depth_sample_mask_in, ""); + mask_bit_idx = LLVMBuildAnd(builder, s_mask, lp_build_broadcast(gallivm, int_vec_type, mask_bit_idx), ""); + post_depth_mask_in = LLVMBuildOr(builder, post_depth_mask_in, mask_bit_idx, ""); + LLVMBuildStore(builder, post_depth_mask_in, post_depth_sample_mask_in); +@@ -970,7 +970,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + lp_build_for_loop_end(&sample_loop_state); + + /* recombined all the coverage masks in the shader exec mask. */ +- tmp_s_mask_or = LLVMBuildLoad(builder, s_mask_or, ""); ++ tmp_s_mask_or = LLVMBuildLoad2(builder, int_vec_type, s_mask_or, ""); + lp_build_mask_update(&mask, tmp_s_mask_or); + + if (key->min_samples == 1) { +@@ -994,7 +994,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + } + + if (post_depth_coverage) { +- system_values.sample_mask_in = LLVMBuildLoad(builder, post_depth_sample_mask_in, ""); ++ system_values.sample_mask_in = LLVMBuildLoad2(builder, int_vec_type, post_depth_sample_mask_in, ""); + } else { + system_values.sample_mask_in = sample_mask_in; + } +@@ -1140,7 +1140,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + + if (key->min_samples > 1) { + /* only the bit corresponding to this sample is to be used. */ +- LLVMValueRef tmp_mask = LLVMBuildLoad(builder, out_sample_mask_storage, "tmp_mask"); ++ LLVMValueRef tmp_mask = LLVMBuildLoad2(builder, int_vec_type, out_sample_mask_storage, "tmp_mask"); + LLVMValueRef out_smask_idx = LLVMBuildShl(builder, lp_build_const_int32(gallivm, 1), sample_loop_state.counter, ""); + LLVMValueRef smask_bit = LLVMBuildAnd(builder, output_smask, lp_build_broadcast(gallivm, int_vec_type, out_smask_idx), ""); + output_smask = LLVMBuildOr(builder, tmp_mask, smask_bit, ""); +@@ -1248,7 +1248,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + (!(depth_mode & EARLY_DEPTH_TEST) || (depth_mode & (EARLY_DEPTH_TEST_INFERRED)))) { + LLVMValueRef out_smask_idx = LLVMBuildShl(builder, lp_build_const_int32(gallivm, 1), sample_loop_state.counter, ""); + out_smask_idx = lp_build_broadcast(gallivm, int_vec_type, out_smask_idx); +- LLVMValueRef output_smask = LLVMBuildLoad(builder, out_sample_mask_storage, ""); ++ LLVMValueRef output_smask = LLVMBuildLoad2(builder, int_vec_type, out_sample_mask_storage, ""); + LLVMValueRef smask_bit = LLVMBuildAnd(builder, output_smask, out_smask_idx, ""); + LLVMValueRef cmp = LLVMBuildICmp(builder, LLVMIntNE, smask_bit, lp_build_const_int_vec(gallivm, int_type, 0), ""); + smask_bit = LLVMBuildSExt(builder, cmp, int_vec_type, ""); +@@ -1363,7 +1363,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + /* if the shader writes sample mask use that */ + LLVMValueRef out_smask_idx = LLVMBuildShl(builder, lp_build_const_int32(gallivm, 1), sample_loop_state.counter, ""); + out_smask_idx = lp_build_broadcast(gallivm, int_vec_type, out_smask_idx); +- LLVMValueRef output_smask = LLVMBuildLoad(builder, out_sample_mask_storage, ""); ++ LLVMValueRef output_smask = LLVMBuildLoad2(builder, int_vec_type, out_sample_mask_storage, ""); + LLVMValueRef smask_bit = LLVMBuildAnd(builder, output_smask, out_smask_idx, ""); + LLVMValueRef cmp = LLVMBuildICmp(builder, LLVMIntNE, smask_bit, lp_build_const_int_vec(gallivm, int_type, 0), ""); + smask_bit = LLVMBuildSExt(builder, cmp, int_vec_type, ""); +@@ -3113,6 +3113,7 @@ generate_fragment(struct llvmpipe_context *lp, + LLVMTypeRef arg_types[15]; + LLVMTypeRef func_type; + LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); ++ LLVMTypeRef int32p_type = LLVMPointerType(int32_type, 0); + LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context); + LLVMTypeRef int8p_type = LLVMPointerType(int8_type, 0); + LLVMValueRef context_ptr; +@@ -3198,13 +3199,13 @@ generate_fragment(struct llvmpipe_context *lp, + arg_types[4] = LLVMPointerType(fs_elem_type, 0); /* a0 */ + arg_types[5] = LLVMPointerType(fs_elem_type, 0); /* dadx */ + arg_types[6] = LLVMPointerType(fs_elem_type, 0); /* dady */ +- arg_types[7] = LLVMPointerType(LLVMPointerType(int8_type, 0), 0); /* color */ +- arg_types[8] = LLVMPointerType(int8_type, 0); /* depth */ ++ arg_types[7] = LLVMPointerType(int8p_type, 0); /* color */ ++ arg_types[8] = int8p_type; /* depth */ + arg_types[9] = LLVMInt64TypeInContext(gallivm->context); /* mask_input */ + arg_types[10] = variant->jit_thread_data_ptr_type; /* per thread data */ +- arg_types[11] = LLVMPointerType(int32_type, 0); /* stride */ ++ arg_types[11] = int32p_type; /* stride */ + arg_types[12] = int32_type; /* depth_stride */ +- arg_types[13] = LLVMPointerType(int32_type, 0); /* color sample strides */ ++ arg_types[13] = int32p_type; /* color sample strides */ + arg_types[14] = int32_type; /* depth sample stride */ + + func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), +@@ -3359,9 +3360,9 @@ generate_fragment(struct llvmpipe_context *lp, + for (unsigned i = 0; i < num_fs; i++) { + if (key->multisample) { + LLVMValueRef smask_val = +- LLVMBuildLoad(builder, +- lp_jit_context_sample_mask(gallivm, variant->jit_context_type, context_ptr), +- ""); ++ LLVMBuildLoad2(builder, int32_type, ++ lp_jit_context_sample_mask(gallivm, variant->jit_context_type, context_ptr), ++ ""); + + /* + * For multisampling, extract the per-sample mask from the +-- +GitLab + + +From 111bf8bfee280683a4c2d14ec08f65675204138c Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Thu, 29 Sep 2022 08:26:01 +1000 +Subject: [PATCH 10/10] llvmpipe/fs: convert outputs handling to explicit api + +Reviewed-by: Brian Paul <brianp@vmware.com> +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876> +--- + src/gallium/drivers/llvmpipe/lp_state_fs.c | 21 +++++++++++---------- + 1 file changed, 11 insertions(+), 10 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index d906d83840eff..b65a3a897eb9c 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -1074,7 +1074,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + + if (color0 != -1 && outputs[color0][3]) { + const struct util_format_description *cbuf_format_desc; +- LLVMValueRef alpha = LLVMBuildLoad(builder, outputs[color0][3], "alpha"); ++ LLVMValueRef alpha = LLVMBuildLoad2(builder, vec_type, outputs[color0][3], "alpha"); + LLVMValueRef alpha_ref_value; + + alpha_ref_value = lp_jit_context_alpha_ref_value(gallivm, context_type, context_ptr); +@@ -1095,7 +1095,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + 0); + + if (color0 != -1 && outputs[color0][3]) { +- LLVMValueRef alpha = LLVMBuildLoad(builder, outputs[color0][3], "alpha"); ++ LLVMValueRef alpha = LLVMBuildLoad2(builder, vec_type, outputs[color0][3], "alpha"); + + if (!key->multisample) { + lp_build_alpha_to_coverage(gallivm, type, +@@ -1130,7 +1130,7 @@ generate_fs_loop(struct gallivm_state *gallivm, + lp_build_context_init(&smask_bld, gallivm, int_type); + + assert(smaski >= 0); +- output_smask = LLVMBuildLoad(builder, outputs[smaski][0], "smask"); ++ output_smask = LLVMBuildLoad2(builder, vec_type, outputs[smaski][0], "smask"); + output_smask = LLVMBuildBitCast(builder, output_smask, smask_bld.vec_type, ""); + if (!key->multisample && key->no_ms_sample_mask_out) { + output_smask = lp_build_and(&smask_bld, output_smask, smask_bld.one); +@@ -1153,12 +1153,12 @@ generate_fs_loop(struct gallivm_state *gallivm, + int pos0 = find_output_by_semantic(&shader->info.base, + TGSI_SEMANTIC_POSITION, + 0); +- LLVMValueRef out = LLVMBuildLoad(builder, outputs[pos0][2], ""); ++ LLVMValueRef out = LLVMBuildLoad2(builder, vec_type, outputs[pos0][2], ""); + LLVMValueRef idx = loop_state.counter; + if (key->min_samples > 1) + idx = LLVMBuildAdd(builder, idx, + LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""), ""); +- LLVMValueRef ptr = LLVMBuildGEP(builder, z_out, &idx, 1, ""); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, vec_type, z_out, &idx, 1, ""); + LLVMBuildStore(builder, out, ptr); + } + +@@ -1166,12 +1166,13 @@ generate_fs_loop(struct gallivm_state *gallivm, + int sten_out = find_output_by_semantic(&shader->info.base, + TGSI_SEMANTIC_STENCIL, + 0); +- LLVMValueRef out = LLVMBuildLoad(builder, outputs[sten_out][1], "output.s"); ++ LLVMValueRef out = LLVMBuildLoad2(builder, vec_type, ++ outputs[sten_out][1], "output.s"); + LLVMValueRef idx = loop_state.counter; + if (key->min_samples > 1) + idx = LLVMBuildAdd(builder, idx, + LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""), ""); +- LLVMValueRef ptr = LLVMBuildGEP(builder, s_out, &idx, 1, ""); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, vec_type, s_out, &idx, 1, ""); + LLVMBuildStore(builder, out, ptr); + } + +@@ -1205,14 +1206,14 @@ generate_fs_loop(struct gallivm_state *gallivm, + /* XXX: just initialize outputs to point at colors[] and + * skip this. + */ +- LLVMValueRef out = LLVMBuildLoad(builder, outputs[attrib][chan], ""); ++ LLVMValueRef out = LLVMBuildLoad2(builder, vec_type, outputs[attrib][chan], ""); + LLVMValueRef color_ptr; + LLVMValueRef color_idx = loop_state.counter; + if (key->min_samples > 1) + color_idx = LLVMBuildAdd(builder, color_idx, + LLVMBuildMul(builder, sample_loop_state.counter, num_loop, ""), ""); +- color_ptr = LLVMBuildGEP(builder, out_color[cbuf][chan], +- &color_idx, 1, ""); ++ color_ptr = LLVMBuildGEP2(builder, vec_type, out_color[cbuf][chan], ++ &color_idx, 1, ""); + lp_build_name(out, "color%u.%c", attrib, "rgba"[chan]); + LLVMBuildStore(builder, out, color_ptr); + } +-- +GitLab + +From 3d242c044758292712e1876ba3afdd3e8f06d5df Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Tue, 4 Oct 2022 09:41:00 +1000 +Subject: [PATCH 1/6] llvmpipe/tests: port to new pointer interfaces. + +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18947> +--- + src/gallium/drivers/llvmpipe/lp_test_arit.c | 6 +++--- + src/gallium/drivers/llvmpipe/lp_test_blend.c | 8 ++++---- + src/gallium/drivers/llvmpipe/lp_test_conv.c | 12 +++++++----- + 3 files changed, 14 insertions(+), 12 deletions(-) + +diff --git a/src/gallium/drivers/llvmpipe/lp_test_arit.c b/src/gallium/drivers/llvmpipe/lp_test_arit.c +index 55ced4c67ccd4..4118928d52ed0 100644 +--- a/src/gallium/drivers/llvmpipe/lp_test_arit.c ++++ b/src/gallium/drivers/llvmpipe/lp_test_arit.c +@@ -362,11 +362,11 @@ build_unary_test_func(struct gallivm_state *gallivm, + LLVMSetFunctionCallConv(func, LLVMCCallConv); + + LLVMPositionBuilderAtEnd(builder, block); +- +- arg1 = LLVMBuildLoad(builder, arg1, ""); ++ ++ arg1 = LLVMBuildLoad2(builder, vf32t, arg1, ""); + + ret = test->builder(&bld, arg1); +- ++ + LLVMBuildStore(builder, ret, arg0); + + LLVMBuildRetVoid(builder); +diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c b/src/gallium/drivers/llvmpipe/lp_test_blend.c +index 7805ec58d98a3..2d44e8eafe70c 100644 +--- a/src/gallium/drivers/llvmpipe/lp_test_blend.c ++++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c +@@ -172,10 +172,10 @@ add_blend_test(struct gallivm_state *gallivm, + builder = gallivm->builder; + LLVMPositionBuilderAtEnd(builder, block); + +- src = LLVMBuildLoad(builder, src_ptr, "src"); +- src1 = LLVMBuildLoad(builder, src1_ptr, "src1"); +- dst = LLVMBuildLoad(builder, dst_ptr, "dst"); +- con = LLVMBuildLoad(builder, const_ptr, "const"); ++ src = LLVMBuildLoad2(builder, vec_type, src_ptr, "src"); ++ src1 = LLVMBuildLoad2(builder, vec_type, src1_ptr, "src1"); ++ dst = LLVMBuildLoad2(builder, vec_type, dst_ptr, "dst"); ++ con = LLVMBuildLoad2(builder, vec_type, const_ptr, "const"); + + res = lp_build_blend_aos(gallivm, blend, format, type, rt, src, NULL, + src1, NULL, dst, NULL, con, NULL, swizzle, 4); +diff --git a/src/gallium/drivers/llvmpipe/lp_test_conv.c b/src/gallium/drivers/llvmpipe/lp_test_conv.c +index 9ae148866af38..05aaa1b4fcdab 100644 +--- a/src/gallium/drivers/llvmpipe/lp_test_conv.c ++++ b/src/gallium/drivers/llvmpipe/lp_test_conv.c +@@ -112,9 +112,11 @@ add_conv_test(struct gallivm_state *gallivm, + LLVMValueRef src[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef dst[LP_MAX_VECTOR_LENGTH]; + unsigned i; ++ LLVMTypeRef src_vec_type = lp_build_vec_type(gallivm, src_type); ++ LLVMTypeRef dst_vec_type = lp_build_vec_type(gallivm, dst_type); + +- args[0] = LLVMPointerType(lp_build_vec_type(gallivm, src_type), 0); +- args[1] = LLVMPointerType(lp_build_vec_type(gallivm, dst_type), 0); ++ args[0] = LLVMPointerType(src_vec_type, 0); ++ args[1] = LLVMPointerType(dst_vec_type, 0); + + func = LLVMAddFunction(module, "test", + LLVMFunctionType(LLVMVoidTypeInContext(context), +@@ -128,15 +130,15 @@ add_conv_test(struct gallivm_state *gallivm, + + for(i = 0; i < num_srcs; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32TypeInContext(context), i, 0); +- LLVMValueRef ptr = LLVMBuildGEP(builder, src_ptr, &index, 1, ""); +- src[i] = LLVMBuildLoad(builder, ptr, ""); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, src_vec_type, src_ptr, &index, 1, ""); ++ src[i] = LLVMBuildLoad2(builder, src_vec_type, ptr, ""); + } + + lp_build_conv(gallivm, src_type, dst_type, src, num_srcs, dst, num_dsts); + + for(i = 0; i < num_dsts; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32TypeInContext(context), i, 0); +- LLVMValueRef ptr = LLVMBuildGEP(builder, dst_ptr, &index, 1, ""); ++ LLVMValueRef ptr = LLVMBuildGEP2(builder, dst_vec_type, dst_ptr, &index, 1, ""); + LLVMBuildStore(builder, dst[i], ptr); + } + +-- +GitLab + + +From 9fe8e5ccf7a18c02634be4e80bb15e854e95e78a Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 14:11:30 +1000 +Subject: [PATCH 2/6] gallivm/llvmpipe: add opaque pointers support to sampler + +This adds explicit context types wiring through the sampler code + +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18947> +--- + src/gallium/auxiliary/draw/draw_llvm.c | 4 ++ + src/gallium/auxiliary/draw/draw_llvm_sample.c | 18 +++-- + src/gallium/auxiliary/gallivm/lp_bld_nir.h | 2 + + .../auxiliary/gallivm/lp_bld_nir_soa.c | 8 +++ + src/gallium/auxiliary/gallivm/lp_bld_sample.c | 20 +++--- + src/gallium/auxiliary/gallivm/lp_bld_sample.h | 23 +++++++ + .../auxiliary/gallivm/lp_bld_sample_soa.c | 69 ++++++++++++++----- + src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 4 ++ + .../auxiliary/gallivm/lp_bld_tgsi_soa.c | 16 +++++ + src/gallium/drivers/llvmpipe/lp_state_cs.c | 1 + + src/gallium/drivers/llvmpipe/lp_state_fs.c | 2 + + src/gallium/drivers/llvmpipe/lp_tex_sample.c | 21 ++++-- + 12 files changed, 148 insertions(+), 40 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c +index 3bdc8775bd7e5..16c93ec85f24e 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm.c ++++ b/src/gallium/auxiliary/draw/draw_llvm.c +@@ -965,6 +965,7 @@ generate_vs(struct draw_llvm_variant *variant, + params.consts_ptr = consts_ptr; + params.system_values = system_values; + params.inputs = inputs; ++ params.context_type = variant->context_type; + params.context_ptr = context_ptr; + params.sampler = draw_sampler; + params.info = &llvm->draw->vs.vertex_shader->info; +@@ -2872,6 +2873,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, + params.mask = &mask; + params.consts_ptr = consts_ptr; + params.system_values = &system_values; ++ params.context_type = variant->context_type; + params.context_ptr = context_ptr; + params.sampler = sampler; + params.info = &llvm->draw->gs.geometry_shader->info; +@@ -3533,6 +3535,7 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, + params.mask = &mask; + params.consts_ptr = consts_ptr; + params.system_values = &system_values; ++ params.context_type = variant->context_type; + params.context_ptr = context_ptr; + params.sampler = sampler; + params.info = &llvm->draw->tcs.tess_ctrl_shader->info; +@@ -4062,6 +4065,7 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, + params.mask = &mask; + params.consts_ptr = consts_ptr; + params.system_values = &system_values; ++ params.context_type = variant->context_type; + params.context_ptr = context_ptr; + params.sampler = sampler; + params.info = &llvm->draw->tes.tess_eval_shader->info; +diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c +index 6032f5b2a002f..5a48fb17caf2b 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c ++++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c +@@ -100,6 +100,7 @@ struct draw_llvm_image_soa + */ + static LLVMValueRef + draw_llvm_texture_member(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, + LLVMValueRef texture_unit_offset, +@@ -128,7 +129,7 @@ draw_llvm_texture_member(struct gallivm_state *gallivm, + /* context[0].textures[unit].member */ + indices[3] = lp_build_const_int32(gallivm, member_index); + +- ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); ++ ptr = LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + + if (emit_load) + res = LLVMBuildLoad(builder, ptr, ""); +@@ -151,6 +152,7 @@ draw_llvm_texture_member(struct gallivm_state *gallivm, + */ + static LLVMValueRef + draw_llvm_sampler_member(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit, + unsigned member_index, +@@ -173,7 +175,7 @@ draw_llvm_sampler_member(struct gallivm_state *gallivm, + /* context[0].samplers[unit].member */ + indices[3] = lp_build_const_int32(gallivm, member_index); + +- ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); ++ ptr = LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + + if (emit_load) + res = LLVMBuildLoad(builder, ptr, ""); +@@ -195,6 +197,7 @@ draw_llvm_sampler_member(struct gallivm_state *gallivm, + */ + static LLVMValueRef + draw_llvm_image_member(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned image_unit, + LLVMValueRef image_unit_offset, +@@ -223,7 +226,7 @@ draw_llvm_image_member(struct gallivm_state *gallivm, + /* context[0].textures[unit].member */ + indices[3] = lp_build_const_int32(gallivm, member_index); + +- ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); ++ ptr = LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + + if (emit_load) + res = LLVMBuildLoad(builder, ptr, ""); +@@ -247,11 +250,12 @@ draw_llvm_image_member(struct gallivm_state *gallivm, + #define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + draw_llvm_texture_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ + LLVMValueRef context_ptr, \ + unsigned texture_unit, \ + LLVMValueRef texture_unit_offset) \ + { \ +- return draw_llvm_texture_member(gallivm, context_ptr, \ ++ return draw_llvm_texture_member(gallivm, context_type, context_ptr, \ + texture_unit, texture_unit_offset, \ + _index, #_name, _emit_load ); \ + } +@@ -272,10 +276,11 @@ DRAW_LLVM_TEXTURE_MEMBER(sample_stride, DRAW_JIT_TEXTURE_SAMPLE_STRIDE, TRUE) + #define DRAW_LLVM_SAMPLER_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + draw_llvm_sampler_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ + LLVMValueRef context_ptr, \ + unsigned sampler_unit) \ + { \ +- return draw_llvm_sampler_member(gallivm, context_ptr, \ ++ return draw_llvm_sampler_member(gallivm, context_type, context_ptr, \ + sampler_unit, _index, #_name, _emit_load ); \ + } + +@@ -289,10 +294,11 @@ DRAW_LLVM_SAMPLER_MEMBER(max_aniso, DRAW_JIT_SAMPLER_MAX_ANISO, TRUE) + #define DRAW_LLVM_IMAGE_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + draw_llvm_image_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ + LLVMValueRef context_ptr, \ + unsigned image_unit, LLVMValueRef image_unit_offset) \ + { \ +- return draw_llvm_image_member(gallivm, context_ptr, \ ++ return draw_llvm_image_member(gallivm, context_type, context_ptr, \ + image_unit, image_unit_offset, \ + _index, #_name, _emit_load ); \ + } +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.h b/src/gallium/auxiliary/gallivm/lp_bld_nir.h +index 922208d8603d5..727837e9a5390 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.h +@@ -246,7 +246,9 @@ struct lp_build_nir_soa_context + LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS]; + const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS]; + LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS]; ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; ++ LLVMTypeRef thread_data_type; + LLVMValueRef thread_data_ptr; + + LLVMValueRef ssbo_ptr; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +index dafbffb344833..443bf4fea8afd 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +@@ -1613,7 +1613,9 @@ static void emit_image_op(struct lp_build_nir_context *bld_base, + struct gallivm_state *gallivm = bld_base->base.gallivm; + + params->type = bld_base->base.type; ++ params->context_type = bld->context_type; + params->context_ptr = bld->context_ptr; ++ params->thread_data_type = bld->thread_data_type; + params->thread_data_ptr = bld->thread_data_ptr; + params->exec_mask = mask_vec(bld_base); + +@@ -1634,6 +1636,7 @@ static void emit_image_size(struct lp_build_nir_context *bld_base, + struct gallivm_state *gallivm = bld_base->base.gallivm; + + params->int_type = bld_base->int_bld.type; ++ params->context_type = bld->context_type; + params->context_ptr = bld->context_ptr; + + if (params->texture_unit_offset) +@@ -1691,7 +1694,9 @@ static void emit_tex(struct lp_build_nir_context *bld_base, + LLVMBuilderRef builder = bld_base->base.gallivm->builder; + + params->type = bld_base->base.type; ++ params->context_type = bld->context_type; + params->context_ptr = bld->context_ptr; ++ params->thread_data_type = bld->thread_data_type; + params->thread_data_ptr = bld->thread_data_ptr; + + if (params->texture_index_offset && bld_base->shader->info.stage != MESA_SHADER_FRAGMENT) { +@@ -1774,6 +1779,7 @@ static void emit_tex_size(struct lp_build_nir_context *bld_base, + struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; + + params->int_type = bld_base->int_bld.type; ++ params->context_type = bld->context_type; + params->context_ptr = bld->context_ptr; + + if (params->texture_unit_offset) +@@ -2847,7 +2853,9 @@ void lp_build_nir_soa(struct gallivm_state *gallivm, + bld.sampler = params->sampler; + // bld.bld_base.info = params->info; + ++ bld.context_type = params->context_type; + bld.context_ptr = params->context_ptr; ++ bld.thread_data_type = params->thread_data_type; + bld.thread_data_ptr = params->thread_data_ptr; + bld.bld_base.aniso_filter_table = params->aniso_filter_table; + bld.image = params->image; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +index bb7b422346575..cdbf737031a8c 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +@@ -266,7 +266,7 @@ lp_build_pmin(struct lp_build_sample_context *bld, + boolean pmin_per_quad = pmin_bld->type.length != length; + unsigned i; + +- first_level = bld->dynamic_state->first_level(bld->gallivm, ++ first_level = bld->dynamic_state->first_level(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); + first_level_vec = lp_build_broadcast_scalar(int_size_bld, first_level); + int_size = lp_build_minify(int_size_bld, bld->int_size, first_level_vec, TRUE); +@@ -376,7 +376,7 @@ lp_build_rho(struct lp_build_sample_context *bld, + * the messy cube maps for now) when requested. + */ + +- first_level = bld->dynamic_state->first_level(bld->gallivm, ++ first_level = bld->dynamic_state->first_level(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); + first_level_vec = lp_build_broadcast_scalar(int_size_bld, first_level); + int_size = lp_build_minify(int_size_bld, bld->int_size, first_level_vec, TRUE); +@@ -854,7 +854,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, + * This is hit during mipmap generation. + */ + LLVMValueRef min_lod = +- dynamic_state->min_lod(bld->gallivm, ++ dynamic_state->min_lod(bld->gallivm, bld->context_type, + bld->context_ptr, sampler_unit); + + lod = lp_build_broadcast_scalar(lodf_bld, min_lod); +@@ -952,7 +952,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, + /* add sampler lod bias */ + if (bld->static_sampler_state->lod_bias_non_zero) { + LLVMValueRef sampler_lod_bias = +- dynamic_state->lod_bias(bld->gallivm, ++ dynamic_state->lod_bias(bld->gallivm, bld->context_type, + bld->context_ptr, sampler_unit); + sampler_lod_bias = lp_build_broadcast_scalar(lodf_bld, + sampler_lod_bias); +@@ -966,7 +966,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, + /* clamp lod */ + if (bld->static_sampler_state->apply_max_lod) { + LLVMValueRef max_lod = +- dynamic_state->max_lod(bld->gallivm, ++ dynamic_state->max_lod(bld->gallivm, bld->context_type, + bld->context_ptr, sampler_unit); + max_lod = lp_build_broadcast_scalar(lodf_bld, max_lod); + +@@ -974,7 +974,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, + } + if (bld->static_sampler_state->apply_min_lod) { + LLVMValueRef min_lod = +- dynamic_state->min_lod(bld->gallivm, ++ dynamic_state->min_lod(bld->gallivm, bld->context_type, + bld->context_ptr, sampler_unit); + min_lod = lp_build_broadcast_scalar(lodf_bld, min_lod); + +@@ -1032,9 +1032,9 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld, + struct lp_sampler_dynamic_state *dynamic_state = bld->dynamic_state; + LLVMValueRef first_level, last_level, level; + +- first_level = dynamic_state->first_level(bld->gallivm, ++ first_level = dynamic_state->first_level(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); +- last_level = dynamic_state->last_level(bld->gallivm, ++ last_level = dynamic_state->last_level(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); + first_level = lp_build_broadcast_scalar(leveli_bld, first_level); + last_level = lp_build_broadcast_scalar(leveli_bld, last_level); +@@ -1094,9 +1094,9 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + + assert(bld->num_lods == bld->num_mips); + +- first_level = dynamic_state->first_level(bld->gallivm, ++ first_level = dynamic_state->first_level(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); +- last_level = dynamic_state->last_level(bld->gallivm, ++ last_level = dynamic_state->last_level(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); + first_level = lp_build_broadcast_scalar(leveli_bld, first_level); + last_level = lp_build_broadcast_scalar(leveli_bld, last_level); +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h +index 91d946545c81c..ecebc8fc631fe 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h +@@ -109,7 +109,9 @@ struct lp_sampler_params + unsigned sampler_index; + LLVMValueRef texture_index_offset; + unsigned sample_key; ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; ++ LLVMTypeRef thread_data_type; + LLVMValueRef thread_data_ptr; + const LLVMValueRef *coords; + const LLVMValueRef *offsets; +@@ -127,6 +129,7 @@ struct lp_sampler_size_query_params + unsigned texture_unit; + LLVMValueRef texture_unit_offset; + unsigned target; ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; + boolean is_sviewinfo; + bool samples_only; +@@ -149,7 +152,9 @@ struct lp_img_params + unsigned target; + LLVMAtomicRMWBinOp op; + LLVMValueRef exec_mask; ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; ++ LLVMTypeRef thread_data_type; + LLVMValueRef thread_data_ptr; + const LLVMValueRef *coords; + LLVMValueRef ms_index; +@@ -230,66 +235,77 @@ struct lp_sampler_dynamic_state + /** Obtain the base texture width (or number of elements) (returns int32) */ + LLVMValueRef + (*width)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain the base texture height (returns int32) */ + LLVMValueRef + (*height)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain the base texture depth (or array size) (returns int32) */ + LLVMValueRef + (*depth)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain the first mipmap level (base level) (returns int32) */ + LLVMValueRef + (*first_level)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain the number of mipmap levels minus one (returns int32) */ + LLVMValueRef + (*last_level)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain stride in bytes between image rows/blocks (returns int32) */ + LLVMValueRef + (*row_stride)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain stride in bytes between image slices (returns int32) */ + LLVMValueRef + (*img_stride)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain pointer to base of texture */ + LLVMValueRef + (*base_ptr)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain pointer to array of mipmap offsets */ + LLVMValueRef + (*mip_offsets)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain number of samples (returns int32) */ + LLVMValueRef + (*num_samples)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain multisample stride (returns int32) */ + LLVMValueRef + (*sample_stride)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + +@@ -298,30 +314,35 @@ struct lp_sampler_dynamic_state + /** Obtain texture min lod (returns float) */ + LLVMValueRef + (*min_lod)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain texture max lod (returns float) */ + LLVMValueRef + (*max_lod)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain texture lod bias (returns float) */ + LLVMValueRef + (*lod_bias)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain texture border color (returns ptr to float[4]) */ + LLVMValueRef + (*border_color)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain maximum anisotropy */ + LLVMValueRef + (*max_aniso)(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit); + +@@ -332,6 +353,7 @@ struct lp_sampler_dynamic_state + */ + LLVMValueRef + (*cache_ptr)(struct gallivm_state *gallivm, ++ LLVMTypeRef thread_data_type, + LLVMValueRef thread_data_ptr, + unsigned unit); + }; +@@ -440,6 +462,7 @@ struct lp_build_sample_context + + LLVMValueRef border_color_clamped; + ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; + + LLVMValueRef aniso_filter_table; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +index bf0453b3de284..c24833dafe123 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +@@ -2046,7 +2046,7 @@ lp_build_layer_coord(struct lp_build_sample_context *bld, + LLVMValueRef num_layers; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + +- num_layers = bld->dynamic_state->depth(bld->gallivm, ++ num_layers = bld->dynamic_state->depth(bld->gallivm, bld->context_type, + bld->context_ptr, texture_unit, NULL); + + if (out_of_bounds) { +@@ -2611,6 +2611,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld, + + if (aniso) + max_aniso = bld->dynamic_state->max_aniso(bld->gallivm, ++ bld->context_type, + bld->context_ptr, + sampler_index); + +@@ -2625,9 +2626,11 @@ lp_build_sample_common(struct lp_build_sample_context *bld, + if (is_lodq) { + LLVMValueRef last_level; + last_level = bld->dynamic_state->last_level(bld->gallivm, ++ bld->context_type, + bld->context_ptr, + texture_index, NULL); + first_level = bld->dynamic_state->first_level(bld->gallivm, ++ bld->context_type, + bld->context_ptr, + texture_index, NULL); + last_level = lp_build_sub(&bld->int_bld, last_level, first_level); +@@ -2674,7 +2677,9 @@ lp_build_sample_common(struct lp_build_sample_context *bld, + unreachable("Bad mip_filter value in lp_build_sample_soa()"); + case PIPE_TEX_MIPFILTER_NONE: + /* always use mip level 0 */ +- first_level = bld->dynamic_state->first_level(bld->gallivm, bld->context_ptr, ++ first_level = bld->dynamic_state->first_level(bld->gallivm, ++ bld->context_type, ++ bld->context_ptr, + texture_index, NULL); + first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level); + *ilevel0 = first_level; +@@ -2702,6 +2707,7 @@ lp_build_clamp_border_color(struct lp_build_sample_context *bld, + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef border_color_ptr = + bld->dynamic_state->border_color(gallivm, ++ bld->context_type, + bld->context_ptr, sampler_unit); + LLVMValueRef border_color; + const struct util_format_description *format_desc = bld->format_desc; +@@ -3128,6 +3134,7 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, + assert(bld->num_mips == 1); + if (bld->static_texture_state->target != PIPE_BUFFER) { + ilevel = bld->dynamic_state->first_level(bld->gallivm, ++ bld->context_type, + bld->context_ptr, texture_unit, NULL); + } + else { +@@ -3197,6 +3204,7 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, + if (bld->fetch_ms) { + LLVMValueRef num_samples; + num_samples = bld->dynamic_state->num_samples(bld->gallivm, ++ bld->context_type, + bld->context_ptr, texture_unit, NULL); + out1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, ms_index, int_coord_bld->zero); + out_of_bounds = lp_build_or(int_coord_bld, out_of_bounds, out1); +@@ -3295,7 +3303,9 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + unsigned sample_key, + unsigned texture_index, + unsigned sampler_index, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, ++ LLVMTypeRef thread_data_type, + LLVMValueRef thread_data_ptr, + const LLVMValueRef *coords, + const LLVMValueRef *offsets, +@@ -3376,6 +3386,7 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + /* Setup our build context */ + memset(&bld, 0, sizeof bld); + bld.gallivm = gallivm; ++ bld.context_type = context_type; + bld.context_ptr = context_ptr; + bld.aniso_filter_table = aniso_filter_table; + bld.static_sampler_state = &derived_sampler_state; +@@ -3559,22 +3570,23 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + lp_build_context_init(&bld.lodi_bld, gallivm, bld.lodi_type); + + /* Get the dynamic state */ +- LLVMValueRef tex_width = dynamic_state->width(gallivm, ++ LLVMValueRef tex_width = dynamic_state->width(gallivm, context_type, + context_ptr, texture_index, + NULL); +- bld.row_stride_array = dynamic_state->row_stride(gallivm, ++ bld.row_stride_array = dynamic_state->row_stride(gallivm, context_type, + context_ptr, texture_index, NULL); +- bld.img_stride_array = dynamic_state->img_stride(gallivm, ++ bld.img_stride_array = dynamic_state->img_stride(gallivm, context_type, + context_ptr, texture_index, NULL); +- bld.base_ptr = dynamic_state->base_ptr(gallivm, ++ bld.base_ptr = dynamic_state->base_ptr(gallivm, context_type, + context_ptr, texture_index, NULL); +- bld.mip_offsets = dynamic_state->mip_offsets(gallivm, ++ bld.mip_offsets = dynamic_state->mip_offsets(gallivm, context_type, + context_ptr, texture_index, NULL); + + if (fetch_ms) { + bld.sample_stride = + lp_build_broadcast_scalar(&bld.int_coord_bld, + dynamic_state->sample_stride(gallivm, ++ context_type, + context_ptr, + texture_index, + NULL)); +@@ -3583,7 +3595,7 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + /* Note that mip_offsets is an array[level] of offsets to texture images */ + + if (dynamic_state->cache_ptr && thread_data_ptr) { +- bld.cache = dynamic_state->cache_ptr(gallivm, ++ bld.cache = dynamic_state->cache_ptr(gallivm, thread_data_type, + thread_data_ptr, texture_index); + } + +@@ -3620,7 +3632,7 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + LLVMConstInt(i32t, 0, 0), ""); + if (dims >= 2) { + LLVMValueRef tex_height = +- dynamic_state->height(gallivm, ++ dynamic_state->height(gallivm, context_type, + context_ptr, texture_index, NULL); + bld.int_size = LLVMBuildInsertElement(builder, bld.int_size, + tex_height, +@@ -3636,7 +3648,7 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + LLVMConstInt(i32t, 1, 0), ""); + if (dims >= 3) { + LLVMValueRef tex_depth = +- dynamic_state->depth(gallivm, context_ptr, ++ dynamic_state->depth(gallivm, context_type, context_ptr, + texture_index, NULL); + bld.int_size = LLVMBuildInsertElement(builder, bld.int_size, + tex_depth, +@@ -3800,6 +3812,7 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + bld4.no_rho_approx = bld.no_rho_approx; + bld4.no_brilinear = bld.no_brilinear; + bld4.gallivm = bld.gallivm; ++ bld4.context_type = bld.context_type; + bld4.context_ptr = bld.context_ptr; + bld4.aniso_filter_table = aniso_filter_table; + bld4.static_texture_state = bld.static_texture_state; +@@ -4001,6 +4014,8 @@ lp_build_sample_gen_func(struct gallivm_state *gallivm, + const struct lp_static_sampler_state *static_sampler_state, + struct lp_sampler_dynamic_state *dynamic_state, + struct lp_type type, ++ LLVMTypeRef context_type, ++ LLVMTypeRef thread_data_type, + unsigned texture_index, + unsigned sampler_index, + LLVMValueRef function, +@@ -4106,7 +4121,9 @@ lp_build_sample_gen_func(struct gallivm_state *gallivm, + sample_key, + texture_index, + sampler_index, ++ context_type, + context_ptr, ++ thread_data_type, + thread_data_ptr, + coords, + offsets, +@@ -4254,6 +4271,8 @@ lp_build_sample_soa_func(struct gallivm_state *gallivm, + static_sampler_state, + dynamic_state, + params->type, ++ params->context_type, ++ params->thread_data_type, + texture_index, + sampler_index, + function, +@@ -4376,7 +4395,9 @@ lp_build_sample_soa(const struct lp_static_texture_state *static_texture_state, + params->sample_key, + params->texture_index, + params->sampler_index, ++ params->context_type, + params->context_ptr, ++ params->thread_data_type, + params->thread_data_ptr, + params->coords, + params->offsets, +@@ -4397,6 +4418,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + { + LLVMValueRef first_level = NULL; + const unsigned num_lods = 1; ++ LLVMTypeRef context_type = params->context_type; + LLVMValueRef context_ptr = params->context_ptr; + const unsigned texture_unit = params->texture_unit; + const enum pipe_texture_target target = params->target; +@@ -4459,6 +4481,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + lp_build_broadcast(gallivm, + lp_build_vec_type(gallivm, params->int_type), + dynamic_state->num_samples(gallivm, ++ context_type, + context_ptr, + texture_unit, + texture_unit_offset)); +@@ -4471,7 +4494,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + /* FIXME: this needs to honor per-element lod */ + lod = LLVMBuildExtractElement(gallivm->builder, params->explicit_lod, + lp_build_const_int32(gallivm, 0), ""); +- first_level = dynamic_state->first_level(gallivm, ++ first_level = dynamic_state->first_level(gallivm, context_type, + context_ptr, texture_unit, + texture_unit_offset); + level = LLVMBuildAdd(gallivm->builder, lod, first_level, "level"); +@@ -4497,6 +4520,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + res_bh = bh = 1; + size = LLVMBuildInsertElement(gallivm->builder, size, + dynamic_state->width(gallivm, ++ context_type, + context_ptr, + texture_unit, + texture_unit_offset), +@@ -4512,7 +4536,9 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + lp_build_const_int32(gallivm, 0), ""); + if (dims >= 2) { + size = LLVMBuildInsertElement(gallivm->builder, size, +- dynamic_state->height(gallivm, context_ptr, ++ dynamic_state->height(gallivm, ++ context_type, ++ context_ptr, + texture_unit, + texture_unit_offset), + lp_build_const_int32(gallivm, 1), ""); +@@ -4530,6 +4556,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + if (dims >= 3) { + size = LLVMBuildInsertElement(gallivm->builder, size, + dynamic_state->depth(gallivm, ++ context_type, + context_ptr, + texture_unit, + texture_unit_offset), +@@ -4550,7 +4577,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + tex_blocksize_log2, view_blocksize); + + if (has_array) { +- LLVMValueRef layers = dynamic_state->depth(gallivm, ++ LLVMValueRef layers = dynamic_state->depth(gallivm, context_type, + context_ptr, texture_unit, + texture_unit_offset); + if (target == PIPE_TEXTURE_CUBE_ARRAY) { +@@ -4577,7 +4604,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + + /* everything is scalar for now */ + lp_build_context_init(&leveli_bld, gallivm, lp_type_int_vec(32, 32)); +- last_level = dynamic_state->last_level(gallivm, ++ last_level = dynamic_state->last_level(gallivm, context_type, + context_ptr, texture_unit, + texture_unit_offset); + +@@ -4624,7 +4651,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, + else { + LLVMValueRef last_level; + +- last_level = dynamic_state->last_level(gallivm, ++ last_level = dynamic_state->last_level(gallivm, context_type, + context_ptr, texture_unit, + texture_unit_offset); + num_levels = lp_build_sub(&bld_int_scalar, last_level, first_level); +@@ -4784,31 +4811,39 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, + } + + LLVMValueRef row_stride = dynamic_state->row_stride(gallivm, ++ params->context_type, + params->context_ptr, + params->image_index, NULL); + LLVMValueRef img_stride = dynamic_state->img_stride(gallivm, ++ params->context_type, + params->context_ptr, + params->image_index, NULL); + LLVMValueRef base_ptr = dynamic_state->base_ptr(gallivm, ++ params->context_type, + params->context_ptr, + params->image_index, NULL); + LLVMValueRef width = dynamic_state->width(gallivm, +- params->context_ptr, ++ params->context_type, ++ params->context_ptr, + params->image_index, NULL); + LLVMValueRef height = dynamic_state->height(gallivm, ++ params->context_type, + params->context_ptr, + params->image_index, NULL); + LLVMValueRef depth = dynamic_state->depth(gallivm, +- params->context_ptr, ++ params->context_type, ++ params->context_ptr, + params->image_index, NULL); + LLVMValueRef num_samples = NULL, sample_stride = NULL; + + LLVMValueRef ms_index = params->ms_index; + if (ms_index) { + num_samples = dynamic_state->num_samples(gallivm, ++ params->context_type, + params->context_ptr, + params->image_index, NULL); + sample_stride = dynamic_state->sample_stride(gallivm, ++ params->context_type, + params->context_ptr, + params->image_index, NULL); + } +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +index 31067e0165491..d335a92388fe4 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +@@ -267,7 +267,9 @@ struct lp_build_tgsi_params { + LLVMValueRef const_sizes_ptr; + const struct lp_bld_tgsi_system_values *system_values; + const LLVMValueRef (*inputs)[4]; ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; ++ LLVMTypeRef thread_data_type; + LLVMValueRef thread_data_ptr; + const struct lp_build_sampler_soa *sampler; + const struct tgsi_shader_info *info; +@@ -521,7 +523,9 @@ struct lp_build_tgsi_soa_context + LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS]; + const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS]; + LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS]; ++ LLVMTypeRef context_type; + LLVMValueRef context_ptr; ++ LLVMTypeRef thread_data_type; + LLVMValueRef thread_data_ptr; + + LLVMValueRef ssbo_ptr; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +index f33de194484a0..d98d20e11e5d3 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +@@ -2273,7 +2273,9 @@ emit_tex( struct lp_build_tgsi_soa_context *bld, + params.sample_key = sample_key; + params.texture_index = unit; + params.sampler_index = unit; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; ++ params.thread_data_type = bld->thread_data_type; + params.thread_data_ptr = bld->thread_data_ptr; + params.coords = coords; + params.offsets = offsets; +@@ -2442,7 +2444,9 @@ emit_sample(struct lp_build_tgsi_soa_context *bld, + params.sample_key = sample_key; + params.texture_index = texture_unit; + params.sampler_index = sampler_unit; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; ++ params.thread_data_type = bld->thread_data_type; + params.thread_data_ptr = bld->thread_data_ptr; + params.coords = coords; + params.offsets = offsets; +@@ -2580,7 +2584,9 @@ emit_fetch_texels( struct lp_build_tgsi_soa_context *bld, + * can exceed this. + */ + params.sampler_index = 0; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; ++ params.thread_data_type = bld->thread_data_type; + params.thread_data_ptr = bld->thread_data_ptr; + params.coords = coords; + params.offsets = offsets; +@@ -2665,6 +2671,7 @@ emit_size_query( struct lp_build_tgsi_soa_context *bld, + params.texture_unit = unit; + params.texture_unit_offset = NULL; + params.target = pipe_target; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; + params.is_sviewinfo = TRUE; + params.lod_property = lod_property; +@@ -3453,7 +3460,9 @@ img_load_emit( + memset(¶ms, 0, sizeof(params)); + + params.type = bld->bld_base.base.type; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; ++ params.thread_data_type = bld->thread_data_type; + params.thread_data_ptr = bld->thread_data_ptr; + params.coords = coords; + params.outdata = emit_data->output; +@@ -3601,7 +3610,9 @@ img_store_emit( + memset(¶ms, 0, sizeof(params)); + + params.type = bld->bld_base.base.type; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; ++ params.thread_data_type = bld->thread_data_type; + params.thread_data_ptr = bld->thread_data_ptr; + params.coords = coords; + params.outdata = NULL; +@@ -3710,6 +3721,7 @@ resq_emit( + params.int_type = bld->bld_base.int_bld.type; + params.texture_unit = buf; + params.target = tgsi_to_pipe_tex_target(target); ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; + params.sizes_out = emit_data->output; + +@@ -3751,7 +3763,9 @@ img_atomic_emit( + memset(¶ms, 0, sizeof(params)); + + params.type = bld->bld_base.base.type; ++ params.context_type = bld->context_type; + params.context_ptr = bld->context_ptr; ++ params.thread_data_type = bld->thread_data_type; + params.thread_data_ptr = bld->thread_data_ptr; + params.exec_mask = mask_vec(bld_base); + params.image_index = emit_data->inst->Src[0].Register.Index; +@@ -4483,7 +4497,9 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, + bld.sampler = params->sampler; + bld.bld_base.info = params->info; + bld.indirect_files = params->info->indirect_files; ++ bld.context_type = params->context_type; + bld.context_ptr = params->context_ptr; ++ bld.thread_data_type = params->thread_data_type; + bld.thread_data_ptr = params->thread_data_ptr; + bld.image = params->image; + bld.shared_ptr = params->shared_ptr; +diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c +index 86f7b65585ae5..22ac92e1fb7da 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c +@@ -447,6 +447,7 @@ generate_compute(struct llvmpipe_context *lp, + params.mask = &mask; + params.consts_ptr = consts_ptr; + params.system_values = &system_values; ++ params.context_type = variant->jit_cs_context_type; + params.context_ptr = context_ptr; + params.sampler = sampler; + params.info = &shader->info.base; +diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c +index d1dbd9d787dc1..e10e10836faa3 100644 +--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c ++++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c +@@ -1052,7 +1052,9 @@ generate_fs_loop(struct gallivm_state *gallivm, + params.consts_ptr = consts_ptr; + params.system_values = &system_values; + params.inputs = interp->inputs; ++ params.context_type = context_type; + params.context_ptr = context_ptr; ++ params.thread_data_type = thread_data_type; + params.thread_data_ptr = thread_data_ptr; + params.sampler = sampler; + params.info = &shader->info.base; +diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c +index 0812bc72cd098..8700eda253332 100644 +--- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c ++++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c +@@ -110,6 +110,7 @@ struct lp_llvm_image_soa + */ + static LLVMValueRef + lp_llvm_texture_member(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned texture_unit, + LLVMValueRef texture_unit_offset, +@@ -144,7 +145,7 @@ lp_llvm_texture_member(struct gallivm_state *gallivm, + indices[3] = lp_build_const_int32(gallivm, member_index); + + LLVMValueRef ptr = +- LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); ++ LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; + +@@ -166,11 +167,12 @@ lp_llvm_texture_member(struct gallivm_state *gallivm, + #define LP_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + lp_llvm_texture_##_name(struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ + LLVMValueRef context_ptr, \ + unsigned texture_unit, \ + LLVMValueRef texture_unit_offset) \ + { \ +- return lp_llvm_texture_member(gallivm, context_ptr, \ ++ return lp_llvm_texture_member(gallivm, context_type, context_ptr, \ + texture_unit, texture_unit_offset, \ + _index, #_name, _emit_load ); \ + } +@@ -199,6 +201,7 @@ LP_LLVM_TEXTURE_MEMBER(sample_stride, LP_JIT_TEXTURE_SAMPLE_STRIDE, TRUE) + */ + static LLVMValueRef + lp_llvm_sampler_member(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned sampler_unit, + unsigned member_index, +@@ -220,7 +223,7 @@ lp_llvm_sampler_member(struct gallivm_state *gallivm, + indices[3] = lp_build_const_int32(gallivm, member_index); + + LLVMValueRef ptr = +- LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); ++ LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; + +@@ -233,10 +236,11 @@ lp_llvm_sampler_member(struct gallivm_state *gallivm, + #define LP_LLVM_SAMPLER_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + lp_llvm_sampler_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ + LLVMValueRef context_ptr, \ + unsigned sampler_unit) \ + { \ +- return lp_llvm_sampler_member(gallivm, context_ptr, \ ++ return lp_llvm_sampler_member(gallivm, context_type, context_ptr, \ + sampler_unit, _index, #_name, _emit_load ); \ + } + +@@ -258,6 +262,7 @@ LP_LLVM_SAMPLER_MEMBER(max_aniso, LP_JIT_SAMPLER_MAX_ANISO, TRUE) + */ + static LLVMValueRef + lp_llvm_image_member(struct gallivm_state *gallivm, ++ LLVMTypeRef context_type, + LLVMValueRef context_ptr, + unsigned image_unit, + LLVMValueRef image_unit_offset, +@@ -285,7 +290,7 @@ lp_llvm_image_member(struct gallivm_state *gallivm, + indices[3] = lp_build_const_int32(gallivm, member_index); + + LLVMValueRef ptr = +- LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); ++ LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; + +@@ -307,10 +312,11 @@ lp_llvm_image_member(struct gallivm_state *gallivm, + #define LP_LLVM_IMAGE_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + lp_llvm_image_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ + LLVMValueRef context_ptr, \ + unsigned image_unit, LLVMValueRef image_unit_offset) \ + { \ +- return lp_llvm_image_member(gallivm, context_ptr, \ ++ return lp_llvm_image_member(gallivm, context_type, context_ptr, \ + image_unit, image_unit_offset, \ + _index, #_name, _emit_load ); \ + } +@@ -329,13 +335,14 @@ LP_LLVM_IMAGE_MEMBER(sample_stride, LP_JIT_IMAGE_SAMPLE_STRIDE, TRUE) + #if LP_USE_TEXTURE_CACHE + static LLVMValueRef + lp_llvm_texture_cache_ptr(struct gallivm_state *gallivm, ++ LLVMTypeRef thread_data_type, + LLVMValueRef thread_data_ptr, + unsigned unit) + { + /* We use the same cache for all units */ + (void)unit; + +- return lp_jit_thread_data_cache(gallivm, LLVMGetElementType(LLVMTypeOf(thread_data_ptr)), thread_data_ptr); ++ return lp_jit_thread_data_cache(gallivm, thread_data_type, thread_data_ptr); + } + #endif + +-- +GitLab + + +From 02c675b1960a11f02b91018c519d9da6b371615b Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 14:41:20 +1000 +Subject: [PATCH 3/6] draw/llvmpipe: move texture/sampler/image member load to + opaque. + +This removes the non-opaque paths from the draw/lp sampling code. + +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18947> +--- + src/gallium/auxiliary/draw/draw_llvm_sample.c | 24 ++++++++++++------- + src/gallium/drivers/llvmpipe/lp_tex_sample.c | 24 ++++++++++++++++--- + 2 files changed, 36 insertions(+), 12 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c +index 5a48fb17caf2b..cde003afcebe6 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c ++++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c +@@ -131,9 +131,11 @@ draw_llvm_texture_member(struct gallivm_state *gallivm, + + ptr = LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + +- if (emit_load) +- res = LLVMBuildLoad(builder, ptr, ""); +- else ++ if (emit_load) { ++ LLVMTypeRef tex_type = LLVMStructGetTypeAtIndex(context_type, DRAW_JIT_CTX_TEXTURES); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(tex_type), member_index); ++ res = LLVMBuildLoad2(builder, res_type, ptr, ""); ++ } else + res = ptr; + + lp_build_name(res, "context.texture%u.%s", texture_unit, member_name); +@@ -177,9 +179,11 @@ draw_llvm_sampler_member(struct gallivm_state *gallivm, + + ptr = LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + +- if (emit_load) +- res = LLVMBuildLoad(builder, ptr, ""); +- else ++ if (emit_load) { ++ LLVMTypeRef samp_type = LLVMStructGetTypeAtIndex(context_type, DRAW_JIT_CTX_SAMPLERS); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(samp_type), member_index); ++ res = LLVMBuildLoad2(builder, res_type, ptr, ""); ++ } else + res = ptr; + + lp_build_name(res, "context.sampler%u.%s", sampler_unit, member_name); +@@ -228,9 +232,11 @@ draw_llvm_image_member(struct gallivm_state *gallivm, + + ptr = LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + +- if (emit_load) +- res = LLVMBuildLoad(builder, ptr, ""); +- else ++ if (emit_load) { ++ LLVMTypeRef img_type = LLVMStructGetTypeAtIndex(context_type, DRAW_JIT_CTX_IMAGES); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(img_type), member_index); ++ res = LLVMBuildLoad2(builder, res_type, ptr, ""); ++ } else + res = ptr; + + lp_build_name(res, "context.image%u.%s", image_unit, member_name); +diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c +index 8700eda253332..e62ec9f6d8915 100644 +--- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c ++++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c +@@ -147,7 +147,13 @@ lp_llvm_texture_member(struct gallivm_state *gallivm, + LLVMValueRef ptr = + LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + +- LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; ++ LLVMValueRef res; ++ if (emit_load) { ++ LLVMTypeRef tex_type = LLVMStructGetTypeAtIndex(context_type, LP_JIT_CTX_TEXTURES); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(tex_type), member_index); ++ res = LLVMBuildLoad2(builder, res_type, ptr, ""); ++ } else ++ res = ptr; + + lp_build_name(res, "context.texture%u.%s", texture_unit, member_name); + +@@ -225,7 +231,13 @@ lp_llvm_sampler_member(struct gallivm_state *gallivm, + LLVMValueRef ptr = + LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + +- LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; ++ LLVMValueRef res; ++ if (emit_load) { ++ LLVMTypeRef samp_type = LLVMStructGetTypeAtIndex(context_type, LP_JIT_CTX_SAMPLERS); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(samp_type), member_index); ++ res = LLVMBuildLoad2(builder, res_type, ptr, ""); ++ } else ++ res = ptr; + + lp_build_name(res, "context.sampler%u.%s", sampler_unit, member_name); + +@@ -292,7 +304,13 @@ lp_llvm_image_member(struct gallivm_state *gallivm, + LLVMValueRef ptr = + LLVMBuildGEP2(builder, context_type, context_ptr, indices, ARRAY_SIZE(indices), ""); + +- LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; ++ LLVMValueRef res; ++ if (emit_load) { ++ LLVMTypeRef img_type = LLVMStructGetTypeAtIndex(context_type, LP_JIT_CTX_IMAGES); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(img_type), member_index); ++ res = LLVMBuildLoad2(builder, res_type, ptr, ""); ++ } else ++ res = ptr; + + lp_build_name(res, "context.image%u.%s", image_unit, member_name); + +-- +GitLab + + +From 1a9889ae12757e9bdc019cbd109783a3e93121b7 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 14:59:54 +1000 +Subject: [PATCH 4/6] draw/llvmpipe: add way to return pointer types to generic + code. + +Some of the generic code tries to load from things it has no +types for, mip offsets, row and image strides. + +Fix the interfaces to allow returning types for these. + +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18947> +--- + src/gallium/auxiliary/draw/draw_llvm_sample.c | 49 ++++++++++++++++--- + src/gallium/auxiliary/gallivm/lp_bld_sample.h | 12 +++-- + .../auxiliary/gallivm/lp_bld_sample_soa.c | 16 ++++-- + src/gallium/drivers/llvmpipe/lp_tex_sample.c | 49 ++++++++++++++++--- + 4 files changed, 104 insertions(+), 22 deletions(-) + +diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c +index cde003afcebe6..19e9937d57ac6 100644 +--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c ++++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c +@@ -106,7 +106,8 @@ draw_llvm_texture_member(struct gallivm_state *gallivm, + LLVMValueRef texture_unit_offset, + unsigned member_index, + const char *member_name, +- boolean emit_load) ++ boolean emit_load, ++ LLVMTypeRef *out_type) + { + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef indices[4]; +@@ -138,6 +139,12 @@ draw_llvm_texture_member(struct gallivm_state *gallivm, + } else + res = ptr; + ++ if (out_type) { ++ LLVMTypeRef tex_type = LLVMStructGetTypeAtIndex(context_type, DRAW_JIT_CTX_TEXTURES); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(tex_type), member_index); ++ *out_type = res_type; ++ } ++ + lp_build_name(res, "context.texture%u.%s", texture_unit, member_name); + + return res; +@@ -263,7 +270,21 @@ draw_llvm_image_member(struct gallivm_state *gallivm, + { \ + return draw_llvm_texture_member(gallivm, context_type, context_ptr, \ + texture_unit, texture_unit_offset, \ +- _index, #_name, _emit_load ); \ ++ _index, #_name, _emit_load, NULL ); \ ++ } ++ ++#define DRAW_LLVM_TEXTURE_MEMBER_OUTTYPE(_name, _index, _emit_load) \ ++ static LLVMValueRef \ ++ draw_llvm_texture_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ ++ LLVMValueRef context_ptr, \ ++ unsigned texture_unit, \ ++ LLVMValueRef texture_unit_offset, \ ++ LLVMTypeRef *out_type) \ ++ { \ ++ return draw_llvm_texture_member(gallivm, context_type, context_ptr, \ ++ texture_unit, texture_unit_offset, \ ++ _index, #_name, _emit_load, out_type); \ + } + + +@@ -273,9 +294,9 @@ DRAW_LLVM_TEXTURE_MEMBER(depth, DRAW_JIT_TEXTURE_DEPTH, TRUE) + DRAW_LLVM_TEXTURE_MEMBER(first_level,DRAW_JIT_TEXTURE_FIRST_LEVEL, TRUE) + DRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, TRUE) + DRAW_LLVM_TEXTURE_MEMBER(base_ptr, DRAW_JIT_TEXTURE_BASE, TRUE) +-DRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE) +-DRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE) +-DRAW_LLVM_TEXTURE_MEMBER(mip_offsets, DRAW_JIT_TEXTURE_MIP_OFFSETS, FALSE) ++DRAW_LLVM_TEXTURE_MEMBER_OUTTYPE(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE) ++DRAW_LLVM_TEXTURE_MEMBER_OUTTYPE(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE) ++DRAW_LLVM_TEXTURE_MEMBER_OUTTYPE(mip_offsets, DRAW_JIT_TEXTURE_MIP_OFFSETS, FALSE) + DRAW_LLVM_TEXTURE_MEMBER(num_samples, DRAW_JIT_TEXTURE_NUM_SAMPLES, TRUE) + DRAW_LLVM_TEXTURE_MEMBER(sample_stride, DRAW_JIT_TEXTURE_SAMPLE_STRIDE, TRUE) + +@@ -309,13 +330,27 @@ DRAW_LLVM_SAMPLER_MEMBER(max_aniso, DRAW_JIT_SAMPLER_MAX_ANISO, TRUE) + _index, #_name, _emit_load ); \ + } + ++#define DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(_name, _index, _emit_load) \ ++ static LLVMValueRef \ ++ draw_llvm_image_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ ++ LLVMValueRef context_ptr, \ ++ unsigned image_unit, LLVMValueRef image_unit_offset, \ ++ LLVMTypeRef *out_type) \ ++ { \ ++ assert(!out_type); \ ++ return draw_llvm_image_member(gallivm, context_type, context_ptr, \ ++ image_unit, image_unit_offset, \ ++ _index, #_name, _emit_load); \ ++ } ++ + + DRAW_LLVM_IMAGE_MEMBER(width, DRAW_JIT_IMAGE_WIDTH, TRUE) + DRAW_LLVM_IMAGE_MEMBER(height, DRAW_JIT_IMAGE_HEIGHT, TRUE) + DRAW_LLVM_IMAGE_MEMBER(depth, DRAW_JIT_IMAGE_DEPTH, TRUE) + DRAW_LLVM_IMAGE_MEMBER(base_ptr, DRAW_JIT_IMAGE_BASE, TRUE) +-DRAW_LLVM_IMAGE_MEMBER(row_stride, DRAW_JIT_IMAGE_ROW_STRIDE, TRUE) +-DRAW_LLVM_IMAGE_MEMBER(img_stride, DRAW_JIT_IMAGE_IMG_STRIDE, TRUE) ++DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(row_stride, DRAW_JIT_IMAGE_ROW_STRIDE, TRUE) ++DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(img_stride, DRAW_JIT_IMAGE_IMG_STRIDE, TRUE) + DRAW_LLVM_IMAGE_MEMBER(num_samples, DRAW_JIT_IMAGE_NUM_SAMPLES, TRUE) + DRAW_LLVM_IMAGE_MEMBER(sample_stride, DRAW_JIT_IMAGE_SAMPLE_STRIDE, TRUE) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h +index ecebc8fc631fe..caf0ab0907d80 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h +@@ -272,14 +272,16 @@ struct lp_sampler_dynamic_state + (*row_stride)(struct gallivm_state *gallivm, + LLVMTypeRef context_type, + LLVMValueRef context_ptr, +- unsigned texture_unit, LLVMValueRef texture_unit_offset); ++ unsigned texture_unit, LLVMValueRef texture_unit_offset, ++ LLVMTypeRef *out_type); + + /** Obtain stride in bytes between image slices (returns int32) */ + LLVMValueRef + (*img_stride)(struct gallivm_state *gallivm, + LLVMTypeRef context_type, + LLVMValueRef context_ptr, +- unsigned texture_unit, LLVMValueRef texture_unit_offset); ++ unsigned texture_unit, LLVMValueRef texture_unit_offset,\ ++ LLVMTypeRef *out_type); + + /** Obtain pointer to base of texture */ + LLVMValueRef +@@ -293,7 +295,8 @@ struct lp_sampler_dynamic_state + (*mip_offsets)(struct gallivm_state *gallivm, + LLVMTypeRef context_type, + LLVMValueRef context_ptr, +- unsigned texture_unit, LLVMValueRef texture_unit_offset); ++ unsigned texture_unit, LLVMValueRef texture_unit_offset, ++ LLVMTypeRef *out_type); + + /** Obtain number of samples (returns int32) */ + LLVMValueRef +@@ -447,9 +450,12 @@ struct lp_build_sample_context + struct lp_build_context lodi_bld; + + /* Common dynamic state values */ ++ LLVMTypeRef row_stride_type; + LLVMValueRef row_stride_array; ++ LLVMTypeRef img_stride_type; + LLVMValueRef img_stride_array; + LLVMValueRef base_ptr; ++ LLVMTypeRef mip_offsets_type; + LLVMValueRef mip_offsets; + LLVMValueRef cache; + LLVMValueRef sample_stride; +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +index c24833dafe123..2e90d09ae617f 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +@@ -3574,13 +3574,16 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + context_ptr, texture_index, + NULL); + bld.row_stride_array = dynamic_state->row_stride(gallivm, context_type, +- context_ptr, texture_index, NULL); ++ context_ptr, texture_index, NULL, ++ &bld.row_stride_type); + bld.img_stride_array = dynamic_state->img_stride(gallivm, context_type, +- context_ptr, texture_index, NULL); ++ context_ptr, texture_index, NULL, ++ &bld.img_stride_type); + bld.base_ptr = dynamic_state->base_ptr(gallivm, context_type, + context_ptr, texture_index, NULL); + bld.mip_offsets = dynamic_state->mip_offsets(gallivm, context_type, +- context_ptr, texture_index, NULL); ++ context_ptr, texture_index, NULL, ++ &bld.mip_offsets_type); + + if (fetch_ms) { + bld.sample_stride = +@@ -3820,9 +3823,12 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, + bld4.dynamic_state = bld.dynamic_state; + bld4.format_desc = bld.format_desc; + bld4.dims = bld.dims; ++ bld4.row_stride_type = bld.row_stride_type; + bld4.row_stride_array = bld.row_stride_array; ++ bld4.img_stride_type = bld.img_stride_type; + bld4.img_stride_array = bld.img_stride_array; + bld4.base_ptr = bld.base_ptr; ++ bld4.mip_offsets_type = bld.mip_offsets_type; + bld4.mip_offsets = bld.mip_offsets; + bld4.int_size = bld.int_size; + bld4.int_tex_blocksize = bld.int_tex_blocksize; +@@ -4813,11 +4819,11 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, + LLVMValueRef row_stride = dynamic_state->row_stride(gallivm, + params->context_type, + params->context_ptr, +- params->image_index, NULL); ++ params->image_index, NULL, NULL); + LLVMValueRef img_stride = dynamic_state->img_stride(gallivm, + params->context_type, + params->context_ptr, +- params->image_index, NULL); ++ params->image_index, NULL, NULL); + LLVMValueRef base_ptr = dynamic_state->base_ptr(gallivm, + params->context_type, + params->context_ptr, +diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c +index e62ec9f6d8915..ddaea90aecda2 100644 +--- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c ++++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c +@@ -116,7 +116,8 @@ lp_llvm_texture_member(struct gallivm_state *gallivm, + LLVMValueRef texture_unit_offset, + unsigned member_index, + const char *member_name, +- boolean emit_load) ++ boolean emit_load, ++ LLVMTypeRef *out_type) + { + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef indices[4]; +@@ -155,6 +156,12 @@ lp_llvm_texture_member(struct gallivm_state *gallivm, + } else + res = ptr; + ++ if (out_type) { ++ LLVMTypeRef tex_type = LLVMStructGetTypeAtIndex(context_type, LP_JIT_CTX_TEXTURES); ++ LLVMTypeRef res_type = LLVMStructGetTypeAtIndex(LLVMGetElementType(tex_type), member_index); ++ *out_type = res_type; ++ } ++ + lp_build_name(res, "context.texture%u.%s", texture_unit, member_name); + + return res; +@@ -180,7 +187,21 @@ lp_llvm_texture_member(struct gallivm_state *gallivm, + { \ + return lp_llvm_texture_member(gallivm, context_type, context_ptr, \ + texture_unit, texture_unit_offset, \ +- _index, #_name, _emit_load ); \ ++ _index, #_name, _emit_load, NULL ); \ ++ } ++ ++#define LP_LLVM_TEXTURE_MEMBER_OUTTYPE(_name, _index, _emit_load) \ ++ static LLVMValueRef \ ++ lp_llvm_texture_##_name(struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ ++ LLVMValueRef context_ptr, \ ++ unsigned texture_unit, \ ++ LLVMValueRef texture_unit_offset, \ ++ LLVMTypeRef *out_type) \ ++ { \ ++ return lp_llvm_texture_member(gallivm, context_type, context_ptr, \ ++ texture_unit, texture_unit_offset, \ ++ _index, #_name, _emit_load, out_type ); \ + } + + +@@ -190,9 +211,9 @@ LP_LLVM_TEXTURE_MEMBER(depth, LP_JIT_TEXTURE_DEPTH, TRUE) + LP_LLVM_TEXTURE_MEMBER(first_level, LP_JIT_TEXTURE_FIRST_LEVEL, TRUE) + LP_LLVM_TEXTURE_MEMBER(last_level, LP_JIT_TEXTURE_LAST_LEVEL, TRUE) + LP_LLVM_TEXTURE_MEMBER(base_ptr, LP_JIT_TEXTURE_BASE, TRUE) +-LP_LLVM_TEXTURE_MEMBER(row_stride, LP_JIT_TEXTURE_ROW_STRIDE, FALSE) +-LP_LLVM_TEXTURE_MEMBER(img_stride, LP_JIT_TEXTURE_IMG_STRIDE, FALSE) +-LP_LLVM_TEXTURE_MEMBER(mip_offsets, LP_JIT_TEXTURE_MIP_OFFSETS, FALSE) ++LP_LLVM_TEXTURE_MEMBER_OUTTYPE(row_stride, LP_JIT_TEXTURE_ROW_STRIDE, FALSE) ++LP_LLVM_TEXTURE_MEMBER_OUTTYPE(img_stride, LP_JIT_TEXTURE_IMG_STRIDE, FALSE) ++LP_LLVM_TEXTURE_MEMBER_OUTTYPE(mip_offsets, LP_JIT_TEXTURE_MIP_OFFSETS, FALSE) + LP_LLVM_TEXTURE_MEMBER(num_samples, LP_JIT_TEXTURE_NUM_SAMPLES, TRUE) + LP_LLVM_TEXTURE_MEMBER(sample_stride, LP_JIT_TEXTURE_SAMPLE_STRIDE, TRUE) + +@@ -339,13 +360,27 @@ lp_llvm_image_member(struct gallivm_state *gallivm, + _index, #_name, _emit_load ); \ + } + ++#define LP_LLVM_IMAGE_MEMBER_OUTTYPE(_name, _index, _emit_load) \ ++ static LLVMValueRef \ ++ lp_llvm_image_##_name( struct gallivm_state *gallivm, \ ++ LLVMTypeRef context_type, \ ++ LLVMValueRef context_ptr, \ ++ unsigned image_unit, LLVMValueRef image_unit_offset, \ ++ LLVMTypeRef *out_type) \ ++ { \ ++ assert(!out_type); \ ++ return lp_llvm_image_member(gallivm, context_type, context_ptr, \ ++ image_unit, image_unit_offset, \ ++ _index, #_name, _emit_load ); \ ++ } ++ + + LP_LLVM_IMAGE_MEMBER(width, LP_JIT_IMAGE_WIDTH, TRUE) + LP_LLVM_IMAGE_MEMBER(height, LP_JIT_IMAGE_HEIGHT, TRUE) + LP_LLVM_IMAGE_MEMBER(depth, LP_JIT_IMAGE_DEPTH, TRUE) + LP_LLVM_IMAGE_MEMBER(base_ptr, LP_JIT_IMAGE_BASE, TRUE) +-LP_LLVM_IMAGE_MEMBER(row_stride, LP_JIT_IMAGE_ROW_STRIDE, TRUE) +-LP_LLVM_IMAGE_MEMBER(img_stride, LP_JIT_IMAGE_IMG_STRIDE, TRUE) ++LP_LLVM_IMAGE_MEMBER_OUTTYPE(row_stride, LP_JIT_IMAGE_ROW_STRIDE, TRUE) ++LP_LLVM_IMAGE_MEMBER_OUTTYPE(img_stride, LP_JIT_IMAGE_IMG_STRIDE, TRUE) + LP_LLVM_IMAGE_MEMBER(num_samples, LP_JIT_IMAGE_NUM_SAMPLES, TRUE) + LP_LLVM_IMAGE_MEMBER(sample_stride, LP_JIT_IMAGE_SAMPLE_STRIDE, TRUE) + +-- +GitLab + + +From 0c865245900615e57f103b5e3f8759a68e978f85 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Mon, 26 Sep 2022 15:02:38 +1000 +Subject: [PATCH 5/6] gallivm/sample: use retrieved types to do opaque pointer + loads. + +This uses the types to do the loads using opaque ptr interfaces. + +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18947> +--- + src/gallium/auxiliary/gallivm/lp_bld_sample.c | 26 ++++++++++++------- + 1 file changed, 16 insertions(+), 10 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +index cdbf737031a8c..9e608303451d6 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c +@@ -1147,10 +1147,11 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + * A helper function that factorizes this common pattern. + */ + static LLVMValueRef +-load_mip(struct gallivm_state *gallivm, LLVMValueRef offsets, LLVMValueRef index1) { ++load_mip(struct gallivm_state *gallivm, ++ LLVMTypeRef ptr_type, LLVMValueRef offsets, LLVMValueRef index1) { + LLVMValueRef zero = lp_build_const_int32(gallivm, 0); + LLVMValueRef indexes[2] = {zero, index1}; +- LLVMValueRef ptr = LLVMBuildGEP(gallivm->builder, offsets, indexes, ARRAY_SIZE(indexes), ""); ++ LLVMValueRef ptr = LLVMBuildGEP2(gallivm->builder, ptr_type, offsets, indexes, ARRAY_SIZE(indexes), ""); + return LLVMBuildLoad2(gallivm->builder, LLVMInt32TypeInContext(gallivm->context), ptr, ""); + } + +@@ -1162,9 +1163,11 @@ LLVMValueRef + lp_build_get_mipmap_level(struct lp_build_sample_context *bld, + LLVMValueRef level) + { +- LLVMValueRef mip_offset = load_mip(bld->gallivm, bld->mip_offsets, level); ++ LLVMValueRef mip_offset = load_mip(bld->gallivm, bld->mip_offsets_type, bld->mip_offsets, level); + LLVMBuilderRef builder = bld->gallivm->builder; +- LLVMValueRef data_ptr = LLVMBuildGEP(builder, bld->base_ptr, &mip_offset, 1, ""); ++ LLVMValueRef data_ptr = LLVMBuildGEP2(builder, ++ LLVMInt8TypeInContext(bld->gallivm->context), ++ bld->base_ptr, &mip_offset, 1, ""); + return data_ptr; + } + +@@ -1180,7 +1183,7 @@ lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + LLVMValueRef offsets, offset1; + + if (bld->num_mips == 1) { +- offset1 = load_mip(bld->gallivm, bld->mip_offsets, level); ++ offset1 = load_mip(bld->gallivm, bld->mip_offsets_type, bld->mip_offsets, level); + offsets = lp_build_broadcast_scalar(&bld->int_coord_bld, offset1); + } + else if (bld->num_mips == bld->coord_bld.type.length / 4) { +@@ -1189,7 +1192,7 @@ lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + offsets = bld->int_coord_bld.undef; + for (i = 0; i < bld->num_mips; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); +- offset1 = load_mip(bld->gallivm, bld->mip_offsets, LLVMBuildExtractElement(builder, level, indexi, "")); ++ offset1 = load_mip(bld->gallivm, bld->mip_offsets_type, bld->mip_offsets, LLVMBuildExtractElement(builder, level, indexi, "")); + LLVMValueRef indexo = lp_build_const_int32(bld->gallivm, 4 * i); + offsets = LLVMBuildInsertElement(builder, offsets, offset1, indexo, ""); + } +@@ -1203,7 +1206,7 @@ lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + offsets = bld->int_coord_bld.undef; + for (i = 0; i < bld->num_mips; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); +- offset1 = load_mip(bld->gallivm, bld->mip_offsets, LLVMBuildExtractElement(builder, level, indexi, "")); ++ offset1 = load_mip(bld->gallivm, bld->mip_offsets_type, bld->mip_offsets, LLVMBuildExtractElement(builder, level, indexi, "")); + offsets = LLVMBuildInsertElement(builder, offsets, offset1, indexi, ""); + } + } +@@ -1333,12 +1336,13 @@ lp_build_scale_view_dim(struct gallivm_state *gallivm, LLVMValueRef size, + */ + static LLVMValueRef + lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, ++ LLVMTypeRef stride_type, + LLVMValueRef stride_array, LLVMValueRef level) + { + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef stride, stride1; + if (bld->num_mips == 1) { +- stride1 = load_mip(bld->gallivm, stride_array, level); ++ stride1 = load_mip(bld->gallivm, stride_type, stride_array, level); + stride = lp_build_broadcast_scalar(&bld->int_coord_bld, stride1); + } + else if (bld->num_mips == bld->coord_bld.type.length / 4) { +@@ -1348,7 +1352,7 @@ lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, + stride = bld->int_coord_bld.undef; + for (i = 0; i < bld->num_mips; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); +- stride1 = load_mip(bld->gallivm, stride_array, LLVMBuildExtractElement(builder, level, indexi, "")); ++ stride1 = load_mip(bld->gallivm, stride_type, stride_array, LLVMBuildExtractElement(builder, level, indexi, "")); + LLVMValueRef indexo = lp_build_const_int32(bld->gallivm, 4 * i); + stride = LLVMBuildInsertElement(builder, stride, stride1, indexo, ""); + } +@@ -1363,7 +1367,7 @@ lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, + stride = bld->int_coord_bld.undef; + for (i = 0; i < bld->coord_bld.type.length; i++) { + LLVMValueRef indexi = lp_build_const_int32(bld->gallivm, i); +- stride1 = load_mip(bld->gallivm, stride_array, LLVMBuildExtractElement(builder, level, indexi, "")); ++ stride1 = load_mip(bld->gallivm, stride_type, stride_array, LLVMBuildExtractElement(builder, level, indexi, "")); + stride = LLVMBuildInsertElement(builder, stride, stride1, indexi, ""); + } + } +@@ -1515,11 +1519,13 @@ lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld, + + if (dims >= 2) { + *row_stride_vec = lp_build_get_level_stride_vec(bld, ++ bld->row_stride_type, + bld->row_stride_array, + ilevel); + } + if (dims == 3 || has_layer_coord(bld->static_texture_state->target)) { + *img_stride_vec = lp_build_get_level_stride_vec(bld, ++ bld->img_stride_type, + bld->img_stride_array, + ilevel); + } +-- +GitLab + + +From 6f27bf250461e02ad7df17ad41cbfa71a4cae487 Mon Sep 17 00:00:00 2001 +From: Dave Airlie <airlied@redhat.com> +Date: Tue, 27 Sep 2022 15:28:18 +1000 +Subject: [PATCH 6/6] gallivm: remove legacy pointer_get apis + +These are no longer used. + +Reviewed-by: Mihai Preda <mhpreda@gmail.com> +Reviewed-by: Roland Scheidegger <sroland@vmware.com> +Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18947> +--- + src/gallium/auxiliary/gallivm/lp_bld_struct.c | 117 ------------------ + src/gallium/auxiliary/gallivm/lp_bld_struct.h | 65 ---------- + 2 files changed, 182 deletions(-) + +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +index 73c32cebadfb6..0595c3d3df220 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c +@@ -41,43 +41,6 @@ + #include "lp_bld_debug.h" + #include "lp_bld_struct.h" + +- +-/* Deprecated (used only by llvmpipe); use lp_build_struct_get_ptr2() instead. */ +-LLVMValueRef +-lp_build_struct_get_ptr(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- unsigned member, +- const char *name) +-{ +- LLVMValueRef indices[2]; +- LLVMValueRef member_ptr; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); +- +- indices[0] = lp_build_const_int32(gallivm, 0); +- indices[1] = lp_build_const_int32(gallivm, member); +- member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, ARRAY_SIZE(indices), ""); +- lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name); +- return member_ptr; +-} +- +-/* Deprecated (used only by llvmpipe); use lp_build_struct_get2() instead. */ +-LLVMValueRef +-lp_build_struct_get(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- unsigned member, +- const char *name) +-{ +- LLVMValueRef member_ptr; +- LLVMValueRef res; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); +- member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name); +- res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); +- lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); +- return res; +-} +- + LLVMValueRef + lp_build_struct_get_ptr2(struct gallivm_state *gallivm, + LLVMTypeRef ptr_type, +@@ -154,86 +117,6 @@ lp_build_array_get2(struct gallivm_state *gallivm, + return res; + } + +-LLVMValueRef +-lp_build_array_get_ptr(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- LLVMValueRef index) +-{ +- LLVMValueRef indices[2]; +- LLVMValueRef element_ptr; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); +- indices[0] = lp_build_const_int32(gallivm, 0); +- indices[1] = index; +- element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, ARRAY_SIZE(indices), ""); +-#ifdef DEBUG +- lp_build_name(element_ptr, "&%s[%s]", +- LLVMGetValueName(ptr), LLVMGetValueName(index)); +-#endif +- return element_ptr; +-} +- +- +-LLVMValueRef +-lp_build_array_get(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- LLVMValueRef index) +-{ +- LLVMValueRef element_ptr; +- LLVMValueRef res; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); +- element_ptr = lp_build_array_get_ptr(gallivm, ptr, index); +- res = LLVMBuildLoad(gallivm->builder, element_ptr, ""); +-#ifdef DEBUG +- lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); +-#endif +- return res; +-} +- +- +-void +-lp_build_array_set(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- LLVMValueRef index, +- LLVMValueRef value) +-{ +- LLVMValueRef element_ptr; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- assert(LLVM_VERSION_MAJOR >= 15 || LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); +- element_ptr = lp_build_array_get_ptr(gallivm, ptr, index); +- LLVMBuildStore(gallivm->builder, value, element_ptr); +-} +- +- +-LLVMValueRef +-lp_build_pointer_get(LLVMBuilderRef builder, +- LLVMValueRef ptr, +- LLVMValueRef index) +-{ +- return lp_build_pointer_get_unaligned(builder, ptr, index, 0); +-} +- +- +-LLVMValueRef +-lp_build_pointer_get_unaligned(LLVMBuilderRef builder, +- LLVMValueRef ptr, +- LLVMValueRef index, +- unsigned alignment) +-{ +- LLVMValueRef element_ptr; +- LLVMValueRef res; +- assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); +- element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); +- res = LLVMBuildLoad(builder, element_ptr, ""); +- if (alignment) +- LLVMSetAlignment(res, alignment); +-#ifdef DEBUG +- lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); +-#endif +- return res; +-} +- + LLVMValueRef + lp_build_pointer_get_unaligned2(LLVMBuilderRef builder, + LLVMTypeRef ptr_type, +diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +index 52d6020563bfb..11f256964f540 100644 +--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h ++++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h +@@ -53,26 +53,6 @@ + offsetof(_ctype, _cmember)) + + +-/** +- * Get value pointer to a structure member. +- * Deprecated (used only by llvmpipe); use lp_build_struct_get_ptr2() instead. +- */ +-LLVMValueRef +-lp_build_struct_get_ptr(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- unsigned member, +- const char *name); +- +-/** +- * Get the value of a structure member. +- * Deprecated (used only by llvmpipe); use lp_build_struct_get2() instead. +- */ +-LLVMValueRef +-lp_build_struct_get(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- unsigned member, +- const char *name); +- + /** + * Get value pointer to a structure member. + * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. +@@ -107,51 +87,6 @@ lp_build_array_get2(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index); + +-/** +- * Get value pointer to an array element. +- */ +-LLVMValueRef +-lp_build_array_get_ptr(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- LLVMValueRef index); +- +-/** +- * Get the value of an array element. +- */ +-LLVMValueRef +-lp_build_array_get(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- LLVMValueRef index); +- +-/** +- * Set the value of an array element. +- */ +-void +-lp_build_array_set(struct gallivm_state *gallivm, +- LLVMValueRef ptr, +- LLVMValueRef index, +- LLVMValueRef value); +- +-/** +- * Get the value of an array element. +- */ +-LLVMValueRef +-lp_build_pointer_get(LLVMBuilderRef builder, +- LLVMValueRef ptr, +- LLVMValueRef index); +- +-/** +- * Get the value of an array element, with explicit alignment. +- * +- * If the element size is different from the alignment this will +- * cause llvm to emit an unaligned load +- */ +-LLVMValueRef +-lp_build_pointer_get_unaligned(LLVMBuilderRef builder, +- LLVMValueRef ptr, +- LLVMValueRef index, +- unsigned alignment); +- + /** + * Get the value of an array element. + * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. +-- +GitLab + |