highly experimental runtime model decimation + file cache adjustment to clean up processed file copies
This commit is contained in:
@@ -12,6 +12,7 @@ using LightlessSync.Services;
|
||||
using LightlessSync.Services.ActorTracking;
|
||||
using LightlessSync.Services.Events;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Services.ModelDecimation;
|
||||
using LightlessSync.Services.PairProcessing;
|
||||
using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.Services.TextureCompression;
|
||||
@@ -45,6 +46,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
private readonly ServerConfigurationManager _serverConfigManager;
|
||||
private readonly PluginWarningNotificationService _pluginWarningNotificationManager;
|
||||
private readonly TextureDownscaleService _textureDownscaleService;
|
||||
private readonly ModelDecimationService _modelDecimationService;
|
||||
private readonly PairStateCache _pairStateCache;
|
||||
private readonly PairPerformanceMetricsCache _performanceMetricsCache;
|
||||
private readonly PenumbraTempCollectionJanitor _tempCollectionJanitor;
|
||||
@@ -162,6 +164,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
|
||||
public long LastAppliedDataBytes { get; private set; }
|
||||
public long LastAppliedDataTris { get; set; } = -1;
|
||||
public long LastAppliedApproximateEffectiveTris { get; set; } = -1;
|
||||
public long LastAppliedApproximateVRAMBytes { get; set; } = -1;
|
||||
public long LastAppliedApproximateEffectiveVRAMBytes { get; set; } = -1;
|
||||
public CharacterData? LastReceivedCharacterData { get; private set; }
|
||||
@@ -198,6 +201,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
PairProcessingLimiter pairProcessingLimiter,
|
||||
ServerConfigurationManager serverConfigManager,
|
||||
TextureDownscaleService textureDownscaleService,
|
||||
ModelDecimationService modelDecimationService,
|
||||
PairStateCache pairStateCache,
|
||||
PairPerformanceMetricsCache performanceMetricsCache,
|
||||
PenumbraTempCollectionJanitor tempCollectionJanitor) : base(logger, mediator)
|
||||
@@ -217,6 +221,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
_pairProcessingLimiter = pairProcessingLimiter;
|
||||
_serverConfigManager = serverConfigManager;
|
||||
_textureDownscaleService = textureDownscaleService;
|
||||
_modelDecimationService = modelDecimationService;
|
||||
_pairStateCache = pairStateCache;
|
||||
_performanceMetricsCache = performanceMetricsCache;
|
||||
_tempCollectionJanitor = tempCollectionJanitor;
|
||||
@@ -242,7 +247,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
return;
|
||||
}
|
||||
|
||||
if (LastAppliedDataBytes < 0 || LastAppliedDataTris < 0
|
||||
if (LastAppliedDataBytes < 0 || LastAppliedDataTris < 0 || LastAppliedApproximateEffectiveTris < 0
|
||||
|| LastAppliedApproximateVRAMBytes < 0 || LastAppliedApproximateEffectiveVRAMBytes < 0)
|
||||
{
|
||||
_forceApplyMods = true;
|
||||
@@ -579,6 +584,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
_forceApplyMods = true;
|
||||
LastAppliedDataBytes = -1;
|
||||
LastAppliedDataTris = -1;
|
||||
LastAppliedApproximateEffectiveTris = -1;
|
||||
LastAppliedApproximateVRAMBytes = -1;
|
||||
LastAppliedApproximateEffectiveVRAMBytes = -1;
|
||||
}
|
||||
@@ -626,6 +632,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
_forceFullReapply = true;
|
||||
LastAppliedDataBytes = -1;
|
||||
LastAppliedDataTris = -1;
|
||||
LastAppliedApproximateEffectiveTris = -1;
|
||||
LastAppliedApproximateVRAMBytes = -1;
|
||||
LastAppliedApproximateEffectiveVRAMBytes = -1;
|
||||
}
|
||||
@@ -725,6 +732,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
private void ApplyCachedMetrics(PairPerformanceMetrics metrics)
|
||||
{
|
||||
LastAppliedDataTris = metrics.TriangleCount;
|
||||
LastAppliedApproximateEffectiveTris = metrics.ApproximateEffectiveTris;
|
||||
LastAppliedApproximateVRAMBytes = metrics.ApproximateVramBytes;
|
||||
LastAppliedApproximateEffectiveVRAMBytes = metrics.ApproximateEffectiveVramBytes;
|
||||
}
|
||||
@@ -732,6 +740,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
private void StorePerformanceMetrics(CharacterData charaData)
|
||||
{
|
||||
if (LastAppliedDataTris < 0
|
||||
|| LastAppliedApproximateEffectiveTris < 0
|
||||
|| LastAppliedApproximateVRAMBytes < 0
|
||||
|| LastAppliedApproximateEffectiveVRAMBytes < 0)
|
||||
{
|
||||
@@ -747,7 +756,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
_performanceMetricsCache.StoreMetrics(
|
||||
Ident,
|
||||
dataHash,
|
||||
new PairPerformanceMetrics(LastAppliedDataTris, LastAppliedApproximateVRAMBytes, LastAppliedApproximateEffectiveVRAMBytes));
|
||||
new PairPerformanceMetrics(LastAppliedDataTris, LastAppliedApproximateVRAMBytes, LastAppliedApproximateEffectiveVRAMBytes, LastAppliedApproximateEffectiveTris));
|
||||
}
|
||||
|
||||
private bool HasMissingCachedFiles(CharacterData characterData)
|
||||
@@ -1079,7 +1088,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
Logger.LogDebug("[BASE-{appbase}] Downloading and applying character for {name}", applicationBase, GetPrimaryAliasOrUidSafe());
|
||||
|
||||
var forceFullReapply = _forceFullReapply
|
||||
|| LastAppliedApproximateVRAMBytes < 0 || LastAppliedDataTris < 0;
|
||||
|| LastAppliedApproximateVRAMBytes < 0 || LastAppliedDataTris < 0 || LastAppliedApproximateEffectiveTris < 0;
|
||||
|
||||
DownloadAndApplyCharacter(applicationBase, characterData.DeepClone(), charaDataToUpdate, forceFullReapply);
|
||||
}
|
||||
@@ -1895,6 +1904,17 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
{
|
||||
await _textureDownscaleService.WaitForPendingJobsAsync(downloadedTextureHashes, downloadToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var downloadedModelHashes = toDownloadReplacements
|
||||
.Where(static replacement => replacement.GamePaths.Any(static path => path.EndsWith(".mdl", StringComparison.OrdinalIgnoreCase)))
|
||||
.Select(static replacement => replacement.Hash)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
if (downloadedModelHashes.Count > 0)
|
||||
{
|
||||
await _modelDecimationService.WaitForPendingJobsAsync(downloadedModelHashes, downloadToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
toDownloadReplacements = TryCalculateModdedDictionary(applicationBase, charaData, out moddedPaths, downloadToken);
|
||||
@@ -2117,18 +2137,19 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
_needsCollectionRebuild = false;
|
||||
if (LastAppliedApproximateVRAMBytes < 0 || LastAppliedApproximateEffectiveVRAMBytes < 0)
|
||||
{
|
||||
_playerPerformanceService.ComputeAndAutoPauseOnVRAMUsageThresholds(this, charaData, new List<DownloadFileTransfer>());
|
||||
}
|
||||
if (LastAppliedDataTris < 0)
|
||||
{
|
||||
await _playerPerformanceService.CheckTriangleUsageThresholds(this, charaData).ConfigureAwait(false);
|
||||
}
|
||||
_playerPerformanceService.ComputeAndAutoPauseOnVRAMUsageThresholds(this, charaData, new List<DownloadFileTransfer>());
|
||||
}
|
||||
|
||||
StorePerformanceMetrics(charaData);
|
||||
_lastSuccessfulDataHash = GetDataHashSafe(charaData);
|
||||
_lastSuccessfulApplyAt = DateTime.UtcNow;
|
||||
ClearFailureState();
|
||||
Logger.LogDebug("[{applicationId}] Application finished", _applicationId);
|
||||
if (LastAppliedDataTris < 0 || LastAppliedApproximateEffectiveTris < 0)
|
||||
{
|
||||
await _playerPerformanceService.CheckTriangleUsageThresholds(this, charaData).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
StorePerformanceMetrics(charaData);
|
||||
_lastSuccessfulDataHash = GetDataHashSafe(charaData);
|
||||
_lastSuccessfulApplyAt = DateTime.UtcNow;
|
||||
ClearFailureState();
|
||||
Logger.LogDebug("[{applicationId}] Application finished", _applicationId);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -2397,9 +2418,18 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
|
||||
foreach (var gamePath in item.GamePaths)
|
||||
{
|
||||
var preferredPath = skipDownscaleForPair
|
||||
? fileCache.ResolvedFilepath
|
||||
: _textureDownscaleService.GetPreferredPath(item.Hash, fileCache.ResolvedFilepath);
|
||||
var preferredPath = fileCache.ResolvedFilepath;
|
||||
if (!skipDownscaleForPair)
|
||||
{
|
||||
if (gamePath.EndsWith(".tex", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
preferredPath = _textureDownscaleService.GetPreferredPath(item.Hash, fileCache.ResolvedFilepath);
|
||||
}
|
||||
else if (gamePath.EndsWith(".mdl", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
preferredPath = _modelDecimationService.GetPreferredPath(item.Hash, fileCache.ResolvedFilepath);
|
||||
}
|
||||
}
|
||||
outputDict[(gamePath, item.Hash)] = preferredPath;
|
||||
}
|
||||
}
|
||||
@@ -2541,6 +2571,7 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
|
||||
_cachedData = null;
|
||||
LastAppliedDataBytes = -1;
|
||||
LastAppliedDataTris = -1;
|
||||
LastAppliedApproximateEffectiveTris = -1;
|
||||
LastAppliedApproximateVRAMBytes = -1;
|
||||
LastAppliedApproximateEffectiveVRAMBytes = -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user