From 264a0cabd1dd2a619f24e34f21f767c6bf36fe76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20=C5=9Alusarz?= Date: Mon, 12 Dec 2022 14:29:52 +0100 Subject: [PATCH] anv: assert when number of primitives is higher than max Such cases can lead to memory corruptions. Acked-by: Caio Oliveira Part-of: --- src/intel/vulkan/anv_pipeline.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index c8b5dc8..1c4d4b9 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -84,6 +84,14 @@ anv_nir_lower_set_vtx_and_prim_count_instr(nir_builder *b, nir_instr *instr, voi if (intrin->intrinsic != nir_intrinsic_set_vertex_and_primitive_count) return false; + /* Detect some cases of invalid primitive count. They might lead to URB + * memory corruption, where workgroups overwrite each other output memory. + */ + if (nir_src_is_const(intrin->src[1]) && + nir_src_as_uint(intrin->src[1]) > b->shader->info.mesh.max_primitives_out) { + assert(!"number of primitives bigger than max specified"); + } + struct lower_set_vtx_and_prim_count_state *state = data; /* this intrinsic should show up only once */ assert(state->primitive_count == NULL); -- 2.7.4