spirv: Propagate explicit layout only in types that need it
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5511>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user