Mesa (main): nir_to_tgsi: Use explicit sizes of NIR variables for UBO declarations.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Aug 31 20:32:50 UTC 2021
Module: Mesa
Branch: main
Commit: 600bdde2c1a9e60b3d4136d7c76419d59204431e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=600bdde2c1a9e60b3d4136d7c76419d59204431e
Author: Emma Anholt <emma at anholt.net>
Date: Mon Aug 2 10:43:02 2021 -0700
nir_to_tgsi: Use explicit sizes of NIR variables for UBO declarations.
This fixes duplicate CB0 declarations, missing interface array
declarations, and too-low sizes of UBOs containing multiple nir_variables.
Closes: #4810
Reviewed-by: Adam Jackson <ajax at redhat.com>
Acked-by: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12175>
---
src/gallium/auxiliary/nir/nir_to_tgsi.c | 43 +++++++++++++++++++++------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c
index 98b25ac1c27..75ebe270cfe 100644
--- a/src/gallium/auxiliary/nir/nir_to_tgsi.c
+++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c
@@ -407,9 +407,6 @@ tgsi_target_from_sampler_dim(enum glsl_sampler_dim dim, bool is_array)
static void
ntt_setup_uniforms(struct ntt_compile *c)
{
- struct pipe_screen *screen = c->screen;
- bool packed = screen->get_param(screen, PIPE_CAP_PACKED_UNIFORMS);
-
nir_foreach_uniform_variable(var, c->s) {
if (glsl_type_is_image(var->type)) {
enum tgsi_texture_type tex_type =
@@ -426,22 +423,38 @@ ntt_setup_uniforms(struct ntt_compile *c)
uint32_t offset = var->data.offset / 4;
uint32_t size = glsl_atomic_size(var->type) / 4;
ureg_DECL_hw_atomic(c->ureg, offset, offset + size - 1, var->data.binding, 0);
- } else {
- unsigned size;
- if (packed) {
- size = DIV_ROUND_UP(glsl_count_dword_slots(var->type,
- var->data.bindless), 4);
- } else {
- size = glsl_count_vec4_slots(var->type, false, var->data.bindless);
- }
-
- for (unsigned i = 0; i < size; i++)
- ureg_DECL_constant(c->ureg, var->data.driver_location + i);
}
+
+ /* lower_uniforms_to_ubo lowered non-sampler uniforms to UBOs, so CB0
+ * size declaration happens with other UBOs below.
+ */
}
+ unsigned ubo_sizes[PIPE_MAX_CONSTANT_BUFFERS] = {0};
nir_foreach_variable_with_modes(var, c->s, nir_var_mem_ubo) {
- ureg_DECL_constant2D(c->ureg, 0, 0, var->data.driver_location);
+ int ubo = var->data.driver_location;
+ if (ubo == -1)
+ continue;
+
+ unsigned size = glsl_get_explicit_size(var->interface_type, false);
+
+ int array_size = 1;
+ if (glsl_type_is_interface(glsl_without_array(var->type)))
+ array_size = MAX2(1, glsl_array_size(var->type));
+ for (int i = 0; i < array_size; i++) {
+ /* Even if multiple NIR variables are in the same uniform block, their
+ * explicit size is the size of the block.
+ */
+ if (ubo_sizes[ubo + i])
+ assert(ubo_sizes[ubo + i] == size);
+
+ ubo_sizes[ubo + i] = size;
+ }
+ }
+
+ for (int i = 0; i < ARRAY_SIZE(ubo_sizes); i++) {
+ if (ubo_sizes[i])
+ ureg_DECL_constant2D(c->ureg, 0, DIV_ROUND_UP(ubo_sizes[i], 16) - 1, i);
}
for (int i = 0; i < c->s->info.num_ssbos; i++) {
More information about the mesa-commit
mailing list