[Chore]: (MG_State/Program): use proper enum constant, get rid of junk

This commit is contained in:
2025-11-12 16:00:44 +08:00
parent bfeb827eb7
commit 9bc0ae6b97
3 changed files with 24 additions and 12 deletions
+14 -4
View File
@@ -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);
@@ -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<int> 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()) {
@@ -104,7 +104,7 @@ namespace MobileGL {
Uint GetExternalIndex() const { return m_externalIndex; }
const UnorderedMap<String, Uint>& GetAttribLocationMap() const { return m_attribLocation; }
// const UnorderedMap<String, Uint>& GetAttribLocationMap() const { return m_attribLocation; }
private:
void DoReflection();
@@ -124,7 +124,7 @@ namespace MobileGL {
Vector<String> m_attribs;
Vector<GLenum> m_attribTypes;
// For SpvcSession::SetVertexAttribLocation()
UnorderedMap<String, Uint> m_attribLocation;
// UnorderedMap<String, Uint> m_attribLocation;
// Uniforms
UnorderedMap<String, Uint> m_uniformLocations;