Compare commits

...
Author SHA1 Message Date
poli0981andClaude Fable 5.2 62aed0d28d feat(shm): layout 5 - region 5, FlAdvancedState, for what a hooked game tells its upscaler, and the control word that asks for it; sized once for train B's three releases, written by nobody yet (Advanced B PR-2, D111/D113)
fl_shm.h: FlAdvancedState (1472 bytes at 0x100; the ring moves to 0x6C0) and FlControlBlock.advancedRequested (took
reserved[0]). While the word is 0 the Overlay is to read and hook exactly what it does today, and the region stays
zero. One writer - the watchdog, once a second; a vendor Boolean or preset is stored plus one and a float as its
bits with a "none" pattern, so zero is "not read" and never a value. The members beta.41 and beta.42 fill are
declared now, so those releases bump no layout.

The Agent's side: ShmLayout (layout 5, the mirror), ShmRingReader.AdvancedState - null until published, then the
last consistent copy - and SetAdvancedRequested, which stores the word either way because the control block
outlives a session. ICaptureSink gains both with default bodies; nothing calls them yet. fl-layout-dump prints every
member and ShmLayoutMirrorTests checks each offset. No hook body changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 00:08:36 +07:00
13 changed files with 653 additions and 21 deletions

No files matched your search

+7
View File
@@ -48,6 +48,13 @@ numeric core and does not move; the heading is the full version — corrected 20
- **`tools/agent-cost.ps1`** (a developer tool): what the shipped capture agent costs while it records, measured on
the real program against the project's own test window, with Advanced metrics off and on.
- **The shared memory between a game and the agent has room for what a game tells its upscaler — and nothing
writes it yet.** Its layout is version 5: one new region, sized once for the three releases of this train, and
one new word by which the agent says "this session records Advanced metrics". With that word at zero — every
session, until the next pull request, and afterwards every session with the option off — the region stays empty and
the component inside the game does exactly what it did before. **A game that is running when you update must be
restarted before FrameLedger measures it again**, as after every update.
### Changed
- **The agent's processor budget says what was measured.** The specification promised that the capture agent uses
+1 -1
View File
@@ -207,7 +207,7 @@ Dependency direction: `App/Agent → Application → Domain`; **`Application →
**Licence header —** every first-party source file (`.cs .cpp .h .inl .ps1 .xaml`) opens with two comment lines, `SPDX-License-Identifier: GPL-3.0-only` and `Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE` (beta.12, owner decision D45). GPLv3 §7 requires additional terms to be named in the source files, and `NOTICE` holds them — (b) preserve the notices, (c) mark modified versions, (e) no trademark rights in the name. `tools/notice-check.ps1` is a `build.ps1` gate; `-Fix` writes a missing header. `src/native/third_party/` is excluded.
**Struct mirroring —** ~~`FlFrameRecord`, `FlShmHandshake`, `FlWriterState` and `FlControlBlock`~~ `FlShmHandshake`, `FlWriterState`, `FlControlBlock`, `FlDisplayState` (layout 4, beta.10), `FlFrameRecord` and `FlTolerance` (D33, beta.9) each exist twice *(corrected 2026-10-04)*: `src/native/FrameLedger.Shm/include/fl_shm.h` / `fl_tolerance.h` (**normative**) and `src/FrameLedger.Shared/ShmLayout.cs` as `[StructLayout(LayoutKind.Sequential)]`. `ShmLayoutMirrorTests` asserts size and every field offset on both sides **against JSON emitted by ~~`tools/fl-layout-dump`~~ `src/native/tools/fl-layout-dump`**, never a transcribed table, and walks the field list in both directions so a field added on either side alone fails.
**Struct mirroring —** ~~`FlFrameRecord`, `FlShmHandshake`, `FlWriterState` and `FlControlBlock`~~ `FlShmHandshake`, `FlWriterState`, `FlControlBlock`, `FlDisplayState` (layout 4, beta.10), `FlAdvancedState` (layout 5, 2026-11-11, Advanced metrics train B), `FlFrameRecord` and `FlTolerance` (D33, beta.9) each exist twice *(corrected 2026-10-04)*: `src/native/FrameLedger.Shm/include/fl_shm.h` / `fl_tolerance.h` (**normative**) and `src/FrameLedger.Shared/ShmLayout.cs` as `[StructLayout(LayoutKind.Sequential)]`. `ShmLayoutMirrorTests` asserts size and every field offset on both sides **against JSON emitted by ~~`tools/fl-layout-dump`~~ `src/native/tools/fl-layout-dump`**, never a transcribed table, and walks the field list in both directions so a field added on either side alone fails.
It also asserts **blittability** (`RuntimeHelpers.IsReferenceOrContainsReferences`), because offsets cannot see it: measured 2026-08-05, swapping the `fixed byte BuildId[32]` for this repo's own `[MarshalAs(ByValTStr)] string` idiom keeps `Marshal.SizeOf` at 64 and every offset correct while `Unsafe.SizeOf` collapses to **40** — a mirror that passes the obvious checks and cannot be read out of a memory-mapped view.
+34 -5
View File
@@ -14,15 +14,17 @@ in beta.9 without a row here)*:
Created by the Overlay on init, opened by the Agent. Name is deliberately plain and identifiable (`19_SAFETY` — no obfuscated object names).
Layout — **~~four~~ five regions, each exactly one 64-byte cache line before the ring** (layout 4 since
2026-09-27, beta.10: region 4 is new and the ring moved from `0xC0` to `0x100`):
Layout — **~~four~~ ~~five~~ six regions** (layout 4 since 2026-09-27, beta.10: region 4 is new and the ring moved
from `0xC0` to `0x100`; **layout 5 since 2026-11-11**, Advanced metrics train B: region 5 is new — twenty-three cache
lines, where the four before it are one each — and the ring moved from `0x100` to `0x6C0`):
```
[0x0000] FlShmHandshake 64 B write-once by the Overlay at init
[0x0040] FlWriterState 64 B Overlay-written (writeIndex touched every present)
[0x0080] FlControlBlock 64 B Agent-written
[0x00C0] FlDisplayState 64 B Overlay-written, at most every 500 ms per chain (layout 4)
[0x0100] FlFrameRecord[capacity] (64 B each, power-of-two capacity)
[0x0100] FlAdvancedState 1472 B Overlay-written by its watchdog, once a second, only while the Agent asks (layout 5)
[0x06C0] FlFrameRecord[capacity] (64 B each, power-of-two capacity)
```
The header is split in two on purpose. The immutable handshake and the
@@ -72,7 +74,8 @@ struct alignas(64) FlControlBlock { // Agent-written
uint32_t overlayEnabled; // @8 in-game overlay draw toggle (v1.1)
uint32_t guardTicks; // @12 completed guard evaluations, NOT a timer
uint32_t logFlushRequested; // @16 a COUNTER: bumped by the Agent at session end; the watchdog flushes the native log on a change (17_HOOK_ENGINE §Native logging, 2026-09-06)
uint32_t reserved[11]; // @20..63 must be zero
uint32_t advancedRequested; // @20 1 while this session records Advanced metrics (D111); written 0 or 1 at attach, either way
uint32_t reserved[10]; // @24..63 must be zero
};
struct alignas(64) FlDisplayState { // Overlay-written (layout 4, 2026-09-27, beta.10)
@@ -93,9 +96,35 @@ static_assert(sizeof(FlShmHandshake) == 64);
static_assert(sizeof(FlWriterState) == 64);
static_assert(sizeof(FlControlBlock) == 64);
static_assert(sizeof(FlDisplayState) == 64);
static_assert(FL_SHM_DISPLAY_OFFSET == 0xC0 && FL_SHM_RING_OFFSET == 0x100 && FL_SHM_RING_OFFSET % 64 == 0);
static_assert(sizeof(FlAdvancedState) == 1472); // region 5: fl_shm.h is its declaration, member by member
static_assert(FL_SHM_DISPLAY_OFFSET == 0xC0 && FL_SHM_ADVANCED_OFFSET == 0x100 && FL_SHM_RING_OFFSET == 0x6C0 && FL_SHM_RING_OFFSET % 64 == 0);
```
**Region 5 — what a hooked game told its upscaler (layout 5, 2026-11-11; Advanced metrics train B, owner decisions
D111 and D113; written by nobody until the Overlay of 0.1.0-beta.40).** `18_GPU_VENDOR_APIS` §Train B is the design.
What the region is, as a contract between the two sides:
- **Off means zero.** `FlControlBlock.advancedRequested` is the Agent's word that this session records Advanced
metrics — written 0 or 1 at attach, either way, because the control block outlives a session
(`ShmRingReader.SetAdvancedRequested`). While it is 0 the Overlay reads no field and installs no hook beyond what
it did before, and writes nothing here: the region is zero from end to end, and `validMask == 0` means "nothing
was read", never "the game used none of it".
- **One writer, once a second.** The detours keep process-local accumulators; the watchdog copies them here at its
tick. No game thread writes the region, so the seqlock has a single writer: `seq` odd, the fields, `seq` even.
- **The reader keeps its last consistent copy** (`ShmRingReader.AdvancedState`): null until something was published;
the same copy while `seq` has not moved, without copying 1472 bytes again; and that copy still when the writer is
inside on every attempt — a watchdog killed with its process leaves `seq` odd for good, and what it published
before is still what the game said.
- **Zero is "not read", never a value.** A Streamline `Boolean` and a DLSS preset are stored as the vendor's value
plus one; a float as its bits, with `FL_ADV_FLOAT_NONE` for "none seen" — the vendors' own sentinels are refused in
the detour and never reach the region; a size of 0 is "not given".
- **A per-frame value is summarised where it is seen**: a flag is an "ever seen" mask, a jitter the largest magnitude,
a field of view its lowest and highest (D114), the reported frame time a count and a sum the watchdog drains.
- **Sized once for the train's three releases.** The members 0.1.0-beta.41 and beta.42 fill (`ffxFg*`, `sl*`,
`features`) are declared now and stay zero until then, so those releases bump no layout.
- The Vulkan layer never writes it. `ShmLayoutMirrorTests.TheAdvancedStateMirrorMatches` checks every member's
offset against `fl-layout-dump`; `ShmRingReaderTests` the three reads and that the request is stored either way.
**Region 4 — the presenting swap chain's display facts (layout 4, 2026-09-27, beta.10).** The owner asked for the game's
window size and display mode (exclusive fullscreen / borderless / windowed) and the share of a session each took. The two
facts only the process knows — whether the chain is in exclusive fullscreen, and which window it presents to — are
+1 -1
View File
@@ -28,7 +28,7 @@ The anti-cheat guard is the one component where a bug can cost someone an accoun
- **Ring buffer:** SPSC correctness under a hammering writer thread; seqlock torn-read detection; wrap and overwrite-oldest semantics; power-of-two capacity assumptions. Include the **one-full-lap case**: a reader stalled exactly `capacity` records must not validate a different frame as unchanged (this is what the never-reset `seq` counter defends, `07_IPC` §Protocol rules).
- **Drop accounting:** the reader-side computation (`writeIndex - readIndex > capacity`) reports the right count and resumes at the right index. The writer has no drop counter to test — by design.
- **Torn records produce gap markers,** not silently shortened streams; a golden test asserts the gap does not appear as a stutter.
- **Record and header layout:** `static_assert(sizeof(...) == 64)` and `offsetof` assertions for `FlFrameRecord` **and all ~~three~~ four header structs** (`FlShmHandshake`, `FlWriterState`, `FlControlBlock`, and `FlDisplayState` since layout 4, beta.10) — plus D33's `FlTolerance`, mirrored the same way *(corrected 2026-10-04)* — the Agent reads across the process boundary in every one of them. Both halves exist as of 2026-08-05: the native side is `layout_test.cpp` plus the `static_assert`s (ctest `fl_shm_layout`), and the runtime offset dump from `tools/fl-layout-dump` is consumed by `ShmLayoutMirrorTests`, which walks the field list in **both directions** and additionally asserts blittability — `Marshal.SizeOf` and every offset stay correct for a mirror that uses `[MarshalAs(ByValTStr)] string`, while `Unsafe.SizeOf` drops from 64 to 40 and the struct can no longer be read from a mapped view.
- **Record and header layout:** `static_assert(sizeof(...) == 64)` and `offsetof` assertions for `FlFrameRecord` **and all ~~three~~ ~~four~~ five header structs** *(five since layout 5, 2026-11-11: `FlAdvancedState`, 1472 bytes)* (`FlShmHandshake`, `FlWriterState`, `FlControlBlock`, and `FlDisplayState` since layout 4, beta.10) — plus D33's `FlTolerance`, mirrored the same way *(corrected 2026-10-04)* — the Agent reads across the process boundary in every one of them. Both halves exist as of 2026-08-05: the native side is `layout_test.cpp` plus the `static_assert`s (ctest `fl_shm_layout`), and the runtime offset dump from `tools/fl-layout-dump` is consumed by `ShmLayoutMirrorTests`, which walks the field list in **both directions** and additionally asserts blittability — `Marshal.SizeOf` and every offset stay correct for a mirror that uses `[MarshalAs(ByValTStr)] string`, while `Unsafe.SizeOf` drops from 64 to 40 and the struct can no longer be read from a mapped view.
- **Fault policy:** injected SEH faults in a fake hook body → counter increments, original still called, self-disable at 3.
- **Hook index verification, by behaviour.** A vtable slot carries no identity, so "check that slot 8 *is* `Present`" is not a question the runtime can answer — the earlier wording here required something unimplementable. What is answerable: patch the slot, call the method, see whether the detour ran (`17_HOOK_ENGINE` §Getting vtable addresses; proved for slots 8, 13 and 22 in `spike-notes.md` §H4). Runs headless on CI via WARP and `CreateSwapChainForComposition`. A deliberate mismatch aborts installation instead of patching.
- **Every probe must be shown to fail.** A probe that ends in an unconditional assertion is green by construction and its ctest is decorative — `fl_proxy_swapchain` shipped in exactly that state. Before a probe counts as a regression net, break the thing it watches and watch it go red.
+1 -1
View File
@@ -622,7 +622,7 @@ Field notes — each of these was a defect in an earlier revision:
- **SPSC lock-free ring**, capacity a power of two (default 8192 records = 512 KB), overwrite-oldest.
- Writer/reader seqlock protocol, including the rule that the payload write must
**exclude** the `seq` field and that `seq` is never reset: `07_IPC` §Protocol rules.
- Header: ~~three~~ **four** separate 64-byte lines before the ring *(corrected 2026-10-04: since layout 4, 2026-09-27,
- Header: ~~three~~ **four** separate 64-byte lines before the ring — and, since layout 5 (2026-11-11), region 5's twenty-three, which the watchdog alone writes and only while the Agent asks (`07_IPC` §Region 5) — *(corrected 2026-10-04: since layout 4, 2026-09-27,
beta.10, `FlDisplayState` at 0xC0 — Overlay-written at most every 500 ms; the ring starts at 0x100)* — `FlShmHandshake` (write-once),
`FlWriterState` (Overlay-written: `writeIndex`, `status`, `apiMask`, `faultCount`),
and `FlControlBlock` (**Agent**-written: `pauseRequested`, `unhookRequested`,
@@ -29,6 +29,21 @@ public interface ICaptureSink : IDisposable
/// </summary>
FlDisplayState? DisplayState { get; }
/// <summary>
/// Region 5 (layout 5, Advanced metrics train B): what the hooked game told its upscaler, as the Overlay last
/// published it - null while it has published nothing, which is every session that does not record Advanced
/// metrics, every Vulkan title (the layer never writes it), and a sink that has no such region.
/// </summary>
FlAdvancedState? AdvancedState => null;
/// <summary>
/// Says whether this session records Advanced metrics (owner decision D111): the one word that lets the Overlay
/// read more inside the game. Written either way at attach; a sink with no control block ignores it.
/// </summary>
void SetAdvancedRequested(bool requested)
{
}
long TotalDropped { get; }
long TotalGaps { get; }
@@ -18,6 +18,10 @@ public sealed class ShmCaptureSink(ShmRingReader reader) : ICaptureSink
public FlDisplayState? DisplayState => _reader.DisplayState;
public FlAdvancedState? AdvancedState => _reader.AdvancedState;
public void SetAdvancedRequested(bool requested) => _reader.SetAdvancedRequested(requested);
public long TotalDropped => _reader.TotalDropped;
public long TotalGaps => _reader.TotalGaps;
@@ -47,6 +47,8 @@ public sealed unsafe class ShmRingReader : IDisposable
private ulong _readIndex;
private bool _pointerHeld;
private bool _disposed;
private FlAdvancedState? _advanced;
private uint _advancedSeq;
private ShmRingReader(MemoryMappedFile mmf, MemoryMappedViewAccessor view, byte* basePtr, uint capacity)
{
@@ -330,6 +332,67 @@ public sealed unsafe class ShmRingReader : IDisposable
Volatile.Write(ref control->PauseRequested, paused ? 1u : 0u);
}
/// <summary>
/// Says whether the session this ring belongs to records Advanced metrics (owner decision D111; layout 5). Written
/// either way: the control block outlives a session, so "off" is a 0 that is stored, never a word that is left
/// alone - a 1 from the session before would be a request nobody made. While it is 0 the Overlay reads and hooks
/// exactly what it did before the option existed.
/// </summary>
public void SetAdvancedRequested(bool requested)
{
ObjectDisposedException.ThrowIf(_disposed, this);
var control = (FlControlBlock*)(_base + ShmLayout.ControlOffset);
Volatile.Write(ref control->AdvancedRequested, requested ? 1u : 0u);
}
/// <summary>
/// Region 5 (layout 5, Advanced metrics train B): what the hooked game told its upscaler, as the Overlay's
/// watchdog last published it - or null while it has published nothing, which is every ring whose session does not
/// record Advanced metrics.
/// </summary>
/// <remarks>
/// <para>
/// <b>The last consistent copy, kept.</b> The watchdog writes once a second and this is read at the session's own
/// pace, so most reads find the same <c>Seq</c> as the copy already held and return it without copying 1472 bytes
/// again. A read that finds the writer inside on every attempt returns that copy too, rather than nothing: a
/// watchdog that died with its process leaves <c>Seq</c> odd for good, and what it published before is still what
/// the game said.
/// </para>
/// <para>Not for two threads at once: the copy is this instance's, and a session's loop is its one reader.</para>
/// </remarks>
public FlAdvancedState? AdvancedState
{
get
{
ObjectDisposedException.ThrowIf(_disposed, this);
var region = (FlAdvancedState*)(_base + ShmLayout.AdvancedOffset);
for (int attempt = 0; attempt < DisplayStateAttempts; attempt++)
{
uint before = Volatile.Read(ref region->Seq);
if (before == 0u || (_advanced is not null && before == _advancedSeq))
{
return _advanced; // never published, or nothing newer than the copy held
}
if ((before & 1u) != 0u)
{
continue;
}
FlAdvancedState copy = *region;
Interlocked.MemoryBarrier();
if (Volatile.Read(ref region->Seq) == before)
{
_advanced = copy;
_advancedSeq = before;
return copy;
}
}
return _advanced;
}
}
/// <summary>
/// Ask the capture side to flush its native event ring to <c>logs\overlay-&lt;pid&gt;-*.log</c> now
/// (<c>17_HOOK_ENGINE</c> §Native logging). A counter: the watchdog acts on a change within one tick,
+214 -4
View File
@@ -37,7 +37,7 @@ public static class ShmLayout
/// user to restart the game — the DLL lives inside a running process, so the two sides cannot be
/// assumed to update in lockstep.
/// </summary>
public const uint LayoutVersion = 4u;
public const uint LayoutVersion = 5u;
public const uint HandshakeOffset = 0x00u;
public const uint WriterOffset = 0x40u;
@@ -46,7 +46,13 @@ public static class ShmLayout
/// <summary>Region 4, <see cref="FlDisplayState"/> (layout 4, beta.10): the ring moved from 0xC0 to make room for it.</summary>
public const uint DisplayOffset = 0xC0u;
public const uint RingOffset = 0x100u;
/// <summary>
/// Region 5, <see cref="FlAdvancedState"/> (layout 5, Advanced metrics train B, owner decisions D111 and D113): what a
/// hooked game told its upscaler. The ring moved from 0x100 to make room for it.
/// </summary>
public const uint AdvancedOffset = 0x100u;
public const uint RingOffset = 0x6C0u;
/// <summary>8192 × 64 B = 512 KiB, ≈16 s at 500 fps.</summary>
public const uint DefaultCapacity = 8192u;
@@ -657,8 +663,15 @@ public unsafe struct FlControlBlock
/// </summary>
public uint LogFlushRequested;
/// <summary>
/// 1 while the session this ring belongs to records Advanced metrics, 0 otherwise (owner decision D111). Written
/// unconditionally at attach - the block outlives a session. While it is 0 the Overlay reads and hooks exactly what it
/// did before the option existed, and region 5 stays zero.
/// </summary>
public uint AdvancedRequested;
/// <summary>Must be zero.</summary>
public fixed uint Reserved[11];
public fixed uint Reserved[10];
}
/// <summary><see cref="FlDisplayState.Flags"/> bits (layout 4, beta.10). A reader ignores a bit it does not know.</summary>
@@ -725,7 +738,204 @@ public unsafe struct FlDisplayState
public fixed uint Reserved[4];
}
/// <summary>Region 5 — the ring. Exactly 64 bytes, no implicit padding.</summary>
/// <summary><see cref="FlAdvancedState.ValidMask"/> bits (layout 5). A reader ignores a bit it does not know.</summary>
[Flags]
public enum FlAdvancedValid : uint
{
None = 0,
/// <summary><c>sl::DLSSOptions</c> was seen chained into <c>slEvaluateFeature</c>'s inputs.</summary>
DlssOptions = 1u << 0,
/// <summary>An ffx upscale dispatch's extra fields were read.</summary>
FfxUpscale = 1u << 1,
/// <summary>The game asked <c>ffxQuery</c> for the upscaler's memory, and it answered.</summary>
FfxMemory = 1u << 2,
/// <summary>0.1.0-beta.41: <c>ffxConfigure</c> with a frame-generation descriptor was seen.</summary>
FfxFgConfig = 1u << 3,
/// <summary>0.1.0-beta.41: <c>slSetConstants</c> was seen.</summary>
SlConstants = 1u << 4,
/// <summary>0.1.0-beta.42: at least one feature slot is filled.</summary>
SlFeatures = 1u << 5,
}
/// <summary>
/// Region 5 — Overlay-written by its watchdog, once a second, <b>only while <see cref="FlControlBlock.AdvancedRequested"/>
/// is 1</b> (layout 5, 2026-11-11, Advanced metrics train B): what a hooked game told its upscaler, read from the arguments
/// of calls the Overlay hooks. Sized once for the three releases of the train: a member a later release fills is here
/// and stays zero until then.
/// </summary>
/// <remarks>
/// <para>
/// <b>Zero is "not read", never a value.</b> <see cref="ValidMask"/> says which groups were ever read. Inside a group a
/// Streamline Boolean or a DLSS preset is the vendor's value PLUS ONE, a float is its bits with
/// <see cref="FloatNone"/> for "no value seen", and a size of 0 is "not given".
/// </para>
/// <para>
/// <b>A seqlock with one writer.</b> <see cref="Seq"/> is odd while the watchdog is inside; a copy taken between two reads
/// of an even, unchanged value is consistent (<c>ShmRingReader.AdvancedState</c>).
/// </para>
/// </remarks>
[StructLayout(LayoutKind.Sequential, Size = 1472)]
public unsafe struct FlAdvancedState
{
/// <summary>A float nobody saw: the bits no detour stores.</summary>
public const uint FloatNone = 0xFFFFFFFFu;
/// <summary>How many feature slots <see cref="Features"/> holds.</summary>
public const int FeatureSlots = 12;
/// <summary>How many words one feature slot is (<c>fl_shm.h</c> lists them).</summary>
public const int FeatureWords = 24;
/// <summary>Odd while the watchdog is inside; +2 per publication.</summary>
public uint Seq;
public FlAdvancedValid ValidMask;
/// <summary>Publications (wraps).</summary>
public uint Samples;
/// <summary>Must be zero.</summary>
public uint Reserved0;
/// <summary>QueryPerformanceCounter at the last publication.</summary>
public ulong SampleQpc;
/// <summary>Must be zero.</summary>
public fixed uint ReservedHeader[10];
/// <summary>The <c>structVersion</c> the game's <c>sl::DLSSOptions</c> declared; 0 = none seen.</summary>
public uint DlssStructVersion;
/// <summary>Evaluates that chained a <c>DLSSOptions</c> (wraps).</summary>
public uint DlssOptionsSeen;
/// <summary>0 = not given.</summary>
public uint DlssOutputWidth;
public uint DlssOutputHeight;
/// <summary>Float bits, or <see cref="FloatNone"/>.</summary>
public uint DlssPreExposureBits;
public uint DlssExposureScaleBits;
/// <summary><c>sl::DLSSPreset</c> PLUS ONE: DLAA, quality, balanced, performance, ultra performance, ultra quality.</summary>
public fixed byte DlssPresets[6];
/// <summary><c>sl::Boolean</c> PLUS ONE; 0 = not read.</summary>
public byte DlssColorBuffersHdr;
public byte DlssAutoExposure;
public byte DlssAlphaUpscaling;
/// <summary>Must be zero.</summary>
public fixed byte DlssPad[3];
/// <summary>Must be zero.</summary>
public fixed uint ReservedDlss[7];
/// <summary>Upscale dispatches whose extras were read (wraps).</summary>
public uint FfxDispatches;
/// <summary>Bit 0: sharpening seen off; bit 1: seen on.</summary>
public uint FfxSharpenSeen;
public uint FfxSharpnessMinBits;
public uint FfxSharpnessMaxBits;
/// <summary>The largest |jitterOffset.x| seen.</summary>
public uint FfxJitterMaxXBits;
public uint FfxJitterMaxYBits;
public uint FfxPreExposureMinBits;
public uint FfxPreExposureMaxBits;
public uint FfxNearBits;
public uint FfxFarBits;
/// <summary>Radians: the lowest and the highest of the session (owner decision D114).</summary>
public uint FfxFovMinBits;
public uint FfxFovMaxBits;
/// <summary>Every <c>FFX_UPSCALE_FLAG</c> bit any dispatch carried.</summary>
public uint FfxFlagsSeen;
public uint FfxResets;
/// <summary>Dispatches since the last publication, and the sum of their <c>frameTimeDelta</c> in microseconds.</summary>
public uint FfxFrameTimeCount;
public uint FfxFrameTimeSumUs;
public ulong FfxMemoryTotalBytes;
public ulong FfxMemoryAliasableBytes;
public uint FfxMemoryQueries;
public uint FfxFgConfigures;
public uint FfxFgEnabledSeen;
public uint FfxFgAsyncSeen;
public uint FfxFgOnlyGeneratedSeen;
public uint FfxFgFlagsSeen;
/// <summary>left, top, width, height.</summary>
public fixed int FfxFgRect[4];
/// <summary>Must be zero.</summary>
public fixed uint ReservedFfx[2];
public uint SlConstantsCalls;
public uint SlResets;
public uint SlJitterMaxXBits;
public uint SlJitterMaxYBits;
public uint SlMvecScaleXBits;
public uint SlMvecScaleYBits;
public uint SlNearBits;
public uint SlFarBits;
public uint SlFovMinBits;
public uint SlFovMaxBits;
public uint SlAspectBits;
/// <summary>One bit per <c>sl::Constants</c> Boolean seen true, in the header's order.</summary>
public uint SlFlagsSeenTrue;
public uint SlFlagsSeenFalse;
/// <summary>Must be zero.</summary>
public fixed uint ReservedSl[3];
/// <summary><see cref="FeatureSlots"/> slots of <see cref="FeatureWords"/> words each (0.1.0-beta.42).</summary>
public fixed uint Features[FeatureSlots * FeatureWords];
}
/// <summary>Region 6 — the ring. Exactly 64 bytes, no implicit padding.</summary>
[StructLayout(LayoutKind.Sequential, Size = 64)]
public unsafe struct FlFrameRecord
{
+180 -5
View File
@@ -29,7 +29,9 @@
// [0x0040] FlWriterState 64 B Overlay-written (writeIndex every present)
// [0x0080] FlControlBlock 64 B Agent-written
// [0x00C0] FlDisplayState 64 B Overlay-written, at most every 500 ms (layout 4, beta.10)
// [0x0100] FlFrameRecord[capacity]
// [0x0100] FlAdvancedState 1472 B Overlay-written by its watchdog, once a second, only while the Agent asks
// (layout 5, Advanced metrics train B)
// [0x06C0] FlFrameRecord[capacity]
//
// The header regions are separate cache lines on purpose. The Overlay
// writes region 2 every frame while the Agent writes region 3 every second;
@@ -62,13 +64,19 @@
// 0xC0 to 0x100 to make room for it. FlWriterState had no slack left
// (dxgiPresentsBeforeHook took its last word), and the display facts are not
// frame facts, so neither the writer state nor the record was the place.
#define FL_SHM_LAYOUT_VERSION 4u
//
// 5 (2026-11-11, Advanced metrics train B, owner decisions D111 and D113): region 5, FlAdvancedState, and the ring
// moved from 0x100 to 0x6C0 to make room for it. What a hooked game told its upscaler is neither a frame fact nor a
// display fact, and no region had room. The region is sized ONCE for the three releases of train B (beta.40, .41,
// .42): a member a later release fills is declared here and stays zero until then, so those releases bump nothing.
#define FL_SHM_LAYOUT_VERSION 5u
#define FL_SHM_HANDSHAKE_OFFSET 0x00u
#define FL_SHM_WRITER_OFFSET 0x40u
#define FL_SHM_CONTROL_OFFSET 0x80u
#define FL_SHM_DISPLAY_OFFSET 0xC0u
#define FL_SHM_RING_OFFSET 0x100u
#define FL_SHM_ADVANCED_OFFSET 0x100u
#define FL_SHM_RING_OFFSET 0x6C0u
#define FL_SHM_DEFAULT_CAPACITY 8192u // 8192 * 64 B = 512 KiB, ~16 s at 500 fps
@@ -821,7 +829,13 @@ struct alignas(64) FlControlBlock {
// last acted on, so the Agent never has to clear anything in a block it is the
// sole writer of. Took reserved[0]; additive, no layout bump.
uint32_t logFlushRequested; // @16
uint32_t reserved[11]; // @20..63 must be zero
// ADVANCED METRICS REQUESTED (2026-11-11, owner decision D111). 1 while the session this ring belongs to records
// Advanced metrics, 0 otherwise - and the Agent writes it UNCONDITIONALLY at attach, before its first guard
// result, because this block outlives a session and a value left by the last one would be a request nobody
// made. While it is 0 the Overlay reads no field and installs no hook beyond what it did before the option
// existed, and region 5 stays zero. Took reserved[0]; additive within the block.
uint32_t advancedRequested; // @20
uint32_t reserved[10]; // @24..63 must be zero
};
// ---------------------------------------------------------------------------
@@ -878,6 +892,136 @@ struct alignas(64) FlDisplayState {
uint32_t reserved[4]; // @48..63 must be zero
};
// ---------------------------------------------------------------------------
// Region 5 — Overlay-written: what a hooked game told its upscaler (layout 5, 2026-11-11, Advanced metrics train B).
// ---------------------------------------------------------------------------
// The owner's "Advanced metrics" (18_GPU_VENDOR_APIS §Advanced metrics): the options a game hands DLSS and FSR, FSR's
// own memory, and - in the two releases after this layout - the constants it hands Streamline, its frame-generation
// configuration and the versions Streamline reports. All of it is read from the ARGUMENTS of calls the Overlay hooks
// (CLAUDE.md rule 4), by the rule of 17_HOOK_ENGINE §Which struct version carries which field: a member is read only
// where the upstream tags prove the game's struct has it.
//
// OFF MEANS OFF (D111). Nothing here is written, and nothing more is read in any hook, unless
// FlControlBlock.advancedRequested is 1. A ring whose session does not record Advanced metrics has this region zero
// from end to end, and `validMask` zero says "nothing was read" - never "the game used none of it".
//
// ONE WRITER, ONCE A SECOND. The detours keep process-local accumulators (relaxed atomics); the WATCHDOG copies them
// here at its 1 Hz tick. No game thread writes this region, so the seqlock has a single writer and needs no
// compare-exchange: `seq` goes odd, the fields are stored, `seq` goes even. A reader copies the region between two
// reads of an even, unchanged `seq`. A watchdog killed with its process can leave `seq` odd for good - a reader that
// keeps the last good copy loses nothing.
//
// VENDOR ZEROS AND SENTINELS (the trap HANDOFF records for rtTier, upscalerQuality and swapEffect). A Streamline
// Boolean and a DLSS preset are stored as the vendor value PLUS ONE, so 0 is "not read" and never "false" or "the
// default preset". A float is stored as its bits; FL_ADV_FLOAT_NONE means no value was seen - the vendors' own
// sentinels (Streamline's INVALID_FLOAT is FLT_MAX) are refused in the detour and never reach here. A width or
// height of 0 is "not given" (Streamline's INVALID_UINT is refused the same way).
//
// PER-FRAME VALUES ARE SUMMARISED WHERE THEY ARE SEEN, not sampled once a second: a flag is an "ever seen" mask, a
// jitter is the largest magnitude seen, a field of view is its lowest and highest (D114: a session's range, never a
// series), and the frame time the game reports is a count and a sum over the second, which the watchdog drains.
// FlAdvancedState.validMask: which groups below were ever read. Additive: a reader ignores a bit it does not know.
enum FlAdvancedValid : uint32_t {
FL_ADV_VALID_DLSS_OPTIONS = 1u << 0, // sl::DLSSOptions seen chained into slEvaluateFeature's inputs
FL_ADV_VALID_FFX_UPSCALE = 1u << 1, // an ffx upscale dispatch's extra fields were read
FL_ADV_VALID_FFX_MEMORY = 1u << 2, // the game asked ffxQuery for the upscaler's memory, and it answered
FL_ADV_VALID_FFX_FG_CONFIG = 1u << 3, // (0.1.0-beta.41) ffxConfigure with a frame-generation descriptor seen
FL_ADV_VALID_SL_CONSTANTS = 1u << 4, // (0.1.0-beta.41) slSetConstants seen
FL_ADV_VALID_SL_FEATURES = 1u << 5, // (0.1.0-beta.42) at least one feature slot filled
};
// A float nobody saw. An all-ones pattern is a NaN no detour stores: every value is checked finite first.
#define FL_ADV_FLOAT_NONE 0xFFFFFFFFu
// Feature slots (0.1.0-beta.42): FL_ADV_FEATURE_SLOTS slots of FL_ADV_FEATURE_WORDS uint32 each, in `features`.
// [0] sl::Feature id PLUS ONE; 0 = an empty slot
// [1] bit 0: slGetFeatureVersion answered; bit 1: slGetFeatureRequirements answered
// [2..4] versionSL major, minor, build [5..7] versionNGX
// [8] FeatureRequirementFlags [9] maxNumCPUThreads
// [10] maxNumViewports [11] numRequiredTags
// [12..14] osVersionDetected [15..17] osVersionRequired
// [18..20] driverVersionDetected [21..23] driverVersionRequired
#define FL_ADV_FEATURE_SLOTS 12u
#define FL_ADV_FEATURE_WORDS 24u
struct alignas(64) FlAdvancedState {
// ---- line 0: the header ------------------------------------------------------------------------------------
uint32_t seq; // @0 seqlock: odd while the watchdog is inside, +2 per publication
uint32_t validMask; // @4 FlAdvancedValid
uint32_t samples; // @8 publications (wraps)
uint32_t reserved0; // @12 must be zero
uint64_t sampleQpc; // @16 QueryPerformanceCounter at the last publication
uint32_t reservedHeader[10]; // @24..63 must be zero
// ---- line 1: sl::DLSSOptions as last seen in slEvaluateFeature's inputs -----------------------------------
uint32_t dlssStructVersion; // @64 the structVersion the game's struct declared; 0 = none seen
uint32_t dlssOptionsSeen; // @68 evaluates that chained a DLSSOptions (wraps)
uint32_t dlssOutputWidth; // @72 0 = not given
uint32_t dlssOutputHeight; // @76
uint32_t dlssPreExposureBits; // @80 float bits, or FL_ADV_FLOAT_NONE
uint32_t dlssExposureScaleBits; // @84
// sl::DLSSPreset PLUS ONE, in the header's order: DLAA, quality, balanced, performance, ultra performance,
// ultra quality (the last is struct version 2's - 0 where the game's struct is older).
uint8_t dlssPresets[6]; // @88..93
uint8_t dlssColorBuffersHdr; // @94 sl::Boolean PLUS ONE; 0 = not read
uint8_t dlssAutoExposure; // @95 (struct version 2)
uint8_t dlssAlphaUpscaling; // @96 (struct version 3)
uint8_t dlssPad[3]; // @97..99 must be zero
uint32_t reservedDlss[7]; // @100..127 must be zero
// ---- line 2: the ffx upscale dispatch, beyond its two sizes ---------------------------------------------------
uint32_t ffxDispatches; // @128 upscale dispatches whose extras were read (wraps)
uint32_t ffxSharpenSeen; // @132 bit 0: seen off; bit 1: seen on
uint32_t ffxSharpnessMinBits; // @136 over the dispatches with sharpening on; float bits or NONE
uint32_t ffxSharpnessMaxBits; // @140
uint32_t ffxJitterMaxXBits; // @144 the largest |jitterOffset.x| seen
uint32_t ffxJitterMaxYBits; // @148
uint32_t ffxPreExposureMinBits; // @152
uint32_t ffxPreExposureMaxBits; // @156
uint32_t ffxNearBits; // @160 cameraNear, the last one seen
uint32_t ffxFarBits; // @164
uint32_t ffxFovMinBits; // @168 cameraFovAngleVertical, radians: the lowest and the highest (D114)
uint32_t ffxFovMaxBits; // @172
uint32_t ffxFlagsSeen; // @176 every FFX_UPSCALE_FLAG bit any dispatch carried
uint32_t ffxResets; // @180 dispatches with `reset` set (wraps)
uint32_t ffxFrameTimeCount; // @184 dispatches since the last publication...
uint32_t ffxFrameTimeSumUs; // @188 ...and the sum of their frameTimeDelta, in microseconds
// ---- line 3: the ffx upscaler's memory, and its frame-generation configuration --------------------------------
uint64_t ffxMemoryTotalBytes; // @192 FfxApiEffectMemoryUsage, as the last answered query gave it
uint64_t ffxMemoryAliasableBytes; // @200
uint32_t ffxMemoryQueries; // @208 answered memory queries (wraps)
uint32_t ffxFgConfigures; // @212 (beta.41) ffxConfigure calls with a frame-generation descriptor
uint32_t ffxFgEnabledSeen; // @216 (beta.41) bit 0: seen off; bit 1: seen on
uint32_t ffxFgAsyncSeen; // @220 (beta.41) allowAsyncWorkloads, the same two bits
uint32_t ffxFgOnlyGeneratedSeen; // @224 (beta.41) onlyPresentGenerated, the same two bits
uint32_t ffxFgFlagsSeen; // @228 (beta.41) every dispatch flag any configure carried
int32_t ffxFgRect[4]; // @232..247 (beta.41) generationRect: left, top, width, height - the last
uint32_t reservedFfx[2]; // @248..255 must be zero
// ---- line 4: sl::Constants, summarised (beta.41) - never the camera's position, axes or matrices -----------
uint32_t slConstantsCalls; // @256 slSetConstants calls, every viewport together (wraps)
uint32_t slResets; // @260 calls with `reset` true
uint32_t slJitterMaxXBits; // @264
uint32_t slJitterMaxYBits; // @268
uint32_t slMvecScaleXBits; // @272 the last one seen
uint32_t slMvecScaleYBits; // @276
uint32_t slNearBits; // @280
uint32_t slFarBits; // @284
uint32_t slFovMinBits; // @288 radians: the lowest and the highest (D114)
uint32_t slFovMaxBits; // @292
uint32_t slAspectBits; // @296
// One bit per sl::Constants Boolean, in the header's order: depthInverted, cameraMotionIncluded, motionVectors3D,
// reset, orthographicProjection, motionVectorsDilated, motionVectorsJittered.
uint32_t slFlagsSeenTrue; // @300
uint32_t slFlagsSeenFalse; // @304
uint32_t reservedSl[3]; // @308..319 must be zero
// ---- lines 5..22: Streamline's features (beta.42) --------------------------------------------------------------
uint32_t features[FL_ADV_FEATURE_SLOTS * FL_ADV_FEATURE_WORDS]; // @320..1471
};
// ---------------------------------------------------------------------------
// Region 5 — the ring. 64 bytes exactly, no implicit padding.
// ---------------------------------------------------------------------------
@@ -1065,6 +1209,8 @@ static_assert(offsetof(FlControlBlock, unhookRequested) == 4);
static_assert(offsetof(FlControlBlock, overlayEnabled) == 8);
static_assert(offsetof(FlControlBlock, guardTicks) == 12);
static_assert(offsetof(FlControlBlock, logFlushRequested) == 16);
static_assert(offsetof(FlControlBlock, advancedRequested) == 20);
static_assert(offsetof(FlControlBlock, reserved) == 24);
static_assert(offsetof(FlFrameRecord, qpc) == 0);
static_assert(offsetof(FlFrameRecord, frameIndex) == 8);
@@ -1123,12 +1269,41 @@ static_assert(offsetof(FlDisplayState, sampleQpc) == 40);
static_assert(offsetof(FlDisplayState, reserved) == 48);
static_assert(offsetof(FlDisplayState, hwnd) % 8 == 0 && offsetof(FlDisplayState, sampleQpc) % 8 == 0);
// Region 5 (layout 5): twenty-three cache lines, each group on its own line, every field naturally aligned.
static_assert(sizeof(FlAdvancedState) == 1472);
static_assert(sizeof(FlAdvancedState) % 64 == 0);
static_assert(offsetof(FlAdvancedState, seq) == 0);
static_assert(offsetof(FlAdvancedState, validMask) == 4);
static_assert(offsetof(FlAdvancedState, samples) == 8);
static_assert(offsetof(FlAdvancedState, sampleQpc) == 16);
static_assert(offsetof(FlAdvancedState, reservedHeader) == 24);
static_assert(offsetof(FlAdvancedState, dlssStructVersion) == 64);
static_assert(offsetof(FlAdvancedState, dlssPreExposureBits) == 80);
static_assert(offsetof(FlAdvancedState, dlssPresets) == 88);
static_assert(offsetof(FlAdvancedState, dlssColorBuffersHdr) == 94);
static_assert(offsetof(FlAdvancedState, dlssAlphaUpscaling) == 96);
static_assert(offsetof(FlAdvancedState, reservedDlss) == 100);
static_assert(offsetof(FlAdvancedState, ffxDispatches) == 128);
static_assert(offsetof(FlAdvancedState, ffxFrameTimeSumUs) == 188);
static_assert(offsetof(FlAdvancedState, ffxMemoryTotalBytes) == 192);
static_assert(offsetof(FlAdvancedState, ffxMemoryQueries) == 208);
static_assert(offsetof(FlAdvancedState, ffxFgRect) == 232);
static_assert(offsetof(FlAdvancedState, reservedFfx) == 248);
static_assert(offsetof(FlAdvancedState, slConstantsCalls) == 256);
static_assert(offsetof(FlAdvancedState, slFlagsSeenFalse) == 304);
static_assert(offsetof(FlAdvancedState, reservedSl) == 308);
static_assert(offsetof(FlAdvancedState, features) == 320);
static_assert(offsetof(FlAdvancedState, sampleQpc) % 8 == 0 && offsetof(FlAdvancedState, ffxMemoryTotalBytes) % 8 == 0);
static_assert(FL_ADV_FEATURE_SLOTS * FL_ADV_FEATURE_WORDS * sizeof(uint32_t) == 1152);
// The regions must not overlap, and the ring must stay 64-aligned.
static_assert(FL_SHM_HANDSHAKE_OFFSET + sizeof(FlShmHandshake) <= FL_SHM_WRITER_OFFSET);
static_assert(FL_SHM_WRITER_OFFSET + sizeof(FlWriterState) <= FL_SHM_CONTROL_OFFSET);
static_assert(FL_SHM_CONTROL_OFFSET + sizeof(FlControlBlock) <= FL_SHM_DISPLAY_OFFSET);
static_assert(FL_SHM_DISPLAY_OFFSET + sizeof(FlDisplayState) <= FL_SHM_RING_OFFSET);
static_assert(FL_SHM_DISPLAY_OFFSET + sizeof(FlDisplayState) <= FL_SHM_ADVANCED_OFFSET);
static_assert(FL_SHM_ADVANCED_OFFSET + sizeof(FlAdvancedState) <= FL_SHM_RING_OFFSET);
static_assert(FL_SHM_DISPLAY_OFFSET % 64 == 0);
static_assert(FL_SHM_ADVANCED_OFFSET % 64 == 0);
static_assert(FL_SHM_RING_OFFSET % 64 == 0);
constexpr size_t FlShmSizeForCapacity(uint32_t capacity) noexcept {
+71 -3
View File
@@ -39,9 +39,10 @@ int main() {
std::printf("{\n");
std::printf(" \"layoutVersion\": %u,\n", FL_SHM_LAYOUT_VERSION);
std::printf(
" \"regions\": { \"handshake\": %u, \"writer\": %u, \"control\": %u, \"display\": %u, \"ring\": %u },\n",
" \"regions\": { \"handshake\": %u, \"writer\": %u, \"control\": %u, \"display\": %u, \"advanced\": %u, "
"\"ring\": %u },\n",
FL_SHM_HANDSHAKE_OFFSET, FL_SHM_WRITER_OFFSET, FL_SHM_CONTROL_OFFSET, FL_SHM_DISPLAY_OFFSET,
FL_SHM_RING_OFFSET);
FL_SHM_ADVANCED_OFFSET, FL_SHM_RING_OFFSET);
// D33: the tolerance mapping (fl_tolerance.h) the Agent writes before an injection under a user-mode exception.
std::printf(" \"tolerance\": { \"magic\": %u, \"version\": %u, \"maxFamilies\": %u, \"nameLen\": %u },\n",
FL_TOLERANCE_MAGIC, FL_TOLERANCE_VERSION, FL_TOLERANCE_MAX_FAMILIES, FL_TOLERANCE_NAME_LEN);
@@ -86,7 +87,8 @@ int main() {
Field("overlayEnabled", offsetof(FlControlBlock, overlayEnabled), sizeof(uint32_t));
Field("guardTicks", offsetof(FlControlBlock, guardTicks), sizeof(uint32_t));
Field("logFlushRequested", offsetof(FlControlBlock, logFlushRequested), sizeof(uint32_t));
Field("reserved", offsetof(FlControlBlock, reserved), sizeof(uint32_t) * 11, true);
Field("advancedRequested", offsetof(FlControlBlock, advancedRequested), sizeof(uint32_t));
Field("reserved", offsetof(FlControlBlock, reserved), sizeof(uint32_t) * 10, true);
std::printf(" ] },\n");
// Layout 4 (beta.10): region 4, the presenting swap chain's display facts.
@@ -104,6 +106,72 @@ int main() {
Field("reserved", offsetof(FlDisplayState, reserved), sizeof(uint32_t) * 4, true);
std::printf(" ] },\n");
// Layout 5 (Advanced metrics train B): region 5, what a hooked game told its upscaler. EVERY member, the ones a
// later release fills included - the mirror is checked whole or it is not checked.
#define FL_ADV_FIELD(name) Field(#name, offsetof(FlAdvancedState, name), sizeof(FlAdvancedState::name))
std::printf(" \"FlAdvancedState\": { \"size\": %zu, \"fields\": [\n", sizeof(FlAdvancedState));
FL_ADV_FIELD(seq);
FL_ADV_FIELD(validMask);
FL_ADV_FIELD(samples);
FL_ADV_FIELD(reserved0);
FL_ADV_FIELD(sampleQpc);
FL_ADV_FIELD(reservedHeader);
FL_ADV_FIELD(dlssStructVersion);
FL_ADV_FIELD(dlssOptionsSeen);
FL_ADV_FIELD(dlssOutputWidth);
FL_ADV_FIELD(dlssOutputHeight);
FL_ADV_FIELD(dlssPreExposureBits);
FL_ADV_FIELD(dlssExposureScaleBits);
FL_ADV_FIELD(dlssPresets);
FL_ADV_FIELD(dlssColorBuffersHdr);
FL_ADV_FIELD(dlssAutoExposure);
FL_ADV_FIELD(dlssAlphaUpscaling);
FL_ADV_FIELD(dlssPad);
FL_ADV_FIELD(reservedDlss);
FL_ADV_FIELD(ffxDispatches);
FL_ADV_FIELD(ffxSharpenSeen);
FL_ADV_FIELD(ffxSharpnessMinBits);
FL_ADV_FIELD(ffxSharpnessMaxBits);
FL_ADV_FIELD(ffxJitterMaxXBits);
FL_ADV_FIELD(ffxJitterMaxYBits);
FL_ADV_FIELD(ffxPreExposureMinBits);
FL_ADV_FIELD(ffxPreExposureMaxBits);
FL_ADV_FIELD(ffxNearBits);
FL_ADV_FIELD(ffxFarBits);
FL_ADV_FIELD(ffxFovMinBits);
FL_ADV_FIELD(ffxFovMaxBits);
FL_ADV_FIELD(ffxFlagsSeen);
FL_ADV_FIELD(ffxResets);
FL_ADV_FIELD(ffxFrameTimeCount);
FL_ADV_FIELD(ffxFrameTimeSumUs);
FL_ADV_FIELD(ffxMemoryTotalBytes);
FL_ADV_FIELD(ffxMemoryAliasableBytes);
FL_ADV_FIELD(ffxMemoryQueries);
FL_ADV_FIELD(ffxFgConfigures);
FL_ADV_FIELD(ffxFgEnabledSeen);
FL_ADV_FIELD(ffxFgAsyncSeen);
FL_ADV_FIELD(ffxFgOnlyGeneratedSeen);
FL_ADV_FIELD(ffxFgFlagsSeen);
FL_ADV_FIELD(ffxFgRect);
FL_ADV_FIELD(reservedFfx);
FL_ADV_FIELD(slConstantsCalls);
FL_ADV_FIELD(slResets);
FL_ADV_FIELD(slJitterMaxXBits);
FL_ADV_FIELD(slJitterMaxYBits);
FL_ADV_FIELD(slMvecScaleXBits);
FL_ADV_FIELD(slMvecScaleYBits);
FL_ADV_FIELD(slNearBits);
FL_ADV_FIELD(slFarBits);
FL_ADV_FIELD(slFovMinBits);
FL_ADV_FIELD(slFovMaxBits);
FL_ADV_FIELD(slAspectBits);
FL_ADV_FIELD(slFlagsSeenTrue);
FL_ADV_FIELD(slFlagsSeenFalse);
FL_ADV_FIELD(reservedSl);
Field("features", offsetof(FlAdvancedState, features), sizeof(FlAdvancedState::features), true);
#undef FL_ADV_FIELD
std::printf(" ] },\n");
std::printf(" \"FlFrameRecord\": { \"size\": %zu, \"fields\": [\n", sizeof(FlFrameRecord));
Field("qpc", offsetof(FlFrameRecord, qpc), sizeof(uint64_t));
Field("frameIndex", offsetof(FlFrameRecord, frameIndex), sizeof(uint32_t));
@@ -185,6 +185,7 @@ public sealed class ShmLayoutMirrorTests
regions.GetProperty("writer").GetUInt32().Should().Be(ShmLayout.WriterOffset);
regions.GetProperty("control").GetUInt32().Should().Be(ShmLayout.ControlOffset);
regions.GetProperty("display").GetUInt32().Should().Be(ShmLayout.DisplayOffset);
regions.GetProperty("advanced").GetUInt32().Should().Be(ShmLayout.AdvancedOffset);
regions.GetProperty("ring").GetUInt32().Should().Be(ShmLayout.RingOffset);
}
@@ -201,6 +202,10 @@ public sealed class ShmLayoutMirrorTests
[Fact]
public void TheDisplayStateMirrorMatches() => AssertMirror<FlDisplayState>("FlDisplayState");
/// <summary>Layout 5 (Advanced metrics train B): region 5, every member - the ones a later release fills included.</summary>
[Fact]
public void TheAdvancedStateMirrorMatches() => AssertMirror<FlAdvancedState>("FlAdvancedState", 1472, "twenty-three cache lines in fl_shm.h");
[Fact]
public void TheFrameRecordMirrorMatches() => AssertMirror<FlFrameRecord>("FlFrameRecord");
@@ -233,6 +238,7 @@ public sealed class ShmLayoutMirrorTests
("FlWriterState", typeof(FlWriterState)),
("FlControlBlock", typeof(FlControlBlock)),
("FlDisplayState", typeof(FlDisplayState)),
("FlAdvancedState", typeof(FlAdvancedState)),
("FlFrameRecord", typeof(FlFrameRecord)),
("FlTolerance", typeof(FlTolerance)),
];
@@ -271,7 +277,7 @@ public sealed class ShmLayoutMirrorTests
[Fact]
public void EveryDumpedStructHasAMirror()
{
string[] mirrored = ["FlShmHandshake", "FlWriterState", "FlControlBlock", "FlDisplayState", "FlFrameRecord", "FlTolerance"];
string[] mirrored = ["FlShmHandshake", "FlWriterState", "FlControlBlock", "FlDisplayState", "FlAdvancedState", "FlFrameRecord", "FlTolerance"];
IEnumerable<string> dumped = _nativeLayout.Value.GetProperty("structs").EnumerateObject().Select(static p => p.Name);
@@ -68,6 +68,8 @@ public sealed class ShmRingReaderTests
public FlControlBlock* Control => (FlControlBlock*)(_base + ShmLayout.ControlOffset);
public FlAdvancedState* Advanced => (FlAdvancedState*)(_base + ShmLayout.AdvancedOffset);
public FlFrameRecord* Slot(ulong index) =>
&((FlFrameRecord*)(_base + ShmLayout.RingOffset))[index & (_capacity - 1)];
@@ -254,6 +256,59 @@ public sealed class ShmRingReaderTests
reader.Should().BeNull();
}
[Fact]
public unsafe void TheAdvancedRequestIsWrittenEitherWayAndTouchesNoOtherWord()
{
// Owner decision D111 (layout 5): the one word that lets the Overlay read more inside a game. The control block
// outlives a session, so "off" must be STORED - a publisher that only ever wrote 1 would leave the last session's
// request standing for one that never asked.
int pid = FakePid();
using var ring = new FakeRing(pid);
using ShmRingReader? reader = ShmRingReader.TryAttach(pid, _buildId, out _);
ring.Control->AdvancedRequested = 1u; // as the session before left it
reader!.SetAdvancedRequested(false);
ring.Control->AdvancedRequested.Should().Be(0u, "off is a zero that is written");
reader.SetAdvancedRequested(true);
ring.Control->AdvancedRequested.Should().Be(1u);
ring.Control->UnhookRequested.Should().Be(0u, "asking for more readings is not the safety stop");
ring.Control->PauseRequested.Should().Be(0u);
ring.Control->LogFlushRequested.Should().Be(0u);
ring.Control->GuardTicks.Should().Be(0u);
}
[Fact]
public unsafe void TheAdvancedRegionReadsNullUntilPublishedThenItsLastConsistentCopy()
{
int pid = FakePid();
using var ring = new FakeRing(pid);
using ShmRingReader? reader = ShmRingReader.TryAttach(pid, _buildId, out _);
reader!.AdvancedState.Should().BeNull("a region nobody published is not a game that used nothing");
// One publication, as the watchdog writes it: odd, the fields, even.
ring.Advanced->Seq = 1u;
ring.Advanced->ValidMask = FlAdvancedValid.DlssOptions;
ring.Advanced->DlssOutputWidth = 3840u;
ring.Advanced->Features[(FlAdvancedState.FeatureSlots * FlAdvancedState.FeatureWords) - 1] = 572u;
reader.AdvancedState.Should().BeNull("the writer is inside, and nothing was published before");
ring.Advanced->Seq = 2u;
FlAdvancedState first = reader.AdvancedState.Should().BeOfType<FlAdvancedState>().Subject;
first.ValidMask.Should().Be(FlAdvancedValid.DlssOptions);
first.DlssOutputWidth.Should().Be(3840u);
first.Features[(FlAdvancedState.FeatureSlots * FlAdvancedState.FeatureWords) - 1].Should().Be(572u, "the region is read to its last word");
// A second publication caught halfway: the reader keeps what it had rather than returning a torn copy or nothing.
ring.Advanced->Seq = 3u;
ring.Advanced->DlssOutputWidth = 2560u;
reader.AdvancedState.Should().BeOfType<FlAdvancedState>().Which.DlssOutputWidth.Should().Be(3840u,
"a watchdog killed with its process leaves the lock odd for good; what it published before still stands");
ring.Advanced->Seq = 4u;
reader.AdvancedState.Should().BeOfType<FlAdvancedState>().Which.DlssOutputWidth.Should().Be(2560u);
}
[Fact]
public unsafe void PauseAndResumeBothLandInTheControlBlock()
{