From e0033ce871eb86a1f73133cff5383f2cef45170f Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 1 Feb 2021 13:53:52 +0100 Subject: [PATCH] gpu/gl: explicitly clear buffers before replacing their content The iOS GL implementation doesn't optimize BufferSubData of the entire buffer, leading to GPU stalls. The workaround is to explicitly clear the buffer before replacing it. Signed-off-by: Elias Naur --- gpu/gl/backend.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gpu/gl/backend.go b/gpu/gl/backend.go index 28dd2a80..04d915ab 100644 --- a/gpu/gl/backend.go +++ b/gpu/gl/backend.go @@ -676,6 +676,12 @@ func (b *gpuBuffer) Upload(data []byte) { if b.hasBuffer { firstBinding := firstBufferType(b.typ) b.backend.funcs.BindBuffer(firstBinding, b.obj) + if len(data) == b.size { + // the iOS GL implementation doesn't recognize when BufferSubData + // clears the entire buffer. Tell it and avoid GPU stalls. + // See also https://github.com/godotengine/godot/issues/23956. + b.backend.funcs.BufferData(firstBinding, b.size, glimpl.DYNAMIC_DRAW) + } b.backend.funcs.BufferSubData(firstBinding, 0, data) } }