[Chore] (MG_Backend/DirectVulkan): exclude some validation logic from release build

This commit is contained in:
2026-05-09 13:45:19 +08:00
parent 9fbd83d602
commit c5bf0dc07d
4 changed files with 19 additions and 85 deletions
+13 -9
View File
@@ -34,7 +34,7 @@
#define MOBILEGL_EGL_API MOBILEGL_API
// ====================== MobileGL configurations ======================= //
#define MOBILEGL_LOG_ACTIVE_LEVEL MOBILEGL_LOG_LEVEL_DEBUG
#define MOBILEGL_LOG_ACTIVE_LEVEL MOBILEGL_LOG_LEVEL_FATAL
#define MOBILEGL_LOG_ENABLE_CONSOLE 0
#define MOBILEGL_LOG_ENABLE_FILE 1
@@ -63,11 +63,15 @@
#endif
// =============================== Utils ================================ //
#define MOBILEGL_ASSERT(condition, ...) \
do { \
if (!(condition)) { \
MGLOG_F("Assertion failed" __VA_OPT__(": ") __VA_ARGS__); \
MGLOG_F(" at %s:%d (%s)", __FILE__, __LINE__, __func__); \
TRAP; \
} \
} while (0)
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
#define MOBILEGL_ASSERT(condition, ...) \
do { \
if (!(condition)) { \
MGLOG_F("Assertion failed" __VA_OPT__(": ") __VA_ARGS__); \
MGLOG_F(" at %s:%d (%s)", __FILE__, __LINE__, __func__); \
TRAP; \
} \
} while (0)
#else
#define MOBILEGL_ASSERT(condition, ...)
#endif
@@ -1549,7 +1549,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
auto& moduleSpv = moduleSpirvs[i];
if (moduleSpv.empty()) continue;
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
ValidateTransformedSpirv(moduleSpv, shaders[i]->GetShaderStage(), program.GetExternalIndex());
#endif
VkShaderModuleCreateInfo smci{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
smci.codeSize = moduleSpv.size() * sizeof(Uint);
@@ -1569,7 +1571,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
}
// Reflect and create layout as part of the program object
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
ValidateRasterizationStageInterface(shaders, moduleSpirvs, entry, program.GetExternalIndex());
#endif
ReflectVertexInputs(shaders, moduleSpirvs, entry);
ReflectFragmentOutputs(shaders, moduleSpirvs, entry);
ReflectLayout(program, moduleSpirvs, entry);
@@ -1998,6 +1998,7 @@ void main() {
return VK_NULL_HANDLE;
}
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
const auto& limits = m_physicalDevice.properties.limits;
if (programObj.fragmentInputComponentCount != 0) {
MOBILEGL_ASSERT(
@@ -2033,6 +2034,7 @@ void main() {
static_cast<Int>(programObj.rasterizationProducerStage));
}
}
#endif
auto vertexInputHash = m_vertexInputStateFactory->ComputeHash(vao);
auto& vis = m_vertexInputStateFactory->GetOrCreateVertexInputState(vao);
@@ -357,84 +357,8 @@ namespace MobileGL::MG_State::GLState {
static_cast<Uint32>(locationType));
}
}
// else if (location >= (int)m_attribs.size()) {
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - attrib location %d >= attribs.size()
// "
// "(%zu). Ignoring.",
// m_externalIndex, location, m_attribs.size());
// continue;
// }
// else {
// bool placed = false;
// for (size_t idx = 0; idx < m_attribs.size(); ++idx) {
// if (m_attribs[idx].empty()) {
// m_attribs[idx] = inVar.name;
// m_attribTypes[idx] = inVar.glDefineType;
// placed = true;
// MGLOG_D("ProgramObject %u: Reflection - placed attrib '%s' into free slot %zu",
// m_externalIndex, inVar.name.c_str(), idx);
// break;
// }
// }
// if (!placed && (int)m_attribs.size() < maxAttribs) {
// m_attribs.push_back(inVar.name);
// m_attribTypes.push_back(inVar.glDefineType);
// placed = true;
// MGLOG_D("ProgramObject %u: Reflection - pushed attrib '%s' to new slot %zu",
// m_externalIndex, inVar.name.c_str(), m_attribs.size() - 1);
// }
// if (!placed) {
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - cannot place attrib '%s' (no
// free "
// "slot and at max capacity). Ignoring.",
// m_externalIndex, inVar.name.c_str());
// }
// }
}
// Implement glBindAttribLocation semantics (explicit locations set by user)
// for (auto& [name, location] : m_explicitAttribLocations) {
// MGLOG_D("ProgramObject %u: Reflection - explicit attrib location request: name='%s' location=%d",
// m_externalIndex, name.c_str(), location);
// if (location < 0) continue;
// if (location >= (int)m_attribs.size()) {
// if (location >= maxAttribs) {
// MGLOG_W("ProgramObject %u: SetExplicitVertexInLocation: requested location %d >= "
// "GL_MAX_VERTEX_ATTRIBS (%d). Ignored for attribute '%s'.",
// m_externalIndex, location, maxAttribs, name.c_str());
// continue;
// }
// m_attribs.resize(location + 1);
// m_attribTypes.resize(location + 1);
// MGLOG_D("ProgramObject %u: Reflection - resized attrib arrays to %zu to accommodate explicit
// "
// "location %d",
// m_externalIndex, m_attribs.size(), location);
// }
//
// if (m_attribs[location] != name) {
// auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
// if (it == m_attribs.end()) {
// MGLOG_D("ProgramObject %u: Reflection - explicit attrib '%s' not found in current list, "
// "skipping swap",
// m_externalIndex, name.c_str());
// continue;
// }
// auto idx = std::distance(m_attribs.begin(), it);
// std::swap(m_attribs[location], m_attribs[idx]);
// std::swap(m_attribTypes[location], m_attribTypes[idx]);
// MGLOG_D("ProgramObject %u: Reflection - swapped attrib '%s' from idx %zu to explicit "
// "location %d",
// m_externalIndex, name.c_str(), idx, location);
// }
//
// for (SizeT idx = 0; idx < m_attribs.size(); ++idx) {
// m_attribLocation[m_attribs[idx]] = idx;
// MGLOG_D("ProgramObject %u: Reflection - attribLocation['%s'] = %zu", m_externalIndex,
// m_attribs[idx].c_str(), idx);
// }
// }
// ---------- UBO ----------
Int uboCount = m_program->getNumUniformBlocks();
MGLOG_D("ProgramObject %u: Reflection - uniform block count (UBO) = %d", m_externalIndex, uboCount);