Module: Mesa Branch: main Commit: 25743209c4ee17aef3591461496fe64c1233657c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=25743209c4ee17aef3591461496fe64c1233657c
Author: Ian Romanick <ian.d.roman...@intel.com> Date: Fri Jul 21 17:05:12 2023 -0700 nir/lower_packing: Add lowering for nir_op_unpack_32_4x8 Nothing should currently hit this path. The next commit adds code to nir_pack_bits and nir_unpack_bits that can lead to this path being hit. v2: Change nir_u2uN(..., 8) to nir_u2u8(...). Suggested by Alyssa. v3: Don't generate nir_extract_u8 if the driver has set lower_extract_byte. These instructions were causing some problems for dozen. Reviewed-by: Alyssa Rosenzweig <aly...@rosenzweig.io> [v2] Reviewed-by: Caio Oliveira <caio.olive...@intel.com> [v2] Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24741> --- src/compiler/nir/nir_lower_packing.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_lower_packing.c b/src/compiler/nir/nir_lower_packing.c index f112d4b5995..4365d5c14ce 100644 --- a/src/compiler/nir/nir_lower_packing.c +++ b/src/compiler/nir/nir_lower_packing.c @@ -108,6 +108,26 @@ lower_pack_32_from_8(nir_builder *b, nir_def *src) } } +static nir_def * +lower_unpack_32_to_8(nir_builder *b, nir_def *src) +{ + /* Some drivers call nir_lower_pack after the last time nir_opt_algebraic + * is called. To prevent issues there, don't generate byte extraction + * instructions when the lowering flag is set. + */ + if (b->shader->options->lower_extract_byte) { + return nir_vec4(b, nir_u2u8(b, src ), + nir_u2u8(b, nir_ushr_imm(b, src, 8)), + nir_u2u8(b, nir_ushr_imm(b, src, 16)), + nir_u2u8(b, nir_ushr_imm(b, src, 24))); + } else { + return nir_vec4(b, nir_u2u8(b, nir_extract_u8_imm(b, src, 0)), + nir_u2u8(b, nir_extract_u8_imm(b, src, 1)), + nir_u2u8(b, nir_extract_u8_imm(b, src, 2)), + nir_u2u8(b, nir_extract_u8_imm(b, src, 3))); + } +} + static bool lower_pack_instr(nir_builder *b, nir_instr *instr, void *data) { @@ -122,7 +142,8 @@ lower_pack_instr(nir_builder *b, nir_instr *instr, void *data) alu_instr->op != nir_op_unpack_64_4x16 && alu_instr->op != nir_op_pack_32_2x16 && alu_instr->op != nir_op_unpack_32_2x16 && - alu_instr->op != nir_op_pack_32_4x8) + alu_instr->op != nir_op_pack_32_4x8 && + alu_instr->op != nir_op_unpack_32_4x8) return false; b->cursor = nir_before_instr(&alu_instr->instr); @@ -152,6 +173,9 @@ lower_pack_instr(nir_builder *b, nir_instr *instr, void *data) case nir_op_pack_32_4x8: dest = lower_pack_32_from_8(b, src); break; + case nir_op_unpack_32_4x8: + dest = lower_unpack_32_to_8(b, src); + break; default: unreachable("Impossible opcode"); }