zink: clean up const-value handling for get_ssbo_size

nir_src_as_const_value can return null pointers, and in other places we
at least assert for this. So let's do that here as well, which makes
Coverity a bit less paranoid.

While we're at it, avoid duplicating the nir_src_as_const_value call to
the same source.

CID: 1444291

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12594>
This commit is contained in:
Erik Faye-Lund 2021-08-26 11:12:23 +02:00 committed by Marge Bot
parent 3e22fc27af
commit 2b82f2b78b
1 changed files with 4 additions and 2 deletions

View File

@ -2454,9 +2454,11 @@ static void
emit_get_ssbo_size(struct ntv_context *ctx, nir_intrinsic_instr *intr)
{
SpvId uint_type = get_uvec_type(ctx, 32, 1);
nir_variable *var = ctx->ssbo_vars[nir_src_as_const_value(intr->src[0])->u32];
nir_const_value *const_block_index = nir_src_as_const_value(intr->src[0]);
assert(const_block_index); // no dynamic indexing for now
nir_variable *var = ctx->ssbo_vars[const_block_index->u32];
SpvId result = spirv_builder_emit_binop(&ctx->builder, SpvOpArrayLength, uint_type,
ctx->ssbos[nir_src_as_const_value(intr->src[0])->u32], 1);
ctx->ssbos[const_block_index->u32], 1);
/* this is going to be converted by nir to:
length = (buffer_size - offset) / stride