From 9fcbaf5d8932df59b6c9e69fe77d953d98d0fb82 Mon Sep 17 00:00:00 2001 From: Aleksi Sapon Date: Wed, 28 Jan 2026 11:49:48 -0500 Subject: [PATCH] llvmpipe: fix incorrect image 64bit fetch return value type Reviewed-by: Konstantin Seurer Part-of: --- .../auxiliary/gallivm/lp_bld_jit_sample.c | 12 +++---- src/gallium/auxiliary/gallivm/lp_bld_sample.h | 4 ++- .../auxiliary/gallivm/lp_bld_sample_soa.c | 31 +++++++++++++------ .../drivers/llvmpipe/lp_texture_handle.c | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c index 129d2b93ddf..4569f226a7f 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c @@ -449,6 +449,10 @@ lp_bld_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, { LLVMBuilderRef builder = gallivm->builder; + uint32_t flags = params->packed_op / LP_IMAGE_OP_COUNT; + bool ms = flags & LP_IMAGE_OP_MS; + bool is64 = flags & LP_IMAGE_OP_64; + if (params->resource) { const struct util_format_description *desc = util_format_description(params->format); struct lp_type texel_type = lp_build_texel_type(params->type, desc); @@ -480,10 +484,6 @@ lp_bld_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, gallivm, params->resource, offsetof(struct lp_descriptor, functions), offsetof(struct lp_texture_functions, image_functions)); - uint32_t flags = params->packed_op / LP_IMAGE_OP_COUNT; - bool ms = flags & LP_IMAGE_OP_MS; - bool is64 = flags & LP_IMAGE_OP_64; - LLVMTypeRef image_function_type = lp_build_image_function_type(gallivm, params, ms, is64); LLVMTypeRef image_function_ptr_type = LLVMPointerType(image_function_type, 0); LLVMTypeRef image_functions_type = LLVMPointerType(image_function_ptr_type, 0); @@ -578,13 +578,13 @@ lp_bld_llvm_image_soa_emit_op(const struct lp_build_image_soa *base, for (unsigned i = 0; i < image->nr_images; i++) { lp_build_image_op_array_case(&switch_info, i, &image->dynamic_state.static_state[i].image_state, - &image->dynamic_state.base); + &image->dynamic_state.base, is64); } lp_build_image_op_array_fini_soa(&switch_info); } else { lp_build_img_op_soa(&image->dynamic_state.static_state[image_index].image_state, &image->dynamic_state.base, - gallivm, params, params->outdata); + gallivm, params, is64, params->outdata); } } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 96ed67d9158..59e16a4279a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -862,6 +862,7 @@ 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, + bool is64, LLVMValueRef *outdata); void @@ -892,7 +893,8 @@ void lp_build_image_op_array_case(struct lp_build_img_op_array_switch *switch_info, int idx, const struct lp_static_texture_state *static_texture_state, - struct lp_sampler_dynamic_state *dynamic_state); + struct lp_sampler_dynamic_state *dynamic_state, + bool is64); void lp_build_image_op_array_fini_soa(struct lp_build_img_op_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 30a201f613f..a86fda5739b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -4641,18 +4641,28 @@ lp_build_do_atomic_soa(struct gallivm_state *gallivm, static void lp_build_img_op_no_format(struct gallivm_state *gallivm, const struct lp_img_params *params, + bool is64, 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; - } + if (params->img_op == LP_IMG_STORE) { + return; + } + + enum pipe_format format = params->format; + if (is64 && format == PIPE_FORMAT_NONE) + format = PIPE_FORMAT_R64G64B64A64_UINT; + + const struct util_format_description *desc = util_format_description(format); + const struct lp_type component_type = lp_build_texel_type(params->type, desc); + + LLVMValueRef zero = lp_build_zero(gallivm, component_type); + for (unsigned chan = 0; chan < (params->img_op == LP_IMG_LOAD ? 4 : 1); + chan++) { + outdata[chan] = zero; } } @@ -4662,6 +4672,7 @@ 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, + bool is64, LLVMValueRef *outdata) { const enum pipe_texture_target target = params->target; @@ -4680,7 +4691,7 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, 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); + lp_build_img_op_no_format(gallivm, params, is64, outdata); return; } @@ -4968,7 +4979,8 @@ void lp_build_image_op_array_case(struct lp_build_img_op_array_switch *switch_info, int idx, const struct lp_static_texture_state *static_texture_state, - struct lp_sampler_dynamic_state *dynamic_state) + struct lp_sampler_dynamic_state *dynamic_state, + bool is64) { struct gallivm_state *gallivm = switch_info->gallivm; LLVMBasicBlockRef this_block = lp_build_insert_new_block(gallivm, "img"); @@ -4981,7 +4993,8 @@ lp_build_image_op_array_case(struct lp_build_img_op_array_switch *switch_info, switch_info->params.image_index = idx; lp_build_img_op_soa(static_texture_state, dynamic_state, - switch_info->gallivm, &switch_info->params, tex_ret); + switch_info->gallivm, &switch_info->params, is64, + tex_ret); if (switch_info->params.img_op != LP_IMG_STORE) { for (unsigned i = 0; diff --git a/src/gallium/drivers/llvmpipe/lp_texture_handle.c b/src/gallium/drivers/llvmpipe/lp_texture_handle.c index 9198cbca790..88e0045ec9c 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture_handle.c +++ b/src/gallium/drivers/llvmpipe/lp_texture_handle.c @@ -449,7 +449,7 @@ compile_image_function(struct llvmpipe_context *ctx, struct lp_static_texture_st LLVMPositionBuilderAtEnd(gallivm->builder, block); LLVMValueRef outdata[5] = { 0 }; - lp_build_img_op_soa(&local_texture, lp_build_image_soa_dynamic_state(image_soa), gallivm, ¶ms, outdata); + lp_build_img_op_soa(&local_texture, lp_build_image_soa_dynamic_state(image_soa), gallivm, ¶ms, is64, outdata); for (uint32_t i = 1; i < 4; i++) if (!outdata[i])