From aba7554f3952a01dae58413e8ab0134027d5bd88 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Jun 2022 14:42:21 -0600 Subject: [PATCH] llvmpipe: asst. clean-up in lp_bld_depth.c Signed-off-by: Brian Paul Reviewed-by: Dave Airlie Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/drivers/llvmpipe/lp_bld_depth.c | 63 ++++++++++----------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_bld_depth.c b/src/gallium/drivers/llvmpipe/lp_bld_depth.c index cb4a727fa3c..8eb0c765800 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_depth.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_depth.c @@ -268,14 +268,19 @@ lp_build_stencil_op(struct lp_build_context *bld, } if (stencil[0].writemask != 0xff || - (stencil[1].enabled && front_facing != NULL && stencil[1].writemask != 0xff)) { + (stencil[1].enabled && front_facing != NULL && + stencil[1].writemask != 0xff)) { /* mask &= stencil[0].writemask */ LLVMValueRef writemask = lp_build_const_int_vec(bld->gallivm, bld->type, stencil[0].writemask); - if (stencil[1].enabled && stencil[1].writemask != stencil[0].writemask && front_facing != NULL) { - LLVMValueRef back_writemask = lp_build_const_int_vec(bld->gallivm, bld->type, - stencil[1].writemask); - writemask = lp_build_select(bld, front_facing, writemask, back_writemask); + if (stencil[1].enabled && + stencil[1].writemask != stencil[0].writemask && + front_facing != NULL) { + LLVMValueRef back_writemask = + lp_build_const_int_vec(bld->gallivm, bld->type, + stencil[1].writemask); + writemask = lp_build_select(bld, front_facing, + writemask, back_writemask); } mask = LLVMBuildAnd(builder, mask, writemask, ""); @@ -316,7 +321,7 @@ lp_depth_type(const struct util_format_description *format_desc, assert(z_swizzle == 0); assert(format_desc->channel[z_swizzle].size == 32); } - else if(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED) { + else if (format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED) { assert(format_desc->block.bits <= 32); assert(format_desc->channel[z_swizzle].normalized); if (format_desc->channel[z_swizzle].size < format_desc->block.bits) { @@ -386,10 +391,7 @@ static boolean get_s_shift_and_mask(const struct util_format_description *format_desc, unsigned *shift, unsigned *mask) { - unsigned s_swizzle; - unsigned sz; - - s_swizzle = format_desc->swizzle[1]; + const unsigned s_swizzle = format_desc->swizzle[1]; if (s_swizzle == PIPE_SWIZZLE_NONE) return FALSE; @@ -404,7 +406,7 @@ get_s_shift_and_mask(const struct util_format_description *format_desc, } *shift = format_desc->channel[s_swizzle].shift; - sz = format_desc->channel[s_swizzle].size; + const unsigned sz = format_desc->channel[s_swizzle].size; *mask = (1U << sz) - 1U; return TRUE; @@ -436,7 +438,7 @@ lp_build_occlusion_count(struct gallivm_state *gallivm, assert(type.length <= 16); assert(type.floating); - if(util_get_cpu_caps()->has_sse && type.length == 4) { + if (util_get_cpu_caps()->has_sse && type.length == 4) { const char *movmskintr = "llvm.x86.sse.movmsk.ps"; const char *popcntintr = "llvm.ctpop.i32"; LLVMValueRef bits = LLVMBuildBitCast(builder, maskvalue, @@ -447,7 +449,7 @@ lp_build_occlusion_count(struct gallivm_state *gallivm, LLVMInt32TypeInContext(context), bits); count = LLVMBuildZExt(builder, count, LLVMIntTypeInContext(context, 64), ""); } - else if(util_get_cpu_caps()->has_avx && type.length == 8) { + else if (util_get_cpu_caps()->has_avx && type.length == 8) { const char *movmskintr = "llvm.x86.avx.movmsk.ps.256"; const char *popcntintr = "llvm.ctpop.i32"; LLVMValueRef bits = LLVMBuildBitCast(builder, maskvalue, @@ -459,7 +461,6 @@ lp_build_occlusion_count(struct gallivm_state *gallivm, count = LLVMBuildZExt(builder, count, LLVMIntTypeInContext(context, 64), ""); } else { - unsigned i; LLVMValueRef countv = LLVMBuildAnd(builder, maskvalue, countmask, "countv"); LLVMTypeRef counttype = LLVMIntTypeInContext(context, type.length * 8); LLVMTypeRef i8vntype = LLVMVectorType(LLVMInt8TypeInContext(context), type.length * 4); @@ -469,7 +470,7 @@ lp_build_occlusion_count(struct gallivm_state *gallivm, countv = LLVMBuildBitCast(builder, countv, i8vntype, ""); - for (i = 0; i < type.length; i++) { + for (unsigned i = 0; i < type.length; i++) { #if UTIL_ARCH_LITTLE_ENDIAN shuffles[i] = lp_build_const_int32(gallivm, 4*i); #else @@ -542,20 +543,16 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, { LLVMBuilderRef builder = gallivm->builder; LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH / 4]; - LLVMValueRef zs_dst1, zs_dst2; - LLVMValueRef zs_dst_ptr; LLVMValueRef depth_offset1, depth_offset2; - LLVMTypeRef load_ptr_type; - unsigned depth_bytes = format_desc->block.bits / 8; + const unsigned depth_bytes = format_desc->block.bits / 8; struct lp_type zs_type = lp_depth_type(format_desc, z_src_type.length); - struct lp_type zs_load_type = zs_type; + struct lp_type zs_load_type = zs_type; zs_load_type.length = zs_load_type.length / 2; + 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; LLVMValueRef looplsb = LLVMBuildAnd(builder, loop_counter, lp_build_const_int32(gallivm, 1), ""); LLVMValueRef loopmsb = LLVMBuildAnd(builder, loop_counter, @@ -567,7 +564,7 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, depth_offset1 = LLVMBuildAdd(builder, depth_offset1, offset2, ""); /* just concatenate the loaded 2x2 values into 4-wide vector */ - for (i = 0; i < 4; i++) { + for (unsigned i = 0; i < 4; i++) { shuffles[i] = lp_build_const_int32(gallivm, i); } } @@ -589,9 +586,12 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, depth_offset2 = LLVMBuildAdd(builder, depth_offset1, depth_stride, ""); /* Load current z/stencil values from z/stencil buffer */ - zs_dst_ptr = LLVMBuildGEP(builder, depth_ptr, &depth_offset1, 1, ""); + LLVMTypeRef load_ptr_type = LLVMPointerType(zs_dst_type, 0); + LLVMValueRef zs_dst_ptr = + LLVMBuildGEP(builder, depth_ptr, &depth_offset1, 1, ""); zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, load_ptr_type, ""); - zs_dst1 = LLVMBuildLoad2(builder, zs_dst_type, zs_dst_ptr, ""); + LLVMValueRef zs_dst1 = LLVMBuildLoad2(builder, zs_dst_type, zs_dst_ptr, ""); + LLVMValueRef zs_dst2; if (is_1d) { zs_dst2 = lp_build_undef(gallivm, zs_load_type); } @@ -619,7 +619,6 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, else if (format_desc->block.bits > 32) { /* rely on llvm to handle too wide vector we have here nicely */ - unsigned i; struct lp_type typex2 = zs_type; struct lp_type s_type = zs_type; LLVMValueRef shuffles1[LP_MAX_VECTOR_LENGTH / 4]; @@ -634,7 +633,7 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, tmp = LLVMBuildBitCast(builder, *z_fb, lp_build_vec_type(gallivm, typex2), ""); - for (i = 0; i < zs_type.length; i++) { + for (unsigned i = 0; i < zs_type.length; i++) { shuffles1[i] = lp_build_const_int32(gallivm, i * 2); shuffles2[i] = lp_build_const_int32(gallivm, i * 2 + 1); } @@ -652,6 +651,7 @@ lp_build_depth_stencil_load_swizzled(struct gallivm_state *gallivm, lp_build_name(*z_fb, "z_dst"); } + /** * Store depth/stencil values. * Incoming values are swizzled (typically n 2x2 quads), stored linear. @@ -718,7 +718,6 @@ lp_build_depth_stencil_write_swizzled(struct gallivm_state *gallivm, depth_offset1 = LLVMBuildAdd(builder, depth_offset1, offset2, ""); } else { - unsigned i; LLVMValueRef loopx2 = LLVMBuildShl(builder, loop_counter, lp_build_const_int32(gallivm, 1), ""); assert(z_src_type.length == 8); @@ -727,7 +726,7 @@ lp_build_depth_stencil_write_swizzled(struct gallivm_state *gallivm, * We load 2x4 values, and need to swizzle them (order * 0,1,4,5,2,3,6,7) - not so hot with avx unfortunately. */ - for (i = 0; i < 8; i++) { + for (unsigned i = 0; i < 8; i++) { shuffles[i] = lp_build_const_int32(gallivm, (i&1) + (i&2) * 2 + (i&4) / 2); } } @@ -780,10 +779,9 @@ lp_build_depth_stencil_write_swizzled(struct gallivm_state *gallivm, z_value, s_value, 1); } else { - unsigned i; LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH / 2]; assert(z_src_type.length == 8); - for (i = 0; i < 8; i++) { + for (unsigned i = 0; i < 8; i++) { shuffles[i*2] = lp_build_const_int32(gallivm, (i&1) + (i&2) * 2 + (i&4) / 2); shuffles[i*2+1] = lp_build_const_int32(gallivm, (i&1) + (i&2) * 2 + (i&4) / 2 + z_src_type.length); @@ -807,6 +805,7 @@ lp_build_depth_stencil_write_swizzled(struct gallivm_state *gallivm, } } + /** * Generate code for performing depth and/or stencil tests. * We operate on a vector of values (typically n 2x2 quads). @@ -858,7 +857,7 @@ lp_build_depth_stencil_test(struct gallivm_state *gallivm, * floats. Setting these bits here will ensure that the lp_build_conv() call * below won't try to unnecessarily clamp the incoming values. */ - if(z_src_type.floating) { + if (z_src_type.floating) { z_src_type.sign = FALSE; z_src_type.norm = TRUE; }