Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ platform setup (Vulkan SDK, GLFW, etc.).
- Play runs threaded (a game thread for the ticks) at a fixed 30 Hz, with the
main thread's frames capped at the monitor's refresh rate (no cap headless).
`--exec direct|inline|threaded`, `--sim-hz N`, `--max-fps N` (0: no cap),
`--vsync on|off` (on by default) and `--interpolation on|off` (on by
default) override, as do `[Engine] Exec`, `SimHz`, `MaxFps`, `VSync` and
`Interpolation` in
`--vsync on|off` (on by default), `--interpolation on|off` (on by
default) and `--frustum-culling on|off` (on by default) override, as do
`[Engine] Exec`, `SimHz`, `MaxFps`, `VSync`, `Interpolation` and
`FrustumCulling` in
`Config/EngineConf.ini`. A test that depends on a mode or a rate sets it. The
startup log line `Run settings: ...` says each value and where it came from.
The editor's GPU Options window (menu Windows; drawn in `--play` too) changes
the rate, the cap, VSync and interpolation at run time.
the rate, the cap, VSync, interpolation and frustum culling at run time.
Detail: [`Docs/time-and-ticks.md`](Docs/time-and-ticks.md) section 2.
- See a run without a window: `--dump-state <file.json>` writes the simulation
state as JSON at chosen ticks (works with `--null-render`), and `--offscreen
Expand Down
7 changes: 6 additions & 1 deletion Config/EngineConf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ DisplayVersionInfoInTitle=true
; Interpolation
; on (default): the renderer draws between the latest two ticks; off: the
; latest tick only. Presentation only. Flag: --interpolation
; FrustumCulling
; on (default): the renderer skips the meshes outside the camera's view;
; off: it draws every mesh. Presentation only. Flag: --frustum-culling
; Every key here is checked in every run, also when a flag overrides it. The editor's
; GPU Options window changes SimHz, MaxFps, VSync and Interpolation at run time.
; GPU Options window changes SimHz, MaxFps, VSync, Interpolation and FrustumCulling at
; run time.
;Exec=threaded
;SimHz=30
;MaxFps=
;VSync=on
;Interpolation=on
;FrustumCulling=on

; resizes window to a small window
[Windowed]
Expand Down
1 change: 1 addition & 0 deletions Docs/agent-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ flag or key. The startup line `Run settings: ...` names each value and its sourc
| Frame cap | `--max-fps N` (0: none, max 1000) | `MaxFps` | monitor refresh rate, else 60 (`FallbackMaxFps`); none with `--null-render` | GPU Options |
| VSync | `--vsync on\|off` | `VSync` | on | GPU Options (swap chain rebuilt) |
| Interpolation | `--interpolation on\|off` | `Interpolation` | on | GPU Options |
| Frustum culling | `--frustum-culling on\|off` | `FrustumCulling` | on | GPU Options |
| Thread jitter (tests) | `--thread-jitter S:U` (threaded only; an error otherwise) | none | off | no |

Other flags: `--null-render` (no window or GPU, virtual clock), `--offscreen` (render
Expand Down
4 changes: 2 additions & 2 deletions Docs/architecture-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ must be started from there. With Ninja the program is
| Dump ticks | `build\Sandbox\bin\Sandbox.exe --null-render --unattended --seed 1 --frames 120 --replay-input Sandbox/Tests/Input/look_camera_cuts.input.jsonl --dump-ticks ticks.txt` (a recording replays only at its rate: `look_camera_cuts_60hz.input.jsonl` needs `--sim-hz 60`) |
| Windowed demo (look camera; threaded, 30 Hz, frames capped at the monitor's refresh rate) | `build\Sandbox\bin\Sandbox.exe --play` |
| The same, unattended (the exit line has the average frame time) | `build\Sandbox\bin\Sandbox.exe --play --unattended --frames 300` (it runs until tick 300 is shown, so for about 10 s at 30 Hz) |
| Other settings | `--exec direct` or `inline`, `--sim-hz N` (1 to 1000), `--max-fps N` (0: no cap), `--vsync on\|off`, `--interpolation on\|off`; or the same keys in `[Engine]` of `Config/EngineConf.ini` (`Exec`, `SimHz`, `MaxFps`, `VSync`, `Interpolation`) |
| Change them while the game runs | The editor UI is drawn in `--play` too, and the Sandbox opens the "GPU Options" window at start in `--play` (menu Windows closes and opens it): VSync (On or Off, with the present mode in use), frame cap, simulation rate, render interpolation, with what the frame limiter does and the measured rates. Press M first if the cursor is hidden |
| Other settings | `--exec direct` or `inline`, `--sim-hz N` (1 to 1000), `--max-fps N` (0: no cap), `--vsync on\|off`, `--interpolation on\|off`, `--frustum-culling on\|off`; or the same keys in `[Engine]` of `Config/EngineConf.ini` (`Exec`, `SimHz`, `MaxFps`, `VSync`, `Interpolation`, `FrustumCulling`) |
| Change them while the game runs | The editor UI is drawn in `--play` too, and the Sandbox opens the "GPU Options" window at start in `--play` (menu Windows closes and opens it): VSync (On or Off, with the present mode in use), frame cap, simulation rate, render interpolation, frustum culling (with the meshes drawn and culled), with what the frame limiter does and the measured rates. Press M first if the cursor is hidden |

## 11. Where to read more

Expand Down
18 changes: 18 additions & 0 deletions Docs/threading-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ lighting test: 42 224 bytes). The frame side copies nothing: it indexes the
new tick of each packet it takes. The render snapshot does a blend and a
matrix per moving entity, and only a compare per entity that did not move.

**Frustum culling** is on the frame side only, in the renderer, after the
snapshot: the packet and the snapshot still hold every mesh. The offscreen
(G-buffer) pass tests each mesh's world box (the model's local bounds, placed
by the item's drawn matrix) against the planes of this frame's camera
(`Frustum`, `MeshCuller` in `FlingEngine/Graphics/inc/`), and skips the draw
and the uniform buffer write of a mesh that is outside. A culled mesh
keeps its proxy slot and GPU resources, so it costs nothing to bring back.
Each mesh is recorded as an indirect draw; the CPU writes its instance count
(1 in view, 0 culled) every frame, so a moving camera never makes the command
buffers record again (they record only when the draw list changes).
The camera is only final in `VulkanApp::Update`, after the frame systems ran,
so the snapshot's blend and matrix work is not culled; a test against the last
frame's camera would not be conservative. Lights are not culled (the deferred
lighting pass is full screen), and there is no shadow pass. `--frustum-culling
on|off`, `[Engine] FrustumCulling` and the GPU Options window, which also shows
the meshes drawn and culled in the last frame. Tests: `GraphicsTests
"[culling]"` (`FrustumCullingTests.cpp`).

**Tests.** `EngineTests "[interp]"` (`EcsBlendTests.cpp`: each packet
carries the latest two ticks of the marked types only; new, destroyed, changed
and reused entities; after skipped packets `BlendFrom` is still the tick before
Expand Down
1 change: 1 addition & 0 deletions Docs/time-and-ticks.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ outside `--exec threaded` is an error.
| Frame cap | `--max-fps N` (0: none, up to 1000) | `MaxFps` | the refresh rate of the window's monitor, else 60; none with `--null-render` | GPU Options, from the next frame |
| VSync | `--vsync on\|off` | `VSync` | on | GPU Options, the swap chain is made again |
| Interpolation | `--interpolation on\|off` | `Interpolation` | on | GPU Options, from the next frame |
| Frustum culling | `--frustum-culling on\|off` | `FrustumCulling` | on | GPU Options, from the next frame |
| Thread jitter (tests) | `--thread-jitter S:U` (`--exec threaded` only) | none | off | no |

`RunSettings` does not change after startup. The live values are in
Expand Down
1 change: 1 addition & 0 deletions FlingEngine/Application/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ namespace Fling
// During Inline or Threaded play the renderer reads the mirror. A VSync change makes
// the swap chain again after this frame's present.
VulkanApp::Get().SetVSync(m_Controls->VSync());
VulkanApp::Get().SetFrustumCulling(m_Controls->FrustumCulling());
VulkanApp::Get().Update(t_DeltaTime, m_World->GetPresentedStorage());

// Offscreen there is no window: no focus, no monitor, and no frame cap (headless)
Expand Down
6 changes: 6 additions & 0 deletions FlingEngine/Core/inc/LaunchOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace Fling
* --interpolation on|off
* Draw between the latest two published ticks (on) or the latest tick
* only. Overrides [Engine] Interpolation
* --frustum-culling on|off
* Skip the meshes outside the camera's view (on) or draw every mesh
* (off). Overrides [Engine] FrustumCulling
* --thread-jitter S:U --exec threaded only: sleep a random 0..U microseconds (seed S) before each wake
* and after each publish on the game thread, and before each frame
*/
Expand Down Expand Up @@ -154,6 +157,9 @@ namespace Fling
/** --interpolation on or off. Empty: not on the command line. */
std::optional<bool> Interpolation;

/** --frustum-culling on or off. Empty: not on the command line. */
std::optional<bool> FrustumCulling;

/** --thread-jitter: the seed and the longest sleep in microseconds. 0 microseconds means off. */
uint32 JitterSeed = 0;
uint32 JitterMaxMicroseconds = 0;
Expand Down
17 changes: 14 additions & 3 deletions FlingEngine/Core/inc/RunSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ namespace Fling
static constexpr const char* MaxFpsKey = "MaxFps";
static constexpr const char* VSyncKey = "VSync";
static constexpr const char* InterpolationKey = "Interpolation";
static constexpr const char* FrustumCullingKey = "FrustumCulling";

String Exec;
String SimHz;
String MaxFps;
String VSync;
String Interpolation;
String FrustumCulling;

/**
* Each key's text from t_GetKey, which returns the text of one [Engine] key, or empty
Expand All @@ -62,7 +64,8 @@ namespace Fling
.SimHz = t_GetKey(SimHzKey),
.MaxFps = t_GetKey(MaxFpsKey),
.VSync = t_GetKey(VSyncKey),
.Interpolation = t_GetKey(InterpolationKey)};
.Interpolation = t_GetKey(InterpolationKey),
.FrustumCulling = t_GetKey(FrustumCullingKey)};
}
};

Expand All @@ -79,9 +82,10 @@ namespace Fling
* | MaxFps | [Engine] MaxFps | --max-fps | monitor refresh, else 60; none headless. 0: no cap |
* | VSync | [Engine] VSync | --vsync | on |
* | Interpolation | [Engine] Interpolation | --interpolation | on |
* | FrustumCulling | [Engine] FrustumCulling | --frustum-culling | on |
*
* The values here do not change after startup. The GPU Options window changes VSync, the
* frame cap, the simulation rate and interpolation while the game runs; RunControls holds
* frame cap, the simulation rate, interpolation and frustum culling while the game runs; RunControls holds
* those live values, starting from these. Edit mode in the editor always runs on one
* thread, whatever Exec says.
*/
Expand Down Expand Up @@ -117,6 +121,13 @@ namespace Fling
bool Interpolation = true;
SettingSource InterpolationSource = SettingSource::Default;

/**
* The renderer does not draw a mesh whose bounds are outside the camera's view this
* frame (MeshCuller in Graphics). Presentation only: the simulation never reads it.
*/
bool FrustumCulling = true;
SettingSource FrustumCullingSource = SettingSource::Default;

/** The refresh rate of the window's monitor at startup (ResolveFrameCap). Empty when not known, and headless.
*/
std::optional<uint32> MonitorHz;
Expand Down Expand Up @@ -164,7 +175,7 @@ namespace Fling
/**
* One line for the startup log with each value and where it came from, for example
* "tick rate 30 Hz (default), exec threaded (default), frame cap 144 fps (the monitor's refresh rate),
* vsync on (default), interpolation on (default)".
* vsync on (default), interpolation on (default), frustum culling on (default)".
*/
CORE_API String Describe() const;
};
Expand Down
4 changes: 3 additions & 1 deletion FlingEngine/Core/src/LaunchOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Fling
constexpr StringView MaxFpsFlag = "max-fps";
constexpr StringView VSyncFlag = "vsync";
constexpr StringView InterpolationFlag = "interpolation";
constexpr StringView FrustumCullingFlag = "frustum-culling";
constexpr StringView ThreadJitterFlag = "thread-jitter";
/**
* Flags that are refused with the name of the flag that does their job, so a script
Expand Down Expand Up @@ -392,7 +393,8 @@ namespace Fling
if (!ReadOptionalUint32(t_CmdLine, SimHzFlag, t_Out.SimHz, t_OutError) ||
!ReadOptionalUint32(t_CmdLine, MaxFpsFlag, t_Out.MaxFps, t_OutError) ||
!ReadOptionalOnOff(t_CmdLine, VSyncFlag, t_Out.VSync, t_OutError) ||
!ReadOptionalOnOff(t_CmdLine, InterpolationFlag, t_Out.Interpolation, t_OutError))
!ReadOptionalOnOff(t_CmdLine, InterpolationFlag, t_Out.Interpolation, t_OutError) ||
!ReadOptionalOnOff(t_CmdLine, FrustumCullingFlag, t_Out.FrustumCulling, t_OutError))
{
return false;
}
Expand Down
13 changes: 12 additions & 1 deletion FlingEngine/Core/src/RunSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ namespace Fling
Keys::InterpolationKey,
t_Out.Interpolation,
t_Out.InterpolationSource,
t_OutError) ||
!PickOnOff(t_Options.FrustumCulling,
t_Config.FrustumCulling,
Keys::FrustumCullingKey,
t_Out.FrustumCulling,
t_Out.FrustumCullingSource,
t_OutError))
{
return false;
Expand All @@ -206,6 +212,10 @@ namespace Fling
t_Out.Ignored.push_back(String("--vsync does nothing with ") + t_Out.HeadlessFlag +
": there is no swap chain");
}
if (t_Options.NullRender && t_Options.FrustumCulling)
{
t_Out.Ignored.push_back("--frustum-culling does nothing with --null-render: nothing is drawn");
}
return true;
}

Expand Down Expand Up @@ -253,7 +263,8 @@ namespace Fling
return "tick rate " + std::to_string(SimHz) + " Hz (" + SettingSourceName(SimHzSource) + "), exec " +
ExecModeName(Exec) + " (" + SettingSourceName(ExecSource) + "), frame cap " + Cap + " (" + CapSource +
"), vsync " + OnOffName(VSync) + " (" + SettingSourceName(VSyncSource) + "), interpolation " +
OnOffName(Interpolation) + " (" + SettingSourceName(InterpolationSource) + ")";
OnOffName(Interpolation) + " (" + SettingSourceName(InterpolationSource) + "), frustum culling " +
OnOffName(FrustumCulling) + " (" + SettingSourceName(FrustumCullingSource) + ")";
}

uint32 LimiterFps(const uint32 t_MaxFps,
Expand Down
3 changes: 2 additions & 1 deletion FlingEngine/Editor/inc/BaseEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ namespace Fling

/**
* The GPU Options window: the device, VSync (with the present mode in use), the frame
* cap, the simulation rate and render interpolation, with what the frame limiter does
* cap, the simulation rate, render interpolation and frustum culling (with the meshes
* drawn and culled), with what the frame limiter does
* and the measured rates, and a button that saves the next frame as a PNG
* (Screenshot::Request). Each control
* calls RunControls, which checks the request; a number box applies when its edit is
Expand Down
9 changes: 9 additions & 0 deletions FlingEngine/Editor/src/BaseEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ namespace Fling
Controls.SetInterpolation(bInterpolation);
}

bool bFrustumCulling = Controls.FrustumCulling();
if (ImGui::Checkbox("Frustum culling", &bFrustumCulling))
{
m_ControlsError.clear();
Controls.SetFrustumCulling(bFrustumCulling);
}
const CullStats Culled = VulkanApp::Get().GetCullStats();
ImGui::TextDisabled("Last frame: %u meshes drawn, %u outside the view", Culled.Drawn, Culled.Culled);

if (!m_ControlsError.empty())
{
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "%s", m_ControlsError.c_str());
Expand Down
10 changes: 8 additions & 2 deletions FlingEngine/Engine/inc/RunControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace Fling

/**
* The live values of the run settings that change while the game runs: the ones a person
* sets in the editor's GPU Options window (VSync, the frame cap, the simulation rate and
* render interpolation), and the ones the window system reports (the monitor's refresh
* sets in the editor's GPU Options window (VSync, the frame cap, the simulation rate,
* render interpolation and frustum culling), and the ones the window system reports (the monitor's refresh
* rate, and whether the window is in the background). They start from the RunSettings
* that the engine resolved at startup, which do not change. Each setter checks its
* request, so the window only draws and calls them.
Expand All @@ -44,6 +44,7 @@ namespace Fling
* on the resize path, after the next present.
* - MaxFps: Engine::Present puts LimiterFps into the FrameLimiter, on the next frame.
* - Interpolation: World::SetInterpolation, which holds it, on the next frame.
* - FrustumCulling: Engine::Present gives it to VulkanApp::SetFrustumCulling, on the next frame.
* - SimHz: World::RequestSimHz, a SetRate clock command applied between two ticks, at the
* next wake. The world holds the rate.
*
Expand Down Expand Up @@ -79,6 +80,10 @@ namespace Fling
bool Interpolation() const;
void SetInterpolation(bool t_On);

/** Frustum culling in the renderer (RunSettings::FrustumCulling). */
bool FrustumCulling() const { return m_FrustumCulling; }
void SetFrustumCulling(bool t_On);

/**
* Ask for a new simulation rate (World::RequestSimHz, applied at the next tick
* boundary). False, with the reason, for a rate that is not from 1 to 1000, or while
Expand Down Expand Up @@ -134,6 +139,7 @@ namespace Fling
uint32 m_InputTickRate = 0;

bool m_VSync = true;
bool m_FrustumCulling = true;
uint32 m_MaxFps = 0;

/** True while the cap is the monitor's refresh rate and no one has set it. */
Expand Down
10 changes: 10 additions & 0 deletions FlingEngine/Engine/src/RunControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Fling
: m_World(t_World),
m_InputTickRate(t_Startup.SimHz),
m_VSync(t_Startup.VSync),
m_FrustumCulling(t_Startup.FrustumCulling),
m_MaxFps(t_Startup.MaxFps),
m_MaxFpsFollowsMonitor(t_Startup.MaxFpsSource == SettingSource::Monitor),
m_MonitorHz(t_Startup.MonitorHz)
Expand All @@ -46,6 +47,15 @@ namespace Fling
}
}

void RunControls::SetFrustumCulling(const bool t_On)
{
if (t_On != m_FrustumCulling)
{
m_FrustumCulling = t_On;
F_LOG_TRACE("Frustum culling {}", t_On ? "on" : "off");
}
}

bool RunControls::SetMaxFps(const uint32 t_Fps, String& t_OutError)
{
t_OutError.clear();
Expand Down
Loading