From: Ian Romanick Date: Wed, 20 Mar 2019 20:42:46 +0000 (-0700) Subject: nir/search: Don't compare 8-bit or 1-bit constants with floats X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e2ad047779b02b48d35de8adaf92feed0f58aa3e;p=mesa.git nir/search: Don't compare 8-bit or 1-bit constants with floats Without this, adding an algebraic rule like (('bcsel', ('flt', a, 0.0), 0.0, ...), ...), will cause assertion failures inside nir_src_comp_as_float in GTF-GL46.gtf21.GL.lessThan.lessThan_vec3_frag (and related tests) from the OpenGL CTS and shaders/closed/steam/witcher-2/511.shader_test from shader-db. All of these cases have some code that ends up like ('bcsel', ('flt', a, 0.0), 'b@1', ...) When the 'b@1' is tested, nir_src_comp_as_float fails because there's no such thing as a 1-bit float. Reviewed-by: Matt Turner Reviewed-by: Thomas Helland --- diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 3ddda7ca332..4838825d7b4 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -326,7 +326,17 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src, return false; switch (const_val->type) { - case nir_type_float: + case nir_type_float: { + nir_load_const_instr *const load = + nir_instr_as_load_const(instr->src[src].src.ssa->parent_instr); + + /* There are 8-bit and 1-bit integer types, but there are no 8-bit or + * 1-bit float types. This prevents potential assertion failures in + * nir_src_comp_as_float. + */ + if (load->def.bit_size < 16) + return false; + for (unsigned i = 0; i < num_components; ++i) { double val = nir_src_comp_as_float(instr->src[src].src, new_swizzle[i]); @@ -334,6 +344,7 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src, return false; } return true; + } case nir_type_int: case nir_type_uint: