From 43da8223121b8807d2dd7fcf1276d145242365e6 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 8 Nov 2022 13:53:25 -0800 Subject: [PATCH] glsl_to_nir: Fix NIR bit-size of ir_triop_bitfield_extract and ir_quadop_bitfield_insert Previously these would return result->bit_size of 32 even though the type might have been int16_t or uint16_t. This prevents many assertion failures in "glsl: Use nir_type_convert instead of nir_type_conversion_op" on zink. Fixes: 5e922fbc160 ("glsl_to_nir: fix bitfield_extract with 16-bit operands") Acked-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index fc498fc..23884f1 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -2345,11 +2345,25 @@ nir_visitor::visit(ir_expression *ir) result = ir->type->is_int_16_32() ? nir_ibitfield_extract(&b, nir_i2i32(&b, srcs[0]), nir_i2i32(&b, srcs[1]), nir_i2i32(&b, srcs[2])) : nir_ubitfield_extract(&b, nir_u2u32(&b, srcs[0]), nir_i2i32(&b, srcs[1]), nir_i2i32(&b, srcs[2])); + + if (ir->type->base_type == GLSL_TYPE_INT16) { + result = nir_i2i16(&b, result); + } else if (ir->type->base_type == GLSL_TYPE_UINT16) { + result = nir_u2u16(&b, result); + } + break; case ir_quadop_bitfield_insert: result = nir_bitfield_insert(&b, nir_u2u32(&b, srcs[0]), nir_u2u32(&b, srcs[1]), nir_i2i32(&b, srcs[2]), nir_i2i32(&b, srcs[3])); + + if (ir->type->base_type == GLSL_TYPE_INT16) { + result = nir_i2i16(&b, result); + } else if (ir->type->base_type == GLSL_TYPE_UINT16) { + result = nir_u2u16(&b, result); + } + break; case ir_quadop_vector: result = nir_vec(&b, srcs, ir->type->vector_elements); @@ -2358,6 +2372,11 @@ nir_visitor::visit(ir_expression *ir) default: unreachable("not reached"); } + + /* The bit-size of the NIR SSA value must match the bit-size of the + * original GLSL IR expression. + */ + assert(result->bit_size == glsl_base_type_get_bit_size(ir->type->base_type)); } void -- 2.7.4