From f3509c07663bf72da43d3b47c391acd75d33430a Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 17 Jul 2020 09:50:35 -0400 Subject: [PATCH] zink: add extension loading framework for spirv builder Reviewed-by: Erik Faye-Lund Part-of: --- .../drivers/zink/nir_to_spirv/spirv_builder.c | 12 ++++++++++++ .../drivers/zink/nir_to_spirv/spirv_builder.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c index 530036d3d70..1b7c676486a 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c +++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c @@ -96,6 +96,16 @@ spirv_builder_emit_cap(struct spirv_builder *b, SpvCapability cap) spirv_buffer_emit_word(&b->capabilities, cap); } +void +spirv_builder_emit_extension(struct spirv_builder *b, const char *name) +{ + size_t pos = b->extensions.num_words; + spirv_buffer_prepare(&b->extensions, b->mem_ctx, 1); + spirv_buffer_emit_word(&b->extensions, SpvOpExtension); + int len = spirv_buffer_emit_string(&b->extensions, b->mem_ctx, name); + b->extensions.words[pos] |= (1 + len) << 16; +} + void spirv_builder_emit_source(struct spirv_builder *b, SpvSourceLanguage lang, uint32_t version) @@ -1106,6 +1116,7 @@ spirv_builder_get_num_words(struct spirv_builder *b) const size_t header_size = 5; return header_size + b->capabilities.num_words + + b->extensions.num_words + b->imports.num_words + b->memory_model.num_words + b->entry_points.num_words + @@ -1131,6 +1142,7 @@ spirv_builder_get_words(struct spirv_builder *b, uint32_t *words, const struct spirv_buffer *buffers[] = { &b->capabilities, + &b->extensions, &b->imports, &b->memory_model, &b->entry_points, diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h index 7b870e94808..a1e9b6c655e 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h +++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h @@ -42,6 +42,7 @@ struct spirv_builder { void *mem_ctx; struct spirv_buffer capabilities; + struct spirv_buffer extensions; struct spirv_buffer imports; struct spirv_buffer memory_model; struct spirv_buffer entry_points; @@ -66,6 +67,9 @@ spirv_builder_new_id(struct spirv_builder *b) void spirv_builder_emit_cap(struct spirv_builder *b, SpvCapability cap); +void +spirv_builder_emit_extension(struct spirv_builder *b, const char *ext); + void spirv_builder_emit_source(struct spirv_builder *b, SpvSourceLanguage lang, uint32_t version); -- 2.30.2