From 883b5407c8d336509a05e4dbc46c91b4e1221651 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 11 Apr 2024 21:11:17 -0400 Subject: [PATCH] asahi: rework VBO lower for divisor=0 silly special case that we should handle. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_linker.h | 2 +- src/asahi/lib/agx_nir_lower_vbo.c | 8 ++++++-- src/asahi/lib/agx_nir_lower_vbo.h | 5 ++++- src/asahi/lib/agx_nir_prolog_epilog.c | 1 + src/gallium/drivers/asahi/agx_state.c | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/asahi/lib/agx_linker.h b/src/asahi/lib/agx_linker.h index c189bb1cd60..2a531937089 100644 --- a/src/asahi/lib/agx_linker.h +++ b/src/asahi/lib/agx_linker.h @@ -47,7 +47,7 @@ struct agx_velem_key { uint32_t divisor; uint16_t stride; uint8_t format; - uint8_t pad; + bool instanced; }; struct agx_vs_prolog_key { diff --git a/src/asahi/lib/agx_nir_lower_vbo.c b/src/asahi/lib/agx_nir_lower_vbo.c index 810eca814dc..827d38f36b8 100644 --- a/src/asahi/lib/agx_nir_lower_vbo.c +++ b/src/asahi/lib/agx_nir_lower_vbo.c @@ -157,8 +157,12 @@ pass(struct nir_builder *b, nir_intrinsic_instr *intr, void *data) * the divisor for per-instance data. Divisor=0 specifies per-vertex data. */ nir_def *el; - if (attrib.divisor) { - el = nir_udiv_imm(b, nir_load_instance_id(b), attrib.divisor); + if (attrib.instanced) { + if (attrib.divisor > 0) + el = nir_udiv_imm(b, nir_load_instance_id(b), attrib.divisor); + else + el = nir_imm_int(b, 0); + el = nir_iadd(b, el, nir_load_base_instance(b)); BITSET_SET(b->shader->info.system_values_read, diff --git a/src/asahi/lib/agx_nir_lower_vbo.h b/src/asahi/lib/agx_nir_lower_vbo.h index baadce2a533..b8036fa9dca 100644 --- a/src/asahi/lib/agx_nir_lower_vbo.h +++ b/src/asahi/lib/agx_nir_lower_vbo.h @@ -21,13 +21,16 @@ extern "C" { * be small so it can be embedded into a shader key. */ struct agx_attribute { + /* If instanced, Zero means all get the same value (Vulkan semantics). */ uint32_t divisor; uint32_t stride; uint16_t src_offset; - uint8_t buf; /* pipe_format, all vertex formats should be <= 255 */ uint8_t format; + + unsigned buf : 7; + bool instanced : 1; }; bool agx_nir_lower_vbo(nir_shader *shader, struct agx_attribute *attribs); diff --git a/src/asahi/lib/agx_nir_prolog_epilog.c b/src/asahi/lib/agx_nir_prolog_epilog.c index 813cd46a668..c54fc541855 100644 --- a/src/asahi/lib/agx_nir_prolog_epilog.c +++ b/src/asahi/lib/agx_nir_prolog_epilog.c @@ -65,6 +65,7 @@ lower_vbo(nir_shader *s, const struct agx_velem_key *key) .divisor = key[i].divisor, .stride = key[i].stride, .format = key[i].format, + .instanced = key[i].instanced, }; } diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 0e6458a431b..1783ed84f5f 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1447,6 +1447,7 @@ agx_create_vertex_elements(struct pipe_context *ctx, unsigned count, .stride = ve.src_stride, .format = ve.src_format, .divisor = ve.instance_divisor, + .instanced = ve.instance_divisor > 0, }; }