From 3ca3b07fc1b46824fb7589fe06f9455d9f85bb12 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 16 Jun 2020 12:47:25 +1000 Subject: [PATCH] gallivm/nir: support passing image index into image code. This doesn't do anything yet, just adds parsing support for it. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 42 +++++++++++++++---- .../auxiliary/gallivm/lp_bld_nir_soa.c | 11 +++++ src/gallium/auxiliary/gallivm/lp_bld_sample.h | 1 + 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 734e0098f14..8daa0e09d8d 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -1077,6 +1077,10 @@ static void visit_load_image(struct lp_build_nir_context *bld_base, LLVMValueRef coords[5]; struct lp_img_params params; const struct glsl_type *type = glsl_without_array(var->type); + unsigned const_index; + LLVMValueRef indir_index; + get_deref_offset(bld_base, deref, false, NULL, NULL, + &const_index, &indir_index); memset(¶ms, 0, sizeof(params)); params.target = glsl_sampler_to_pipe(glsl_get_sampler_dim(type), glsl_sampler_type_is_array(type)); @@ -1090,7 +1094,8 @@ static void visit_load_image(struct lp_build_nir_context *bld_base, params.img_op = LP_IMG_LOAD; if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_MS) params.ms_index = get_src(bld_base, instr->src[2]); - params.image_index = var->data.binding; + params.image_index = var->data.binding + (indir_index ? 0 : const_index); + params.image_index_offset = indir_index; bld_base->image_op(bld_base, ¶ms); } @@ -1106,6 +1111,10 @@ static void visit_store_image(struct lp_build_nir_context *bld_base, LLVMValueRef coords[5]; struct lp_img_params params; const struct glsl_type *type = glsl_without_array(var->type); + unsigned const_index; + LLVMValueRef indir_index; + get_deref_offset(bld_base, deref, false, NULL, NULL, + &const_index, &indir_index); memset(¶ms, 0, sizeof(params)); params.target = glsl_sampler_to_pipe(glsl_get_sampler_dim(type), glsl_sampler_type_is_array(type)); @@ -1122,7 +1131,8 @@ static void visit_store_image(struct lp_build_nir_context *bld_base, if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_MS) params.ms_index = get_src(bld_base, instr->src[2]); params.img_op = LP_IMG_STORE; - params.image_index = var->data.binding; + params.image_index = var->data.binding + (indir_index ? 0 : const_index); + params.image_index_offset = indir_index; if (params.target == PIPE_TEXTURE_1D_ARRAY) coords[2] = coords[1]; @@ -1142,6 +1152,10 @@ static void visit_atomic_image(struct lp_build_nir_context *bld_base, LLVMValueRef in_val = get_src(bld_base, instr->src[3]); LLVMValueRef coords[5]; const struct glsl_type *type = glsl_without_array(var->type); + unsigned const_index; + LLVMValueRef indir_index; + get_deref_offset(bld_base, deref, false, NULL, NULL, + &const_index, &indir_index); memset(¶ms, 0, sizeof(params)); @@ -1194,7 +1208,8 @@ static void visit_atomic_image(struct lp_build_nir_context *bld_base, params.outdata = result; params.img_op = (instr->intrinsic == nir_intrinsic_image_deref_atomic_comp_swap) ? LP_IMG_ATOMIC_CAS : LP_IMG_ATOMIC; - params.image_index = var->data.binding; + params.image_index = var->data.binding + (indir_index ? 0 : const_index); + params.image_index_offset = indir_index; bld_base->image_op(bld_base, ¶ms); } @@ -1207,8 +1222,14 @@ static void visit_image_size(struct lp_build_nir_context *bld_base, nir_deref_instr *deref = nir_instr_as_deref(instr->src[0].ssa->parent_instr); nir_variable *var = nir_deref_instr_get_variable(deref); struct lp_sampler_size_query_params params = { 0 }; - params.texture_unit = var->data.binding; - params.target = glsl_sampler_to_pipe(glsl_get_sampler_dim(var->type), glsl_sampler_type_is_array(var->type)); + unsigned const_index; + LLVMValueRef indir_index; + const struct glsl_type *type = glsl_without_array(var->type); + get_deref_offset(bld_base, deref, false, NULL, NULL, + &const_index, &indir_index); + params.texture_unit = var->data.binding + (indir_index ? 0 : const_index); + params.texture_unit_offset = indir_index; + params.target = glsl_sampler_to_pipe(glsl_get_sampler_dim(type), glsl_sampler_type_is_array(type)); params.sizes_out = result; bld_base->image_size(bld_base, ¶ms); @@ -1221,8 +1242,15 @@ static void visit_image_samples(struct lp_build_nir_context *bld_base, nir_deref_instr *deref = nir_instr_as_deref(instr->src[0].ssa->parent_instr); nir_variable *var = nir_deref_instr_get_variable(deref); struct lp_sampler_size_query_params params = { 0 }; - params.texture_unit = var->data.binding; - params.target = glsl_sampler_to_pipe(glsl_get_sampler_dim(var->type), glsl_sampler_type_is_array(var->type)); + unsigned const_index; + LLVMValueRef indir_index; + const struct glsl_type *type = glsl_without_array(var->type); + get_deref_offset(bld_base, deref, false, NULL, NULL, + &const_index, &indir_index); + + params.texture_unit = var->data.binding + (indir_index ? 0 : const_index); + params.texture_unit_offset = indir_index; + params.target = glsl_sampler_to_pipe(glsl_get_sampler_dim(type), glsl_sampler_type_is_array(type)); params.sizes_out = result; params.samples_only = true; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 6444ae2237f..22ac493d2e3 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -1225,10 +1225,17 @@ static void emit_image_op(struct lp_build_nir_context *bld_base, struct lp_img_params *params) { struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; + struct gallivm_state *gallivm = bld_base->base.gallivm; + params->type = bld_base->base.type; params->context_ptr = bld->context_ptr; params->thread_data_ptr = bld->thread_data_ptr; params->exec_mask = mask_vec(bld_base); + + if (params->image_index_offset) + params->image_index_offset = LLVMBuildExtractElement(gallivm->builder, params->image_index_offset, + lp_build_const_int32(gallivm, 0), ""); + bld->image->emit_op(bld->image, bld->bld_base.base.gallivm, params); @@ -1239,10 +1246,14 @@ static void emit_image_size(struct lp_build_nir_context *bld_base, struct lp_sampler_size_query_params *params) { struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; + struct gallivm_state *gallivm = bld_base->base.gallivm; params->int_type = bld_base->int_bld.type; params->context_ptr = bld->context_ptr; + if (params->texture_unit_offset) + params->texture_unit_offset = LLVMBuildExtractElement(gallivm->builder, params->texture_unit_offset, + lp_build_const_int32(gallivm, 0), ""); bld->image->emit_size_query(bld->image, bld->bld_base.base.gallivm, params); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 22fab7445aa..9b42d3faad5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -140,6 +140,7 @@ struct lp_img_params { struct lp_type type; unsigned image_index; + LLVMValueRef image_index_offset; unsigned img_op; unsigned target; LLVMAtomicRMWBinOp op; -- 2.30.2