lavapipe: Only check NULL pointers in one place in src_only_uses_uniforms
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 6 Feb 2023 18:23:25 +0000 (10:23 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 7 Feb 2023 19:15:16 +0000 (11:15 -0800)
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 <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21144>

src/gallium/frontends/lavapipe/lvp_inline_uniforms.c

index 1afb29b..a287125 100644 (file)
@@ -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;