Vixen
caa30e12
csharp
public sealed class PingPongTextures

Two textures a simulation alternates between, imported into a graph and swapped per step.

Read the guide page for this →

Remarks

[35 § B5](../../docs/plan/35-water.md#b5-there-is-no-ping-pong-compute-target-helper). A height field advanced by a pass that reads frame N and writes frame N + 1 needs two targets and a rotation between them, and the render graph has to be told about the dependency or the barrier between the write and the next frame's read is one somebody has to remember. Compute exists and is spent; this is the small piece that did not.

Imported, not declared, and that is the whole reason this type exists rather than two CreateTexture calls. The graph's transients are recycled at the end of the frame precisely because their lifetime ends inside it — a ping-pong's does not, by definition. Declaring them would give the read target whatever memory the pool happened to hand back, which is the previous frame's contents about as often as it is not, and therefore looks almost right.

⚠ The first read is undefined until something has written it, and HasHistory is how a caller knows. The graph cannot catch this: an import counts as produced, so reading one no pass has written is legal and silent. A simulation step should either skip the read on its first frame or clear the pair — see Clear, which is the same decision made once rather than per consumer.

Not a subclass of anything and not held by the graph. A ping-pong outlives the graph it is imported into, and several graphs in one frame may import the same one; ownership belongs to whoever runs the simulation.

Fields and properties (6)

  • public const ResourceState RestingState

    What an idle ping-pong's textures are left in between frames.

  • public TextureDescription Description

    What each of the two textures is.

  • public long StepCount

    How many steps have been taken.

  • public bool HasHistory

    Whether anything has been written yet.

  • public TextureHandle ReadTexture

    The texture this step reads.

  • public TextureHandle WriteTexture

    The texture this step writes.

Methods (5)

  • public PingPongTextures(IGraphicsDevice device, in TextureDescription description)

    Creates a pair from a description.

  • public PingPongPair Import(RenderGraph graph)

    Brings both textures into a graph as this step's read and write.

  • public void Clear(RenderGraph graph, Color4 clear = default(Color4))

    Declares a pass that clears both textures, so the first read is defined.

  • public void Advance()

    Swaps the two, so this step's result becomes the next one's input.

  • public void Dispose()

    Destroys both textures and their views.

Used by (2)

  • PingPongTextureTestsVixen.Graphics.RenderGraph.Tests
  • WaterRippleSimulationVixen.Rendering.Water