Vixen
02b45cc4
csharp
public sealed class MaterialRecords

Every material of one effect, as records of one buffer.

Read the guide page for this →

Remarks

What replaces a descriptor set per material. A draw that binds a set per material cannot be merged with a draw that binds a different one, which is the sentence everything in docs/plan/23-bindless-materials.md follows from. A buffer of records is bound once and subscripted by a number the draw carries, so two materials' draws differ in their data and in nothing a command list can see.

Per effect, and that is a correction to the plan. The sketch said one buffer per variant, which turns out to be one buffer per material: a variant is a (material, flags, shader) triple, so there is exactly one material in each. What several materials genuinely share is their effect — same shader, same composition, same permutation — and that is what a record buffer is keyed by. The layout is the effect's, so every record in one buffer has the same shape by construction rather than by a check.

Written once, not once a frame. A record is rewritten when its material's values change and the buffer goes to the device when any of them did. A settled scene uploads nothing, which is the same economy EffectConstants has and the same reason: the bytes are the expensive part, not the bookkeeping.

An index, once given out, does not move. Same argument as BindlessTable's: it is written into a per-object block the host has already filled, and there is nothing to go back and renumber. So the buffer grows and a released record leaves a hole, which is what Count counts and what a caller trades against.

Fields and properties (5)

  • public int Stride

    How many bytes one record occupies.

  • public int Count

    How many records have been handed out.

  • public BufferHandle Buffer

    The buffer, invalid until something has been written.

  • public int UploadCount

    How many times the records have actually gone to the GPU.

  • public ReadOnlySpan<byte> Bytes

    The records as they were last filled.

Methods (5)

  • public MaterialRecords(IGraphicsDevice device, int stride, string name = "MaterialRecords")

    Creates a record buffer for one effect.

  • public int IndexOf(int variant)

    The record one variant occupies, giving it one if it has none.

  • public bool Write(int index, ReadOnlySpan<byte> bytes)

    Fills one record, and answers whether the bytes were different from last time.

  • public BufferHandle Upload()

    Puts the records on the device, if any of them changed.

  • public void Dispose()

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

Used by (2)

  • MaterialRecordBufferTestsVixen.Rendering.Tests
  • MaterialRenderFeatureVixen.Rendering