From e6cfd1ed6421c6abcf1893802ae55562fde45d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Thu, 10 Feb 2022 23:52:04 +0100 Subject: [PATCH] spirv: Create PRIMITIVE_INDICES for NV_mesh_shader on-demand. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Marcin Ślusarz Part-of: --- 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); }