diff --git a/HANDOFF_DILIGENT.md b/HANDOFF_DILIGENT.md index e053042f..36674a97 100644 --- a/HANDOFF_DILIGENT.md +++ b/HANDOFF_DILIGENT.md @@ -157,6 +157,7 @@ Verified locally on Turnip Adreno 750: - `ClearBufferfv` / `ClearBufferfi` / `ClearBufferiv` / `ClearBufferuiv` (incl. stencil clear) - `BlitFramebuffer` (same-size color copy between current read/draw FBOs) - `CopyTexImage2D` / `CopyTexSubImage2D` (whole-color copy fallback) + - `CopyImageSubData` (whole-texture copy between two texture objects) - `GetTexImage` / `GetTextureImage` (RGBA8 readback) - `ReadPixels` from default and user color attachments - Primitive expansion: @@ -250,7 +251,7 @@ Notes: - [x] `MultiDraw*` - [x] `BlitFramebuffer` (same-size color copy) - [x] `ReadPixels` from non-default framebuffer - - [x] `CopyTexImage*` wired as whole-color copy + - [x] `CopyTexImage*` / `CopyImageSubData` wired as whole-resource copies - [x] `GetTexImage` / `GetTextureImage` (RGBA8) - [x] Indirect draws (CPU fallback) diff --git a/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp b/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp index 931d5d45..4bcdb093 100644 --- a/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp +++ b/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp @@ -515,6 +515,30 @@ namespace MobileGL::MG_Backend::DiligentBackend { renderer->ReadTextureImage(*texture, static_cast(level), pixels); } + void CopyImageSubData(const SharedPtr& srcTexture, + GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, + const SharedPtr& dstTexture, + GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, + GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth) { + (void)srcTarget; + (void)srcLevel; + (void)srcX; + (void)srcY; + (void)srcZ; + (void)dstTarget; + (void)dstLevel; + (void)dstX; + (void)dstY; + (void)dstZ; + (void)srcWidth; + (void)srcHeight; + (void)srcDepth; + auto* renderer = GetActiveRenderer(); + if (renderer != nullptr && srcTexture && dstTexture) { + renderer->CopyTextureSubData(*srcTexture, *dstTexture); + } + } + void Present() { auto* renderer = GetActiveRenderer(); if (renderer != nullptr) { @@ -628,6 +652,7 @@ namespace MobileGL::MG_Backend::DiligentBackend { m_functions.GL.BlitFramebuffer = BlitFramebuffer; m_functions.GL.CopyTexImage2D = CopyTexImage2D; m_functions.GL.CopyTexSubImage2D = CopyTexSubImage2D; + m_functions.GL.CopyImageSubData = CopyImageSubData; m_functions.GL.GetTexImage = GetTexImage; m_functions.GL.GetTextureImage = GetTextureImage; m_functions.GL.ReadPixels = ReadPixels; diff --git a/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.cpp b/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.cpp index 61d7a0ce..bc9b34bc 100644 --- a/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.cpp +++ b/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.cpp @@ -1816,6 +1816,29 @@ void main() m_pContext->CopyTexture(copyAttribs); } + void DiligentRenderer::CopyTextureSubData(MG_State::GLState::ITextureObject& src, + MG_State::GLState::ITextureObject& dst) { + if (!m_initialized || !m_pContext) { + return; + } + if (SyncTexture(src) == nullptr || SyncTexture(dst) == nullptr) { + return; + } + auto srcIt = m_textureCache.find(src.GetLifetimeId()); + auto dstIt = m_textureCache.find(dst.GetLifetimeId()); + if (srcIt == m_textureCache.end() || dstIt == m_textureCache.end() || + !srcIt->second.Texture || !dstIt->second.Texture) { + return; + } + if (srcIt->second.Texture == dstIt->second.Texture) { + return; + } + ::Diligent::CopyTextureAttribs copyAttribs( + srcIt->second.Texture, ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION, + dstIt->second.Texture, ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + m_pContext->CopyTexture(copyAttribs); + } + Bool DiligentRenderer::ReadTextureImage(MG_State::GLState::ITextureObject& texture, Uint32 level, void* pixels) { if (!m_initialized || !m_pContext || pixels == nullptr) { diff --git a/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h b/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h index 92268af7..fdf1075e 100644 --- a/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h +++ b/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h @@ -66,6 +66,7 @@ namespace MobileGL::MG_Backend::DiligentBackend { GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); void CopyReadFramebufferToTexture(MG_State::GLState::ITextureObject& dst); + void CopyTextureSubData(MG_State::GLState::ITextureObject& src, MG_State::GLState::ITextureObject& dst); Bool ReadTextureImage(MG_State::GLState::ITextureObject& texture, Uint32 level, void* pixels); void Present();