From 9bc0ae6b971fff5731607d199dbaaae26e33871f Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Wed, 12 Nov 2025 16:00:44 +0800 Subject: [PATCH] [Chore]: (MG_State/Program): use proper enum constant, get rid of junk --- MobileGL/MG_Backend/DirectGLES/Managers.cpp | 18 ++++++++++++++---- .../GLState/ProgramState/ProgramObject.cpp | 14 ++++++++------ .../GLState/ProgramState/ProgramObject.h | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index de8f4725..0293a1ea 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -486,6 +486,11 @@ namespace MobileGL::MG_Backend::DirectGLES { // Attach current shaders auto& attachedShaders = stateProgramObject->GetAttachedShaders(); MGLOG_D("Attaching %zu shaders to program %u", attachedShaders.size(), m_backendProgramId); + for (auto& shader: attachedShaders) { + const auto& src = shader->GetShaderSource(); + const auto& stage = MG_Util::ConvertGLEnumToString(MG_Util::ConvertShaderStageToGLEnum(shader->GetShaderStage())); + MGLOG_D("Original src @ %s: \n%s", stage.c_str(), src.c_str()); + } auto& shaderSpirvs = stateProgramObject->GetGeneratedSpirv(); for (int index = 0; index < attachedShaders.size(); ++index) { @@ -501,9 +506,14 @@ namespace MobileGL::MG_Backend::DirectGLES { auto& spirvCode = shaderSpirvs[index]; MG_Util::ShaderTranspiler::SpvcSession spvcSession(spirvCode); - if (glShaderType == GL_VERTEX_SHADER) { - spvcSession.SetVertexAttribLocation(stateProgramObject->GetAttribLocationMap()); - } +// if (glShaderType == GL_VERTEX_SHADER) { +// if (stateProgramObject->GetAttribLocationMap().empty()) +// MGLOG_D("%s: no explicitly set vertex in location", __func__); +// for (auto& [name, loc]: stateProgramObject->GetAttribLocationMap()) { +// MGLOG_D("%s: got explicitly set - layout(location = %d) %s;", __func__, loc, name.c_str()); +// } +//// spvcSession.SetVertexAttribLocation(stateProgramObject->GetAttribLocationMap()); +// } spvc_compiler_options options; spvcSession.CreateOptions(&options); @@ -533,7 +543,7 @@ namespace MobileGL::MG_Backend::DirectGLES { source = ForceSupporterOutput(source); const char* sourceCStr = source.c_str(); - MGLOG_D("Setting shader source for backend shader ID: %u", backendShaderId); + MGLOG_D("Setting shader source for backend shader ID: %u\nsrc:\n%s", backendShaderId, sourceCStr); MG_External::GLES::glShaderSource(backendShaderId, 1, &sourceCStr, nullptr); MG_External::GLES::glCompileShader(backendShaderId); diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp index 098d4343..bb003ad7 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp @@ -149,7 +149,7 @@ namespace MobileGL { for (int i = 0; i < m_activeUniformCount; i++) { auto& uniform = m_program->getUniform(i); auto location = uniform.layoutLocation(); - if (location != 4095) { + if (location != glslang::TQualifier::layoutLocationEnd) { m_maxUniformLocation = std::max(m_maxUniformLocation, location); } m_uniformNameMaxLength = std::max(m_uniformNameMaxLength, (Int)uniform.name.length()); @@ -171,7 +171,7 @@ namespace MobileGL { } // i-th elements refers to uniform at layout(location = i, ...) - m_uniformIndexInTProgram.resize(m_maxUniformLocation + 1, 4095); + m_uniformIndexInTProgram.resize(m_maxUniformLocation + 1, glslang::TQualifier::layoutLocationEnd); m_uniformSamplerOrImageUnitIndex.resize(m_maxUniformLocation + 1, -1); Vector unallocatedUniformIndex; @@ -180,7 +180,7 @@ namespace MobileGL { for (int i = 0; i < m_activeUniformCount; i++) { auto& uniform = m_program->getUniform(i); auto location = uniform.layoutLocation(); - if (m_uniformLocations[uniform.name] == 4095) { + if (m_uniformLocations[uniform.name] == glslang::TQualifier::layoutLocationEnd) { unallocatedUniformIndex.emplace_back(i); MGLOG_D("ProgramObject %u: Reflection - uniform '%s' is unallocated, will assign later", m_externalIndex, uniform.name.c_str()); @@ -195,7 +195,7 @@ namespace MobileGL { for (auto index : unallocatedUniformIndex) { auto& uniform = m_program->getUniform(index); for (; locNeedle <= m_maxUniformLocation; locNeedle++) { - if (m_uniformIndexInTProgram[locNeedle] != 4095) continue; + if (m_uniformIndexInTProgram[locNeedle] != glslang::TQualifier::layoutLocationEnd) continue; // Found a vacant location at locNeedle m_uniformIndexInTProgram[locNeedle] = index; m_uniformLocations[uniform.name] = locNeedle; @@ -207,13 +207,15 @@ namespace MobileGL { } } + // ------------ attributes (vertex in) --------------- int inCount = m_program->getNumPipeInputs(); MGLOG_D("ProgramObject %u: Reflection - pipe input count (attributes) = %d", m_externalIndex, inCount); int maxLoc = -1; for (int i = 0; i < inCount; ++i) { int loc = m_program->getPipeInput(i).layoutLocation(); - if (loc >= 0) maxLoc = std::max(maxLoc, loc); + if (loc >= 0 && loc != glslang::TQualifier::layoutLocationEnd) + maxLoc = std::max(maxLoc, loc); MGLOG_D("ProgramObject %u: Reflection - pipe input[%d] name='%s' layoutLocation=%d glType=%u", m_externalIndex, i, m_program->getPipeInput(i).name.c_str(), loc, m_program->getPipeInput(i).glDefineType); @@ -245,7 +247,7 @@ namespace MobileGL { if (location >= 0 && location < (int)m_attribs.size()) { m_attribs[location] = inVar.name; m_attribTypes[location] = inVar.glDefineType; - MGLOG_D("ProgramObject %u: Reflection - placed attrib '%s' at explicit location %d", + MGLOG_D("ProgramObject %u: Reflection - got attrib '%s' at explicit location %d", m_externalIndex, inVar.name.c_str(), location); } // else if (location >= (int)m_attribs.size()) { diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h index ccbba86b..446d3db4 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h @@ -104,7 +104,7 @@ namespace MobileGL { Uint GetExternalIndex() const { return m_externalIndex; } - const UnorderedMap& GetAttribLocationMap() const { return m_attribLocation; } +// const UnorderedMap& GetAttribLocationMap() const { return m_attribLocation; } private: void DoReflection(); @@ -124,7 +124,7 @@ namespace MobileGL { Vector m_attribs; Vector m_attribTypes; // For SpvcSession::SetVertexAttribLocation() - UnorderedMap m_attribLocation; +// UnorderedMap m_attribLocation; // Uniforms UnorderedMap m_uniformLocations;