From ef23ce58961ad08df13003ea122e0218fd34cd46 Mon Sep 17 00:00:00 2001 From: Michael Parkin-White Date: Wed, 22 Feb 2023 13:38:04 +0000 Subject: [PATCH] Fix #104016: Resolve Metal LineLoop emulation. Metal LineLoop emulation path does not correctly apply when using SSBO vertex fetch mode alongside 3D line rendering. Patch moves line emulation above SSBO vertex fetch setup to ensure the correct emulation parameters are passed to the shader. Authored by Apple: Michael Parkin-White Ref #96261 --- source/blender/gpu/metal/mtl_immediate.mm | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/source/blender/gpu/metal/mtl_immediate.mm b/source/blender/gpu/metal/mtl_immediate.mm index 985b962cc99..4656d935ce7 100644 --- a/source/blender/gpu/metal/mtl_immediate.mm +++ b/source/blender/gpu/metal/mtl_immediate.mm @@ -239,6 +239,17 @@ void MTLImmediate::end() desc.vertex_descriptor.buffer_layouts[0].stride = this->vertex_format.stride; BLI_assert(this->vertex_format.stride > 0); + /* Emulate LineLoop using LineStrip. */ + if (this->prim_type == GPU_PRIM_LINE_LOOP) { + /* Patch final vertex of line loop to close. Rendered using LineStrip. + * Note: vertex_len represents original length, however, allocated Metal + * buffer contains space for one extra vertex when LineLoop is used. */ + uchar *buffer_data = reinterpret_cast(current_allocation_.data); + memcpy(buffer_data + (vertex_len)*vertex_format.stride, buffer_data, vertex_format.stride); + this->vertex_idx++; + this->prim_type = GPU_PRIM_LINE_STRIP; + } + /* SSBO Vertex Fetch -- Verify Attributes. */ if (active_mtl_shader->get_uses_ssbo_vertex_fetch()) { active_mtl_shader->ssbo_vertex_fetch_bind_attributes_end(rec); @@ -337,16 +348,6 @@ void MTLImmediate::end() } rendered = true; } break; - case GPU_PRIM_LINE_LOOP: { - /* Patch final vertex of line loop to close. Rendered using LineStrip. - * Note: vertex_len represents original length, however, allocated Metal - * buffer contains space for one extra vertex when LineLoop is used. */ - uchar *buffer_data = reinterpret_cast(current_allocation_.data); - memcpy(buffer_data + (vertex_len)*vertex_format.stride, - buffer_data, - vertex_format.stride); - this->vertex_idx++; - } break; default: { BLI_assert_unreachable(); } break; -- 2.30.2