Commit 30fd1dad authored by Timothy Arceri's avatar Timothy Arceri

nir: match constant bools with @bool type

For simplicity we only allow this to work for scalar types.
parent 632241b0
......@@ -49,10 +49,11 @@ static const uint8_t identity_swizzle[NIR_MAX_VEC_COMPONENTS] = { 0, 1, 2, 3 };
* Used for satisfying 'a@type' constraints.
*/
static bool
src_is_type(nir_src src, nir_alu_type type)
src_is_type(nir_alu_src alu_src, nir_alu_type type, unsigned num_components)
{
assert(type != nir_type_invalid);
nir_src src = alu_src.src;
if (!src.is_ssa)
return false;
......@@ -69,13 +70,18 @@ src_is_type(nir_src src, nir_alu_type type)
case nir_op_iand:
case nir_op_ior:
case nir_op_ixor:
return src_is_type(src_alu->src[0].src, nir_type_bool) &&
src_is_type(src_alu->src[1].src, nir_type_bool);
return src_is_type(src_alu->src[0], nir_type_bool,
nir_ssa_alu_instr_src_components(src_alu, 0)) &&
src_is_type(src_alu->src[1], nir_type_bool,
nir_ssa_alu_instr_src_components(src_alu, 1));
case nir_op_inot:
return src_is_type(src_alu->src[0].src, nir_type_bool);
return src_is_type(src_alu->src[0], nir_type_bool,
nir_ssa_alu_instr_src_components(src_alu, 0));
case nir_op_bcsel:
return src_is_type(src_alu->src[1].src, nir_type_bool) &&
src_is_type(src_alu->src[2].src, nir_type_bool);
return src_is_type(src_alu->src[1], nir_type_bool,
nir_ssa_alu_instr_src_components(src_alu, 1)) &&
src_is_type(src_alu->src[2], nir_type_bool,
nir_ssa_alu_instr_src_components(src_alu, 2));
default:
break;
}
......@@ -89,6 +95,14 @@ src_is_type(nir_src src, nir_alu_type type)
return intr->intrinsic == nir_intrinsic_load_front_face ||
intr->intrinsic == nir_intrinsic_load_helper_invocation;
}
} else if (src.ssa->parent_instr->type == nir_instr_type_load_const) {
nir_load_const_instr *load =
nir_instr_as_load_const(src.ssa->parent_instr);
if (type == nir_type_bool && num_components == 1) {
return load->value.u32[alu_src.swizzle[0]] == NIR_TRUE ||
load->value.u32[alu_src.swizzle[0]] == NIR_FALSE;
}
}
/* don't know */
......@@ -162,7 +176,8 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
return false;
if (var->type != nir_type_invalid &&
!src_is_type(instr->src[src].src, var->type))
!src_is_type(instr->src[src], var->type,
nir_ssa_alu_instr_src_components(instr, src)))
return false;
state->variables_seen |= (1 << var->variable);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment