Skip to main content

Module backend

Module backend 

Source
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§

ChunkMesh
One streamed chunk’s geometry plus placement, supplied to RenderBackend::add_chunk_mesh. frame reclaims retired deferred frees before the chunk is placed in the streaming headroom.
DeviceCapabilities
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.
DrawGeometryUpdate
One draw slot’s fresh geometry, supplied to RenderBackend::rebuild_static_geometry when 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. indices are mesh-relative (0-based); the backend rebases them onto whatever new vertex region the draw lands in.
FrameParams
Per-frame inputs for RenderBackend::draw_frame. world_hidden is 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.
GpuClassInput
The cheap signals every backend can gather about its GPU, mapped to a coarse GpuTier by 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 not Copy); a backend exposes the name separately when a UI needs it.
QualitySettings
The resolved per-feature quality settings for RenderBackend::apply_quality_settings. GraphicsSystem derives these from its stored PostProcessConfig (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. Each Option mirrors the init-time gate: None means the feature is off and its passes / resources should be torn down; Some means 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).
SkinnedDrawGeometryUpdate
One skinned draw slot’s fresh geometry, supplied to RenderBackend::rebuild_skinned_geometry when 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. indices are mesh-relative (0-based); the backend rebases them onto the new vertex region.
SkinnedSlotLayout
The post-rebuild layout for one skinned slot, returned by RenderBackend::rebuild_skinned_geometry so the asset hot-reload helper can refresh its SkinnedMeshSourceEntrys’ vertex_base / vertex_count / index_count to 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’s vertex_base. Constructed only by the cn debug binary’s skinned-rebuild reload pass; reads as dead under cargo 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 via classify_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§

RenderBackend
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 through classify_tier’s integrated branch and the two backends disagree on the same GPU. M<n> maps to n + 6, matching Metal’s MTLGPUFamily::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 Unknown so the resolver uses the conservative baseline.