Mesa (main): compiler/types: Unify the guts of get_sampler/image_count

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Oct 16 06:15:08 UTC 2021


Module: Mesa
Branch: main
Commit: 7558c9cb07ee186dac374c279520385ae7c036c3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7558c9cb07ee186dac374c279520385ae7c036c3

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Fri Oct 15 16:52:51 2021 -0500

compiler/types: Unify the guts of get_sampler/image_count

Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13389>

---

 src/compiler/nir_types.cpp | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index 2b37fd2fb45..7b6b57f3078 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -883,12 +883,12 @@ glsl_get_cl_type_size_align(const struct glsl_type *type,
    *align = glsl_get_cl_alignment(type);
 }
 
-unsigned
-glsl_type_get_sampler_count(const struct glsl_type *type)
+static unsigned
+glsl_type_count(const glsl_type *type, glsl_base_type base_type)
 {
    if (glsl_type_is_array(type)) {
-      return (glsl_get_aoa_size(type) *
-              glsl_type_get_sampler_count(glsl_without_array(type)));
+      return glsl_get_length(type) *
+             glsl_type_count(glsl_get_array_element(type), base_type);
    }
 
    /* Ignore interface blocks - they can only contain bindless samplers,
@@ -897,38 +897,26 @@ glsl_type_get_sampler_count(const struct glsl_type *type)
    if (glsl_type_is_struct(type)) {
       unsigned count = 0;
       for (unsigned i = 0; i < glsl_get_length(type); i++)
-         count += glsl_type_get_sampler_count(glsl_get_struct_field(type, i));
+         count += glsl_type_count(glsl_get_struct_field(type, i), base_type);
       return count;
    }
 
-   if (glsl_type_is_sampler(type))
+   if (glsl_get_base_type(type) == base_type)
       return 1;
 
    return 0;
 }
 
 unsigned
-glsl_type_get_image_count(const struct glsl_type *type)
+glsl_type_get_sampler_count(const struct glsl_type *type)
 {
-   if (glsl_type_is_array(type)) {
-      return (glsl_get_aoa_size(type) *
-              glsl_type_get_image_count(glsl_without_array(type)));
-   }
-
-   /* Ignore interface blocks - they can only contain bindless images,
-    * which we shouldn't count.
-    */
-   if (glsl_type_is_struct(type)) {
-      unsigned count = 0;
-      for (unsigned i = 0; i < glsl_get_length(type); i++)
-         count += glsl_type_get_image_count(glsl_get_struct_field(type, i));
-      return count;
-   }
-
-   if (glsl_type_is_image(type))
-      return 1;
+   return glsl_type_count(type, GLSL_TYPE_SAMPLER);
+}
 
-   return 0;
+unsigned
+glsl_type_get_image_count(const struct glsl_type *type)
+{
+   return glsl_type_count(type, GLSL_TYPE_IMAGE);
 }
 
 enum glsl_interface_packing



More information about the mesa-commit mailing list