Skip to content

Commit

Permalink
Revert to old (Vantage) way of GPU Working Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Jul 18, 2023
1 parent 405c98e commit abc4884
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task SetStateAsync(HybridModeState state)
}
finally
{
if (!gSyncChanged && igpuMode == IGPUModeState.Default)
if (!gSyncChanged && igpuMode is IGPUModeState.Default or IGPUModeState.Auto)
await _dgpuNotify.NotifyLaterIfNeededAsync().ConfigureAwait(false);
}
}
Expand Down
22 changes: 12 additions & 10 deletions LenovoLegionToolkit.Lib/Features/Hybrid/IGPUModeFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

namespace LenovoLegionToolkit.Lib.Features.Hybrid;

public class IGPUModeFeature : AbstractCompositeFeature<IGPUModeState, IGPUModeCapabilityFeature, IGPUModeFeatureFlagsFeature, IGPUModeGamezoneFeature>
public class IGPUModeFeature : AbstractCompositeFeature<IGPUModeState, IGPUModeGamezoneFeature, IGPUModeCapabilityFeature, IGPUModeFeatureFlagsFeature>
{
public bool EnableLegacySwitching { get; set; }
public bool ExperimentalGPUWorkingMode { get; set; }

public IGPUModeFeature(IGPUModeCapabilityFeature feature1, IGPUModeFeatureFlagsFeature feature2, IGPUModeGamezoneFeature feature3) : base(feature1, feature2, feature3) { }
public IGPUModeFeature(IGPUModeGamezoneFeature feature1, IGPUModeCapabilityFeature feature2, IGPUModeFeatureFlagsFeature feature3) : base(feature1, feature2, feature3) { }

protected override async Task<IFeature<IGPUModeState>?> GetFeatureLazyAsync()
{
if (EnableLegacySwitching)
return await Feature3.IsSupportedAsync().ConfigureAwait(false) ? Feature3 : null;
if (ExperimentalGPUWorkingMode)
{
if (await Feature2.IsSupportedAsync().ConfigureAwait(false))
return Feature2;

if (await Feature1.IsSupportedAsync().ConfigureAwait(false))
return Feature1;
if (await Feature3.IsSupportedAsync().ConfigureAwait(false))
return Feature3;

if (await Feature2.IsSupportedAsync().ConfigureAwait(false))
return Feature2;
return null;
}

return null;
return await Feature1.IsSupportedAsync().ConfigureAwait(false) ? Feature1 : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Task NotifyLaterIfNeededAsync()
token = _notifyLaterCancellationTokenSource.Token;
}

_ = Task.Delay(TimeSpan.FromSeconds(10), token)
_ = Task.Delay(TimeSpan.FromSeconds(5), token)
.ContinueWith(async t =>
{
if (!t.IsCompletedSuccessfully)
Expand Down
22 changes: 12 additions & 10 deletions LenovoLegionToolkit.Lib/Features/Hybrid/Notify/DGPUNotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public event EventHandler<bool>? Notified
}
}

public bool EnableLegacySwitching { get; set; }
public bool ExperimentalGPUWorkingMode { get; set; }

public DGPUNotify(DGPUCapabilityNotify capabilityNotify, DGPUFeatureFlagsNotify featureFlagsNotify, DGPUGamezoneNotify gamezoneNotify)
public DGPUNotify(DGPUGamezoneNotify gamezoneNotify, DGPUCapabilityNotify capabilityNotify, DGPUFeatureFlagsNotify featureFlagsNotify)
{
_gamezoneNotify = gamezoneNotify ?? throw new ArgumentNullException(nameof(gamezoneNotify));
_capabilityNotify = capabilityNotify ?? throw new ArgumentNullException(nameof(capabilityNotify));
_featureFlagsNotify = featureFlagsNotify ?? throw new ArgumentNullException(nameof(featureFlagsNotify));
_gamezoneNotify = gamezoneNotify ?? throw new ArgumentNullException(nameof(gamezoneNotify));

_lazyAsyncNotify = new(GetNotifyLazyAsync);
}
Expand All @@ -54,15 +54,17 @@ public async Task NotifyLaterIfNeededAsync()

private async Task<IDGPUNotify?> GetNotifyLazyAsync()
{
if (EnableLegacySwitching)
return await _gamezoneNotify.IsSupportedAsync().ConfigureAwait(false) ? _gamezoneNotify : null;
if (ExperimentalGPUWorkingMode)
{
if (await _capabilityNotify.IsSupportedAsync().ConfigureAwait(false))
return _capabilityNotify;

if (await _capabilityNotify.IsSupportedAsync().ConfigureAwait(false))
return _capabilityNotify;
if (await _featureFlagsNotify.IsSupportedAsync().ConfigureAwait(false))
return _featureFlagsNotify;

if (await _featureFlagsNotify.IsSupportedAsync().ConfigureAwait(false))
return _featureFlagsNotify;
return null;
}

return null;
return await _gamezoneNotify.IsSupportedAsync().ConfigureAwait(false) ? _gamezoneNotify : null;
}
}
8 changes: 2 additions & 6 deletions LenovoLegionToolkit.WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private async void Application_Startup(object sender, StartupEventArgs e)
IoCContainer.Resolve<WhiteKeyboardLenovoLightingBacklightFeature>().ForceDisable = flags.ForceDisableLenovoLighting;
IoCContainer.Resolve<PanelLogoLenovoLightingBacklightFeature>().ForceDisable = flags.ForceDisableLenovoLighting;
IoCContainer.Resolve<PortsBacklightFeature>().ForceDisable = flags.ForceDisableLenovoLighting;
IoCContainer.Resolve<IGPUModeFeature>().EnableLegacySwitching = flags.LegacyGPUWorkingModeSwitching;
IoCContainer.Resolve<DGPUNotify>().EnableLegacySwitching = flags.LegacyGPUWorkingModeSwitching;
IoCContainer.Resolve<IGPUModeFeature>().ExperimentalGPUWorkingMode = flags.ExperimentalGPUWorkingMode;
IoCContainer.Resolve<DGPUNotify>().ExperimentalGPUWorkingMode = flags.ExperimentalGPUWorkingMode;

await LogSoftwareStatusAsync();
await InitPowerModeFeatureAsync();
Expand All @@ -106,10 +106,6 @@ private async void Application_Startup(object sender, StartupEventArgs e)
await InitGpuOverclockControllerAsync();
await InitAutomationProcessorAsync();

var dgpuNotify = IoCContainer.Resolve<DGPUNotify>();
if (await dgpuNotify.IsSupportedAsync())
await dgpuNotify.NotifyAsync();

#if !DEBUG
Autorun.Validate();
#endif
Expand Down
6 changes: 3 additions & 3 deletions LenovoLegionToolkit.WPF/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Flags
public bool ForceDisableRgbKeyboardSupport { get; }
public bool ForceDisableSpectrumKeyboardSupport { get; }
public bool ForceDisableLenovoLighting { get; }
public bool LegacyGPUWorkingModeSwitching { get; }
public bool ExperimentalGPUWorkingMode { get; }

public Flags(IEnumerable<string> startupArgs)
{
Expand All @@ -32,7 +32,7 @@ public Flags(IEnumerable<string> startupArgs)
ForceDisableRgbKeyboardSupport = args.Contains("--force-disable-rgbkb");
ForceDisableSpectrumKeyboardSupport = args.Contains("--force-disable-spectrumkb");
ForceDisableLenovoLighting = args.Contains("--force-disable-lenovolighting");
LegacyGPUWorkingModeSwitching = args.Contains("--legacy-gpu-working-mode");
ExperimentalGPUWorkingMode = args.Contains("--experimental-gpu-working-mode");
}

private static IEnumerable<string> LoadExternalArgs()
Expand All @@ -57,5 +57,5 @@ public override string ToString() =>
$" {nameof(ForceDisableRgbKeyboardSupport)}: {ForceDisableRgbKeyboardSupport}," +
$" {nameof(ForceDisableSpectrumKeyboardSupport)}: {ForceDisableSpectrumKeyboardSupport}," +
$" {nameof(ForceDisableLenovoLighting)}: {ForceDisableLenovoLighting}," +
$" {nameof(LegacyGPUWorkingModeSwitching)}: {LegacyGPUWorkingModeSwitching}";
$" {nameof(ExperimentalGPUWorkingMode)}: {ExperimentalGPUWorkingMode}";
}

0 comments on commit abc4884

Please sign in to comment.