From 8e5cc46577f7e7a8e3aa41df4dadd4bad7026d63 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 27 Oct 2025 12:59:55 +0800 Subject: [PATCH] [Chore] (MG_State/ProgramObject): directly use TProgram for reflection --- .../GLState/ProgramState/ProgramObject.cpp | 23 +++++---------- .../GLState/ProgramState/ProgramObject.h | 28 +++++++++++-------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp index 67a8a98d..3b7b0f58 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp @@ -91,11 +91,7 @@ namespace MobileGL { // i-th elements refers to uniform at layout(location = i, ...) // Be aware, there could be gaps in between these vectors // Locations can be not sequential - m_uniformNames.resize(m_maxUniformLocation + 1); - m_uniformTypes.resize(m_maxUniformLocation + 1, GL_ZERO); - m_uniformIsOpaqueType.resize(m_maxUniformLocation + 1); - m_uniformOffsets.resize(m_maxUniformLocation + 1); - m_uniformArraySizes.resize(m_maxUniformLocation + 1); + m_uniformIndexInTProgram.resize(m_maxUniformLocation + 1, 4095); Vector unallocatedUniformIndex; @@ -103,26 +99,21 @@ namespace MobileGL { for (int i = 0; i < m_activeUniformCount; i++) { auto& uniform = m_program->getUniform(i); auto location = uniform.layoutLocation(); - if (location >= m_uniformNames.size()) { + if (m_uniformLocations[uniform.name] == 4095) { unallocatedUniformIndex.emplace_back(i); continue; // will allocate unallocated uniforms later } - m_uniformNames[location] = uniform.name; - m_uniformTypes[location] = uniform.glDefineType; - m_uniformIsOpaqueType[location] = uniform.getType()->isOpaque(); - m_uniformArraySizes[location] = uniform.size; + m_uniformIndexInTProgram[location] = i; } SizeT locNeedle = 0; - for (auto index : unallocatedUniformIndex) { + for (auto index: unallocatedUniformIndex) { auto& uniform = m_program->getUniform(index); for (; locNeedle <= m_maxUniformLocation; locNeedle++) { - if (m_uniformTypes[locNeedle] != GL_ZERO) continue; + if (m_uniformIndexInTProgram[locNeedle] != 4095) + continue; // Found a vacant location at locNeedle - m_uniformNames[locNeedle] = uniform.name; - m_uniformTypes[locNeedle] = uniform.glDefineType; - m_uniformIsOpaqueType[locNeedle] = uniform.getType()->isOpaque(); - m_uniformArraySizes[locNeedle] = uniform.size; + m_uniformIndexInTProgram[locNeedle] = index; m_uniformLocations[uniform.name] = locNeedle; break; } diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h index fcb47d2b..bc0c4bde 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h @@ -25,17 +25,27 @@ namespace MobileGL { Uint GetMaxUniformLocation() const { return m_maxUniformLocation; } Int GetUniformLocation(const String& name) { const auto it = m_uniformLocations.find(name); - if (it == m_uniformLocations.end()) return -1; + if (it == m_uniformLocations.end()) + return -1; return (Int)it->second; } - GLenum GetUniformType(Uint index) const { return m_uniformTypes[index]; } + GLenum GetUniformType(Uint location) const { + auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]); + return uniform.glDefineType; + } - Bool IsUniformOpaqueAtLocation(Uint location) const { return m_uniformIsOpaqueType[location]; } + Bool IsUniformOpaqueAtLocation(Uint location) const { + auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]); + return uniform.getType()->isOpaque(); + } - const String& GetUniformName(Uint index) const { return m_uniformNames[index]; } + const String& GetUniformName(Uint location) const { + auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]); + return uniform.name; + } Uint GetUniformOffset(Uint location) const { return m_uniformOffsets[location]; } Uint GetUniformSizesInBytes(Uint location) const { - return MG_Util::GetGLTypeSize(m_uniformTypes[location]); + return MG_Util::GetGLTypeSize(GetUniformType(location)); } Int GetAttributeLocation(const String& name) { @@ -79,12 +89,8 @@ namespace MobileGL { UnorderedMap m_uniformLocations; // Ordered by location, - // aka. m_uniformNames[loc] == "name at location `loc`" - Vector m_uniformNames; - // ditto. - Vector m_uniformTypes; - Vector m_uniformIsOpaqueType; - Vector m_uniformArraySizes; + // aka. m_uniformIndexInTProgram[loc] == "uniform index of TProgram at location `loc`" + Vector m_uniformIndexInTProgram; // Need to be reflected after linking of SPIR-V binary Vector m_uniformOffsets;