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
8 changes: 8 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ platform setup (Vulkan SDK, GLFW, etc.).
The editor's GPU Options window (menu Windows; drawn in `--play` too) changes
the rate, the cap, VSync and interpolation 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
--screenshot <file.png>` renders with Vulkan into offscreen images and saves PNG
files (no window, no display; a software driver such as llvmpipe is enough).
Prefer the state dump; use screenshots for rendering work. From C++ (any
module, any thread): `Fling::Screenshot::Request(path, callback)` in
`Screenshot.h`; the editor's GPU Options window has a Take screenshot button. Detail:
[`Skills/testing.md`](Skills/testing.md#seeing-the-game-without-a-window).
- Drive a headless run with `--replay-input <file>`. Agents can write their own
`.input.jsonl` files. Format and flags: [`Skills/input-playback.md`](Skills/input-playback.md).
- Load a level other than `[Game] StartLevel` with `--level <file>` (relative
Expand Down
22 changes: 20 additions & 2 deletions Assets/Shaders/Deferred/deferred.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ layout (binding = 4) uniform sampler2D samplerMetal;
layout (binding = 5) uniform sampler2D samplerRoughness;

// In UV from the vertex shader
// True on a CPU driver such as llvmpipe (VK_PHYSICAL_DEVICE_TYPE_CPU): see the loop counts in main
layout (constant_id = 0) const bool CPU_DRIVER = false;

layout (location = 0) in vec2 inUV;

// Final screen color
Expand Down Expand Up @@ -60,10 +63,25 @@ void main()
// so that calculations only have to be done for visible fragments
// independent of no. of lights.

// The loop counts. On a CPU driver only (CPU_DRIVER, set by GeometrySubpass), the min with
// a value only the GPU knows (the G-buffer size, never 0) changes nothing, but keeps the
// driver from compiling the shader again for each count: llvmpipe's uniform inlining does
// that for loop bounds read from a uniform buffer, and its code for these two loops reads
// a null pointer (a crash on CPU rendering). A GPU driver removes the branch when it
// specializes the shader, so it pays nothing
uint DirLightCount = lights.DirLightCount;
uint PointLightCount = lights.PointLightCount;
if (CPU_DRIVER)
{
const uint NotInlined = uint(textureSize(samplerposition, 0).x) + 128u;
DirLightCount = min(DirLightCount, NotInlined);
PointLightCount = min(PointLightCount, NotInlined);
}

// Ambient part
vec3 LightColor = vec3(0.0, 0.0, 0.0);
// Directional lights -------------------------
for(uint i = 0; i < lights.DirLightCount; i++)
for(uint i = 0; i < DirLightCount; i++)
{
LightColor += DirLightPBR(
lights.DirLights[i],
Expand All @@ -78,7 +96,7 @@ void main()
}

// Point lights -------------------------
for(uint i = 0; i < lights.PointLightCount; i++)
for(uint i = 0; i < PointLightCount; i++)
{
// Vector to light
vec3 L = lights.PointLights[i].Pos.xyz - fragPos;
Expand Down
9 changes: 8 additions & 1 deletion Docs/agent-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,11 @@ flag or key. The startup line `Run settings: ...` names each value and its sourc
| Interpolation | `--interpolation on\|off` | `Interpolation` | 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), `--unattended` (no
Other flags: `--null-render` (no window or GPU, virtual clock), `--offscreen` (render
with the GPU into images, no window, with the timing of `--null-render`),
`--resolution WxH`, `--screenshot <file.png>` and `--screenshot-ticks L` (PNG of the
frame that shows each tick), `--dump-state <file.json>` and `--dump-state-ticks L` (the
simulation state as JSON after each tick), `--unattended` (no
dialogs; a crash exits 2 with a stack trace), `--frames N` (see below),
`--frames-per-tick N` (headless frames between ticks), `--seed S`, `--level <file>` (relative to `Assets/`),
`--play`, `--dump-schedule`, `--validate-schedule`, `--dump-ticks <file>`,
Expand Down Expand Up @@ -829,6 +833,9 @@ the tests from the repository root. clang-cl configure flags are in

Headless run: `Sandbox --null-render --unattended --frames 120 --seed 1` (the last log
lines print `Sandbox: 754 transforms, checksum ...` and `Fling exit: code=0 ticks=120 ...`).
To see what a run did without a window, read the state (`--dump-state`), or render
offscreen and look at a PNG (`--offscreen --screenshot`; a software Vulkan driver such
as llvmpipe is enough): `Skills/testing.md`, "Seeing the game without a window".

Test layout (Catch2 3; each executable links only its module):

Expand Down
25 changes: 23 additions & 2 deletions FlingEngine/Application/inc/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <memory>
#include <optional>
#include <type_traits>
#include <utility>
#include <vector>

/**
* Triggers a breakpoint at the call site, halting execution if a debugger is attached.
Expand All @@ -50,8 +52,9 @@ namespace Fling
* along with all startup/shutdown ordering.
*
* The loop does not need a window: with --null-render the engine makes no
* window and no GPU device, and ticks with a fixed delta. See LaunchOptions
* for the launch flags.
* window and no GPU device, and ticks with a fixed delta. With --offscreen it
* renders with the GPU into images it owns, still with no window, on the same
* fixed delta. See LaunchOptions for the launch flags.
*/
class Engine
{
Expand Down Expand Up @@ -238,6 +241,24 @@ namespace Fling
/** Writes the ledger rows of the ticks since the last call to the --dump-ticks file (main thread). */
void DumpNewTicks();

/** Writes the state dumps that the ticks made since the last call to their --dump-state files (main thread). */
void WriteStateDumps();

/** Before the frame is drawn: a Screenshot::Request for each --screenshot tick that it shows. */
void RequestScreenshots();

/** --dump-state: the ticks whose state has not been written yet. Sorted. */
std::vector<uint64> m_PendingStateDumps;

/** --dump-state: files that could not be written. */
uint32 m_StateDumpsFailed = 0;

/** --screenshot: the ticks whose frame has not been saved yet. Sorted. */
std::vector<uint64> m_PendingScreenshots;

/** --screenshot: captures that failed. */
uint32 m_ScreenshotsFailed = 0;

/** The exec mode's policies: the world's mode and last tick, and for threaded play the game thread and input.
*/
void SetUpExecMode();
Expand Down
Loading