From 071c8eb673d6dd40d5f81a499fa06aaa2891d567 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sun, 23 Aug 2026 10:12:58 +0800 Subject: [PATCH] [Feat] (Diligent): wire fence sync CPU fallback - Provide always-signaled FenceSync/ClientWaitSync/WaitSync/DeleteSync/GetSyncStatus - Update handoff; 16 Diligent tests pass --- HANDOFF_DILIGENT.md | 3 +- .../Diligent/BackendObject_Diligent.cpp | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/HANDOFF_DILIGENT.md b/HANDOFF_DILIGENT.md index 2170ee4e..46df8ff2 100644 --- a/HANDOFF_DILIGENT.md +++ b/HANDOFF_DILIGENT.md @@ -160,6 +160,7 @@ Verified locally on Turnip Adreno 750: - `CopyImageSubData` (whole-texture copy between two texture objects) - `GenerateMipmap` (Diligent GPU mip generation on state textures) - `GetTexImage` / `GetTextureImage` (RGBA8 readback) + - Fence sync entries (`FenceSync` / `ClientWaitSync` / `WaitSync` / `DeleteSync` / `GetSyncStatus`) as CPU always-signaled fallback - `ReadPixels` from default and user color attachments - Primitive expansion: - `GL_TRIANGLE_FAN` expanded to triangle list @@ -218,7 +219,7 @@ Notes: - Textures auto-sync `ITextureObject` → Diligent resources, including mip levels and sampler state; compressed textures and integer/3-channel formats that Diligent lacks are still skipped. - Global UBO (default-block `glUniform*`) and named application UBO blocks (through `glBindBufferBase`/`glUniformBlockBinding`) now upload and bind; SSBOs are still not fed from frontend buffer bindings. - No swapchain / EGL window surface presentation yet; `Present()` only flushes. -- No transform feedback / queries / sync / readback of non-color resources. +- No transform feedback / GPU queries / non-color readback; fence sync is provided as a CPU always-signaled fallback. - Draw range, multi-draw, instanced-draw wrappers, clear-buffer, blit, read-pixels, CopyTexImage*, CopyImageSubData, GenerateMipmap, GetTexImage/GetTextureImage and indirect draws are now wired; buffer subdata paths still remain. - A last-PSO cache now avoids recreating the pipeline when program/render-state/topology/VAO layout is unchanged; texture/UBO resources are still rebound dynamically per draw. - The `GLFunctionsTable` is only partially populated. diff --git a/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp b/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp index c2316d33..3536a38e 100644 --- a/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp +++ b/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp @@ -571,6 +571,35 @@ namespace MobileGL::MG_Backend::DiligentBackend { } } + BackendSyncHandle FenceSync() { + // CPU fallback fence: always signaled is a valid implementation for a + // backend without native sync primitives. The handle still round-trips + // through ClientWaitSync/DeleteSync so frontend state stays balanced. + return new int(0); + } + + GLenum ClientWaitSync(BackendSyncHandle sync, GLbitfield flags, GLuint64 timeout) { + (void)sync; + (void)flags; + (void)timeout; + return GL_ALREADY_SIGNALED; + } + + void WaitSync(BackendSyncHandle sync, GLbitfield flags, GLuint64 timeout) { + (void)sync; + (void)flags; + (void)timeout; + } + + void DeleteSync(BackendSyncHandle sync) { + delete static_cast(sync); + } + + Bool GetSyncStatus(BackendSyncHandle sync) { + (void)sync; + return true; + } + void Present() { auto* renderer = GetActiveRenderer(); if (renderer != nullptr) { @@ -690,6 +719,11 @@ namespace MobileGL::MG_Backend::DiligentBackend { m_functions.GL.GetTexImage = GetTexImage; m_functions.GL.GetTextureImage = GetTextureImage; m_functions.GL.ReadPixels = ReadPixels; + m_functions.GL.FenceSync = FenceSync; + m_functions.GL.ClientWaitSync = ClientWaitSync; + m_functions.GL.WaitSync = WaitSync; + m_functions.GL.DeleteSync = DeleteSync; + m_functions.GL.GetSyncStatus = GetSyncStatus; m_functions.Present = Present; m_initialized = true;