Mesa (master): nir: Always create UBO variable when lowering uniforms to ubo

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue May 5 09:38:46 UTC 2020


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

Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Fri Feb 14 02:14:07 2020 -0500

nir: Always create UBO variable when lowering uniforms to ubo

Zink needs to know the sizes of UBOs, and for normal UBOs we get this
from the nir_var_mem_ubo variables. This allows us to treat all of these
the same way.

We're about to need the same information for the in-progress D3D12
driver, so let's do this in a central location instead of in the driver.

This version is also a bit more careful than the Zink version. In
particular, for two reasons:
1. We increase the variable bindings when we adjust the pre-existing
   UBOs.
2. We increase shader->info.num_ubos when we insert a new UBO variable.

Reviewed-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4734>

---

 src/compiler/nir/nir_lower_uniforms_to_ubo.c | 29 ++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_lower_uniforms_to_ubo.c b/src/compiler/nir/nir_lower_uniforms_to_ubo.c
index 565410cf0cc..1046fdc6117 100644
--- a/src/compiler/nir/nir_lower_uniforms_to_ubo.c
+++ b/src/compiler/nir/nir_lower_uniforms_to_ubo.c
@@ -103,8 +103,33 @@ nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier)
       }
    }
 
+   if (progress) {
+      if (!shader->info.first_ubo_is_default_ubo) {
+         nir_foreach_variable(var, &shader->uniforms) {
+            if (var->data.mode == nir_var_mem_ubo)
+               var->data.binding++;
+         }
+      }
+
+      if (shader->num_uniforms > 0) {
+         const struct glsl_type *type = glsl_array_type(glsl_vec4_type(),
+                                                        shader->num_uniforms, 0);
+         nir_variable *ubo = nir_variable_create(shader, nir_var_mem_ubo, type,
+                                                 "uniform_0");
+         ubo->data.binding = 0;
+
+         struct glsl_struct_field field = {
+            .type = type,
+            .name = "data",
+            .location = -1,
+         };
+         ubo->interface_type =
+               glsl_interface_type(&field, 1, GLSL_INTERFACE_PACKING_STD430,
+                                   false, "__ubo0_interface");
+         shader->info.num_ubos++;
+      }
+   }
+
    shader->info.first_ubo_is_default_ubo = true;
    return progress;
 }
-
-



More information about the mesa-commit mailing list