Vixen
02b45cc4
csharp
public sealed class MaterialRenderFeature

Which material each object uses, and which shader variant that resolves to.

Read the guide page for this →

Remarks

This is where the shader half of the engine meets the renderer half. Preparation turns a material's ParameterCollection — plus whatever the object's other sub-features contribute through IPermutationSubFeature — into an EffectKey, resolves it through the EffectSystem, and remembers the answer per object, so by the time anything is recorded "which shader" is an array lookup.

Resolution happens in preparation, not in the draw call, and not in extraction. Not in the draw call because resolving can compile, and compiling inside a command list is the stall that a frame budget cannot absorb. Not in extraction because the answer is only needed for objects that survived culling, which in a well-culled scene is far fewer — the same reason the phase exists at all.

Per distinct variant, not per object. The per-object step is building a small flag mask and one dictionary lookup; building the key and asking the effect system happens once per (material, flags) pair that has ever been seen. Ten thousand objects over twenty materials, half of them skinned, is forty resolutions.

The sort group is derived from the resolved effect. That is what turns the renderer's depth sort into a state-change-minimising one: objects that will bind the same pipeline get the same group, land adjacent in the stage's list, and reach the mesh feature as one run it can bind once for. A sort group taken from anything else — a material id, a mesh id — would group things that do not share a pipeline and separate things that do.

Fields and properties (21)

  • public override string Name

    The sub-feature's name, for logging and profiling.

  • public RenderDataKey<int> MaterialIndex

    Each object's index into Materials, or 0 for none.

  • public RenderDataKey<int> VariantIndex

    Each object's resolved variant — its effect and its sort group.

  • public IReadOnlyList<Material> Materials

    The materials this feature knows about.

  • public int VariantCount

    How many distinct variants preparation has resolved.

  • public Dictionary<string, IReadOnlyList<ParameterKey>> PermutationKeys

    Which permutation keys the shader's variants are selected by, per shader name.

  • public Dictionary<PermutationKey<bool>, PermutationKey<bool>> PermutationSources

    Which contributed flag supplies a shader permutation's value, by the shader's own key.

  • public EffectSystem? Effects

    Where effects are resolved from. Set before the first frame that prepares.

  • public IGraphicsDevice? Device

    The device a material's own descriptor set is written on, or null to leave that to a host.

  • public BindlessTable? Textures

    The global texture table a material's textures are registered in, or null.

  • public Dictionary<ParameterKey<uint>, ParameterKey<TextureViewHandle>> TextureIndices

    Which of a shader's uint parameters is filled from which of a material's textures.

  • public bool UseRecords

    Whether a material's values go into a record buffer rather than a descriptor set.

  • public const string RecordIndexName

    What a shader calls its [MaterialIndex], which is where a host pushes the record.

  • public ParameterCollection Permutations

    Permutation values that belong to the frame rather than to an object or a material.

  • public IReadOnlyDictionary<uint, MaterialRecords> Records

    The record buffers, one per effect, for a host that binds them.

  • public int IndexedTextureCount

    How many table slots this feature currently holds a reference to.

  • public DescriptorAllocator? Descriptors

    Where a material's descriptor set comes from.

  • public int BoundCount

    How many variants have a set this feature wrote, or a record it filled.

  • public int UploadedRecordCount

    How many record buffers went to the device this frame.

  • public int UploadCount

    How many times a material's uniform block has actually gone to the GPU.

  • public Effect? AnyResolved

    Any variant this feature has resolved, or null before the first one has.

Methods (11)

  • public bool EnableRecords(PermutationKey<bool> shaderKey)

    Turns the record path on where the device can take it, and leaves it off where it cannot.

  • protected internal override void Initialize(RenderSystem system)

    Registers this sub-feature's per-object data. Called once.

  • public int Add(Material material)

    Registers a material and returns the index objects refer to it by.

  • public void Assign(RenderSystem system, RenderObjectId id, Material material)

    Points an object at a material.

  • protected internal override void Prepare(RenderSystem system)

    Fills this sub-feature's data for the visible objects.

  • public (uint Group, int Index)? RecordOf(RenderSystem system, RenderObjectId id, RenderStage? stage = null)

    Which record of which buffer an object's material occupies.

  • public Effect? EffectOf(RenderSystem system, RenderObjectId id, RenderStage? stage = null)

    The effect an object resolved to for a stage, or null when it has none.

  • public DescriptorSetHandle DescriptorsOf(RenderSystem system, RenderObjectId id, RenderStage? stage = null)

    The descriptor set an object's material binds, invalid when it has none.

  • public ReadOnlySpan<byte> ConstantsOf(RenderSystem system, RenderObjectId id, RenderStage? stage = null)

    The bytes of an object's material block, as they were last filled.

  • public uint SortGroupOf(RenderSystem system, RenderObjectId id, RenderStage? stage = null)

    The sort group for an object: its variant's, so equal pipelines sort together.

  • public void Dispose()

    Releases the uniform blocks this feature created.

Used by (62, showing 40)

  • ArenaThirdPersonShooter
  • BindlessFrameTestsVixen.Rendering.Tests
  • ClusteredLightingTestsVixen.Rendering.Tests
  • ClusteredShadingDeviceTestsVixen.Graphics.Golden.Tests
  • CompositorAssetTestsVixen.Rendering.Tests
  • CompositorBuilderVixen.Rendering
  • CompositorImageTestsVixen.Graphics.Golden.Tests
  • DepthPrepassTestsVixen.Rendering.Tests
  • DescriptorBindingTestsVixen.Rendering.Tests
  • DrawCompactionTestsVixen.Rendering.Tests
  • ForwardFrameTestsVixen.Rendering.Tests
  • ForwardLightingRenderFeatureVixen.Rendering
  • ForwardLightingTestsVixen.Rendering.Tests
  • GpuDrivenCompositorTestsVixen.Rendering.Tests
  • GraphicsCompositorTestsVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • HarnessVixen.Rendering.Tests
  • IrradianceBounceDeviceTestsVixen.Graphics.Golden.Tests
  • IrradianceShadingDeviceTestsVixen.Graphics.Golden.Tests
  • LodTestsVixen.Rendering.Tests
  • MaterialBindingTestsVixen.Rendering.Tests