/* The value in shared memory is a 32-bit value */
if (type->is_boolean())
- ret = nir_i2b(&b, &instr->dest.ssa);
+ ret = nir_b2b1(&b, &instr->dest.ssa);
break;
}
case nir_intrinsic_store_shared: {
nir_ssa_def *nir_val = evaluate_rvalue(val);
/* The value in shared memory is a 32-bit value */
if (val->type->is_boolean())
- nir_val = nir_b2i32(&b, nir_val);
+ nir_val = nir_b2b32(&b, nir_val);
instr->src[0] = nir_src_for_ssa(nir_val);
instr->num_components = val->type->vector_elements;
result = &load->dest.ssa;
}
- if (intrin->dest.ssa.bit_size == 1)
- result = nir_i2b(b, result);
+ if (intrin->dest.ssa.bit_size == 1) {
+ /* For shared, we can go ahead and use NIR's and/or the back-end's
+ * standard encoding for booleans rather than forcing a 0/1 boolean.
+ * This should save an instruction or two.
+ */
+ if (mode == nir_var_mem_shared)
+ result = nir_b2b1(b, result);
+ else
+ result = nir_i2b(b, result);
+ }
return result;
}
nir_intrinsic_instr *store = nir_intrinsic_instr_create(b->shader, op);
if (value->bit_size == 1) {
- /* TODO: Make the native bool bit_size an option. */
- value = nir_b2i(b, value, 32);
+ /* For shared, we can go ahead and use NIR's and/or the back-end's
+ * standard encoding for booleans rather than forcing a 0/1 boolean.
+ * This should save an instruction or two.
+ *
+ * TODO: Make the native bool bit_size an option.
+ */
+ if (mode == nir_var_mem_shared)
+ value = nir_b2b32(b, value);
+ else
+ value = nir_b2i(b, value, 32);
}
store->src[0] = nir_src_for_ssa(value);
nir_builder_instr_insert(b, &load->instr);
if (load->dest.ssa.bit_size < 8) {
- /* Booleans are special-cased to be 32-bit
- *
- * Ideally, for drivers that can handle 32-bit booleans, we wouldn't
- * emit the i2b here. However, at this point, the driver is likely to
- * still have 1-bit booleans so we need to at least convert bit sizes.
- * Unfortunately, we don't have a good way to annotate the load as
- * loading a known boolean value so the optimizer isn't going to be
- * able to get rid of the conversion. Some day, we may solve that
- * problem but not today.
- */
+ /* Booleans are special-cased to be 32-bit */
assert(glsl_type_is_boolean(deref->type));
load->dest.ssa.bit_size = 32;
- return nir_i2b(b, &load->dest.ssa);
+ return nir_b2b1(b, &load->dest.ssa);
} else {
return &load->dest.ssa;
}