gallium/util: Add a helper function for point sprite handling.
authorEric Anholt <eric@anholt.net>
Tue, 3 Dec 2019 23:26:29 +0000 (15:26 -0800)
committerEric Anholt <eric@anholt.net>
Mon, 29 Jun 2020 16:07:17 +0000 (09:07 -0700)
Many drivers will need to do the same thing here, so consolidate it.

Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2952>

src/gallium/auxiliary/util/u_helpers.h

index 09a95a7ab70ddc1042604c4702b5bf203e44225a..db7b3efc71136d2581d4119e223adcddcc4043dd 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "pipe/p_state.h"
 #include "c11/threads.h"
+#include "compiler/shader_enums.h"
 #include <stdio.h>
 
 #ifdef __cplusplus
@@ -56,6 +57,24 @@ bool util_upload_index_buffer(struct pipe_context *pipe,
                               struct pipe_resource **out_buffer,
                               unsigned *out_offset, unsigned alignment);
 
+/* Helper function to determine if the varying should contain the point
+ * coordinates, given the sprite_coord_enable mask.  Requires
+ * PIPE_CAP_TGSI_TEXCOORD to be enabled.
+ */
+static inline bool
+util_varying_is_point_coord(gl_varying_slot slot, uint32_t sprite_coord_enable)
+{
+   if (slot == VARYING_SLOT_PNTC)
+      return true;
+
+   if (slot >= VARYING_SLOT_TEX0 && slot <= VARYING_SLOT_TEX7 &&
+       (sprite_coord_enable & (1 << (slot - VARYING_SLOT_TEX0)))) {
+      return true;
+   }
+
+   return false;
+}
+
 void
 util_pin_driver_threads_to_random_L3(struct pipe_context *ctx,
                                      thrd_t *upper_thread);