From e86cc99649cd08c5fc9e2945918570bfe67edc5c Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 4 Mar 2022 10:59:12 -0500 Subject: [PATCH] gallivm: avoid division by zero when computing cube face this is illegal and produces NaNs which blow up the sample instr cc: mesa-stable fixes (llvmpipe and zink): KHR-GL45.incomplete_texture_access.sampler dEQP-GLES31.functional.program_uniform.by_pointer.render.array_in_struct.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_pointer.render.array_in_struct.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_pointer.render.array_in_struct.sampler2D_samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_pointer.render.basic.samplerCube_both dEQP-GLES31.functional.program_uniform.by_pointer.render.basic.samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_pointer.render.basic.samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_pointer.render.basic_struct.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_pointer.render.basic_struct.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_pointer.render.nested_structs_arrays.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_pointer.render.nested_structs_arrays.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_pointer.render.nested_structs_arrays.sampler2D_samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_pointer.render.struct_in_array.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_pointer.render.struct_in_array.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_pointer.render.struct_in_array.sampler2D_samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_value.render.array_in_struct.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_value.render.array_in_struct.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_value.render.array_in_struct.sampler2D_samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_value.render.basic.samplerCube_both dEQP-GLES31.functional.program_uniform.by_value.render.basic.samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_value.render.basic.samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_value.render.basic_struct.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_value.render.basic_struct.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_value.render.nested_structs_arrays.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_value.render.nested_structs_arrays.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_value.render.nested_structs_arrays.sampler2D_samplerCube_vertex dEQP-GLES31.functional.program_uniform.by_value.render.struct_in_array.sampler2D_samplerCube_both dEQP-GLES31.functional.program_uniform.by_value.render.struct_in_array.sampler2D_samplerCube_fragment dEQP-GLES31.functional.program_uniform.by_value.render.struct_in_array.sampler2D_samplerCube_vertex Reviewed-by: Roland Scheidegger Part-of: (cherry picked from commit c82dcdf598f7b78c4a0106a71e008b482cf8f70b) --- .pick_status.json | 2 +- src/gallium/auxiliary/gallivm/lp_bld_sample.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index ae46ae32899..6129189cd2f 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -544,7 +544,7 @@ "description": "gallivm: avoid division by zero when computing cube face", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index 0c9a41aeb26..19bd8463d44 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -1726,7 +1726,10 @@ lp_build_cube_imapos(struct lp_build_context *coord_bld, LLVMValueRef coord) /* ima = +0.5 / abs(coord); */ LLVMValueRef posHalf = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, 0.5); LLVMValueRef absCoord = lp_build_abs(coord_bld, coord); - LLVMValueRef ima = lp_build_div(coord_bld, posHalf, absCoord); + /* avoid div by zero */ + LLVMValueRef sel = lp_build_cmp(coord_bld, PIPE_FUNC_GREATER, absCoord, coord_bld->zero); + LLVMValueRef div = lp_build_div(coord_bld, posHalf, absCoord); + LLVMValueRef ima = lp_build_select(coord_bld, sel, div, coord_bld->zero); return ima; }