[Mesa-dev] [PATCH 2/4] gallivm: prepare for dynamic texture sizes
Roland Scheidegger
sroland at vmware.com
Mon Apr 18 16:14:10 UTC 2016
Am 18.04.2016 um 04:49 schrieb Dave Airlie:
> From: Dave Airlie <airlied at redhat.com>
>
> Currently the texture member functions take a texture unit
> number, in order for TXQ to work we want to use a dynamic
> value here, so we need to pass in an value reference.
>
> This means we can't do the assert or add the llvm name.
>
> For most normal users they still pass a constant value here,
> just for the TXQ paths do we actually care that it gets the
> value.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
> src/gallium/auxiliary/draw/draw_llvm_sample.c | 10 +++---
> src/gallium/auxiliary/gallivm/lp_bld_sample.c | 13 ++++---
> src/gallium/auxiliary/gallivm/lp_bld_sample.h | 18 +++++-----
> src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 41 ++++++++++++-----------
> src/gallium/drivers/llvmpipe/lp_tex_sample.c | 10 +++---
> 5 files changed, 48 insertions(+), 44 deletions(-)
>
> diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c
> index 1845c05..7e25918 100644
> --- a/src/gallium/auxiliary/draw/draw_llvm_sample.c
> +++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c
> @@ -85,7 +85,7 @@ static LLVMValueRef
> draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit,
> + LLVMValueRef tex_unit_ref,
> unsigned member_index,
> const char *member_name,
> boolean emit_load)
> @@ -95,14 +95,12 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> LLVMValueRef ptr;
> LLVMValueRef res;
>
> - debug_assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
> -
> /* context[0] */
> indices[0] = lp_build_const_int32(gallivm, 0);
> /* context[0].textures */
> indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
> /* context[0].textures[unit] */
> - indices[2] = lp_build_const_int32(gallivm, texture_unit);
> + indices[2] = tex_unit_ref;
> /* context[0].textures[unit].member */
> indices[3] = lp_build_const_int32(gallivm, member_index);
>
> @@ -113,7 +111,7 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> else
> res = ptr;
>
> - lp_build_name(res, "context.texture%u.%s", texture_unit, member_name);
> +// lp_build_name(res, "context.texture%u.%s", texture_unit, member_name);
>
> return res;
> }
> @@ -179,7 +177,7 @@ draw_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
> draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
> struct gallivm_state *gallivm, \
> LLVMValueRef context_ptr, \
> - unsigned texture_unit) \
> + LLVMValueRef texture_unit) \
> { \
> return draw_llvm_texture_member(base, gallivm, context_ptr, \
> texture_unit, _index, #_name, _emit_load ); \
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
> index 4befb3a..2f61cbf 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
> @@ -238,6 +238,7 @@ lp_build_rho(struct lp_build_sample_context *bld,
> unsigned i;
> LLVMValueRef i32undef = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
> LLVMValueRef rho_xvec, rho_yvec;
> + LLVMValueRef tunit = lp_build_const_int32(bld->gallivm, texture_unit);
>
> /* Note that all simplified calculations will only work for isotropic filtering */
>
> @@ -247,7 +248,7 @@ lp_build_rho(struct lp_build_sample_context *bld,
> */
>
> first_level = bld->dynamic_state->first_level(bld->dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
> 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);
> float_size = lp_build_int_to_float(float_size_bld, int_size);
> @@ -904,11 +905,12 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
> 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;
> + LLVMValueRef tunit = lp_build_const_int32(bld->gallivm, texture_unit);
>
> first_level = dynamic_state->first_level(dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
> last_level = dynamic_state->last_level(dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
> first_level = lp_build_broadcast_scalar(leveli_bld, first_level);
> last_level = lp_build_broadcast_scalar(leveli_bld, last_level);
>
> @@ -964,13 +966,14 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
> LLVMValueRef first_level, last_level;
> LLVMValueRef clamp_min;
> LLVMValueRef clamp_max;
> + LLVMValueRef tunit = lp_build_const_int32(bld->gallivm, texture_unit);
>
> assert(bld->num_lods == bld->num_mips);
>
> first_level = dynamic_state->first_level(dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
> last_level = dynamic_state->last_level(dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
> first_level = lp_build_broadcast_scalar(leveli_bld, first_level);
> last_level = lp_build_broadcast_scalar(leveli_bld, last_level);
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
> index 9ec051a..aecce14 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
> @@ -194,63 +194,63 @@ struct lp_sampler_dynamic_state
> (*width)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain the base texture height (returns int32) */
> LLVMValueRef
> (*height)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain the base texture depth (or array size) (returns int32) */
> LLVMValueRef
> (*depth)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain the first mipmap level (base level) (returns int32) */
> LLVMValueRef
> (*first_level)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain the number of mipmap levels minus one (returns int32) */
> LLVMValueRef
> (*last_level)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain stride in bytes between image rows/blocks (returns int32) */
> LLVMValueRef
> (*row_stride)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain stride in bytes between image slices (returns int32) */
> LLVMValueRef
> (*img_stride)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain pointer to base of texture */
> LLVMValueRef
> (*base_ptr)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /** Obtain pointer to array of mipmap offsets */
> LLVMValueRef
> (*mip_offsets)(const struct lp_sampler_dynamic_state *state,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit);
> + LLVMValueRef texture_unit);
>
> /* These are callbacks for sampler state */
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> index c16b1c9..d39fb60 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> @@ -1743,9 +1743,10 @@ lp_build_layer_coord(struct lp_build_sample_context *bld,
> {
> LLVMValueRef num_layers;
> struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
> + LLVMValueRef tunit = lp_build_const_int32(bld->gallivm, texture_unit);
>
> num_layers = bld->dynamic_state->depth(bld->dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
>
> if (out_of_bounds) {
> LLVMValueRef out1, out;
> @@ -1790,7 +1791,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
> LLVMValueRef first_level, cube_rho = NULL;
> LLVMValueRef lod_ipart = NULL;
> struct lp_derivatives cube_derivs;
> -
> + LLVMValueRef tunit = lp_build_const_int32(bld->gallivm, texture_index);
> /*
> printf("%s mip %d min %d mag %d\n", __FUNCTION__,
> mip_filter, min_filter, mag_filter);
> @@ -1882,7 +1883,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
> /* always use mip level 0 */
> first_level = bld->dynamic_state->first_level(bld->dynamic_state,
> bld->gallivm, bld->context_ptr,
> - texture_index);
> + tunit);
> first_level = lp_build_broadcast_scalar(&bld->leveli_bld, first_level);
> *ilevel0 = first_level;
> break;
> @@ -2299,7 +2300,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 tunit = lp_build_const_int32(bld->gallivm, texture_unit);
> out_of_bounds = int_coord_bld->zero;
>
> if (explicit_lod && bld->static_texture_state->target != PIPE_BUFFER) {
> @@ -2317,7 +2318,7 @@ lp_build_fetch_texel(struct lp_build_sample_context *bld,
> assert(bld->num_mips == 1);
> if (bld->static_texture_state->target != PIPE_BUFFER) {
> ilevel = bld->dynamic_state->first_level(bld->dynamic_state, bld->gallivm,
> - bld->context_ptr, texture_unit);
> + bld->context_ptr, tunit);
> }
> else {
> ilevel = lp_build_const_int32(bld->gallivm, 0);
> @@ -2466,6 +2467,7 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
> LLVMValueRef lod_bias = NULL;
> LLVMValueRef explicit_lod = NULL;
> boolean op_is_tex;
> + LLVMValueRef tunit = lp_build_const_int32(gallivm, texture_index);
>
> if (0) {
> enum pipe_format fmt = static_texture_state->format;
> @@ -2699,15 +2701,15 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
>
> /* Get the dynamic state */
> tex_width = dynamic_state->width(dynamic_state, gallivm,
> - context_ptr, texture_index);
> + context_ptr, tunit);
> bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm,
> - context_ptr, texture_index);
> + context_ptr, tunit);
> bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm,
> - context_ptr, texture_index);
> + context_ptr, tunit);
> bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm,
> - context_ptr, texture_index);
> + context_ptr, tunit);
> bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm,
> - context_ptr, texture_index);
> + context_ptr, tunit);
> /* Note that mip_offsets is an array[level] of offsets to texture images */
>
> if (dynamic_state->cache_ptr && thread_data_ptr) {
> @@ -2726,14 +2728,14 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
> if (dims >= 2) {
> LLVMValueRef tex_height =
> dynamic_state->height(dynamic_state, gallivm,
> - context_ptr, texture_index);
> + context_ptr, tunit);
> bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
> tex_height,
> LLVMConstInt(i32t, 1, 0), "");
> if (dims >= 3) {
> LLVMValueRef tex_depth =
> dynamic_state->depth(dynamic_state, gallivm, context_ptr,
> - texture_index);
> + tunit);
> bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
> tex_depth,
> LLVMConstInt(i32t, 2, 0), "");
> @@ -3447,6 +3449,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
> boolean has_array;
> unsigned num_lods = 1;
> struct lp_build_context bld_int_vec4;
> + LLVMValueRef tunit = lp_build_const_int32(gallivm, params->texture_unit);
>
> if (static_state->format == PIPE_FORMAT_NONE) {
> /*
> @@ -3510,7 +3513,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
> lod = LLVMBuildExtractElement(gallivm->builder, params->explicit_lod,
> lp_build_const_int32(gallivm, 0), "");
> first_level = dynamic_state->first_level(dynamic_state, gallivm,
> - params->context_ptr, params->texture_unit);
> + params->context_ptr, tunit);
> level = LLVMBuildAdd(gallivm->builder, lod, first_level, "level");
> lod = lp_build_broadcast_scalar(&bld_int_vec4, level);
> } else {
> @@ -3522,14 +3525,14 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
> size = LLVMBuildInsertElement(gallivm->builder, size,
> dynamic_state->width(dynamic_state, gallivm,
> params->context_ptr,
> - params->texture_unit),
> + tunit),
> lp_build_const_int32(gallivm, 0), "");
>
> if (dims >= 2) {
> size = LLVMBuildInsertElement(gallivm->builder, size,
> dynamic_state->height(dynamic_state, gallivm,
> params->context_ptr,
> - params->texture_unit),
> + tunit),
> lp_build_const_int32(gallivm, 1), "");
> }
>
> @@ -3537,7 +3540,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
> size = LLVMBuildInsertElement(gallivm->builder, size,
> dynamic_state->depth(dynamic_state, gallivm,
> params->context_ptr,
> - params->texture_unit),
> + tunit),
> lp_build_const_int32(gallivm, 2), "");
> }
>
> @@ -3546,7 +3549,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
> if (has_array) {
> LLVMValueRef layers = dynamic_state->depth(dynamic_state, gallivm,
> params->context_ptr,
> - params->texture_unit);
> + tunit);
> if (params->target == PIPE_TEXTURE_CUBE_ARRAY) {
> /*
> * It looks like GL wants number of cubes, d3d10.1 has it undefined?
> @@ -3573,7 +3576,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
> lp_build_context_init(&leveli_bld, gallivm, lp_type_int_vec(32, 32));
> last_level = dynamic_state->last_level(dynamic_state, gallivm,
> params->context_ptr,
> - params->texture_unit);
> + tunit);
>
> out = lp_build_cmp(&leveli_bld, PIPE_FUNC_LESS, level, first_level);
> out1 = lp_build_cmp(&leveli_bld, PIPE_FUNC_GREATER, level, last_level);
> @@ -3615,7 +3618,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
>
> last_level = dynamic_state->last_level(dynamic_state, gallivm,
> params->context_ptr,
> - params->texture_unit);
> + tunit);
> 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);
> }
> diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c
> index 8adaa8e..f002347 100644
> --- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c
> +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c
> @@ -91,7 +91,7 @@ static LLVMValueRef
> lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> struct gallivm_state *gallivm,
> LLVMValueRef context_ptr,
> - unsigned texture_unit,
> + LLVMValueRef tex_unit_ref,
> unsigned member_index,
> const char *member_name,
> boolean emit_load)
> @@ -101,14 +101,14 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> LLVMValueRef ptr;
> LLVMValueRef res;
>
> - assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
> +// assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
I think it would be nice if this would be replaced by assertions in the
places where the texture_unit number initially comes from (if it's an
immediate), if those places don't already do that.
>
> /* context[0] */
> indices[0] = lp_build_const_int32(gallivm, 0);
> /* context[0].textures */
> indices[1] = lp_build_const_int32(gallivm, LP_JIT_CTX_TEXTURES);
> /* context[0].textures[unit] */
> - indices[2] = lp_build_const_int32(gallivm, texture_unit);
> + indices[2] = tex_unit_ref;
> /* context[0].textures[unit].member */
> indices[3] = lp_build_const_int32(gallivm, member_index);
>
> @@ -119,7 +119,7 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> else
> res = ptr;
>
> - lp_build_name(res, "context.texture%u.%s", texture_unit, member_name);
> +// lp_build_name(res, "context.texture%u.%s", texture_unit, member_name);
Hmm it's kind of sad to see this go, as these names are quite useful
when examining the IR. I wonder if printing the LLVMGetValueName()
instead of the texture_unit number would be useful?
Otherwise,
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
>
> return res;
> }
> @@ -139,7 +139,7 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
> lp_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
> struct gallivm_state *gallivm, \
> LLVMValueRef context_ptr, \
> - unsigned texture_unit) \
> + LLVMValueRef texture_unit) \
> { \
> return lp_llvm_texture_member(base, gallivm, context_ptr, \
> texture_unit, _index, #_name, _emit_load ); \
>
More information about the mesa-dev
mailing list