From 6e25a5a3756546b49bfaf53a2b16cc9b6d313928 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 16 Jun 2020 12:49:30 +1000 Subject: [PATCH] gallivm/nir: refactor image operations for indirect support. This just refactors the image code, so that outdata is passed explicitly, and refactors the internal handling of NONE formats. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/draw/draw_llvm_sample.c | 2 +- src/gallium/auxiliary/gallivm/lp_bld_sample.h | 7 ++- .../auxiliary/gallivm/lp_bld_sample_soa.c | 55 +++++++++---------- src/gallium/drivers/llvmpipe/lp_tex_sample.c | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c index ed78066d690..fa5729e3ef6 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_sample.c +++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c @@ -422,7 +422,7 @@ draw_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, lp_build_img_op_soa(&image->dynamic_state.static_state[image_index].image_state, &image->dynamic_state.base, - gallivm, params); + gallivm, params, params->outdata); } /** * Fetch the texture size. diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 9b42d3faad5..399c24df1d6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -706,9 +706,10 @@ lp_build_minify(struct lp_build_context *bld, void lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, - struct lp_sampler_dynamic_state *dynamic_state, - struct gallivm_state *gallivm, - const struct lp_img_params *params); + struct lp_sampler_dynamic_state *dynamic_state, + struct gallivm_state *gallivm, + const struct lp_img_params *params, + LLVMValueRef outdata[4]); void lp_build_sample_array_init_soa(struct lp_build_sample_array_switch *switch_info, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index a05b9efcc42..a852490f041 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -4093,11 +4093,29 @@ lp_build_do_atomic_soa(struct gallivm_state *gallivm, atomic_result[0] = LLVMBuildLoad(gallivm->builder, atom_res, ""); } +static void +lp_build_img_op_no_format(struct gallivm_state *gallivm, + const struct lp_img_params *params, + LLVMValueRef outdata[4]) +{ + /* + * If there's nothing bound, format is NONE, and we must return + * all zero as mandated by d3d10 in this case. + */ + if (params->img_op != LP_IMG_STORE) { + LLVMValueRef zero = lp_build_zero(gallivm, params->type); + for (unsigned chan = 0; chan < (params->img_op == LP_IMG_LOAD ? 4 : 1); chan++) { + outdata[chan] = zero; + } + } +} + void lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, struct lp_sampler_dynamic_state *dynamic_state, struct gallivm_state *gallivm, - const struct lp_img_params *params) + const struct lp_img_params *params, + LLVMValueRef outdata[4]) { unsigned target = params->target; unsigned dims = texture_dims(target); @@ -4113,6 +4131,10 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, lp_build_context_init(&int_bld, gallivm, int_type); lp_build_context_init(&int_coord_bld, gallivm, int_coord_type); + if (static_texture_state->format == PIPE_FORMAT_NONE) { + lp_build_img_op_no_format(gallivm, params, outdata); + return; + } LLVMValueRef offset, i, j; LLVMValueRef row_stride = dynamic_state->row_stride(dynamic_state, gallivm, @@ -4184,19 +4206,6 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, } } - if (static_texture_state->format == PIPE_FORMAT_NONE) { - /* - * If there's nothing bound, format is NONE, and we must return - * all zero as mandated by d3d10 in this case. - */ - unsigned chan; - LLVMValueRef zero = lp_build_zero(gallivm, params->type); - for (chan = 0; chan < 4; chan++) { - params->outdata[chan] = zero; - } - return; - } - offset = lp_build_andnot(&int_coord_bld, offset, out_of_bounds); struct lp_build_context texel_bld; lp_build_context_init(&texel_bld, gallivm, texel_type); @@ -4206,28 +4215,18 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, base_ptr, offset, i, j, NULL, - params->outdata); + outdata); for (unsigned chan = 0; chan < 4; chan++) { - params->outdata[chan] = lp_build_select(&texel_bld, out_of_bounds, - texel_bld.zero, params->outdata[chan]); + outdata[chan] = lp_build_select(&texel_bld, out_of_bounds, + texel_bld.zero, outdata[chan]); } } else if (params->img_op == LP_IMG_STORE) { - if (static_texture_state->format == PIPE_FORMAT_NONE) - return; lp_build_store_rgba_soa(gallivm, format_desc, params->type, params->exec_mask, base_ptr, offset, out_of_bounds, params->indata); } else { - if (static_texture_state->format == PIPE_FORMAT_NONE) { - /* - * For atomic operation just return 0 in the unbound case to avoid a crash. - */ - LLVMValueRef zero = lp_build_zero(gallivm, params->type); - params->outdata[0] = zero; - return; - } lp_build_do_atomic_soa(gallivm, format_desc, params->type, params->exec_mask, base_ptr, offset, out_of_bounds, - params->img_op, params->op, params->indata, params->indata2, params->outdata); + params->img_op, params->op, params->indata, params->indata2, outdata); } } diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c index 1f29be56bf1..6197275b761 100644 --- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c @@ -474,7 +474,7 @@ lp_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, lp_build_img_op_soa(&image->dynamic_state.static_state[image_index].image_state, &image->dynamic_state.base, - gallivm, params); + gallivm, params, params->outdata); } /** -- 2.30.2