mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Refactor] (MG_Config, MG_Backend/DirectVulkan, trace-replay): centralize Magma env parsing and rename R11G11B10F fallback
This commit is contained in:
+3
-1
@@ -41,8 +41,10 @@ namespace MobileGL::MG_Config {
|
||||
String RetraceAngleDir;
|
||||
// MOBILEGL_DISABLE_SUBGROUP: force-disable Vulkan shader subgroup support.
|
||||
Bool DisableSubgroup = false;
|
||||
// MOBILEGL_VULKAN_R11G11B10F_FALLBACK: use fallback format for R11G11B10F on Vulkan.
|
||||
// MOBILEGL_MAGMA_R11G11B10F_FALLBACK: use fallback format for R11G11B10F on Vulkan.
|
||||
Bool VulkanR11G11B10FFallback = false;
|
||||
// MOBILEGL_MAGMA_FRAMESINFLIGHT: requested Magma frames in flight, defaulting to 3.
|
||||
Uint32 MagmaFramesInFlight = 3;
|
||||
// MOBILEGL_GLES_PRESENT_STATS: log present pixel statistics (DirectGLES backend).
|
||||
Bool GlesPresentStats = false;
|
||||
// MOBILEGL_ANGLE_LLVMPIPE_AVOID_SAMPLER_MIPMAP_MIN_FILTER: avoid mipmap min
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
|
||||
#ifndef _WIN32
|
||||
extern char** environ;
|
||||
#endif
|
||||
@@ -83,13 +86,35 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
return it != acceptedEnvVariablesMap->end() && IsTruthyValue(it->second);
|
||||
}
|
||||
|
||||
inline Uint32 QueryEnvUint32(const String& key, Uint32 defaultValue, Uint32 minValue, Uint32 maxValue) {
|
||||
auto it = acceptedEnvVariablesMap->find(key);
|
||||
if (it == acceptedEnvVariablesMap->end()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
const String& value = it->second;
|
||||
char* parseEnd = nullptr;
|
||||
errno = 0;
|
||||
const unsigned long parsedValue = std::strtoul(value.c_str(), &parseEnd, 10);
|
||||
if (parseEnd == value.c_str() || *parseEnd != '\0' || errno == ERANGE || parsedValue < minValue ||
|
||||
parsedValue > maxValue) {
|
||||
MGLOG_W("Config: Ignoring invalid env variable %s='%s'; expected an integer in range [%u, %u], "
|
||||
"using default %u",
|
||||
key.c_str(), value.c_str(), minValue, maxValue, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return static_cast<Uint32>(parsedValue);
|
||||
}
|
||||
|
||||
inline void InitFeatures() {
|
||||
auto& features = MG_Config::Features;
|
||||
features.DisableTimerQuery = QueryEnvFlag("MOBILEGL_DISABLE_TIMERQUERY");
|
||||
features.RetraceUseAngle = QueryEnvFlag("MOBILEGL_RETRACE_USE_ANGLE");
|
||||
QueryEnvVariable("MOBILEGL_RETRACE_ANGLE_DIR", features.RetraceAngleDir, "");
|
||||
features.DisableSubgroup = QueryEnvFlag("MOBILEGL_DISABLE_SUBGROUP");
|
||||
features.VulkanR11G11B10FFallback = QueryEnvFlag("MOBILEGL_VULKAN_R11G11B10F_FALLBACK");
|
||||
features.VulkanR11G11B10FFallback = QueryEnvFlag("MOBILEGL_MAGMA_R11G11B10F_FALLBACK");
|
||||
features.MagmaFramesInFlight = QueryEnvUint32("MOBILEGL_MAGMA_FRAMESINFLIGHT", 3, 1, 64);
|
||||
features.GlesPresentStats = QueryEnvFlag("MOBILEGL_GLES_PRESENT_STATS");
|
||||
features.AvoidAngleLlvmpipeSamplerMipmapMinFilter =
|
||||
QueryEnvFlag("MOBILEGL_ANGLE_LLVMPIPE_AVOID_SAMPLER_MIPMAP_MIN_FILTER");
|
||||
|
||||
@@ -1911,20 +1911,10 @@ void main() {
|
||||
// renderer init.) Existing logs already report the swapchain's min/actual image count;
|
||||
// this one adds the frames-in-flight decision itself.
|
||||
{
|
||||
// Desired depth comes from the MOBILEGL_MAGMA_FRAMESINFLIGHT env var (so it can be
|
||||
// tuned per device without a rebuild); if unset/invalid, fall back to the config value.
|
||||
Uint32 requestedFramesInFlight = m_config.MaxFramesInFlight;
|
||||
if (const char* framesEnv = std::getenv("MOBILEGL_MAGMA_FRAMESINFLIGHT")) {
|
||||
char* parseEnd = nullptr;
|
||||
const long parsedFrames = std::strtol(framesEnv, &parseEnd, 10);
|
||||
if (parseEnd != framesEnv && *parseEnd == '\0' && parsedFrames >= 1 && parsedFrames <= 64) {
|
||||
requestedFramesInFlight = static_cast<Uint32>(parsedFrames);
|
||||
MGLOG_I("MaxFramesInFlight: MOBILEGL_MAGMA_FRAMESINFLIGHT=%ld requested", parsedFrames);
|
||||
} else {
|
||||
MGLOG_W("MaxFramesInFlight: ignoring invalid MOBILEGL_MAGMA_FRAMESINFLIGHT='%s'; "
|
||||
"falling back to %u", framesEnv, requestedFramesInFlight);
|
||||
}
|
||||
}
|
||||
// Desired depth comes from MOBILEGL_MAGMA_FRAMESINFLIGHT, parsed once by ConfigLoader
|
||||
// with a default of 3 when the variable is unset or invalid.
|
||||
Uint32 requestedFramesInFlight = MG_Config::Features.MagmaFramesInFlight;
|
||||
MGLOG_I("MaxFramesInFlight: configured request=%u", requestedFramesInFlight);
|
||||
|
||||
VkSurfaceCapabilitiesKHR surfaceCaps{};
|
||||
const VkResult capsResult = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||
|
||||
Reference in New Issue
Block a user