From 65db990b39e5ef88a7ecf3d0926661a71a0db84c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Feb 2023 10:23:25 -0800 Subject: [PATCH] lavapipe: Only check NULL pointers in one place in src_only_uses_uniforms It took me a minute to figure out why the last uni_offsets NULL check didn't also need to check num_offsets. I think this makes the code slightly easier to understand. Reviewed-By: Mike Blumenkrantz Part-of: --- .../frontends/lavapipe/lvp_inline_uniforms.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c b/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c index 1afb29be8a9..a2871258401 100644 --- a/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c +++ b/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c @@ -86,22 +86,30 @@ src_only_uses_uniforms(const nir_src *src, int component, nir_src_is_const(intr->src[1]) && /* TODO: Can't handle other bit sizes for now. */ intr->dest.ssa.bit_size == 32) { + /* num_offsets can be NULL if-and-only-if uni_offsets is NULL. */ + assert((num_offsets == NULL) == (uni_offsets == NULL)); + + /* If we're just checking that it's a uniform load, don't check (or + * add to) the table. + */ + if (uni_offsets == NULL) + return true; + uint32_t offset = nir_src_as_uint(intr->src[1]) + component * 4; /* Already recorded by other one */ uint32_t ubo = nir_src_as_uint(intr->src[0]); - for (int i = 0; uni_offsets && i < num_offsets[ubo]; i++) { + for (int i = 0; i < num_offsets[ubo]; i++) { if (uni_offsets[ubo * PIPE_MAX_CONSTANT_BUFFERS + i] == offset) return true; } /* Exceed uniform number limit */ - if (num_offsets && num_offsets[ubo] == MAX_INLINABLE_UNIFORMS) + if (num_offsets[ubo] == MAX_INLINABLE_UNIFORMS) return false; /* Record the uniform offset. */ - if (uni_offsets) - uni_offsets[ubo * PIPE_MAX_CONSTANT_BUFFERS + num_offsets[ubo]++] = offset; + uni_offsets[ubo * PIPE_MAX_CONSTANT_BUFFERS + num_offsets[ubo]++] = offset; return true; } return false;