zink: add spirv_builder methods for OpVectorExtractDynamic and OpVectorInsertDynamic
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 4 Jun 2020 21:01:58 +0000 (17:01 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 17 Jun 2020 20:42:01 +0000 (20:42 +0000)
based on spirv specs

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5163>

src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h

index 4f4b790cddc0f90ee5147730aa30619c7af87703..a03d08e06eb4a6a1753805c8091cc12835092e66 100644 (file)
@@ -465,6 +465,42 @@ spirv_builder_emit_vector_shuffle(struct spirv_builder *b, SpvId result_type,
    return result;
 }
 
+SpvId
+spirv_builder_emit_vector_extract(struct spirv_builder *b, SpvId result_type,
+                                  SpvId vector_1,
+                                  uint32_t component)
+{
+   SpvId result = spirv_builder_new_id(b);
+
+   int words = 5;
+   spirv_buffer_prepare(&b->instructions, words);
+   spirv_buffer_emit_word(&b->instructions, SpvOpVectorExtractDynamic | (words << 16));
+   spirv_buffer_emit_word(&b->instructions, result_type);
+   spirv_buffer_emit_word(&b->instructions, result);
+   spirv_buffer_emit_word(&b->instructions, vector_1);
+   spirv_buffer_emit_word(&b->instructions, spirv_builder_const_uint(b, 32, component));
+   return result;
+}
+
+SpvId
+spirv_builder_emit_vector_insert(struct spirv_builder *b, SpvId result_type,
+                                  SpvId vector_1,
+                                  SpvId component,
+                                  uint32_t index)
+{
+   SpvId result = spirv_builder_new_id(b);
+
+   int words = 6;
+   spirv_buffer_prepare(&b->instructions, words);
+   spirv_buffer_emit_word(&b->instructions, SpvOpVectorInsertDynamic | (words << 16));
+   spirv_buffer_emit_word(&b->instructions, result_type);
+   spirv_buffer_emit_word(&b->instructions, result);
+   spirv_buffer_emit_word(&b->instructions, vector_1);
+   spirv_buffer_emit_word(&b->instructions, component);
+   spirv_buffer_emit_word(&b->instructions, spirv_builder_const_uint(b, 32, index));
+   return result;
+}
+
 void
 spirv_builder_emit_branch(struct spirv_builder *b, SpvId label)
 {
index d13426a637ac7b3c70f0256960afcb8d786c4ca4..00000cf4e99296dc9ead0f0f6d9e8b2d19563acf 100644 (file)
@@ -192,7 +192,15 @@ spirv_builder_emit_vector_shuffle(struct spirv_builder *b, SpvId result_type,
                                   SpvId vector_1, SpvId vector_2,
                                   const uint32_t components[],
                                   size_t num_components);
-
+SpvId
+spirv_builder_emit_vector_extract(struct spirv_builder *b, SpvId result_type,
+                                  SpvId vector_1,
+                                  uint32_t component);
+SpvId
+spirv_builder_emit_vector_insert(struct spirv_builder *b, SpvId result_type,
+                                  SpvId vector_1,
+                                  SpvId component,
+                                  uint32_t index);
 void
 spirv_builder_emit_branch(struct spirv_builder *b, SpvId label);