From d2dfcee7f7ebf87dae9570f1c7476eacb6240f83 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 27 Mar 2020 00:29:14 -0500 Subject: [PATCH] nir: Use b2b opcodes for shared and constant memory No shader-db changes on ICL with iris Reviewed-by: Alyssa Rosenzweig Reviewed-by: Kenneth Graunke Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 4 ++-- src/compiler/nir/nir_lower_io.c | 24 ++++++++++++++++++---- src/compiler/nir/nir_opt_large_constants.c | 13 ++---------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index fe045eaca9b..1101b9d39a6 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -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; diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index aac1e0e257e..92d2a1f8ba0 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -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); diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index a3c002f5f4c..e32265e50ec 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -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; } -- 2.30.2