From c457e1f0e4d8beb3eb4c8d58452063652278764b Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 26 Aug 2022 15:13:04 +1000 Subject: [PATCH] gallivm/sample: move some first_level/last_level calcs out There were a fair few instances of first/level dynamic state getting, these could be moved up a level or two and made more common. Reviewed-by: Brian Paul Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_sample.c | 46 ++++----------- src/gallium/auxiliary/gallivm/lp_bld_sample.h | 7 ++- .../auxiliary/gallivm/lp_bld_sample_soa.c | 58 ++++++++++++------- 3 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index 9e608303451..405b53b5c6e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -244,7 +244,7 @@ lp_sampler_static_sampler_state(struct lp_static_sampler_state *state, /* build aniso pmin value */ static LLVMValueRef lp_build_pmin(struct lp_build_sample_context *bld, - unsigned texture_unit, + LLVMValueRef first_level, LLVMValueRef s, LLVMValueRef t, LLVMValueRef max_aniso) @@ -260,16 +260,12 @@ lp_build_pmin(struct lp_build_sample_context *bld, LLVMValueRef index1 = LLVMConstInt(i32t, 1, 0); LLVMValueRef ddx_ddy = lp_build_packed_ddx_ddy_twocoord(coord_bld, s, t); LLVMValueRef int_size, float_size; - LLVMValueRef first_level, first_level_vec; unsigned length = coord_bld->type.length; unsigned num_quads = length / 4; boolean pmin_per_quad = pmin_bld->type.length != length; unsigned i; - 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); + int_size = lp_build_minify(int_size_bld, bld->int_size, first_level, TRUE); float_size = lp_build_int_to_float(float_size_bld, int_size); max_aniso = lp_build_broadcast_scalar(coord_bld, max_aniso); max_aniso = lp_build_mul(coord_bld, max_aniso, max_aniso); @@ -338,7 +334,7 @@ lp_build_pmin(struct lp_build_sample_context *bld, */ static LLVMValueRef lp_build_rho(struct lp_build_sample_context *bld, - unsigned texture_unit, + LLVMValueRef first_level, LLVMValueRef s, LLVMValueRef t, LLVMValueRef r, @@ -360,7 +356,6 @@ lp_build_rho(struct lp_build_sample_context *bld, LLVMValueRef rho_vec; LLVMValueRef int_size, float_size; LLVMValueRef rho; - LLVMValueRef first_level, first_level_vec; unsigned length = coord_bld->type.length; unsigned num_quads = length / 4; boolean rho_per_quad = rho_bld->type.length != length; @@ -376,10 +371,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, 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); + int_size = lp_build_minify(int_size_bld, bld->int_size, first_level, TRUE); float_size = lp_build_int_to_float(float_size_bld, int_size); if (derivs) { @@ -806,8 +798,8 @@ lp_build_ilog2_sqrt(struct lp_build_context *bld, void lp_build_lod_selector(struct lp_build_sample_context *bld, boolean is_lodq, - unsigned texture_unit, unsigned sampler_unit, + LLVMValueRef first_level, LLVMValueRef s, LLVMValueRef t, LLVMValueRef r, @@ -873,10 +865,10 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, if (bld->static_sampler_state->aniso && !explicit_lod) { - rho = lp_build_pmin(bld, texture_unit, s, t, max_aniso); + rho = lp_build_pmin(bld, first_level, s, t, max_aniso); rho_squared = true; } else - rho = lp_build_rho(bld, texture_unit, s, t, r, derivs); + rho = lp_build_rho(bld, first_level, s, t, r, derivs); /* * Compute lod = log2(rho) @@ -1023,21 +1015,14 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, */ void lp_build_nearest_mip_level(struct lp_build_sample_context *bld, - unsigned texture_unit, + LLVMValueRef first_level, + LLVMValueRef last_level, LLVMValueRef lod_ipart, LLVMValueRef *level_out, LLVMValueRef *out_of_bounds) { struct lp_build_context *leveli_bld = &bld->leveli_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, bld->context_type, - bld->context_ptr, texture_unit, NULL); - 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); + LLVMValueRef level; level = lp_build_add(leveli_bld, lod_ipart, first_level); @@ -1079,28 +1064,21 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld, void lp_build_linear_mip_levels(struct lp_build_sample_context *bld, unsigned texture_unit, + LLVMValueRef first_level, + LLVMValueRef last_level, LLVMValueRef lod_ipart, LLVMValueRef *lod_fpart_inout, LLVMValueRef *level0_out, LLVMValueRef *level1_out) { LLVMBuilderRef builder = bld->gallivm->builder; - struct lp_sampler_dynamic_state *dynamic_state = bld->dynamic_state; struct lp_build_context *leveli_bld = &bld->leveli_bld; struct lp_build_context *levelf_bld = &bld->levelf_bld; - LLVMValueRef first_level, last_level; LLVMValueRef clamp_min; LLVMValueRef clamp_max; assert(bld->num_lods == bld->num_mips); - 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, 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); - *level0_out = lp_build_add(leveli_bld, lod_ipart, first_level); *level1_out = lp_build_add(leveli_bld, *level0_out, leveli_bld->one); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index caf0ab0907d..b5872fdd180 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -598,8 +598,8 @@ lp_sampler_static_texture_state_image(struct lp_static_texture_state *state, void lp_build_lod_selector(struct lp_build_sample_context *bld, boolean is_lodq, - unsigned texture_index, unsigned sampler_index, + LLVMValueRef first_level, LLVMValueRef s, LLVMValueRef t, LLVMValueRef r, @@ -615,7 +615,8 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, void lp_build_nearest_mip_level(struct lp_build_sample_context *bld, - unsigned texture_unit, + LLVMValueRef first_level, + LLVMValueRef last_level, LLVMValueRef lod, LLVMValueRef *level_out, LLVMValueRef *out_of_bounds); @@ -623,6 +624,8 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld, void lp_build_linear_mip_levels(struct lp_build_sample_context *bld, unsigned texture_unit, + LLVMValueRef first_level, + LLVMValueRef last_level, LLVMValueRef lod_ipart, LLVMValueRef *lod_fpart_inout, LLVMValueRef *level0_out, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index 2e90d09ae61..1605a159468 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -2539,7 +2539,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld, const unsigned mag_filter = bld->static_sampler_state->mag_img_filter; const unsigned target = bld->static_texture_state->target; const bool aniso = bld->static_sampler_state->aniso; - LLVMValueRef first_level = NULL; + LLVMValueRef first_level, last_level; LLVMValueRef lod_ipart = NULL; struct lp_derivatives cube_derivs; @@ -2548,6 +2548,15 @@ lp_build_sample_common(struct lp_build_sample_context *bld, mip_filter, min_filter, mag_filter); */ + first_level = bld->dynamic_state->first_level(bld->gallivm, + bld->context_type, + bld->context_ptr, + texture_index, NULL); + last_level = bld->dynamic_state->last_level(bld->gallivm, + bld->context_type, + bld->context_ptr, + texture_index, NULL); + /* * Choose cube face, recompute texcoords for the chosen face and * calculate / transform derivatives. @@ -2618,21 +2627,14 @@ lp_build_sample_common(struct lp_build_sample_context *bld, /* Need to compute lod either to choose mipmap levels or to * distinguish between minification/magnification with one mipmap level. */ - lp_build_lod_selector(bld, is_lodq, texture_index, sampler_index, + LLVMValueRef first_level_vec = lp_build_broadcast_scalar(&bld->int_size_in_bld, first_level); + lp_build_lod_selector(bld, is_lodq, sampler_index, + first_level_vec, coords[0], coords[1], coords[2], derivs, lod_bias, explicit_lod, mip_filter, max_aniso, lod, &lod_ipart, lod_fpart, lod_pos_or_zero); 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); last_level = lp_build_int_to_float(&bld->float_bld, last_level); last_level = lp_build_broadcast_scalar(&bld->lodf_bld, last_level); @@ -2663,12 +2665,17 @@ lp_build_sample_common(struct lp_build_sample_context *bld, lod_ipart = lp_build_extract_range(bld->gallivm, lod_ipart, 0, 1); } + first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level); + last_level = lp_build_broadcast_scalar(&bld->leveli_bld, last_level); + /* * Compute integer mipmap level(s) to fetch texels from: ilevel0, ilevel1 */ if (aniso) { - lp_build_nearest_mip_level(bld, texture_index, lod_ipart, ilevel0, NULL); + lp_build_nearest_mip_level(bld, + first_level, last_level, + lod_ipart, ilevel0, NULL); return; } @@ -2677,21 +2684,20 @@ 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_type, - bld->context_ptr, - texture_index, NULL); - first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level); *ilevel0 = first_level; break; case PIPE_TEX_MIPFILTER_NEAREST: assert(lod_ipart); - lp_build_nearest_mip_level(bld, texture_index, lod_ipart, ilevel0, NULL); + lp_build_nearest_mip_level(bld, + first_level, last_level, + lod_ipart, ilevel0, NULL); break; case PIPE_TEX_MIPFILTER_LINEAR: assert(lod_ipart); assert(*lod_fpart); + lp_build_linear_mip_levels(bld, texture_index, + first_level, last_level, lod_ipart, lod_fpart, ilevel0, ilevel1); break; @@ -3116,6 +3122,9 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, LLVMValueRef x = coords[0], y = coords[1], z = coords[2]; LLVMValueRef width, height, depth, i, j; LLVMValueRef offset, out_of_bounds, out1; + LLVMValueRef first_level = bld->dynamic_state->first_level(bld->gallivm, + bld->context_type, + bld->context_ptr, texture_unit, NULL); out_of_bounds = int_coord_bld->zero; @@ -3127,15 +3136,20 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, else { ilevel = explicit_lod; } - lp_build_nearest_mip_level(bld, texture_unit, ilevel, &ilevel, + LLVMValueRef last_level = bld->dynamic_state->last_level(bld->gallivm, + bld->context_type, + bld->context_ptr, texture_unit, NULL); + first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level); + last_level = lp_build_broadcast_scalar(&bld->leveli_bld, last_level); + lp_build_nearest_mip_level(bld, + first_level, last_level, + ilevel, &ilevel, out_of_bound_ret_zero ? &out_of_bounds : NULL); } else { 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); + ilevel = first_level; } else { ilevel = lp_build_const_int32(bld->gallivm, 0);