Skip to content

Commit 17d480d

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.0] [URP] Implement Lazy initialisation for PlatformAutoDetect
1 parent 18b7166 commit 17d480d

1 file changed

Lines changed: 35 additions & 17 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,21 +1954,39 @@ internal enum URPProfileId
19541954
internal static class PlatformAutoDetect
19551955
{
19561956
/// <summary>
1957-
/// Detect and cache runtime platform information. This function should only be called once when creating the URP.
1957+
/// Detect and cache runtime platform information.
1958+
/// Lazy initialized for situations where platform detection is required before URP is initialized (UUM-134298)
19581959
/// </summary>
1959-
internal static void Initialize()
1960+
private sealed class PlatformDetectionCache
19601961
{
1961-
bool isRunningMobile = false;
1962-
#if ENABLE_VR && ENABLE_VR_MODULE
1963-
#if PLATFORM_WINRT || PLATFORM_ANDROID
1964-
isRunningMobile = IsRunningXRMobile();
1962+
public readonly bool isXRMobile;
1963+
public readonly bool isShaderAPIMobileDefined;
1964+
public readonly bool isSwitch;
1965+
public readonly bool isSwitch2;
1966+
public readonly bool isRunningOnPowerVRGPU;
1967+
1968+
public PlatformDetectionCache()
1969+
{
1970+
bool isRunningMobile = false;
1971+
#if ENABLE_VR && ENABLE_XR_MODULE
1972+
#if PLATFORM_WINRT || PLATFORM_ANDROID
1973+
isRunningMobile = IsRunningXRMobile();
1974+
#endif
19651975
#endif
1966-
#endif
19671976

1968-
isXRMobile = isRunningMobile;
1969-
isShaderAPIMobileDefined = GraphicsSettings.HasShaderDefine(BuiltinShaderDefine.SHADER_API_MOBILE);
1970-
isSwitch = Application.platform == RuntimePlatform.Switch;
1971-
isSwitch2 = Application.platform == RuntimePlatform.Switch2;
1977+
isXRMobile = isRunningMobile;
1978+
isShaderAPIMobileDefined = GraphicsSettings.HasShaderDefine(BuiltinShaderDefine.SHADER_API_MOBILE);
1979+
isSwitch = Application.platform == RuntimePlatform.Switch;
1980+
isSwitch2 = Application.platform == RuntimePlatform.Switch2;
1981+
isRunningOnPowerVRGPU = SystemInfo.graphicsDeviceName.Contains("PowerVR");
1982+
}
1983+
}
1984+
1985+
private static readonly Lazy<PlatformDetectionCache> platformCache = new(() => new PlatformDetectionCache(), true);
1986+
1987+
internal static void Initialize()
1988+
{
1989+
_ = platformCache.Value;
19721990
}
19731991

19741992
#if ENABLE_VR && ENABLE_VR_MODULE
@@ -1997,19 +2015,21 @@ private static bool IsRunningXRMobile()
19972015
/// <summary>
19982016
/// If true, the runtime platform is an XR mobile platform.
19992017
/// </summary>
2000-
internal static bool isXRMobile { get; private set; } = false;
2018+
internal static bool isXRMobile => platformCache.Value.isXRMobile;
20012019

20022020
/// <summary>
20032021
/// If true, then SHADER_API_MOBILE has been defined in URP Shaders.
20042022
/// </summary>
2005-
internal static bool isShaderAPIMobileDefined { get; private set; } = false;
2023+
internal static bool isShaderAPIMobileDefined => platformCache.Value.isShaderAPIMobileDefined;
20062024

20072025
/// <summary>
20082026
/// If true, then the runtime platform is set to Switch.
20092027
/// </summary>
2010-
internal static bool isSwitch { get; private set; } = false;
2028+
internal static bool isSwitch => platformCache.Value.isSwitch;
20112029

2012-
internal static bool isSwitch2 { get; private set; } = false;
2030+
internal static bool isSwitch2 => platformCache.Value.isSwitch2;
2031+
2032+
internal static bool isRunningOnPowerVRGPU => platformCache.Value.isRunningOnPowerVRGPU;
20132033

20142034
/// <summary>
20152035
/// Gives the SH evaluation mode when set to automatically detect.
@@ -2028,7 +2048,5 @@ internal static ShEvalMode ShAutoDetect(ShEvalMode mode)
20282048

20292049
return mode;
20302050
}
2031-
2032-
internal static bool isRunningOnPowerVRGPU = SystemInfo.graphicsDeviceName.Contains("PowerVR");
20332051
}
20342052
}

0 commit comments

Comments
 (0)