Mesa (main): spirv: Create PRIMITIVE_INDICES for NV_mesh_shader on-demand.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Feb 14 18:36:38 UTC 2022
Module: Mesa
Branch: main
Commit: e6cfd1ed6421c6abcf1893802ae55562fde45d20
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e6cfd1ed6421c6abcf1893802ae55562fde45d20
Author: Timur Kristóf <timur.kristof at gmail.com>
Date: Thu Feb 10 23:52:04 2022 +0100
spirv: Create PRIMITIVE_INDICES for NV_mesh_shader on-demand.
The shader can have SpvOpWritePackedPrimitiveIndices4x8NV while the
output variable may not exist. This seems to be a defect in the
NV_mesh_shader SPIR-V spec, let's work around it by creating the
variable on-demand.
Signed-off-by: Timur Kristóf <timur.kristof at gmail.com>
Reviewed-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15005>
---
src/compiler/spirv/spirv_to_nir.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 79e176a2218..f0461d8f612 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -5604,13 +5604,27 @@ vtn_handle_write_packed_primitive_indices(struct vtn_builder *b, SpvOp opcode,
}
}
- /* TODO(mesh): It may be the case that the variable is not present in the
+ /* It may be the case that the variable is not present in the
* entry point interface list.
*
* See https://github.com/KhronosGroup/SPIRV-Registry/issues/104.
*/
- vtn_fail_if(indices == NULL,
- "Missing output variable decorated with PrimitiveIndices builtin.");
+
+ if (!indices) {
+ unsigned vertices_per_prim =
+ num_mesh_vertices_per_primitive(b->shader->info.mesh.primitive_type);
+ unsigned max_prim_indices =
+ vertices_per_prim * b->shader->info.mesh.max_primitives_out;
+ const struct glsl_type *t =
+ glsl_array_type(glsl_uint_type(), max_prim_indices, 0);
+ nir_variable *var =
+ nir_variable_create(b->shader, nir_var_shader_out, t,
+ "gl_PrimitiveIndicesNV");
+
+ var->data.location = VARYING_SLOT_PRIMITIVE_INDICES;
+ var->data.interpolation = INTERP_MODE_NONE;
+ indices = nir_build_deref_var(&b->nb, var);
+ }
nir_ssa_def *offset = vtn_get_nir_ssa(b, w[1]);
nir_ssa_def *packed = vtn_get_nir_ssa(b, w[2]);
@@ -5619,7 +5633,7 @@ vtn_handle_write_packed_primitive_indices(struct vtn_builder *b, SpvOp opcode,
nir_deref_instr *offset_deref =
nir_build_deref_array(&b->nb, indices,
nir_iadd_imm(&b->nb, offset, i));
- nir_ssa_def *val = nir_u2u(&b->nb, nir_channel(&b->nb, unpacked, i), 32);
+ nir_ssa_def *val = nir_u2u32(&b->nb, nir_channel(&b->nb, unpacked, i));
nir_store_deref(&b->nb, offset_deref, val, 0x1);
}
More information about the mesa-commit
mailing list