Files
tbd-station-14/Content.Client/Parallax/Data/GeneratedParallaxTextureSource.cs
Pieter-Jan Briers 1d5a06612a Optimize parallax VRAM usage (#37180)
* Disable parallax texture preloading

Many parallax layers are specific to a single map and will likely never be loaded for the duration of the game. Save VRAM by not loading them always.

Requires engine master

* Put generated parallax identifier in texture name

Makes it show up properly in debugging tools

* Don't load generated parallaxes multiple times

Many parallax prototypes re-use the same generated parallax configs. These generated parallaxes were being loaded multiple times at once, which was a massive waste of VRAM.

We now move these into a separate cache for deduplication. I had to write a lot of logic to handle loading cancellation and ref counting. Yay.

Also fixes some spaghetti with the previous parallax loading system: cancellation didn't work properly, give proper names to generated texture names, etc.

This saves like 100+ MB of VRAM.
2025-05-22 11:22:08 +10:00

42 lines
1.3 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Content.Client.Parallax.Managers;
using Robust.Client.Graphics;
using Robust.Shared.Utility;
namespace Content.Client.Parallax.Data;
[UsedImplicitly]
[DataDefinition]
public sealed partial class GeneratedParallaxTextureSource : IParallaxTextureSource
{
/// <summary>
/// Parallax config path (the TOML file).
/// In client resources.
/// </summary>
[DataField("configPath")]
public ResPath ParallaxConfigPath { get; private set; } = new("/parallax_config.toml");
/// <summary>
/// ID for debugging, caching, and so forth.
/// The empty string here is reserved for the original parallax.
/// It is required to provide a unique ID for any unique config contents.
/// </summary>
[DataField("id")]
public string Identifier { get; private set; } = "other";
async Task<Texture> IParallaxTextureSource.GenerateTexture(CancellationToken cancel)
{
var cache = IoCManager.Resolve<GeneratedParallaxCache>();
return await cache.Load(Identifier, ParallaxConfigPath, cancel);
}
void IParallaxTextureSource.Unload(IDependencyCollection dependencies)
{
var cache = dependencies.Resolve<GeneratedParallaxCache>();
cache.Unload(Identifier);
}
}