Mesa (master): spirv: Propagate explicit layout only in types that need it
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Aug 4 15:35:27 UTC 2020
Module: Mesa
Branch: master
Commit: b98dd704894713b5f0b8fa2c1b52c0b970e9f89b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b98dd704894713b5f0b8fa2c1b52c0b970e9f89b
Author: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Date: Wed Jul 29 12:42:08 2020 -0700
spirv: Propagate explicit layout only in types that need it
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5511>
---
src/compiler/spirv/spirv_to_nir.c | 34 ++++++++++++++++++++++++++++++++++
src/compiler/spirv/vtn_variables.c | 9 ---------
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 4c621534996..a0dc9c264b3 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -775,6 +775,33 @@ wrap_type_in_array(const struct glsl_type *type,
glsl_get_explicit_stride(array_type));
}
+static bool
+vtn_type_needs_explicit_layout(struct vtn_builder *b, enum vtn_variable_mode mode)
+{
+ /* For OpenCL we never want to strip the info from the types, and it makes
+ * type comparisons easier in later stages.
+ */
+ if (b->options->environment == NIR_SPIRV_OPENCL)
+ return true;
+
+ switch (mode) {
+ case vtn_variable_mode_input:
+ case vtn_variable_mode_output:
+ /* Layout decorations kept because we need offsets for XFB arrays of
+ * blocks.
+ */
+ return b->shader->info.has_transform_feedback_varyings;
+
+ case vtn_variable_mode_ssbo:
+ case vtn_variable_mode_phys_ssbo:
+ case vtn_variable_mode_ubo:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
const struct glsl_type *
vtn_type_get_nir_type(struct vtn_builder *b, struct vtn_type *type,
enum vtn_variable_mode mode)
@@ -839,6 +866,13 @@ vtn_type_get_nir_type(struct vtn_builder *b, struct vtn_type *type,
}
}
+ /* Layout decorations are allowed but ignored in certain conditions,
+ * to allow SPIR-V generators perform type deduplication. Discard
+ * unnecessary ones when passing to NIR.
+ */
+ if (!vtn_type_needs_explicit_layout(b, mode))
+ return glsl_get_bare_type(type->type);
+
return type->type;
}
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 2100b481cce..5f09857a9c8 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -2197,10 +2197,6 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
/* Create the variable normally */
var->var = rzalloc(b->shader, nir_variable);
var->var->name = ralloc_strdup(var->var, val->name);
- /* Workgroup variables don't have any explicit layout but some
- * layouts may have leaked through due to type deduplication in the
- * SPIR-V.
- */
var->var->type = vtn_type_get_nir_type(b, var->type, var->mode);
var->var->data.mode = nir_var_mem_shared;
break;
@@ -2253,11 +2249,6 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
var->var = rzalloc(b->shader, nir_variable);
var->var->name = ralloc_strdup(var->var, val->name);
- /* In Vulkan, shader I/O variables don't have any explicit layout but
- * some layouts may have leaked through due to type deduplication in
- * the SPIR-V. We do, however, keep the layouts in the variable's
- * interface_type because we need offsets for XFB arrays of blocks.
- */
var->var->type = vtn_type_get_nir_type(b, var->type, var->mode);
var->var->data.mode = nir_mode;
var->var->data.patch = var->patch;
More information about the mesa-commit
mailing list