Expand description
RenderBackend trait: the union of methods every graphics backend implements, dispatched dynamically by GraphicsSystem so the per-frame step + setup logic lives in one cfg-free copy instead of three.
Each concrete backend (MtlContext / DxContext / VkContext) supplies a thin forwarder impl that delegates to the existing inherent methods (see metal/backend.rs, directx/backend.rs, vulkan/backend.rs).
Two cross-backend signature variances are handled here:
upload_skinned: Metal uses three shader payloads (vert + frag + shadow); DX/VK use one (frag). The trait method takes all three; DX/VK ignore the unused bytes.setup_chunk_streaming: Metal binds chunk textures per draw and ignores the (texture_slot, normal_map_slot) args; DX/VK bake them into a shared descriptor at setup time.
render_stats has a default no-op impl so a backend with no draw-call /
object counters need not override it; all three shipping backends do.
Structs§
- Chunk
Mesh - One streamed chunk’s geometry plus placement, supplied to
RenderBackend::add_chunk_mesh.framereclaims retired deferred frees before the chunk is placed in the streaming headroom. - Device
Capabilities - GPU/device capability flags, queried from the backend once it is built. Surfaced so the settings menu can gray out (and make inert) toggles the device cannot honor – e.g. ray-traced reflections on a GPU without hardware ray tracing. Mirrors an RHI-style capability set: a handful of bools held in memory and re-queried each launch, never persisted, so it is always correct for the current device + driver.
- Draw
Geometry Update - One draw slot’s fresh geometry, supplied to
RenderBackend::rebuild_static_geometrywhen an asset hot-reload changed its vertex / index count and the slot can no longer hold the new data in place. The backend rebuilds the entire shared vertex / index buffer; draws not named here keep their current geometry, copied byte-for- byte from the live buffers.indicesare mesh-relative (0-based); the backend rebases them onto whatever new vertex region the draw lands in. - Frame
Params - Per-frame inputs for
RenderBackend::draw_frame.world_hiddenis set when an opaque menu backdrop covers the scene: the backend skips every world pass and presents only the overlay (text_calls) over a cleared target. - GpuClass
Input - The cheap signals every backend can gather about its GPU, mapped to a coarse
GpuTierby one shared rule so the three backends classify consistently and the mapping is unit-testable without a GPU. The backends differ in what they can report (Apple exposes a GPU family; DirectX / Vulkan expose a VRAM figure and a discrete / integrated flag), so this carries the union and the rule uses whichever signals are present. - GpuProfile
- A coarse, Copy snapshot of the active GPU’s class, queried from the backend
once it is built (mirrors
DeviceCapabilities). Read at init to choose sensible default graphics quality; never persisted, re-queried each launch so it is always correct for the current device + driver. The GPU name is deliberately omitted (it is notCopy); a backend exposes the name separately when a UI needs it. - Quality
Settings - The resolved per-feature quality settings for
RenderBackend::apply_quality_settings.GraphicsSystemderives these from its storedPostProcessConfig(with the user’s persisted toggle overrides applied) whenever a Quality-group toggle changes, so the backend receives ready-to-use settings rather than re-deriving from the asset. EachOptionmirrors the init-time gate:Nonemeans the feature is off and its passes / resources should be torn down;Somemeans it is on and its resources should exist. A backend without a live-rebuild path ignores this (the choice still persists and applies at the next launch). - Skinned
Draw Geometry Update - One skinned draw slot’s fresh geometry, supplied to
RenderBackend::rebuild_skinned_geometrywhen an asset hot-reload changed its vertex / index count and the slot can no longer hold the new data in its existing region of the shared skinned vertex / index buffers. The backend rebuilds both shared buffers; slots not named here keep their current geometry, copied byte-for-byte from the live buffers and re-based onto whatever new vertex region they land in.indicesare mesh-relative (0-based); the backend rebases them onto the new vertex region. - Skinned
Slot Layout - The post-rebuild layout for one skinned slot, returned by
RenderBackend::rebuild_skinned_geometryso the asset hot-reload helper can refresh itsSkinnedMeshSourceEntrys’vertex_base/vertex_count/index_countto point at the new regions. Returned for every slot (both the ones whose geometry was replaced and the ones whose geometry was carried over) because the rebuild may have shifted every slot’svertex_base. Constructed only by thecn debugbinary’s skinned-rebuild reload pass; reads as dead undercargo check --lib.
Enums§
- GpuTier
- Coarse performance class for default-quality selection, ordered low -> high so
callers can compare with
>=. Each backend maps its native signals (memory budget, discrete / integrated, Apple GPU family) onto this viaclassify_tier. - GpuVendor
- Coarse GPU vendor class, derived per backend from the adapter’s reported vendor id (DirectX / Vulkan) or unified-memory / Apple-family signals (Metal). Used only to pick default quality and to gate vendor-specific options (e.g. which upscalers to offer); never persisted.
Traits§
- Render
Backend - The set of operations GraphicsSystem performs on a graphics backend. Implementations are thin forwarders to the inherent methods on MtlContext / DxContext / VkContext.
Functions§
- apple_
family_ from_ device_ name - The Apple GPU family generation rank a device name implies, or 0 when the name
is not an Apple silicon GPU. Metal reads the rank straight off the device
(
MTLDevice::supportsFamily); Vulkan has no equivalent query, so a MoltenVK build recovers it from the reported device name (“Apple M2 Max”). Without it Apple silicon falls throughclassify_tier’s integrated branch and the two backends disagree on the same GPU.M<n>maps ton + 6, matching Metal’sMTLGPUFamily::Apple7= M1. - classify_
tier - Map the gathered GPU signals to a coarse performance tier. Apple silicon is
classified by GPU family generation (family alone cannot separate base from
Pro / Max / Ultra within a generation – a working-set refinement can split
them later); a non-Apple integrated / low-power GPU is the lowest tier; a
discrete GPU is bucketed by dedicated VRAM. An unreporting device (no memory,
not discrete) stays
Unknownso the resolver uses the conservative baseline.