From e9a09fff3e981ec373beec3bea2bdae221d4310c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Ma=CC=88rki?= Date: Mon, 4 Nov 2024 20:29:50 +0100 Subject: [PATCH] use global buffer index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Märki --- ios/graphics/Model/MultiBuffer.swift | 22 +++---- ios/graphics/RenderingContext.swift | 91 +++++++++++++++++----------- 2 files changed, 62 insertions(+), 51 deletions(-) diff --git a/ios/graphics/Model/MultiBuffer.swift b/ios/graphics/Model/MultiBuffer.swift index 007599241..e05239ce5 100644 --- a/ios/graphics/Model/MultiBuffer.swift +++ b/ios/graphics/Model/MultiBuffer.swift @@ -8,14 +8,10 @@ import Metal import simd -private let bufferCount = 3 // Triple buffering - public struct MultiBuffer { // Warning: Seems like suited to be generic // But makeBuffer &reference does not like generic data var buffers: [MTLBuffer] - var currentBufferIndex = 0 - var currentFrameId = -1 fileprivate init(buffers: [MTLBuffer]) { self.buffers = buffers @@ -24,21 +20,15 @@ public struct MultiBuffer { public mutating func getNextBuffer(_ context: RenderingContext) -> MTLBuffer? { - if context.frameId != currentFrameId { - currentBufferIndex = (currentBufferIndex + 1) % bufferCount - currentFrameId = context.frameId - } - guard currentBufferIndex < buffers.count else { - return nil - } - return buffers[currentBufferIndex] + return buffers[context.currentBufferIndex] } } extension MultiBuffer { public init(device: MTLDevice) { var initialMutable = simd_float1(1.0) - let buffers: [MTLBuffer] = (0.. { extension MultiBuffer { public init(device: MTLDevice) { var initialMutable = simd_float4(0.0, 0.0, 0.0, 0.0) - let buffers: [MTLBuffer] = (0.. { extension MultiBuffer { public init(device: MTLDevice) { var initialMutable = simd_float4x4(1.0) - let buffers: [MTLBuffer] = (0..