Module: Mesa Branch: main Commit: 7d4453b586260639c20c0632c1b95a282a855a4c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7d4453b586260639c20c0632c1b95a282a855a4c
Author: Dave Airlie <airl...@redhat.com> Date: Thu Sep 28 11:21:13 2023 +1000 gallivm/sample: refactor first/last level handling and use level_zero_only. This will help later esp for multisample textures which only ever have level 0 Reviewed-by: Roland Scheidegger <srol...@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25398> --- src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 97 +++++++++++++++++------ 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index 28c498cd93f..9878e59dad0 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -222,6 +222,40 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld, } } +static LLVMValueRef +get_first_level(struct gallivm_state *gallivm, + LLVMTypeRef resources_type, + LLVMValueRef resources_ptr, + unsigned texture_unit, + LLVMValueRef texture_unit_offset, + const struct lp_static_texture_state *static_state, + struct lp_sampler_dynamic_state *dynamic_state) +{ + if (static_state->level_zero_only) + return lp_build_const_int32(gallivm, 0); + else + return dynamic_state->first_level(gallivm, resources_type, + resources_ptr, texture_unit, + texture_unit_offset); +} + + +static LLVMValueRef +get_last_level(struct gallivm_state *gallivm, + LLVMTypeRef resources_type, + LLVMValueRef resources_ptr, + unsigned texture_unit, + LLVMValueRef texture_unit_offset, + const struct lp_static_texture_state *static_state, + struct lp_sampler_dynamic_state *dynamic_state) +{ + if (static_state->level_zero_only) + return lp_build_const_int32(gallivm, 0); + else + return dynamic_state->last_level(gallivm, resources_type, + resources_ptr, texture_unit, + texture_unit_offset); +} /** * Helper to compute the mirror function for the PIPE_WRAP_MIRROR_REPEAT mode. @@ -2541,14 +2575,18 @@ 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->resources_type, - bld->resources_ptr, - texture_index, NULL); - last_level = bld->dynamic_state->last_level(bld->gallivm, - bld->resources_type, - bld->resources_ptr, - texture_index, NULL); + first_level = get_first_level(bld->gallivm, + bld->resources_type, + bld->resources_ptr, + texture_index, NULL, + bld->static_texture_state, + bld->dynamic_state); + last_level = get_last_level(bld->gallivm, + bld->resources_type, + bld->resources_ptr, + texture_index, NULL, + bld->static_texture_state, + bld->dynamic_state); /* * Choose cube face, recompute texcoords for the chosen face and @@ -3106,10 +3144,14 @@ 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->resources_type, - bld->resources_ptr, texture_unit, NULL); - + LLVMValueRef first_level; + + first_level = get_first_level(bld->gallivm, + bld->resources_type, + bld->resources_ptr, + texture_unit, NULL, + bld->static_texture_state, + bld->dynamic_state); out_of_bounds = int_coord_bld->zero; if (explicit_lod && bld->static_texture_state->target != PIPE_BUFFER) { @@ -3119,9 +3161,15 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, } else { ilevel = explicit_lod; } - LLVMValueRef last_level = bld->dynamic_state->last_level(bld->gallivm, - bld->resources_type, - bld->resources_ptr, texture_unit, NULL); + LLVMValueRef last_level; + + last_level = get_last_level(bld->gallivm, + bld->resources_type, + bld->resources_ptr, + texture_unit, NULL, + bld->static_texture_state, + bld->dynamic_state); + 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, @@ -4465,9 +4513,9 @@ 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, resources_type, - resources_ptr, texture_unit, - texture_unit_offset); + first_level = get_first_level(gallivm, resources_type, resources_ptr, + texture_unit, texture_unit_offset, + static_state, dynamic_state); level = LLVMBuildAdd(gallivm->builder, lod, first_level, "level"); lod = lp_build_broadcast_scalar(&bld_int_vec4, level); } else { @@ -4575,9 +4623,9 @@ 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, resources_type, - resources_ptr, texture_unit, - texture_unit_offset); + last_level = get_last_level(gallivm, resources_type, resources_ptr, + texture_unit, texture_unit_offset, + static_state, dynamic_state); out = lp_build_cmp(&leveli_bld, PIPE_FUNC_LESS, level, first_level); out1 = lp_build_cmp(&leveli_bld, PIPE_FUNC_GREATER, level, last_level); @@ -4619,10 +4667,9 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, num_levels = bld_int_scalar.one; } else { LLVMValueRef last_level; - - last_level = dynamic_state->last_level(gallivm, resources_type, - resources_ptr, texture_unit, - texture_unit_offset); + last_level = get_last_level(gallivm, resources_type, resources_ptr, + texture_unit, texture_unit_offset, + static_state, dynamic_state); num_levels = lp_build_sub(&bld_int_scalar, last_level, first_level); num_levels = lp_build_add(&bld_int_scalar, num_levels, bld_int_scalar.one);