nir: Use b2b opcodes for shared and constant memory

No shader-db changes on ICL with iris

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4338>
This commit is contained in:
Jason Ekstrand 2020-03-27 00:29:14 -05:00 committed by Marge Bot
parent 16a80ff18a
commit d2dfcee7f7
3 changed files with 24 additions and 17 deletions

View File

@ -1549,7 +1549,7 @@ nir_visitor::visit(ir_call *ir)
/* 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: {
@ -1571,7 +1571,7 @@ nir_visitor::visit(ir_call *ir)
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;

View File

@ -938,8 +938,16 @@ build_explicit_io_load(nir_builder *b, nir_intrinsic_instr *intrin,
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;
}
@ -974,8 +982,16 @@ build_explicit_io_store(nir_builder *b, nir_intrinsic_instr *intrin,
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);

View File

@ -86,19 +86,10 @@ build_constant_load(nir_builder *b, nir_deref_instr *deref,
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;
}