Module: Mesa Branch: main Commit: 749a4fff86914453b922da1db1b7c2ffb7ebc5a2 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=749a4fff86914453b922da1db1b7c2ffb7ebc5a2
Author: Dave Airlie <airl...@redhat.com> Date: Tue Sep 26 16:25:05 2023 +1000 gallivm/lp: reduce size of lp_jit_texture. This is step one in a size reduction plan, this reduces lp_jit_texture by making all the fields smaller in the struct and upsizing on the llvm size. It goes from 280->264. This isn't sufficient to get conformance, but it's a good step one. Reviewed-by: Roland Scheidegger <srol...@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25398> --- src/gallium/auxiliary/gallivm/lp_bld_jit_types.c | 8 +-- src/gallium/auxiliary/gallivm/lp_bld_jit_types.h | 14 ++-- src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 79 +++++++++++++++-------- 3 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c index 852bcd8519f..fd5534165c8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c @@ -146,13 +146,13 @@ lp_build_create_jit_texture_type(struct gallivm_state *gallivm) LLVMTypeRef elem_types[LP_JIT_TEXTURE_NUM_FIELDS]; /* struct lp_jit_texture */ - elem_types[LP_JIT_TEXTURE_WIDTH] = + elem_types[LP_JIT_TEXTURE_WIDTH] = + elem_types[LP_JIT_TEXTURE_SAMPLE_STRIDE] = LLVMInt32TypeInContext(lc); elem_types[LP_JIT_TEXTURE_HEIGHT] = - elem_types[LP_JIT_TEXTURE_DEPTH] = + elem_types[LP_JIT_TEXTURE_DEPTH] = LLVMInt16TypeInContext(lc); elem_types[LP_JIT_TEXTURE_NUM_SAMPLES] = - elem_types[LP_JIT_TEXTURE_SAMPLE_STRIDE] = elem_types[LP_JIT_TEXTURE_FIRST_LEVEL] = - elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32TypeInContext(lc); + elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt8TypeInContext(lc); elem_types[LP_JIT_TEXTURE_BASE] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0); elem_types[LP_JIT_TEXTURE_ROW_STRIDE] = elem_types[LP_JIT_TEXTURE_IMG_STRIDE] = diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h index 827e818f300..33d9fb207a5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h @@ -64,14 +64,14 @@ struct lp_jit_texture { const void *base; uint32_t width; /* same as number of elements */ - uint32_t height; - uint32_t depth; /* doubles as array size */ - uint32_t num_samples; + uint16_t height; + uint16_t depth; /* doubles as array size */ + uint8_t num_samples; + uint8_t first_level; + uint8_t last_level; uint32_t sample_stride; uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; - uint32_t first_level; - uint32_t last_level; uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]; }; @@ -81,11 +81,11 @@ enum { LP_JIT_TEXTURE_HEIGHT, LP_JIT_TEXTURE_DEPTH, LP_JIT_TEXTURE_NUM_SAMPLES, + LP_JIT_TEXTURE_FIRST_LEVEL, + LP_JIT_TEXTURE_LAST_LEVEL, LP_JIT_TEXTURE_SAMPLE_STRIDE, LP_JIT_TEXTURE_ROW_STRIDE, LP_JIT_TEXTURE_IMG_STRIDE, - LP_JIT_TEXTURE_FIRST_LEVEL, - LP_JIT_TEXTURE_LAST_LEVEL, LP_JIT_TEXTURE_MIP_OFFSETS, LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ }; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index ba5b1463d1a..64aa9738865 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -233,10 +233,16 @@ get_first_level(struct gallivm_state *gallivm, { 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); + else { + LLVMValueRef first_level; + + first_level = dynamic_state->first_level(gallivm, resources_type, + resources_ptr, texture_unit, + texture_unit_offset); + first_level = LLVMBuildZExt(gallivm->builder, first_level, + LLVMInt32TypeInContext(gallivm->context), ""); + return first_level; + } } @@ -251,10 +257,16 @@ get_last_level(struct gallivm_state *gallivm, { 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); + else { + LLVMValueRef last_level; + + last_level = dynamic_state->last_level(gallivm, resources_type, + resources_ptr, texture_unit, + texture_unit_offset); + last_level = LLVMBuildZExt(gallivm->builder, last_level, + LLVMInt32TypeInContext(gallivm->context), ""); + return last_level; + } } /** @@ -2054,7 +2066,8 @@ lp_build_layer_coord(struct lp_build_sample_context *bld, num_layers = bld->dynamic_state->depth(bld->gallivm, bld->resources_type, bld->resources_ptr, texture_unit, NULL); - + num_layers = LLVMBuildZExt(bld->gallivm->builder, num_layers, + bld->int_bld.elem_type, ""); if (out_of_bounds) { LLVMValueRef out1, out; assert(!is_cube_array); @@ -3144,6 +3157,7 @@ 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; first_level = get_first_level(bld->gallivm, @@ -3161,6 +3175,7 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, } else { ilevel = explicit_lod; } + LLVMValueRef last_level; last_level = get_last_level(bld->gallivm, @@ -3248,6 +3263,8 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld, bld->resources_type, bld->resources_ptr, texture_unit, NULL); + num_samples = LLVMBuildZExt(bld->gallivm->builder, num_samples, + bld->int_bld.elem_type, ""); LLVMValueRef sample_stride = bld->dynamic_state->sample_stride(bld->gallivm, bld->resources_type, bld->resources_ptr, @@ -3662,6 +3679,8 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, LLVMValueRef tex_height = dynamic_state->height(gallivm, resources_type, resources_ptr, texture_index, NULL); + tex_height = LLVMBuildZExt(gallivm->builder, tex_height, + bld.int_bld.elem_type, ""); bld.int_size = LLVMBuildInsertElement(builder, bld.int_size, tex_height, LLVMConstInt(i32t, 1, 0), ""); @@ -3678,6 +3697,8 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm, LLVMValueRef tex_depth = dynamic_state->depth(gallivm, resources_type, resources_ptr, texture_index, NULL); + tex_depth = LLVMBuildZExt(gallivm->builder, tex_depth, + bld.int_bld.elem_type, ""); bld.int_size = LLVMBuildInsertElement(builder, bld.int_size, tex_depth, LLVMConstInt(i32t, 2, 0), ""); @@ -4505,6 +4526,8 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, resources_ptr, texture_unit, texture_unit_offset); + num_samples = LLVMBuildZExt(gallivm->builder, num_samples, + bld_int_vec4.elem_type, ""); } else { num_samples = lp_build_const_int32(gallivm, 0); } @@ -4545,12 +4568,14 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, res_bw = bw = 1; if (res_bh == bh) res_bh = bh = 1; + + LLVMValueRef tex_width = dynamic_state->width(gallivm, + resources_type, + resources_ptr, + texture_unit, + texture_unit_offset); size = LLVMBuildInsertElement(gallivm->builder, size, - dynamic_state->width(gallivm, - resources_type, - resources_ptr, - texture_unit, - texture_unit_offset), + tex_width, lp_build_const_int32(gallivm, 0), ""); tex_blocksize = LLVMBuildInsertElement(gallivm->builder, tex_blocksize, lp_build_const_int32(gallivm, res_bw), @@ -4562,12 +4587,12 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, lp_build_const_int32(gallivm, bw), lp_build_const_int32(gallivm, 0), ""); if (dims >= 2) { - size = LLVMBuildInsertElement(gallivm->builder, size, - dynamic_state->height(gallivm, - resources_type, - resources_ptr, - texture_unit, - texture_unit_offset), + LLVMValueRef tex_height = + dynamic_state->height(gallivm, resources_type, + resources_ptr, texture_unit, texture_unit_offset); + tex_height = LLVMBuildZExt(gallivm->builder, tex_height, + bld_int_vec4.elem_type, ""); + size = LLVMBuildInsertElement(gallivm->builder, size, tex_height, lp_build_const_int32(gallivm, 1), ""); tex_blocksize = LLVMBuildInsertElement(gallivm->builder, tex_blocksize, lp_build_const_int32(gallivm, res_bh), @@ -4581,12 +4606,12 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, } if (dims >= 3) { - size = LLVMBuildInsertElement(gallivm->builder, size, - dynamic_state->depth(gallivm, - resources_type, - resources_ptr, - texture_unit, - texture_unit_offset), + LLVMValueRef tex_depth = + dynamic_state->depth(gallivm, resources_type, + resources_ptr, texture_unit, texture_unit_offset); + tex_depth = LLVMBuildZExt(gallivm->builder, tex_depth, + bld_int_vec4.elem_type, ""); + size = LLVMBuildInsertElement(gallivm->builder, size, tex_depth, lp_build_const_int32(gallivm, 2), ""); tex_blocksize = LLVMBuildInsertElement(gallivm->builder, tex_blocksize, lp_build_const_int32(gallivm, 1), @@ -4607,6 +4632,8 @@ lp_build_size_query_soa(struct gallivm_state *gallivm, LLVMValueRef layers = dynamic_state->depth(gallivm, resources_type, resources_ptr, texture_unit, texture_unit_offset); + layers = LLVMBuildZExt(gallivm->builder, layers, + bld_int_vec4.elem_type, ""); if (target == PIPE_TEXTURE_CUBE_ARRAY) { /* * It looks like GL wants number of cubes, d3d10.1 has it undefined?