nir: Add nir_alu_src_as_uint helper
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Tue, 25 Apr 2023 18:39:23 +0000 (14:39 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Thu, 11 May 2023 13:23:04 +0000 (09:23 -0400)
We have a few ALU instructions that take a constant source. Technically, they
have a swizzle so you can't just nir_src_as_uint them, even though a bunch of
backends do. To help backends do the right thing, add a helper that's just as
easy to use that will chase the swizzle properly.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22695>

src/compiler/nir/nir.h

index db75f75..9776aca 100644 (file)
@@ -2725,6 +2725,13 @@ nir_ssa_scalar_resolved(nir_ssa_def *def, unsigned channel)
    return nir_ssa_scalar_chase_movs(nir_get_ssa_scalar(def, channel));
 }
 
+static inline uint64_t
+nir_alu_src_as_uint(nir_alu_src src)
+{
+   assert(src.src.is_ssa && "precondition");
+   nir_ssa_scalar scalar = nir_get_ssa_scalar(src.src.ssa, src.swizzle[0]);
+   return nir_ssa_scalar_as_uint(scalar);
+}
 
 typedef struct {
    bool success;