From 99dcb5bceccb731233438cf5adcb433809bf183a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 6 Jun 2022 14:34:55 -0600 Subject: [PATCH] llvmpipe: asst. clean-ups in lp_tex_sample.c Signed-off-by: Brian Paul Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/drivers/llvmpipe/lp_tex_sample.c | 95 ++++++++++---------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c index 4e9e04fda46..61ce6439a11 100644 --- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c @@ -1,5 +1,5 @@ /************************************************************************** - * + * * Copyright 2009 VMware, Inc. * All rights reserved. * @@ -10,11 +10,11 @@ * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. @@ -22,7 +22,7 @@ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * + * **************************************************************************/ /** @@ -79,6 +79,7 @@ struct lp_llvm_sampler_soa unsigned nr_samplers; }; + struct llvmpipe_image_dynamic_state { struct lp_sampler_dynamic_state base; @@ -86,8 +87,9 @@ struct llvmpipe_image_dynamic_state const struct lp_image_static_state *static_state; }; + /** - * This is the bridge between our sampler and the TGSI translator. + * This is the bridge between our images and the TGSI translator. */ struct lp_llvm_image_soa { @@ -118,8 +120,6 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base, { LLVMBuilderRef builder = gallivm->builder; LLVMValueRef indices[4]; - LLVMValueRef ptr; - LLVMValueRef res; assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS); @@ -130,19 +130,24 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base, /* context[0].textures[unit] */ indices[2] = lp_build_const_int32(gallivm, texture_unit); if (texture_unit_offset) { - indices[2] = LLVMBuildAdd(gallivm->builder, indices[2], texture_unit_offset, ""); - LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntULT, indices[2], lp_build_const_int32(gallivm, PIPE_MAX_SHADER_SAMPLER_VIEWS), ""); - indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2], lp_build_const_int32(gallivm, texture_unit), ""); + indices[2] = LLVMBuildAdd(gallivm->builder, indices[2], + texture_unit_offset, ""); + LLVMValueRef cond = + LLVMBuildICmp(gallivm->builder, LLVMIntULT, + indices[2], + lp_build_const_int32(gallivm, + PIPE_MAX_SHADER_SAMPLER_VIEWS), ""); + indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2], + lp_build_const_int32(gallivm, + texture_unit), ""); } /* context[0].textures[unit].member */ indices[3] = lp_build_const_int32(gallivm, member_index); - ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); + LLVMValueRef ptr = + LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); - if (emit_load) - res = LLVMBuildLoad(builder, ptr, ""); - else - res = ptr; + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; lp_build_name(res, "context.texture%u.%s", texture_unit, member_name); @@ -205,8 +210,6 @@ lp_llvm_sampler_member(const struct lp_sampler_dynamic_state *base, { LLVMBuilderRef builder = gallivm->builder; LLVMValueRef indices[4]; - LLVMValueRef ptr; - LLVMValueRef res; assert(sampler_unit < PIPE_MAX_SAMPLERS); @@ -219,12 +222,10 @@ lp_llvm_sampler_member(const struct lp_sampler_dynamic_state *base, /* context[0].samplers[unit].member */ indices[3] = lp_build_const_int32(gallivm, member_index); - ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); + LLVMValueRef ptr = + LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); - if (emit_load) - res = LLVMBuildLoad(builder, ptr, ""); - else - res = ptr; + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; lp_build_name(res, "context.sampler%u.%s", sampler_unit, member_name); @@ -271,8 +272,6 @@ lp_llvm_image_member(const struct lp_sampler_dynamic_state *base, { LLVMBuilderRef builder = gallivm->builder; LLVMValueRef indices[4]; - LLVMValueRef ptr; - LLVMValueRef res; assert(image_unit < PIPE_MAX_SHADER_IMAGES); @@ -290,12 +289,10 @@ lp_llvm_image_member(const struct lp_sampler_dynamic_state *base, /* context[0].images[unit].member */ indices[3] = lp_build_const_int32(gallivm, member_index); - ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); + LLVMValueRef ptr = + LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), ""); - if (emit_load) - res = LLVMBuildLoad(builder, ptr, ""); - else - res = ptr; + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; lp_build_name(res, "context.image%u.%s", image_unit, member_name); @@ -334,6 +331,7 @@ LP_LLVM_IMAGE_MEMBER(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) + #if LP_USE_TEXTURE_CACHE static LLVMValueRef lp_llvm_texture_cache_ptr(const struct lp_sampler_dynamic_state *base, @@ -366,25 +364,27 @@ lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base, const struct lp_sampler_params *params) { struct lp_llvm_sampler_soa *sampler = (struct lp_llvm_sampler_soa *)base; - unsigned texture_index = params->texture_index; - unsigned sampler_index = params->sampler_index; + const unsigned texture_index = params->texture_index; + const unsigned sampler_index = params->sampler_index; assert(sampler_index < PIPE_MAX_SAMPLERS); assert(texture_index < PIPE_MAX_SHADER_SAMPLER_VIEWS); - + if (LP_PERF & PERF_NO_TEX) { lp_build_sample_nop(gallivm, params->type, params->coords, params->texel); return; } if (params->texture_index_offset) { + LLVMValueRef unit = + LLVMBuildAdd(gallivm->builder, params->texture_index_offset, + lp_build_const_int32(gallivm, texture_index), ""); + struct lp_build_sample_array_switch switch_info; memset(&switch_info, 0, sizeof(switch_info)); - LLVMValueRef unit = LLVMBuildAdd(gallivm->builder, params->texture_index_offset, - lp_build_const_int32(gallivm, texture_index), ""); lp_build_sample_array_init_soa(&switch_info, gallivm, params, unit, 0, sampler->nr_samplers); - + // build the switch cases for (unsigned i = 0; i < sampler->nr_samplers; i++) { lp_build_sample_array_case_soa(&switch_info, i, &sampler->dynamic_state.static_state[i].texture_state, @@ -400,6 +400,7 @@ lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base, } } + /** * Fetch the texture size. */ @@ -423,9 +424,9 @@ struct lp_build_sampler_soa * lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, unsigned nr_samplers) { - struct lp_llvm_sampler_soa *sampler; + assert(static_state); - sampler = CALLOC_STRUCT(lp_llvm_sampler_soa); + struct lp_llvm_sampler_soa *sampler = CALLOC_STRUCT(lp_llvm_sampler_soa); if (!sampler) return NULL; @@ -459,26 +460,30 @@ lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, return &sampler->base; } + static void lp_llvm_image_soa_destroy(struct lp_build_image_soa *image) { FREE(image); } + static void lp_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, struct gallivm_state *gallivm, const struct lp_img_params *params) { struct lp_llvm_image_soa *image = (struct lp_llvm_image_soa *)base; - unsigned image_index = params->image_index; + const unsigned image_index = params->image_index; assert(image_index < PIPE_MAX_SHADER_IMAGES); if (params->image_index_offset) { struct lp_build_img_op_array_switch switch_info; memset(&switch_info, 0, sizeof(switch_info)); - LLVMValueRef unit = LLVMBuildAdd(gallivm->builder, params->image_index_offset, - lp_build_const_int32(gallivm, image_index), ""); + LLVMValueRef unit = LLVMBuildAdd(gallivm->builder, + params->image_index_offset, + lp_build_const_int32(gallivm, + image_index), ""); lp_build_image_op_switch_soa(&switch_info, gallivm, params, unit, 0, image->nr_images); @@ -496,13 +501,14 @@ lp_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, } } + /** * Fetch the texture size. */ static void lp_llvm_image_soa_emit_size_query(const struct lp_build_image_soa *base, - struct gallivm_state *gallivm, - const struct lp_sampler_size_query_params *params) + struct gallivm_state *gallivm, + const struct lp_sampler_size_query_params *params) { struct lp_llvm_image_soa *image = (struct lp_llvm_image_soa *)base; @@ -514,13 +520,12 @@ lp_llvm_image_soa_emit_size_query(const struct lp_build_image_soa *base, params); } + struct lp_build_image_soa * lp_llvm_image_soa_create(const struct lp_image_static_state *static_state, unsigned nr_images) { - struct lp_llvm_image_soa *image; - - image = CALLOC_STRUCT(lp_llvm_image_soa); + struct lp_llvm_image_soa *image = CALLOC_STRUCT(lp_llvm_image_soa); if (!image) return NULL;