Skip to content

Migrate the ReScaleFrame runtime and integrations to Rust - #6

Draft
NightHammer1000 wants to merge 2430 commits into
mainfrom
rust/orchestrator-anomaly
Draft

NightHammer1000 wants to merge 2430 commits into
mainfrom
rust/orchestrator-anomaly

Conversation

@NightHammer1000

Copy link
Copy Markdown
Contributor

Summary

  • Move first-party Runtime and integration ownership into Rust across the core, Anomaly, and the in-tree game and engine adapters. Keep typed SDK, COM, and fault-guard calls behind the native boundary.
  • Preserve the public plugin C ABI and both DLL and linked consumers. The branch includes fixes for Streamline signature resolution and checked shutdown, plus the Vulkan FSR4 fixture table repair.
  • Pin 9f53f1b0 as the source candidate. Head 894a55f9 adds the verification record.

Verification

Pinned Rust formatting, locked offline Cargo metadata, source public-header and carrier-definition comparisons, and whitespace checks passed. Native builds and runtime checks are pending for this candidate.

  • Build the DLL and linked consumers with matching SDK features and compare binary exports, ordinals, forwarders, and linkage.
  • Run focused fixtures and record device results separately.
  • Compare Standard and AVX Anomaly with the C++ baseline for rendering, presentation, held input, overlay handoff, fallback, resize, and explicit plugin retirement.

Candidate verification record · Implementation tracker · C++ Anomaly baseline

@NightHammer1000
NightHammer1000 force-pushed the rust/orchestrator-anomaly branch 2 times, most recently from 4b24cdc to d828647 Compare November 22, 2026 20:26
… codes, on ac7-render-scope

The result-code import swap moved the cfg onto the backend_result line, so the featureless archive (and cargo clippy without --all-features) failed: rsf_ac7_plugin is an optional dependency, and the shared surface checks use ABI_MISMATCH and INVALID_ARGUMENT in every build.
rsf_overlay_d3d12_frame_for_window lost its export and with it the extern exemption from too_many_arguments; it takes the allow its neighbours use. resolve_backend reads the startup service with ? as clippy::question_mark asks.
motion/device_fixture/draw.rs reads back through sr_fixture_readback, which was gated on sr-fixtures alone. The module is self-contained and its imports are in motion-device-fixture's feature set, so it builds under either feature.
tools/exposure_probe created its NVIDIA-adapter device by hand; it calls d3d11_device_on and takes rsf-test-support. The Anomaly FG fixture's chosen-adapter swap chain calls a new d3d11_swapchain_on, which d3d11_swapchain forwards to as d3d11_device does to d3d11_device_on. The other setups the PORT.md review named already used d3d11_device_on; T9 is checked off.
fg_choice_main.c existed only to hand rsf_fg_default_backend's address to a fixture in rsf-generation-fixtures, which does not depend on the orchestrator; the function is Rust. The persistence and vendor-default checks are fg_choice.rs unit tests over the same entries, on a TemporaryIni. The launcher, tests/generation/src/choice.rs, the rsf_fg_choice_test target and the two windows-sys features only it used are gone.
Products had one production implementation, AuxiliarySr, and one test fake. d3d11_host_reduced::Products is now a type alias, AuxiliarySr in builds and d3d11_host::tests::FakeProducts under cfg(test), and the host calls inherent methods. The trait's bool contract is a second impl AuxiliarySr block; the owner's Option-returning reservation is renamed reserve_frame and refine takes the surface limit itself. Under test the host reaches the fake, so the host-only owner methods allow dead_code there. The auxiliary SR device fixture calls the owner's methods directly.
Seven platform fakes (tick, dlss_preset_valid, sr12_destroy, fg_submitted, fg_hudless, fg_window, present_request) and the with/event/events helpers were text-identical in callback_host/tests.rs and render_host/tests.rs. host_test_fakes! emits them once per module against that module's own World and WORLD, whose fields and defaults differ.
The Godot, Steam and Unity records built from Default::default() and then assigned field by field (clippy::field_reassign_with_default) now use struct literals with ..Default::default(); two lock_or_recover calls lose a needless borrow; tests/vulkan_gpu.rs names both transmute types, transmuting straight to rsf_vk_get_proc.
…tance

bc63495 wrote it as checked(record).is_some_and(allows_sr). That Option::is_some_and instance goes to a shared generic codegen unit, which the linker pulls from every Rust archive for its other instances, and it references the archive's own allows_sr, whose object carries the three no_mangle frame-policy exports. ReScaleFrame.Game.Anomaly.dll links rsf_anomaly_plugin_rust and rsf_graphics_rust, so it got them twice (LNK2005). The let-else form its two siblings use keeps the call in frame_policy's own unit.
rustfmt over the eleven orchestrator files the D3D12 FG and SR rounds left unformatted; the Unity editor-plan test builds its packet as a struct literal (field_reassign_with_default) and the Anomaly half decode passes half itself (redundant_closure).
clippy::redundant_field_names on capture_parameters and preset_valid, from the simp-vk-rest round.
package.cpp called the Runtime, bridge and Win32 functions by name. The
port kept a unit Leaves struct whose methods only forwarded to raw::*, a
LOADED flag left from the adopted platform table, and C-shaped Win32
leaves (out-parameters, 0/1 words) between two pieces of Rust. Callers
now use raw::* directly (still the test fakes under cfg(test)), the
Win32 leaves take and return Rust values, and the exports no longer
refuse before plugin load, as the C++ did not. The routing test of the
removed load gate is gone; the export test expects the waiting-device
BUSY instead of the unloaded FAILED.
rsf_unity_frame_admission and rsf_unity_source_submission were C typedefs
in bridge_state.h that no C file reads; only bridge_state.rs and
bridge_d3d12.rs pass them. They are Rust structs now, and the receipt
compares with PartialEq instead of a field-by-field helper.
vulkan_bridge.cpp's intercept() compared four names and returned the
interceptor. The port built a nine-slot interceptor table, published it
through a bind that refused incomplete tables (the table is a constant
built one line earlier), and tested that routing machinery. resolve()
now matches the name directly and the installed hooks keep only Unity's
instance resolver; device commands still resolve their continuation from
the supplied device, the dispatch-owner fix. The tests of the slot table,
bind and the cached-original helper are removed; the extension, merge
and interop-lookup tests stay.
The shared device's creation went Rust -> rsf_uvk_foreign_create_device
(C) -> rsf_uvk_bridge_create_device (Rust) only to hand back the two
guarded loader lookups as untyped function pointers, which Rust then
transmuted three times. The C leaf now exports the guarded lookups and
Rust calls them by name. With that the device, command-slot and image
handle records no longer cross C: vulkan_state.h is gone and the records
are Rust structs. The GPU leaves only vulkan_state and vulkan_bridge call
take references and return the swap chain extent instead of raw pointers
and out-parameters, and vulkan_foreign.h loses five declarations of
functions that no longer exist as C entries.
DeviceHandles and CommandSlot in d3d11_state.rs never cross C, yet kept
repr(C) and offset asserts from the retired native header. The Proof
alias and waiter() were view() under other names. The D3D11 graphics
leaves only the owner calls take references instead of raw pointers and
dereferencing them again inside.
lifecycle_refuses_short_and_foreign_structures exercised
rsf_game_sys::call_header::validate, which this crate only calls.
package.c kept a C leaf only to call the header-only rsf_dlss_preset_valid,
and the Rust tests faked it. The Mono plugin already checks
RSF_DLSS_PRESET_MASK directly; the package does the same, and the
configure transcripts lose the fake's preset call.
The C++ render hooks held one thread-local World. The port moved it into
render_hooks.c and reached it from Rust through five partial World views and
leaf tables (scope, producer, publication, imagespace, recovery), with a C
NativeInputs lease moved between Rust and C. The World and its COM
references now live in render_hooks.rs; render_hooks.c keeps the typed
detours, their trampolines and the guarded Runtime calls. Render inputs,
depth domains, resolution, screen and CPU identity are called as Rust
functions instead of C exports.

The fixed defects stay: Effects admission carried to its return, RETIRE
reporting whether the token is gone, a finished token retiring without a
repeated FINISH, the failed output restore in the UI_RESTORED receipt and
the retired resolution scope retry at World admission. The fake-leaf seam
tests go with the leaf tables.
The FidelityFX WSI dispatch, Streamline NGX dispatch, Streamline selected-device and vendor
census layout tests check C and C++ vendor headers. The port had split each into a C or C++
shim that re-exported the header through uintptr_t entries or a visitor callback, a fixture
header, bindgen output (committed for the WSI one) and a Rust scenario behind a Cargo feature.
Each is again one file as on main, with the checks the port added kept: the WSI test's return
value and queue checks, the Streamline first-use layout cases (from the deleted
sdk-fixes/dispatch-tests.cpp) and the DLSS-G options layout include.
rsf_d3d11_host_rendered_fg_device named rsf_d3d11_host_device_fixtures_rust, a target that no
longer exists since the presentation fixture archives were merged; the archive that carries the
d3d11-host-device-fixtures feature is rsf_presentation_d3d11_host_device_rust.
overlay_native12 and overlay_wrapped12 reached their own D3D12 and D3D11-on-12 calls through
Platform tables of extern C functions with raw-pointer records (FrameTable, Draw, DrawCall,
Target, Interop, WrappedTarget), as overlay_native12_platform.h had during the port. As in
overlay_native12.cpp and overlay_d3d12.cpp, each owner now holds windows-crate references and
calls D3D12 directly; overlay_wrapped12 calls the overlay host's Rust admit, draw, start and
stop functions instead of four extern C wrappers. The fixture tests of the tables go; the ring,
fence-event and retry-gate tests stay. Kept: failed-owner retirement on the original queue, the
retry gate, empty-draw skips, elapsed normalization and the armed-event retention.
A RECONFIGURE pass only plans and always keeps the engine's evaluation, so each one flipped the on-change 'SR host dispatch' line to 'native evaluation retained' and back. The render plan line reports plans; the dispatch line now follows evaluations only. Needed by the RDR2 plan requests (docs/research/rdr2-renderer.md, 28 November); Skyrim's planning passes no longer flip it either.
The decrypted 1.0.1491.50 image shows the settings manager's own tick (+2c8976c, now the discovered 'settings tick' site) running its stage machine inside the CRITICAL_SECTION at manager+3b8 and reconfiguring at stage 8; the game's apply refuses stages 0x177. ScriptHook only supplied a periodic game-thread caller. The plugin's latency-sleep hook, called by the game's frame function after SIMULATION_START, now drives the ASI's settings owner through an export each frame; it polls the saved quality every 250 ms and pins the pending owner and requests the reconfiguration under TryEnterCriticalSection. The plugin also asks the core for the selected backend's plan with a RECONFIGURE pass and publishes it; once settled, the DLSS optimal-table and FSR2 dimension hooks render at it. Unit tests cover the plan settling, stage gating, retry backoff and the reconfigure pass; discovery resolves every site in the dump. Not game-tested. See docs/research/rdr2-renderer.md, 28 November.
A Present is attributed to a source only inside an adapter WINDOW scope, so
a predecessor presented without one never recorded an outcome and its
reserved successor waited for it until the 100 ms bound. In the installed
SkyrimSE.exe the main tick presents the predecessor (render 0x6565b0 at
0x659319, Present inside the renderer end 0x1009f70) before it joins the poll
job at 0x65932f, so the outcome is knowable in time. A completed Present on
the owned chain that no window scope attributes now records every source
begun before it as presented without one (UNVERIFIED), and both the
reservation join and the previous-Present join read that fact. The successor
stops waiting at once and is refused pacing; the 120-join pause is removed.
The 100 ms bound and its log line remain for any other missing outcome.

Only Skyrim and Fallout 4 reserve sources; AC7 and Anomaly report keyed
INPUT_SAMPLE frames and use the previous-Present join. Research:
docs/research/skyrim-prospective-source-20261115.md.
Checks: unit tests of the reservation book and the join; the
native_fg_cpu_contract fixture with a new case, run through a temporary cargo
wrapper; clippy -D warnings with and without fixture-leaves. No game run.
The step that re-entered the World on the new presentation owner is not
identified from the binaries: in Fallout4.exe the window procedure 0xc3a5f0
reaches only the raw-input Keyboard and Mouse hooks within five direct calls,
and ENB's d3d11.dll holds no static reference to a hooked function. The first
refusal now also logs the calling thread's return addresses as module+offset,
so the next run names the path that re-entered.

Research: docs/research/rust-fallout4-render-hooks.md.
Checks: unit test of the refusal and the stack text; clippy -D warnings. No game run.
rsf_game_render_config::unjittered() is true for an enabled plan with one
phase (FSR1): an integration whose engine jitters by itself clears that
jitter. Without a plan the engine keeps its own sampling, which jitters()
alone cannot tell apart. RDR2 and Fallout 4 act on it.

Checks: cargo test -p rsf-game-sys --lib (31 passed; the plan test asserts
unjittered() for FSR1, a temporal plan, no plan and the request record).
With FSR1 selected the views keep FXAA and are not jittered (views.rs), but
the native graph refused every view without jitter (graph.rs make_plan,
has_jitter), so the engine's own scaling presented the frame and the core
FSR1 pass never ran. The graph now admits an unjittered view when the plan's
backend takes no jitter (jitter_admitted); a temporal backend still needs a
jittered view. The SR node sits at the tonemapper's input, so FSR1 and the
shared sharpening run there and FXAA, the reviewed AA role between the root
and the tonemapper, stays on after them. Velocity still renders without TAA
through the temporal velocity patch at ShouldRenderVelocities 0x118a4e3
(patches.rs; docs/research/ue418-hook-map.md). Translucency mesh scopes keep
their jitter gate: FSR1 reads no translucency mask.

Evidence: native views run AntiAliasingMethod 1
(docs/research/ac7-renderer-roots-20260930.md); the walk accepts only
reviewed pass roles (RSF_AC7_ROLE_AA among them) up to the tonemapper.

Checks: cargo test -p rsf-ac7-plugin --lib (26 passed, new
fsr1_admits_the_unjittered_view_and_a_temporal_backend_does_not); clippy
clean. Not game-run.
RDR2's jitter comes from the game's own DLSS/FSR2 mode, which the adapter
keeps as its input carrier. Read in the decrypted 1.0.1491.50 dump
(dumps/rdr2-20261025, capstone): the pixel-jitter setter +26f7b1c stores the
pair at viewport +0x664/+0x668 and rebuilds the projection; of its 17
callers only +31828f and +5fe1ce pass a non-zero pair. +31828f takes it from
the generator +5a6a38, which zeroes its result and then copies the current
sample of the active DLSS state (0x45913a0, +7bf05c), else FSR2 (0x4591a60,
+7bf0b4), else TAA (0x3f28fe0, +7bf104). The same result reaches the
upscaler evaluate at +5c7c57. A mode switch cannot remove the jitter without
losing the carrier, so the adapter hooks the generator (new "camera jitter"
site, unique in both dumps) and writes zero when the host's plan is
unjittered (rsf_game_render_config::unjittered). Projection and carrier
parameters stay unjittered and in agreement, which the camera decode's
projection/NGX jitter check requires. Each change is logged: "RDR2 camera
jitter off: the selected backend takes no jitter (FSR1)."

The hunks stay out of the parts of scene.rs another worker changes (sleep).
Research: games/rdr2/RESEARCH-HANDOFF.md, the jitter generator row and note.

Checks: cargo test -p rsf-rdr2 --lib (36 passed; the dump test resolves the
new site at its recorded RVA 0x5a6a38); clippy clean. Not game-run.
Under FSR1 the engine kept jittering while RSF excluded its TAA. Read in the
installed 1.11.240.0 Fallout4.exe (capstone): the temporal update +182d580
writes the TAA jitter to State+4/+8 (0x3d871a4) from an 8-phase Halton index
when State+ac (0x3d8724c, the flag the TAA query +2214fc0 also reads) is set
and State+b0 is clear, and zero otherwise. It is the last call of WorldBegin
+21f0ac0 (at +21f0e4c). The camera cache updates (+21f32a5...) run builder
+182d750 later, which adds that jitter to P only with State+ac and the
entry's useJitter byte set, and the TAA effect reads the pair (+2214b73,
+2218c4b).

The WorldBegin detour now calls rsf_fallout4_render_after_world after the
admitted ordinary original, which clears State+4/+8 when the host's plan is
unjittered (rsf_game_render_config::unjittered). The offset is the one the
verified temporal size site stores (movss [rdi+4], xmm7; movss [rdi+8],
xmm3). The temporal update writes the pair again every frame, so a temporal
plan simply stops clearing it. Each change is logged: "Fallout4 camera
jitter off: the selected backend takes no jitter (FSR1)." The site named
"jitter store" (+165ba9f) is frame-delta bookkeeping, not jitter.

Native TAA stays excluded while RSF owns the output (render_hooks.rs gate):
it runs in image space after the reconstruction seam, so keeping it under
FSR1 needs a later seam (docs/implementation.md).

Checks: cargo test -p rsf-fallout4 --lib (29 passed, including the
installed-executable discovery test); clippy clean. No new unit test: the
decision is the SDK fact, the write goes to the discovered State. Not
game-run.
Adds the 29 November follow-up to the FSR1 entry: the AC7 graph admission,
the RDR2 jitter generator, Fallout 4's temporal update and WorldBegin order,
and Skyrim SE's process function (+14edbf0: effects, then 0x1e/0x22, then
native TAA +1544da0 at +14eddbf). Skyrim needs no code change: jitter is
already zero for one phase, and native TAA cannot stay on at its current
seam because the output scope sets the ratios to 1 before that function
while motion and history are render-scale. Skyrim SE and Fallout 4 keep no
engine AA under FSR1 until an FSR1 seam after image space exists.

Method: targeted capstone disassembly of the installed (RDR2: dumped)
executables around sites the adapters discover; the REA, Ghidra and IDA
servers were unavailable.
…read

An FSR or XeSS context is created for one output and quality. A resize
built the new-size adapter in resize_output and a quality change
recreated the vendor context in set_quality, both on the render thread,
and the next evaluate rebuilt the vendor pipelines there: the same
first-use cost the backend switch had, and a long one on a cold cache.

Both now go through the preparation that a switch uses. One function,
pursue, makes a backend at the wanted output and quality the target for
select, set_quality, resize_output and start: OK when it is what serves
(abandoning anything else), PENDING while it is prepared, the refusal
when exactly that was refused. A commit for another output brings its
cleared output texture with the adapter, so the output texture, the
status output and the context change together. A quality change keeps
the active context serving; a resize keeps the old output in the status
until the commit, so callers that require it to match keep SR out of
their frames instead of stalling. DLSS and FSR1 still change in the
call, and take the wanted quality on a switch. dlss_pipeline.h is ABI 7.

The D3D11 host and Anomaly accept a pending quality change; both already
repeat a resize until the status reports the new output.

Checks: cargo test -p rsf-orchestrator --lib (451 passed), cargo test
-p rsf-anomaly --features sr-fixtures --lib (170 passed, plus the
runtime fixture's lifecycle, start-refused and pending cases through a
temporary harness, removed), cargo clippy and cargo fmt on both crates.
Not game-run.
Both D3D12 hosts created their FSR and XeSS sr12 contexts on the engine's
recording thread, and the first sr12_evaluate built the vendor pipelines
on the engine's command list: the stall that ended the AC7 run, on RDR2
and Unity.

render_host/prepare.rs creates the context on a worker with its own copy
of the vendor directories and warms it with Sr12::warm_up: one dispatch
through the session on a queue of its own, through the same
sr_bridge::dispatch_warm_up the D3D11 bridge uses, waiting until the GPU
has retired it. It runs on sr_prepare, so ownership, abandonment and the
queued log lines work as for the D3D11 pipeline; both hosts' log
callbacks queue a worker's lines.

The RDR2 host keeps evaluating with its current context while the new
one is built, commits at the first pass whose slots are drained, keeps
the current context after a refusal and does not retry that key, and
publishes a RECONFIGURE plan when a planned context commits. The Unity
callback host already turns SR off and drains while a change applies;
it now builds the first view's context on a worker, and later views one
at a time, publishes the plan at commit (Unity reads it every frame in
GetResolutionInfo) and drops a context finished for a configuration a
change has replaced. DLSS, FSR1 and backend zero are still created in
the call.

Checks: cargo test -p rsf-orchestrator --lib (453 passed), cargo clippy
--all-targets and cargo fmt. Not game-run.
The Vulkan host retired its session and opened the new one inside the
engine's SR pass. FidelityFX Vulkan builds its pipelines when its effect
is created, and the FSR4 split built them at its DX12 bridge's first
dispatch, so a switch stalled Godot's rendering thread.

FSR and XeSS sessions are now opened on a worker through sr_prepare while
the current session keeps serving its device and output; the new one
takes over at the first pass after it is open, once the current one has
retired after its frames. A refused request keeps the current session
and is not tried again. The FSR4 split owner warms its bridge as it is
created: rsf_fsr4_compat::vulkan_bridge::warm_up records one dispatch on
blank images on the bridge's own queue and waits on its local fence, so
the host's shared timeline is untouched.

A Vulkan device holds no reference a worker could keep, so nothing is
abandoned here: a superseded preparation waits in a list and is closed
when its worker finishes, and stop or a device change waits for every
worker (Preparation::wait). Godot reads the host's status extent every
frame and so renders at the serving session's size until the commit.
DLSS stays on the recording thread.

Checks: cargo test -p rsf-orchestrator --lib (453 passed), cargo test -p
rsf-fsr4-compat, cargo clippy --all-targets with fsr4-vk and ffx-vk, cargo
fmt. The host opens sessions through linked::open with no unit-test
seam; the FSR4 state fixture needs its CMake harness and was not run.
Not game-run.
The full-size crash frame could not enter the auxiliary route. Keep the texture lease through planning, FG notification and evaluation, then verify the same source before publishing. Research and dispatch evidence are in docs/research/rust-fallout4-render-hooks.md. Windows check, crate tests and Clippy passed.
The installed executables route reduced imagespace colour through a final scaler after TAA. Fallout constructs its upsample effect but its PC active predicate returns false. Keep the engine sampling through these passes, substitute EASU at the native draw and retain the original scaler on refusal. Native, FXP and test evidence is in docs/research/bethesda-native-aa-spatial-20261129.md.
Follow the pinned SDK threading and viewport contracts documented in docs/research/streamline-sr-preparation.md. The Windows workspace tests cover supersession, allocation refusal, retained views and deferred GPU retirement.
Build the relocated bridge, real panel and backend switch fixtures together. The RTX 4070 Laptop results and cold first-evaluation limits are recorded in docs/research/streamline-sr-preparation.md.
Both installed Bethesda proxies return inline array storage even with a zero class count. Preserve the wrapper shader identity and read actual linkage from the device context when present. Native analysis and the two different paths to snapshot retirement are recorded in docs/research/bethesda-first-world-av-20261129.md.
The shared viewport also serves generation, so a source without a CPU token uses a pinned graphics-only SDK slot. Preserve exact frame ownership for markers and retry transient token refusal without tripping the vendor failure limit. The source 387 trace, six-handle SDK contract and fake tests are in docs/research/bethesda-first-world-av-20261129.md.
Acquire the output scope before the host may publish, balance it independently of pending auxiliary cleanup, and trace the actual imagespace continuation. The fake refusal and installed native-size branch are described in docs/research/bethesda-first-world-av-20261129.md.
A reentrant callback may invalidate the World between evaluation and commit. Restore only the matching output and auxiliary scope, and report both sides of each first-world retirement boundary. See docs/research/bethesda-first-world-av-20261129.md for the native path and source-replacement check.
Install the observer from the runtime that owns the process graphics session and remove it on unload. Preserve native exception dispatch and append complete carrier receipts. The native and synthetic evidence is in docs/research/bethesda-first-world-av-20261129.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant