[Fix] (MG_State/Program): use vector to save uniforms instead

This commit is contained in:
2025-08-13 16:41:46 +08:00
parent d1942bc57d
commit bfb62872c9
3 changed files with 17 additions and 7 deletions
@@ -67,7 +67,12 @@ namespace MobileGL {
root->traverse(&traverser);
auto& symbols = traverser.GetCollectedSymbols();
for (const auto& symbol : symbols) {
m_uniforms[symbol->getName().c_str()] = symbol->getQualifier().layoutLocation;
auto layoutLoc = symbol->getQualifier().layoutLocation;
if (layoutLoc >= m_uniforms.size()) {
m_uniforms.reserve(std::bit_ceil(layoutLoc));
m_uniforms.resize(layoutLoc + 1);
}
m_uniforms[layoutLoc] = symbol->getName().c_str();
}
return true;
@@ -73,7 +73,7 @@ namespace MobileGL {
const ShaderStage m_stage;
String m_source;
SharedPtr<glslang::TShader> m_shader;
UnorderedMap<String, Int> m_uniforms;
Vector<String> m_uniforms;
String m_infoLog;
Bool m_deleteStatus = false;
+10 -5
View File
@@ -199,7 +199,7 @@ TEST_F(ProgramUtilTest, CompileVertexShaderWithLocation) {
ASSERT_NE(res.error().errc, 0);
FAIL() << "errc: " << res.error().errc << "\nlog: " << res.error().log;
}
UnorderedMap<String, Int> uniforms;
Vector<String> uniforms;
auto pShader = res.value();
auto root = pShader->getIntermediate()->getTreeRoot();
@@ -207,12 +207,17 @@ TEST_F(ProgramUtilTest, CompileVertexShaderWithLocation) {
root->traverse(&traverser);
auto& symbols = traverser.GetCollectedSymbols();
for (const auto& symbol : symbols) {
uniforms[symbol->getName().c_str()] = symbol->getQualifier().layoutLocation;
auto layoutLoc = symbol->getQualifier().layoutLocation;
if (layoutLoc >= uniforms.size()) {
uniforms.reserve(std::bit_ceil(layoutLoc));
uniforms.resize(layoutLoc + 1);
}
uniforms[layoutLoc] = symbol->getName().c_str();
}
EXPECT_EQ(uniforms["ProjMat"], 1);
EXPECT_EQ(uniforms["InSize"], 20);
EXPECT_EQ(uniforms["OutSize"], 4095);
EXPECT_EQ(uniforms[1], "ProjMat");
EXPECT_EQ(uniforms[20], "InSize");
EXPECT_EQ(uniforms[4095], "OutSize");
}
TEST_F(ProgramUtilTest, CompileAndLinkProgram) {