Vixen
02b45cc4
csharp
public sealed class VfxGpuSort

The order a device-resident effect is drawn in, produced on the device.

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

Remarks

The last thing a GPU particle system still came home for. Reaping took the compaction off the bus and the indirect draw took the count; this takes the order, which an alpha-blended effect needs and which was the remaining reason a device-resident system had to read itself back every frame.

A bitonic sort, because a GPU comparison sort has to be a sorting network. Every invocation runs the same instructions, so a data-dependent partition — which is what a quicksort is — would serialise them. Bitonic is the network with no data dependence at all: a fixed sequence of compare-exchanges, every pass perfectly parallel, and no invocation ever needing to know what another decided. It costs log²(n) passes, which for the 4096 default is seventy-eight dispatches.

⚠ The buffers are the capacity rounded up to a power of two, and the tail is padded rather than the network truncated. A bitonic network is defined for a power-of-two length; a particle system has whatever count the last reap produced. Padding the slots above the count with the largest possible key sorts them past every real particle and leaves the network the same network every frame — truncating instead would mean a different pass list per frame, computed on the host, from a count the host does not have without a readback. Which is the readback this class exists to avoid.

⚠ What comes out is an index buffer, not reordered particles. Moving the particles would be a second compaction over every attribute; an order is one uint each, and the draw reads through it. It is also what keeps a particle's slot stable across the sort, which matters because the simulation addresses particles by slot and the sort runs between frames of it.

Fields and properties (5)

  • public int Capacity

    How many slots the network covers — the capacity rounded up to a power of two.

  • public VfxSortMode Mode

    Which key this sorts on.

  • public PipelineLayoutHandle SeedLayout

    The layout the seed kernel's pipeline is created against.

  • public PipelineLayoutHandle StepLayout

    The layout the step kernel's pipeline is created against.

  • public BufferHandle Order

    The sorted order — one particle slot per entry, furthest or oldest first.

Methods (6)

  • public VfxGpuSort(IGraphicsDevice device, VfxGpuSimulation simulation, VfxSortMode mode)

    Allocates the key and index buffers for one system.

  • public static int Passes(int capacity)

    How many passes the network runs for a capacity.

  • public void Record(ICommandList list, PipelineHandle seed, PipelineHandle step, int count, Vector3 camera = default(Vector3))

    Records the whole network: one seed dispatch and the compare-exchange passes.

  • public void Download(ICommandList list)

    Records the copy that brings the order back, for a caller checking it.

  • public void Read(Span<uint> order)

    Reads a completed Download.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (1)

  • VfxSortTestsVixen.Vfx.Gpu.Tests