Mesa (master): mesa/st: Move the dword slot counting function to glsl_types as well.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 15 00:28:40 UTC 2020


Module: Mesa
Branch: master
Commit: bc4f089d0167dc22fb86c85fbd0fd0fa6f073a85
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bc4f089d0167dc22fb86c85fbd0fd0fa6f073a85

Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan  6 12:00:57 2020 -0800

mesa/st: Move the dword slot counting function to glsl_types as well.

To implement NIR-to-TGSI, we need to be able to get the size of the
uniform variable for the TGSI declaration, not just the
.driver_location.  With its location in mesa/st, drivers couldn't link
to it from nir-to-tgsi.

This feels like a common enough function to want, so let's share it in
the core compiler.

Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3297>

---

 src/compiler/glsl_types.cpp                | 52 ++++++++++++++++++++
 src/compiler/glsl_types.h                  |  8 +++
 src/compiler/nir_types.cpp                 |  6 +++
 src/compiler/nir_types.h                   |  1 +
 src/mesa/Makefile.sources                  |  2 -
 src/mesa/meson.build                       |  2 -
 src/mesa/state_tracker/st_glsl_to_nir.cpp  | 10 +++-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  1 -
 src/mesa/state_tracker/st_glsl_types.cpp   | 78 ------------------------------
 src/mesa/state_tracker/st_glsl_types.h     | 44 -----------------
 src/mesa/state_tracker/st_nir_builtins.c   |  1 -
 11 files changed, 75 insertions(+), 130 deletions(-)

diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index a814166f9e5..e664f4ab4cd 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -2517,6 +2517,58 @@ glsl_type::count_vec4_slots(bool is_gl_vertex_input, bool is_bindless) const
    return 0;
 }
 
+unsigned
+glsl_type::count_dword_slots(bool is_bindless) const
+{
+   switch (this->base_type) {
+   case GLSL_TYPE_UINT:
+   case GLSL_TYPE_INT:
+   case GLSL_TYPE_FLOAT:
+   case GLSL_TYPE_BOOL:
+      return this->components();
+   case GLSL_TYPE_UINT16:
+   case GLSL_TYPE_INT16:
+   case GLSL_TYPE_FLOAT16:
+      return DIV_ROUND_UP(this->components(), 2);
+   case GLSL_TYPE_UINT8:
+   case GLSL_TYPE_INT8:
+      return DIV_ROUND_UP(this->components(), 4);
+   case GLSL_TYPE_IMAGE:
+   case GLSL_TYPE_SAMPLER:
+      if (!is_bindless)
+         return 0;
+      /* FALLTHROUGH */
+   case GLSL_TYPE_DOUBLE:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
+      return this->components() * 2;
+   case GLSL_TYPE_ARRAY:
+      return this->fields.array->count_dword_slots(is_bindless) *
+             this->length;
+
+   case GLSL_TYPE_STRUCT: {
+      unsigned size = 0;
+      for (unsigned i = 0; i < this->length; i++) {
+         size += this->fields.structure[i].type->count_dword_slots(is_bindless);
+      }
+      return size;
+   }
+
+   case GLSL_TYPE_ATOMIC_UINT:
+      return 0;
+   case GLSL_TYPE_SUBROUTINE:
+      return 1;
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
+   case GLSL_TYPE_INTERFACE:
+   case GLSL_TYPE_FUNCTION:
+   default:
+      unreachable("invalid type in st_glsl_type_dword_size()");
+   }
+
+   return 0;
+}
+
 int
 glsl_type::coordinate_components() const
 {
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index c29d589a148..76a6fd2e448 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -481,6 +481,14 @@ public:
     */
    unsigned count_vec4_slots(bool is_gl_vertex_input, bool bindless) const;
 
+   /**
+    * Calculate the number of vec4 slots required to hold this type.
+    *
+    * This is the underlying recursive type_size function for
+    * gallium's PIPE_CAP_PACKED_UNIFORMS case.
+    */
+   unsigned count_dword_slots(bool bindless) const;
+
    /**
     * Calculate the number of attribute slots required to hold this type
     *
diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index ecceffeb351..1e45df74452 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -159,6 +159,12 @@ glsl_count_vec4_slots(const struct glsl_type *type,
    return type->count_vec4_slots(is_gl_vertex_input, is_bindless);
 }
 
+unsigned
+glsl_count_dword_slots(const struct glsl_type *type, bool is_bindless)
+{
+   return type->count_dword_slots(is_bindless);
+}
+
 unsigned
 glsl_count_attribute_slots(const struct glsl_type *type,
                            bool is_gl_vertex_input)
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
index ff4c7fae85a..d61cfeb3978 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -82,6 +82,7 @@ unsigned glsl_get_aoa_size(const struct glsl_type *type);
 
 unsigned glsl_count_vec4_slots(const struct glsl_type *type,
                                bool is_gl_vertex_input, bool is_bindless);
+unsigned glsl_count_dword_slots(const struct glsl_type *type, bool is_bindless);
 unsigned glsl_count_attribute_slots(const struct glsl_type *type,
                                     bool is_gl_vertex_input);
 unsigned glsl_get_component_slots(const struct glsl_type *type);
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index e4252ce8006..b65ada9b9f3 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -534,8 +534,6 @@ STATETRACKER_FILES = \
 	state_tracker/st_glsl_to_tgsi_private.h \
 	state_tracker/st_glsl_to_tgsi_temprename.cpp \
 	state_tracker/st_glsl_to_tgsi_temprename.h \
-	state_tracker/st_glsl_types.cpp \
-	state_tracker/st_glsl_types.h \
 	state_tracker/st_manager.c \
 	state_tracker/st_manager.h \
 	state_tracker/st_mesa_to_tgsi.c \
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index 4651ef88d6a..bc165572c26 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -578,8 +578,6 @@ files_libmesa_gallium = files(
   'state_tracker/st_glsl_to_tgsi_private.h',
   'state_tracker/st_glsl_to_tgsi_temprename.cpp',
   'state_tracker/st_glsl_to_tgsi_temprename.h',
-  'state_tracker/st_glsl_types.cpp',
-  'state_tracker/st_glsl_types.h',
   'state_tracker/st_manager.c',
   'state_tracker/st_manager.h',
   'state_tracker/st_mesa_to_tgsi.c',
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index d148e89d823..9c6031f4a19 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -40,7 +40,6 @@
 
 #include "main/shaderobj.h"
 #include "st_context.h"
-#include "st_glsl_types.h"
 #include "st_program.h"
 #include "st_shader_cache.h"
 
@@ -897,6 +896,12 @@ st_nir_lower_samplers(struct pipe_screen *screen, nir_shader *nir,
    }
 }
 
+static int
+st_packed_uniforms_type_size(const struct glsl_type *type, bool bindless)
+{
+   return glsl_count_dword_slots(type, bindless);
+}
+
 static int
 st_unpacked_uniforms_type_size(const struct glsl_type *type, bool bindless)
 {
@@ -907,7 +912,8 @@ void
 st_nir_lower_uniforms(struct st_context *st, nir_shader *nir)
 {
    if (st->ctx->Const.PackedDriverUniformStorage) {
-      NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
+      NIR_PASS_V(nir, nir_lower_io, nir_var_uniform,
+                 st_packed_uniforms_type_size,
                  (nir_lower_io_options)0);
       NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
    } else {
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 9a6bf30803f..0416a0b02a1 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -49,7 +49,6 @@
 #include "tgsi/tgsi_info.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
-#include "st_glsl_types.h"
 #include "st_program.h"
 #include "st_mesa_to_tgsi.h"
 #include "st_format.h"
diff --git a/src/mesa/state_tracker/st_glsl_types.cpp b/src/mesa/state_tracker/st_glsl_types.cpp
deleted file mode 100644
index 07275e3b8be..00000000000
--- a/src/mesa/state_tracker/st_glsl_types.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2005-2007  Brian Paul   All Rights Reserved.
- * Copyright (C) 2008  VMware, Inc.   All Rights Reserved.
- * Copyright © 2010 Intel Corporation
- * Copyright © 2011 Bryan Cain
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "st_glsl_types.h"
-
-int
-st_glsl_type_dword_size(const struct glsl_type *type, bool bindless)
-{
-   unsigned int size, i;
-
-   switch (type->base_type) {
-   case GLSL_TYPE_UINT:
-   case GLSL_TYPE_INT:
-   case GLSL_TYPE_FLOAT:
-   case GLSL_TYPE_BOOL:
-      return type->components();
-   case GLSL_TYPE_UINT16:
-   case GLSL_TYPE_INT16:
-   case GLSL_TYPE_FLOAT16:
-      return DIV_ROUND_UP(type->components(), 2);
-   case GLSL_TYPE_UINT8:
-   case GLSL_TYPE_INT8:
-      return DIV_ROUND_UP(type->components(), 4);
-   case GLSL_TYPE_IMAGE:
-   case GLSL_TYPE_SAMPLER:
-      if (!bindless)
-         return 0;
-   case GLSL_TYPE_DOUBLE:
-   case GLSL_TYPE_UINT64:
-   case GLSL_TYPE_INT64:
-      return type->components() * 2;
-   case GLSL_TYPE_ARRAY:
-      return st_glsl_type_dword_size(type->fields.array, bindless) *
-             type->length;
-   case GLSL_TYPE_STRUCT:
-      size = 0;
-      for (i = 0; i < type->length; i++) {
-         size += st_glsl_type_dword_size(type->fields.structure[i].type,
-                                         bindless);
-      }
-      return size;
-   case GLSL_TYPE_ATOMIC_UINT:
-      return 0;
-   case GLSL_TYPE_SUBROUTINE:
-      return 1;
-   case GLSL_TYPE_VOID:
-   case GLSL_TYPE_ERROR:
-   case GLSL_TYPE_INTERFACE:
-   case GLSL_TYPE_FUNCTION:
-   default:
-      unreachable("invalid type in st_glsl_type_dword_size()");
-   }
-
-   return 0;
-}
diff --git a/src/mesa/state_tracker/st_glsl_types.h b/src/mesa/state_tracker/st_glsl_types.h
deleted file mode 100644
index fb1c4a269d6..00000000000
--- a/src/mesa/state_tracker/st_glsl_types.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2005-2007  Brian Paul   All Rights Reserved.
- * Copyright (C) 2008  VMware, Inc.   All Rights Reserved.
- * Copyright © 2010 Intel Corporation
- * Copyright © 2011 Bryan Cain
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __ST_GLSL_TYPES_H__
-#define __ST_GLSL_TYPES_H__
-
-#include "compiler/glsl_types.h"
-#include "compiler/nir/nir.h"
-#include "compiler/nir_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int st_glsl_type_dword_size(const struct glsl_type *type, bool bindless);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __ST_GLSL_TYPES_H__ */
diff --git a/src/mesa/state_tracker/st_nir_builtins.c b/src/mesa/state_tracker/st_nir_builtins.c
index de518098024..52e68d3f69c 100644
--- a/src/mesa/state_tracker/st_nir_builtins.c
+++ b/src/mesa/state_tracker/st_nir_builtins.c
@@ -21,7 +21,6 @@
  */
 
 #include "tgsi/tgsi_from_mesa.h"
-#include "st_glsl_types.h"
 #include "st_nir.h"
 
 #include "compiler/nir/nir_builder.h"



More information about the mesa-commit mailing list