Mesa (master): zink: support non-const offsets

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 13 12:12:19 UTC 2020


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

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Fri Oct  9 13:21:53 2020 +0200

zink: support non-const offsets

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7079>

---

 .../drivers/zink/nir_to_spirv/nir_to_spirv.c       | 81 ++++++++++------------
 1 file changed, 38 insertions(+), 43 deletions(-)

diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
index b9de912f442..271fecbe397 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
@@ -1562,51 +1562,46 @@ emit_load_ubo_vec4(struct ntv_context *ctx, nir_intrinsic_instr *intr)
    assert(const_block_index); // no dynamic indexing for now
    assert(const_block_index->u32 == 0); // we only support the default UBO for now
 
-   nir_const_value *const_offset = nir_src_as_const_value(intr->src[1]);
-   if (const_offset) {
-      SpvId uvec4_type = get_uvec_type(ctx, 32, 4);
-      SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder,
-                                                      SpvStorageClassUniform,
-                                                      uvec4_type);
-
-      unsigned idx = const_offset->u32;
-      SpvId member = emit_uint_const(ctx, 32, 0);
-      SpvId offset = emit_uint_const(ctx, 32, idx);
-      SpvId offsets[] = { member, offset };
-      SpvId ptr = spirv_builder_emit_access_chain(&ctx->builder, pointer_type,
-                                                  ctx->ubos[0], offsets,
-                                                  ARRAY_SIZE(offsets));
-      SpvId result = spirv_builder_emit_load(&ctx->builder, uvec4_type, ptr);
-
-      SpvId type = get_dest_uvec_type(ctx, &intr->dest);
-      unsigned num_components = nir_dest_num_components(intr->dest);
-      if (num_components == 1) {
-         uint32_t components[] = { 0 };
-         result = spirv_builder_emit_composite_extract(&ctx->builder,
-                                                       type,
-                                                       result, components,
-                                                       1);
-      } else if (num_components < 4) {
-         SpvId constituents[num_components];
-         SpvId uint_type = spirv_builder_type_uint(&ctx->builder, 32);
-         for (uint32_t i = 0; i < num_components; ++i)
-            constituents[i] = spirv_builder_emit_composite_extract(&ctx->builder,
-                                                                   uint_type,
-                                                                   result, &i,
-                                                                   1);
-
-         result = spirv_builder_emit_composite_construct(&ctx->builder,
-                                                         type,
-                                                         constituents,
-                                                         num_components);
-      }
+   SpvId offset = get_src(ctx, &intr->src[1]);
+   SpvId uvec4_type = get_uvec_type(ctx, 32, 4);
+   SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder,
+                                                   SpvStorageClassUniform,
+                                                   uvec4_type);
+
+   SpvId member = emit_uint_const(ctx, 32, 0);
+   SpvId offsets[] = { member, offset };
+   SpvId ptr = spirv_builder_emit_access_chain(&ctx->builder, pointer_type,
+                                               ctx->ubos[0], offsets,
+                                               ARRAY_SIZE(offsets));
+   SpvId result = spirv_builder_emit_load(&ctx->builder, uvec4_type, ptr);
 
-      if (nir_dest_bit_size(intr->dest) == 1)
-         result = uvec_to_bvec(ctx, result, num_components);
+   SpvId type = get_dest_uvec_type(ctx, &intr->dest);
+   unsigned num_components = nir_dest_num_components(intr->dest);
+   if (num_components == 1) {
+      uint32_t components[] = { 0 };
+      result = spirv_builder_emit_composite_extract(&ctx->builder,
+                                                    type,
+                                                    result, components,
+                                                    1);
+   } else if (num_components < 4) {
+      SpvId constituents[num_components];
+      SpvId uint_type = spirv_builder_type_uint(&ctx->builder, 32);
+      for (uint32_t i = 0; i < num_components; ++i)
+         constituents[i] = spirv_builder_emit_composite_extract(&ctx->builder,
+                                                                uint_type,
+                                                                result, &i,
+                                                                1);
+
+      result = spirv_builder_emit_composite_construct(&ctx->builder,
+                                                      type,
+                                                      constituents,
+                                                      num_components);
+   }
+
+   if (nir_dest_bit_size(intr->dest) == 1)
+      result = uvec_to_bvec(ctx, result, num_components);
 
-      store_dest(ctx, &intr->dest, result, nir_type_uint);
-   } else
-      unreachable("uniform-addressing not yet supported");
+   store_dest(ctx, &intr->dest, result, nir_type_uint);
 }
 
 static void



More information about the mesa-commit mailing list