diff --git a/HANDOFF_DILIGENT.md b/HANDOFF_DILIGENT.md index 36674a97..b7577685 100644 --- a/HANDOFF_DILIGENT.md +++ b/HANDOFF_DILIGENT.md @@ -158,6 +158,7 @@ Verified locally on Turnip Adreno 750: - `BlitFramebuffer` (same-size color copy between current read/draw FBOs) - `CopyTexImage2D` / `CopyTexSubImage2D` (whole-color copy fallback) - `CopyImageSubData` (whole-texture copy between two texture objects) + - `GenerateMipmap` (Diligent GPU mip generation on state textures) - `GetTexImage` / `GetTextureImage` (RGBA8 readback) - `ReadPixels` from default and user color attachments - Primitive expansion: @@ -218,7 +219,7 @@ Notes: - 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. -- Draw range, multi-draw, instanced-draw wrappers, clear-buffer, blit, read-pixels, CopyTexImage*, GetTexImage/GetTextureImage and indirect draws are now wired; buffer subdata paths still remain. +- 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 4bcdb093..4e107cf7 100644 --- a/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp +++ b/MobileGL/MG_Backend/Diligent/BackendObject_Diligent.cpp @@ -539,6 +539,18 @@ namespace MobileGL::MG_Backend::DiligentBackend { } } + void GenerateMipmap(GLenum target) { + auto* renderer = GetActiveRenderer(); + if (renderer == nullptr || MG_State::pGLContext == nullptr || target != GL_TEXTURE_2D) { + return; + } + auto& unit = MG_State::pGLContext->GetTextureUnitObject(MG_State::pGLContext->GetActiveTextureUnit()); + auto texture = unit.GetBindingSlot(TextureTarget::Texture2D).GetBoundObject(); + if (texture) { + renderer->GenerateMipmap(*texture); + } + } + void Present() { auto* renderer = GetActiveRenderer(); if (renderer != nullptr) { @@ -653,6 +665,7 @@ namespace MobileGL::MG_Backend::DiligentBackend { m_functions.GL.CopyTexImage2D = CopyTexImage2D; m_functions.GL.CopyTexSubImage2D = CopyTexSubImage2D; m_functions.GL.CopyImageSubData = CopyImageSubData; + m_functions.GL.GenerateMipmap = GenerateMipmap; 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 bc9b34bc..511b2380 100644 --- a/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.cpp +++ b/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.cpp @@ -714,6 +714,7 @@ void main() } else { texDesc.BindFlags |= ::Diligent::BIND_RENDER_TARGET; } + texDesc.MiscFlags = ::Diligent::MISC_TEXTURE_FLAG_GENERATE_MIPS; ::Diligent::RefCntAutoPtr<::Diligent::ITexture> pTexture; m_pDevice->CreateTexture(texDesc, nullptr, &pTexture); @@ -1839,6 +1840,17 @@ void main() m_pContext->CopyTexture(copyAttribs); } + void DiligentRenderer::GenerateMipmap(MG_State::GLState::ITextureObject& texture) { + if (m_pContext == nullptr || SyncTexture(texture) == nullptr) { + return; + } + auto it = m_textureCache.find(texture.GetLifetimeId()); + if (it == m_textureCache.end() || !it->second.SRV) { + return; + } + m_pContext->GenerateMips(it->second.SRV); + } + 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 fdf1075e..8ea301d6 100644 --- a/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h +++ b/MobileGL/MG_Backend/Diligent/Renderer/DiligentRenderer.h @@ -67,6 +67,7 @@ namespace MobileGL::MG_Backend::DiligentBackend { GLbitfield mask, GLenum filter); void CopyReadFramebufferToTexture(MG_State::GLState::ITextureObject& dst); void CopyTextureSubData(MG_State::GLState::ITextureObject& src, MG_State::GLState::ITextureObject& dst); + void GenerateMipmap(MG_State::GLState::ITextureObject& texture); Bool ReadTextureImage(MG_State::GLState::ITextureObject& texture, Uint32 level, void* pixels); void Present();