Scene-wide renderer settings
Scene-wide renderer settings
The global pipeline switches — shadows, deferred shading, order-independent transparency, culling — live in the world's .world_settings file under [render], not in a runtime API. The renderer reads the file once a frame, so an edit reaches the next frame. Edit them there (the engine/development guides cover world settings):
[render]
shadows = true
deferred = true
oit = true
culling_mode = "gpu"
anisotropy = 16 # texture filtering quality: 1, 2, 4, 8 or 16
shadow_distance = 0 # how far from the camera the sun shadows; 0 out to the far plane
shadow_caster_min_radius_px = 0 # smallest on-screen caster that still casts
shadow_caster_max_distance = 0 # how far from the camera casters keep casting
contact_shadows = true # contact shadows at their defaults while nothing else states them
frame_rate_cap = 0 # most frames per second the engine runs at; 0 for no cap
frame_rate_mode = "adaptive" # adaptive: the highest even rate frames sustain; fixed: the cap's rate
max_frames_in_flight = 2 # frames of GPU work that may be outstanding
present_mode = "mailbox" # how a presented frame reaches the display
draw_every_frame = false # true draws every frame; false draws a frame only when the picture changed
edit_preview_rate = 15 # frames a second an editor nobody attends draws motion only its picture makes; 0 for the full rate
The values above are the high tier's on a desktop. anisotropy and
shadow_distance take their defaults from the device's quality tier wherever
the file leaves them out; a value the file states holds every device to it, the
phone included. The graphics-quality guide
(guides { path = "topics/graphics-quality" }) lists what each tier states.
Texture filtering is the one of these with a runtime API as well, because it is the setting worth scaling with a quality slider. anisotropy is how many samples a material texture is allowed to take along the axis of greatest compression — which is what keeps detail on a surface seen at a grazing angle. At 1 (plain trilinear) a road, a floor, or a long wall receding toward the horizon blurs to a flat average well before it gets there; at 16 the detail that is in the texture stays resolvable.
renderer.setAnisotropy(16) --> 16 the effective level, clamped to the device
renderer.anisotropy() --> 16 what material textures sample at now
renderer.maxAnisotropy() --> 16 what this device can do (16, or 1 without the feature)
setAnisotropy returns the level that was actually applied, so asking for more than the hardware offers reports the clamp rather than failing. It takes effect on the next frame for content already on screen — no reload, no re-upload. A level that is not a power of two in [1, 16] is an error rather than a silent round. The world setting seeds the level at boot and whenever the file changes; a runtime call overrides it until then.
Frame pacing is how far the CPU is allowed to run ahead of the GPU.
Submitting work returns before the GPU has done it, and everything a submission
holds — its staging allocations, its bind groups, its command buffer — stays
alive until it completes. A frame that asks for more work than the GPU finishes
in a frame's time therefore leaves that behind it, and unbounded that is memory
growth rather than a lower frame rate. max_frames_in_flight is the bound; the
runtime knob is the setting worth scaling with a latency slider.
renderer.framePacing() --> { framesInFlight = 2, maxFramesInFlight = 2, mechanism = "submission-wait", … }
renderer.setMaxFramesInFlight(1) --> 1 lowest latency, least CPU/GPU overlap
renderer.setPresentMode("mailbox")--> "mailbox"
mechanism names how the bound is enforced where the engine is running.
submission-wait waits for the frame that many frames back, so a paced frame
costs latency and still draws. submitted-work-done counts outstanding frames
off the queue's own completion signal and declines to start a frame while the
bound is met — the remedy on a platform that cannot block — counting those in
pacedFrames and leaving the last presented image up until the GPU catches up.
Either way framesInFlight is taken from the queue's completion signal and
stays at or under maxFramesInFlight, so it reads under the bound while the
device keeps up and at it while the device is behind — and the backlog a slow
frame can build is bounded by a number you set.
setPresentMode answers the canonical spelling of what you asked for; read
renderer.framePacing().presentMode for the mode the surface took. Each of the
two settings is seeded on its own, so editing one of them in the file leaves a
runtime override of the other in force.
present_mode decides how a finished frame reaches the display: fifo queues
every frame and shows it on a vertical blank (never tears, never drops one),
mailbox replaces the queued frame with the newest, immediate presents as
soon as the frame is ready and can tear, fifo_relaxed tears rather than stall
when a frame misses its blank, and auto_vsync / auto_no_vsync leave the
choice to the backend. On a desktop the default is mailbox: a frame that runs
past the vblank budget then shows its real rate, where fifo would lock it to a
divisor of the refresh rate (a 7ms frame on a 144Hz display presents at a hard
72), and the frame loop makes its frames at the display's refresh rate, since a
mailbox surface shows one frame per refresh however many it is handed. Under
immediate and auto_no_vsync the loop runs every frame it is ready for, which
makes them the modes for measuring how fast frames can run; a surface that does
not offer immediate presents fifo in its place, and every surface takes
auto_no_vsync. On Android the default is fifo, so every frame lands on a
vsync of the panel and the engine makes no frame the panel never shows, which a phone would
pay for in battery and heat. A surface that does not offer the mode presents
fifo, so read renderer.framePacing().presentMode for what took effect and
.presentModes for what the surface offers.
The frame-rate cap holds the whole frame loop (scripts, physics, audio, networking and drawing) to at most a rate content chooses. It is the setting a game picks for battery and heat on a phone, or for a steady pace on any display.
renderer.setFrameRateCap(30) --> 30
renderer.framePacing() --> { displayRefreshHz = 120, frameRateCap = 30, refreshesPerFrame = 4, targetFps = 30, deliveredFps = 30.0, … }
renderer.setFrameRateCap(nil) --> nil every frame the display shows
Frames come due on an even grid. Where the display's refresh rate is known (a
phone's panel, a desktop window's monitor, a browser's animation frames) the
grid is a whole number of refreshes, the fewest whose rate stays inside the
cap, so each frame stays on screen for the same number of vsyncs: 30 on a
120 Hz panel is every 4th refresh, 60 every 2nd, and a cap the refresh rate
does not divide evenly delivers the next rate below it (50 on 120 Hz delivers
40). targetFps is what the cap delivers on this display and deliveredFps
what the loop actually ran at. On Android the system compositor is told the
rate too, so a panel with more than one refresh rate can run at one the cap
divides. A headless engine presents to no display and holds the cap at its
own rate. frame_rate_cap under [render] in .world_settings seeds it, so a
world states its cap once and every session opens under it, and a runtime call
stays in force until that value changes. The perf reading an execute response carries judges
a capped frame against the cap's interval: under a cap of 30 a 33 ms frame is on
time, and one a refresh past its interval reads as slow.
The engine chooses the rate. On a display that shows each frame on a
vsync (presentMode fifo, fifo_relaxed or auto_vsync: a phone, a
browser tab, a desktop window set to fifo) the frame loop always runs at a
rate the display shows evenly, and every frame is due on its own vsync, so no
frame is made that the display has no refresh to show. In adaptive mode, the
default, that rate is the highest one the frames sustain, at most the cap (the
display's highest refresh rate without one): a frame that cannot hold 120 on a
120 Hz panel runs at an even 60 rather than alternating between one refresh
and two at 60 to 67, one that cannot hold 60 runs at 40, and the rate goes
back up once the frames hold the faster one again. A rate it tried and had to
leave is tried again later each time, so a scene whose GPU work hides behind
the slower rate does not swing between the two. fixed holds the cap's rate
(the display's highest without one) whatever the frames take.
renderer.setFrameRateMode("adaptive") --> "adaptive"
renderer.framePacing() --> { chosenFps = 60, frameRateReason = "frame_time", frameWorkMs = 14.2,
-- targetFps = 60, refreshesPerFrame = 2, displayVote = "ANativeWindow_setFrameRateWithChangeStrategy",
-- displayVoteFps = 60, … }
renderer.setFrameRateMode("fixed") --> "fixed" hold the cap's rate
frameRateReason says why the rate is what it is: cap (the highest rate the
cap delivers), display (the display's highest rate, with no cap),
frame_time (a lower even rate, because frames did not hold the faster one)
or uncapped (no target: a surface that shows a frame the moment it is ready,
immediate or auto_no_vsync, a display whose refresh rate is not read, or no
display, with no cap). frameWorkMs is the time recent drawn
frames took, which the rate is chosen from. On Android the display is asked
for the lowest of its modes the chosen rate divides into whole refreshes
(displayVote, displayVoteFps): frames at 60 ask for 60 Hz, frames at 40
for 120 Hz, shown every third refresh. The compositor decides whether the
panel changes mode. A lower mode is asked for once it has stood for a second,
a higher one at once. The engine chooses between the display's refresh and
its whole divisors down to 30 (120, 60, 40 and 30 on a 120 Hz panel); a cap
may ask for a lower rate. A rate stepped down to during a load comes back to
the full rate in one step once the frames are light again. lateFrames and missedPresents count the
frames that came late to the frame loop and those the display showed past
their interval after the frame before, and rateStepsDown / rateRaises the
changes of rate; each change is a [frame rate] line in the engine log naming
what decided it. A desktop window and a browser have no
call for it and hold their frames to the display by pacing alone
(displayVote = "none"). On a mailbox surface the loop is held to the cap,
or with none to one frame per refresh of the mode the display runs in now
(frameRateReason display), and a frame that takes longer than a refresh runs
as soon as it is ready rather than at an even rate below. Under immediate or
auto_no_vsync, and with no display at all, the cap alone holds the loop. frame_rate_mode under
[render] in .world_settings seeds the mode.
An idle screen is not redrawn. A renderer presenting to a display
draws while what is on screen changes and for a short settling run after the
last change (temporal antialiasing, an exposure and the shadow pages settle
over it), then stops drawing until the next change; the image it presented
last stays on screen. While the gameplay clock runs, or anything else keeps the
engine moving (a task owed the next frame, a key held, a tool call in flight),
its frames keep running at the display's rate without
drawing, so they cost the CPU work of a frame and none of its GPU work. An
engine with nothing moving at all (an idle editor, a paused game whose menu
stands still) is still: it runs a frame at once when something arrives (input,
a tool call, a loaded file, a message) and otherwise only when a wait a task
holds comes due, at most four times a second (renderer.framePacing().engineStill
and movingBecause; the core/engine guide's "How fast time passes" has the
whole rule). Every source that can change
the picture reports itself: a new UI layout, the camera, a renderer setting a
script states (setProjectionOffset, setShadowConfig, the render path), a
renderable added, moved or re-described, a component written, a script's
command, a texture or compute buffer written, a shader that reads the frame
clock while the clock runs, work still landing, the window.
The frame after a change draws it. A change of the UI alone (a hover, a
tooltip, a panel's text) leaves the scene's picture as it was: while a Scene
panel holds that picture, the frame draws the UI over it without drawing the
scene again (uiOnlyFrames counts those frames). A tool call draws nothing by
being in flight: what it changes is drawn as a change, and what it reads a
frame for (a capture, task.waitDrawnFrames) asks for that frame.
renderer.framePacing() --> { drawPolicy = "changes", producing = false, idleSkippedFrames = 5412,
-- pictureChanges = { ui = 31, camera = 4, world = 12, … },
-- lastPictureChange = "world",
-- lastPictureChangeDetail = "…Light on lamp-1 'Desk Lamp'",
-- redrawReasons = { { source = "clock", owner = "water.shader", recent = 587, … }, … } }
renderer.activity() --> { fps = 58.7, drawnFps = 58.7, cpuPercent = 37, still = false,
-- movingBecause = "picture", wokenBy = { … }, redrawReasons = { … }, busyJobs = { … } }
renderer.setDrawEveryFrame(true) -- every frame drawn, on every renderer
pictureChanges counts the frames on which each source changed the picture.
Every change names its owner, what within the source changed it: the screen a
UI pass laid out and why it ran (tree: hud), the component and entity a world
write changed, the program reading the clock, the command a script applied.
lastPictureChange / lastPictureChangeDetail name the latest, and
redrawReasons lists the owners by how often they changed the picture over
the last 5 to 10 seconds, so a picture that looks still and keeps being drawn
names what is moving, by name. renderer.activity() puts the top of that list
beside the engine's frame rate, the CPU it spends, what keeps it moving or,
while it is still, what ran the frames it ran (wokenBy: an arrival, or the
schedule its tasks set), and the job kinds its worker pools ran; the proxy's list_instances and
instance_health print the same reading for every engine.
renderer.setDrawEveryFrame(true) draws every frame instead, for content that
changes its picture in a way the engine does not see or that is measured frame
by frame; draw_every_frame under [render] seeds it. Left at false, a
headless engine draws while something reads its frames.
An editor nobody attends previews motion at a lower rate. A picture that
moves by itself (a material reading the frame clock, clouds, content moving in
editorUpdate) would keep an editor drawing every frame. Once three seconds
pass with no input, nothing reading frames and no change of the UI, window or
surface, an editor in edit mode whose picture alone moves draws it at
edit_preview_rate frames a second (15 unless the world states another; 0
draws it at the full rate). Each of those frames draws the picture where the
clock has reached, so it moves at its real speed in fewer steps. Input, a call
or a capture runs the next frame at once and the frames after it at the full
rate. An agent's call is not a person attending: it holds the full rate only
while it is in flight, so an agent calling every few seconds leaves the editor
at its preview rate between its calls. While the window holds no input focus
(another window has it, the browser page is blurred or hidden, the Android
activity lost its window focus) the preview runs at no more than 2 frames a
second, and the window taking the focus back or any input runs the next frame
at once. A window fully covered or minimized presents nothing and runs one
frame a second. Play mode and setDrawEveryFrame(true) are never held to it.
renderer.framePacing() reports previewFps (the rate in force),
windowFocused, previewGapMs while the rate holds the loop, and
previewWaits / previewSeconds.
The desktop window during an XR session is chosen, because the headset's
two eyes are drawn already and every other picture is a scene drawn again. An
engine started with --xr serves the headset first; the window shows one of
three things.
renderer.setSpectatorMode("mirror") --> "mirror" the left eye's picture, copied: no second scene render
renderer.setSpectatorMode("off") --> "off" nothing drawn to the window: no render, no UI layout, no present
renderer.setSpectatorMode("editor") --> "editor" the desktop editor beside the session, its own viewport camera
renderer.spectatorMode() --> "editor" what has been asked for
mirror is the mode an XR session starts in: the window is one textured
triangle sampling the target the headset's frame drew, cropped to the window's
aspect ratio. off is the mode for a machine with no use for the window.
editor is the one mode that pays for a second scene render, the editor's own
(its UI, panels, gizmos and viewport camera), because that is the window it
draws. --xr-spectator off|mirror|editor names the mode a boot starts in.
With no XR session serving frames the window is the ordinary desktop window
whatever the mode. /zero/runtime/observations/xr reports the mode in force as
spectator, and the window's cost shows in the frame profile: the
render.render_frame.spectator_mirror span exists in mirror, and
prepare_ui_rendering and the viewport's scene passes run in editor only.
The pipeline cache is the driver's compiled code for the pipelines this renderer builds, kept across runs. A pipeline is machine code the GPU driver compiles from the shader bound into it, and every launch pays that compile before the first frame drawing with that pipeline can appear. The engine hands each build the store and writes the whole store back: once the burst of builds a launch boots with settles, then at most once every five minutes while new pipelines keep being built, and again as the engine closes, so a short run keeps what it compiled too. A thread of its own reads the store and writes the file, so the frame that starts a write waits for neither. The next launch of an unchanged shader reads back what the last one compiled.
renderer.pipelineCache() --> { supported = true, pipelinesBuilt = 41, buildMs = 812.4, restoredBytes = 1_620_324, … }
pipelinesBuilt and buildMs are what this session built and what it cost —
the number the store lowers — and restoredBytes is what a previous run left
for this GPU. path names the file, which carries the GPU's identity, so a
machine with two adapters keeps two; the driver validates the blob it is handed
before trusting it, so one left by a driver that has since been updated is
rejected and that launch compiles from source. saves, savedBytes and
dirty describe writing it back — dirty stays true while the file is behind
what the driver holds, including after a write that failed, which lastError
then names — a failed write costs the stored compile and never the frame.
supported is false where the platform holds no store a program can carry — a
browser keeps its own and hands none out — and reason says which; the build
count and timing still read true there.
A pipeline a material, the sky, a depth view, a post-process pass or a compute
program a script registers needs after boot is built off the frame thread —
the shader module behind that compute program with it — on a pool of worker
threads on native (buildWorkers says how many), behind the browser's
asynchronous pipeline entry point on the web. So a burst of new materials or
post-process effects costs a frame nothing beyond drawing the placeholder until
each pipeline lands, and a burst of effects costs it nothing beyond each effect
starting on the frame its pipeline does; a dispatch issued before its program
arrives is held over and runs then, and compute.programState reads pending
until it does.
offFrameBuilt and offFrameBuildMs are the pipelines and the milliseconds
that never held a frame. buildsSubmitted, buildsFinished, buildsFailed
and buildsInstalled count every module and pipeline request made,
completed, refused and taken back by a frame, so a queue that is draining
reads differently from one that is stuck. buildsAbandoned counts the
requests a renderer still held when a device rebuild let it go, which no frame
takes back. buildsSuperseded counts the requests a worker set down unbuilt
because the shader they were cut from was saved again before a worker reached
them, so a burst of saves of a shader, or of a module it includes, compiles
what the last save asked for plus what the workers had already begun.
buildsPending is what the renderer drawing now has yet to
take back, a finished result included until a frame installs it. Every
request made is installed, abandoned or pending, so a rebuilt device leaves
nothing behind in buildsPending, and it settles to zero with
renderer.pendingWork().pipelineBuilds. A material whose pipelines are still
building stays as it was drawing until the last of them lands, and a pipeline
the driver refuses is reported once against the shader, the way a compile
error is. A save of a shader, or of a module that shaders include, rebuilds
every pipeline of the shaders it reaches the same way: their materials keep
drawing with the pipelines of the text they were drawn with before the save,
each one until the recompiled pipeline under its key lands and takes its
place, so the picture changes once, from the old shading to the new.
previousPipelines counts the previous text's pipelines still held, and reads
zero once every rebuild has landed. A recompiled module the device refuses
draws the magenta error shader, and a save that changes the texture slots, the
properties or the storage buffers a shader declares regroups its materials,
which then draw from the frame the recompiled pipelines land.
What the renderer still owes the picture is its own reading. A frame draws what the renderer holds at the moment it runs, and several of the things it holds arrive over more than one frame: a pipeline is bound the frame its build is taken in, a texture is uploaded under a per-frame time budget, a released texture's GPU object is freed on the frame the release queue is drained, a streamable texture climbs toward the level its screen size asks for one level at a time.
The texture upload budget is 3 ms of uploading per frame, read after each
upload: a frame always uploads the texture at the front of the queue, and stops
taking more once the uploads it made have spent the budget. So a screen that
shows several large images for the first time, or a batch of
renderer.texture.create calls in one step, lands its textures over the next
few frames rather than in one long frame, in the order they were made. Until its
texture lands, a UI image naming it draws its loading state and a material slot
naming it samples the slot's fallback; both pick the texture up on the frame it
arrives.
The queue holds one upload per texture: a renderer.texture.update of a
texture still waiting replaces the pixels it will land with, and keeps its
place, and a renderer.destroy of one takes its upload out of the queue.
textureUploads counts the textures still queued.
renderer.pendingWork() --> { settled = true, outstanding = 0, pipelineBuilds = 0, textureUploads = 0, textureReleases = 0, textureResidency = 0, epoch = 41, frame = 9120 }
settled is true when nothing is outstanding, and means the frames after this
one draw the same picture unless something changes the scene — the word a
measurement of a rendered frame holds for before it takes one. epoch counts
the times the renderer has gone from owing nothing to owing something, which is
what a PAIR of readings needs: a run of work that begins and ends between two
samples leaves both of them reading settled and leaves the epoch higher, so
settled at both ends under one epoch says nothing arrived across the whole
span. Test.settleReading and Test.readWhileRendererIsStill are built on
exactly that pair of conditions, so a suite measuring a picture reads one the
renderer has finished putting up.
Per-camera overrides live on the Camera component — debugChannel, postProcessing (whether that camera runs the post-process chain, and the render-feature passes that declared themselves part of the film with it), and the renderLayers spec (a space-separated list of layer names, e.g. "all !ui", where ui / sky / debug / EditorUI are built-in layers) decide what that camera draws (the render-textures guide uses this for secondary views).
That spec is one half of the render-layer system; the other half is which
entities are on each layer, written with renderLayer.set — { tree = true }
puts an entity and every descendant on a layer in one call, and the reply counts
what it moved. The render-layers guide covers both sides.