mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Misc] (MG_State/ProgramState): Better log.
This commit is contained in:
@@ -84,11 +84,10 @@ namespace MobileGL {
|
|||||||
m_shaders[i]->GetShaderSource().c_str());
|
m_shaders[i]->GetShaderSource().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
MG_Util::ShaderTranspiler::ProgramAttrib attrib{
|
MG_Util::ShaderTranspiler::ProgramAttrib attrib{.shaders = Move(shaders),
|
||||||
.shaders = Move(shaders),
|
.explicitVertexInLocations = m_explicitAttribLocations,
|
||||||
.explicitVertexInLocations = m_explicitAttribLocations,
|
.explicitFragmentOutLocations =
|
||||||
.explicitFragmentOutLocations = m_explicitFragDataLocation
|
m_explicitFragDataLocation};
|
||||||
};
|
|
||||||
|
|
||||||
MGLOG_D("ProgramObject %u: Calling ShaderCompiler::LinkProgram", m_externalIndex);
|
MGLOG_D("ProgramObject %u: Calling ShaderCompiler::LinkProgram", m_externalIndex);
|
||||||
auto result = MG_Util::ShaderTranspiler::ShaderCompiler::LinkProgram(attrib);
|
auto result = MG_Util::ShaderTranspiler::ShaderCompiler::LinkProgram(attrib);
|
||||||
@@ -215,8 +214,7 @@ namespace MobileGL {
|
|||||||
int maxLoc = -1;
|
int maxLoc = -1;
|
||||||
for (int i = 0; i < inCount; ++i) {
|
for (int i = 0; i < inCount; ++i) {
|
||||||
int loc = m_program->getPipeInput(i).layoutLocation();
|
int loc = m_program->getPipeInput(i).layoutLocation();
|
||||||
if (loc >= 0 && loc != glslang::TQualifier::layoutLocationEnd)
|
if (loc >= 0 && loc != glslang::TQualifier::layoutLocationEnd) maxLoc = std::max(maxLoc, loc);
|
||||||
maxLoc = std::max(maxLoc, loc);
|
|
||||||
MGLOG_D("ProgramObject %u: Reflection - pipe input[%d] name='%s' layoutLocation=%d glType=%u",
|
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_externalIndex, i, m_program->getPipeInput(i).name.c_str(), loc,
|
||||||
m_program->getPipeInput(i).glDefineType);
|
m_program->getPipeInput(i).glDefineType);
|
||||||
@@ -252,7 +250,8 @@ namespace MobileGL {
|
|||||||
m_externalIndex, inVar.name.c_str(), location);
|
m_externalIndex, inVar.name.c_str(), location);
|
||||||
}
|
}
|
||||||
// else if (location >= (int)m_attribs.size()) {
|
// else if (location >= (int)m_attribs.size()) {
|
||||||
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - attrib location %d >= attribs.size() "
|
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - attrib location %d >= attribs.size()
|
||||||
|
// "
|
||||||
// "(%zu). Ignoring.",
|
// "(%zu). Ignoring.",
|
||||||
// m_externalIndex, location, m_attribs.size());
|
// m_externalIndex, location, m_attribs.size());
|
||||||
// continue;
|
// continue;
|
||||||
@@ -277,7 +276,8 @@ namespace MobileGL {
|
|||||||
// m_externalIndex, inVar.name.c_str(), m_attribs.size() - 1);
|
// m_externalIndex, inVar.name.c_str(), m_attribs.size() - 1);
|
||||||
// }
|
// }
|
||||||
// if (!placed) {
|
// if (!placed) {
|
||||||
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - cannot place attrib '%s' (no free "
|
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - cannot place attrib '%s' (no
|
||||||
|
// free "
|
||||||
// "slot and at max capacity). Ignoring.",
|
// "slot and at max capacity). Ignoring.",
|
||||||
// m_externalIndex, inVar.name.c_str());
|
// m_externalIndex, inVar.name.c_str());
|
||||||
// }
|
// }
|
||||||
@@ -298,7 +298,8 @@ namespace MobileGL {
|
|||||||
// }
|
// }
|
||||||
// m_attribs.resize(location + 1);
|
// m_attribs.resize(location + 1);
|
||||||
// m_attribTypes.resize(location + 1);
|
// m_attribTypes.resize(location + 1);
|
||||||
// MGLOG_D("ProgramObject %u: Reflection - resized attrib arrays to %zu to accommodate explicit "
|
// MGLOG_D("ProgramObject %u: Reflection - resized attrib arrays to %zu to accommodate explicit
|
||||||
|
// "
|
||||||
// "location %d",
|
// "location %d",
|
||||||
// m_externalIndex, m_attribs.size(), location);
|
// m_externalIndex, m_attribs.size(), location);
|
||||||
// }
|
// }
|
||||||
@@ -366,8 +367,8 @@ namespace MobileGL {
|
|||||||
m_externalIndex, i);
|
m_externalIndex, i);
|
||||||
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader return code %d, log:\n%s",
|
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader return code %d, log:\n%s",
|
||||||
m_externalIndex, res.error().errc, res.error().log.c_str());
|
m_externalIndex, res.error().errc, res.error().log.c_str());
|
||||||
MGLOG_E("ProgramObject %u: GenerateBinary - last compiled shader src: \n%s",
|
MGLOG_E("ProgramObject %u: GenerateBinary - last compiled shader src: \n%s", m_externalIndex,
|
||||||
m_externalIndex, m_shaders[i]->GetShaderSource().c_str());
|
m_shaders[i]->GetShaderSource().c_str());
|
||||||
}
|
}
|
||||||
assert(res); // keep original assert but log first
|
assert(res); // keep original assert but log first
|
||||||
shaders[i] = res.value();
|
shaders[i] = res.value();
|
||||||
@@ -375,11 +376,9 @@ namespace MobileGL {
|
|||||||
m_externalIndex, i, shaders[i].get());
|
m_externalIndex, i, shaders[i].get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgramAttrib attrib{
|
ProgramAttrib attrib{.shaders = Move(shaders),
|
||||||
.shaders = Move(shaders),
|
.explicitVertexInLocations = m_explicitAttribLocations,
|
||||||
.explicitVertexInLocations = m_explicitAttribLocations,
|
.explicitFragmentOutLocations = m_explicitFragDataLocation};
|
||||||
.explicitFragmentOutLocations = m_explicitFragDataLocation
|
|
||||||
};
|
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - linking program for binary", m_externalIndex);
|
MGLOG_D("ProgramObject %u: GenerateBinary - linking program for binary", m_externalIndex);
|
||||||
auto programResult = ShaderCompiler::LinkProgram(attrib);
|
auto programResult = ShaderCompiler::LinkProgram(attrib);
|
||||||
if (!programResult) {
|
if (!programResult) {
|
||||||
@@ -413,50 +412,53 @@ namespace MobileGL {
|
|||||||
SpvcSession session(spv);
|
SpvcSession session(spv);
|
||||||
auto result = session.ParseMetaData();
|
auto result = session.ParseMetaData();
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
MGLOG_E("ProgramObject %u: GenerateBinary - SpvcSession::ParseMetaData failed for module %zu, err = %d%s",
|
MGLOG_D("ProgramObject %u: GenerateBinary - SpvcSession::ParseMetaData failed for module %zu, "
|
||||||
m_externalIndex, i, result, (result == SPVC_ERROR_INVALID_SPIRV ? ". Probably no global UBO?" : ""));
|
"err = %d%s",
|
||||||
|
m_externalIndex, i, result,
|
||||||
|
(result == SPVC_ERROR_INVALID_SPIRV ? ". Probably no global UBO?" : ""));
|
||||||
|
m_uniformSizesInBytes.clear();
|
||||||
|
m_uniformOffsets.clear();
|
||||||
|
m_uboScratch.clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
// auto srcResult = ShaderCompiler::DecompileShader(session);
|
auto& meta = session.GetMetadata();
|
||||||
// assert(srcResult);
|
auto size = meta.uboSize;
|
||||||
// auto src = srcResult.value();
|
MGLOG_D("ProgramObject %u: GenerateBinary - SPIR-V meta: uboSize=%zu plainUniformCount=%zu "
|
||||||
// printf("decompiled src: \n%s\n", src.c_str());
|
"plainUniformOffsets=%zu",
|
||||||
|
m_externalIndex, meta.uboSize, meta.plainUniformMemberSizesInBytes.size(),
|
||||||
auto& meta = session.GetMetadata();
|
meta.plainUniformOffsetsInUBO.size());
|
||||||
auto size = meta.uboSize;
|
m_uboScratch.resize(size);
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - SPIR-V meta: uboSize=%zu plainUniformCount=%zu "
|
m_uniformOffsets.resize(m_maxUniformLocation + 1);
|
||||||
"plainUniformOffsets=%zu",
|
for (const auto& [name, offset] : meta.plainUniformOffsetsInUBO) {
|
||||||
m_externalIndex, meta.uboSize, meta.plainUniformMemberSizesInBytes.size(),
|
if (m_uniformLocations.find(name) != m_uniformLocations.end()) {
|
||||||
meta.plainUniformOffsetsInUBO.size());
|
m_uniformOffsets[m_uniformLocations[name]] = offset;
|
||||||
m_uboScratch.resize(size);
|
MGLOG_D(
|
||||||
m_uniformOffsets.resize(m_maxUniformLocation + 1);
|
"ProgramObject %u: GenerateBinary - uniform '%s' offset=%u assigned to location %u",
|
||||||
for (const auto& [name, offset] : meta.plainUniformOffsetsInUBO) {
|
|
||||||
if (m_uniformLocations.find(name) != m_uniformLocations.end()) {
|
|
||||||
m_uniformOffsets[m_uniformLocations[name]] = offset;
|
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - uniform '%s' offset=%u assigned to location %u",
|
|
||||||
m_externalIndex, name.c_str(), offset, m_uniformLocations[name]);
|
m_externalIndex, name.c_str(), offset, m_uniformLocations[name]);
|
||||||
} else {
|
} else {
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - uniform '%s' offset=%u but not found in "
|
MGLOG_D("ProgramObject %u: GenerateBinary - uniform '%s' offset=%u but not found in "
|
||||||
"m_uniformLocations",
|
"m_uniformLocations",
|
||||||
m_externalIndex, name.c_str(), offset);
|
m_externalIndex, name.c_str(), offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
m_uniformSizesInBytes.resize(m_maxUniformLocation + 1);
|
||||||
m_uniformSizesInBytes.resize(m_maxUniformLocation + 1);
|
for (const auto& [name, size] : meta.plainUniformMemberSizesInBytes) {
|
||||||
for (const auto& [name, size] : meta.plainUniformMemberSizesInBytes) {
|
if (m_uniformLocations.find(name) != m_uniformLocations.end()) {
|
||||||
if (m_uniformLocations.find(name) != m_uniformLocations.end()) {
|
m_uniformSizesInBytes[m_uniformLocations[name]] = size;
|
||||||
m_uniformSizesInBytes[m_uniformLocations[name]] = size;
|
MGLOG_D(
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - uniform '%s' size=%u assigned to location %u",
|
"ProgramObject %u: GenerateBinary - uniform '%s' size=%u assigned to location %u",
|
||||||
m_externalIndex, name.c_str(), size, m_uniformLocations[name]);
|
m_externalIndex, name.c_str(), size, m_uniformLocations[name]);
|
||||||
} else {
|
} else {
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - uniform '%s' size=%u but not found in "
|
MGLOG_D("ProgramObject %u: GenerateBinary - uniform '%s' size=%u but not found in "
|
||||||
"m_uniformLocations",
|
"m_uniformLocations",
|
||||||
m_externalIndex, name.c_str(), size);
|
m_externalIndex, name.c_str(), size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Only parse first module that contains uniform metadata
|
||||||
|
MGLOG_D("ProgramObject %u: GenerateBinary - finished parsing module %zu; breaking after first "
|
||||||
|
"valid metadata",
|
||||||
|
m_externalIndex, i);
|
||||||
}
|
}
|
||||||
// Only parse first module that contains uniform metadata
|
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - finished parsing module %zu; breaking after first "
|
|
||||||
"valid metadata",
|
|
||||||
m_externalIndex, i);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -468,16 +470,16 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProgramObject::SetExplicitVertexInLocation(Uint index, const char* name) {
|
void ProgramObject::SetExplicitVertexInLocation(Uint index, const char* name) {
|
||||||
MGLOG_D("ProgramObject %u: SetExplicitVertexInLocation called name='%s' index=%u", m_externalIndex, name,
|
MGLOG_D("ProgramObject %u: SetExplicitVertexInLocation called name='%s' index=%u", m_externalIndex,
|
||||||
index);
|
name, index);
|
||||||
m_explicitAttribLocations[name] = index;
|
m_explicitAttribLocations[name] = index;
|
||||||
MGLOG_D("ProgramObject %u: SetExplicitVertexInLocation - stored explicit location for '%s' -> %u",
|
MGLOG_D("ProgramObject %u: SetExplicitVertexInLocation - stored explicit location for '%s' -> %u",
|
||||||
m_externalIndex, name, index);
|
m_externalIndex, name, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramObject::SetExplicitFragmentOutLocation(Uint index, const char* name) {
|
void ProgramObject::SetExplicitFragmentOutLocation(Uint index, const char* name) {
|
||||||
MGLOG_D("ProgramObject %u: SetExplicitFragmentOutLocation called name='%s' index=%u", m_externalIndex, name,
|
MGLOG_D("ProgramObject %u: SetExplicitFragmentOutLocation called name='%s' index=%u", m_externalIndex,
|
||||||
index);
|
name, index);
|
||||||
m_explicitFragDataLocation[name] = index;
|
m_explicitFragDataLocation[name] = index;
|
||||||
MGLOG_D("ProgramObject %u: SetExplicitFragmentOutLocation - stored explicit location for '%s' -> %u",
|
MGLOG_D("ProgramObject %u: SetExplicitFragmentOutLocation - stored explicit location for '%s' -> %u",
|
||||||
m_externalIndex, name, index);
|
m_externalIndex, name, index);
|
||||||
@@ -486,8 +488,7 @@ namespace MobileGL {
|
|||||||
Int ProgramObject::GetFragmentDataLocation(const char* name) {
|
Int ProgramObject::GetFragmentDataLocation(const char* name) {
|
||||||
// TODO: should retrieve "post-mortem" location from glslang instead
|
// TODO: should retrieve "post-mortem" location from glslang instead
|
||||||
auto it = m_explicitFragDataLocation.find(name);
|
auto it = m_explicitFragDataLocation.find(name);
|
||||||
if (it == m_explicitFragDataLocation.end())
|
if (it == m_explicitFragDataLocation.end()) return -1;
|
||||||
return -1;
|
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
} // namespace GLState
|
} // namespace GLState
|
||||||
|
|||||||
Reference in New Issue
Block a user