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 <mattst88@gmail.com>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
This commit is contained in:
Ian Romanick 2019-03-20 13:42:46 -07:00
parent 5116646a76
commit e2ad047779
1 changed files with 12 additions and 1 deletions

View File

@ -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: