From 848f11065873846ace97d7c7db1f1076f99d18a2 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sun, 8 Jun 2025 01:57:13 +0800 Subject: [PATCH] [Fix] (DiligentEngine): Fix some miscellaneous issues. --- .../Implementations/EGL/Diligent/EGL_impl.cpp | 46 ++++++++++++++----- .../Implementations/GL/Drawing/GL_Drawing.cpp | 9 +++- .../Implementations/GL/Program/GL_Program.cpp | 2 + 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp index b7fb9e86..9d5b78b0 100644 --- a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp +++ b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp @@ -64,6 +64,7 @@ namespace MG_Diligent { PSOCreateInfo.GraphicsPipeline.PrimitiveTopology = Diligent::PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + /* PSOCreateInfo.GraphicsPipeline.NumRenderTargets = fbInfo.ColorRTVs.size(); for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) { if (fbInfo.ColorRTVs[i]) { @@ -73,12 +74,9 @@ namespace MG_Diligent { PSOCreateInfo.GraphicsPipeline.RTVFormats[i] = Diligent::TEX_FORMAT_RGBA8_UNORM; } } + */ - if (fbInfo.DepthStencilFormat != Diligent::TEX_FORMAT_UNKNOWN) { - PSOCreateInfo.GraphicsPipeline.DSVFormat = fbInfo.DepthStencilFormat; - } else { - PSOCreateInfo.GraphicsPipeline.DSVFormat = Diligent::TEX_FORMAT_D32_FLOAT; - } + PSOCreateInfo.GraphicsPipeline.DSVFormat = Diligent::TEX_FORMAT_UNKNOWN; Diligent::BlendStateDesc &blendDesc = PSOCreateInfo.GraphicsPipeline.BlendDesc; blendDesc.IndependentBlendEnable = false; @@ -672,11 +670,28 @@ namespace MG_EGL::Diligent { EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) { MG_Util::Debug::LogD("Flushing context"); + if (MG_Diligent::IsInRenderPass) { + MG_Util::Debug::LogD("Ending current render pass."); + MG_Diligent::g_pContext->EndRenderPass(); + MG_Diligent::IsInRenderPass = false; + MG_Util::Debug::LogD("Current render pass ended."); + } else { + MG_Util::Debug::LogD("No active render pass to end."); + } MG_Diligent::g_pContext->Flush(); MG_Util::Debug::LogD("Presenting swap chain"); MG_Diligent::g_pSwapChain->Present(); MG_GL::GL::UpdateDefaultFramebuffer(); + if (MG_Diligent::IsInRenderPass) { + MG_Util::Debug::LogD("Ending current render pass."); + MG_Diligent::g_pContext->EndRenderPass(); + MG_Diligent::IsInRenderPass = false; + MG_Util::Debug::LogD("Current render pass ended."); + } else { + MG_Util::Debug::LogD("No active render pass to end."); + } + MG_Diligent::g_pContext->Flush(); MG_Util::Debug::LogD("Finishing frame"); MG_Diligent::g_pContext->FinishFrame(); @@ -691,14 +706,23 @@ namespace MG_EGL::Diligent { ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); + static ::Diligent::OptimizedClearValue DefaultClearValues[2]; + DefaultClearValues[0].Format = fbInfo.ColorRTVs[0]->GetDesc().Format; + DefaultClearValues[0].Color[0] = 0.0f; + DefaultClearValues[0].Color[1] = 0.0f; + DefaultClearValues[0].Color[2] = 0.0f; + DefaultClearValues[0].Color[3] = 1.0f; + DefaultClearValues[1].Format = fbInfo.DepthStencilFormat; + DefaultClearValues[1].DepthStencil.Depth = 1.0f; + DefaultClearValues[1].DepthStencil.Stencil = 0; + MG_Util::Debug::LogD("Beginning render pass: pass=%p, fb=%p", fbInfo.pRenderPass, fbInfo.pFramebuffer); MG_Diligent::g_pContext->BeginRenderPass( - ::Diligent::BeginRenderPassAttribs{ - fbInfo.pRenderPass, - fbInfo.pFramebuffer, - ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION - } - ); + ::Diligent::BeginRenderPassAttribs{ fbInfo.pRenderPass, fbInfo.pFramebuffer, + 2, DefaultClearValues, + ::Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION} + ); + MG_Diligent::IsInRenderPass = true; } const auto& SCDesc = MG_Diligent::g_pSwapChain->GetDesc(); MG_Util::Debug::LogD("Setting viewport: width=%d, height=%d", SCDesc.Width, SCDesc.Height); diff --git a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp index a717a3b8..efc9f94b 100644 --- a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp +++ b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp @@ -380,6 +380,14 @@ namespace MG_GL::GL { } void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) { + if (MG_Diligent::IsInRenderPass) { + MG_Util::Debug::LogD("Ending current render pass."); + MG_Diligent::g_pContext->EndRenderPass(); + MG_Diligent::IsInRenderPass = false; + MG_Util::Debug::LogD("Current render pass ended."); + } else { + MG_Util::Debug::LogD("No active render pass to end."); + } GLuint program = MG_State::GetCurrentProgram(); MG_Util::Debug::LogD("DrawElements called with mode: %d, count: %d, type: %d, program: %u", mode, count, type, program); if (program == 0) { @@ -499,7 +507,6 @@ namespace MG_GL::GL { EnsureRenderPassActive(); MG_Diligent::g_pContext->DrawIndexed(drawAttrs); - MG_Diligent::g_pContext->EndRenderPass(); MG_Diligent::IsInRenderPass = false; MG_Util::Debug::LogD("DrawIndexed completed."); diff --git a/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp b/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp index b6c0a424..d8dcd048 100644 --- a/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp +++ b/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp @@ -260,6 +260,8 @@ namespace MG_GL::GL { if (MG_Diligent::g_ShaderMap.find(shaderId) == MG_Diligent::g_ShaderMap.end() || MG_Diligent::g_ShaderMap[shaderId] == nullptr) { GLenum shaderType = shaderObj.type; std::string sourceStr = shaderSources[shaderId]; + MG_Util::Debug::LogD("Shader ID: %u, type: %s\nConverted source:\n%s", + shaderId, MG_Util::Debug::GLEnumToString(shaderType), sourceStr.c_str()); Diligent::ShaderCreateInfo ShaderCI; ShaderCI.Source = sourceStr.c_str();