zink: add spirv_builder_function_call
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 25 Aug 2022 07:42:43 +0000 (09:42 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 26 Aug 2022 10:05:03 +0000 (10:05 +0000)
It can be useful not just to create functions, but also being able to
call them. This adds the spirv_builder-helper for this.

Cc: mesa-stable
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18244>

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

index b1573e5..88eb233 100644 (file)
@@ -404,6 +404,28 @@ spirv_builder_function_end(struct spirv_builder *b)
    spirv_buffer_emit_word(&b->instructions, SpvOpFunctionEnd | (1 << 16));
 }
 
+SpvId
+spirv_builder_function_call(struct spirv_builder *b, SpvId result_type,
+                            SpvId function, const SpvId arguments[],
+                            size_t num_arguments)
+{
+   SpvId result = spirv_builder_new_id(b);
+
+   int words = 4 + num_arguments;
+   spirv_buffer_prepare(&b->instructions, b->mem_ctx, words);
+   spirv_buffer_emit_word(&b->instructions,
+                          SpvOpFunctionCall | (words << 16));
+   spirv_buffer_emit_word(&b->instructions, result_type);
+   spirv_buffer_emit_word(&b->instructions, result);
+   spirv_buffer_emit_word(&b->instructions, function);
+
+   for (int i = 0; i < num_arguments; ++i)
+      spirv_buffer_emit_word(&b->instructions, arguments[i]);
+
+   return result;
+}
+
+
 void
 spirv_builder_label(struct spirv_builder *b, SpvId label)
 {
index 01833ce..2d5887e 100644 (file)
@@ -414,6 +414,11 @@ spirv_builder_type_function(struct spirv_builder *b, SpvId return_type,
                             size_t num_parameter_types);
 
 SpvId
+spirv_builder_function_call(struct spirv_builder *b, SpvId result_type,
+                            SpvId function, const SpvId arguments[],
+                            size_t num_arguments);
+
+SpvId
 spirv_builder_const_bool(struct spirv_builder *b, bool val);
 
 SpvId