Vixen
02b45cc4
csharp
public sealed class EffectDiskCache

The second tier: variants written down beside the project so the next run does not compile them again.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Read-through and write-back over an inner source. A miss asks whatever is behind it — the Raven compiler in the editor, a dev machine over TCP on a device — and writes down what comes back, which is the whole reason this tier answers with an EffectData rather than an Effect: a set of device handles cannot be written to a file.

Keyed by (key, target), with the source hash checked rather than named. Doc 06 asks for a cache keyed by the Raven source hash as well, and the difference matters in one direction only: a reader has to be able to find an entry, and a runtime asking for a variant does not know what the shader source hashed to — the compiler that knew is the thing this tier exists to avoid running. So the hash rides inside the record, where it can be compared once the entry is found, and Expect is what a host that does know sets. An entry that fails the comparison is treated as absent and overwritten, which is what makes editing a shader invalidate exactly the variants of it.

Every failure to read is a miss, never an exception. A cache is an optimisation, and a truncated file — a build killed halfway through a write, a full disk, a directory two machines share over a network — must cost a recompile and nothing else. A failure to write is swallowed for the same reason.

Fields and properties (7)

  • public const string Extension

    The extension every entry has.

  • public string Directory

    Where the entries are.

  • public string Target

    The backend the entries are for, as Raven's TargetBackends names it.

  • public IEffectSource? Source

    What answers a miss, or null for a cache that only reads.

  • public string Expect

    The source hash entries must carry, or empty to accept any.

  • public int Hits

    How many entries have been read from disk.

  • public int Writes

    How many entries have been written.

Methods (4)

  • public EffectDiskCache(string directory, string target, IEffectSource? source = null)

    A cache in a directory, created on first write.

  • public EffectData? TryGet(EffectKey key)

    The variant for a key, or null when this source does not have it.

  • public void Store(EffectData effect)

    Puts a variant in the cache without going through a miss.

  • public string PathOf(EffectKey key)

    Where one key's entry lives.

Used by (3)

  • EffectCacheTestsVixen.Shaders.Tests
  • EditorEffectsVixen.Editor.App
  • ShaderCompilerServiceTestsVixen.ShaderCompilerService.Tests