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@gmail.com>
Reviewed-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15005>
This commit is contained in:
Timur Kristóf
2022-02-10 23:52:04 +01:00
parent 0445802ab2
commit e6cfd1ed64
+18 -4
View File
@@ -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);
}