From a046957a79c78ecdcfe1db844bde28bf9862ccbf Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 19 Jul 2019 17:35:27 +0200 Subject: [PATCH] zink/spirv: fixup b2i32 Acked-by: Jordan Justen --- .../drivers/zink/nir_to_spirv/nir_to_spirv.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index 0f5e9d4f9f1..3e4612fe1a9 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -66,6 +66,10 @@ static SpvId get_uvec_constant(struct ntv_context *ctx, unsigned bit_size, unsigned num_components, uint32_t value); +static SpvId +get_ivec_constant(struct ntv_context *ctx, unsigned bit_size, + unsigned num_components, int32_t value); + static SpvId emit_unop(struct ntv_context *ctx, SpvOp op, SpvId type, SpvId src); @@ -110,6 +114,13 @@ emit_uint_const(struct ntv_context *ctx, int bit_size, uint32_t value) return spirv_builder_const_uint(&ctx->builder, bit_size, value); } +static SpvId +emit_int_const(struct ntv_context *ctx, int bit_size, int32_t value) +{ + assert(bit_size == 32); + return spirv_builder_const_int(&ctx->builder, bit_size, value); +} + static SpvId get_fvec_type(struct ntv_context *ctx, unsigned bit_size, unsigned num_components) { @@ -719,6 +730,26 @@ get_uvec_constant(struct ntv_context *ctx, unsigned bit_size, num_components); } +static SpvId +get_ivec_constant(struct ntv_context *ctx, unsigned bit_size, + unsigned num_components, int32_t value) +{ + assert(bit_size == 32); + + SpvId result = emit_int_const(ctx, bit_size, value); + if (num_components == 1) + return result; + + assert(num_components > 1); + SpvId components[num_components]; + for (int i = 0; i < num_components; i++) + components[i] = result; + + SpvId type = get_ivec_type(ctx, bit_size, num_components); + return spirv_builder_const_composite(&ctx->builder, type, components, + num_components); +} + static inline unsigned alu_instr_src_components(const nir_alu_instr *instr, unsigned src) { @@ -829,8 +860,8 @@ emit_alu(struct ntv_context *ctx, nir_alu_instr *alu) case nir_op_b2i32: assert(nir_op_infos[alu->op].num_inputs == 1); result = emit_select(ctx, dest_type, src[0], - get_uvec_constant(ctx, 32, num_components, 1), - get_uvec_constant(ctx, 32, num_components, 0)); + get_ivec_constant(ctx, 32, num_components, 1), + get_ivec_constant(ctx, 32, num_components, 0)); break; case nir_op_b2f32: -- 2.30.2