gallivm: use LLVM opaque pointers in lp_bld_sample.c

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>
This commit is contained in:
Mihai Preda 2022-05-02 16:04:44 +03:00 committed by Mihai Preda
parent 2a59fdb96d
commit 12cac07fe6
1 changed files with 20 additions and 29 deletions

View File

@ -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, "");
}
}