FrameLedger.NvapiBridge.dll - loaded by the Agent into its own process, never into a game - gains five reads. Nothing composes them yet: no Agent code calls the reader, so no behaviour changes. - Native (fl_nvapi_bridge.h/.cpp, ABI 3, additive): FlNvReadFacts (the card's type, bus, PCI ids, VBIOS, architecture, core counts, base and boost clocks, memory sizes, the driver's package, the chipset), FlNvReadLive (free video memory with evictions and promotions, the frame-buffer / video / bus utilisation, video clock, P-state, board and power-supply temperatures, the throttle word, encoder statistics), FlNvReadDisplays (HDR formats and luminances, variable refresh, adaptive sync per connected display), FlNvSessionDisplay (one display's variable-refresh state and one process's colour space) and FlNvProfileSettings (every setting of the global profile, or what a game's own profile sets). Each struct carries its size and a present mask; a clear bit is N/A, never 0. No ABI 2 struct changed size, and FL_NV_FIELD_VRAM stays clear, so which layer fills vram_adapter does not change. - No identifier has an entry point (D104): no board serial, unique id, EDID, or list of encoding programs. A display is passed on by its place in the list, never by NVAPI's handle. - tools/nvapi-readonly-check.ps1 (D108), wired into build.ps1: every NvAPI_* call of the bridge's source is on tools/nvapi-allowed-calls.txt and every name there is called - forty-four - and a name that sets, saves, restores, registers or controls, or returns an identifier, is red even when the list names it. Seventeen self-test cases, both directions; the self-test caught two holes in the rule as first written. - Managed: mirrors of the five structs, INvapiAdvancedBridge (a port of its own; a DLL that predates ABI 3 answers Unavailable, never throws), NvapiAdvancedReader (the structs become the catalog's facts and readings - every nvapi. entry of the Agent's reach and no other, held in both directions) and Application.Advanced's value model: a fact is a number, the vendor's words, our own tokens the App will translate, or rows; one that was not read is absent. - Measured the day it was written (ctest fl_nvapi_bridge, AVAILABLE branch, RTX 5080): all twenty facts answer; eight of ten live groups - the card has no board or power-supply temperature sensor; the display answers its four groups; the global profile lists 24 settings. 20_OPEN_QUESTIONS M12 is half answered, with what is still open. - The vendored nvapi.h misspells NV_ENCODER_STATISTICS_VER; the bridge names NV_ENCODER_STATISTICS_VER1. - Fixed from #387: Qodana's one result, a redundant "!" in AdvancedMetricCatalogTests. - docs: 18_GPU_VENDOR_APIS (ABI 3, the gate), 12_BUILD (gate 14e), CLAUDE.md, CHANGELOG. Hook overhead: not applicable - nothing in code loaded into a game changes (Overlay, VkLayer, Shm, Injector untouched). Gate on the dev box: all passed in 301 s (native 32/32). Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
151 lines
5.3 KiB
C#
151 lines
5.3 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using FrameLedger.Infrastructure.Telemetry;
|
|
|
|
namespace FrameLedger.Infrastructure.Tests.Telemetry;
|
|
|
|
/// <summary>A scripted <see cref="INvapiAdvancedBridge"/>: what each ABI 3 read answers. A read left null answers a status.</summary>
|
|
internal sealed class FakeNvapiAdvancedBridge : INvapiAdvancedBridge
|
|
{
|
|
/// <summary>What a read with nothing scripted answers: <c>FL_NV_NOT_INITIALISED</c>.</summary>
|
|
public const int NotAnswered = -1000;
|
|
|
|
public NvapiFacts? Facts { get; set; }
|
|
|
|
public NvapiLive? Live { get; set; }
|
|
|
|
public NvapiDisplays? Displays { get; set; }
|
|
|
|
public NvapiSessionDisplay? Session { get; set; }
|
|
|
|
/// <summary>The global profile's list and entries, answered for a null path.</summary>
|
|
public (NvapiProfileList List, NvapiProfileEntry[] Entries)? GlobalProfile { get; set; }
|
|
|
|
/// <summary>What a path's own profile answers.</summary>
|
|
public (NvapiProfileList List, NvapiProfileEntry[] Entries)? GameProfile { get; set; }
|
|
|
|
public List<string> Calls { get; } = [];
|
|
|
|
public int ReadFacts(out NvapiFacts facts)
|
|
{
|
|
Calls.Add("facts");
|
|
facts = Facts ?? default;
|
|
return Facts is null ? NotAnswered : 0;
|
|
}
|
|
|
|
public int ReadLive(out NvapiLive live)
|
|
{
|
|
Calls.Add("live");
|
|
live = Live ?? default;
|
|
return Live is null ? NotAnswered : 0;
|
|
}
|
|
|
|
public int ReadDisplays(out NvapiDisplays displays)
|
|
{
|
|
Calls.Add("displays");
|
|
displays = Displays ?? default;
|
|
return Displays is null ? NotAnswered : 0;
|
|
}
|
|
|
|
public int SessionDisplay(string gdiDeviceName, uint pid, out NvapiSessionDisplay display)
|
|
{
|
|
Calls.Add($"session-display {gdiDeviceName} {pid}");
|
|
display = Session ?? default;
|
|
return Session is null ? NotAnswered : 0;
|
|
}
|
|
|
|
public int ProfileSettings(string? exePath, bool ownOnly, out NvapiProfileList list, out IReadOnlyList<NvapiProfileEntry> entries)
|
|
{
|
|
Calls.Add($"profile {exePath ?? "(global)"} own={ownOnly}");
|
|
(NvapiProfileList List, NvapiProfileEntry[] Entries)? scripted = exePath is null ? GlobalProfile : GameProfile;
|
|
list = scripted?.List ?? default;
|
|
entries = scripted?.Entries ?? [];
|
|
return scripted is null ? NotAnswered : 0;
|
|
}
|
|
|
|
/// <summary>Every field of <c>FlNvFacts</c> present — the bridge's answer on the dev box's RTX 5080, 2026-11-11.</summary>
|
|
public static NvapiFacts FullFacts() => new()
|
|
{
|
|
Present = 0xFFFFF,
|
|
GpuIndex = 0,
|
|
GpuCount = 1,
|
|
GpuType = 2,
|
|
SystemType = 2,
|
|
External = 0,
|
|
BusType = 3,
|
|
PciDeviceId = 0x2C0210DE,
|
|
PciSubSystemId = 0x41961458,
|
|
PciRevisionId = 0xA1,
|
|
ArchId = 0x1B0,
|
|
ArchImplementation = 0x3,
|
|
ArchRevision = 0xA1,
|
|
CoreCount = 10752,
|
|
RtCores = 84,
|
|
TensorCores = 336,
|
|
RamBusWidth = 256,
|
|
DriverFlags = 0x5,
|
|
ClockBaseCoreMhz = 2295,
|
|
ClockBaseMemoryMhz = 15001,
|
|
ClockBoostCoreMhz = 2670,
|
|
ClockBoostMemoryMhz = 15001,
|
|
TempDefaultMaxC = 150,
|
|
FbPhysicalKb = 16666368,
|
|
FbVirtualKb = 16694272,
|
|
VramDedicatedBytes = 16303UL << 20,
|
|
VramDedicatedAvailableBytes = 15979UL << 20,
|
|
VramSystemBytes = 0,
|
|
VramSharedBytes = 16300UL << 20,
|
|
Vbios = "98.03.6c.00.68",
|
|
BaseBranch = "R620",
|
|
InterfaceVersion = "NVidia Complete Version 1.10",
|
|
ChipsetVendor = "Intel",
|
|
ChipsetName = "Intel-RaptorLake",
|
|
};
|
|
|
|
/// <summary>Every field of <c>FlNvLive</c> present, including the two temperatures the RTX 5080 does not have.</summary>
|
|
public static NvapiLive FullLive() => new()
|
|
{
|
|
Present = 0x3FF,
|
|
VramAvailableBytes = 14714UL << 20,
|
|
VramDedicatedAvailableBytes = 15979UL << 20,
|
|
EvictionsBytes = 89UL << 20,
|
|
EvictionCount = 184,
|
|
PromotionsBytes = 3UL << 20,
|
|
PromotionCount = 1,
|
|
LoadFramebufferPct = 1,
|
|
LoadVideoPct = 0,
|
|
LoadBusPct = 3,
|
|
ClockVideoMhz = 2295,
|
|
TempBoardC = 41,
|
|
TempPowerSupplyC = 47,
|
|
Pstate = 0,
|
|
ThrottleReasons = 0x08,
|
|
EncoderSessions = 1,
|
|
EncoderFps = 60,
|
|
EncoderLatencyUs = 4200,
|
|
};
|
|
|
|
/// <summary>Two displays: an HDR adaptive-sync one answering everything, and one that answered nothing.</summary>
|
|
public static NvapiDisplays TwoDisplays()
|
|
{
|
|
var displays = new NvapiDisplay[NvapiDisplays.MaxDisplays];
|
|
displays[0] = new NvapiDisplay
|
|
{
|
|
DisplayId = 0x80061082,
|
|
Present = NvapiDisplay.HasHdr | NvapiDisplay.HasCaps | NvapiDisplay.HasVrr | NvapiDisplay.HasAdaptiveSync,
|
|
Active = 1,
|
|
HdrFlags = NvapiDisplay.HdrSt2084 | NvapiDisplay.HdrHdr10Plus | 0x0A,
|
|
LuminanceMax = 417,
|
|
LuminanceMinTenThousandths = 698,
|
|
LuminanceMaxFrameAverage = 391,
|
|
CapsFlags = NvapiDisplay.CapsVrr | NvapiDisplay.CapsVrrNow,
|
|
VrrFlags = NvapiDisplay.VrrEnabled,
|
|
AdaptiveSyncFlags = 0,
|
|
MaxFrameIntervalUs = 0,
|
|
};
|
|
displays[1] = new NvapiDisplay { DisplayId = 0x80061083, Present = 0, Active = 0 };
|
|
return new NvapiDisplays { Count = 2, Displays = displays };
|
|
}
|
|
}
|