[Refactor] (MG_Impl/GLImpl): replace Flywheel dispatch sync hack with MOBILEGL_COHERENT_AS_FLUSH

This commit is contained in:
2026-07-15 21:51:20 -04:00
parent f80f6f4a62
commit 3e4ce5caa7
28 changed files with 295 additions and 62 deletions
@@ -246,26 +246,6 @@ namespace MobileGL::MG_Impl::GLImpl {
MG_Backend::gBackendFunctionsTable.GL.DrawArraysIndirect(mode, indirect);
}
// Flywheel-style engines write GPU-copy descriptors into a FLUSH_EXPLICIT
// persistent map and glBindBufferRange that span as an SSBO for a compute
// dispatch WITHOUT ever flushing it (undefined per spec, but real drivers'
// persistent maps alias GPU-visible memory, so it works there). MobileGL's
// persistent maps alias the CPU shadow, so those bytes would never reach the
// GPU: push every explicitly-ranged SSBO binding of such maps down right
// before each dispatch. Whole-buffer (BindBufferBase) bindings are excluded
// on purpose — ranges the app DID flush already arrived, and re-uploading a
// 16MB staging ring per dispatch would be prohibitive.
static void SyncUnflushedMappedSsboRangesForDispatch() {
const auto pointCount = MG_State::pGLContext->GetBufferBindingPointCount(BufferTarget::ShaderStorage);
for (SizeT i = 0; i < pointCount; ++i) {
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::ShaderStorage, i);
if (!point.HasExplicitRange()) continue;
const auto& bufferObject = point.GetBoundObject();
if (!bufferObject) continue;
bufferObject->SyncMappedRangeForGpuRead(point.GetRange());
}
}
/* @INSERTION_POINT:FUNCTION_IMPLEMENTATION@ */
void DispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ) {
auto dispatchCompute = MG_Backend::gBackendFunctionsTable.GL.DispatchCompute;
@@ -276,7 +256,6 @@ namespace MobileGL::MG_Impl::GLImpl {
return;
}
if (!ValidateCurrentProgramForCompute(__func__)) return;
SyncUnflushedMappedSsboRangesForDispatch();
dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
}
@@ -290,7 +269,6 @@ namespace MobileGL::MG_Impl::GLImpl {
return;
}
if (!ValidateCurrentProgramForCompute(__func__)) return;
SyncUnflushedMappedSsboRangesForDispatch();
dispatchComputeIndirect(indirect);
}