diff --git a/builder/linux/hookshot-folder b/builder/linux/hookshot-folder index e8095bd..c9a0729 100755 --- a/builder/linux/hookshot-folder +++ b/builder/linux/hookshot-folder @@ -38,6 +38,9 @@ if [ -n "$run" ]; then fi for game in bin/triforce bin/hookshot; do if [ -x "$HERE/$game" ]; then + # ((Triforce, 11-23) the log into triforce_log.txt whatever stderr is (Steam's pipe, a terminal, ~/.xsession-errors), + # as the launcher's Play does. HOS_LOG_FILE=0: stderr, as before) + export HOS_LOG_FILE="${HOS_LOG_FILE:-1}" cd "$HERE" exec "./$game" fi diff --git a/builder/linux/hookshot-launch b/builder/linux/hookshot-launch index dd7366c..ce093f4 100755 --- a/builder/linux/hookshot-launch +++ b/builder/linux/hookshot-launch @@ -64,6 +64,9 @@ done cd "$folder" # (--play already chose Play. The game's own update question stays for a bin/triforce the player started themselves) export HOOKSHOT_NO_UPDATE_CHECK=1 +# ((Triforce, 11-23) the log into triforce_log.txt whatever stderr is (a terminal, a pipe, ~/.xsession-errors), as the +# launcher's Play does: the game writes its log file only when stderr is none. HOS_LOG_FILE=0: stderr, as before) +export HOS_LOG_FILE="${HOS_LOG_FILE:-1}" for game in ./bin/triforce ./bin/hookshot; do if [ -x "$game" ]; then exec "$game" diff --git a/docs/development.md b/docs/development.md index 7d0fb42..4bfade1 100644 --- a/docs/development.md +++ b/docs/development.md @@ -83,7 +83,7 @@ screen. It costs some GPU time on cards that cull quickly, so it is off unless s | `HOS_AUDIO=0` | No sound device is opened (the mixer still runs); `scripts/run-vk.ps1` sets it unless `-Sound` | | `HOS_AUDIO_EFFECTS=0` | The game's plain reverb, delay and biquad filter effects on its mixes and its splitter destinations' biquad filters are accepted and left out, as before they were emulated (the sound unfiltered and at full level: the "Volcano eruption audio bugged" ticket); the I3DL2 reverb still runs. By default they run on the mix buffers in the order the game added them (`host/nn_audio.c` "mix effects"; `tests/test_audio_mix_effects.py`) | | `HOS_LANGUAGE=` | The game's language for this run, a code from `language.txt` | -| `HOS_OUTPUT_RES=<0..3>`, `HOS_HANDHELD=1`, `HOS_ASPECT=` | Over the options file: the output resolution (0 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080), the handheld profile, a picture wider than 16:9 (2.3889 for 3440x1440; the Ultrawide row's 21:9 is 2.3704, 64:27, and its 32:9 3.5556) | +| `HOS_OUTPUT_RES=<0..8>`, `HOS_OUTPUT_SIZE=x`, `HOS_HANDHELD=1`, `HOS_ASPECT=` | Over the options file: the output resolution (as `output_res` below), Custom's size (as `output_width` and `output_height`), the handheld profile, and the picture's shape whatever the Output resolution and the Ultrawide row say (a ratio, width over height: 2.3889 is 3440x1440's; the picture is the output's height in that shape, kept to 3840x2160's pixels). The Insert menu shows `HOS_OUTPUT_SIZE` and `HOS_ASPECT` in the rows they set, which then have nothing to choose | | `HOS_DYNRES=0`, `HOS_REALTIME_STEP=0`, `HOS_TEXT_SPEED=<0..3>` | Over the options file: Resolution 100% (non-zero: Auto), Game speed Per frame (1: Real time), Text speed | | `RX_VK_FIRST_START_AUTO=1`, `RX_VK_FIRST_START_AUTO=` | (Triforce, 11-22, the performance audit's PRESENT-46, after Source A's; off by default) A first start sized to the card: with no options file, `RX_VK_LOW_SPEC` not asked and `HOS_DYNRES` not set, a weak card starts with the Render resolution row at 50% in place of Auto, or at 33% for an integrated GPU beside 4 processor threads or fewer (`gpu/vk/first_start.h`, `gpu/vk/vk_menu.cpp` `menu_first_start`, called from `mkwvk_init` once the device is made). Weak is Source A's tier 1: an integrated GPU (a handheld's is one; the `SteamDeck` variable is not read, it took desktops for handhelds), a card without mesh shaders, or 4.5 GB of video memory or less. Only that row is set: the upscaler, the textures and the output stay, and nothing is saved, so each start chooses again until the player saves options. A number over 1 plays a card of that many MB (the lab: `=4096` on a large card). Not set or `=0`: as before. Off until the owner decides what a first start on a weak card gets; unmeasured (Source A states no gain and tried it on one RTX 4070 Ti). One `menu: first start:` line says the choice | | `HOS_STEP_STEADY=0` | (Triforce, on by default since the lab's A/B; `=0` the mean of the last five as before) The game's real-time step kept steady, after NX2navi's steady step (`host/step_steady.h`, `host/nn_vi.c` `realtime_step`): the mean of the last 12 present intervals without their longest and shortest in place of the mean of the last five (`HOS_REALTIME_WINDOW`), the paced period itself where that mean is within 3% of it, and what the display showed and the game was not given repaid at a 64th a frame, 10% of the step at most (a quarter second owed at most). A cap the game holds steps it by the period exactly, and a hitch is paid back over most of a second instead of in the next five frames (a 50 ms frame at 240: 200 frames of at most 10% more, where the mean of five gave five steps of 13 ms). Game time still follows the clock | @@ -367,6 +367,7 @@ case-sensitive, and an unknown one is ignored. | `RX_VK_LAZY_PAYERS=<1..4>` | (Triforce, 4 by default; `=1` as before) How many of the lazy write-back's payments copy at once (`gpu/vk/wb_lazy_payers.h`, NX2navi's `wb_lazy_unlocked`). A payment's copy goes onto the queue after everything submitted so far and its thread waits for it (0.5 to 3 ms each in the owner's sessions, up to 21 ms at a load); with one at a time, a second thread that touched another owed page, or the replay giving a mirror up, waited for the first one's copy to come back before its own went onto the queue. Each payment holds a slot of its own (a command buffer and a fence); the pages of two payments are never the same ones (`gpu/vk/wb_lazy_state.h`), and each copy still goes onto the one queue after everything before it. The 600-submit line `vk: lazy write-back (600 submits)` ends with the payments that waited for a free slot and the most slots in use at once | | `RX_VK_GEN_SEED=` | The page write generations (`gpu/vk/write_gen.h`) start at `n` and not at 1 (decimal, or hex with `0x`; 2^62 at most). They are 64 bits; the 32-bit ones of earlier builds ran out after days of play, and textures and mirrors then kept old contents. `RX_VK_GEN_SEED=0xFFFF0000` takes a play test across 2^32 within seconds: the log says `the write generations start at` and, at the crossing, `this run has made 4294967296 write generations`, and nothing in the picture should change there | | `RX_VK_UPSCALE_OFF=1` | (Triforce) The upscaler Off for one run: the game's gameplay upscale networks are not dispatched, their input is stretched linearly into their output (`gpu/vk/upscale_off.h`). Softer than the networks below 100%; only while the game's own upscaler draws (DLSS and FSR take the dispatch first). Not set: as before, the networks run, and on cards that run them on software multiplies the first one is stood in for. The lab's `upoff` phases switch it within a run | +| `RX_VK_N64=<0..2>`, `RX_VK_N64_LINES=`, `RX_VK_N64_LOD=`, `RX_VK_N64_TV=0\|1`, `RX_VK_N64_MASK=<0..4>`, `RX_VK_N64_FPS=` | (Triforce) N64 Classic for one run, over the Insert menu's N64 Classic row and its Remembered page (`gpu/vk/n64_rules.h`, `gpu/vk/vk_n64.cpp`): 1 Faithful, 2 Remembered (its page's values), 0 off; unset, the row (F7 turns it on and off, but not while the switch is set). Its 3D pass takes every gameplay upscale network's place (`shaders/n64_3d.comp`): the 3D on a grid of 240 lines (480 for Remembered) as wide as the picture's shape, each grid pixel the mean of its footprint, Faithful's at 15-bit colour with the ordered dither, then out to the picture's size, linear along each line and hard between lines. While it draws, DLSS, FSR 3.1 and FSR 4 step aside (the game's own as far as they are concerned) and the game's SMAA is left out (`RX_VK_AA` still goes over that); not on a RenoDX run's RGBA16F scene. `RX_VK_N64_LINES` sets the grid's lines. (Step 3) The texture blur: the scene's tiled material textures sampled that many mip levels coarser (Faithful +2.5, Remembered +1.5, never past the card's `maxSamplerLodBias`), on the upscalers' scene-only path (not the shadow maps, the HUD or the output's passes); `RX_VK_N64_LOD=` over the preset's, `0` none. (Step 4) The TV at the window, in the filter's place at the window's own pixels, HUD and all (the FPS counter is drawn after it; the options' own screens go under it, below): the screen's curve, the composite colour bleed, the beam across 240 TV lines (wider where bright), the mask (Auto: the slot mask on a picture placed 1440 lines tall or more, none below), the glow from the picture at 1/8, the vignette; not on HDR Native's PQ picture, nor under DLSS frame generation, nor with `RX_VK_UPSCALE=0`. `RX_VK_N64_TV=0` leaves it out, `RX_VK_N64_MASK=<0..4>` (Auto, none, aperture grille, slot mask, shadow mask) picks the mask. (Step 7) The frame rate: Faithful 20, Remembered its page's Frame rate row; the renderer tells the host once a present (`HOS_OPT_N64_FPS`), which paces the game at it from the next frame, no restart (`host/n64_pace.h`, `host/nn_vi.c` `n64_pace_decide`): never above the Frame rate cap, never under 15, not while a movie plays, game time real time. `RX_VK_N64_FPS=` over both presets (0 the cap's); `HOS_N64_PACE=0` keeps the cap's whatever the renderer says. The log says `vi: N64 Classic: frames paced at` at each change. (Step 8) At F7 or a change of the row, half a second of the TV switching off and on (the picture squashed to a bright line, then a dot, and opened again), the 3D, the TV and the frame rate changing at its middle (`n64_tick` once a present); not on HDR Native's picture nor under DLSS frame generation (the choice at once there), and not at a start. `RX_VK_N64_TV_ANIM=0`: the choice at once. (11-22) The options' own screens (the open menu, our tabs over the game's Options screen, the Mods entry) are drawn into a layer of the picture's place that the TV lays over the picture before its steps, so they bend, scan and bleed as the game's own screens under them (`vk_menu.cpp` `menu_tv_layer`, `vk_imgui.cpp` `record_layer`), and the glow's 1/8 copy is made again with them over the picture (else it blurred the game's own panes through their plates); the FPS counter, the notice and benchmark mode's panel stay over it, flat; with HDR on the options stay over it too (their pictures are in HDR10's codes, not the SDR picture's). The mouse is taken through the TV's curve to where the options and the game's own menus were drawn (`n64_rules.h` `screen_point`, `vk_n64.h` `n64_screen_point`; the game's through the renderer's `screen_point`). `RX_VK_N64_TV_MENU=0`: the options over the TV, flat, as before. The log says `vk: N64 Classic:` at its first grid and each new size | | `RX_VK_STUB_SAME_SIZE=0` | (Triforce, 11-22, the performance audit's GPUWORK-21, after Source B's and Source A's; `gpu/vk/stub_same_size.h`) On unless `0`. A gameplay upscale network that cannot run (left out or not translated: `RX_VK_NO_F16`, a card or driver that cannot build it) is stood in for by its input drawn into its output (`gpu/vk/vk_draw.cpp` `upscale_stub`) also where the two are one size: `9dc98871eb7fc101`, the network of Render resolution 100%, was declined as "no larger than its input" and skipped whole, a black 3D under the HUD. Both gameplay networks now take the typed upscale first (it reads the scene's shared-exponent picture and undoes the network's square-root encoding; it was the 3/4 network's alone), then the blit, which warns of wrong colours for both, then nothing. The picture is the upscaler Off's: softer, none of the network's anti-aliasing. Only where the network cannot run. `0`: the decline, and the 3/4 network alone in the typed upscale, as before. `RX_VK_NO_UPSCALE_STUB=1` still turns the whole stub off; `RX_VK_FORCE_UPSCALE_STUB=2` sends every network through it, for a look | | `RX_VK_DLSS=0/1/2`, `RX_VK_DLSS_PRESET=`, `RX_VK_DLSS_LOG=1`, `RX_VK_REFLEX`, `RX_VK_REFLEX_LOG=1`, `RX_VK_ANTILAG=0/1` | NVIDIA DLSS and Reflex, and AMD Anti-Lag 2, for one run (`=-` on Reflex or Anti-Lag 2: its extensions not even enabled): the readme's NVIDIA DLSS section. `RX_VK_DLSS_TRACE=` logs one frame's large draws every that many frames, `RX_VK_DLSS_DEBUG=motion` shows the motion vectors, `=alternate` the game's own upscale every other frame | | `RX_VK_FSR4=0/1/2`, `RX_VK_FSR_DIR=` | AMD FSR 4 for one run (0 never, 1 FSR 4, 2 its Native AA), and another folder for AMD's DLLs (not from `hookshot_env.txt`): the readme's AMD FSR 4 section. `RX_VK_FSR4=1/2` and `RX_VK_DLSS=1/2` go over the Upscaler row, a saved FSR 3.1 too where the engine they ask for runs; `RX_VK_FSR=1` goes over them (one upscaler at a time; `=2`: FSR 3.1 as its Native AA, the 3D at full size). The DLSS trace and debug switches above apply to FSR 4 too, on the frame chain they share | @@ -393,12 +394,16 @@ case-sensitive, and an unknown one is ignored. | `RX_VK_CAP_FREE_ASYNC=0` | (Triforce, on by default; `=0` as before) A retired capture buffer the spares cannot keep (past 12 buffers or 768 MB, 32 MB on a card of 6.5 GB or less) is destroyed on a thread of its own (`gpu/vk/vk_memory.cpp` `cap_buf_free`, `destroy_buffer_later`), not in the capture's take on the replay's thread with its locks held: freeing a 64-256 MB host-cached buffer makes the driver unmap and release every page, the `retires` part of a `vk: slow capture take` line. Only buffers the GPU is done with get there; the memory comes back a moment later. The 600-take line counts the buffers and MB handed over. With no thread to be had they are destroyed where they were retired | | `RX_VK_PARALLEL=<0..8>`, `RX_VK_PARALLEL_AUTO=<2..8>` | The parallel replay: a frame's large command buffers recorded on that many threads, always, or wherever short trials as the game runs find it faster than the replay thread alone; `RX_VK_PARALLEL=0`: never. The Debug tab's Replay helper threads row is the second without an environment to set (`replay_helper_threads=` 1 to 7 for 2 to 8 threads); either switch goes over the row. The row's Automatic (8), which it is unless the options file says otherwise, is the count `gpu/vk/replay_threads.h` gives the PC: none with four cores or fewer or on AMD's driver for RDNA 1 and 2, 2 threads with five to seven cores, 3 with eight or more. The log says at the start what was chosen (`replay helper threads:`) and at each trial which way is in use (`parallel replay, trial`). Between trials the tuner's rule (`gpu/vk/replay_threads.h` `rule`) judges every 120 frames on the replay thread alone: where the replay is plainly the frame's limit (70% of the frame or more) and the helper threads would take at least 1 ms and a tenth of the frame off it, never counting below the GPU's time (the game waits for each frame's GPU work), they are turned on without a trial; where they cannot pay (no command buffer large enough to cut, the GPU's time about as long as the replay's, or the replay under 60% of the frame: the game's own threads are its limit) no trial is made while that holds; trials decide the rest, and a trial that takes the helpers back off holds the rule's "on" for 3,600 presents. The log says so (`parallel replay, the rule`) when its verdict changes. `RX_VK_PARALLEL_RULE=0`: trials only, as before. With DLSS or FSR on, for upscaling or frame generation, the dry pass tells their hooks in the draws in stream order, and each command buffer from the first draw or dispatch that takes what they noted (the upscale, or the engine's point before the bloom) on is recorded in order after the segments before it (`gpu/vk/stream_order.h`); `RX_VK_PARALLEL_TEMPORAL=0`: the replay thread records alone then, as before. The frame statistics' `a frame's parallel replay:` line says in how many frames the threads recorded, the command buffers in segments and alone (and why), and the time in them; the next one (`its parts`) where that time went: the setup before the threads begin, how soon each command buffer's first segment reached the GPU, the helper threads' wake-up, each command buffer's longest segment, the replay thread's wait, the submits, the recording lock's waits, and the segments' GPU time (the `GPU time` line counts the segments too; it left them out). After each trial's line a `trial N's parts` line gives its three parts' frame, replay thread's time, GPU time, the rest of the frame, full barriers and draws, and the helper threads' parts. That header lists what an audit of the parallel replay found and fixed, and what is left. `RX_VK_NO_DRY_COPIES=1`: the dry pass does not mark what copies and texture clears write, as before. The replay thread records the next segment to submit itself when no helper thread has begun it (it only waited before, on the core kept for it); `RX_VK_PARALLEL_OWN=0`: it waits for the helper threads, as before. `RX_VK_PARALLEL_SEG=<32..>`: the draws and dispatches a segment is cut for (160); `RX_VK_PARALLEL_SEGS=<2..12>`: the most segments a command buffer is cut into (6), without which a smaller `RX_VK_PARALLEL_SEG` cuts no finer once a command buffer has six segments' worth | | `RX_VK_PARALLEL_BACKOFF=0` | The tuner's trials as before: one every 1,800 presents after one that kept the way, each with 104 frames the other way. With the back-off (the default, `gpu/vk/replay_threads.h` `Tuner`) each trial that keeps the way, the other way longer than both of its own parts, puts the next one off twice as long (3,600, 7,200, then 14,400 presents at most; a margin of 10% or more counts twice), one too close to tell keeps the old interval (the first such one after a change of scene or way: 900 presents), and once the way has held so the other way is tried for 64 frames, not 104; a short trial that finds the other way shorter changes nothing itself, a full trial follows at once. The next trial comes early (900 presents after the last one at the soonest, never while the rule says no trial) when the scene clearly changes: two windows of 120 frames in a row whose draws moved by a quarter (200 at least) or whose replay or GPU time moved by 30% (1 ms at least) from the first window after the way was set, or a trial whose first and last parts did. In the lab's steady Market a trial came every ~2,090 presents, each ~100 frames 1.9 ms longer; the trial lines now end with when the next may come, and `parallel replay, the scene changed` says when one was brought forward | -| `RX_VK_TUNER_SETTLED=0` | The tuner's rule judges every window and a trial the scene changed under decides, as before. With settled scenes only (the default, `gpu/vk/replay_threads.h` `Tuner`, after Kaefergeneral's #dev-fixes post: on his 5900X and RTX 3090 the rule turned the helper threads on in an area's load and the first trial after the arrival kept them, and Automatic was 6 to 10% slower than Off) the rule judges a window of 120 frames only if the one before it describes the same scene (its draws within a quarter, 200 at least, its replay and GPU times within 30%, 1 ms at least: the back-off's test), so a load's window and the first after it get no verdict and the rule's "on" comes a window after a scene settles; a trial whose first and last parts moved so changes nothing, either way, and the next comes 120 presents after a window like the one before it, not 900 or more later. The trial's line says so (`the scene changed under it`), and `parallel replay, the scene settled` when the next is set | +| `RX_VK_TUNER_SETTLED=0` | The tuner's rule judges every window and a trial the scene changed under decides, as before. With settled scenes only (the default, `gpu/vk/replay_threads.h` `Tuner`, after Kaefergeneral's #dev-fixes post: on his 5900X and RTX 3090 the rule turned the helper threads on in an area's load and the first trial after the arrival kept them, and Automatic was 6 to 10% slower than Off) the rule judges a window of 120 frames only if the one before it describes the same scene (its draws within a quarter, 200 at least, its replay and GPU times within 30%, 1 ms at least: the back-off's test), so a load's window and the first after it get no verdict and the rule's "on" comes a window after a scene settles; a trial whose first and last parts moved so changes nothing, either way, and the next comes 120 presents after a window like the one before it, not 900 or more later. The trial's line says so (`the scene changed under it`), and `parallel replay, the scene settled` when the next is set. Between trials the scene is calm while two windows in a row of the way in use describe one scene: a trial due waits for a calm scene (900 presents at most), none begins where nothing is cut (a loading screen), and after a trial the scene moved under the next is never more than 900 presents late. The rule's "on" holds only for the scene it judged: the first window that moved from the first with the helper threads on takes them back off (`the rule's "on" withdrawn`), and the rule judges the new scene; and the rule's "on" needs three windows in a row, each within those margins of the first of them (an arrival whose texture load comes down a little each window passes two alike, not three) | | `RX_VK_RECORDER=thread`, `=defer`, `=sync`, `=off` | (unset: `thread` on an NVIDIA GPU with 12 logical processors or more, and on an AMD GPU with 6 physical cores or more in the process's affinity but for AMD's Windows driver for RX 5000 and RX 6000 (`gpu/vk/recorder_auto.h`); else off. The log's `vk: recorder thread on/off by default` line says which rule applied; `RX_VK_LAB_AB=norec` makes the calls directly in its phases, to measure it) `thread`: the replay thread's `vkCmd*` calls packed with copies of their arguments into a ring and made by a recorder thread of their own, in order (`gpu/vk/vk_recorder.h`); the replay thread waits for it at every command buffer begin, end and reset, submit, wait, readback and destruction. Beside the Replay helper threads too (no longer refused with `RX_VK_PARALLEL`): a parallel replay's segments make their calls themselves, after the ring has been run (`segments_begin`), and the recorder is idle while they record. With it on, the frame statistics' `a frame's recorder thread` line says how many of the replay's calls it made a frame and in how long, and how long the replay thread waited for it; what it saves is the replay time line's `commands` with it against without it. `defer` and `sync` are its test steps (held and run on the same thread). `RX_VK_RECORDER_RING_MB` (8), `RX_VK_RECORDER_SPIN_US`, `RX_VK_RECORDER_STATS=0`, `RX_VK_RECORDER_POISON=1`, `RX_VK_RECORDER_PIN` (`next`, `sibling` or a mask) | | `RX_VK_REPLAY_PRIO=0` or `1` | (Triforce, on by default, after NX2navi's `recorder_prio`; `=0` as before) A thread runs at the highest priority while it replays the game's frames (the submitting thread's replay and its capture, the present, the stopped work the order thread lets on: `gpu/vk/vk_replay.cpp` `ReplayPin`) and gets its own priority back after, so the game's code it runs between replays keeps the game's priority; the core kept for the replay is kept from the game's threads only, and the helper threads and the capture's copy helpers (above normal) outranked a replay at the game's priority there. A thread at that priority or above already is left alone. The replay thread of `RX_VK_ASYNC=1` and the recorder thread of `RX_VK_RECORDER=thread` take the level for good. `=1`: above normal. The log's `vk: a thread that replays runs at` line says which (`gpu/vk/replay_prio.h`) | | `RX_VK_REPLAY_PIN_SOFT=0`, `=2` | (Triforce, 11-22, the performance audit's THREAD-09, after Source A's; Windows) A thread is pinned while it replays to the core the host keeps for the replay, and that core is kept from the game's threads, not from other programs': where another program's high-priority thread holds it, the pinned replay waits for it, ready to run (Source A, a 6+8-core hybrid processor with an overlay service at priority 15: 14 to 37 frames over 40 ms in a 40 s run, none with this). Not set: on a processor with cores of more than one kind the pin is soft: the thread may run on the reserved core and on the fastest-kind cores among its own processors, the reserved core's last logical processor is its ideal one, and the core it is on when the pin starts is left out so that it moves at once; its affinity and ideal processor come back after the replay. The replay thread of `RX_VK_ASYNC=1` gets the same processors for good. A processor of one kind of core keeps the strict pin, and nothing changes there. `0`: the reserved core alone everywhere, as before; `2`: soft everywhere (the lab; the knob `pinsoft` of `RX_VK_LAB_AB` does it by phases). A thread of another program that wakes on the core every millisecond moves the replay again and again (Source A: 54.3 against 44.6 fps, one run each): `0` is for that. The log's `vk: a replay's pin is` line says which (`gpu/vk/replay_pin.h`, `gpu/vk/vk_replay.cpp` `ReplayPin`, `replay_pin_soft`) | | `HOS_VCORES=0`, `HOS_CORES=<1..8>`, `HOS_RESERVE_CORE=0` | No virtual cores; the cores the game sees (6); no core kept for the replay (one is, with 8 or more logical processors) | | `HOS_VCORES=0`, `HOS_CORES=<1..8>`, `HOS_RESERVE_CORE=0`, `=1` | No virtual cores; the cores the game sees (6); no core kept for the replay (one is, with 8 or more logical processors). (Triforce, 11-22, the performance audit's THREAD-49, after Source A's) On the cache die of a two-die X3D processor with SMT off none is kept unless `HOS_RESERVE_CORE=1` asks for it or the replay has a thread of its own (`RX_VK_ASYNC=1`): the game then has all 8 of the die's cores (Source A, a 9950X3D with SMT off: 59.8-59.9 fps with none kept against 56.9-57.4 with one). The log's `cpu: no core kept for the replay on the cache die` line says so. With SMT on and on every other processor nothing changes (`host/hos_x3d.h` `hos_x3d_keep_replay_core`) | +| `HOS_L3_HOME=0` | (Triforce, 11-23, Windows) On a processor with two or more L3 caches of the same size and 6+ cores under the first (a Ryzen 9 5900X, 5950X, 7900X, 7950X, 9900X, 9950X), the core kept for the replay is the first die's last core, not the processor's last on the second die, and the game's main and presenting threads are kept on the first die's other cores, so that what the main thread writes is in the L3 the replay reads it from; the game's other threads, the renderer's helpers and the driver's stay where Windows puts them. Nothing with one L3, with L3 caches of different sizes (`host/hos_x3d.h` has those), with fewer than 6 cores under the first, or with more than one processor group. The log's `cpu: logical processors ... share one of` line says what was found. `0`: as before (`host/hos_l3_home.h`, `host/hos_thread.c`, `tests/test_l3_home.py`) | +| `RX_VK_DYNRES_UNION=0` | (Triforce, 11-23) Resolution Auto's clock takes the frames' GPU time as the union of the recordings' timestamp intervals, each moment once (`gpu/vk/gpu_busy.h`). Their sum, as before with `0`, counted again the overlaps of AMD's first timestamps, written while the recording before still runs: 14.9 ms against a 7.8 ms span on an RX 6700 XT, and Auto drew the 3D at 854 x 480 on a card half idle. The union still counts a recording's waits on the GPU for events the CPU sets later (19.8 ms against a 5.9 ms span on the same card), so while the host does not wait for the GPU (its waits on all threads, `gpu_wait_kinds.h`, the compositor's image excluded: the card is the limit from 2 ms a frame on average, until they fall under 1 ms) the clock says at most the replay's span: only a card that holds the frame back steps the 3D down. `0` takes both away. The log's `vk: dynamic resolution's clock` line says which (`gpu/vk/vk_replay.cpp` `ts_dyn_present`, `tests/test_gpu_busy.py`) | +| `RX_VK_ACQUIRE_AHEAD=0`, `=1` | (Triforce, 11-23, Windows) On AMD's driver the present thread (`RX_VK_PRESENT_THREAD`, wanted for this) acquires the next swapchain image right after its present and waits for it to be free there, while the presenting thread replays the frame; `present_image` then finds the image held and free and records its blit at once. An RX 6700 XT (26.11.2) waited 2.4 to 4.2 ms of every frame for the image in `present_image` (the pacing's wait in the present line), 16% of the presenting thread in a profile: AMD presents through DXGI and the image comes back with the compositor's refresh. Only with the acquire's fence (`RX_VK_ACQUIRE_FENCE`), without DLSS frame generation; nothing while an image is held or a resize or lost surface waits. A `vk: the next image acquired ahead` line every 600 presents. `0`: off; `1`: on any card (`gpu/vk/vk_replay.cpp` `acquire_ahead`, `tests/test_acquire_ahead.py`) | +| `RX_VK_QUERY_RING=0` | (Triforce, 11-23) A recording's GPU timestamps are read from a mapped, host-coherent ring the GPU copies them into, not with `vkGetQueryPoolResults` (about 0.6 ms a frame on AMD's Windows driver on the replay thread, and a recorder boundary with `RX_VK_RECORDER=thread`): a slot's next use copies its last use's timestamps, each with its availability word, before it resets them, behind a transfer-to-host barrier; the slot's turn after that reads them, so the GPU time arrives a turn of the ring later (48 recordings). The upload command buffer's timestamps are read as before. Not without host-coherent memory. `0`: as before (`gpu/vk/vk_replay.cpp` `query_ring_make`, `gpu_time_begin`, `gpu_time_collect`; `tests/test_query_ring.py`) | | `HOS_AV1=mf`, `HOS_AV1_MISSING=1` | (Triforce, 11-22, the performance audit's IO-32; Windows) The game's AV1 movies on Media Foundation first (Microsoft's AV1 Video Extension), as before, and on dav1d only where the PC has no such decoder. Without it dav1d goes first where the FFmpeg the build links has libdav1d, as on Linux, and Media Foundation where it has not or where libdav1d does not open (`host/video_av1.h`, `host/nn_video.c` `dec_init_sized`): Media Foundation's path decodes in software on every GPU (`host/mf_av1.c` takes the synchronous decoder). `HOS_AV1=dav1d`, the old way to ask for dav1d first, is the default now. `HOS_AV1_MISSING=1`: Media Foundation as if the extension were missing. Each movie logs one line at its Stop, Flush or its decoder's end: its pictures, the decoder, the mean and the worst time to decode a submission, and the pictures skipped to catch up (`host/video_movie.h`). The two decoders were not timed against each other in the game | | `HOS_VIDEO_RGBA=1` | (Triforce, 11-22, the performance audit's IO-36) Every planar 4:2:0 movie picture (libdav1d's) is converted to RGBA when it is decoded, as before: a swscale pass, an 8 MB allocation and an 8 MB row copy for a 1080p picture, on the movie thread. Without it such a picture is kept as NV12 alone, as Media Foundation's NV12 pictures already were, and its pool makes the RGBA only if the game reads RGBA, which this game's movie library does not; planar 4:2:0 with alpha is converted at once either way. The NV12 buffer is zeroed only for an odd size or a format that is not copied into it, and U and V are interleaved 16 pairs a step with SSE2 (`host/video_nv12.h`, `host/nn_video.c` `queue_frame`). The movie's line in the log (IO-32) has the time a picture took with either. Not timed in the game | | `HOS_VIDEO_UNBOUNDED_CATCHUP=1`, `HOS_VIDEO_NO_CATCHUP=1` | (Triforce, 11-22, the performance audit's THREAD-82) The movie decoder's acquire skips the pictures behind the movie's clock and decodes the next ones to skip them too. `HOS_VIDEO_UNBOUNDED_CATCHUP=1`: with no bound but a guard of 600 steps, as before: with a decoder slower than the movie (19.5 ms a picture against 16.7) each picture decoded to catch up puts the clock further ahead, so an acquire decoded up to about 300 pictures with its lock held, threw them away, and the next started further behind. Without it each decode that gives a picture is timed, about the last 8 kept as one number, and the acquire stops decoding ahead when that number is more than the gap between two pictures (from the pictures' own times) or once it has decoded for one gap, and shows the late picture it has (`host/video_catchup.h`, `host/nn_video.c` `dec_acquire`): such a movie falls behind its sound instead of stalling, and its line in the log says "slower than it plays". A decoder faster than the movie catches up as before, a few pictures an acquire. `HOS_VIDEO_NO_CATCHUP=1`: no picture skipped at all (the movie in slow motion under 60 fps). Not run in the game | @@ -542,10 +547,11 @@ number is not the obvious one: | `frame_pacing` | 0 Off, 1 frames on an even line. With `steady_frame_rate`, the Frame pacing row (`gpu/vk/merged_rows.h`): Off is 0 and 0, Even 1 and 0, Steady (any rate) 1 and 1, Steady (refresh steps) 1 and 2 | | `steady_frame_rate` | 0 Off, 1 any rate (the cap, then 200, 180, 160, 144, 120, 110, 100, 90, 80, 72, 66, 60, 55, 50, 45, 40, 36, 30 under it), 2 whole divisions of the display's refresh rate under the cap, from 30 up (`host/pace_steady.h`) | | `resolution` | 0 Auto, 1 100%, 2 75%, 3 67%, 4 50%, 5 58%, 6 33% (with DLSS and FSR: 3 Quality, 5 Balanced, 4 Performance, 6 Ultra Performance; their Native (100%) is `dlss` 2, 5 or 6) | -| `output_res` | 0 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080, 4 5120x1440, 5 5120x2880, 6 5120x2160, 7 1536x864 (the handheld profile; before `options_version` 8 it was `handheld_profile=1`, read as 7) | -| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9 (before `options_version` 6, 1 was the monitor's shape: read as the nearest of the four, `gpu/vk/ultrawide_rows.h`) | +| `output_res` | 0 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080, 4 5120x1440, 5 5120x2880, 6 5120x2160, 8 Screen, 9 Custom (`output_width` x `output_height`), 7 1536x864 (the handheld profile; before `options_version` 8 it was `handheld_profile=1`, read as 7) | +| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9, 4 4:3 (before `options_version` 6, 1 was the monitor's shape: read as the nearest of the first four, `gpu/vk/ultrawide_rows.h`) | | `hdr`, `renodx_hdr` | the HDR row (`gpu/vk/merged_rows.h`): `hdr` 0 Off, 1 Expanded, 2 Native (the game's own); `renodx_hdr` 1 with `hdr` 2 is Native + RenoDX | | `nvidia_reflex`, `amd_anti-lag_2` | the Low latency row by the card's maker: 0 Off, 1 On, 2 On + Boost (NVIDIA alone) | +| `output_width`, `output_height` | Custom's size in pixels (`output_res=8`): a connected screen's as chosen in the menu, or any size set with the Output width and Output height rows, shown while it is the choice: 640 to 7680 and 360 to 2880, in steps of 8 in the menu; 2560 and 1440 until they are set | | `hdr_paper_white`, `hdr_peak_brightness` | nits: 80 to 400, and 400 to 10,000 | | `renodx_tonemapper` | 0 Vanilla, 1 PsychoV35, 2 RenoDRT | | `renodx_gamma_correction` | 0 Off, 1 2.2, 2 BT.1886 (2.4) | @@ -567,6 +573,8 @@ number is not the obvious one: | `robust_buffers` | 0 Auto (on), 1 Off, 2 On | | `game_speed` | 0 Per frame, 1 Real time | | `text_speed` | 0 Normal, 1 2x, 2 4x, 3 Instant | +| `achievements` | 1 on, 0 off: whether anything is earned (`host/achievements.c`, option id 175); at once | +| `achievement_notices` | 1 on, 0 off: an earned one's notice and its sound (option id 176); it is earned and listed either way | | `menu_sounds` | percent, 0 to 100: 80 unless set, 0 silent. The settings' own sounds, the game's interface sounds from its RomFS (`host/menu_sound.c`, `gpu/vk/menu_sound_events.h`; option ids 135 and 136), under `master_volume` | | `microphone` | 0 Off, 1 Default, 2 and up a microphone (the name in `microphone_device` decides which) | | `mouse_camera` | 0 As the stick, 1 Native | @@ -645,3 +653,23 @@ force and why; the Full overlay's Frame limit line names RivaTuner or NVIDIA Ref License: GPL-3.0-or-later, as mkw-recomp: a64-kit's translator is suyu's (GPL-2.0-or-later) and Eden's code is GPL-3.0. + +### Native ultrawide on 0.6 + +`options_version=9` keeps output 7 for handheld and uses 8 for Screen, 9 for Custom. +The menu lists connected monitors by name and saves their size, so unplugging or +reordering monitors does not change the picture. Custom retains the entered pair +when choosing a monitor; Use current window size copies the drawable pixel size. +A non-16:9 output owns the picture shape; the Aspect ratio row keeps the upstream +four shapes for 16:9 outputs. The HUD, menus and story movies retain 16:9 geometry. +The title movie fills through 12:5 (+1% rounding tolerance); wider titles keep bars. + +Both stock 0.6 and native 0.5.2 wrote version 8. Native files are identified by +`output_width` or `output_height`, which their writer always emitted. Their old +Screen 7 and Custom 8 become 8 and 9. Stock handheld 7 stays 7. Native version-8 +fixed wide pictures stay wide; stock fixed wide outputs migrate by their old +Aspect ratio choice. Files before version 8 retain the earlier shape migrations. +The host, menu and native launcher apply these rules before saving version 9. +The generic manifest cannot migrate a whole file, so offers only fixed values +that mean the same under all file versions; use the menu or native launcher for +handheld, Screen and Custom. diff --git a/gpu/vk/gpu_busy.h b/gpu/vk/gpu_busy.h new file mode 100644 index 0000000..5267081 --- /dev/null +++ b/gpu/vk/gpu_busy.h @@ -0,0 +1,35 @@ +// (Triforce, 11-23) The GPU's busy time as the union of the recordings' timestamp intervals, for the game's dynamic resolution's +// clock (vk_replay.cpp ts_dyn_present). The clock summed each recording's interval, top of the pipe to its end. On AMD's +// Windows driver a recording's first timestamp is written when the command processor reaches it, while the recording before +// it still runs, so the intervals of a frame's 20 to 30 recordings overlap and their sum counts the overlaps again: on an RX +// 6700 XT at 2560 x 1440 the sum came to 14.9 ms where the replay's whole span was 7.8 ms (scale 1.9), and Resolution Auto +// drew the 3D at 854 x 480 with the card half idle. The union counts each moment once. +// +// Intervals come in the order their recordings are read back, which on one queue is the order they ran; one that begins +// before the last one's end adds only what lies past that end. One read back out of order (it began before an interval +// already counted) adds only its part past the latest end: the busy time is then under, never over, the truth. +// tests/test_gpu_busy.py +#pragma once + +#include + +namespace mkwvk::gpu_busy { + +struct Union { + uint64_t end = 0; // (the latest end counted, in timestamp ticks) + uint64_t ticks = 0; // (the busy ticks counted so far) + + /// A recording's interval [begin, finish), in the queue's timestamp ticks + void add(uint64_t begin, uint64_t finish) { + if (finish <= begin) return; + if (begin >= end) { + ticks += finish - begin; + end = finish; + } else if (finish > end) { + ticks += finish - end; + end = finish; + } + } +}; + +} // namespace mkwvk::gpu_busy diff --git a/gpu/vk/n64_rules.h b/gpu/vk/n64_rules.h new file mode 100644 index 0000000..2db7be3 --- /dev/null +++ b/gpu/vk/n64_rules.h @@ -0,0 +1,409 @@ +/* (Triforce, 11-22) N64 Classic: the Insert menu's N64 Classic row and the Remembered page's rows, as plain functions (the + plan: n64-classic-mode-plan.md, step 1). What each preset looks like, the grid the 3D pass draws on, the texture blur + on a card, how strong the scanlines are on a screen, when the mask shows, what the mode stands in front of while it is + on, the frame rate the host is told, F7, and the TV's switch-off and switch-on. No Vulkan, no menu: + tests/test_n64_rules.py compiles and runs them. Nothing calls them yet. + + Two presets with two jobs. Faithful is fixed (kFaithful): the 1998 cartridge on a 1998 TV, always 20 frames a second. + Remembered is the player's own: its rows (Rows) are kept in triforce_options.ini under kSpec's keys, and start as + kSpec's defaults. Both become a Look the same way (look_of_rows), so the page's Copy Faithful is kFaithful copied into + the rows and nothing more, and Remembered then looks exactly as Faithful does. + + The per-pixel maths of the 3D pass (the colour depth and the ordered dither) is in shaders/n64_common.glsl, which the + shaders include and the test compiles as C++. */ +#pragma once + +#include + +#include "aa_rows.h" // (the Anti-aliasing row's Off, and through it the Upscaler row's values: upscaler_rows.h) + +namespace mkwvk::n64_rules { + +// ---- the N64 Classic row ---- + +/// The N64 Classic row (opts.n64_classic, saved as n64_classic; RX_VK_N64 over it). Off by default, as every feature is +enum { OFF = 0, FAITHFUL = 1, REMEMBERED = 2, kPresets = 3 }; +inline const char* name(int v) { + switch (v) { + case FAITHFUL: return "Faithful"; + case REMEMBERED: return "Remembered"; + default: return "Off"; // (also for a value past the row) + } +} +/// The row's value as one of its choices, RX_VK_N64=<0..2> over it for a run (env: its number, -1 unset). Anything else is +/// Off +constexpr int chosen(int row, int env) { + const int v = env >= 0 ? env : row; + return v >= OFF && v < kPresets ? v : OFF; +} + +// ---- the Remembered page's rows ---- + +/// The page's rows, in the page's order, and their place in Rows +enum Row { FPS, LINES, COLOUR, DITHER, BLUR, TV, SCANLINES, MASK, MASK_STRENGTH, BLEED, GLOW, CURVATURE, SATURATION, kRows }; +/// A row's key in the options file, its range, its step and the value it starts at (Remembered's own defaults) +struct RowSpec { + const char* key; + int lo, hi, step, def; +}; +constexpr RowSpec kSpec[kRows] = { + {"n64_rem_fps", 0, 4, 1, 0}, // (kFps: Frame rate cap) + {"n64_rem_lines", 0, 3, 1, 2}, // (kLines: 480) + {"n64_rem_colour", 0, 2, 1, 2}, // (kColourBits: Full) + {"n64_rem_dither", 0, 2, 1, 0}, // (kDither: Off) + {"n64_rem_blur", 0, 6, 1, 3}, // (halves of a mip level: +1.5) + {"n64_rem_tv", 0, 1, 1, 1}, // (On) + {"n64_rem_scanlines", 0, 80, 5, 35}, // (percent: how dark the gaps between TV lines are) + {"n64_rem_mask", 0, 4, 1, 0}, // (the Mask enum below: Auto) + {"n64_rem_mask_strength", 5, 50, 5, 15}, // (percent) + {"n64_rem_bleed", 0, 2, 1, 1}, // (kBleed: Light) + {"n64_rem_glow", 0, 50, 5, 25}, // (percent) + {"n64_rem_curvature", 0, 3, 1, 1}, // (kCurvature: Slight) + {"n64_rem_saturation", 50, 150, 5, 110}, // (percent) +}; +/// What the rows' values stand for. Frame rate: 0 the Frame rate cap row's own rate, else frames a second (20 and 17: the +/// 1998 cartridge on a 60 Hz and on a 50 Hz TV, a third of each) +constexpr int kFps[] = {0, 60, 30, 20, 17}; +constexpr int kLines[] = {240, 360, 480, 720}; +/// Colour: bits a channel, 0 Full (as it is). 5 is the console's 16-bit picture, 6 the 18 bits of a cheap panel +constexpr int kColourBits[] = {5, 6, 0}; +constexpr float kDither[] = {0.0f, 0.5f, 1.0f}; +/// Colour bleed: how far the colour (not the brightness) blurs sideways, in pixels of a 320-wide picture (a composite +/// cable's is about 3) +constexpr float kBleed[] = {0.0f, 1.5f, 3.0f}; +/// Curvature: the screen's barrel, as a share of the picture at its corners (0 flat) +constexpr float kCurvature[] = {0.0f, 0.015f, 0.03f, 0.05f}; +/// The Mask row. Auto: the slot mask on a picture placed 1440 lines tall or more, none below (kMaskAutoLines); a mask the +/// player picks is shown on any screen +enum Mask { MASK_AUTO = 0, MASK_OFF = 1, MASK_APERTURE = 2, MASK_SLOT = 3, MASK_SHADOW = 4 }; +/// The texture blur: a row step is half a mip level +constexpr float kBlurStep = 0.5f; + +/// The page's values, by Row +struct Rows { + int v[kRows]; +}; +/// The rows of values kept as a plain array (vk_menu.h Options's n64_rem), in Row's order +constexpr Rows rows_of(const int* v) { + Rows r{}; + for (int i = 0; i < kRows; i++) r.v[i] = v ? v[i] : kSpec[i].def; + return r; +} +/// Remembered as it starts (the page's Reset) +constexpr Rows defaults() { + Rows r{}; + for (int i = 0; i < kRows; i++) r.v[i] = kSpec[i].def; + return r; +} +/// Faithful, which is never changed: 20 frames a second, 240 lines, 15-bit colour with the full dither, textures 2.5 mip +/// levels blurrier, the TV on with 60% scanlines, Auto's slot mask at 30%, a composite cable's bleed, 10% glow, a curved +/// screen, the game's own saturation. The page's Copy Faithful copies it into Remembered's rows +constexpr Rows kFaithful = {{3, 0, 0, 2, 5, 1, 60, MASK_AUTO, 30, 2, 10, 2, 100}}; + +/// A row's value as the row has it: inside its range, on its steps (a hand-edited or older file's value is brought back to +/// the row, rounded down to a step) +constexpr int clamp_row(int row, int v) { + if (row < 0 || row >= kRows) return 0; + const RowSpec& s = kSpec[row]; + if (v < s.lo) return s.lo; + if (v > s.hi) return s.hi; + return s.lo + (v - s.lo) / s.step * s.step; +} +constexpr Rows clamped(Rows r) { + for (int i = 0; i < kRows; i++) r.v[i] = clamp_row(i, r.v[i]); + return r; +} +/// A row with nothing to do just now, shown fixed (greyed, no arrows; Left and Right leave it alone): Dither while Colour is +/// Full (nothing to dither), the TV's rows while CRT TV is off, Mask strength while Mask is Off +constexpr bool row_fixed(const Rows& r, int row) { + const Rows c = clamped(r); + if (row == DITHER) return kColourBits[c.v[COLOUR]] == 0; + if (row >= SCANLINES && row <= SATURATION && !c.v[TV]) return true; + if (row == MASK_STRENGTH) return c.v[MASK] == MASK_OFF; + return false; +} + +// ---- the look ---- + +/// What the three passes and the host are given: one of these for the frame +struct Look { + bool on = false; + int fps = 0; // frames a second the host is asked for; 0 the Frame rate cap row's own + int lines = 0; // the 3D grid's lines (its width follows the picture's shape: grid) + int colour_bits = 0; // bits a channel; 0 the picture as it is + float dither = 0.0f; // the ordered dither's strength, 0 to 1 (0 with full colour: nothing to dither) + float lod_bias = 0.0f; // the texture blur in mip levels, before the card's limit (lod_bias) + bool tv = false; // the TV pass at the window + float scanlines = 0.0f; // how dark the gaps between TV lines are, 0 to 1, before the screen's say (scanline_strength) + int mask = MASK_OFF; // the Mask row's choice; Auto is decided by the screen (mask_shown) + float mask_strength = 0.0f; + float bleed = 0.0f; // kBleed's + float glow = 0.0f; + float curvature = 0.0f; // kCurvature's + float saturation = 1.0f; +}; +/// The look of a set of rows (Faithful's or Remembered's): what each value stands for +constexpr Look look_of_rows(Rows rows) { + const Rows r = clamped(rows); + Look l; + l.on = true; + l.fps = kFps[r.v[FPS]]; + l.lines = kLines[r.v[LINES]]; + l.colour_bits = kColourBits[r.v[COLOUR]]; + l.dither = l.colour_bits ? kDither[r.v[DITHER]] : 0.0f; + l.lod_bias = r.v[BLUR] * kBlurStep; + l.tv = r.v[TV] != 0; + l.scanlines = l.tv ? r.v[SCANLINES] / 100.0f : 0.0f; + l.mask = l.tv ? r.v[MASK] : (int)MASK_OFF; + l.mask_strength = l.tv && l.mask != MASK_OFF ? r.v[MASK_STRENGTH] / 100.0f : 0.0f; + l.bleed = l.tv ? kBleed[r.v[BLEED]] : 0.0f; + l.glow = l.tv ? r.v[GLOW] / 100.0f : 0.0f; + l.curvature = l.tv ? kCurvature[r.v[CURVATURE]] : 0.0f; + l.saturation = l.tv ? r.v[SATURATION] / 100.0f : 1.0f; + return l; +} +/// The look for the N64 Classic row's value: nothing with Off; Faithful's whatever the page holds; Remembered's rows +constexpr Look look_of(int preset, const Rows& remembered) { + if (preset == FAITHFUL) return look_of_rows(kFaithful); + if (preset == REMEMBERED) return look_of_rows(remembered); + return Look{}; +} +/// Two looks the same, field by field (Copy Faithful's promise) +constexpr bool same(const Look& a, const Look& b) { + return a.on == b.on && a.fps == b.fps && a.lines == b.lines && a.colour_bits == b.colour_bits && a.dither == b.dither && + a.lod_bias == b.lod_bias && a.tv == b.tv && a.scanlines == b.scanlines && a.mask == b.mask && + a.mask_strength == b.mask_strength && a.bleed == b.bleed && a.glow == b.glow && a.curvature == b.curvature && + a.saturation == b.saturation; +} + +/// The lab's switches for a run, over the look of either preset (an A/B, Faithful's too). -1 (or below 0) unset: +/// RX_VK_N64_LINES=, RX_VK_N64_LOD=, RX_VK_N64_TV=0|1, RX_VK_N64_MASK=<0..4> (the Mask enum), +/// RX_VK_N64_FPS= +struct Env { + int lines = -1; + float lod = -1.0f; + int tv = -1; + int mask = -1; + int fps = -1; +}; +constexpr Look with_env(Look l, const Env& e) { + if (!l.on) return l; + if (e.lines > 0) l.lines = e.lines; + if (e.lod >= 0.0f) l.lod_bias = e.lod; + if (e.tv == 0) l.tv = false; + if (e.tv > 0) l.tv = true; + if (e.mask >= MASK_AUTO && e.mask <= MASK_SHADOW) l.mask = e.mask; + if (e.fps >= 0) l.fps = e.fps; + return l; +} + +// ---- the 3D pass's grid ---- + +/// The lines of a TV of then: the scanlines follow these whatever the 3D's own lines +constexpr int kTvLines = 240; +struct Grid { + uint32_t w = 0, h = 0; +}; +/// The grid the 3D pass draws on for a picture of picture_w x picture_h: `lines` tall (never more than the picture) and as +/// wide as the picture's shape makes it, rounded: 240 lines are 320 at 4:3, 427 at 16:9, 569 at the host's 21:9 picture +/// (3416 x 1440). Nothing when a size is not known +constexpr Grid grid(int lines, uint32_t picture_w, uint32_t picture_h) { + if (lines <= 0 || !picture_w || !picture_h) return {}; + const uint32_t h = (uint32_t)lines < picture_h ? (uint32_t)lines : picture_h; + const uint64_t w = (2ull * h * picture_w + picture_h) / (2ull * picture_h); + return {w ? (uint32_t)w : 1u, h}; +} + +// ---- the texture blur ---- + +/// The texture LOD bias for the scene's material samplers (vk_draw.cpp sampler_make, through the scene-only path the +/// upscalers' bias takes): the look's, never past the card's maxSamplerLodBias (Vulkan promises 2 at least), never below 0. +/// 0 with the mode off +constexpr float lod_bias(const Look& l, float card_max) { + if (!l.on || l.lod_bias <= 0.0f || card_max <= 0.0f) return 0.0f; + return l.lod_bias < card_max ? l.lod_bias : card_max; +} +/// (step 3) A draw into a target of w x h (sharpen_rules.h lod_scene_size: its smallest colour target, or a depth-only +/// draw's depth) is the scene for the picture N64 Classic's 3D pass last drew, ow x oh, while its blur is on: the picture +/// 1 to 3 times its size on each axis, smaller on one at least, and of its shape (within a 32nd). The upscalers' bias goes +/// by the last upscale's render size and this frame's scene camera, which their own hooks note; with N64 Classic those +/// hooks are off, so the game's dynamic resolution, which makes new targets at each size, is taken by its shape here, the +/// frame of a new size included. The sun's and the characters' shadow maps (square), half-size buffers past a third, and +/// the HUD and the output's passes (the picture's own size) are not the scene. (At a fixed 100% the scene is the picture's +/// size: the last upscale's render size, as before, takes it.) Nothing while a size is not known +constexpr bool scene_draw(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) { + if (!w || !h || !ow || !oh || w > ow || h > oh || (w == ow && h == oh)) return false; + if ((uint64_t)w * 3 < ow || (uint64_t)h * 3 < oh) return false; + const uint64_t a = (uint64_t)w * oh, b = (uint64_t)h * ow; // (the two shapes, cross-multiplied) + const uint64_t d = a > b ? a - b : b - a, big = a > b ? a : b; + return d * 32 <= big; +} + +// ---- the TV, on a screen ---- + +/// The scanlines' strength on a picture placed place_h window pixels tall: the look's while a TV line has 3 window pixels +/// or more, fading to none at 2 (thinner, they only make moire). The Steam Deck's 720 lines for a 16:9 picture are 3 a line +constexpr float scanline_strength(float strength, uint32_t place_h, int tv_lines = kTvLines) { + if (strength <= 0.0f || !place_h || tv_lines <= 0) return 0.0f; + const float px = (float)place_h / (float)tv_lines; + const float k = px >= 3.0f ? 1.0f : px <= 2.0f ? 0.0f : px - 2.0f; + return strength * k; +} +/// (step 4) The colour bleed (Look's, in pixels of a 320-wide 4:3 picture) in the widths of a picture of picture_w x +/// picture_h, as the TV shader steps along a line: a pixel of the 240-line grid is a 240th of the height, so the picture is +/// 240 x its shape such pixels wide (427 at 16:9). 0 when a size is not known +constexpr float tv_bleed_uv(float bleed, uint32_t picture_w, uint32_t picture_h) { + if (bleed <= 0.0f || !picture_w || !picture_h) return 0.0f; + return bleed * (float)picture_h / ((float)kTvLines * (float)picture_w); +} +/// Mask Auto: shown on a picture placed this tall or more (3 window pixels a triad stay fine there), none below +constexpr uint32_t kMaskAutoLines = 1440; +/// The mask drawn on a picture placed place_h window pixels tall: Auto's slot mask or none by the height; a mask the player +/// picked, as it is +constexpr int mask_shown(int mask, uint32_t place_h) { + if (mask == MASK_AUTO) return place_h >= kMaskAutoLines ? (int)MASK_SLOT : (int)MASK_OFF; + return mask >= MASK_OFF && mask <= MASK_SHADOW ? mask : (int)MASK_OFF; +} + +// ---- what the mode stands in front of ---- + +/// While N64 Classic is on, its 3D pass takes the gameplay upscale: DLSS, DLAA, FSR 3.1 and FSR 4 step aside (the game's own +/// as far as they are concerned), the game's SMAA is left out (the grid's averaging smooths the edges), and the window's +/// Sharpness is none. The rows keep their saved values: off again, each is what it was +constexpr int upscaler(int preset, int chosen_upscaler) { return preset != OFF ? (int)upscaler_rows::GAME : chosen_upscaler; } +constexpr int anti_aliasing(int preset, int chosen_aa) { return preset != OFF ? (int)aa_rows::OFF : chosen_aa; } +constexpr int sharpness(int preset, int chosen_sharpness) { return preset != OFF ? 0 : chosen_sharpness; } +/// The Upscaler, Render resolution, Anti-aliasing and Sharpness rows shown fixed, their text "N64 Classic" +constexpr bool fixes_rows(int preset) { return preset != OFF; } +/// The 3D pass runs: not on a RenoDX run's RGBA16F scene (scene_rgba16f), whose upscale output it does not take +constexpr bool three_d_runs(const Look& l, bool scene_rgba16f) { return l.on && !scene_rgba16f; } +/// The TV pass runs at the window: not on HDR Native's PQ picture (native_pq, RenoDX's too), nor while DLSS frame +/// generation makes its frames from the finished image after it (dlssg: its motion would move the scanlines and the mask) +constexpr bool tv_runs(const Look& l, bool native_pq, bool dlssg) { return l.on && l.tv && !native_pq && !dlssg; } + +// ---- the frame rate ---- + +/// What the renderer tells the host (host/nn_vi.c pace_fps, step 7): the look's rate, 0 for the cap's own and with the +/// mode off +constexpr int fps(const Look& l) { return l.on ? l.fps : 0; } +/// The rate the frames are paced by with that answer under the Frame rate cap row's cap: the mode's where it is lower, +/// the cap's otherwise (a Remembered 60 under a cap of 45 is 45). The caps the game offers are 30 and up, so Faithful's 20 +/// is always 20 +constexpr int paced(int n64_fps, int cap) { return n64_fps > 0 && n64_fps < cap ? n64_fps : cap; } + +// ---- F7 ---- + +/// The preset F7 turns on from Off (saved as kLastKey, so a start finds the player's own): Faithful until another is +/// chosen +constexpr const char* kLastKey = "n64_classic_last"; +struct Toggle { + int last = FAITHFUL; + /// The row now holds row (a press of F7, the row itself, the options file at the start) + constexpr void noted(int row) { + if (row == FAITHFUL || row == REMEMBERED) last = row; + } + /// F7 pressed with the row at row: what the row becomes + constexpr int pressed(int row) { + if (row == FAITHFUL || row == REMEMBERED) { + last = row; + return OFF; + } + return last; + } +}; + +// ---- the TV switching off and on ---- + +/// Half a second at each change of the row or F7: the old picture squashed to a bright line, then to a dot (the first +/// half), the new one opening from the dot to a line, then to the whole picture (the second). The 3D, the TV and the +/// frame rate change at the middle, where the screen is a dot (`after`), so the change of rate is not seen +constexpr float kAnimSeconds = 0.5f; +struct AnimFrame { + float scale_x = 1.0f, scale_y = 1.0f; // the picture's width and height, shares of the whole + float flash = 0.0f; // the brightness added, 0 to 1: the most at the dot + bool after = false; // the new look's frame (from the middle on) + bool done = true; // the switch is over: the picture as it is +}; +constexpr float kAnimLine = 0.004f, kAnimDot = 0.01f; // (the line's height and the dot's width, shares of the picture) +constexpr AnimFrame anim(float t) { + if (t < 0.0f) return AnimFrame{}; + if (t >= kAnimSeconds) return {1.0f, 1.0f, 0.0f, true, true}; + const float half = kAnimSeconds / 2.0f; + const bool after = t >= half; + const float u = after ? (kAnimSeconds - t) / half : t / half; // (0 at either end, 1 at the middle) + AnimFrame f; + f.after = after, f.done = false, f.flash = u; + if (u < 0.6f) { + f.scale_y = 1.0f - (1.0f - kAnimLine) * (u / 0.6f); + } else { + f.scale_y = kAnimLine; + f.scale_x = 1.0f - (1.0f - kAnimDot) * ((u - 0.6f) / 0.4f); + } + return f; +} + +/// (step 8) The switch from one preset to another, taken once a present (vk_n64.cpp n64_tick): which preset the passes and +/// the host go by now (shown: the one before until the switch's middle, the one chosen from it), and the TV's frame of it. +/// The first present takes the preset as it is, with no switch (a start does not switch the TV on). A new choice while the +/// picture still closes is what opens instead; one after the middle switches again from what is shown. animate false +/// (RX_VK_N64_TV_ANIM=0, or no TV pass can draw it: HDR Native's picture, DLSS frame generation): the choice at once +struct Switch { + int from = OFF, to = OFF; // the preset before the switch and the one chosen + double t0 = -1.0; // when the switch began, in seconds; below 0, none + bool started = false; + struct Now { + int shown = OFF; + AnimFrame frame; // (done: no switch running, the picture as it is) + }; + constexpr Now at(double now, int chosen, bool animate) { + if (!started || !animate) { + started = true, from = to = chosen, t0 = -1.0; + return {chosen, AnimFrame{}}; + } + const bool running = t0 >= 0.0 && now - t0 < kAnimSeconds; + if (chosen != to) { + if (running && now - t0 < kAnimSeconds / 2.0) { + to = chosen; // (still closing: the new choice opens) + } else { + from = to, to = chosen, t0 = now; // (a new switch, from what is shown) + } + } + if (t0 < 0.0 || now - t0 >= kAnimSeconds) { + from = to, t0 = -1.0; + return {to, AnimFrame{}}; + } + const AnimFrame f = anim((float)(now - t0)); + return {f.after ? to : from, f}; + } +}; + +/// (step 8) The TV pass draws at the window: for the look's TV, or for the TV switching off and on (anim not done: the +/// squash over whatever look is shown, an Off one's too), never on HDR Native's PQ picture nor under DLSS frame generation +constexpr bool tv_draws(const Look& l, const AnimFrame& frame, bool native_pq, bool dlssg) { + return ((l.on && l.tv) || !frame.done) && !native_pq && !dlssg; +} + +// ---- (11-22, the owner's test: "the extra menu UI, and the options isn't in the exact position it should be") the TV's +// screen, for the mouse. The options are drawn under the TV now (vk_menu.cpp menu_tv_layer), so they bend with the game's +// own screens; the cursor is still where the window has it, flat. A point of the window is taken to the point of the +// picture the TV shows there, as n64_tv.comp finds it (its squash, then n64_tv.glsl n64_warp), and the controls are +// tested there, where they were drawn ---- + +/// A point in a window's pixels +struct ScreenPoint { + float x = 0.0f, y = 0.0f; +}; +/// The point of the picture the TV shows at (px, py) of the window: the picture fills the place x, y, w, h of the window +/// (the same pixels) through the screen's curve (curve) and the switch's squash (ax, ay: n64_tv.comp's anim_x, anim_y, 1 +/// at rest). Outside the place, or with no place: the point as it is. A point the TV shows black (off the curved picture, +/// or around the squash) is taken past the picture's edge, where nothing was drawn +constexpr ScreenPoint screen_point(float px, float py, float x, float y, float w, float h, float curve, float ax, float ay) { + if (w <= 0.0f || h <= 0.0f || ax <= 0.0f || ay <= 0.0f) return {px, py}; + float a = (px - x) / w * 2.0f - 1.0f, b = (py - y) / h * 2.0f - 1.0f; + if (a < -1.0f || a > 1.0f || b < -1.0f || b > 1.0f) return {px, py}; + a /= ax, b /= ay; + const float r = 1.0f + curve * (a * a + b * b); // (n64_warp: the same for both axes) + return {x + (a * r * 0.5f + 0.5f) * w, y + (b * r * 0.5f + 0.5f) * h}; +} + +} // namespace mkwvk::n64_rules diff --git a/gpu/vk/output_sizes.h b/gpu/vk/output_sizes.h new file mode 100644 index 0000000..7614724 --- /dev/null +++ b/gpu/vk/output_sizes.h @@ -0,0 +1,208 @@ +/* (Triforce) The Output resolution row's sizes and the picture they give, for host/nn_applet.c (the game's output at the + start), host/hos_main.c (the widescreen picture) and gpu/vk/vk_menu.cpp (the rows). One rule for every size: + + The Output resolution is the picture's size. The game's own frame (its HUD, menus and story movies) is 16:9 at that height. + A size of another shape is a wider or a narrower picture of exactly that size: the world fills it, and the frame + keeps its 16:9 shape in its middle (a narrower one: its whole width). A 16:9 size takes its shape from the Ultrawide + row instead (gpu/vk/ultrawide_rows.h), at the same height. + + So 3840 x 1600 is the frame 2848 x 1600 in the picture 3840 x 1600, a 12:5 screen pixel for pixel, and the Ultrawide + row has nothing to choose there: it shows the size's shape. + + 0 to 6 are fixed sizes, numbered as they were added so that a saved number keeps its size: 0 the game's 2048 x 1152, + 1 2560 x 1440, 2 3840 x 2160, 3 1920 x 1080, 4 5120 x 1440 (32:9), 5 5120 x 2880, 6 5120 x 2160 (21:9). Then: + - 9 Custom: any size, output_width= and output_height= in triforce_options.ini (the Output width and Output height + rows, 2560 x 1440 until they are set), or HOS_OUTPUT_SIZE=x over them. + The menu's row lists the size of every connected screen by the monitor's name (host/hos_screens.h), and choosing one + is choosing Custom with that size: what is saved is a size, never a screen's place among those connected, so the same + file gives the same picture at the next start whichever screens are there, and a size whose screen is gone is shown + as Custom. A screen of a fixed size is that fixed choice. + - 8 Screen: the size of the screen the game's window opens on, read at the start. What an options file from before + the screens were listed has, and HOS_OUTPUT_RES=8; it means what it meant, and the menu saves it as that size. + + Before options_version 8 the two fixed sizes that are not 16:9 were the game's frame itself: its 16:9 cameras and HUD + stretched over it unless the Ultrawide row was set to the same shape, and with another shape the row's picture at that + height. output_res_read keeps such a file's picture. + + Plain C: the host's C and the renderer's C++ both take it. */ +#ifndef OUTPUT_SIZES_H +#define OUTPUT_SIZES_H + +#include + +#define OUTPUT_FIXED_N 8 +#define OUTPUT_SCREEN 8 +#define OUTPUT_CUSTOM 9 +#define OUTPUT_LAST 9 +#define OUTPUT_OPTIONS_VERSION 9 /* (stock 0.6 and native 0.5.2 migrate to this distinct schema) */ + +/* A size from outside keeps its shape, within what the picture takes (5:4 to 32:9, output_picture), and is brought into + these limits in that shape: no side past its end, and at most 5120 x 2880's pixels. The game's render targets come from a + pool scaled with the picture's pixels and kept to 900 MB, the most known to pass the game's own reservation at boot + (host/nn_applet.c hos_rt_pool_size); 5120 x 2880 (14.7 million pixels) is the largest picture that booted and played + with it. So 7680 x 4320 is 5120 x 2880, and 10000 x 5000 is 5424 x 2712: smaller, never another shape. */ +#define OUTPUT_MIN_W 640 +#define OUTPUT_MIN_H 360 +#define OUTPUT_MAX_W 7680 +#define OUTPUT_MAX_H 2880 +#define OUTPUT_MAX_PIXELS (5120.0 * 2880.0) +/* A shape from the Ultrawide row or HOS_ASPECT at a 16:9 size: the picture kept to 3840 x 2160's pixels, as before (a 32:9 + picture at the 4K output was 7680 x 2160, and the game crashed as Kokiri Forest loaded, issue 1031: 5400 x 1520 there) */ +#define OUTPUT_ROW_PIXELS (3840.0 * 2160.0) +#define OUTPUT_SHAPE_MIN (5.0 / 4.0) +#define OUTPUT_SHAPE_MAX (32.0 / 9.0) + +/* The fixed size v's width or height (v 0 to 6) */ +static inline unsigned output_fixed_size(int v, int height) { + static const unsigned wh[OUTPUT_FIXED_N][2] = {{2048, 1152}, {2560, 1440}, {3840, 2160}, {1920, 1080}, + {5120, 1440}, {5120, 2880}, {5120, 2160}, {1536, 864}}; + if (v < 0 || v >= OUTPUT_FIXED_N) v = 0; + return wh[v][height ? 1 : 0]; +} + +/* The game's 16:9 frame at that height: its width the nearest whole multiple of 8 pixels (1600: 2848) */ +static inline unsigned output_frame_width(unsigned height) { return (height * 16u + 36u) / 72u * 8u; } + +/* Whether a shape, width over height, is the game's own 16:9 (within 1%: 1366 x 768 is) */ +static inline int output_shape_is_game(double shape) { + const double game = 16.0 / 9.0; + return !(shape > game * 1.01 || shape < game * 0.99); +} + +/* Whether a size has a shape of its own, not the game's 16:9: such a size is a wider or narrower picture by itself, and + the Ultrawide row does not apply to it */ +static inline int output_size_shaped(unsigned w, unsigned h) { return w && h && !output_shape_is_game((double)w / (double)h); } + +/* "x" (HOS_OUTPUT_SIZE): 1 and the two sides, or 0 when it is not that */ +static inline int output_parse_size(const char *s, long *w, long *h) { + long v[2] = {0, 0}; + int i = 0; + if (!s) return 0; + for (;; s++) { + if (*s >= '0' && *s <= '9') { + if (v[i] > 100000) return 0; + v[i] = v[i] * 10 + (*s - '0'); + } else if ((*s == 'x' || *s == 'X') && i == 0 && v[0] > 0) { + i = 1; + } else if (*s == 0 && i == 1 && v[1] > 0) { + *w = v[0], *h = v[1]; + return 1; + } else { + return 0; + } + } +} + +/* (output_size_used) The widths, whole multiples of 8, that a picture of height h can have on one side of 16:9 (wide: wider + than it, else narrower): those whose shape is within 5:4 to 32:9 and outside the 1% beside 16:9, within the width's ends + and the pixels. *lo > *hi: none at that height */ +static inline void output_width_range(unsigned h, int wide, unsigned *lo, unsigned *hi) { + const double game = 16.0 / 9.0, edge = (double)h * game * (wide ? 1.01 : 0.99); + double least = wide ? floor(edge / 8.0) * 8.0 + 8.0 : ceil((double)h * OUTPUT_SHAPE_MIN / 8.0) * 8.0; /* (past the edge) */ + double most = wide ? floor((double)h * OUTPUT_SHAPE_MAX / 8.0) * 8.0 : ceil(edge / 8.0) * 8.0 - 8.0; /* (short of it) */ + const double pixels = floor(OUTPUT_MAX_PIXELS / (double)h / 8.0) * 8.0; + if (least < OUTPUT_MIN_W) least = OUTPUT_MIN_W; + if (most > OUTPUT_MAX_W) most = OUTPUT_MAX_W; + if (most > pixels) most = pixels; + *lo = (unsigned)least, *hi = most < 0 ? 0 : (unsigned)most; +} + +/* A size from outside as the game takes it: 0 when there is none (a side 0 or less); else 1 and the size in its own shape + (kept to 5:4 to 32:9) within the limits above: made smaller in that shape where a side or the pixels are past them, larger + where a side is under its least. Its width is a whole multiple of 8 pixels (as every picture's), its height too where it + was made smaller, and a shape within 1% of 16:9 is the game's own frame at that height. The shape is taken first: clamping + each side by itself would change it (7680 x 4320 would come out 2.67:1). + What comes out is the picture, pixel for pixel, and is taken as itself when given again (the menu saves it and the host + reads it back). That holds by how the width is chosen, not by trying again: the width is the multiple of 8 nearest the + shape's among those output_width_range allows at that height, so the size that comes out keeps every limit and its side of + 16:9; given again, nothing makes it smaller or larger, its height stays, and its own width is the nearest to its shape. + Rounding the width alone to the nearest 8 did not have that: at an end of the shapes it could pass the end, and beside + 16:9 it could fall into the 1% (tests/test_output_resolution.py goes through sizes) */ +static inline int output_size_used(long w, long h, unsigned *out_w, unsigned *out_h) { + if (w <= 0 || h <= 0) return 0; + double shape = (double)w / (double)h; + if (shape > OUTPUT_SHAPE_MAX) shape = OUTPUT_SHAPE_MAX; + if (shape < OUTPUT_SHAPE_MIN) shape = OUTPUT_SHAPE_MIN; + if (output_shape_is_game(shape)) { /* (16:9 fits every limit at a height within its own) */ + const unsigned uh = (unsigned)(h < OUTPUT_MIN_H ? OUTPUT_MIN_H : h > OUTPUT_MAX_H ? OUTPUT_MAX_H : h); + *out_w = output_frame_width(uh), *out_h = uh; + return 1; + } + const int wide = shape > 16.0 / 9.0; + double fh = (double)h, scale = 1.0; + const double fw = fh * shape; + if (fh * scale > OUTPUT_MAX_H) scale = OUTPUT_MAX_H / fh; + if (fw * scale > OUTPUT_MAX_W) scale = OUTPUT_MAX_W / fw; + if (fw * fh * scale * scale > OUTPUT_MAX_PIXELS) scale = sqrt(OUTPUT_MAX_PIXELS / (fw * fh)); + unsigned uh, lo, hi; + if (scale < 1.0) { /* (smaller, in its shape: the height a whole multiple of 8 as well) */ + uh = (unsigned)(fh * scale / 8.0) * 8u; + } else { + if (fh < OUTPUT_MIN_H) fh = OUTPUT_MIN_H; + if (fh * shape < OUTPUT_MIN_W) fh = OUTPUT_MIN_W / shape; + uh = (unsigned)ceil(fh); + } + output_width_range(uh, wide, &lo, &hi); + /* (no width at that height: a shape just wider than 16:9 at the most pixels, where the first width past the 1% is over + them, by 8 at most. 8 lines fewer make room: there the pixels then allow about 14 more of width, and the 1% is about + 14 nearer) */ + if (lo > hi) uh = (uh - 1u) / 8u * 8u, output_width_range(uh, wide, &lo, &hi); + unsigned uw = (unsigned)((double)uh * shape / 8.0 + 0.5) * 8u; + if (uw < lo) uw = lo; + if (uw > hi) uw = hi; + *out_w = uw, *out_h = uh; + return 1; +} + +/* output_width= and output_height= as an options file has them (0: no line), for Custom's size: a side that is not a size + (no line, 0 or less) is the row's default, 2560 and 1440. The host and the menu read the file's two numbers through this + and output_size_used, so a size written past the rows' ends keeps its shape for both */ +static inline void output_custom_read(long *w, long *h) { + if (*w <= 0) *w = 2560; + if (*h <= 0) *h = 1440; +} + +/* The picture for the game's frame of height frame_h and a shape want, width over height: 0 for the game's own 16:9 picture + (want 0, 1 or less, or within 1% of 16:9), else 1 and its size, whole multiples of 8 pixels wide. The shape is kept to + 5:4 to 32:9. sized: the shape is the Output resolution's own (frame_h its height, want its width over its height), and the + picture is that size; otherwise the shape is the Ultrawide row's or HOS_ASPECT's, and a picture of more than + 3840 x 2160's pixels is made smaller in its shape */ +static inline int output_picture(unsigned frame_h, double want, int sized, unsigned *out_w, unsigned *out_h) { + if (!(want > 1.0) || output_shape_is_game(want)) return 0; + const double r = want > OUTPUT_SHAPE_MAX ? OUTPUT_SHAPE_MAX : want < OUTPUT_SHAPE_MIN ? OUTPUT_SHAPE_MIN : want; + const double most = sized ? OUTPUT_MAX_PIXELS : OUTPUT_ROW_PIXELS; + unsigned oh = frame_h, ow = (unsigned)(oh * r / 8 + 0.5) * 8; /* (whole multiples of 8 pixels) */ + if ((double)ow * oh > most) { + oh = (unsigned)(sqrt(most / r) / 8) * 8; + ow = (unsigned)(oh * r / 8) * 8; + } + *out_w = ow, *out_h = oh; + return 1; +} + +/* output_res= as an options file holds it, with the file's options_version and its Ultrawide row (as ultrawide_row_read + gives it). Before version 8, 4 (5120 x 1440) and 6 (5120 x 2160) were the game's frame: with the row on another shape + than theirs the picture was the row's at their height, which the 16:9 size of that height (1, 2560 x 1440, and 2, + 3840 x 2160) gives with the same row. With the row on their own shape the picture was theirs, as it is now; with the row + on 16:9 the 16:9 picture was stretched over them, and is now theirs too */ +static inline int output_res_read(int v, int version, int ultrawide_row) { + if (version >= 8) return v; + if (v == 4 && ultrawide_row != 0 && ultrawide_row != 3) return 1; + if (v == 6 && ultrawide_row != 0 && ultrawide_row != 2) return 2; + return v; +} + +/* Stock 0.6 and the native 0.5.2 branch both wrote version 8. The native writer + always wrote Custom's size fields, even under a fixed output. Before 8, stock + had no output 7/8. Call before clamping the saved value or migrating handheld. */ +static inline int output_legacy_file(int version, int size_fields) { + return version < 8 || (version == 8 && size_fields); +} +static inline int output_file_read(int v, int version, int row, int size_fields) { + if (version >= OUTPUT_OPTIONS_VERSION) return v; + const int legacy = output_legacy_file(version, size_fields); + v = output_res_read(v, legacy ? version : 7, row); + if (legacy && v >= 7 && v <= 8) return v + 1; + return v; +} +#endif diff --git a/gpu/vk/replay_threads.h b/gpu/vk/replay_threads.h index 9f807a7..b9bc528 100644 --- a/gpu/vk/replay_threads.h +++ b/gpu/vk/replay_threads.h @@ -249,10 +249,36 @@ inline Verdict rule(const Frame& m, int threads) { /// - a trial whose first and last parts moved so decides nothing, either way (not better, no recheck), and the next one comes /// kWindow after a window of the way in use like the one before it (settle_look), not kEvery later, and never while the rule /// says no trial. kHold and the thresholds as they were. tests/test_replay_threads_tuner.py "settled" +/// (Triforce, 11-22) And with settled, between trials, the way in use's windows each against the one before it (settle_look, +/// all the time now, not only after a trial the scene moved under): the scene is calm while two in a row describe one scene. A +/// change of way, a trial's start and a load begin it again (a trial that ends without a change and without its scene moving +/// keeps it: its frames were the same way's as before it). On the same 5900X and RTX 3090 (v0.6.0 with the settled scenes +/// above, the benchmark's route, fix one's A/B), three things were still left: +/// - a trial on a loading screen: nothing there is cut, both ways are the same work, yet it was measured and its "as it was" +/// put the next one off. A trial due in a calm scene with nothing to cut does not begin; it stays due; +/// - a trial due during an arrival: it began on the arrival's frames and decided nothing. A trial due waits for a calm scene, +/// kEvery presents at most (one that never calms still has its trials), and after a trial the scene moved under the next is +/// kWindow after the scene settled, as above, but never more than kEvery after it was due (no INT64_MAX wait); +/// - the rule's "on" in an arrival's steady stretch: the Market's textures loaded for some 4 s at 36 to 46 fps (the replay +/// 17.3 ms of a 21.5 ms frame, 2,174 draws), two windows alike, so the rule judged it and turned the helper threads on; the +/// area then came down to its settled frames (582 draws) and the "on" stood for the 20 s measured, 56.1 fps against 60.9 +/// with them off. An "on" the rule gave holds only for the scene it judged: the first window of the helper threads after it +/// is its reference, and the first that moved from it (scene_moved) takes them back off (withdrawn), no kHold, the rule to +/// judge the new scene's windows again. A trial that ends in a calm scene decides from then on, and nothing is withdrawn. +/// tests/test_replay_threads_tuner.py "settled" +/// (Triforce, 11-23) And the rule's "on" needs kOnWindows (3) windows in a row on the replay thread alone, each within +/// scene_moved's margins of the first of them; its "no trial" two alike, as above. On 0.7 with the above (testq #973, the +/// benchmark's route, 3 launches) the rule turned the helper threads on at every Market arrival: the area's texture load comes +/// down window by window (2,284, 2,211 and 2,339 draws in the windows it judged, 1,634, 1,621 and 1,618 in the next, then 877, +/// 861 and 823), each step under kSceneDraws, so two neighbouring windows passed as one scene; the "on" stood 360 presents +/// until withdrawn, its frames 2.2 ms longer (15.3 to 16.5 ms against 13.1 to 13.7 with the helper threads off). Stock 0.7's +/// pairwise gate gave the same "on" in 5 of its 9 launches. Where the helpers win, "on" comes a window later (kWindow presents +/// after each arrival). tests/test_replay_threads_tuner.py "calm" class Tuner { public: static constexpr int kEvery = 900, kTake = 80, kSettle = 24, kWindow = 120, kHold = 4 * kEvery; static constexpr int kTakeShort = 40, kBackoffMax = 16 * kEvery; + static constexpr int kOnWindows = 3; // (settled: the windows in a row, alike to the first of them, the rule's "on" needs) static constexpr double kClear = 1.10, kSceneDraws = 0.25, kSceneDrawsMin = 200, kScenePart = 0.30, kScenePartMs = 1.0; bool use_rule = true; bool backoff = true; // (the back-off above; false: every step as before it) @@ -279,6 +305,9 @@ public: // (settled's) bool unsettled = false; // (a window the rule did not judge, or a trial that decided nothing: the scene moved) bool settle = false; // (the scene settled after such a trial: the next trial at next) + bool withdrawn = false; // (the rule's "on" taken back: its scene changed, window the frames it moved to, ref its own) + bool on_waits = false; // (the rule says on, but its scene has not held kOnWindows windows yet) + Frame ref; }; /// f: the frame just presented; on: the helper threads in use for it; order_only: both ways are the replay thread alone Step step(const Frame& f, bool on, bool order_only) { @@ -293,12 +322,19 @@ public: // the same scene) s.window = win_.mean(); const bool same = !settled || (win_prev_set_ && !scene_moved(win_prev_, s.window)); + // (and the rule's "on" kOnWindows in a row, each within the margins of the first of them: an arrival's + // texture load that comes down a little each window passes two windows alike, not this) + if (!same) on_anchor_ = s.window, on_run_ = 1; + else if (scene_moved(on_anchor_, s.window)) on_anchor_ = win_prev_, on_run_ = 2; + else on_run_++; win_prev_ = s.window, win_prev_set_ = true; if (!same) { s.unsettled = true; } else { s.ruled = true, s.verdict = rule(s.window, threads); - const bool turn_on = s.verdict.kind == Verdict::kOn && frames_ >= hold_until_; + const bool held_on = settled && on_run_ < kOnWindows; // (the scene not held long enough yet) + const bool turn_on = s.verdict.kind == Verdict::kOn && frames_ >= hold_until_ && !held_on; + s.on_waits = s.verdict.kind == Verdict::kOn && held_on; s.rule_new = s.verdict.kind != last_ || turn_on; last_ = s.verdict.kind; if (turn_on) { @@ -306,6 +342,7 @@ public: next_trial_ = frames_ + kEvery; waiting_ = false, win_prev_set_ = false; // (the way changed: a trial kEvery on, as after a change) if (backoff) held_ = 0, fresh_ = true, scene_restart(); + if (settled) calm_restart(), by_rule_ = true, rule_ref_set_ = false; // (its scene's, below) } else if (s.verdict.kind == Verdict::kOff) { next_trial_ = std::max(next_trial_, frames_ + kEvery); no_trial_until_ = frames_ + kEvery; @@ -320,13 +357,31 @@ public: } else { win_ = Part{}, win_frames_ = 0, win_prev_set_ = false; } - if (waiting_) settle_look(f, s); - else if (backoff) scene_look(f, s); + if (settled) { + settle_look(f, on, s); + if (s.flip) return s; // (the rule's "on" withdrawn) + } + if (backoff && !waiting_) scene_look(f, s); if (frames_ < next_trial_) return s; if (order_only) return s; + // (settled: a trial due waits for a calm scene, kEvery at most, one that never calms still has its trials; and none + // begins where nothing is cut, both ways the same work) + if (settled) { + if (calm_ && calm_cut_ <= 0) { + due_from_ = -1; + return s; + } + if (!calm_) { + if (due_from_ < 0) due_from_ = frames_; + if (frames_ - due_from_ < kEvery) return s; + waiting_ = false; // (a scene that does not settle: the trial goes ahead, as before) + } + due_from_ = -1; + } phase_ = 1, n_ = 0; short_ = backoff && held_ >= 2; win_ = Part{}, win_frames_ = 0, win_prev_set_ = false; // (the rule's next window begins after the trial) + settle_win_ = Part{}, settle_frames_ = 0; // (and the calm scene's: its window before and its state are kept) sum_[0] = sum_[1] = sum_[2] = 0, cnt_[0] = cnt_[1] = cnt_[2] = 0; part_[0] = part_[1] = part_[2] = Part{}; return s; @@ -379,9 +434,14 @@ public: last_end_ = frames_; scene_restart(); } - if (s.unsettled) { // (the next trial kWindow after a window like the one before it: settle_look) - waiting_ = true, next_trial_ = INT64_MAX; - settle_win_ = Part{}, settle_frames_ = 0, settle_prev_set_ = false; + if (s.unsettled) { // (the next trial kWindow after a window like the one before it, settle_look; kEvery after it is + // due at most, the trial gate above) + waiting_ = true, next_trial_ = std::max(frames_ + kWindow, no_trial_until_); + } + if (settled) { + if (s.flip || moved) calm_restart(); // (the other way's frames, or another scene's) + if (s.ok && !moved) by_rule_ = false; // (a trial in a calm scene decides from here: nothing to withdraw) + else rule_ref_set_ = false; // (else the rule's "on" is held against the scene after the trial) } s.next = next_trial_; s.trial = true, s.parts = part_; @@ -405,9 +465,13 @@ public: private: void scene_restart() { scene_win_ = Part{}, scene_frames_ = 0, ref_set_ = false, strikes_ = 0; } - /// (settled: after a trial the scene moved under, the way's windows each against the one before; the first like it, and - /// the next trial kWindow on, never while the rule says no trial. A load breaks the run) - void settle_look(const Frame& f, Step& s) { + /// (settled: the calm scene begins again: the other way's frames, or another scene's) + void calm_restart() { settle_win_ = Part{}, settle_frames_ = 0, settle_prev_set_ = false, calm_ = false; } + /// (settled: between trials, the way in use's windows each against the one before; calm while two in a row describe one + /// scene, a load breaks the run. After a trial the scene moved under, the first like the one before it, and the next trial + /// kWindow on, never while the rule says no trial. And while the helper threads are on by the rule's "on", no trial since: + /// their first window is its reference, and the first that moved from it takes them back off) + void settle_look(const Frame& f, bool on, Step& s) { if (f.frame <= 60.0) settle_win_.add(f); if (++settle_frames_ < kWindow) return; const bool counted = settle_win_.n >= kWindow * 3 / 4; @@ -415,7 +479,20 @@ private: settle_win_ = Part{}, settle_frames_ = 0; const bool same = counted && settle_prev_set_ && !scene_moved(settle_prev_, m); settle_prev_ = m, settle_prev_set_ = counted; - if (!same) return; + calm_ = same; + if (counted) calm_cut_ = m.cut; + if (counted && on && by_rule_) { // (a load is no window of either scene: the next counted one tells) + if (!rule_ref_set_) { + rule_ref_ = m, rule_ref_set_ = true; + } else if (scene_moved(rule_ref_, m)) { + s.flip = s.withdrawn = true, s.window = m, s.ref = rule_ref_; + by_rule_ = false, rule_ref_set_ = false, win_prev_set_ = false; + if (backoff) held_ = 0, fresh_ = true, scene_restart(); + calm_restart(); + return; + } + } + if (!same || !waiting_) return; waiting_ = false, s.settle = true; next_trial_ = std::max(frames_ + kWindow, no_trial_until_); s.next = next_trial_; @@ -465,6 +542,13 @@ private: bool win_prev_set_ = false, waiting_ = false, settle_prev_set_ = false; Part settle_win_; int settle_frames_ = 0; + // (the calm scene's between trials, the trial due's wait for it, and the rule's "on" held against its scene) + bool calm_ = false, by_rule_ = false, rule_ref_set_ = false; + double calm_cut_ = 0; + Frame on_anchor_; // (the first window of the run the rule's "on" is judged by, and the run's windows so far) + int on_run_ = 0; + int64_t due_from_ = -1; + Frame rule_ref_; }; } // namespace replay_threads diff --git a/gpu/vk/save_file_rows.h b/gpu/vk/save_file_rows.h new file mode 100644 index 0000000..20b88af --- /dev/null +++ b/gpu/vk/save_file_rows.h @@ -0,0 +1,200 @@ +// (Triforce) Save files on the menu's side: the files the host names (host/save_files.c; vk_api.h HOS_OPT_FILES_*), the one +// this run plays, the one the player chose, and what the host said became of it. vk_menu.cpp draws the file select. +// +// The files are the host's: each is a folder the game saves in, and the game is started on one of them. The menu is told +// each file's name, when it was last saved and which is this run's, a byte a call as the save rows' lines are. A file +// chosen that is this run's is played at once; another is asked of the host, which keeps it as the next start's and says +// so: the menu then restarts the game. +// +// The host's calls (text, add, done, said) come on the game's presenting thread, the page is drawn and pressed on the +// renderer's: names and lines are written before count says the files are there and never after; the rest are atomics. +// +// No ImGui and no Vulkan: tests/test_save_files.py compiles it alone. +#pragma once +#include +#include +#include +#include +#include + +namespace save_file_rows { +constexpr int kSlots = 3; // (host/save_files.h SAVE_FILES; List::slots has an entry for each) +constexpr int kName = 25, kWhen = 24; +constexpr int kPath = 600; // (the file its picture is in: a path of the game folder's) +constexpr int kPlace = 49; // (where it was played last: host/save_files.h SAVE_CARD_PLACE and its end) +constexpr int kStones = 3, kMedals = 6, kHearts = 20; // (host/save_files.h SAVE_CARD_*: its items' bits, the stones first) +constexpr int kSaved = 1, kCurrent = 2; // (vk_api.h HOS_FILE_*) +constexpr int kChosen = 256; // (vk_api.h HOS_FILES_CHOSEN) +enum Said { kNothing, kRestart, kFailed }; // (vk_api.h HOS_OPT_FILES_SAID: 1 and 2) + +struct List { + char names[kSlots][kName] = {}; + char whens[kSlots][kWhen] = {}; + char pictures[kSlots][kPath] = {}; // (where its saves' captions are: "NN\caption.sav", NN the slot; "" no save in it) + // (its card, as the host kept it while the file was played: host/save_files.h SaveCard) + char places[kSlots][kPlace] = {}; // (where it was played last, "" not known) + int items[kSlots] = {}; // (the stones and medallions held: bits 0 to kStones - 1, then kMedals) + int hearts[kSlots] = {}; // (heart containers, 0 not known) + int slots[kSlots] = {-1, -1, -1}; // (the slot the game saved in last while the file was played, -1 not known) + char made[kSlots][kWhen] = {}; // (and when, as the game writes a time; "" not known) + unsigned char bits[kSlots] = {}; + std::atomic count{0}; // (the files shown: 0 until the host's list is whole) + std::atomic after_choice{0}; // (this start follows a choice: the game restarted for it) + std::atomic ask{0}; // (the file chosen that is not this run's, its number, until the host takes it) + std::atomic answer{kNothing}; + // the host's side + char in[kName + 2 * kWhen + kPath + kPlace + 48] = {}; + int in_n = 0, added = 0; + + /// HOS_OPT_FILES_TEXT: the next byte of the file being named + void text(int byte) { + if (byte > 0 && byte < 256 && in_n + 1 < (int)sizeof in) in[in_n++] = (char)byte; + } + static int hex(char ch) { return ch >= '0' && ch <= '9' ? ch - '0' : ch >= 'a' && ch <= 'f' ? ch - 'a' + 10 : -1; } + /// `from` copied into a field of `cap` bytes, cut at a whole letter + static void put(char* to, int cap, const char* from) { + int n = (int)strlen(from); + if (n > cap - 1) { + n = cap - 1; + while (n && ((unsigned char)from[n] & 0xC0) == 0x80) n--; + } + memcpy(to, from, (size_t)n); + to[n] = 0; + } + /// HOS_OPT_FILES_ADD: the bytes so far are the next file's name and, each after a line feed, when it was last saved, the + /// file its picture is in, and its card: "||||" + void add(int file_bits) { + in[in_n] = 0; + in_n = 0; + if (count.load(std::memory_order_acquire) || added >= kSlots) return; // (shown already, or no room left) + const int slot = added++; + char* when = strchr(in, '\n'); + char* picture = when ? strchr(when + 1, '\n') : nullptr; + char* card = picture ? strchr(picture + 1, '\n') : nullptr; + if (when) *when++ = 0; + if (picture) *picture++ = 0; + if (card) *card++ = 0; + put(names[slot], kName, in[0] ? in : "(no name)"); + put(whens[slot], kWhen, when ? when : ""); + if (picture && strlen(picture) < (size_t)kPath) strcpy(pictures[slot], picture); // (a path cut short names no file: none then) + if (char* bar = card ? strchr(card, '|') : nullptr) { + *bar++ = 0; + put(places[slot], kPlace, card); + int held = 0, n = 0; + for (; hex(*bar) >= 0 && n < 4; bar++, n++) held = held << 4 | hex(*bar); + items[slot] = held & ((1 << (kStones + kMedals)) - 1); + const int count = *bar == '|' ? atoi(bar + 1) : 0; + hearts[slot] = count >= 1 && count <= kHearts ? count : 0; + if (char* last = *bar == '|' ? strchr(bar + 1, '|') : nullptr) { + const int in = atoi(last + 1); + char* when_made = strchr(last + 1, '|'); + if (in >= 0 && in < 12 && when_made && (last[1] >= '0' && last[1] <= '9')) slots[slot] = in, put(made[slot], kWhen, when_made + 1); + } + } + bits[slot] = (unsigned char)(file_bits & (kSaved | kCurrent)); + } + /// HOS_OPT_FILES_COUNT: the list is whole: how many, and kChosen + void done(int value) { + in_n = 0; + if (count.load(std::memory_order_acquire)) return; + const int n = value & 255; + after_choice.store((value & kChosen) != 0, std::memory_order_relaxed); + count.store(n < added ? n : added, std::memory_order_release); + } + int shown() const { return count.load(std::memory_order_acquire); } + /// The file this run plays, -1 when the host named none as it + int current() const { + for (int i = 0, n = shown(); i < n; i++) + if (bits[i] & kCurrent) return i; + return -1; + } + bool saved(int slot) const { return slot >= 0 && slot < shown() && (bits[slot] & kSaved); } + /// The title asks which file to play: the files are there. At every start, the one that follows a choice too: the file + /// select is where a file is changed again (asked once after a choice and not again, there was no way back from the title) + bool asks() const { return shown() > 0; } + /// This start follows a choice at the file select (the game restarted for it) + bool chosen() const { return after_choice.load(std::memory_order_relaxed) != 0; } + /// A file chosen. true: it is this run's, played at once. false: asked of the host (or no such file: nothing asked) + bool choose(int slot) { + if (slot < 0 || slot >= shown()) return false; + if (slot == current()) return true; + answer.store(kNothing, std::memory_order_relaxed); + ask.store(slot + 1, std::memory_order_release); + return false; + } + /// HOS_OPT_FILES_ASK: the file chosen since the last read, its number; 0 none + int take_ask() { return ask.load(std::memory_order_relaxed) ? ask.exchange(0, std::memory_order_acq_rel) : 0; } + /// HOS_OPT_FILES_SAID: what became of the file asked for + void said(int value) { answer.store(value == 1 ? kRestart : value == 2 ? kFailed : kNothing, std::memory_order_release); } + /// The host's word since the last ask, once: kRestart, kFailed, or kNothing + int take_said() { return answer.load(std::memory_order_relaxed) ? answer.exchange(kNothing, std::memory_order_acq_rel) : kNothing; } +}; + +/// A save's picture in the bytes of the file that holds it: the game keeps it as a JPEG among its own data. From the first +/// start of one (FF D8 FF) to the last end of one after it (FF D9): where it is and how long, false when there is none +inline bool jpeg_in(const unsigned char* bytes, size_t n, size_t* at, size_t* len) { + size_t first = n, last = 0; + for (size_t i = 0; i + 2 < n; i++) + if (bytes[i] == 0xFF && bytes[i + 1] == 0xD8 && bytes[i + 2] == 0xFF) { first = i; break; } + if (first == n) return false; + for (size_t i = n - 1; i > first + 2; i--) + if (bytes[i] == 0xD9 && bytes[i - 1] == 0xFF) { last = i + 1; break; } + if (!last) return false; + *at = first, *len = last - first; + return true; +} + +/// When a save was made, as its caption file has it. The game shows a save's own time on its load list; the files' dates on +/// the disk are not that (the game writes every slot again when it saves any, and its settings at other times). The +/// caption's form is not known to this repository, so the time is looked for as the two shapes a console's time has, in +/// the bytes outside the picture: a calendar time (year, a 16-bit number, then month, day, hour, minute, second, a byte +/// each), and failing that a count of seconds since 1970 (64 bits). The latest found is taken, and the log says which +/// (vk_menu.cpp files_pictures_load): a card whose time is wrong says the shape is another +struct SaveTime { + int kind = 0; // (0 none found, 1 a calendar time, 2 a count of seconds) + int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0; // (kind 1) + int64_t seconds = 0; // (kind 2) + /// later than `o`? (of the same kind: a file's saves are) + bool after(const SaveTime& o) const { return kind > o.kind || (kind == o.kind && key() > o.key()); } + int64_t key() const { + return kind == 2 ? seconds : kind == 1 ? ((((((int64_t)year * 13 + month) * 32 + day) * 24 + hour) * 60 + minute) * 60 + second) : 0; + } +}; +/// max_year, max_seconds: now, a day on (a save is not of the future): among a file's other bytes a time of any year was +/// found where there was none ("9/25/2093", his picture, 11-18). No save of this game is older than 2025 +inline SaveTime caption_time(const unsigned char* b, size_t n, size_t picture_at, size_t picture_len, int max_year, int64_t max_seconds) { + SaveTime best, posix; + const auto outside = [&](size_t i, size_t len) { return i + len <= picture_at || i >= picture_at + picture_len; }; + for (size_t i = 0; i + 7 <= n; i++) { + if (!outside(i, 7)) continue; + SaveTime t; + t.kind = 1, t.year = b[i] | b[i + 1] << 8, t.month = b[i + 2], t.day = b[i + 3], t.hour = b[i + 4], t.minute = b[i + 5], t.second = b[i + 6]; + if (t.year < 2025 || t.year > max_year || t.month < 1 || t.month > 12 || t.day < 1 || t.day > 31 || t.hour > 23 || t.minute > 59 || t.second > 59) + continue; + if (t.after(best)) best = t; + } + if (best.kind) return best; + for (size_t i = 0; i + 8 <= n; i++) { + if (!outside(i, 8) || b[i + 4] || b[i + 5] || b[i + 6] || b[i + 7]) continue; + const int64_t v = (int64_t)b[i] | (int64_t)b[i + 1] << 8 | (int64_t)b[i + 2] << 16 | (int64_t)b[i + 3] << 24; + if (v < 1735689600LL || v > max_seconds) continue; // (2025 to now) + SaveTime t; + t.kind = 2, t.seconds = v; + if (t.after(posix)) posix = t; + } + return posix; +} +/// A time as the game's load list writes it: 11/18/2026 1:40 a.m. +inline void game_time(char* out, size_t cap, int year, int month, int day, int hour, int minute) { + snprintf(out, cap, "%d/%d/%d %d:%02d %s", month, day, year, hour % 12 ? hour % 12 : 12, minute, hour < 12 ? "a.m." : "p.m."); +} + +/// The choice moved by Up and Down (step), Home and End, kept to the n files. true: it moved +inline bool move(int& choice, int step, bool home, bool end, int n) { + if (n <= 0) return false; + const int was = choice; + choice = home ? 0 : end ? n - 1 : choice + step; + choice = choice < 0 ? 0 : choice >= n ? n - 1 : choice; + return choice != was; +} +} // namespace save_file_rows diff --git a/gpu/vk/shaders/fg_scale.comp b/gpu/vk/shaders/fg_scale.comp index e6fc6aa..2d48372 100644 --- a/gpu/vk/shaders/fg_scale.comp +++ b/gpu/vk/shaders/fg_scale.comp @@ -76,6 +76,11 @@ vec3 side_fill(vec2 uv) { } // (and less than one step of 8 bits of noise over it: the dim, smooth sides showed 8-bit steps as contour lines) float dither(ivec2 g) { return (fract(52.9829189 * fract(0.06711056 * float(g.x) + 0.00583715 * float(g.y))) - 0.5) / 255.0; } +// The sides cover every pixel outside the middle; the soft edge belongs inside the menu's own edge. +float side_outside(float x, float x0, float x1) { + const float feather = 0.006; + return max(1.0 - smoothstep(x0, x0 + feather, x), smoothstep(x1 - feather, x1, x)); +} void main() { const ivec2 g = ivec2(gl_GlobalInvocationID.xy); const ivec2 d = imageSize(dst); @@ -92,8 +97,7 @@ void main() { // (beside a menu: the sides first, and wholly outside the middle nothing else, not the filter's 16 taps to throw away) float outside = 0.0; if (pc.side != 0 && pc.x1 > pc.x0) { - const float feather = 0.006; - outside = max(1.0 - smoothstep(pc.x0 - feather, pc.x0, uv.x), smoothstep(pc.x1, pc.x1 + feather, uv.x)); + outside = side_outside(uv.x, pc.x0, pc.x1); if (outside >= 1.0) { imageStore(dst, g, vec4(pc.side == 2 ? vec3(0.0) : side_fill(uv) + dither(g), 1.0)); return; diff --git a/gpu/vk/shaders/fg_scale_comp_spv.h b/gpu/vk/shaders/fg_scale_comp_spv.h index 4bd4a46..e5d177b 100644 --- a/gpu/vk/shaders/fg_scale_comp_spv.h +++ b/gpu/vk/shaders/fg_scale_comp_spv.h @@ -1,11 +1,11 @@ -// fg_scale.comp sha256 8fa651e772e5095ebdd47bd844fd2a637ccae7ff9e851d2235751f44bb09367c (tests/test_fg_scale_sharpen.py --write: glslangValidator -V --target-env vulkan1.2 --vn FG_SCALE_COMP_SPV) +// fg_scale.comp sha256 7e8baf842b4319e5ae86cae0b650af1c239b175836feeabf8380ea5420c70530 (tests/test_fg_scale_sharpen.py --write: glslangValidator -V --target-env vulkan1.2 --vn FG_SCALE_COMP_SPV) // 1116.6.0 #pragma once const uint32_t FG_SCALE_COMP_SPV[] = { - 0x07230203,0x00010500,0x0008000b,0x000002b5,0x00000000,0x00020011,0x00000001,0x00020011, + 0x07230203,0x00010500,0x0008000b,0x000002c1,0x00000000,0x00020011,0x00000001,0x00020011, 0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e, - 0x00000000,0x00000001,0x000a000f,0x00000005,0x00000004,0x6e69616d,0x00000000,0x0000007c, - 0x00000087,0x00000155,0x000001b6,0x000001be,0x00060010,0x00000004,0x00000011,0x00000008, + 0x00000000,0x00000001,0x000a000f,0x00000005,0x00000004,0x6e69616d,0x00000000,0x00000082, + 0x0000008d,0x0000015b,0x000001cb,0x000001d3,0x00060010,0x00000004,0x00000011,0x00000008, 0x00000008,0x00000001,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, 0x00000000,0x00060005,0x0000000a,0x636e616c,0x32736f7a,0x3b316628,0x00000000,0x00030005, 0x00000009,0x00000078,0x00050005,0x0000000d,0x6d746163,0x286c6c75,0x003b3166,0x00030005, @@ -16,471 +16,480 @@ const uint32_t FG_SCALE_COMP_SPV[] = { 0x00000077,0x00030005,0x0000001c,0x00000065,0x00040005,0x0000001d,0x756f6d61,0x0000746e, 0x00060005,0x00000021,0x65646973,0x6c69665f,0x6676286c,0x00003b32,0x00030005,0x00000020, 0x00007675,0x00050005,0x00000028,0x68746964,0x76287265,0x003b3269,0x00030005,0x00000027, - 0x00000067,0x00030005,0x0000003b,0x00000070,0x00030005,0x0000007a,0x00000050,0x00050006, - 0x0000007a,0x00000000,0x65646f6d,0x00000000,0x00050006,0x0000007a,0x00000001,0x72616873, - 0x00000070,0x00040006,0x0000007a,0x00000002,0x00003078,0x00040006,0x0000007a,0x00000003, - 0x00003178,0x00050006,0x0000007a,0x00000004,0x65646973,0x00000000,0x00030005,0x0000007c, - 0x00006370,0x00030005,0x00000087,0x00637273,0x00040005,0x0000008e,0x657a6973,0x00000000, - 0x00030005,0x00000093,0x00000070,0x00030005,0x00000099,0x00000062,0x00030005,0x0000009d, - 0x00000066,0x00030005,0x000000a2,0x006d7573,0x00040005,0x000000a4,0x67696577,0x00007468, - 0x00030005,0x000000a6,0x00000079,0x00030005,0x000000b0,0x00000078,0x00030005,0x000000b8, - 0x00000064,0x00030005,0x000000c0,0x00000077,0x00040005,0x000000c7,0x61726170,0x0000006d, - 0x00040005,0x000000cd,0x61726170,0x0000006d,0x00040005,0x000000d4,0x61726170,0x0000006d, - 0x00040005,0x000000d8,0x61726170,0x0000006d,0x00030005,0x000000ff,0x00346f6c,0x00030005, - 0x00000107,0x00346968,0x00030005,0x0000010f,0x00006f6c,0x00030005,0x00000113,0x00006968, - 0x00050005,0x00000117,0x625f6f74,0x6b63616c,0x00000000,0x00050005,0x0000011f,0x775f6f74, - 0x65746968,0x00000000,0x00040005,0x00000129,0x6d6f6f72,0x00000000,0x00040005,0x0000012d, - 0x65626f6c,0x00000000,0x00040005,0x0000013d,0x72616873,0x00000070,0x00040005,0x00000154, - 0x70657473,0x00000000,0x00040005,0x00000155,0x6c616d73,0x0000006c,0x00030005,0x0000015c, - 0x006d7573,0x00040005,0x0000015d,0x67696577,0x00007468,0x00030005,0x0000015e,0x00000079, - 0x00030005,0x00000168,0x00000069,0x00030005,0x00000170,0x00000077,0x00030005,0x000001b3, - 0x00000067,0x00080005,0x000001b6,0x475f6c67,0x61626f6c,0x766e496c,0x7461636f,0x496e6f69, - 0x00000044,0x00030005,0x000001bb,0x00000064,0x00030005,0x000001be,0x00747364,0x00030005, - 0x000001c9,0x00007675,0x00040005,0x000001d7,0x636f6c62,0x0000006b,0x00030005,0x000001dc, - 0x006d7573,0x00030005,0x000001dd,0x00000079,0x00030005,0x000001e5,0x00000078,0x00040005, - 0x0000020e,0x7374756f,0x00656469,0x00040005,0x0000023d,0x61726170,0x0000006d,0x00040005, - 0x00000240,0x61726170,0x0000006d,0x00030005,0x0000024b,0x00000063,0x00040005,0x0000024c, - 0x61726170,0x0000006d,0x00030005,0x00000254,0x00000065,0x00030005,0x00000260,0x0000006e, - 0x00030005,0x0000026a,0x00000073,0x00030005,0x00000273,0x00000077,0x00030005,0x0000027d, - 0x00000072,0x00040005,0x00000286,0x61726170,0x0000006d,0x00040005,0x00000288,0x61726170, - 0x0000006d,0x00040005,0x0000028a,0x61726170,0x0000006d,0x00040005,0x0000028c,0x61726170, - 0x0000006d,0x00040005,0x0000028e,0x61726170,0x0000006d,0x00040005,0x00000290,0x61726170, - 0x0000006d,0x00040005,0x000002a0,0x61726170,0x0000006d,0x00040005,0x000002a3,0x61726170, - 0x0000006d,0x00030047,0x0000007a,0x00000002,0x00050048,0x0000007a,0x00000000,0x00000023, - 0x00000000,0x00050048,0x0000007a,0x00000001,0x00000023,0x00000004,0x00050048,0x0000007a, - 0x00000002,0x00000023,0x00000008,0x00050048,0x0000007a,0x00000003,0x00000023,0x0000000c, - 0x00050048,0x0000007a,0x00000004,0x00000023,0x00000010,0x00040047,0x00000087,0x00000021, - 0x00000000,0x00040047,0x00000087,0x00000022,0x00000000,0x00040047,0x00000155,0x00000021, - 0x00000002,0x00040047,0x00000155,0x00000022,0x00000000,0x00040047,0x000001b6,0x0000000b, - 0x0000001c,0x00030047,0x000001be,0x00000019,0x00040047,0x000001be,0x00000021,0x00000001, - 0x00040047,0x000001be,0x00000022,0x00000000,0x00040047,0x000002b4,0x0000000b,0x00000019, - 0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020, - 0x00040020,0x00000007,0x00000007,0x00000006,0x00040021,0x00000008,0x00000006,0x00000007, - 0x00040017,0x0000000f,0x00000006,0x00000002,0x00040020,0x00000010,0x00000007,0x0000000f, - 0x00040017,0x00000011,0x00000006,0x00000003,0x00040021,0x00000012,0x00000011,0x00000010, - 0x00040020,0x00000016,0x00000007,0x00000011,0x00090021,0x00000017,0x00000011,0x00000016, - 0x00000016,0x00000016,0x00000016,0x00000016,0x00000007,0x00040015,0x00000023,0x00000020, - 0x00000001,0x00040017,0x00000024,0x00000023,0x00000002,0x00040020,0x00000025,0x00000007, - 0x00000024,0x00040021,0x00000026,0x00000006,0x00000025,0x0004002b,0x00000006,0x0000002d, - 0x38d1b717,0x00020014,0x0000002e,0x0004002b,0x00000006,0x00000032,0x3f800000,0x0004002b, - 0x00000006,0x00000035,0x40000000,0x0004002b,0x00000006,0x00000039,0x00000000,0x0004002b, - 0x00000006,0x0000003c,0x40490fdb,0x0004002b,0x00000006,0x00000043,0x3f000000,0x0004002b, - 0x00000006,0x00000053,0x3fc00000,0x0004002b,0x00000006,0x0000005a,0x40200000,0x0004002b, - 0x00000006,0x00000066,0xbf000000,0x0004002b,0x00000006,0x00000072,0x40800000,0x0007001e, - 0x0000007a,0x00000023,0x00000006,0x00000006,0x00000006,0x00000023,0x00040020,0x0000007b, - 0x00000009,0x0000007a,0x0004003b,0x0000007b,0x0000007c,0x00000009,0x0004002b,0x00000023, - 0x0000007d,0x00000000,0x00040020,0x0000007e,0x00000009,0x00000023,0x00090019,0x00000084, - 0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b, - 0x00000085,0x00000084,0x00040020,0x00000086,0x00000000,0x00000085,0x0004003b,0x00000086, - 0x00000087,0x00000000,0x00040017,0x0000008a,0x00000006,0x00000004,0x0006002c,0x00000011, - 0x000000a3,0x00000039,0x00000039,0x00000039,0x00040020,0x000000a5,0x00000007,0x00000023, - 0x0004002b,0x00000023,0x000000a7,0xffffffff,0x0004002b,0x00000023,0x000000ae,0x00000002, - 0x00040015,0x000000c8,0x00000020,0x00000000,0x0004002b,0x000000c8,0x000000c9,0x00000000, - 0x0004002b,0x000000c8,0x000000ce,0x00000001,0x0005002c,0x00000024,0x000000e5,0x0000007d, - 0x0000007d,0x0004002b,0x00000023,0x000000e8,0x00000001,0x0004002b,0x00000006,0x0000011b, - 0x3a800000,0x0006002c,0x00000011,0x0000011c,0x0000011b,0x0000011b,0x0000011b,0x0004002b, - 0x000000c8,0x00000133,0x00000002,0x0004002b,0x00000006,0x00000137,0x3e400000,0x0004003b, - 0x00000086,0x00000155,0x00000000,0x0004002b,0x00000023,0x0000015f,0xfffffffc,0x0004002b, - 0x00000023,0x00000166,0x00000004,0x0004002b,0x00000006,0x0000017a,0x41000000,0x0005002c, - 0x0000000f,0x00000188,0x00000039,0x00000039,0x0005002c,0x0000000f,0x00000189,0x00000032, - 0x00000032,0x0004002b,0x00000006,0x0000019b,0x3f400000,0x0004002b,0x00000006,0x0000019f, - 0x4253ee82,0x0004002b,0x00000006,0x000001a0,0x3d897143,0x0004002b,0x00000006,0x000001a5, - 0x3bbf4590,0x0004002b,0x00000006,0x000001af,0x437f0000,0x00040017,0x000001b4,0x000000c8, - 0x00000003,0x00040020,0x000001b5,0x00000001,0x000001b4,0x0004003b,0x000001b5,0x000001b6, - 0x00000001,0x00040017,0x000001b7,0x000000c8,0x00000002,0x00090019,0x000001bc,0x00000006, - 0x00000001,0x00000000,0x00000000,0x00000000,0x00000002,0x00000004,0x00040020,0x000001bd, - 0x00000000,0x000001bc,0x0004003b,0x000001bd,0x000001be,0x00000000,0x00040017,0x000001c3, - 0x0000002e,0x00000002,0x0004002b,0x00000023,0x000001d3,0x00000003,0x0004002b,0x00000006, - 0x000001f6,0x3e800000,0x0004002b,0x00000006,0x00000206,0x41800000,0x00040020,0x00000214, - 0x00000009,0x00000006,0x0004002b,0x00000006,0x0000021f,0x3bc49ba6,0x0004002b,0x000000c8, - 0x000002b3,0x00000008,0x0006002c,0x000001b4,0x000002b4,0x000002b3,0x000002b3,0x000000ce, - 0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b, - 0x00000025,0x000001b3,0x00000007,0x0004003b,0x00000025,0x000001bb,0x00000007,0x0004003b, - 0x00000010,0x000001c9,0x00000007,0x0004003b,0x00000010,0x000001d7,0x00000007,0x0004003b, - 0x00000016,0x000001dc,0x00000007,0x0004003b,0x000000a5,0x000001dd,0x00000007,0x0004003b, - 0x000000a5,0x000001e5,0x00000007,0x0004003b,0x00000007,0x0000020e,0x00000007,0x0004003b, - 0x00000016,0x00000239,0x00000007,0x0004003b,0x00000010,0x0000023d,0x00000007,0x0004003b, - 0x00000025,0x00000240,0x00000007,0x0004003b,0x00000016,0x0000024b,0x00000007,0x0004003b, - 0x00000010,0x0000024c,0x00000007,0x0004003b,0x00000010,0x00000254,0x00000007,0x0004003b, - 0x00000016,0x00000260,0x00000007,0x0004003b,0x00000016,0x0000026a,0x00000007,0x0004003b, - 0x00000016,0x00000273,0x00000007,0x0004003b,0x00000016,0x0000027d,0x00000007,0x0004003b, - 0x00000016,0x00000286,0x00000007,0x0004003b,0x00000016,0x00000288,0x00000007,0x0004003b, - 0x00000016,0x0000028a,0x00000007,0x0004003b,0x00000016,0x0000028c,0x00000007,0x0004003b, - 0x00000016,0x0000028e,0x00000007,0x0004003b,0x00000007,0x00000290,0x00000007,0x0004003b, - 0x00000016,0x0000029c,0x00000007,0x0004003b,0x00000010,0x000002a0,0x00000007,0x0004003b, - 0x00000025,0x000002a3,0x00000007,0x0004003d,0x000001b4,0x000001b8,0x000001b6,0x0007004f, - 0x000001b7,0x000001b9,0x000001b8,0x000001b8,0x00000000,0x00000001,0x0004007c,0x00000024, - 0x000001ba,0x000001b9,0x0003003e,0x000001b3,0x000001ba,0x0004003d,0x000001bc,0x000001bf, - 0x000001be,0x00040068,0x00000024,0x000001c0,0x000001bf,0x0003003e,0x000001bb,0x000001c0, - 0x0004003d,0x00000024,0x000001c1,0x000001b3,0x0004003d,0x00000024,0x000001c2,0x000001bb, - 0x000500af,0x000001c3,0x000001c4,0x000001c1,0x000001c2,0x0004009a,0x0000002e,0x000001c5, - 0x000001c4,0x000300f7,0x000001c7,0x00000000,0x000400fa,0x000001c5,0x000001c6,0x000001c7, - 0x000200f8,0x000001c6,0x000100fd,0x000200f8,0x000001c7,0x0004003d,0x00000024,0x000001ca, - 0x000001b3,0x0004006f,0x0000000f,0x000001cb,0x000001ca,0x00050050,0x0000000f,0x000001cc, - 0x00000043,0x00000043,0x00050081,0x0000000f,0x000001cd,0x000001cb,0x000001cc,0x0004003d, - 0x00000024,0x000001ce,0x000001bb,0x0004006f,0x0000000f,0x000001cf,0x000001ce,0x00050088, - 0x0000000f,0x000001d0,0x000001cd,0x000001cf,0x0003003e,0x000001c9,0x000001d0,0x00050041, - 0x0000007e,0x000001d1,0x0000007c,0x00000166,0x0004003d,0x00000023,0x000001d2,0x000001d1, - 0x000500aa,0x0000002e,0x000001d4,0x000001d2,0x000001d3,0x000300f7,0x000001d6,0x00000000, - 0x000400fa,0x000001d4,0x000001d5,0x000001d6,0x000200f8,0x000001d5,0x0004003d,0x00000024, - 0x000001d8,0x000001bb,0x0004006f,0x0000000f,0x000001d9,0x000001d8,0x00050050,0x0000000f, - 0x000001da,0x00000032,0x00000032,0x00050088,0x0000000f,0x000001db,0x000001da,0x000001d9, - 0x0003003e,0x000001d7,0x000001db,0x0003003e,0x000001dc,0x000000a3,0x0003003e,0x000001dd, - 0x0000007d,0x000200f9,0x000001de,0x000200f8,0x000001de,0x000400f6,0x000001e0,0x000001e1, - 0x00000000,0x000200f9,0x000001e2,0x000200f8,0x000001e2,0x0004003d,0x00000023,0x000001e3, - 0x000001dd,0x000500b1,0x0000002e,0x000001e4,0x000001e3,0x00000166,0x000400fa,0x000001e4, - 0x000001df,0x000001e0,0x000200f8,0x000001df,0x0003003e,0x000001e5,0x0000007d,0x000200f9, - 0x000001e6,0x000200f8,0x000001e6,0x000400f6,0x000001e8,0x000001e9,0x00000000,0x000200f9, - 0x000001ea,0x000200f8,0x000001ea,0x0004003d,0x00000023,0x000001eb,0x000001e5,0x000500b1, - 0x0000002e,0x000001ec,0x000001eb,0x00000166,0x000400fa,0x000001ec,0x000001e7,0x000001e8, - 0x000200f8,0x000001e7,0x0004003d,0x00000085,0x000001ed,0x00000087,0x0004003d,0x0000000f, - 0x000001ee,0x000001c9,0x0004003d,0x00000023,0x000001ef,0x000001e5,0x0004006f,0x00000006, - 0x000001f0,0x000001ef,0x0004003d,0x00000023,0x000001f1,0x000001dd,0x0004006f,0x00000006, - 0x000001f2,0x000001f1,0x00050050,0x0000000f,0x000001f3,0x000001f0,0x000001f2,0x00050050, - 0x0000000f,0x000001f4,0x00000053,0x00000053,0x00050083,0x0000000f,0x000001f5,0x000001f3, - 0x000001f4,0x0005008e,0x0000000f,0x000001f7,0x000001f5,0x000001f6,0x0004003d,0x0000000f, - 0x000001f8,0x000001d7,0x00050085,0x0000000f,0x000001f9,0x000001f7,0x000001f8,0x00050081, - 0x0000000f,0x000001fa,0x000001ee,0x000001f9,0x00070058,0x0000008a,0x000001fb,0x000001ed, - 0x000001fa,0x00000002,0x00000039,0x0008004f,0x00000011,0x000001fc,0x000001fb,0x000001fb, - 0x00000000,0x00000001,0x00000002,0x0004003d,0x00000011,0x000001fd,0x000001dc,0x00050081, - 0x00000011,0x000001fe,0x000001fd,0x000001fc,0x0003003e,0x000001dc,0x000001fe,0x000200f9, - 0x000001e9,0x000200f8,0x000001e9,0x0004003d,0x00000023,0x000001ff,0x000001e5,0x00050080, - 0x00000023,0x00000200,0x000001ff,0x000000e8,0x0003003e,0x000001e5,0x00000200,0x000200f9, - 0x000001e6,0x000200f8,0x000001e8,0x000200f9,0x000001e1,0x000200f8,0x000001e1,0x0004003d, - 0x00000023,0x00000201,0x000001dd,0x00050080,0x00000023,0x00000202,0x00000201,0x000000e8, - 0x0003003e,0x000001dd,0x00000202,0x000200f9,0x000001de,0x000200f8,0x000001e0,0x0004003d, - 0x000001bc,0x00000203,0x000001be,0x0004003d,0x00000024,0x00000204,0x000001b3,0x0004003d, - 0x00000011,0x00000205,0x000001dc,0x00060050,0x00000011,0x00000207,0x00000206,0x00000206, - 0x00000206,0x00050088,0x00000011,0x00000208,0x00000205,0x00000207,0x00050051,0x00000006, - 0x00000209,0x00000208,0x00000000,0x00050051,0x00000006,0x0000020a,0x00000208,0x00000001, - 0x00050051,0x00000006,0x0000020b,0x00000208,0x00000002,0x00070050,0x0000008a,0x0000020c, - 0x00000209,0x0000020a,0x0000020b,0x00000032,0x00040063,0x00000203,0x00000204,0x0000020c, - 0x000100fd,0x000200f8,0x000001d6,0x0003003e,0x0000020e,0x00000039,0x00050041,0x0000007e, - 0x0000020f,0x0000007c,0x00000166,0x0004003d,0x00000023,0x00000210,0x0000020f,0x000500ab, - 0x0000002e,0x00000211,0x00000210,0x0000007d,0x000300f7,0x00000213,0x00000000,0x000400fa, - 0x00000211,0x00000212,0x00000213,0x000200f8,0x00000212,0x00050041,0x00000214,0x00000215, - 0x0000007c,0x000001d3,0x0004003d,0x00000006,0x00000216,0x00000215,0x00050041,0x00000214, - 0x00000217,0x0000007c,0x000000ae,0x0004003d,0x00000006,0x00000218,0x00000217,0x000500ba, - 0x0000002e,0x00000219,0x00000216,0x00000218,0x000200f9,0x00000213,0x000200f8,0x00000213, - 0x000700f5,0x0000002e,0x0000021a,0x00000211,0x000001d6,0x00000219,0x00000212,0x000300f7, - 0x0000021c,0x00000000,0x000400fa,0x0000021a,0x0000021b,0x0000021c,0x000200f8,0x0000021b, - 0x00050041,0x00000214,0x0000021d,0x0000007c,0x000000ae,0x0004003d,0x00000006,0x0000021e, - 0x0000021d,0x00050083,0x00000006,0x00000220,0x0000021e,0x0000021f,0x00050041,0x00000214, - 0x00000221,0x0000007c,0x000000ae,0x0004003d,0x00000006,0x00000222,0x00000221,0x00050041, - 0x00000007,0x00000223,0x000001c9,0x000000c9,0x0004003d,0x00000006,0x00000224,0x00000223, - 0x0008000c,0x00000006,0x00000225,0x00000001,0x00000031,0x00000220,0x00000222,0x00000224, - 0x00050083,0x00000006,0x00000226,0x00000032,0x00000225,0x00050041,0x00000214,0x00000227, - 0x0000007c,0x000001d3,0x0004003d,0x00000006,0x00000228,0x00000227,0x00050041,0x00000214, - 0x00000229,0x0000007c,0x000001d3,0x0004003d,0x00000006,0x0000022a,0x00000229,0x00050081, - 0x00000006,0x0000022b,0x0000022a,0x0000021f,0x00050041,0x00000007,0x0000022c,0x000001c9, - 0x000000c9,0x0004003d,0x00000006,0x0000022d,0x0000022c,0x0008000c,0x00000006,0x0000022e, - 0x00000001,0x00000031,0x00000228,0x0000022b,0x0000022d,0x0007000c,0x00000006,0x0000022f, - 0x00000001,0x00000028,0x00000226,0x0000022e,0x0003003e,0x0000020e,0x0000022f,0x0004003d, - 0x00000006,0x00000230,0x0000020e,0x000500be,0x0000002e,0x00000231,0x00000230,0x00000032, - 0x000300f7,0x00000233,0x00000000,0x000400fa,0x00000231,0x00000232,0x00000233,0x000200f8, - 0x00000232,0x0004003d,0x000001bc,0x00000234,0x000001be,0x0004003d,0x00000024,0x00000235, - 0x000001b3,0x00050041,0x0000007e,0x00000236,0x0000007c,0x00000166,0x0004003d,0x00000023, - 0x00000237,0x00000236,0x000500aa,0x0000002e,0x00000238,0x00000237,0x000000ae,0x000300f7, - 0x0000023b,0x00000000,0x000400fa,0x00000238,0x0000023a,0x0000023c,0x000200f8,0x0000023a, - 0x0003003e,0x00000239,0x000000a3,0x000200f9,0x0000023b,0x000200f8,0x0000023c,0x0004003d, - 0x0000000f,0x0000023e,0x000001c9,0x0003003e,0x0000023d,0x0000023e,0x00050039,0x00000011, - 0x0000023f,0x00000021,0x0000023d,0x0004003d,0x00000024,0x00000241,0x000001b3,0x0003003e, - 0x00000240,0x00000241,0x00050039,0x00000006,0x00000242,0x00000028,0x00000240,0x00060050, - 0x00000011,0x00000243,0x00000242,0x00000242,0x00000242,0x00050081,0x00000011,0x00000244, - 0x0000023f,0x00000243,0x0003003e,0x00000239,0x00000244,0x000200f9,0x0000023b,0x000200f8, - 0x0000023b,0x0004003d,0x00000011,0x00000245,0x00000239,0x00050051,0x00000006,0x00000246, - 0x00000245,0x00000000,0x00050051,0x00000006,0x00000247,0x00000245,0x00000001,0x00050051, - 0x00000006,0x00000248,0x00000245,0x00000002,0x00070050,0x0000008a,0x00000249,0x00000246, - 0x00000247,0x00000248,0x00000032,0x00040063,0x00000234,0x00000235,0x00000249,0x000100fd, - 0x000200f8,0x00000233,0x000200f9,0x0000021c,0x000200f8,0x0000021c,0x0004003d,0x0000000f, - 0x0000024d,0x000001c9,0x0003003e,0x0000024c,0x0000024d,0x00050039,0x00000011,0x0000024e, - 0x00000014,0x0000024c,0x0003003e,0x0000024b,0x0000024e,0x00050041,0x00000214,0x0000024f, - 0x0000007c,0x000000e8,0x0004003d,0x00000006,0x00000250,0x0000024f,0x000500ba,0x0000002e, - 0x00000251,0x00000250,0x00000039,0x000300f7,0x00000253,0x00000000,0x000400fa,0x00000251, - 0x00000252,0x00000253,0x000200f8,0x00000252,0x0004003d,0x00000085,0x00000255,0x00000087, - 0x00040064,0x00000084,0x00000256,0x00000255,0x00050067,0x00000024,0x00000257,0x00000256, - 0x0000007d,0x0004006f,0x0000000f,0x00000258,0x00000257,0x00050050,0x0000000f,0x00000259, - 0x00000032,0x00000032,0x00050088,0x0000000f,0x0000025a,0x00000259,0x00000258,0x0004003d, - 0x00000024,0x0000025b,0x000001bb,0x0004006f,0x0000000f,0x0000025c,0x0000025b,0x00050050, - 0x0000000f,0x0000025d,0x00000032,0x00000032,0x00050088,0x0000000f,0x0000025e,0x0000025d, - 0x0000025c,0x0007000c,0x0000000f,0x0000025f,0x00000001,0x00000028,0x0000025a,0x0000025e, - 0x0003003e,0x00000254,0x0000025f,0x0004003d,0x00000085,0x00000261,0x00000087,0x0004003d, - 0x0000000f,0x00000262,0x000001c9,0x00050041,0x00000007,0x00000263,0x00000254,0x000000ce, - 0x0004003d,0x00000006,0x00000264,0x00000263,0x0004007f,0x00000006,0x00000265,0x00000264, - 0x00050050,0x0000000f,0x00000266,0x00000039,0x00000265,0x00050081,0x0000000f,0x00000267, - 0x00000262,0x00000266,0x00070058,0x0000008a,0x00000268,0x00000261,0x00000267,0x00000002, - 0x00000039,0x0008004f,0x00000011,0x00000269,0x00000268,0x00000268,0x00000000,0x00000001, - 0x00000002,0x0003003e,0x00000260,0x00000269,0x0004003d,0x00000085,0x0000026b,0x00000087, - 0x0004003d,0x0000000f,0x0000026c,0x000001c9,0x00050041,0x00000007,0x0000026d,0x00000254, - 0x000000ce,0x0004003d,0x00000006,0x0000026e,0x0000026d,0x00050050,0x0000000f,0x0000026f, - 0x00000039,0x0000026e,0x00050081,0x0000000f,0x00000270,0x0000026c,0x0000026f,0x00070058, - 0x0000008a,0x00000271,0x0000026b,0x00000270,0x00000002,0x00000039,0x0008004f,0x00000011, - 0x00000272,0x00000271,0x00000271,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000026a, - 0x00000272,0x0004003d,0x00000085,0x00000274,0x00000087,0x0004003d,0x0000000f,0x00000275, - 0x000001c9,0x00050041,0x00000007,0x00000276,0x00000254,0x000000c9,0x0004003d,0x00000006, - 0x00000277,0x00000276,0x0004007f,0x00000006,0x00000278,0x00000277,0x00050050,0x0000000f, - 0x00000279,0x00000278,0x00000039,0x00050081,0x0000000f,0x0000027a,0x00000275,0x00000279, - 0x00070058,0x0000008a,0x0000027b,0x00000274,0x0000027a,0x00000002,0x00000039,0x0008004f, - 0x00000011,0x0000027c,0x0000027b,0x0000027b,0x00000000,0x00000001,0x00000002,0x0003003e, - 0x00000273,0x0000027c,0x0004003d,0x00000085,0x0000027e,0x00000087,0x0004003d,0x0000000f, - 0x0000027f,0x000001c9,0x00050041,0x00000007,0x00000280,0x00000254,0x000000c9,0x0004003d, - 0x00000006,0x00000281,0x00000280,0x00050050,0x0000000f,0x00000282,0x00000281,0x00000039, - 0x00050081,0x0000000f,0x00000283,0x0000027f,0x00000282,0x00070058,0x0000008a,0x00000284, - 0x0000027e,0x00000283,0x00000002,0x00000039,0x0008004f,0x00000011,0x00000285,0x00000284, - 0x00000284,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000027d,0x00000285,0x0004003d, - 0x00000011,0x00000287,0x0000024b,0x0003003e,0x00000286,0x00000287,0x0004003d,0x00000011, - 0x00000289,0x00000260,0x0003003e,0x00000288,0x00000289,0x0004003d,0x00000011,0x0000028b, - 0x0000026a,0x0003003e,0x0000028a,0x0000028b,0x0004003d,0x00000011,0x0000028d,0x00000273, - 0x0003003e,0x0000028c,0x0000028d,0x0004003d,0x00000011,0x0000028f,0x0000027d,0x0003003e, - 0x0000028e,0x0000028f,0x00050041,0x00000214,0x00000291,0x0000007c,0x000000e8,0x0004003d, - 0x00000006,0x00000292,0x00000291,0x0003003e,0x00000290,0x00000292,0x000a0039,0x00000011, - 0x00000293,0x0000001e,0x00000286,0x00000288,0x0000028a,0x0000028c,0x0000028e,0x00000290, - 0x0003003e,0x0000024b,0x00000293,0x000200f9,0x00000253,0x000200f8,0x00000253,0x0004003d, - 0x00000006,0x00000294,0x0000020e,0x000500ba,0x0000002e,0x00000295,0x00000294,0x00000039, - 0x000300f7,0x00000297,0x00000000,0x000400fa,0x00000295,0x00000296,0x00000297,0x000200f8, - 0x00000296,0x0004003d,0x00000011,0x00000298,0x0000024b,0x00050041,0x0000007e,0x00000299, - 0x0000007c,0x00000166,0x0004003d,0x00000023,0x0000029a,0x00000299,0x000500aa,0x0000002e, - 0x0000029b,0x0000029a,0x000000ae,0x000300f7,0x0000029e,0x00000000,0x000400fa,0x0000029b, - 0x0000029d,0x0000029f,0x000200f8,0x0000029d,0x0003003e,0x0000029c,0x000000a3,0x000200f9, - 0x0000029e,0x000200f8,0x0000029f,0x0004003d,0x0000000f,0x000002a1,0x000001c9,0x0003003e, - 0x000002a0,0x000002a1,0x00050039,0x00000011,0x000002a2,0x00000021,0x000002a0,0x0004003d, - 0x00000024,0x000002a4,0x000001b3,0x0003003e,0x000002a3,0x000002a4,0x00050039,0x00000006, - 0x000002a5,0x00000028,0x000002a3,0x00060050,0x00000011,0x000002a6,0x000002a5,0x000002a5, - 0x000002a5,0x00050081,0x00000011,0x000002a7,0x000002a2,0x000002a6,0x0003003e,0x0000029c, - 0x000002a7,0x000200f9,0x0000029e,0x000200f8,0x0000029e,0x0004003d,0x00000011,0x000002a8, - 0x0000029c,0x0004003d,0x00000006,0x000002a9,0x0000020e,0x00060050,0x00000011,0x000002aa, - 0x000002a9,0x000002a9,0x000002a9,0x0008000c,0x00000011,0x000002ab,0x00000001,0x0000002e, - 0x00000298,0x000002a8,0x000002aa,0x0003003e,0x0000024b,0x000002ab,0x000200f9,0x00000297, - 0x000200f8,0x00000297,0x0004003d,0x000001bc,0x000002ac,0x000001be,0x0004003d,0x00000024, - 0x000002ad,0x000001b3,0x0004003d,0x00000011,0x000002ae,0x0000024b,0x00050051,0x00000006, - 0x000002af,0x000002ae,0x00000000,0x00050051,0x00000006,0x000002b0,0x000002ae,0x00000001, - 0x00050051,0x00000006,0x000002b1,0x000002ae,0x00000002,0x00070050,0x0000008a,0x000002b2, - 0x000002af,0x000002b0,0x000002b1,0x00000032,0x00040063,0x000002ac,0x000002ad,0x000002b2, - 0x000100fd,0x00010038,0x00050036,0x00000006,0x0000000a,0x00000000,0x00000008,0x00030037, - 0x00000007,0x00000009,0x000200f8,0x0000000b,0x0004003b,0x00000007,0x0000003b,0x00000007, - 0x0004003d,0x00000006,0x0000002a,0x00000009,0x0006000c,0x00000006,0x0000002b,0x00000001, - 0x00000004,0x0000002a,0x0003003e,0x00000009,0x0000002b,0x0004003d,0x00000006,0x0000002c, - 0x00000009,0x000500b8,0x0000002e,0x0000002f,0x0000002c,0x0000002d,0x000300f7,0x00000031, - 0x00000000,0x000400fa,0x0000002f,0x00000030,0x00000031,0x000200f8,0x00000030,0x000200fe, - 0x00000032,0x000200f8,0x00000031,0x0004003d,0x00000006,0x00000034,0x00000009,0x000500be, - 0x0000002e,0x00000036,0x00000034,0x00000035,0x000300f7,0x00000038,0x00000000,0x000400fa, - 0x00000036,0x00000037,0x00000038,0x000200f8,0x00000037,0x000200fe,0x00000039,0x000200f8, - 0x00000038,0x0004003d,0x00000006,0x0000003d,0x00000009,0x00050085,0x00000006,0x0000003e, - 0x0000003c,0x0000003d,0x0003003e,0x0000003b,0x0000003e,0x0004003d,0x00000006,0x0000003f, - 0x0000003b,0x0006000c,0x00000006,0x00000040,0x00000001,0x0000000d,0x0000003f,0x00050085, - 0x00000006,0x00000041,0x00000035,0x00000040,0x0004003d,0x00000006,0x00000042,0x0000003b, - 0x00050085,0x00000006,0x00000044,0x00000042,0x00000043,0x0006000c,0x00000006,0x00000045, - 0x00000001,0x0000000d,0x00000044,0x00050085,0x00000006,0x00000046,0x00000041,0x00000045, - 0x0004003d,0x00000006,0x00000047,0x0000003b,0x0004003d,0x00000006,0x00000048,0x0000003b, - 0x00050085,0x00000006,0x00000049,0x00000047,0x00000048,0x00050088,0x00000006,0x0000004a, - 0x00000046,0x00000049,0x000200fe,0x0000004a,0x00010038,0x00050036,0x00000006,0x0000000d, - 0x00000000,0x00000008,0x00030037,0x00000007,0x0000000c,0x000200f8,0x0000000e,0x0004003d, - 0x00000006,0x0000004d,0x0000000c,0x0006000c,0x00000006,0x0000004e,0x00000001,0x00000004, - 0x0000004d,0x0003003e,0x0000000c,0x0000004e,0x0004003d,0x00000006,0x0000004f,0x0000000c, - 0x000500b8,0x0000002e,0x00000050,0x0000004f,0x00000032,0x000300f7,0x00000052,0x00000000, - 0x000400fa,0x00000050,0x00000051,0x00000052,0x000200f8,0x00000051,0x0004003d,0x00000006, - 0x00000054,0x0000000c,0x00050085,0x00000006,0x00000055,0x00000053,0x00000054,0x0004003d, - 0x00000006,0x00000056,0x0000000c,0x00050085,0x00000006,0x00000057,0x00000055,0x00000056, - 0x0004003d,0x00000006,0x00000058,0x0000000c,0x00050085,0x00000006,0x00000059,0x00000057, - 0x00000058,0x0004003d,0x00000006,0x0000005b,0x0000000c,0x00050085,0x00000006,0x0000005c, - 0x0000005a,0x0000005b,0x0004003d,0x00000006,0x0000005d,0x0000000c,0x00050085,0x00000006, - 0x0000005e,0x0000005c,0x0000005d,0x00050083,0x00000006,0x0000005f,0x00000059,0x0000005e, - 0x00050081,0x00000006,0x00000060,0x0000005f,0x00000032,0x000200fe,0x00000060,0x000200f8, - 0x00000052,0x0004003d,0x00000006,0x00000062,0x0000000c,0x000500b8,0x0000002e,0x00000063, - 0x00000062,0x00000035,0x000300f7,0x00000065,0x00000000,0x000400fa,0x00000063,0x00000064, - 0x00000065,0x000200f8,0x00000064,0x0004003d,0x00000006,0x00000067,0x0000000c,0x00050085, - 0x00000006,0x00000068,0x00000066,0x00000067,0x0004003d,0x00000006,0x00000069,0x0000000c, - 0x00050085,0x00000006,0x0000006a,0x00000068,0x00000069,0x0004003d,0x00000006,0x0000006b, - 0x0000000c,0x00050085,0x00000006,0x0000006c,0x0000006a,0x0000006b,0x0004003d,0x00000006, - 0x0000006d,0x0000000c,0x00050085,0x00000006,0x0000006e,0x0000005a,0x0000006d,0x0004003d, - 0x00000006,0x0000006f,0x0000000c,0x00050085,0x00000006,0x00000070,0x0000006e,0x0000006f, - 0x00050081,0x00000006,0x00000071,0x0000006c,0x00000070,0x0004003d,0x00000006,0x00000073, - 0x0000000c,0x00050085,0x00000006,0x00000074,0x00000072,0x00000073,0x00050083,0x00000006, - 0x00000075,0x00000071,0x00000074,0x00050081,0x00000006,0x00000076,0x00000075,0x00000035, - 0x000200fe,0x00000076,0x000200f8,0x00000065,0x000200fe,0x00000039,0x00010038,0x00050036, - 0x00000011,0x00000014,0x00000000,0x00000012,0x00030037,0x00000010,0x00000013,0x000200f8, - 0x00000015,0x0004003b,0x00000010,0x0000008e,0x00000007,0x0004003b,0x00000010,0x00000093, - 0x00000007,0x0004003b,0x00000025,0x00000099,0x00000007,0x0004003b,0x00000010,0x0000009d, - 0x00000007,0x0004003b,0x00000016,0x000000a2,0x00000007,0x0004003b,0x00000007,0x000000a4, - 0x00000007,0x0004003b,0x000000a5,0x000000a6,0x00000007,0x0004003b,0x000000a5,0x000000b0, - 0x00000007,0x0004003b,0x00000010,0x000000b8,0x00000007,0x0004003b,0x00000007,0x000000c0, - 0x00000007,0x0004003b,0x00000007,0x000000c4,0x00000007,0x0004003b,0x00000007,0x000000c7, - 0x00000007,0x0004003b,0x00000007,0x000000cd,0x00000007,0x0004003b,0x00000007,0x000000d4, - 0x00000007,0x0004003b,0x00000007,0x000000d8,0x00000007,0x00050041,0x0000007e,0x0000007f, - 0x0000007c,0x0000007d,0x0004003d,0x00000023,0x00000080,0x0000007f,0x000500aa,0x0000002e, - 0x00000081,0x00000080,0x0000007d,0x000300f7,0x00000083,0x00000000,0x000400fa,0x00000081, - 0x00000082,0x00000083,0x000200f8,0x00000082,0x0004003d,0x00000085,0x00000088,0x00000087, - 0x0004003d,0x0000000f,0x00000089,0x00000013,0x00070058,0x0000008a,0x0000008b,0x00000088, - 0x00000089,0x00000002,0x00000039,0x0008004f,0x00000011,0x0000008c,0x0000008b,0x0000008b, - 0x00000000,0x00000001,0x00000002,0x000200fe,0x0000008c,0x000200f8,0x00000083,0x0004003d, - 0x00000085,0x0000008f,0x00000087,0x00040064,0x00000084,0x00000090,0x0000008f,0x00050067, - 0x00000024,0x00000091,0x00000090,0x0000007d,0x0004006f,0x0000000f,0x00000092,0x00000091, - 0x0003003e,0x0000008e,0x00000092,0x0004003d,0x0000000f,0x00000094,0x00000013,0x0004003d, - 0x0000000f,0x00000095,0x0000008e,0x00050085,0x0000000f,0x00000096,0x00000094,0x00000095, - 0x00050050,0x0000000f,0x00000097,0x00000043,0x00000043,0x00050083,0x0000000f,0x00000098, - 0x00000096,0x00000097,0x0003003e,0x00000093,0x00000098,0x0004003d,0x0000000f,0x0000009a, - 0x00000093,0x0006000c,0x0000000f,0x0000009b,0x00000001,0x00000008,0x0000009a,0x0004006e, - 0x00000024,0x0000009c,0x0000009b,0x0003003e,0x00000099,0x0000009c,0x0004003d,0x0000000f, - 0x0000009e,0x00000093,0x0004003d,0x00000024,0x0000009f,0x00000099,0x0004006f,0x0000000f, - 0x000000a0,0x0000009f,0x00050083,0x0000000f,0x000000a1,0x0000009e,0x000000a0,0x0003003e, - 0x0000009d,0x000000a1,0x0003003e,0x000000a2,0x000000a3,0x0003003e,0x000000a4,0x00000039, - 0x0003003e,0x000000a6,0x000000a7,0x000200f9,0x000000a8,0x000200f8,0x000000a8,0x000400f6, - 0x000000aa,0x000000ab,0x00000000,0x000200f9,0x000000ac,0x000200f8,0x000000ac,0x0004003d, - 0x00000023,0x000000ad,0x000000a6,0x000500b3,0x0000002e,0x000000af,0x000000ad,0x000000ae, - 0x000400fa,0x000000af,0x000000a9,0x000000aa,0x000200f8,0x000000a9,0x0003003e,0x000000b0, - 0x000000a7,0x000200f9,0x000000b1,0x000200f8,0x000000b1,0x000400f6,0x000000b3,0x000000b4, - 0x00000000,0x000200f9,0x000000b5,0x000200f8,0x000000b5,0x0004003d,0x00000023,0x000000b6, - 0x000000b0,0x000500b3,0x0000002e,0x000000b7,0x000000b6,0x000000ae,0x000400fa,0x000000b7, - 0x000000b2,0x000000b3,0x000200f8,0x000000b2,0x0004003d,0x00000023,0x000000b9,0x000000b0, - 0x0004006f,0x00000006,0x000000ba,0x000000b9,0x0004003d,0x00000023,0x000000bb,0x000000a6, - 0x0004006f,0x00000006,0x000000bc,0x000000bb,0x00050050,0x0000000f,0x000000bd,0x000000ba, - 0x000000bc,0x0004003d,0x0000000f,0x000000be,0x0000009d,0x00050083,0x0000000f,0x000000bf, - 0x000000bd,0x000000be,0x0003003e,0x000000b8,0x000000bf,0x00050041,0x0000007e,0x000000c1, - 0x0000007c,0x0000007d,0x0004003d,0x00000023,0x000000c2,0x000000c1,0x000500aa,0x0000002e, - 0x000000c3,0x000000c2,0x000000ae,0x000300f7,0x000000c6,0x00000000,0x000400fa,0x000000c3, - 0x000000c5,0x000000d3,0x000200f8,0x000000c5,0x00050041,0x00000007,0x000000ca,0x000000b8, - 0x000000c9,0x0004003d,0x00000006,0x000000cb,0x000000ca,0x0003003e,0x000000c7,0x000000cb, - 0x00050039,0x00000006,0x000000cc,0x0000000a,0x000000c7,0x00050041,0x00000007,0x000000cf, - 0x000000b8,0x000000ce,0x0004003d,0x00000006,0x000000d0,0x000000cf,0x0003003e,0x000000cd, - 0x000000d0,0x00050039,0x00000006,0x000000d1,0x0000000a,0x000000cd,0x00050085,0x00000006, - 0x000000d2,0x000000cc,0x000000d1,0x0003003e,0x000000c4,0x000000d2,0x000200f9,0x000000c6, - 0x000200f8,0x000000d3,0x00050041,0x00000007,0x000000d5,0x000000b8,0x000000c9,0x0004003d, - 0x00000006,0x000000d6,0x000000d5,0x0003003e,0x000000d4,0x000000d6,0x00050039,0x00000006, - 0x000000d7,0x0000000d,0x000000d4,0x00050041,0x00000007,0x000000d9,0x000000b8,0x000000ce, - 0x0004003d,0x00000006,0x000000da,0x000000d9,0x0003003e,0x000000d8,0x000000da,0x00050039, - 0x00000006,0x000000db,0x0000000d,0x000000d8,0x00050085,0x00000006,0x000000dc,0x000000d7, - 0x000000db,0x0003003e,0x000000c4,0x000000dc,0x000200f9,0x000000c6,0x000200f8,0x000000c6, - 0x0004003d,0x00000006,0x000000dd,0x000000c4,0x0003003e,0x000000c0,0x000000dd,0x0004003d, - 0x00000006,0x000000de,0x000000c0,0x0004003d,0x00000085,0x000000df,0x00000087,0x0004003d, - 0x00000024,0x000000e0,0x00000099,0x0004003d,0x00000023,0x000000e1,0x000000b0,0x0004003d, - 0x00000023,0x000000e2,0x000000a6,0x00050050,0x00000024,0x000000e3,0x000000e1,0x000000e2, - 0x00050080,0x00000024,0x000000e4,0x000000e0,0x000000e3,0x0004003d,0x0000000f,0x000000e6, - 0x0000008e,0x0004006e,0x00000024,0x000000e7,0x000000e6,0x00050050,0x00000024,0x000000e9, - 0x000000e8,0x000000e8,0x00050082,0x00000024,0x000000ea,0x000000e7,0x000000e9,0x0008000c, - 0x00000024,0x000000eb,0x00000001,0x0000002d,0x000000e4,0x000000e5,0x000000ea,0x00040064, - 0x00000084,0x000000ec,0x000000df,0x0007005f,0x0000008a,0x000000ed,0x000000ec,0x000000eb, - 0x00000002,0x0000007d,0x0008004f,0x00000011,0x000000ee,0x000000ed,0x000000ed,0x00000000, - 0x00000001,0x00000002,0x0005008e,0x00000011,0x000000ef,0x000000ee,0x000000de,0x0004003d, - 0x00000011,0x000000f0,0x000000a2,0x00050081,0x00000011,0x000000f1,0x000000f0,0x000000ef, - 0x0003003e,0x000000a2,0x000000f1,0x0004003d,0x00000006,0x000000f2,0x000000c0,0x0004003d, - 0x00000006,0x000000f3,0x000000a4,0x00050081,0x00000006,0x000000f4,0x000000f3,0x000000f2, - 0x0003003e,0x000000a4,0x000000f4,0x000200f9,0x000000b4,0x000200f8,0x000000b4,0x0004003d, - 0x00000023,0x000000f5,0x000000b0,0x00050080,0x00000023,0x000000f6,0x000000f5,0x000000e8, - 0x0003003e,0x000000b0,0x000000f6,0x000200f9,0x000000b1,0x000200f8,0x000000b3,0x000200f9, - 0x000000ab,0x000200f8,0x000000ab,0x0004003d,0x00000023,0x000000f7,0x000000a6,0x00050080, - 0x00000023,0x000000f8,0x000000f7,0x000000e8,0x0003003e,0x000000a6,0x000000f8,0x000200f9, - 0x000000a8,0x000200f8,0x000000aa,0x0004003d,0x00000011,0x000000f9,0x000000a2,0x0004003d, - 0x00000006,0x000000fa,0x000000a4,0x00060050,0x00000011,0x000000fb,0x000000fa,0x000000fa, - 0x000000fa,0x00050088,0x00000011,0x000000fc,0x000000f9,0x000000fb,0x000200fe,0x000000fc, - 0x00010038,0x00050036,0x00000011,0x0000001e,0x00000000,0x00000017,0x00030037,0x00000016, - 0x00000018,0x00030037,0x00000016,0x00000019,0x00030037,0x00000016,0x0000001a,0x00030037, - 0x00000016,0x0000001b,0x00030037,0x00000016,0x0000001c,0x00030037,0x00000007,0x0000001d, - 0x000200f8,0x0000001f,0x0004003b,0x00000016,0x000000ff,0x00000007,0x0004003b,0x00000016, - 0x00000107,0x00000007,0x0004003b,0x00000016,0x0000010f,0x00000007,0x0004003b,0x00000016, - 0x00000113,0x00000007,0x0004003b,0x00000016,0x00000117,0x00000007,0x0004003b,0x00000016, - 0x0000011f,0x00000007,0x0004003b,0x00000016,0x00000129,0x00000007,0x0004003b,0x00000007, - 0x0000012d,0x00000007,0x0004003b,0x00000016,0x0000013d,0x00000007,0x0004003d,0x00000011, - 0x00000100,0x00000019,0x0004003d,0x00000011,0x00000101,0x0000001a,0x0007000c,0x00000011, - 0x00000102,0x00000001,0x00000025,0x00000100,0x00000101,0x0004003d,0x00000011,0x00000103, - 0x0000001b,0x0004003d,0x00000011,0x00000104,0x0000001c,0x0007000c,0x00000011,0x00000105, - 0x00000001,0x00000025,0x00000103,0x00000104,0x0007000c,0x00000011,0x00000106,0x00000001, - 0x00000025,0x00000102,0x00000105,0x0003003e,0x000000ff,0x00000106,0x0004003d,0x00000011, - 0x00000108,0x00000019,0x0004003d,0x00000011,0x00000109,0x0000001a,0x0007000c,0x00000011, - 0x0000010a,0x00000001,0x00000028,0x00000108,0x00000109,0x0004003d,0x00000011,0x0000010b, - 0x0000001b,0x0004003d,0x00000011,0x0000010c,0x0000001c,0x0007000c,0x00000011,0x0000010d, - 0x00000001,0x00000028,0x0000010b,0x0000010c,0x0007000c,0x00000011,0x0000010e,0x00000001, - 0x00000028,0x0000010a,0x0000010d,0x0003003e,0x00000107,0x0000010e,0x0004003d,0x00000011, - 0x00000110,0x000000ff,0x0004003d,0x00000011,0x00000111,0x00000018,0x0007000c,0x00000011, - 0x00000112,0x00000001,0x00000025,0x00000110,0x00000111,0x0003003e,0x0000010f,0x00000112, - 0x0004003d,0x00000011,0x00000114,0x00000107,0x0004003d,0x00000011,0x00000115,0x00000018, - 0x0007000c,0x00000011,0x00000116,0x00000001,0x00000028,0x00000114,0x00000115,0x0003003e, - 0x00000113,0x00000116,0x0004003d,0x00000011,0x00000118,0x0000010f,0x0004003d,0x00000011, - 0x00000119,0x00000113,0x0005008e,0x00000011,0x0000011a,0x00000119,0x00000072,0x0007000c, - 0x00000011,0x0000011d,0x00000001,0x00000028,0x0000011a,0x0000011c,0x00050088,0x00000011, - 0x0000011e,0x00000118,0x0000011d,0x0003003e,0x00000117,0x0000011e,0x0004003d,0x00000011, - 0x00000120,0x00000113,0x00060050,0x00000011,0x00000121,0x00000032,0x00000032,0x00000032, - 0x00050083,0x00000011,0x00000122,0x00000121,0x00000120,0x0004003d,0x00000011,0x00000123, - 0x000000ff,0x0005008e,0x00000011,0x00000124,0x00000123,0x00000072,0x00060050,0x00000011, - 0x00000125,0x00000072,0x00000072,0x00000072,0x00050083,0x00000011,0x00000126,0x00000125, - 0x00000124,0x0007000c,0x00000011,0x00000127,0x00000001,0x00000028,0x00000126,0x0000011c, - 0x00050088,0x00000011,0x00000128,0x00000122,0x00000127,0x0003003e,0x0000011f,0x00000128, - 0x0004003d,0x00000011,0x0000012a,0x00000117,0x0004003d,0x00000011,0x0000012b,0x0000011f, - 0x0007000c,0x00000011,0x0000012c,0x00000001,0x00000025,0x0000012a,0x0000012b,0x0003003e, - 0x00000129,0x0000012c,0x00050041,0x00000007,0x0000012e,0x00000129,0x000000c9,0x0004003d, - 0x00000006,0x0000012f,0x0000012e,0x00050041,0x00000007,0x00000130,0x00000129,0x000000ce, - 0x0004003d,0x00000006,0x00000131,0x00000130,0x0007000c,0x00000006,0x00000132,0x00000001, - 0x00000025,0x0000012f,0x00000131,0x00050041,0x00000007,0x00000134,0x00000129,0x00000133, - 0x0004003d,0x00000006,0x00000135,0x00000134,0x0007000c,0x00000006,0x00000136,0x00000001, - 0x00000025,0x00000132,0x00000135,0x0008000c,0x00000006,0x00000138,0x00000001,0x0000002b, - 0x00000136,0x00000039,0x00000137,0x0004007f,0x00000006,0x00000139,0x00000138,0x0004003d, - 0x00000006,0x0000013a,0x0000001d,0x0008000c,0x00000006,0x0000013b,0x00000001,0x0000002b, - 0x0000013a,0x00000039,0x00000032,0x00050085,0x00000006,0x0000013c,0x00000139,0x0000013b, - 0x0003003e,0x0000012d,0x0000013c,0x0004003d,0x00000011,0x0000013e,0x00000018,0x0004003d, - 0x00000006,0x0000013f,0x0000012d,0x0004003d,0x00000011,0x00000140,0x00000019,0x0004003d, - 0x00000011,0x00000141,0x0000001a,0x00050081,0x00000011,0x00000142,0x00000140,0x00000141, - 0x0004003d,0x00000011,0x00000143,0x0000001b,0x00050081,0x00000011,0x00000144,0x00000142, - 0x00000143,0x0004003d,0x00000011,0x00000145,0x0000001c,0x00050081,0x00000011,0x00000146, - 0x00000144,0x00000145,0x0005008e,0x00000011,0x00000147,0x00000146,0x0000013f,0x00050081, - 0x00000011,0x00000148,0x0000013e,0x00000147,0x0004003d,0x00000006,0x00000149,0x0000012d, - 0x00050085,0x00000006,0x0000014a,0x00000072,0x00000149,0x00050081,0x00000006,0x0000014b, - 0x00000032,0x0000014a,0x00060050,0x00000011,0x0000014c,0x0000014b,0x0000014b,0x0000014b, - 0x00050088,0x00000011,0x0000014d,0x00000148,0x0000014c,0x0003003e,0x0000013d,0x0000014d, - 0x0004003d,0x00000011,0x0000014e,0x0000013d,0x0004003d,0x00000011,0x0000014f,0x0000010f, - 0x0004003d,0x00000011,0x00000150,0x00000113,0x0008000c,0x00000011,0x00000151,0x00000001, - 0x0000002b,0x0000014e,0x0000014f,0x00000150,0x000200fe,0x00000151,0x00010038,0x00050036, - 0x00000011,0x00000021,0x00000000,0x00000012,0x00030037,0x00000010,0x00000020,0x000200f8, - 0x00000022,0x0004003b,0x00000010,0x00000154,0x00000007,0x0004003b,0x00000016,0x0000015c, - 0x00000007,0x0004003b,0x00000007,0x0000015d,0x00000007,0x0004003b,0x000000a5,0x0000015e, - 0x00000007,0x0004003b,0x000000a5,0x00000168,0x00000007,0x0004003b,0x00000007,0x00000170, - 0x00000007,0x0004003d,0x00000085,0x00000156,0x00000155,0x00040064,0x00000084,0x00000157, - 0x00000156,0x00050067,0x00000024,0x00000158,0x00000157,0x0000007d,0x0004006f,0x0000000f, - 0x00000159,0x00000158,0x00050050,0x0000000f,0x0000015a,0x00000035,0x00000035,0x00050088, - 0x0000000f,0x0000015b,0x0000015a,0x00000159,0x0003003e,0x00000154,0x0000015b,0x0003003e, - 0x0000015c,0x000000a3,0x0003003e,0x0000015d,0x00000039,0x0003003e,0x0000015e,0x0000015f, - 0x000200f9,0x00000160,0x000200f8,0x00000160,0x000400f6,0x00000162,0x00000163,0x00000000, - 0x000200f9,0x00000164,0x000200f8,0x00000164,0x0004003d,0x00000023,0x00000165,0x0000015e, - 0x000500b3,0x0000002e,0x00000167,0x00000165,0x00000166,0x000400fa,0x00000167,0x00000161, - 0x00000162,0x000200f8,0x00000161,0x0003003e,0x00000168,0x0000015f,0x000200f9,0x00000169, - 0x000200f8,0x00000169,0x000400f6,0x0000016b,0x0000016c,0x00000000,0x000200f9,0x0000016d, - 0x000200f8,0x0000016d,0x0004003d,0x00000023,0x0000016e,0x00000168,0x000500b3,0x0000002e, - 0x0000016f,0x0000016e,0x00000166,0x000400fa,0x0000016f,0x0000016a,0x0000016b,0x000200f8, - 0x0000016a,0x0004003d,0x00000023,0x00000171,0x00000168,0x0004003d,0x00000023,0x00000172, - 0x00000168,0x00050084,0x00000023,0x00000173,0x00000171,0x00000172,0x0004003d,0x00000023, - 0x00000174,0x0000015e,0x0004003d,0x00000023,0x00000175,0x0000015e,0x00050084,0x00000023, - 0x00000176,0x00000174,0x00000175,0x00050080,0x00000023,0x00000177,0x00000173,0x00000176, - 0x0004006f,0x00000006,0x00000178,0x00000177,0x0004007f,0x00000006,0x00000179,0x00000178, - 0x00050088,0x00000006,0x0000017b,0x00000179,0x0000017a,0x0006000c,0x00000006,0x0000017c, - 0x00000001,0x0000001b,0x0000017b,0x0003003e,0x00000170,0x0000017c,0x0004003d,0x00000006, - 0x0000017d,0x00000170,0x0004003d,0x00000085,0x0000017e,0x00000155,0x0004003d,0x0000000f, - 0x0000017f,0x00000020,0x0004003d,0x00000023,0x00000180,0x00000168,0x0004006f,0x00000006, - 0x00000181,0x00000180,0x0004003d,0x00000023,0x00000182,0x0000015e,0x0004006f,0x00000006, - 0x00000183,0x00000182,0x00050050,0x0000000f,0x00000184,0x00000181,0x00000183,0x0004003d, - 0x0000000f,0x00000185,0x00000154,0x00050085,0x0000000f,0x00000186,0x00000184,0x00000185, - 0x00050081,0x0000000f,0x00000187,0x0000017f,0x00000186,0x0008000c,0x0000000f,0x0000018a, - 0x00000001,0x0000002b,0x00000187,0x00000188,0x00000189,0x00070058,0x0000008a,0x0000018b, - 0x0000017e,0x0000018a,0x00000002,0x00000039,0x0008004f,0x00000011,0x0000018c,0x0000018b, - 0x0000018b,0x00000000,0x00000001,0x00000002,0x0005008e,0x00000011,0x0000018d,0x0000018c, - 0x0000017d,0x0004003d,0x00000011,0x0000018e,0x0000015c,0x00050081,0x00000011,0x0000018f, - 0x0000018e,0x0000018d,0x0003003e,0x0000015c,0x0000018f,0x0004003d,0x00000006,0x00000190, - 0x00000170,0x0004003d,0x00000006,0x00000191,0x0000015d,0x00050081,0x00000006,0x00000192, - 0x00000191,0x00000190,0x0003003e,0x0000015d,0x00000192,0x000200f9,0x0000016c,0x000200f8, - 0x0000016c,0x0004003d,0x00000023,0x00000193,0x00000168,0x00050080,0x00000023,0x00000194, - 0x00000193,0x000000e8,0x0003003e,0x00000168,0x00000194,0x000200f9,0x00000169,0x000200f8, - 0x0000016b,0x000200f9,0x00000163,0x000200f8,0x00000163,0x0004003d,0x00000023,0x00000195, - 0x0000015e,0x00050080,0x00000023,0x00000196,0x00000195,0x000000e8,0x0003003e,0x0000015e, - 0x00000196,0x000200f9,0x00000160,0x000200f8,0x00000162,0x0004003d,0x00000011,0x00000197, - 0x0000015c,0x0004003d,0x00000006,0x00000198,0x0000015d,0x00060050,0x00000011,0x00000199, - 0x00000198,0x00000198,0x00000198,0x00050088,0x00000011,0x0000019a,0x00000197,0x00000199, - 0x0005008e,0x00000011,0x0000019c,0x0000019a,0x0000019b,0x000200fe,0x0000019c,0x00010038, - 0x00050036,0x00000006,0x00000028,0x00000000,0x00000026,0x00030037,0x00000025,0x00000027, - 0x000200f8,0x00000029,0x00050041,0x000000a5,0x000001a1,0x00000027,0x000000c9,0x0004003d, - 0x00000023,0x000001a2,0x000001a1,0x0004006f,0x00000006,0x000001a3,0x000001a2,0x00050085, - 0x00000006,0x000001a4,0x000001a0,0x000001a3,0x00050041,0x000000a5,0x000001a6,0x00000027, - 0x000000ce,0x0004003d,0x00000023,0x000001a7,0x000001a6,0x0004006f,0x00000006,0x000001a8, - 0x000001a7,0x00050085,0x00000006,0x000001a9,0x000001a5,0x000001a8,0x00050081,0x00000006, - 0x000001aa,0x000001a4,0x000001a9,0x0006000c,0x00000006,0x000001ab,0x00000001,0x0000000a, - 0x000001aa,0x00050085,0x00000006,0x000001ac,0x0000019f,0x000001ab,0x0006000c,0x00000006, - 0x000001ad,0x00000001,0x0000000a,0x000001ac,0x00050083,0x00000006,0x000001ae,0x000001ad, - 0x00000043,0x00050088,0x00000006,0x000001b0,0x000001ae,0x000001af,0x000200fe,0x000001b0, - 0x00010038 + 0x00000067,0x00080005,0x0000002e,0x65646973,0x74756f5f,0x65646973,0x3b316628,0x663b3166, + 0x00003b31,0x00030005,0x0000002b,0x00000078,0x00030005,0x0000002c,0x00003078,0x00030005, + 0x0000002d,0x00003178,0x00030005,0x00000041,0x00000070,0x00030005,0x00000080,0x00000050, + 0x00050006,0x00000080,0x00000000,0x65646f6d,0x00000000,0x00050006,0x00000080,0x00000001, + 0x72616873,0x00000070,0x00040006,0x00000080,0x00000002,0x00003078,0x00040006,0x00000080, + 0x00000003,0x00003178,0x00050006,0x00000080,0x00000004,0x65646973,0x00000000,0x00030005, + 0x00000082,0x00006370,0x00030005,0x0000008d,0x00637273,0x00040005,0x00000094,0x657a6973, + 0x00000000,0x00030005,0x00000099,0x00000070,0x00030005,0x0000009f,0x00000062,0x00030005, + 0x000000a3,0x00000066,0x00030005,0x000000a8,0x006d7573,0x00040005,0x000000aa,0x67696577, + 0x00007468,0x00030005,0x000000ac,0x00000079,0x00030005,0x000000b6,0x00000078,0x00030005, + 0x000000be,0x00000064,0x00030005,0x000000c6,0x00000077,0x00040005,0x000000cd,0x61726170, + 0x0000006d,0x00040005,0x000000d3,0x61726170,0x0000006d,0x00040005,0x000000da,0x61726170, + 0x0000006d,0x00040005,0x000000de,0x61726170,0x0000006d,0x00030005,0x00000105,0x00346f6c, + 0x00030005,0x0000010d,0x00346968,0x00030005,0x00000115,0x00006f6c,0x00030005,0x00000119, + 0x00006968,0x00050005,0x0000011d,0x625f6f74,0x6b63616c,0x00000000,0x00050005,0x00000125, + 0x775f6f74,0x65746968,0x00000000,0x00040005,0x0000012f,0x6d6f6f72,0x00000000,0x00040005, + 0x00000133,0x65626f6c,0x00000000,0x00040005,0x00000143,0x72616873,0x00000070,0x00040005, + 0x0000015a,0x70657473,0x00000000,0x00040005,0x0000015b,0x6c616d73,0x0000006c,0x00030005, + 0x00000162,0x006d7573,0x00040005,0x00000163,0x67696577,0x00007468,0x00030005,0x00000164, + 0x00000079,0x00030005,0x0000016e,0x00000069,0x00030005,0x00000176,0x00000077,0x00030005, + 0x000001c8,0x00000067,0x00080005,0x000001cb,0x475f6c67,0x61626f6c,0x766e496c,0x7461636f, + 0x496e6f69,0x00000044,0x00030005,0x000001d0,0x00000064,0x00030005,0x000001d3,0x00747364, + 0x00030005,0x000001de,0x00007675,0x00040005,0x000001ec,0x636f6c62,0x0000006b,0x00030005, + 0x000001f1,0x006d7573,0x00030005,0x000001f2,0x00000079,0x00030005,0x000001fa,0x00000078, + 0x00040005,0x00000223,0x7374756f,0x00656469,0x00040005,0x00000232,0x61726170,0x0000006d, + 0x00040005,0x00000235,0x61726170,0x0000006d,0x00040005,0x00000238,0x61726170,0x0000006d, + 0x00040005,0x00000249,0x61726170,0x0000006d,0x00040005,0x0000024c,0x61726170,0x0000006d, + 0x00030005,0x00000257,0x00000063,0x00040005,0x00000258,0x61726170,0x0000006d,0x00030005, + 0x00000260,0x00000065,0x00030005,0x0000026c,0x0000006e,0x00030005,0x00000276,0x00000073, + 0x00030005,0x0000027f,0x00000077,0x00030005,0x00000289,0x00000072,0x00040005,0x00000292, + 0x61726170,0x0000006d,0x00040005,0x00000294,0x61726170,0x0000006d,0x00040005,0x00000296, + 0x61726170,0x0000006d,0x00040005,0x00000298,0x61726170,0x0000006d,0x00040005,0x0000029a, + 0x61726170,0x0000006d,0x00040005,0x0000029c,0x61726170,0x0000006d,0x00040005,0x000002ac, + 0x61726170,0x0000006d,0x00040005,0x000002af,0x61726170,0x0000006d,0x00030047,0x00000080, + 0x00000002,0x00050048,0x00000080,0x00000000,0x00000023,0x00000000,0x00050048,0x00000080, + 0x00000001,0x00000023,0x00000004,0x00050048,0x00000080,0x00000002,0x00000023,0x00000008, + 0x00050048,0x00000080,0x00000003,0x00000023,0x0000000c,0x00050048,0x00000080,0x00000004, + 0x00000023,0x00000010,0x00040047,0x0000008d,0x00000021,0x00000000,0x00040047,0x0000008d, + 0x00000022,0x00000000,0x00040047,0x0000015b,0x00000021,0x00000002,0x00040047,0x0000015b, + 0x00000022,0x00000000,0x00040047,0x000001cb,0x0000000b,0x0000001c,0x00030047,0x000001d3, + 0x00000019,0x00040047,0x000001d3,0x00000021,0x00000001,0x00040047,0x000001d3,0x00000022, + 0x00000000,0x00040047,0x000002c0,0x0000000b,0x00000019,0x00020013,0x00000002,0x00030021, + 0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040020,0x00000007,0x00000007, + 0x00000006,0x00040021,0x00000008,0x00000006,0x00000007,0x00040017,0x0000000f,0x00000006, + 0x00000002,0x00040020,0x00000010,0x00000007,0x0000000f,0x00040017,0x00000011,0x00000006, + 0x00000003,0x00040021,0x00000012,0x00000011,0x00000010,0x00040020,0x00000016,0x00000007, + 0x00000011,0x00090021,0x00000017,0x00000011,0x00000016,0x00000016,0x00000016,0x00000016, + 0x00000016,0x00000007,0x00040015,0x00000023,0x00000020,0x00000001,0x00040017,0x00000024, + 0x00000023,0x00000002,0x00040020,0x00000025,0x00000007,0x00000024,0x00040021,0x00000026, + 0x00000006,0x00000025,0x00060021,0x0000002a,0x00000006,0x00000007,0x00000007,0x00000007, + 0x0004002b,0x00000006,0x00000033,0x38d1b717,0x00020014,0x00000034,0x0004002b,0x00000006, + 0x00000038,0x3f800000,0x0004002b,0x00000006,0x0000003b,0x40000000,0x0004002b,0x00000006, + 0x0000003f,0x00000000,0x0004002b,0x00000006,0x00000042,0x40490fdb,0x0004002b,0x00000006, + 0x00000049,0x3f000000,0x0004002b,0x00000006,0x00000059,0x3fc00000,0x0004002b,0x00000006, + 0x00000060,0x40200000,0x0004002b,0x00000006,0x0000006c,0xbf000000,0x0004002b,0x00000006, + 0x00000078,0x40800000,0x0007001e,0x00000080,0x00000023,0x00000006,0x00000006,0x00000006, + 0x00000023,0x00040020,0x00000081,0x00000009,0x00000080,0x0004003b,0x00000081,0x00000082, + 0x00000009,0x0004002b,0x00000023,0x00000083,0x00000000,0x00040020,0x00000084,0x00000009, + 0x00000023,0x00090019,0x0000008a,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000, + 0x00000001,0x00000000,0x0003001b,0x0000008b,0x0000008a,0x00040020,0x0000008c,0x00000000, + 0x0000008b,0x0004003b,0x0000008c,0x0000008d,0x00000000,0x00040017,0x00000090,0x00000006, + 0x00000004,0x0006002c,0x00000011,0x000000a9,0x0000003f,0x0000003f,0x0000003f,0x00040020, + 0x000000ab,0x00000007,0x00000023,0x0004002b,0x00000023,0x000000ad,0xffffffff,0x0004002b, + 0x00000023,0x000000b4,0x00000002,0x00040015,0x000000ce,0x00000020,0x00000000,0x0004002b, + 0x000000ce,0x000000cf,0x00000000,0x0004002b,0x000000ce,0x000000d4,0x00000001,0x0005002c, + 0x00000024,0x000000eb,0x00000083,0x00000083,0x0004002b,0x00000023,0x000000ee,0x00000001, + 0x0004002b,0x00000006,0x00000121,0x3a800000,0x0006002c,0x00000011,0x00000122,0x00000121, + 0x00000121,0x00000121,0x0004002b,0x000000ce,0x00000139,0x00000002,0x0004002b,0x00000006, + 0x0000013d,0x3e400000,0x0004003b,0x0000008c,0x0000015b,0x00000000,0x0004002b,0x00000023, + 0x00000165,0xfffffffc,0x0004002b,0x00000023,0x0000016c,0x00000004,0x0004002b,0x00000006, + 0x00000180,0x41000000,0x0005002c,0x0000000f,0x0000018e,0x0000003f,0x0000003f,0x0005002c, + 0x0000000f,0x0000018f,0x00000038,0x00000038,0x0004002b,0x00000006,0x000001a1,0x3f400000, + 0x0004002b,0x00000006,0x000001a5,0x4253ee82,0x0004002b,0x00000006,0x000001a6,0x3d897143, + 0x0004002b,0x00000006,0x000001ab,0x3bbf4590,0x0004002b,0x00000006,0x000001b5,0x437f0000, + 0x0004002b,0x00000006,0x000001bb,0x3bc49ba6,0x00040017,0x000001c9,0x000000ce,0x00000003, + 0x00040020,0x000001ca,0x00000001,0x000001c9,0x0004003b,0x000001ca,0x000001cb,0x00000001, + 0x00040017,0x000001cc,0x000000ce,0x00000002,0x00090019,0x000001d1,0x00000006,0x00000001, + 0x00000000,0x00000000,0x00000000,0x00000002,0x00000004,0x00040020,0x000001d2,0x00000000, + 0x000001d1,0x0004003b,0x000001d2,0x000001d3,0x00000000,0x00040017,0x000001d8,0x00000034, + 0x00000002,0x0004002b,0x00000023,0x000001e8,0x00000003,0x0004002b,0x00000006,0x0000020b, + 0x3e800000,0x0004002b,0x00000006,0x0000021b,0x41800000,0x00040020,0x00000229,0x00000009, + 0x00000006,0x0004002b,0x000000ce,0x000002bf,0x00000008,0x0006002c,0x000001c9,0x000002c0, + 0x000002bf,0x000002bf,0x000000d4,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003, + 0x000200f8,0x00000005,0x0004003b,0x00000025,0x000001c8,0x00000007,0x0004003b,0x00000025, + 0x000001d0,0x00000007,0x0004003b,0x00000010,0x000001de,0x00000007,0x0004003b,0x00000010, + 0x000001ec,0x00000007,0x0004003b,0x00000016,0x000001f1,0x00000007,0x0004003b,0x000000ab, + 0x000001f2,0x00000007,0x0004003b,0x000000ab,0x000001fa,0x00000007,0x0004003b,0x00000007, + 0x00000223,0x00000007,0x0004003b,0x00000007,0x00000232,0x00000007,0x0004003b,0x00000007, + 0x00000235,0x00000007,0x0004003b,0x00000007,0x00000238,0x00000007,0x0004003b,0x00000016, + 0x00000245,0x00000007,0x0004003b,0x00000010,0x00000249,0x00000007,0x0004003b,0x00000025, + 0x0000024c,0x00000007,0x0004003b,0x00000016,0x00000257,0x00000007,0x0004003b,0x00000010, + 0x00000258,0x00000007,0x0004003b,0x00000010,0x00000260,0x00000007,0x0004003b,0x00000016, + 0x0000026c,0x00000007,0x0004003b,0x00000016,0x00000276,0x00000007,0x0004003b,0x00000016, + 0x0000027f,0x00000007,0x0004003b,0x00000016,0x00000289,0x00000007,0x0004003b,0x00000016, + 0x00000292,0x00000007,0x0004003b,0x00000016,0x00000294,0x00000007,0x0004003b,0x00000016, + 0x00000296,0x00000007,0x0004003b,0x00000016,0x00000298,0x00000007,0x0004003b,0x00000016, + 0x0000029a,0x00000007,0x0004003b,0x00000007,0x0000029c,0x00000007,0x0004003b,0x00000016, + 0x000002a8,0x00000007,0x0004003b,0x00000010,0x000002ac,0x00000007,0x0004003b,0x00000025, + 0x000002af,0x00000007,0x0004003d,0x000001c9,0x000001cd,0x000001cb,0x0007004f,0x000001cc, + 0x000001ce,0x000001cd,0x000001cd,0x00000000,0x00000001,0x0004007c,0x00000024,0x000001cf, + 0x000001ce,0x0003003e,0x000001c8,0x000001cf,0x0004003d,0x000001d1,0x000001d4,0x000001d3, + 0x00040068,0x00000024,0x000001d5,0x000001d4,0x0003003e,0x000001d0,0x000001d5,0x0004003d, + 0x00000024,0x000001d6,0x000001c8,0x0004003d,0x00000024,0x000001d7,0x000001d0,0x000500af, + 0x000001d8,0x000001d9,0x000001d6,0x000001d7,0x0004009a,0x00000034,0x000001da,0x000001d9, + 0x000300f7,0x000001dc,0x00000000,0x000400fa,0x000001da,0x000001db,0x000001dc,0x000200f8, + 0x000001db,0x000100fd,0x000200f8,0x000001dc,0x0004003d,0x00000024,0x000001df,0x000001c8, + 0x0004006f,0x0000000f,0x000001e0,0x000001df,0x00050050,0x0000000f,0x000001e1,0x00000049, + 0x00000049,0x00050081,0x0000000f,0x000001e2,0x000001e0,0x000001e1,0x0004003d,0x00000024, + 0x000001e3,0x000001d0,0x0004006f,0x0000000f,0x000001e4,0x000001e3,0x00050088,0x0000000f, + 0x000001e5,0x000001e2,0x000001e4,0x0003003e,0x000001de,0x000001e5,0x00050041,0x00000084, + 0x000001e6,0x00000082,0x0000016c,0x0004003d,0x00000023,0x000001e7,0x000001e6,0x000500aa, + 0x00000034,0x000001e9,0x000001e7,0x000001e8,0x000300f7,0x000001eb,0x00000000,0x000400fa, + 0x000001e9,0x000001ea,0x000001eb,0x000200f8,0x000001ea,0x0004003d,0x00000024,0x000001ed, + 0x000001d0,0x0004006f,0x0000000f,0x000001ee,0x000001ed,0x00050050,0x0000000f,0x000001ef, + 0x00000038,0x00000038,0x00050088,0x0000000f,0x000001f0,0x000001ef,0x000001ee,0x0003003e, + 0x000001ec,0x000001f0,0x0003003e,0x000001f1,0x000000a9,0x0003003e,0x000001f2,0x00000083, + 0x000200f9,0x000001f3,0x000200f8,0x000001f3,0x000400f6,0x000001f5,0x000001f6,0x00000000, + 0x000200f9,0x000001f7,0x000200f8,0x000001f7,0x0004003d,0x00000023,0x000001f8,0x000001f2, + 0x000500b1,0x00000034,0x000001f9,0x000001f8,0x0000016c,0x000400fa,0x000001f9,0x000001f4, + 0x000001f5,0x000200f8,0x000001f4,0x0003003e,0x000001fa,0x00000083,0x000200f9,0x000001fb, + 0x000200f8,0x000001fb,0x000400f6,0x000001fd,0x000001fe,0x00000000,0x000200f9,0x000001ff, + 0x000200f8,0x000001ff,0x0004003d,0x00000023,0x00000200,0x000001fa,0x000500b1,0x00000034, + 0x00000201,0x00000200,0x0000016c,0x000400fa,0x00000201,0x000001fc,0x000001fd,0x000200f8, + 0x000001fc,0x0004003d,0x0000008b,0x00000202,0x0000008d,0x0004003d,0x0000000f,0x00000203, + 0x000001de,0x0004003d,0x00000023,0x00000204,0x000001fa,0x0004006f,0x00000006,0x00000205, + 0x00000204,0x0004003d,0x00000023,0x00000206,0x000001f2,0x0004006f,0x00000006,0x00000207, + 0x00000206,0x00050050,0x0000000f,0x00000208,0x00000205,0x00000207,0x00050050,0x0000000f, + 0x00000209,0x00000059,0x00000059,0x00050083,0x0000000f,0x0000020a,0x00000208,0x00000209, + 0x0005008e,0x0000000f,0x0000020c,0x0000020a,0x0000020b,0x0004003d,0x0000000f,0x0000020d, + 0x000001ec,0x00050085,0x0000000f,0x0000020e,0x0000020c,0x0000020d,0x00050081,0x0000000f, + 0x0000020f,0x00000203,0x0000020e,0x00070058,0x00000090,0x00000210,0x00000202,0x0000020f, + 0x00000002,0x0000003f,0x0008004f,0x00000011,0x00000211,0x00000210,0x00000210,0x00000000, + 0x00000001,0x00000002,0x0004003d,0x00000011,0x00000212,0x000001f1,0x00050081,0x00000011, + 0x00000213,0x00000212,0x00000211,0x0003003e,0x000001f1,0x00000213,0x000200f9,0x000001fe, + 0x000200f8,0x000001fe,0x0004003d,0x00000023,0x00000214,0x000001fa,0x00050080,0x00000023, + 0x00000215,0x00000214,0x000000ee,0x0003003e,0x000001fa,0x00000215,0x000200f9,0x000001fb, + 0x000200f8,0x000001fd,0x000200f9,0x000001f6,0x000200f8,0x000001f6,0x0004003d,0x00000023, + 0x00000216,0x000001f2,0x00050080,0x00000023,0x00000217,0x00000216,0x000000ee,0x0003003e, + 0x000001f2,0x00000217,0x000200f9,0x000001f3,0x000200f8,0x000001f5,0x0004003d,0x000001d1, + 0x00000218,0x000001d3,0x0004003d,0x00000024,0x00000219,0x000001c8,0x0004003d,0x00000011, + 0x0000021a,0x000001f1,0x00060050,0x00000011,0x0000021c,0x0000021b,0x0000021b,0x0000021b, + 0x00050088,0x00000011,0x0000021d,0x0000021a,0x0000021c,0x00050051,0x00000006,0x0000021e, + 0x0000021d,0x00000000,0x00050051,0x00000006,0x0000021f,0x0000021d,0x00000001,0x00050051, + 0x00000006,0x00000220,0x0000021d,0x00000002,0x00070050,0x00000090,0x00000221,0x0000021e, + 0x0000021f,0x00000220,0x00000038,0x00040063,0x00000218,0x00000219,0x00000221,0x000100fd, + 0x000200f8,0x000001eb,0x0003003e,0x00000223,0x0000003f,0x00050041,0x00000084,0x00000224, + 0x00000082,0x0000016c,0x0004003d,0x00000023,0x00000225,0x00000224,0x000500ab,0x00000034, + 0x00000226,0x00000225,0x00000083,0x000300f7,0x00000228,0x00000000,0x000400fa,0x00000226, + 0x00000227,0x00000228,0x000200f8,0x00000227,0x00050041,0x00000229,0x0000022a,0x00000082, + 0x000001e8,0x0004003d,0x00000006,0x0000022b,0x0000022a,0x00050041,0x00000229,0x0000022c, + 0x00000082,0x000000b4,0x0004003d,0x00000006,0x0000022d,0x0000022c,0x000500ba,0x00000034, + 0x0000022e,0x0000022b,0x0000022d,0x000200f9,0x00000228,0x000200f8,0x00000228,0x000700f5, + 0x00000034,0x0000022f,0x00000226,0x000001eb,0x0000022e,0x00000227,0x000300f7,0x00000231, + 0x00000000,0x000400fa,0x0000022f,0x00000230,0x00000231,0x000200f8,0x00000230,0x00050041, + 0x00000007,0x00000233,0x000001de,0x000000cf,0x0004003d,0x00000006,0x00000234,0x00000233, + 0x0003003e,0x00000232,0x00000234,0x00050041,0x00000229,0x00000236,0x00000082,0x000000b4, + 0x0004003d,0x00000006,0x00000237,0x00000236,0x0003003e,0x00000235,0x00000237,0x00050041, + 0x00000229,0x00000239,0x00000082,0x000001e8,0x0004003d,0x00000006,0x0000023a,0x00000239, + 0x0003003e,0x00000238,0x0000023a,0x00070039,0x00000006,0x0000023b,0x0000002e,0x00000232, + 0x00000235,0x00000238,0x0003003e,0x00000223,0x0000023b,0x0004003d,0x00000006,0x0000023c, + 0x00000223,0x000500be,0x00000034,0x0000023d,0x0000023c,0x00000038,0x000300f7,0x0000023f, + 0x00000000,0x000400fa,0x0000023d,0x0000023e,0x0000023f,0x000200f8,0x0000023e,0x0004003d, + 0x000001d1,0x00000240,0x000001d3,0x0004003d,0x00000024,0x00000241,0x000001c8,0x00050041, + 0x00000084,0x00000242,0x00000082,0x0000016c,0x0004003d,0x00000023,0x00000243,0x00000242, + 0x000500aa,0x00000034,0x00000244,0x00000243,0x000000b4,0x000300f7,0x00000247,0x00000000, + 0x000400fa,0x00000244,0x00000246,0x00000248,0x000200f8,0x00000246,0x0003003e,0x00000245, + 0x000000a9,0x000200f9,0x00000247,0x000200f8,0x00000248,0x0004003d,0x0000000f,0x0000024a, + 0x000001de,0x0003003e,0x00000249,0x0000024a,0x00050039,0x00000011,0x0000024b,0x00000021, + 0x00000249,0x0004003d,0x00000024,0x0000024d,0x000001c8,0x0003003e,0x0000024c,0x0000024d, + 0x00050039,0x00000006,0x0000024e,0x00000028,0x0000024c,0x00060050,0x00000011,0x0000024f, + 0x0000024e,0x0000024e,0x0000024e,0x00050081,0x00000011,0x00000250,0x0000024b,0x0000024f, + 0x0003003e,0x00000245,0x00000250,0x000200f9,0x00000247,0x000200f8,0x00000247,0x0004003d, + 0x00000011,0x00000251,0x00000245,0x00050051,0x00000006,0x00000252,0x00000251,0x00000000, + 0x00050051,0x00000006,0x00000253,0x00000251,0x00000001,0x00050051,0x00000006,0x00000254, + 0x00000251,0x00000002,0x00070050,0x00000090,0x00000255,0x00000252,0x00000253,0x00000254, + 0x00000038,0x00040063,0x00000240,0x00000241,0x00000255,0x000100fd,0x000200f8,0x0000023f, + 0x000200f9,0x00000231,0x000200f8,0x00000231,0x0004003d,0x0000000f,0x00000259,0x000001de, + 0x0003003e,0x00000258,0x00000259,0x00050039,0x00000011,0x0000025a,0x00000014,0x00000258, + 0x0003003e,0x00000257,0x0000025a,0x00050041,0x00000229,0x0000025b,0x00000082,0x000000ee, + 0x0004003d,0x00000006,0x0000025c,0x0000025b,0x000500ba,0x00000034,0x0000025d,0x0000025c, + 0x0000003f,0x000300f7,0x0000025f,0x00000000,0x000400fa,0x0000025d,0x0000025e,0x0000025f, + 0x000200f8,0x0000025e,0x0004003d,0x0000008b,0x00000261,0x0000008d,0x00040064,0x0000008a, + 0x00000262,0x00000261,0x00050067,0x00000024,0x00000263,0x00000262,0x00000083,0x0004006f, + 0x0000000f,0x00000264,0x00000263,0x00050050,0x0000000f,0x00000265,0x00000038,0x00000038, + 0x00050088,0x0000000f,0x00000266,0x00000265,0x00000264,0x0004003d,0x00000024,0x00000267, + 0x000001d0,0x0004006f,0x0000000f,0x00000268,0x00000267,0x00050050,0x0000000f,0x00000269, + 0x00000038,0x00000038,0x00050088,0x0000000f,0x0000026a,0x00000269,0x00000268,0x0007000c, + 0x0000000f,0x0000026b,0x00000001,0x00000028,0x00000266,0x0000026a,0x0003003e,0x00000260, + 0x0000026b,0x0004003d,0x0000008b,0x0000026d,0x0000008d,0x0004003d,0x0000000f,0x0000026e, + 0x000001de,0x00050041,0x00000007,0x0000026f,0x00000260,0x000000d4,0x0004003d,0x00000006, + 0x00000270,0x0000026f,0x0004007f,0x00000006,0x00000271,0x00000270,0x00050050,0x0000000f, + 0x00000272,0x0000003f,0x00000271,0x00050081,0x0000000f,0x00000273,0x0000026e,0x00000272, + 0x00070058,0x00000090,0x00000274,0x0000026d,0x00000273,0x00000002,0x0000003f,0x0008004f, + 0x00000011,0x00000275,0x00000274,0x00000274,0x00000000,0x00000001,0x00000002,0x0003003e, + 0x0000026c,0x00000275,0x0004003d,0x0000008b,0x00000277,0x0000008d,0x0004003d,0x0000000f, + 0x00000278,0x000001de,0x00050041,0x00000007,0x00000279,0x00000260,0x000000d4,0x0004003d, + 0x00000006,0x0000027a,0x00000279,0x00050050,0x0000000f,0x0000027b,0x0000003f,0x0000027a, + 0x00050081,0x0000000f,0x0000027c,0x00000278,0x0000027b,0x00070058,0x00000090,0x0000027d, + 0x00000277,0x0000027c,0x00000002,0x0000003f,0x0008004f,0x00000011,0x0000027e,0x0000027d, + 0x0000027d,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000276,0x0000027e,0x0004003d, + 0x0000008b,0x00000280,0x0000008d,0x0004003d,0x0000000f,0x00000281,0x000001de,0x00050041, + 0x00000007,0x00000282,0x00000260,0x000000cf,0x0004003d,0x00000006,0x00000283,0x00000282, + 0x0004007f,0x00000006,0x00000284,0x00000283,0x00050050,0x0000000f,0x00000285,0x00000284, + 0x0000003f,0x00050081,0x0000000f,0x00000286,0x00000281,0x00000285,0x00070058,0x00000090, + 0x00000287,0x00000280,0x00000286,0x00000002,0x0000003f,0x0008004f,0x00000011,0x00000288, + 0x00000287,0x00000287,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000027f,0x00000288, + 0x0004003d,0x0000008b,0x0000028a,0x0000008d,0x0004003d,0x0000000f,0x0000028b,0x000001de, + 0x00050041,0x00000007,0x0000028c,0x00000260,0x000000cf,0x0004003d,0x00000006,0x0000028d, + 0x0000028c,0x00050050,0x0000000f,0x0000028e,0x0000028d,0x0000003f,0x00050081,0x0000000f, + 0x0000028f,0x0000028b,0x0000028e,0x00070058,0x00000090,0x00000290,0x0000028a,0x0000028f, + 0x00000002,0x0000003f,0x0008004f,0x00000011,0x00000291,0x00000290,0x00000290,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x00000289,0x00000291,0x0004003d,0x00000011,0x00000293, + 0x00000257,0x0003003e,0x00000292,0x00000293,0x0004003d,0x00000011,0x00000295,0x0000026c, + 0x0003003e,0x00000294,0x00000295,0x0004003d,0x00000011,0x00000297,0x00000276,0x0003003e, + 0x00000296,0x00000297,0x0004003d,0x00000011,0x00000299,0x0000027f,0x0003003e,0x00000298, + 0x00000299,0x0004003d,0x00000011,0x0000029b,0x00000289,0x0003003e,0x0000029a,0x0000029b, + 0x00050041,0x00000229,0x0000029d,0x00000082,0x000000ee,0x0004003d,0x00000006,0x0000029e, + 0x0000029d,0x0003003e,0x0000029c,0x0000029e,0x000a0039,0x00000011,0x0000029f,0x0000001e, + 0x00000292,0x00000294,0x00000296,0x00000298,0x0000029a,0x0000029c,0x0003003e,0x00000257, + 0x0000029f,0x000200f9,0x0000025f,0x000200f8,0x0000025f,0x0004003d,0x00000006,0x000002a0, + 0x00000223,0x000500ba,0x00000034,0x000002a1,0x000002a0,0x0000003f,0x000300f7,0x000002a3, + 0x00000000,0x000400fa,0x000002a1,0x000002a2,0x000002a3,0x000200f8,0x000002a2,0x0004003d, + 0x00000011,0x000002a4,0x00000257,0x00050041,0x00000084,0x000002a5,0x00000082,0x0000016c, + 0x0004003d,0x00000023,0x000002a6,0x000002a5,0x000500aa,0x00000034,0x000002a7,0x000002a6, + 0x000000b4,0x000300f7,0x000002aa,0x00000000,0x000400fa,0x000002a7,0x000002a9,0x000002ab, + 0x000200f8,0x000002a9,0x0003003e,0x000002a8,0x000000a9,0x000200f9,0x000002aa,0x000200f8, + 0x000002ab,0x0004003d,0x0000000f,0x000002ad,0x000001de,0x0003003e,0x000002ac,0x000002ad, + 0x00050039,0x00000011,0x000002ae,0x00000021,0x000002ac,0x0004003d,0x00000024,0x000002b0, + 0x000001c8,0x0003003e,0x000002af,0x000002b0,0x00050039,0x00000006,0x000002b1,0x00000028, + 0x000002af,0x00060050,0x00000011,0x000002b2,0x000002b1,0x000002b1,0x000002b1,0x00050081, + 0x00000011,0x000002b3,0x000002ae,0x000002b2,0x0003003e,0x000002a8,0x000002b3,0x000200f9, + 0x000002aa,0x000200f8,0x000002aa,0x0004003d,0x00000011,0x000002b4,0x000002a8,0x0004003d, + 0x00000006,0x000002b5,0x00000223,0x00060050,0x00000011,0x000002b6,0x000002b5,0x000002b5, + 0x000002b5,0x0008000c,0x00000011,0x000002b7,0x00000001,0x0000002e,0x000002a4,0x000002b4, + 0x000002b6,0x0003003e,0x00000257,0x000002b7,0x000200f9,0x000002a3,0x000200f8,0x000002a3, + 0x0004003d,0x000001d1,0x000002b8,0x000001d3,0x0004003d,0x00000024,0x000002b9,0x000001c8, + 0x0004003d,0x00000011,0x000002ba,0x00000257,0x00050051,0x00000006,0x000002bb,0x000002ba, + 0x00000000,0x00050051,0x00000006,0x000002bc,0x000002ba,0x00000001,0x00050051,0x00000006, + 0x000002bd,0x000002ba,0x00000002,0x00070050,0x00000090,0x000002be,0x000002bb,0x000002bc, + 0x000002bd,0x00000038,0x00040063,0x000002b8,0x000002b9,0x000002be,0x000100fd,0x00010038, + 0x00050036,0x00000006,0x0000000a,0x00000000,0x00000008,0x00030037,0x00000007,0x00000009, + 0x000200f8,0x0000000b,0x0004003b,0x00000007,0x00000041,0x00000007,0x0004003d,0x00000006, + 0x00000030,0x00000009,0x0006000c,0x00000006,0x00000031,0x00000001,0x00000004,0x00000030, + 0x0003003e,0x00000009,0x00000031,0x0004003d,0x00000006,0x00000032,0x00000009,0x000500b8, + 0x00000034,0x00000035,0x00000032,0x00000033,0x000300f7,0x00000037,0x00000000,0x000400fa, + 0x00000035,0x00000036,0x00000037,0x000200f8,0x00000036,0x000200fe,0x00000038,0x000200f8, + 0x00000037,0x0004003d,0x00000006,0x0000003a,0x00000009,0x000500be,0x00000034,0x0000003c, + 0x0000003a,0x0000003b,0x000300f7,0x0000003e,0x00000000,0x000400fa,0x0000003c,0x0000003d, + 0x0000003e,0x000200f8,0x0000003d,0x000200fe,0x0000003f,0x000200f8,0x0000003e,0x0004003d, + 0x00000006,0x00000043,0x00000009,0x00050085,0x00000006,0x00000044,0x00000042,0x00000043, + 0x0003003e,0x00000041,0x00000044,0x0004003d,0x00000006,0x00000045,0x00000041,0x0006000c, + 0x00000006,0x00000046,0x00000001,0x0000000d,0x00000045,0x00050085,0x00000006,0x00000047, + 0x0000003b,0x00000046,0x0004003d,0x00000006,0x00000048,0x00000041,0x00050085,0x00000006, + 0x0000004a,0x00000048,0x00000049,0x0006000c,0x00000006,0x0000004b,0x00000001,0x0000000d, + 0x0000004a,0x00050085,0x00000006,0x0000004c,0x00000047,0x0000004b,0x0004003d,0x00000006, + 0x0000004d,0x00000041,0x0004003d,0x00000006,0x0000004e,0x00000041,0x00050085,0x00000006, + 0x0000004f,0x0000004d,0x0000004e,0x00050088,0x00000006,0x00000050,0x0000004c,0x0000004f, + 0x000200fe,0x00000050,0x00010038,0x00050036,0x00000006,0x0000000d,0x00000000,0x00000008, + 0x00030037,0x00000007,0x0000000c,0x000200f8,0x0000000e,0x0004003d,0x00000006,0x00000053, + 0x0000000c,0x0006000c,0x00000006,0x00000054,0x00000001,0x00000004,0x00000053,0x0003003e, + 0x0000000c,0x00000054,0x0004003d,0x00000006,0x00000055,0x0000000c,0x000500b8,0x00000034, + 0x00000056,0x00000055,0x00000038,0x000300f7,0x00000058,0x00000000,0x000400fa,0x00000056, + 0x00000057,0x00000058,0x000200f8,0x00000057,0x0004003d,0x00000006,0x0000005a,0x0000000c, + 0x00050085,0x00000006,0x0000005b,0x00000059,0x0000005a,0x0004003d,0x00000006,0x0000005c, + 0x0000000c,0x00050085,0x00000006,0x0000005d,0x0000005b,0x0000005c,0x0004003d,0x00000006, + 0x0000005e,0x0000000c,0x00050085,0x00000006,0x0000005f,0x0000005d,0x0000005e,0x0004003d, + 0x00000006,0x00000061,0x0000000c,0x00050085,0x00000006,0x00000062,0x00000060,0x00000061, + 0x0004003d,0x00000006,0x00000063,0x0000000c,0x00050085,0x00000006,0x00000064,0x00000062, + 0x00000063,0x00050083,0x00000006,0x00000065,0x0000005f,0x00000064,0x00050081,0x00000006, + 0x00000066,0x00000065,0x00000038,0x000200fe,0x00000066,0x000200f8,0x00000058,0x0004003d, + 0x00000006,0x00000068,0x0000000c,0x000500b8,0x00000034,0x00000069,0x00000068,0x0000003b, + 0x000300f7,0x0000006b,0x00000000,0x000400fa,0x00000069,0x0000006a,0x0000006b,0x000200f8, + 0x0000006a,0x0004003d,0x00000006,0x0000006d,0x0000000c,0x00050085,0x00000006,0x0000006e, + 0x0000006c,0x0000006d,0x0004003d,0x00000006,0x0000006f,0x0000000c,0x00050085,0x00000006, + 0x00000070,0x0000006e,0x0000006f,0x0004003d,0x00000006,0x00000071,0x0000000c,0x00050085, + 0x00000006,0x00000072,0x00000070,0x00000071,0x0004003d,0x00000006,0x00000073,0x0000000c, + 0x00050085,0x00000006,0x00000074,0x00000060,0x00000073,0x0004003d,0x00000006,0x00000075, + 0x0000000c,0x00050085,0x00000006,0x00000076,0x00000074,0x00000075,0x00050081,0x00000006, + 0x00000077,0x00000072,0x00000076,0x0004003d,0x00000006,0x00000079,0x0000000c,0x00050085, + 0x00000006,0x0000007a,0x00000078,0x00000079,0x00050083,0x00000006,0x0000007b,0x00000077, + 0x0000007a,0x00050081,0x00000006,0x0000007c,0x0000007b,0x0000003b,0x000200fe,0x0000007c, + 0x000200f8,0x0000006b,0x000200fe,0x0000003f,0x00010038,0x00050036,0x00000011,0x00000014, + 0x00000000,0x00000012,0x00030037,0x00000010,0x00000013,0x000200f8,0x00000015,0x0004003b, + 0x00000010,0x00000094,0x00000007,0x0004003b,0x00000010,0x00000099,0x00000007,0x0004003b, + 0x00000025,0x0000009f,0x00000007,0x0004003b,0x00000010,0x000000a3,0x00000007,0x0004003b, + 0x00000016,0x000000a8,0x00000007,0x0004003b,0x00000007,0x000000aa,0x00000007,0x0004003b, + 0x000000ab,0x000000ac,0x00000007,0x0004003b,0x000000ab,0x000000b6,0x00000007,0x0004003b, + 0x00000010,0x000000be,0x00000007,0x0004003b,0x00000007,0x000000c6,0x00000007,0x0004003b, + 0x00000007,0x000000ca,0x00000007,0x0004003b,0x00000007,0x000000cd,0x00000007,0x0004003b, + 0x00000007,0x000000d3,0x00000007,0x0004003b,0x00000007,0x000000da,0x00000007,0x0004003b, + 0x00000007,0x000000de,0x00000007,0x00050041,0x00000084,0x00000085,0x00000082,0x00000083, + 0x0004003d,0x00000023,0x00000086,0x00000085,0x000500aa,0x00000034,0x00000087,0x00000086, + 0x00000083,0x000300f7,0x00000089,0x00000000,0x000400fa,0x00000087,0x00000088,0x00000089, + 0x000200f8,0x00000088,0x0004003d,0x0000008b,0x0000008e,0x0000008d,0x0004003d,0x0000000f, + 0x0000008f,0x00000013,0x00070058,0x00000090,0x00000091,0x0000008e,0x0000008f,0x00000002, + 0x0000003f,0x0008004f,0x00000011,0x00000092,0x00000091,0x00000091,0x00000000,0x00000001, + 0x00000002,0x000200fe,0x00000092,0x000200f8,0x00000089,0x0004003d,0x0000008b,0x00000095, + 0x0000008d,0x00040064,0x0000008a,0x00000096,0x00000095,0x00050067,0x00000024,0x00000097, + 0x00000096,0x00000083,0x0004006f,0x0000000f,0x00000098,0x00000097,0x0003003e,0x00000094, + 0x00000098,0x0004003d,0x0000000f,0x0000009a,0x00000013,0x0004003d,0x0000000f,0x0000009b, + 0x00000094,0x00050085,0x0000000f,0x0000009c,0x0000009a,0x0000009b,0x00050050,0x0000000f, + 0x0000009d,0x00000049,0x00000049,0x00050083,0x0000000f,0x0000009e,0x0000009c,0x0000009d, + 0x0003003e,0x00000099,0x0000009e,0x0004003d,0x0000000f,0x000000a0,0x00000099,0x0006000c, + 0x0000000f,0x000000a1,0x00000001,0x00000008,0x000000a0,0x0004006e,0x00000024,0x000000a2, + 0x000000a1,0x0003003e,0x0000009f,0x000000a2,0x0004003d,0x0000000f,0x000000a4,0x00000099, + 0x0004003d,0x00000024,0x000000a5,0x0000009f,0x0004006f,0x0000000f,0x000000a6,0x000000a5, + 0x00050083,0x0000000f,0x000000a7,0x000000a4,0x000000a6,0x0003003e,0x000000a3,0x000000a7, + 0x0003003e,0x000000a8,0x000000a9,0x0003003e,0x000000aa,0x0000003f,0x0003003e,0x000000ac, + 0x000000ad,0x000200f9,0x000000ae,0x000200f8,0x000000ae,0x000400f6,0x000000b0,0x000000b1, + 0x00000000,0x000200f9,0x000000b2,0x000200f8,0x000000b2,0x0004003d,0x00000023,0x000000b3, + 0x000000ac,0x000500b3,0x00000034,0x000000b5,0x000000b3,0x000000b4,0x000400fa,0x000000b5, + 0x000000af,0x000000b0,0x000200f8,0x000000af,0x0003003e,0x000000b6,0x000000ad,0x000200f9, + 0x000000b7,0x000200f8,0x000000b7,0x000400f6,0x000000b9,0x000000ba,0x00000000,0x000200f9, + 0x000000bb,0x000200f8,0x000000bb,0x0004003d,0x00000023,0x000000bc,0x000000b6,0x000500b3, + 0x00000034,0x000000bd,0x000000bc,0x000000b4,0x000400fa,0x000000bd,0x000000b8,0x000000b9, + 0x000200f8,0x000000b8,0x0004003d,0x00000023,0x000000bf,0x000000b6,0x0004006f,0x00000006, + 0x000000c0,0x000000bf,0x0004003d,0x00000023,0x000000c1,0x000000ac,0x0004006f,0x00000006, + 0x000000c2,0x000000c1,0x00050050,0x0000000f,0x000000c3,0x000000c0,0x000000c2,0x0004003d, + 0x0000000f,0x000000c4,0x000000a3,0x00050083,0x0000000f,0x000000c5,0x000000c3,0x000000c4, + 0x0003003e,0x000000be,0x000000c5,0x00050041,0x00000084,0x000000c7,0x00000082,0x00000083, + 0x0004003d,0x00000023,0x000000c8,0x000000c7,0x000500aa,0x00000034,0x000000c9,0x000000c8, + 0x000000b4,0x000300f7,0x000000cc,0x00000000,0x000400fa,0x000000c9,0x000000cb,0x000000d9, + 0x000200f8,0x000000cb,0x00050041,0x00000007,0x000000d0,0x000000be,0x000000cf,0x0004003d, + 0x00000006,0x000000d1,0x000000d0,0x0003003e,0x000000cd,0x000000d1,0x00050039,0x00000006, + 0x000000d2,0x0000000a,0x000000cd,0x00050041,0x00000007,0x000000d5,0x000000be,0x000000d4, + 0x0004003d,0x00000006,0x000000d6,0x000000d5,0x0003003e,0x000000d3,0x000000d6,0x00050039, + 0x00000006,0x000000d7,0x0000000a,0x000000d3,0x00050085,0x00000006,0x000000d8,0x000000d2, + 0x000000d7,0x0003003e,0x000000ca,0x000000d8,0x000200f9,0x000000cc,0x000200f8,0x000000d9, + 0x00050041,0x00000007,0x000000db,0x000000be,0x000000cf,0x0004003d,0x00000006,0x000000dc, + 0x000000db,0x0003003e,0x000000da,0x000000dc,0x00050039,0x00000006,0x000000dd,0x0000000d, + 0x000000da,0x00050041,0x00000007,0x000000df,0x000000be,0x000000d4,0x0004003d,0x00000006, + 0x000000e0,0x000000df,0x0003003e,0x000000de,0x000000e0,0x00050039,0x00000006,0x000000e1, + 0x0000000d,0x000000de,0x00050085,0x00000006,0x000000e2,0x000000dd,0x000000e1,0x0003003e, + 0x000000ca,0x000000e2,0x000200f9,0x000000cc,0x000200f8,0x000000cc,0x0004003d,0x00000006, + 0x000000e3,0x000000ca,0x0003003e,0x000000c6,0x000000e3,0x0004003d,0x00000006,0x000000e4, + 0x000000c6,0x0004003d,0x0000008b,0x000000e5,0x0000008d,0x0004003d,0x00000024,0x000000e6, + 0x0000009f,0x0004003d,0x00000023,0x000000e7,0x000000b6,0x0004003d,0x00000023,0x000000e8, + 0x000000ac,0x00050050,0x00000024,0x000000e9,0x000000e7,0x000000e8,0x00050080,0x00000024, + 0x000000ea,0x000000e6,0x000000e9,0x0004003d,0x0000000f,0x000000ec,0x00000094,0x0004006e, + 0x00000024,0x000000ed,0x000000ec,0x00050050,0x00000024,0x000000ef,0x000000ee,0x000000ee, + 0x00050082,0x00000024,0x000000f0,0x000000ed,0x000000ef,0x0008000c,0x00000024,0x000000f1, + 0x00000001,0x0000002d,0x000000ea,0x000000eb,0x000000f0,0x00040064,0x0000008a,0x000000f2, + 0x000000e5,0x0007005f,0x00000090,0x000000f3,0x000000f2,0x000000f1,0x00000002,0x00000083, + 0x0008004f,0x00000011,0x000000f4,0x000000f3,0x000000f3,0x00000000,0x00000001,0x00000002, + 0x0005008e,0x00000011,0x000000f5,0x000000f4,0x000000e4,0x0004003d,0x00000011,0x000000f6, + 0x000000a8,0x00050081,0x00000011,0x000000f7,0x000000f6,0x000000f5,0x0003003e,0x000000a8, + 0x000000f7,0x0004003d,0x00000006,0x000000f8,0x000000c6,0x0004003d,0x00000006,0x000000f9, + 0x000000aa,0x00050081,0x00000006,0x000000fa,0x000000f9,0x000000f8,0x0003003e,0x000000aa, + 0x000000fa,0x000200f9,0x000000ba,0x000200f8,0x000000ba,0x0004003d,0x00000023,0x000000fb, + 0x000000b6,0x00050080,0x00000023,0x000000fc,0x000000fb,0x000000ee,0x0003003e,0x000000b6, + 0x000000fc,0x000200f9,0x000000b7,0x000200f8,0x000000b9,0x000200f9,0x000000b1,0x000200f8, + 0x000000b1,0x0004003d,0x00000023,0x000000fd,0x000000ac,0x00050080,0x00000023,0x000000fe, + 0x000000fd,0x000000ee,0x0003003e,0x000000ac,0x000000fe,0x000200f9,0x000000ae,0x000200f8, + 0x000000b0,0x0004003d,0x00000011,0x000000ff,0x000000a8,0x0004003d,0x00000006,0x00000100, + 0x000000aa,0x00060050,0x00000011,0x00000101,0x00000100,0x00000100,0x00000100,0x00050088, + 0x00000011,0x00000102,0x000000ff,0x00000101,0x000200fe,0x00000102,0x00010038,0x00050036, + 0x00000011,0x0000001e,0x00000000,0x00000017,0x00030037,0x00000016,0x00000018,0x00030037, + 0x00000016,0x00000019,0x00030037,0x00000016,0x0000001a,0x00030037,0x00000016,0x0000001b, + 0x00030037,0x00000016,0x0000001c,0x00030037,0x00000007,0x0000001d,0x000200f8,0x0000001f, + 0x0004003b,0x00000016,0x00000105,0x00000007,0x0004003b,0x00000016,0x0000010d,0x00000007, + 0x0004003b,0x00000016,0x00000115,0x00000007,0x0004003b,0x00000016,0x00000119,0x00000007, + 0x0004003b,0x00000016,0x0000011d,0x00000007,0x0004003b,0x00000016,0x00000125,0x00000007, + 0x0004003b,0x00000016,0x0000012f,0x00000007,0x0004003b,0x00000007,0x00000133,0x00000007, + 0x0004003b,0x00000016,0x00000143,0x00000007,0x0004003d,0x00000011,0x00000106,0x00000019, + 0x0004003d,0x00000011,0x00000107,0x0000001a,0x0007000c,0x00000011,0x00000108,0x00000001, + 0x00000025,0x00000106,0x00000107,0x0004003d,0x00000011,0x00000109,0x0000001b,0x0004003d, + 0x00000011,0x0000010a,0x0000001c,0x0007000c,0x00000011,0x0000010b,0x00000001,0x00000025, + 0x00000109,0x0000010a,0x0007000c,0x00000011,0x0000010c,0x00000001,0x00000025,0x00000108, + 0x0000010b,0x0003003e,0x00000105,0x0000010c,0x0004003d,0x00000011,0x0000010e,0x00000019, + 0x0004003d,0x00000011,0x0000010f,0x0000001a,0x0007000c,0x00000011,0x00000110,0x00000001, + 0x00000028,0x0000010e,0x0000010f,0x0004003d,0x00000011,0x00000111,0x0000001b,0x0004003d, + 0x00000011,0x00000112,0x0000001c,0x0007000c,0x00000011,0x00000113,0x00000001,0x00000028, + 0x00000111,0x00000112,0x0007000c,0x00000011,0x00000114,0x00000001,0x00000028,0x00000110, + 0x00000113,0x0003003e,0x0000010d,0x00000114,0x0004003d,0x00000011,0x00000116,0x00000105, + 0x0004003d,0x00000011,0x00000117,0x00000018,0x0007000c,0x00000011,0x00000118,0x00000001, + 0x00000025,0x00000116,0x00000117,0x0003003e,0x00000115,0x00000118,0x0004003d,0x00000011, + 0x0000011a,0x0000010d,0x0004003d,0x00000011,0x0000011b,0x00000018,0x0007000c,0x00000011, + 0x0000011c,0x00000001,0x00000028,0x0000011a,0x0000011b,0x0003003e,0x00000119,0x0000011c, + 0x0004003d,0x00000011,0x0000011e,0x00000115,0x0004003d,0x00000011,0x0000011f,0x00000119, + 0x0005008e,0x00000011,0x00000120,0x0000011f,0x00000078,0x0007000c,0x00000011,0x00000123, + 0x00000001,0x00000028,0x00000120,0x00000122,0x00050088,0x00000011,0x00000124,0x0000011e, + 0x00000123,0x0003003e,0x0000011d,0x00000124,0x0004003d,0x00000011,0x00000126,0x00000119, + 0x00060050,0x00000011,0x00000127,0x00000038,0x00000038,0x00000038,0x00050083,0x00000011, + 0x00000128,0x00000127,0x00000126,0x0004003d,0x00000011,0x00000129,0x00000105,0x0005008e, + 0x00000011,0x0000012a,0x00000129,0x00000078,0x00060050,0x00000011,0x0000012b,0x00000078, + 0x00000078,0x00000078,0x00050083,0x00000011,0x0000012c,0x0000012b,0x0000012a,0x0007000c, + 0x00000011,0x0000012d,0x00000001,0x00000028,0x0000012c,0x00000122,0x00050088,0x00000011, + 0x0000012e,0x00000128,0x0000012d,0x0003003e,0x00000125,0x0000012e,0x0004003d,0x00000011, + 0x00000130,0x0000011d,0x0004003d,0x00000011,0x00000131,0x00000125,0x0007000c,0x00000011, + 0x00000132,0x00000001,0x00000025,0x00000130,0x00000131,0x0003003e,0x0000012f,0x00000132, + 0x00050041,0x00000007,0x00000134,0x0000012f,0x000000cf,0x0004003d,0x00000006,0x00000135, + 0x00000134,0x00050041,0x00000007,0x00000136,0x0000012f,0x000000d4,0x0004003d,0x00000006, + 0x00000137,0x00000136,0x0007000c,0x00000006,0x00000138,0x00000001,0x00000025,0x00000135, + 0x00000137,0x00050041,0x00000007,0x0000013a,0x0000012f,0x00000139,0x0004003d,0x00000006, + 0x0000013b,0x0000013a,0x0007000c,0x00000006,0x0000013c,0x00000001,0x00000025,0x00000138, + 0x0000013b,0x0008000c,0x00000006,0x0000013e,0x00000001,0x0000002b,0x0000013c,0x0000003f, + 0x0000013d,0x0004007f,0x00000006,0x0000013f,0x0000013e,0x0004003d,0x00000006,0x00000140, + 0x0000001d,0x0008000c,0x00000006,0x00000141,0x00000001,0x0000002b,0x00000140,0x0000003f, + 0x00000038,0x00050085,0x00000006,0x00000142,0x0000013f,0x00000141,0x0003003e,0x00000133, + 0x00000142,0x0004003d,0x00000011,0x00000144,0x00000018,0x0004003d,0x00000006,0x00000145, + 0x00000133,0x0004003d,0x00000011,0x00000146,0x00000019,0x0004003d,0x00000011,0x00000147, + 0x0000001a,0x00050081,0x00000011,0x00000148,0x00000146,0x00000147,0x0004003d,0x00000011, + 0x00000149,0x0000001b,0x00050081,0x00000011,0x0000014a,0x00000148,0x00000149,0x0004003d, + 0x00000011,0x0000014b,0x0000001c,0x00050081,0x00000011,0x0000014c,0x0000014a,0x0000014b, + 0x0005008e,0x00000011,0x0000014d,0x0000014c,0x00000145,0x00050081,0x00000011,0x0000014e, + 0x00000144,0x0000014d,0x0004003d,0x00000006,0x0000014f,0x00000133,0x00050085,0x00000006, + 0x00000150,0x00000078,0x0000014f,0x00050081,0x00000006,0x00000151,0x00000038,0x00000150, + 0x00060050,0x00000011,0x00000152,0x00000151,0x00000151,0x00000151,0x00050088,0x00000011, + 0x00000153,0x0000014e,0x00000152,0x0003003e,0x00000143,0x00000153,0x0004003d,0x00000011, + 0x00000154,0x00000143,0x0004003d,0x00000011,0x00000155,0x00000115,0x0004003d,0x00000011, + 0x00000156,0x00000119,0x0008000c,0x00000011,0x00000157,0x00000001,0x0000002b,0x00000154, + 0x00000155,0x00000156,0x000200fe,0x00000157,0x00010038,0x00050036,0x00000011,0x00000021, + 0x00000000,0x00000012,0x00030037,0x00000010,0x00000020,0x000200f8,0x00000022,0x0004003b, + 0x00000010,0x0000015a,0x00000007,0x0004003b,0x00000016,0x00000162,0x00000007,0x0004003b, + 0x00000007,0x00000163,0x00000007,0x0004003b,0x000000ab,0x00000164,0x00000007,0x0004003b, + 0x000000ab,0x0000016e,0x00000007,0x0004003b,0x00000007,0x00000176,0x00000007,0x0004003d, + 0x0000008b,0x0000015c,0x0000015b,0x00040064,0x0000008a,0x0000015d,0x0000015c,0x00050067, + 0x00000024,0x0000015e,0x0000015d,0x00000083,0x0004006f,0x0000000f,0x0000015f,0x0000015e, + 0x00050050,0x0000000f,0x00000160,0x0000003b,0x0000003b,0x00050088,0x0000000f,0x00000161, + 0x00000160,0x0000015f,0x0003003e,0x0000015a,0x00000161,0x0003003e,0x00000162,0x000000a9, + 0x0003003e,0x00000163,0x0000003f,0x0003003e,0x00000164,0x00000165,0x000200f9,0x00000166, + 0x000200f8,0x00000166,0x000400f6,0x00000168,0x00000169,0x00000000,0x000200f9,0x0000016a, + 0x000200f8,0x0000016a,0x0004003d,0x00000023,0x0000016b,0x00000164,0x000500b3,0x00000034, + 0x0000016d,0x0000016b,0x0000016c,0x000400fa,0x0000016d,0x00000167,0x00000168,0x000200f8, + 0x00000167,0x0003003e,0x0000016e,0x00000165,0x000200f9,0x0000016f,0x000200f8,0x0000016f, + 0x000400f6,0x00000171,0x00000172,0x00000000,0x000200f9,0x00000173,0x000200f8,0x00000173, + 0x0004003d,0x00000023,0x00000174,0x0000016e,0x000500b3,0x00000034,0x00000175,0x00000174, + 0x0000016c,0x000400fa,0x00000175,0x00000170,0x00000171,0x000200f8,0x00000170,0x0004003d, + 0x00000023,0x00000177,0x0000016e,0x0004003d,0x00000023,0x00000178,0x0000016e,0x00050084, + 0x00000023,0x00000179,0x00000177,0x00000178,0x0004003d,0x00000023,0x0000017a,0x00000164, + 0x0004003d,0x00000023,0x0000017b,0x00000164,0x00050084,0x00000023,0x0000017c,0x0000017a, + 0x0000017b,0x00050080,0x00000023,0x0000017d,0x00000179,0x0000017c,0x0004006f,0x00000006, + 0x0000017e,0x0000017d,0x0004007f,0x00000006,0x0000017f,0x0000017e,0x00050088,0x00000006, + 0x00000181,0x0000017f,0x00000180,0x0006000c,0x00000006,0x00000182,0x00000001,0x0000001b, + 0x00000181,0x0003003e,0x00000176,0x00000182,0x0004003d,0x00000006,0x00000183,0x00000176, + 0x0004003d,0x0000008b,0x00000184,0x0000015b,0x0004003d,0x0000000f,0x00000185,0x00000020, + 0x0004003d,0x00000023,0x00000186,0x0000016e,0x0004006f,0x00000006,0x00000187,0x00000186, + 0x0004003d,0x00000023,0x00000188,0x00000164,0x0004006f,0x00000006,0x00000189,0x00000188, + 0x00050050,0x0000000f,0x0000018a,0x00000187,0x00000189,0x0004003d,0x0000000f,0x0000018b, + 0x0000015a,0x00050085,0x0000000f,0x0000018c,0x0000018a,0x0000018b,0x00050081,0x0000000f, + 0x0000018d,0x00000185,0x0000018c,0x0008000c,0x0000000f,0x00000190,0x00000001,0x0000002b, + 0x0000018d,0x0000018e,0x0000018f,0x00070058,0x00000090,0x00000191,0x00000184,0x00000190, + 0x00000002,0x0000003f,0x0008004f,0x00000011,0x00000192,0x00000191,0x00000191,0x00000000, + 0x00000001,0x00000002,0x0005008e,0x00000011,0x00000193,0x00000192,0x00000183,0x0004003d, + 0x00000011,0x00000194,0x00000162,0x00050081,0x00000011,0x00000195,0x00000194,0x00000193, + 0x0003003e,0x00000162,0x00000195,0x0004003d,0x00000006,0x00000196,0x00000176,0x0004003d, + 0x00000006,0x00000197,0x00000163,0x00050081,0x00000006,0x00000198,0x00000197,0x00000196, + 0x0003003e,0x00000163,0x00000198,0x000200f9,0x00000172,0x000200f8,0x00000172,0x0004003d, + 0x00000023,0x00000199,0x0000016e,0x00050080,0x00000023,0x0000019a,0x00000199,0x000000ee, + 0x0003003e,0x0000016e,0x0000019a,0x000200f9,0x0000016f,0x000200f8,0x00000171,0x000200f9, + 0x00000169,0x000200f8,0x00000169,0x0004003d,0x00000023,0x0000019b,0x00000164,0x00050080, + 0x00000023,0x0000019c,0x0000019b,0x000000ee,0x0003003e,0x00000164,0x0000019c,0x000200f9, + 0x00000166,0x000200f8,0x00000168,0x0004003d,0x00000011,0x0000019d,0x00000162,0x0004003d, + 0x00000006,0x0000019e,0x00000163,0x00060050,0x00000011,0x0000019f,0x0000019e,0x0000019e, + 0x0000019e,0x00050088,0x00000011,0x000001a0,0x0000019d,0x0000019f,0x0005008e,0x00000011, + 0x000001a2,0x000001a0,0x000001a1,0x000200fe,0x000001a2,0x00010038,0x00050036,0x00000006, + 0x00000028,0x00000000,0x00000026,0x00030037,0x00000025,0x00000027,0x000200f8,0x00000029, + 0x00050041,0x000000ab,0x000001a7,0x00000027,0x000000cf,0x0004003d,0x00000023,0x000001a8, + 0x000001a7,0x0004006f,0x00000006,0x000001a9,0x000001a8,0x00050085,0x00000006,0x000001aa, + 0x000001a6,0x000001a9,0x00050041,0x000000ab,0x000001ac,0x00000027,0x000000d4,0x0004003d, + 0x00000023,0x000001ad,0x000001ac,0x0004006f,0x00000006,0x000001ae,0x000001ad,0x00050085, + 0x00000006,0x000001af,0x000001ab,0x000001ae,0x00050081,0x00000006,0x000001b0,0x000001aa, + 0x000001af,0x0006000c,0x00000006,0x000001b1,0x00000001,0x0000000a,0x000001b0,0x00050085, + 0x00000006,0x000001b2,0x000001a5,0x000001b1,0x0006000c,0x00000006,0x000001b3,0x00000001, + 0x0000000a,0x000001b2,0x00050083,0x00000006,0x000001b4,0x000001b3,0x00000049,0x00050088, + 0x00000006,0x000001b6,0x000001b4,0x000001b5,0x000200fe,0x000001b6,0x00010038,0x00050036, + 0x00000006,0x0000002e,0x00000000,0x0000002a,0x00030037,0x00000007,0x0000002b,0x00030037, + 0x00000007,0x0000002c,0x00030037,0x00000007,0x0000002d,0x000200f8,0x0000002f,0x0004003d, + 0x00000006,0x000001b9,0x0000002c,0x0004003d,0x00000006,0x000001ba,0x0000002c,0x00050081, + 0x00000006,0x000001bc,0x000001ba,0x000001bb,0x0004003d,0x00000006,0x000001bd,0x0000002b, + 0x0008000c,0x00000006,0x000001be,0x00000001,0x00000031,0x000001b9,0x000001bc,0x000001bd, + 0x00050083,0x00000006,0x000001bf,0x00000038,0x000001be,0x0004003d,0x00000006,0x000001c0, + 0x0000002d,0x00050083,0x00000006,0x000001c1,0x000001c0,0x000001bb,0x0004003d,0x00000006, + 0x000001c2,0x0000002d,0x0004003d,0x00000006,0x000001c3,0x0000002b,0x0008000c,0x00000006, + 0x000001c4,0x00000001,0x00000031,0x000001c1,0x000001c2,0x000001c3,0x0007000c,0x00000006, + 0x000001c5,0x00000001,0x00000028,0x000001bf,0x000001c4,0x000200fe,0x000001c5,0x00010038 }; diff --git a/gpu/vk/shaders/n64_3d.comp b/gpu/vk/shaders/n64_3d.comp new file mode 100644 index 0000000..1be1097 --- /dev/null +++ b/gpu/vk/shaders/n64_3d.comp @@ -0,0 +1,61 @@ +#version 450 +// (Triforce, 11-22) N64 Classic's 3D pass (n64-classic-mode-plan.md, step 2), in the gameplay upscale network's place +// (vk_draw.cpp taau_stand_in, n64_upscale): the 3D drawn the console's way. Two dispatches of this one program: +// +// pass 0, make: over the grid (240 lines and as wide as the picture's shape: 427 x 240 at 16:9). Each grid pixel is the +// mean of its footprint of the input, 4 x 4 bilinear taps (8 x 8 texels: a 3D at full size at 1440 is 6 x 6 a pixel), +// in linear light, kept at the look's colour depth with the ordered dither (n64_common.glsl), into `grid_img`. +// pass 1, show: over the output, at the picture's size. Each pixel takes its grid row whole and a place between two +// grid pixels along it: linear along the line, as the console's video chip resampled it, hard between lines. +// +// The averaging stands in for the video chip's edge anti-aliasing and its divot filter: edges come out smooth with no +// single-pixel gaps. The input is what the network samples, the square root of the tone mapped scene (as +// taau_upscale.comp reads it); the output is the network's, linear, into its B10G11R11 picture, before the HUD. +#extension GL_GOOGLE_include_directive : require +#include "n64_common.glsl" + +layout(local_size_x = 8, local_size_y = 8) in; +layout(binding = 0) uniform sampler2D src; +layout(binding = 1, rgba16f) uniform image2D grid_img; +layout(binding = 2, r11f_g11f_b10f) uniform writeonly image2D dst; +layout(push_constant) uniform P { + ivec2 grid; // the grid's size + ivec2 size; // the output's + int pass; // 0 make, 1 show + int bits; // bits a channel, 0 full colour + float dither; // the dither's strength, 0 to 1 +} pc; + +void make(ivec2 g) { + vec3 sum = vec3(0.0); + for (int j = 0; j < 4; j++) + for (int i = 0; i < 4; i++) { + const vec2 uv = (vec2(g) + (vec2(float(i), float(j)) + 0.5) / 4.0) / vec2(pc.grid); + const vec3 s = textureLod(src, uv, 0.0).rgb; + vec3 c = s * s; + if (any(isnan(c)) || any(isinf(c))) c = vec3(0.0); // (a frame's blown-up texel: none of its light) + sum += c; + } + const vec3 c = sum / 16.0; + imageStore(grid_img, g, vec4(n64_keep(c.r, pc.bits, pc.dither, g.x, g.y), n64_keep(c.g, pc.bits, pc.dither, g.x, g.y), + n64_keep(c.b, pc.bits, pc.dither, g.x, g.y), 1.0)); +} + +void show(ivec2 o) { + const int row = n64_row(o.y, pc.grid.y, pc.size.y); + const float gx = n64_column(o.x, pc.grid.x, pc.size.x); + const int x0 = int(floor(gx)); + const float t = gx - float(x0); + const vec3 a = imageLoad(grid_img, ivec2(clamp(x0, 0, pc.grid.x - 1), row)).rgb; + const vec3 b = imageLoad(grid_img, ivec2(clamp(x0 + 1, 0, pc.grid.x - 1), row)).rgb; + imageStore(dst, o, vec4(mix(a, b, t), 1.0)); +} + +void main() { + const ivec2 p = ivec2(gl_GlobalInvocationID.xy); + if (pc.pass == 0) { + if (all(lessThan(p, pc.grid))) make(p); + } else if (all(lessThan(p, pc.size))) { + show(p); + } +} diff --git a/gpu/vk/shaders/n64_3d_comp_spv.h b/gpu/vk/shaders/n64_3d_comp_spv.h new file mode 100644 index 0000000..328cbbd --- /dev/null +++ b/gpu/vk/shaders/n64_3d_comp_spv.h @@ -0,0 +1,374 @@ +// n64_3d.comp + n64_common.glsl sha256 ff1a301858e3f8f11d425cc4a727daacb316ad2d25a422f20fd8a23070c6ef34 (tests/test_n64_3d.py --write: glslangValidator -V --target-env vulkan1.2 --vn N64_3D_COMP_SPV) + // 1116.6.0 + #pragma once +const uint32_t N64_3D_COMP_SPV[] = { + 0x07230203,0x00010500,0x0008000b,0x000001f4,0x00000000,0x00020011,0x00000001,0x00020011, + 0x00000031,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e, + 0x00000000,0x00000001,0x000a000f,0x00000005,0x00000004,0x6e69616d,0x00000000,0x00000123, + 0x0000012d,0x00000151,0x000001c3,0x000001d2,0x00060010,0x00000004,0x00000011,0x00000008, + 0x00000008,0x00000001,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f, + 0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004, + 0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005, + 0x00000004,0x6e69616d,0x00000000,0x00070005,0x0000000b,0x5f34366e,0x65796162,0x69283272, + 0x31693b31,0x0000003b,0x00030005,0x00000009,0x00000078,0x00030005,0x0000000a,0x00000079, + 0x00070005,0x0000000f,0x5f34366e,0x65796162,0x69283472,0x31693b31,0x0000003b,0x00030005, + 0x0000000d,0x00000078,0x00030005,0x0000000e,0x00000079,0x00090005,0x00000015,0x5f34366e, + 0x68746964,0x6f5f7265,0x65736666,0x31692874,0x3b31693b,0x00000000,0x00030005,0x00000013, + 0x00000078,0x00030005,0x00000014,0x00000079,0x000a0005,0x0000001e,0x5f34366e,0x6e617571, + 0x657a6974,0x3b316628,0x663b3169,0x31693b31,0x3b31693b,0x00000000,0x00030005,0x00000019, + 0x00000076,0x00040005,0x0000001a,0x73746962,0x00000000,0x00050005,0x0000001b,0x65727473, + 0x6874676e,0x00000000,0x00030005,0x0000001c,0x00000078,0x00030005,0x0000001d,0x00000079, + 0x00060005,0x00000022,0x5f34366e,0x6f636e65,0x66286564,0x00003b31,0x00030005,0x00000021, + 0x00000076,0x00060005,0x00000025,0x5f34366e,0x6f636564,0x66286564,0x00003b31,0x00030005, + 0x00000024,0x00000076,0x00090005,0x0000002c,0x5f34366e,0x7065656b,0x3b316628,0x663b3169, + 0x31693b31,0x3b31693b,0x00000000,0x00030005,0x00000027,0x00000076,0x00040005,0x00000028, + 0x73746962,0x00000000,0x00050005,0x00000029,0x65727473,0x6874676e,0x00000000,0x00030005, + 0x0000002a,0x00000078,0x00030005,0x0000002b,0x00000079,0x00070005,0x00000032,0x5f34366e, + 0x28776f72,0x693b3169,0x31693b31,0x0000003b,0x00030005,0x0000002f,0x00000079,0x00040005, + 0x00000030,0x64697267,0x0000685f,0x00040005,0x00000031,0x657a6973,0x0000685f,0x00080005, + 0x00000038,0x5f34366e,0x756c6f63,0x69286e6d,0x31693b31,0x3b31693b,0x00000000,0x00030005, + 0x00000035,0x00000078,0x00040005,0x00000036,0x64697267,0x0000775f,0x00040005,0x00000037, + 0x657a6973,0x0000775f,0x00050005,0x0000003e,0x656b616d,0x32697628,0x0000003b,0x00030005, + 0x0000003d,0x00000067,0x00050005,0x00000041,0x776f6873,0x32697628,0x0000003b,0x00030005, + 0x00000040,0x0000006f,0x00040005,0x0000004f,0x61726170,0x0000006d,0x00040005,0x00000051, + 0x61726170,0x0000006d,0x00040005,0x0000005a,0x61726170,0x0000006d,0x00040005,0x0000005b, + 0x61726170,0x0000006d,0x00040005,0x00000065,0x61726170,0x0000006d,0x00040005,0x00000066, + 0x61726170,0x0000006d,0x00040005,0x00000078,0x6576656c,0x0000736c,0x00030005,0x0000007d, + 0x00000063,0x00030005,0x00000082,0x00000071,0x00040005,0x00000087,0x61726170,0x0000006d, + 0x00040005,0x00000089,0x61726170,0x0000006d,0x00040005,0x000000c8,0x61726170,0x0000006d, + 0x00040005,0x000000ca,0x61726170,0x0000006d,0x00040005,0x000000cb,0x61726170,0x0000006d, + 0x00040005,0x000000cd,0x61726170,0x0000006d,0x00040005,0x000000cf,0x61726170,0x0000006d, + 0x00040005,0x000000d1,0x61726170,0x0000006d,0x00040005,0x000000d4,0x61726170,0x0000006d, + 0x00030005,0x000000d8,0x00000072,0x00030005,0x000000ff,0x006d7573,0x00030005,0x00000101, + 0x0000006a,0x00030005,0x00000109,0x00000069,0x00030005,0x00000113,0x00007675,0x00030005, + 0x00000121,0x00000050,0x00050006,0x00000121,0x00000000,0x64697267,0x00000000,0x00050006, + 0x00000121,0x00000001,0x657a6973,0x00000000,0x00050006,0x00000121,0x00000002,0x73736170, + 0x00000000,0x00050006,0x00000121,0x00000003,0x73746962,0x00000000,0x00050006,0x00000121, + 0x00000004,0x68746964,0x00007265,0x00030005,0x00000123,0x00006370,0x00030005,0x00000129, + 0x00000073,0x00030005,0x0000012d,0x00637273,0x00030005,0x00000133,0x00000063,0x00030005, + 0x0000014b,0x00000063,0x00050005,0x00000151,0x64697267,0x676d695f,0x00000000,0x00040005, + 0x00000154,0x61726170,0x0000006d,0x00040005,0x00000159,0x61726170,0x0000006d,0x00040005, + 0x0000015d,0x61726170,0x0000006d,0x00040005,0x00000161,0x61726170,0x0000006d,0x00040005, + 0x00000164,0x61726170,0x0000006d,0x00040005,0x00000169,0x61726170,0x0000006d,0x00040005, + 0x0000016c,0x61726170,0x0000006d,0x00040005,0x0000016f,0x61726170,0x0000006d,0x00040005, + 0x00000172,0x61726170,0x0000006d,0x00040005,0x00000175,0x61726170,0x0000006d,0x00040005, + 0x00000179,0x61726170,0x0000006d,0x00040005,0x0000017d,0x61726170,0x0000006d,0x00040005, + 0x00000180,0x61726170,0x0000006d,0x00040005,0x00000183,0x61726170,0x0000006d,0x00040005, + 0x00000186,0x61726170,0x0000006d,0x00030005,0x0000018b,0x00776f72,0x00040005,0x0000018c, + 0x61726170,0x0000006d,0x00040005,0x0000018f,0x61726170,0x0000006d,0x00040005,0x00000192, + 0x61726170,0x0000006d,0x00030005,0x00000196,0x00007867,0x00040005,0x00000197,0x61726170, + 0x0000006d,0x00040005,0x0000019a,0x61726170,0x0000006d,0x00040005,0x0000019d,0x61726170, + 0x0000006d,0x00030005,0x000001a1,0x00003078,0x00030005,0x000001a5,0x00000074,0x00030005, + 0x000001aa,0x00000061,0x00030005,0x000001b5,0x00000062,0x00030005,0x000001c3,0x00747364, + 0x00030005,0x000001cf,0x00000070,0x00080005,0x000001d2,0x475f6c67,0x61626f6c,0x766e496c, + 0x7461636f,0x496e6f69,0x00000044,0x00040005,0x000001e4,0x61726170,0x0000006d,0x00040005, + 0x000001ef,0x61726170,0x0000006d,0x00030047,0x00000121,0x00000002,0x00050048,0x00000121, + 0x00000000,0x00000023,0x00000000,0x00050048,0x00000121,0x00000001,0x00000023,0x00000008, + 0x00050048,0x00000121,0x00000002,0x00000023,0x00000010,0x00050048,0x00000121,0x00000003, + 0x00000023,0x00000014,0x00050048,0x00000121,0x00000004,0x00000023,0x00000018,0x00040047, + 0x0000012d,0x00000021,0x00000000,0x00040047,0x0000012d,0x00000022,0x00000000,0x00040047, + 0x00000151,0x00000021,0x00000001,0x00040047,0x00000151,0x00000022,0x00000000,0x00030047, + 0x000001c3,0x00000019,0x00040047,0x000001c3,0x00000021,0x00000002,0x00040047,0x000001c3, + 0x00000022,0x00000000,0x00040047,0x000001d2,0x0000000b,0x0000001c,0x00040047,0x000001f3, + 0x0000000b,0x00000019,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00040015, + 0x00000006,0x00000020,0x00000001,0x00040020,0x00000007,0x00000007,0x00000006,0x00050021, + 0x00000008,0x00000006,0x00000007,0x00000007,0x00030016,0x00000011,0x00000020,0x00050021, + 0x00000012,0x00000011,0x00000007,0x00000007,0x00040020,0x00000017,0x00000007,0x00000011, + 0x00080021,0x00000018,0x00000011,0x00000017,0x00000007,0x00000017,0x00000007,0x00000007, + 0x00040021,0x00000020,0x00000011,0x00000017,0x00060021,0x0000002e,0x00000006,0x00000007, + 0x00000007,0x00000007,0x00060021,0x00000034,0x00000011,0x00000007,0x00000007,0x00000007, + 0x00040017,0x0000003a,0x00000006,0x00000002,0x00040020,0x0000003b,0x00000007,0x0000003a, + 0x00040021,0x0000003c,0x00000002,0x0000003b,0x0004002b,0x00000006,0x00000046,0x00000001, + 0x0004002b,0x00000006,0x00000048,0x00000002,0x0004002b,0x00000006,0x00000054,0x00000004, + 0x0004002b,0x00000006,0x00000061,0x00000003,0x0004002b,0x00000011,0x00000069,0x3f000000, + 0x0004002b,0x00000011,0x0000006b,0x41800000,0x0004002b,0x00000006,0x00000071,0x00000000, + 0x00020014,0x00000072,0x0004002b,0x00000011,0x0000007f,0x00000000,0x0004002b,0x00000011, + 0x00000080,0x3f800000,0x0004002b,0x00000011,0x00000097,0x3b4d2e1c,0x0004002b,0x00000011, + 0x0000009d,0x414eb852,0x0004002b,0x00000011,0x000000a0,0x3f870a3d,0x0004002b,0x00000011, + 0x000000a2,0x3ed55555,0x0004002b,0x00000011,0x000000a5,0x3d6147ae,0x0004002b,0x00000011, + 0x000000ab,0x3d25aee6,0x0004002b,0x00000011,0x000000b6,0x4019999a,0x00040017,0x000000fd, + 0x00000011,0x00000003,0x00040020,0x000000fe,0x00000007,0x000000fd,0x0006002c,0x000000fd, + 0x00000100,0x0000007f,0x0000007f,0x0000007f,0x00040017,0x00000111,0x00000011,0x00000002, + 0x00040020,0x00000112,0x00000007,0x00000111,0x0004002b,0x00000011,0x0000011d,0x40800000, + 0x0007001e,0x00000121,0x0000003a,0x0000003a,0x00000006,0x00000006,0x00000011,0x00040020, + 0x00000122,0x00000009,0x00000121,0x0004003b,0x00000122,0x00000123,0x00000009,0x00040020, + 0x00000124,0x00000009,0x0000003a,0x00090019,0x0000012a,0x00000011,0x00000001,0x00000000, + 0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x0000012b,0x0000012a,0x00040020, + 0x0000012c,0x00000000,0x0000012b,0x0004003b,0x0000012c,0x0000012d,0x00000000,0x00040017, + 0x00000130,0x00000011,0x00000004,0x00040017,0x00000138,0x00000072,0x00000003,0x00090019, + 0x0000014f,0x00000011,0x00000001,0x00000000,0x00000000,0x00000000,0x00000002,0x00000002, + 0x00040020,0x00000150,0x00000000,0x0000014f,0x0004003b,0x00000150,0x00000151,0x00000000, + 0x00040015,0x00000155,0x00000020,0x00000000,0x0004002b,0x00000155,0x00000156,0x00000000, + 0x00040020,0x0000015a,0x00000009,0x00000006,0x00040020,0x0000015e,0x00000009,0x00000011, + 0x0004002b,0x00000155,0x00000165,0x00000001,0x0004002b,0x00000155,0x0000017a,0x00000002, + 0x00090019,0x000001c1,0x00000011,0x00000001,0x00000000,0x00000000,0x00000000,0x00000002, + 0x00000008,0x00040020,0x000001c2,0x00000000,0x000001c1,0x0004003b,0x000001c2,0x000001c3, + 0x00000000,0x00040017,0x000001d0,0x00000155,0x00000003,0x00040020,0x000001d1,0x00000001, + 0x000001d0,0x0004003b,0x000001d1,0x000001d2,0x00000001,0x00040017,0x000001d3,0x00000155, + 0x00000002,0x00040017,0x000001df,0x00000072,0x00000002,0x0004002b,0x00000155,0x000001f2, + 0x00000008,0x0006002c,0x000001d0,0x000001f3,0x000001f2,0x000001f2,0x00000165,0x00050036, + 0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000003b, + 0x000001cf,0x00000007,0x0004003b,0x0000003b,0x000001e4,0x00000007,0x0004003b,0x0000003b, + 0x000001ef,0x00000007,0x0004003d,0x000001d0,0x000001d4,0x000001d2,0x0007004f,0x000001d3, + 0x000001d5,0x000001d4,0x000001d4,0x00000000,0x00000001,0x0004007c,0x0000003a,0x000001d6, + 0x000001d5,0x0003003e,0x000001cf,0x000001d6,0x00050041,0x0000015a,0x000001d7,0x00000123, + 0x00000048,0x0004003d,0x00000006,0x000001d8,0x000001d7,0x000500aa,0x00000072,0x000001d9, + 0x000001d8,0x00000071,0x000300f7,0x000001db,0x00000000,0x000400fa,0x000001d9,0x000001da, + 0x000001e7,0x000200f8,0x000001da,0x0004003d,0x0000003a,0x000001dc,0x000001cf,0x00050041, + 0x00000124,0x000001dd,0x00000123,0x00000071,0x0004003d,0x0000003a,0x000001de,0x000001dd, + 0x000500b1,0x000001df,0x000001e0,0x000001dc,0x000001de,0x0004009b,0x00000072,0x000001e1, + 0x000001e0,0x000300f7,0x000001e3,0x00000000,0x000400fa,0x000001e1,0x000001e2,0x000001e3, + 0x000200f8,0x000001e2,0x0004003d,0x0000003a,0x000001e5,0x000001cf,0x0003003e,0x000001e4, + 0x000001e5,0x00050039,0x00000002,0x000001e6,0x0000003e,0x000001e4,0x000200f9,0x000001e3, + 0x000200f8,0x000001e3,0x000200f9,0x000001db,0x000200f8,0x000001e7,0x0004003d,0x0000003a, + 0x000001e8,0x000001cf,0x00050041,0x00000124,0x000001e9,0x00000123,0x00000046,0x0004003d, + 0x0000003a,0x000001ea,0x000001e9,0x000500b1,0x000001df,0x000001eb,0x000001e8,0x000001ea, + 0x0004009b,0x00000072,0x000001ec,0x000001eb,0x000300f7,0x000001ee,0x00000000,0x000400fa, + 0x000001ec,0x000001ed,0x000001ee,0x000200f8,0x000001ed,0x0004003d,0x0000003a,0x000001f0, + 0x000001cf,0x0003003e,0x000001ef,0x000001f0,0x00050039,0x00000002,0x000001f1,0x00000041, + 0x000001ef,0x000200f9,0x000001ee,0x000200f8,0x000001ee,0x000200f9,0x000001db,0x000200f8, + 0x000001db,0x000100fd,0x00010038,0x00050036,0x00000006,0x0000000b,0x00000000,0x00000008, + 0x00030037,0x00000007,0x00000009,0x00030037,0x00000007,0x0000000a,0x000200f8,0x0000000c, + 0x0004003d,0x00000006,0x00000043,0x00000009,0x0004003d,0x00000006,0x00000044,0x0000000a, + 0x000500c6,0x00000006,0x00000045,0x00000043,0x00000044,0x000500c7,0x00000006,0x00000047, + 0x00000045,0x00000046,0x00050084,0x00000006,0x00000049,0x00000047,0x00000048,0x0004003d, + 0x00000006,0x0000004a,0x0000000a,0x000500c7,0x00000006,0x0000004b,0x0000004a,0x00000046, + 0x00050080,0x00000006,0x0000004c,0x00000049,0x0000004b,0x000200fe,0x0000004c,0x00010038, + 0x00050036,0x00000006,0x0000000f,0x00000000,0x00000008,0x00030037,0x00000007,0x0000000d, + 0x00030037,0x00000007,0x0000000e,0x000200f8,0x00000010,0x0004003b,0x00000007,0x0000004f, + 0x00000007,0x0004003b,0x00000007,0x00000051,0x00000007,0x0004003b,0x00000007,0x0000005a, + 0x00000007,0x0004003b,0x00000007,0x0000005b,0x00000007,0x0004003d,0x00000006,0x00000050, + 0x0000000d,0x0003003e,0x0000004f,0x00000050,0x0004003d,0x00000006,0x00000052,0x0000000e, + 0x0003003e,0x00000051,0x00000052,0x00060039,0x00000006,0x00000053,0x0000000b,0x0000004f, + 0x00000051,0x00050084,0x00000006,0x00000055,0x00000053,0x00000054,0x0004003d,0x00000006, + 0x00000056,0x0000000d,0x000500c3,0x00000006,0x00000057,0x00000056,0x00000046,0x0004003d, + 0x00000006,0x00000058,0x0000000e,0x000500c3,0x00000006,0x00000059,0x00000058,0x00000046, + 0x0003003e,0x0000005a,0x00000057,0x0003003e,0x0000005b,0x00000059,0x00060039,0x00000006, + 0x0000005c,0x0000000b,0x0000005a,0x0000005b,0x00050080,0x00000006,0x0000005d,0x00000055, + 0x0000005c,0x000200fe,0x0000005d,0x00010038,0x00050036,0x00000011,0x00000015,0x00000000, + 0x00000012,0x00030037,0x00000007,0x00000013,0x00030037,0x00000007,0x00000014,0x000200f8, + 0x00000016,0x0004003b,0x00000007,0x00000065,0x00000007,0x0004003b,0x00000007,0x00000066, + 0x00000007,0x0004003d,0x00000006,0x00000060,0x00000013,0x000500c7,0x00000006,0x00000062, + 0x00000060,0x00000061,0x0004003d,0x00000006,0x00000063,0x00000014,0x000500c7,0x00000006, + 0x00000064,0x00000063,0x00000061,0x0003003e,0x00000065,0x00000062,0x0003003e,0x00000066, + 0x00000064,0x00060039,0x00000006,0x00000067,0x0000000f,0x00000065,0x00000066,0x0004006f, + 0x00000011,0x00000068,0x00000067,0x00050081,0x00000011,0x0000006a,0x00000068,0x00000069, + 0x00050088,0x00000011,0x0000006c,0x0000006a,0x0000006b,0x00050083,0x00000011,0x0000006d, + 0x0000006c,0x00000069,0x000200fe,0x0000006d,0x00010038,0x00050036,0x00000011,0x0000001e, + 0x00000000,0x00000018,0x00030037,0x00000017,0x00000019,0x00030037,0x00000007,0x0000001a, + 0x00030037,0x00000017,0x0000001b,0x00030037,0x00000007,0x0000001c,0x00030037,0x00000007, + 0x0000001d,0x000200f8,0x0000001f,0x0004003b,0x00000017,0x00000078,0x00000007,0x0004003b, + 0x00000017,0x0000007d,0x00000007,0x0004003b,0x00000017,0x00000082,0x00000007,0x0004003b, + 0x00000007,0x00000087,0x00000007,0x0004003b,0x00000007,0x00000089,0x00000007,0x0004003d, + 0x00000006,0x00000070,0x0000001a,0x000500b3,0x00000072,0x00000073,0x00000070,0x00000071, + 0x000300f7,0x00000075,0x00000000,0x000400fa,0x00000073,0x00000074,0x00000075,0x000200f8, + 0x00000074,0x0004003d,0x00000011,0x00000076,0x00000019,0x000200fe,0x00000076,0x000200f8, + 0x00000075,0x0004003d,0x00000006,0x00000079,0x0000001a,0x000500c4,0x00000006,0x0000007a, + 0x00000046,0x00000079,0x00050082,0x00000006,0x0000007b,0x0000007a,0x00000046,0x0004006f, + 0x00000011,0x0000007c,0x0000007b,0x0003003e,0x00000078,0x0000007c,0x0004003d,0x00000011, + 0x0000007e,0x00000019,0x0008000c,0x00000011,0x00000081,0x00000001,0x0000002b,0x0000007e, + 0x0000007f,0x00000080,0x0003003e,0x0000007d,0x00000081,0x0004003d,0x00000011,0x00000083, + 0x0000007d,0x0004003d,0x00000011,0x00000084,0x00000078,0x00050085,0x00000011,0x00000085, + 0x00000083,0x00000084,0x00050081,0x00000011,0x00000086,0x00000085,0x00000069,0x0004003d, + 0x00000006,0x00000088,0x0000001c,0x0003003e,0x00000087,0x00000088,0x0004003d,0x00000006, + 0x0000008a,0x0000001d,0x0003003e,0x00000089,0x0000008a,0x00060039,0x00000011,0x0000008b, + 0x00000015,0x00000087,0x00000089,0x0004003d,0x00000011,0x0000008c,0x0000001b,0x00050085, + 0x00000011,0x0000008d,0x0000008b,0x0000008c,0x00050081,0x00000011,0x0000008e,0x00000086, + 0x0000008d,0x0006000c,0x00000011,0x0000008f,0x00000001,0x00000008,0x0000008e,0x0004003d, + 0x00000011,0x00000090,0x00000078,0x00050088,0x00000011,0x00000091,0x0000008f,0x00000090, + 0x0003003e,0x00000082,0x00000091,0x0004003d,0x00000011,0x00000092,0x00000082,0x0008000c, + 0x00000011,0x00000093,0x00000001,0x0000002b,0x00000092,0x0000007f,0x00000080,0x000200fe, + 0x00000093,0x00010038,0x00050036,0x00000011,0x00000022,0x00000000,0x00000020,0x00030037, + 0x00000017,0x00000021,0x000200f8,0x00000023,0x0004003b,0x00000017,0x00000099,0x00000007, + 0x0004003d,0x00000011,0x00000096,0x00000021,0x000500bc,0x00000072,0x00000098,0x00000096, + 0x00000097,0x000300f7,0x0000009b,0x00000000,0x000400fa,0x00000098,0x0000009a,0x0000009f, + 0x000200f8,0x0000009a,0x0004003d,0x00000011,0x0000009c,0x00000021,0x00050085,0x00000011, + 0x0000009e,0x0000009c,0x0000009d,0x0003003e,0x00000099,0x0000009e,0x000200f9,0x0000009b, + 0x000200f8,0x0000009f,0x0004003d,0x00000011,0x000000a1,0x00000021,0x0007000c,0x00000011, + 0x000000a3,0x00000001,0x0000001a,0x000000a1,0x000000a2,0x00050085,0x00000011,0x000000a4, + 0x000000a0,0x000000a3,0x00050083,0x00000011,0x000000a6,0x000000a4,0x000000a5,0x0003003e, + 0x00000099,0x000000a6,0x000200f9,0x0000009b,0x000200f8,0x0000009b,0x0004003d,0x00000011, + 0x000000a7,0x00000099,0x000200fe,0x000000a7,0x00010038,0x00050036,0x00000011,0x00000025, + 0x00000000,0x00000020,0x00030037,0x00000017,0x00000024,0x000200f8,0x00000026,0x0004003b, + 0x00000017,0x000000ad,0x00000007,0x0004003d,0x00000011,0x000000aa,0x00000024,0x000500bc, + 0x00000072,0x000000ac,0x000000aa,0x000000ab,0x000300f7,0x000000af,0x00000000,0x000400fa, + 0x000000ac,0x000000ae,0x000000b2,0x000200f8,0x000000ae,0x0004003d,0x00000011,0x000000b0, + 0x00000024,0x00050088,0x00000011,0x000000b1,0x000000b0,0x0000009d,0x0003003e,0x000000ad, + 0x000000b1,0x000200f9,0x000000af,0x000200f8,0x000000b2,0x0004003d,0x00000011,0x000000b3, + 0x00000024,0x00050081,0x00000011,0x000000b4,0x000000b3,0x000000a5,0x00050088,0x00000011, + 0x000000b5,0x000000b4,0x000000a0,0x0007000c,0x00000011,0x000000b7,0x00000001,0x0000001a, + 0x000000b5,0x000000b6,0x0003003e,0x000000ad,0x000000b7,0x000200f9,0x000000af,0x000200f8, + 0x000000af,0x0004003d,0x00000011,0x000000b8,0x000000ad,0x000200fe,0x000000b8,0x00010038, + 0x00050036,0x00000011,0x0000002c,0x00000000,0x00000018,0x00030037,0x00000017,0x00000027, + 0x00030037,0x00000007,0x00000028,0x00030037,0x00000017,0x00000029,0x00030037,0x00000007, + 0x0000002a,0x00030037,0x00000007,0x0000002b,0x000200f8,0x0000002d,0x0004003b,0x00000017, + 0x000000c8,0x00000007,0x0004003b,0x00000017,0x000000ca,0x00000007,0x0004003b,0x00000007, + 0x000000cb,0x00000007,0x0004003b,0x00000017,0x000000cd,0x00000007,0x0004003b,0x00000007, + 0x000000cf,0x00000007,0x0004003b,0x00000007,0x000000d1,0x00000007,0x0004003b,0x00000017, + 0x000000d4,0x00000007,0x0004003d,0x00000006,0x000000bb,0x00000028,0x000500b3,0x00000072, + 0x000000bc,0x000000bb,0x00000071,0x0004003d,0x00000011,0x000000bd,0x00000027,0x000500be, + 0x00000072,0x000000be,0x000000bd,0x00000080,0x000500a6,0x00000072,0x000000bf,0x000000bc, + 0x000000be,0x000300f7,0x000000c1,0x00000000,0x000400fa,0x000000bf,0x000000c0,0x000000c1, + 0x000200f8,0x000000c0,0x0004003d,0x00000011,0x000000c2,0x00000027,0x000200fe,0x000000c2, + 0x000200f8,0x000000c1,0x0004003d,0x00000011,0x000000c4,0x00000027,0x000500ba,0x00000072, + 0x000000c5,0x000000c4,0x0000007f,0x0004003d,0x00000011,0x000000c6,0x00000027,0x000600a9, + 0x00000011,0x000000c7,0x000000c5,0x000000c6,0x0000007f,0x0003003e,0x000000c8,0x000000c7, + 0x00050039,0x00000011,0x000000c9,0x00000022,0x000000c8,0x0003003e,0x000000ca,0x000000c9, + 0x0004003d,0x00000006,0x000000cc,0x00000028,0x0003003e,0x000000cb,0x000000cc,0x0004003d, + 0x00000011,0x000000ce,0x00000029,0x0003003e,0x000000cd,0x000000ce,0x0004003d,0x00000006, + 0x000000d0,0x0000002a,0x0003003e,0x000000cf,0x000000d0,0x0004003d,0x00000006,0x000000d2, + 0x0000002b,0x0003003e,0x000000d1,0x000000d2,0x00090039,0x00000011,0x000000d3,0x0000001e, + 0x000000ca,0x000000cb,0x000000cd,0x000000cf,0x000000d1,0x0003003e,0x000000d4,0x000000d3, + 0x00050039,0x00000011,0x000000d5,0x00000025,0x000000d4,0x000200fe,0x000000d5,0x00010038, + 0x00050036,0x00000006,0x00000032,0x00000000,0x0000002e,0x00030037,0x00000007,0x0000002f, + 0x00030037,0x00000007,0x00000030,0x00030037,0x00000007,0x00000031,0x000200f8,0x00000033, + 0x0004003b,0x00000007,0x000000d8,0x00000007,0x0004003b,0x00000007,0x000000e7,0x00000007, + 0x0004003d,0x00000006,0x000000d9,0x0000002f,0x0004006f,0x00000011,0x000000da,0x000000d9, + 0x00050081,0x00000011,0x000000db,0x000000da,0x00000069,0x0004003d,0x00000006,0x000000dc, + 0x00000030,0x0004006f,0x00000011,0x000000dd,0x000000dc,0x00050085,0x00000011,0x000000de, + 0x000000db,0x000000dd,0x0004003d,0x00000006,0x000000df,0x00000031,0x0004006f,0x00000011, + 0x000000e0,0x000000df,0x00050088,0x00000011,0x000000e1,0x000000de,0x000000e0,0x0004006e, + 0x00000006,0x000000e2,0x000000e1,0x0003003e,0x000000d8,0x000000e2,0x0004003d,0x00000006, + 0x000000e3,0x000000d8,0x0004003d,0x00000006,0x000000e4,0x00000030,0x00050082,0x00000006, + 0x000000e5,0x000000e4,0x00000046,0x000500b1,0x00000072,0x000000e6,0x000000e3,0x000000e5, + 0x000300f7,0x000000e9,0x00000000,0x000400fa,0x000000e6,0x000000e8,0x000000eb,0x000200f8, + 0x000000e8,0x0004003d,0x00000006,0x000000ea,0x000000d8,0x0003003e,0x000000e7,0x000000ea, + 0x000200f9,0x000000e9,0x000200f8,0x000000eb,0x0004003d,0x00000006,0x000000ec,0x00000030, + 0x00050082,0x00000006,0x000000ed,0x000000ec,0x00000046,0x0003003e,0x000000e7,0x000000ed, + 0x000200f9,0x000000e9,0x000200f8,0x000000e9,0x0004003d,0x00000006,0x000000ee,0x000000e7, + 0x000200fe,0x000000ee,0x00010038,0x00050036,0x00000011,0x00000038,0x00000000,0x00000034, + 0x00030037,0x00000007,0x00000035,0x00030037,0x00000007,0x00000036,0x00030037,0x00000007, + 0x00000037,0x000200f8,0x00000039,0x0004003d,0x00000006,0x000000f1,0x00000035,0x0004006f, + 0x00000011,0x000000f2,0x000000f1,0x00050081,0x00000011,0x000000f3,0x000000f2,0x00000069, + 0x0004003d,0x00000006,0x000000f4,0x00000036,0x0004006f,0x00000011,0x000000f5,0x000000f4, + 0x00050085,0x00000011,0x000000f6,0x000000f3,0x000000f5,0x0004003d,0x00000006,0x000000f7, + 0x00000037,0x0004006f,0x00000011,0x000000f8,0x000000f7,0x00050088,0x00000011,0x000000f9, + 0x000000f6,0x000000f8,0x00050083,0x00000011,0x000000fa,0x000000f9,0x00000069,0x000200fe, + 0x000000fa,0x00010038,0x00050036,0x00000002,0x0000003e,0x00000000,0x0000003c,0x00030037, + 0x0000003b,0x0000003d,0x000200f8,0x0000003f,0x0004003b,0x000000fe,0x000000ff,0x00000007, + 0x0004003b,0x00000007,0x00000101,0x00000007,0x0004003b,0x00000007,0x00000109,0x00000007, + 0x0004003b,0x00000112,0x00000113,0x00000007,0x0004003b,0x000000fe,0x00000129,0x00000007, + 0x0004003b,0x000000fe,0x00000133,0x00000007,0x0004003b,0x000000fe,0x0000014b,0x00000007, + 0x0004003b,0x00000017,0x00000154,0x00000007,0x0004003b,0x00000007,0x00000159,0x00000007, + 0x0004003b,0x00000017,0x0000015d,0x00000007,0x0004003b,0x00000007,0x00000161,0x00000007, + 0x0004003b,0x00000007,0x00000164,0x00000007,0x0004003b,0x00000017,0x00000169,0x00000007, + 0x0004003b,0x00000007,0x0000016c,0x00000007,0x0004003b,0x00000017,0x0000016f,0x00000007, + 0x0004003b,0x00000007,0x00000172,0x00000007,0x0004003b,0x00000007,0x00000175,0x00000007, + 0x0004003b,0x00000017,0x00000179,0x00000007,0x0004003b,0x00000007,0x0000017d,0x00000007, + 0x0004003b,0x00000017,0x00000180,0x00000007,0x0004003b,0x00000007,0x00000183,0x00000007, + 0x0004003b,0x00000007,0x00000186,0x00000007,0x0003003e,0x000000ff,0x00000100,0x0003003e, + 0x00000101,0x00000071,0x000200f9,0x00000102,0x000200f8,0x00000102,0x000400f6,0x00000104, + 0x00000105,0x00000000,0x000200f9,0x00000106,0x000200f8,0x00000106,0x0004003d,0x00000006, + 0x00000107,0x00000101,0x000500b1,0x00000072,0x00000108,0x00000107,0x00000054,0x000400fa, + 0x00000108,0x00000103,0x00000104,0x000200f8,0x00000103,0x0003003e,0x00000109,0x00000071, + 0x000200f9,0x0000010a,0x000200f8,0x0000010a,0x000400f6,0x0000010c,0x0000010d,0x00000000, + 0x000200f9,0x0000010e,0x000200f8,0x0000010e,0x0004003d,0x00000006,0x0000010f,0x00000109, + 0x000500b1,0x00000072,0x00000110,0x0000010f,0x00000054,0x000400fa,0x00000110,0x0000010b, + 0x0000010c,0x000200f8,0x0000010b,0x0004003d,0x0000003a,0x00000114,0x0000003d,0x0004006f, + 0x00000111,0x00000115,0x00000114,0x0004003d,0x00000006,0x00000116,0x00000109,0x0004006f, + 0x00000011,0x00000117,0x00000116,0x0004003d,0x00000006,0x00000118,0x00000101,0x0004006f, + 0x00000011,0x00000119,0x00000118,0x00050050,0x00000111,0x0000011a,0x00000117,0x00000119, + 0x00050050,0x00000111,0x0000011b,0x00000069,0x00000069,0x00050081,0x00000111,0x0000011c, + 0x0000011a,0x0000011b,0x00050050,0x00000111,0x0000011e,0x0000011d,0x0000011d,0x00050088, + 0x00000111,0x0000011f,0x0000011c,0x0000011e,0x00050081,0x00000111,0x00000120,0x00000115, + 0x0000011f,0x00050041,0x00000124,0x00000125,0x00000123,0x00000071,0x0004003d,0x0000003a, + 0x00000126,0x00000125,0x0004006f,0x00000111,0x00000127,0x00000126,0x00050088,0x00000111, + 0x00000128,0x00000120,0x00000127,0x0003003e,0x00000113,0x00000128,0x0004003d,0x0000012b, + 0x0000012e,0x0000012d,0x0004003d,0x00000111,0x0000012f,0x00000113,0x00070058,0x00000130, + 0x00000131,0x0000012e,0x0000012f,0x00000002,0x0000007f,0x0008004f,0x000000fd,0x00000132, + 0x00000131,0x00000131,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000129,0x00000132, + 0x0004003d,0x000000fd,0x00000134,0x00000129,0x0004003d,0x000000fd,0x00000135,0x00000129, + 0x00050085,0x000000fd,0x00000136,0x00000134,0x00000135,0x0003003e,0x00000133,0x00000136, + 0x0004003d,0x000000fd,0x00000137,0x00000133,0x0004009c,0x00000138,0x00000139,0x00000137, + 0x0004009a,0x00000072,0x0000013a,0x00000139,0x000400a8,0x00000072,0x0000013b,0x0000013a, + 0x000300f7,0x0000013d,0x00000000,0x000400fa,0x0000013b,0x0000013c,0x0000013d,0x000200f8, + 0x0000013c,0x0004003d,0x000000fd,0x0000013e,0x00000133,0x0004009d,0x00000138,0x0000013f, + 0x0000013e,0x0004009a,0x00000072,0x00000140,0x0000013f,0x000200f9,0x0000013d,0x000200f8, + 0x0000013d,0x000700f5,0x00000072,0x00000141,0x0000013a,0x0000010b,0x00000140,0x0000013c, + 0x000300f7,0x00000143,0x00000000,0x000400fa,0x00000141,0x00000142,0x00000143,0x000200f8, + 0x00000142,0x0003003e,0x00000133,0x00000100,0x000200f9,0x00000143,0x000200f8,0x00000143, + 0x0004003d,0x000000fd,0x00000144,0x00000133,0x0004003d,0x000000fd,0x00000145,0x000000ff, + 0x00050081,0x000000fd,0x00000146,0x00000145,0x00000144,0x0003003e,0x000000ff,0x00000146, + 0x000200f9,0x0000010d,0x000200f8,0x0000010d,0x0004003d,0x00000006,0x00000147,0x00000109, + 0x00050080,0x00000006,0x00000148,0x00000147,0x00000046,0x0003003e,0x00000109,0x00000148, + 0x000200f9,0x0000010a,0x000200f8,0x0000010c,0x000200f9,0x00000105,0x000200f8,0x00000105, + 0x0004003d,0x00000006,0x00000149,0x00000101,0x00050080,0x00000006,0x0000014a,0x00000149, + 0x00000046,0x0003003e,0x00000101,0x0000014a,0x000200f9,0x00000102,0x000200f8,0x00000104, + 0x0004003d,0x000000fd,0x0000014c,0x000000ff,0x00060050,0x000000fd,0x0000014d,0x0000006b, + 0x0000006b,0x0000006b,0x00050088,0x000000fd,0x0000014e,0x0000014c,0x0000014d,0x0003003e, + 0x0000014b,0x0000014e,0x0004003d,0x0000014f,0x00000152,0x00000151,0x0004003d,0x0000003a, + 0x00000153,0x0000003d,0x00050041,0x00000017,0x00000157,0x0000014b,0x00000156,0x0004003d, + 0x00000011,0x00000158,0x00000157,0x0003003e,0x00000154,0x00000158,0x00050041,0x0000015a, + 0x0000015b,0x00000123,0x00000061,0x0004003d,0x00000006,0x0000015c,0x0000015b,0x0003003e, + 0x00000159,0x0000015c,0x00050041,0x0000015e,0x0000015f,0x00000123,0x00000054,0x0004003d, + 0x00000011,0x00000160,0x0000015f,0x0003003e,0x0000015d,0x00000160,0x00050041,0x00000007, + 0x00000162,0x0000003d,0x00000156,0x0004003d,0x00000006,0x00000163,0x00000162,0x0003003e, + 0x00000161,0x00000163,0x00050041,0x00000007,0x00000166,0x0000003d,0x00000165,0x0004003d, + 0x00000006,0x00000167,0x00000166,0x0003003e,0x00000164,0x00000167,0x00090039,0x00000011, + 0x00000168,0x0000002c,0x00000154,0x00000159,0x0000015d,0x00000161,0x00000164,0x00050041, + 0x00000017,0x0000016a,0x0000014b,0x00000165,0x0004003d,0x00000011,0x0000016b,0x0000016a, + 0x0003003e,0x00000169,0x0000016b,0x00050041,0x0000015a,0x0000016d,0x00000123,0x00000061, + 0x0004003d,0x00000006,0x0000016e,0x0000016d,0x0003003e,0x0000016c,0x0000016e,0x00050041, + 0x0000015e,0x00000170,0x00000123,0x00000054,0x0004003d,0x00000011,0x00000171,0x00000170, + 0x0003003e,0x0000016f,0x00000171,0x00050041,0x00000007,0x00000173,0x0000003d,0x00000156, + 0x0004003d,0x00000006,0x00000174,0x00000173,0x0003003e,0x00000172,0x00000174,0x00050041, + 0x00000007,0x00000176,0x0000003d,0x00000165,0x0004003d,0x00000006,0x00000177,0x00000176, + 0x0003003e,0x00000175,0x00000177,0x00090039,0x00000011,0x00000178,0x0000002c,0x00000169, + 0x0000016c,0x0000016f,0x00000172,0x00000175,0x00050041,0x00000017,0x0000017b,0x0000014b, + 0x0000017a,0x0004003d,0x00000011,0x0000017c,0x0000017b,0x0003003e,0x00000179,0x0000017c, + 0x00050041,0x0000015a,0x0000017e,0x00000123,0x00000061,0x0004003d,0x00000006,0x0000017f, + 0x0000017e,0x0003003e,0x0000017d,0x0000017f,0x00050041,0x0000015e,0x00000181,0x00000123, + 0x00000054,0x0004003d,0x00000011,0x00000182,0x00000181,0x0003003e,0x00000180,0x00000182, + 0x00050041,0x00000007,0x00000184,0x0000003d,0x00000156,0x0004003d,0x00000006,0x00000185, + 0x00000184,0x0003003e,0x00000183,0x00000185,0x00050041,0x00000007,0x00000187,0x0000003d, + 0x00000165,0x0004003d,0x00000006,0x00000188,0x00000187,0x0003003e,0x00000186,0x00000188, + 0x00090039,0x00000011,0x00000189,0x0000002c,0x00000179,0x0000017d,0x00000180,0x00000183, + 0x00000186,0x00070050,0x00000130,0x0000018a,0x00000168,0x00000178,0x00000189,0x00000080, + 0x00040063,0x00000152,0x00000153,0x0000018a,0x000100fd,0x00010038,0x00050036,0x00000002, + 0x00000041,0x00000000,0x0000003c,0x00030037,0x0000003b,0x00000040,0x000200f8,0x00000042, + 0x0004003b,0x00000007,0x0000018b,0x00000007,0x0004003b,0x00000007,0x0000018c,0x00000007, + 0x0004003b,0x00000007,0x0000018f,0x00000007,0x0004003b,0x00000007,0x00000192,0x00000007, + 0x0004003b,0x00000017,0x00000196,0x00000007,0x0004003b,0x00000007,0x00000197,0x00000007, + 0x0004003b,0x00000007,0x0000019a,0x00000007,0x0004003b,0x00000007,0x0000019d,0x00000007, + 0x0004003b,0x00000007,0x000001a1,0x00000007,0x0004003b,0x00000017,0x000001a5,0x00000007, + 0x0004003b,0x000000fe,0x000001aa,0x00000007,0x0004003b,0x000000fe,0x000001b5,0x00000007, + 0x00050041,0x00000007,0x0000018d,0x00000040,0x00000165,0x0004003d,0x00000006,0x0000018e, + 0x0000018d,0x0003003e,0x0000018c,0x0000018e,0x00060041,0x0000015a,0x00000190,0x00000123, + 0x00000071,0x00000165,0x0004003d,0x00000006,0x00000191,0x00000190,0x0003003e,0x0000018f, + 0x00000191,0x00060041,0x0000015a,0x00000193,0x00000123,0x00000046,0x00000165,0x0004003d, + 0x00000006,0x00000194,0x00000193,0x0003003e,0x00000192,0x00000194,0x00070039,0x00000006, + 0x00000195,0x00000032,0x0000018c,0x0000018f,0x00000192,0x0003003e,0x0000018b,0x00000195, + 0x00050041,0x00000007,0x00000198,0x00000040,0x00000156,0x0004003d,0x00000006,0x00000199, + 0x00000198,0x0003003e,0x00000197,0x00000199,0x00060041,0x0000015a,0x0000019b,0x00000123, + 0x00000071,0x00000156,0x0004003d,0x00000006,0x0000019c,0x0000019b,0x0003003e,0x0000019a, + 0x0000019c,0x00060041,0x0000015a,0x0000019e,0x00000123,0x00000046,0x00000156,0x0004003d, + 0x00000006,0x0000019f,0x0000019e,0x0003003e,0x0000019d,0x0000019f,0x00070039,0x00000011, + 0x000001a0,0x00000038,0x00000197,0x0000019a,0x0000019d,0x0003003e,0x00000196,0x000001a0, + 0x0004003d,0x00000011,0x000001a2,0x00000196,0x0006000c,0x00000011,0x000001a3,0x00000001, + 0x00000008,0x000001a2,0x0004006e,0x00000006,0x000001a4,0x000001a3,0x0003003e,0x000001a1, + 0x000001a4,0x0004003d,0x00000011,0x000001a6,0x00000196,0x0004003d,0x00000006,0x000001a7, + 0x000001a1,0x0004006f,0x00000011,0x000001a8,0x000001a7,0x00050083,0x00000011,0x000001a9, + 0x000001a6,0x000001a8,0x0003003e,0x000001a5,0x000001a9,0x0004003d,0x0000014f,0x000001ab, + 0x00000151,0x0004003d,0x00000006,0x000001ac,0x000001a1,0x00060041,0x0000015a,0x000001ad, + 0x00000123,0x00000071,0x00000156,0x0004003d,0x00000006,0x000001ae,0x000001ad,0x00050082, + 0x00000006,0x000001af,0x000001ae,0x00000046,0x0008000c,0x00000006,0x000001b0,0x00000001, + 0x0000002d,0x000001ac,0x00000071,0x000001af,0x0004003d,0x00000006,0x000001b1,0x0000018b, + 0x00050050,0x0000003a,0x000001b2,0x000001b0,0x000001b1,0x00050062,0x00000130,0x000001b3, + 0x000001ab,0x000001b2,0x0008004f,0x000000fd,0x000001b4,0x000001b3,0x000001b3,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x000001aa,0x000001b4,0x0004003d,0x0000014f,0x000001b6, + 0x00000151,0x0004003d,0x00000006,0x000001b7,0x000001a1,0x00050080,0x00000006,0x000001b8, + 0x000001b7,0x00000046,0x00060041,0x0000015a,0x000001b9,0x00000123,0x00000071,0x00000156, + 0x0004003d,0x00000006,0x000001ba,0x000001b9,0x00050082,0x00000006,0x000001bb,0x000001ba, + 0x00000046,0x0008000c,0x00000006,0x000001bc,0x00000001,0x0000002d,0x000001b8,0x00000071, + 0x000001bb,0x0004003d,0x00000006,0x000001bd,0x0000018b,0x00050050,0x0000003a,0x000001be, + 0x000001bc,0x000001bd,0x00050062,0x00000130,0x000001bf,0x000001b6,0x000001be,0x0008004f, + 0x000000fd,0x000001c0,0x000001bf,0x000001bf,0x00000000,0x00000001,0x00000002,0x0003003e, + 0x000001b5,0x000001c0,0x0004003d,0x000001c1,0x000001c4,0x000001c3,0x0004003d,0x0000003a, + 0x000001c5,0x00000040,0x0004003d,0x000000fd,0x000001c6,0x000001aa,0x0004003d,0x000000fd, + 0x000001c7,0x000001b5,0x0004003d,0x00000011,0x000001c8,0x000001a5,0x00060050,0x000000fd, + 0x000001c9,0x000001c8,0x000001c8,0x000001c8,0x0008000c,0x000000fd,0x000001ca,0x00000001, + 0x0000002e,0x000001c6,0x000001c7,0x000001c9,0x00050051,0x00000011,0x000001cb,0x000001ca, + 0x00000000,0x00050051,0x00000011,0x000001cc,0x000001ca,0x00000001,0x00050051,0x00000011, + 0x000001cd,0x000001ca,0x00000002,0x00070050,0x00000130,0x000001ce,0x000001cb,0x000001cc, + 0x000001cd,0x00000080,0x00040063,0x000001c4,0x000001c5,0x000001ce,0x000100fd,0x00010038 +}; diff --git a/gpu/vk/shaders/n64_common.glsl b/gpu/vk/shaders/n64_common.glsl new file mode 100644 index 0000000..20f0689 --- /dev/null +++ b/gpu/vk/shaders/n64_common.glsl @@ -0,0 +1,48 @@ +// (Triforce, 11-22) N64 Classic's per-pixel maths for its 3D pass (the plan's step 2, n64_3d.comp): the console's 16-bit +// colour, 5 bits a channel, and its 4 x 4 ordered dither, both on the 240-line grid, not on the screen's pixels. Values are +// display-referred (gamma encoded, 0 to 1), as the console's picture was: the pass encodes before and decodes after. +// +// Written in what GLSL and C++ share (scalar steps, int bit operations, no arrays, no swizzles): tests/test_n64_rules.py +// compiles this file as C++ and runs it on authored values. The rules around it (the presets, the grid's size) are in +// gpu/vk/n64_rules.h. + +// (the 4 x 4 Bayer matrix's entry at a grid pixel, 0 to 15: two 2 x 2 steps, the lowest bits of x and y weighed 4 times +// the next ones, so neighbouring pixels are as far apart in the order as they can be. The console's graphics chip offered +// a Bayer matrix and a "magic square" one; at 240 lines through a TV the two cannot be told apart) +int n64_bayer2(int x, int y) { return ((x ^ y) & 1) * 2 + (y & 1); } +int n64_bayer4(int x, int y) { return n64_bayer2(x, y) * 4 + n64_bayer2(x >> 1, y >> 1); } + +// (its threshold at grid pixel x, y, centred on 0: -15/32 to +15/32 of one step) +float n64_dither_offset(int x, int y) { return (float(n64_bayer4(x & 3, y & 3)) + 0.5) / 16.0 - 0.5; } + +// (one channel kept at `bits` a channel, 0: as it is, dithered by `strength`, 0 none to 1 the full threshold, at grid +// pixel x, y. A value on one of the levels stays on it at any strength; one between two levels comes out as a mix of the +// two over each 4 x 4 cell, in the share of its place between them) +float n64_quantize(float v, int bits, float strength, int x, int y) { + if (bits <= 0) return v; + const float levels = float((1 << bits) - 1); + const float c = clamp(v, 0.0, 1.0); + const float q = floor(c * levels + 0.5 + n64_dither_offset(x, y) * strength) / levels; + return clamp(q, 0.0, 1.0); +} + +// (the sRGB curve both ways: the picture the 3D pass reads and writes is linear light, the console's was display-referred) +float n64_encode(float v) { return v <= 0.0031308 ? v * 12.92 : 1.055 * pow(v, 1.0 / 2.4) - 0.055; } +float n64_decode(float v) { return v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4); } + +// (one channel of linear light as the grid keeps it: encoded, kept at `bits` with the dither, decoded. Full colour (bits +// 0) and light above white (HDR's highlights, which no 16-bit picture held anyway) as they are; below black, or not a +// number, black) +float n64_keep(float v, int bits, float strength, int x, int y) { + if (bits <= 0 || v >= 1.0) return v; + return n64_decode(n64_quantize(n64_encode(v > 0.0 ? v : 0.0), bits, strength, x, y)); +} + +// (where an output pixel finds the grid. Its row: the one whose band of the output it is in, every band the same height +// when the sizes divide (1440 output rows, 240 grid rows: 6 each), so the lines have hard edges, as the console's did. Its +// column: a place between two grid pixels, for the video chip's linear resample along the line) +int n64_row(int y, int grid_h, int size_h) { + const int r = int((float(y) + 0.5) * float(grid_h) / float(size_h)); + return r < grid_h - 1 ? r : grid_h - 1; +} +float n64_column(int x, int grid_w, int size_w) { return (float(x) + 0.5) * float(grid_w) / float(size_w) - 0.5; } diff --git a/gpu/vk/shaders/n64_tv.comp b/gpu/vk/shaders/n64_tv.comp new file mode 100644 index 0000000..4e6ac48 --- /dev/null +++ b/gpu/vk/shaders/n64_tv.comp @@ -0,0 +1,114 @@ +#version 450 +// (Triforce, 11-22) N64 Classic's TV (n64-classic-mode-plan.md, step 4): the window pass in the filter's place +// (vk_framegen.cpp framegen_scale, upscaler_rows.h window_filter's kTvFilter), from the finished picture, HUD and all, to its +// place in the window at the window's own pixels. ((11-22, the owner's test) The options' own screens go under it with the +// game's: drawn into a layer of the picture's place before it (vk_menu.cpp menu_tv_layer), laid over the picture here, before +// any of the TV, as the game's own HUD is in the picture. The FPS counter is drawn after it, flat.) +// +// Per window pixel: ((step 8) at a switch, the picture squashed to a line, then a dot, and its flash: n64_rules.h anim) the +// screen's curve (where the picture is under it; off the picture, black), the composite signal's +// colour blurred sideways more than its brightness, then in linear light the saturation, the beam across the TV line (240 +// lines over the picture, lined up with the 3D pass's grid; wider where bright), the phosphor mask at the window's own +// pixels, the glow from the picture at 1/8 (the copy the ultrawide menu sides use), the vignette and the rounded corners. +// The picture is sRGB-encoded, as the window pass's other shaders and hdr_encode.comp take it: decoded here, encoded again, +// with less than a step of 8 bits of noise against banding (fg_scale.comp's). +#extension GL_GOOGLE_include_directive : require +#include "n64_common.glsl" +#include "n64_tv.glsl" + +layout(local_size_x = 8, local_size_y = 8) in; +layout(binding = 0) uniform sampler2D src; // the picture (or, beside ultrawide's menu sides, the window-size image with them) +layout(binding = 1, rgba8) uniform writeonly image2D dst; +layout(binding = 2) uniform sampler2D small; // the picture at 1/8 +// ((11-22) the options' layer: the picture's place, colours premultiplied by their cover and encoded as the picture is +// (vk_imgui.cpp record_layer); bound to something else, and not read, when there is none (menu 0) +layout(binding = 3) uniform sampler2D menu; +// ((11-22, the owner's second look: the game's own panes showed through the options' plates, blurred) menu 2: this dispatch +// makes the glow's 1/8 copy again, dst the small image: the picture with the options' layer over it, each pixel its 8 x 8 +// block's mean as fg_scale.comp's side 3 makes it. The glow then comes from what the screen shows, not from what the game +// drew under the options) +layout(push_constant) uniform P { + float lines; // the TV's lines over the picture (240) + float scan; // the scanlines' strength on this screen (n64_rules.h scanline_strength) + float mask; // the mask's strength + float bleed; // how far the colour blurs sideways, in the picture's widths (n64_rules.h tv_bleed_uv) + float glow; + float curve; + float saturation; + int mask_type; // n64_rules.h mask_shown's: 1 none, 2 aperture grille, 3 slot mask, 4 shadow mask + float anim_x; // ((step 8) the TV switching off and on, n64_rules.h anim: the picture's width and height, shares of + float anim_y; // the whole (1, 1 at rest), and the light added, 0 to 1) + float flash; + int menu; // ((11-22) 1: the options' layer is over the picture; 2: the 1/8 copy with it, into dst) +} pc; + +// (the picture at uv, the options' layer over it: everything below takes the two as one, as it takes the game's HUD) +vec3 encoded(vec2 uv) { + vec3 c = clamp(textureLod(src, uv, 0.0).rgb, 0.0, 1.0); + if (pc.menu != 0) { + const vec4 m = clamp(textureLod(menu, uv, 0.0), 0.0, 1.0); + c = m.rgb + c * (1.0 - m.a); + } + return clamp(c, 0.0, 1.0); +} +vec3 decode3(vec3 c) { return vec3(n64_decode(c.r), n64_decode(c.g), n64_decode(c.b)); } +vec3 encode3(vec3 c) { return vec3(n64_encode(c.r), n64_encode(c.g), n64_encode(c.b)); } +float dither(ivec2 g) { return (fract(52.9829189 * fract(0.06711056 * float(g.x) + 0.00583715 * float(g.y))) - 0.5) / 255.0; } + +void main() { + const ivec2 g = ivec2(gl_GlobalInvocationID.xy); + const ivec2 d = imageSize(dst); + if (any(greaterThanEqual(g, d))) return; + if (pc.menu == 2) { // (the glow's 1/8 copy: 4 x 4 taps on the corners of each pixel's block's 2 x 2s, its mean) + const vec2 at = (vec2(g) + 0.5) / vec2(d), block = 1.0 / vec2(d); + vec3 sum = vec3(0.0); + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) sum += encoded(at + (vec2(x, y) - 1.5) * 0.25 * block); + imageStore(dst, g, vec4(sum / 16.0, 1.0)); + return; + } + vec2 p = (vec2(g) + 0.5) / vec2(d) * 2.0 - 1.0; + // (the TV switching off and on: the whole picture squashed into the middle, to a line, then a dot; around it the tube is dark) + if (abs(p.x) > pc.anim_x || abs(p.y) > pc.anim_y) { + imageStore(dst, g, vec4(0.0, 0.0, 0.0, 1.0)); + return; + } + p /= vec2(pc.anim_x, pc.anim_y); + const vec2 w = vec2(n64_warp(p.x, p.y, pc.curve), n64_warp(p.y, p.x, pc.curve)); + if (abs(w.x) > 1.0 || abs(w.y) > 1.0) { + imageStore(dst, g, vec4(0.0, 0.0, 0.0, 1.0)); + return; + } + const vec2 uv = w * 0.5 + 0.5; + // (the composite signal: brightness from here, colour from 5 taps across the bleed) + vec3 e = encoded(uv); + if (pc.bleed > 0.0) { + float i = 0.0, q = 0.0; + for (int t = -2; t <= 2; t++) { + const vec3 s = encoded(uv + vec2(float(t) * pc.bleed * 0.5, 0.0)); + i += n64_bleed_weight(t) * n64_i(s.r, s.g, s.b); + q += n64_bleed_weight(t) * n64_q(s.r, s.g, s.b); + } + const float y = n64_y(e.r, e.g, e.b); + e = clamp(vec3(n64_red(y, i, q), n64_green(y, i, q), n64_blue(y, i, q)), 0.0, 1.0); + } + vec3 c = decode3(e); + const float luma = dot(c, vec3(0.2126, 0.7152, 0.0722)); + c = max(mix(vec3(luma), c, pc.saturation), 0.0); + // (the beam across its TV line, each channel by its own light) + const float f = fract(uv.y * pc.lines) - 0.5; + c *= vec3(n64_scan(f, c.r, pc.scan), n64_scan(f, c.g, pc.scan), n64_scan(f, c.b, pc.scan)); + // (the mask, at the window's own pixels) + c *= vec3(n64_mask(g.x, g.y, pc.mask_type, 0, pc.mask), n64_mask(g.x, g.y, pc.mask_type, 1, pc.mask), + n64_mask(g.x, g.y, pc.mask_type, 2, pc.mask)); + // (the glow: the picture at 1/8, four taps a small pixel and a half around, added) + if (pc.glow > 0.0) { + const vec2 o = 1.5 / vec2(textureSize(small, 0)); + const vec3 b = (textureLod(small, uv + vec2(-o.x, -o.y), 0.0).rgb + textureLod(small, uv + vec2(o.x, -o.y), 0.0).rgb + + textureLod(small, uv + vec2(-o.x, o.y), 0.0).rgb + textureLod(small, uv + vec2(o.x, o.y), 0.0).rgb) * 0.25; + c += pc.glow * decode3(clamp(b, 0.0, 1.0)); + } + c *= n64_vignette(uv.x, uv.y, pc.curve) * n64_corner(w.x, w.y, pc.curve); + c = mix(c, vec3(0.9, 0.95, 1.0), clamp(pc.flash, 0.0, 1.0) * 0.8); // (the switch's flash: the line and the dot glow bluish white) + imageStore(dst, g, vec4(encode3(clamp(c, 0.0, 1.0)) + dither(g), 1.0)); +} diff --git a/gpu/vk/shaders/n64_tv.glsl b/gpu/vk/shaders/n64_tv.glsl new file mode 100644 index 0000000..c0faa24 --- /dev/null +++ b/gpu/vk/shaders/n64_tv.glsl @@ -0,0 +1,91 @@ +// (Triforce, 11-22) N64 Classic's TV, per pixel (n64-classic-mode-plan.md, step 4; shaders/n64_tv.comp): the beam across a +// TV line, the phosphor mask, the composite signal's colour, the vignette and the screen's curve. Written in what GLSL and +// C++ share (scalar steps, int operations, no arrays, no swizzles): tests/test_n64_tv.py compiles this file as C++ and runs +// it on authored values. Light is linear here unless a name says otherwise; the composite steps take the encoded signal. + +// ---- the beam ---- + +// (its width, in TV lines (one sigma), from the light it draws, 0 to 1: a dim line is thin, a bright one swells into the gap +// beside it, as a tube's spot grew with its current) +float n64_beam_sigma(float level) { return 0.18 + 0.22 * clamp(level, 0.0, 1.0); } +// (the beam's light at f TV lines from the line's middle, -0.5 to 0.5, of its peak) +float n64_beam(float f, float level) { + const float s = n64_beam_sigma(level); + return exp(-f * f / (2.0 * s * s)); +} +// (the mean of n64_beam over a whole line: sigma * sqrt(2 pi) * erf(0.5 / (sigma sqrt 2)), erf by its closed approximation +// (Winitzki's, a = 0.147), within a thousandth here) +float n64_beam_mean(float level) { + const float s = n64_beam_sigma(level); + const float x = 0.5 / (s * 1.41421356); + const float x2 = x * x; + const float erf = sqrt(1.0 - exp(-x2 * (1.27323954 + 0.147 * x2) / (1.0 + 0.147 * x2))); + return s * 2.50662827 * erf; +} +// (what a channel of light `level` is multiplied by at f lines from its line's middle, with the scanlines at `strength`, 0 to +// 1: the gap darkened that much, and seven tenths of the light the gap took given back to the line, so a picture keeps most +// of its brightness and bright lines bloom. 1 everywhere at strength 0) +float n64_scan(float f, float level, float strength) { + const float k = clamp(strength, 0.0, 1.0); + const float beam = n64_beam(f, level); + const float back = 1.0 / n64_beam_mean(level); + return (1.0 + k * (beam - 1.0)) * (1.0 + 0.7 * k * (back - 1.0)); +} + +// ---- the mask ---- + +// (which of red, green and blue (channel 0, 1, 2) a window pixel's phosphor shows, 1, or not, 0. type: 2 aperture grille +// (stripes), 3 slot mask (stripes broken every 4 rows, the breaks of neighbouring triads 2 rows apart), 4 shadow mask (dots, +// alternate rows half a triad apart); anything else, every channel) +float n64_mask_lit(int x, int y, int type, int channel) { + if (type == 2) return x % 3 == channel ? 1.0 : 0.0; + if (type == 3) { + const int row = (y + ((x / 3) % 2) * 2) % 4; + return row != 0 && x % 3 == channel ? 1.0 : 0.0; + } + if (type == 4) return (x + (y % 2) * 2) % 3 == channel ? 1.0 : 0.0; + return 1.0; +} +// (what a channel is multiplied by there: an unlit phosphor darkened by `strength`, 0 to 1, and the mask's mean darkening +// half given back, so the picture dims only a little with it) +float n64_mask(int x, int y, int type, int channel, float strength) { + const float k = clamp(strength, 0.0, 1.0); + if (type < 2 || type > 4 || k <= 0.0) return 1.0; + const float lit = n64_mask_lit(x, y, type, channel); + const float mean_dark = type == 3 ? k * 3.0 / 4.0 : k * 2.0 / 3.0; // (a channel lit on a quarter of a slot mask, a third of the others) + return (1.0 - k + k * lit) / (1.0 - 0.5 * mean_dark); +} + +// ---- the composite signal (on the encoded picture, as the cable carried it) ---- + +float n64_y(float r, float g, float b) { return 0.299 * r + 0.587 * g + 0.114 * b; } +float n64_i(float r, float g, float b) { return 0.595716 * r - 0.274453 * g - 0.321263 * b; } +float n64_q(float r, float g, float b) { return 0.211456 * r - 0.522591 * g + 0.311135 * b; } +float n64_red(float y, float i, float q) { return y + 0.9563 * i + 0.6210 * q; } +float n64_green(float y, float i, float q) { return y - 0.2721 * i - 0.6474 * q; } +float n64_blue(float y, float i, float q) { return y - 1.1070 * i + 1.7046 * q; } +// (the weight of tap t, -2 to 2, of the colour's sideways blur: 1, 2, 3, 2, 1 of 9) +float n64_bleed_weight(int t) { return (3.0 - float(t < 0 ? -t : t)) / 9.0; } + +// ---- the screen ---- + +// (a coordinate across the screen, -1 to 1, to where the picture is under it on a screen curved by `curve` (its barrel at +// the corners), given the other coordinate: pushed outward the more the further from the middle, so the picture's corners +// fall off the screen, which is black there) +float n64_warp(float a, float other, float curve) { return a * (1.0 + curve * (a * a + other * other)); } +// (the light at a place of the picture, u and v 0 to 1: the corners darker, the more the more the screen is curved; 1 +// everywhere on a flat one) +float n64_vignette(float u, float v, float curve) { + const float amount = clamp(curve * 15.0, 0.0, 0.6); + const float edge = clamp(16.0 * u * v * (1.0 - u) * (1.0 - v), 0.0, 1.0); + return 1.0 - amount * (1.0 - sqrt(sqrt(edge))); +} +// (the rounded corner's light at a place of the warped picture, a and b -1 to 1: 1 inside, falling to 0 over the corner's +// edge; a corner's radius is a 30th of the picture on a curved screen, none on a flat one) +float n64_corner(float a, float b, float curve) { + if (curve <= 0.0) return 1.0; + const float r = 1.0 / 15.0; + const float da = max(abs(a) - (1.0 - r), 0.0), db = max(abs(b) - (1.0 - r), 0.0); + const float d = sqrt(da * da + db * db) / r; + return clamp((1.0 - d) * 8.0, 0.0, 1.0); +} diff --git a/gpu/vk/shaders/n64_tv_comp_spv.h b/gpu/vk/shaders/n64_tv_comp_spv.h new file mode 100644 index 0000000..1d08411 --- /dev/null +++ b/gpu/vk/shaders/n64_tv_comp_spv.h @@ -0,0 +1,816 @@ +// n64_tv.comp + n64_common.glsl + n64_tv.glsl sha256 00b8c1f90ff2ae61901950ec49e2b3f91d870008fad41ca4a6a4a18b90a21883 (tests/test_n64_tv.py --write: glslangValidator -V --target-env vulkan1.2 --vn N64_TV_COMP_SPV) + // 1116.6.0 + #pragma once +const uint32_t N64_TV_COMP_SPV[] = { + 0x07230203,0x00010500,0x0008000b,0x0000046d,0x00000000,0x00020011,0x00000001,0x00020011, + 0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e, + 0x00000000,0x00000001,0x000b000f,0x00000005,0x00000004,0x6e69616d,0x00000000,0x0000020b, + 0x00000216,0x00000220,0x0000026f,0x00000277,0x000003f4,0x00060010,0x00000004,0x00000011, + 0x00000008,0x00000008,0x00000001,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47, + 0x4c474f4f,0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576, + 0x00080004,0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669, + 0x00040005,0x00000004,0x6e69616d,0x00000000,0x00060005,0x0000000a,0x5f34366e,0x6f636e65, + 0x66286564,0x00003b31,0x00030005,0x00000009,0x00000076,0x00060005,0x0000000d,0x5f34366e, + 0x6f636564,0x66286564,0x00003b31,0x00030005,0x0000000c,0x00000076,0x00070005,0x00000010, + 0x5f34366e,0x6d616562,0x6769735f,0x6628616d,0x00003b31,0x00040005,0x0000000f,0x6576656c, + 0x0000006c,0x00060005,0x00000015,0x5f34366e,0x6d616562,0x3b316628,0x003b3166,0x00030005, + 0x00000013,0x00000066,0x00040005,0x00000014,0x6576656c,0x0000006c,0x00070005,0x00000018, + 0x5f34366e,0x6d616562,0x61656d5f,0x3166286e,0x0000003b,0x00040005,0x00000017,0x6576656c, + 0x0000006c,0x00070005,0x0000001e,0x5f34366e,0x6e616373,0x3b316628,0x663b3166,0x00003b31, + 0x00030005,0x0000001b,0x00000066,0x00040005,0x0000001c,0x6576656c,0x0000006c,0x00050005, + 0x0000001d,0x65727473,0x6874676e,0x00000000,0x00090005,0x00000027,0x5f34366e,0x6b73616d, + 0x74696c5f,0x3b316928,0x693b3169,0x31693b31,0x0000003b,0x00030005,0x00000023,0x00000078, + 0x00030005,0x00000024,0x00000079,0x00040005,0x00000025,0x65707974,0x00000000,0x00040005, + 0x00000026,0x6e616863,0x006c656e,0x00090005,0x0000002f,0x5f34366e,0x6b73616d,0x3b316928, + 0x693b3169,0x31693b31,0x3b31663b,0x00000000,0x00030005,0x0000002a,0x00000078,0x00030005, + 0x0000002b,0x00000079,0x00040005,0x0000002c,0x65707974,0x00000000,0x00040005,0x0000002d, + 0x6e616863,0x006c656e,0x00050005,0x0000002e,0x65727473,0x6874676e,0x00000000,0x00060005, + 0x00000034,0x5f34366e,0x31662879,0x3b31663b,0x003b3166,0x00030005,0x00000031,0x00000072, + 0x00030005,0x00000032,0x00000067,0x00030005,0x00000033,0x00000062,0x00060005,0x00000039, + 0x5f34366e,0x31662869,0x3b31663b,0x003b3166,0x00030005,0x00000036,0x00000072,0x00030005, + 0x00000037,0x00000067,0x00030005,0x00000038,0x00000062,0x00060005,0x0000003e,0x5f34366e, + 0x31662871,0x3b31663b,0x003b3166,0x00030005,0x0000003b,0x00000072,0x00030005,0x0000003c, + 0x00000067,0x00030005,0x0000003d,0x00000062,0x00070005,0x00000043,0x5f34366e,0x28646572, + 0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000040,0x00000079,0x00030005,0x00000041, + 0x00000069,0x00030005,0x00000042,0x00000071,0x00070005,0x00000048,0x5f34366e,0x65657267, + 0x3166286e,0x3b31663b,0x003b3166,0x00030005,0x00000045,0x00000079,0x00030005,0x00000046, + 0x00000069,0x00030005,0x00000047,0x00000071,0x00070005,0x0000004d,0x5f34366e,0x65756c62, + 0x3b316628,0x663b3166,0x00003b31,0x00030005,0x0000004a,0x00000079,0x00030005,0x0000004b, + 0x00000069,0x00030005,0x0000004c,0x00000071,0x00080005,0x00000051,0x5f34366e,0x65656c62, + 0x65775f64,0x74686769,0x3b316928,0x00000000,0x00030005,0x00000050,0x00000074,0x00070005, + 0x00000056,0x5f34366e,0x70726177,0x3b316628,0x663b3166,0x00003b31,0x00030005,0x00000053, + 0x00000061,0x00040005,0x00000054,0x6568746f,0x00000072,0x00040005,0x00000055,0x76727563, + 0x00000065,0x00080005,0x0000005b,0x5f34366e,0x6e676976,0x65747465,0x3b316628,0x663b3166, + 0x00003b31,0x00030005,0x00000058,0x00000075,0x00030005,0x00000059,0x00000076,0x00040005, + 0x0000005a,0x76727563,0x00000065,0x00080005,0x00000060,0x5f34366e,0x6e726f63,0x66287265, + 0x31663b31,0x3b31663b,0x00000000,0x00030005,0x0000005d,0x00000061,0x00030005,0x0000005e, + 0x00000062,0x00040005,0x0000005f,0x76727563,0x00000065,0x00060005,0x00000067,0x6f636e65, + 0x28646564,0x3b326676,0x00000000,0x00030005,0x00000066,0x00007675,0x00060005,0x0000006c, + 0x6f636564,0x28336564,0x3b336676,0x00000000,0x00030005,0x0000006b,0x00000063,0x00060005, + 0x0000006f,0x6f636e65,0x28336564,0x3b336676,0x00000000,0x00030005,0x0000006e,0x00000063, + 0x00050005,0x00000075,0x68746964,0x76287265,0x003b3269,0x00030005,0x00000074,0x00000067, + 0x00030005,0x000000a7,0x00000073,0x00040005,0x000000a8,0x61726170,0x0000006d,0x00030005, + 0x000000b8,0x00000073,0x00040005,0x000000b9,0x61726170,0x0000006d,0x00030005,0x000000bc, + 0x00000078,0x00030005,0x000000c2,0x00003278,0x00030005,0x000000c6,0x00667265,0x00030005, + 0x000000dd,0x0000006b,0x00040005,0x000000e0,0x6d616562,0x00000000,0x00040005,0x000000e1, + 0x61726170,0x0000006d,0x00040005,0x000000e3,0x61726170,0x0000006d,0x00040005,0x000000e6, + 0x6b636162,0x00000000,0x00040005,0x000000e7,0x61726170,0x0000006d,0x00030005,0x0000010a, + 0x00776f72,0x00030005,0x0000012f,0x0000006b,0x00030005,0x0000013d,0x0074696c,0x00040005, + 0x0000013e,0x61726170,0x0000006d,0x00040005,0x00000140,0x61726170,0x0000006d,0x00040005, + 0x00000142,0x61726170,0x0000006d,0x00040005,0x00000144,0x61726170,0x0000006d,0x00050005, + 0x00000147,0x6e61656d,0x7261645f,0x0000006b,0x00040005,0x000001c9,0x756f6d61,0x0000746e, + 0x00040005,0x000001cf,0x65676465,0x00000000,0x00030005,0x000001ea,0x00006164,0x00030005, + 0x000001f0,0x00006264,0x00030005,0x000001f5,0x00000064,0x00030005,0x00000207,0x00000063, + 0x00030005,0x0000020b,0x00637273,0x00030005,0x00000214,0x00000050,0x00050006,0x00000214, + 0x00000000,0x656e696c,0x00000073,0x00050006,0x00000214,0x00000001,0x6e616373,0x00000000, + 0x00050006,0x00000214,0x00000002,0x6b73616d,0x00000000,0x00050006,0x00000214,0x00000003, + 0x65656c62,0x00000064,0x00050006,0x00000214,0x00000004,0x776f6c67,0x00000000,0x00050006, + 0x00000214,0x00000005,0x76727563,0x00000065,0x00060006,0x00000214,0x00000006,0x75746173, + 0x69746172,0x00006e6f,0x00060006,0x00000214,0x00000007,0x6b73616d,0x7079745f,0x00000065, + 0x00050006,0x00000214,0x00000008,0x6d696e61,0x0000785f,0x00050006,0x00000214,0x00000009, + 0x6d696e61,0x0000795f,0x00050006,0x00000214,0x0000000a,0x73616c66,0x00000068,0x00050006, + 0x00000214,0x0000000b,0x756e656d,0x00000000,0x00030005,0x00000216,0x00006370,0x00030005, + 0x0000021f,0x0000006d,0x00040005,0x00000220,0x756e656d,0x00000000,0x00040005,0x00000237, + 0x61726170,0x0000006d,0x00040005,0x0000023c,0x61726170,0x0000006d,0x00040005,0x00000241, + 0x61726170,0x0000006d,0x00040005,0x00000249,0x61726170,0x0000006d,0x00040005,0x0000024d, + 0x61726170,0x0000006d,0x00040005,0x00000251,0x61726170,0x0000006d,0x00030005,0x0000026c, + 0x00000067,0x00080005,0x0000026f,0x475f6c67,0x61626f6c,0x766e496c,0x7461636f,0x496e6f69, + 0x00000044,0x00030005,0x00000274,0x00000064,0x00030005,0x00000277,0x00747364,0x00030005, + 0x00000287,0x00007461,0x00040005,0x0000028f,0x636f6c62,0x0000006b,0x00030005,0x00000294, + 0x006d7573,0x00030005,0x00000296,0x00000079,0x00030005,0x0000029e,0x00000078,0x00040005, + 0x000002b4,0x61726170,0x0000006d,0x00030005,0x000002c7,0x00000070,0x00030005,0x000002f2, + 0x00000077,0x00040005,0x000002f4,0x61726170,0x0000006d,0x00040005,0x000002f7,0x61726170, + 0x0000006d,0x00040005,0x000002fa,0x61726170,0x0000006d,0x00040005,0x000002fe,0x61726170, + 0x0000006d,0x00040005,0x00000301,0x61726170,0x0000006d,0x00040005,0x00000304,0x61726170, + 0x0000006d,0x00030005,0x0000031a,0x00007675,0x00030005,0x0000031f,0x00000065,0x00040005, + 0x00000320,0x61726170,0x0000006d,0x00030005,0x00000328,0x00000069,0x00030005,0x00000329, + 0x00000071,0x00030005,0x0000032a,0x00000074,0x00030005,0x00000333,0x00000073,0x00040005, + 0x0000033d,0x61726170,0x0000006d,0x00040005,0x0000033f,0x61726170,0x0000006d,0x00040005, + 0x00000342,0x61726170,0x0000006d,0x00040005,0x00000345,0x61726170,0x0000006d,0x00040005, + 0x00000348,0x61726170,0x0000006d,0x00040005,0x0000034f,0x61726170,0x0000006d,0x00040005, + 0x00000352,0x61726170,0x0000006d,0x00040005,0x00000355,0x61726170,0x0000006d,0x00040005, + 0x00000358,0x61726170,0x0000006d,0x00030005,0x00000361,0x00000079,0x00040005,0x00000362, + 0x61726170,0x0000006d,0x00040005,0x00000365,0x61726170,0x0000006d,0x00040005,0x00000368, + 0x61726170,0x0000006d,0x00040005,0x0000036c,0x61726170,0x0000006d,0x00040005,0x0000036e, + 0x61726170,0x0000006d,0x00040005,0x00000370,0x61726170,0x0000006d,0x00040005,0x00000373, + 0x61726170,0x0000006d,0x00040005,0x00000375,0x61726170,0x0000006d,0x00040005,0x00000377, + 0x61726170,0x0000006d,0x00040005,0x0000037a,0x61726170,0x0000006d,0x00040005,0x0000037c, + 0x61726170,0x0000006d,0x00040005,0x0000037e,0x61726170,0x0000006d,0x00030005,0x00000385, + 0x00000063,0x00040005,0x00000386,0x61726170,0x0000006d,0x00040005,0x00000389,0x616d756c, + 0x00000000,0x00030005,0x0000039a,0x00000066,0x00040005,0x000003a2,0x61726170,0x0000006d, + 0x00040005,0x000003a4,0x61726170,0x0000006d,0x00040005,0x000003a7,0x61726170,0x0000006d, + 0x00040005,0x000003ab,0x61726170,0x0000006d,0x00040005,0x000003ad,0x61726170,0x0000006d, + 0x00040005,0x000003b0,0x61726170,0x0000006d,0x00040005,0x000003b4,0x61726170,0x0000006d, + 0x00040005,0x000003b6,0x61726170,0x0000006d,0x00040005,0x000003b9,0x61726170,0x0000006d, + 0x00040005,0x000003c1,0x61726170,0x0000006d,0x00040005,0x000003c4,0x61726170,0x0000006d, + 0x00040005,0x000003c7,0x61726170,0x0000006d,0x00040005,0x000003ca,0x61726170,0x0000006d, + 0x00040005,0x000003cb,0x61726170,0x0000006d,0x00040005,0x000003cf,0x61726170,0x0000006d, + 0x00040005,0x000003d2,0x61726170,0x0000006d,0x00040005,0x000003d5,0x61726170,0x0000006d, + 0x00040005,0x000003d8,0x61726170,0x0000006d,0x00040005,0x000003d9,0x61726170,0x0000006d, + 0x00040005,0x000003dd,0x61726170,0x0000006d,0x00040005,0x000003e0,0x61726170,0x0000006d, + 0x00040005,0x000003e3,0x61726170,0x0000006d,0x00040005,0x000003e6,0x61726170,0x0000006d, + 0x00040005,0x000003e7,0x61726170,0x0000006d,0x00030005,0x000003f3,0x0000006f,0x00040005, + 0x000003f4,0x6c616d73,0x0000006c,0x00030005,0x000003fb,0x00000062,0x00040005,0x00000432, + 0x61726170,0x0000006d,0x00040005,0x00000437,0x61726170,0x0000006d,0x00040005,0x0000043a, + 0x61726170,0x0000006d,0x00040005,0x0000043d,0x61726170,0x0000006d,0x00040005,0x00000441, + 0x61726170,0x0000006d,0x00040005,0x00000444,0x61726170,0x0000006d,0x00040005,0x00000447, + 0x61726170,0x0000006d,0x00040005,0x00000460,0x61726170,0x0000006d,0x00040005,0x00000462, + 0x61726170,0x0000006d,0x00040047,0x0000020b,0x00000021,0x00000000,0x00040047,0x0000020b, + 0x00000022,0x00000000,0x00030047,0x00000214,0x00000002,0x00050048,0x00000214,0x00000000, + 0x00000023,0x00000000,0x00050048,0x00000214,0x00000001,0x00000023,0x00000004,0x00050048, + 0x00000214,0x00000002,0x00000023,0x00000008,0x00050048,0x00000214,0x00000003,0x00000023, + 0x0000000c,0x00050048,0x00000214,0x00000004,0x00000023,0x00000010,0x00050048,0x00000214, + 0x00000005,0x00000023,0x00000014,0x00050048,0x00000214,0x00000006,0x00000023,0x00000018, + 0x00050048,0x00000214,0x00000007,0x00000023,0x0000001c,0x00050048,0x00000214,0x00000008, + 0x00000023,0x00000020,0x00050048,0x00000214,0x00000009,0x00000023,0x00000024,0x00050048, + 0x00000214,0x0000000a,0x00000023,0x00000028,0x00050048,0x00000214,0x0000000b,0x00000023, + 0x0000002c,0x00040047,0x00000220,0x00000021,0x00000003,0x00040047,0x00000220,0x00000022, + 0x00000000,0x00040047,0x0000026f,0x0000000b,0x0000001c,0x00030047,0x00000277,0x00000019, + 0x00040047,0x00000277,0x00000021,0x00000001,0x00040047,0x00000277,0x00000022,0x00000000, + 0x00040047,0x000003f4,0x00000021,0x00000002,0x00040047,0x000003f4,0x00000022,0x00000000, + 0x00040047,0x0000046c,0x0000000b,0x00000019,0x00020013,0x00000002,0x00030021,0x00000003, + 0x00000002,0x00030016,0x00000006,0x00000020,0x00040020,0x00000007,0x00000007,0x00000006, + 0x00040021,0x00000008,0x00000006,0x00000007,0x00050021,0x00000012,0x00000006,0x00000007, + 0x00000007,0x00060021,0x0000001a,0x00000006,0x00000007,0x00000007,0x00000007,0x00040015, + 0x00000020,0x00000020,0x00000001,0x00040020,0x00000021,0x00000007,0x00000020,0x00070021, + 0x00000022,0x00000006,0x00000021,0x00000021,0x00000021,0x00000021,0x00080021,0x00000029, + 0x00000006,0x00000021,0x00000021,0x00000021,0x00000021,0x00000007,0x00040021,0x0000004f, + 0x00000006,0x00000021,0x00040017,0x00000062,0x00000006,0x00000002,0x00040020,0x00000063, + 0x00000007,0x00000062,0x00040017,0x00000064,0x00000006,0x00000003,0x00040021,0x00000065, + 0x00000064,0x00000063,0x00040020,0x00000069,0x00000007,0x00000064,0x00040021,0x0000006a, + 0x00000064,0x00000069,0x00040017,0x00000071,0x00000020,0x00000002,0x00040020,0x00000072, + 0x00000007,0x00000071,0x00040021,0x00000073,0x00000006,0x00000072,0x0004002b,0x00000006, + 0x00000078,0x3b4d2e1c,0x00020014,0x00000079,0x0004002b,0x00000006,0x0000007f,0x414eb852, + 0x0004002b,0x00000006,0x00000082,0x3f870a3d,0x0004002b,0x00000006,0x00000084,0x3ed55555, + 0x0004002b,0x00000006,0x00000087,0x3d6147ae,0x0004002b,0x00000006,0x0000008d,0x3d25aee6, + 0x0004002b,0x00000006,0x00000098,0x4019999a,0x0004002b,0x00000006,0x0000009d,0x3e3851ec, + 0x0004002b,0x00000006,0x0000009e,0x3e6147ae,0x0004002b,0x00000006,0x000000a0,0x00000000, + 0x0004002b,0x00000006,0x000000a1,0x3f800000,0x0004002b,0x00000006,0x000000af,0x40000000, + 0x0004002b,0x00000006,0x000000bd,0x3f000000,0x0004002b,0x00000006,0x000000bf,0x3fb504f3, + 0x0004002b,0x00000006,0x000000c9,0x3fa2f983,0x0004002b,0x00000006,0x000000ca,0x3e16872b, + 0x0004002b,0x00000006,0x000000d7,0x40206c99,0x0004002b,0x00000006,0x000000f0,0x3f333333, + 0x0004002b,0x00000020,0x000000fb,0x00000002,0x0004002b,0x00000020,0x00000100,0x00000003, + 0x0004002b,0x00000020,0x00000111,0x00000004,0x0004002b,0x00000020,0x00000114,0x00000000, + 0x0004002b,0x00000006,0x0000014e,0x40400000,0x0004002b,0x00000006,0x00000150,0x40800000, + 0x0004002b,0x00000006,0x00000163,0x3e991687,0x0004002b,0x00000006,0x00000166,0x3f1645a2, + 0x0004002b,0x00000006,0x0000016a,0x3de978d5,0x0004002b,0x00000006,0x00000170,0x3f1880d8, + 0x0004002b,0x00000006,0x00000173,0x3e8c851b,0x0004002b,0x00000006,0x00000177,0x3ea47c95, + 0x0004002b,0x00000006,0x0000017d,0x3e5887ec,0x0004002b,0x00000006,0x00000180,0x3f05c886, + 0x0004002b,0x00000006,0x00000184,0x3e9f4d16,0x0004002b,0x00000006,0x0000018b,0x3f74d014, + 0x0004002b,0x00000006,0x0000018f,0x3f1ef9db,0x0004002b,0x00000006,0x00000196,0x3e8b50b1, + 0x0004002b,0x00000006,0x0000019a,0x3f25bc02,0x0004002b,0x00000006,0x000001a1,0x3f8db22d, + 0x0004002b,0x00000006,0x000001a5,0x3fda3055,0x0004002b,0x00000006,0x000001b7,0x41100000, + 0x0004002b,0x00000006,0x000001cb,0x41700000,0x0004002b,0x00000006,0x000001cd,0x3f19999a, + 0x0004002b,0x00000006,0x000001d0,0x41800000,0x0004002b,0x00000006,0x000001ed,0x3f6eeeef, + 0x0004002b,0x00000006,0x000001fe,0x3d888889,0x0004002b,0x00000006,0x00000202,0x41000000, + 0x00090019,0x00000208,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001, + 0x00000000,0x0003001b,0x00000209,0x00000208,0x00040020,0x0000020a,0x00000000,0x00000209, + 0x0004003b,0x0000020a,0x0000020b,0x00000000,0x00040017,0x0000020e,0x00000006,0x00000004, + 0x000e001e,0x00000214,0x00000006,0x00000006,0x00000006,0x00000006,0x00000006,0x00000006, + 0x00000006,0x00000020,0x00000006,0x00000006,0x00000006,0x00000020,0x00040020,0x00000215, + 0x00000009,0x00000214,0x0004003b,0x00000215,0x00000216,0x00000009,0x0004002b,0x00000020, + 0x00000217,0x0000000b,0x00040020,0x00000218,0x00000009,0x00000020,0x00040020,0x0000021e, + 0x00000007,0x0000020e,0x0004003b,0x0000020a,0x00000220,0x00000000,0x00040015,0x0000022a, + 0x00000020,0x00000000,0x0004002b,0x0000022a,0x0000022b,0x00000003,0x0004002b,0x0000022a, + 0x00000238,0x00000000,0x0004002b,0x0000022a,0x0000023d,0x00000001,0x0004002b,0x0000022a, + 0x00000242,0x00000002,0x0004002b,0x00000006,0x00000258,0x4253ee82,0x0004002b,0x00000006, + 0x00000259,0x3d897143,0x0004002b,0x00000006,0x0000025e,0x3bbf4590,0x0004002b,0x00000006, + 0x00000268,0x437f0000,0x00040017,0x0000026d,0x0000022a,0x00000003,0x00040020,0x0000026e, + 0x00000001,0x0000026d,0x0004003b,0x0000026e,0x0000026f,0x00000001,0x00040017,0x00000270, + 0x0000022a,0x00000002,0x00090019,0x00000275,0x00000006,0x00000001,0x00000000,0x00000000, + 0x00000000,0x00000002,0x00000004,0x00040020,0x00000276,0x00000000,0x00000275,0x0004003b, + 0x00000276,0x00000277,0x00000000,0x00040017,0x0000027c,0x00000079,0x00000002,0x0006002c, + 0x00000064,0x00000295,0x000000a0,0x000000a0,0x000000a0,0x0004002b,0x00000006,0x000002ac, + 0x3fc00000,0x0004002b,0x00000006,0x000002af,0x3e800000,0x0004002b,0x00000020,0x000002b9, + 0x00000001,0x0004002b,0x00000020,0x000002d5,0x00000008,0x00040020,0x000002d6,0x00000009, + 0x00000006,0x0004002b,0x00000020,0x000002e0,0x00000009,0x0007002c,0x0000020e,0x000002e9, + 0x000000a0,0x000000a0,0x000000a0,0x000000a1,0x0004002b,0x00000020,0x000002f3,0x00000005, + 0x0004002b,0x00000020,0x0000032b,0xfffffffe,0x0004002b,0x00000006,0x0000038b,0x3e59b3d0, + 0x0004002b,0x00000006,0x0000038c,0x3f371759,0x0004002b,0x00000006,0x0000038d,0x3d93dd98, + 0x0006002c,0x00000064,0x0000038e,0x0000038b,0x0000038c,0x0000038d,0x0004002b,0x00000020, + 0x00000393,0x00000006,0x0004002b,0x00000020,0x000003c0,0x00000007,0x0004003b,0x0000020a, + 0x000003f4,0x00000000,0x0004002b,0x00000006,0x0000044f,0x3f666666,0x0004002b,0x00000006, + 0x00000450,0x3f733333,0x0006002c,0x00000064,0x00000451,0x0000044f,0x00000450,0x000000a1, + 0x0004002b,0x00000020,0x00000452,0x0000000a,0x0004002b,0x00000006,0x00000456,0x3f4ccccd, + 0x0004002b,0x0000022a,0x0000046b,0x00000008,0x0006002c,0x0000026d,0x0000046c,0x0000046b, + 0x0000046b,0x0000023d,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, + 0x00000005,0x0004003b,0x00000072,0x0000026c,0x00000007,0x0004003b,0x00000072,0x00000274, + 0x00000007,0x0004003b,0x00000063,0x00000287,0x00000007,0x0004003b,0x00000063,0x0000028f, + 0x00000007,0x0004003b,0x00000069,0x00000294,0x00000007,0x0004003b,0x00000021,0x00000296, + 0x00000007,0x0004003b,0x00000021,0x0000029e,0x00000007,0x0004003b,0x00000063,0x000002b4, + 0x00000007,0x0004003b,0x00000063,0x000002c7,0x00000007,0x0004003b,0x00000063,0x000002f2, + 0x00000007,0x0004003b,0x00000007,0x000002f4,0x00000007,0x0004003b,0x00000007,0x000002f7, + 0x00000007,0x0004003b,0x00000007,0x000002fa,0x00000007,0x0004003b,0x00000007,0x000002fe, + 0x00000007,0x0004003b,0x00000007,0x00000301,0x00000007,0x0004003b,0x00000007,0x00000304, + 0x00000007,0x0004003b,0x00000063,0x0000031a,0x00000007,0x0004003b,0x00000069,0x0000031f, + 0x00000007,0x0004003b,0x00000063,0x00000320,0x00000007,0x0004003b,0x00000007,0x00000328, + 0x00000007,0x0004003b,0x00000007,0x00000329,0x00000007,0x0004003b,0x00000021,0x0000032a, + 0x00000007,0x0004003b,0x00000069,0x00000333,0x00000007,0x0004003b,0x00000063,0x0000033d, + 0x00000007,0x0004003b,0x00000021,0x0000033f,0x00000007,0x0004003b,0x00000007,0x00000342, + 0x00000007,0x0004003b,0x00000007,0x00000345,0x00000007,0x0004003b,0x00000007,0x00000348, + 0x00000007,0x0004003b,0x00000021,0x0000034f,0x00000007,0x0004003b,0x00000007,0x00000352, + 0x00000007,0x0004003b,0x00000007,0x00000355,0x00000007,0x0004003b,0x00000007,0x00000358, + 0x00000007,0x0004003b,0x00000007,0x00000361,0x00000007,0x0004003b,0x00000007,0x00000362, + 0x00000007,0x0004003b,0x00000007,0x00000365,0x00000007,0x0004003b,0x00000007,0x00000368, + 0x00000007,0x0004003b,0x00000007,0x0000036c,0x00000007,0x0004003b,0x00000007,0x0000036e, + 0x00000007,0x0004003b,0x00000007,0x00000370,0x00000007,0x0004003b,0x00000007,0x00000373, + 0x00000007,0x0004003b,0x00000007,0x00000375,0x00000007,0x0004003b,0x00000007,0x00000377, + 0x00000007,0x0004003b,0x00000007,0x0000037a,0x00000007,0x0004003b,0x00000007,0x0000037c, + 0x00000007,0x0004003b,0x00000007,0x0000037e,0x00000007,0x0004003b,0x00000069,0x00000385, + 0x00000007,0x0004003b,0x00000069,0x00000386,0x00000007,0x0004003b,0x00000007,0x00000389, + 0x00000007,0x0004003b,0x00000007,0x0000039a,0x00000007,0x0004003b,0x00000007,0x000003a2, + 0x00000007,0x0004003b,0x00000007,0x000003a4,0x00000007,0x0004003b,0x00000007,0x000003a7, + 0x00000007,0x0004003b,0x00000007,0x000003ab,0x00000007,0x0004003b,0x00000007,0x000003ad, + 0x00000007,0x0004003b,0x00000007,0x000003b0,0x00000007,0x0004003b,0x00000007,0x000003b4, + 0x00000007,0x0004003b,0x00000007,0x000003b6,0x00000007,0x0004003b,0x00000007,0x000003b9, + 0x00000007,0x0004003b,0x00000021,0x000003c1,0x00000007,0x0004003b,0x00000021,0x000003c4, + 0x00000007,0x0004003b,0x00000021,0x000003c7,0x00000007,0x0004003b,0x00000021,0x000003ca, + 0x00000007,0x0004003b,0x00000007,0x000003cb,0x00000007,0x0004003b,0x00000021,0x000003cf, + 0x00000007,0x0004003b,0x00000021,0x000003d2,0x00000007,0x0004003b,0x00000021,0x000003d5, + 0x00000007,0x0004003b,0x00000021,0x000003d8,0x00000007,0x0004003b,0x00000007,0x000003d9, + 0x00000007,0x0004003b,0x00000021,0x000003dd,0x00000007,0x0004003b,0x00000021,0x000003e0, + 0x00000007,0x0004003b,0x00000021,0x000003e3,0x00000007,0x0004003b,0x00000021,0x000003e6, + 0x00000007,0x0004003b,0x00000007,0x000003e7,0x00000007,0x0004003b,0x00000063,0x000003f3, + 0x00000007,0x0004003b,0x00000069,0x000003fb,0x00000007,0x0004003b,0x00000069,0x00000432, + 0x00000007,0x0004003b,0x00000007,0x00000437,0x00000007,0x0004003b,0x00000007,0x0000043a, + 0x00000007,0x0004003b,0x00000007,0x0000043d,0x00000007,0x0004003b,0x00000007,0x00000441, + 0x00000007,0x0004003b,0x00000007,0x00000444,0x00000007,0x0004003b,0x00000007,0x00000447, + 0x00000007,0x0004003b,0x00000069,0x00000460,0x00000007,0x0004003b,0x00000072,0x00000462, + 0x00000007,0x0004003d,0x0000026d,0x00000271,0x0000026f,0x0007004f,0x00000270,0x00000272, + 0x00000271,0x00000271,0x00000000,0x00000001,0x0004007c,0x00000071,0x00000273,0x00000272, + 0x0003003e,0x0000026c,0x00000273,0x0004003d,0x00000275,0x00000278,0x00000277,0x00040068, + 0x00000071,0x00000279,0x00000278,0x0003003e,0x00000274,0x00000279,0x0004003d,0x00000071, + 0x0000027a,0x0000026c,0x0004003d,0x00000071,0x0000027b,0x00000274,0x000500af,0x0000027c, + 0x0000027d,0x0000027a,0x0000027b,0x0004009a,0x00000079,0x0000027e,0x0000027d,0x000300f7, + 0x00000280,0x00000000,0x000400fa,0x0000027e,0x0000027f,0x00000280,0x000200f8,0x0000027f, + 0x000100fd,0x000200f8,0x00000280,0x00050041,0x00000218,0x00000282,0x00000216,0x00000217, + 0x0004003d,0x00000020,0x00000283,0x00000282,0x000500aa,0x00000079,0x00000284,0x00000283, + 0x000000fb,0x000300f7,0x00000286,0x00000000,0x000400fa,0x00000284,0x00000285,0x00000286, + 0x000200f8,0x00000285,0x0004003d,0x00000071,0x00000288,0x0000026c,0x0004006f,0x00000062, + 0x00000289,0x00000288,0x00050050,0x00000062,0x0000028a,0x000000bd,0x000000bd,0x00050081, + 0x00000062,0x0000028b,0x00000289,0x0000028a,0x0004003d,0x00000071,0x0000028c,0x00000274, + 0x0004006f,0x00000062,0x0000028d,0x0000028c,0x00050088,0x00000062,0x0000028e,0x0000028b, + 0x0000028d,0x0003003e,0x00000287,0x0000028e,0x0004003d,0x00000071,0x00000290,0x00000274, + 0x0004006f,0x00000062,0x00000291,0x00000290,0x00050050,0x00000062,0x00000292,0x000000a1, + 0x000000a1,0x00050088,0x00000062,0x00000293,0x00000292,0x00000291,0x0003003e,0x0000028f, + 0x00000293,0x0003003e,0x00000294,0x00000295,0x0003003e,0x00000296,0x00000114,0x000200f9, + 0x00000297,0x000200f8,0x00000297,0x000400f6,0x00000299,0x0000029a,0x00000000,0x000200f9, + 0x0000029b,0x000200f8,0x0000029b,0x0004003d,0x00000020,0x0000029c,0x00000296,0x000500b1, + 0x00000079,0x0000029d,0x0000029c,0x00000111,0x000400fa,0x0000029d,0x00000298,0x00000299, + 0x000200f8,0x00000298,0x0003003e,0x0000029e,0x00000114,0x000200f9,0x0000029f,0x000200f8, + 0x0000029f,0x000400f6,0x000002a1,0x000002a2,0x00000000,0x000200f9,0x000002a3,0x000200f8, + 0x000002a3,0x0004003d,0x00000020,0x000002a4,0x0000029e,0x000500b1,0x00000079,0x000002a5, + 0x000002a4,0x00000111,0x000400fa,0x000002a5,0x000002a0,0x000002a1,0x000200f8,0x000002a0, + 0x0004003d,0x00000062,0x000002a6,0x00000287,0x0004003d,0x00000020,0x000002a7,0x0000029e, + 0x0004006f,0x00000006,0x000002a8,0x000002a7,0x0004003d,0x00000020,0x000002a9,0x00000296, + 0x0004006f,0x00000006,0x000002aa,0x000002a9,0x00050050,0x00000062,0x000002ab,0x000002a8, + 0x000002aa,0x00050050,0x00000062,0x000002ad,0x000002ac,0x000002ac,0x00050083,0x00000062, + 0x000002ae,0x000002ab,0x000002ad,0x0005008e,0x00000062,0x000002b0,0x000002ae,0x000002af, + 0x0004003d,0x00000062,0x000002b1,0x0000028f,0x00050085,0x00000062,0x000002b2,0x000002b0, + 0x000002b1,0x00050081,0x00000062,0x000002b3,0x000002a6,0x000002b2,0x0003003e,0x000002b4, + 0x000002b3,0x00050039,0x00000064,0x000002b5,0x00000067,0x000002b4,0x0004003d,0x00000064, + 0x000002b6,0x00000294,0x00050081,0x00000064,0x000002b7,0x000002b6,0x000002b5,0x0003003e, + 0x00000294,0x000002b7,0x000200f9,0x000002a2,0x000200f8,0x000002a2,0x0004003d,0x00000020, + 0x000002b8,0x0000029e,0x00050080,0x00000020,0x000002ba,0x000002b8,0x000002b9,0x0003003e, + 0x0000029e,0x000002ba,0x000200f9,0x0000029f,0x000200f8,0x000002a1,0x000200f9,0x0000029a, + 0x000200f8,0x0000029a,0x0004003d,0x00000020,0x000002bb,0x00000296,0x00050080,0x00000020, + 0x000002bc,0x000002bb,0x000002b9,0x0003003e,0x00000296,0x000002bc,0x000200f9,0x00000297, + 0x000200f8,0x00000299,0x0004003d,0x00000275,0x000002bd,0x00000277,0x0004003d,0x00000071, + 0x000002be,0x0000026c,0x0004003d,0x00000064,0x000002bf,0x00000294,0x00060050,0x00000064, + 0x000002c0,0x000001d0,0x000001d0,0x000001d0,0x00050088,0x00000064,0x000002c1,0x000002bf, + 0x000002c0,0x00050051,0x00000006,0x000002c2,0x000002c1,0x00000000,0x00050051,0x00000006, + 0x000002c3,0x000002c1,0x00000001,0x00050051,0x00000006,0x000002c4,0x000002c1,0x00000002, + 0x00070050,0x0000020e,0x000002c5,0x000002c2,0x000002c3,0x000002c4,0x000000a1,0x00040063, + 0x000002bd,0x000002be,0x000002c5,0x000100fd,0x000200f8,0x00000286,0x0004003d,0x00000071, + 0x000002c8,0x0000026c,0x0004006f,0x00000062,0x000002c9,0x000002c8,0x00050050,0x00000062, + 0x000002ca,0x000000bd,0x000000bd,0x00050081,0x00000062,0x000002cb,0x000002c9,0x000002ca, + 0x0004003d,0x00000071,0x000002cc,0x00000274,0x0004006f,0x00000062,0x000002cd,0x000002cc, + 0x00050088,0x00000062,0x000002ce,0x000002cb,0x000002cd,0x0005008e,0x00000062,0x000002cf, + 0x000002ce,0x000000af,0x00050050,0x00000062,0x000002d0,0x000000a1,0x000000a1,0x00050083, + 0x00000062,0x000002d1,0x000002cf,0x000002d0,0x0003003e,0x000002c7,0x000002d1,0x00050041, + 0x00000007,0x000002d2,0x000002c7,0x00000238,0x0004003d,0x00000006,0x000002d3,0x000002d2, + 0x0006000c,0x00000006,0x000002d4,0x00000001,0x00000004,0x000002d3,0x00050041,0x000002d6, + 0x000002d7,0x00000216,0x000002d5,0x0004003d,0x00000006,0x000002d8,0x000002d7,0x000500ba, + 0x00000079,0x000002d9,0x000002d4,0x000002d8,0x000400a8,0x00000079,0x000002da,0x000002d9, + 0x000300f7,0x000002dc,0x00000000,0x000400fa,0x000002da,0x000002db,0x000002dc,0x000200f8, + 0x000002db,0x00050041,0x00000007,0x000002dd,0x000002c7,0x0000023d,0x0004003d,0x00000006, + 0x000002de,0x000002dd,0x0006000c,0x00000006,0x000002df,0x00000001,0x00000004,0x000002de, + 0x00050041,0x000002d6,0x000002e1,0x00000216,0x000002e0,0x0004003d,0x00000006,0x000002e2, + 0x000002e1,0x000500ba,0x00000079,0x000002e3,0x000002df,0x000002e2,0x000200f9,0x000002dc, + 0x000200f8,0x000002dc,0x000700f5,0x00000079,0x000002e4,0x000002d9,0x00000286,0x000002e3, + 0x000002db,0x000300f7,0x000002e6,0x00000000,0x000400fa,0x000002e4,0x000002e5,0x000002e6, + 0x000200f8,0x000002e5,0x0004003d,0x00000275,0x000002e7,0x00000277,0x0004003d,0x00000071, + 0x000002e8,0x0000026c,0x00040063,0x000002e7,0x000002e8,0x000002e9,0x000100fd,0x000200f8, + 0x000002e6,0x00050041,0x000002d6,0x000002eb,0x00000216,0x000002d5,0x0004003d,0x00000006, + 0x000002ec,0x000002eb,0x00050041,0x000002d6,0x000002ed,0x00000216,0x000002e0,0x0004003d, + 0x00000006,0x000002ee,0x000002ed,0x00050050,0x00000062,0x000002ef,0x000002ec,0x000002ee, + 0x0004003d,0x00000062,0x000002f0,0x000002c7,0x00050088,0x00000062,0x000002f1,0x000002f0, + 0x000002ef,0x0003003e,0x000002c7,0x000002f1,0x00050041,0x00000007,0x000002f5,0x000002c7, + 0x00000238,0x0004003d,0x00000006,0x000002f6,0x000002f5,0x0003003e,0x000002f4,0x000002f6, + 0x00050041,0x00000007,0x000002f8,0x000002c7,0x0000023d,0x0004003d,0x00000006,0x000002f9, + 0x000002f8,0x0003003e,0x000002f7,0x000002f9,0x00050041,0x000002d6,0x000002fb,0x00000216, + 0x000002f3,0x0004003d,0x00000006,0x000002fc,0x000002fb,0x0003003e,0x000002fa,0x000002fc, + 0x00070039,0x00000006,0x000002fd,0x00000056,0x000002f4,0x000002f7,0x000002fa,0x00050041, + 0x00000007,0x000002ff,0x000002c7,0x0000023d,0x0004003d,0x00000006,0x00000300,0x000002ff, + 0x0003003e,0x000002fe,0x00000300,0x00050041,0x00000007,0x00000302,0x000002c7,0x00000238, + 0x0004003d,0x00000006,0x00000303,0x00000302,0x0003003e,0x00000301,0x00000303,0x00050041, + 0x000002d6,0x00000305,0x00000216,0x000002f3,0x0004003d,0x00000006,0x00000306,0x00000305, + 0x0003003e,0x00000304,0x00000306,0x00070039,0x00000006,0x00000307,0x00000056,0x000002fe, + 0x00000301,0x00000304,0x00050050,0x00000062,0x00000308,0x000002fd,0x00000307,0x0003003e, + 0x000002f2,0x00000308,0x00050041,0x00000007,0x00000309,0x000002f2,0x00000238,0x0004003d, + 0x00000006,0x0000030a,0x00000309,0x0006000c,0x00000006,0x0000030b,0x00000001,0x00000004, + 0x0000030a,0x000500ba,0x00000079,0x0000030c,0x0000030b,0x000000a1,0x000400a8,0x00000079, + 0x0000030d,0x0000030c,0x000300f7,0x0000030f,0x00000000,0x000400fa,0x0000030d,0x0000030e, + 0x0000030f,0x000200f8,0x0000030e,0x00050041,0x00000007,0x00000310,0x000002f2,0x0000023d, + 0x0004003d,0x00000006,0x00000311,0x00000310,0x0006000c,0x00000006,0x00000312,0x00000001, + 0x00000004,0x00000311,0x000500ba,0x00000079,0x00000313,0x00000312,0x000000a1,0x000200f9, + 0x0000030f,0x000200f8,0x0000030f,0x000700f5,0x00000079,0x00000314,0x0000030c,0x000002e6, + 0x00000313,0x0000030e,0x000300f7,0x00000316,0x00000000,0x000400fa,0x00000314,0x00000315, + 0x00000316,0x000200f8,0x00000315,0x0004003d,0x00000275,0x00000317,0x00000277,0x0004003d, + 0x00000071,0x00000318,0x0000026c,0x00040063,0x00000317,0x00000318,0x000002e9,0x000100fd, + 0x000200f8,0x00000316,0x0004003d,0x00000062,0x0000031b,0x000002f2,0x0005008e,0x00000062, + 0x0000031c,0x0000031b,0x000000bd,0x00050050,0x00000062,0x0000031d,0x000000bd,0x000000bd, + 0x00050081,0x00000062,0x0000031e,0x0000031c,0x0000031d,0x0003003e,0x0000031a,0x0000031e, + 0x0004003d,0x00000062,0x00000321,0x0000031a,0x0003003e,0x00000320,0x00000321,0x00050039, + 0x00000064,0x00000322,0x00000067,0x00000320,0x0003003e,0x0000031f,0x00000322,0x00050041, + 0x000002d6,0x00000323,0x00000216,0x00000100,0x0004003d,0x00000006,0x00000324,0x00000323, + 0x000500ba,0x00000079,0x00000325,0x00000324,0x000000a0,0x000300f7,0x00000327,0x00000000, + 0x000400fa,0x00000325,0x00000326,0x00000327,0x000200f8,0x00000326,0x0003003e,0x00000328, + 0x000000a0,0x0003003e,0x00000329,0x000000a0,0x0003003e,0x0000032a,0x0000032b,0x000200f9, + 0x0000032c,0x000200f8,0x0000032c,0x000400f6,0x0000032e,0x0000032f,0x00000000,0x000200f9, + 0x00000330,0x000200f8,0x00000330,0x0004003d,0x00000020,0x00000331,0x0000032a,0x000500b3, + 0x00000079,0x00000332,0x00000331,0x000000fb,0x000400fa,0x00000332,0x0000032d,0x0000032e, + 0x000200f8,0x0000032d,0x0004003d,0x00000062,0x00000334,0x0000031a,0x0004003d,0x00000020, + 0x00000335,0x0000032a,0x0004006f,0x00000006,0x00000336,0x00000335,0x00050041,0x000002d6, + 0x00000337,0x00000216,0x00000100,0x0004003d,0x00000006,0x00000338,0x00000337,0x00050085, + 0x00000006,0x00000339,0x00000336,0x00000338,0x00050085,0x00000006,0x0000033a,0x00000339, + 0x000000bd,0x00050050,0x00000062,0x0000033b,0x0000033a,0x000000a0,0x00050081,0x00000062, + 0x0000033c,0x00000334,0x0000033b,0x0003003e,0x0000033d,0x0000033c,0x00050039,0x00000064, + 0x0000033e,0x00000067,0x0000033d,0x0003003e,0x00000333,0x0000033e,0x0004003d,0x00000020, + 0x00000340,0x0000032a,0x0003003e,0x0000033f,0x00000340,0x00050039,0x00000006,0x00000341, + 0x00000051,0x0000033f,0x00050041,0x00000007,0x00000343,0x00000333,0x00000238,0x0004003d, + 0x00000006,0x00000344,0x00000343,0x0003003e,0x00000342,0x00000344,0x00050041,0x00000007, + 0x00000346,0x00000333,0x0000023d,0x0004003d,0x00000006,0x00000347,0x00000346,0x0003003e, + 0x00000345,0x00000347,0x00050041,0x00000007,0x00000349,0x00000333,0x00000242,0x0004003d, + 0x00000006,0x0000034a,0x00000349,0x0003003e,0x00000348,0x0000034a,0x00070039,0x00000006, + 0x0000034b,0x00000039,0x00000342,0x00000345,0x00000348,0x00050085,0x00000006,0x0000034c, + 0x00000341,0x0000034b,0x0004003d,0x00000006,0x0000034d,0x00000328,0x00050081,0x00000006, + 0x0000034e,0x0000034d,0x0000034c,0x0003003e,0x00000328,0x0000034e,0x0004003d,0x00000020, + 0x00000350,0x0000032a,0x0003003e,0x0000034f,0x00000350,0x00050039,0x00000006,0x00000351, + 0x00000051,0x0000034f,0x00050041,0x00000007,0x00000353,0x00000333,0x00000238,0x0004003d, + 0x00000006,0x00000354,0x00000353,0x0003003e,0x00000352,0x00000354,0x00050041,0x00000007, + 0x00000356,0x00000333,0x0000023d,0x0004003d,0x00000006,0x00000357,0x00000356,0x0003003e, + 0x00000355,0x00000357,0x00050041,0x00000007,0x00000359,0x00000333,0x00000242,0x0004003d, + 0x00000006,0x0000035a,0x00000359,0x0003003e,0x00000358,0x0000035a,0x00070039,0x00000006, + 0x0000035b,0x0000003e,0x00000352,0x00000355,0x00000358,0x00050085,0x00000006,0x0000035c, + 0x00000351,0x0000035b,0x0004003d,0x00000006,0x0000035d,0x00000329,0x00050081,0x00000006, + 0x0000035e,0x0000035d,0x0000035c,0x0003003e,0x00000329,0x0000035e,0x000200f9,0x0000032f, + 0x000200f8,0x0000032f,0x0004003d,0x00000020,0x0000035f,0x0000032a,0x00050080,0x00000020, + 0x00000360,0x0000035f,0x000002b9,0x0003003e,0x0000032a,0x00000360,0x000200f9,0x0000032c, + 0x000200f8,0x0000032e,0x00050041,0x00000007,0x00000363,0x0000031f,0x00000238,0x0004003d, + 0x00000006,0x00000364,0x00000363,0x0003003e,0x00000362,0x00000364,0x00050041,0x00000007, + 0x00000366,0x0000031f,0x0000023d,0x0004003d,0x00000006,0x00000367,0x00000366,0x0003003e, + 0x00000365,0x00000367,0x00050041,0x00000007,0x00000369,0x0000031f,0x00000242,0x0004003d, + 0x00000006,0x0000036a,0x00000369,0x0003003e,0x00000368,0x0000036a,0x00070039,0x00000006, + 0x0000036b,0x00000034,0x00000362,0x00000365,0x00000368,0x0003003e,0x00000361,0x0000036b, + 0x0004003d,0x00000006,0x0000036d,0x00000361,0x0003003e,0x0000036c,0x0000036d,0x0004003d, + 0x00000006,0x0000036f,0x00000328,0x0003003e,0x0000036e,0x0000036f,0x0004003d,0x00000006, + 0x00000371,0x00000329,0x0003003e,0x00000370,0x00000371,0x00070039,0x00000006,0x00000372, + 0x00000043,0x0000036c,0x0000036e,0x00000370,0x0004003d,0x00000006,0x00000374,0x00000361, + 0x0003003e,0x00000373,0x00000374,0x0004003d,0x00000006,0x00000376,0x00000328,0x0003003e, + 0x00000375,0x00000376,0x0004003d,0x00000006,0x00000378,0x00000329,0x0003003e,0x00000377, + 0x00000378,0x00070039,0x00000006,0x00000379,0x00000048,0x00000373,0x00000375,0x00000377, + 0x0004003d,0x00000006,0x0000037b,0x00000361,0x0003003e,0x0000037a,0x0000037b,0x0004003d, + 0x00000006,0x0000037d,0x00000328,0x0003003e,0x0000037c,0x0000037d,0x0004003d,0x00000006, + 0x0000037f,0x00000329,0x0003003e,0x0000037e,0x0000037f,0x00070039,0x00000006,0x00000380, + 0x0000004d,0x0000037a,0x0000037c,0x0000037e,0x00060050,0x00000064,0x00000381,0x00000372, + 0x00000379,0x00000380,0x00060050,0x00000064,0x00000382,0x000000a0,0x000000a0,0x000000a0, + 0x00060050,0x00000064,0x00000383,0x000000a1,0x000000a1,0x000000a1,0x0008000c,0x00000064, + 0x00000384,0x00000001,0x0000002b,0x00000381,0x00000382,0x00000383,0x0003003e,0x0000031f, + 0x00000384,0x000200f9,0x00000327,0x000200f8,0x00000327,0x0004003d,0x00000064,0x00000387, + 0x0000031f,0x0003003e,0x00000386,0x00000387,0x00050039,0x00000064,0x00000388,0x0000006c, + 0x00000386,0x0003003e,0x00000385,0x00000388,0x0004003d,0x00000064,0x0000038a,0x00000385, + 0x00050094,0x00000006,0x0000038f,0x0000038a,0x0000038e,0x0003003e,0x00000389,0x0000038f, + 0x0004003d,0x00000006,0x00000390,0x00000389,0x00060050,0x00000064,0x00000391,0x00000390, + 0x00000390,0x00000390,0x0004003d,0x00000064,0x00000392,0x00000385,0x00050041,0x000002d6, + 0x00000394,0x00000216,0x00000393,0x0004003d,0x00000006,0x00000395,0x00000394,0x00060050, + 0x00000064,0x00000396,0x00000395,0x00000395,0x00000395,0x0008000c,0x00000064,0x00000397, + 0x00000001,0x0000002e,0x00000391,0x00000392,0x00000396,0x00060050,0x00000064,0x00000398, + 0x000000a0,0x000000a0,0x000000a0,0x0007000c,0x00000064,0x00000399,0x00000001,0x00000028, + 0x00000397,0x00000398,0x0003003e,0x00000385,0x00000399,0x00050041,0x00000007,0x0000039b, + 0x0000031a,0x0000023d,0x0004003d,0x00000006,0x0000039c,0x0000039b,0x00050041,0x000002d6, + 0x0000039d,0x00000216,0x00000114,0x0004003d,0x00000006,0x0000039e,0x0000039d,0x00050085, + 0x00000006,0x0000039f,0x0000039c,0x0000039e,0x0006000c,0x00000006,0x000003a0,0x00000001, + 0x0000000a,0x0000039f,0x00050083,0x00000006,0x000003a1,0x000003a0,0x000000bd,0x0003003e, + 0x0000039a,0x000003a1,0x0004003d,0x00000006,0x000003a3,0x0000039a,0x0003003e,0x000003a2, + 0x000003a3,0x00050041,0x00000007,0x000003a5,0x00000385,0x00000238,0x0004003d,0x00000006, + 0x000003a6,0x000003a5,0x0003003e,0x000003a4,0x000003a6,0x00050041,0x000002d6,0x000003a8, + 0x00000216,0x000002b9,0x0004003d,0x00000006,0x000003a9,0x000003a8,0x0003003e,0x000003a7, + 0x000003a9,0x00070039,0x00000006,0x000003aa,0x0000001e,0x000003a2,0x000003a4,0x000003a7, + 0x0004003d,0x00000006,0x000003ac,0x0000039a,0x0003003e,0x000003ab,0x000003ac,0x00050041, + 0x00000007,0x000003ae,0x00000385,0x0000023d,0x0004003d,0x00000006,0x000003af,0x000003ae, + 0x0003003e,0x000003ad,0x000003af,0x00050041,0x000002d6,0x000003b1,0x00000216,0x000002b9, + 0x0004003d,0x00000006,0x000003b2,0x000003b1,0x0003003e,0x000003b0,0x000003b2,0x00070039, + 0x00000006,0x000003b3,0x0000001e,0x000003ab,0x000003ad,0x000003b0,0x0004003d,0x00000006, + 0x000003b5,0x0000039a,0x0003003e,0x000003b4,0x000003b5,0x00050041,0x00000007,0x000003b7, + 0x00000385,0x00000242,0x0004003d,0x00000006,0x000003b8,0x000003b7,0x0003003e,0x000003b6, + 0x000003b8,0x00050041,0x000002d6,0x000003ba,0x00000216,0x000002b9,0x0004003d,0x00000006, + 0x000003bb,0x000003ba,0x0003003e,0x000003b9,0x000003bb,0x00070039,0x00000006,0x000003bc, + 0x0000001e,0x000003b4,0x000003b6,0x000003b9,0x00060050,0x00000064,0x000003bd,0x000003aa, + 0x000003b3,0x000003bc,0x0004003d,0x00000064,0x000003be,0x00000385,0x00050085,0x00000064, + 0x000003bf,0x000003be,0x000003bd,0x0003003e,0x00000385,0x000003bf,0x00050041,0x00000021, + 0x000003c2,0x0000026c,0x00000238,0x0004003d,0x00000020,0x000003c3,0x000003c2,0x0003003e, + 0x000003c1,0x000003c3,0x00050041,0x00000021,0x000003c5,0x0000026c,0x0000023d,0x0004003d, + 0x00000020,0x000003c6,0x000003c5,0x0003003e,0x000003c4,0x000003c6,0x00050041,0x00000218, + 0x000003c8,0x00000216,0x000003c0,0x0004003d,0x00000020,0x000003c9,0x000003c8,0x0003003e, + 0x000003c7,0x000003c9,0x0003003e,0x000003ca,0x00000114,0x00050041,0x000002d6,0x000003cc, + 0x00000216,0x000000fb,0x0004003d,0x00000006,0x000003cd,0x000003cc,0x0003003e,0x000003cb, + 0x000003cd,0x00090039,0x00000006,0x000003ce,0x0000002f,0x000003c1,0x000003c4,0x000003c7, + 0x000003ca,0x000003cb,0x00050041,0x00000021,0x000003d0,0x0000026c,0x00000238,0x0004003d, + 0x00000020,0x000003d1,0x000003d0,0x0003003e,0x000003cf,0x000003d1,0x00050041,0x00000021, + 0x000003d3,0x0000026c,0x0000023d,0x0004003d,0x00000020,0x000003d4,0x000003d3,0x0003003e, + 0x000003d2,0x000003d4,0x00050041,0x00000218,0x000003d6,0x00000216,0x000003c0,0x0004003d, + 0x00000020,0x000003d7,0x000003d6,0x0003003e,0x000003d5,0x000003d7,0x0003003e,0x000003d8, + 0x000002b9,0x00050041,0x000002d6,0x000003da,0x00000216,0x000000fb,0x0004003d,0x00000006, + 0x000003db,0x000003da,0x0003003e,0x000003d9,0x000003db,0x00090039,0x00000006,0x000003dc, + 0x0000002f,0x000003cf,0x000003d2,0x000003d5,0x000003d8,0x000003d9,0x00050041,0x00000021, + 0x000003de,0x0000026c,0x00000238,0x0004003d,0x00000020,0x000003df,0x000003de,0x0003003e, + 0x000003dd,0x000003df,0x00050041,0x00000021,0x000003e1,0x0000026c,0x0000023d,0x0004003d, + 0x00000020,0x000003e2,0x000003e1,0x0003003e,0x000003e0,0x000003e2,0x00050041,0x00000218, + 0x000003e4,0x00000216,0x000003c0,0x0004003d,0x00000020,0x000003e5,0x000003e4,0x0003003e, + 0x000003e3,0x000003e5,0x0003003e,0x000003e6,0x000000fb,0x00050041,0x000002d6,0x000003e8, + 0x00000216,0x000000fb,0x0004003d,0x00000006,0x000003e9,0x000003e8,0x0003003e,0x000003e7, + 0x000003e9,0x00090039,0x00000006,0x000003ea,0x0000002f,0x000003dd,0x000003e0,0x000003e3, + 0x000003e6,0x000003e7,0x00060050,0x00000064,0x000003eb,0x000003ce,0x000003dc,0x000003ea, + 0x0004003d,0x00000064,0x000003ec,0x00000385,0x00050085,0x00000064,0x000003ed,0x000003ec, + 0x000003eb,0x0003003e,0x00000385,0x000003ed,0x00050041,0x000002d6,0x000003ee,0x00000216, + 0x00000111,0x0004003d,0x00000006,0x000003ef,0x000003ee,0x000500ba,0x00000079,0x000003f0, + 0x000003ef,0x000000a0,0x000300f7,0x000003f2,0x00000000,0x000400fa,0x000003f0,0x000003f1, + 0x000003f2,0x000200f8,0x000003f1,0x0004003d,0x00000209,0x000003f5,0x000003f4,0x00040064, + 0x00000208,0x000003f6,0x000003f5,0x00050067,0x00000071,0x000003f7,0x000003f6,0x00000114, + 0x0004006f,0x00000062,0x000003f8,0x000003f7,0x00050050,0x00000062,0x000003f9,0x000002ac, + 0x000002ac,0x00050088,0x00000062,0x000003fa,0x000003f9,0x000003f8,0x0003003e,0x000003f3, + 0x000003fa,0x0004003d,0x00000209,0x000003fc,0x000003f4,0x0004003d,0x00000062,0x000003fd, + 0x0000031a,0x00050041,0x00000007,0x000003fe,0x000003f3,0x00000238,0x0004003d,0x00000006, + 0x000003ff,0x000003fe,0x0004007f,0x00000006,0x00000400,0x000003ff,0x00050041,0x00000007, + 0x00000401,0x000003f3,0x0000023d,0x0004003d,0x00000006,0x00000402,0x00000401,0x0004007f, + 0x00000006,0x00000403,0x00000402,0x00050050,0x00000062,0x00000404,0x00000400,0x00000403, + 0x00050081,0x00000062,0x00000405,0x000003fd,0x00000404,0x00070058,0x0000020e,0x00000406, + 0x000003fc,0x00000405,0x00000002,0x000000a0,0x0008004f,0x00000064,0x00000407,0x00000406, + 0x00000406,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000209,0x00000408,0x000003f4, + 0x0004003d,0x00000062,0x00000409,0x0000031a,0x00050041,0x00000007,0x0000040a,0x000003f3, + 0x00000238,0x0004003d,0x00000006,0x0000040b,0x0000040a,0x00050041,0x00000007,0x0000040c, + 0x000003f3,0x0000023d,0x0004003d,0x00000006,0x0000040d,0x0000040c,0x0004007f,0x00000006, + 0x0000040e,0x0000040d,0x00050050,0x00000062,0x0000040f,0x0000040b,0x0000040e,0x00050081, + 0x00000062,0x00000410,0x00000409,0x0000040f,0x00070058,0x0000020e,0x00000411,0x00000408, + 0x00000410,0x00000002,0x000000a0,0x0008004f,0x00000064,0x00000412,0x00000411,0x00000411, + 0x00000000,0x00000001,0x00000002,0x00050081,0x00000064,0x00000413,0x00000407,0x00000412, + 0x0004003d,0x00000209,0x00000414,0x000003f4,0x0004003d,0x00000062,0x00000415,0x0000031a, + 0x00050041,0x00000007,0x00000416,0x000003f3,0x00000238,0x0004003d,0x00000006,0x00000417, + 0x00000416,0x0004007f,0x00000006,0x00000418,0x00000417,0x00050041,0x00000007,0x00000419, + 0x000003f3,0x0000023d,0x0004003d,0x00000006,0x0000041a,0x00000419,0x00050050,0x00000062, + 0x0000041b,0x00000418,0x0000041a,0x00050081,0x00000062,0x0000041c,0x00000415,0x0000041b, + 0x00070058,0x0000020e,0x0000041d,0x00000414,0x0000041c,0x00000002,0x000000a0,0x0008004f, + 0x00000064,0x0000041e,0x0000041d,0x0000041d,0x00000000,0x00000001,0x00000002,0x00050081, + 0x00000064,0x0000041f,0x00000413,0x0000041e,0x0004003d,0x00000209,0x00000420,0x000003f4, + 0x0004003d,0x00000062,0x00000421,0x0000031a,0x00050041,0x00000007,0x00000422,0x000003f3, + 0x00000238,0x0004003d,0x00000006,0x00000423,0x00000422,0x00050041,0x00000007,0x00000424, + 0x000003f3,0x0000023d,0x0004003d,0x00000006,0x00000425,0x00000424,0x00050050,0x00000062, + 0x00000426,0x00000423,0x00000425,0x00050081,0x00000062,0x00000427,0x00000421,0x00000426, + 0x00070058,0x0000020e,0x00000428,0x00000420,0x00000427,0x00000002,0x000000a0,0x0008004f, + 0x00000064,0x00000429,0x00000428,0x00000428,0x00000000,0x00000001,0x00000002,0x00050081, + 0x00000064,0x0000042a,0x0000041f,0x00000429,0x0005008e,0x00000064,0x0000042b,0x0000042a, + 0x000002af,0x0003003e,0x000003fb,0x0000042b,0x00050041,0x000002d6,0x0000042c,0x00000216, + 0x00000111,0x0004003d,0x00000006,0x0000042d,0x0000042c,0x0004003d,0x00000064,0x0000042e, + 0x000003fb,0x00060050,0x00000064,0x0000042f,0x000000a0,0x000000a0,0x000000a0,0x00060050, + 0x00000064,0x00000430,0x000000a1,0x000000a1,0x000000a1,0x0008000c,0x00000064,0x00000431, + 0x00000001,0x0000002b,0x0000042e,0x0000042f,0x00000430,0x0003003e,0x00000432,0x00000431, + 0x00050039,0x00000064,0x00000433,0x0000006c,0x00000432,0x0005008e,0x00000064,0x00000434, + 0x00000433,0x0000042d,0x0004003d,0x00000064,0x00000435,0x00000385,0x00050081,0x00000064, + 0x00000436,0x00000435,0x00000434,0x0003003e,0x00000385,0x00000436,0x000200f9,0x000003f2, + 0x000200f8,0x000003f2,0x00050041,0x00000007,0x00000438,0x0000031a,0x00000238,0x0004003d, + 0x00000006,0x00000439,0x00000438,0x0003003e,0x00000437,0x00000439,0x00050041,0x00000007, + 0x0000043b,0x0000031a,0x0000023d,0x0004003d,0x00000006,0x0000043c,0x0000043b,0x0003003e, + 0x0000043a,0x0000043c,0x00050041,0x000002d6,0x0000043e,0x00000216,0x000002f3,0x0004003d, + 0x00000006,0x0000043f,0x0000043e,0x0003003e,0x0000043d,0x0000043f,0x00070039,0x00000006, + 0x00000440,0x0000005b,0x00000437,0x0000043a,0x0000043d,0x00050041,0x00000007,0x00000442, + 0x000002f2,0x00000238,0x0004003d,0x00000006,0x00000443,0x00000442,0x0003003e,0x00000441, + 0x00000443,0x00050041,0x00000007,0x00000445,0x000002f2,0x0000023d,0x0004003d,0x00000006, + 0x00000446,0x00000445,0x0003003e,0x00000444,0x00000446,0x00050041,0x000002d6,0x00000448, + 0x00000216,0x000002f3,0x0004003d,0x00000006,0x00000449,0x00000448,0x0003003e,0x00000447, + 0x00000449,0x00070039,0x00000006,0x0000044a,0x00000060,0x00000441,0x00000444,0x00000447, + 0x00050085,0x00000006,0x0000044b,0x00000440,0x0000044a,0x0004003d,0x00000064,0x0000044c, + 0x00000385,0x0005008e,0x00000064,0x0000044d,0x0000044c,0x0000044b,0x0003003e,0x00000385, + 0x0000044d,0x0004003d,0x00000064,0x0000044e,0x00000385,0x00050041,0x000002d6,0x00000453, + 0x00000216,0x00000452,0x0004003d,0x00000006,0x00000454,0x00000453,0x0008000c,0x00000006, + 0x00000455,0x00000001,0x0000002b,0x00000454,0x000000a0,0x000000a1,0x00050085,0x00000006, + 0x00000457,0x00000455,0x00000456,0x00060050,0x00000064,0x00000458,0x00000457,0x00000457, + 0x00000457,0x0008000c,0x00000064,0x00000459,0x00000001,0x0000002e,0x0000044e,0x00000451, + 0x00000458,0x0003003e,0x00000385,0x00000459,0x0004003d,0x00000275,0x0000045a,0x00000277, + 0x0004003d,0x00000071,0x0000045b,0x0000026c,0x0004003d,0x00000064,0x0000045c,0x00000385, + 0x00060050,0x00000064,0x0000045d,0x000000a0,0x000000a0,0x000000a0,0x00060050,0x00000064, + 0x0000045e,0x000000a1,0x000000a1,0x000000a1,0x0008000c,0x00000064,0x0000045f,0x00000001, + 0x0000002b,0x0000045c,0x0000045d,0x0000045e,0x0003003e,0x00000460,0x0000045f,0x00050039, + 0x00000064,0x00000461,0x0000006f,0x00000460,0x0004003d,0x00000071,0x00000463,0x0000026c, + 0x0003003e,0x00000462,0x00000463,0x00050039,0x00000006,0x00000464,0x00000075,0x00000462, + 0x00060050,0x00000064,0x00000465,0x00000464,0x00000464,0x00000464,0x00050081,0x00000064, + 0x00000466,0x00000461,0x00000465,0x00050051,0x00000006,0x00000467,0x00000466,0x00000000, + 0x00050051,0x00000006,0x00000468,0x00000466,0x00000001,0x00050051,0x00000006,0x00000469, + 0x00000466,0x00000002,0x00070050,0x0000020e,0x0000046a,0x00000467,0x00000468,0x00000469, + 0x000000a1,0x00040063,0x0000045a,0x0000045b,0x0000046a,0x000100fd,0x00010038,0x00050036, + 0x00000006,0x0000000a,0x00000000,0x00000008,0x00030037,0x00000007,0x00000009,0x000200f8, + 0x0000000b,0x0004003b,0x00000007,0x0000007b,0x00000007,0x0004003d,0x00000006,0x00000077, + 0x00000009,0x000500bc,0x00000079,0x0000007a,0x00000077,0x00000078,0x000300f7,0x0000007d, + 0x00000000,0x000400fa,0x0000007a,0x0000007c,0x00000081,0x000200f8,0x0000007c,0x0004003d, + 0x00000006,0x0000007e,0x00000009,0x00050085,0x00000006,0x00000080,0x0000007e,0x0000007f, + 0x0003003e,0x0000007b,0x00000080,0x000200f9,0x0000007d,0x000200f8,0x00000081,0x0004003d, + 0x00000006,0x00000083,0x00000009,0x0007000c,0x00000006,0x00000085,0x00000001,0x0000001a, + 0x00000083,0x00000084,0x00050085,0x00000006,0x00000086,0x00000082,0x00000085,0x00050083, + 0x00000006,0x00000088,0x00000086,0x00000087,0x0003003e,0x0000007b,0x00000088,0x000200f9, + 0x0000007d,0x000200f8,0x0000007d,0x0004003d,0x00000006,0x00000089,0x0000007b,0x000200fe, + 0x00000089,0x00010038,0x00050036,0x00000006,0x0000000d,0x00000000,0x00000008,0x00030037, + 0x00000007,0x0000000c,0x000200f8,0x0000000e,0x0004003b,0x00000007,0x0000008f,0x00000007, + 0x0004003d,0x00000006,0x0000008c,0x0000000c,0x000500bc,0x00000079,0x0000008e,0x0000008c, + 0x0000008d,0x000300f7,0x00000091,0x00000000,0x000400fa,0x0000008e,0x00000090,0x00000094, + 0x000200f8,0x00000090,0x0004003d,0x00000006,0x00000092,0x0000000c,0x00050088,0x00000006, + 0x00000093,0x00000092,0x0000007f,0x0003003e,0x0000008f,0x00000093,0x000200f9,0x00000091, + 0x000200f8,0x00000094,0x0004003d,0x00000006,0x00000095,0x0000000c,0x00050081,0x00000006, + 0x00000096,0x00000095,0x00000087,0x00050088,0x00000006,0x00000097,0x00000096,0x00000082, + 0x0007000c,0x00000006,0x00000099,0x00000001,0x0000001a,0x00000097,0x00000098,0x0003003e, + 0x0000008f,0x00000099,0x000200f9,0x00000091,0x000200f8,0x00000091,0x0004003d,0x00000006, + 0x0000009a,0x0000008f,0x000200fe,0x0000009a,0x00010038,0x00050036,0x00000006,0x00000010, + 0x00000000,0x00000008,0x00030037,0x00000007,0x0000000f,0x000200f8,0x00000011,0x0004003d, + 0x00000006,0x0000009f,0x0000000f,0x0008000c,0x00000006,0x000000a2,0x00000001,0x0000002b, + 0x0000009f,0x000000a0,0x000000a1,0x00050085,0x00000006,0x000000a3,0x0000009e,0x000000a2, + 0x00050081,0x00000006,0x000000a4,0x0000009d,0x000000a3,0x000200fe,0x000000a4,0x00010038, + 0x00050036,0x00000006,0x00000015,0x00000000,0x00000012,0x00030037,0x00000007,0x00000013, + 0x00030037,0x00000007,0x00000014,0x000200f8,0x00000016,0x0004003b,0x00000007,0x000000a7, + 0x00000007,0x0004003b,0x00000007,0x000000a8,0x00000007,0x0004003d,0x00000006,0x000000a9, + 0x00000014,0x0003003e,0x000000a8,0x000000a9,0x00050039,0x00000006,0x000000aa,0x00000010, + 0x000000a8,0x0003003e,0x000000a7,0x000000aa,0x0004003d,0x00000006,0x000000ab,0x00000013, + 0x0004007f,0x00000006,0x000000ac,0x000000ab,0x0004003d,0x00000006,0x000000ad,0x00000013, + 0x00050085,0x00000006,0x000000ae,0x000000ac,0x000000ad,0x0004003d,0x00000006,0x000000b0, + 0x000000a7,0x00050085,0x00000006,0x000000b1,0x000000af,0x000000b0,0x0004003d,0x00000006, + 0x000000b2,0x000000a7,0x00050085,0x00000006,0x000000b3,0x000000b1,0x000000b2,0x00050088, + 0x00000006,0x000000b4,0x000000ae,0x000000b3,0x0006000c,0x00000006,0x000000b5,0x00000001, + 0x0000001b,0x000000b4,0x000200fe,0x000000b5,0x00010038,0x00050036,0x00000006,0x00000018, + 0x00000000,0x00000008,0x00030037,0x00000007,0x00000017,0x000200f8,0x00000019,0x0004003b, + 0x00000007,0x000000b8,0x00000007,0x0004003b,0x00000007,0x000000b9,0x00000007,0x0004003b, + 0x00000007,0x000000bc,0x00000007,0x0004003b,0x00000007,0x000000c2,0x00000007,0x0004003b, + 0x00000007,0x000000c6,0x00000007,0x0004003d,0x00000006,0x000000ba,0x00000017,0x0003003e, + 0x000000b9,0x000000ba,0x00050039,0x00000006,0x000000bb,0x00000010,0x000000b9,0x0003003e, + 0x000000b8,0x000000bb,0x0004003d,0x00000006,0x000000be,0x000000b8,0x00050085,0x00000006, + 0x000000c0,0x000000be,0x000000bf,0x00050088,0x00000006,0x000000c1,0x000000bd,0x000000c0, + 0x0003003e,0x000000bc,0x000000c1,0x0004003d,0x00000006,0x000000c3,0x000000bc,0x0004003d, + 0x00000006,0x000000c4,0x000000bc,0x00050085,0x00000006,0x000000c5,0x000000c3,0x000000c4, + 0x0003003e,0x000000c2,0x000000c5,0x0004003d,0x00000006,0x000000c7,0x000000c2,0x0004007f, + 0x00000006,0x000000c8,0x000000c7,0x0004003d,0x00000006,0x000000cb,0x000000c2,0x00050085, + 0x00000006,0x000000cc,0x000000ca,0x000000cb,0x00050081,0x00000006,0x000000cd,0x000000c9, + 0x000000cc,0x00050085,0x00000006,0x000000ce,0x000000c8,0x000000cd,0x0004003d,0x00000006, + 0x000000cf,0x000000c2,0x00050085,0x00000006,0x000000d0,0x000000ca,0x000000cf,0x00050081, + 0x00000006,0x000000d1,0x000000a1,0x000000d0,0x00050088,0x00000006,0x000000d2,0x000000ce, + 0x000000d1,0x0006000c,0x00000006,0x000000d3,0x00000001,0x0000001b,0x000000d2,0x00050083, + 0x00000006,0x000000d4,0x000000a1,0x000000d3,0x0006000c,0x00000006,0x000000d5,0x00000001, + 0x0000001f,0x000000d4,0x0003003e,0x000000c6,0x000000d5,0x0004003d,0x00000006,0x000000d6, + 0x000000b8,0x00050085,0x00000006,0x000000d8,0x000000d6,0x000000d7,0x0004003d,0x00000006, + 0x000000d9,0x000000c6,0x00050085,0x00000006,0x000000da,0x000000d8,0x000000d9,0x000200fe, + 0x000000da,0x00010038,0x00050036,0x00000006,0x0000001e,0x00000000,0x0000001a,0x00030037, + 0x00000007,0x0000001b,0x00030037,0x00000007,0x0000001c,0x00030037,0x00000007,0x0000001d, + 0x000200f8,0x0000001f,0x0004003b,0x00000007,0x000000dd,0x00000007,0x0004003b,0x00000007, + 0x000000e0,0x00000007,0x0004003b,0x00000007,0x000000e1,0x00000007,0x0004003b,0x00000007, + 0x000000e3,0x00000007,0x0004003b,0x00000007,0x000000e6,0x00000007,0x0004003b,0x00000007, + 0x000000e7,0x00000007,0x0004003d,0x00000006,0x000000de,0x0000001d,0x0008000c,0x00000006, + 0x000000df,0x00000001,0x0000002b,0x000000de,0x000000a0,0x000000a1,0x0003003e,0x000000dd, + 0x000000df,0x0004003d,0x00000006,0x000000e2,0x0000001b,0x0003003e,0x000000e1,0x000000e2, + 0x0004003d,0x00000006,0x000000e4,0x0000001c,0x0003003e,0x000000e3,0x000000e4,0x00060039, + 0x00000006,0x000000e5,0x00000015,0x000000e1,0x000000e3,0x0003003e,0x000000e0,0x000000e5, + 0x0004003d,0x00000006,0x000000e8,0x0000001c,0x0003003e,0x000000e7,0x000000e8,0x00050039, + 0x00000006,0x000000e9,0x00000018,0x000000e7,0x00050088,0x00000006,0x000000ea,0x000000a1, + 0x000000e9,0x0003003e,0x000000e6,0x000000ea,0x0004003d,0x00000006,0x000000eb,0x000000dd, + 0x0004003d,0x00000006,0x000000ec,0x000000e0,0x00050083,0x00000006,0x000000ed,0x000000ec, + 0x000000a1,0x00050085,0x00000006,0x000000ee,0x000000eb,0x000000ed,0x00050081,0x00000006, + 0x000000ef,0x000000a1,0x000000ee,0x0004003d,0x00000006,0x000000f1,0x000000dd,0x00050085, + 0x00000006,0x000000f2,0x000000f0,0x000000f1,0x0004003d,0x00000006,0x000000f3,0x000000e6, + 0x00050083,0x00000006,0x000000f4,0x000000f3,0x000000a1,0x00050085,0x00000006,0x000000f5, + 0x000000f2,0x000000f4,0x00050081,0x00000006,0x000000f6,0x000000a1,0x000000f5,0x00050085, + 0x00000006,0x000000f7,0x000000ef,0x000000f6,0x000200fe,0x000000f7,0x00010038,0x00050036, + 0x00000006,0x00000027,0x00000000,0x00000022,0x00030037,0x00000021,0x00000023,0x00030037, + 0x00000021,0x00000024,0x00030037,0x00000021,0x00000025,0x00030037,0x00000021,0x00000026, + 0x000200f8,0x00000028,0x0004003b,0x00000021,0x0000010a,0x00000007,0x0004003d,0x00000020, + 0x000000fa,0x00000025,0x000500aa,0x00000079,0x000000fc,0x000000fa,0x000000fb,0x000300f7, + 0x000000fe,0x00000000,0x000400fa,0x000000fc,0x000000fd,0x000000fe,0x000200f8,0x000000fd, + 0x0004003d,0x00000020,0x000000ff,0x00000023,0x0005008b,0x00000020,0x00000101,0x000000ff, + 0x00000100,0x0004003d,0x00000020,0x00000102,0x00000026,0x000500aa,0x00000079,0x00000103, + 0x00000101,0x00000102,0x000600a9,0x00000006,0x00000104,0x00000103,0x000000a1,0x000000a0, + 0x000200fe,0x00000104,0x000200f8,0x000000fe,0x0004003d,0x00000020,0x00000106,0x00000025, + 0x000500aa,0x00000079,0x00000107,0x00000106,0x00000100,0x000300f7,0x00000109,0x00000000, + 0x000400fa,0x00000107,0x00000108,0x00000109,0x000200f8,0x00000108,0x0004003d,0x00000020, + 0x0000010b,0x00000024,0x0004003d,0x00000020,0x0000010c,0x00000023,0x00050087,0x00000020, + 0x0000010d,0x0000010c,0x00000100,0x0005008b,0x00000020,0x0000010e,0x0000010d,0x000000fb, + 0x00050084,0x00000020,0x0000010f,0x0000010e,0x000000fb,0x00050080,0x00000020,0x00000110, + 0x0000010b,0x0000010f,0x0005008b,0x00000020,0x00000112,0x00000110,0x00000111,0x0003003e, + 0x0000010a,0x00000112,0x0004003d,0x00000020,0x00000113,0x0000010a,0x000500ab,0x00000079, + 0x00000115,0x00000113,0x00000114,0x000300f7,0x00000117,0x00000000,0x000400fa,0x00000115, + 0x00000116,0x00000117,0x000200f8,0x00000116,0x0004003d,0x00000020,0x00000118,0x00000023, + 0x0005008b,0x00000020,0x00000119,0x00000118,0x00000100,0x0004003d,0x00000020,0x0000011a, + 0x00000026,0x000500aa,0x00000079,0x0000011b,0x00000119,0x0000011a,0x000200f9,0x00000117, + 0x000200f8,0x00000117,0x000700f5,0x00000079,0x0000011c,0x00000115,0x00000108,0x0000011b, + 0x00000116,0x000600a9,0x00000006,0x0000011d,0x0000011c,0x000000a1,0x000000a0,0x000200fe, + 0x0000011d,0x000200f8,0x00000109,0x0004003d,0x00000020,0x0000011f,0x00000025,0x000500aa, + 0x00000079,0x00000120,0x0000011f,0x00000111,0x000300f7,0x00000122,0x00000000,0x000400fa, + 0x00000120,0x00000121,0x00000122,0x000200f8,0x00000121,0x0004003d,0x00000020,0x00000123, + 0x00000023,0x0004003d,0x00000020,0x00000124,0x00000024,0x0005008b,0x00000020,0x00000125, + 0x00000124,0x000000fb,0x00050084,0x00000020,0x00000126,0x00000125,0x000000fb,0x00050080, + 0x00000020,0x00000127,0x00000123,0x00000126,0x0005008b,0x00000020,0x00000128,0x00000127, + 0x00000100,0x0004003d,0x00000020,0x00000129,0x00000026,0x000500aa,0x00000079,0x0000012a, + 0x00000128,0x00000129,0x000600a9,0x00000006,0x0000012b,0x0000012a,0x000000a1,0x000000a0, + 0x000200fe,0x0000012b,0x000200f8,0x00000122,0x000200fe,0x000000a1,0x00010038,0x00050036, + 0x00000006,0x0000002f,0x00000000,0x00000029,0x00030037,0x00000021,0x0000002a,0x00030037, + 0x00000021,0x0000002b,0x00030037,0x00000021,0x0000002c,0x00030037,0x00000021,0x0000002d, + 0x00030037,0x00000007,0x0000002e,0x000200f8,0x00000030,0x0004003b,0x00000007,0x0000012f, + 0x00000007,0x0004003b,0x00000007,0x0000013d,0x00000007,0x0004003b,0x00000021,0x0000013e, + 0x00000007,0x0004003b,0x00000021,0x00000140,0x00000007,0x0004003b,0x00000021,0x00000142, + 0x00000007,0x0004003b,0x00000021,0x00000144,0x00000007,0x0004003b,0x00000007,0x00000147, + 0x00000007,0x0004003b,0x00000007,0x0000014a,0x00000007,0x0004003d,0x00000006,0x00000130, + 0x0000002e,0x0008000c,0x00000006,0x00000131,0x00000001,0x0000002b,0x00000130,0x000000a0, + 0x000000a1,0x0003003e,0x0000012f,0x00000131,0x0004003d,0x00000020,0x00000132,0x0000002c, + 0x000500b1,0x00000079,0x00000133,0x00000132,0x000000fb,0x0004003d,0x00000020,0x00000134, + 0x0000002c,0x000500ad,0x00000079,0x00000135,0x00000134,0x00000111,0x000500a6,0x00000079, + 0x00000136,0x00000133,0x00000135,0x0004003d,0x00000006,0x00000137,0x0000012f,0x000500bc, + 0x00000079,0x00000138,0x00000137,0x000000a0,0x000500a6,0x00000079,0x00000139,0x00000136, + 0x00000138,0x000300f7,0x0000013b,0x00000000,0x000400fa,0x00000139,0x0000013a,0x0000013b, + 0x000200f8,0x0000013a,0x000200fe,0x000000a1,0x000200f8,0x0000013b,0x0004003d,0x00000020, + 0x0000013f,0x0000002a,0x0003003e,0x0000013e,0x0000013f,0x0004003d,0x00000020,0x00000141, + 0x0000002b,0x0003003e,0x00000140,0x00000141,0x0004003d,0x00000020,0x00000143,0x0000002c, + 0x0003003e,0x00000142,0x00000143,0x0004003d,0x00000020,0x00000145,0x0000002d,0x0003003e, + 0x00000144,0x00000145,0x00080039,0x00000006,0x00000146,0x00000027,0x0000013e,0x00000140, + 0x00000142,0x00000144,0x0003003e,0x0000013d,0x00000146,0x0004003d,0x00000020,0x00000148, + 0x0000002c,0x000500aa,0x00000079,0x00000149,0x00000148,0x00000100,0x000300f7,0x0000014c, + 0x00000000,0x000400fa,0x00000149,0x0000014b,0x00000152,0x000200f8,0x0000014b,0x0004003d, + 0x00000006,0x0000014d,0x0000012f,0x00050085,0x00000006,0x0000014f,0x0000014d,0x0000014e, + 0x00050088,0x00000006,0x00000151,0x0000014f,0x00000150,0x0003003e,0x0000014a,0x00000151, + 0x000200f9,0x0000014c,0x000200f8,0x00000152,0x0004003d,0x00000006,0x00000153,0x0000012f, + 0x00050085,0x00000006,0x00000154,0x00000153,0x000000af,0x00050088,0x00000006,0x00000155, + 0x00000154,0x0000014e,0x0003003e,0x0000014a,0x00000155,0x000200f9,0x0000014c,0x000200f8, + 0x0000014c,0x0004003d,0x00000006,0x00000156,0x0000014a,0x0003003e,0x00000147,0x00000156, + 0x0004003d,0x00000006,0x00000157,0x0000012f,0x00050083,0x00000006,0x00000158,0x000000a1, + 0x00000157,0x0004003d,0x00000006,0x00000159,0x0000012f,0x0004003d,0x00000006,0x0000015a, + 0x0000013d,0x00050085,0x00000006,0x0000015b,0x00000159,0x0000015a,0x00050081,0x00000006, + 0x0000015c,0x00000158,0x0000015b,0x0004003d,0x00000006,0x0000015d,0x00000147,0x00050085, + 0x00000006,0x0000015e,0x000000bd,0x0000015d,0x00050083,0x00000006,0x0000015f,0x000000a1, + 0x0000015e,0x00050088,0x00000006,0x00000160,0x0000015c,0x0000015f,0x000200fe,0x00000160, + 0x00010038,0x00050036,0x00000006,0x00000034,0x00000000,0x0000001a,0x00030037,0x00000007, + 0x00000031,0x00030037,0x00000007,0x00000032,0x00030037,0x00000007,0x00000033,0x000200f8, + 0x00000035,0x0004003d,0x00000006,0x00000164,0x00000031,0x00050085,0x00000006,0x00000165, + 0x00000163,0x00000164,0x0004003d,0x00000006,0x00000167,0x00000032,0x00050085,0x00000006, + 0x00000168,0x00000166,0x00000167,0x00050081,0x00000006,0x00000169,0x00000165,0x00000168, + 0x0004003d,0x00000006,0x0000016b,0x00000033,0x00050085,0x00000006,0x0000016c,0x0000016a, + 0x0000016b,0x00050081,0x00000006,0x0000016d,0x00000169,0x0000016c,0x000200fe,0x0000016d, + 0x00010038,0x00050036,0x00000006,0x00000039,0x00000000,0x0000001a,0x00030037,0x00000007, + 0x00000036,0x00030037,0x00000007,0x00000037,0x00030037,0x00000007,0x00000038,0x000200f8, + 0x0000003a,0x0004003d,0x00000006,0x00000171,0x00000036,0x00050085,0x00000006,0x00000172, + 0x00000170,0x00000171,0x0004003d,0x00000006,0x00000174,0x00000037,0x00050085,0x00000006, + 0x00000175,0x00000173,0x00000174,0x00050083,0x00000006,0x00000176,0x00000172,0x00000175, + 0x0004003d,0x00000006,0x00000178,0x00000038,0x00050085,0x00000006,0x00000179,0x00000177, + 0x00000178,0x00050083,0x00000006,0x0000017a,0x00000176,0x00000179,0x000200fe,0x0000017a, + 0x00010038,0x00050036,0x00000006,0x0000003e,0x00000000,0x0000001a,0x00030037,0x00000007, + 0x0000003b,0x00030037,0x00000007,0x0000003c,0x00030037,0x00000007,0x0000003d,0x000200f8, + 0x0000003f,0x0004003d,0x00000006,0x0000017e,0x0000003b,0x00050085,0x00000006,0x0000017f, + 0x0000017d,0x0000017e,0x0004003d,0x00000006,0x00000181,0x0000003c,0x00050085,0x00000006, + 0x00000182,0x00000180,0x00000181,0x00050083,0x00000006,0x00000183,0x0000017f,0x00000182, + 0x0004003d,0x00000006,0x00000185,0x0000003d,0x00050085,0x00000006,0x00000186,0x00000184, + 0x00000185,0x00050081,0x00000006,0x00000187,0x00000183,0x00000186,0x000200fe,0x00000187, + 0x00010038,0x00050036,0x00000006,0x00000043,0x00000000,0x0000001a,0x00030037,0x00000007, + 0x00000040,0x00030037,0x00000007,0x00000041,0x00030037,0x00000007,0x00000042,0x000200f8, + 0x00000044,0x0004003d,0x00000006,0x0000018a,0x00000040,0x0004003d,0x00000006,0x0000018c, + 0x00000041,0x00050085,0x00000006,0x0000018d,0x0000018b,0x0000018c,0x00050081,0x00000006, + 0x0000018e,0x0000018a,0x0000018d,0x0004003d,0x00000006,0x00000190,0x00000042,0x00050085, + 0x00000006,0x00000191,0x0000018f,0x00000190,0x00050081,0x00000006,0x00000192,0x0000018e, + 0x00000191,0x000200fe,0x00000192,0x00010038,0x00050036,0x00000006,0x00000048,0x00000000, + 0x0000001a,0x00030037,0x00000007,0x00000045,0x00030037,0x00000007,0x00000046,0x00030037, + 0x00000007,0x00000047,0x000200f8,0x00000049,0x0004003d,0x00000006,0x00000195,0x00000045, + 0x0004003d,0x00000006,0x00000197,0x00000046,0x00050085,0x00000006,0x00000198,0x00000196, + 0x00000197,0x00050083,0x00000006,0x00000199,0x00000195,0x00000198,0x0004003d,0x00000006, + 0x0000019b,0x00000047,0x00050085,0x00000006,0x0000019c,0x0000019a,0x0000019b,0x00050083, + 0x00000006,0x0000019d,0x00000199,0x0000019c,0x000200fe,0x0000019d,0x00010038,0x00050036, + 0x00000006,0x0000004d,0x00000000,0x0000001a,0x00030037,0x00000007,0x0000004a,0x00030037, + 0x00000007,0x0000004b,0x00030037,0x00000007,0x0000004c,0x000200f8,0x0000004e,0x0004003d, + 0x00000006,0x000001a0,0x0000004a,0x0004003d,0x00000006,0x000001a2,0x0000004b,0x00050085, + 0x00000006,0x000001a3,0x000001a1,0x000001a2,0x00050083,0x00000006,0x000001a4,0x000001a0, + 0x000001a3,0x0004003d,0x00000006,0x000001a6,0x0000004c,0x00050085,0x00000006,0x000001a7, + 0x000001a5,0x000001a6,0x00050081,0x00000006,0x000001a8,0x000001a4,0x000001a7,0x000200fe, + 0x000001a8,0x00010038,0x00050036,0x00000006,0x00000051,0x00000000,0x0000004f,0x00030037, + 0x00000021,0x00000050,0x000200f8,0x00000052,0x0004003b,0x00000021,0x000001ad,0x00000007, + 0x0004003d,0x00000020,0x000001ab,0x00000050,0x000500b1,0x00000079,0x000001ac,0x000001ab, + 0x00000114,0x000300f7,0x000001af,0x00000000,0x000400fa,0x000001ac,0x000001ae,0x000001b2, + 0x000200f8,0x000001ae,0x0004003d,0x00000020,0x000001b0,0x00000050,0x0004007e,0x00000020, + 0x000001b1,0x000001b0,0x0003003e,0x000001ad,0x000001b1,0x000200f9,0x000001af,0x000200f8, + 0x000001b2,0x0004003d,0x00000020,0x000001b3,0x00000050,0x0003003e,0x000001ad,0x000001b3, + 0x000200f9,0x000001af,0x000200f8,0x000001af,0x0004003d,0x00000020,0x000001b4,0x000001ad, + 0x0004006f,0x00000006,0x000001b5,0x000001b4,0x00050083,0x00000006,0x000001b6,0x0000014e, + 0x000001b5,0x00050088,0x00000006,0x000001b8,0x000001b6,0x000001b7,0x000200fe,0x000001b8, + 0x00010038,0x00050036,0x00000006,0x00000056,0x00000000,0x0000001a,0x00030037,0x00000007, + 0x00000053,0x00030037,0x00000007,0x00000054,0x00030037,0x00000007,0x00000055,0x000200f8, + 0x00000057,0x0004003d,0x00000006,0x000001bb,0x00000053,0x0004003d,0x00000006,0x000001bc, + 0x00000055,0x0004003d,0x00000006,0x000001bd,0x00000053,0x0004003d,0x00000006,0x000001be, + 0x00000053,0x00050085,0x00000006,0x000001bf,0x000001bd,0x000001be,0x0004003d,0x00000006, + 0x000001c0,0x00000054,0x0004003d,0x00000006,0x000001c1,0x00000054,0x00050085,0x00000006, + 0x000001c2,0x000001c0,0x000001c1,0x00050081,0x00000006,0x000001c3,0x000001bf,0x000001c2, + 0x00050085,0x00000006,0x000001c4,0x000001bc,0x000001c3,0x00050081,0x00000006,0x000001c5, + 0x000000a1,0x000001c4,0x00050085,0x00000006,0x000001c6,0x000001bb,0x000001c5,0x000200fe, + 0x000001c6,0x00010038,0x00050036,0x00000006,0x0000005b,0x00000000,0x0000001a,0x00030037, + 0x00000007,0x00000058,0x00030037,0x00000007,0x00000059,0x00030037,0x00000007,0x0000005a, + 0x000200f8,0x0000005c,0x0004003b,0x00000007,0x000001c9,0x00000007,0x0004003b,0x00000007, + 0x000001cf,0x00000007,0x0004003d,0x00000006,0x000001ca,0x0000005a,0x00050085,0x00000006, + 0x000001cc,0x000001ca,0x000001cb,0x0008000c,0x00000006,0x000001ce,0x00000001,0x0000002b, + 0x000001cc,0x000000a0,0x000001cd,0x0003003e,0x000001c9,0x000001ce,0x0004003d,0x00000006, + 0x000001d1,0x00000058,0x00050085,0x00000006,0x000001d2,0x000001d0,0x000001d1,0x0004003d, + 0x00000006,0x000001d3,0x00000059,0x00050085,0x00000006,0x000001d4,0x000001d2,0x000001d3, + 0x0004003d,0x00000006,0x000001d5,0x00000058,0x00050083,0x00000006,0x000001d6,0x000000a1, + 0x000001d5,0x00050085,0x00000006,0x000001d7,0x000001d4,0x000001d6,0x0004003d,0x00000006, + 0x000001d8,0x00000059,0x00050083,0x00000006,0x000001d9,0x000000a1,0x000001d8,0x00050085, + 0x00000006,0x000001da,0x000001d7,0x000001d9,0x0008000c,0x00000006,0x000001db,0x00000001, + 0x0000002b,0x000001da,0x000000a0,0x000000a1,0x0003003e,0x000001cf,0x000001db,0x0004003d, + 0x00000006,0x000001dc,0x000001c9,0x0004003d,0x00000006,0x000001dd,0x000001cf,0x0006000c, + 0x00000006,0x000001de,0x00000001,0x0000001f,0x000001dd,0x0006000c,0x00000006,0x000001df, + 0x00000001,0x0000001f,0x000001de,0x00050083,0x00000006,0x000001e0,0x000000a1,0x000001df, + 0x00050085,0x00000006,0x000001e1,0x000001dc,0x000001e0,0x00050083,0x00000006,0x000001e2, + 0x000000a1,0x000001e1,0x000200fe,0x000001e2,0x00010038,0x00050036,0x00000006,0x00000060, + 0x00000000,0x0000001a,0x00030037,0x00000007,0x0000005d,0x00030037,0x00000007,0x0000005e, + 0x00030037,0x00000007,0x0000005f,0x000200f8,0x00000061,0x0004003b,0x00000007,0x000001ea, + 0x00000007,0x0004003b,0x00000007,0x000001f0,0x00000007,0x0004003b,0x00000007,0x000001f5, + 0x00000007,0x0004003d,0x00000006,0x000001e5,0x0000005f,0x000500bc,0x00000079,0x000001e6, + 0x000001e5,0x000000a0,0x000300f7,0x000001e8,0x00000000,0x000400fa,0x000001e6,0x000001e7, + 0x000001e8,0x000200f8,0x000001e7,0x000200fe,0x000000a1,0x000200f8,0x000001e8,0x0004003d, + 0x00000006,0x000001eb,0x0000005d,0x0006000c,0x00000006,0x000001ec,0x00000001,0x00000004, + 0x000001eb,0x00050083,0x00000006,0x000001ee,0x000001ec,0x000001ed,0x0007000c,0x00000006, + 0x000001ef,0x00000001,0x00000028,0x000001ee,0x000000a0,0x0003003e,0x000001ea,0x000001ef, + 0x0004003d,0x00000006,0x000001f1,0x0000005e,0x0006000c,0x00000006,0x000001f2,0x00000001, + 0x00000004,0x000001f1,0x00050083,0x00000006,0x000001f3,0x000001f2,0x000001ed,0x0007000c, + 0x00000006,0x000001f4,0x00000001,0x00000028,0x000001f3,0x000000a0,0x0003003e,0x000001f0, + 0x000001f4,0x0004003d,0x00000006,0x000001f6,0x000001ea,0x0004003d,0x00000006,0x000001f7, + 0x000001ea,0x00050085,0x00000006,0x000001f8,0x000001f6,0x000001f7,0x0004003d,0x00000006, + 0x000001f9,0x000001f0,0x0004003d,0x00000006,0x000001fa,0x000001f0,0x00050085,0x00000006, + 0x000001fb,0x000001f9,0x000001fa,0x00050081,0x00000006,0x000001fc,0x000001f8,0x000001fb, + 0x0006000c,0x00000006,0x000001fd,0x00000001,0x0000001f,0x000001fc,0x00050088,0x00000006, + 0x000001ff,0x000001fd,0x000001fe,0x0003003e,0x000001f5,0x000001ff,0x0004003d,0x00000006, + 0x00000200,0x000001f5,0x00050083,0x00000006,0x00000201,0x000000a1,0x00000200,0x00050085, + 0x00000006,0x00000203,0x00000201,0x00000202,0x0008000c,0x00000006,0x00000204,0x00000001, + 0x0000002b,0x00000203,0x000000a0,0x000000a1,0x000200fe,0x00000204,0x00010038,0x00050036, + 0x00000064,0x00000067,0x00000000,0x00000065,0x00030037,0x00000063,0x00000066,0x000200f8, + 0x00000068,0x0004003b,0x00000069,0x00000207,0x00000007,0x0004003b,0x0000021e,0x0000021f, + 0x00000007,0x0004003d,0x00000209,0x0000020c,0x0000020b,0x0004003d,0x00000062,0x0000020d, + 0x00000066,0x00070058,0x0000020e,0x0000020f,0x0000020c,0x0000020d,0x00000002,0x000000a0, + 0x0008004f,0x00000064,0x00000210,0x0000020f,0x0000020f,0x00000000,0x00000001,0x00000002, + 0x00060050,0x00000064,0x00000211,0x000000a0,0x000000a0,0x000000a0,0x00060050,0x00000064, + 0x00000212,0x000000a1,0x000000a1,0x000000a1,0x0008000c,0x00000064,0x00000213,0x00000001, + 0x0000002b,0x00000210,0x00000211,0x00000212,0x0003003e,0x00000207,0x00000213,0x00050041, + 0x00000218,0x00000219,0x00000216,0x00000217,0x0004003d,0x00000020,0x0000021a,0x00000219, + 0x000500ab,0x00000079,0x0000021b,0x0000021a,0x00000114,0x000300f7,0x0000021d,0x00000000, + 0x000400fa,0x0000021b,0x0000021c,0x0000021d,0x000200f8,0x0000021c,0x0004003d,0x00000209, + 0x00000221,0x00000220,0x0004003d,0x00000062,0x00000222,0x00000066,0x00070058,0x0000020e, + 0x00000223,0x00000221,0x00000222,0x00000002,0x000000a0,0x00070050,0x0000020e,0x00000224, + 0x000000a0,0x000000a0,0x000000a0,0x000000a0,0x00070050,0x0000020e,0x00000225,0x000000a1, + 0x000000a1,0x000000a1,0x000000a1,0x0008000c,0x0000020e,0x00000226,0x00000001,0x0000002b, + 0x00000223,0x00000224,0x00000225,0x0003003e,0x0000021f,0x00000226,0x0004003d,0x0000020e, + 0x00000227,0x0000021f,0x0008004f,0x00000064,0x00000228,0x00000227,0x00000227,0x00000000, + 0x00000001,0x00000002,0x0004003d,0x00000064,0x00000229,0x00000207,0x00050041,0x00000007, + 0x0000022c,0x0000021f,0x0000022b,0x0004003d,0x00000006,0x0000022d,0x0000022c,0x00050083, + 0x00000006,0x0000022e,0x000000a1,0x0000022d,0x0005008e,0x00000064,0x0000022f,0x00000229, + 0x0000022e,0x00050081,0x00000064,0x00000230,0x00000228,0x0000022f,0x0003003e,0x00000207, + 0x00000230,0x000200f9,0x0000021d,0x000200f8,0x0000021d,0x0004003d,0x00000064,0x00000231, + 0x00000207,0x00060050,0x00000064,0x00000232,0x000000a0,0x000000a0,0x000000a0,0x00060050, + 0x00000064,0x00000233,0x000000a1,0x000000a1,0x000000a1,0x0008000c,0x00000064,0x00000234, + 0x00000001,0x0000002b,0x00000231,0x00000232,0x00000233,0x000200fe,0x00000234,0x00010038, + 0x00050036,0x00000064,0x0000006c,0x00000000,0x0000006a,0x00030037,0x00000069,0x0000006b, + 0x000200f8,0x0000006d,0x0004003b,0x00000007,0x00000237,0x00000007,0x0004003b,0x00000007, + 0x0000023c,0x00000007,0x0004003b,0x00000007,0x00000241,0x00000007,0x00050041,0x00000007, + 0x00000239,0x0000006b,0x00000238,0x0004003d,0x00000006,0x0000023a,0x00000239,0x0003003e, + 0x00000237,0x0000023a,0x00050039,0x00000006,0x0000023b,0x0000000d,0x00000237,0x00050041, + 0x00000007,0x0000023e,0x0000006b,0x0000023d,0x0004003d,0x00000006,0x0000023f,0x0000023e, + 0x0003003e,0x0000023c,0x0000023f,0x00050039,0x00000006,0x00000240,0x0000000d,0x0000023c, + 0x00050041,0x00000007,0x00000243,0x0000006b,0x00000242,0x0004003d,0x00000006,0x00000244, + 0x00000243,0x0003003e,0x00000241,0x00000244,0x00050039,0x00000006,0x00000245,0x0000000d, + 0x00000241,0x00060050,0x00000064,0x00000246,0x0000023b,0x00000240,0x00000245,0x000200fe, + 0x00000246,0x00010038,0x00050036,0x00000064,0x0000006f,0x00000000,0x0000006a,0x00030037, + 0x00000069,0x0000006e,0x000200f8,0x00000070,0x0004003b,0x00000007,0x00000249,0x00000007, + 0x0004003b,0x00000007,0x0000024d,0x00000007,0x0004003b,0x00000007,0x00000251,0x00000007, + 0x00050041,0x00000007,0x0000024a,0x0000006e,0x00000238,0x0004003d,0x00000006,0x0000024b, + 0x0000024a,0x0003003e,0x00000249,0x0000024b,0x00050039,0x00000006,0x0000024c,0x0000000a, + 0x00000249,0x00050041,0x00000007,0x0000024e,0x0000006e,0x0000023d,0x0004003d,0x00000006, + 0x0000024f,0x0000024e,0x0003003e,0x0000024d,0x0000024f,0x00050039,0x00000006,0x00000250, + 0x0000000a,0x0000024d,0x00050041,0x00000007,0x00000252,0x0000006e,0x00000242,0x0004003d, + 0x00000006,0x00000253,0x00000252,0x0003003e,0x00000251,0x00000253,0x00050039,0x00000006, + 0x00000254,0x0000000a,0x00000251,0x00060050,0x00000064,0x00000255,0x0000024c,0x00000250, + 0x00000254,0x000200fe,0x00000255,0x00010038,0x00050036,0x00000006,0x00000075,0x00000000, + 0x00000073,0x00030037,0x00000072,0x00000074,0x000200f8,0x00000076,0x00050041,0x00000021, + 0x0000025a,0x00000074,0x00000238,0x0004003d,0x00000020,0x0000025b,0x0000025a,0x0004006f, + 0x00000006,0x0000025c,0x0000025b,0x00050085,0x00000006,0x0000025d,0x00000259,0x0000025c, + 0x00050041,0x00000021,0x0000025f,0x00000074,0x0000023d,0x0004003d,0x00000020,0x00000260, + 0x0000025f,0x0004006f,0x00000006,0x00000261,0x00000260,0x00050085,0x00000006,0x00000262, + 0x0000025e,0x00000261,0x00050081,0x00000006,0x00000263,0x0000025d,0x00000262,0x0006000c, + 0x00000006,0x00000264,0x00000001,0x0000000a,0x00000263,0x00050085,0x00000006,0x00000265, + 0x00000258,0x00000264,0x0006000c,0x00000006,0x00000266,0x00000001,0x0000000a,0x00000265, + 0x00050083,0x00000006,0x00000267,0x00000266,0x000000bd,0x00050088,0x00000006,0x00000269, + 0x00000267,0x00000268,0x000200fe,0x00000269,0x00010038 +}; diff --git a/gpu/vk/tests/present_rect_test.cpp b/gpu/vk/tests/present_rect_test.cpp index 9648e76..aa881fa 100644 --- a/gpu/vk/tests/present_rect_test.cpp +++ b/gpu/vk/tests/present_rect_test.cpp @@ -1,6 +1,8 @@ // Game-free regression for the production Vulkan presentation rectangle helper. #include #include +#include +#include #include #include "../vk_present_rect.h" @@ -37,6 +39,31 @@ int main() { {0, 0, 5120, 1440}); expect("logical portrait content", mkwvk::present_rect(1920, 1080, nullptr, 1600, 1000, {0.5}), {550, 0, 500, 1000}); + // (Triforce) An Output resolution of its own shape is the picture (gpu/vk/output_sizes.h), and the host gives its shape as a + // float (host/hos_main.c hos_aspect_ratio): on a screen of that size it fills it pixel for pixel, with no bar from the float; + // the window it opens in (720 high) has its shape; a screen or a window of another shape shows it whole between bars + struct Own { + uint32_t w, h; + }; + for (const Own o : {Own{3840, 1600}, Own{3440, 1440}, Own{2560, 1080}, Own{5120, 1440}, Own{5120, 2160}, Own{1920, 1200}, + Own{1280, 1024}}) { + const PresentAspect own{static_cast((double)o.w / (double)o.h)}; + expect("an output size's picture on its own screen", mkwvk::present_rect(o.w, o.h, nullptr, o.w, o.h, own), {0, 0, o.w, o.h}); + const uint32_t win_w = static_cast(720 * static_cast(own.ratio) + 0.5f); // (host/display.c) + expect("an output size's picture in its starting window", mkwvk::present_rect(o.w, o.h, nullptr, win_w, 720, own), + {0, 0, win_w, 720}); + } + constexpr PresentAspect twelve_five{static_cast(3840.0 / 1600.0)}; + expect("3840x1600 picture, fullscreen on a 3840x2160 screen", + mkwvk::present_rect(3840, 1600, nullptr, 3840, 2160, twelve_five), {0, 280, 3840, 1600}); + expect("3840x1600 picture, fullscreen on a 3440x1440 screen", + mkwvk::present_rect(3840, 1600, nullptr, 3440, 1440, twelve_five), {0, 3, 3440, 1433}); + expect("3840x1600 picture in a 16:9 window", mkwvk::present_rect(3840, 1600, nullptr, 1280, 720, twelve_five), + {0, 93, 1280, 533}); + expect("3440x1440 picture, fullscreen on a 3840x1600 screen", + mkwvk::present_rect(3440, 1440, nullptr, 3840, 1600, {static_cast(3440.0 / 1440.0)}), {9, 0, 3822, 1600}); + expect("1920x1200 picture, fullscreen on a 1920x1080 screen", + mkwvk::present_rect(1920, 1200, nullptr, 1920, 1080, {1.6f}), {96, 0, 1728, 1080}); expect("ultrawide source aspect fits naturally", mkwvk::present_rect(3440, 1440, nullptr, 3440, 1440), {0, 0, 3440, 1440}); expect("ultrawide source remains wider than 16:9", diff --git a/gpu/vk/ultrawide_rows.h b/gpu/vk/ultrawide_rows.h index ee17967..5457240 100644 --- a/gpu/vk/ultrawide_rows.h +++ b/gpu/vk/ultrawide_rows.h @@ -3,7 +3,15 @@ 2 a fixed 21:9 (64:27, the shape of a 2560 x 1080 or a 5120 x 2160 screen), 3 a fixed 32:9. A value past the row is its nearest end. Before options_version 6 the row's 1 was "Monitor's shape" (the main monitor's own ratio): such a file's 1 is read as the shape nearest the main monitor's, ultrawide_row_nearest, so its picture stays as it was on the common screens (16:9, 16:10, - 21:9 and 32:9 ones; a 4:3 one gets 16:10). Plain C, no includes: the host's C and the renderer's C++ both take it. */ + 21:9 and 32:9 ones; a 4:3 one gets 16:10). + (Triforce) The row is the shape of a 16:9 Output resolution, at its height. A screen of another shape than these four (a + 3440 x 1440 or a 3840 x 1600 one) is not a fifth value here: its size is an Output resolution (Screen, or Custom), which is + then the picture by itself, and the row shows that shape with nothing to choose (gpu/vk/output_sizes.h, vk_menu.cpp + tx_shape). ((Triforce, 11-22, N64 Classic, step 6) 4, a fixed 4:3: the 1998 TV's shape, the + picture the game's height and narrower, its cameras 4:3, the HUD across its width (host/hos_main.c's path for a shape + narrower than 16:9); the nearest shape of an old file's Monitor's shape is still one of the first four.) + So the row keeps the four fixed shapes, each the same picture on every PC, and no value of it follows the monitor. + Plain C, no includes: the host's C and the renderer's C++ both take it. */ #ifndef ULTRAWIDE_ROWS_H #define ULTRAWIDE_ROWS_H @@ -11,10 +19,11 @@ static inline float ultrawide_row_ratio(int row) { if (row <= 0) return 0.0f; if (row == 1) return 1.6f; + if (row >= 4) return (float)(4.0 / 3.0); /* ((Triforce, N64 Classic) 4:3, the row's last) */ return row == 2 ? (float)(64.0 / 27.0) : (float)(32.0 / 9.0); } -/* Whether the row's shape is wider than the game's 16:9: 21:9 and 32:9 (16:10 is narrower, 1.6). The HUD position and the +/* Whether the row's shape is wider than the game's 16:9: 21:9 and 32:9 (16:10 and 4:3 are narrower). The HUD position and the menu sides act only on such a picture's sides (gpu/vk/vk_menu.cpp row_shown) */ static inline int ultrawide_row_wider(int row) { return ultrawide_row_ratio(row) > (float)(16.0 / 9.0); } diff --git a/gpu/vk/upscale_off.h b/gpu/vk/upscale_off.h index 84ef8fb..c44ece4 100644 --- a/gpu/vk/upscale_off.h +++ b/gpu/vk/upscale_off.h @@ -16,9 +16,10 @@ namespace upscale_off { struct Choice { - bool stand_in; // the stretch draws the dispatch's output; the network is not dispatched - bool temporal; // as the stand-in was before: its history bound and FXAA. false: the plain linear stretch - bool by_shape; // taken for its shape alone: the caller must still see the scene's formats at both ends + bool stand_in; // the stretch draws the dispatch's output; the network is not dispatched + bool temporal; // as the stand-in was before: its history bound and FXAA. false: the plain linear stretch + bool by_shape; // taken for its shape alone: the caller must still see the scene's formats at both ends + bool n64 = false; // ((Triforce, N64 Classic) N64 Classic's 3D pass draws it in place of the stretch: n64_rules.h) }; /// listed: the program is one RX_VK_TAAU_KEYS names (by default fd029a317a9a4b94 on software multiplies); @@ -30,5 +31,13 @@ constexpr Choice choose(bool listed, bool off, bool by_key, bool shaped) { if (off && shaped && !listed) return {true, false, true}; return {listed, true, false}; } +/// ((Triforce, 11-22, N64 Classic, step 2) n64: N64 Classic's 3D pass is on (vk_n64.cpp n64_3d_now). It takes every gameplay +/// upscale, by key or by its shape, over the stretch and over the list: the mode is the 3D's look, not a cheaper upscale. +/// Without it, as above +constexpr Choice choose(bool listed, bool off, bool by_key, bool shaped, bool n64) { + if (n64 && by_key) return {true, false, false, true}; + if (n64 && shaped) return {true, false, true, true}; + return choose(listed, off, by_key, shaped); +} } // namespace upscale_off diff --git a/gpu/vk/upscaler_rows.h b/gpu/vk/upscaler_rows.h index 82efeeb..fc4105c 100644 --- a/gpu/vk/upscaler_rows.h +++ b/gpu/vk/upscaler_rows.h @@ -185,6 +185,12 @@ inline int auto_filter(unsigned picture_w, unsigned picture_h, unsigned dest_w, inline int window_filter(unsigned picture_w, unsigned picture_h, unsigned dest_w, unsigned dest_h, bool native_hdr) { return native_hdr ? 0 : auto_filter(picture_w, picture_h, dest_w, dest_h); } +/// ((Triforce, 11-22, N64 Classic, step 4) opts.upscale's value while N64 Classic's TV runs (vk_framegen.cpp framegen_scale): +/// its pass in the filter's place, at the window's own pixels, at every present (the TV is the whole picture's look, at 1:1 +/// too). Past the filters RX_VK_UPSCALE can name (0 to 3) +constexpr int kTvFilter = 4; +/// The window's filter for a present with the TV: kTvFilter while it runs (tv: vk_n64.cpp n64_tv_now), else window_filter's +inline int tv_filter(int filter, bool tv) { return tv ? kTvFilter : filter; } /// The DLSS model row (opts.dlss_model, saved as dlss_model): which of NVIDIA's networks DLSS and DLAA draw with, by its /// preset (NVSDK_NGX_DLSS_Hint_Render_Preset_*). 0 the transformer, preset K (the default here, the one tested); 1 the second diff --git a/gpu/vk/vk_aa.cpp b/gpu/vk/vk_aa.cpp index 9e0bbb4..e5e14de 100644 --- a/gpu/vk/vk_aa.cpp +++ b/gpu/vk/vk_aa.cpp @@ -19,6 +19,7 @@ #include "vk_aa.h" #include "vk_fsr3.h" // (fsr3_wanted: AMD FSR 3.1 upscales, with its own anti-aliasing) #include "vk_menu.h" +#include "vk_n64.h" // ((Triforce, N64 Classic) the game's SMAA left out while its 3D pass draws: choice_now) #include "vk_temporal.h" // (temporal_mode: NVIDIA DLSS or AMD FSR 4 does) #include "vk_texture.h" // (texture_frame_no) @@ -54,6 +55,13 @@ bool keep_passes() { }(); return on; } +/// The row's choice, RX_VK_AA over it, and ((Triforce, 11-22, N64 Classic) Off while N64 Classic's 3D pass draws the gameplay +/// upscale (n64_rules.h anti_aliasing): the grid's averaging smooths the edges, so the game's edge and weight passes go +/// too. RX_VK_AA still goes over it, for an A/B +int choice_now() { + const int choice = ar::chosen(opts.aa, env_choice()); + return env_choice() >= 0 ? choice : n64_rules::anti_aliasing(n64_in_front(), choice); +} /// What upscales now, as the menu's Upscaler row shows it (vk_menu.cpp upscaler) int upscaler_now() { if (fsr3_wanted()) return fsr3_native() ? upscaler_rows::FSR3_AA : upscaler_rows::FSR3; @@ -358,7 +366,7 @@ int aa_mode() { State& s = st(); std::lock_guard lk(s.mu); if (frame_read.load(std::memory_order_relaxed) != frame) { - const int choice = ar::chosen(opts.aa, env_choice()); + const int choice = choice_now(); // ((Triforce, FSR3-06, FSR4-5) with an upscaler after the bloom, none: aa_rows.h effective) const int want = ar::effective(choice, upscaler_now(), temporal_before_bloom(), env_choice() >= 0); frame_begun(s, frame, want); @@ -370,7 +378,7 @@ int aa_mode() { int aa_env_choice() { return env_choice(); } -bool aa_asked() { return ar::chosen(opts.aa, env_choice()) != ar::GAME || engaged.load(std::memory_order_relaxed) || upscaler_asks(); } +bool aa_asked() { return choice_now() != ar::GAME || engaged.load(std::memory_order_relaxed) || upscaler_asks(); } bool aa_leave_out(uint64_t key) { if (!aa_asked()) return false; diff --git a/gpu/vk/vk_api.h b/gpu/vk/vk_api.h index 1f3233a..4fc64e9 100644 --- a/gpu/vk/vk_api.h +++ b/gpu/vk/vk_api.h @@ -15,7 +15,9 @@ extern "C" { #endif -#define MKWVK_API_VERSION 15 +/* ((Triforce, 11-22) 16: MkwVkRenderer's screen_point, N64 Classic's TV's curve for the game's own menus' mouse. 11-23: 19, as + ultrawide's screens and wide_backdrop (16, 17, 18 on its own line) came first on next/update) */ +#define MKWVK_API_VERSION 19 enum { HOS_OPT_CHEAT_HEARTS = 32, HOS_OPT_CHEAT_FLIGHT, HOS_OPT_CHEAT_ACTION, HOS_OPT_CHEAT_CAMERA }; /* (hookshot) the Motion page's rows (host/pad_sdl.c reads them, vk_replay.cpp's option answers them): Motion controls on or off, the horizontal's and the vertical's sensitivity in percent, each turned around, and the deadzone (0 to 2) */ @@ -39,6 +41,10 @@ enum { HOS_OPT_GAME_OPTIONS = 48, HOS_OPT_EXITING }; rate cap on Monitor's rate (host/nn_vi.c fps_max, gpu/vk/fps_cap.h): its refresh rate rounded, 30 to 240; 0 when the rate cannot be read. 60 to 69 are the display, graphics and system rows' */ enum { HOS_OPT_DISPLAY_CAP = 60 }; +/* ((Triforce, 11-22, N64 Classic, step 7) HOS_OPT_N64_FPS: the frame rate N64 Classic asks the host to pace the game at + (gpu/vk/n64_rules.h fps: Faithful's 20, the Remembered page's row; 0 none: the cap's), asked once a present + (host/nn_vi.c n64_pace_decide, host/n64_pace.h) */ +enum { HOS_OPT_N64_FPS = 61 }; /* (Triforce) The System tab's save rows (gpu/vk/vk_menu.cpp), whose work the host does on a thread of its own (host/save_share.c): HOS_OPT_SHARE_ASK, option: what a row asked for since the last read, HOS_SHARE_*, 0 nothing (taken: the next read answers 0). HOS_OPT_SHARE_TEXT, option_set: the next byte of a line for the menu, UTF-8, and @@ -135,7 +141,7 @@ enum { HOS_MENU_SOUND_OPEN = 1, HOS_MENU_SOUND_CLOSE, HOS_MENU_SOUND_CURSOR, HOS the button above it, then HOS_OPT_MODS_LIST: HOS_MODS_LIST_* bits (that frame's report is whole). HOS_OPT_MODS_ENTER, option_set: the cursor goes onto Mods (1: the game's Down there, which the game is not given, host/nn_hid.c), or Mods was clicked (2: open it; (Triforce, 11-19) 3: Quit under it clicked, its dialog opens; 4: the mouse moved onto Quit; 5: a Down - held from higher up the list, its repeat onto Mods, which repeats on at the step). HOS_OPT_MODS_SELECTED, option: 1 while the cursor is on Mods or its screen is open (the game gets + held from higher up the list, its repeat onto Mods, which repeats on at the step; on the title, while the save files are on, the entry under Mods is Save Select, host/save_files.c, and 3 and 4 are its). HOS_OPT_MODS_SELECTED, option: 1 while the cursor is on Mods or its screen is open (the game gets no input then: host/nn_hid.c). HOS_OPT_MODS_PRESS, option_set: presses the game was given meanwhile that are the menu's (a test's scripted ones, which reach no window): HOS_MODS_PRESS_* bits. ((Triforce, 11-19) with HOS_MODS_REPORT, each read's report: also the directions held then, HOS_MODS_PRESS_DIRS bits shifted by HOS_MODS_HELD_SHIFT, which the menu repeats @@ -170,7 +176,28 @@ enum { HOS_OPT_MODS_ALPHA = 162 }; HOS_OPT_ACH_COUNT, option_set: the list is whole (0: none). HOS_OPT_ACH_EARNED, option_set: the achievement at that place in the list was earned now, the bytes sent so far the day: the notice shows it. One at a time, the host waits between two */ enum { HOS_OPT_ACH_TEXT = 165, HOS_OPT_ACH_ADD, HOS_OPT_ACH_COUNT, HOS_OPT_ACH_EARNED, HOS_OPT_ACH_ASK }; +/* ((Triforce) 11-23: the System tab's Achievements group. HOS_OPT_ACH_ON, option: 1 while its Achievements row is On (0: + nothing is asked of the save data and nothing earned, at once). HOS_OPT_ACH_NOTICES, option: 1 while its Achievement + notices row is On (0: what is earned is told to the list without the notice's sound, and the menu shows no notice). + 185 and 186: 170 is the bench's helper test, 180 to 184 the save files) */ +enum { HOS_OPT_ACH_ON = 185, HOS_OPT_ACH_NOTICES }; enum { HOS_ACH_EARNED = 256 }; +/* ((Triforce) 11-22) The benchmark's helper-thread test (host/hos_bench.c, HOS_BENCH_HELPERS=1). HOS_OPT_HELPERS_FORCE, + option_set: 0 the replay thread alone, 1 the replay helper threads in use, -1 the tuner decides again (gpu/vk/replay_threads.h), + each from the next present on; option: the helper threads such a test can use, 0 where it cannot (the Debug tab's row Off, + RX_VK_PARALLEL, or a PC Automatic gives none) */ +enum { HOS_OPT_HELPERS_FORCE = 170 }; +/* (Triforce) Save files (host/save_files.c keeps them, on unless HOS_SAVE_FILES=0; gpu/vk/vk_menu.cpp and + gpu/vk/save_file_rows.h show them: the file select at the title, and the System tab's Save files row; 180 to 184 are + theirs; 170 is the bench's helper test). HOS_OPT_FILES_ASK, option: the file the player chose to play that is not this run's, its number (1 the first; taken: + the next read answers 0), 0 none; a renderer that shows them answers 0 and more. Once it answers the host names the + files, in their order: HOS_OPT_FILES_TEXT, option_set: the next byte of a file's name, UTF-8, then a line feed and when it + was last saved (nothing: no save in it yet); HOS_OPT_FILES_ADD, option_set: the bytes sent so far are the next file's, the + value its HOS_FILE_* bits; HOS_OPT_FILES_COUNT, option_set: the list is whole, the value how many, and HOS_FILES_CHOSEN when + this start follows a choice (the game restarted for it). HOS_OPT_FILES_SAID, option_set: what became of the file asked + for: 1 it is the next start's (the menu restarts the game), 2 it could not be kept (nothing changes) */ +enum { HOS_OPT_FILES_TEXT = 180, HOS_OPT_FILES_ADD, HOS_OPT_FILES_COUNT, HOS_OPT_FILES_ASK, HOS_OPT_FILES_SAID }; +enum { HOS_FILE_SAVED = 1, HOS_FILE_CURRENT = 2, HOS_FILES_CHOSEN = 256 }; /* (hookshot) the mouse over the window while it is free (not captured): the Insert menu's (host/display.c, host/posix/display_sdl.c). x and y: the cursor in the window's pixels, of a window width x height pixels (the @@ -200,6 +227,14 @@ typedef struct MkwVkBench { } MkwVkBench; /* what the executable gives the back end */ +/* ((Triforce) a connected screen: its native size in pixels, whether the game's window opens on it, and the monitor's own + name in UTF-8 ("" where the system has none) */ +typedef struct MkwVkScreen { + uint32_t w, h; + int32_t opens; + char name[64]; +} MkwVkScreen; + typedef struct MkwVkHost { uint32_t version; /* MKWVK_API_VERSION */ void (*log)(const char *line); @@ -284,6 +319,14 @@ typedef struct MkwVkHost { /* (Triforce, 11-19, version 15) while the game has the keys' face (prompt_face): the face of the controller used last, once host/prompts.c has built its icons for the overlay (prompts/External.pad.bfotf.zs); -1 none */ int (*prompt_pad_face)(void); + /* ((Triforce) 16) the connected screens as the host found them at the start (host/hos_screens.h), for the Insert menu's + Output resolution row, which offers each one's size: at most cap written, how many; 0 when none is known */ + int (*screens)(MkwVkScreen *out, int cap); + /* ((Triforce) 17) ultrawide's menus: 1 while a game menu runs whose backdrop is the one the Ultrawide menus row puts in + the middle 16:9 (host/oot_title_movie.h: the file select, the file's box, the Options, the system menus' backdrop + itself). The blur of the last picture that the renderer sees drawn is then that backdrop, to be given sides, and not + the item wheel's background, which keeps the whole picture (gpu/vk/wide_sides_rule.h) */ + int (*wide_backdrop)(void); } MkwVkHost; /* what the back end gives the executable: the rx_* functions (gpu/render/rx_nvn.h, rx_core) */ @@ -332,6 +375,10 @@ typedef struct MkwVkRenderer { /* (hookshot, the Insert menu) a setting changed from the game's side, kept in the options file: 7 the mouse's sensitivity in percent (the - and = keys, host/nn_hid.c) */ void (*option_set)(int id, int value); + /* ((Triforce, 11-22, N64 Classic) a point of a w x h window, in its pixels (the cursor's), to the point of the game's picture + N64 Classic's TV showed there at the last present, through its screen's curve: where the game's own menus drew what the + cursor is over (host/oot_menu.c). As it is when the TV did not draw (gpu/vk/vk_n64.h n64_screen_point) */ + void (*screen_point)(int *x, int *y, int w, int h); } MkwVkRenderer; /* the DLL's one export: null when Vulkan is not usable (the executable then falls back to WebGPU) */ diff --git a/gpu/vk/vk_draw.cpp b/gpu/vk/vk_draw.cpp index 825121f..902205e 100644 --- a/gpu/vk/vk_draw.cpp +++ b/gpu/vk/vk_draw.cpp @@ -59,6 +59,7 @@ #include "vk_texture.h" #include "movie_upscale_policy.h" #include "upscale_off.h" // ((Triforce, 11-22, GPUWORK-20) which network dispatches the plain stretch stands in for) +#include "vk_n64.h" // ((Triforce, 11-22, N64 Classic) its 3D pass in the gameplay upscale's place: n64_upscale) #include "stub_same_size.h" // ((Triforce, 11-22, GPUWORK-21) a gameplay network that cannot run, at its input's size: upscale_stub) #include "lab_ab.h" // ((Triforce, 11-22, GPUWORK-20) the lab's "upoff" phases) #include "occ_lean.h" // ((Triforce, 11-22, DESC-82) the occlusion proxies' census, RX_VK_OCC_LEAN=3) @@ -109,6 +110,7 @@ #include "shaders/clear_u_frag_spv.h" #include "shaders/clear_vert_spv.h" #include "shaders/taau_upscale_comp_spv.h" +#include "shaders/n64_3d_comp_spv.h" // ((Triforce, N64 Classic) shaders/n64_3d.comp) #include "shaders/movie_upscale_comp_spv.h" #include "shader_recompiler/backend/spirv/mma_layout.h" #include "vk_renodx.h" @@ -3805,6 +3807,11 @@ std::atomic upscale_lod_render_h{0}; // (and it // ((Triforce, S8) this frame's scene size, from the upscaler's camera note in stream order (upscale_lod_scene): the // game's dynamic resolution makes new targets at each size, which the last upscale's size (the frame before's) misses) std::atomic upscale_lod_scene_now{0}; // (sharpen_rules.h lod_scene_pack) +// ((Triforce, 11-22, N64 Classic, step 3) the picture its 3D pass last drew, w | h << 32 (n64_upscale): while its texture blur +// is on (a positive bias, which only it asks for), a draw of a scene's size for that picture is the scene (n64_rules.h +// scene_draw), the frame of a dynamic resolution's new size included: the upscalers' scene camera, which takes that frame +// for them, is not noted while they step aside +std::atomic n64_lod_output{0}; /// ((Triforce, S8) Whether a draw into these targets renders the jittered scene (sharpen_rules.h lod_scene_now): its colour /// targets, or a depth-only draw's depth target (lod_scene_size), at the last upscale's render size or this frame's scene /// camera's. False while no bias is in use @@ -3817,9 +3824,16 @@ bool draw_in_scene(const Targets& at) { if (at.depth) depth = {at.depth->width, at.depth->height, at.depth_level}; uint32_t w, h; sharpen_rules::lod_scene_size(color, n, depth, &w, &h); - return sharpen_rules::lod_scene_now(w, h, upscale_lod_render.load(std::memory_order_relaxed), - upscale_lod_render_h.load(std::memory_order_relaxed), - upscale_lod_scene_now.load(std::memory_order_relaxed), texture_frame_no()); + const bool upscalers = sharpen_rules::lod_scene_now(w, h, upscale_lod_render.load(std::memory_order_relaxed), + upscale_lod_render_h.load(std::memory_order_relaxed), + upscale_lod_scene_now.load(std::memory_order_relaxed), texture_frame_no()); + if (upscalers) return true; + // ((Triforce, 11-22, N64 Classic, step 3) its blur: a draw of a scene's size and shape for the picture its pass drew) + if (upscale_lod_bias.load(std::memory_order_relaxed) > 0.0f) { + const uint64_t o = n64_lod_output.load(std::memory_order_relaxed); + return n64_rules::scene_draw(w, h, (uint32_t)o, (uint32_t)(o >> 32)); + } + return false; } /// compare: the shader reads depth with a reference (a sampler without one cannot compare). scene: for a draw into the /// jittered scene (draw_in_scene), the only one the upscaler's texture LOD bias is added for @@ -4593,7 +4607,14 @@ void upscale_lod_tick() { // not draw, makes no samplers anew twice; without it, none) static bool jitter = false; float want = 0.0f; - if (!off && (temporal_wanted() || fsr3_wanted())) { + // ((Triforce, 11-22, N64 Classic, step 3) its texture blur while its 3D pass draws the gameplay upscale (the upscalers step + // aside then): the look's positive bias, never past the card's limit (n64_rules.h lod_bias), on the same scene-only path, + // taken as it is (it changes only with the look). RX_VK_N64_LOD over the preset's; RX_VK_UPSCALE_LOD_BIAS is the upscalers' + const bool n64 = n64_3d_now(); + if (n64) { + jitter = false; + want = n64_rules::lod_bias(n64_look(), dev.props.limits.maxSamplerLodBias); + } else if (!off && (temporal_wanted() || fsr3_wanted())) { if (temporal_jitter_size(0) || fsr3_inputs::jitter_size(0)) jitter = true; want = sharpen_rules::lod_bias_want(mode, fixed, upscale_lod_render.load(std::memory_order_relaxed), upscale_lod_output.load(std::memory_order_relaxed), jitter); @@ -4603,12 +4624,13 @@ void upscale_lod_tick() { upscale_lod_scene_now.store(0, std::memory_order_relaxed); } const float now = upscale_lod_bias.load(std::memory_order_relaxed); - const float next = sharpen_rules::lod_bias_step(mode, now, want); // (a fixed one as it is asked) + const float next = n64 ? want : sharpen_rules::lod_bias_step(mode, now, want); // (a fixed one as it is asked; N64's too) if (next == now) return; upscale_lod_bias.store(next, std::memory_order_relaxed); sampler_bias_changed(); logf("vk: texture LOD bias %+.2f on the scene's tiled textures (%s; was %+.2f)", (double)next, next == 0.0f ? "no upscaler: the game's own" + : n64 ? "N64 Classic's texture blur" : fixed_on ? "RX_VK_UPSCALE_LOD_BIAS" : jitter ? "the upscaler's render scale, -0.5 for its jitter" : "the upscaler's render scale", (double)now); @@ -7672,7 +7694,9 @@ extern int64_t presents_now; // (vk_replay.cpp) // movie draws none: then ultrawide's sides are blurred or black (vk_framegen.cpp wide_sides) std::atomic world_drawn_at{0}; // The last present whose frame drew the item wheel's background (02ff9920: the last frame of play, blurred, over the whole picture; -// drawn behind the wheel only, not the pause menu or the map): no sides of ours then (vk_framegen.cpp wide_sides) +// not drawn by the pause menu or the map): no sides of ours then (vk_framegen.cpp wide_sides). (Triforce) The same program draws +// the backdrop of a system menu over the title (the file select: the title movie blurred), which is centred and takes the +// sides: wide_sides_rule.h tells the two apart with the host std::atomic wheel_drawn_at{0}; uint32_t stage_cbuf_word(const NvnState& s, const Stage& st, uint32_t index, uint32_t offset); // (vk_shader.cpp) // (hookshot) RX_VK_EXPOSURE_LOG=1: the final pass's exposure (c3+0x38 of its fragment stage, OoT's 73320e720a317817) at each @@ -10492,6 +10516,133 @@ static bool typed_upscale(VkCommandBuffer cmd, VkImageView input_view, VkImageVi if (temporal) probe_image(cmd, out, level, 0, key, 't'); return true; } +/// ((Triforce, 11-22) N64 Classic's 3D pass (n64-classic-mode-plan.md, step 2; shaders/n64_3d.comp) in a gameplay upscale +/// network's place, from taau_stand_in under its lock: the network's input (input_view; `in` for its size) made into the grid +/// of the look's lines (n64_rules.h grid: as wide as the output's shape makes it), each grid pixel the mean of its footprint, +/// kept at the look's colour depth with the ordered dither; then out to the network's output (output_view, `out` at +/// `level`) at the picture's size, linear along each line and hard between lines. The grid image is this pass's own, made +/// again at a new size; the one before is given back 120 presents later, when no work in flight can use it. false: nothing +/// was recorded (the pipeline or the grid could not be made), and the caller leaves the game's network to draw +static bool n64_upscale(VkCommandBuffer cmd, VkImageView input_view, const Texture* in, VkImageView output_view, Texture* out, + uint32_t level) { + if (!dev.push_descriptor || !vkCmdPushDescriptorSetKHR || !input_view || !output_view || !in || !out) return false; + static VkPipeline pipe = VK_NULL_HANDLE; + static VkPipelineLayout layout = VK_NULL_HANDLE; + static VkSampler linear = VK_NULL_HANDLE; + static bool tried = false; + struct Push { + int32_t grid[2], size[2]; + int32_t pass, bits; + float dither; + }; + if (!tried) { + tried = true; + VkDescriptorSetLayoutBinding b[3] = {{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}, + {1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}, + {2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr}}; + VkDescriptorSetLayoutCreateInfo li{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; + li.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR; + li.bindingCount = 3, li.pBindings = b; + VkDescriptorSetLayout set{}; + vkCreateDescriptorSetLayout(dev.device, &li, nullptr, &set); + const VkPushConstantRange pr{VK_SHADER_STAGE_COMPUTE_BIT, 0, (uint32_t)sizeof(Push)}; + VkPipelineLayoutCreateInfo pi{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; + pi.setLayoutCount = 1, pi.pSetLayouts = &set, pi.pushConstantRangeCount = 1, pi.pPushConstantRanges = ≺ + vkCreatePipelineLayout(dev.device, &pi, nullptr, &layout); + VkShaderModuleCreateInfo mi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; + mi.codeSize = sizeof N64_3D_COMP_SPV, mi.pCode = N64_3D_COMP_SPV; + VkShaderModule m{}; + vkCreateShaderModule(dev.device, &mi, nullptr, &m); + VkComputePipelineCreateInfo ci{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; + ci.stage = {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, m, "main", nullptr}; + ci.layout = layout; + if (!m || vkCreateComputePipelines(dev.device, VK_NULL_HANDLE, 1, &ci, nullptr, &pipe) != VK_SUCCESS) pipe = VK_NULL_HANDLE; + if (m) vkDestroyShaderModule(dev.device, m, nullptr); + VkSamplerCreateInfo si{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; + si.magFilter = si.minFilter = VK_FILTER_LINEAR; + si.addressModeU = si.addressModeV = si.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + si.maxLod = 0.25f; + if (vkCreateSampler(dev.device, &si, nullptr, &linear) != VK_SUCCESS) linear = VK_NULL_HANDLE; + logf("vk: N64 Classic: its 3D pass %s", pipe && linear ? "is ready" : "was not made: the game's upscale draws"); + } + if (!pipe || !linear) return false; + const n64_rules::Look look = n64_look(); + const uint32_t ow = std::max(1u, out->width >> level), oh = std::max(1u, out->height >> level); + const n64_rules::Grid g = n64_rules::grid(look.lines, ow, oh); + if (!g.w || !g.h || !in->width || !in->height) return false; + // ((step 3) the scene's size and the picture's for its texture blur, as the upscalers note theirs: upscale_lod_tick, + // draw_in_scene) + upscale_lod_note(in->width, in->height, ow); + n64_lod_output.store((uint64_t)oh << 32 | ow, std::memory_order_relaxed); + struct GridImage { + VkImage image = VK_NULL_HANDLE; + VmaAllocation memory = nullptr; + VkImageView view = VK_NULL_HANDLE; + uint32_t w = 0, h = 0; + uint64_t frame = 0; + }; + static GridImage now; + static std::vector old; + for (size_t i = 0; i < old.size();) { + if (texture_frame_no() - old[i].frame < 120) { i++; continue; } + if (old[i].view) vkDestroyImageView(dev.device, old[i].view, nullptr); + destroy_image(old[i].image, old[i].memory); + old.erase(old.begin() + (ptrdiff_t)i); + } + if (!now.image || now.w != g.w || now.h != g.h) { + if (now.image) now.frame = texture_frame_no(), old.push_back(now); + now = GridImage{}; + VkImageCreateInfo ic{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; + ic.imageType = VK_IMAGE_TYPE_2D, ic.format = VK_FORMAT_R16G16B16A16_SFLOAT; + ic.extent = {g.w, g.h, 1}, ic.mipLevels = 1, ic.arrayLayers = 1, ic.samples = VK_SAMPLE_COUNT_1_BIT; + ic.tiling = VK_IMAGE_TILING_OPTIMAL, ic.usage = VK_IMAGE_USAGE_STORAGE_BIT; + if (!create_image(ic, now.image, now.memory)) return now = GridImage{}, false; + VkImageViewCreateInfo vc{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; + vc.image = now.image, vc.viewType = VK_IMAGE_VIEW_TYPE_2D, vc.format = ic.format; + vc.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + if (vkCreateImageView(dev.device, &vc, nullptr, &now.view) != VK_SUCCESS) { + destroy_image(now.image, now.memory); + return now = GridImage{}, false; + } + VkImageMemoryBarrier2 ib{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2}; // (UNDEFINED -> GENERAL, once) + ib.srcStageMask = VK_PIPELINE_STAGE_2_NONE, ib.srcAccessMask = VK_ACCESS_2_NONE; + ib.dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + ib.dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT | VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT; + ib.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, ib.newLayout = VK_IMAGE_LAYOUT_GENERAL; + ib.srcQueueFamilyIndex = ib.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + ib.image = now.image, ib.subresourceRange = vc.subresourceRange; + VkDependencyInfo di{VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; + di.imageMemoryBarrierCount = 1, di.pImageMemoryBarriers = &ib; + vkCmdPipelineBarrier2(cmd, &di); + now.w = g.w, now.h = g.h; + static int told = 0; // (each new size said, the first 16: the output's size changes rarely) + if (told++ < 16) + logf("vk: N64 Classic: the 3D on a %ux%u grid for a %ux%u picture, from a %ux%u 3D, %s colour", g.w, g.h, ow, oh, + in->width, in->height, look.colour_bits ? (look.colour_bits == 5 ? "15-bit" : "18-bit") : "full"); + } + const VkDescriptorImageInfo in_info{linear, input_view, VK_IMAGE_LAYOUT_GENERAL}; + const VkDescriptorImageInfo grid_info{VK_NULL_HANDLE, now.view, VK_IMAGE_LAYOUT_GENERAL}; + const VkDescriptorImageInfo out_info{VK_NULL_HANDLE, output_view, VK_IMAGE_LAYOUT_GENERAL}; + VkWriteDescriptorSet w[3]{{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}, + {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}}; + w[0].dstBinding = 0, w[0].descriptorCount = 1, w[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + w[0].pImageInfo = &in_info; + w[1].dstBinding = 1, w[1].descriptorCount = 1, w[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + w[1].pImageInfo = &grid_info; + w[2].dstBinding = 2, w[2].descriptorCount = 1, w[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + w[2].pImageInfo = &out_info; + Push pc{{(int32_t)g.w, (int32_t)g.h}, {(int32_t)ow, (int32_t)oh}, 0, look.colour_bits, look.dither}; + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); + vkCmdPushDescriptorSetKHR(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, layout, 0, 3, w); + vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof pc, &pc); + vkCmdDispatch(cmd, (g.w + 7) / 8, (g.h + 7) / 8, 1); // (make: the grid) + full_barrier(cmd, "barrier (N64 Classic's grid)"); + pc.pass = 1; + vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof pc, &pc); + vkCmdDispatch(cmd, (ow + 7) / 8, (oh + 7) / 8, 1); // (show: the picture) + descriptors_disturbed(); // (the program's own pushes are gone from the bind point) + return true; +} /// ((Triforce, FG-2) A gameplay network's output whose dispatch goes on past fsr3_stand_in (the game's own network, or the /// TAAU or the Anti-aliasing row's pass in its place): taken as frame generation's picture without the HUD once it has run, /// hudless_after_dispatch. The recording thread's own: each worker records its dispatches whole) @@ -10629,15 +10780,19 @@ bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) { if (!dev.push_descriptor || !vkCmdPushDescriptorSetKHR || p.stages.empty()) return false; const Stage& st = p.stages[0]; const bool off = upscale_off_on(); - const bool shaped = off && st.info.uses_cooperative_matrix && st.info.texture_descriptors.size() == 1 && + const bool n64 = n64_3d_now(); // ((Triforce, 11-22, N64 Classic) its 3D pass in the network's place: n64_upscale) + const bool shaped = (off || n64) && st.info.uses_cooperative_matrix && st.info.texture_descriptors.size() == 1 && st.info.image_descriptors.size() == 1; - const upscale_off::Choice ch = upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped); + const upscale_off::Choice ch = upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped, n64); if (!ch.stand_in) return false; if (st.info.texture_descriptors.empty() || st.info.image_descriptors.empty()) return false; - if (ch.by_shape) { // (a network of that shape that is not a gameplay upscale, a movie's: its input is not the scene's format) - Texture* in = nullptr; + Texture* in = nullptr; // (the network's input: for one taken by its shape, and for N64 Classic's grid, which needs its size) + if (ch.by_shape || ch.n64) { const uint32_t in_handle = handle_of(s, st, st.info.texture_descriptors[0], 0); if (in_handle) texture_view_of(in_handle, VK_IMAGE_VIEW_TYPE_2D, ViewUse::Sample, VK_FORMAT_UNDEFINED, &in); + if (!in) return false; + } + if (ch.by_shape) { // (a network of that shape that is not a gameplay upscale, a movie's: its input is not the scene's format) if (!in || in->format != VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) return false; } size_t ntex = 0; // (build_descriptors' image infos: the textures', then the images') @@ -10653,8 +10808,10 @@ bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) { const char* keys = !ch.temporal ? "the upscaler Off" : getenv("RX_VK_TAAU_KEYS") ? getenv("RX_VK_TAAU_KEYS") : "fd029a317a9a4b94"; bool done; { - ParLock lk; // (Triforce: typed_upscale's pipeline and history images are shared by every recording thread: upscale_stub) - done = typed_upscale(cmd, dw().imgs[0].imageView, dw().imgs[ntex].imageView, out, level, p.key, keys, ch.temporal); + ParLock lk; // (Triforce: typed_upscale's pipeline and history images are shared by every recording thread: upscale_stub; + // N64 Classic's pipeline and grid as well) + if (ch.n64) done = n64_upscale(cmd, dw().imgs[0].imageView, in, dw().imgs[ntex].imageView, out, level); + else done = typed_upscale(cmd, dw().imgs[0].imageView, dw().imgs[ntex].imageView, out, level, p.key, keys, ch.temporal); } if (done) hudless_after_dispatch(cmd, p.key); // ((Triforce, FG-2) the picture it wrote in the network's place, before the HUD) return done; diff --git a/gpu/vk/vk_framegen.cpp b/gpu/vk/vk_framegen.cpp index 1582783..6ea0000 100644 --- a/gpu/vk/vk_framegen.cpp +++ b/gpu/vk/vk_framegen.cpp @@ -33,8 +33,10 @@ #include "vk_pace.h" // (Triforce: whether RivaTuner holds the frames this thread presents) #include "vk_present_rect.h" #include "vk_temporal.h" // ((Triforce, S1) temporal_sharpens_3d: the upscaler sharpened the 3D before the HUD) +#include "wide_sides_rule.h" // ((Triforce) when ultrawide's menu sides show) #include "vk_texture.h" #include "sharpen_rules.h" // ((Triforce, S1, S3-S6) the window pass's Sharpness and filter, the PQ picture's shaders) +#include "vk_n64.h" // ((Triforce, N64 Classic, step 4) its TV in the window filter's place: framegen_scale) #include #include "shaders/fg_copy_comp_spv.h" @@ -46,6 +48,7 @@ #include "shaders/fg_luma_comp_spv.h" #include "shaders/fg_median_comp_spv.h" #include "shaders/fg_scale_comp_spv.h" +#include "shaders/n64_tv_comp_spv.h" // ((Triforce, N64 Classic) shaders/n64_tv.comp) #include "shaders/fg_synth_comp_spv.h" #include "shaders/fsr1_easu_comp_spv.h" #include "shaders/fsr1_rcas_comp_spv.h" @@ -144,6 +147,12 @@ struct ScaleState { Img cropped, scaled, small; // (small: the picture at 1/8, for ultrawide's blurred menu sides) Img easu_img; // (FSR 1: EASU's output, RCAS's input, the window's size) uint32_t cropped_w = 0, cropped_h = 0, scaled_w = 0, scaled_h = 0, small_w = 0, small_h = 0; + // ((Triforce, N64 Classic, step 4) its TV's pipeline (shaders/n64_tv.comp: init_tv), and beside ultrawide's menu sides the + // window-size image the filter draws them into first) + Pipe tv; + bool tv_tried = false; + Img tv_img; + uint32_t tv_w = 0, tv_h = 0; } scale; struct HdrState { // (hookshot) the HDR10 pass (framegen_hdr) @@ -377,6 +386,21 @@ bool init_scale_pq() { return true; } +/// ((Triforce, 11-22, N64 Classic, step 4) its TV's pipeline (shaders/n64_tv.comp), made at its first present; rgba8 only (the +/// TV does not run on HDR Native's PQ picture). False: not made (said once), and the window's filter draws as before +bool init_tv() { + if (scale.tv_tried) return scale.tv.pipe != VK_NULL_HANDLE; + scale.tv_tried = true; + const VkDescriptorType S = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, I = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + if (!init_scale() || !make_pipe(scale.tv, N64_TV_COMP_SPV, sizeof N64_TV_COMP_SPV, {S, I, S, S}, 48)) { + drop_pipe(scale.tv); + logf("vk: N64 Classic: its TV pass could not be made: the window's filter draws as before"); + return false; + } + logf("vk: N64 Classic: its TV pass is ready"); + return true; +} + bool make_img(Img& i, uint32_t w, uint32_t h, VkFormat f, VkImageUsageFlags usage) { Img made; VkImageCreateInfo ci{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; @@ -724,15 +748,18 @@ WideSides wide_sides() { extern int64_t presents_now; extern std::atomic wheel_drawn_at; // (no world: a menu. But not the item wheel, whose background is the last frame of play over the whole picture, as on the - // console: its sides are left as the game draws them) - const bool no_world = presents_now - world_drawn_at.load(std::memory_order_relaxed) > 3 && - presents_now - wheel_drawn_at.load(std::memory_order_relaxed) > 3; + // console: its sides are left as the game draws them. (Triforce) The program that draws it also draws the centred + // backdrop of a system menu over the title, which does get the sides: the host says which it is, wide_sides_rule.h) + const bool centred_menu = host->wide_backdrop && host->wide_backdrop() != 0; + const int side = wide_sides_rule::show(opts.wide_menus, margin, presents_now, world_drawn_at.load(std::memory_order_relaxed), + wheel_drawn_at.load(std::memory_order_relaxed), centred_menu); wide_possible.store(opts.wide_menus && margin > 0.0f, std::memory_order_relaxed); - if (opts.wide_menus && margin > 0.0f && no_world) w.x0 = margin, w.side = opts.wide_menus; + if (side) w.x0 = margin, w.side = side; static int told = 0; if (w.side != told) { // (each change logged: a report of blurred sides in play says when they came and went) - logf("vk: ultrawide menu sides %s at present %lld (the world last drawn at present %lld)", w.side ? "on" : "off", - (long long)presents_now, (long long)world_drawn_at.load(std::memory_order_relaxed)); + logf("vk: ultrawide menu sides %s at present %lld (the world last drawn at present %lld, the last picture's blur at %lld%s)", + w.side ? "on" : "off", (long long)presents_now, (long long)world_drawn_at.load(std::memory_order_relaxed), + (long long)wheel_drawn_at.load(std::memory_order_relaxed), centred_menu ? ", a menu's centred backdrop" : ""); told = w.side; } return w; @@ -770,8 +797,9 @@ VkImage framegen_scale(VkCommandBuffer cmd, VkImageView src, VkImage image, uint std::lock_guard qk(dev.present_mu); device_wait_idle_locked(); } - drop_img(scale.cropped), drop_img(scale.scaled), drop_img(scale.easu_img), drop_img(scale.small); + drop_img(scale.cropped), drop_img(scale.scaled), drop_img(scale.easu_img), drop_img(scale.small), drop_img(scale.tv_img); scale.cropped_w = scale.cropped_h = scale.scaled_w = scale.scaled_h = scale.small_w = scale.small_h = 0; + scale.tv_w = scale.tv_h = 0; scale.format = format; } const Pipe& filter = pq ? scale.pipe16 : scale.pipe; @@ -833,6 +861,87 @@ VkImage framegen_scale(VkCommandBuffer cmd, VkImageView src, VkImage image, uint } // (the size the picture is at: the cropped one when the game drew into part of its texture) const uint32_t iw = src == scale.cropped.view ? scale.cropped_w : sw, ih = src == scale.cropped.view ? scale.cropped_h : sh; + // ((Triforce, 11-22, N64 Classic, step 4) its TV in the filter's place (upscaler_rows.h kTvFilter; n64_tv_now: not on HDR + // Native's PQ picture, nor under DLSS frame generation): from the picture to its place in the window at the window's own + // pixels, the glow from the picture at 1/8 (the copy ultrawide's menu sides blur). Beside those sides the filter draws + // them first, into an image of the window's size, and the TV goes over it. Its pipeline not made: the filter, as before + if (!pq && n64_tv_now(pq) && init_tv()) { + const n64_rules::Look look = n64_look(); + const n64_rules::AnimFrame f = n64_anim(); // ((step 8) the TV switching off and on: 1, 1 and no flash at rest) + const uint32_t smw = std::max(1u, source.w / 8), smh = std::max(1u, source.h / 8); + if (scale.small_w != smw || scale.small_h != smh) { + { + std::lock_guard qk(dev.present_mu); + device_wait_idle_locked(); + } + drop_img(scale.small); + scale.small_w = scale.small_h = 0; + if (!make_img(scale.small, smw, smh, scale.format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)) { + drop_img(scale.small); + return VK_NULL_HANDLE; + } + scale.small_w = smw, scale.small_h = smh; + to_general(cmd, scale.small.image); + } + struct { int mode; float sharp; float x0, x1; int side; } sp{0, 0.0f, wide.x0, 1.0f - wide.x0, 3}; + pass(cmd, filter, {{src, scale.linear}, {scale.small.view, VK_NULL_HANDLE}, {src, scale.linear}}, smw, smh, &sp, sizeof sp); + VkImageView picture = src; + if (wide.side) { + if (scale.tv_w != dw || scale.tv_h != dh) { + { + std::lock_guard qk(dev.present_mu); + device_wait_idle_locked(); + } + drop_img(scale.tv_img); + scale.tv_w = scale.tv_h = 0; + if (!make_img(scale.tv_img, dw, dh, scale.format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)) { + drop_img(scale.tv_img); + return VK_NULL_HANDLE; + } + scale.tv_w = dw, scale.tv_h = dh; + to_general(cmd, scale.tv_img.image); + } + sp.side = wide.side; + pass(cmd, filter, {{src, scale.linear}, {scale.tv_img.view, VK_NULL_HANDLE}, {wide.side == 1 ? scale.small.view : src, scale.linear}}, + dw, dh, &sp, sizeof sp); + picture = scale.tv_img.view; + } + const int mask = n64_rules::mask_shown(look.mask, dh); + // ((11-22, the owner's test) the TV's screen for the mouse (vk_n64.h n64_screen_point), and the options' own screens + // under it with the game's (vk_menu.cpp menu_tv_layer: their layer of this place, drawn now; null when none shows) + n64_screen_drawn(look.curvature, f.scale_x, f.scale_y); + const VkImageView menu = menu_tv_layer(cmd); + struct { float lines, scan, mask, bleed, glow, curve, saturation; int mask_type; float anim_x, anim_y, flash; int menu; } tp{ + (float)n64_rules::kTvLines, n64_rules::scanline_strength(look.scanlines, dh), look.mask_strength, + n64_rules::tv_bleed_uv(look.bleed, source.w, source.h), look.glow, look.curvature, look.saturation, mask, + f.scale_x, f.scale_y, f.flash, menu ? 1 : 0}; + // ((11-22, the owner's second look) the glow's 1/8 copy made again with the options over the picture (the TV's menu 2): + // from the picture alone, the glow added a blur of the game's own panes under them through their plates. After the + // ultrawide sides took the copy before it, which stays the picture's) + if (menu) { + tp.menu = 2; + pass(cmd, scale.tv, {{picture, scale.linear}, {scale.small.view, VK_NULL_HANDLE}, {picture, scale.linear}, {menu, scale.linear}}, + smw, smh, &tp, sizeof tp); + tp.menu = 1; + } + pass(cmd, scale.tv, {{picture, scale.linear}, {scale.scaled.view, VK_NULL_HANDLE}, {scale.small.view, scale.linear}, + {menu ? menu : scale.small.view, scale.linear}}, dw, dh, &tp, sizeof tp); + // (each new place, preset, mask or scanline strength said once the switch is over: a report of moire or a dim picture + // then says which. (11-22) Before, the place and the mask alone, so the first line, written as the TV switched on with + // Off's look still shown, said "scanlines 0%" for good) + static uint64_t told = ~0ull; + const int shown = n64_shown(); + const uint64_t now = (uint64_t)dw << 44 | (uint64_t)dh << 28 | (uint64_t)(shown & 3) << 24 | (uint64_t)(mask & 7) << 16 | + (uint64_t)std::lround(std::clamp(tp.scan, 0.0f, 1.0f) * 1000.0f); + if (f.done && now != told) { + told = now; + static const char* const masks[] = {"", "no mask", "the aperture grille", "the slot mask", "the shadow mask"}; + logf("vk: N64 Classic: the TV (%s) at %ux%u from a %ux%u picture: scanlines %.0f%%, %s%s", n64_rules::name(shown), dw, dh, + source.w, source.h, (double)(tp.scan * 100.0f), masks[mask >= 1 && mask <= 4 ? mask : 1], + wide.side ? ", over ultrawide's menu sides" : ""); + } + return scale.scaled.image; + } // (Triforce: AMD FSR 1, EvilOOT's own window filter: EASU, the edge-adaptive upscale, then RCAS at the Sharpness row. // ((Triforce, S4) only where it enlarges, as AMD's EASU is made for: not at 1:1, where the menu says the filter is not // needed, nor to a smaller window; there Catmull-Rom or the plain copy with the other filters' Sharpness. (S6) Nor diff --git a/gpu/vk/vk_fsr3.cpp b/gpu/vk/vk_fsr3.cpp index cc24986..8a4dee0 100644 --- a/gpu/vk/vk_fsr3.cpp +++ b/gpu/vk/vk_fsr3.cpp @@ -23,6 +23,7 @@ #include "vk_draw.h" // (descriptors_disturbed) #include "vk_gprof.h" // (RX_VK_PASS_TIMING: a span per pass, so the report names them) #include "vk_menu.h" +#include "vk_n64.h" // ((Triforce, N64 Classic) its 3D pass takes the gameplay upscale while it is on: fsr3_wanted) #include "vk_temporal.h" // (temporal_env_chosen: RX_VK_DLSS / RX_VK_FSR4 over the row's FSR 3.1) #include "vk_texture.h" #include "sharpen_rules.h" // ((Triforce, S1, S2) the Sharpness row as FSR's own: RCAS's constants, the boost below 3/4) @@ -974,6 +975,8 @@ std::string own_said(Out& o) { bool fsr3_wanted() { static const int env = env_switch("RX_VK_FSR"); if (env == 0) return false; + // ((Triforce, 11-22, N64 Classic) not while its 3D pass draws the gameplay upscale: n64_rules.h upscaler, the switch too) + if (n64_rules::upscaler(n64_in_front(), upscaler_rows::FSR3) != upscaler_rows::FSR3) return false; // (the Upscaler row's FSR 3.1 or its Native AA, upscaler_rows.h, read each time: the row changes it while the game runs. // RX_VK_DLSS=1 / 2 or RX_VK_FSR4=1 / 2 goes over the row, its FSR 3.1 too: vk_temporal.cpp's chain draws then) return (env > 0 || (upscaler_rows::is_fsr3(opts.dlss) && !temporal_env_chosen())) && fsr3::supported(); diff --git a/gpu/vk/vk_game_tex.h b/gpu/vk/vk_game_tex.h index fefc482..bc1cee8 100644 --- a/gpu/vk/vk_game_tex.h +++ b/gpu/vk/vk_game_tex.h @@ -281,9 +281,12 @@ inline bool make_skin(std::vector&& bntx_bytes, Skin& skin) { // archive lists them under: the Spiritual Stones and the medallions as the load list shows them, a song's icon, a Gold // Skulltula's mark, a rupee. Taken when the archive has them and they are of a form this reads; the skin is whole // without them, and the icons are then drawn + // ((Triforce) 11-18) and for the file select's cards (vk_menu.cpp draw_files): a heart, the "Autosave" tag's plate static const char* const more[] = { "DataFileImportantIcon_00", "DataFileImportantIcon_01", "DataFileImportantIcon_02", "DataFileImportantIcon_03", "DataFileImportantIcon_04", "DataFileImportantIcon_05", "DataFileImportantIcon_06", "DataFileImportantIcon_07", "DataFileImportantIcon_08", + "HeartBase_00", "HeartFrame_00", "NumBaseAutoSave_00", + // (and for the achievements' icons, vk_menu.cpp ach_icon: a song's, a Gold Skulltula's mark, a rupee) "OcarinaMelodyIcon_00", "MapIconCollectSkullSign_00", "RupeeIconNew_00"}; for (const char* n : more) { const Bntx::Entry* e = bntx.find(n); diff --git a/gpu/vk/vk_imgui.cpp b/gpu/vk/vk_imgui.cpp index ef9e855..adcbd6b 100644 --- a/gpu/vk/vk_imgui.cpp +++ b/gpu/vk/vk_imgui.cpp @@ -234,9 +234,9 @@ void art_make() { // (the presenting thread, before a frame: the images as ImG t->UseColors = true; ImGui::RegisterUserTexture(t); arts_.push_back({e.name, Art{t, (float)e.img.w, (float)e.img.h, e.img.mask}}); - if (!e.name.compare(0, 8, "DataFile") || !e.name.compare(0, 7, "Ocarina") || !e.name.compare(0, 7, "MapIcon") || !e.name.compare(0, 5, "Rupee")) - // ((Triforce) the achievements' icons: which form each is, once) - logf("vk: ui: the game's own %s: %u x %u, %s", e.name.c_str(), e.img.w, e.img.h, e.img.mask ? "a mask" : "a picture"); + if (!e.name.compare(0, 8, "DataFile") || !e.name.compare(0, 5, "Heart") || !e.name.compare(0, 7, "Ocarina") || !e.name.compare(0, 7, "MapIcon") || + !e.name.compare(0, 5, "Rupee")) // ((Triforce) the file select's and the achievements': which form each is, once) + logf("vk: ui: the load list's %s: %u x %u, %s", e.name.c_str(), e.img.w, e.img.h, e.img.mask ? "a mask" : "a picture"); } skin_.images.clear(), skin_.images.shrink_to_fit(); art_state.store(3, std::memory_order_release); @@ -490,7 +490,9 @@ bool init() { // screen's pictures and the Salesman. 64 ran out at the fifth page of mods, 11-17: every overlay then waited on it) ii.DescriptorPoolSize = 1024; ii.MinImageCount = 2; - ii.ImageCount = 4; // (its vertex buffers in turn: one more than the three frames present_image keeps in flight) + // (its vertex buffers in turn, one set a draw: one more than the three frames present_image keeps in flight, and (11-22) two + // draws a frame while the options go under N64 Classic's TV (record_layer, record_rest): 2 x 3 + 1, rounded up) + ii.ImageCount = 8; ii.UseDynamicRendering = true; ii.PipelineInfoMain.PipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO; ii.PipelineInfoMain.PipelineRenderingCreateInfo.colorAttachmentCount = 1; @@ -614,14 +616,10 @@ void idle() { reap(false); // (staging buffers and old textures let go while nothing shows too) } -void record_to(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) { - ImGui::Render(); - ImDrawData* dd = ImGui::GetDrawData(); - presents++; - reap(false); - if (srgb_target) linearize(dd); - else if (dev.hdr) hdr10(dd); // (the overlays at the paper white, not at the display's peak with the wrong primaries) - if (!image || !view) return; +namespace { +/// The frame's textures copied in on cmd (no wait on the queue). false: the font atlas could not be made, and the frame waits +/// for it (nothing drawn); a picture that could not be made has its draws left out +bool textures(VkCommandBuffer cmd, ImDrawData* dd) { // (a texture that could not be made has no descriptor: draws that sample it must not be recorded. (Triforce, 11-17) Those // draws alone are left out, not the frame's overlays: one picture of the Mods screen that could not be made hid every // overlay, the menus and the Mods entry under the game's list with them. The font atlas missing leaves the frame out) @@ -640,12 +638,16 @@ void record_to(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, if (!missing.empty()) { // (asked for again next frame) static bool told = false; if (!told) told = true, logf("vk: ui: a texture could not be made (out of memory?): %s", atlas_missing ? "the overlays wait for it" : "its pictures left out"); - if (atlas_missing) return; + if (atlas_missing) return false; for (ImDrawList* list : dd->CmdLists) for (ImDrawCmd& dc : list->CmdBuffer) if (dc.TexRef._TexData && missing.contains(dc.TexRef._TexData)) dc.ElemCount = 0, dc.TexRef = ImGui::GetIO().Fonts->TexRef; // (nothing drawn; a descriptor that is there bound) } + return true; +} +/// dd's drawing over image (TRANSFER_DST_OPTIMAL before and after, a view of it for colour attachment), one render pass +void render_over(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h, ImDrawData* dd) { layout(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT); @@ -666,6 +668,182 @@ void record_to(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT | VK_ACCESS_2_TRANSFER_WRITE_BIT); } +} // namespace + +void record_to(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) { + ImGui::Render(); + ImDrawData* dd = ImGui::GetDrawData(); + presents++; + reap(false); + if (srgb_target) linearize(dd); + else if (dev.hdr) hdr10(dd); // (the overlays at the paper white, not at the display's peak with the wrong primaries) + if (!image || !view) return; + if (!textures(cmd, dd)) return; + render_over(cmd, image, view, w, h, dd); +} + +// ---- ((Triforce, 11-22, N64 Classic, after the owner's test: "None of the classic visual effects apply to any of the custom +// UI") The frame's drawing in two: the options (the background list: vk_menu.cpp menu_tv_layer draws them there) into a +// layer of the picture's place, which N64 Classic's TV lays over the picture and takes in with it (n64_tv.comp); then the +// rest (the foreground list: the FPS counter, the notice, benchmark mode's panel) over the window, flat, as before ---- +namespace { +struct Layer { + VkImage image = VK_NULL_HANDLE; + VmaAllocation alloc = nullptr; + VkImageView draw = VK_NULL_HANDLE; // (the overlays' own format: their pipeline's, the window images' views') + VkImageView sample = VK_NULL_HANDLE; // (its UNORM: the bytes as they are, encoded as the picture is; draw's when not sRGB) + uint32_t w = 0, h = 0; + VkFormat format = VK_FORMAT_UNDEFINED; +}; +Layer layer; +bool split = false; // (this frame was drawn by record_layer: record_rest has the rest of it to draw) +bool split_wait = false; // (...but its textures could not be made: nothing of it is drawn, as record_to does then) +bool split_layer = false; // (...and the options are in the layer: over the window only beside the picture's place) +float split_place[4] = {}; +/// An sRGB format's UNORM twin, the same bytes; the format itself otherwise +VkFormat unorm_of(VkFormat f) { + return f == VK_FORMAT_B8G8R8A8_SRGB ? VK_FORMAT_B8G8R8A8_UNORM + : f == VK_FORMAT_R8G8B8A8_SRGB ? VK_FORMAT_R8G8B8A8_UNORM + : f == VK_FORMAT_A8B8G8R8_SRGB_PACK32 ? VK_FORMAT_A8B8G8R8_UNORM_PACK32 + : f; +} +/// The layer at w x h in the overlays' format: the one before let go once the frames in flight are done with it. false: it +/// could not be made (said once); the options then go over the window as before +bool layer_fit(uint32_t w, uint32_t h) { + if (layer.image && layer.w == w && layer.h == h && layer.format == pipeline_format) return true; + if (layer.image) { + dead.push_back({presents, Tex{layer.image, layer.alloc, layer.draw, VK_NULL_HANDLE}}); + if (layer.sample != layer.draw) dead.push_back({presents, Tex{VK_NULL_HANDLE, nullptr, layer.sample, VK_NULL_HANDLE}}); + layer = Layer{}; + } + const VkFormat sample_format = unorm_of(pipeline_format); + VkImageCreateInfo ci{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; + ci.flags = sample_format != pipeline_format ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0; + ci.imageType = VK_IMAGE_TYPE_2D; + ci.format = pipeline_format; + ci.extent = {w, h, 1}; + ci.mipLevels = ci.arrayLayers = 1; + ci.samples = VK_SAMPLE_COUNT_1_BIT; + ci.tiling = VK_IMAGE_TILING_OPTIMAL; + ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + Layer made; + bool ok = create_image(ci, made.image, made.alloc); + VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; + vi.image = made.image; + vi.viewType = VK_IMAGE_VIEW_TYPE_2D; + vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + vi.format = pipeline_format; + if (ok) ok = vkCreateImageView(dev.device, &vi, nullptr, &made.draw) == VK_SUCCESS; + vi.format = sample_format; + if (ok && sample_format == pipeline_format) made.sample = made.draw; + else if (ok) ok = vkCreateImageView(dev.device, &vi, nullptr, &made.sample) == VK_SUCCESS; + if (!ok) { // (nothing recorded uses them yet) + static bool told = false; + if (!told) + told = true, logf("vk: ui: the options' layer under N64 Classic's TV (%ux%u, format %d) could not be made: they go over " + "the window as before", w, h, (int)pipeline_format); + if (made.draw) vkDestroyImageView(dev.device, made.draw, nullptr); + if (made.image) destroy_image(made.image, made.alloc); + return false; + } + made.w = w, made.h = h, made.format = pipeline_format; + layer = made; + return true; +} +/// The lists to draw (the empty left out), in an ImDrawData of its own over a w x h image whose corner is (x, y) of the window +ImDrawData part_of(std::initializer_list lists, float x, float y, uint32_t w, uint32_t h) { + ImDrawData d; + d.Valid = true; + d.DisplayPos = ImVec2(x, y); + d.DisplaySize = ImVec2((float)w, (float)h); + d.FramebufferScale = ImVec2(1.0f, 1.0f); + for (ImDrawList* l : lists) { + if (!l || l->CmdBuffer.Size == 0 || l->VtxBuffer.Size == 0) continue; + d.CmdLists.push_back(l); + d.TotalVtxCount += l->VtxBuffer.Size; + d.TotalIdxCount += l->IdxBuffer.Size; + } +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + d.CmdListsCount = d.CmdLists.Size; +#endif + return d; +} +} // namespace + +VkImageView record_layer(VkCommandBuffer cmd, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { + ImGui::Render(); + ImDrawData* dd = ImGui::GetDrawData(); + presents++; + reap(false); + split = true, split_layer = false; + split_place[0] = (float)x, split_place[1] = (float)y, split_place[2] = (float)w, split_place[3] = (float)h; + // (the overlays' colours once for the frame as an sRGB window image takes them: the layer's drawing view is of that format + // too. HDR10's are made in record_rest, for the window alone: the layer is SDR, as the picture it goes into) + if (srgb_target) linearize(dd); + split_wait = !textures(cmd, dd); + if (split_wait) return VK_NULL_HANDLE; + ImDrawData d = part_of({ImGui::GetBackgroundDrawList()}, (float)x, (float)y, w, h); + if (d.CmdLists.empty() || !layer_fit(w, h)) return VK_NULL_HANDLE; // (nothing of the options; or no layer: over the window) + layout(cmd, layer.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, 0, + VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT); + VkRenderingAttachmentInfo ca{VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO}; + ca.imageView = layer.draw; + ca.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + ca.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // (nothing: the options' colours over it come out premultiplied by their cover) + ca.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + ca.clearValue.color = VkClearColorValue{{0.0f, 0.0f, 0.0f, 0.0f}}; + VkRenderingInfo ri{VK_STRUCTURE_TYPE_RENDERING_INFO}; + ri.renderArea = {{0, 0}, {w, h}}; + ri.layerCount = 1; + ri.colorAttachmentCount = 1; + ri.pColorAttachments = &ca; + vkCmdBeginRendering(cmd, &ri); + ImGui_ImplVulkan_RenderDrawData(&d, cmd); + vkCmdEndRendering(cmd); + layout(cmd, layer.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, VK_ACCESS_2_SHADER_SAMPLED_READ_BIT); + split_layer = true; + return layer.sample; +} + +void record_rest(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) { + if (!split) return; + split = false; + if (split_wait || index >= dev.swap_views.size() || !dev.swap_views[index]) return; + ImDrawData* dd = ImGui::GetDrawData(); + if (!srgb_target && dev.hdr) hdr10(dd); // (the window's part: at the paper white, as record_to has it) + ImDrawList* under = ImGui::GetBackgroundDrawList(); + ImDrawList* over = ImGui::GetForegroundDrawList(); + if (!split_layer) { // (the options not in a layer: over the window, under the rest, as before) + ImDrawData d = part_of({under, over}, 0.0f, 0.0f, w, h); + if (!d.CmdLists.empty()) render_over(cmd, dev.swap_images[index], dev.swap_views[index], w, h, &d); + return; + } + // (the options in the layer, under the TV: what of them lies beside the picture's place, on the black bars of another + // shape, still over the window, cut to those bars; then the rest) + const float x0 = split_place[0], y0 = split_place[1], x1 = x0 + split_place[2], y1 = y0 + split_place[3]; + const float W = (float)w, H = (float)h; + const ImVec4 bars[4] = {{0, 0, W, y0}, {0, y1, W, H}, {0, y0, x0, y1}, {x1, y0, W, y1}}; + std::vector cut; + for (const ImVec4& bar : bars) { + if (bar.z <= bar.x || bar.w <= bar.y || !under->CmdBuffer.Size || !under->VtxBuffer.Size) continue; + ImDrawList* c = under->CloneOutput(); + for (ImDrawCmd& dc : c->CmdBuffer) // (none left of one: the backend skips it) + dc.ClipRect = ImVec4(std::max(dc.ClipRect.x, bar.x), std::max(dc.ClipRect.y, bar.y), std::min(dc.ClipRect.z, bar.z), + std::min(dc.ClipRect.w, bar.w)); + cut.push_back(c); + } + ImDrawData d = part_of({}, 0.0f, 0.0f, w, h); + for (ImDrawList* l : cut) d.CmdLists.push_back(l), d.TotalVtxCount += l->VtxBuffer.Size, d.TotalIdxCount += l->IdxBuffer.Size; + if (over && over->CmdBuffer.Size && over->VtxBuffer.Size) + d.CmdLists.push_back(over), d.TotalVtxCount += over->VtxBuffer.Size, d.TotalIdxCount += over->IdxBuffer.Size; +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + d.CmdListsCount = d.CmdLists.Size; +#endif + if (!d.CmdLists.empty()) render_over(cmd, dev.swap_images[index], dev.swap_views[index], w, h, &d); + for (ImDrawList* l : cut) IM_DELETE(l); +} void record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) { const bool has = index < dev.swap_views.size() && dev.swap_views[index]; diff --git a/gpu/vk/vk_imgui.h b/gpu/vk/vk_imgui.h index 6e29cf1..cca8873 100644 --- a/gpu/vk/vk_imgui.h +++ b/gpu/vk/vk_imgui.h @@ -51,6 +51,16 @@ void record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h); /// The same over another image (TRANSFER_DST_OPTIMAL before and after, colour-attachment use, a view of it; headless, the /// shots' RGBA: vk_replay.cpp RX_VK_SHOT_MENU) void record_to(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h); +/// ((Triforce, 11-22, N64 Classic) The frame's drawing in two, for the options under N64 Classic's TV (vk_menu.cpp +/// menu_tv_layer): the background list's (the options') into a layer of w x h, the window's place (x, y) at its corner, +/// cleared first and GENERAL after, for the TV's pass to sample; its colours premultiplied by their cover, encoded as the +/// picture is. Returns that layer's view, or null: nothing of the options, or no layer (record_rest then draws them over the +/// window as before). New glyphs and textures are copied in on cmd here, for the whole frame +VkImageView record_layer(VkCommandBuffer cmd, uint32_t x, uint32_t y, uint32_t w, uint32_t h); +/// ...and the rest of that frame over the window's image `index` (as record): the foreground list (the FPS counter, the notice, +/// benchmark mode's panel), and what of the options lies beside the layer's place (black bars of another shape). Nothing +/// when record_layer did not draw this frame +void record_rest(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h); /// A present with nothing drawn: what record let go is destroyed once the GPU is done with it, all the same void idle(); /// The glyphs (printable ASCII) of every font at these pixel sizes, baked a few sizes a frame from the next begin on: the diff --git a/gpu/vk/vk_menu.cpp b/gpu/vk/vk_menu.cpp index 3944161..9d371fa 100644 --- a/gpu/vk/vk_menu.cpp +++ b/gpu/vk/vk_menu.cpp @@ -78,14 +78,17 @@ #include "merged_rows.h" // ((Triforce, options_version 7) the rows that each choose two saved values, and the older files' migration) #include "aa_rows.h" // (Triforce, the Anti-aliasing row: its choices, and when it does not apply) #include "vk_aa.h" // (...RX_VK_AA over it, and whether the game's pass was there to replace) +#include "vk_n64.h" // ((Triforce, N64 Classic, step 4) its TV in the window filter's place) #include "tex_detail.h" // (the Texture detail row: the levels' names, RX_VK_TEX_DETAIL) #include "fps_cap.h" // (the Game frame rate cap row's Monitor's rate) #include "ultrawide_rows.h" // ((Triforce) the Ultrawide row's shapes, and its old Monitor's shape read before options_version 6) +#include "output_sizes.h" // ((Triforce) the Output resolution row's sizes: the fixed ones, Screen and Custom) #include "present_mode.h" // (the VSync row: what its choice comes to on this driver) #include "game_language.h" // (the Game language row: what language.txt chooses and offers) #include "menu_restart.h" #include "mod_cheat_rows.h" // (Triforce: the System tab's rows for the cheats of the mods' cheat files) #include "achievement_rows.h" // (Triforce: the achievements the host names, their notice and their page) +#include "save_file_rows.h" // (Triforce: the save files the host names, and the title's file select) #include "menu_sound_events.h" // (Triforce: the options' own sounds: which one a tick asks for, and their queue to the host) #include "mods_entry_anim.h" // ((Triforce, 11-19) the Mods entry under the title's list: the game's entries' animations) #include "focus_anim.h" // ((Triforce, 11-19) Mods and Quit under the System list, Quit's dialog: the game's buttons' and dialogs') @@ -130,7 +133,9 @@ enum MenuTab { TAB_MOTION = TAB_COUNT, // (hookshot: not a tab of the strip, the Motion page that the Controls tab's Motion row // opens: one past the strip's tabs, so a tab added before TAB_COUNT moves it along) TAB_PAGE = TAB_MOTION + 1, // (hookshot: the Controls page's rows, above its grid; no tab shows them) - TAB_HIDDEN = TAB_PAGE + 1 // ((Triforce, options_version 7) saved values a merged row stands for: never shown, merged_rows.h) + TAB_N64 = TAB_PAGE + 1, // ((Triforce, 11-22, N64 Classic, step 5) the Remembered page that the Graphics tab's + // Remembered settings row opens: no tab shows it) + TAB_HIDDEN = TAB_N64 + 1 // ((Triforce, options_version 7) saved values a merged row stands for: never shown, merged_rows.h) }; struct Row { @@ -307,6 +312,7 @@ unsigned upscalers_available() { int upscaler() { return fsr3_wanted() ? (int)(fsr3_native() ? ur::FSR3_AA : ur::FSR3) : temporal_mode(); } /// ((Triforce, options_version 7) the engine alone: an engine's native AA is the Render resolution row's Native (100%)) const char* tx_upscaler(int) { + if (n64_in_front() != n64_rules::OFF) return "N64 Classic"; // ((Triforce, N64 Classic) its 3D pass draws in their place) static const char* t[ur::kUpscalers] = {"Game", "NVIDIA DLSS", "NVIDIA DLSS", "AMD FSR 3.1", "AMD FSR 4", "AMD FSR 4", "AMD FSR 3.1"}; // ((Triforce, FSR4-7) FSR 4 by the version AMD's library runs here, "AMD FSR 4.1", once it has been asked. up is the @@ -486,22 +492,243 @@ struct Out { uint32_t w, h; }; // ((Triforce, 11-16, the owner: "Add a resolution of 5120x2160 before 5120x2880") 6 is 5120x2160, after the others so that the -// saved numbers keep their sizes; kOutputOrder shows it between 5120x1440 and 5120x2880) -// ((Triforce, options_version 7) 7 is 1536x864, the game's handheld profile, which was a row of its own (Handheld profile) that -// overrode this one: host/nn_applet.c runs the game undocked for it. kOutputOrder shows it first, the smallest) +// saved numbers keep their sizes. (Triforce) 8 Screen and 9 Custom take their sizes from outside the build. The rule for all of +// them is output_sizes.h's: the size is the picture's, the game's frame 16:9 at its height constexpr Out kOutputs[] = {{2048, 1152}, {2560, 1440}, {3840, 2160}, {1920, 1080}, {5120, 1440}, {5120, 2880}, {5120, 2160}, {1536, 864}}; -constexpr int kLastOutput = std::size(kOutputs) - 1; -static_assert(kLastOutput == merged_rows::kHandheldOutput, "the Output resolution row's handheld profile is merged_rows.h's"); +static_assert(std::size(kOutputs) == OUTPUT_FIXED_N); +constexpr int kLastOutput = OUTPUT_LAST; int output_choice(int v) { return v >= 0 && v <= kLastOutput ? v : 0; } -// Display the sizes from smallest to largest while keeping the IDs used by saved settings. -constexpr int kOutputOrder[] = {7, 3, 0, 1, 2, 4, 6, 5}; -static_assert(std::size(kOutputOrder) == std::size(kOutputs)); -int step_output_choice(int id, int dir) { - const int* pos = std::find(std::begin(kOutputOrder), std::end(kOutputOrder), output_choice(id)); - const int next = std::clamp((int)(pos - std::begin(kOutputOrder)) + dir, 0, kLastOutput); - return kOutputOrder[next]; +// The connected screens as the host found them at the start (MkwVkHost.screens, at menu_init): each one's native size, the +// size the game takes it at (output_size_used: {0, 0} for none), the monitor's own name, and whether the window opens on it. +// The row offers each one's size; what is saved is that size, as Custom's (output_width=, output_height=), never a place in +// this list: the same file means the same picture with other screens connected, and a size whose screen is gone is Custom +struct Screen { + Out native, used; + std::string name; + bool opens; +}; +std::vector screens; +void screen_add(uint32_t w, uint32_t h, const char* name, bool opens) { + unsigned uw = 0, uh = 0; + if (!output_size_used(w, h, &uw, &uh)) return; + screens.push_back(Screen{Out{w, h}, Out{uw, uh}, name ? name : "", opens}); +} +/// The screen the window opens on, nullptr when the host knows none +const Screen* screen_opening() { + for (const Screen& s : screens) + if (s.opens) return &s; + return nullptr; +} +/// The main monitor's size, for an options file from before options_version 6 whose Ultrawide row was Monitor's shape: the +/// one the host reads that row by (host/hos_main.c, host/nn_applet.c: GetSystemMetrics). Off Windows that is the desktop's +/// main display (host/posix/win32_posix.c, display_sdl.c), which is the screen the window opens on; the renderer has no +/// GetSystemMetrics there, and takes it from the host's screens. {0, 0} when none is known: 16:9, for the host as well +Out main_screen() { +#ifdef _WIN32 + return Out{(uint32_t)std::max(GetSystemMetrics(SM_CXSCREEN), 0), (uint32_t)std::max(GetSystemMetrics(SM_CYSCREEN), 0)}; +#else + return screen_opening() ? screen_opening()->native : Out{0, 0}; +#endif +} +/// The connected screens of a size, as the game takes them, by name: "LG ULTRAGEAR", "2x LG ULTRAGEAR", "DELL U2720Q, LG +/// ULTRAGEAR"; one the system gives no name is "Screen". "" when no screen has that size +std::string screen_names(Out size) { + std::vector> names; + for (const Screen& s : screens) { + if (s.used.w != size.w || s.used.h != size.h) continue; + const std::string name = s.name.empty() ? "Screen" : s.name; + const auto at = std::find_if(names.begin(), names.end(), [&](const auto& n) { return n.first == name; }); + if (at == names.end()) names.push_back({name, 1}); + else at->second++; + } + std::string all; + for (const auto& [name, count] : names) + all += (all.empty() ? "" : ", ") + (count > 1 ? std::to_string(count) + "x " : std::string()) + name; + return all; +} +/// HOS_OUTPUT_SIZE's size, which the host takes over the Custom rows for the run: true and the sides while it is set (a +/// value that is not x: 0 x 0, no size, as the host) +bool custom_env(long* w = nullptr, long* h = nullptr) { + const char* e = getenv("HOS_OUTPUT_SIZE"); + if (!e) return false; + long ew = 0, eh = 0; + if (!output_parse_size(e, &ew, &eh)) ew = eh = 0; + if (w) *w = ew; + if (h) *h = eh; + return true; +} +/// Custom's size as the game takes it: the Output width and Output height rows' (HOS_OUTPUT_SIZE's over them) within what a +/// picture can be, output_size_used; {0, 0} for none (a HOS_OUTPUT_SIZE that is not a size) +Out custom_size() { + long w = opts.output_width, h = opts.output_height; + custom_env(&w, &h); + unsigned uw = 0, uh = 0; + return output_size_used(w, h, &uw, &uh) ? Out{uw, uh} : Out{0, 0}; +} +/// The Custom rows' values from the options file's output_width= and output_height= (0: no line), at menu_init: as written +/// where the rows can hold them, else the size the game takes them as (output_size_used: its shape kept, which keeping each +/// row to its own ends would not), so that the menu shows and saves what the host ran (host/nn_applet.c flex_read) +void custom_rows_read(long w, long h) { + output_custom_read(&w, &h); + unsigned uw = 0, uh = 0; + const bool held = w >= OUTPUT_MIN_W && w <= OUTPUT_MAX_W && h >= OUTPUT_MIN_H && h <= OUTPUT_MAX_H; + if (!held && output_size_used(w, h, &uw, &uh)) w = uw, h = uh; + opts.output_width = (int)w, opts.output_height = (int)h; +} +// While a screen occupies the two active output fields, retain the player's unrounded Custom input. +Out remembered_custom{}; +void restore_custom() { + if (!remembered_custom.h) return; + opts.output_width = (int)remembered_custom.w; + opts.output_height = (int)remembered_custom.h; + remembered_custom = {}; +} +void choose_screen(Out size) { + if (!remembered_custom.h) remembered_custom = Out{(unsigned)opts.output_width, (unsigned)opts.output_height}; + unsigned w, h; + if (output_size_used(remembered_custom.w, remembered_custom.h, &w, &h) && w == size.w && h == size.h) { + restore_custom(); + return; + } + opts.output_width = (int)size.w; + opts.output_height = (int)size.h; +} +void read_remembered_custom(const char* text) { + long w = 0, h = 0; + if (output_parse_size(text, &w, &h) && + w >= OUTPUT_MIN_W && w <= OUTPUT_MAX_W && h >= OUTPUT_MIN_H && h <= OUTPUT_MAX_H) + remembered_custom = Out{(unsigned)w, (unsigned)h}; +} +/// The size of a saved value: a fixed one's, Custom's, or the old Screen's ({0, 0}: none) +Out row_size(int v) { + v = output_choice(v); + if (v == OUTPUT_SCREEN) return screen_opening() ? screen_opening()->used : Out{0, 0}; // (the old Screen value: as the host) + return v < OUTPUT_SCREEN ? kOutputs[v] : custom_size(); +} +/// The size a choice runs at: the row's, 2560x1440 when Screen or Custom has none, as the host +Out output_size_of(int v) { + const Out s = row_size(v); + return s.h ? s : kOutputs[1]; +} +/// Whether a choice's size has a shape of its own, not 16:9: its picture is that size, and the Ultrawide row has nothing to +/// choose (docked only: the handheld profile runs the game's own output) +bool output_shaped(int v) { + const Out s = output_size_of(v); + return opts.output_res != merged_rows::kHandheldOutput && output_size_shaped(s.w, s.h); +} +/// The game's frame for a choice, its HUD, menus and story movies: the size, or 16:9 at its height when it has another shape +Out output_frame(int v) { + const Out s = output_size_of(v); + return output_size_shaped(s.w, s.h) ? Out{output_frame_width(s.h), s.h} : s; +} +/// HOS_ASPECT's shape, which the host takes over the Output resolution's and the Ultrawide row's for the run; 0 when not set +float aspect_env() { + const char* e = getenv("HOS_ASPECT"); + return e ? (float)atof(e) : 0.0f; +} +/// The picture the options give at the next start, as host/hos_main.c makes it (output_picture): the Output resolution's size +/// when it has its own shape, else its height in the Ultrawide row's shape (HOS_ASPECT's over both). 2048x1152 is the game's +/// 2560x1440 at its graphics scale 0.8 (host/nn_applet.c), its wider picture too +Out output_picture_of(int v, int ultrawide_row) { + v = output_choice(v); + const Out size = output_size_of(v), frame = v ? output_frame(v) : kOutputs[1]; + const bool env = getenv("HOS_ASPECT") != nullptr; + const bool sized = !env && output_size_shaped(size.w, size.h); + const double want = env ? aspect_env() : sized ? (double)size.w / (double)size.h : ultrawide_row_ratio(ultrawide_row); + unsigned w = 0, h = 0; + if (!output_picture(frame.h, want, sized, &w, &h)) return v ? frame : kOutputs[0]; + return v ? Out{w, h} : Out{w * 4 / 5, h * 4 / 5}; +} +// The row's choices: the fixed sizes, each connected screen's size that is not one of those (once for screens of one size), and +// Custom where its size is not a screen's. Smallest to largest, by width and then height; of one size a fixed one first; one +// with no size at the end. A choice is saved as its value: a fixed size's number, or OUTPUT_CUSTOM with the size in the Output +// width and Output height rows, which choosing a screen's size fills in with the size the game takes that screen at (size; +// native: that screen's own, {0, 0} for a choice that is no screen's) +struct OutEntry { + int id; + Out size, native; +}; +std::vector output_entries() { + std::vector e; + const auto has = [&](int id, Out s) { + return std::any_of(e.begin(), e.end(), [&](const OutEntry& x) { return x.id == id && x.size.w == s.w && x.size.h == s.h; }); + }; + // (a screen of a fixed size is that fixed choice, the same picture; but not of 2048x1152, which is the game's 2560x1440 at + // its own scale and not a 2048x1152 picture) + const auto fixed = [](Out s) { + for (int v = 1; v < OUTPUT_FIXED_N; v++) + if (v != merged_rows::kHandheldOutput && kOutputs[v].w == s.w && kOutputs[v].h == s.h) return true; + return false; + }; + for (int v = 0; v < OUTPUT_FIXED_N; v++) e.push_back(OutEntry{v, kOutputs[v], Out{0, 0}}); + // (HOS_OUTPUT_SIZE is Custom's size for the run: a screen's size cannot be chosen then) + for (const Screen& s : screens) + if (!custom_env() && !fixed(s.used) && !has(OUTPUT_CUSTOM, s.used)) e.push_back(OutEntry{OUTPUT_CUSTOM, s.used, s.native}); + // (the old Screen value, only while it is still what is chosen: menu_init makes it the screen's size, output_adopt_screen) + if (output_choice(opts.output_res) == OUTPUT_SCREEN) e.push_back(OutEntry{OUTPUT_SCREEN, row_size(OUTPUT_SCREEN), Out{0, 0}}); + // A fixed choice can have a remembered Custom in an edited file. Only the remembered pair is restored. + if ((opts.output_res == OUTPUT_CUSTOM || !remembered_custom.h || custom_env()) && !has(OUTPUT_CUSTOM, custom_size())) + e.push_back(OutEntry{OUTPUT_CUSTOM, custom_size(), Out{0, 0}}); + if (remembered_custom.h && !custom_env()) { + unsigned w, h; + if (output_size_used(remembered_custom.w, remembered_custom.h, &w, &h) && !has(OUTPUT_CUSTOM, Out{w, h})) + e.push_back(OutEntry{OUTPUT_CUSTOM, Out{w, h}, Out{0, 0}}); + } + const auto key = [](const OutEntry& x) { return x.size.h ? (uint64_t)x.size.w << 32 | x.size.h : ~0ull; }; + std::stable_sort(e.begin(), e.end(), [&](const OutEntry& a, const OutEntry& b) { return key(a) < key(b); }); + return e; +} +/// The choice the options have now: the saved value's, and for Custom the one of its size (a screen's, or Custom itself) +int output_entry_now(const std::vector& e) { + const int v = output_choice(opts.output_res); + const Out c = custom_size(); + for (size_t i = 0; i < e.size(); i++) + if (e[i].id == v && (v != OUTPUT_CUSTOM || (e[i].size.w == c.w && e[i].size.h == c.h))) return (int)i; + return 0; +} +/// A choice as the row shows it: the size, with the names of the connected screens that have it ("3840x1600 (LG ULTRAGEAR)"); +/// Custom with its size +std::string output_label(const OutEntry& x) { + if (!x.size.h) return x.id == OUTPUT_SCREEN ? "Screen (not known)" : "Custom (not set)"; + if (x.id == merged_rows::kHandheldOutput) return "1536x864 (handheld)"; + const std::string size = std::to_string(x.size.w) + "x" + std::to_string(x.size.h); + if (x.id == OUTPUT_CUSTOM && !x.native.h) return "Custom (" + size + ")"; + if (x.id == 0) return size; // (the game's own: no screen's size, output_entries) + const std::string names = screen_names(x.size); + return names.empty() ? (x.id == OUTPUT_SCREEN ? "Screen (" + size + ")" : size) : size + " (" + names + ")"; +} +/// One choice down or up the row (dir -1 or 1): false at its end. With apply the options take it: its value, and a +/// screen's size as Custom's +bool output_step(int dir, bool apply) { + const std::vector e = output_entries(); + const int at = output_entry_now(e), to = std::clamp(at + dir, 0, (int)e.size() - 1); + if (to == at) return false; + if (apply) { + opts.output_res = e[to].id; + // (the size as the game takes it, which the rows can always hold: a 7680x4320 screen's is 5120x2880, not each side cut + // to the rows' ends, which would be another shape) + if (e[to].native.h) choose_screen(e[to].size); + else restore_custom(); + } + return true; +} +/// An options file's output_res=8, Screen (and HOS_OUTPUT_RES=8): the size of the screen the window opens on, which +/// is what the host ran it as at this start (host/nn_applet.c). The menu keeps it as that size, Custom's, so that the next +/// save writes a size and not "whichever screen" (a fixed size's number where it is one); with no screen known, the +/// 2560x1440 the host ran. Left alone while +/// HOS_OUTPUT_SIZE is Custom's size +void output_adopt_screen() { + if (output_choice(opts.output_res) != OUTPUT_SCREEN || custom_env()) return; + const Screen* s = screen_opening(); + opts.output_res = s ? OUTPUT_CUSTOM : 1; + for (int v = 1; s && v < OUTPUT_FIXED_N; v++) // (a screen of a fixed size: that fixed choice) + if (v != merged_rows::kHandheldOutput && kOutputs[v].w == s->used.w && kOutputs[v].h == s->used.h) opts.output_res = v; + if (s && opts.output_res == OUTPUT_CUSTOM) choose_screen(s->used); +} +/// The picture the menu's sizes are shown for (the Render resolution's, the performance panel's) +Out shown_output() { + return opts.output_res == merged_rows::kHandheldOutput ? Out{1536, 864} : output_picture_of(opts.output_res, opts.ultrawide); } -Out shown_output() { return kOutputs[output_choice(opts.output_res)]; } // The size the game draws the 3D at for a fixed scale of its output, a twelfth of it: every twelfth asked came out exact at the three // outputs (2048x1152: 0.58 drew 1195x672, 0.6667 1366x768). So the scale the game is given is the twelfth too: 0.67 drew 2615x1471 at // 3840x2160, not the 2560x1440 of 8/12. @@ -561,6 +788,7 @@ const char* hn_resolution(int v, int variant) { /// (Triforce) The Anti-aliasing row (aa_rows.h, vk_aa.h): its choice, RX_VK_AA's for the run over it; while DLSS or FSR /// draws, whose anti-aliasing the picture has instead const char* tx_aa(int v) { + if (n64_in_front() != n64_rules::OFF) return "N64 Classic"; // ((Triforce, N64 Classic) its grid smooths the edges) const int up = upscaler(); if (ur::is_dlss(up)) return "DLSS's own"; if (aa_rows::upscaler_own(up)) return "FSR's own"; @@ -583,11 +811,14 @@ const char* hn_aa(int v, int variant) { static const char* const missing = "No frame of the last minute had the game's own anti-aliasing pass to replace (a screen without the 3D, or another " "version of the game): the picture is the game's."; + static const char* const n64 = // ((Triforce, N64 Classic) variant 5) + "N64 Classic draws the 3D on its own grid, which smooths the edges: nothing to set here while it is on. The choice is " + "kept for when it is off."; if (variant < 0) { const int up = upscaler(); const bool asked = aa_rows::chosen(v, aa_env_choice()) != aa_rows::GAME; - variant = ur::is_dlss(up) ? 1 : aa_rows::upscaler_own(up) ? 2 : asked && aa_state() == aa_rows::MISSING ? 4 - : aa_env_choice() >= 0 ? 3 : 0; + variant = n64_in_front() != n64_rules::OFF ? 5 : ur::is_dlss(up) ? 1 : aa_rows::upscaler_own(up) ? 2 + : asked && aa_state() == aa_rows::MISSING ? 4 : aa_env_choice() >= 0 ? 3 : 0; } switch (variant) { case 0: return t[v >= 0 && v < aa_rows::kValues ? v : 0]; @@ -595,34 +826,162 @@ const char* hn_aa(int v, int variant) { case 2: return own[1]; case 3: return env; case 4: return missing; + case 5: return n64; default: return nullptr; } } +int shape_owner(); +// ---- ((Triforce, 11-22, N64 Classic, step 5) its row and the Remembered page (n64_rules.h; vk_n64.cpp) ---- +void save(); // (below) +/// The N64 Classic row: its value's name, RX_VK_N64's for the run over it +const char* tx_n64(int v) { return n64_rules::name(n64_env_set() ? n64_preset() : v); } +/// The N64 Classic row: the value chosen (variant 0), or that RX_VK_N64 set it for this run (1) +const char* hn_n64(int v, int variant) { + static const char* const t[n64_rules::kPresets] = { + "The remake as it is.", + "The 1998 cartridge on a TV of then: the 3D on 240 lines with 16-bit colour and its dither, blurry textures, scanlines " + "and a curved screen, at 20 frames a second. Always the same.", + "How you remember it: sharper and richer than the real thing. Set it to your taste in Remembered settings."}; + static const char* const env = "Set for this run by RX_VK_N64, whatever is chosen here."; + if (variant < 0) variant = n64_env_set() ? 1 : 0; + if (variant == 0) return t[v >= 0 && v < n64_rules::kPresets ? v : 0]; + return variant == 1 ? env : nullptr; +} +const char* tx_n64_fps(int v) { + static const char* const t[] = {"Frame rate cap", "60", "30", "20 (1998)", "17 (1998, 50 Hz)"}; + return t[std::clamp(v, 0, 4)]; +} +const char* tx_n64_lines(int v) { + static const char* const t[] = {"240 lines", "360 lines", "480 lines", "720 lines"}; + return t[std::clamp(v, 0, 3)]; +} +const char* tx_n64_colour(int v) { + static const char* const t[] = {"15-bit (1998)", "18-bit", "Full"}; + return t[std::clamp(v, 0, 2)]; +} +const char* tx_n64_dither(int v) { + static const char* const t[] = {"Off", "Light", "Full"}; + return t[std::clamp(v, 0, 2)]; +} +const char* tx_n64_blur(int v) { + static char b[16]; + if (v <= 0) return "Off"; + snprintf(b, sizeof b, "+%.1f", v * n64_rules::kBlurStep); + return b; +} +const char* tx_n64_mask(int v) { + static const char* const t[] = {"Auto", "Off", "Aperture grille", "Slot mask", "Shadow mask"}; + return t[std::clamp(v, 0, 4)]; +} +const char* tx_n64_bleed(int v) { + static const char* const t[] = {"Off", "Light", "Composite"}; + return t[std::clamp(v, 0, 2)]; +} +const char* tx_n64_curve(int v) { + static const char* const t[] = {"Flat", "Slight", "Curved", "Very curved"}; + return t[std::clamp(v, 0, 3)]; +} +/// A Remembered page row's place in n64_rules::Rows (its value is opts.n64_rem's), -1 for any other value +int n64_rem_row(const int* value) { + const int* first = &opts.n64_rem[0]; + return value && value >= first && value < first + n64_rules::kRows ? (int)(value - first) : -1; +} +/// The Graphics tab's row that opens the Remembered page (the TAB_N64 rows), as the Motion row opens the Motion page +bool is_n64_page_row(const Row& r) { return r.tab == TAB_GRAPHICS && !r.value && !strcmp(r.name, "Remembered settings"); } +/// The Remembered page's two actions: 1 Copy Faithful, 2 Reset to defaults; 0 another row +int n64_action(const Row& r) { + if (r.tab != TAB_N64 || r.value) return 0; + return !strcmp(r.name, "Copy Faithful") ? 1 : !strcmp(r.name, "Reset to defaults") ? 2 : 0; +} +/// An action pressed: Faithful's values into Remembered's rows (20 frames a second too), or Remembered's defaults; saved +void n64_act(int action) { + if (action != 1 && action != 2) return; + const n64_rules::Rows to = action == 1 ? n64_rules::kFaithful : n64_rules::defaults(); + std::copy(std::begin(to.v), std::end(to.v), opts.n64_rem); + save(); +} /// A row with nothing else to choose here: shown without its arrows, Left and Right leave it (and the saved value) alone bool row_fixed(const int* value) { + // ((Triforce) the Ultrawide row while the Output resolution's own shape or HOS_ASPECT is the picture's; the Custom rows + // while HOS_OUTPUT_SIZE is Custom's size) + if (value == &opts.ultrawide && shape_owner() != 0) return true; + if ((value == &opts.output_width || value == &opts.output_height) && custom_env()) return true; // ((Triforce, options_version 7) the rows that showed fixed where they could do nothing (Reflex, Anti-Lag, the window's // filter, the Render resolution with a native AA) are hidden there, or gone: row_shown) return (value == &opts.aa && aa_rows::fixed(upscaler(), aa_env_choice() >= 0)) || (value == &opts.dlss && ur::upscaler_fixed(upscalers_available())) || - (value == &opts.dlss_model && ur::model_fixed(upscaler(), dlss_preset_env() != nullptr)); + (value == &opts.dlss_model && ur::model_fixed(upscaler(), dlss_preset_env() != nullptr)) || + // ((Triforce, 11-22, N64 Classic) the Upscaler and the Anti-aliasing while its 3D pass draws in their place; its own + // row with RX_VK_N64 set for the run; a Remembered row with nothing to do (n64_rules.h row_fixed) + ((value == &opts.dlss || value == &opts.aa) && n64_in_front() != n64_rules::OFF) || + (value == &opts.n64_classic && n64_env_set()) || + (n64_rem_row(value) >= 0 && n64_rules::row_fixed(n64_rules::rows_of(opts.n64_rem), n64_rem_row(value))); } const char* tx_output_res(int v) { - static char b[32]; + static char b[200]; + const std::vector e = output_entries(); v = output_choice(v); if (v == merged_rows::kHandheldOutput) return "1536x864 (handheld)"; - const Out o = kOutputs[v]; - snprintf(b, sizeof b, "%ux%u", o.w, o.h); // ((Triforce, 11-16) the size alone; the hint says which is the game's own) + size_t at = (size_t)output_entry_now(e); + if (e[at].id != v) { // (not the value chosen: a fixed size's own choice, or Custom's) + for (size_t i = 0; i < e.size(); i++) + if (e[i].id == v && (e[at].id != v || !e[i].native.h)) at = i; + } + snprintf(b, sizeof b, "%s", output_label(e[at]).c_str()); return b; } +/// (Triforce) The Output width and Output height rows (output_width=, output_height=): a side in pixels as chosen, or +/// HOS_OUTPUT_SIZE's while it is set. What the game makes of the two is the Output resolution row's Custom (custom_size) +const char* tx_custom_side(int v, bool height) { + static char b[2][16]; + long w = 0, h = 0; + if (custom_env(&w, &h)) v = (int)(height ? h : w); + if (v > 0) snprintf(b[height], sizeof b[height], "%d", v); + else snprintf(b[height], sizeof b[height], "Not set"); + return b[height]; +} +const char* tx_custom_width(int v) { return tx_custom_side(v, false); } +const char* tx_custom_height(int v) { return tx_custom_side(v, true); } const char* tx_speed(int v) { return v ? "Real time" : "Per frame"; } const char* tx_text_speed(int v) { static const char* t[] = {"Normal", "2x", "4x", "Instant"}; if ((unsigned)v >= sizeof t / sizeof t[0]) return t[0]; return t[v]; } -const char* tx_ultrawide(int v) { // (Triforce: 1 to 3, the fixed shapes, ultrawide_rows.h; host/hos_main.c ultrawide_ratio) - static const char* const t[] = {"16:9", "16:10", "21:9", "32:9"}; - return t[std::min(std::max(v, 0), 3)]; +const char* tx_ultrawide(int v) { // (Triforce: 1 to 4, the fixed shapes, ultrawide_rows.h; host/hos_main.c ultrawide_ratio) + static const char* const t[] = {"16:9", "16:10", "21:9", "32:9", "4:3"}; + return t[std::min(std::max(v, 0), 4)]; +} +/// A shape, width over height, by name: one of the Ultrawide row's where it is that one, else its width for a height of 1 +/// (3840x1600: 2.40:1) +const char* shape_name(double ratio) { + static char b[16]; + for (int row = 1; row <= 3; row++) + if (fabs(ratio / (double)ultrawide_row_ratio(row) - 1.0) < 0.001) return tx_ultrawide(row); + snprintf(b, sizeof b, "%.2f:1", ratio); + return b; +} +/// What decides the picture's shape at the next start, as host/hos_main.c takes it: 2 HOS_ASPECT, 1 the Output resolution's +/// own shape (a size that is not 16:9), 0 the Ultrawide row +int shape_owner() { return getenv("HOS_ASPECT") ? 2 : output_shaped(opts.output_res) ? 1 : 0; } +/// The picture's shape at the next start by name: the Ultrawide row's choice v, or the shape that is the picture's whatever +/// is chosen there (shape_owner) +const char* shape_now(int v) { + const int owner = shape_owner(); + if (owner == 0) return tx_ultrawide(v); + if (owner == 2) return aspect_env() > 1.0f && !output_shape_is_game(aspect_env()) ? shape_name(aspect_env()) : tx_ultrawide(0); + const Out o = output_size_of(opts.output_res); + return shape_name((double)o.w / (double)o.h); +} +/// The Ultrawide row's value: its choice, or the shape the picture has whatever is chosen here, with where it comes from +const char* tx_shape(int v) { + static char b[48]; + const int owner = shape_owner(); + if (owner == 0) return tx_ultrawide(v); + const Out o = output_size_of(opts.output_res); + if (owner == 2) snprintf(b, sizeof b, "%s (HOS_ASPECT)", shape_now(v)); + else snprintf(b, sizeof b, "%s (%ux%u)", shape_now(v), o.w, o.h); + return b; } const char* tx_wide_hud(int v) { return v ? "Screen edges" : "Middle"; } const char* tx_prompts(int v) { @@ -861,10 +1220,12 @@ MENU_HINTS(hn_output_res, 0, "The game's own size.", "The sharpest on a 2560x1440 screen: nothing to scale to the window.", "The sharpest on a 3840x2160 screen. The game's render targets get a bigger GPU pool, so a full-size 3D fits.", "The sharpest on a 1920x1080 screen: the HUD and text pixel for pixel, nothing to scale to the window.", - "The sharpest on a 5120x1440 ultrawide screen: the whole frame pixel for pixel. The game's render targets get a bigger GPU pool, so a full-size 3D fits.", + "A 32:9 picture, the sharpest on a 5120x1440 ultrawide screen: pixel for pixel, the HUD in its 16:9 shape in the middle. The game's render targets get a bigger GPU pool, so a full-size 3D fits.", "The sharpest on a 5120x2880 (5K) screen: the whole frame pixel for pixel. The game's render targets get a bigger GPU pool, so a full-size 3D fits.", - "The sharpest on a 5120x2160 ultrawide screen: the whole frame pixel for pixel. The game's render targets get a bigger GPU pool, so a full-size 3D fits.", - "The game's handheld profile, as if the console were undocked: lighter on the graphics card, and softer.") + "A 21:9 picture, the sharpest on a 5120x2160 ultrawide screen: pixel for pixel, the HUD in its 16:9 shape in the middle. The game's render targets get a bigger GPU pool, so a full-size 3D fits.", + "The game's handheld profile, as if the console were undocked: lighter on the graphics card, and softer.", + "The size of the screen the game opens on, whatever its shape: pixel for pixel in fullscreen, the HUD in its 16:9 shape in the middle of a wider screen.", + "A connected screen's own size, pixel for pixel in fullscreen there, or any size set with Output width and Output height below (HOS_OUTPUT_SIZE over them, when it is set): up to the pixels of 5120x2880, the HUD in its 16:9 shape in the middle of a wider picture.") // ((Triforce, options_version 7) the Window scaling filter row is gone, and with it its hint: the sizes choose the filter, // upscaler_rows.h window_filter. FSR 1's RCAS follows the Sharpness row: none at 0, vk_framegen.cpp framegen_scale) /// Sharpness: off at 0; ((Triforce, S1, S7) else where it sharpens: the upscaler's 3D before the HUD (variant 1), or the @@ -882,7 +1243,23 @@ MENU_HINTS(hn_ultrawide, 0, "The game's own shape.", "A 21:9 picture whatever the screen (64:27, as a 2560x1080 screen): the window opens in that shape, and a screen of " "another shape shows it between black bars. The HUD keeps its 16:9 shape in the middle.", "A 32:9 picture whatever the screen (as a 5120x1440 screen): the window opens in that shape, and a screen of " - "another shape shows it between black bars. The HUD keeps its 16:9 shape in the middle.") + "another shape shows it between black bars. The HUD keeps its 16:9 shape in the middle.", + // ((Triforce, 11-22, N64 Classic, step 6) the 1998 TV's shape) + "A 4:3 picture whatever the screen, the shape of a TV of 1998: the world narrower at the sides, the HUD across its " + "width, and a screen of another shape shows it between black bars. With N64 Classic, its 3D is 320 x 240.") +/// The Ultrawide row's line: its value's (variant 0), or what sets the shape in its place (shape_owner): the Output +/// resolution's own shape (1), HOS_ASPECT (2) +const char* hn_shape(int v, int variant) { + if (variant < 0) variant = shape_owner(); + switch (variant) { + case 0: return hn_ultrawide(v, 0); + case 1: + return "The Output resolution's own shape: its size is the whole picture, and the HUD keeps its 16:9 shape in the " + "middle of a wider one. Nothing to set here; a 16:9 Output resolution takes its shape from this row."; + case 2: return "Set for this run by HOS_ASPECT, whatever is chosen here."; + default: return nullptr; + } +} const char* tx_wide_menus(int v) { static const char* t[] = {"Full width", "Centred, blurred sides", "Centred, black bars"}; return t[std::min(std::max(v, 0), 2)]; @@ -981,35 +1358,74 @@ bool is_merged(const int* v) { return v == &merged.hdr || v == &merged.framegen achievement_rows::List ach_list; achievement_rows::View ach_view; constexpr int kAchPage = 10; // (page: see kModsPage) -constexpr char kAchRow[] = "Achievements"; // (the row's name in the table below: is_ach_row tells it by it) +constexpr char kAchRow[] = "View achievements"; // (the row's name in the table below: is_ach_row tells it by it) constexpr int64_t kAchNoticeMs = 4000; // (how long a notice stays: host/achievements.c waits a little longer between two) int ach_columns = 2, ach_capacity = 8; // (the page's cards as last drawn: the keys move by them) int ach_notice = -1; // (the achievement the notice shows, -1 none) int64_t ach_notice_at = 0; // (and since when, prof_now) +// (Triforce) Save files, as the Nintendo 64 game had them (host/save_files.c keeps them, on unless HOS_SAVE_FILES=0, and names +// them for the menu: menu_option_set, HOS_OPT_FILES_*; save_file_rows.h has the list). The game reads its saves once, at its +// start, so a file is a start: the game starts on the file played last and shows its title as ever, and the title's list has +// an entry of ours under Mods, Save Select (draw_files_row), which opens the file select, kFilesPage. There the file this +// run plays goes on at once; another is asked of the host and the game restarts on it. (It opened by itself over the +// title's list at first: he did not want that.) The System tab's Save files row opens the same page; not shown until the +// host has named the files +save_file_rows::List save_files; +constexpr int kFilesPage = 11; // (page: see kModsPage) +constexpr char kFilesRow[] = "Save files"; // (the row's name in the table below: is_files_row tells it by it) +int files_choice = 0; // (the card chosen) +bool files_at_title = false; // (the page was opened by the title, not by its row: Back and Play give the game its list) +int files_wait = -1; // (the file asked of the host, until it answers) +bool files_failed = false; // (the host could not keep the last choice) +bool is_files_row(const Row& r) { return r.tab == TAB_SYSTEM && !r.value && !strcmp(r.name, kFilesRow); } /// The System tab's Achievements row: confirm opens their page bool is_ach_row(const Row& r) { return r.tab == TAB_SYSTEM && !r.value && !strcmp(r.name, kAchRow); } +// ((Triforce, 11-22, N64 Classic, step 5) a row of the Remembered page: its value opts.n64_rem's, its range and step +// n64_rules.h kSpec's (its key kSpec's too, through ini_key's table of names), taken at once +#define N64_ROW(row, title, text, help) \ + {TAB_N64, title, &opts.n64_rem[n64_rules::row], n64_rules::kSpec[n64_rules::row].lo, n64_rules::kSpec[n64_rules::row].hi, \ + n64_rules::kSpec[n64_rules::row].step, text, help, nullptr, false, true} +constexpr char kUseWindowSize[] = "Use current window size"; Row rows[] = { // ---- Display ---- MENU_HEADING(TAB_DISPLAY, "Screen"), {TAB_DISPLAY, "Fullscreen", &opts.fullscreen, 0, 1, 1, tx_onoff, "The game fills the whole screen, without the window's border. F10 and Alt+Enter do the same.", nullptr, false, true}, {TAB_DISPLAY, "Output resolution", &opts.output_res, 0, kLastOutput, 1, tx_output_res, - "The size of the game's whole frame, HUD included, before it is scaled to the window. Applies after a restart.", + "The picture's size, before it is scaled to the window: the fixed sizes, and the size of each connected screen by its " + "name. A size that is not 16:9 is a wider or narrower picture: the HUD, menus and story movies keep their 16:9 shape at its " + "height. Docked only. Applies after a restart.", hn_output_res, true}, + // ((Triforce) the Custom size's two sides, output_width= and output_height= by their names, shown while Custom or a + // screen's size is chosen: row_shown. No line about the value: the Output resolution row above shows the size the game + // makes of the two) + {TAB_DISPLAY, kUseWindowSize, nullptr, 0, 0, 0, nullptr, + "Copy the current window's pixel size to Custom. In fullscreen this uses the fullscreen size. Applies after a restart."}, + {TAB_DISPLAY, "Output width", &opts.output_width, OUTPUT_MIN_W, OUTPUT_MAX_W, 8, tx_custom_width, + "The output resolution's width in pixels, where it is a screen's size or Custom; hold Left or Right to move faster. Output " + "resolution shows the size the game takes: 5:4 to 32:9 in shape, at most the pixels of 5120x2880. Applies after a restart.", + nullptr, true}, + {TAB_DISPLAY, "Output height", &opts.output_height, OUTPUT_MIN_H, OUTPUT_MAX_H, 8, tx_custom_height, + "The output resolution's height in pixels, where it is a screen's size or Custom; hold Left or Right to move faster. Output " + "resolution shows the size the game takes: 5:4 to 32:9 in shape, at most the pixels of 5120x2880. Applies after a restart.", + nullptr, true}, {TAB_DISPLAY, "GPU device", &opts.gpu_device, 0, 8, 1, tx_gpu, "Which graphics card the game runs on. Applies after a restart.", hn_gpu, true, true}, MENU_HEADING(TAB_DISPLAY, "Ultrawide"), - {TAB_DISPLAY, "Aspect ratio", &opts.ultrawide, 0, 3, 1, tx_ultrawide, - "The shape of the picture: the game's own 16:9, or 16:10, 21:9 or 32:9 for a screen of that shape. A screen of another " - "shape shows it between black bars. Applies after a restart.", hn_ultrawide, true}, - // (Triforce: host/oot_wide_hud.c. Shown with a shape wider than 16:9: row_shown) + {TAB_DISPLAY, "Aspect ratio", &opts.ultrawide, 0, 4, 1, tx_shape, + "The picture's shape for a 16:9 Output resolution: the game's own 16:9, or a fixed 16:10, 21:9 or 32:9 at the same height, " + "for a screen or a window of that shape, or 4:3, a TV's of 1998. A screen of another shape shows the picture between black bars. An Output " + "resolution that is not 16:9 has its own shape, shown here. Applies after a restart.", hn_shape, true}, + // (Triforce: host/oot_wide_hud.c) {TAB_DISPLAY, "HUD position", &opts.wide_hud, 0, 1, 1, tx_wide_hud, - "Where the hearts, the item buttons and the map sit. Middle: in the middle 16:9, as on a normal screen. Screen edges: " - "in the screen's corners. Applies after a restart.", nullptr, true, true}, + "With a picture wider than 16:9: where corner HUD elements, tips and notices sit. Middle: in the " + "middle 16:9, as on a normal screen. Screen edges: out in the screen's corners. Applies after a restart.", nullptr, + true, true}, {TAB_DISPLAY, "Menu sides", &opts.wide_menus, 0, 2, 1, tx_wide_menus, - "What is beside the pause, item and map menus, loading screens and movies, which are 16:9. Changes at once.", - hn_wide_menus}, + "With a picture wider than 16:9: the pause, item and map menus, and what shows beside them. Loading screens and story movies, " + "which draw no world either, get the same sides (the title's movie fills the picture up to 12:5); a fade always covers the " + "whole screen. Changes at once.", hn_wide_menus}, MENU_HEADING(TAB_DISPLAY, "HDR"), // (HDR and RenoDX HDR in one row: merged_rows.h. Off, Expanded and Native change at once, as the HDR row did; Native + // RenoDX, which the scene's format and RenoDX's shaders are chosen for at the start (host/nn_vi.c hos_scene_rgba16f), @@ -1100,6 +1516,40 @@ Row rows[] = { {TAB_GRAPHICS, "Anti-aliasing", &opts.aa, 0, aa_rows::kValues - 1, 1, tx_aa, "How the 3D's edges are smoothed: the game's own SMAA, none, FXAA, or SMAA at its Ultra preset. Changes at once.", hn_aa, false, true}, + // ((Triforce, 11-22, N64 Classic, step 5) the 1998 look (n64_rules.h, vk_n64.cpp): Off, Faithful (fixed), Remembered (its + // page). Taken at each frame; F7 turns it between Off and the last preset (n64_classic_last); RX_VK_N64 over it + MENU_HEADING(TAB_GRAPHICS, "N64 Classic"), + {TAB_GRAPHICS, "N64 Classic", &opts.n64_classic, 0, n64_rules::kPresets - 1, 1, tx_n64, + "The game as the 1998 cartridge on a TV of then. F7 turns it on and off. Changes at once.", hn_n64, false, true}, + {TAB_GRAPHICS, "Remembered settings", nullptr, 0, 0, 0, nullptr, // (opens the Remembered page, the TAB_N64 rows) + "Remembered's frame rate, its 3D and its TV, each to your taste."}, + // (the Remembered page (TAB_N64), which Remembered settings opens: Remembered's own look and pace, every row taken at + // once. N64_ROW takes each row's range, step and key from n64_rules.h kSpec; row_fixed greys those with nothing to do) + MENU_HEADING(TAB_N64, "Pace"), + N64_ROW(FPS, "Frame rate", tx_n64_fps, + "How many frames a second the game runs at with Remembered: the Frame rate cap's, or fewer. 20 is the 1998 " + "cartridge's, 17 its own on a 50 Hz TV. Movies keep the cap's."), + MENU_HEADING(TAB_N64, "The 3D"), + N64_ROW(LINES, "3D resolution", tx_n64_lines, "How many lines the 3D is drawn on. 240 is the console's; more is sharper."), + N64_ROW(COLOUR, "Colour", tx_n64_colour, "How many colours the 3D has. 15-bit is the console's 16-bit picture."), + N64_ROW(DITHER, "Dither", tx_n64_dither, + "The fine pattern that hides the steps between fewer colours. Nothing to dither with full colour."), + N64_ROW(BLUR, "Texture blur", tx_n64_blur, + "How much less detail the textures show, in steps of half a mip level, as the console's small textures did."), + MENU_HEADING(TAB_N64, "The TV"), + N64_ROW(TV, "CRT TV", tx_onoff, "The TV over the picture. Off: the 3D's look alone, for a real CRT or a capture card."), + N64_ROW(SCANLINES, "Scanlines", tx_percent, "How dark the gaps between the TV's lines are."), + N64_ROW(MASK, "Mask", tx_n64_mask, + "The pattern of the TV's red, green and blue phosphors. Auto: the slot mask on a picture 1440 lines tall or more, " + "none on smaller screens."), + N64_ROW(MASK_STRENGTH, "Mask strength", tx_percent, "How strongly the mask shows."), + N64_ROW(BLEED, "Colour bleed", tx_n64_bleed, "Colour smeared sideways, as a composite cable carried it; brightness stays sharp."), + N64_ROW(GLOW, "Glow", tx_percent, "Light glowing around the bright parts of the picture."), + N64_ROW(CURVATURE, "Curvature", tx_n64_curve, "How curved the screen is. A curved one has darker, rounded corners."), + N64_ROW(SATURATION, "Colour saturation", tx_percent, "How rich the colours are. 100% is the game's."), + MENU_HEADING(TAB_N64, "Start again"), + {TAB_N64, "Copy Faithful", nullptr, 0, 0, 0, nullptr, "Remembered set to Faithful's values: a start for your own."}, + {TAB_N64, "Reset to defaults", nullptr, 0, 0, 0, nullptr, "Remembered as it was at first."}, MENU_HEADING(TAB_GRAPHICS, "Frame generation"), // (Frame generation and DLSS frame generation in one row, merged_rows.h: the renderer's own, AMD FSR 4 where its library // makes the frames, NVIDIA DLSS where it can run (vk_dlssg.cpp: read at the start, so it takes a restart)) @@ -1139,6 +1589,20 @@ Row rows[] = { "How the game's mesh-shader draws run. Try Compute fallback on an AMD card that shows glowing walls or loses the GPU. " "Applies after a restart.", hn_mesh, true}, + // ---- System ---- + // ((Triforce) 11-23, his "can we move [achievements] to a more pronounced place for people to find (and disable or + // enable)": a group of their own, the tab's first. The list's page (host/achievements.c's list; shown once the host has + // named it), whether anything is earned, and whether one earned shows its notice. They were a row under Saves & + // reports, and off only by HOS_ACHIEVEMENTS=0 in triforce_env.txt) + MENU_HEADING(TAB_SYSTEM, "Achievements"), + {TAB_SYSTEM, "View achievements", nullptr, 0, 0, 0, nullptr, // (kAchRow) + "Every achievement, and the ones you have earned. They are earned as you play; nothing is set here."}, + {TAB_SYSTEM, "Achievements", &opts.achievements, 0, 1, 1, tx_onoff, + "Whether things you do in the game are marked as earned. Off: nothing is checked or earned, and what you have earned " + "is kept.", nullptr, false, true}, + {TAB_SYSTEM, "Achievement notices", &opts.achievement_notices, 0, 1, 1, tx_onoff, + "Whether a notice and a sound tell you when you earn one. Off: they are still earned, and listed under View " + "achievements.", nullptr, false, true}, // ---- System: the game's ---- MENU_HEADING(TAB_SYSTEM, "Game"), // (Triforce: language.txt's choice, not the options file's. Its entries are counted when the file is read: lang_load) @@ -1177,9 +1641,10 @@ Row rows[] = { {TAB_SYSTEM, "Bug capture (F8)", nullptr, 0, 0, 0, nullptr, "Writes what a problem report needs into a folder of its own under captures in the game folder: a picture, your " "settings, the end of the log and your save. F8 does the same while you play."}, - // (Triforce: host/achievements.c's list, on a page of its own; shown once the host has named it) - {TAB_SYSTEM, "Achievements", nullptr, 0, 0, 0, nullptr, // (kAchRow) - "Every achievement, and the ones you have earned in this game folder. They are earned as you play; nothing is set here."}, + // (Triforce: host/save_files.c's files, the title's file select again; shown once the host has named them) + {TAB_SYSTEM, "Save files", nullptr, 0, 0, 0, nullptr, // (kFilesRow) + "Your save files: each is a playthrough of its own, with its own saves and autosaves. Choosing another restarts the game " + "on it, so save first."}, MENU_HEADING(TAB_SYSTEM, "Online"), {TAB_SYSTEM, "Discord status", &opts.discord, 0, 1, 1, tx_onoff, "Shows \"Playing Triforce\" and the time played in your Discord status, while Discord runs on this PC.", nullptr, false, @@ -1365,6 +1830,8 @@ Row rows[] = { {TAB_HIDDEN, "Steady frame rate", &opts.steady_fps, 0, 2, 1, tx_steady_fps, nullptr}, {TAB_HIDDEN, "NVIDIA Reflex", &opts.reflex, 0, 2, 1, tx_latency, nullptr}, {TAB_HIDDEN, "AMD Anti-Lag 2", &opts.antilag, 0, 1, 1, tx_onoff, nullptr}, + // ((Triforce, N64 Classic, step 5) F7's preset from Off (n64_rules.h Toggle): saved as n64_classic_last, its name's key) + {TAB_HIDDEN, "N64 Classic last", &opts.n64_last, n64_rules::FAITHFUL, n64_rules::REMEMBERED, 1, nullptr, nullptr}, }; constexpr int kRowsEnd = sizeof rows / sizeof rows[0]; // (the table's end: tests read the table up to here) @@ -1473,6 +1940,11 @@ void quit_gone() { quit_ask = false, quit_open_ns = 0, quit_shut_ns = 0; } /// (its Out still playing) bool quit_closing() { return !quit_ask && quit_shut_ns && prof_now() - quit_shut_ns < focus_anim::kOutNs; } bool quit_entry_shown() { return (mods_list_bits.load(std::memory_order_relaxed) & HOS_MODS_LIST_TITLE) == 0; } +/// (Triforce) Save Select, the entry under Mods on the title's list while the host has named the save files (host/save_files.c): +/// where Quit is under the System list's Mods, and mods_row_sel 1 as it is. Not on the pause menu: a file is changed at the title +bool files_row_shown() { + return save_files.shown() > 0 && (mods_list_bits.load(std::memory_order_relaxed) & HOS_MODS_LIST_TITLE) != 0; +} std::atomic game_frames{0}; // (the game's frames shown: menu_note_frame) /// ((Triforce, 11-19) the lab's "one DOWN from Options on the title did nothing and logged nothing": with the game's window /// behind another one its frames came 80 to 235 ms apart, and a list told of at each of them counted as gone after 150 ms, so @@ -1709,7 +2181,7 @@ const char* cheat_confirm(int i) { constexpr int kRows = sizeof rows / sizeof rows[0]; int cur_tab = TAB_DISPLAY; -int tab_selected[TAB_COUNT + 1] = {}; // (and the Motion page's) +int tab_selected[TAB_N64 + 1] = {}; // (and the Motion page's, ((Triforce, N64 Classic) and the Remembered page's) bool is_motion_row(const Row& r) { return r.tab == TAB_CONTROLS && !r.value && !strcmp(r.name, "Motion"); } // (Triforce) The System tab's rows that act on a press, after NX2navi's: Export save, Export save for a bug report, Import a @@ -1793,9 +2265,14 @@ bool restart_changed(const Row& r) { const int slot = restart_slot_of(r); return r.value && r.restart && slot >= 0 && restart_value_of(r) != restart_state.start[slot]; } +/// (Triforce) A row whose value the game does not read as the options are: the Custom size's two sides while the Output +/// resolution is a fixed size (walking the row past a screen's size leaves that size in them). Such a row asks for no restart +bool restart_inert(const Row& r) { + return (r.value == &opts.output_width || r.value == &opts.output_height) && output_choice(opts.output_res) != OUTPUT_CUSTOM; +} void restart_values(int* now) { for (int i = 0; i < kRows; i++) - if (restart_slot[i] >= 0) now[restart_slot[i]] = restart_value_of(rows[i]); + if (restart_slot[i] >= 0) now[restart_slot[i]] = restart_inert(rows[i]) ? restart_state.start[restart_slot[i]] : restart_value_of(rows[i]); } /// The rows whose value is not the one the game runs with (a bit a slot) unsigned restart_pending() { @@ -1915,12 +2392,18 @@ bool group_shown(int heading); bool row_shown(int i) { const int up = rows[i].value == &opts.upscale_pre || rows[i].value == &opts.dlss_model || rows[i].value == &opts.aa ? upscaler() : ur::GAME; return (rows[i].cheat < 0 || cheats_on()) && + (rows[i].name != kUseWindowSize || (opts.output_res == OUTPUT_CUSTOM && !custom_env())) && + // ((Triforce) the Custom size's two sides only while the Output resolution is Custom) + ((rows[i].value != &opts.output_width && rows[i].value != &opts.output_height) || + output_choice(opts.output_res) == OUTPUT_CUSTOM) && (rows[i].value != &opts.dlss || ur::upscaler_shown(dlss_built() || fsr4_built(), fsr3::supported())) && // ((Triforce, options_version 7) the DLSS model with NVIDIA DLSS as the Upscaler alone; Upscale before bloom with any // upscaler but the game's own, which it does nothing with (vk_temporal.cpp pre_wanted); Anti-aliasing with the game's // own alone: DLSS and FSR smooth the edges themselves (aa_rows.h)) (rows[i].value != &opts.dlss_model || (ur::model_shown(dlss_built()) && ur::is_dlss(up))) && (rows[i].value != &opts.upscale_pre || up != ur::GAME) && (rows[i].value != &opts.aa || up == ur::GAME) && + // ((Triforce, 11-22, N64 Classic) Remembered settings with Remembered chosen) + (!is_n64_page_row(rows[i]) || n64_preset() == n64_rules::REMEMBERED) && // (local, RenoDX port: its rows with HDR Native, in a build with its shaders; Triforce: and its own row on, and // of the rows one tonemapper alone reads those of the one chosen. (options_version 7) The UI brightness is one of them: // without RenoDX the HUD's white is the picture's, Paper white) @@ -1929,7 +2412,7 @@ bool row_shown(int i) { // shape wider than 16:9 (21:9 and 32:9: 16:10 is narrower, ultrawide_rows.h); Sprint mode with a sprint button, Walk // scale with a walk key; Low latency where Reflex or Anti-Lag 2 runs) ((rows[i].value != &opts.hdr_white && rows[i].value != &opts.hdr_peak) || opts.hdr != 0) && - ((rows[i].value != &opts.wide_hud && rows[i].value != &opts.wide_menus) || ultrawide_row_wider(opts.ultrawide)) && + ((rows[i].value != &opts.wide_hud && rows[i].value != &opts.wide_menus) || (output_picture_of(opts.output_res, opts.ultrawide).w > output_picture_of(opts.output_res, opts.ultrawide).h * (16.0 / 9.0) * 1.01)) && (rows[i].value != &opts.sprint_mode || opts.sprint_button != 0) && (rows[i].value != &opts.walk_scale || opts.walk_key != 0) && (rows[i].value != &merged.latency || latency_vendor() != mr7::LATENCY_NONE) && #ifndef _WIN32 // (Triforce: the lazy write-back's fault handler pays on Windows only, vk_memory.cpp) @@ -1943,6 +2426,8 @@ bool row_shown(int i) { (!rows[i].heading || strcmp(rows[i].name, kModCheatHeading) || mod_cheats.shown() > 0) && // (Triforce: the Achievements row once the host has named them: off, or none, and there is no such row) (strcmp(rows[i].name, kAchRow) || rows[i].tab != TAB_SYSTEM || ach_list.shown() > 0) && + // (Triforce: and the Save files row once the host has named the files) + (strcmp(rows[i].name, kFilesRow) || rows[i].tab != TAB_SYSTEM || save_files.shown() > 0) && (mod_cheat_slot(rows[i].name) < 0 || mod_cheat_slot(rows[i].name) < mod_cheats.shown()) && (!rows[i].heading || rows[i].tab == TAB_DEBUG || group_shown(i)); } @@ -1985,9 +2470,9 @@ constexpr int64_t kMarqueeStep = 150000000LL, kMarqueeRest = 1200000000LL; // int hover_tab = -1; int drag_row = -1; bool mouse_read = false; // (the menu has read the mouse since it opened) -bool is_slider(const Row& r) { return r.value == &opts.sharpness || r.value == &opts.mouse_sens || r.value == &opts.gyro_sens_x || r.value == &opts.gyro_sens_y; } +bool is_slider(const Row& r) { return r.value == &opts.sharpness || r.value == &opts.mouse_sens || r.value == &opts.gyro_sens_x || r.value == &opts.gyro_sens_y || r.value == &opts.output_width || r.value == &opts.output_height; } /// (a scale: the arrows and a click stop at its ends; Rumble strength would go from Off to its strongest) -bool stops_at_ends(const Row& r) { return r.value == &opts.mouse_sens || r.value == &opts.rumble || r.value == &opts.rumble_curve || r.value == &opts.lstick_dead_zone || r.value == &opts.rstick_dead_zone || r.value == &opts.walk_scale || r.value == &opts.gyro_sens_x || r.value == &opts.gyro_sens_y; } +bool stops_at_ends(const Row& r) { return r.value == &opts.mouse_sens || r.value == &opts.rumble || r.value == &opts.rumble_curve || r.value == &opts.lstick_dead_zone || r.value == &opts.rstick_dead_zone || r.value == &opts.walk_scale || r.value == &opts.gyro_sens_x || r.value == &opts.gyro_sens_y || r.value == &opts.output_width || r.value == &opts.output_height; } /// (the ini's Rumble strength on the menu's steps: 0 to 300, the nearest 25) int rumble_step(int v) { return (std::min(std::max(v, 0), 300) + 12) / 25 * 25; } std::string ini_path() { @@ -2011,6 +2496,12 @@ const char* ini_key(const Row& r) { {"Hue correction", "renodx_hue_correction"}, {"Color grading", "renodx_color_grading"}, {"Highlights", "renodx_highlights"}, {"Shadows", "renodx_shadows"}, {"Contrast", "renodx_contrast"}, {"Saturation", "renodx_saturation"}, {"Bloom", "renodx_bloom"}, + // ((Triforce, 11-22, N64 Classic) the Remembered page's rows, under n64_rules.h kSpec's keys (tests/test_n64_row.py holds + // the two the same; its saturation is Colour saturation, RenoDX's row having Saturation) + {"Frame rate", "n64_rem_fps"}, {"3D resolution", "n64_rem_lines"}, {"Colour", "n64_rem_colour"}, {"Dither", "n64_rem_dither"}, + {"Texture blur", "n64_rem_blur"}, {"CRT TV", "n64_rem_tv"}, {"Scanlines", "n64_rem_scanlines"}, {"Mask", "n64_rem_mask"}, + {"Mask strength", "n64_rem_mask_strength"}, {"Colour bleed", "n64_rem_bleed"}, {"Glow", "n64_rem_glow"}, + {"Curvature", "n64_rem_curvature"}, {"Colour saturation", "n64_rem_saturation"}, }; for (const auto& k : kept) if (r.value && !strcmp(r.name, k[0])) return k[1]; @@ -2200,6 +2691,8 @@ void save() { // (hookshot) the lines that are not the menu's are kept: the controls, pad_ and key_ (host/nn_hid.c) // (and every other line the menu does not write, such as discord_app_id=: they were dropped at the next save) std::string kept, others; + // With no remembered size, leave a line first added outside after menu_init to its writer. + const bool own_custom = remembered_custom.h || ini_base.count("output_custom_size") || !merge; ini_merge::Map disk; // ((Triforce) the file's lines as they are now) if (FILE* f = fopen(ini_path().c_str(), "r")) { char line[256]; @@ -2212,7 +2705,7 @@ void save() { const char* eq = strchr(line, '='); if (!eq || eq == line) continue; const std::string key(line, (size_t)(eq - line)); - bool mine = key == "microphone_device" || key == "options_version" || key == "debug_tab" || key == "gpu_device_name"; + bool mine = (key == "output_custom_size" && own_custom) || key == "microphone_device" || key == "options_version" || key == "debug_tab" || key == "gpu_device_name"; // (Triforce: the RivaTuner limit row of the test builds is gone, RivaTuner being the limiter wherever it can be: // its line is read by nothing and is not written again. (options_version 7) Nor are the lines of the rows whose job // is done otherwise now: merged_rows.h kDropped, read once by menu_init's migration) @@ -2236,6 +2729,8 @@ void save() { }; for (const Row& r : rows) if (ini_row(r)) put(ini_key(r), std::to_string(*r.value)); + if (remembered_custom.h) put("output_custom_size", std::to_string(remembered_custom.w) + "x" + std::to_string(remembered_custom.h)); + else if (own_custom && disk.count("output_custom_size")) put("output_custom_size", ""); if (!mic_want.empty()) put("microphone_device", mic_want); // (hookshot: also while it is unplugged) // ((Triforce) 11-20) the GPU device row's card by its name beside its number: the chosen card's as this run lists them; // a choice past the list (the card taken out) keeps the name it had; Auto writes none @@ -2251,7 +2746,8 @@ void save() { // see merged_rows.h migrate (the 436f9ac-based builds wrote 7 for that: such a file has none of the dropped lines, so // migrate leaves it as it is)) static_assert(merged_rows::kVersion == 8, "the options file's version as merged_rows.h migrates to it"); - out += "options_version=8\n"; + // (Triforce) 9: stock and native output numbers share one schema, see output_sizes.h) + out += "options_version=9\n"; out += others; if (!can_bind()) out += kept; for (int i = 0; i < HOS_KEY_N && can_bind(); i++) { // (the keys-only controls, HOS_KEY_*, have no pad_ line) @@ -2301,12 +2797,13 @@ void set_row(Row& r, int v, int dir, bool keep = true) { v = to.resolution; if (to.upscaler != upscaler()) upscaler_now = to.upscaler; // (Native (100%) on or off: the engine's native AA) } - if (r.value == &opts.output_res) { // (smallest to largest: kOutputOrder) - v = step_output_choice(*r.value, dir); - if (v == *r.value) return; + if (r.value == &opts.output_res) { // (smallest to largest, the screens' sizes among the fixed ones: output_entries) + if (!output_step(dir, true)) return; + v = *r.value; } if (is_merged(r.value)) v = merged_step(r.value, *r.value, dir); // ((Triforce, options_version 7) its choices here) if (stops_at_ends(r)) v = std::min(std::max(v, r.lo), r.hi); // (a scale: it stops at its ends) + if ((r.value == &opts.output_width || r.value == &opts.output_height) && v != *r.value) remembered_custom = {}; if (r.value == &opts.pad_layout) { if (v > 2) v = dir > 0 ? 0 : 2; if (v < 0) v = 2; @@ -2328,6 +2825,18 @@ void set_row(Row& r, int v, int dir, bool keep = true) { if (keep) save(); } +// Snapshot the drawable in pixels when confirmed. Both dimensions share one save and restart prompt. +void use_window_size(unsigned width, unsigned height) { + unsigned w, h; + if (!output_size_used(width, height, &w, &h)) return; + remembered_custom = {}; + for (Row& dimension : rows) { + if (dimension.value == &opts.output_width) set_row(dimension, (int)w, 1, false); + if (dimension.value == &opts.output_height) set_row(dimension, (int)h, 1, false); + } + save(); +} + // ---- (hookshot) the Controls page: what presses each of the Switch's buttons, a gamepad input and up to two keys ---- struct Control { int button; // HOS_SW_*, or HOS_KEY_* (keys only) @@ -2544,13 +3053,16 @@ struct PerfView { perf_stats::Base base; } perf_view; menu_hit::Map hits; // (the menu's controls as last drawn: the mouse's, menu_tick) -float scroll_at[TAB_MOTION + 2]; // (the first row shown, eased toward the selection: the options' tabs and the Motion page, then - // the Controls page: kControlsSlot) +// ((Triforce, 11-22, N64 Classic) the options were drawn under its TV at the last present (menu_tv_layer): the mouse is +// taken through the TV's curve to where they were drawn (vk_n64.h n64_screen_point). The presenting thread's, as hits is +bool options_under_tv = false; +float scroll_at[TAB_N64 + 1]; // (the first row shown, eased toward the selection: the options' tabs and the Motion page, then + // the Controls page: kControlsSlot; ((Triforce, N64 Classic) then the Remembered page) constexpr int kControlsSlot = TAB_MOTION + 1; -int wheel_rows[TAB_MOTION + 2]; // (the mouse wheel's notches since the last drawing, a slot each: scroll_rows scrolls by them) -int scrolled_to[TAB_MOTION + 2] = {-1, -1, -1, -1, -1, -1, -1, -1}; // (the selection scroll_rows last brought into view) -static_assert(TAB_MOTION + 2 == 8, "scrolled_to: a slot for each tab, the Motion page and the Controls page"); -float scroll_want[TAB_MOTION + 2]; // (where scroll_at is going: the wheel moves it, a new selection too) +int wheel_rows[TAB_N64 + 1]; // (the mouse wheel's notches since the last drawing, a slot each: scroll_rows scrolls by them) +int scrolled_to[TAB_N64 + 1] = {-1, -1, -1, -1, -1, -1, -1, -1, -1}; // (the selection scroll_rows last brought into view) +static_assert(TAB_N64 + 1 == 9, "scrolled_to: a slot for each tab, the Motion page, the Controls page and the Remembered page"); +float scroll_want[TAB_N64 + 1]; // (where scroll_at is going: the wheel moves it, a new selection too) float ease_step = 0; // (this drawing's share of the way: the time since the last one) bool ease_live = false; // ((Triforce) menu_record steps the easing: a window's frames. Without them a still is drawn settled) @@ -3001,7 +3513,8 @@ void draw_options(ui::Ctx& c) { const float s = c.s, hh = banner_h(c); header_layer(c, true); // ((Triforce, 11-19) over the Full panel inside the game's Options screen: draw_menu) ui::banner(c, hh); - draw_tabs(c, cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab, embed_open, true); // (the Motion page: under Controls) + // (the Motion page: under Controls; ((Triforce, N64 Classic) the Remembered page: under Graphics) + draw_tabs(c, cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab == TAB_N64 ? TAB_GRAPHICS : cur_tab, embed_open, true); header_layer(c, false); // the rows, in the column; the caption beside it float cx0, cx1, hx0, hx1; @@ -3024,8 +3537,10 @@ void draw_options(ui::Ctx& c) { int prompts_n = 3; if (!selr.value) prompt_list[0] = {ui::kConfirm, confirms ? (pending == &selr ? "Confirm" : selr.name) : "Open"}; if (share_row(selr)) prompt_list[0] = {ui::kConfirm, share_label(share_row(selr))}; + if (n64_action(selr)) prompt_list[0] = {ui::kConfirm, "Apply"}; // ((Triforce, N64 Classic) Copy Faithful, Reset to defaults) if (sel_cheat >= 0) prompt_list[0] = {ui::kLeftRight, "Change"}; // (Triforce: a mod's cheat, On | Off) if (cur_tab == TAB_MOTION) prompt_list[1] = {ui::kBack, "Back"}, prompts_n = 2; // (Esc: to Controls) + if (cur_tab == TAB_N64) prompt_list[1] = {ui::kBack, "Back"}, prompts_n = 2; // ((Triforce, N64 Classic) Esc: to Graphics) if (selr.cheat >= 0) { // (a debug tool: Change when Left and Right do something, then what confirm does) prompts_n = 0; if (selr.cheat <= 1 || selr.cheat == 7 || cheat_chooses(selr.cheat) || age_shown(selr.cheat)) @@ -3097,10 +3612,10 @@ void draw_options(ui::Ctx& c) { } else if (!r.value) { // (a page, or Restart and Quit: Confirm until the second press) const bool ends = false; if (pending == &r) choice_cell(c, va, vb, "Press again", selected, false, false); - else action_cell(c, va, vb, ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open", selected); + else action_cell(c, va, vb, r.name == kUseWindowSize ? "Copy" : ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open", selected); } else { const bool fixed = row_fixed(r.value); - if (is_slider(r)) { + if (is_slider(r) && !fixed) { // ((Triforce) a fixed one: its value alone, as a choice with nothing to choose) slider_cell(c, va, vb, r.text(*r.value), menu_hit::slider_permille(*r.value, r.lo, r.hi), selected, &t0, &t1); t0 = t1 = 0; // (no track to drag: the arrows step it) } else if (r.text == tx_onoff && !fixed) { // (a toggle as the game's: On at the left, Off at the right) @@ -3108,8 +3623,8 @@ void draw_options(ui::Ctx& c) { vm = halves_meet(va, vb); } else { const bool output_row = r.value == &opts.output_res; - const bool left = !fixed && (!output_row || step_output_choice(*r.value, -1) != *r.value) && (!stops_at_ends(r) || *r.value > r.lo); - const bool right = !fixed && (!output_row || step_output_choice(*r.value, 1) != *r.value) && (!stops_at_ends(r) || *r.value < r.hi); + const bool left = !fixed && (!output_row || output_step(-1, false)) && (!stops_at_ends(r) || *r.value > r.lo); + const bool right = !fixed && (!output_row || output_step(1, false)) && (!stops_at_ends(r) || *r.value < r.hi); choice_cell(c, va, vb, r.text(*r.value), selected, left, right, fixed); } } @@ -4567,15 +5082,18 @@ constexpr ImU32 kTitleInkSel = ui::rgba(255, 255, 255); // (T_Btn_02's: white) constexpr ImU32 kTitleDecoInk = ui::rgba(131, 115, 22); // (P_Deco_*_00's: colour 4, linear 0.227 0.173 0.008) constexpr ImU32 kTitleGlow = ui::rgba(120, 140, 255); mods_entry::Anim title_anim; +// ((Triforce) Save Select under it is the same part with its own label and animation: draw_title_files sets these for its call) +const char* title_label = "Mods"; +int title_entry = 0; // (0 Mods, 1 Save Select: its hit, and Mods' Decide and place are Mods' alone) void draw_title_mods(ui::Ctx& c, bool sel, float cx, float cy, float k, float pitch) { const int64_t now = prof_now(), age = mods_list_age(); title_anim.step(now, sel, std::min(age, mods_entry::kListShownNs), mods_list_shown()); const float show = title_anim.shown, f = title_anim.focus; const ImVec2 m = ui::at(c, cx, cy); - const char* const label = "Mods"; + const char* const label = title_label; const float px = ui::lu(c, kTitleText * ui::kType * k), tw = ui::size_of(c.f.body, px, label).x; const float deco_x = tw * 0.5f + ui::lu(c, kTitleDecoGap * k); - const mods_entry::Decide d = mods_entry::decide_at(mods_decide_ns ? now - mods_decide_ns : -1); + const mods_entry::Decide d = mods_entry::decide_at(mods_decide_ns && !title_entry ? now - mods_decide_ns : -1); if (f > 0 && show > 0) { const float hw = deco_x + ui::lu(c, kTitleBandPast * k), hh = ui::lu(c, kTitleBandH * 0.5f * k); const ImVec2 a(m.x - hw, m.y - hh), b(m.x + hw, m.y + hh); @@ -4647,10 +5165,20 @@ void draw_title_mods(ui::Ctx& c, bool sel, float cx, float cy, float k, float pi } // (the entry's hit: across the line as the host takes the game's (host/oot_menu.c list_boxes: 1100 wide), a pitch high) const float hw = ui::lu(c, 550 * k), hh = ui::lu(c, pitch * 0.5f); - hits.add(m.x - hw, m.y - hh, m.x + hw, m.y + hh, menu_hit::kButton, 0); + hits.add(m.x - hw, m.y - hh, m.x + hw, m.y + hh, menu_hit::kButton, title_entry); + if (title_entry) return; mods_entry_px[0] = m.x - hw, mods_entry_px[1] = m.y - hh, mods_entry_px[2] = m.x + hw, mods_entry_px[3] = m.y + hh; mods_entry_px[4] = ui::lu(c, pitch); } +/// (Triforce) Save Select on the title's list: the same entry a pitch under Mods, with its own animation +mods_entry::Anim files_title_anim; +void draw_title_files(ui::Ctx& c, bool sel, float cx, float cy, float k, float pitch) { + std::swap(title_anim, files_title_anim); + title_label = "Save Select", title_entry = 1; + draw_title_mods(c, sel, cx, cy, k, pitch); + title_label = "Mods", title_entry = 0; + std::swap(title_anim, files_title_anim); +} /// (Triforce) The Mods entry, under the game list's last button by the list's own pitch (host/oot_menu.c): on the pause menu's /// System page a button as the game's own (PaCommonBtnThin: the plate with the curls, 672 x 144 units, its text 54; the @@ -4684,6 +5212,8 @@ void draw_mods_row(ui::Ctx& c, bool sel) { } // (the list's scale: the part's 60-unit hit box as the host finds it; one not told, the part's own size) const float k = x1 - x0 > 6 && x1 - x0 < 600 ? (x1 - x0) / 60.0f : 1.0f; + // ((Triforce) Save Select under it while the save files are on: the cursor is on one of the two) + if (files_row_shown()) draw_title_files(c, sel && mods_row_sel == 1, cx, cy - pitch, k, pitch), sel = sel && mods_row_sel == 0; draw_title_mods(c, sel, cx, cy, k, pitch); } @@ -4920,16 +5450,256 @@ void draw_achievements(ui::Ctx& c) { ui::prompt_bar(c, prompts, (int)(sizeof prompts / sizeof prompts[0])); } +/// (Triforce) A save file's picture and time on its card: those of its newest save, as the game's own load list shows them. +/// Each of the file's slots has a caption file (the host names where they are: host/save_files.c), in which the game keeps +/// the save's picture, a JPEG, and when it was made. Looked for once a run, when the file select first opens: every slot's +/// caption read whole, its time found (save_file_rows.h caption_time), and of the one saved last the JPEG (jpeg_in) decoded +/// with Windows' own decoder (vk_mods.h: none on Linux, and no picture then); its texture made at the first drawing. The +/// saves are only read. A file none of whose slots tells a time shows its first slot's picture and the folder's date +struct FilePicture { + int state = 0; // (0 not looked for, 1 its pixels wait for their texture, 2 shown, 3 none) + std::vector rgba; + int w = 0, h = 0; + ImTextureData* texture = nullptr; + char when[32] = ""; // (the newest save's own time, as the game writes one; "" not found: the host's, the folder's date) +}; +FilePicture file_pictures[save_file_rows::kSlots]; +void files_pictures_load() { + for (int i = 0, n = save_files.shown(); i < n; i++) { + FilePicture& p = file_pictures[i]; + if (p.state) continue; + p.state = 3; + if (!save_files.pictures[i][0]) continue; + std::string newest; // (the newest save's picture, as it is in its caption) + save_file_rows::SaveTime latest; + int from = -1, slots = 0; + // ((Triforce) 11-18, his picture: "the date doesn't match lol neither does the picture": a time of 2093 was found among + // a caption's other bytes. The slot the game saved in last is known where the file was played with this: the host saw + // it written and kept it with the card (host/save_files.c hos_save_card_wrote). That slot's picture and that time, + // then; a file not saved in since: the latest time a caption tells that can be a save's, 2025 to now, as before) + const int known = save_files.slots[i]; + const time_t now = time(nullptr) + 86400; + const tm* const now_tm = localtime(&now); + const int max_year = now_tm ? now_tm->tm_year + 1900 : 2100; + for (int slot = 0; slot < 12; slot++) { // (the game looks for slot_00 to slot_11) + if (known >= 0 && slot != known) continue; + char path[save_file_rows::kPath + 32]; + snprintf(path, sizeof path, "%s%02d\\caption.sav", save_files.pictures[i], slot); + FILE* f = fopen(path, "rb"); + if (!f) continue; + std::string bytes(size_t(1) << 20, '\0'); // (a save's caption is some tens of kilobytes) + bytes.resize(fread(bytes.data(), 1, bytes.size(), f)); + fclose(f); + slots++; + size_t at = 0, len = 0; + const bool pictured = save_file_rows::jpeg_in((const unsigned char*)bytes.data(), bytes.size(), &at, &len); + const save_file_rows::SaveTime t = + save_file_rows::caption_time((const unsigned char*)bytes.data(), bytes.size(), pictured ? at : bytes.size(), pictured ? len : 0, max_year, + (int64_t)now); + if (from >= 0 && !t.after(latest)) continue; // (the first slot, until one tells a later time) + from = slot, latest = t; + newest = pictured ? bytes.substr(at, len) : std::string(); + } + if (from < 0) continue; + if (known >= 0) snprintf(p.when, sizeof p.when, "%s", save_files.made[i]); + else if (latest.kind == 1) save_file_rows::game_time(p.when, sizeof p.when, latest.year, latest.month, latest.day, latest.hour, latest.minute); + else if (latest.kind == 2) { + const time_t made = (time_t)latest.seconds; + if (const tm* local = localtime(&made)) + save_file_rows::game_time(p.when, sizeof p.when, local->tm_year + 1900, local->tm_mon + 1, local->tm_mday, local->tm_hour, local->tm_min); + } + if (known >= 0) logf("menu: save file %d: slot_%02d is the one the game saved in last, %s (kept with its card)", i + 1, from, p.when); + else + logf("menu: save file %d: of its %d slots slot_%02d is the newest%s%s%s", i + 1, slots, from, + latest.kind ? ", saved " : ": none of them tells when it was saved (its first slot is shown, and the folder's date)", p.when, + latest.kind == 1 ? " (a calendar time in its caption)" : latest.kind == 2 ? " (a count of seconds in its caption)" : ""); + if (newest.empty()) { + logf("menu: save file %d: no picture found in that save", i + 1); + continue; + } + if (mods::decode_image(newest, 512, p.rgba, &p.w, &p.h) && p.w > 0 && p.h > 0 && p.rgba.size() == (size_t)p.w * p.h * 4) p.state = 1; + else logf("menu: save file %d: its save's picture could not be read (%zu bytes of it)", i + 1, newest.size()); + } +}/// The file select opened: the choice on the file this run plays +void files_open(bool at_title) { + page = kFilesPage, files_at_title = at_title, files_wait = -1, files_failed = false; + files_choice = std::max(0, save_files.current()); + files_pictures_load(); +} +/// (Triforce) The file select (kFilesPage): a card for each file the host named, its number, its name and when it was last +/// saved; the one this run plays is marked. The caption says what choosing the chosen one does +void draw_files(ui::Ctx& c) { + const float s = c.s; + const int n = save_files.shown(), cur = save_files.current(); + files_choice = std::clamp(files_choice, 0, std::max(0, n - 1)); + const bool here = files_choice == cur, waiting = files_wait >= 0; + const float hh = title_banner(c, "Select a file", nullptr); + const char* act = here ? "Play" : "Switch file"; + const ui::Prompt prompts[] = {{ui::kUpDown, "Move"}, {ui::kConfirm, act}, {ui::kBack, "Back"}}; + float cx0, cx1, hx0, hx1; + bool narrow; + columns(c, &cx0, &cx1, &hx0, &hx1, &narrow); + column(c, cx0, cx1, hh); + const float bar = ui::prompt_bar_top(c); + const float left = cx0 + 24 * s, right = cx1 - 24 * s, top = hh + 22 * s, pitch = 124 * s; + if (n > 0) { + const bool saved = save_files.saved(files_choice); + char when[64] = "No save in it yet."; + const char* const made = file_pictures[files_choice].when[0] ? file_pictures[files_choice].when : save_files.whens[files_choice]; + if (saved && made[0]) snprintf(when, sizeof when, "Last saved %s", made); + else if (saved) snprintf(when, sizeof when, "Has a save."); + const char* help = here ? "The file the game is playing now. Its saves and autosaves are its own." : + saved ? "Another file, with its own saves and autosaves. The game starts again to play it: what is not saved in " + "the file you are playing now is lost." : + "An empty file: a new game of its own. The game starts again to play it."; + caption(c, hx0, hx1, save_files.names[files_choice], help, when, + waiting ? "Starting the game on this file..." : files_failed ? "The choice could not be kept: nothing changed." : nullptr); + } + for (int i = 0; i < n; ++i) { + const ImVec2 a(left, top + i * pitch), b(right, a.y + pitch - 12 * s); + const bool saved = save_files.saved(i); + ui::plate(c, a, b, i == cur); + const float my = (a.y + b.y) * 0.5f; + // (its save's picture at the left, 16:9; a file without one: a dark plate that says so) + const float ph = b.y - a.y - 20 * s, pw = ph * 16.0f / 9.0f; + const ImVec2 pa(a.x + 12 * s, a.y + 10 * s), pb(pa.x + pw, pa.y + ph); + FilePicture& pic = file_pictures[i]; + if (pic.state == 1) { // (its texture, at the first drawing) + pic.texture = IM_NEW(ImTextureData)(); + pic.texture->Create(ImTextureFormat_RGBA32, pic.w, pic.h); + memcpy(pic.texture->GetPixels(), pic.rgba.data(), pic.rgba.size()); + pic.texture->UseColors = true; + ImGui::RegisterUserTexture(pic.texture); + pic.rgba.clear(), pic.rgba.shrink_to_fit(); + pic.state = 2; + } + c.d->AddRectFilled(pa, pb, ui::rgba(18, 13, 8, 255)); + if (pic.state == 2 && pic.texture) { + const float iw = (float)pic.w, ih = (float)pic.h; + ImVec2 uv0(0, 0), uv1(1, 1); + if (iw / ih > pw / ph) { const float k = (ph / pw) * iw / ih; uv0.x = (1 - 1 / k) * 0.5f, uv1.x = 1 - uv0.x; } // (wider: its sides cut) + else { const float k = (pw / ph) * ih / iw; uv0.y = (1 - 1 / k) * 0.5f, uv1.y = 1 - uv0.y; } + c.d->AddImage(pic.texture->GetTexRef(), pa, pb, uv0, uv1); + } else { + ui::text_mid_centre(c, c.f.body, 13 * s, (pa.x + pb.x) * 0.5f, my, ui::kDim, saved ? "No picture" : "New game"); + } + c.d->AddRect(pa, pb, ui::alpha(ui::kEdge, 0.9f), 0, std::max(1.0f, s)); + // (Triforce, 11-18, his picture of the game's own load list: "can we show progress of the latest autosave like this?") + // The card as the game's: the save's time over the place it was played last, a line, the hearts under it, and at the + // right the plate with the six medallions round the three Spiritual Stones, each in its place when held. The file's + // name on the tag where the game says Autosave. What the host kept as the file was played (host/save_files.h + // SaveCard): a file not played with this yet has its name and its time alone + namespace ar = achievement_rows; + const bool carded = saved && (save_files.places[i][0] || save_files.items[i] || save_files.hearts[i]); + const float R = 44 * s, tx = pb.x + 18 * s; + const ImVec2 wc(b.x - 18 * s - R, my); + const float text_right = carded ? wc.x - R - 16 * s : b.x - 16 * s; + { // (the tag: the file's name; the one this run plays in gold, "Playing" before it) + const float tw = ui::size_of(c.f.strong, 13.5f * s, save_files.names[i]).x + 22 * s; + const ImVec2 g(text_right - tw, a.y + 10 * s); + c.d->AddRectFilled(g, g + ImVec2(tw, 23 * s), i == cur ? ui::kAccent : ui::alpha(ui::kAccent, 0.45f), 4 * s); + ui::text_mid_centre(c, c.f.strong, 13.5f * s, g.x + tw * 0.5f, g.y + 11.5f * s, ui::kGoldInk, save_files.names[i]); + if (i == cur) ui::text_mid_right(c, c.f.strong, 13.5f * s, g.x - 10 * s, g.y + 11.5f * s, ui::kGoldHi, "Playing"); + } + c.d->PushClipRect(ImVec2(tx, a.y), ImVec2(text_right, b.y), true); + ui::text_mid(c, c.f.body, 15 * s, tx, a.y + 21 * s, saved ? ui::kSoft : kCardOff, + saved ? (pic.when[0] ? pic.when : save_files.whens[i][0] ? save_files.whens[i] : "Saved") : "No save yet"); + const char* const place = !saved ? "New game" : save_files.places[i][0] ? save_files.places[i] : "Saved game"; + ui::text_mid(c, c.f.strong, 23 * s, tx, a.y + 50 * s, saved ? ui::kInkBright : ui::kSoft, place); + c.d->PopClipRect(); + c.d->AddLine(ImVec2(tx, a.y + 71 * s), ImVec2(text_right, a.y + 71 * s), ui::alpha(ui::kEdge, 0.7f), std::max(1.0f, s)); + for (int k = 0, hearts = carded ? save_files.hearts[i] : 0; k < hearts; k++) { // (a heart: two lobes over a point) + const float w = 15 * s, hx = tx + w * 0.5f + k * (w + 4 * s), hy = a.y + 90 * s; + if (hx + w * 0.5f > text_right) break; + if (const ui::Art* heart = ui::art("HeartBase_00")) { // (the game's own heart: its base in its red, its frame over it) + // ((Triforce) 11-18, his picture: the hearts were small and grey. The game's heart is a pale picture in the middle + // of a square of margin, which its layout colours and draws larger than its slot: twice the slot's width here, + // a slot apart, the base in the load list's red-orange and the frame's line over it a shade lighter) + const float slot_w = 21 * s, hw = slot_w * 2.1f, hh2 = hw * heart->h / heart->w, mx = tx + slot_w * 0.5f + k * slot_w; + if (mx + slot_w * 0.5f > text_right) break; + const ImVec2 ha(mx - hw * 0.5f, hy - hh2 * 0.5f), hb(mx + hw * 0.5f, hy + hh2 * 0.5f); + // ((Triforce) 11-18, his next picture: the frame came out right, an orange outline, but the heart inside it dark + // brown. HeartBase_00 is the heart's dark ground, not its red: the game lays the fill over it from other layers. + // The fill is drawn here, in the load list's red-orange with a lighter upper half, inside the game's own frame) + (void)heart; + const float fw = slot_w * 0.80f, fy = hy - fw * 0.02f; + const ImU32 fill = ui::rgba(238, 92, 48), lit = ui::rgba(250, 128, 70); + c.d->AddCircleFilled(ImVec2(mx - fw * 0.24f, fy - fw * 0.13f), fw * 0.27f, fill, 20); + c.d->AddCircleFilled(ImVec2(mx + fw * 0.24f, fy - fw * 0.13f), fw * 0.27f, fill, 20); + c.d->AddTriangleFilled(ImVec2(mx - fw * 0.49f, fy - fw * 0.02f), ImVec2(mx + fw * 0.49f, fy - fw * 0.02f), ImVec2(mx, fy + fw * 0.50f), fill); + c.d->AddCircleFilled(ImVec2(mx - fw * 0.24f, fy - fw * 0.17f), fw * 0.15f, lit, 16); + c.d->AddCircleFilled(ImVec2(mx + fw * 0.24f, fy - fw * 0.17f), fw * 0.15f, lit, 16); + if (const ui::Art* frame = ui::art("HeartFrame_00")) ui::image(c, frame, ha, hb, ui::rgba(255, 150, 96)); + continue; + } + const ImU32 red = ui::rgba(236, 86, 52), rim = ui::rgba(140, 34, 22); + c.d->AddCircleFilled(ImVec2(hx - w * 0.25f, hy - w * 0.14f), w * 0.31f, rim, 16), c.d->AddCircleFilled(ImVec2(hx + w * 0.25f, hy - w * 0.14f), w * 0.31f, rim, 16); + c.d->AddTriangleFilled(ImVec2(hx - w * 0.55f, hy + w * 0.02f), ImVec2(hx + w * 0.55f, hy + w * 0.02f), ImVec2(hx, hy + w * 0.60f), rim); + c.d->AddCircleFilled(ImVec2(hx - w * 0.25f, hy - w * 0.14f), w * 0.25f, red, 16), c.d->AddCircleFilled(ImVec2(hx + w * 0.25f, hy - w * 0.14f), w * 0.25f, red, 16); + c.d->AddTriangleFilled(ImVec2(hx - w * 0.46f, hy + w * 0.01f), ImVec2(hx + w * 0.46f, hy + w * 0.01f), ImVec2(hx, hy + w * 0.50f), red); + c.d->AddCircleFilled(ImVec2(hx - w * 0.28f, hy - w * 0.20f), w * 0.08f, ui::rgba(255, 190, 160, 200), 8); + } + if (carded) { // (the plate: the medallions of light, forest, fire, water, spirit and shadow round it from the top, the stones in its middle) + static const int medal_tones[save_file_rows::kMedals] = {ar::kYellow, ar::kGreen, ar::kRed, ar::kBlue, ar::kOrange, ar::kPurple}; + static const int stone_tones[save_file_rows::kStones] = {ar::kGreen, ar::kRed, ar::kBlue}; + // (the game's own pictures of them, DataFileImportantIcon_00 to _08, when its archive gave them. kFileIcon: the + // picture's number for each of the items' bits. The stones first (forest, fire, water), then the medallions as the + // plate has them round it from the top: light, forest, fire, water, spirit, shadow. (11-18: taken first to be in + // gpu/vk/oot_cheat_items.h's order, light last: his card had Shadow's picture where Light is held and Light's where + // Forest is. _03 is Light, then, and the six go round the plate; _08, Shadow's, was drawn for Light)) + static const int kFileIcon[save_file_rows::kStones + save_file_rows::kMedals] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; + const auto game_icon = [&](int bit, ImVec2 m, float r) { + char name[32]; + snprintf(name, sizeof name, "DataFileImportantIcon_%02d", kFileIcon[bit]); + const ui::Art* t = ui::art(name); + if (!t || t->mask) return false; // (a mask is a shape without its colours: the drawn icon then) + const float hw = r * 1.45f, hh2 = hw * t->h / t->w; + ui::image(c, t, ImVec2(m.x - hw, m.y - hh2), ImVec2(m.x + hw, m.y + hh2)); + return true; + }; + const ImU32 socket = ui::rgba(30, 22, 12, 230); + c.d->AddNgonFilled(wc, R, ui::rgba(74, 56, 30, 240), 6); + c.d->AddNgon(wc, R, ui::alpha(ui::kEdge, 0.9f), 6, std::max(1.0f, 1.3f * s)); + for (int k = 0; k < save_file_rows::kMedals; k++) { + const float ang = -1.5707963f + k * 1.0471976f, r = R * 0.19f; + const ImVec2 m(wc.x + std::cos(ang) * R * 0.66f, wc.y + std::sin(ang) * R * 0.66f); + if (!(save_files.items[i] >> (save_file_rows::kStones + k) & 1)) c.d->AddCircleFilled(m, r, socket, 24); + else if (game_icon(save_file_rows::kStones + k, m, r)) {} + else ach_icon(c, m, r, ar::kMedal | medal_tones[k] << 4, true); + } + for (int k = 0; k < save_file_rows::kStones; k++) { + const float r = R * 0.17f; + const ImVec2 m(wc.x + (k - 1) * R * 0.36f, wc.y); + if (!(save_files.items[i] >> k & 1)) c.d->AddCircleFilled(m, r, socket, 24); + else if (game_icon(k, m, r)) {} + else ach_icon(c, m, r, ar::kGem | stone_tones[k] << 4, true); + } + } + if (i == files_choice) ui::glow(c, a, b); + hits.add(a.x, a.y, b.x, b.y, menu_hit::kListLine, i); + } + if (n > 0 && !waiting) { // (the chosen file's action, for the mouse) + const float my = bar - 14 * s - 29 * s, bw = ui::size_of(c.f.strong, 18 * s, "Switch file").x + 36 * s; + const ImVec2 a(right - bw, my - 17 * s), b(right, my + 17 * s); + ui::button(c, a, b, act, false); + hits.add(a.x, a.y, b.x, b.y, menu_hit::kButton, 0); + } + ui::prompt_bar(c, prompts, (int)(sizeof prompts / sizeof prompts[0])); +} + /// (Triforce) The notice of an achievement earned: a plate at the top of the screen, its icon, "Achievement earned" and its -/// name, slid in from above and out again (achievement_rows.h notice_in). Over the game and over the options alike +/// name, slid in from above and out again (achievement_rows.h notice_in). Over the game and over the options alike. +/// ((Triforce) 11-23: and under the name where the list is, kAchWhere: the moment a player wants to know) +constexpr char kAchWhere[] = "See all: Options > System"; void draw_ach_notice(ui::Ctx& c) { const int slot = ach_notice; if (slot < 0 || slot >= ach_list.shown()) return; const float k = achievement_rows::notice_in((prof_now() - ach_notice_at) / 1000000, kAchNoticeMs); if (k <= 0) return; const float s = c.s, in = 1 - (1 - k) * (1 - k), r = 26 * s, pad = 16 * s; - const float text_w = std::max(ui::size_of(c.f.strong, 21 * s, ach_list.names[slot]).x, ui::size_of(c.f.strong, 13.5f * s, "Achievement earned").x); - const float w = pad + 2 * r + 16 * s + text_w + 28 * s, h = 76 * s; + const float text_w = std::max({ui::size_of(c.f.strong, 21 * s, ach_list.names[slot]).x, ui::size_of(c.f.strong, 13.5f * s, "Achievement earned").x, + ui::size_of(c.f.body, 12 * s, kAchWhere).x}); + const float w = pad + 2 * r + 16 * s + text_w + 28 * s, h = 94 * s; const ImVec2 a((c.w - w) * 0.5f, -h + (h + 34 * s) * in), b(a.x + w, a.y + h); // ((Triforce) 11-18: the game's own plate, as the file select's cards and the Achievements page's, with a gold rim; it was a // dark rounded box of the menu's own) @@ -4939,6 +5709,7 @@ void draw_ach_notice(ui::Ctx& c) { const float tx = a.x + pad + 2 * r + 16 * s; ui::text_mid(c, c.f.strong, 13.5f * s, tx, a.y + 25 * s, ui::kGoldHi, "Achievement earned"); ui::text_mid(c, c.f.strong, 21 * s, tx, a.y + 51 * s, ui::kInkBright, ach_list.names[slot]); + ui::text_mid(c, c.f.body, 12 * s, tx, a.y + 75 * s, ui::kSoft, kAchWhere); } void draw_ask(ui::Ctx& c) { @@ -5141,6 +5912,7 @@ void draw_menu(ui::Ctx& c, bool perf_under) { else if (page == 6) draw_names(k); // ((Triforce) Game flags, Cutscenes, Scan amiibo) else if (page == kModsPage) draw_mods(k); else if (page == kAchPage) draw_achievements(k); // ((Triforce) the System tab's Achievements) + else if (page == kFilesPage) draw_files(k); // ((Triforce) the title's file select, and the System tab's Save files) else draw_options(k); if (on_game) c.d->PopClipRect(); int perf0 = 0, perf1 = 0; // (the Full panel's vertices: in the window's pixels already) @@ -5511,6 +6283,15 @@ void menu_init() { const char* hearts = getenv("HOS_OOT_PROTECT_HEARTS"); protect_hearts.store(hearts && !strcmp(hearts, "1")); } + if (host && host->screens) { // ((Triforce) the connected screens, as the host found them at the start: before the file, + // which an old Ultrawide row is read with) + MkwVkScreen list[16]; + const int n = host->screens(list, 16); + for (int i = 0; i < n; i++) { + list[i].name[sizeof list[i].name - 1] = 0; + screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0); + } + } if (FILE* f = fopen(ini_path().c_str(), "r")) { has_options = true; char line[80]; @@ -5541,9 +6322,18 @@ void menu_init() { if (!strcmp(line, "gpu_device_name")) gpu_want = mic_key(eq + 1); // ((Triforce) 11-20: the GPU device row's card, by its name) } fclose(f); + { // ((Triforce) Custom's size from the file's own two numbers, not each kept to its row's ends: custom_rows_read) + const auto side = [](const char* key) { + const auto at = ini_base.find(key); + return at == ini_base.end() ? 0L : atol(at->second.c_str()); + }; + custom_rows_read(side("output_width"), side("output_height")); + const auto remembered = ini_base.find("output_custom_size"); + if (remembered != ini_base.end()) read_remembered_custom(remembered->second.c_str()); + } // ((Triforce) options_version 8 (7 in the 436f9ac-based builds; v0.5.1's 7 still had the rows): the handheld profile is // an Output resolution, the shared stick dead zone each stick's own; the other rows that went keep nothing to move (merged_rows.h kDropped). Before the values at the start are taken) - merged_rows::migrate(version, before7, opts.output_res, opts.lstick_dead_zone, opts.rstick_dead_zone); + hdr_at_start = opts.hdr; // (local, RenoDX port: vk_menu.h) renodx_at_start = opts.renodx, upscale_pre_at_start = opts.upscale_pre; tex_detail_at_start = opts.tex_detail; @@ -5582,12 +6372,16 @@ void menu_init() { if (version < 7) opts.pace = 1; // ((Triforce, 11-16, the owner: "remove monitors shape as a option keep 16:9 16:10 21:9 32:9") Before options_version 6 // the Ultrawide row's 1 was Monitor's shape; now it is 16:10. Such a file's 1 becomes the shape nearest the main - // monitor's, as host/hos_main.c read it at this start (ultrawide_rows.h) -#ifdef _WIN32 - opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); -#else - opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, 0, 0); -#endif + // monitor's, as host/hos_main.c read it at this start (ultrawide_rows.h), on every system (main_screen) + opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, (int)main_screen().w, (int)main_screen().h); + // ((Triforce) Before options_version 8 the sizes 5120x1440 and 5120x2160 were the game's frame, and the Ultrawide row + // gave the picture's shape there too: with the row on another shape than theirs, the 16:9 size of their height, which + // gives that picture now, as host/nn_applet.c read it at this start (output_sizes.h output_res_read)) + const bool legacy_output = output_legacy_file(version, ini_base.count("output_width") || ini_base.count("output_height") || ini_base.count("output_custom_size")); + opts.output_res = output_file_read(opts.output_res, version, opts.ultrawide, + ini_base.count("output_width") || ini_base.count("output_height") || ini_base.count("output_custom_size")); + merged_rows::migrate(legacy_output && version == 8 ? 7 : version, before7, + opts.output_res, opts.lstick_dead_zone, opts.rstick_dead_zone); } // An opt-in profile for 4 GB cards: keep existing options authoritative, but make a first run usable on // low-VRAM hardware without requiring the menu to render first. ((Triforce, options_version 7) What the Quality preset's @@ -5610,6 +6404,7 @@ void menu_init() { if (const char* e = getenv("HOS_REALTIME_STEP")) opts.realtime = atoi(e) != 0; if (const char* e = getenv("HOS_DYNRES")) opts.resolution = atoi(e) != 0 ? 0 : 1; if (const char* e = getenv("HOS_OUTPUT_RES")) opts.output_res = output_choice(atoi(e)); + output_adopt_screen(); // (an old file's Screen: that screen's size, as a size) lang_load(); // (Triforce: the Game language row, from language.txt) merged_sync(); // ((Triforce, options_version 7) the merged rows from what was read) restart_init(); // (what this run started with: the rows that take a restart differ from it once changed) @@ -5695,6 +6490,7 @@ int menu_take_amiibo_ask() { return amiibo_ask.take(); } int menu_take_mod_cheat() { return mod_cheats.take(); } // (Triforce: a mod's cheat the player switched, for the host) +int menu_take_file_ask() { return save_files.take_ask(); } // (Triforce: the save file chosen that is not this run's, for the host) // ---- (Triforce) the options' own sounds: the game's interface sounds, after NX2navi's menu sounds. menu_tick says which // (menu_sound_events.h), the host's sound thread takes them (vk_api.h HOS_OPT_MENU_SOUND) and plays them from the player's @@ -5710,6 +6506,13 @@ static_assert(menu_sound::kOpen == HOS_MENU_SOUND_OPEN && menu_sound::kClose == static_assert(menu_sound::kPageAsk == 5, "the restart question is page 5"); static menu_sound::Queue sound_queue; constexpr int kSoundPageMotion = 7; // (the Motion page is a tab no strip shows, opened from a row of Controls: a page, to the ear) +// ((Triforce, 11-22, N64 Classic, after the owner's test: "do a pass for the SfX playing in the new sub menu") and the +// Remembered page, opened from a row of Graphics, likewise. As Graphics' rows alone its opening and its Back were silent: +// both take their press for themselves (press[7], press[5] false again by the sound's turn), and the row and value the +// cursor stood on could be the same number on both) +constexpr int kSoundPageN64 = 10; +static_assert(kSoundPageN64 != kModsPage && kSoundPageN64 != kModsRowPage && kSoundPageN64 != kSoundPageMotion, + "the Remembered page's page, to the ear, is a number of its own"); /// What the options show now, as far as their sounds go (menu_sound::State): menu_tick takes it before and after its input static menu_sound::State sound_state() { menu_sound::State s; @@ -5717,8 +6520,9 @@ static menu_sound::State sound_state() { if (!s.open) return s; s.embedded = embed_open || game_options_shown(); const bool motion = page == 0 && cur_tab == TAB_MOTION; - s.page = motion ? kSoundPageMotion : page; - s.tab = motion ? (int)TAB_CONTROLS : cur_tab; + const bool n64_page = page == 0 && cur_tab == TAB_N64; // ((Triforce, N64 Classic) the Remembered page) + s.page = motion ? kSoundPageMotion : n64_page ? kSoundPageN64 : page; + s.tab = motion ? (int)TAB_CONTROLS : cur_tab == TAB_N64 ? (int)TAB_GRAPHICS : cur_tab; // ((Triforce, N64 Classic) under Graphics) auto hashed = [](const std::string& t) { int64_t h = 1469598103934665603LL; for (const char ch : t) h = (h ^ (unsigned char)ch) * 1099511628211LL; @@ -5759,12 +6563,16 @@ static menu_sound::State sound_state() { s.mode = names_edit ? menu_sound::kModeEdit : menu_sound::kModeNone; } else if (page == kAchPage) { s.cursor = ach_view.choice, s.group = ach_view.page; + } else if (page == kFilesPage) { + s.cursor = files_choice, s.mode = files_wait >= 0 ? menu_sound::kModeConfirm : menu_sound::kModeNone; } return s; } int menu_take_sound() { return sound_queue.take(prof_now()); } // (the options' next sound, for the host's sound thread) void mods_sound(int id) { if (opts.menu_sounds > 0) sound_queue.put(id, prof_now()); } // ((Triforce) the Mods entry's and screen's own sounds -int menu_mods_selected() { return open_now.load(std::memory_order_relaxed) && (page == kModsRowPage || page == kModsPage); } +int menu_mods_selected() { // ((Triforce) and the file select opened from Save Select, the entry under Mods on the title) + return open_now.load(std::memory_order_relaxed) && (page == kModsRowPage || page == kModsPage || (page == kFilesPage && files_at_title)); +} /// ((Triforce, 11-20) the owner: "have the in game mods menu in the title screen play the shop theme quietly in the /// background ... it mutes the title screen music's audio while in the mod menu and fades in/out". What the host's sound /// thread asks each block (host/mods_music.c): 2 while the Mods screen is open from the title's list, 1 while that list is @@ -5795,13 +6603,14 @@ void menu_note_present_sizes(uint32_t picture_w, uint32_t picture_h, uint32_t wi const PresentAspect aspect{host && host->aspect_ratio ? host->aspect_ratio() : 0.0f}; const PresentRect place = present_rect(picture_w, picture_h, nullptr, window_w, window_h, aspect); const bool native_hdr = dev.hdr && opts.hdr == 2; - const int filter = ur::window_filter(picture_w, picture_h, place.w, place.h, native_hdr); + // ((Triforce, 11-22, N64 Classic, step 4) its TV in the filter's place while it runs, at 1:1 too (upscaler_rows.h tv_filter) + const int filter = ur::tv_filter(ur::window_filter(picture_w, picture_h, place.w, place.h, native_hdr), n64_tv_now(native_hdr)); const bool same = picture_w == place.w && picture_h == place.h; const int tell = filter * 4 + native_hdr * 2 + same; static int told = -1; if (tell != told) logf("menu: the window's filter: %s (the picture %ux%u, shown at %ux%u)", - filter == 3 ? "AMD FSR 1" : same ? "none, the sizes are the same" + filter == ur::kTvFilter ? "N64 Classic's TV" : filter == 3 ? "AMD FSR 1" : same ? "none, the sizes are the same" : native_hdr ? "the plain copy (HDR Native: its 10 bits kept)" : "the plain copy", picture_w, picture_h, place.w, place.h); told = tell; @@ -6013,10 +6822,11 @@ static void perf_sample(double shown, double game) { if (holder != mkwvk::pace::GAME) strncat(t, holder == mkwvk::pace::RTSS ? " (RivaTuner)" : " (NVIDIA Reflex)", sizeof t - strlen(t) - 1); set(4, t); set(5, tx_onoff(opts.vsync)); - set(6, tx_ultrawide(opts.ultrawide)); + set(6, shape_now(opts.ultrawide)); // ((Triforce) the Output resolution's own shape where it has one) unsigned ow = 0, oh = 0; t[0] = 0; - if (sscanf(tx_output_res(opts.output_res), "%ux%u", &ow, &oh) == 2 && oh) snprintf(t, sizeof t, "%up", oh); + oh = shown_output().h, ow = shown_output().w; // ((Triforce) Screen's and Custom's too) + if (ow && oh) snprintf(t, sizeof t, "%up", oh); set(7, t); set(8, tx_hdr(opts.hdr)); set(9, perf_framegen_text(t, sizeof t)); // (what makes the frames, by name, as NX2navi's) @@ -6077,6 +6887,19 @@ void menu_option_set(int id, int value) { game_options_from_pause.store(value == 2, std::memory_order_relaxed); return; } + // (Triforce: the save files, named by the host once this renderer answers, and its word on a file chosen: host/save_files.c) + if (id == HOS_OPT_FILES_TEXT) return save_files.text(value); + if (id == HOS_OPT_FILES_ADD) return save_files.add(value); + if (id == HOS_OPT_FILES_COUNT) { + save_files.done(value); + menu_refresh = true; + return; + } + if (id == HOS_OPT_FILES_SAID) { + save_files.said(value); + menu_refresh = true; + return; + } // (Triforce: the achievements, named by the host once this renderer answers, and each one earned as it is: // host/achievements.c, one call at a time) if (id == HOS_OPT_ACH_TEXT) return ach_list.text(value); @@ -6249,7 +7072,7 @@ void tab_move(int dir) { int entry[TAB_COUNT + 2], n = 0; for (int t = 0; t < TAB_DEBUG; t++) entry[n++] = t; if (debug_shown()) entry[n++] = TAB_DEBUG; - const int from = page == kModsPage ? kModsTab : cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab; + const int from = page == kModsPage ? kModsTab : cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab == TAB_N64 ? TAB_GRAPHICS : cur_tab; int at = 0; while (at < n - 1 && entry[at] != from) at++; if (embed_open && ((dir < 0 && at == 0) || (dir > 0 && at == n - 1))) { @@ -6560,7 +7383,8 @@ void menu_tick() { page = enter == 2 && !decide ? kModsPage : kModsRowPage; // ((Triforce) 11-19: 3, Quit clicked: its dialog opens; 4, the mouse moved onto Quit: it has the cursor) mods_row_sel = enter == 3 || enter == 4 ? 1 : 0, quit_gone(), quit_sel = 0; - if (enter == 3) quit_open(); + if (enter == 3 && !mods_title_list()) quit_open(); + if (enter == 3 && files_row_shown()) files_open(true); // ((Triforce) on the title it is Save Select: the file select at once) entered_by_down = enter == 1 || enter == 5; // ((Triforce, 11-19) 5: a Down held from higher up the game's list, its repeat onto Mods: held on, it repeats // on at the step (the repeat below takes it as held past the first delay), as the game's list went on) @@ -6580,6 +7404,18 @@ void menu_tick() { open_now.load() ? "the menu is open" : "the game's list was last told of too long ago"); } } + // (Triforce) the host's word on a file chosen at the file select: kept as the next start's, the game restarts as Restart now does; or not kept) + if (const int said = save_files.take_said()) { + files_wait = -1, menu_refresh = true; + if (said == save_file_rows::kRestart) { + save(); + pipeline_cache_save(true); + memory_trial_orderly_end(); + logf("menu: restart (another save file)"); + open_now = false, page = 0; + if (const HWND window = app_window()) PostMessageA(window, WM_APP + 9, 0, 0); + } else files_failed = true; + } if (!open_now.load() || page != kModsPage) { // ((Triforce) no text taken off the Mods screen: none kept for it either) mods_text_wanted.store(false, std::memory_order_relaxed); std::lock_guard g(mods_typed_mu); @@ -6742,6 +7578,24 @@ void menu_tick() { next = next[n] == ',' ? next + n + 1 : nullptr; } } + { // ((Triforce, 11-22, N64 Classic, step 5) F7: N64 Classic between Off and the last preset (n64_rules.h Toggle, the last + // kept as n64_classic_last), saved as the row is, said at the foot of the screen; not while RX_VK_N64 sets it for the run. + // The last preset follows the row too, whoever chose it + static bool f7_held = false; + if (opts.n64_classic == n64_rules::FAITHFUL || opts.n64_classic == n64_rules::REMEMBERED) opts.n64_last = opts.n64_classic; + const bool f7_down = mine && (GetAsyncKeyState(VK_F7) & 0x8000) != 0; + if (f7_down && !f7_held && !n64_env_set()) { + n64_rules::Toggle toggle; + toggle.last = opts.n64_last; + opts.n64_classic = toggle.pressed(opts.n64_classic); + opts.n64_last = toggle.last; + save(); + snprintf(notice_text, sizeof notice_text, "N64 Classic: %s", n64_rules::name(opts.n64_classic)); + notice_until = prof_now() + 2000000000LL; + logf("menu: F7: N64 Classic %s", n64_rules::name(opts.n64_classic)); + } + f7_held = f7_down; + } { // (Triforce) F8, a bug capture. The window's key handler asks the host for it itself (host/display.c); where the host has // no queue of key presses (Linux) the key is read here, and asked for as the rows ask static bool f8_held = false; @@ -6756,7 +7610,8 @@ void menu_tick() { notice_until = prof_now() + 4000000000LL; } // ((Triforce) an achievement earned: its notice, from now for kAchNoticeMs) - if (const int earned = ach_list.take_fresh(); earned >= 0) ach_notice = earned, ach_notice_at = prof_now(); + // ((Triforce) 11-23: not with the Achievement notices row Off; the list has it as earned all the same) + if (const int earned = ach_list.take_fresh(); earned >= 0 && opts.achievement_notices) ach_notice = earned, ach_notice_at = prof_now(); if (cur_tab == TAB_DEBUG && !debug_shown()) cur_tab = TAB_DISPLAY; { // (Triforce) presses the host passed on while the Mods entry or its screen has the cursor (a test's scripted ones) const int mp = mods_press.exchange(0, std::memory_order_relaxed); @@ -6883,6 +7738,8 @@ void menu_tick() { if (!game_tab_read) gp.pressed = 0, game_tab_read = true; // (pressed before the tabs were shown: not theirs) int ix = 0, iy = 0; menu_hit::to_image(gp.x, gp.y, gp.width, gp.height, (int)dev.swap_extent.width, (int)dev.swap_extent.height, &ix, &iy); + // ((Triforce, 11-22, N64 Classic) the tabs drawn under its TV: the cursor where the curve showed them) + if (options_under_tv) n64_screen_point(&ix, &iy, (int)dev.swap_extent.width, (int)dev.swap_extent.height); const menu_hit::Hit hit = on ? hits.at(game_tab_map.back_x((float)ix), game_tab_map.back_y((float)iy)) : menu_hit::Hit{}; hover_tab = hit.part == menu_hit::kTab && hit.index != kGameTab ? hit.index : -1; if (on && (gp.pressed & HOS_MOUSE_LEFT)) { @@ -6921,6 +7778,8 @@ void menu_tick() { int ix = 0, iy = 0; menu_hit::to_image(ptr.x, ptr.y, ptr.width, ptr.height, (int)dev.swap_extent.width, (int)dev.swap_extent.height, &ix, &iy); + // ((Triforce, 11-22, N64 Classic) the options drawn under its TV: the cursor where the curve showed them) + if (options_under_tv) n64_screen_point(&ix, &iy, (int)dev.swap_extent.width, (int)dev.swap_extent.height); if (mouse) mx = (int)std::floor(menu_map.back_x((float)ix)), my = (int)std::floor(menu_map.back_y((float)iy)); // (the menu's column's pixels: draw_menu) // ((Triforce) the first read takes no click: one from before the menu opened is not its own. The window keeps the // clicks on the game's Options screen for its tabs over the header, host/display.c game_menu_press) @@ -7119,6 +7978,30 @@ void menu_tick() { else teleport_choice = std::clamp(teleport_step_rows(teleport_choice, rows) + (press[4] - press[3]), 0, kTeleports - 1); if (teleport_choice != was) teleport_follow = true, changed = true; } + } else if (open_now.load() && page == kFilesPage) { // (Triforce) the file select: the choice moves, confirm plays the file + const int n = save_files.shown(); + if (mouse) { // (a card chosen by a click, the button plays it; a right click goes back) + const menu_hit::Hit hit = hits.at((float)mx, (float)my); + if ((ptr.pressed & HOS_MOUSE_LEFT) && hit.part == menu_hit::kListLine && hit.index >= 0 && hit.index < n && files_wait < 0) + changed |= files_choice != hit.index, files_choice = hit.index; + else if ((ptr.pressed & HOS_MOUSE_LEFT) && hit.part == menu_hit::kButton && hit.index == 0) press[7] = true; + if (ptr.pressed & HOS_MOUSE_RIGHT) press[5] = true; + } + // (Back from the title's: the cursor on Save Select again; Play there, or the list gone: the game's list. From its row: + // the System tab, the row still selected) + const auto leave = [&](bool play) { + if (files_at_title && !play && mods_list_fresh() && files_row_shown()) page = kModsRowPage, mods_row_sel = 1; + else if (files_at_title) open_now = false, page = 0; + else page = 0; + changed = true; + }; + if (files_wait >= 0) {} // (asked of the host: its word comes at the next tick or two, menu_tick's top) + else if (press[5] || !n) leave(false); + else if (press[7]) { + files_failed = false; + if (save_files.choose(files_choice)) leave(true); // (the file this run plays: on with it) + else files_wait = files_choice, changed = true; + } else changed |= save_file_rows::move(files_choice, press[2] - press[1], press[15], press[16], n); } else if (open_now.load() && page == kAchPage) { // (Triforce) the Achievements page: nothing to set, the choice moves const int n = ach_list.shown(); if (mouse) { // (a card chosen by a click, the page arrows, the wheel a page; a right click goes back) @@ -7142,7 +8025,9 @@ void menu_tick() { } } else if (open_now.load() && page == kModsRowPage) { // (Triforce) the cursor on the entries under the game's list const bool quit_here = quit_entry_shown(); - if (!quit_here) mods_row_sel = 0, quit_gone(); + const bool files_here = files_row_shown(); // ((Triforce) on the title Save Select is under Mods, as Quit is here) + if (!quit_here && !files_here) mods_row_sel = 0; + if (!quit_here) quit_gone(); // ((Triforce, 11-19) the dialog takes input once its In has played, as the game's: what comes before is not kept) const bool quit_ready = quit_ask && focus_anim::window_ready(prof_now() - quit_open_ns); if (mouse) { // (the cursor on an entry or a dialog button chooses it; a click is A) @@ -7177,6 +8062,10 @@ void menu_tick() { changed = true; } else if (press[5] || press[0] || press[6]) quit_cancel(), mods_sound(HOS_MENU_SOUND_CANCEL), changed = true; press[1] = press[2] = press[5] = press[0] = press[6] = false, tab_left = tab_right = false; + } else if (press[7] && files_here && mods_row_sel == 1) { // ((Triforce) A on Save Select: the file select) + files_open(true), mods_sound(HOS_MENU_SOUND_SYS_DECIDE), changed = true; + } else if (press[2] && files_here && mods_row_sel == 0) { // ((Triforce) Down from the title's Mods: Save Select) + mods_row_sel = 1, mods_sound(HOS_MENU_SOUND_SYS_CURSOR), changed = true; } else if (press[7]) { // (A: Mods opens; on Quit its dialog) if (mods_row_sel == 1) quit_open(), mods_sound(HOS_MENU_SOUND_SYS_DECIDE), changed = true; else if (mods_title_list()) mods_decide_ns = prof_now(), mods_sound(HOS_MENU_SOUND_SYS_DECIDE), changed = true; // (its Decide first) @@ -7253,12 +8142,15 @@ void menu_tick() { if (ptr.wheel && drag_row < 0) wheel_rows[cur_tab] += ptr.wheel, changed = true; } if (press[5] && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS, press[5] = false, changed = true; // (back) + if (press[5] && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS, press[5] = false, changed = true; // ((Triforce, N64 Classic) back) if (press[5] && pending) pending = nullptr, changed = true; // (a Restart or Quit waiting for its second press: cancelled) else if (press[5] && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS, press[5] = false, changed = true; // (back) + else if (press[5] && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS, press[5] = false, changed = true; // ((Triforce, N64 Classic)) else if (press[5] && restart_ask()) page = 5, ask_sel = 0, changed = true; // (the restart question first) else if (press[5]) open_now = false; // (the tabs: LB and RB, Q and E, or Tab; from the Motion page, as from Controls) if ((tab_left || tab_right) && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS; + if ((tab_left || tab_right) && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS; // ((Triforce, N64 Classic) as from Graphics) if (tab_left || tab_right) { // (inside the game's Options: past our first or last tab is the game's own again; Mods // after System: tab_move) tab_move(tab_left ? -1 : 1); @@ -7293,7 +8185,17 @@ void menu_tick() { else if (mod_cheat_slot(r.name) >= 0) changed |= mod_cheats.press(mod_cheat_slot(r.name), press[3], press[4], press[7]); else if (press[7] && share_row(r)) share_press(share_row(r)), press[7] = false, changed = true; // (Triforce: the host does it) else if (press[7] && is_ach_row(r)) page = kAchPage, ach_view.reveal(ach_capacity), press[7] = false, changed = true; + else if (press[7] && r.name == kUseWindowSize) { + use_window_size(dev.swap_extent.width, dev.swap_extent.height); + press[7] = false; + changed = true; + } + else if (press[7] && is_files_row(r)) files_open(false), press[7] = false, changed = true; else if (press[7] && is_motion_row(r)) cur_tab = TAB_MOTION, tab_selected[TAB_MOTION] = 0, press[7] = false, changed = true; + // ((Triforce, 11-22, N64 Classic) Remembered settings opens its page; the page's two actions act on a press) + else if (press[7] && is_n64_page_row(r)) cur_tab = TAB_N64, tab_selected[TAB_N64] = 0, press[7] = false, changed = true; + // (its press kept: the sound's confirm, kDecide. The row has no value, and nothing after this takes press[7] for it) + else if (press[7] && n64_action(r)) n64_act(n64_action(r)), changed = true; else if (press[7] && !r.value && can_bind()) page = 1, csel = 0, ccol = 0, changed = true; if ((press[3] || press[4] || press[7]) && r.value) { // (Enter, or A, as Right) if (press[7]) press[4] = true; @@ -7463,20 +8365,113 @@ void draw_bench(ui::Ctx& c, const MkwVkBench& b) { if (b.phase < MKWVK_BENCH_DONE) c.d->AddText(body, small, ImVec2(x0, y), faint, "Esc stops the benchmark"); } -void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) { - const bool start = startup_on.load(std::memory_order_acquire); - static MkwVkBench bench; // ((Triforce) benchmark mode: its panel over everything else) - const bool bench_on = bench_now(&bench); - if (!start) bugshot_record(cmd, index, w, h); // (Triforce: a bug capture's picture of this frame, before anything is drawn over it) - const bool fps = opts.show_fps && !start; // (no game frames yet: not "0 FPS" over the start-up screen) - const bool open = open_now.load(std::memory_order_relaxed); - const bool note = !open && !start && notice_text[0] && prof_now() < notice_until; +namespace { +/// (Triforce) What the overlays show at a present, asked once (menu_tv_layer's, or menu_record's) +struct Showing { + bool start = false, fps = false, open = false, note = false, game_tab = false, mods_row = false, bench_on = false; + bool earned = false; // ((Triforce, 11-23) an achievement's notice (draw_ach_notice), flat over the TV as the notice +}; +MkwVkBench overlay_bench; // ((Triforce) benchmark mode: its panel over everything else) +Showing showing_now() { + Showing s; + s.start = startup_on.load(std::memory_order_acquire); + s.bench_on = bench_now(&overlay_bench); + s.fps = opts.show_fps && !s.start; // (no game frames yet: not "0 FPS" over the start-up screen) + s.open = open_now.load(std::memory_order_relaxed); + s.note = !s.open && !s.start && notice_text[0] && prof_now() < notice_until; // (Triforce: the game's own Options screen is up and none of our tabs: its header's tabs alone) const int64_t game_seen = game_options_ns.load(std::memory_order_relaxed); - const bool game_tab = !open && !start && embed_allowed() && game_seen && prof_now() - game_seen < 250000000LL && embed_since; - const bool mods_row = !open && !start && (mods_list_fresh() || mods_title_fading()); // ((Triforce) the Mods entry under the game's list) - const bool earned = !start && ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000; // ((Triforce) an achievement's notice) - if (!start && !fps && !open && !note && !game_tab && !mods_row && !bench_on && !earned) { // (nothing shows: no ImGui frame, no render pass) + s.game_tab = !s.open && !s.start && embed_allowed() && game_seen && prof_now() - game_seen < 250000000LL && embed_since; + s.mods_row = !s.open && !s.start && (mods_list_fresh() || mods_title_fading()); // ((Triforce) the Mods entry under the game's list) + s.earned = !s.start && ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000; // ((Triforce) an achievement's notice) + return s; +} +/// The overlays of a w x h window, after ui::begin. ((Triforce, 11-22, N64 Classic) under: the list the options' own screens +/// go into (the open menu, the game tab's header, the Mods entry; the Full panel while it is under them), for N64 Classic's TV +/// to take in (menu_tv_layer); null: one list for all, as before. The FPS counter, the notice and benchmark mode's panel stay +/// over the window, flat: a counter in a corner the curve takes away is no counter) +void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) { + { // (the easing's step: the time since the last drawing, a quarter of the way in 1/60 s) + static int64_t last = 0; + const int64_t now = prof_now(); + ease_step = last ? std::min(1.0f, (float)((now - last) / 1e9) * 15.0f) : 1.0f; + last = now; + ease_live = true; + } + ui::Ctx c = menu_ctx(w, h); + prebake(c); // (the menu's glyphs at this size, before it opens: no hitch then) + if (s.start) { // (under the menu, in the overlay's own fonts) + ui::Ctx sc = ui_ctx(w, h); + draw_startup(sc); + } + ui::Ctx m = c; // (the options' own screens) + if (under) m.d = under; + // ((Triforce) Full: NX2navi's panel alone, no counter beside it (its perf_draw), and under the options or the game tab's + // header while they show (its BringWindowToDisplayBack): the open menu covers it) + const bool full = s.fps && opts.show_fps == 2; + // ((Triforce, 11-19) the Mods entry's page: the panel over Quit's dialog and its dim, as over the game's own dialogs, which + // the game draws under every overlay. The lab's "its dim covers the left part of the stats overlay") + const bool over_row = s.open && page == kModsRowPage; + if (s.open) draw_menu(m, full && !over_row); + else { + if (full) draw_perf(s.game_tab || s.mods_row ? m : c); // (under the header or the entry: in their list) + if (s.game_tab) draw_game_tab(m); + else if (s.mods_row) draw_mods_row_shut(m); + } + if (full && over_row) draw_perf(c); + if (s.fps && !full) draw_fps(c, (s.open && page != kModsRowPage) || s.game_tab); // ((Triforce) the Mods entry: the counter stays where the game list has it) + if (s.note) draw_notice(c); + if (s.earned) draw_ach_notice(c); // ((Triforce, 11-23) flat on top, as the notice + if (s.bench_on) { // ((Triforce) benchmark mode's panel, in the overlay's own fonts, over the rest + ui::Ctx bc = ui_ctx(w, h); + draw_bench(bc, overlay_bench); + } +} +// ((Triforce, 11-22, N64 Classic) this present's overlays were drawn by menu_tv_layer: menu_record draws what is left of them +// (tv_drawn); or it asked what shows and drew nothing: menu_record takes its answer, so benchmark mode is asked once a present) +bool tv_drawn = false; +bool tv_layer = false; // (...and the options are in its layer: the mouse goes through the TV's curve to them) +bool tv_asked = false; +Showing tv_showing; +} // namespace + +VkImageView menu_tv_layer(VkCommandBuffer cmd) { + tv_drawn = tv_layer = tv_asked = false; + static const bool on = !(getenv("RX_VK_N64_TV_MENU") && *getenv("RX_VK_N64_TV_MENU") && atoi(getenv("RX_VK_N64_TV_MENU")) == 0); + uint32_t x = 0, y = 0, pw = 0, ph = 0, w = 0, h = 0; + if (!on || !n64_screen_place(&x, &y, &pw, &ph, &w, &h)) return VK_NULL_HANDLE; // (a shot's window pass: no window under it) + tv_showing = showing_now(), tv_asked = true; + const Showing& s = tv_showing; + // (none of the options' own screens; or a bug capture waits for this frame's picture, which is taken before the + // overlays; or an HDR10 window, whose overlays' pictures are made in its codes (vk_imgui.cpp pixels), not the SDR + // picture's the TV draws in: menu_record then, as before) + if (s.start || !(s.open || s.game_tab || s.mods_row) || bugshot_state() == 1 || dev.hdr || !ui::begin(w, h)) + return VK_NULL_HANDLE; + draw_overlays(w, h, s, ImGui::GetBackgroundDrawList()); + ::mkwvk::rec::boundary(::mkwvk::rec::B_DIRECT); // (Dear ImGui records into cmd directly, its backend through its own pointers: what this thread recorded through vk_work.h reaches cmd first) + const VkImageView layer = ui::record_layer(cmd, x, y, pw, ph); + tv_drawn = true, tv_layer = layer != VK_NULL_HANDLE, tv_asked = false; + static bool told = false; + if (layer && !told) + told = true, logf("menu: the options' own screens drawn under N64 Classic's TV, in a layer of the picture's place (%ux%u at " + "%u,%u of %ux%u); the FPS counter over it (RX_VK_N64_TV_MENU=0: all over the TV, as before)", pw, ph, x, y, w, h); + return layer; +} + +void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) { + if (tv_drawn) { // ((Triforce, 11-22, N64 Classic) the options went under the TV this present: the rest over the window + tv_drawn = false; + options_under_tv = tv_layer; // (no layer made: they went over the window, flat, as before) + bugshot_record(cmd, index, w, h); // (a copy under way goes on; none was waiting for this frame: menu_tv_layer) + ::mkwvk::rec::boundary(::mkwvk::rec::B_DIRECT); + ui::record_rest(cmd, index, w, h); + return; + } + options_under_tv = false; + const Showing s = tv_asked ? tv_showing : showing_now(); + tv_asked = false; + if (!s.start) bugshot_record(cmd, index, w, h); // (Triforce: a bug capture's picture of this frame, before anything is drawn over it) + if (!s.start && !s.fps && !s.open && !s.note && !s.game_tab && !s.mods_row && !s.bench_on && !s.earned) { // (nothing shows: no ImGui frame, no render pass) // (but a new window size or Menu size since the last bake: one frame with nothing drawn that bakes the menu's glyphs // and measures its page for the new size, so the next open has no hitch whatever was resized while nothing showed) if (prebake_needed(w, h) && ui::begin(w, h)) { @@ -7490,39 +8485,7 @@ void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) { return; } if (!ui::begin(w, h)) return; - { // (the easing's step: the time since the last drawing, a quarter of the way in 1/60 s) - static int64_t last = 0; - const int64_t now = prof_now(); - ease_step = last ? std::min(1.0f, (float)((now - last) / 1e9) * 15.0f) : 1.0f; - last = now; - ease_live = true; - } - ui::Ctx c = menu_ctx(w, h); - prebake(c); // (the menu's glyphs at this size, before it opens: no hitch then) - if (start) { // (under the menu, in the overlay's own fonts) - ui::Ctx sc = ui_ctx(w, h); - draw_startup(sc); - } - // ((Triforce) Full: NX2navi's panel alone, no counter beside it (its perf_draw), and under the options or the game tab's - // header while they show (its BringWindowToDisplayBack): the open menu covers it) - const bool full = fps && opts.show_fps == 2; - // ((Triforce, 11-19) the Mods entry's page: the panel over Quit's dialog and its dim, as over the game's own dialogs, which - // the game draws under every overlay. The lab's "its dim covers the left part of the stats overlay") - const bool over_row = open && page == kModsRowPage; - if (open) draw_menu(c, full && !over_row); - else { - if (full) draw_perf(c); - if (game_tab) draw_game_tab(c); - else if (mods_row) draw_mods_row_shut(c); - } - if (full && over_row) draw_perf(c); - if (fps && !full) draw_fps(c, (open && page != kModsRowPage) || game_tab); // ((Triforce) the Mods entry: the counter stays where the game list has it) - if (note) draw_notice(c); - if (earned) draw_ach_notice(c); - if (bench_on) { // ((Triforce) benchmark mode's panel, in the overlay's own fonts, over the rest - ui::Ctx bc = ui_ctx(w, h); - draw_bench(bc, bench); - } + draw_overlays(w, h, s, nullptr); ::mkwvk::rec::boundary(::mkwvk::rec::B_DIRECT); // (Dear ImGui records into cmd directly, its backend through its own pointers: what this thread recorded through vk_work.h reaches cmd first) ui::record(cmd, index, w, h); } diff --git a/gpu/vk/vk_menu.h b/gpu/vk/vk_menu.h index 50537dd..cf52aca 100644 --- a/gpu/vk/vk_menu.h +++ b/gpu/vk/vk_menu.h @@ -52,7 +52,8 @@ struct Options { int resolution = 0; // the 3D's (Render resolution): 0 Auto (the game's dynamic resolution), else a share of the output, // 1..6 = 100%, 75%, 67%, 50%, 58%, 33% (upscaler_rows.h; nx2/oot_patches.py) int output_res = 0; // the game's whole frame, docked: 0 its 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080, 4 5120x1440, 5 5120x2880, 6 5120x2160; - // (options_version 7) 7 1536x864, the game's handheld profile (merged_rows.h kHandheldOutput); read once, at the start (host/nn_applet.c) + // 8 Screen, 9 Custom (output_sizes.h); 7 1536x864, the game's handheld profile (merged_rows.h kHandheldOutput); read once, at the start (host/nn_applet.c) + int output_width = 2560, output_height = 1440; int upscale = 0; // to the window: 0 off (the plain copy), 1 Catmull-Rom, 2 Lanczos, 3 AMD FSR 1 (EASU + RCAS). (options_version 7) No // row: chosen at each present by the picture's size and its place in the window (vk_menu.cpp // menu_note_present_sizes, upscaler_rows.h auto_filter); RX_VK_UPSCALE=<0..3> fixes it for a run @@ -72,6 +73,13 @@ struct Options { int aa = 0; // (Triforce) Anti-aliasing: 0 the game's own SMAA, as before the row; in its place 1 nothing, 2 FXAA, 3 SMAA at // its Ultra preset (aa_rows.h, vk_aa.cpp; RX_VK_AA over it). Not applied while DLSS, DLAA or FSR // upscales. Taken each frame. Saved as anti-aliasing + // ((Triforce, 11-22, N64 Classic, step 5) the 1998 look (n64_rules.h, vk_n64.cpp): 0 Off, 1 Faithful (fixed), 2 Remembered + // (the Remembered page's rows below). Taken at each frame; RX_VK_N64 over it. Saved as n64_classic + int n64_classic = 0; + int n64_last = 1; // the preset F7 turns on from Off, the last one chosen (n64_rules.h Toggle); saved as n64_classic_last + // Remembered's page, by n64_rules::Row: n64_rules.h kSpec's defaults (tests/test_n64_row.py holds the two the same), saved + // under kSpec's keys (vk_menu.cpp ini_key) + int n64_rem[13] = {0, 2, 2, 0, 3, 1, 35, 0, 15, 1, 25, 1, 110}; int aniso = 0; // texture filtering: 0 the game's, 1 2x, 2 4x, 3 8x, 4 16x anisotropic at least (vk_draw.cpp sampler_for) int tex_detail = 0; // (Triforce) Texture detail: 0 Automatic (by the card's video memory), 1 Full, 2 Reduced, 3 Low; read at the // start (tex_detail.h, vk_texture.cpp texture_detail_level; RX_VK_TEX_DETAIL over it) @@ -79,8 +87,8 @@ struct Options { // half the video memory, when every block of them is opaque; read at the start (tex_bc1.h, vk_texture.cpp // bc1_on; RX_VK_TEX_BC1 over it) int realtime = 1; // game time follows the clock (host/nn_vi.c); 0: per frame (slower frames, slower game) - int ultrawide = 0; // the camera's shape: 0 the game's 16:9, 1 the monitor's when it is wider or narrower, 2 a fixed 21:9, 3 a fixed - // 32:9; read once, at the start (host/hos_main.c ultrawide_ratio) + int ultrawide = 0; // the picture's shape for a 16:9 Output resolution: 0 the game's 16:9, 1 a fixed 16:10, 2 a fixed 21:9, 3 a fixed + // 32:9 (ultrawide_rows.h); read once, at the start (host/hos_main.c ultrawide_ratio) int wide_menus = 1; // ultrawide: the pause, item and map menus 0 at full width (stretched), 1 in the middle 16:9 with the sides // blurred, 2 with black bars (nx2/oot_wide.py, vk_framegen.cpp) int show_fps = 0; // the FPS counter row: 0 off, 1 the counter, 2 (Triforce) Full, NX2navi's full performance overlay in the counter's place: @@ -144,6 +152,10 @@ struct Options { int wide_hud = 0; // (Triforce) with Ultrawide: 0 the HUD in the middle 16:9, 1 its corner pieces at the screen's edges (host/oot_wide_hud.c) int sprint_button = 0; // (Triforce) the sprint button: 0 off, 1 the left stick's click, 2 B (host/oot_sprint.h) int sprint_mode = 0; // 0 toggle (a press starts it, the next ends it), 1 hold + // ((Triforce) 11-23) the System tab's Achievements group (host/achievements.c): whether anything is earned, and whether + // one earned shows its notice and plays its sound. HOS_ACHIEVEMENTS=0 still turns them off whole + int achievements = 1; + int achievement_notices = 1; int discord = 1; // (hookshot) the Discord status (host/discord_rpc.c): 1 on, shown while a Discord client runs on this PC int language = 0; // (Triforce) Game language: the row's entry among the languages language.txt names (game_language.h). Not kept in // the options file: the choice is that file's line, which the host reads at the start (host/nn_applet.c) @@ -202,6 +214,9 @@ int menu_take_amiibo_ask(); /// (Triforce) A cheat of a mod's cheat file the player switched on the System tab since the last call: (its row + 1) * 2, plus 1 /// for on; 0 nothing (vk_api.h HOS_OPT_MODCHEAT_ASK, mod_cheat_rows.h) int menu_take_mod_cheat(); +/// (Triforce) The save file the player chose to play that is not this run's, its number (1 the first), since the last call; 0 +/// none (vk_api.h HOS_OPT_FILES_ASK, save_file_rows.h) +int menu_take_file_ask(); /// (Triforce) The next of the options' own sounds asked for since the last call, HOS_MENU_SOUND_* (vk_api.h), 0 none: for the /// host's sound thread alone (HOS_OPT_MENU_SOUND; menu_sound_events.h's queue, host/menu_sound.c) int menu_take_sound(); @@ -223,6 +238,13 @@ void menu_note_present_sizes(uint32_t picture_w, uint32_t picture_h, uint32_t wi /// Over the window's image `index` (TRANSFER_DST_OPTIMAL before and after), w x h: the start-up screen, the menu and the FPS /// counter, drawn with Dear ImGui (vk_imgui.h, vk_ui.h). Nothing recorded while none of them shows void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h); +/// ((Triforce, 11-22, N64 Classic, after the owner's test) From N64 Classic's TV pass, before it draws (vk_framegen.cpp +/// framegen_scale): while the options' own screens show (the menu open, our tabs over the game's Options screen, the Mods +/// entry), this present's overlays are drawn now, the options into a layer of the picture's place that the TV takes in +/// with the game's picture (vk_imgui.h record_layer), so they bend, scan and bleed as the game's own screens under them do; +/// menu_record then draws the rest over the window, flat (the FPS counter). Null: nothing of the options this present, or +/// no layer; menu_record draws as before. RX_VK_N64_TV_MENU=0: never (the options over the TV, flat, as before) +VkImageView menu_tv_layer(VkCommandBuffer cmd); /// (headless shots, RX_VK_SHOT_MENU) The menu and the counter over another image: TRANSFER_DST_OPTIMAL before and after, /// R8G8B8A8_UNORM with colour-attachment use, view a view of it void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h); diff --git a/gpu/vk/vk_n64.cpp b/gpu/vk/vk_n64.cpp new file mode 100644 index 0000000..54b368c --- /dev/null +++ b/gpu/vk/vk_n64.cpp @@ -0,0 +1,157 @@ +// (Triforce, 11-22) N64 Classic at work: see vk_n64.h (n64-classic-mode-plan.md, steps 2 to 8). +#include +#include +#include +#include +#include + +#include "vk_n64.h" +#include "vk_internal.h" // (logf) +#include "vk_menu.h" // ((step 5) opts: the Insert menu's N64 Classic row and the Remembered page) +#include "vk_dlssg.h" // ((step 4) dlssg::active: DLSS frame generation's frames are made after the window pass) +#include "vk_temporal.h" // (temporal_scene_format: a RenoDX run's RGBA16F scene, which the 3D pass does not take) + +namespace mkwvk { +namespace { + +/// A switch's number, `unset` when it is not set or is not a number +int env_number(const char* name, int unset) { + const char* e = getenv(name); + return e && ((*e >= '0' && *e <= '9') || *e == '-') ? atoi(e) : unset; +} + +} // namespace + +namespace { +/// RX_VK_N64 for the run, -1 unset +int env_n64() { + static const int env = [] { + const int v = env_number("RX_VK_N64", -1); + if (v >= 0) logf("vk: N64 Classic: RX_VK_N64=%d, %s, for this run over the menu's row", v, n64_rules::name(n64_rules::chosen(0, v))); + return v; + }(); + return env; +} +} // namespace + +bool n64_env_set() { return env_n64() >= 0; } + +namespace { +// ((step 8) the switch, ticked once a present (n64_tick); shown is read by every pass and by the host's answer, so it is an +// atomic of its own, -1 before the first present (then the preset chosen); the TV's frame, read once a present, under the lock) +std::atomic shown_now{-1}; +std::mutex switch_mu; +n64_rules::Switch switch_rule; +n64_rules::AnimFrame anim_now; +/// RX_VK_N64_TV_ANIM=0: no switching off and on, the choice at once +bool anim_on() { + static const bool on = env_number("RX_VK_N64_TV_ANIM", 1) != 0; + return on; +} +} // namespace + +void n64_tick(bool native_pq) { + const double t = std::chrono::duration(std::chrono::steady_clock::now().time_since_epoch()).count(); + std::lock_guard lk(switch_mu); + const int before = shown_now.load(std::memory_order_relaxed); + const n64_rules::Switch::Now now = switch_rule.at(t, n64_preset(), anim_on() && !native_pq && !dlssg::active()); + anim_now = now.frame; + shown_now.store(now.shown, std::memory_order_relaxed); + if (before >= 0 && now.shown != before) + logf("vk: N64 Classic: %s from here (was %s)", n64_rules::name(now.shown), n64_rules::name(before)); +} + +int n64_shown() { + const int s = shown_now.load(std::memory_order_relaxed); + return s >= 0 ? s : n64_preset(); +} + +n64_rules::AnimFrame n64_anim() { + std::lock_guard lk(switch_mu); + return anim_now; +} + +int n64_preset() { return n64_rules::chosen(opts.n64_classic, env_n64()); } // ((step 5) the Insert menu's row, RX_VK_N64 over it) + +n64_rules::Look n64_look() { + static const n64_rules::Env env = [] { + n64_rules::Env e; + e.lines = env_number("RX_VK_N64_LINES", -1); + if (const char* v = getenv("RX_VK_N64_LOD"); v && *v) e.lod = (float)atof(v); + e.tv = env_number("RX_VK_N64_TV", -1); + e.mask = env_number("RX_VK_N64_MASK", -1); + e.fps = env_number("RX_VK_N64_FPS", -1); + return e; + }(); + // ((step 5) Remembered's page; (step 8) the preset shown, which changes at a switch's middle) + return n64_rules::with_env(n64_rules::look_of(n64_shown(), n64_rules::rows_of(opts.n64_rem)), env); +} + +bool n64_3d_now() { + const n64_rules::Look l = n64_look(); + if (!l.on) return false; + const bool rgba16f = temporal_scene_format(VK_FORMAT_R16G16B16A16_SFLOAT); + static std::atomic told{false}; + if (rgba16f && !told.exchange(true, std::memory_order_relaxed)) + logf("vk: N64 Classic: this run's scene is RGBA16F (RenoDX's HDR): its 3D pass does not draw, the game's upscale does"); + return n64_rules::three_d_runs(l, rgba16f); +} + +int n64_in_front() { return n64_3d_now() ? n64_shown() : (int)n64_rules::OFF; } + +bool n64_tv_now(bool native_pq) { return n64_rules::tv_draws(n64_look(), n64_anim(), native_pq, dlssg::active()); } + +namespace { +// ((11-22) the TV's screen: the present's own (the presenting thread's alone), and the last one done, which the mouse goes by +// from any thread, under its lock) +struct Screen { + bool drawn = false; + uint32_t x = 0, y = 0, w = 0, h = 0, window_w = 0, window_h = 0; + float curve = 0.0f, anim_x = 1.0f, anim_y = 1.0f; +}; +bool screen_open = false; +Screen screen_now; +std::mutex screen_mu; +Screen screen_done; +} // namespace + +void n64_screen_begin(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t window_w, uint32_t window_h) { + screen_open = true; + screen_now = Screen{}; + screen_now.x = x, screen_now.y = y, screen_now.w = w, screen_now.h = h, screen_now.window_w = window_w, screen_now.window_h = window_h; +} + +void n64_screen_drawn(float curve, float anim_x, float anim_y) { + if (!screen_open) return; // (a shot's window pass: no window under it) + screen_now.drawn = true, screen_now.curve = curve, screen_now.anim_x = anim_x, screen_now.anim_y = anim_y; +} + +void n64_screen_end() { + if (!screen_open) return; + screen_open = false; + std::lock_guard lk(screen_mu); + screen_done = screen_now; +} + +bool n64_screen_place(uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h, uint32_t* window_w, uint32_t* window_h) { + if (!screen_open || !screen_now.w || !screen_now.h || !screen_now.window_w || !screen_now.window_h) return false; + *x = screen_now.x, *y = screen_now.y, *w = screen_now.w, *h = screen_now.h; + *window_w = screen_now.window_w, *window_h = screen_now.window_h; + return true; +} + +void n64_screen_point(int* x, int* y, int win_w, int win_h) { + Screen s; + { + std::lock_guard lk(screen_mu); + s = screen_done; + } + if (!s.drawn || win_w <= 0 || win_h <= 0 || !s.window_w || !s.window_h) return; + // (the cursor's pixel's middle, in the window image's pixels; back in the window's, the pixel it falls in) + const float kx = (float)s.window_w / (float)win_w, ky = (float)s.window_h / (float)win_h; + const n64_rules::ScreenPoint p = n64_rules::screen_point(((float)*x + 0.5f) * kx, ((float)*y + 0.5f) * ky, (float)s.x, (float)s.y, + (float)s.w, (float)s.h, s.curve, s.anim_x, s.anim_y); + *x = (int)std::floor(p.x / kx), *y = (int)std::floor(p.y / ky); +} + +} // namespace mkwvk diff --git a/gpu/vk/vk_n64.h b/gpu/vk/vk_n64.h new file mode 100644 index 0000000..af0e376 --- /dev/null +++ b/gpu/vk/vk_n64.h @@ -0,0 +1,60 @@ +// (Triforce, 11-22) N64 Classic at work (n64-classic-mode-plan.md): what is in effect for the frame being recorded, for the +// passes that draw it (vk_draw.cpp n64_upscale) and for what it stands in front of (vk_temporal.cpp temporal_mode, +// vk_fsr3.cpp fsr3_wanted, vk_aa.cpp). The rules themselves are n64_rules.h. +// +// The Insert menu's N64 Classic row (Graphics) and its Remembered page (step 5), RX_VK_N64=<0..2> and the lab's switches over +// them for a run. Off (the default), nothing here is on and every caller does what it did before. +#pragma once + +#include + +#include "n64_rules.h" + +namespace mkwvk { + +/// The N64 Classic row's value in effect (n64_rules.h OFF, FAITHFUL, REMEMBERED): the Insert menu's row (opts.n64_classic), +/// RX_VK_N64 over it for a run +int n64_preset(); +/// RX_VK_N64 sets the mode for this run (the row then has nothing to choose, and F7 does nothing) +bool n64_env_set(); +/// The frame's look: the preset's (Remembered's from its rows), the lab's switches over it (n64_rules.h with_env) +n64_rules::Look n64_look(); +/// N64 Classic's 3D pass takes the gameplay upscale this frame: the mode is on and the scene is the game's B10G11R11 (not a +/// RenoDX run's RGBA16F, n64_rules.h three_d_runs). What DLSS, FSR and the game's SMAA step aside for +bool n64_3d_now(); +/// The preset while the 3D pass takes the upscale (n64_3d_now), else OFF: what n64_rules.h upscaler and anti_aliasing are +/// asked with, so DLSS, FSR and the game's SMAA step aside only while the pass draws in their place +int n64_in_front(); +/// (step 4) N64 Classic's TV draws at the window this present: the look's TV on, or (step 8) the TV switching off and on, and +/// not on HDR Native's PQ picture (native_pq) nor while DLSS frame generation makes its frames from the finished image +/// (n64_rules.h tv_draws) +bool n64_tv_now(bool native_pq); +/// (step 8) Once a present (vk_replay.cpp, beside the texture blur's tick): the switch from the preset shown to the one +/// chosen (n64_rules.h Switch), half a second of the TV switching off and on at an F7 or a change of the row, the preset +/// the passes and the host go by changing at its middle. native_pq: HOS Native's picture, where no TV pass draws it +void n64_tick(bool native_pq); +/// (step 8) The preset the passes and the host go by now: the one chosen (n64_preset), or while a switch closes, the one +/// before it. n64_look is its look +int n64_shown(); +/// (step 8) The TV's frame of the switch now (n64_rules.h AnimFrame; done: none running) +n64_rules::AnimFrame n64_anim(); + +// ((11-22, after the owner's test) The TV's screen at a present, for the options drawn under it (vk_menu.cpp menu_tv_layer) +// and for the mouse (n64_screen_point). The present (vk_replay.cpp present_image) says where the picture goes in the window +// before its window pass (begin) and is done after it (end); the TV's pass says it drew, with what curve and squash, in +// between (drawn). Outside a present's window pass (a headless shot's) there is no place: nothing goes under the TV) + +/// The present's window pass begins: the picture goes to x, y, w, h of a window_w x window_h window image +void n64_screen_begin(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t window_w, uint32_t window_h); +/// The TV drew this present's picture, through this curve and squash (n64_tv.comp's curve, anim_x, anim_y) +void n64_screen_drawn(float curve, float anim_x, float anim_y); +/// The present's window pass is over: what it drew is what the mouse goes by until the next one +void n64_screen_end(); +/// Between begin and end: where the picture goes, and the window's size. false outside a present's window pass +bool n64_screen_place(uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h, uint32_t* window_w, uint32_t* window_h); +/// A point of a win_w x win_h window (the cursor's, in its pixels) taken to the point of the picture the TV showed there at +/// the last present (n64_rules.h screen_point): where the options' and the game's own controls were drawn. As it is when +/// the TV did not draw that present. Any thread (the host's game menus ask from the game's) +void n64_screen_point(int* x, int* y, int win_w, int win_h); + +} // namespace mkwvk diff --git a/gpu/vk/vk_recorder.h b/gpu/vk/vk_recorder.h index 016b00b..73e7027 100644 --- a/gpu/vk/vk_recorder.h +++ b/gpu/vk/vk_recorder.h @@ -87,7 +87,7 @@ extern std::atomic par_active; // (vk_replay.cpp: a parallel replay's se V(vkCmdSetDepthCompareOp) V(vkCmdSetStencilTestEnable) V(vkCmdSetRasterizerDiscardEnable) V(vkCmdSetPolygonModeEXT) \ V(vkCmdSetDepthClampEnableEXT) V(vkCmdSetAlphaToCoverageEnableEXT) \ A(vkCmdSetColorBlendEnableEXT) A(vkCmdSetColorBlendEquationEXT) A(vkCmdSetColorWriteMaskEXT) \ - A(vkCmdSetFragmentShadingRateKHR) V(vkCmdWriteBufferMarkerAMD) A(vkCmdSetCheckpointNV) V(vkCmdWriteTimestamp2) V(vkCmdResetQueryPool) + A(vkCmdSetFragmentShadingRateKHR) V(vkCmdWriteBufferMarkerAMD) A(vkCmdSetCheckpointNV) V(vkCmdWriteTimestamp2) V(vkCmdResetQueryPool) V(vkCmdCopyQueryPoolResults) // (DEFER) The calls that drain the thread's held packets first (vk_work.h has a macro for each: the test checks the two lists agree, // and that every file making one of these calls includes vk_work.h or is on its list of known exceptions). K: a ::vkx function, diff --git a/gpu/vk/vk_replay.cpp b/gpu/vk/vk_replay.cpp index 7f90776..39adb14 100644 --- a/gpu/vk/vk_replay.cpp +++ b/gpu/vk/vk_replay.cpp @@ -31,6 +31,7 @@ #include // (RX_VK_SEG_EARLY: ub_grow_mu) #include "vk_dlssg.h" +#include "vk_n64.h" // ((Triforce, N64 Classic) its frame rate for the host: HOS_OPT_N64_FPS) #include "cpu_count.h" // ((Triforce, 11-22, OS-49) the threads to size by: HOS_SIM_CPU #include "sim_gpu.h" // ((Triforce, 11-22, OS-49) RX_VK_SIM_GPU_SLOW, a lab switch: a slower GPU, sim_burn #include "occ_lean.h" // ((Triforce, 11-22, DESC-82) the occlusion proxies' census's line, status_tick @@ -71,6 +72,7 @@ #include "tail_early.h" // (Triforce: the early tail's rules, Start next frame early) #include "pass_barrier.h" // (Triforce: the pass barrier's game mode, which RX_VK_EVENT_BARRIER follows when unset) #include "replay_prio.h" // (Triforce: the replay's priority while it records, RX_VK_REPLAY_PRIO: ReplayPin) +#include "gpu_busy.h" // ((Triforce, 11-23) the recordings' GPU time as the union of their intervals: ts_dyn_present) #include "replay_pin.h" // (Triforce: the soft pin where the cores are of more than one kind, RX_VK_REPLAY_PIN_SOFT: ReplayPin) #include "mesh_ahead.h" // (Triforce: a run of indirect mesh draws, RX_VK_MESH_AHEAD: mesh_ahead_note) #include "gate_wait.h" // (Triforce: a submission that begins with a wait for the CPU's signal, RX_VK_GATE_WAIT_MS: submit_q) @@ -667,6 +669,62 @@ int64_t st_gpu_ns, st_gpu_max_ns; VkQueryPool ts_up_pool = VK_NULL_HANDLE; bool ts_up_pending[kRecordings]; int64_t st_gpu_up_ns, st_gpu_up_max_ns; +// ---- (Triforce, 11-23) RX_VK_QUERY_RING: a recording's timestamps read from memory the GPU copied them into, not with +// vkGetQueryPoolResults. On AMD's Windows driver that call cost about 0.6 ms a frame on the thread that replays the frame (two a +// recording, ~25 recordings a frame: 7.7% of its running time in a profile of an RX 6700 XT), and with RX_VK_RECORDER=thread each +// call is a boundary that waits for the recorder thread first. A slot's next use begins with a copy of its last use's timestamps +// (long done: the slot's fence was waited for) into the ring, each value with its availability word, before the queries are +// reset (query commands on one queue run in submission order), behind a transfer-to-host barrier; the next time the slot comes +// round, its fence waited for again, the CPU reads them. So each recording's GPU time arrives one turn of the ring later (48 +// recordings, about two frames) and nothing waits for it: the dynamic resolution's clock and the overlay average over 30 +// presents anyway. Only the recording's own timestamps (ts_pool): the upload command buffer's (ts_up_pool) are reset in that +// command buffer, which runs before the copy could, and stay read as before. Not without host-coherent memory for the ring (no +// invalidate, a boundary too). RX_VK_QUERY_RING=0: read with vkGetQueryPoolResults, as before. tests/test_query_ring.py +constexpr int kRingWords = 8; // (per slot: up to 3 timestamps, each a value and its availability word, 64 bytes a slot) +VkBuffer ts_ring = VK_NULL_HANDLE; +VmaAllocation ts_ring_alloc = nullptr; +const volatile uint64_t* ts_ring_map = nullptr; +bool ts_ring_copied[kRecordings]; // (the slot's last use copied its use before's timestamps: read them when it comes round) +int64_t st_ring_read, st_ring_unavailable; +bool query_ring_on() { + static const bool v = !(getenv("RX_VK_QUERY_RING") && atoi(getenv("RX_VK_QUERY_RING")) == 0); + return v; +} +/// (with ts_pool, the first time: where gpu_time_begin makes the pools) the ring, mapped and host-coherent, or none +void query_ring_make() { + if (!query_ring_on() || ts_ring) return; + void* mapped = nullptr; + if (!create_buffer_cached(kRecordings * kRingWords * 8, VK_BUFFER_USAGE_TRANSFER_DST_BIT, ts_ring, ts_ring_alloc, &mapped, true) || + !mapped) { + ts_ring = VK_NULL_HANDLE, ts_ring_alloc = nullptr; + logf("vk: the timestamps' ring could not be made: read with vkGetQueryPoolResults (RX_VK_QUERY_RING)"); + return; + } + VkMemoryPropertyFlags flags = 0; + alloc_memory_type(ts_ring_alloc, &flags); + if (!(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) { // (an invalidate would be a recorder boundary: the old way instead) + destroy_buffer(ts_ring, ts_ring_alloc); + ts_ring = VK_NULL_HANDLE, ts_ring_alloc = nullptr; + logf("vk: no host-coherent memory for the timestamps' ring: read with vkGetQueryPoolResults (RX_VK_QUERY_RING)"); + return; + } + std::memset(mapped, 0, kRecordings * kRingWords * 8); + ts_ring_map = (const volatile uint64_t*)mapped; + logf("vk: the recordings' timestamps go through a ring the GPU copies them into, read a turn later without a driver call " + "(RX_VK_QUERY_RING=0: vkGetQueryPoolResults)"); +} +// ((Triforce, 11-23) gpu_busy.h: the same intervals as one union, for the dynamic resolution's clock; gpu_busy_mu: read back on more +// than one thread) +std::mutex gpu_busy_mu; +::mkwvk::gpu_busy::Union gpu_busy_union; +void gpu_busy_add(uint64_t begin, uint64_t finish) { + std::lock_guard lk(gpu_busy_mu); + gpu_busy_union.add(begin, finish); +} +int64_t gpu_busy_ns() { + std::lock_guard lk(gpu_busy_mu); + return (int64_t)((double)gpu_busy_union.ticks * (double)dev.props.limits.timestampPeriod); +} // (Triforce, 11-15) the parallel replay's segments have their timestamps too (they had none: in the owner's test8 the GPU // time line read 2.2 to 2.8 ms a frame while the helpers recorded, 6.4 without them), and their share is counted apart int64_t st_gpu_seg_ns; @@ -800,21 +858,38 @@ void gpu_time_collect(Recording& r) { if (vkGetQueryPoolResults(dev.device, ts_up_pool, 2 * r.slot, 2, sizeof t, t, 8, VK_QUERY_RESULT_64_BIT) == VK_SUCCESS && t[1] > t[0]) { const int64_t ns = (int64_t)((t[1] - t[0]) * (double)dev.props.limits.timestampPeriod); + gpu_busy_add(t[0], t[1]); // (Triforce, 11-23) st_gpu_up_ns += ns; st_gpu_up_max_ns = std::max(st_gpu_up_max_ns, ns); if (r.segment) st_gpu_seg_ns += ns; } } - if (!ts_pool || !ts_pending[r.slot]) return; - ts_pending[r.slot] = false; - // ((Triforce, 11-22, OS-49) ts_count: three with RX_VK_SIM_GPU_SLOW, the last the recording's end: sim_collect) + // ((Triforce, 11-23) RX_VK_QUERY_RING: the timestamps the slot's last use copied (those of its use before), from memory) const int tn = ts_count(); uint64_t t[3] = {0, 0, 0}; - const bool got = vkGetQueryPoolResults(dev.device, ts_pool, tn * r.slot, tn, sizeof t, t, 8, VK_QUERY_RESULT_64_BIT) == VK_SUCCESS; + bool got = false; + if (ts_ring_map) { + if (!ts_ring_copied[r.slot] || !r.submitted) return; // (nothing copied, or the copy never went to the GPU) + ts_ring_copied[r.slot] = false; + const volatile uint64_t* w = ts_ring_map + (size_t)r.slot * kRingWords; + got = true; + for (int i = 0; i < tn; i++) { + t[i] = w[2 * i]; + got = got && w[2 * i + 1] != 0; // (each value's availability word) + } + st_ring_read++; + if (!got) st_ring_unavailable++; + } else { + if (!ts_pool || !ts_pending[r.slot]) return; + ts_pending[r.slot] = false; + // ((Triforce, 11-22, OS-49) ts_count: three with RX_VK_SIM_GPU_SLOW, the last the recording's end: sim_collect) + got = vkGetQueryPoolResults(dev.device, ts_pool, tn * r.slot, tn, sizeof t, t, 8, VK_QUERY_RESULT_64_BIT) == VK_SUCCESS; + } if (tn == 3) sim_collect(r, got ? t : nullptr); if (!got) return; if (t[tn - 1] <= t[0]) return; const int64_t ns = (int64_t)((t[tn - 1] - t[0]) * (double)dev.props.limits.timestampPeriod); + gpu_busy_add(t[0], t[tn - 1]); // (Triforce, 11-23) st_gpu_ns += ns; st_gpu_max_ns = std::max(st_gpu_max_ns, ns); if (r.segment) st_gpu_seg_ns += ns; @@ -828,6 +903,21 @@ void gpu_time_begin(Recording& r) { if (!ts_pool) return; qi.queryCount = 2 * kRecordings; if (vkCreateQueryPool(dev.device, &qi, nullptr, &ts_up_pool) != VK_SUCCESS) ts_up_pool = VK_NULL_HANDLE; + query_ring_make(); // (Triforce, 11-23) + } + // ((Triforce, 11-23) RX_VK_QUERY_RING: the slot's last use's timestamps (done: its fence was waited for) into the ring, before the + // reset below, the command buffer just begun (no pass open); read when the slot comes round again, gpu_time_collect) + if (ts_ring_map && ts_pending[r.slot]) { + ts_pending[r.slot] = false; + vkCmdCopyQueryPoolResults(r.cmd, ts_pool, ts_count() * r.slot, ts_count(), ts_ring, (VkDeviceSize)r.slot * kRingWords * 8, 16, + VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT); + VkMemoryBarrier2 mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER_2}; + mb.srcStageMask = VK_PIPELINE_STAGE_2_COPY_BIT, mb.srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT; + mb.dstStageMask = VK_PIPELINE_STAGE_2_HOST_BIT, mb.dstAccessMask = VK_ACCESS_2_HOST_READ_BIT; + VkDependencyInfo di{VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; + di.memoryBarrierCount = 1, di.pMemoryBarriers = &mb; + vkCmdPipelineBarrier2(r.cmd, &di); + ts_ring_copied[r.slot] = true; } vkCmdResetQueryPool(r.cmd, ts_pool, ts_count() * r.slot, ts_count()); vkCmdWriteTimestamp2(r.cmd, VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT, ts_pool, ts_count() * r.slot); @@ -1628,27 +1718,58 @@ uint64_t ts_anchor_ns = 0; // (the last present's time: counter timestamps are // own controller reads these reports, and it runs only on Auto. RX_VK_DYNRES_GPU=0 (or RX_VK_TS_SCALE set): the fixed scale uint64_t ts_first_ns = 0, ts_last_ns = 0; // (this frame's first and last timestamp report, real clock) double ts_ema_gpu_ns = 0, ts_ema_span_ns = 0, ts_dyn_scale = 0.1; +double ts_ema_behind_ns = 0; // ((Triforce, 11-23) the host's waits for the GPU a present, averaged as the two above) +bool ts_gpu_limited = false; // ((Triforce, 11-23) the card the frame's limit: ts_dyn_present, with its two thresholds) int64_t ts_gpu_last = 0; +// (Triforce, 11-23) The frames' GPU time is the union of the recordings' intervals (gpu_busy.h): their sum counted the overlaps of +// AMD's early first timestamps again, and Auto stepped the 3D down on a card half idle. RX_VK_DYNRES_UNION=0: the sum, as before. +// The union alone was not enough: a recording that waits on the GPU for an event the CPU sets later (the stream's waits, ev_values) +// counts that wait as GPU time too, and on an RX 6700 XT with the replay the frame's limit the union came to 19.8 ms against a +// 5.9 ms span (11-22): the clock read the CPU's time as the card's. So while the replay does not wait for the GPU (no recording +// slot waited for: st_wait_ns, the GPU behind), the card is not the frame's limit, and the clock says at most the span; only a +// GPU that holds the replay back can step the 3D down. RX_VK_DYNRES_UNION=0 also takes this rule away +bool ts_dyn_union() { + static const bool v = !(getenv("RX_VK_DYNRES_UNION") && atoi(getenv("RX_VK_DYNRES_UNION")) == 0); + return v; +} bool ts_dyn_on() { static const bool v = !getenv("RX_VK_TS_SCALE") && !(getenv("RX_VK_DYNRES_GPU") && atoi(getenv("RX_VK_DYNRES_GPU")) == 0); return v; } void ts_dyn_present() { // (once a present, before the anchor moves) if (!ts_dyn_on()) return; - const int64_t g = st_gpu_ns + st_gpu_up_ns; + const int64_t g = ts_dyn_union() ? gpu_busy_ns() : st_gpu_ns + st_gpu_up_ns; const double dg = (double)(g - ts_gpu_last); ts_gpu_last = g; const double span = ts_last_ns > ts_first_ns ? (double)(ts_last_ns - ts_first_ns) : 0.0; ts_first_ns = ts_last_ns = 0; + static int64_t waited_last = 0; // ((Triforce, 11-23) the replay's waits for a recording slot: the GPU behind) + // ((Triforce, 11-23) and every other host wait for the GPU, on all threads (gpu_wait_kinds.h: the game's fences and sync points, + // a frame's fence; the compositor's image excluded, image_free). With the 3D at 1920 x 1080 on an RX 6700 XT the slot waits + // stayed at 0.03 ms a frame while the host waited 6 to 17 ms a frame for the GPU elsewhere and submits blocked for up to 45 + // ms (11-23): the card was a limit the slot waits did not see, and Auto stayed at its top level) + static ::gpu_wait_kinds::Reader host_waits; + const double dw = (double)(st_wait_ns - waited_last) + (double)host_waits.take(nullptr, nullptr); + waited_last = st_wait_ns; if (dg <= 0 || dg > 200e6 || span <= 0) return; // (no GPU time read this present, or no frame of reports) const double k = 1.0 / 30.0; ts_ema_gpu_ns = ts_ema_gpu_ns ? ts_ema_gpu_ns + k * (dg - ts_ema_gpu_ns) : dg; ts_ema_span_ns = ts_ema_span_ns ? ts_ema_span_ns + k * (span - ts_ema_span_ns) : span; - ts_dyn_scale = std::clamp(ts_ema_gpu_ns / ts_ema_span_ns, 0.02, 8.0); + ts_ema_behind_ns += k * (std::max(0.0, dw) - ts_ema_behind_ns); + // ((Triforce, 11-23) the card the frame's limit: the host waited for it, 2 ms a frame or more on average, until the waits fall + // under 1 ms (two thresholds, so that the 3D is not stepped down and back up again around one). Not GPU-bound, the waits for + // a frame's fence and the game's sync points come to 0.4 to 1.3 ms a frame (the same card at 854 x 480, 11-22)) + if (ts_ema_behind_ns >= 2e6) ts_gpu_limited = true; + else if (ts_ema_behind_ns < 1e6) ts_gpu_limited = false; + const bool gpu_limit = !ts_dyn_union() || ts_gpu_limited; + ts_dyn_scale = std::clamp(ts_ema_gpu_ns / ts_ema_span_ns, 0.02, gpu_limit ? 8.0 : 1.0); static int64_t n = 0; if (++n % 1200 == 0) - logf("vk: dynamic resolution's clock: the frame's GPU time %.2f ms, the replay's span between its timestamp reports %.2f ms: " - "scale %.3f (RX_VK_DYNRES_GPU=0: 0.1)", ts_ema_gpu_ns / 1e6, ts_ema_span_ns / 1e6, ts_dyn_scale); + logf("vk: dynamic resolution's clock: the frame's GPU time %.2f ms (%s), the replay's span between its timestamp reports " + "%.2f ms, the host's waits for the GPU %.2f ms: scale %.3f%s (RX_VK_DYNRES_GPU=0: 0.1)", ts_ema_gpu_ns / 1e6, + ts_dyn_union() ? "the recordings' intervals as one union; RX_VK_DYNRES_UNION=0: their sum" : "the recordings' intervals summed", + ts_ema_span_ns / 1e6, ts_ema_behind_ns / 1e6, ts_dyn_scale, + ts_dyn_union() && !ts_gpu_limited ? ", at most 1: the card is not the frame's limit" : ""); } /// A GPU-timeline write of guest memory (the stream's own writes: they reach memory in command order) @@ -3361,6 +3482,9 @@ bool par_auto() { return v; } bool par_auto_on = false; // (the replay thread's: the parallel replay is the one in use now) +/// ((Triforce) 11-22) the benchmark's helper-thread test (host/hos_bench.c, HOS_OPT_HELPERS_FORCE): -1 the tuner decides, 0 the +/// replay thread alone, 1 the helper threads in use. Set from the game's thread, applied by par_tune_present at the next present +std::atomic par_forced{-1}; int par_threads() { const int n = par_threads_max(); return par_auto() && !par_auto_on ? 0 : n; @@ -3657,6 +3781,15 @@ void par_tune_present() { const double ms = std::chrono::duration(now - last).count(); last = now; const replay_threads::Frame fr = par_frame_now(ms); + // ((Triforce) 11-22) the benchmark's helper-thread test holds the way: the tuner is not told these frames (its windows + // and trials go on from where they were once it decides again) + if (const int forced = par_forced.load(std::memory_order_relaxed); forced >= 0) { + if (par_auto_on != (forced == 1)) + logf("vk: parallel replay: the benchmark's helper-thread test has the %s", forced == 1 ? "helper threads in use" + : "replay thread alone"); + par_auto_on = forced == 1; + return; + } static replay_threads::Tuner tuner = [] { replay_threads::Tuner t; t.use_rule = par_rule_on(); @@ -3677,6 +3810,7 @@ void par_tune_present() { "thread %.2f, %.0f%% of it, the GPU %.2f; %.0f of its %.0f draws and dispatches in command buffers to cut, %.2f us " "each: %d threads would take %.2f ms off the replay thread, and the frame %.2f ms at most): %s", (long long)tuner.frames(), s.flip ? "the helper threads on, without a trial" + : s.on_waits ? "the helper threads on once the scene has held three windows (Triforce, 11-23)" : v.kind == replay_threads::Verdict::kOff ? "no trial while this holds" : "the trials decide", w.frame, w.replay, 100.0 * v.share, w.gpu, w.cut, w.draws, w.draws > 0 ? 1000.0 * w.op / w.draws : 0.0, tuner.threads, v.saved, v.gain, v.why); @@ -3701,6 +3835,14 @@ void par_tune_present() { (long long)s.changes, more); par_trial_parts((long long)s.trials, s.parts); } + if (s.withdrawn) { // ((Triforce) 11-22: settled, the rule's "on" held against its scene) + static int told; + if (told++ < 40) + logf("vk: parallel replay, the rule's \"on\" withdrawn at present %lld: its scene changed (%.0f draws a frame, the replay " + "thread %.2f ms, the GPU %.2f, against %.0f, %.2f and %.2f with the helper threads first on): the replay thread " + "alone, the rule judges the new scene", (long long)tuner.frames(), s.window.draws, s.window.replay, s.window.gpu, + s.ref.draws, s.ref.replay, s.ref.gpu); + } if (s.settle) { // (Triforce, 11-22: after a trial the scene moved under) static int told; if (told++ < 40) @@ -7165,6 +7307,7 @@ void do_present(const nvn_tex* t, const int crop[4]) { const bool native_pq = tex && dev.hdr && opts.hdr == 2 && want_fmt == VK_FORMAT_A2B10G10R10_UNORM_PACK32; present_native_pq.store(held ? held_pic.valid && held_pic.pq : native_pq, std::memory_order_relaxed); upscale_lod_tick(); // ((Triforce, S8) the texture LOD bias follows DLSS's or FSR's render scale: vk_draw.h) + n64_tick(present_native_pq.load(std::memory_order_relaxed)); // ((Triforce, N64 Classic, step 8) the TV's switch, once a present) if (held) { // (Triforce: the held picture's own view, for the same passes) if (src && !dev.offscreen && (opts.upscale || opts.sharpness || dev.hdr || wide_sides_possible())) direct_view = held_pic.view; } else if (tex && !dev.offscreen && (opts.upscale || opts.sharpness || dev.hdr || wide_sides_possible())) { // (and ultrawide's menu sides) @@ -7864,8 +8007,16 @@ bool present_thread_on() { return on; } /// This present goes out from the present thread: one of the game's pictures, with none of the presents of their own +bool acquire_ahead_wanted(); // ((Triforce, 11-23) below, with the acquire's fence) bool present_thread_wanted() { - return present_thread_use(present_thread_on(), smooth_mine, framegen_on(), dlssg::active(), antilag_running()) != 0; + // (Triforce, 11-23) and with the next image acquired ahead (acquire_ahead_wanted), which only the present thread can do off the + // frame's path. RX_VK_PRESENT_THREAD=0: never + static const bool never = [] { + const char* e = getenv("RX_VK_PRESENT_THREAD"); + return e && *e && atoi(e) == 0; + }(); + const bool on = present_thread_on() || (!never && acquire_ahead_wanted()); + return present_thread_use(on, smooth_mine, framegen_on(), dlssg::active(), antilag_running()) != 0; } /// present_image's first step (present_image_mu held): the present handed over before this one out void present_thread_settle() { @@ -7885,6 +8036,7 @@ int64_t present_waited_ns() { return present_fig.wait_ns.load(std::memory_order_ static void present_out(const PresentOut& o, std::unique_lock& qk, bool on_thread); namespace { +void acquire_ahead(); // ((Triforce, 11-23) RX_VK_ACQUIRE_AHEAD: below, with the acquire's fence) void present_thread_main() { SetThreadDescription(GetCurrentThread(), L"mkw_vk present"); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); // (as frame generation's display thread) @@ -7895,6 +8047,7 @@ void present_thread_main() { std::unique_lock qk(dev.present_mu, std::defer_lock); present_out(o, qk, true); } + acquire_ahead(); // ((Triforce, 11-23) the next frame's image, while the presenting thread replays that frame) smooth_mine = false; present_hand.done(); } @@ -7948,6 +8101,7 @@ struct HeldImage { uint64_t generation = 0; // (dev.swap_generation of the swapchain it came from) int presents = 0; // (the presents that found it not free yet) bool logged = false; // (its hold logged: the first 16 are) + bool free = false; // ((Triforce, 11-23) acquired ahead and waited free already: acquire_ahead; its fence reset) }; HeldImage held_image; // (present_image_mu) VkFence acquire_fence_now = VK_NULL_HANDLE; // (present_image_mu; unsignaled whenever no acquire signals it) @@ -7969,6 +8123,9 @@ void held_image_drop() { /// Whether the image just acquired, or the one held, is free: its fence waited for up to timeout_ns, and reset once signaled /// for the next acquire. VK_TIMEOUT: not yet VkResult image_free(uint64_t timeout_ns) { + // ((Triforce, 11-23) the image back from the compositor at its refresh: pacing, not the GPU's work, so not in the host's waits + // for the GPU (gpu_wait_kinds.h) that the dynamic resolution's clock reads, ts_dyn_present) + const ::gpu_wait_kinds::Exclude compositor; VkResult r = vkWaitForFences(dev.device, 1, &acquire_fence_now, VK_TRUE, timeout_ns); if (r == VK_SUCCESS) r = vkResetFences(dev.device, 1, &acquire_fence_now); return r; @@ -7976,6 +8133,64 @@ VkResult image_free(uint64_t timeout_ns) { // ((Triforce, 11-22, the performance audit's PRESENT-45, after Source A's) a present on the present thread answered that the // window's surface is lost (present_out): the next present_image, the thread that makes the swapchain, lets it go) std::atomic surface_lost_noted{false}; +// ---- (Triforce, 11-23) RX_VK_ACQUIRE_AHEAD: the next frame's swapchain image acquired, and waited free, on the present thread +// right after its present, while the presenting thread replays that frame. On an RX 6700 XT (AMD's Windows driver, 26.11.2) the +// image's wait in present_image (image_free, the pacing's wait in the present line) took 2.4 to 4.2 ms of every frame with the +// game the frame's limit at 45 to 52 fps, and the profile put 16% of the presenting thread in it: AMD presents through DXGI, +// and an image comes back with the compositor's next refresh. Ahead, the wait overlaps the replay, and present_image finds the +// image held and free (held_image.free) and records its blit at once. Held images keep their rules: a swapchain made again +// drops it (present_image's generation check), and one not free in 250 ms is held as before and looked at by the next present. +// Only on the present thread (present_thread_wanted turns it on for this: the wait on the presenting thread itself would gain +// nothing), with the acquire's fence (RX_VK_ACQUIRE_FENCE), without DLSS frame generation, on AMD's Windows driver; not while a +// resize or a lost surface waits for present_image, which makes the swapchain. RX_VK_ACQUIRE_AHEAD=0: off, =1: on any card +bool acquire_ahead_wanted() { +#ifdef _WIN32 + static const int asked = [] { + const char* e = getenv("RX_VK_ACQUIRE_AHEAD"); + return e && *e ? atoi(e) : -1; + }(); + if (asked == 0 || !acquire_fence_on() || dlssg::active()) return false; + return asked > 0 || dev.props.vendorID == 0x1002; +#else + return false; +#endif +} +struct AcquireAheadFigures { // (the present thread's alone: the line every 600 acquires) + int64_t acquired = 0, free = 0, held = 0, skipped = 0, wait_ns = 0; +} acquire_ahead_fig; +void acquire_ahead() { + if (!acquire_ahead_wanted()) return; + // (no lock: every present_image settles this thread's work first (present_thread_settle, present_image_mu held) before it + // looks at held_image, and hands the next present over only after its own use of the image; between the hand-over and the + // next settle this thread alone touches held_image and the fence. present_image_mu here would deadlock with that settle) + if (held_image.on || !dev.swapchain || dev.swap_resize.load(std::memory_order_acquire) || + surface_lost_noted.load(std::memory_order_acquire)) { + acquire_ahead_fig.skipped++; + return; + } + const VkFence fence = acquire_fence(); + if (!fence) return; + uint32_t index = 0; + const VkResult res = vkAcquireNextImageKHR(dev.device, dev.swapchain, UINT64_MAX, VK_NULL_HANDLE, fence, &index); + if (res == VK_ERROR_DEVICE_LOST) device_lost(); + if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) { // (out of date, a lost surface: present_image's to handle, as before) + acquire_ahead_fig.skipped++; + return; + } + const auto w0 = std::chrono::steady_clock::now(); + const VkResult ready = image_free(250000000ull); + if (ready == VK_ERROR_DEVICE_LOST) device_lost(); + acquire_ahead_fig.wait_ns += std::chrono::duration_cast(std::chrono::steady_clock::now() - w0).count(); + held_image = {true, index, dev.swap_generation, 0, false, ready == VK_SUCCESS}; + acquire_ahead_fig.acquired++, (ready == VK_SUCCESS ? acquire_ahead_fig.free : acquire_ahead_fig.held)++; + if (acquire_ahead_fig.acquired % 600 == 0) { + logf("vk: the next image acquired ahead on the present thread (RX_VK_ACQUIRE_AHEAD), 600 presents: %lld free when looked at " + "(its wait %.2f ms on average, off the frame's path), %lld not free in 250 ms (held), %lld left to present_image", + (long long)acquire_ahead_fig.free, acquire_ahead_fig.wait_ns / 600.0 / 1e6, (long long)acquire_ahead_fig.held, + (long long)acquire_ahead_fig.skipped); + acquire_ahead_fig = {}; + } +} } // namespace // (hookshot) One thread in here at a time; the queue's own lock (dev.present_mu, the replay's submits take it too) is held only @@ -8089,7 +8304,8 @@ void present_image(VkImage src, uint32_t sw, uint32_t sh, const int crop[4], VkI } if (fenced) { // ((Triforce) RX_VK_ACQUIRE_FENCE: the image free before anything is recorded for it; the wait is the pacing's) const auto w0 = std::chrono::steady_clock::now(); - const VkResult ready = image_free(held_image.on ? 0 : 250000000ull); + // ((Triforce, 11-23) acquired ahead and waited free on the present thread: its fence reset already, nothing to wait for) + const VkResult ready = held_image.on && held_image.free ? VK_SUCCESS : image_free(held_image.on ? 0 : 250000000ull); if (ready == VK_ERROR_DEVICE_LOST) device_lost(); present_fig.paced_ns.fetch_add( std::chrono::duration_cast(std::chrono::steady_clock::now() - w0).count(), @@ -8133,7 +8349,10 @@ void present_image(VkImage src, uint32_t sw, uint32_t sh, const int crop[4], VkI // The following blit overlaps the clear in the content rectangle. image_barrier(f.cmd, dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); } + // ((Triforce, 11-22, N64 Classic) where the picture goes, for its TV's screen: the options drawn under it, the mouse after it) + n64_screen_begin(rect.x, rect.y, rect.w, rect.h, dev.swap_extent.width, dev.swap_extent.height); const VkImage scaled = src && view ? framegen_scale(f.cmd, view, src, sw, sh, crop, rect.w, rect.h) : VK_NULL_HANDLE; + n64_screen_end(); // (hookshot) the Insert menu's HDR: the picture (scaled, or the game's own with its crop) to HDR10, copied in as the SDR one is // (lab, 11-13) RX_VK_TEST_HDR_PASS=1: the HDR pass on a screen that is not HDR (its colours are wrong there, by design): // whether the pass gets a picture at all can be seen without an HDR display @@ -9277,19 +9496,28 @@ void fill_replay_table(MkwVkRenderer& t) { if (id == HOS_OPT_SPRINT) return opts.sprint_button; if (id == HOS_OPT_SPRINT_HOLD) return opts.sprint_mode; if (id == HOS_OPT_DISPLAY_CAP) return fps_cap::of_display(display_refresh_mhz()); // (Monitor's rate: host/nn_vi.c fps_max) + // ((Triforce, 11-22, N64 Classic, step 7) its frame rate while its 3D pass draws (n64_rules.h fps; host/nn_vi.c n64_pace_decide) + if (id == HOS_OPT_N64_FPS) return n64_3d_now() ? n64_rules::fps(n64_look()) : 0; if (id == HOS_OPT_PACE_START) return pace::frame_start(); // (Triforce: the game's frame starts, host/nn_vi.c hos_vi_native_acquire) if (id == HOS_OPT_PACE_STEADY) return pace::steady_held_us(); // (Triforce: the present's hold for the Steady frame rate row) if (id == HOS_OPT_SHARE_ASK) return menu_take_share_ask(); // (Triforce: the System tab's save rows, host/save_share.c) if (id == HOS_OPT_BUG_SHOT) return menu_bug_shot(); // (and a bug capture's picture: host/bug_capture.c) if (id == HOS_OPT_MODCHEAT_ASK) return menu_take_mod_cheat(); // (Triforce: a mod's cheat switched on its row, host/mod_cheats.c) + if (id == HOS_OPT_FILES_ASK) return menu_take_file_ask(); // (Triforce: the save file chosen at the title's file select, host/save_files.c) + if (id == HOS_OPT_ACH_ON) return opts.achievements != 0; // ((Triforce) the Achievements group's rows) + if (id == HOS_OPT_ACH_NOTICES) return opts.achievement_notices != 0; if (id == HOS_OPT_ACH_ASK) return 1; // (Triforce: this renderer shows the achievements: host/achievements.c names them) if (id == HOS_OPT_MODS_SELECTED) return menu_mods_selected(); // (Triforce: the Mods entry has the cursor, host/oot_menu.c) if (id == HOS_OPT_MODS_MUSIC) return menu_mods_music(); // ((Triforce, 11-20) the Mods screen's music, host/mods_music.c) if (id == HOS_OPT_TEXT_WANTED) return menu_text_wanted(); // (Triforce: the Mods screen's search takes text, host/display.c) + if (id == HOS_OPT_HELPERS_FORCE) return par_auto() ? par_threads_max() : 0; // ((Triforce) 11-22: host/hos_bench.c) return id == 0 ? opts.realtime : id == 1 ? menu_is_open() : id == 2 ? resolution_auto() && !temporal_full_scale() : id == 3 ? (temporal_full_scale() ? 10000 : resolution_scale()) : id == 4 ? opts.pad_background : id == 5 ? opts.text_speed : id == 6 ? opts.mouse_native : id == 7 ? opts.mouse_sens : id == 8 ? opts.mouse_invert : id == 9 ? opts.rumble : id == 16 ? opts.invert_cam_x : id == 17 ? opts.invert_cam_y : id == HOS_OPT_GYRO ? opts.gyro : id == HOS_OPT_GYRO_SENS_X ? opts.gyro_sens_x : id == HOS_OPT_GYRO_SENS_Y ? opts.gyro_sens_y : id == HOS_OPT_GYRO_INV_X ? opts.gyro_inv_x : id == HOS_OPT_GYRO_INV_Y ? opts.gyro_inv_y : id == HOS_OPT_GYRO_DEADZONE ? opts.gyro_deadzone : id == HOS_OPT_DLSS_JITTER_W || id == HOS_OPT_DLSS_JITTER_H || id == HOS_OPT_DLSS_JITTER_PHASES ? jitter_option(id) : 0; }; + // ((Triforce, 11-22, N64 Classic) a point of the window, the cursor's, to where its TV showed the picture's (host/oot_menu.c: + // the game's own menus under the TV's curve) + t.screen_point = [](int* x, int* y, int w, int h) { n64_screen_point(x, y, w, h); }; t.option_set = [](int id, int value) { if (id == HOS_OPT_EXITING) { // ((Triforce, handoff §8) the files threads of their own are writing, finished first) const file_writers::Stopped s = file_writers::stop(file_writers::exit_wait_ms()); @@ -9304,6 +9532,7 @@ void fill_replay_table(MkwVkRenderer& t) { if (id == HOS_OPT_PACE_PERIOD) return pace::set_period_ns(value); // (Triforce: the period the host paces by, vk_pace.cpp) if (id == HOS_OPT_PACE_MOVIE) return pace::set_movie(value); // (and whether a movie plays) if (id == HOS_OPT_PACE_STEADY) return pace::set_steady(value); // ((Triforce) and whether it is the Steady frame rate row's) + if (id == HOS_OPT_HELPERS_FORCE) return par_forced.store(value < 0 ? -1 : value ? 1 : 0, std::memory_order_relaxed); menu_option_set(id, value); }; t.nvn_register_sampler = register_sampler_queued; diff --git a/gpu/vk/vk_temporal.cpp b/gpu/vk/vk_temporal.cpp index efc91d6..a9b6ac4 100644 --- a/gpu/vk/vk_temporal.cpp +++ b/gpu/vk/vk_temporal.cpp @@ -73,6 +73,7 @@ #include "vk_fsr4.h" #include "vk_menu.h" #include "vk_renodx.h" // (renodx_built: temporal_scene_format) +#include "vk_n64.h" // ((Triforce, N64 Classic) its 3D pass takes the gameplay upscale while it is on: temporal_mode) #include "vk_texture.h" #include "shaders/dlss_actor_frag_spv.h" @@ -116,6 +117,9 @@ int temporal_mode() { rearm_on_choice(v); if (dlss > 0) v = dlss >= 2 ? ur::DLAA : ur::DLSS; // (2 and up: DLAA, as RX_VK_DLSS was clamped before) else if (fsr4 > 0) v = fsr4 >= 2 ? ur::FSR4_AA : ur::FSR4; + // ((Triforce, 11-22, N64 Classic) while its 3D pass draws the gameplay upscale, the game's own as far as the chain is + // concerned (n64_rules.h upscaler): no jitter, no motion, no feature drawn. The row and the switches keep their values + v = n64_rules::upscaler(n64_in_front(), v); // (FSR 3.1, the row's 3, is not an engine of this chain: the game's own as far as it is concerned. Nor anything while // FSR 3.1 upscales: one upscaler at a time, and one camera jitter. A switch above goes over the row's FSR 3.1 too // (fsr3_wanted asks temporal_env_chosen); RX_VK_FSR=1 goes over them) @@ -265,6 +269,8 @@ struct State { uint32_t pre_out_id = 0; // (its creation number and texture_destroyed_count when noted: there_still) uint64_t pre_out_noted = 0; const Texture* pre_scene = nullptr; + uint32_t pre_scene_id = 0; // (its creation number and texture_destroyed_count when drawn into: pre_scene_alive) + uint64_t pre_scene_noted = 0; uint64_t pre_late = 0, pre_drawn = 0, pre_missed = 0; int pre_miss_run = 0; // (frames in a row without the point) uint64_t pre_late_frame = 0; @@ -592,6 +598,16 @@ bool make_pipelines(bool hdr) { /// or its picture at the output's size bool there_still(uint32_t id, uint64_t noted) { return !texture_destroyed_since(id, noted); } bool there_still(const Camera& cam) { return there_still(cam.color_id, cam.noted) && there_still(cam.depth_id, cam.noted); } +/// The scene's target the engine drew into before the bloom, unless that texture went since: then the pending point is +/// dropped. (0.7.0 crash at pre_dispatch: the stale pointer read after the scene's target went with a window resize, an +/// alt-tab or an area change while a point was still pending; RX_VK_PRE_SCENE_CHECK=0 = as before) +bool pre_scene_alive(State& s) { + static const bool check = !getenv("RX_VK_PRE_SCENE_CHECK") || strcmp(getenv("RX_VK_PRE_SCENE_CHECK"), "0"); + if (!s.pre_scene) return false; + if (!check || there_still(s.pre_scene_id, s.pre_scene_noted)) return true; + s.pre_scene = nullptr, s.pre_pending = false, s.pre_final = nullptr, s.pre_direct = false; + return false; +} /// A view of a depth texture's depth alone, for sampling (made once per image); of a colour texture, its colour (the /// scene's target, sampled and written by temporal_pre_tonemap) @@ -1592,6 +1608,7 @@ bool pre_copy(VkCommandBuffer cmd, Texture* final, Texture* in, VkImageView in_v bool pre_dispatch(VkCommandBuffer cmd, int mode, Texture* in, VkImageView in_view, Texture* out, VkImageView out_view, uint32_t out_level, bool learn = true) { State& s = st(); + if (s.pre_pending) (void)pre_scene_alive(s); // (the engine drew before the bloom, and this is the scene's upscale: the tone mapped picture goes to the output as it // is, or is there already, drawn at the output's size) // (its input is the scene's own texture with the game's formats, the game packing the tone mapped picture back into it; @@ -1729,6 +1746,7 @@ bool pre_fsr3(VkCommandBuffer cmd, Texture* scene, VkImageView view, uint32_t rw } full_barrier(cmd); s.pre_pending = true, s.pre_frame = texture_frame_no(), s.pre_scene = scene, s.pre_drawn++; + s.pre_scene_id = scene->id, s.pre_scene_noted = texture_destroyed_count(); s.pre_final = nullptr, s.pre_direct = false, s.pre_miss_run = 0, s.pre_touched = false; s.pre_picture = {picture, ow, oh}; return true; @@ -2050,6 +2068,7 @@ bool chain(VkCommandBuffer cmd, int mode, Engine& engine, const Camera& cam, con s.status_drawn++; if (pre) { s.pre_pending = true, s.pre_frame = now, s.pre_scene = pre, s.pre_drawn++; + s.pre_scene_id = pre->id, s.pre_scene_noted = texture_destroyed_count(); s.pre_final = nullptr, s.pre_direct = false, s.pre_miss_run = 0, s.pre_touched = false; s.pre_picture = {picture, s.output.width, s.output.height}; full_barrier(cmd); @@ -2082,6 +2101,7 @@ bool temporal_pre_point(const Texture* color0, uint64_t program, bool* late) { if (!color0 || !pre_wanted(temporal_mode())) return false; State& s = st(); std::lock_guard lk(s.mu); + if (s.pre_pending) (void)pre_scene_alive(s); // (pending from an earlier frame: that frame had no upscale's dispatch after it. Not this frame's) if (s.pre_pending && texture_frame_no() != s.pre_frame && color0 == s.pre_scene) s.pre_pending = false; if (s.pre_pending) { // (the engine drew already: a draw into the scene now is one it did not see) @@ -2196,7 +2216,7 @@ bool temporal_pre_dispatch(VkCommandBuffer cmd, Texture* in, VkImageView in_view bool temporal_pre_composite(const Texture* color0, uint32_t width, uint32_t height, TemporalRetarget* k) { State& s = st(); std::lock_guard lk(s.mu); - if (!s.pre_pending || s.pre_final || !s.pre_scene || !color0 || color0 == s.pre_scene) return false; + if (!s.pre_pending || s.pre_final || !pre_scene_alive(s) || !color0 || color0 == s.pre_scene) return false; if (!temporal_scene_format(color0->format) || width != s.pre_scene->width || height != s.pre_scene->height) return false; s.pre_final = color0; @@ -2222,7 +2242,7 @@ VkImageView temporal_pre_merged(VkCommandBuffer cmd) { std::lock_guard lk(s.mu); const uint32_t ow = s.pre_picture.width, oh = s.pre_picture.height; // (nothing drawn into the scene since, or no copy of it: the engine's picture as it is) - if (!s.pre_pending || !s.pre_touched || !s.pre_scene || !s.base.image || s.base.width != s.pre_scene->width || + if (!s.pre_pending || !s.pre_touched || !pre_scene_alive(s) || !s.base.image || s.base.width != s.pre_scene->width || s.base.height != s.pre_scene->height) return s.pre_picture.view; const VkDescriptorType S = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, I = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; diff --git a/gpu/vk/vk_work.h b/gpu/vk/vk_work.h index f1394a6..fb4d1bb 100644 --- a/gpu/vk/vk_work.h +++ b/gpu/vk/vk_work.h @@ -77,6 +77,8 @@ inline VkResult query_results(Call&& call, VkDevice device, VkQueryPool pool, ui #define vkCmdUpdateBuffer(...) (::mkwvk::rec::rx_vkCmdUpdateBuffer(RX_WORK_ON(__VA_ARGS__))) #define vkCmdBeginQuery(...) (::mkwvk::rec::rx_vkCmdBeginQuery(RX_WORK_ON(__VA_ARGS__))) #define vkCmdEndQuery(...) (::mkwvk::rec::rx_vkCmdEndQuery(RX_WORK_ON(__VA_ARGS__))) +// ((Triforce, 11-23) RX_VK_QUERY_RING: a recording's timestamps copied by the GPU into a mapped ring, vk_replay.cpp gpu_time_end) +#define vkCmdCopyQueryPoolResults(...) (::mkwvk::rec::rx_vkCmdCopyQueryPoolResults(RX_WORK_ON(__VA_ARGS__))) // (RX_VK_RECORDER) the calls that set state, bind or mark: not work (no count), but in the command buffer in order with the work, so // through the recorder too diff --git a/gpu/vk/wide_sides_rule.h b/gpu/vk/wide_sides_rule.h new file mode 100644 index 0000000..d0d6eb6 --- /dev/null +++ b/gpu/vk/wide_sides_rule.h @@ -0,0 +1,35 @@ +// (Triforce) Ultrawide's menu sides: when the renderer shows them, as plain code (vk_framegen.cpp wide_sides; +// tests/test_wide_sides.py). No Vulkan, no host. +// +// With the Insert menu's Ultrawide menus row on Centred the game's menus keep their 16:9 shape in the middle of a wider +// picture, and the renderer treats what is beside them: out of focus (1) or black (2). It shows the sides while a menu +// shows, which it tells by what the frame draws: +// - the world's lighting composite drawn (vk_draw.cpp world_drawn_at): play, no menu, no sides; +// - the blur of the last picture drawn (vk_draw.cpp wheel_drawn_at, program 02ff9920): the item wheel's background, the +// last frame of play blurred over the whole picture, which the game keeps whole (host/oot_wide_hud.h's keep class 0): +// its sides are the game's own, none of ours. +// The same program also draws the backdrop of a system menu opened over the title (the file select, seen in the game: the +// title movie behind it, blurred). That backdrop is the system menus' (keep class 1), which the row puts in the middle +// 16:9, so it needs the sides: taken for the wheel's it got none, and the sharp movie stood beside the blurred middle. +// The program alone cannot tell the two apart; the host can, by the game's menu screens that run (MkwVkHost.wide_backdrop: +// a menu whose backdrop is the centred one). While such a menu runs the blur drawn is its backdrop and not the wheel's. +#pragma once +#include + +namespace mkwvk::wide_sides_rule { + +/// (a frame the world or the wheel skips: 3 presents' grace) +constexpr int64_t kGrace = 3; + +/// The sides to show: 0 none, else the row's value (1 out of focus, 2 black). setting: the Ultrawide menus row. margin: the +/// middle 16:9's margin at either side, 0 for a 16:9 picture or while the host wants none (the filled title movie alone). +/// now, world_at, blur_at: the present now, and the last ones whose frames drew the world and the blur of the last +/// picture. centred_menu: the host says a menu with the centred backdrop runs +constexpr int show(int setting, float margin, int64_t now, int64_t world_at, int64_t blur_at, bool centred_menu) { + if (!setting || !(margin > 0.0f)) return 0; + if (now - world_at <= kGrace) return 0; // (the world: play) + if (now - blur_at <= kGrace && !centred_menu) return 0; // (the item wheel's background, whole by the game) + return setting; +} + +} // namespace mkwvk::wide_sides_rule diff --git a/host/achievements.c b/host/achievements.c index a7ff58a..42edb22 100644 --- a/host/achievements.c +++ b/host/achievements.c @@ -5,13 +5,18 @@ - On by default (11-22, the owner's word); HOS_ACHIEVEMENTS=0 (triforce_env.txt) turns them off. While off nothing is read, of the game or of the disk. + - (11-23) The System tab's Achievements group has two rows of them, read from the renderer at each check: Achievements + Off (HOS_OPT_ACH_ON 0) and nothing is asked of the save data or earned, from the next check on, and On again as + soon; Achievement notices Off (HOS_OPT_ACH_NOTICES 0) and one earned is kept, said in the log and told to the list, + without the sound (the menu shows no notice then). - The lists are read at the game's first present (hos_achievements_frame, host/nvn_native.c): the built-in one, then achievements.txt in the game folder when there is one. Once the renderer answers they are named to the menu (HOS_OPT_ACH_TEXT, _ADD, _COUNT: gpu/vk/achievement_rows.h), which lists them on the System tab's Achievements page. - host/hos_main.c asks once a second at Link's update, on the game's thread, while a save is loaded, and hands over how the save data is read (hos_achievements_check). - An achievement earned is written to triforce_achievements.txt in the game folder at once (the file whole, under - another name first), said in the log, and shown: the menu's notice (HOS_OPT_ACH_EARNED) with the system menu's + another name first; while the save files are on, host/save_files.c, in the folder of the file played, so that each + file has what it earned and no other's: earned_file), said in the log, and shown: the menu's notice (HOS_OPT_ACH_EARNED) with the system menu's decide sound (HOS_MENU_SOUND_SYS_DECIDE, at the Menu sounds row's volume; silent where that row is Off. Not the item fanfare: most are earned as the game plays that itself). One at a time: a save that earns several at once shows them one after the other. @@ -30,6 +35,7 @@ int rx_option(int id, int otherwise); void rx_option_set(int id, int value); +const char *hos_save_files_dir(int *first); /* host/save_files.c */ #define EARNED_FILE "triforce_achievements.txt" #define OWN_FILE "achievements.txt" @@ -60,10 +66,20 @@ static int game_file(char *out, size_t cap, const char *name) { return snprintf(out, cap, "%.*s%s", (int)(slash + 1 - exe), exe, name) < (int)cap; } -/* a text file of the game folder whole, its end a 0 (freed by the caller); NULL when it is not there or over `most` */ -static char *read_text(const char *name, long most) { - char path[MAX_PATH + 40]; - if (!game_file(path, sizeof path, name)) return NULL; +/* ((Triforce) 11-23, his "I don't want achievements to carry across" the save files.) Where the earned ones are kept: the + game folder's triforce_achievements.txt, or, while the save files are on, the one in the folder of the file this run + plays. *inherits: that file is File 1 and may start from the game folder's, which is what it earned before there were + files (read only: the game folder's is left as it is) */ +static int earned_file(char *out, size_t cap, int *inherits) { + int first = 0; + const char *dir = hos_save_files_dir(&first); + *inherits = dir && first; + if (!dir) return game_file(out, cap, EARNED_FILE); + return snprintf(out, cap, "%s%c" EARNED_FILE, dir, strchr(dir, '\\') ? '\\' : '/') < (int)cap; +} + +/* a text file whole, its end a 0 (freed by the caller); NULL when it is not there or over `most` */ +static char *read_text(const char *path, long most) { FILE *f = fopen(path, "rb"); if (!f) return NULL; char *text = NULL; @@ -80,9 +96,10 @@ static char *read_text(const char *name, long most) { static void earned_save(void) { static char text[ACH_MAX * (ACH_NAME + 40) + ACH_ORPHANS * ACH_LINE + 200]; - char path[MAX_PATH + 40], fresh[MAX_PATH + 48]; + char path[MAX_PATH + 160], fresh[MAX_PATH + 168]; + int inherits; const size_t n = ach_earned_write(&list, text, sizeof text); - if (!n || !game_file(path, sizeof path, EARNED_FILE)) return; + if (!n || !earned_file(path, sizeof path, &inherits)) return; snprintf(fresh, sizeof fresh, "%s.new", path); FILE *f = fopen(fresh, "wb"); /* (its lines end the same on Windows and Linux) */ const int ok = f && fwrite(text, 1, n, f) == n; @@ -95,10 +112,13 @@ static void earned_save(void) { static void lists_read(void) { int refused = 0; const int built_in = ach_parse(&list, ACH_BUILTIN, &refused); - char *own = read_text(OWN_FILE, OWN_MOST); + char path[MAX_PATH + 160]; + int inherits = 0; + char *own = game_file(path, sizeof path, OWN_FILE) ? read_text(path, OWN_MOST) : NULL; const int own_n = own ? ach_parse(&list, own, &refused) : 0; free(own); - char *earned = read_text(EARNED_FILE, OWN_MOST); + char *earned = earned_file(path, sizeof path, &inherits) ? read_text(path, OWN_MOST) : NULL; + if (!earned && inherits && game_file(path, sizeof path, EARNED_FILE)) earned = read_text(path, OWN_MOST); const int marked = earned ? ach_earned_read(&list, earned) : 0; free(earned); hos_log("achievements: %d (%d of " OWN_FILE "%s), %d earned so far%s", list.n, own_n, own ? "" : ", which is not there", marked, @@ -152,7 +172,8 @@ void hos_achievements_frame(void) { /* host/hos_main.c, once a second at Link's update while a save is loaded (now_ns: hos_now_ns): what the save data has earned since the last call is marked, kept and shown */ void hos_achievements_check(AchProbe probe, void *ctx, int64_t now_ns) { - if (!hos_achievements_on()) return; + if (!hos_achievements_on() || !rx_option(HOS_OPT_ACH_ON, 1)) return; + const int quiet = !rx_option(HOS_OPT_ACH_NOTICES, 1); lock(); if (!ready) ready = 1, lists_read(); int fresh[ACH_MAX]; @@ -162,15 +183,15 @@ void hos_achievements_check(AchProbe probe, void *ctx, int64_t now_ns) { if (nwaiting < ACH_MAX) waiting[nwaiting++] = fresh[i]; } if (got) earned_save(); - if (nwaiting && named && now_ns >= next_shown) { /* (not before the menu has the list: it shows them by their place in it) */ + if (nwaiting && named && (quiet || now_ns >= next_shown)) { /* (not before the menu has the list: it shows them by their place in it) */ const int at = waiting[0]; char day[16]; memmove(waiting, waiting + 1, sizeof waiting[0] * (size_t)--nwaiting); - next_shown = now_ns + SHOWN_MS * 1000000LL; + next_shown = quiet ? now_ns : now_ns + SHOWN_MS * 1000000LL; /* (no notice shown: the next need not wait for it) */ day_of(list.a[at].when, day, sizeof day); to_menu(day); rx_option_set(HOS_OPT_ACH_EARNED, at); - hos_menu_sound_play(HOS_MENU_SOUND_SYS_DECIDE, now_ns); + if (!quiet) hos_menu_sound_play(HOS_MENU_SOUND_SYS_DECIDE, now_ns); } unlock(); } diff --git a/host/achievements.h b/host/achievements.h index 63d012a..2b1b7ed 100644 --- a/host/achievements.h +++ b/host/achievements.h @@ -86,7 +86,19 @@ typedef int (*AchProbe)(void *ctx, int kind, const char *what); "[A Giant's Blade]\nabout: Earn Biggoron's Sword.\nicon: sword\nitem Weapon_Sword_Biggoron\n" \ "[Deep Pockets]\nabout: Carry the Giant's Wallet.\nicon: token green\nitem Item_Wallet_Large\n" \ "[Light Against the Dark]\nabout: Receive the Light Arrow.\nicon: star yellow\nitem Item_Arrow_Light\n" \ - "[Twice as Tough]\nabout: Receive Double Defense.\nicon: shield silver\nitem Item_FairyBless_DefenseDouble\n" + "[Twice as Tough]\nabout: Receive Double Defense.\nicon: shield silver\nitem Item_FairyBless_DefenseDouble\n" \ + "[Honorary Thief]\nabout: Be handed the Gerudo's Card.\nicon: star red\nitem Item_Token_Gerudo\n" \ + "[Read the Fine Print]\nabout: Buy a blade that will not last.\nicon: sword silver\nitem Weapon_Sword_Giant\n" \ + "[Something's Buzzing]\nabout: Receive the Stone of Agony.\nicon: gem silver\nitem Item_AgonyStone\n" \ + "[Fashion Victim]\nabout: Own both tunics and both pairs of boots.\nicon: shield red\nitem Armor_Adult_Goron\nitem Armor_Adult_Zora\n" \ + "item Armor_Adult_HeavyBoot\nitem Armor_Adult_HoverBoot\n" \ + "[Jack]\nabout: Carry 10 Magic Beans at once.\nicon: star green\nitem Item_MagicBean 10\n" \ + "[Going Nuts]\nabout: Carry 40 Deku Nuts.\nicon: star orange\nitem Item_DekuNut 40\n" \ + "[Demolition Permit]\nabout: Carry 40 Bombs and 50 Bombchus.\nicon: shield orange\nitem Item_Bomb 40\nitem Item_Bombchu 50\n" \ + "[Three Goddesses]\nabout: Receive Din's Fire, Farore's Wind and Nayru's Love.\nicon: gem yellow\nitem Item_DinFire\n" \ + "item Item_FaroreWind\nitem Item_NayruLove\n" \ + "[Rain Dance]\nabout: Learn the Song of Storms.\nicon: note blue\nitem Item_Melody_StormSong\n" \ + "[Deep End]\nabout: Earn the Golden Scale.\nicon: shield blue\nitem Item_Scale_Gold\n" /* FNV-1a 32 of a name's bytes */ static inline uint32_t ach_key(const char *name) { diff --git a/host/display.c b/host/display.c index 1ab61c1..5982eb6 100644 --- a/host/display.c +++ b/host/display.c @@ -19,6 +19,7 @@ #include "../gpu/render/rx.h" void rx_close_asked(void); /* host/rx_backend.c */ #include "../gpu/vk/vk_api.h" +#include "hos_screens.h" /* ((Triforce) the connected screens, for the Output resolution) */ void hos_relaunch_ask(void); /* (host/hos_relaunch.c) */ void hos_bug_capture_key(void); /* (host/bug_capture.c) */ @@ -111,6 +112,86 @@ static void set_fullscreen(HWND w, int on) { hos_log("display: %s", on ? "fullscreen" : "windowed"); } +/* (Triforce) The monitor the game's window opens on, asked before there is a window (the game takes its output size + first). The window is made at CW_USEDEFAULT: Windows puts it on the monitor the shell started the game from when it names + one (a taskbar or a shortcut on another monitor: STARTUPINFO's hStdOutput is that monitor's handle unless it is a + standard handle), else on the main monitor: NULL here. */ +static HMONITOR shell_monitor(void) { + STARTUPINFOW si; + MONITORINFO mi; + memset(&si, 0, sizeof si); + si.cb = sizeof si; + GetStartupInfoW(&si); + mi.cbSize = sizeof mi; + if (!(si.dwFlags & STARTF_USESTDHANDLES) && si.hStdOutput && GetMonitorInfoA((HMONITOR)si.hStdOutput, &mi)) + return (HMONITOR)si.hStdOutput; + return NULL; +} +/* Its size in pixels (the process is DPI aware by then, host/hos_main.c), 0 x 0 when the system does not say. A window moved + to another monitor later keeps the picture it started with: the game makes its render targets once, and the present fits + the picture into whatever the window is (gpu/vk/vk_present_rect.h). */ +void hos_screen_size(int *w, int *h) { + const HMONITOR shell = shell_monitor(); + MONITORINFO mi; + mi.cbSize = sizeof mi; + if (shell && GetMonitorInfoA(shell, &mi)) { + *w = (int)(mi.rcMonitor.right - mi.rcMonitor.left), *h = (int)(mi.rcMonitor.bottom - mi.rcMonitor.top); + return; + } + *w = GetSystemMetrics(SM_CXSCREEN), *h = GetSystemMetrics(SM_CYSCREEN); +} +/* A monitor's own name ("LG ULTRAGEAR": its EDID's, through the display configuration) by its GDI device ("\\.\DISPLAY1"), + UTF-8; "" where there is none (a laptop's panel, a remote session) */ +static void screen_name(const char *device, char *out, int cap) { + UINT32 np = 0, nm = 0; + out[0] = 0; + if (GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &np, &nm) != ERROR_SUCCESS || !np) return; + DISPLAYCONFIG_PATH_INFO *paths = (DISPLAYCONFIG_PATH_INFO *)calloc(np, sizeof *paths); + DISPLAYCONFIG_MODE_INFO *modes = (DISPLAYCONFIG_MODE_INFO *)calloc(nm ? nm : 1, sizeof *modes); + if (paths && modes && QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &np, paths, &nm, modes, NULL) == ERROR_SUCCESS) { + for (UINT32 i = 0; i < np && !out[0]; i++) { + DISPLAYCONFIG_SOURCE_DEVICE_NAME src; + DISPLAYCONFIG_TARGET_DEVICE_NAME tgt; + char gdi[64]; + memset(&src, 0, sizeof src); + src.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, src.header.size = sizeof src; + src.header.adapterId = paths[i].sourceInfo.adapterId, src.header.id = paths[i].sourceInfo.id; + if (DisplayConfigGetDeviceInfo(&src.header) != ERROR_SUCCESS) continue; + if (!WideCharToMultiByte(CP_UTF8, 0, src.viewGdiDeviceName, -1, gdi, sizeof gdi, NULL, NULL) || strcmp(gdi, device)) continue; + memset(&tgt, 0, sizeof tgt); + tgt.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME, tgt.header.size = sizeof tgt; + tgt.header.adapterId = paths[i].targetInfo.adapterId, tgt.header.id = paths[i].targetInfo.id; + if (DisplayConfigGetDeviceInfo(&tgt.header) != ERROR_SUCCESS || !tgt.flags.friendlyNameFromEdid) break; + if (!WideCharToMultiByte(CP_UTF8, 0, tgt.monitorFriendlyDeviceName, -1, out, cap, NULL, NULL)) out[0] = 0; + } + } + free(paths), free(modes); +} +struct screen_list { + HosScreen *out; + int cap, n; + HMONITOR shell; +}; +static BOOL CALLBACK screen_each(HMONITOR m, HDC dc, LPRECT rect, LPARAM param) { + struct screen_list *l = (struct screen_list *)param; + MONITORINFOEXA mi; + (void)dc, (void)rect; + mi.cbSize = sizeof mi; + if (l->n >= l->cap || !GetMonitorInfoA(m, (MONITORINFO *)&mi)) return TRUE; + HosScreen *s = &l->out[l->n++]; + memset(s, 0, sizeof *s); + s->w = (int)(mi.rcMonitor.right - mi.rcMonitor.left), s->h = (int)(mi.rcMonitor.bottom - mi.rcMonitor.top); + s->opens = l->shell ? m == l->shell : (mi.dwFlags & MONITORINFOF_PRIMARY) != 0; + screen_name(mi.szDevice, s->name, (int)sizeof s->name); + return TRUE; +} +/* (host/hos_screens.h) Every connected monitor: its size in pixels, its name, and which one the window opens on */ +int hos_screens(HosScreen *out, int cap) { + struct screen_list l = {out, cap, 0, shell_monitor()}; + EnumDisplayMonitors(NULL, NULL, screen_each, (LPARAM)&l); + return l.n; +} + static void dpi_aware_thread(void) { if (getenv("HOS_DPI_UNAWARE")) return; typedef void *(WINAPI * SetCtx)(void *); @@ -481,7 +562,7 @@ static DWORD WINAPI display_main(void *p) { RegisterClassA(&wc); dpi_aware_thread(); extern float hos_aspect_ratio; - /* (the picture's shape when Monitor's shape set one, wider or narrower than 16:9: 960 x 720 for 4:3, 1720 x 720 for 21:9) */ + /* (the picture's shape when it is not 16:9, the Output resolution's own or the Ultrawide row's: 960 x 720 for 4:3, 1728 x 720 for 3840 x 1600) */ int win_w = hos_aspect_ratio > 0.0f ? (int)(720 * hos_aspect_ratio + 0.5f) : 1280, win_h = 720; if (getenv("HOS_WINDOW_SIZE")) { int w = 0, h = 0; diff --git a/host/hos_bench.c b/host/hos_bench.c index 468a8b9..732c16f 100644 --- a/host/hos_bench.c +++ b/host/hos_bench.c @@ -20,7 +20,14 @@ renderer told), so the caches are written. Esc (the window in front) or the window closed by the launcher: written with "stopped": true. 4. No save is written while it runs (host/nn_fs.c Commit), the hearts are protected (host/hos_main.c), and the player's - devices do not count (host/nn_hid.c): the benchmark's presses count with the window behind other windows. */ + devices do not count (host/nn_hid.c): the benchmark's presses count with the window behind other windows. + 5. ((Triforce) 11-22) The helper-thread test (HOS_BENCH_HELPERS=1, the launcher's "Start with the helper-thread test"): + each scene is measured twice in a row, its HOS_BENCH_SECONDS with the replay helper threads off and as long with them + on (gpu/vk/vk_replay.cpp par_forced, through HOS_OPT_HELPERS_FORCE: the tuner out of the way), each after its own 1.5 s + of settling. The order turns from scene to scene (off first in the first, third, ...; on first in the second, ...), so + that warming up and a scene that changes favour neither. The scene's own figures are the "off" half's; "helpers" has + both halves, and "helper_test" the threads the test used (0: it could not run, the row's Off or a PC Automatic gives + none; each scene then measured once, the helpers as the options have them). */ #include "hos.h" #include "hos_paths.h" #include "hos_bench.h" @@ -39,6 +46,7 @@ void hos_hid_tap(const char *press); /* host/nn_h void hos_hid_stick(int lx, int ly, int rx, int ry, int hold_ms); const char *rx_describe(void); /* host/rx_backend.c */ int rx_option(int id, int otherwise); +void rx_option_set(int id, int value); void hos_window_close(void); /* host/display.c, host/posix/display_sdl.c */ extern const char *hos_user_dir; /* host/nn_fs.c */ @@ -52,12 +60,20 @@ extern const char *hos_user_dir; /* host/nn_f #define HIST_BINS 2000 /* (the scene's frame times so far, 0.1 ms each up to 200 ms: the panel's 1% low) */ typedef struct { int action; char name[48]; } Scene; +/* ((Triforce) 11-22) one half of the helper-thread test's scene: its figures as a scene's */ +typedef struct { + int frames, npoints; + double seconds, avg, low1, low01, max_ms; + float points[GRAPH_POINTS]; +} Half; typedef struct { int frames; double seconds, avg, low1, low01, max_ms; float points[GRAPH_POINTS]; int npoints; int scene; /* ((Triforce, 11-19) the scene it measured: a scene skipped before it shifts no name */ + int tested, on_first; /* ((Triforce) 11-22) the helper-thread test: measured both ways, and in which order */ + Half way[2]; /* (0 off, 1 on) */ } Result; typedef struct { uint64_t screen, vt; int stage, presses, focus_asks; int64_t press_ns, ask_ns; } Screen; @@ -90,6 +106,10 @@ static struct { char error[160]; int written, closing; int64_t end_ns; + /* ((Triforce) 11-22) the helper-thread test: asked for, the threads it uses (-1 not asked of the renderer yet, 0 none), + the scene's half being measured (0, 1), the way it holds (0 off, 1 on), and the halves measured so far */ + int helpers, helper_threads, half, way, way_set; + Half halves[2]; } B = {SRWLOCK_INIT}; int hos_bench_on(void) { return B.on; } @@ -133,6 +153,9 @@ void hos_bench_init(void) { parse_scenes(scenes && *scenes ? scenes : "1001:Hyrule Field,1003:Castle Town Market,1000:Kokiri Forest,1007:Lake Hylia"); if (!B.nscenes) parse_scenes("1001:Hyrule Field"); B.slot = B.newest = -1; + const char *helpers = getenv("HOS_BENCH_HELPERS"); + B.helpers = helpers && atoi(helpers) != 0; + B.helper_threads = -1; B.t_start = hos_now_ns(); B.phase = MKWVK_BENCH_BOOT; B.on = 1; @@ -254,11 +277,9 @@ static int64_t rank_of(const int64_t *v, int n, double q) { if (r > n) r = n; return v[r - 1]; } -static void scene_done(void) { /* (under the lock) */ - if (B.nresults >= MAX_SCENES) return; - Result *r = &B.results[B.nresults++]; +/* the measured intervals' figures (under the lock; sorts B.iv) */ +static void stats_of(Half *r) { memset(r, 0, sizeof *r); - r->scene = B.scene; r->frames = B.n; int64_t sum = 0; for (int i = 0; i < B.n; i++) sum += B.iv[i]; @@ -283,9 +304,34 @@ static void scene_done(void) { /* (under the lock) */ r->low1 = r->low01 = -1; } } - hos_log("benchmark: scene %d of %d, %s: %.1f fps average, 1%% low %.1f, 0.1%% low %.1f, %d frames in %.2f s", B.nresults, - B.nscenes, B.scenes[r->scene].name, r->avg, r->low1, r->low01, r->frames, r->seconds); } +static int helper_test(void) { return B.helpers && B.helper_threads >= 2; } +static void scene_done(void) { /* (under the lock) */ + if (B.nresults >= MAX_SCENES) return; + Result *r = &B.results[B.nresults++]; + memset(r, 0, sizeof *r); + r->scene = B.scene; + Half own; + if (helper_test()) { /* (both halves measured: the scene's own figures are the "off" half's) */ + r->tested = 1, r->on_first = B.way == 0; /* (the way held now is the second half's) */ + r->way[0] = B.halves[0], r->way[1] = B.halves[1]; + own = B.halves[0]; + } else { + stats_of(&own); + } + r->frames = own.frames, r->seconds = own.seconds, r->avg = own.avg, r->low1 = own.low1, r->low01 = own.low01; + r->max_ms = own.max_ms, r->npoints = own.npoints; + memcpy(r->points, own.points, sizeof r->points); + hos_log("benchmark: scene %d of %d, %s: %.1f fps average, 1%% low %.1f, 0.1%% low %.1f, %d frames in %.2f s%s", B.nresults, + B.nscenes, B.scenes[r->scene].name, r->avg, r->low1, r->low01, r->frames, r->seconds, + r->tested ? " (the helper threads off)" : ""); + if (r->tested) + hos_log("benchmark: scene %d of %d, %s, the helper threads on: %.1f fps average, 1%% low %.1f, 0.1%% low %.1f, %d " + "frames in %.2f s; off %.1f (measured %s)", B.nresults, B.nscenes, B.scenes[r->scene].name, r->way[1].avg, + r->way[1].low1, r->way[1].low01, r->way[1].frames, r->way[1].seconds, r->way[0].avg, r->on_first ? "second" : "first"); +} +/* ((Triforce) 11-22) a half's figures, as the scene's in the results */ +static void json_half(FILE *f, const Half *h); static void json_text(FILE *f, const char *s) { fputc('"', f); for (; s && *s; s++) { @@ -361,11 +407,21 @@ static void write_results(int stopped) { /* (under the lock; once) */ fprintf(f, ",\"avg\":%.2f,\"low1\":%.2f,\"low01\":%.2f,\"frames\":%d,\"seconds\":%.3f,\"max_ms\":%.2f,\"frametimes_ms\":[", bench_finite(r->avg), bench_finite(r->low1), bench_finite(r->low01), r->frames, bench_finite(r->seconds), bench_finite(r->max_ms)); for (int p = 0; p < r->npoints; p++) fprintf(f, "%s%.2f", p ? "," : "", bench_finite(r->points[p])); - fprintf(f, "]}"); + fprintf(f, "]"); + if (r->tested) { /* ((Triforce) 11-22) the helper-thread test's two halves */ + fprintf(f, ",\"helpers\":{\"first\":\"%s\",\"off\":", r->on_first ? "on" : "off"); + json_half(f, &r->way[0]); + fprintf(f, ",\"on\":"); + json_half(f, &r->way[1]); + fprintf(f, "}"); + } + fprintf(f, "}"); } fprintf(f, "],\"skipped\":["); for (int i = 0; i < B.nskipped; i++) fprintf(f, "%s", i ? "," : ""), json_text(f, B.scenes[B.skipped[i]].name); - fprintf(f, "],\"settings\":"); + fprintf(f, "]"); + if (B.helpers) fprintf(f, ",\"helper_test\":{\"threads\":%d}", B.helper_threads > 0 ? B.helper_threads : 0); + fprintf(f, ",\"settings\":"); json_settings(f); fprintf(f, "}\n"); const int ok = fflush(f) == 0; @@ -377,6 +433,12 @@ static void write_results(int stopped) { /* (under the lock; once) */ hos_log("benchmark: the results could not be moved to %s", B.path); hos_log_flush(); } +static void json_half(FILE *f, const Half *h) { + fprintf(f, "{\"avg\":%.2f,\"low1\":%.2f,\"low01\":%.2f,\"frames\":%d,\"seconds\":%.3f,\"max_ms\":%.2f,\"frametimes_ms\":[", + bench_finite(h->avg), bench_finite(h->low1), bench_finite(h->low01), h->frames, bench_finite(h->seconds), bench_finite(h->max_ms)); + for (int p = 0; p < h->npoints; p++) fprintf(f, "%s%.2f", p ? "," : "", bench_finite(h->points[p])); + fprintf(f, "]}"); +} static void fail(int64_t now, const char *why) { /* (under the lock) */ if (B.phase >= MKWVK_BENCH_DONE) return; snprintf(B.error, sizeof B.error, "%s", why); @@ -485,6 +547,7 @@ int hos_bench_link_wants_state(void) { } static void go_scene(int64_t now) { /* (under the lock) the next scene's teleport */ B.phase = MKWVK_BENCH_TRAVEL, B.t_phase = now; + B.half = 0, B.way_set = 0; /* ((Triforce) 11-22: the helper-thread test's halves begin again) */ B.want = 1, B.tries = 0, B.resends = 0, B.saw_load = 0, B.retry_ns = 0, B.sent_ns = 0; hos_log("benchmark: going to %s (scene %d of %d)", B.scenes[B.scene].name, B.scene + 1, B.nscenes); } @@ -569,6 +632,18 @@ void hos_bench_present(int64_t now) { break; case MKWVK_BENCH_SETTLE: hos_hid_stick(0, 0, PAN, 0, 250); + if (B.helpers && B.helper_threads < 0) { /* ((Triforce) 11-22) the helper-thread test: what it can use, asked once */ + B.helper_threads = rx_option(HOS_OPT_HELPERS_FORCE, 0); + if (helper_test()) + hos_log("benchmark: the helper-thread test: each scene with %d helper threads off and on", B.helper_threads); + else + hos_log("benchmark: the helper-thread test cannot run here: no helper threads (the Debug tab's row Off, " + "RX_VK_PARALLEL, or a PC Automatic gives none); each scene measured once"); + } + if (helper_test() && !B.way_set) { /* (the scene's first half: off first in the first scene, on first in the next) */ + B.way = B.scene % 2, B.way_set = 1, B.t_phase = now; + rx_option_set(HOS_OPT_HELPERS_FORCE, B.way); + } if (now - B.t_phase >= SETTLE_NS) { B.phase = MKWVK_BENCH_MEASURE, B.measure_t0 = now, B.n = 0; memset(B.hist, 0, sizeof B.hist); @@ -587,6 +662,17 @@ void hos_bench_present(int64_t now) { B.hist[bin < HIST_BINS ? bin : HIST_BINS]++; } if (now - B.measure_t0 >= (int64_t)(B.seconds * 1e9)) { + if (helper_test()) { /* ((Triforce) 11-22) a half measured: the other way next, after its own settling */ + stats_of(&B.halves[B.way]); + hos_log("benchmark: %s, the helper threads %s: %.1f fps average over %d frames", B.scenes[B.scene].name, + B.way ? "on" : "off", B.halves[B.way].avg, B.halves[B.way].frames); + if (B.half == 0) { + B.half = 1, B.way ^= 1; + rx_option_set(HOS_OPT_HELPERS_FORCE, B.way); + B.phase = MKWVK_BENCH_SETTLE, B.t_phase = now; + break; + } + } scene_done(); if (++B.scene >= B.nscenes) { B.phase = MKWVK_BENCH_DONE, B.end_ns = now; @@ -607,6 +693,10 @@ void hos_bench_present(int64_t now) { if (w) GetWindowThreadProcessId(w, &pid); if (pid == GetCurrentProcessId()) stop(now, "Esc pressed"); } + if (helper_test() && B.phase >= MKWVK_BENCH_DONE && B.way_set >= 0) { /* ((Triforce) 11-22: the tuner decides again) */ + rx_option_set(HOS_OPT_HELPERS_FORCE, -1); + B.way_set = -1; + } ReleaseSRWLockExclusive(&B.lock); if (close) { hos_log("benchmark: the game quits"); @@ -631,10 +721,13 @@ int hos_bench_state(MkwVkBench *out) { const int sc = B.scene < B.nscenes ? B.scene : B.nscenes - 1; out->scene = B.phase == MKWVK_BENCH_BOOT ? 0 : sc + 1; snprintf(out->name, sizeof out->name, "%s", B.phase == MKWVK_BENCH_BOOT ? "" : B.scenes[sc].name); + if (helper_test() && B.way_set > 0 && (B.phase == MKWVK_BENCH_SETTLE || B.phase == MKWVK_BENCH_MEASURE)) + snprintf(out->name, sizeof out->name, "%.30s, helpers %s", B.scenes[sc].name, B.way ? "on" : "off"); const int64_t now = hos_now_ns(); double frac = 0; if (B.phase == MKWVK_BENCH_MEASURE) frac = (now - B.measure_t0) / (B.seconds * 1e9); if (frac > 1) frac = 1; + if (helper_test()) frac = (B.half + frac) / 2; /* ((Triforce) 11-22: a scene is two halves) */ out->progress = B.phase >= MKWVK_BENCH_DONE && B.phase != MKWVK_BENCH_DONE ? (float)B.nresults / B.nscenes : B.phase == MKWVK_BENCH_DONE ? 1.0f : B.phase == MKWVK_BENCH_BOOT ? 0.0f : (float)((sc + frac) / B.nscenes); if (B.phase == MKWVK_BENCH_FAILED) snprintf(out->line, sizeof out->line, "%s", B.error); diff --git a/host/hos_l3_home.h b/host/hos_l3_home.h new file mode 100644 index 0000000..4a51b80 --- /dev/null +++ b/host/hos_l3_home.h @@ -0,0 +1,104 @@ +/* (Triforce, 11-23) One L3 cache for the frame's two hot threads, on a processor with two or more L3 caches of the same size: AMD's + two-die Ryzen 9 parts (a 5900X or 5950X, a 7900X or 7950X, a 9900X or 9950X), each die of six or eight cores with an L3 + of its own. The replay reads what the game's main thread has just written (its command buffers, the uniforms and + vertices it filled), and on those parts the core kept for the replay was the processor's last, on the second die, while + Windows ran the main thread mostly on the first, where its preferred cores are: every line the replay read crossed + from one die's L3 to the other's over the fabric (an RX 6700 XT with a 5900X, 11-22: 12 ms of replay a frame in play). + + Here the die of the lowest logical processor the process may use (the first die, where Windows' preferred cores are) + is the home: the core kept for the replay is its last core (host/hos_thread.c last_fastest_core), and the game's main + thread and its presenting thread (where the replay runs) are kept on its other cores (hos_thread_pin). The game's other + threads, the renderer's helper and recorder threads and the driver's stay where Windows puts them, on both dies: NX2navi + measured that the game held to six cores loses more than the shared cache gives (host/hos_x3d.h), and only the two + threads that hand the frame over are held here. + + Nothing is done: + - with one L3 (a 5600X, a 5800X3D, a 7800X3D, an Intel processor of either kind); + - with L3 caches of different sizes: a two-die X3D part, which host/hos_x3d.h handles; + - where the home has fewer than HOS_L3_HOME_MIN_CORES cores the process may use (a 3900X's three-core CCXs, a 7900X3D's + six-core die has no home here as its caches differ): the main thread would be left fewer than five cores beside the + replay's; + - with more than one processor group, or a list that puts a processor under two L3 caches. + HOS_L3_HOME=0 turns it off. Plain code over the caches and cores the system lists: tests/test_l3_home.py runs it on + authored topologies. */ +#ifndef HOS_L3_HOME_H +#define HOS_L3_HOME_H +#include +#include + +#include "hos_x3d.h" /* (HosCache) */ + +enum { + HOS_L3_HOME_NONE, /* no L3 listed, or a list that contradicts itself */ + HOS_L3_HOME_GROUPS, /* more than one processor group */ + HOS_L3_HOME_ONE, /* one L3 among the processors the process may use */ + HOS_L3_HOME_MIXED, /* L3 caches of different sizes (host/hos_x3d.h) */ + HOS_L3_HOME_FEW, /* the home has fewer than HOS_L3_HOME_MIN_CORES cores */ + HOS_L3_HOME_USED /* the home: the processors to keep the two threads and the replay's core on */ +}; +#define HOS_L3_HOME_MIN_CORES 6 + +typedef struct { + int why; /* HOS_L3_HOME_* */ + uint64_t home; /* the allowed logical processors under the home's L3 (FEW, USED) */ + uint64_t bytes; /* each L3's size */ + int cores; /* the cores in home */ + int domains; /* the L3 caches with a processor the process may use */ +} HosL3Home; + +/* caches: every cache listed (the L3 ones are looked at); cores: each core's logical processors; allowed: the process's + affinity; groups: the active processor groups. The home's mask when it is used (HOS_L3_HOME_USED), else 0 */ +static inline uint64_t hos_l3_home_pick(const HosCache *caches, int ncaches, const uint64_t *cores, int ncores, + uint64_t allowed, int groups, HosL3Home *out) { + HosL3Home h = {HOS_L3_HOME_NONE, 0, 0, 0, 0}; + *out = h; + if (groups != 1) { + out->why = HOS_L3_HOME_GROUPS; + return 0; + } + uint64_t seen = 0, first = 0; + for (int i = 0; i < ncaches; i++) { + const uint64_t m = caches[i].mask & allowed; + if (caches[i].level != 3 || !m || !caches[i].bytes) continue; + if (seen & m) return 0; /* (a processor under two L3 caches: not a list to act on) */ + seen |= m; + if (!h.bytes) h.bytes = caches[i].bytes; + else if (caches[i].bytes != h.bytes) h.why = HOS_L3_HOME_MIXED; + h.domains++; + if (m & (allowed & (0 - allowed))) first = m; /* (the L3 of the lowest allowed logical processor) */ + } + out->bytes = h.bytes, out->domains = h.domains; + if (!h.domains) return 0; + if (h.domains < 2) { + out->why = HOS_L3_HOME_ONE; + return 0; + } + if (h.why == HOS_L3_HOME_MIXED || !first) { + out->why = h.why == HOS_L3_HOME_MIXED ? HOS_L3_HOME_MIXED : HOS_L3_HOME_NONE; + return 0; + } + for (int i = 0; i < ncores; i++) + if (cores[i] & first) h.cores++; + out->home = first, out->cores = h.cores; + if (h.cores < HOS_L3_HOME_MIN_CORES) { + out->why = HOS_L3_HOME_FEW; + return 0; + } + out->why = HOS_L3_HOME_USED; + return first; +} + +/* The two threads that hand the frame over: the game's main thread (named MainThread at the boot, sead::MainThread once + the game names it) and its presenting thread, where the replay runs (gpu/vk/vk_replay.cpp ReplayPin pins it to the + kept core while it replays and gives back this affinity after) */ +static inline int hos_l3_home_thread(const char *name) { + return name && (!strcmp(name, "sead::MainThread") || !strcmp(name, "MainThread") || !strcmp(name, "Presentation Thread")); +} + +/* Their affinity, 0 for none set: the home's processors the process may use, without the core kept for the replay; none + where that leaves nothing */ +static inline uint64_t hos_l3_home_thread_mask(uint64_t process, uint64_t home, uint64_t reserved) { + const uint64_t m = process & home & ~reserved; + return home ? m : 0; +} +#endif diff --git a/host/hos_main.c b/host/hos_main.c index 29e076d..a6f3211 100644 --- a/host/hos_main.c +++ b/host/hos_main.c @@ -16,7 +16,9 @@ #include "../gpu/vk/oot_cheat_items.h" #include "../gpu/vk/oot_debug_link.h" /* ((Triforce) the Game flags and Cutscenes pages' lines) */ #include "achievements.h" /* ((Triforce) what an achievement asks of the save data: host/achievements.c) */ +#include "save_files.h" /* ((Triforce) the title's file select: host/save_files.c) */ #include "../gpu/vk/ultrawide_rows.h" /* ((Triforce) the Ultrawide row's shapes: ultrawide_ratio) */ +#include "../gpu/vk/output_sizes.h" /* ((Triforce) the picture for the Output resolution and a shape: output_picture) */ #include #include #include @@ -417,6 +419,10 @@ static int env_line_allowed(const char *name, const char *value) { if (!strncmp(name, "SDL_", 4) && (strstr(name, "_LIB") || strstr(name, "GL_DRIVER"))) return 0; for (const char *p = name; *p; p++) if (!((*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_')) return 0; + /* ((Triforce, 11-23) HOS_LOG_FILE is a switch, not a file's name: 1, the log into triforce_log.txt whatever stderr is, so + a player whose game is started from a terminal, Steam or a script can have the log file; the file is always the one + beside the game) */ + if (!strcmp(name, "HOS_LOG_FILE")) return (value[0] == '0' || value[0] == '1') && !value[1]; /* (hookshot) the switches that name a file to write or a folder take no value here, not even a bare name: one resolves in the game's folder (HOS_SAMPLE_FILE=triforce_vk.dll emptied the renderer) */ const size_t nl = strlen(name); @@ -1204,6 +1210,49 @@ static void oot_teleport_followup(Ctx *c) { events && recomp_load64(c, events + 104) ? 1 : 0); } +/* ---- (Triforce) A save file's card on the file select (host/save_files.c, on unless HOS_SAVE_FILES=0): what the game's own + load list shows of a save, told from the running game and not read out of the save. Every two seconds at Link's update, + while a save is loaded: the map he is on (Sequence_CurrentBanc, as the teleport reads it), which Spiritual Stones and + medallions he holds (their Pouch names are gpu/vk/oot_cheat_items.h's), and the game's count of his life. Nothing is + written into the game. + His life: the Int of GameData that holds his most life, in quarters of a heart. Its name is not known to this + repository, and none of the game's is taken from its files: the names below are the ones games of this engine have used, + tried once a run, the first the save data has taken, and the log says which (or that none is: the card has no hearts + then) */ +static int oot_max_life(Ctx *c) { + static const char *const names[] = {"PlayerStatus.MaxLife", "MaxLife", "Player.MaxLife", "PlayerStatus.MaxHeart", "MaxHeart"}; + static uint32_t hash; + static int tried; + const uint64_t mgr = oot_singleton(c, OOT_GAMEDATA_SLOT); + if (!mgr) return 0; + if (!tried) { + tried = 1; + for (unsigned i = 0; i < sizeof names / sizeof names[0] && !hash; i++) { + const uint64_t entry = oot_gd_int(c, mgr, oot_murmur3(names[i])); + if (!entry) continue; + hash = oot_murmur3(names[i]); + hos_log("save files: the card's hearts: the save data's %s is %d", names[i], (int)recomp_load32(c, entry + 0x1c)); + } + if (!hash) hos_log("save files: the card's hearts: the save data has none of the names tried for Link's life: no hearts on the cards"); + } + const uint64_t entry = hash ? oot_gd_int(c, mgr, hash) : 0; + return entry ? (int)recomp_load32(c, entry + 0x1c) : 0; +} +static void oot_save_card_tick(Ctx *c, int64_t now) { + static const char *const held[SAVE_CARD_ITEMS] = {"Item_Stone_Forest", "Item_Stone_Fire", "Item_Stone_Water", "Item_Medal_Light", "Item_Medal_Forest", + "Item_Medal_Fire", "Item_Medal_Water", "Item_Medal_Spirit", "Item_Medal_Shadow"}; + static int64_t next; + if (!hos_save_files_on() || now < next) return; + next = now + 2000000000LL; + if (oot_pouch_count(c, oot_item_names[0]) < 0) return; /* (no save loaded: GameData holds a new game's values) */ + char map[64]; + int items = 0; + oot_gamedata_string(c, 0x1d6189dau, map, sizeof map); /* Sequence_CurrentBanc */ + for (int i = 0; i < SAVE_CARD_ITEMS; i++) + if (oot_item_get(c, held[i]) > 0) items |= 1 << i; + hos_save_card_note(map, items, oot_max_life(c), now); +} + /* ---- (Triforce) Game flags by name and events by name: the Debug tab's two pages ---- After NX2navi's F9 panel (its flags by name and its cutscene starter; that code is not the owner's and none of it is here: this is written on what the tools above already had of build e0f3ccfa). A flag is a Bool of GameData, which @@ -1409,6 +1458,7 @@ static void oot_update_player_cheats(Ctx *c, uint64_t actor, uint64_t components oot_inventory_refresh(c, now); oot_link_tick(c, actor, now); /* ((Triforce) the Game flags and Cutscenes pages) */ oot_achievements_tick(c, now); /* ((Triforce) host/achievements.c) */ + oot_save_card_tick(c, now); /* ((Triforce) host/save_files.c: this save file's card) */ if (action >= OOT_CHEAT_ITEM_ACTION && action < OOT_CHEAT_ITEM_ACTION + 256 * (int)OOT_ITEM_COUNT) { oot_inventory_edit(c, action); } else if (action == OOT_AGE_ACTION) { @@ -2033,6 +2083,7 @@ static int game_main(int argc, char **argv) { } #endif static char beside_image[MAX_PATH], beside_romfs[MAX_PATH], beside_user[MAX_PATH]; + const int user_given = hos_user_dir != NULL; /* (--user) */ if (!image) { /* (hookshot) started with nothing, as a game is: everything beside the executable (the builder's folder) */ char dir[MAX_PATH]; const DWORD len = hos_game_path_a(dir, MAX_PATH); @@ -2052,6 +2103,9 @@ static int game_main(int argc, char **argv) { #else if (!hos_user_dir) hos_user_dir = beside_user; #endif + /* ((Triforce) the title's file select, host/save_files.c: the folder of the file last chosen; off, or a + folder named with --user: the one above) */ + if (!user_given) hos_user_dir = hos_save_files_start(dir, hos_user_dir); } } } @@ -2101,14 +2155,22 @@ static int game_main(int argc, char **argv) { return 1; } hos_mem_init(hos_image_end); - { /* (hookshot) Widescreen and ultrawide (nx2/oot_wide.py): HOS_ASPECT= (2.3889 for 3440x1440), else the Insert menu's - Ultrawide (off unless set: a fixed 16:10, 21:9 or 32:9, ultrawide_ratio). The game's picture takes that shape at its own height (the + { /* (hookshot) Widescreen and ultrawide (nx2/oot_wide.py): HOS_ASPECT= (2.3889 for 3440x1440), else the Output + resolution's own shape when it is not 16:9 (5120 x 1440, 5120 x 2160, Screen or Custom: the picture is that size, + host/nn_applet.c hos_output_ratio, gpu/vk/output_sizes.h), else the Insert menu's Ultrawide (off unless set: a fixed + 16:10, 21:9 or 32:9, ultrawide_ratio). The game's picture takes that shape at its own height (the world wider at the sides on an ultrawide screen, narrower on a 16:10 or 4:3 one), its 16:9 cameras the picture's ratio. Wider than 16:9 the HUD, menus and movies keep the middle 16:9; narrower they fill the picture's width. Until now the one 16:9 constant in the game's data was changed and the 16:9 picture stretched to the window. */ const char *e = getenv("HOS_ASPECT"); float want = e ? (float)atof(e) : 0.0f; + int sized = 0; /* (the shape is the Output resolution's own: the picture is its size) */ if (!e) { + float hos_output_ratio(void); + want = hos_output_ratio(); + sized = want > 0.0f; + } + if (!e && !sized) { int row = 0, version = 0; char path[MAX_PATH]; const DWORD len = hos_game_path_a(path, MAX_PATH); @@ -2138,18 +2200,15 @@ static int game_main(int argc, char **argv) { /* (a screen narrower than 16:9 too, 16:10 to 5:4: the picture keeps the game's height and is narrower, the cameras take its ratio, and the HUD fills its width instead of a middle 16:9 wider than the screen. A 4:3 CRT at the 1440 output: picture 1920 x 1440, scene 1440 x 1080, HUD 100%) */ - if (want > game * 1.01 || (want > 1.0f && want < game * 0.99)) { - double r = want > 32.0 / 9.0 ? 32.0 / 9.0 : want < 5.0 / 4.0 ? 5.0 / 4.0 : want; - uint32_t hos_output_size(int height); /* (host/nn_applet.c: the Output resolution's height, 1440 as shipped) */ - unsigned oh = hos_output_size(1), ow = (unsigned)(oh * r / 8 + 0.5) * 8; /* (whole multiples of 8 pixels) */ - /* (at most 3840 x 2160's pixels, the shape kept: the game's render targets come from a pool sized for its picture - (host/nn_applet.c hos_rt_pool_size), and a 32:9 screen at the 4K output made a 7680 x 2160 one. Its pool at the - output's size ran out as Kokiri Forest loaded (a null pointer, issue 1031); a pool for the whole picture, 1.4 GB, - failed the game's own reservation at boot. 5400 x 1520 there, more than the 5120 x 1440 screens it was seen on) */ - if ((double)ow * oh > 3840.0 * 2160.0) { - oh = (unsigned)(sqrt(3840.0 * 2160.0 / r) / 8) * 8; - ow = (unsigned)(oh * r / 8) * 8; - } + uint32_t hos_output_size(int height); /* (host/nn_applet.c: the Output resolution's height, 1440 as shipped) */ + unsigned ow = 0, oh = 0; + /* (gpu/vk/output_sizes.h output_picture: whole multiples of 8 pixels. A shape of the row's or HOS_ASPECT's at most + 3840 x 2160's pixels, the shape kept: the game's render targets come from a pool sized for its picture + (host/nn_applet.c hos_rt_pool_size), and a 32:9 screen at the 4K output made a 7680 x 2160 one. Its pool at the + output's size ran out as Kokiri Forest loaded (a null pointer, issue 1031); a pool for the whole picture, 1.4 GB, + failed the game's own reservation at boot. 5400 x 1520 there, more than the 5120 x 1440 screens it was seen on. + A size's own shape: that size) */ + if (output_picture(hos_output_size(1), want, sized, &ow, &oh)) { const unsigned sh = oh * 3 / 4, sw = (unsigned)(ow * 0.75 / 8 + 0.5) * 8; /* (the scene, 3/4 of the picture as shipped) */ hos_wide_out = (uint64_t)oh << 32 | ow; hos_wide_scene = (uint64_t)sh << 32 | sw; diff --git a/host/hos_screens.h b/host/hos_screens.h new file mode 100644 index 0000000..e0d9114 --- /dev/null +++ b/host/hos_screens.h @@ -0,0 +1,17 @@ +/* (Triforce) The connected screens, as the game's window code finds them at the start (host/display.c on Windows, + host/posix/display_sdl.c with SDL elsewhere), for the Output resolution: host/nn_applet.c takes the size of the one the + window opens on for the old Screen value, and the Insert menu lists each one's size as a choice (MkwVkHost.screens, + host/rx_backend.c). Sizes are native pixels. A screen is told to the player by its size and its name; nothing keeps its + place in this list, which changes as screens are plugged in. */ +#pragma once + +typedef struct HosScreen { + int w, h; /* (pixels) */ + int opens; /* (1: the game's window opens on this one) */ + char name[64]; /* (the monitor's own name, UTF-8, "" where the system has none: a laptop's panel) */ +} HosScreen; + +/* The connected screens, at most cap of them: how many were written (0: none known, a run with no window) */ +int hos_screens(HosScreen *out, int cap); +/* The size of the one the window opens on, 0 x 0 when it is not known */ +void hos_screen_size(int *w, int *h); diff --git a/host/hos_sdl.c b/host/hos_sdl.c index e543569..3210812 100644 --- a/host/hos_sdl.c +++ b/host/hos_sdl.c @@ -17,6 +17,7 @@ static struct { void *CreateWindow, *SetWindowPosition, *SetWindowFullscreen, *SetRelativeMouseMode, *GetPrimaryDisplay, *GetDesktopDisplayMode, *Vulkan_CreateSurface, *PixelSize, *GetKeyboardState, *GetMouseState, *WaitEventTimeout, *PollEvent, *GetWindowSize, *LoadPNG, *SetWindowIcon, *DestroySurface, *GetWindowDisplay, *GetCurrentDisplayMode; + void *GetDisplays, *GetDisplayName; /* ((Triforce) optional: every display, hos_sdl_displays) */ /* sound */ void *OpenAudioDevice, *PauseAudioDevice, *OpenAudioDeviceStream, *ResumeAudioStreamDevice, *PutAudioStreamData; /* controllers */ @@ -79,6 +80,9 @@ static int get_all(HMODULE m, int three) { /* ((Triforce) 11-20) a controller's type and name by its place in the list, for the instruments left out (pad_kind.h) */ *(FARPROC *)&f.JoyTypeOf = GetProcAddress(m, three ? "SDL_GetJoystickTypeForID" : "SDL_JoystickGetDeviceType"); *(FARPROC *)&f.PadNameOf = GetProcAddress(m, three ? "SDL_GetGamepadNameForID" : "SDL_GameControllerNameForIndex"); + /* ((Triforce) every connected display and its name: SDL3's list of ids, SDL2's count; without them the main one alone) */ + *(FARPROC *)&f.GetDisplays = GetProcAddress(m, three ? "SDL_GetDisplays" : "SDL_GetNumVideoDisplays"); + *(FARPROC *)&f.GetDisplayName = GetProcAddress(m, "SDL_GetDisplayName"); if (three) { GET(SetWindowPosition, "SDL_SetWindowPosition"); GET(GetPrimaryDisplay, "SDL_GetPrimaryDisplay"); @@ -187,6 +191,42 @@ int hos_sdl_desktop_size(int *width, int *height) { *width = m.w, *height = m.h; return 1; } +int hos_sdl_displays(HosSdlDisplay *out, int cap) { + int n = 0; + if (!f.GetDisplays) return 0; + if (version == 3) { /* (SDL_GetDisplays: the ids, freed with SDL_free; SDL_DisplayMode as above) */ + int count = 0; + uint32_t *ids = CALL(uint32_t *(*)(int *), GetDisplays)(&count); + /* (the main display first, whatever SDL's order: it is the one hos_sdl_desktop_size reads) */ + const uint32_t main_id = CALL(uint32_t (*)(void), GetPrimaryDisplay)(); + for (int i = 1; ids && i < count; i++) + if (ids[i] == main_id) ids[i] = ids[0], ids[0] = main_id; + for (int i = 0; ids && i < count && n < cap; i++) { + const uint8_t *m = CALL(const uint8_t *(*)(uint32_t), GetDesktopDisplayMode)(ids[i]); + if (!m) continue; + int w, h; + float density; + memcpy(&w, m + 8, 4), memcpy(&h, m + 12, 4), memcpy(&density, m + 16, 4); + if (!(density > 0)) density = 1; + const char *name = f.GetDisplayName ? CALL(const char *(*)(uint32_t), GetDisplayName)(ids[i]) : NULL; + out[n].w = (int)(w * density + 0.5f), out[n].h = (int)(h * density + 0.5f); + snprintf(out[n].name, sizeof out[n].name, "%s", name ? name : ""); + n++; + } + if (ids) CALL(void (*)(void *), Free)(ids); + return n; + } + const int count = CALL(int (*)(void), GetDisplays)(); /* (SDL2: by index, 0 the main display) */ + for (int i = 0; i < count && n < cap; i++) { + struct { uint32_t format; int w, h, refresh_rate; void *driverdata; } m; + if (CALL(int (*)(int, void *), GetDesktopDisplayMode)(i, &m)) continue; + const char *name = f.GetDisplayName ? CALL(const char *(*)(int), GetDisplayName)(i) : NULL; + out[n].w = m.w, out[n].h = m.h; + snprintf(out[n].name, sizeof out[n].name, "%s", name ? name : ""); + n++; + } + return n; +} int hos_sdl_refresh_mhz(void *window) { if (!window || !f.GetWindowDisplay || !f.GetCurrentDisplayMode) return 0; float hz = 0; diff --git a/host/hos_sdl.h b/host/hos_sdl.h index a826488..ecabb3f 100644 --- a/host/hos_sdl.h +++ b/host/hos_sdl.h @@ -21,6 +21,10 @@ void *hos_sdl_window(const char *title, int width, int height); void hos_sdl_fullscreen(void *window, int on); /* (the desktop's mode, borderless) */ void hos_sdl_relative_mouse(void *window, int on); int hos_sdl_desktop_size(int *width, int *height); +/* ((Triforce) every connected display, the main one first: its desktop size in pixels and its name ("" when SDL has none); + how many were written, at most cap. 0 from an SDL without the calls: hos_sdl_desktop_size still has the main one's) */ +typedef struct { int w, h; char name[64]; } HosSdlDisplay; +int hos_sdl_displays(HosSdlDisplay *out, int cap); int hos_sdl_refresh_mhz(void *window); /* the refresh rate of the window's display in mHz, 0 when not known (the main thread) */ int hos_sdl_vulkan_surface(void *window, void *instance, void *surface_out); /* (VkInstance, VkSurfaceKHR *): 1 if made */ void hos_sdl_pixel_size(void *window, int *width, int *height); diff --git a/host/hos_thread.c b/host/hos_thread.c index 5efe516..a99d843 100644 --- a/host/hos_thread.c +++ b/host/hos_thread.c @@ -6,6 +6,7 @@ +0x1F8, so lifted SDK code that reads it inline finds the same thread the HLE knows. */ #include "hos.h" #include "hos_x3d.h" +#include "hos_l3_home.h" /* ((Triforce, 11-23) one L3 for the main thread, the presenting thread and the replay's core) */ #include "hos_sim_cpu.h" /* ((Triforce, 11-22, OS-49) HOS_SIM_CPU, a lab switch: fewer of the PC's cores */ #include "pace_wait.h" /* ((Triforce) hos_sleep_until_ns: the frame wait to its time) */ #include "short_sleep.h" /* ((Triforce, 11-21) how sleeps under a millisecond wait, by the PC's processors) */ @@ -728,7 +729,7 @@ static uint64_t pick_reserved_core(const uint64_t *masks, const unsigned char *c has a thread of its own (RX_VK_ASYNC=1): hos_x3d.h hos_x3d_keep_replay_core has the rule and Source A's numbers */ #if defined(_WIN32) /* (hos_x3d_pick over what Windows lists for the calling thread's processor group) */ -static uint64_t x3d_detect(HosX3d *out) { +static uint64_t x3d_detect(HosX3d *out, HosL3Home *home) { static HosCache caches[1024]; static uint64_t cores[256]; int ncaches = 0, ncores = 0; @@ -763,9 +764,11 @@ static uint64_t x3d_detect(HosX3d *out) { } free(buf); } + hos_l3_home_pick(caches, ncaches, cores, ncores, (uint64_t)proc, (int)GetActiveProcessorGroupCount(), home); /* (Triforce, 11-23) */ return hos_x3d_pick(caches, ncaches, cores, ncores, (uint64_t)proc, (int)GetActiveProcessorGroupCount(), out); } #endif +static uint64_t l3_home_mask; /* ((Triforce, 11-23) hos_l3_home.h: the home, 0 for none; set with hos_x3d_cpus' mask) */ static uint64_t hos_x3d_cpus(void) { static uint64_t mask = ~0ull; static SRWLOCK lk = SRWLOCK_INIT; @@ -774,9 +777,10 @@ static uint64_t hos_x3d_cpus(void) { mask = 0; #if defined(_WIN32) HosX3d x; + HosL3Home h; const char *e = getenv("HOS_X3D"); const int off = e && *e && !atoi(e); - const uint64_t die = x3d_detect(&x); + const uint64_t die = x3d_detect(&x, &h); if (x.why == HOS_X3D_USED && !off) mask = die; if (x.why == HOS_X3D_USED || x.why == HOS_X3D_FEW) /* (a processor with L3 caches of two sizes: said either way) */ hos_log("cpu: logical processors %#llx share the largest L3 cache (%llu MB, against %llu MB), %d cores: %s", @@ -784,6 +788,18 @@ static uint64_t hos_x3d_cpus(void) { x.why == HOS_X3D_FEW ? "fewer than 8, so the game's threads are not kept there" : off ? "not used (HOS_X3D=0)" : "the game's threads are kept there, and the replay's core when one is kept (HOS_X3D=0: as before)"); + /* ((Triforce, 11-23) hos_l3_home.h: with no cache die, the home for the two threads that hand the frame over) */ + const char *he = getenv("HOS_L3_HOME"); + const int home_off = he && *he && !atoi(he); + if (!mask && h.why == HOS_L3_HOME_USED && !home_off) l3_home_mask = h.home; + if (h.why == HOS_L3_HOME_USED || h.why == HOS_L3_HOME_FEW) + hos_log("cpu: logical processors %#llx share one of %d L3 caches (%llu MB each), %d cores: %s", + (unsigned long long)h.home, h.domains, (unsigned long long)(h.bytes >> 20), h.cores, + h.why == HOS_L3_HOME_FEW ? "fewer than 6, so nothing is kept there" + : mask ? "not used (the cache die is)" + : home_off ? "not used (HOS_L3_HOME=0)" + : "the game's main and presenting threads and the replay's core are kept there, the other threads " + "anywhere (HOS_L3_HOME=0: as before)"); #endif } const uint64_t m = mask; @@ -804,6 +820,7 @@ static uint64_t last_fastest_core(int *cores) { GROUP_AFFINITY ga; const WORD group = GetThreadGroupAffinity(GetCurrentThread(), &ga) ? ga.Group : 0; const uint64_t die = hos_x3d_cpus(); /* (Triforce: the cores of the die the game's threads are kept on, when there is one) */ + const uint64_t home = die ? 0 : l3_home_mask; /* ((Triforce, 11-23) or of the home, hos_l3_home.h) */ if (GetLogicalProcessorInformationEx(RelationProcessorCore, NULL, &len) || GetLastError() != ERROR_INSUFFICIENT_BUFFER) return 0; char *buf = (char *)malloc(len); @@ -813,6 +830,7 @@ static uint64_t last_fastest_core(int *cores) { if (!e->Size) break; if (e->Relationship == RelationProcessorCore && e->Processor.GroupCount && e->Processor.GroupMask[0].Group == group && (!die || ((uint64_t)e->Processor.GroupMask[0].Mask & die)) && + (!home || ((uint64_t)e->Processor.GroupMask[0].Mask & home)) && (!sim_cpu_mask || ((uint64_t)e->Processor.GroupMask[0].Mask & sim_cpu_mask))) { /* ((Triforce, OS-49) inside it) */ masks[n] = (uint64_t)e->Processor.GroupMask[0].Mask; classes[n] = e->Processor.EfficiencyClass; @@ -916,6 +934,12 @@ void hos_thread_pin(void *h, const char *name) { const uint64_t want = hos_x3d_thread_mask((uint64_t)proc, die, reserved); if (want) SetThreadAffinityMask(h, (DWORD_PTR)want); } + if (l3_home_mask && hos_l3_home_thread(name)) { /* ((Triforce, 11-23) the main and presenting threads on the home, hos_l3_home.h) */ + DWORD_PTR proc = 0, sys = 0; + GetProcessAffinityMask(GetCurrentProcess(), &proc, &sys); + const uint64_t want = hos_l3_home_thread_mask((uint64_t)proc, l3_home_mask, reserved); + if (want) SetThreadAffinityMask(h, (DWORD_PTR)want); + } static NameSpec pins[24], prios[24]; static int npins = -1, nprios; static SRWLOCK lk = SRWLOCK_INIT; @@ -1576,6 +1600,7 @@ static struct { threads spinning already); grant to run: from vc_grant until the waiter holds vc_lock again, after a spin and after a sleep (NX2navi's "core grant to run", runtime/kernel.c grant_at) */ int64_t spun, slept, spin_ns, spin_capped, run_spin_ns, run_spin_n, run_sleep_ns, run_sleep_n, run_max_ns; + int64_t pin_waits; /* ((Triforce, 11-23) waits past esc_eq kept to their one core behind a better holder: vc_acquire */ } vc_st; /* ((Triforce, 11-22, the performance audit's OS-51) the waits since the last present, beside vc_st's 5 s: their time summed over the threads, how many, the longest. Added to with vc_lock held, taken by the present's look without it @@ -1669,6 +1694,9 @@ static void vc_stats_locked(int64_t now) { (long long)vc_st.slept, vc_st.run_spin_n ? vc_st.run_spin_ns / 1e3 / vc_st.run_spin_n : 0.0, (long long)vc_st.run_spin_n, vc_st.run_sleep_n ? vc_st.run_sleep_ns / 1e3 / vc_st.run_sleep_n : 0.0, (long long)vc_st.run_sleep_n, vc_st.run_max_ns / 1e3); + if (vc_st.pin_waits) /* ((Triforce, 11-23) vc_acquire: the escapes the one-core rule held back) */ + hos_log("vcores: %lld waits held to their one core past the escape, behind a holder of better priority there " + "(HOS_VCORE_PIN_ESCAPE_MS=0: they escape at HOS_VCORE_ESCAPE_EQ_US, as before)", (long long)vc_st.pin_waits); memset(&vc_st, 0, sizeof vc_st); vc_st.since = now; } @@ -1722,9 +1750,14 @@ static int vc_spin(HosThread *t, int64_t ns) { return 1; } static void vc_acquire(HosThread *t) { - static int64_t esc_better = -1, esc_eq, slice, spin; + static int64_t esc_better = -1, esc_eq, slice, spin, pin_esc; if (esc_better < 0) { esc_eq = vc_env_ns("HOS_VCORE_ESCAPE_EQ_US", 250000); + { /* ((Triforce, 11-23) a waiter held to one core behind a better holder: its escape's backstop, below) */ + const char *e = getenv("HOS_VCORE_PIN_ESCAPE_MS"); + const long long ms = e && *e ? atoll(e) : 5000; + pin_esc = ms > 0 ? ms * 1000000LL : 0; + } { /* ((Triforce) the spin, vc_spin: HOS_VCORE_SPIN_US, up to a second; off where no thread may spin) */ const int64_t s = vc_env_ns("HOS_VCORE_SPIN_US", 250); spin = !vc_spin_max() || s <= 0 ? 0 : s > 1000000000LL ? 1000000000LL : s; @@ -1751,6 +1784,7 @@ static void vc_acquire(HosThread *t) { if (vc_nq < 1024) vc_queue[vc_nq++] = t; vc_st.waits++; int spun = 0, slept = 0, ended = 0; /* ((Triforce) the spin tried, a sleep taken, the wait ended in the spin) */ + int pin_noted = 0; /* ((Triforce, 11-23) this wait counted in vc_st.pin_waits */ for (;;) { /* the worst holder worse than t on a core t may use gives it up at its next checkpoint; after HOS_VCORE_SLICE_US (2000) of waiting, a holder as good as t does too (a time slice: Horizon would leave @@ -1797,7 +1831,24 @@ static void vc_acquire(HosThread *t) { break; } const int64_t waited = hos_now_ns() - t0; - if (waited > (worst ? esc_better : esc_eq)) { + /* ((Triforce, 11-23) A waiter held to one core, behind a holder of better priority there, does not escape at + esc_eq: Horizon never runs it then, and the game pins threads to another's core so the two never overlap. + 0.7.0's load crash in f_80119570 (an effect graph's owner half made, read 0x48 / garbage +0x48) came each time + right after PreActorModelCompose escaped core 1 or 2 while BaseProcCreateAndDeleteThread held it. A backstop + at HOS_VCORE_PIN_ESCAPE_MS (5000; 0: as before) stays for a holder that never gives the core up at all */ + int64_t limit = worst ? esc_better : esc_eq; + if (!worst && pin_esc && (m & (m - 1)) == 0) { + const int k = __builtin_ctz(m); + HosThread *h = k < vc_cores() ? vc_owner[k] : NULL; + if (h && h->priority < t->priority) { + limit = pin_esc; + if (waited > esc_eq && !pin_noted) { + pin_noted = 1; + vc_st.pin_waits++; + } + } + } + if (waited > limit) { vc_dequeue(t); vc_st.escapes++; static int logged; diff --git a/host/n64_pace.h b/host/n64_pace.h new file mode 100644 index 0000000..d86baf0 --- /dev/null +++ b/host/n64_pace.h @@ -0,0 +1,39 @@ +/* (Triforce, 11-22) N64 Classic's frame rate (n64-classic-mode-plan.md, step 7): the frames paced at the rate the renderer + asks for (HOS_OPT_N64_FPS: Faithful's 20, or the Remembered page's row; gpu/vk/n64_rules.h fps), in play, with no restart + (nn_vi.c n64_pace_decide, pace_fps). + + The host already changes the rate it paces the game by while it runs: 240 while a movie plays at the 60 cap + (movie_pace.h). pace_fps is what the pacing, the game's frame limiter, its rate slot and the real-time step go by, and + the step's average starts again whenever it changes. N64 Classic's rate is one more input to it, asked once a present + beside the movie's. It only ever lowers the rate (a rate at or above the cap is the cap's), and gives way while a movie + plays: the movie player takes one picture a frame at most, so at 20 it would skip pictures. The real-time step stops at + 4/60 of a second (15 a second) and the game's rate slot takes 15 and up, so a rate under 15 is not taken. Game time + stays real time. fps_max stays the cap itself, read once, as it does for movies; the vsync event keeps the cap's rate, + as it does while a movie raises the pace. + + HOS_N64_PACE=0: the renderer's rate is not taken, the cap's as before. The rules alone, no game and no clock: + tests/test_n64_pace.py compiles them. */ +#pragma once + +#include + +/* The lowest rate taken: the real-time step's floor, 4/60 of a second */ +#define N64_PACE_LOWEST 15 + +/* Whether the renderer's rate is taken (HOS_N64_PACE: env, its value or NULL): unset, empty or not a 0, as HOS_MOVIE_PACE + is read */ +static inline int n64_pace_on(const char *env) { return !(env && *env && atoi(env) == 0); } + +/* The rate N64 Classic paces the frames at this present, 0 none: the renderer's (asked: frames a second, 0 none) where it is + on, no movie plays (movie: a movie player updated in the last quarter second), it is the real-time step's to take, and it + is under the cap (cap: the Frame rate cap's rate); else none */ +static inline int n64_pace_rate(int on, int asked, int movie, int cap) { + return on && !movie && asked >= N64_PACE_LOWEST && asked < cap ? asked : 0; +} + +/* The rate the frames are paced by: N64 Classic's where it has one, else the one the cap and a movie give (movie_pace_fps) */ +static inline int n64_pace_fps(int rate, int paced) { return rate > 0 ? rate : paced; } + +/* The present's interval in vsyncs with N64 Classic's rate: 1, for it paces by itself, as a cap under 60 does (the game's + own request for 2 vsyncs a frame would make 20 into 10); else as it was */ +static inline int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; } diff --git a/host/nn_applet.c b/host/nn_applet.c index 83b2ca6..1db5811 100644 --- a/host/nn_applet.c +++ b/host/nn_applet.c @@ -8,6 +8,9 @@ #include #include #include /* (the exe's folder; the browser build: the Microsoft C runtime's time functions) */ +#include "../gpu/vk/output_sizes.h" /* ((Triforce) the Output resolution row's sizes, the menu's too) */ +#include "../gpu/vk/ultrawide_rows.h" /* ((Triforce) the Ultrawide row as an old options file holds it: output_res_read) */ +#include "hos_screens.h" /* ((Triforce) the connected screens: the one the window opens on, and each one's size for the log) */ static int64_t boot_ns; @@ -107,37 +110,128 @@ int hos_ini_option(const char *key, int otherwise) { /* (hookshot: the Insert /* ((Triforce, options_version 7) The Insert menu's handheld profile is the Output resolution row's 1536 x 864: output_res=7, or HOS_OUTPUT_RES=7. handheld_profile=1 is a file's from before version 7, the row that was, until the menu writes the file again (gpu/vk/merged_rows.h migrate: it becomes output_res=7) */ -static int output_row(void) { return getenv("HOS_OUTPUT_RES") ? atoi(getenv("HOS_OUTPUT_RES")) : ini_option("output_res", 0); } +static int output_size_fields(void) { + return ini_option("output_width", -1) != -1 || ini_option("output_height", -1) != -1 || ini_option("output_custom_size", -1) != -1; +} +static int output_row(void) { + if (getenv("HOS_OUTPUT_RES")) return atoi(getenv("HOS_OUTPUT_RES")); + return output_file_read(ini_option("output_res", 0), ini_option("options_version", 0), 0, output_size_fields()); +} static int handheld(void) { static int v = -1; if (v < 0) - v = getenv("HOS_HANDHELD") ? atoi(getenv("HOS_HANDHELD")) != 0 : output_row() == 7 || ini_option("handheld_profile", 0) != 0; + v = getenv("HOS_HANDHELD") ? atoi(getenv("HOS_HANDHELD")) != 0 : output_row() == 7 || + ((output_legacy_file(ini_option("options_version", 0), output_size_fields()) || ini_option("options_version", 0) == 9) && + ini_option("handheld_profile", 0) != 0); return v; } /* (hookshot) The Insert menu's Output resolution (output_res=, HOS_OUTPUT_RES over it), docked only: 0 the game's 2048 x 1152, 1 2560 x 1440, 2 3840 x 2160, 3 1920 x 1080, 4 5120 x 1440, 5 5120 x 2880, 6 5120 x 2160 ((Triforce) after the others: a - saved number keeps its size). The game's frame is its display size (2560 x 1440 as shipped; - nx2/oot_patches.py apply_output_size asks hos_output_size) times its graphics scale (GetCurrentGraphicsScale: 0 x1, 1 x0.8, - 2 x0.667). Here it saw scale 1 (x0 left at the call before's answer), so 2048 x 1152; each explicit size uses x1. */ + saved number keeps its size), 7 handheld, 8 Screen, 9 Custom (gpu/vk/output_sizes.h, with the rule: the size is the picture's, the + game's frame 16:9 at its height). The game's frame is its display size (2560 x 1440 as shipped; nx2/oot_patches.py + apply_output_size asks hos_output_size) times its graphics scale (GetCurrentGraphicsScale: 0 x1, 1 x0.8, 2 x0.667). Here it + saw scale 1 (x0 left at the call before's answer), so 2048 x 1152; each explicit size uses x1. A size that is not 16:9 + (5120 x 1440, 5120 x 2160, and Screen or Custom of such a shape) is the widescreen picture's (hos_output_ratio, + host/hos_main.c). + The menu lists every connected screen's size as a choice and saves the one chosen as Custom's size (9 with + output_width= and output_height=): a size, which means the same whichever screens are connected at the next start. 8, + Screen, is what an options file from before that has, and HOS_OUTPUT_RES=8: the size of the screen the window opens on, + as it always was; the menu saves it as that size */ +static unsigned flex_wh[2][2]; /* (Triforce) Screen's and Custom's sizes as used, 0 x 0 for none: flex_read */ +static void flex_read(void) { + static int done; + if (done) return; + done = 1; + int sw = 0, sh = 0; + hos_screen_size(&sw, &sh); + long w = sw, h = sh; + if (!output_size_used(w, h, &flex_wh[0][0], &flex_wh[0][1])) flex_wh[0][0] = flex_wh[0][1] = 0; + else if ((long)flex_wh[0][0] != w || (long)flex_wh[0][1] != h) + hos_log("oe: the screen's %ldx%ld is taken as %ux%u (gpu/vk/output_sizes.h: the sides, the shape and the pixels a picture can have)", + w, h, flex_wh[0][0], flex_wh[0][1]); + const char *e = getenv("HOS_OUTPUT_SIZE"); + w = h = 0; + if (e) { + if (!output_parse_size(e, &w, &h)) hos_log("oe: HOS_OUTPUT_SIZE=%s is not x: not taken", e); + } else { /* (the file's two numbers, as the menu reads them: gpu/vk/vk_menu.cpp custom_rows_read) */ + w = ini_option("output_width", 0), h = ini_option("output_height", 0); + output_custom_read(&w, &h); + } + if (!output_size_used(w, h, &flex_wh[1][0], &flex_wh[1][1])) flex_wh[1][0] = flex_wh[1][1] = 0; + else if ((long)flex_wh[1][0] != w || (long)flex_wh[1][1] != h) + hos_log("oe: the custom output size %ldx%ld is taken as %ux%u (gpu/vk/output_sizes.h: the sides, the shape and the pixels a picture can have)", + w, h, flex_wh[1][0], flex_wh[1][1]); +} +/* (the log: every connected screen with the size the game would take it at, and whether Custom's size is one of them) */ +static void screens_log(int custom) { + HosScreen list[16]; + const int n = hos_screens(list, 16); + int found = 0; + for (int i = 0; i < n; i++) { + unsigned w = 0, h = 0; + if (!output_size_used(list[i].w, list[i].h, &w, &h)) continue; + hos_log("oe: screen %dx%d%s%s%s%s", list[i].w, list[i].h, list[i].name[0] ? " \"" : "", list[i].name, list[i].name[0] ? "\"" : "", + list[i].opens ? ", the one the window opens on" : ""); + if (custom && w == flex_wh[1][0] && h == flex_wh[1][1]) found = 1; + } + if (custom && n && !found) + hos_log("oe: output resolution Custom %ux%u is no connected screen's size: taken as it is", flex_wh[1][0], flex_wh[1][1]); +} +static unsigned out_wh[2]; /* (the Output resolution's size, the picture's: output_mode) */ static int output_mode(void) { static int v = -1; if (v < 0) { - static const char *const names[] = {"2048x1152 (the game's)", "2560x1440", "3840x2160", "1920x1080", "5120x1440", "5120x2880", "5120x2160"}; - v = output_row(); - if ((unsigned)v >= sizeof names / sizeof *names || handheld()) v = 0; /* (7, the handheld profile's: handheld() sizes it) */ - hos_log("oe: output resolution %s", handheld() ? "the handheld profile's (1536x864)" : names[v]); + static const char *const names[] = {"2048x1152 (the game's)", "2560x1440", "3840x2160", "1920x1080", "5120x1440", "5120x2880", "5120x2160", "1536x864 (handheld)", "Screen", "Custom"}; + if (getenv("HOS_OUTPUT_RES")) { + v = atoi(getenv("HOS_OUTPUT_RES")); + } else { /* (a file from before options_version 8: 5120 x 1440 and 5120 x 2160 as it had them, output_res_read) */ + const int version = ini_option("options_version", 0); + const int row = ultrawide_row_read(ini_option("ultrawide", 0), version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + const int saved = ini_option("output_res", 0); + v = output_file_read(saved, version, row, output_size_fields()); + if (v != saved) { + if (saved == 7 || saved == 8) + hos_log("oe: output resolution %s (%d) from native 0.5.2: now %d under options_version %d, the same choice", + saved == 7 ? "Screen" : "Custom", saved, v, OUTPUT_OPTIONS_VERSION); + else + hos_log("oe: output resolution %s with Ultrawide on another shape, from before options_version %d: %s now, the same picture", + names[saved], OUTPUT_OPTIONS_VERSION, names[v]); + } + } + if ((unsigned)v > OUTPUT_LAST || handheld()) v = 0; + if (v >= OUTPUT_SCREEN) { + flex_read(); + const unsigned *s = flex_wh[v - OUTPUT_SCREEN]; + if (!s[1]) { /* (no size: the screen's not known, or HOS_OUTPUT_SIZE is not one) */ + hos_log("oe: output resolution %s: %s, so 2560x1440", names[v], + v == OUTPUT_SCREEN ? "the screen's size is not known" : "HOS_OUTPUT_SIZE is not a size"); + v = 1; + } else { + out_wh[0] = s[0], out_wh[1] = s[1]; + } + } + /* (0, the game's own 2048 x 1152: its display size 2560 x 1440 at its graphics scale x0.8, above) */ + if (v < OUTPUT_SCREEN) out_wh[0] = output_fixed_size(v ? v : 1, 0), out_wh[1] = output_fixed_size(v ? v : 1, 1); + if (v >= OUTPUT_SCREEN) hos_log("oe: output resolution %s %ux%u", names[v], out_wh[0], out_wh[1]); + else hos_log("oe: output resolution %s", names[v]); + screens_log(v == OUTPUT_CUSTOM); + if (output_size_shaped(out_wh[0], out_wh[1])) + hos_log("oe: %ux%u is the picture: the game's frame is %ux%u in its middle", out_wh[0], out_wh[1], + output_frame_width(out_wh[1]), out_wh[1]); } return v; } +/* The game's frame: the Output resolution's size, or 16:9 at its height when the size has another shape */ uint32_t hos_output_size(int height) { - switch (output_mode()) { - case 2: return height ? 2160 : 3840; - case 3: return height ? 1080 : 1920; - case 4: return height ? 1440 : 5120; - case 5: return height ? 2880 : 5120; - case 6: return height ? 2160 : 5120; /* ((Triforce) 5120 x 2160) */ - default: return height ? 1440 : 2560; - } + output_mode(); + if (height) return out_wh[1]; + return output_size_shaped(out_wh[0], out_wh[1]) ? output_frame_width(out_wh[1]) : out_wh[0]; +} +/* (Triforce, host/hos_main.c) The Output resolution's own shape, width over height, when it is not 16:9: the picture is then + that size, and the Ultrawide row does not apply. 0 for a 16:9 size (the row's shape, or the game's own picture) */ +float hos_output_ratio(void) { + output_mode(); + return output_size_shaped(out_wh[0], out_wh[1]) ? (float)((double)out_wh[0] / (double)out_wh[1]) : 0.0f; } /* (hookshot) The render targets' GPU pool (nx2/oot_patches.py), 0x13100000 bytes as shipped, for 2560 x 1440: a 3840x2160 3D at the 4K output ran out of it. Scaled with the output's pixels, or the widescreen picture's when it has more (host/hos_main.c: @@ -153,7 +247,7 @@ uint32_t hos_output_size(int height) { output with RenoDX HDR boots and played in the world, 17,160 presents at about 50 fps, RenoDX's four shaders in place, no error from the pool (one short session, not every area; its scene target and each copy are 118 MB there). */ /* ((Triforce, 11-21, the performance audit's TEX-85) Whether the render targets' heap is held to a size, with no room to - give: HOS_RT_POOL_MB set, or the 5120-wide outputs' 900 MB. -1 until hos_rt_pool_size has run. host/shadow_slot.h reserves + give: HOS_RT_POOL_MB set, or a picture limited to the 900 MB cap. -1 until hos_rt_pool_size has run. host/shadow_slot.h reserves no stepped storage there unless asked to) */ static int rt_pool_pinned = -1; int hos_rt_pool_pinned(void) { return __atomic_load_n(&rt_pool_pinned, __ATOMIC_RELAXED); } @@ -166,21 +260,25 @@ uint64_t hos_rt_pool_size(uint64_t game) { const uint64_t scaled = px > 2560 * 1440 ? (game * px / (2560 * 1440) + 0xfffff) & ~0xfffffULL : game; const uint64_t minimum = 512ULL << 20, five_k = 900ULL << 20; /* ((Triforce) and the 5120 x 2160 output: scaled, its pool is 915 MB, more than any pool known to pass the game's reservation - at a 5120-wide output; 900 MB ran the 3D at the full 5120 x 2880, a third more pixels) */ - const int is_five_k = hos_output_size(0) == 5120 && hos_output_size(1) >= 2160; + at a 5120-wide output; 900 MB ran the 3D at the full 5120 x 2880, a third more pixels. So any output of more pixels than + 3840 x 2160's, whether they are the frame's or the widescreen picture's: a 5120 x 2160 picture has the frame 3840 x 2160, + and scaled for the picture its pool would be those 915 MB (the 1.4 GB of a 7680 x 2160 picture failed the reservation + too, host/hos_main.c). gpu/vk/output_sizes.h keeps a picture to 5120 x 2880's pixels, the most the 900 MB are known to + hold) */ + const int is_five_k = px > 3840ull * 2160ull; extern int hos_scene_rgba16f(void); /* (local, RenoDX port) the scene's colour target at 8 bytes a pixel in place of 4: room for it and its copies, at 3840 x 2160 33 MB each */ const uint64_t rgba16f = hos_scene_rgba16f() ? 128ULL << 20 : 0; const uint64_t asked = (e ? strtoull(e, NULL, 0) << 20 : scaled < minimum ? minimum : is_five_k && scaled > five_k ? five_k : scaled) + (e ? 0 : rgba16f); /* (the 5120 x 2880 output: 900 MB for the whole pool, see above; an explicit HOS_RT_POOL_MB still wins) */ const uint64_t v = !e && is_five_k && asked > five_k ? five_k : asked; - __atomic_store_n(&rt_pool_pinned, e != NULL || v != asked || (is_five_k && scaled > five_k), __ATOMIC_RELAXED); /* ((Triforce, 11-21, TEX-85)) */ + __atomic_store_n(&rt_pool_pinned, e != NULL || (is_five_k && v == five_k), __ATOMIC_RELAXED); /* ((Triforce, 11-21, TEX-85)) */ static int logged; if (!logged++) { hos_log("applet: render target pool %llu MB (the game's %llu MB)", (unsigned long long)(v >> 20), (unsigned long long)(game >> 20)); if (v != asked) - hos_log("applet: render target pool: %llu MB asked (the %ux%u output), kept to %llu MB: more fails the game's reservation at boot", - (unsigned long long)(asked >> 20), hos_output_size(0), hos_output_size(1), (unsigned long long)(v >> 20)); + hos_log("applet: render target pool: %llu MB asked (%llu pixels), kept to %llu MB: more fails the game's reservation at boot", + (unsigned long long)(asked >> 20), (unsigned long long)px, (unsigned long long)(v >> 20)); } return v; } diff --git a/host/nn_fs.c b/host/nn_fs.c index 05e19bb..d0bc5d9 100644 --- a/host/nn_fs.c +++ b/host/nn_fs.c @@ -8,6 +8,8 @@ of guest threads can read one file at once. Results: switchbrew "Error codes" (module 2 = fs). */ #include "hos.h" #include "stall_host.h" /* ((Triforce, 11-22, OS-51) the host's part of a long frame, counted where it is spent) */ +#include "host_alloc.h" /* ((Triforce, 11-23) hos_xcalloc: the handles' allocations wait at the commit limit */ +#include "oot_title_movie.h" #include #include #include @@ -236,6 +238,7 @@ static void make_dirs(const char *path) { /* every parent of path */ typedef struct { char name[HOS_FS_PATH]; int is_dir; uint64_t size; } ExtraEntry; /* (a listed folder's mod-only entries) */ typedef struct { HANDLE h; int writable; HANDLE find; WIN32_FIND_DATAA fd; int find_done, is_dir; char path[HOS_FS_PATH]; + enum OotMovieFile movie; ExtraEntry *extras; int nextras, extra_pos; } Handle; static Handle *handles[4096]; @@ -244,7 +247,12 @@ static SRWLOCK handle_lock = SRWLOCK_INIT; static uint64_t new_handle(Handle *h) { AcquireSRWLockExclusive(&handle_lock); for (int i = 0; i < 4096; i++) - if (!handles[i]) { handles[i] = h; ReleaseSRWLockExclusive(&handle_lock); return (uint64_t)i + 1; } + if (!handles[i]) { + handles[i] = h; + oot_movie_file_change(h->movie, 1); + ReleaseSRWLockExclusive(&handle_lock); + return (uint64_t)i + 1; + } ReleaseSRWLockExclusive(&handle_lock); hos_fatal(NULL, "fs: out of handles"); return 0; @@ -256,7 +264,10 @@ static Handle *get_handle(Ctx *c, uint64_t id) { } static void free_handle(uint64_t id) { AcquireSRWLockExclusive(&handle_lock); - if (id && id <= 4096) handles[id - 1] = NULL; + if (id && id <= 4096 && handles[id - 1]) { + oot_movie_file_change(handles[id - 1]->movie, -1); + handles[id - 1] = NULL; + } ReleaseSRWLockExclusive(&handle_lock); } @@ -353,7 +364,7 @@ static int tx_mount(const char *name, const char *uid, char *root, size_t cap) { if (!save_tx_enabled()) return 0; static int at_exit; int ok = 0, locked = 1; - char note[256] = ""; + char note[HOS_FS_PATH + 384] = ""; /* ((Triforce, 11-23) room for a failed working copy's file and reason: save_tx.h tx_why) */ AcquireSRWLockExclusive(&tx_lock); const int import_said = tx_import_note[0] != 0; if (!at_exit) at_exit = 1, atexit(hos_fs_save_finish); @@ -587,6 +598,9 @@ HLE(_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci) { return; } { void hos_bench_file_opened(const char *guest); hos_bench_file_opened(g); } /* ((Triforce) benchmark mode: which save file loads */ + /* ((Triforce) the file select's cards, host/save_files.c: a slot of the save opened to be written is the slot the game + saves in now; nothing while the save files are off) */ + if (want_write) { void hos_save_card_wrote(const char *guest_path); hos_save_card_wrote(g); } /* (mkw-recomp) HOS_NO_MOVIES=1: MKW's WebM movies (cup openings, billboards, emblems) are not found, and the game goes on without them (decoded by nn_video.c otherwise) */ if (!want_write && getenv("HOS_NO_MOVIES")) { @@ -624,16 +638,33 @@ HLE(_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci) { if (open_keep_core) away = hos_vcore_away(); /* ((Triforce, 11-21, IO-24) otherwise given up already, above) */ HANDLE h = CreateFileA(path, GENERIC_READ | (want_write ? GENERIC_WRITE : 0), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + const DWORD open_err = h == INVALID_HANDLE_VALUE ? GetLastError() : 0; /* (before the core is taken back) */ if (away) hos_vcore_back(); if (h == INVALID_HANDLE_VALUE) { + /* ((Triforce, 11-23, ticket "Cannot launch into game after 0.7 update", Linux) a file of a writable mount (the save's) + that is there but would not open answers "not found" all the same. In the report's log the save had no working copy, + the game's save manager looped (some 200,000 core takes a second; an open is one) and the file select never came, + and nothing said which file or why. Said for the first 8 such files */ + static volatile LONG there_said; + if (writable && GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES && InterlockedIncrement(&there_said) <= 8) + hos_log("fs: OpenFile(%s): %s is there but could not be opened for %s (error %lu): the game is told it is not there", + g, path, want_write ? "writing" : "reading", (unsigned long)open_err); if (hos_trace || fs_trace()) hos_log("fs: OpenFile(%s): not found", g); RET(R_PATH_NOT_FOUND); return; } - Handle *fh = (Handle *)calloc(1, sizeof *fh); + /* ((Triforce, 11-23, ticket 1574276312678408316) at Windows' commit limit this calloc answered NULL and the write + below ended the game as "write 0" inside OpenFile, with no word of the memory; now it waits as the host's other + tables do (host_alloc.h) and, still refused, ends the game saying why */ + Handle *fh = (Handle *)hos_xcalloc(1, sizeof *fh); + if (!fh) { + CloseHandle(h); + hos_fatal(c, "fs: OpenFile(%s): out of memory for its handle (Windows is out of RAM and page file)", g); + } fh->h = h; fh->writable = want_write; snprintf(fh->path, sizeof fh->path, "%s", g); + fh->movie = oot_movie_file(fh->path); G64(ARG(0)) = new_handle(fh); if (hos_trace || fs_trace()) hos_log("fs: OpenFile(%s)", g); RET(0); @@ -854,7 +885,11 @@ HLE(_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc) { /* ---- directories: DirectoryEntry = { char name[0x301]; pad[3]; s8 type at 0x304 (0 directory, 1 file); pad[3]; s64 size at 0x308 } ---- */ static void add_extra(void *arg, const char *name, int is_dir, uint64_t size) { Handle *dh = (Handle *)arg; - if (!(dh->nextras & 15)) dh->extras = (ExtraEntry *)realloc(dh->extras, sizeof *dh->extras * (size_t)(dh->nextras + 16)); + if (!(dh->nextras & 15)) { /* ((Triforce, 11-23) as OpenFile's handle: waits at the commit limit, NULL ends the game saying why) */ + ExtraEntry *more = (ExtraEntry *)hos_xrealloc(dh->extras, sizeof *dh->extras * (size_t)(dh->nextras + 16)); + if (!more) hos_fatal(NULL, "fs: OpenDirectory: out of memory for the mods' entries (Windows is out of RAM and page file)"); + dh->extras = more; + } ExtraEntry *e = &dh->extras[dh->nextras++]; snprintf(e->name, sizeof e->name, "%s", name); e->is_dir = is_dir, e->size = size; @@ -863,7 +898,8 @@ HLE(_ZN2nn2fs13OpenDirectoryEPNS0_15DirectoryHandleEPKci) { char path[HOS_FS_PATH], pat[HOS_FS_PATH]; if (!host_path(gstr(ARG(1)), path, sizeof path, NULL)) { RET(R_PATH_NOT_FOUND); return; } snprintf(pat, sizeof pat, "%s\\*", path); - Handle *dh = (Handle *)calloc(1, sizeof *dh); + Handle *dh = (Handle *)hos_xcalloc(1, sizeof *dh); /* ((Triforce, 11-23) as OpenFile's handle, above) */ + if (!dh) hos_fatal(c, "fs: OpenDirectory(%s): out of memory for its handle (Windows is out of RAM and page file)", gstr(ARG(1))); dh->is_dir = (int)ARG(2); /* mode: 1 directories, 2 files, 3 both */ snprintf(dh->path, sizeof dh->path, "%s", pat); /* (for GetDirectoryEntryCount) */ dh->find = FindFirstFileA(pat, &dh->fd); diff --git a/host/nn_vi.c b/host/nn_vi.c index 4b48c11..9bd18a0 100644 --- a/host/nn_vi.c +++ b/host/nn_vi.c @@ -6,6 +6,7 @@ #include "step_steady.h" /* ((Triforce) HOS_STEP_STEADY=1: realtime_step) */ #include "pace_steady.h" /* ((Triforce) the Steady frame rate row: steady_period) */ #include "movie_pace.h" /* ((Triforce, 11-22, PRESENT-30) paced at 240 while a movie plays at the 60 cap) */ +#include "n64_pace.h" /* ((Triforce, 11-22, N64 Classic) paced at its frame rate: n64_pace_decide, pace_fps */ #include "../gpu/vk/vk_api.h" /* (HOS_OPT_HDR_*: the Insert menu's HDR, answered by the renderer) */ #define WIN32_LEAN_AND_MEAN #include @@ -294,9 +295,13 @@ void hos_vi_native_acquire(int active) { fps_max stays the cap itself, which the Steady row, the present interval and the other limiters' hand-off read. Not with the Steady frame rate row on. HOS_MOVIE_PACE=0: the cap kept through movies, as before */ static int movie_raise; +/* ((Triforce, 11-22, N64 Classic, step 7) the rate it paces the frames at, 0 none (n64_pace.h): n64_pace_decide, once a + present with the movie's decision, so a movie gives way to nothing and the cap stays the cap */ +static int n64_rate; static int pace_fps(void) { - return movie_pace_fps(movie_raise, fps_max()); + return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max())); } +static void n64_pace_decide(void); /* (below) */ static void movie_pace_decide(void) { static int on = -1, steady = -1; static long long raised; @@ -312,6 +317,23 @@ static void movie_pace_decide(void) { if (!raise && movie_raise) hos_log("vi: the movie is over: frames paced at the 60 cap again, after %lld at %d", raised, MOVIE_PACE_FPS), raised = 0; if (raise) raised++; movie_raise = raise; + n64_pace_decide(); /* ((Triforce, N64 Classic, step 7) its rate, beside the movie's */ +} +/* ((Triforce, 11-22, N64 Classic, step 7) The rate the renderer asks for (HOS_OPT_N64_FPS: Faithful's 20, or the Remembered + page's row; 0 none), taken where n64_pace.h takes it: under the cap, 15 and up, none while a movie plays. HOS_N64_PACE=0: + never. Each change said once */ +static void n64_pace_decide(void) { + static int on = -1; + if (on < 0) { + on = n64_pace_on(getenv("HOS_N64_PACE")); + if (!on) hos_log("vi: HOS_N64_PACE=0: N64 Classic's frame rate is not taken, the cap's is"); + } + int rx_option(int id, int otherwise); + const int was = n64_rate; + n64_rate = n64_pace_rate(on, on ? rx_option(HOS_OPT_N64_FPS, 0) : 0, movie_plays(), fps_max()); + if (n64_rate != was) + hos_log(n64_rate ? "vi: N64 Classic: frames paced at %d (the cap %d)" : "vi: N64 Classic: frames paced at the cap again (%d, the cap %d)", + n64_rate ? n64_rate : fps_max(), fps_max()); } /* (mkw-recomp) MKW's frame pacer (0x806bcbb0, x19 when it sets the interval: nvn_native.c): its measured frame time (+0x128, ticks), its running excess (+0x218) and interval (+0x214), logged with the frame rate */ @@ -581,6 +603,9 @@ static void realtime_step(int64_t now) { faster than real time, so a cap above 60 keeps the real-time step whatever that row says) */ /* (nor under 60: a cap of 30 would be the game at half speed for good) */ if (!rx_option(0, 1) && pace == 60) { + /* (a movie's 240 pacing left the timed step (1/240 s) there: the game's own step again, or the game ran at a quarter + of its speed at a full 60 fps after the first movie, 0.7.0 "extreme slowmo") */ + __atomic_store_n(&hos_frame_seconds_bits, 0, __ATOMIC_RELAXED); int *slot = (int *)GP(mod + 0x2c8); if (*slot >= 15 && *slot <= 60) *slot = 60; return; @@ -821,7 +846,7 @@ void hos_vi_native_presented(void) { if (ms) hos_sleep_ns(ms * 1000000LL); } /* (a cap under 60 paces by itself, whatever interval the game asked for while Monitor's rate was not known yet) */ - const int interval = fps_max() < 60 ? 1 : present_interval; + const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval); /* ((N64 Classic) 1 at its rate) */ const int64_t now = hos_now_ns(); { void hos_bench_present(int64_t now); hos_bench_present(now); } /* ((Triforce) benchmark mode: every present's interval) */ /* ((Triforce) the Steady frame rate row: a period this PC holds in the scene, never shorter than the cap's) */ diff --git a/host/nvn_native.c b/host/nvn_native.c index 8db91e8..a0d6648 100644 --- a/host/nvn_native.c +++ b/host/nvn_native.c @@ -2793,6 +2793,8 @@ NV(nvnQueuePresentTexture) { { void hos_stall_host_presented(void); hos_stall_host_presented(); } void hos_mod_cheats_frame(void); /* (Triforce) mod_cheats.c: the mods' cheat files, once a game frame; nothing without one */ hos_mod_cheats_frame(); + void hos_save_files_frame(void); + hos_save_files_frame(); /* ((Triforce) host/save_files.c: the title's file select; nothing while it is off) */ void hos_achievements_frame(void); hos_achievements_frame(); /* ((Triforce) host/achievements.c: its lists read and named to the menu; nothing while it is off) */ } diff --git a/host/oot_menu.c b/host/oot_menu.c index f5e4b4d..c79c357 100644 --- a/host/oot_menu.c +++ b/host/oot_menu.c @@ -14,6 +14,7 @@ HOS_MENU_TRACE=1: the focus changes, the screens and what the mouse does logged. */ #include "hos.h" #include "guest_bounds.h" /* ((Triforce) hos_range_ok: set_item_key's buffer) */ +#include "oot_title_movie.h" /* ((Triforce) oot_menu_screen_tick: a menu open over the title's filled movie) */ /* (Triforce) The game's own Options screen (the layout SystemOption_00; the title's Options and the pause menu's are the one screen), by its vtable (HOS_MENU_TRACE in a headless run, 2026-11-10: the screen of 15 entries that starts to run when Options is chosen, from the title and from the pause menu alike, and stops with Back; L and R do nothing on it). While @@ -284,6 +285,7 @@ static void focus_locked(uint64_t screen, uint64_t pane, uint64_t lr) { void hos_mouse_game_menu(void); /* (display.c) */ void hos_mouse_game_menu_gone(void); int hos_mouse_game_pointer(int *x, int *y, int *w, int *h, uint32_t *pressed, int *wheel); +void rx_screen_point(int *x, int *y, int w, int h); /* (rx_backend.c: N64 Classic's TV's curve) */ void hos_hid_tap(const char *press); /* (nn_hid.c) */ void hos_hid_stick(int lx, int ly, int rx, int ry, int hold_ms); void hos_hid_drag(int dx, int dy, int right); /* (nn_hid.c: as the camera's mouse; the left stick or the right) */ @@ -504,6 +506,8 @@ static void mouse_tick_locked(Ctx *c, uint64_t screen) { uint32_t pressed; const int got = hos_mouse_game_pointer(&px, &py, &w, &h, &pressed, &wheel); if (!got) return; + /* ((Triforce, 11-22, N64 Classic) the game's screens under its TV's curve: the cursor where the curve showed them) */ + rx_screen_point(&px, &py, w, h); const int hidden = got == 2; /* (the cursor hidden while the pad is in use: the wheel only, no pointing) */ const int pause = screen == pause_screen_now(); const float scale = 3840.0f / (float)w > 2160.0f / (float)h ? 3840.0f / (float)w : 2160.0f / (float)h; @@ -873,6 +877,7 @@ extern volatile LONG64 hos_present_count; /* (display.c: the game's own presen static Rect mods_entry; /* (the entry's box, as the renderer draws it: under the last button by the pitch) */ static Rect quit_entry; /* ((Triforce, 11-19) Quit's, under Mods by the pitch; empty on the title's list */ static volatile LONG64 mods_entry_ns; +int hos_save_files_on(void); /* ((Triforce) host/save_files.c: on the title the entry under Mods is Save Select then) */ typedef struct { Rect r[16]; uint64_t b[16]; int n, pause; } ModsList; static void mods_list_entry(int i, uint64_t entry, uint64_t button, void *arg) { (void)i, (void)entry; @@ -1018,6 +1023,13 @@ static void mods_list_tick(uint64_t screen, int title, ModsCall *call) { mods_entry = (Rect){mx - 550, my - pitch / 2, mx + 550, my + pitch / 2}; } quit_entry = title ? (Rect){0, 0, 0, 0} : (Rect){r.x0, r.y0 - 2 * pitch, r.x1, r.y1 - 2 * pitch}; + /* ((Triforce) on the title, while the save files are on (host/save_files.c), the entry under Mods is Save Select: a line + of the title's list as Mods is one, a pitch lower. Its words are Quit's (3 clicked, 4 the mouse onto it): the renderer + knows by the list which of the two it draws there (vk_menu.cpp files_row_shown) */ + if (title && hos_save_files_on()) { + const float mx = (r.x0 + r.x1) / 2, my = (r.y0 + r.y1) / 2 - 2 * pitch; + quit_entry = (Rect){mx - 550, my - pitch / 2, mx + 550, my + pitch / 2}; + } if (alpha >= 0.5f) InterlockedExchange64(&mods_entry_ns, (LONG64)now); /* (the mouse's: an entry not shown yet is not there to click) */ rx_option_set(HOS_OPT_MODS_ALPHA, (int)(alpha * 1000.0f + 0.5f)); rx_option_set(HOS_OPT_MODS_X0, (int)r.x0), rx_option_set(HOS_OPT_MODS_X1, (int)r.x1); @@ -1093,6 +1105,7 @@ static Seen *screen_seen(uint64_t screen, int64_t now) { void hos_oot_menu_tick(Ctx *c, uint64_t screen) { if (!screen) return; if (trace < 0) trace = getenv("HOS_MENU_TRACE") != NULL; + oot_menu_screen_tick(peek64(screen)); /* ((Triforce) the screen's class, each frame it runs: oot_title_movie.h) */ const int64_t now = hos_now_ns(); AcquireSRWLockExclusive(&seen_lock); Seen *me = screen_seen(screen, now); @@ -1200,6 +1213,7 @@ void hos_oot_menu_tick(Ctx *c, uint64_t screen) { static int options_from_pause; const int64_t now = hos_now_ns(); if (vt == PAUSE_SCREEN_VTABLE) __atomic_store_n(&pause_ran_ns, now, __ATOMIC_RELAXED); + oot_menu_screen_tick(vt); /* ((Triforce) the screen's class, each frame it runs: oot_title_movie.h) */ if (vt != OPTIONS_SCREEN_VTABLE) return; static int tabs = -1; if (tabs < 0) { diff --git a/host/oot_title_movie.c b/host/oot_title_movie.c new file mode 100644 index 0000000..78c034a --- /dev/null +++ b/host/oot_title_movie.c @@ -0,0 +1,84 @@ +/* OoT's title movie draw and its viewport share a thread; file handles and presents do not. */ +#include "oot_title_movie.h" +#include +#define WIN32_LEAN_AND_MEAN +#include + +extern volatile LONG64 hos_present_count; +void hos_log(const char *fmt, ...); + +enum OotMovieFile oot_movie_file(const char *path) { + const size_t n = strlen(path); + if (n < 5 || _stricmp(path + n - 5, ".webm")) return OOT_MOVIE_NONE; + const char *name = strchr(path, ':'); + name = name ? name + 1 : path; + while (*name == '/') ++name; + const char prefix[] = "Event/Movie/Dm_Title_"; + return !strncmp(name, prefix, sizeof prefix - 1) && !strchr(name + sizeof prefix - 1, '/') + ? OOT_MOVIE_TITLE : OOT_MOVIE_OTHER; +} + +static int title_only; +void oot_movie_file_change(enum OotMovieFile kind, int delta) { + /* nn_fs holds handle_lock across each insertion and removal, including duplicate opens. */ + static int titles, others; + if (kind == OOT_MOVIE_TITLE) titles += delta; + else if (kind == OOT_MOVIE_OTHER) others += delta; + else return; + __atomic_store_n(&title_only, titles > 0 && others == 0, __ATOMIC_RELEASE); +} + +static _Thread_local float pending_ratio; +static LONG64 last_draw = -1; +int hos_movie_cover_begin(float ratio) { + pending_ratio = oot_title_cover_ratio(ratio) && __atomic_load_n(&title_only, __ATOMIC_ACQUIRE) ? ratio : 0; + return pending_ratio != 0; +} + +int hos_movie_cover_viewport(uint64_t *y, uint64_t *height) { + if (!pending_ratio) return 0; + const float ratio = pending_ratio; + pending_ratio = 0; + int32_t top = (int32_t)*y, h = (int32_t)*height; + if (!oot_title_movie_cover(ratio, &top, &h)) return 0; + *y = (uint32_t)top; + *height = (uint32_t)h; + __atomic_store_n(&last_draw, __atomic_load_n(&hos_present_count, __ATOMIC_RELAXED), __ATOMIC_RELEASE); + return 1; +} + +int oot_movie_cover_recent(void) { + static int logged; + const LONG64 draw = __atomic_load_n(&last_draw, __ATOMIC_ACQUIRE); + const LONG64 now = __atomic_load_n(&hos_present_count, __ATOMIC_RELAXED); + const int covered = draw >= 0 && now - draw <= 2; + if (__atomic_exchange_n(&logged, covered, __ATOMIC_RELAXED) != covered) + hos_log("wide: title movie cover %s", covered ? "on" : "off"); + return covered; +} + +/* (Triforce) A menu over the filled movie (oot_title_movie.h). The menu screens' updates run on the game's threads, the + question comes from the renderer's: the present it last ran at and its class, each written and read whole */ +static LONG64 menu_ran = -1; +static LONG64 menu_class; +void oot_menu_screen_tick(uint64_t screen_class) { + if (!oot_title_menu_class(screen_class)) return; + __atomic_store_n(&menu_class, (LONG64)screen_class, __ATOMIC_RELAXED); + __atomic_store_n(&menu_ran, __atomic_load_n(&hos_present_count, __ATOMIC_RELAXED), __ATOMIC_RELEASE); +} + +int oot_menu_backdrop_runs(void) { + return oot_menu_recent(__atomic_load_n(&hos_present_count, __ATOMIC_RELAXED), __atomic_load_n(&menu_ran, __ATOMIC_ACQUIRE)); +} + +int oot_menu_over_movie(void) { + static int logged; + const int over = oot_menu_backdrop_runs(); + /* (each change said, with the screen that told it: a report of a seam beside a menu at the title says which screen + the menu was, or that none of the known ones ran) */ + if (__atomic_exchange_n(&logged, over, __ATOMIC_RELAXED) != over) + hos_log("wide: a menu screen %s (class %#llx): menu sides %s", over ? "runs" : "has stopped", + (unsigned long long)__atomic_load_n(&menu_class, __ATOMIC_RELAXED), + over ? "as the Ultrawide menus row asks, over the title movie too" : "off again while the title movie fills the picture"); + return over; +} diff --git a/host/oot_title_movie.h b/host/oot_title_movie.h new file mode 100644 index 0000000..0ddd32f --- /dev/null +++ b/host/oot_title_movie.h @@ -0,0 +1,71 @@ +#ifndef OOT_TITLE_MOVIE_H +#define OOT_TITLE_MOVIE_H + +#include + +enum OotMovieFile { OOT_MOVIE_NONE, OOT_MOVIE_TITLE, OOT_MOVIE_OTHER }; +enum OotMovieFile oot_movie_file(const char *path); +void oot_movie_file_change(enum OotMovieFile kind, int delta); +int hos_movie_cover_begin(float ratio); +int hos_movie_cover_viewport(uint64_t *y, uint64_t *height); +int oot_movie_cover_recent(void); + +/* (Triforce) A game menu open over the title's filled movie. The filled movie has no menu sides (it is the picture, edge + to edge), but a menu opened over it is drawn as in play: with the Insert menu's Ultrawide menus row on Centred its + backdrop takes the middle 16:9, and the sides beside it are the renderer's (blurred or black). Seen in the game: with the + sides off for the movie's sake the file select's blurred backdrop stood in the middle of the sharp movie, a seam at each + side. So the title alone and a menu over it have to be told apart. + What tells them apart is the game's own menu screens: every menu screen's update calls host/oot_menu.c each frame it + runs (nx2/oot_patches.py patch_menu_tick), with the screen, whose first word is its class. The title's own list + (0x84c106e8, Continue and the rest) is such a screen too and is the title, so "some menu screen runs" will not do. + A menu over the title is one of: + - the system menus' backdrop itself (host/oot_wide_hud.h's keep class 1), where it runs as a screen: the very thing + that is drawn in the middle; + - the screens the title's list opens: the file select, the chosen file's box (host/hos_bench.c names both), and the + game's Options (host/oot_menu.c OPTIONS_SCREEN_VTABLE). + None of them runs while the title alone shows, so the title cannot be taken for a menu. */ +static inline int oot_title_menu_class(uint64_t screen_class) { + return screen_class == 0x84c04fb0ULL || /* the pause and system menus' backdrop */ + screen_class == 0x84c0eba0ULL || /* the file select */ + screen_class == 0x84c0f840ULL || /* the chosen file's box */ + screen_class == 0x84c0f108ULL; /* the game's Options */ +} +/* host/oot_menu.c, each frame a menu screen runs: its class */ +void oot_menu_screen_tick(uint64_t screen_class); +/* 1 while such a menu ran within the last OOT_MENU_PRESENTS presents of the game (its screens run once a frame; a frame + or two can pass between a screen's last update and the last picture that shows it) */ +#define OOT_MENU_PRESENTS 3 +int oot_menu_over_movie(void); +/* The same without a word in the log: for the renderer, which asks whether the blur of the last picture it sees drawn is + such a menu's centred backdrop or the item wheel's whole one (MkwVkHost.wide_backdrop, gpu/vk/wide_sides_rule.h). The + item wheel is play's: none of these screens runs with it */ +int oot_menu_backdrop_runs(void); +static inline int oot_menu_recent(int64_t now, int64_t ran) { return ran >= 0 && now - ran <= OOT_MENU_PRESENTS; } + +/* The menu sides' margin the renderer is given (MkwVkHost.wide_menus, host/rx_backend.c): none while the filled title + movie alone shows; the picture's own (hos_wide_margin) in play, and with a menu open over the movie */ +static inline float oot_wide_menu_margin(float margin, int movie_covers, int menu_over_it) { + return movie_covers && !menu_over_it ? 0.0f : margin; +} + +static inline int oot_title_cover_ratio(float ratio) { + /* Allow the same 1% tolerance as the output shape check: picture widths round to 8 pixels. */ + return ratio > 16.0f / 9.0f && ratio <= (12.0f / 5.0f) * 1.01f; +} + +/* The SetViewport site at main+0x284824 passes y and height in target pixels and the picture's + hos_wide_ratio. Return 1 with the viewport grown and centred, or 0 with both values untouched. + At 12:5 the crop still shows 800 of 1080 lines; beyond it keep the whole movie in the middle. */ +static inline int oot_title_movie_cover(float ratio, int32_t *y, int32_t *height) { + if (!oot_title_cover_ratio(ratio) || *height <= 0) + return 0; + const int64_t covered = (int64_t)((double)*height * ratio * 9 / 16 + 0.5); + const int64_t top = (int64_t)*y - (covered - *height) / 2; + if (covered > INT32_MAX || top < INT32_MIN) + return 0; + *y = (int32_t)top; + *height = (int32_t)covered; + return 1; +} + +#endif diff --git a/host/oot_wide_hud.c b/host/oot_wide_hud.c index d344991..5df74bd 100644 --- a/host/oot_wide_hud.c +++ b/host/oot_wide_hud.c @@ -3,7 +3,7 @@ at 0x80794368), and the Ultrawide HUD row's setting. The Insert menu's "Ultrawide HUD" row (ultrawide_hud= in the options file): 0 the middle, as before; 1 the screen's - edges. HOS_WIDE_HUD=<0|1> over it. Read once, at the start: the hearts', the item slot's and the small map's panes + edges. HOS_WIDE_HUD=<0|1> over it. Read once, at the start: the edge-anchored HUD panes are moved in the layouts as the game loads them (host/prompts.c build_layouts asks hos_wide_hud_out). Lab switches: HOS_WIDE_LOG=1 names each screen class the first time its projection is set (its address and where it was put); HOS_WIDE_SHIFT==,... moves whole layouts to a side, to find out what a class draws. */ diff --git a/host/oot_wide_hud.h b/host/oot_wide_hud.h index b0a8d92..3940996 100644 --- a/host/oot_wide_hud.h +++ b/host/oot_wide_hud.h @@ -11,14 +11,14 @@ (oot_hud_row can also move a whole layout out to one side, which the lab's HOS_WIDE_SHIFT uses to find out what a screen draws. No layout of the game's is placed that way: see below.) - The Insert menu's "Ultrawide HUD" row on Screen edges puts the hearts and the item slot in the picture's top corners - and the small map at its right edge. Those are moved inside their layouts, by oot_hud_out, because a projection + The Insert menu's "Ultrawide HUD" row on Screen edges places the side HUD, notices, and edge-anchored action states at their + authored offsets from the picture's edges. Those are moved inside their layouts, by oot_hud_out, because a projection cannot do it: PlayerStatus_00 holds the hearts (on a pane at the grid's top left corner) and the item slot (on one at its top right) together, and MapMenu_00 is the small map and the pause menu's whole-screen map in one layout, whose projection is not set again as the menu opens (tried: the menu's map sat off to the right). nx2/prompt_assets.py HUD_SIDE_PANES lists the panes, host/prompts.c build_layouts writes them as the game loads its layouts, so the row is read once, at the start. Layouts that follow something in the 3D world (the targeting pointer, an enemy's bar, a - speech balloon) and the action buttons stay in the middle. */ + speech balloon) stay in the middle. Only the right-hand action-button state moves. */ #ifndef OOT_WIDE_HUD_H #define OOT_WIDE_HUD_H #include diff --git a/host/posix/display_sdl.c b/host/posix/display_sdl.c index 2babf0a..ea3ae66 100644 --- a/host/posix/display_sdl.c +++ b/host/posix/display_sdl.c @@ -11,6 +11,7 @@ the game gets none of it; the capture it had comes back when the menu closes. */ #include "../hos.h" #include "../hos_sdl.h" +#include "../hos_screens.h" /* ((Triforce) the connected screens, for the Output resolution) */ /* (the window's app id: the applications menu's entry names it as its StartupWMClass, builder/linux/hookshot_builder.py) */ #define HOS_APP_ID "io.github.NotRexed.Hookshot" @@ -178,6 +179,34 @@ static void menu_mouse(int open) { captured_before_menu = 0; } } +/* ((Triforce) host/hos_screens.h) Every connected display, read once on the main thread in hos_display_init (SDL's video + calls belong to it): SDL's list with the main display first, which is the one the window opens on as far as the host + can say (the compositor places it); from an SDL without the list, the main display alone, by the size already read */ +static HosScreen screens[16]; +static int screens_n; +static void screens_read(int main_w, int main_h) { + HosSdlDisplay d[16]; + const int n = hos_sdl_displays(d, 16); + screens_n = 0; + for (int i = 0; i < n; i++) { + if (d[i].w <= 0 || d[i].h <= 0) continue; + HosScreen *s = &screens[screens_n]; + memset(s, 0, sizeof *s); + s->w = d[i].w, s->h = d[i].h, s->opens = screens_n == 0; + snprintf(s->name, sizeof s->name, "%s", d[i].name); + screens_n++; + } + if (!screens_n && main_w > 0 && main_h > 0) { + memset(&screens[0], 0, sizeof screens[0]); + screens[0].w = main_w, screens[0].h = main_h, screens[0].opens = 1; + screens_n = 1; + } +} +int hos_screens(HosScreen *out, int cap) { + const int n = screens_n < cap ? screens_n : cap; + memcpy(out, screens, (size_t)n * sizeof *out); + return n; +} static int sdl_ready; int hos_display_owns_sdl(void) { return sdl_ready; } /* (controllers stay on this thread while it runs SDL) */ @@ -205,12 +234,18 @@ int hos_display_init(void) { fprintf(stderr, "display: SDL_Init: %s: no window\n", hos_sdl_error()); return -1; } - int w, h; + int w = 0, h = 0; if (hos_sdl_desktop_size(&w, &h)) hos_posix_window[1] = w, hos_posix_window[2] = h; + screens_read(w, h); /* ((Triforce) every display, on this thread: the game's asks later, hos_screens) */ sdl_ready = 1; return 1; } +/* (Triforce) The size, in pixels, of the display the game's window opens on, for the Output resolution + (host/nn_applet.c): the desktop's main display, as hos_display_init read it before the game; 0 x 0 with no SDL or no + display (HOS_HEADLESS). A window on another display keeps the picture it started with, fitted into it. */ +void hos_screen_size(int *w, int *h) { *w = hos_posix_window[1], *h = hos_posix_window[2]; } + /* the game's thread, when NVN is up (hos_main.c): the window is made on the main thread, which waits for this */ void hos_display_start(void) { if (getenv("HOS_HEADLESS") || !sdl_ready) { /* no window: the renderer still draws, offscreen (screenshots) */ @@ -229,7 +264,7 @@ void hos_display_loop(void) { HosSdlEvent e; while (!__atomic_load_n(&start_asked, __ATOMIC_ACQUIRE)) hos_sdl_wait_event(&e, 10); /* (nothing to show yet) */ extern float hos_aspect_ratio; - /* (the picture's shape when Monitor's shape set one, wider or narrower than 16:9: 960 x 720 for 4:3, 1720 x 720 for 21:9) */ + /* (the picture's shape when it is not 16:9, the Output resolution's own or the Ultrawide row's: 960 x 720 for 4:3, 1728 x 720 for 3840 x 1600) */ int win_w = hos_aspect_ratio > 0.0f ? (int)(720 * hos_aspect_ratio + 0.5f) : 1280, win_h = 720; if (getenv("HOS_WINDOW_SIZE")) { int w = 0, h = 0; diff --git a/host/prompts.c b/host/prompts.c index 32869e9..f8e9199 100644 --- a/host/prompts.c +++ b/host/prompts.c @@ -508,7 +508,7 @@ static void ring_places(const int *bind, int place[4]) { - the ocarina hint's icons moved apart for the wide ones bound (prompts//hint.bin, nx2/prompt_assets.py HINTS: "HPHN", u32 count of pad inputs, each one's icon's extra width (f32), u32 panes; each: u32 offset, u8 slot, 3 bytes, f32 x): each icon the one before's extra further on, the last one where it is; - - the hearts, the item slot and the small map out at a wide picture's sides (prompts/wide.bin, nx2/prompt_assets.py HUD_SIDE_PANES: "HPWD", u32 + - the edge-anchored HUD out at a wide picture's sides (prompts/wide.bin, nx2/prompt_assets.py HUD_SIDE_PANES: "HPWD", u32 count; each: u32 offset, i8 side, 3 bytes, f32 x), with the Insert menu's Ultrawide HUD row on Screen edges (host/oot_wide_hud.h); none when all are as the game has them (the game's own file) */ @@ -602,7 +602,7 @@ static int build_layouts(char *out, size_t cap) { snprintf(path, sizeof path, "%sprompts/Common.blarc", dir); snprintf(keypath, sizeof keypath, "%sprompts/Common.blarc.key", dir); ok = write_patched(path, out, keypath, h, runs, nruns); - hos_log("prompts: the Talk ring's A B X Y at places %d %d %d %d, the ocarina hint %s, the hearts, item slot and map %s%s", + hos_log("prompts: the Talk ring's A B X Y at places %d %d %d %d, the ocarina hint %s, edge-anchored HUD %s%s", place[0], place[1], place[2], place[3], xs ? "spread" : "as is", wxs ? "at the picture's sides" : "as is", ok ? "" : ": could not be written"); } diff --git a/host/rx_backend.c b/host/rx_backend.c index 27d7e3e..bf5f673 100644 --- a/host/rx_backend.c +++ b/host/rx_backend.c @@ -3,6 +3,8 @@ executable. Decided at rx_start, before any other rx_* call; a DLL that is missing or finds no usable Vulkan device leaves the WebGPU renderer in place (logged). */ #include "hos.h" +#include "oot_title_movie.h" +#include #include #include #define WIN32_LEAN_AND_MEAN @@ -60,6 +62,7 @@ void hos_mic_select(int mode, const char *name, int index); void hos_bind(int set, int button, int slot, int code); int hos_prompts_face(void); /* prompts.c */ int hos_prompts_pad_face(void); +#include "hos_screens.h" /* ((Triforce) display.c: the connected screens, for the Insert menu's Output resolution) */ #if defined(A64_WRITE_TRACK) && !defined(__EMSCRIPTEN__) void hos_mark_written(const void *p, size_t n); #endif @@ -275,8 +278,17 @@ static float host_wide_menus(uint32_t keep_mask) { /* (MkwVkHost.wide_menus) * static int looked; if (!looked) looked = 1, forced = getenv("HOS_WIDE_KEEP"); hos_wide_keep_mask = forced ? (uint32_t)strtoul(forced, NULL, 16) : keep_mask; - return hos_wide_margin; + /* ((Triforce) no sides beside the filled title movie, but those the row asks for beside a menu opened over it: both + asked every time, each says its own changes in the log) */ + int rx_option(int id, int otherwise); + const int covers = oot_movie_cover_recent(), menu = oot_menu_over_movie() || rx_option(HOS_OPT_MODS_MUSIC, 0) == 2; + return oot_wide_menu_margin(hos_wide_margin, covers, menu); } +static int host_wide_backdrop(void) { + int rx_option(int id, int otherwise); + /* The renderer owns Mods over the title; no guest screen class reports it to oot_menu_screen_tick. */ + return oot_menu_backdrop_runs() || rx_option(HOS_OPT_MODS_MUSIC, 0) == 2; +} /* (MkwVkHost.wide_backdrop) */ int hos_mouse_pointer(MkwVkPointer *out); /* display.c, posix/display_sdl.c */ int hos_sdl_gyro_status(void); /* pad_sdl.c */ extern const char *hos_romfs_dir; /* nn_fs.c, set by hos_main.c */ @@ -297,6 +309,18 @@ int hos_vk_take_key_press(int key) { #define host_take_key_press NULL #endif +/* ((Triforce) MkwVkHost.screens: the window code's list, as the interface has a screen) */ +static int host_screens(MkwVkScreen *out, int cap) { + HosScreen list[16]; + int n = hos_screens(list, cap < 16 ? cap : 16); + for (int i = 0; i < n; i++) { + memset(&out[i], 0, sizeof out[i]); + out[i].w = list[i].w > 0 ? (uint32_t)list[i].w : 0, out[i].h = list[i].h > 0 ? (uint32_t)list[i].h : 0; + out[i].opens = list[i].opens; + snprintf(out[i].name, sizeof out[i].name, "%s", list[i].name); + } + return n; +} static const MkwVkHost vk_host = { MKWVK_API_VERSION, host_log, hos_guest_base, hos_guest_size, hos_gpu_ptr, nvn_gpu_guest, nvn_gpu_read, nvn_gpu_write, host_collect, host_free_pages, host_mark_written, hos_ticks, hos_now_ns, nvn_tex_layout, @@ -304,7 +328,7 @@ static const MkwVkHost vk_host = { hos_gpu_maps_generation, nvn_vmap_generation, hos_reserved_cpus, host_collect_in, host_guest_alloc, host_watch_guest_writes, hos_pad_raw, hos_binding, hos_bind, host_aspect_ratio, host_take_key_press, hos_mouse_pointer, hos_mic_count, hos_mic_name, hos_mic_select, hos_sdl_gyro_status, hos_log_flush, hos_prompts_face, - host_romfs_dir, host_wide_menus, hos_bench_state, hos_prompts_pad_face, + host_romfs_dir, host_wide_menus, hos_bench_state, hos_prompts_pad_face, host_screens, host_wide_backdrop, }; static const MkwVkRenderer *vk; /* the Vulkan back end, when it was chosen and started */ @@ -704,6 +728,9 @@ int rx_memory_holders(char *out, size_t n) { } /* (nvn_native.c: the CPU set an event's value) in order with the submits, for the GPU's waits on it */ int rx_option(int id, int otherwise) { return vk && vk->option ? vk->option(id) : otherwise; } +/* ((Triforce, 11-22, N64 Classic) the cursor under its TV's curve: where the game's picture under it was drawn (vk_api.h + screen_point); as it is without the renderer's answer */ +void rx_screen_point(int *x, int *y, int w, int h) { if (vk && vk->screen_point) vk->screen_point(x, y, w, h); } void rx_option_set(int id, int value) { if (vk && vk->option_set) vk->option_set(id, value); } void rx_nvn_event_signal(uint64_t gpu, uint32_t value) { if (vk && vk->nvn_event_signal) vk->nvn_event_signal(gpu, value); diff --git a/host/save_files.c b/host/save_files.c new file mode 100644 index 0000000..f04b44a --- /dev/null +++ b/host/save_files.c @@ -0,0 +1,274 @@ +/* (Triforce) Save files, as the Nintendo 64 game had them: the title asks which file to play, and the game's saves and + autosaves live in that file. host/save_files.h has what a file is and the form of triforce_files.txt; this file has + what is the game folder's and the menu's. + + - On by default (11-23); HOS_SAVE_FILES=0 (triforce_env.txt) turns it off. While off the game's folder is the one it + always had, and nothing is read or written here. Off too when the folder was named on the command line (--user). + - hos_save_files_start (host/hos_main.c, before the game's memory is made): the folder of the file the last choice + named, which becomes hos_user_dir. The game mounts it at its start, reads its saves once, before its title shows, + and keeps them in memory (tried: files taken out of the mounted folder at the title were still listed and loaded): + so another file is another start, and never a folder changed under a running game. + - hos_save_files_frame (host/nvn_native.c, at each present): once the renderer answers, the files are named to the + menu (HOS_OPT_FILES_TEXT, _ADD, _COUNT: gpu/vk/save_file_rows.h), which asks at the title which to play. A file + chosen that is not this run's (HOS_OPT_FILES_ASK) is written to triforce_files.txt as the next start's, with the + time, and the menu is told (HOS_OPT_FILES_SAID): it restarts the game, as its Restart now does. The start that + follows a choice says so to the menu (which asks at the title all the same: that is where a file is changed again). + - A file's save is never opened here: whether it has one, when it was last written and which of its files holds its + picture are its folder's own (the menu reads the picture out of that file itself). Where it was played last, its + stones, medallions and hearts are told by host/hos_main.c as it is played (hos_save_card_note) and kept beside it, + triforce_card.txt: what the game's own load list shows of a save, without the save's data read. */ +#include "hos.h" +#include "hos_paths.h" +#include +#include +#include +#include +#include "../gpu/vk/vk_api.h" +#include "save_files.h" + +int rx_option(int id, int otherwise); +void rx_option_set(int id, int value); + +#define FILES_FILE "triforce_files.txt" +enum { FILES_PATH = MAX_PATH + 64, FILES_MOST = 4096 }; + +static SaveFiles files; +static int started; /* hos_save_files_start chose a folder: the files are this run's */ +static int after_choice; /* this start follows a file's choice */ +static char files_path[FILES_PATH]; /* triforce_files.txt */ +static char base_dir[FILES_PATH]; /* file 1's folder */ +static char user_dir[FILES_PATH]; /* this run's */ + +/* On unless HOS_SAVE_FILES=0 ((Triforce) 11-23, the owner's word: on by default; File 1 is the folder the game always had, so + a start with no triforce_files.txt plays the saves it always did). Read once */ +int hos_save_files_on(void) { + static int on = -1; + if (on < 0) { + const char *e = getenv("HOS_SAVE_FILES"); + on = !(e && e[0] == '0' && !e[1]); + } + return on; +} + +static void files_read(void) { + static char text[FILES_MOST + 1]; + FILE *f = fopen(files_path, "rb"); + const size_t n = f ? fread(text, 1, FILES_MOST, f) : 0; + if (f) fclose(f); + text[n] = 0; + for (size_t i = 0; i < n; i++) + if (!text[i]) text[i] = ' '; + save_files_parse(&files, text); +} + +/* triforce_files.txt whole, under another name first: 1 written */ +static int files_save(void) { + static char text[FILES_MOST]; + char fresh[FILES_PATH + 8]; + const size_t n = save_files_write(&files, text, sizeof text); + if (!n) return 0; + snprintf(fresh, sizeof fresh, "%s.new", files_path); + FILE *f = fopen(fresh, "wb"); /* (its lines end the same on Windows and Linux) */ + const int ok = f && fwrite(text, 1, n, f) == n; + if ((f && fclose(f)) || !ok || !MoveFileExA(fresh, files_path, MOVEFILE_REPLACE_EXISTING)) { + remove(fresh); + hos_log("save files: %s could not be written", files_path); + return 0; + } + return 1; +} + +/* host/hos_main.c, at the start, the game's folder known and no --user given: the folder the game saves in this run. + game_dir: the game folder; base_user: the folder the game always had. Off: base_user itself */ +const char *hos_save_files_start(const char *game_dir, const char *base_user) { + if (!hos_save_files_on()) return base_user; + if (snprintf(files_path, sizeof files_path, "%s%c%s", game_dir, strchr(game_dir, '\\') ? '\\' : '/', FILES_FILE) >= (int)sizeof files_path || + !save_files_folder(base_user, 0, base_dir, sizeof base_dir)) { + hos_log("save files: the game folder's path is too long: the game's own folder is used, %s", base_user); + return base_user; + } + files_read(); + if (!save_files_folder(base_dir, files.current, user_dir, sizeof user_dir)) files.current = 0, snprintf(user_dir, sizeof user_dir, "%s", base_dir); + after_choice = save_files_chosen_now(&files, (int64_t)time(NULL)); + if (files.chosen) { /* (taken: a start after this one asks again) */ + files.chosen = 0; + files_save(); + } + started = 1; + hos_log("save files: file %d of %d, \"%s\": its saves are in %s%s", files.current + 1, SAVE_FILES, files.names[files.current], user_dir, + after_choice ? " (chosen at the title: the game restarted for it)" : ""); + return user_dir; +} + +/* ---- the menu's side: gpu/vk/save_file_rows.h ---- */ +static void to_menu(const char *text) { + for (const char *p = text; *p; p++) rx_option_set(HOS_OPT_FILES_TEXT, (unsigned char)*p); +} +/* a time as the game's own load list writes a save's: 11/18/2026 1:40 a.m. ("" for none) */ +static void game_time(time_t t, char *out, size_t cap) { + const struct tm *tm = t > 0 ? localtime(&t) : NULL; + out[0] = 0; + if (tm) snprintf(out, cap, "%d/%d/%d %d:%02d %s", tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900, tm->tm_hour % 12 ? tm->tm_hour % 12 : 12, tm->tm_min, + tm->tm_hour < 12 ? "a.m." : "p.m."); +} +static time_t unix_of(const FILETIME *ft) { /* (a FILETIME: 100 ns since 1601; 0 when it is none) */ + const uint64_t v = (uint64_t)ft->dwHighDateTime << 32 | ft->dwLowDateTime; + return v > 116444736000000000ULL ? (time_t)((v - 116444736000000000ULL) / 10000000ULL) : 0; +} +/* What a file's card shows of its save, from its folder alone (no save is opened here): when its account.sav was last + written, in `when` ("" when it has no save yet, or the time cannot be told), and where its slots are, in `picture`: the + start of their caption files' paths, up to the slot's number ("" none). The game keeps a save's picture and its time + in that file, and the menu reads them from there itself (gpu/vk/save_file_rows.h jpeg_in, caption_time). 1 when the + file has a save: a slot, not the account.sav alone */ +static int last_saved(int file, char *when, size_t when_cap, char *picture, size_t picture_cap) { + char dir[FILES_PATH], pat[FILES_PATH + 96]; + WIN32_FIND_DATAA fd, found; + int saved = 0; + when[0] = picture[0] = 0; + if (!save_files_folder(base_dir, file, dir, sizeof dir)) return 0; + snprintf(pat, sizeof pat, "%s\\save\\*", dir); + HANDLE h = FindFirstFileA(pat, &fd); + if (h == INVALID_HANDLE_VALUE) return 0; + do { + if (fd.cFileName[0] == '.' || strlen(fd.cFileName) > 40) continue; + snprintf(pat, sizeof pat, "%s\\save\\%s\\account.sav", dir, fd.cFileName); + HANDLE a = FindFirstFileA(pat, &found); + if (a == INVALID_HANDLE_VALUE) continue; + FindClose(a); + const time_t t = unix_of(&found.ftLastWriteTime); + game_time(t, when, when_cap); + for (int slot = 0; slot < 12; slot++) { /* (the game looks for slot_00 to slot_11) */ + snprintf(pat, sizeof pat, "%s\\save\\%s\\slot_%02d\\caption.sav", dir, fd.cFileName, slot); + HANDLE s = FindFirstFileA(pat, &found); + if (s == INVALID_HANDLE_VALUE) continue; + FindClose(s); + saved = 1; + } + /* ((Triforce) 11-18, his picture of the game's own load list beside the card: "the screenshot doesn't match the last + autosave either nor does the time". The slot written last cannot be told from the disk: the game writes them all + again whenever it saves one. Where the slots are, then, and the menu reads each one's own time out of it) */ + if (saved && snprintf(picture, picture_cap, "%s\\save\\%s\\slot_", dir, fd.cFileName) >= (int)picture_cap) picture[0] = 0; + /* ((Triforce) 11-18, his picture: File 2, a new game started and not yet saved, said "Saved game" with no picture. The + game makes account.sav as it starts on a file: a file has a save once it has a slot) */ + if (!saved) when[0] = 0; + break; + } while (FindNextFileA(h, &fd)); + FindClose(h); + return saved; +} +/* ---- a file's card: host/save_files.h SaveCard ---- */ +#define CARD_FILE "triforce_card.txt" +static int card_path(const char *dir, char *out, size_t cap) { + return snprintf(out, cap, "%s%c" CARD_FILE, dir, strchr(dir, '\\') ? '\\' : '/') < (int)cap; +} +/* A file's card as its folder keeps it: nothing of it when the file was not played with this yet */ +static void card_of(int file, SaveCard *card) { + char dir[FILES_PATH], path[FILES_PATH + 40], text[512]; + memset(card, 0, sizeof *card); + if (!save_files_folder(base_dir, file, dir, sizeof dir) || !card_path(dir, path, sizeof path)) return; + FILE *f = fopen(path, "rb"); + if (!f) return; + const size_t n = fread(text, 1, sizeof text - 1, f); + fclose(f); + text[n] = 0; + for (size_t i = 0; i < n; i++) + if (!text[i]) text[i] = ' '; + save_card_parse(card, text); +} +/* ---- the card kept. Two of the game's threads come here, Link's update and whichever one saves: what they share is under + one lock, held for a card's writing and no longer ---- */ +static volatile char card_busy; +static SaveCard card_kept; /* what this file's triforce_card.txt has */ +static SaveCard card_seen; /* the place, the items and the hearts as last told */ +static int card_known, card_told; /* the kept card was read; something was told this run */ +static void card_lock(void) { + while (__atomic_test_and_set(&card_busy, __ATOMIC_ACQUIRE)) {} +} +static void card_unlock(void) { __atomic_clear(&card_busy, __ATOMIC_RELEASE); } +/* (with the lock held) the card written into this run's folder, whole, under another name first */ +static void card_keep(const SaveCard *card) { + char path[FILES_PATH + 40], fresh[FILES_PATH + 48], text[512]; + const size_t n = save_card_write(card, text, sizeof text); + if (!n || !card_path(user_dir, path, sizeof path)) return; + snprintf(fresh, sizeof fresh, "%s.new", path); + FILE *f = fopen(fresh, "wb"); /* (its lines end the same on Windows and Linux) */ + const int ok = f && fwrite(text, 1, n, f) == n; + if ((f && fclose(f)) || !ok || !MoveFileExA(fresh, path, MOVEFILE_REPLACE_EXISTING)) { + remove(fresh); + static int said; + if (!said++) hos_log("save files: %s could not be written: this file's card stays as it was", path); + return; + } + card_kept = *card; +} +/* host/nn_fs.c, a file of the save opened to be written (any of the game's threads): a slot's is that slot saved in, now. + Kept at once, with the place, the items and the hearts as last told. ((Triforce) 11-18: it was kept at Link's next + update. He saved from the pause menu, where Link is not updated, and went to the title: the card never had the save.) + The game writes a slot's caption and its progress one after the other: one save, one time */ +void hos_save_card_wrote(const char *guest_path) { + const int slot = started ? save_card_slot_of(guest_path) : -1; + if (slot < 0) return; + const int64_t now = (int64_t)time(NULL); + card_lock(); + if (!card_known) card_known = 1, card_of(files.current, &card_kept); + SaveCard card = card_told ? card_seen : card_kept; + card.slot1 = slot + 1; + card.saved = card_kept.slot1 == slot + 1 && now >= card_kept.saved && now - card_kept.saved < 10 ? card_kept.saved : now; + if (!save_card_same(&card, &card_kept)) card_keep(&card); + card_unlock(); +} +/* host/hos_main.c, every two seconds at Link's update while a save is loaded (the game's thread; now_ns: hos_now_ns): the + map he is on (its own name), the stones and medallions he holds (SAVE_CARD_* bits) and the game's count of his life (0: + not known). What the next save is kept with; and kept by itself when it is not what is kept already, five seconds + apart at most, so that a file played and not saved in has its card too */ +void hos_save_card_note(const char *map, int items, int life, int64_t now_ns) { + static int64_t next; + if (!started || !map || !map[0]) return; + SaveCard card; + memset(&card, 0, sizeof card); + save_card_place(map, card.place, sizeof card.place); + card.items = items & ((1 << SAVE_CARD_ITEMS) - 1), card.hearts = save_card_hearts(life); + card_lock(); + if (!card_known) card_known = 1, card_of(files.current, &card_kept); + card.slot1 = card_kept.slot1, card.saved = card_kept.saved; /* (the slot saved in last: hos_save_card_wrote's) */ + card_seen = card, card_told = 1; + if (now_ns >= next && !save_card_same(&card, &card_kept)) next = now_ns + 5000000000LL, card_keep(&card); + card_unlock(); +} +/* host/achievements.c: the folder of the file this run plays, where what that file earned is kept; NULL while the save + files are off (the game folder keeps it then). *first: it is File 1, which was the game's only one before */ +const char *hos_save_files_dir(int *first) { + if (!started) return NULL; + *first = files.current == 0; + return user_dir; +} +static void name_files(void) { + for (int i = 0; i < SAVE_FILES; i++) { + char when[32], picture[FILES_PATH + 96], shown[SAVE_CARD_PLACE + 96], made[32] = ""; + SaveCard card; + const int saved = last_saved(i, when, sizeof when, picture, sizeof picture); + card_of(i, &card); + game_time((time_t)card.saved, made, sizeof made); + /* (its place, its items, its hearts; then the slot saved in last, -1 not known, and when, as the game writes a time) */ + snprintf(shown, sizeof shown, "%s|%x|%d|%d|%s", card.place, (unsigned)card.items, card.hearts, card.slot1 - 1, card.slot1 ? made : ""); + to_menu(files.names[i]), to_menu("\n"), to_menu(when), to_menu("\n"), to_menu(picture), to_menu("\n"), to_menu(shown); + rx_option_set(HOS_OPT_FILES_ADD, (saved ? HOS_FILE_SAVED : 0) | (i == files.current ? HOS_FILE_CURRENT : 0)); + } + rx_option_set(HOS_OPT_FILES_COUNT, SAVE_FILES | (after_choice ? HOS_FILES_CHOSEN : 0)); +} +/* host/nvn_native.c, at each present of the game's: the files named to the menu once it answers, and the file it chose + made the next start's */ +void hos_save_files_frame(void) { + static int named; /* (the present's thread alone) */ + if (!started) return; + const int ask = rx_option(HOS_OPT_FILES_ASK, -1); + if (ask < 0) return; /* (no renderer that shows them yet) */ + if (!named) named = 1, name_files(); + if (ask < 1 || ask > SAVE_FILES || ask - 1 == files.current) return; + const int was = files.current; + files.current = ask - 1, files.chosen = (int64_t)time(NULL); + const int kept = files_save(); + hos_log("save files: file %d, \"%s\", chosen: %s", ask, files.names[ask - 1], kept ? "the game starts again on it" : "it could not be kept, nothing changes"); + files.current = was, files.chosen = 0; /* (this run plays the file it started on, to its end) */ + rx_option_set(HOS_OPT_FILES_SAID, kept ? 1 : 2); +} diff --git a/host/save_files.h b/host/save_files.h new file mode 100644 index 0000000..14efd7a --- /dev/null +++ b/host/save_files.h @@ -0,0 +1,208 @@ +/* (Triforce) Save files, as the Nintendo 64 game had them: a few files to choose from at the title, each a playthrough of + its own. host/save_files.c has what is the game folder's and the menu's. Nothing of the host is in here: + tests/test_save_files.py compiles it alone. + + The game keeps all it saves under one folder (hos_user_dir: account.sav, option.sav and its slot_NN folders, the saves + and the autosaves of one playthrough), which it reads once, at its start, before its title shows. A file is such a + folder: file 1 the folder the game always had ("user"), file N that folder's name with "-N" after it ("user-2"). The + game is started on one of them and knows of no other; another file is another start (host/hos_relaunch.c). + + triforce_files.txt in the game folder keeps which, and their names: + current=2 the file the next start plays (1 without the line, or with one that names none) + chosen=1763456789 when a file was chosen for a restart (unix time): the start that follows knows it is that restart + 1=Spanky a file's name, SAVE_FILE_NAME bytes at most ("File 1" without the line) */ +#ifndef HOS_SAVE_FILES_H +#define HOS_SAVE_FILES_H +#include +#include +#include +#include +#include + +enum { SAVE_FILES = 3, SAVE_FILE_NAME = 24, SAVE_FILES_CHOSEN_S = 180 /* (a restart is a few seconds; a start long after it asks again) */ }; + +typedef struct SaveFiles { + int current; /* 0 to SAVE_FILES - 1 */ + int64_t chosen; /* unix time of the choice a restart follows, 0 none */ + char names[SAVE_FILES][SAVE_FILE_NAME + 1]; +} SaveFiles; + +static inline void save_files_defaults(SaveFiles *f) { + memset(f, 0, sizeof *f); + for (int i = 0; i < SAVE_FILES; i++) snprintf(f->names[i], sizeof f->names[i], "File %d", i + 1); +} + +/* triforce_files.txt's text read over the defaults. A line that is none of its three is passed over, a file's number that + is none and an empty name are not taken, a name is cut at SAVE_FILE_NAME bytes (never inside a letter) */ +static inline void save_files_parse(SaveFiles *f, const char *text) { + save_files_defaults(f); + for (const char *line = text; *line; ) { + const char *end = line; + while (*end && *end != '\n') end++; + size_t n = (size_t)(end - line); + while (n && (line[n - 1] == '\r' || line[n - 1] == ' ' || line[n - 1] == '\t')) n--; + if (n > 8 && !memcmp(line, "current=", 8)) { + const long v = strtol(line + 8, NULL, 10); + if (v >= 1 && v <= SAVE_FILES) f->current = (int)v - 1; + } else if (n > 7 && !memcmp(line, "chosen=", 7)) { + const long long v = strtoll(line + 7, NULL, 10); + f->chosen = v > 0 ? v : 0; + } else if (n > 2 && line[0] >= '1' && line[0] < '1' + SAVE_FILES && line[1] == '=') { + size_t len = n - 2; + if (len > SAVE_FILE_NAME) { + len = SAVE_FILE_NAME; + while (len && ((unsigned char)line[2 + len] & 0xC0) == 0x80) len--; + } + int plain = len > 0; + for (size_t i = 0; i < len; i++) plain &= (unsigned char)line[2 + i] >= 32; + if (plain) memcpy(f->names[line[0] - '1'], line + 2, len), f->names[line[0] - '1'][len] = 0; + } + line = *end ? end + 1 : end; + } +} + +/* triforce_files.txt's text written into out: its length, 0 when cap is too small for it */ +static inline size_t save_files_write(const SaveFiles *f, char *out, size_t cap) { + int n = snprintf(out, cap, "# The save files (the title's file select): the one the next start plays, and their names.\ncurrent=%d\n", f->current + 1); + if (n < 0 || (size_t)n >= cap) return 0; + size_t at = (size_t)n; + if (f->chosen > 0) { + n = snprintf(out + at, cap - at, "chosen=%lld\n", (long long)f->chosen); + if (n < 0 || (size_t)n >= cap - at) return 0; + at += (size_t)n; + } + for (int i = 0; i < SAVE_FILES; i++) { + n = snprintf(out + at, cap - at, "%d=%s\n", i + 1, f->names[i]); + if (n < 0 || (size_t)n >= cap - at) return 0; + at += (size_t)n; + } + return at; +} + +/* A file's folder: file 0 the folder the game always had (base), file N - 1 that name with "-N" after it. 1 when it fits */ +static inline int save_files_folder(const char *base, int file, char *out, size_t cap) { + if (file < 0 || file >= SAVE_FILES) return 0; + size_t n = strlen(base); + while (n > 1 && (base[n - 1] == '/' || base[n - 1] == '\\')) n--; /* ("user\" and "user": the same folder) */ + const int len = file ? snprintf(out, cap, "%.*s-%d", (int)n, base, file + 1) : snprintf(out, cap, "%.*s", (int)n, base); + return len > 0 && (size_t)len < cap; +} + +/* 1 when this start follows a file's choice (now: unix time): the restart the choice asked for */ +static inline int save_files_chosen_now(const SaveFiles *f, int64_t now) { + return f->chosen > 0 && now >= f->chosen && now - f->chosen <= SAVE_FILES_CHOSEN_S; +} + +/* ---- A file's card on the file select: what the game's own load list shows of a save, kept by the host as it is played ---- + The game shows a save's place, hearts, Spiritual Stones and medallions from the save's own data, whose form this + repository does not know and does not read. The same is known while the game runs: host/hos_main.c tells it as the file is + played (hos_save_card_note), and it is kept in the file's folder, triforce_card.txt: + place=Kokiri Forest where Link was (the map's own name, its words set apart) + items=1c9 SAVE_CARD_* bits, hex: the stones and medallions he holds + hearts=7 his heart containers, 0 when they are not known + slot=3 the slot the game saved in last while this file was played (host/nn_fs.c tells: a slot's file + saved=1763456789 opened to be written), and when (unix time): the save whose picture and time the card shows. + The slots' files cannot tell: the game writes them all again when it saves one */ +enum { SAVE_CARD_PLACE = 48, + SAVE_CARD_STONES = 3, /* bits 0 to 2: the Spiritual Stones of the forest, of fire, of water */ + SAVE_CARD_MEDALS = 6, /* bits 3 to 8: the medallions of light, forest, fire, water, spirit, shadow */ + SAVE_CARD_ITEMS = SAVE_CARD_STONES + SAVE_CARD_MEDALS, SAVE_CARD_HEARTS = 20 }; +typedef struct SaveCard { + char place[SAVE_CARD_PLACE + 1]; + int items, hearts; + int slot1; /* the slot saved in last, and 1; 0 not known */ + int64_t saved; /* when, unix time; 0 not known */ +} SaveCard; + +/* The slot a guest path of the save names ("save:/slot_03/caption.sav": 3), -1 when it names none of slot_00 to slot_11 */ +static inline int save_card_slot_of(const char *guest) { + const char *s = guest ? strstr(guest, "slot_") : NULL; + if (!s || s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9' || (s[7] != '/' && s[7] != '\\')) return -1; + const int slot = (s[5] - '0') * 10 + (s[6] - '0'); + return slot < 12 ? slot : -1; +} +/* (a map that is another in each of Link's ages says which at its name's end: the game's own load list does not) */ +static inline void save_card_trim_age(char *place) { + const size_t n = strlen(place); + if (n > 6 && (!strcmp(place + n - 6, " Adult") || !strcmp(place + n - 6, " Child"))) place[n - 6] = 0; +} + +/* A map's own name as a card shows it: "KokiriForest" is "Kokiri Forest", "Inside_GanonCastle01" "Inside Ganon Castle 01", + "DekuTree_B1F" "Deku Tree B1F". A space before a capital that follows a small letter (or a digit, when it begins a word), + and before a digit that follows a small letter; '_' a space */ +static inline void save_card_place(const char *map, char *out, size_t cap) { + size_t n = 0; + for (const char *p = map; *p && n + 2 < cap; p++) { + const unsigned char ch = (unsigned char)*p, before = p > map ? (unsigned char)p[-1] : 0; + const int upper = ch >= 'A' && ch <= 'Z', digit = ch >= '0' && ch <= '9'; + const int was_lower = before >= 'a' && before <= 'z', was_digit = before >= '0' && before <= '9'; + if (ch == '_' || ch < 32) { + if (n && out[n - 1] != ' ') out[n++] = ' '; + continue; + } + const int word = p[1] >= 'a' && p[1] <= 'z'; /* (a capital that begins a word, not one of a floor's name: B1F) */ + if (n && out[n - 1] != ' ' && ((upper && (was_lower || (was_digit && word))) || (digit && was_lower))) out[n++] = ' '; + out[n++] = (char)ch; + } + while (n && out[n - 1] == ' ') n--; + if (cap) out[n] = 0, save_card_trim_age(out); +} + +/* Heart containers from the game's own count of Link's life, which it keeps in quarters of a heart: 0 when the number is + not one (not whole hearts, under the three every game starts with, or over SAVE_CARD_HEARTS) */ +static inline int save_card_hearts(int life) { return life >= 12 && life <= 4 * SAVE_CARD_HEARTS && life % 4 == 0 ? life / 4 : 0; } + +/* triforce_card.txt's text read: what is not one of its lines is passed over, a number that is none is 0 */ +static inline void save_card_parse(SaveCard *c, const char *text) { + memset(c, 0, sizeof *c); + for (const char *line = text; *line; ) { + const char *end = line; + while (*end && *end != '\n') end++; + size_t n = (size_t)(end - line); + while (n && (line[n - 1] == '\r' || line[n - 1] == ' ')) n--; + if (n > 6 && !memcmp(line, "place=", 6)) { + size_t len = n - 6 > SAVE_CARD_PLACE ? SAVE_CARD_PLACE : n - 6; + while (len && ((unsigned char)line[6 + len] & 0xC0) == 0x80) len--; + memcpy(c->place, line + 6, len), c->place[len] = 0; + for (size_t i = 0; i < len; i++) + if ((unsigned char)c->place[i] < 32 || c->place[i] == '|') c->place[i] = ' '; + save_card_trim_age(c->place); /* (a card kept before the age was left out) */ + } else if (n > 6 && !memcmp(line, "items=", 6)) { + c->items = (int)(strtoul(line + 6, NULL, 16) & ((1u << SAVE_CARD_ITEMS) - 1)); + } else if (n > 7 && !memcmp(line, "hearts=", 7)) { + const long v = strtol(line + 7, NULL, 10); + c->hearts = v >= 1 && v <= SAVE_CARD_HEARTS ? (int)v : 0; + } else if (n > 5 && !memcmp(line, "slot=", 5)) { + const long v = line[5] >= '0' && line[5] <= '9' ? strtol(line + 5, NULL, 10) : -1; + c->slot1 = v >= 0 && v < 12 ? (int)v + 1 : 0; + } else if (n > 6 && !memcmp(line, "saved=", 6)) { + const long long v = strtoll(line + 6, NULL, 10); + c->saved = v > 0 ? v : 0; + } + line = *end ? end + 1 : end; + } +} +/* triforce_card.txt's text written into out: its length, 0 when cap is too small for it */ +static inline size_t save_card_write(const SaveCard *c, char *out, size_t cap) { + int n = snprintf(out, cap, "# What the file select shows of this save file: where it was played last, the stones and medallions held, the hearts,\n" + "# and the slot the game saved in last.\nplace=%s\nitems=%x\nhearts=%d\n", c->place, (unsigned)c->items, c->hearts); + if (n <= 0 || (size_t)n >= cap) return 0; + if (c->slot1) { + const int more = snprintf(out + n, cap - (size_t)n, "slot=%d\nsaved=%lld\n", c->slot1 - 1, (long long)c->saved); + if (more <= 0 || (size_t)more >= cap - (size_t)n) return 0; + n += more; + } + return (size_t)n; +} +static inline int save_card_same(const SaveCard *a, const SaveCard *b) { + return !strcmp(a->place, b->place) && a->items == b->items && a->hearts == b->hearts && a->slot1 == b->slot1 && a->saved == b->saved; +} + +/* host/save_files.c */ +void hos_save_card_note(const char *map, int items, int life, int64_t now_ns); +void hos_save_card_wrote(const char *guest_path); +int hos_save_files_on(void); +const char *hos_save_files_dir(int *first); +const char *hos_save_files_start(const char *game_dir, const char *base_user); +void hos_save_files_frame(void); +#endif diff --git a/host/save_tx.h b/host/save_tx.h index 6e3e3c8..bfbf23f 100644 --- a/host/save_tx.h +++ b/host/save_tx.h @@ -30,6 +30,7 @@ #include #include #include +#include #define SAVE_TX_BACKUPS 5 #define SAVE_TX_BACKUP_GAP_S 300 @@ -50,6 +51,26 @@ static int tx_crashed(void) { return save_tx_dead; } static time_t tx_now(void) { return save_tx_test_now ? save_tx_test_now : time(NULL); } + +/* ((Triforce, 11-23, ticket "Cannot launch into game after 0.7 update", Linux) The first thing a mount's working copy could not + do, said in the mount's note: the log only said "no working copy could be made", never which file or why. Called right + after the call that failed (its error: GetLastError on Windows, errno's text elsewhere) */ +static char save_tx_why[HOS_FS_PATH + 128]; +static void tx_why(const char *what, const char *path) { + if (save_tx_why[0]) return; +#ifdef _WIN32 + const unsigned long e = (unsigned long)GetLastError(); + snprintf(save_tx_why, sizeof save_tx_why, "%s %s (error %lu)", what, path, e); +#else + const int e = errno; + snprintf(save_tx_why, sizeof save_tx_why, "%s %s (%s)", what, path, strerror(e)); +#endif +} +static void tx_note_add(char *note, size_t cap, const char *what) { /* (after a recovery's note, when there is one) */ + if (!note || !cap) return; + const size_t n = strlen(note); + if (n + 1 < cap) snprintf(note + n, cap - n, "%s%s", n ? "; " : "", what); +} static int tx_exists(const char *p) { return GetFileAttributesA(p) != INVALID_FILE_ATTRIBUTES; } static int tx_is_dir(const char *p) { const DWORD a = GetFileAttributesA(p); @@ -107,9 +128,13 @@ static int tx_empty(const char *dir) { /* 1: a folder with nothing in it */ static int tx_copy_file(const char *src, const char *dst, int flush) { HANDLE in = CreateFileA(src, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (in == INVALID_HANDLE_VALUE) return 0; + if (in == INVALID_HANDLE_VALUE) { + tx_why("cannot open", src); + return 0; + } HANDLE out = CreateFileA(dst, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (out == INVALID_HANDLE_VALUE) { + tx_why("cannot make", dst); CloseHandle(in); return 0; } @@ -118,12 +143,12 @@ static int tx_copy_file(const char *src, const char *dst, int flush) { int ok = buf != NULL; while (ok) { DWORD got = 0, put = 0; - if (!ReadFile(in, buf, chunk, &got, NULL)) ok = 0; + if (!ReadFile(in, buf, chunk, &got, NULL)) ok = 0, tx_why("cannot read", src); else if (!got) break; - else if (!WriteFile(out, buf, got, &put, NULL) || put != got) ok = 0; + else if (!WriteFile(out, buf, got, &put, NULL) || put != got) ok = 0, tx_why("cannot write", dst); } free(buf); - if (ok && flush && !FlushFileBuffers(out)) ok = 0; + if (ok && flush && !FlushFileBuffers(out)) ok = 0, tx_why("cannot write out", dst); CloseHandle(out); CloseHandle(in); return ok; @@ -132,7 +157,10 @@ static int tx_copy_file(const char *src, const char *dst, int flush) { /* A folder with everything in it, links left out; dst is made. 1: every file copied */ static int tx_copy_tree(const char *src, const char *dst, int flush) { tx_make_dirs(dst); - if (!tx_is_dir(dst)) return 0; + if (!tx_is_dir(dst)) { + tx_why("cannot make the folder", dst); + return 0; + } char pat[HOS_FS_PATH]; WIN32_FIND_DATAA fd; snprintf(pat, sizeof pat, "%s\\*", src); @@ -144,7 +172,7 @@ static int tx_copy_tree(const char *src, const char *dst, int flush) { if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) continue; char a[HOS_FS_PATH], b[HOS_FS_PATH]; if (snprintf(a, sizeof a, "%s\\%s", src, fd.cFileName) >= (int)sizeof a || - snprintf(b, sizeof b, "%s\\%s", dst, fd.cFileName) >= (int)sizeof b) { ok = 0; continue; } + snprintf(b, sizeof b, "%s\\%s", dst, fd.cFileName) >= (int)sizeof b) { ok = 0; tx_why("a path too long under", src); continue; } if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ok &= tx_copy_tree(a, b, flush); else ok &= tx_copy_file(a, b, flush); } while (FindNextFileA(f, &fd)); @@ -350,19 +378,34 @@ static int save_tx_mount(const SaveTxPaths *p, char *note, size_t cap) { } if (tx_crashed()) return 0; tx_old_away(p, 1, NULL, 0); + save_tx_why[0] = 0; + char why[HOS_FS_PATH + 256]; tx_delete_tree(p->work); - if (tx_exists(p->work)) return 0; /* (a file of it is held open: no second run of the game beside this one's files) */ + if (tx_exists(p->work)) { /* (a file of it is held open: no second run of the game beside this one's files) */ + tx_why("cannot delete", p->work); + snprintf(why, sizeof why, "the working copy from before could not be deleted: %s", save_tx_why); + tx_note_add(note, cap, why); + return 0; + } /* (the newest save: a finished commit still waiting, else the committed one) */ const unsigned left = tx_ready_highest(p, ready, sizeof ready); const char *from = left ? ready : p->save; if (tx_is_dir(from)) { if (!tx_copy_tree(from, p->work, 0)) { + snprintf(why, sizeof why, "the save could not be copied to its working copy: %s", save_tx_why[0] ? save_tx_why : "?"); + tx_note_add(note, cap, why); tx_delete_tree(p->work); return 0; } } else tx_make_dirs(p->work); tx_make_dirs(p->save); /* (the save "exists" from its first mount on, as before: IsSaveDataExisting) */ - return tx_is_dir(p->work); + if (!tx_is_dir(p->work)) { + tx_why("cannot make the folder", p->work); + snprintf(why, sizeof why, "the working copy could not be made: %s", save_tx_why); + tx_note_add(note, cap, why); + return 0; + } + return 1; } /* Every file of a folder written out to the disk (FlushFileBuffers). 1: all of them */ diff --git a/launcher/App/Backend.Bench.cs b/launcher/App/Backend.Bench.cs index 522faba..edb7fbf 100644 --- a/launcher/App/Backend.Bench.cs +++ b/launcher/App/Backend.Bench.cs @@ -18,7 +18,12 @@ public sealed partial class Backend void RegisterBench() { On("bench", _ => BenchAsk()); - OnAsync("bench.go", m => (string?)m["id"] == "go" ? RunBench(compare: false) : Task.CompletedTask); + OnAsync("bench.go", m => (string?)m["id"] switch + { + "go" => RunBench(compare: false), + "helpers" => RunBench(compare: false, helperTest: true), // ((Triforce) 11-22: with the helper-thread test) + _ => Task.CompletedTask, + }); OnAsync("bench.compare", _ => RunBench(compare: true)); On("benchstop", _ => { try { benchCts?.Cancel(); } catch { } }); On("benchapply", _ => ApplyBench()); @@ -49,11 +54,13 @@ public sealed partial class Backend "

The game opens full screen, loads your newest save by itself and flies through four places: Hyrule Field, " + "Castle Town Market, Kokiri Forest and Lake Hylia. Its own panel shows where it is and the frame rate.

" + "

About 2 minutes. Leave the controls alone meanwhile. Esc in the game stops it.

" + - "

Your saves are not touched, and your settings are put back as they were. Then this window shows what it found.

", - "bench.go", new[] { ("no", "Not now", false), ("go", "Start", true) }); + "

Your saves are not touched, and your settings are put back as they were. Then this window shows what it found.

" + + "

With the helper-thread test it measures each place twice, with the replay helper threads off and on, and " + + "says which your PC runs faster (about 1 minute more).

", + "bench.go", new[] { ("no", "Not now", false), ("helpers", "With the helper-thread test", false), ("go", "Start", true) }); } - async Task RunBench(bool compare) + async Task RunBench(bool compare, bool helperTest = false) { var g = GameDir; if (g == null || benchCts != null) return; @@ -70,8 +77,9 @@ public sealed partial class Backend var t0 = DateTime.UtcNow; void Running(string line) => Send(new JsonObject { - ["t"] = "bench", ["phase"] = "run", ["pass"] = compare ? "Comparing with " + second!.Value.Item2 : "Finding your best settings", - ["frac"] = Math.Min(0.97, (DateTime.UtcNow - t0).TotalSeconds / 150), ["fps"] = null, + ["t"] = "bench", ["phase"] = "run", + ["pass"] = compare ? "Comparing with " + second!.Value.Item2 : helperTest ? "Finding your best settings · with the helper-thread test" : "Finding your best settings", + ["frac"] = Math.Min(0.97, (DateTime.UtcNow - t0).TotalSeconds / (helperTest ? 220 : 150)), ["fps"] = null, ["place"] = new JsonObject { ["name"] = "Running in the game window", ["img"] = pic }, ["line"] = line + " · " + BuildClock.Span(DateTime.UtcNow - t0), }); @@ -85,7 +93,7 @@ public sealed partial class Backend }); try { - var run = await bm.RunOnceAsync(g, second, progress, cts.Token); + var run = await bm.RunOnceAsync(g, second, progress, cts.Token, helperTest); if (compare) { benchRun2 = run; benchSecond = second; } else { benchRun = run; benchRun2 = null; benchSecond = bm.SecondPass(g, BenchIni.Read(Path.Combine(g, GameOptionsSchema.FileName))); } benchLast = "Last run " + DateTime.Now.ToString("d MMM, HH:mm"); @@ -113,8 +121,14 @@ public sealed partial class Backend if (g == null || benchRun == null) return; var now = BenchIni.Read(Path.Combine(g, GameOptionsSchema.FileName)); var r1 = benchRun; var r2 = benchRun2; - benchRecs = Benchmark.Recommend(now, r1.Scenes, r2?.Scenes, r2 != null ? benchSecond : null, Benchmark.DisplayHz()); + // ((Triforce) 11-22) after the helper-thread test the other rows are judged by the frame rates of the way it recommends + var helpers = Benchmark.RecommendHelpers(now, r1.Scenes); + var p1 = helpers == null ? r1.Scenes : Benchmark.AsRecommended(r1.Scenes, helpers.To); + var recs0 = Benchmark.Recommend(now, p1, r2?.Scenes, r2 != null ? benchSecond : null, Benchmark.DisplayHz()); + if (helpers != null) recs0.Add(helpers); + benchRecs = recs0; var use2 = r2 != null && benchRecs.Any(c => c.Key == Benchmark.KUpscaler && c.Changes); + var tested = r2 == null && r1.Scenes.Any(s => s.Helpers != null); // (the helper-thread test's halves side by side) var places = new JsonArray(); for (var i = 0; i < r1.Scenes.Count; i++) { @@ -126,6 +140,11 @@ public sealed partial class Backend ["graph"] = Graph(a.FrameTimes), }; if (b != null) { o["fps2"] = Math.Round(b.AverageFps); o["low2"] = Math.Round(b.OnePercentLow); o["graph2"] = Graph(b.FrameTimes); } + else if (tested && a.Helpers is { } h) + { + o["fps"] = Math.Round(h.OffFps); o["low"] = Math.Round(h.OffLow); o["graph"] = Graph(h.OffTimes); + o["fps2"] = Math.Round(h.OnFps); o["low2"] = Math.Round(h.OnLow); o["graph2"] = Graph(h.OnTimes); + } places.Add(o); } var recs = new JsonArray(); @@ -135,10 +154,12 @@ public sealed partial class Backend Send(new JsonObject { ["t"] = "bench", ["phase"] = "done", ["places"] = places, ["recs"] = recs, - ["verdict"] = Benchmark.Summary(r1.Scenes, r2?.Scenes, r2 != null ? benchSecond?.name : null) + Benchmark.SkippedNote(r1.Skipped), + ["verdict"] = Benchmark.Summary(r1.Scenes, r2?.Scenes, r2 != null ? benchSecond?.name : null) + Benchmark.SkippedNote(r1.Skipped) + + Benchmark.HelperNote(r1), ["eb"] = "Benchmark finished · " + BuildClock.Span(r1.Took + (r2?.Took ?? TimeSpan.Zero)) + (gpu != null ? " · " + gpu : ""), ["compare"] = r2 == null && benchSecond != null ? "Compare with " + benchSecond.Value.name : null, - ["second"] = r2 != null ? benchSecond?.name : null, + ["second"] = r2 != null ? benchSecond?.name : tested ? "Helpers on" : null, + ["first"] = tested ? "Helpers off" : r1.Scenes.Any(s => s.Helpers != null) ? "Your settings, helpers off" : null, ["apply"] = benchRecs.Any(c => c.Changes), }); } @@ -176,6 +197,8 @@ public sealed partial class Backend /// The menu's own words for the values the benchmark touches (Triforce.Logic.GameOptionsSchema). static string BenchLabel(string key, int v, IReadOnlyList all, bool after = false) { + if (key == Benchmark.KHelpers) // ((Triforce) 11-22: the Debug tab's row, not one of the schema's; gpu/vk/vk_menu.cpp tx_replay_threads) + return v == Benchmark.HelpersOff ? "Off" : v is >= 1 and <= 7 ? $"Auto, {v + 1} threads" : "Automatic"; if (GameOptionsSchema.ByKey(key) is not { } row) return GameOptionsSchema.Part(key)?.Label(v) ?? v.ToString(); // ((Triforce, options_version 8) a merged row's part: Steady frame rate, Frame generation) if (key == Benchmark.KResolution) { diff --git a/launcher/App/Backend.Settings.cs b/launcher/App/Backend.Settings.cs index 803db92..edf0c71 100644 --- a/launcher/App/Backend.Settings.cs +++ b/launcher/App/Backend.Settings.cs @@ -113,10 +113,11 @@ public sealed partial class Backend static string Capital(string s) => s.Length > 0 ? char.ToUpperInvariant(s[0]) + s.Substring(1) : s; - /// ((Triforce) 11-20) The folder the game writes triforce_log.txt in: its program's (Game.FindExe: the game folder on - /// Windows, bin/ under it on Linux with the launcher script). Null without a built game. + /// ((Triforce) 11-20) The folder the game writes triforce_log.txt in: the game folder itself. ((Triforce, 11-23) Not + /// the folder of Game.FindExe's program: on Linux that is bin/, and the game writes its log beside image.bin, a folder up + /// (host/hos_paths.h hos_game_path_a), so the row opened a bin/ with no log in it.) Null without a built game. string? GameLogFolder(string? game) => - game != null && new Game(ctx).FindExe(game) is { } exe ? Path.GetDirectoryName(exe) : null; + game != null && new Game(ctx).FindExe(game) != null ? game : null; string VersionsLine(string? game) => "launcher " + BuildInfo.Version + " · tools " + (new Tools(ctx).InstalledVersion ?? "none") + " · game " + (game != null ? Game.BuiltVersion(game) ?? "unknown" : "not built"); diff --git a/launcher/Logic/Benchmark.cs b/launcher/Logic/Benchmark.cs index b33f8fb..dfe697c 100644 --- a/launcher/Logic/Benchmark.cs +++ b/launcher/Logic/Benchmark.cs @@ -30,6 +30,18 @@ public sealed record PlaceResult(string Place, double AverageFps, double OnePerc { public double Low01 { get; init; } public IReadOnlyList FrameTimes { get; init; } = Array.Empty(); + /// ((Triforce) 11-22) the helper-thread test's two halves of this place (null: not tested) + public HelperHalves? Helpers { get; init; } +} + +/// ((Triforce) 11-22) A place measured twice in a row by the helper-thread test (host/hos_bench.c HOS_BENCH_HELPERS): +/// the replay helper threads off and on, the tuner out of the way; OnFirst: the order (it turns from place to place). +public sealed record HelperHalves(double OffFps, double OffLow, double OnFps, double OnLow, bool OnFirst) +{ + public IReadOnlyList OffTimes { get; init; } = Array.Empty(); + public IReadOnlyList OnTimes { get; init; } = Array.Empty(); + /// "on" faster by more than the margin: +1; slower by more: -1; else 0 (too close to tell) + public int Verdict => OnFps >= OffFps * Benchmark.HelperMargin ? 1 : OffFps >= OnFps * Benchmark.HelperMargin ? -1 : 0; } /// One benchmark run as the game wrote it. @@ -37,6 +49,9 @@ public sealed record BenchRun(IReadOnlyList Scenes, string? Gpu, bo { /// ((Triforce, 11-19) the places the game would not take Link to, left out (host/hos_bench.c skip_scene) public IReadOnlyList Skipped { get; init; } = Array.Empty(); + /// ((Triforce) 11-22) the helper-thread test: null not asked for; 0 asked, but the game had no helper threads to + /// test (a PC Automatic gives none); else the threads it tested + public int? HelperThreads { get; init; } } /// A setting the benchmark would change: its triforce_options.ini key, the menu's row name, the value now and the @@ -79,6 +94,13 @@ public sealed class Benchmark : IBenchmarkRunner static readonly (int value, int fps)[] Caps = { (0, 60), (2, 120), (3, 144), (5, 240) }; public const int UpGame = 0, UpDlss = 1, UpFsr3 = 3, ResQuality = 3, ResBalanced = 5, CapUncapped = 5; public const int SteadyRefreshSteps = 2; // (fps_cap.h: 0 Off, 1 Any rate, 2 Refresh steps) + // ((Triforce) 11-22) the Debug tab's Replay helper threads row (gpu/vk/replay_threads.h): 0 Off, 1 to 7 a fixed count + // (n + 1 threads), 8 Automatic, also when the file has no such line + public const string KHelpers = "replay_helper_threads"; + public const int HelpersOff = 0, HelpersAutomatic = 8; + /// A place counts as faster one way only by more than this (the run-to-run spread of a place's average on a lab PC, + /// about 3 %) + public const double HelperMargin = 1.03; public string WorkFolder => Path.Combine(ctx.WorkFolder, "benchmark"); string Marker => Path.Combine(WorkFolder, "restore.txt"); @@ -150,7 +172,8 @@ public sealed class Benchmark : IBenchmarkRunner /// One benchmark run: the game in its benchmark mode (it loads the newest save by itself, visits the scenes with /// its own panel on screen, writes its results and quits). Settings for the run: the player's, uncapped and without VSync, /// plus at Quality when given. Stop: the token (the game is closed and writes "stopped"). - public async Task RunOnceAsync(string game, (int upscaler, string name)? upscaler, IProgress? progress, CancellationToken token) + public async Task RunOnceAsync(string game, (int upscaler, string name)? upscaler, IProgress? progress, CancellationToken token, + bool helperTest = false) { var g = new Game(ctx); var exe = g.FindExe(game) ?? throw new BenchmarkException("There is no built game in " + game + "."); @@ -175,6 +198,9 @@ public sealed class Benchmark : IBenchmarkRunner { var keys = new Dictionary { [KCap] = CapUncapped, [KVsync] = 0, [KSteady] = 0, [KFrameGen] = 0 }; if (upscaler is { } u) { keys[KUpscaler] = u.upscaler; keys[KResolution] = ResQuality; } + // ((Triforce) 11-22) the helper-thread test needs the helper threads there: the row's fixed count as the player has it, + // else Automatic's (its Off has none); the game holds them off and on itself, the tuner out of the way + if (helperTest && !(BenchIni.Read(ini).TryGetValue(KHelpers, out var hr) && hr is >= 1 and <= 7)) keys[KHelpers] = HelpersAutomatic; BenchIni.Set(ini, keys); var si = new ProcessStartInfo(exe) { UseShellExecute = false, WorkingDirectory = game, RedirectStandardError = true, RedirectStandardOutput = true }; foreach (var a in new[] { Path.Combine(game, "image.bin"), "--romfs", Path.Combine(game, "romfs"), "--user", userCopy }) si.ArgumentList.Add(a); @@ -183,6 +209,7 @@ public sealed class Benchmark : IBenchmarkRunner si.Environment["HOS_OOT_PROTECT_HEARTS"] = "1"; si.Environment["HOS_INPUT_SCRIPT_BACKGROUND"] = "1"; si.Environment["HOOKSHOT_NO_UPDATE_CHECK"] = "1"; + if (helperTest) si.Environment["HOS_BENCH_HELPERS"] = "1"; if (ctx.Env("TRIFORCE_BENCH_GAME_ENV") is { Length: > 0 } extra) // (tests: e.g. the stand-in game's speed) foreach (var kv in extra.Split(';')) if (kv.IndexOf('=') is var i and > 0) si.Environment[kv[..i]] = kv[(i + 1)..]; var logPath = Path.Combine(WorkFolder, upscaler == null ? "run.log" : "run-upscaler.log"); @@ -202,7 +229,8 @@ public sealed class Benchmark : IBenchmarkRunner p.ErrorDataReceived += (_, e) => Got(e.Data); p.OutputDataReceived += (_, e) => Got(e.Data); p.BeginErrorReadLine(); p.BeginOutputReadLine(); - ctx.Log.Write("benchmark: started the game in benchmark mode (pid " + p.Id + ")" + (upscaler is { } up2 ? " with " + up2.name : "")); + ctx.Log.Write("benchmark: started the game in benchmark mode (pid " + p.Id + ")" + (upscaler is { } up2 ? " with " + up2.name : "") + + (helperTest ? ", with the helper-thread test" : "")); using (token.Register(() => { try { if (!p.HasExited && !(p.CloseMainWindow() && p.WaitForExit(15000))) p.Kill(true); } catch { } })) { while (!p.HasExited) @@ -243,14 +271,30 @@ public sealed class Benchmark : IBenchmarkRunner double D(string k) => s.TryGetProperty(k, out var v) && v.TryGetDouble(out var d) ? d : 0; var ft = new List(); if (s.TryGetProperty("frametimes_ms", out var f)) foreach (var x in f.EnumerateArray()) if (x.TryGetDouble(out var d)) ft.Add(d); - scenes.Add(new PlaceResult(s.TryGetProperty("name", out var n) ? n.GetString() ?? "" : "", D("avg"), D("low1"), false) { Low01 = D("low01"), FrameTimes = ft }); + HelperHalves? halves = null; + if (s.TryGetProperty("helpers", out var h) && h.ValueKind == System.Text.Json.JsonValueKind.Object && + h.TryGetProperty("off", out var off) && h.TryGetProperty("on", out var on)) + { + static double H(System.Text.Json.JsonElement e, string k) => e.TryGetProperty(k, out var v) && v.TryGetDouble(out var d) ? d : 0; + static List T(System.Text.Json.JsonElement e) + { + var l = new List(); + if (e.TryGetProperty("frametimes_ms", out var a)) foreach (var x in a.EnumerateArray()) if (x.TryGetDouble(out var d)) l.Add(d); + return l; + } + halves = new HelperHalves(H(off, "avg"), H(off, "low1"), H(on, "avg"), H(on, "low1"), + h.TryGetProperty("first", out var fi) && fi.GetString() == "on") { OffTimes = T(off), OnTimes = T(on) }; + } + scenes.Add(new PlaceResult(s.TryGetProperty("name", out var n) ? n.GetString() ?? "" : "", D("avg"), D("low1"), false) + { Low01 = D("low01"), FrameTimes = ft, Helpers = halves }); } var skipped = new List(); if (r.TryGetProperty("skipped", out var sk) && sk.ValueKind == System.Text.Json.JsonValueKind.Array) foreach (var x in sk.EnumerateArray()) if (x.GetString() is { Length: > 0 } name) skipped.Add(name); + int? helperThreads = r.TryGetProperty("helper_test", out var ht) && ht.TryGetProperty("threads", out var htn) && htn.TryGetInt32(out var hn) ? hn : null; return new BenchRun(scenes, r.TryGetProperty("gpu", out var gpu) ? gpu.GetString() : null, r.TryGetProperty("stopped", out var st) && st.ValueKind == System.Text.Json.JsonValueKind.True, - r.TryGetProperty("error", out var er) ? er.GetString() : null, took) { Skipped = skipped }; + r.TryGetProperty("error", out var er) ? er.GetString() : null, took) { Skipped = skipped, HelperThreads = helperThreads }; } /// The old interface: one run, then the rules (the App runs the upscaler pass on its own, when asked). @@ -302,6 +346,44 @@ public sealed class Benchmark : IBenchmarkRunner return recs; } + /// ((Triforce) 11-22) The helper-thread test's suggestion for the Replay helper threads row, or null (not tested, + /// or no place measured both ways): no place faster with them, Off; every place faster, the row as it is when it has + /// them (Automatic or a fixed count), else Automatic; some faster and some not, Automatic, where the tuner decides as the + /// game runs. + public static SettingChange? RecommendHelpers(IReadOnlyDictionary now, IReadOnlyList places) + { + var tested = places.Where(p => p.Helpers != null).Select(p => p.Helpers!.Verdict).ToList(); + if (tested.Count == 0) return null; + var from = now.TryGetValue(KHelpers, out var v) && v is >= 0 and <= 8 ? v : HelpersAutomatic; + var to = !tested.Contains(1) ? HelpersOff : tested.All(x => x == 1) ? (from == HelpersOff ? HelpersAutomatic : from) : HelpersAutomatic; + return new SettingChange(KHelpers, "Replay helper threads", from, to); + } + + /// ((Triforce) 11-22) The places as they run with the row set to : the "off" half's figures for + /// Off, the faster half's otherwise (Automatic's tuner keeps the faster way; a fixed count does too) + public static IReadOnlyList AsRecommended(IReadOnlyList places, int row) => places.Select(p => + p.Helpers is not { } h ? p + : row == HelpersOff || h.OffFps >= h.OnFps ? p with { AverageFps = h.OffFps, OnePercentLow = h.OffLow, FrameTimes = h.OffTimes } + : p with { AverageFps = h.OnFps, OnePercentLow = h.OnLow, FrameTimes = h.OnTimes }).ToList(); + + /// ((Triforce) 11-22) the verdict's sentence for the helper-thread test ("" when it did not run) + public static string HelperNote(BenchRun run) + { + if (run.HelperThreads is not { } threads) return ""; + if (threads < 2) return " The helper-thread test could not run: the game has no replay helper threads on this PC."; + var tested = run.Scenes.Where(p => p.Helpers != null).ToList(); + if (tested.Count == 0) return ""; + static string Pct(HelperHalves h) => (h.OnFps / h.OffFps - 1).ToString("+0%;-0%;0%", CultureInfo.InvariantCulture); + var faster = tested.Where(p => p.Helpers!.Verdict == 1).Select(p => p.Place + " " + Pct(p.Helpers!)).ToList(); + var slower = tested.Where(p => p.Helpers!.Verdict == -1).Select(p => p.Place + " " + Pct(p.Helpers!)).ToList(); + var s = $" With the {threads} replay helper threads on: "; + if (faster.Count == tested.Count) return s + $"faster everywhere ({string.Join(", ", faster)})."; + if (faster.Count == 0) + return s + (slower.Count > 0 ? $"faster nowhere, slower in {string.Join(", ", slower)}" : "no place more than 3 % apart") + + ", so they are better off."; + return s + $"faster in {string.Join(", ", faster)}, not elsewhere, so Automatic decides as you play."; + } + /// ((Triforce, 11-19) the verdict's note for places left out ("" when none) public static string SkippedNote(IReadOnlyList skipped) => skipped.Count == 0 ? "" : " " + string.Join(" and ", skipped) + (skipped.Count == 1 ? " was" : " were") + " left out: the game would not take Link there from your save."; diff --git a/launcher/Logic/GameOptions/GameOptionRow.cs b/launcher/Logic/GameOptions/GameOptionRow.cs index 8143078..eaa7395 100644 --- a/launcher/Logic/GameOptions/GameOptionRow.cs +++ b/launcher/Logic/GameOptions/GameOptionRow.cs @@ -17,14 +17,20 @@ public enum GameOptionKind { Choice, Slider } public sealed record GameOptionChoice(int Value, string Label); /// The values of the other rows, for the labels that depend on them (the Render resolution's sizes follow the -/// Upscaler and the Output resolution; the Anti-aliasing row shows the upscaler's own while one draws; the Microphone shows -/// the saved device's name). GameOptionsFile is one. +/// Upscaler and the Output resolution; the Anti-aliasing row shows the upscaler's own while one +/// draws; the Microphone shows the saved device's name; the Output resolution's Screen and Custom show their sizes, and the +/// Ultrawide row the shape of an Output resolution that has its own). GameOptionsFile is one. public interface IGameOptionValues { /// A row's value as the game reads it (its default when the file has no line). int Get(string key); /// A line's value as the file has it, null when it has no such line. string? Raw(string key); + /// The main monitor's size in pixels, for the Output resolution's Screen; null where it is not known. + (int W, int H)? Screen => null; + /// The Custom size the game's menu keeps aside (output_custom_size), which choosing Custom takes back; null + /// where there is none. + (int W, int H)? EnteredCustomSize => null; } /// ((Triforce, options_version 8) A saved value that a merged row stands for (vk_menu.cpp's TAB_HIDDEN rows): its key diff --git a/launcher/Logic/GameOptions/GameOptionsFile.cs b/launcher/Logic/GameOptions/GameOptionsFile.cs index ba89a54..0f2ac5c 100644 --- a/launcher/Logic/GameOptions/GameOptionsFile.cs +++ b/launcher/Logic/GameOptions/GameOptionsFile.cs @@ -21,6 +21,7 @@ public sealed class GameOptionsFile : IGameOptionValues Dictionary raw = new(StringComparer.Ordinal); // (each key's last value, trimmed as ini_merge.h does) Dictionary read = new(StringComparer.Ordinal); // (each row's value as the game reads this file) readonly Dictionary set = new(StringComparer.Ordinal); // (the rows the launcher changed: their new values) + bool customSizeUsed; // (the launcher gave Custom another size, or took the entered one back: Save empties output_custom_size) GameOptionsFile(string path, (int W, int H)? mainScreen) { @@ -31,12 +32,16 @@ public sealed class GameOptionsFile : IGameOptionValues /// The game folder's options. mainScreen: the main monitor's size in pixels, for a file from before /// options_version 6 whose Ultrawide is 1 (then "Monitor's shape": the game reads it as the shape nearest the main - /// monitor's); without it such a 1 is read as 16:9, as the game does where it cannot ask. A missing file is all defaults. + /// monitor's). Without it (the launcher has none off Windows) that row is the game's to read: the game knows its + /// screen on every system, and a guess here would be written as the player's choice. The row then stays 1 and the + /// file stays at its version (WaitsForGame). A missing file is all defaults. public static GameOptionsFile Load(string gameFolder, (int W, int H)? mainScreen = null) => new(System.IO.Path.Combine(gameFolder, GameOptionsSchema.FileName), mainScreen); /// The file was there when it was last read. public bool Exists { get; private set; } + /// The main monitor's size it was loaded with (the Output resolution's Screen shows it). + public (int W, int H)? Screen => mainScreen; /// Its options_version (0: none, a file from before the line, or no file). public int Version { get; private set; } @@ -47,6 +52,7 @@ public sealed class GameOptionsFile : IGameOptionValues var text = Exists ? File.ReadAllText(Path, Encoding.Latin1) : ""; Parse(text); set.Clear(); + customSizeUsed = false; } void Parse(string text) @@ -93,6 +99,10 @@ public sealed class GameOptionsFile : IGameOptionValues foreach (var p in GameOptionsSchema.Parts.Values) v[p.Key] = exists && lines.TryGetValue(p.Key, out var s) ? p.AsRead(Atoi(s)) : p.Default; if (!exists) return v; + // (Custom's size: the file's own two numbers, not each kept to its row's ends, as the game reads them) + (v[GameOptionsSchema.OutputWidthKey], v[GameOptionsSchema.OutputHeightKey]) = GameOptionsSchema.CustomRowsRead( + lines.TryGetValue(GameOptionsSchema.OutputWidthKey, out var cw) ? Atoi(cw) : 0, + lines.TryGetValue(GameOptionsSchema.OutputHeightKey, out var ch) ? Atoi(ch) : 0); foreach (var (key, value) in Migrated(lines)) if (v.ContainsKey(key)) v[key] = value; if (!lines.ContainsKey(GameOptionsSchema.ResolutionKey) && lines.TryGetValue("dynamic_resolution", out var dyn)) v[GameOptionsSchema.ResolutionKey] = Atoi(dyn) != 0 ? 0 : 1; @@ -100,8 +110,19 @@ public sealed class GameOptionsFile : IGameOptionValues return v; } + /// A file from before options_version 6 with Ultrawide 1, "Monitor's shape", and no main monitor known here to + /// read it by: the launcher cannot say which shape that is (on a 3440x1440 display the game reads 21:9). It leaves the + /// row for the game: not shown as another value, and Save neither writes the older file's rules' values nor raises its + /// options_version, because a file at the current version with ultrawide=1 means 16:10. Until the game has saved the + /// file, the game reads the launcher's other changes by that older version's rules. A row the launcher's user sets + /// here is a choice among the current shapes, and ends the wait. + bool WaitsForGame(Dictionary lines) => + mainScreen == null && (lines.TryGetValue(GameOptionsSchema.VersionKey, out var v) ? Atoi(v) : 0) < 6 && + lines.TryGetValue(GameOptionsSchema.UltrawideKey, out var row) && Atoi(row) == 1; + /// menu_init's rules for a file of an older options_version, as key and the value the game takes in its place - /// (only the keys whose value it changes). The Debug tab's keys too: the game's readers before the menu take the same rules. + /// (only the keys whose value it changes). The Debug tab's keys too: the game's readers before the menu take the same + /// rules. Not the Ultrawide row's old 1, nor the Output resolution that depends on it, while that waits for the game. List<(string Key, int Value)> Migrated(Dictionary lines) { var list = new List<(string, int)>(); @@ -111,10 +132,11 @@ public sealed class GameOptionsFile : IGameOptionValues { if (!lines.TryGetValue(key, out var s) || Atoi(s) != value) list.Add((key, value)); } + var nativeOld = version < 8 || (version == 8 && (lines.ContainsKey(GameOptionsSchema.OutputWidthKey) || lines.ContainsKey(GameOptionsSchema.OutputHeightKey) || lines.ContainsKey(GameOptionsSchema.CustomSizeKey))); // ((Triforce, options_version 8) merged_rows.h migrate: the handheld profile is the Output resolution's 1536x864, the // shared stick dead zone each stick's own where it had none of its own. The other rows that went move nothing; their // lines stay until the game's next save drops them. A 436f9ac-based build's 7 has none of these lines: nothing moves) - if (version < 8) + if (nativeOld) { if (lines.TryGetValue("handheld_profile", out var hh) && Atoi(hh) != 0) Force(GameOptionsSchema.OutputResKey, GameOptionsSchema.HandheldOutput); var old = lines.TryGetValue("stick_dead_zone", out var sz) ? Atoi(sz) : 0; @@ -135,9 +157,24 @@ public sealed class GameOptionsFile : IGameOptionValues if (version < 6) { Force("tail_early", 1); - if (lines.TryGetValue("ultrawide", out var uw) && Atoi(uw) == 1) Force("ultrawide", NearestShape(mainScreen)); + if (!WaitsForGame(lines) && lines.TryGetValue("ultrawide", out var uw) && Atoi(uw) == 1) Force("ultrawide", NearestShape(mainScreen)); } if (version < 7) Force("frame_pacing", 1); + // (before 8 the Output resolution's 5120x1440 and 5120x2160 were the game's frame, and the Ultrawide row gave the + // picture's shape there too: output_sizes.h output_res_read, with the row as the game reads it) + if (version < 9 && !WaitsForGame(lines) && lines.TryGetValue(GameOptionsSchema.OutputResKey, out var res)) + { + var row = lines.TryGetValue(GameOptionsSchema.UltrawideKey, out var shape) ? Math.Clamp(Atoi(shape), 0, 3) : 0; + if (version < 6 && row == 1) row = NearestShape(mainScreen); + var legacy = nativeOld; + var now = GameOptionsSchema.OutputResRead(Atoi(res), legacy ? version : 7, row); + if (legacy && now is 7 or 8) now++; + if ((version < 8 || legacy) && lines.TryGetValue("handheld_profile", out var handheld) && Atoi(handheld) != 0) now = 7; + if (now != Atoi(res)) Force(GameOptionsSchema.OutputResKey, now); + } + // Native 0.6 still wrote the old profile row in version 9. Stock version 8 ignores it. + if (version == 9 && lines.TryGetValue("handheld_profile", out var profile) && Atoi(profile) != 0) + Force(GameOptionsSchema.OutputResKey, 7); return list; } @@ -180,7 +217,8 @@ public sealed class GameOptionsFile : IGameOptionValues public string? Raw(string key) => raw.GetValueOrDefault(key); /// A row's value's label as the game's menu shows it, the other rows as they are here (the Render resolution's - /// sizes, the Anti-aliasing while an upscaler draws, the Microphone's device). + /// sizes, the Anti-aliasing while an upscaler draws, the Microphone's device, Screen's and Custom's sizes, the shape of + /// an Output resolution that has its own). public string Label(string key) => GameOptionsSchema.Get(key).Label(Get(key), this); /// The values a row offers with the other rows as they are here: the Upscaler's engines (the one chosen by its @@ -197,6 +235,8 @@ public sealed class GameOptionsFile : IGameOptionValues GameOptionsSchema.ResolutionKey => GameOptionsSchema.ResolutionSteps(Value(GameOptionsSchema.UpscalerKey)).ToList(), GameOptionsSchema.UpscalerKey => GameOptionsSchema.UpscalerOrder.Select(e => e == GameOptionsSchema.Engine(now) ? now : e).ToList(), GameOptionsSchema.MicKey => Raw(GameOptionsSchema.MicDeviceKey) is { Length: > 0 } ? new List { 0, 1, 2 } : new List { 0, 1 }, + // (an Output resolution of its own shape: the row has nothing to choose, as in the menu) + GameOptionsSchema.UltrawideKey when GameOptionsSchema.OutputShaped(this) => new List { Get(key) }, _ => row.Choices.Select(c => c.Value).ToList(), }; if (!values.Contains(now)) values.Add(now); @@ -210,6 +250,23 @@ public sealed class GameOptionsFile : IGameOptionValues return values.Select(v => new GameOptionChoice(v, row.Label(v, this))).ToList(); } + /// The Custom size the game's menu keeps beside a screen's (output_custom_size, read as the menu reads it, + /// read_remembered_custom: under any Output resolution, a size the two rows can hold), null when there is none or the + /// launcher has used it up. + public (int W, int H)? EnteredCustomSize + { + get + { + if (customSizeUsed) return null; + if (Raw(GameOptionsSchema.CustomSizeKey) is not { } text) return null; + var x = text.IndexOfAny(new[] { 'x', 'X' }); + if (x <= 0 || !text.All(c => c is >= '0' and <= '9' or 'x' or 'X') || text.Count(c => c is 'x' or 'X') != 1) return null; + int w = Atoi(text[..x]), h = Atoi(text[(x + 1)..]); + var (width, height) = (GameOptionsSchema.Get(GameOptionsSchema.OutputWidthKey), GameOptionsSchema.Get(GameOptionsSchema.OutputHeightKey)); + return w >= width.Lo && w <= width.Hi && h >= height.Lo && h <= height.Hi ? (w, h) : null; + } + } + /// The saved values the launcher changed since the file was read, by their keys in the file (a merged row's are /// its parts'), with their new values (Save writes these). public IReadOnlyDictionary Changes => set; @@ -274,7 +331,17 @@ public sealed class GameOptionsFile : IGameOptionValues Put(Res, row.Clamp(value)); return Get(key); } - Put(key, row.Clamp(value)); + var next = row.Clamp(value); + var changed = Get(key) != next; + // Custom edits replace the remembered pair; choosing another output restores it, as the game's menu does. + if (changed && key is GameOptionsSchema.OutputWidthKey or GameOptionsSchema.OutputHeightKey) customSizeUsed = true; + if (changed && key == GameOptionsSchema.OutputResKey && EnteredCustomSize is { } entered) + { + Put(GameOptionsSchema.OutputWidthKey, entered.W); + Put(GameOptionsSchema.OutputHeightKey, entered.H); + customSizeUsed = true; + } + Put(key, next); return Get(key); } @@ -307,13 +374,14 @@ public sealed class GameOptionsFile : IGameOptionValues /// get its value, every other line stays exactly as the file has it (so a line changed outside since Load is kept, as /// the game's merge keeps it), a changed row the file has no line for is added before options_version. A file of an /// older options_version is brought up to the current one as the game would read it (the values its rules give are - /// written, options_version=8), so the game does not read the launcher's values by the old rules. The whole file is + /// written, options_version=9), so the game does not read the launcher's values by the old rules; not while an old + /// Monitor's shape waits for the game (WaitsForGame). The whole file is /// written beside it as .new and then put in its place: a reader never meets half a file, and a failure leaves the old /// one (IOException). Nothing to write: nothing written. The caller refuses while the game runs (Game.IsRunning). /// Afterwards this object holds the file as written. public void Save() { - if (set.Count == 0) return; + if (set.Count == 0) { customSizeUsed = false; return; } var exists = File.Exists(Path); var text = exists ? File.ReadAllText(Path, Encoding.Latin1) : ""; var disk = SplitLines(text); @@ -324,18 +392,36 @@ public sealed class GameOptionsFile : IGameOptionValues var write = new Dictionary(StringComparer.Ordinal); var hasVersion = diskRaw.TryGetValue(GameOptionsSchema.VersionKey, out var vs); - if (exists && (!hasVersion || Atoi(vs!) < GameOptionsSchema.CurrentVersion)) + // (an old Monitor's shape the launcher cannot read: the file keeps its version and its rules, for the game; unless + // the row is set here, which is a choice among the current shapes) + var waits = WaitsForGame(diskRaw) && !set.ContainsKey(GameOptionsSchema.UltrawideKey); + if (exists && !waits) { foreach (var (k, v) in Migrated(diskRaw)) write[k] = v.ToString(CultureInfo.InvariantCulture); if (!diskRaw.ContainsKey(GameOptionsSchema.ResolutionKey) && diskRaw.TryGetValue("dynamic_resolution", out var dyn)) write[GameOptionsSchema.ResolutionKey] = (Atoi(dyn) != 0 ? 0 : 1).ToString(CultureInfo.InvariantCulture); } foreach (var (k, v) in set) write[k] = v.ToString(CultureInfo.InvariantCulture); + // An older native launcher left this line behind. Keep it consistent when the current output row changes. + if (!waits && diskRaw.ContainsKey("handheld_profile")) + { + var output = write.TryGetValue(GameOptionsSchema.OutputResKey, out var written) ? Atoi(written) : Get(GameOptionsSchema.OutputResKey); + write["handheld_profile"] = output == GameOptionsSchema.HandheldOutput ? "1" : "0"; + } // ((Triforce) 11-20) the GPU device row's card by its name too: the game finds it by the name first, so the number // counted in Windows' order (no triforce_gpus.txt before the game's first run) no longer picks another card. Auto: empty if (set.TryGetValue(GameOptionsSchema.GpuKey, out var gpu)) write[GameOptionsSchema.GpuNameKey] = (GameOptionsSchema.GpuNameOf(gpu) ?? "").Replace('\r', ' ').Replace('\n', ' '); - var bump = !exists || !hasVersion || Atoi(vs!) < GameOptionsSchema.CurrentVersion; + // (Custom's size is its two sides together: the launcher shows the pair as the game takes it (Effective: 7680x4320 in + // the file is 5120x2880), so a change of one side is a change of that pair. Written with only the changed side, + // 3840 beside the file's 4320 would be another size than the one shown. Both sides whenever either is written) + foreach (var (side, other) in new[] { (GameOptionsSchema.OutputWidthKey, GameOptionsSchema.OutputHeightKey), + (GameOptionsSchema.OutputHeightKey, GameOptionsSchema.OutputWidthKey) }) + if (write.ContainsKey(side) && !write.ContainsKey(other)) write[other] = Get(other).ToString(CultureInfo.InvariantCulture); + // (emptied, as the menu writes it with none kept; only where the file has the line) + if (customSizeUsed && diskRaw.TryGetValue(GameOptionsSchema.CustomSizeKey, out var kept) && kept.Length > 0) + write[GameOptionsSchema.CustomSizeKey] = ""; + var bump = !waits && (!exists || !hasVersion || Atoi(vs!) < GameOptionsSchema.CurrentVersion); if (bump) write[GameOptionsSchema.VersionKey] = GameOptionsSchema.CurrentVersion.ToString(CultureInfo.InvariantCulture); var outLines = new List(disk.Count + write.Count); @@ -360,6 +446,7 @@ public sealed class GameOptionsFile : IGameOptionValues Exists = true; Parse(sb.ToString()); set.Clear(); + customSizeUsed = false; } static int IndexOf(GameOptionRow r) diff --git a/launcher/Logic/GameOptions/GameOptionsSchema.cs b/launcher/Logic/GameOptions/GameOptionsSchema.cs index 2e1aa08..0621757 100644 --- a/launcher/Logic/GameOptions/GameOptionsSchema.cs +++ b/launcher/Logic/GameOptions/GameOptionsSchema.cs @@ -17,11 +17,17 @@ public static class GameOptionsSchema { /// The file the game reads at its start and writes at every change in its menu, in the game folder. public const string FileName = "triforce_options.ini"; - /// The options_version the game writes (vk_menu.cpp save, merged_rows.h kVersion): the file's format, which - /// menu_init's rules read. - public const int CurrentVersion = 8; + /// The options_version the game writes (vk_menu.cpp save): the file's format, which menu_init's rules read. + public const int CurrentVersion = 9; public const string OutputResKey = "output_res"; + public const string OutputWidthKey = "output_width"; + public const string OutputHeightKey = "output_height"; + public const string UltrawideKey = "ultrawide"; + /// The Custom size the player entered, <w>x<h>, kept by the game's menu while a screen's size is in + /// output_width and output_height (vk_menu.cpp remembered_custom); empty or absent when there is none. The menu reads + /// it under any Output resolution, and so does GameOptionsFile. No row. + public const string CustomSizeKey = "output_custom_size"; public const string ResolutionKey = "resolution"; public const string UpscalerKey = "dlss"; public const string RumbleKey = "rumble_strength"; @@ -155,7 +161,23 @@ public static class GameOptionsSchema static string TxRdxGrade(int v, IGameOptionValues? o) => v.ToString(CultureInfo.InvariantCulture); static string TxSpeed(int v, IGameOptionValues? o) => v != 0 ? "Real time" : "Per frame"; static string TxTextSpeed(int v, IGameOptionValues? o) => OrFirst(new[] { "Normal", "2x", "4x", "Instant" }, v); - static string TxUltrawide(int v, IGameOptionValues? o) => Pick(new[] { "16:9", "16:10", "21:9", "32:9" }, v); + static readonly string[] Shapes = { "16:9", "16:10", "21:9", "32:9" }; + /// tx_shape: the row's choice, or the shape of an Output resolution that has its own (the row then has nothing + /// to choose) with its size. (The game shows HOS_ASPECT's there while it is set.) + static string TxUltrawide(int v, IGameOptionValues? o) + { + if (!OutputShaped(o)) return Pick(Shapes, v); + var (w, h) = OutputSizeOf(V(o, OutputResKey, 0), o); + return ShapeName((double)w / h) + " (" + w + "x" + h + ")"; + } + /// shape_name: one of the Ultrawide row's where it is that one, else its width for a height of 1 (2.40:1). + static string ShapeName(double ratio) + { + for (var row = 1; row <= 3; row++) + if (Math.Abs(ratio / UltrawideRatio(row) - 1.0) < 0.001) return Shapes[row]; + return ratio.ToString("0.00", CultureInfo.InvariantCulture) + ":1"; + } + static string TxPixels(int v, IGameOptionValues? o) => v.ToString(CultureInfo.InvariantCulture); static string TxWideHud(int v, IGameOptionValues? o) => v != 0 ? "Screen edges" : "Middle"; static string TxWideMenus(int v, IGameOptionValues? o) => Pick(new[] { "Full width", "Centred, blurred sides", "Centred, black bars" }, v); static string TxPrompts(int v, IGameOptionValues? o) => @@ -213,22 +235,148 @@ public static class GameOptionsSchema /// The microphone_device line's name as text: the file's bytes are UTF-8 (read here as Latin-1, byte for byte). internal static string MicName(string raw) => System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Latin1.GetBytes(raw)).Trim(); - // ---- the Output resolution and the Render resolution ---- + // ---- the Output resolution, the picture it gives, and the Render resolution ---- - /// The Output resolution's sizes by their saved value (kOutputs); 6 and 7 came after the others so that saved - /// values keep their sizes. (options_version 8) 7 is 1536x864, the game's handheld profile, once a row of its own. + /// The Output resolution's fixed sizes by their saved value (kOutputs); 6 came after the others so that saved + /// values keep their sizes. 9 is Custom, any size (gpu/vk/output_sizes.h): the size is the picture's, the game's frame + /// 16:9 at its height, and a size that is not 16:9 is a wider or narrower picture by itself. The game's menu lists the + /// size of every connected screen by its name and saves the one chosen as Custom's size, so here such a choice is + /// Custom with that size. 8 is Screen, the size of the screen the game's window opens on: what an older file has, and + /// still read; the game's menu saves it as that size. public static readonly IReadOnlyList<(int W, int H)> Outputs = new[] { (2048, 1152), (2560, 1440), (3840, 2160), (1920, 1080), (5120, 1440), (5120, 2880), (5120, 2160), (1536, 864) }; - /// The Output resolution's handheld profile (merged_rows.h kHandheldOutput). public const int HandheldOutput = 7; - /// The order the menu shows them in, smallest to largest (kOutputOrder). - public static readonly IReadOnlyList OutputOrder = new[] { 7, 3, 0, 1, 2, 4, 6, 5 }; - static int OutputChoice(int v) => v >= 0 && v < Outputs.Count ? v : 0; + public const int OutputScreen = 8, OutputCustom = 9; + /// The order the launcher lists them in: the fixed sizes smallest to largest, then Screen and Custom. (The menu + /// puts the screens' sizes and Custom among the fixed ones by their sizes, output_entries.) + public static readonly IReadOnlyList OutputOrder = new[] { 7, 3, 0, 1, 2, 4, 6, 5, OutputScreen, OutputCustom }; + static int OutputChoice(int v) => v >= 0 && v <= OutputCustom ? v : 0; + + // (gpu/vk/output_sizes.h, as plain code) + const int OutputMinW = 640, OutputMinH = 360, OutputMaxW = 7680, OutputMaxH = 2880; + const double OutputMaxPixels = 5120.0 * 2880.0, OutputRowPixels = 3840.0 * 2160.0, ShapeMin = 5.0 / 4.0, ShapeMax = 32.0 / 9.0; + static int OutputFrameWidth(int height) => (height * 16 + 36) / 72 * 8; + static bool ShapeIsGame(double shape) => !(shape > 16.0 / 9.0 * 1.01 || shape < 16.0 / 9.0 * 0.99); + static bool SizeShaped((int W, int H) s) => s.W > 0 && s.H > 0 && !ShapeIsGame((double)s.W / s.H); + /// ultrawide_row_ratio: the Ultrawide row's shape, 0 for the game's own 16:9. + static double UltrawideRatio(int row) => row <= 0 ? 0 : row == 1 ? 1.6f : row == 2 ? (float)(64.0 / 27.0) : (float)(32.0 / 9.0); + /// output_width_range: the widths, whole multiples of 8, a picture of height h can have on one side of 16:9: + /// within 5:4 to 32:9 and outside the 1% beside 16:9, within the width's ends and the pixels. Lo above Hi: none. + static (int Lo, int Hi) OutputWidthRange(int h, bool wide) + { + const double game = 16.0 / 9.0; + var edge = h * game * (wide ? 1.01 : 0.99); + var least = wide ? Math.Floor(edge / 8.0) * 8.0 + 8.0 : Math.Ceiling(h * ShapeMin / 8.0) * 8.0; + var most = wide ? Math.Floor(h * ShapeMax / 8.0) * 8.0 : Math.Ceiling(edge / 8.0) * 8.0 - 8.0; + var pixels = Math.Floor(OutputMaxPixels / h / 8.0) * 8.0; + least = Math.Max(least, OutputMinW); + most = Math.Min(Math.Min(most, OutputMaxW), pixels); + return ((int)least, most < 0 ? 0 : (int)most); + } + /// output_size_used: a size from outside (the screen's, Custom's) as the game takes it, null for none. Its + /// shape first (5:4 to 32:9), then into the limits in that shape: 7680x4320 is 5120x2880. The width is the multiple of + /// 8 nearest the shape's among those OutputWidthRange allows, so what comes out is taken as itself when given again. + internal static (int W, int H)? OutputSizeUsed(long w, long h) + { + if (w <= 0 || h <= 0) return null; + var shape = Math.Clamp((double)w / h, ShapeMin, ShapeMax); + if (ShapeIsGame(shape)) + { + var gh = (int)Math.Clamp(h, OutputMinH, OutputMaxH); + return (OutputFrameWidth(gh), gh); + } + var wide = shape > 16.0 / 9.0; + double fh = h, scale = 1.0; + var fw = fh * shape; + if (fh * scale > OutputMaxH) scale = OutputMaxH / fh; + if (fw * scale > OutputMaxW) scale = OutputMaxW / fw; + if (fw * fh * scale * scale > OutputMaxPixels) scale = Math.Sqrt(OutputMaxPixels / (fw * fh)); + int uh; + if (scale < 1.0) uh = (int)(fh * scale / 8.0) * 8; + else + { + if (fh < OutputMinH) fh = OutputMinH; + if (fh * shape < OutputMinW) fh = OutputMinW / shape; + uh = (int)Math.Ceiling(fh); + } + var (lo, hi) = OutputWidthRange(uh, wide); + if (lo > hi) + { + uh = (uh - 1) / 8 * 8; + (lo, hi) = OutputWidthRange(uh, wide); + } + return (Math.Clamp((int)(uh * shape / 8.0 + 0.5) * 8, lo, hi), uh); + } + /// custom_rows_read: the Output width and Output height rows' values for the file's two numbers (0: no line): a + /// side that is not a size is its default; as written where the rows can hold them, else the size the game takes. + internal static (int W, int H) CustomRowsRead(long w, long h) + { + if (w <= 0) w = 2560; + if (h <= 0) h = 1440; + var held = w >= OutputMinW && w <= OutputMaxW && h >= OutputMinH && h <= OutputMaxH; + return held ? ((int)w, (int)h) : OutputSizeUsed(w, h)!.Value; + } + /// output_picture: the picture for the frame's height and a shape, null for the game's own 16:9 picture. + internal static (int W, int H)? OutputPicture(int frameH, double want, bool sized) + { + if (!(want > 1.0) || ShapeIsGame(want)) return null; + var r = Math.Clamp(want, ShapeMin, ShapeMax); + var most = sized ? OutputMaxPixels : OutputRowPixels; + int oh = frameH, ow = (int)(oh * r / 8 + 0.5) * 8; + if ((double)ow * oh > most) + { + oh = (int)(Math.Sqrt(most / r) / 8) * 8; + ow = (int)(oh * r / 8) * 8; + } + return (ow, oh); + } + /// output_res_read: output_res as a file of an older options_version holds it, with its Ultrawide row. Before 8, + /// 5120x1440 (4) and 5120x2160 (6) were the game's frame: with the row on another shape than theirs, the 16:9 size of + /// their height, which gives the same picture. + internal static int OutputResRead(int v, int version, int ultrawide) + { + if (version >= 8) return v; + if (v == 4 && ultrawide != 0 && ultrawide != 3) return 1; + if (v == 6 && ultrawide != 0 && ultrawide != 2) return 2; + return v; + } + /// row_size: the size a choice shows, null for a Screen that is not known. + static (int W, int H)? RowSize(int v, IGameOptionValues? o) + { + v = OutputChoice(v); + if (v < OutputScreen) return Outputs[v]; + if (v == OutputScreen) return o?.Screen is { } s ? OutputSizeUsed(s.W, s.H) : null; + // (under another choice with a size kept aside, Custom is that size: choosing it takes it back, as in the menu, where + // only the kept pair is offered then, output_entries) + if (V(o, OutputResKey, 0) != OutputCustom && o?.EnteredCustomSize is { } entered) return OutputSizeUsed(entered.W, entered.H); + return OutputSizeUsed(V(o, OutputWidthKey, 2560), V(o, OutputHeightKey, 1440)); + } + /// output_size_of: the size a choice runs at (2560x1440 for a Screen that is not known, as the game). + static (int W, int H) OutputSizeOf(int v, IGameOptionValues? o) => RowSize(v, o) ?? Outputs[1]; + /// output_shaped: the Output resolution chosen has a shape of its own (docked), so the Ultrawide row does not apply. + internal static bool OutputShaped(IGameOptionValues? o) => + o != null && V(o, OutputResKey, 0) != HandheldOutput && SizeShaped(OutputSizeOf(V(o, OutputResKey, 0), o)); + /// output_picture_of: the picture the options give, the size's own or its height in the Ultrawide row's shape. + static (int W, int H) PictureOf(IGameOptionValues? o) + { + var v = OutputChoice(V(o, OutputResKey, 0)); + var size = OutputSizeOf(v, o); + var frameH = v == 0 ? Outputs[1].H : size.H; + var sized = SizeShaped(size); + var want = sized ? (double)size.W / size.H : UltrawideRatio(Math.Clamp(V(o, UltrawideKey, 0), 0, 3)); + if (OutputPicture(frameH, want, sized) is not { } p) return v == 0 ? Outputs[0] : size; + return v == 0 ? (p.W * 4 / 5, p.H * 4 / 5) : p; + } + /// tx_output_res: a fixed size, "Screen (WxH)" with the main monitor's size where the launcher knows it (the + /// game shows the monitor's it opens on), "Custom (WxH)" with the Output width and Output height rows' size as the game + /// takes it. static string TxOutputRes(int v, IGameOptionValues? o) { v = OutputChoice(v); - if (v == HandheldOutput) return "1536x864 (handheld)"; - var (w, h) = Outputs[v]; - return w + "x" + h; + var size = RowSize(v, o); + if (v == 7) return "1536x864 (handheld)"; + if (v < OutputScreen) return size!.Value.W + "x" + size.Value.H; + var name = v == OutputScreen ? "Screen" : "Custom"; + return size is { } s ? name + " (" + s.W + "x" + s.H + ")" : name; } // (upscaler_rows.h) @@ -272,7 +420,8 @@ public static class GameOptionsSchema } static string ModeName(int v) => Percent(v) switch { 67 => "Quality", 58 => "Balanced", 50 => "Performance", 33 => "Ultra Performance", _ => "" }; /// tx_resolution: by the Upscaler chosen, and the size the game draws the 3D at for a fixed share of the - /// Output resolution (the handheld profile's 1536x864 among them), a twelfth of it as the game takes it. + /// picture (the Output resolution's own, or its height in the Ultrawide row's shape; the handheld profile's 1536x864), + /// a twelfth of it as the game takes it. static string TxResolution(int v, IGameOptionValues? o) { var up = V(o, UpscalerKey, 0); @@ -280,7 +429,7 @@ public static class GameOptionsSchema var p = Percent(v); if (p == 0) return "Auto (dynamic)"; if (ScalesByMode(up) && ModeName(v).Length > 0) return ModeName(v) + " (" + p + "%)"; - var (ow, oh) = Outputs[OutputChoice(V(o, OutputResKey, 0))]; + var (ow, oh) = (V(o, OutputResKey, 0) == HandheldOutput) ? (1536, 864) : PictureOf(o); var k = Math.Min(Math.Max((int)(p / 100.0f * 12.0f + 0.5f), 1), 12); return p + "% (" + (ow * k + 11) / 12 + "x" + oh * k / 12 + ")"; } @@ -382,16 +531,20 @@ public static class GameOptionsSchema { Row(GameOptionTab.Display, "Screen", "Fullscreen", 0, 1, 1, 0, GameOptionKind.Choice, TxOnoff, false, true, "The game fills the whole screen, without the window's border. F10 and Alt+Enter do the same."), - Row(GameOptionTab.Display, "Screen", "Output resolution", 0, 7, 1, 0, GameOptionKind.Choice, TxOutputRes, true, false, - "The size of the game's whole frame, HUD included, before it is scaled to the window. Applies after a restart."), + Row(GameOptionTab.Display, "Screen", "Output resolution", 0, 9, 1, 0, GameOptionKind.Choice, TxOutputRes, true, false, + "The picture's size, before it is scaled to the window: the fixed sizes, and the size of each connected screen by its name. A size that is not 16:9 is a wider or narrower picture: the HUD, menus and story movies keep their 16:9 shape at its height. Docked only. Applies after a restart."), + Row(GameOptionTab.Display, "Screen", "Output width", 640, 7680, 8, 2560, GameOptionKind.Slider, TxPixels, true, false, + "The output resolution's width in pixels, where it is a screen's size or Custom; hold Left or Right to move faster. Output resolution shows the size the game takes: 5:4 to 32:9 in shape, at most the pixels of 5120x2880. Applies after a restart."), + Row(GameOptionTab.Display, "Screen", "Output height", 360, 2880, 8, 1440, GameOptionKind.Slider, TxPixels, true, false, + "The output resolution's height in pixels, where it is a screen's size or Custom; hold Left or Right to move faster. Output resolution shows the size the game takes: 5:4 to 32:9 in shape, at most the pixels of 5120x2880. Applies after a restart."), Row(GameOptionTab.Display, "Screen", "GPU device", 0, 8, 1, 0, GameOptionKind.Choice, TxGpu, true, true, "Which graphics card the game runs on. Applies after a restart."), Row(GameOptionTab.Display, "Ultrawide", "Aspect ratio", 0, 3, 1, 0, GameOptionKind.Choice, TxUltrawide, true, false, - "The shape of the picture: the game's own 16:9, or 16:10, 21:9 or 32:9 for a screen of that shape. A screen of another shape shows it between black bars. Applies after a restart."), + "The picture's shape for a 16:9 Output resolution: the game's own 16:9, or a fixed 16:10, 21:9 or 32:9 at the same height, for a screen or a window of that shape. A screen of another shape shows the picture between black bars. An Output resolution that is not 16:9 has its own shape, shown here. Applies after a restart."), Row(GameOptionTab.Display, "Ultrawide", "HUD position", 0, 1, 1, 0, GameOptionKind.Choice, TxWideHud, true, true, - "Where the hearts, the item buttons and the map sit. Middle: in the middle 16:9, as on a normal screen. Screen edges: in the screen's corners. Applies after a restart."), + "With a picture wider than 16:9: where corner HUD elements, tips and notices sit. Middle: in the middle 16:9, as on a normal screen. Screen edges: out in the screen's corners. Applies after a restart."), Row(GameOptionTab.Display, "Ultrawide", "Menu sides", 0, 2, 1, 1, GameOptionKind.Choice, TxWideMenus, false, false, - "What is beside the pause, item and map menus, loading screens and movies, which are 16:9. Changes at once."), + "With a picture wider than 16:9: the pause, item and map menus, and what shows beside them. Loading screens and story movies, which draw no world either, get the same sides (the title's movie fills the picture up to 12:5); a fade always covers the whole screen. Changes at once."), Merged(GameOptionTab.Display, "HDR", "HDR", 0, 3, 1, MergeHdr, TxHdrMode, true, true, "HDR10 on an HDR display (Windows: Use HDR on in the display settings). Native + RenoDX applies after a restart."), Row(GameOptionTab.Display, "HDR", "Paper white", 80, 400, 10, 200, GameOptionKind.Slider, TxNits, false, true, @@ -560,6 +713,7 @@ public static class GameOptionsSchema [VersionKey] = "the file's format: the rules the game reads an older file by (GameOptionsFile.Save writes 8 when it brings an older file up to date)", [MicDeviceKey] = "the Microphone row's device, by its name: the game's to choose from the devices it lists", [GpuNameKey] = "the GPU device row's card by its name (11-20): Save writes it with the row; the game finds the card by it first", + [CustomSizeKey] = "the Custom size entered before a screen's size was chosen in the game's Output resolution row: the game's to keep; GameOptionsFile empties it when it writes another Custom size, and takes it back into the rows when the Output resolution is changed", ["layout_preset"] = "the Controls page's Layout preset: choosing one in the game rebinds the pad_ lines, which a changed value alone would not do", ["debug_tools"] = "the Debug tab (not ported)", ["descriptor_reuse"] = "the Debug tab's Developer rows (not ported)", diff --git a/launcher/Logic/Startup.cs b/launcher/Logic/Startup.cs index aed86b6..97a81b5 100644 --- a/launcher/Logic/Startup.cs +++ b/launcher/Logic/Startup.cs @@ -190,7 +190,10 @@ public static class Startup var result = new StartupResult { Args = a, Screen = StartScreen.Check, Lock = held, GameFolder = a.UpdateFolder ?? a.LaunchFolder, SignalUpWhenShown = a.Relaunched }; if (!ctx.IsWindows) + { + if (a.LaunchFolder != null && a.UpdateFolder == null) UseLaunchFolder(ctx, a.LaunchFolder); return a.LaunchFolder != null && a.UpdateFolder == null ? Same(result, StartScreen.Launch) : result; + } // (TRIFORCE_DEV=1: run in place, without installing, for testing) if (ctx.RunningInstalled || ctx.Env("TRIFORCE_DEV") == "1") return result; @@ -215,6 +218,24 @@ public static class Startup return Same(result, StartScreen.Install); } + /// ((Triforce, 11-23, ticket "[Linux] Non-default dir for triforce not generating log files") Linux --launch <dir>: + /// that folder becomes the launcher's game folder (Settings.GameFolder), as a build there makes it. The folder's own + /// "triforce" script (its menu entry, desktop shortcut and Steam shortcut) starts the launcher so, and the launcher read + /// the folder and never used it: Home, Play, the saves and Game logs were the last built folder's. A game in a folder + /// of its own was played from that other folder, whose triforce_log.txt it wrote, and nothing was written beside it. + /// Only a folder that holds a game. TRIFORCE_LAUNCH_SAVED_FOLDER=1: the saved folder stays, as before. + static void UseLaunchFolder(TriforceContext ctx, string folder) + { + if (ctx.Env("TRIFORCE_LAUNCH_SAVED_FOLDER") == "1") return; + string full; + try { full = Path.GetFullPath(folder); } catch (Exception) { return; } + if (new Game(ctx).FindExe(full) == null) { ctx.Log.Write("start: --launch " + full + " holds no game: the saved game folder stays"); return; } + var was = ctx.Settings.GameFolder; + if (was != null && TriforceContext.SamePath(was, full)) return; + ctx.Settings.GameFolder = full; + ctx.Log.Write("start: --launch " + full + ": the game folder now (it was " + (was ?? "none") + ")"); + } + static StartupResult Same(StartupResult r, StartScreen screen) => new() { Args = r.Args, Screen = screen, Lock = r.Lock, GameFolder = r.GameFolder, SignalUpWhenShown = r.SignalUpWhenShown, diff --git a/launcher/Logic/Tools.cs b/launcher/Logic/Tools.cs index 44f7c60..9614581 100644 --- a/launcher/Logic/Tools.cs +++ b/launcher/Logic/Tools.cs @@ -298,6 +298,9 @@ public sealed class Tools } foreach (var f in b.Files) // (the base whole in the new folder, whichever way it came) { + // ((Triforce, 11-22, the v0.7.0 update stop "The tools' base lacks python/Lib/.../__pycache__/...pyc") the bytecode + // caches as HasBase takes them: rewritten by Python as it runs, so kept bases have them at other sizes or not at all) + if (Regenerated(f.Path)) continue; var fi = new FileInfo(Path.Combine(part, f.Path)); if (!fi.Exists || fi.Length != f.Size) throw new InvalidDataException("The tools' base lacks " + f.Path + " (or it has another size): they were not changed."); } diff --git a/launcher/LogicTests/Tests.Core.cs b/launcher/LogicTests/Tests.Core.cs index 7338d61..b143f48 100644 --- a/launcher/LogicTests/Tests.Core.cs +++ b/launcher/LogicTests/Tests.Core.cs @@ -14,6 +14,7 @@ static partial class Tests yield return Sync("linux: the user folder follows the saves (triforce/user, then hookshot, then the game's)", LinuxUserFolder); yield return Sync("benchmark: an uneven run gets Steady frame rate Refresh steps, an even one keeps the player's", BenchSteady); yield return Sync("benchmark: a place left out is read and said", BenchSkipped); + yield return Sync("benchmark: the helper-thread test's halves are read, and the row is suggested from them", BenchHelpers); yield return Sync("settings: color scheme, the page's 'color' read", ColorParse); yield return Sync("settings: color scheme kept and read back (registry.txt, builder.ini, old files)", ColorKept); yield return Sync("settings: color scheme, the launcher's color (--snapshot, commands out of order)", ColorChoice); @@ -103,6 +104,46 @@ static partial class Tests Equal(0, Benchmark.ReadResults(f, TimeSpan.Zero).Skipped.Count, "an older game's results: none"); } + static void BenchHelpers() + { + var root = NewRoot("benchhelpers"); + var f = Path.Combine(root, "results.json"); + // (as host/hos_bench.c writes it with HOS_BENCH_HELPERS=1: the scene's own figures are the "off" half's) + File.WriteAllText(f, "{\"version\":1,\"stopped\":false,\"scenes\":[" + + "{\"name\":\"Hyrule Field\",\"avg\":80.2,\"low1\":55,\"frametimes_ms\":[12.5],\"helpers\":{\"first\":\"off\"," + + "\"off\":{\"avg\":80.2,\"low1\":55,\"frametimes_ms\":[12.5]},\"on\":{\"avg\":75.3,\"low1\":52,\"frametimes_ms\":[13.3,13.4]}}}," + + "{\"name\":\"Castle Town Market\",\"avg\":71.4,\"low1\":40,\"frametimes_ms\":[14],\"helpers\":{\"first\":\"on\"," + + "\"off\":{\"avg\":71.4,\"low1\":40,\"frametimes_ms\":[14]},\"on\":{\"avg\":64.4,\"low1\":36,\"frametimes_ms\":[15.5]}}}]," + + "\"skipped\":[],\"helper_test\":{\"threads\":3},\"settings\":{}}"); + var run = Benchmark.ReadResults(f, TimeSpan.FromSeconds(1)); + Equal(3, run.HelperThreads, "the threads tested"); + var field = run.Scenes[0].Helpers; + Check(field != null && field.OffFps == 80.2 && field.OnFps == 75.3 && !field.OnFirst && field.OnTimes.Count == 2, "the Field's halves"); + Check(run.Scenes[1].Helpers is { OnFirst: true }, "the order, turned in the second place"); + Equal(-1, field!.Verdict, "6 % slower with them: slower"); + // the suggestion: slower everywhere, Off; from Automatic (the file without the line is Automatic too) + var none = new Dictionary(); + var off = Benchmark.RecommendHelpers(none, run.Scenes)!; + Check(off.Key == Benchmark.KHelpers && off.From == Benchmark.HelpersAutomatic && off.To == Benchmark.HelpersOff, "slower everywhere: Off"); + Check(Benchmark.HelperNote(run).Contains("faster nowhere"), "the verdict says so"); + static PlaceResult P(string n, double offFps, double onFps) => new(n, offFps, offFps * 0.8) { Helpers = new HelperHalves(offFps, offFps * 0.8, onFps, onFps * 0.8, false) }; + var faster = new[] { P("Hyrule Field", 70, 80), P("Kokiri Forest", 60, 66) }; + Equal(Benchmark.HelpersAutomatic, Benchmark.RecommendHelpers(none, faster)!.To, "faster everywhere: Automatic stays"); + Equal(Benchmark.HelpersAutomatic, Benchmark.RecommendHelpers(new Dictionary { [Benchmark.KHelpers] = 0 }, faster)!.To, "from Off: Automatic"); + Equal(2, Benchmark.RecommendHelpers(new Dictionary { [Benchmark.KHelpers] = 2 }, faster)!.To, "a fixed count stays"); + var mixed = new[] { P("Hyrule Field", 70, 80), P("Kokiri Forest", 66, 60) }; + Equal(Benchmark.HelpersAutomatic, Benchmark.RecommendHelpers(new Dictionary { [Benchmark.KHelpers] = 0 }, mixed)!.To, "mixed: Automatic decides"); + Check(Benchmark.HelperNote(new BenchRun(mixed, null, false, null, TimeSpan.Zero) { HelperThreads = 3 }).Contains("Automatic decides"), "mixed: said"); + var close = new[] { P("Hyrule Field", 70, 71), P("Kokiri Forest", 66, 65) }; + Equal(Benchmark.HelpersOff, Benchmark.RecommendHelpers(none, close)!.To, "nowhere more than 3 % apart: Off, nothing gained"); + Equal(null, Benchmark.RecommendHelpers(none, new[] { new PlaceResult("Hyrule Field", 60, 50) }), "not tested: no suggestion"); + Check(Benchmark.HelperNote(new BenchRun(Array.Empty(), null, false, null, TimeSpan.Zero) { HelperThreads = 0 }).Contains("could not run"), "no helper threads: said"); + Equal("", Benchmark.HelperNote(new BenchRun(faster, null, false, null, TimeSpan.Zero)), "not asked: nothing said"); + // the other rows are judged by the way suggested + var asOff = Benchmark.AsRecommended(faster, Benchmark.HelpersOff); + Check(asOff[0].AverageFps == 70 && Benchmark.AsRecommended(faster, Benchmark.HelpersAutomatic)[0].AverageFps == 80, "the way's own figures"); + } + static void BenchSteady() { var now = new Dictionary { [Benchmark.KSteady] = 0 }; diff --git a/launcher/LogicTests/Tests.GameOptions.cs b/launcher/LogicTests/Tests.GameOptions.cs index f938f0a..589941d 100644 --- a/launcher/LogicTests/Tests.GameOptions.cs +++ b/launcher/LogicTests/Tests.GameOptions.cs @@ -13,6 +13,7 @@ static partial class Tests public static IEnumerable<(string Name, Func Run)> GameOptionsTests() { (string, Func) Sync(string n, Action a) => (n, () => { a(); return Task.CompletedTask; }); + yield return Sync("game options: output migration", OutputMigration); yield return Sync("game options: schema matches vk_menu.cpp's table", GameOptionsMatchMenu); yield return Sync("game options: keys, labels, choices, no Hookshot", GameOptionsLabels); yield return Sync("game options: the real triforce_options.ini (read only)", GameOptionsRealFile); @@ -121,7 +122,7 @@ static partial class Tests Check(table.Count > 100, "the table read: " + table.Count + " entries"); var symbols = new Dictionary { - ["kLastOutput"] = 7, ["ur::kValues - 1"] = 6, ["ur::kUpscalers - 1"] = 6, ["ur::kModels - 1"] = 3, ["aa_rows::kValues - 1"] = 3, + ["kLastOutput"] = 9, ["OUTPUT_MIN_W"] = 640, ["OUTPUT_MAX_W"] = 7680, ["OUTPUT_MIN_H"] = 360, ["OUTPUT_MAX_H"] = 2880, ["ur::kValues - 1"] = 6, ["ur::kUpscalers - 1"] = 6, ["ur::kModels - 1"] = 3, ["aa_rows::kValues - 1"] = 3, ["2 + kMaxMics"] = 18, ["HOS_PROMPT_N"] = 6, ["mr7::FG_DLSS_LAST"] = 12, ["framegen_rows::kRowMax"] = 9, }; int Num(string s, string what) => int.TryParse(s, out var v) ? v : symbols.TryGetValue(s, out v) ? v : throw new TestFailed(what + ": a symbol the test does not know, " + s); @@ -182,7 +183,9 @@ static partial class Tests Equal(string.Join("|", names), string.Join("|", GameOptionsSchema.All.Select(r => r.Name)), "the rows, in the menu's order"); // (the lines the game's save drops, merged_rows.h kDropped: kept keys, read once to move them) var mr = File.ReadAllText(Path.Combine(dir!, "merged_rows.h")); - Check(mr.Contains("kVersion = " + GameOptionsSchema.CurrentVersion + ";"), "merged_rows.h's kVersion is CurrentVersion"); + Check(mr.Contains("kVersion = 8;"), "merged rows retain stock version 8"); + var sizes = File.ReadAllText(Path.Combine(dir!, "output_sizes.h")); + Check(sizes.Contains("#define OUTPUT_OPTIONS_VERSION " + GameOptionsSchema.CurrentVersion), "output_sizes.h owns CurrentVersion"); var dropped = Regex.Match(mr, @"kDropped\[\]\s*=\s*\{([^}]*)\}").Groups[1].Value; foreach (Match d in Regex.Matches(dropped, "\"([^\"]+)\"")) Check(GameOptionsSchema.KeptKeys.ContainsKey(d.Groups[1].Value) && GameOptionsSchema.ByKey(d.Groups[1].Value) == null, d.Groups[1].Value + ": dropped by the game, a kept key here"); @@ -241,7 +244,8 @@ static partial class Tests string L(string key, int v) => GameOptionsSchema.Get(key).Label(v); string Cs(string key) => string.Join("|", GameOptionsSchema.Get(key).Choices.Select(c => c.Value + "=" + c.Label)); Equal("-3=30|-2=40|-1=45|0=60 (the console's)|1=90|2=120|3=144|4=165|5=240|6=Monitor's rate", Cs("frame_rate_cap"), "fps cap"); - Equal("7=1536x864 (handheld)|3=1920x1080|0=2048x1152|1=2560x1440|2=3840x2160|4=5120x1440|6=5120x2160|5=5120x2880", Cs("output_res"), "output sizes, smallest first"); + Equal("7=1536x864 (handheld)|3=1920x1080|0=2048x1152|1=2560x1440|2=3840x2160|4=5120x1440|6=5120x2160|5=5120x2880|8=Screen|9=Custom (2560x1440)", Cs("output_res"), + "output sizes, smallest first, then Screen and Custom"); Equal("0=Game|1=NVIDIA DLSS|3=AMD FSR 3.1|4=AMD FSR 4", Cs("dlss"), "upscalers: the engines, in the menu's order"); Equal("0=Auto (dynamic)|1=100% (2048x1152)|2=75% (1536x864)|3=67% (1366x768)|4=50% (1024x576)", Cs("resolution"), "render resolution, the game's own"); Equal("0=Off|1=Default", Cs("microphone"), "microphone without devices"); @@ -281,6 +285,123 @@ static partial class Tests Equal("NVIDIA DLSS", L("dlss", 2), "DLAA reads as its engine"); Equal("AMD FSR 3.1", L("dlss", 6), "FSR 3.1's native AA too"); Equal("Native (100%)", L("resolution", GameOptionsSchema.NativeStep), "the Render resolution's Native"); + Equal("3440", L("output_width", 3440), "Custom's width, in pixels"); + + // (the Output resolution is the picture's size, output_sizes.h: Screen and Custom show theirs as the game takes it, a size + // that is not 16:9 has its own shape, which the Ultrawide row then shows with nothing to choose, and the Render + // resolution's sizes are the picture's) + var wide = GameOptionsFile.Load(NewGameFolder("game-options-wide", "output_res=8\nultrawide=2\nresolution=2\noptions_version=9\n"), (3840, 1600)); + Equal("Screen (3840x1600)", wide.Label("output_res"), "Screen: the main monitor's size"); + Equal("2.40:1 (3840x1600)", wide.Label("ultrawide"), "its own shape, not the row's 21:9"); + Equal("2=2.40:1 (3840x1600)", string.Join("|", wide.ChoicesOf("ultrawide").Select(c => c.Value + "=" + c.Label)), "nothing to choose there"); + Equal("75% (2880x1200)", wide.Label("resolution"), "the 3D's size is the picture's share"); + Check(wide.ChoicesOf("output_res").Any(c => c.Label == "Custom (2560x1440)"), "Custom before its rows are set"); + wide.Set("output_res", 9); + wide.Set("output_width", 3437); + Equal(3440, wide.Get("output_width"), "the width on its steps of 8"); + wide.Set("output_height", 1440); + Equal("Custom (3440x1440)", wide.Label("output_res"), "Custom: its rows' size"); + Equal("2.39:1 (3440x1440)", wide.Label("ultrawide"), "3440x1440 is not 64:27"); + wide.Set("output_width", 7680); + wide.Set("output_height", 2880); + Equal("Custom (6248x2344)", wide.Label("output_res"), "more pixels than 5120x2880's: smaller, in its shape"); + wide.Set("output_res", 4); + Equal("32:9 (5120x1440)", wide.Label("ultrawide"), "5120x1440 is a 32:9 picture by itself"); + wide.Set("output_res", 6); + Equal("21:9 (5120x2160)", wide.Label("ultrawide"), "5120x2160 a 21:9 one"); + Equal("75% (3840x1620)", wide.Label("resolution"), "of the whole 5120x2160"); + wide.Set("output_res", 2); + Equal("21:9", wide.Label("ultrawide"), "a 16:9 size: the row's shape"); + Equal(4, wide.ChoicesOf("ultrawide").Count, "and its four choices"); + Equal("75% (3312x1398)", wide.Label("resolution"), "the row's 21:9 at the 4K output: kept to 3840x2160's pixels"); + wide.Set("ultrawide", 0); + Equal("75% (2880x1620)", wide.Label("resolution"), "the game's own picture"); + wide.Set("output_res", 8); + wide.Set("output_res", 7); + Equal("16:9", wide.Label("ultrawide"), "the handheld profile runs the game's own output: the row's shape"); + // (output_custom_size: the Custom size the game's menu keeps while a screen's size is in the two rows. A kept key; a + // Custom size written here is the entered one from now on and empties it, so the menu does not offer both; another + // Output resolution chosen takes it back into the rows, as walking the menu's row does; any other change leaves it) + Check(GameOptionsSchema.IsKept("output_custom_size"), "output_custom_size is a kept key"); + const string screenChosen = "output_res=9\noutput_width=3840\noutput_height=1600\noutput_custom_size=3437x1440\noptions_version=9\n"; + var kept = NewGameFolder("game-options-kept", screenChosen); + var kf = GameOptionsFile.Load(kept); + Equal("", string.Join(",", kf.UnknownKeys), "no key nobody knows"); + Equal((3437, 1440), kf.EnteredCustomSize!.Value, "the entered size, as the menu reads it"); + kf.Set("sharpness", 30); + kf.Save(); + Check(File.ReadAllText(Path.Combine(kept, GameOptionsSchema.FileName)).Contains("output_custom_size=3437x1440\n"), "another row: the line as it was"); + kf.Set("output_width", 3440); + kf.Set("output_height", 1440); + Equal(null, kf.EnteredCustomSize, "used up by a size written here"); + kf.Save(); + Equal("output_res=9\noutput_width=3440\noutput_height=1440\noutput_custom_size=\nsharpness=30\noptions_version=9\n", + File.ReadAllText(Path.Combine(kept, GameOptionsSchema.FileName)), "a Custom size written by the launcher: the kept one emptied"); + var left = NewGameFolder("game-options-left", screenChosen); + var lf = GameOptionsFile.Load(left); + lf.Set("output_res", 1); + Equal(3437, lf.Get("output_width"), "leaving Custom: the entered size back in the rows"); + lf.Save(); + Equal("output_res=1\noutput_width=3437\noutput_height=1440\noutput_custom_size=\noptions_version=9\n", + File.ReadAllText(Path.Combine(left, GameOptionsSchema.FileName)), "and the line emptied"); + // (read under any Output resolution, as the menu does: under a fixed size with a screen's size in the rows, Custom + // is the size kept aside, and choosing it, or another fixed size, takes it back into the rows) + const string fixedChosen = "output_res=1\noutput_width=3840\noutput_height=1600\noutput_custom_size=3437x1440\noptions_version=9\n"; + var ff = GameOptionsFile.Load(NewGameFolder("game-options-kept-fixed", fixedChosen)); + Equal((3437, 1440), ff.EnteredCustomSize!.Value, "read under a fixed size too"); + Check(ff.ChoicesOf("output_res").Any(c => c.Value == 9 && c.Label == "Custom (3440x1440)"), "Custom offered as the size it takes back, not the screen's in the rows"); + ff.Set("output_res", 9); + Equal("Custom (3440x1440)", ff.Label("output_res"), "chosen: that size"); + Equal(3437, ff.Get("output_width"), "as entered, in the rows"); + ff.Save(); + Equal("output_res=9\noutput_width=3437\noutput_height=1440\noutput_custom_size=\noptions_version=9\n", File.ReadAllText(ff.Path), "written, the line emptied"); + var f2 = GameOptionsFile.Load(NewGameFolder("game-options-kept-fixed2", fixedChosen)); + f2.Set("output_res", 3); + f2.Save(); + Equal("output_res=3\noutput_width=3437\noutput_height=1440\noutput_custom_size=\noptions_version=9\n", File.ReadAllText(f2.Path), "another fixed size: taken back as well"); + var f3 = GameOptionsFile.Load(NewGameFolder("game-options-kept-fixed3", fixedChosen)); + f3.Set("sharpness", 30); + f3.Save(); + Check(File.ReadAllText(f3.Path).Contains("output_width=3840\noutput_height=1600\noutput_custom_size=3437x1440\n"), "any other row: all three as they were"); + Equal(null, GameOptionsFile.Load(NewGameFolder("game-options-kept-bad", "output_res=9\noutput_custom_size=100x100\noptions_version=9\n")).EnteredCustomSize, + "nor a size the rows cannot hold"); + var none = NewGameFolder("game-options-kept-none", "output_res=9\noutput_width=3840\noutput_height=1600\noptions_version=9\n"); + var nf8 = GameOptionsFile.Load(none); + nf8.Set("output_width", 3440); + nf8.Save(); + Check(!File.ReadAllText(Path.Combine(none, GameOptionsSchema.FileName)).Contains("output_custom_size"), "no line where the file has none"); + + // (a size keeps its shape: one past the rows' ends is made smaller in it, as the game reads the file's two numbers) + var tall = GameOptionsFile.Load(NewGameFolder("game-options-tall", "output_res=9\noutput_width=10000\noutput_height=5000\noptions_version=9\n")); + Equal("Custom (5424x2712)", tall.Label("output_res"), "10000x5000 is 2:1 at 5120x2880's pixels"); + Equal(5424, tall.Get("output_width"), "and the rows hold that size"); + Equal("2.00:1 (5424x2712)", tall.Label("ultrawide"), "its shape kept"); + // (the pair is shown as the game takes it, so one side changed is written with the other as shown: 3840 beside the + // file's 4320 would be 16:18 by the file, 5:4 for the game, where the launcher showed 3840x2880) + var pair = NewGameFolder("game-options-pair", "output_res=9\noutput_width=7680\noutput_height=4320\noptions_version=9\n"); + var pf = GameOptionsFile.Load(pair); + Equal("Custom (5120x2880)", pf.Label("output_res"), "7680x4320 in the file: 5120x2880"); + Equal(2880, pf.Get("output_height"), "the rows hold the size taken"); + pf.Set("output_width", 3840); + Equal("Custom (3840x2880)", pf.Label("output_res"), "the width changed, beside the height shown"); + pf.Save(); + Equal("output_res=9\noutput_width=3840\noutput_height=2880\noptions_version=9\n", File.ReadAllText(Path.Combine(pair, GameOptionsSchema.FileName)), + "both sides written: the size shown"); + Equal("Custom (3840x2880)", GameOptionsFile.Load(pair).Label("output_res"), "and read back as shown"); + var one = NewGameFolder("game-options-one-side", "output_res=9\noutput_height=1600\noptions_version=9\n"); + var of1 = GameOptionsFile.Load(one); + of1.Set("output_height", 1440); + of1.Save(); + Equal("output_res=9\noutput_height=1440\noutput_width=2560\noptions_version=9\n", File.ReadAllText(Path.Combine(one, GameOptionsSchema.FileName)), + "a side the file has no line for: written too"); + Equal("Screen (5120x2880)", GameOptionsFile.Load(NewGameFolder("game-options-8k", "output_res=8\noptions_version=9\n"), (7680, 4320)).Label("output_res"), + "a 7680x4320 screen: 16:9 still"); + Equal("Custom (2560x1440)", GameOptionsFile.Load(NewGameFolder("game-options-nosize", "output_res=9\noutput_width=0\noutput_height=-3\noptions_version=9\n")).Label("output_res"), + "a side that is not a size: its default"); + Equal("Screen", GameOptionsFile.Load(NewGameFolder("game-options-noscreen", "output_res=8\noptions_version=9\n")).Label("output_res"), + "Screen where the launcher does not know the monitor"); + Equal("Screen (1368x768)", GameOptionsFile.Load(NewGameFolder("game-options-1366", "output_res=8\noptions_version=9\n"), (1366, 768)).Label("output_res"), + "a 16:9 screen: the game's frame at its height"); // (the GPU device row: the names the launcher gives it) var before = GameOptionsSchema.GpuNames; @@ -397,7 +518,7 @@ static partial class Tests "fps_counter=1\r\nhdr=0\r\nhdr_paper_white=400\r\nhdr_peak_brightness=4000\r\nrenodx_midgray=2\r\nrenodx_color_space=2\r\nquality_preset=0\r\n" + "resolution=1\r\ntexture_detail=1\r\ndlss=0\r\ndlss_model=1\r\nanti-aliasing=1\r\nsharpness=50\r\nupscaling=2\r\nframe_pacing=1\r\nnvidia_reflex=0\r\n" + "robust_buffers=1\r\nmicrophone=1\r\nmouse_sensitivity=125\r\ncontroller_in_background=1\r\nlayout_preset=1\r\nbutton_prompts=2\r\ndebug_tools=0\r\n" + - "replay_helper_threads=0\r\ntail_early=1\r\noptions_version=7\r\nmenu_size=1\r\npad_a=0\r\nkey_a=69,0\r\nkey_cam_right=39,76\r\n"; + "replay_helper_threads=0\r\ntail_early=1\r\noptions_version=9\r\nmenu_size=1\r\npad_a=0\r\nkey_a=69,0\r\nkey_cam_right=39,76\r\n"; static string NewGameFolder(string name, string content) { @@ -510,23 +631,23 @@ static partial class Tests Check(merged.Contains("\r\nhdr=2\r\nzz_tool_line=5\r\n"), "the outside change and its new line kept in place"); Check(merged.StartsWith("fullscreen=1\r\n"), "the launcher's change in its line"); Check(merged.Contains("\r\nsharpness=70\r\n"), "a row changed on both sides: the launcher's (the later writer)"); - Equal(outside.Replace("fullscreen=0", "fullscreen=1").Replace("sharpness=20", "sharpness=70").Replace("options_version=7", "options_version=8"), merged, + Equal(outside.Replace("fullscreen=0", "fullscreen=1").Replace("sharpness=20", "sharpness=70").Replace("options_version=7", "options_version=9"), merged, "every other line as the file had it (the version 7 file brought up to 8: nothing of it moves)"); Equal("zz_tool_line", a.UnknownKeys.Single(), "an unknown key, kept"); Equal(2, a.Get("hdr"), "this object holds the file as written"); // (a row with no line goes in before options_version; duplicates all take the value) - var d = NewGameFolder("game-options-dup", "sharpness=10\nsharpness=20\n#note\noptions_version=7\nmenu_size=1\n"); + var d = NewGameFolder("game-options-dup", "sharpness=10\nsharpness=20\n#note\noptions_version=9\nmenu_size=1\n"); var df = GameOptionsFile.Load(d); Equal(20, df.Get("sharpness"), "the last line wins, as the game reads it"); df.Set("sharpness", 30); df.Set("vsync", 0); df.Save(); - Equal("sharpness=30\nsharpness=30\n#note\nvsync=0\noptions_version=8\nmenu_size=1\n", File.ReadAllText(Path.Combine(d, GameOptionsSchema.FileName)), "LF kept, line added, comment kept, brought up to 8"); + Equal("sharpness=30\nsharpness=30\n#note\nvsync=0\noptions_version=9\nmenu_size=1\n", File.ReadAllText(Path.Combine(d, GameOptionsSchema.FileName)), "LF kept, line added, comment kept"); // (a device's name in UTF-8: its bytes as they were, its label as text) var mic = "microphone_device=Mikrofon (Ä USB)"; - var micBytes = Encoding.UTF8.GetBytes("microphone=2\r\n" + mic + "\r\noptions_version=7\r\n"); + var micBytes = Encoding.UTF8.GetBytes("microphone=2\r\n" + mic + "\r\noptions_version=9\r\n"); var mg = Path.Combine(NewRoot("game-options-mic"), "game"); Directory.CreateDirectory(mg); File.WriteAllBytes(Path.Combine(mg, GameOptionsSchema.FileName), micBytes); @@ -559,7 +680,7 @@ static partial class Tests Equal(10000, f.Set("hdr_peak_brightness", 12345), "past the end: the end"); Equal(130, f.Set("mouse_sensitivity", 125), "onto the steps: the nearest, the larger on a tie"); Equal(50, f.Set("rumble_strength", 60), "rumble on 25s"); - Equal(0, f.Set("output_res", 9), "an output past the list: the first"); + Equal(0, f.Set("output_res", 10), "an output past the list: the first"); Equal(7, f.Set("output_res", 7), "the handheld profile's output"); Equal(-1, f.Set("left_stick_dead_zone", -7), "a range below 0"); Equal(-3, f.Set("frame_rate_cap", -3), "the cap's 30"); @@ -648,14 +769,38 @@ static partial class Tests Equal(1, f.Get("frame_pacing"), "pacing on, as the game reads a file before 7"); Equal(2, f.Get("ultrawide"), "the monitor's shape at 2560x1080: 21:9"); Equal(0, f.Get("nvidia_reflex"), "Reflex as saved from 5 on"); - Equal(0, GameOptionsFile.Load(g).Get("ultrawide"), "without the screen: 16:9, as the game where it cannot ask"); + // (without the screen, as the launcher is off Windows: the row is the game's to read, which knows its screen and reads + // 21:9 on this one. Not shown as a guess; and a save keeps the file at its version with its old lines, where it + // wrote ultrawide=0 and the current version, which the game then took as the player's 16:9) + var blind = NewGameFolder("game-options-v5-blind", "frame_pacing=0\r\nultrawide=1\r\noutput_res=4\r\nsharpness=20\r\noptions_version=5\r\n"); + var bf = GameOptionsFile.Load(blind); + Equal(1, bf.Get("ultrawide"), "without the screen: the row as the file has it, for the game"); + Equal(4, bf.Get("output_res"), "and the 5120x1440 that depends on it"); + Equal(1, bf.Get("frame_pacing"), "the file's other old rules still read"); + bf.Set("sharpness", 30); + bf.Save(); + Equal("frame_pacing=0\r\nultrawide=1\r\noutput_res=4\r\nsharpness=30\r\noptions_version=5\r\n", + File.ReadAllText(Path.Combine(blind, GameOptionsSchema.FileName)), "saved at its version: nothing guessed, nothing migrated"); + Equal(5, GameOptionsFile.Load(blind).Version, "still 5"); + // (the row set here is a choice among the current shapes: the file is brought up to date with it) + bf.Set("ultrawide", 2); + bf.Save(); + Equal("frame_pacing=1\r\nultrawide=2\r\noutput_res=4\r\nsharpness=30\r\noptions_version=9\r\n", + File.ReadAllText(Path.Combine(blind, GameOptionsSchema.FileName)).Replace("tail_early=1\r\n", ""), + "the row chosen here: up to date, beside the 5120x1440 the launcher showed"); + // (with the screen known nothing waits, as before; nor from version 6 on, where 1 is 16:10) + Equal(1, GameOptionsFile.Load(NewGameFolder("game-options-v6-blind", "ultrawide=1\noptions_version=6\n")).Get("ultrawide"), "from 6 on: 16:10"); + var v6 = GameOptionsFile.Load(NewGameFolder("game-options-v6-save", "ultrawide=1\nsharpness=20\noptions_version=6\n")); + v6.Set("sharpness", 30); + v6.Save(); + Check(File.ReadAllText(v6.Path).Contains("options_version=9"), "a version 6 file is brought up to date without a screen"); f.Set("sharpness", 30); f.Save(); - Equal("frame_pacing=1\r\nultrawide=2\r\nnvidia_reflex=0\r\nsharpness=30\r\noptions_version=8\r\npad_a=0\r\n", + Equal("frame_pacing=1\r\nultrawide=2\r\nnvidia_reflex=0\r\nsharpness=30\r\noptions_version=9\r\npad_a=0\r\n", File.ReadAllText(Path.Combine(g, GameOptionsSchema.FileName)).Replace("tail_early=1\r\n", ""), "brought up to 8 as the game would read it"); - Check(File.ReadAllText(Path.Combine(g, GameOptionsSchema.FileName)).Contains("tail_early=1\r\noptions_version=8"), "the Debug tab's tail_early too, before the version"); + Check(File.ReadAllText(Path.Combine(g, GameOptionsSchema.FileName)).Contains("tail_early=1\r\noptions_version=9"), "the Debug tab's tail_early too, before the version"); var again = GameOptionsFile.Load(g); - Equal(8, again.Version, "now 8"); + Equal(9, again.Version, "now 8"); again.Set(GameOptionsSchema.PacingKey, 0); again.Save(); Equal(0, GameOptionsFile.Load(g).Get("frame_pacing"), "and from 7 on the choice is read as it is"); @@ -671,7 +816,7 @@ static partial class Tests Equal("", string.Join(",", hf.UnknownKeys), "the old rows' lines: known"); hf.Set("vsync", 0); hf.Save(); - Equal("output_res=7\nhandheld_profile=1\nstick_dead_zone=3\nright_stick_dead_zone=12\nquality_preset=4\nupscaling=2\nvsync=0\nleft_stick_dead_zone=15\noptions_version=8\n", + Equal("output_res=7\nhandheld_profile=1\nstick_dead_zone=3\nright_stick_dead_zone=12\nquality_preset=4\nupscaling=2\nvsync=0\nleft_stick_dead_zone=15\noptions_version=9\n", File.ReadAllText(Path.Combine(h, GameOptionsSchema.FileName)), "brought up to 8: the moved values written, the old lines left for the game to drop"); var h8 = GameOptionsFile.Load(h); h8.Set("output_res", 1); @@ -681,6 +826,23 @@ static partial class Tests var n7 = GameOptionsFile.Load(NewGameFolder("game-options-n7", "output_res=3\nleft_stick_dead_zone=-1\noptions_version=7\n")); Equal(3, n7.Get("output_res"), "no handheld line: the output as it is"); Equal(-1, n7.Get("left_stick_dead_zone"), "no shared line: the default"); + // (options_version 7: 5120x1440 and 5120x2160 were the game's frame, and the Ultrawide row gave the picture's shape there + // too. With the row on another shape than theirs: the 16:9 size of their height, the same picture; else as they are) + var w7 = NewGameFolder("game-options-v7", "output_res=4\r\nultrawide=2\r\nsharpness=20\r\noptions_version=7\r\n"); + var wf7 = GameOptionsFile.Load(w7); + Equal(1, wf7.Get("output_res"), "5120x1440 with the row on 21:9: 2560x1440, whose 21:9 picture it was"); + Equal("21:9", wf7.Label("ultrawide"), "and the row's shape still"); + wf7.Set("sharpness", 30); + wf7.Save(); + Equal("output_res=1\r\nultrawide=2\r\nsharpness=30\r\noptions_version=9\r\n", File.ReadAllText(Path.Combine(w7, GameOptionsSchema.FileName)), + "written as the game reads it, at 8"); + Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v7b", "output_res=4\nultrawide=3\noptions_version=7\n")).Get("output_res"), "its own shape: as it is"); + Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v7c", "output_res=4\nultrawide=0\noptions_version=7\n")).Get("output_res"), "16:9 there: as it is, now its picture"); + Equal(2, GameOptionsFile.Load(NewGameFolder("game-options-v7d", "output_res=6\nultrawide=3\noptions_version=7\n")).Get("output_res"), "5120x2160 with 32:9: 3840x2160"); + Equal(6, GameOptionsFile.Load(NewGameFolder("game-options-v7e", "output_res=6\nultrawide=2\noptions_version=7\n")).Get("output_res"), "5120x2160 with its 21:9"); + Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v8", "output_res=4\nultrawide=2\noptions_version=9\n")).Get("output_res"), "from 8 on as chosen: the row is not read there"); + Equal(4, GameOptionsFile.Load(NewGameFolder("game-options-v5b", "output_res=4\nultrawide=1\noptions_version=5\n"), (5120, 1440)).Get("output_res"), + "before 6 the row's 1 was the monitor's shape: 32:9 on a 5120x1440 one, 5120x1440's own"); // (no options_version line: Game speed real time; no resolution line but the old dynamic_resolution) var o = NewGameFolder("game-options-v0", "game_speed=0\ndynamic_resolution=0\n"); @@ -704,7 +866,7 @@ static partial class Tests nf.Set(GameOptionsSchema.PacingKey, 3); nf.Save(); var nl = OperatingSystem.IsWindows() ? "\r\n" : "\n"; - Equal("vsync=0" + nl + "steady_frame_rate=2" + nl + "master_volume=85" + nl + "options_version=8" + nl, File.ReadAllText(nf.Path), + Equal("vsync=0" + nl + "steady_frame_rate=2" + nl + "master_volume=85" + nl + "options_version=9" + nl, File.ReadAllText(nf.Path), "a new file: the values in the menu's order (a merged row's parts at its place; frame_pacing at its default not written), then the version"); Check(nf.Exists, "now there"); } diff --git a/launcher/LogicTests/Tests.OutputMigration.cs b/launcher/LogicTests/Tests.OutputMigration.cs new file mode 100644 index 0000000..7109153 --- /dev/null +++ b/launcher/LogicTests/Tests.OutputMigration.cs @@ -0,0 +1,42 @@ +using Triforce.Logic; +using static Triforce.LogicTests.T; + +namespace Triforce.LogicTests; + +static partial class Tests +{ + static void OutputMigration() + { + foreach (var (name, text, output) in new[] + { + ("launcher-profile", "handheld_profile=1\noptions_version=9\n", 7), + ("stock-stale-profile", "output_res=1\nhandheld_profile=1\noptions_version=8\n", 1), + ("stock-handheld", "output_res=7\noptions_version=8\n", 7), + ("stock-wide", "output_res=4\nultrawide=2\noptions_version=8\n", 1), + ("native-screen", "output_res=7\noutput_width=2560\noutput_height=1440\noptions_version=8\n", 8), + ("native-wide", "output_res=4\nultrawide=2\noutput_width=2560\noutput_height=1440\noptions_version=8\n", 4), + ("player", "output_res=8\noutput_width=3840\noutput_height=1600\noutput_custom_size=2560x1440\nultrawide=2\noptions_version=8\n", 9), + }) + { + var folder = NewGameFolder("migration-" + name, text); + var file = GameOptionsFile.Load(folder, (3840, 1600)); + Equal(output, file.Get("output_res"), name + " read"); + file.Set("sharpness", 25); + file.Save(); + var again = GameOptionsFile.Load(folder, (3840, 1600)); + Equal(9, again.Version, name + " version"); + Equal(output, again.Get("output_res"), name + " round trip"); + if (name == "player") + { + Equal(3840, again.Get("output_width"), "player active width"); + Equal(1600, again.Get("output_height"), "player active height"); + Check(File.ReadAllText(again.Path).Contains("output_custom_size=2560x1440"), "remembered pair retained"); + } + } + var handheld = GameOptionsFile.Load(NewGameFolder("migration-handheld", "output_res=7\nhandheld_profile=1\noptions_version=9\n")); + handheld.Set("output_res", 0); + handheld.Save(); + Equal(0, GameOptionsFile.Load(Path.GetDirectoryName(handheld.Path)!).Get("output_res"), "leaving native handheld round trip"); + Check(File.ReadAllText(handheld.Path).Contains("handheld_profile=0"), "old native profile follows the output row"); + } +} diff --git a/launcher/LogicTests/Tests.Release.cs b/launcher/LogicTests/Tests.Release.cs index d4aadb4..f5c7043 100644 --- a/launcher/LogicTests/Tests.Release.cs +++ b/launcher/LogicTests/Tests.Release.cs @@ -294,6 +294,24 @@ static partial class Tests File.Delete(Path.Combine(t2.Folder, Tools.BaseHave)); Check(!Tools.HasBase(b2, t2.Folder, null), "a real base file changed still is not"); Check(Tools.Regenerated(@"python\Lib\x\__pycache__\a.pyc") && !Tools.Regenerated("python/Lib/os.py"), "what counts as rewritten"); + + // (11-22, v0.7.0's update stop "The tools' base lacks python/Lib/.../__pycache__/...pyc (or it has another size)": HasBase + // kept a base whose caches Python had rewritten, and UnpackParts' last look then wanted them at their packed sizes) + var root3 = NewRoot("parts-pyc-unpack"); + var t3 = new Tools(Ctx(root3)); + var list3 = BaseList(("python/python.exe", "py"), ("python/Lib/__pycache__/os.cpython-314.pyc", "packed bytes"), + ("python/Lib/__pycache__/gone.cpython-314.pyc", "packed")); + var b3 = Tools.ParseBaseList(list3)!; + Directory.CreateDirectory(Path.Combine(t3.Folder, "python", "Lib", "__pycache__")); + File.WriteAllText(Path.Combine(t3.Folder, "python", "python.exe"), "py"); + File.WriteAllText(Path.Combine(t3.Folder, "python", "Lib", "__pycache__", "os.cpython-314.pyc"), "rewritten by python, longer"); + File.WriteAllText(Path.Combine(t3.Folder, "version.txt"), "v0.6.0"); + Check(Tools.HasBase(b3, t3.Folder, null), "the kept base with rewritten and missing caches"); + var code3 = Path.Combine(root3, "code.zip"); + File.WriteAllBytes(code3, Zip(("tools/nx2/make_game.py", "new"), ("tools/base.list", list3))); + t3.UnpackParts(code3, null, b3, "v0.7.0", null); + Equal("v0.7.0", t3.InstalledVersion, "a code part over a base whose caches Python rewrote"); + Equal("rewritten by python, longer", File.ReadAllText(Path.Combine(t3.Folder, "python", "Lib", "__pycache__", "os.cpython-314.pyc")), "its caches kept as they were"); } static async Task ToolsUpdate() diff --git a/launcher/ui/app.js b/launcher/ui/app.js index bfbaf7e..be04286 100644 --- a/launcher/ui/app.js +++ b/launcher/ui/app.js @@ -754,7 +754,7 @@ function onBench(b) { $('#benchEb').textContent = b.eb || ''; $('#places').innerHTML = (b.places || []).map(p => `
${sparkline(p.graph)}${p.graph2 ? sparkline(p.graph2, 'b') : ''}
` + (p.fps2 != null - ? `
${esc(p.name)}Your settings${p.fps} fps · low ${p.low}${esc(b.second || '')}${p.fps2} fps · low ${p.low2}
` + ? `
${esc(p.name)}${esc(b.first || 'Your settings')}${p.fps} fps · low ${p.low}${esc(b.second || '')}${p.fps2} fps · low ${p.low2}
` : `
${esc(p.name)}${p.fps} fps · low ${p.low}
`)).join(''); $('#verdict').innerHTML = b.verdict || ''; $('#recs').innerHTML = (b.recs || []).map(r => `
${esc(r.name)}${esc(r.from)}→${esc(r.to)}
`).join(''); diff --git a/nx2/make_game.py b/nx2/make_game.py index 2af8c0e..0229ef8 100644 --- a/nx2/make_game.py +++ b/nx2/make_game.py @@ -2025,6 +2025,31 @@ def fsr_wanted(a, out): RENODX_MARK = ".hookshot_renodx" # (in a game folder built with RenoDX's HDR: --update builds it with RenoDX again) +def write_mark(path): + """A folder's mark (FSR_MARK, RENODX_MARK) for the next --update. It only remembers a choice: a drive that refuses the + file (11-23 ticket 108774, OSError [Errno 22] on an X: drive) must not stop the build. A read-only or hidden one left there + is cleared and written once more; failing that, a note and the build goes on (Setup passes the switch itself)""" + for attempt in (0, 1): + try: + open(path, "w").close() + return True + except OSError as e: + if attempt == 0 and os.path.exists(path): + try: + os.chmod(path, 0o666) + if os.name == "nt": + import ctypes + ctypes.windll.kernel32.SetFileAttributesW(str(path), 0x80) # (FILE_ATTRIBUTE_NORMAL) + os.remove(path) + continue + except OSError: + pass + print("note: the folder's mark %s could not be written (%s): the build goes on; the next update needs the same " + "choice in Setup" % (os.path.basename(path), e), flush=True) + return False + return False + + def renodx_wanted(a, out): """RenoDX's HDR in this build. (Triforce, 11-13: every build has it, not only one that asks with --renodx; --no-renodx builds without. It acts only with the Insert menu's HDR set to Native.)""" @@ -2181,7 +2206,7 @@ def main(a=None): if fsr_wanted(a, out): os.environ["HOOKSHOT_FSR"] = "1" fetch_fsr_runtime(work) # (AMD's two libraries, for the game folder: place_fsr_runtime at the end) - open(os.path.join(out, FSR_MARK), "w").close() + write_mark(os.path.join(out, FSR_MARK)) if os.environ.get("HOOKSHOT_VK_PREBUILT"): # (the AppImage's back end: built with FSR 4 since 11-20, appimage.sh) print("--fsr: this build uses the prebuilt Vulkan back end (HOOKSHOT_VK_PREBUILT), which has AMD FSR 4 built in " "already: the Upscaler row offers it once amd_fidelityfx_upscaler_vk.so is in the game folder", flush=True) @@ -2200,7 +2225,7 @@ def main(a=None): renodx_folder = prepare_renodx(work) if renodx_folder: os.environ["HOOKSHOT_RENODX"] = renodx_folder - open(os.path.join(out, RENODX_MARK), "w").close() + write_mark(os.path.join(out, RENODX_MARK)) else: os.environ.pop("HOOKSHOT_RENODX", None) if os.path.isfile(os.path.join(out, RENODX_MARK)): diff --git a/nx2/oot_wide.py b/nx2/oot_wide.py index 9204ac8..aa3a15c 100644 --- a/nx2/oot_wide.py +++ b/nx2/oot_wide.py @@ -3,7 +3,8 @@ The game draws a 2560x1440 picture whatever the screen and renders its scene at 1920x1080; its cameras use a 16:9 ratio. With these patches the picture takes the window's shape (the height stays the game's, the width grows on an ultrawide screen and shrinks on a 16:10 or 4:3 one), the 16:9 cameras take the picture's ratio, the HUD and menus keep their 16:9 -shape in the middle of a wider picture (a narrower one: its whole width), pre-rendered movies play in that middle 16:9, +shape in the middle of a wider picture (a narrower one: its whole width), story movies play in that middle 16:9, +title movies fill the picture up to 12:5, and the picture a save keeps shows that middle 16:9 (a narrower picture: its middle band, at the texture's shape). Every patch reads host globals (host/hos_wide.c) that stay 0 for a 16:9 window, so the game runs as shipped then. @@ -51,7 +52,11 @@ HUD = ("{ extern volatile float hos_wide_squeeze; if (hos_wide_squeeze > 0.0f) { " /* (nx2/oot_wide.py: HUD in the middle 16:9, or at the screen's edges) */" % (UI_M00, UI_M11)) -MOVIE = ("{ extern volatile float hos_wide_margin; const float _m = hos_wide_margin; if (_m > 0.0f) { " +# Within f_83b7c710 the movie site (main+0x3b5c758) and its SetViewport (main+0x284824) run +# on the same thread. Between 0x83b7c758 and the unconditional call at 0x83b7c78c, only f_809ebaf0 runs; it calls no viewport helper. +# Leave the scissor full width and consume the mark only at SetViewport. +MOVIE = ("{ extern int hos_movie_cover_begin(float); extern volatile float hos_wide_ratio; " + "extern volatile float hos_wide_margin; const float _m = hos_wide_margin; if (!hos_movie_cover_begin(hos_wide_ratio) && _m > 0.0f) { " "const uint64_t _vp = c->x[29] - 40; uint32_t _ua = (uint32_t)recomp_load32(c, _vp + 8), _ub = (uint32_t)recomp_load32(c, _vp + 16); " "float _a, _b; memcpy(&_a, &_ua, 4); memcpy(&_b, &_ub, 4); const float _in = (_b - _a) * _m; _a += _in; _b -= _in; " "memcpy(&_ua, &_a, 4); memcpy(&_ub, &_b, 4); recomp_store32(c, _vp + 8, _ua); recomp_store32(c, _vp + 16, _ub); } }" @@ -63,7 +68,8 @@ MOVIE = ("{ extern volatile float hos_wide_margin; const float _m = hos_wide_mar # ratio over 16:9, centred: the middle 16:9 fills the texture (the scissor keeps the texture's), as a 16:9 window would show. # Narrower than 16:9 (4:3, 16:10) it is made taller instead, by 16:9 over the picture's ratio: the picture's middle band fills # the texture at its own shape, neither squeezed nor with bars. -THUMB = ("{ extern volatile float hos_wide_ratio; const float _r = hos_wide_ratio; if (_r > 0.0f && (uint32_t)c->x[1] == 0 " +THUMB = ("{ extern int hos_movie_cover_viewport(uint64_t *, uint64_t *); " + "extern volatile float hos_wide_ratio; const float _r = hos_wide_ratio; if (!hos_movie_cover_viewport(&c->x[2], &c->x[4]) && _r > 0.0f && (uint32_t)c->x[1] == 0 " "&& (uint32_t)c->x[2] == 0 && (uint32_t)c->x[3] == 543 && (uint32_t)c->x[4] == 306) { " "if (_r > 16.0f / 9.0f) { const int _w = (int)(543.0f * _r / (16.0f / 9.0f) + 0.5f); " "c->x[1] = (uint32_t)((543 - _w) / 2); c->x[3] = (uint32_t)_w; } " diff --git a/nx2/prompt_assets.py b/nx2/prompt_assets.py index 99c16a2..3a026a0 100644 --- a/nx2/prompt_assets.py +++ b/nx2/prompt_assets.py @@ -890,7 +890,7 @@ HINT_FITS = 720 # (the widest advance the game's spacing holds: its own should HINT_SCALE = 0.1 # (layout units per font unit: the icons' panes draw the font at 100 per 1000 em) -def layout_panes(lay): +def layout_panes(lay, *, unique=False): """a BFFH layout's panes: {name: its record's offset} (the record: rotation, scale at +0x10, translation at +0x1c, size at +0x2c); the header gives the offsets of the names' table (+0x118), the records' table (+0x120) and the count (+0x130)""" names, recs = struct.unpack_from("> 4) << 16) + + +HUD_COUNTER_INSTANCES = {"Pa_Parts_00", "Pa_Parts_01"} +HUD_X_TRACKS = { + "DoCommand_00": [("N_PosType_00", "PosType", 2, {234: 0, 724: 1, 466: 0})], + "MapMenu_00": [("N_MapIcon_00", "MapType", 2, {1490: 1}), + ("N_PatternDungeonMini_01", "DungeonMiniMapPattern", 2, {1536: 1})], + "SaveLoadIcon_00": [("N_InOut_00", "EnableText", 1, {-1720: -1, 1740: 1})], +} + + +# The dungeon pattern inherits MapType. Both sets of offsets shipped in the original minimap. +HUD_NESTED_TRACKS = {("MapMenu_00", "N_PatternDungeonMini_01", "DungeonMiniMapPattern"): + ("N_MapIcon_00", "MapType")} + + +def hud_track_keys(lay, animation, path, places, channels): + """Follow the animation's target descriptor to its indexed curve. Reject missing or ambiguous bindings.""" + name = lay.find(b"\0" + animation.encode() + b"\0") + 1 + if not name: + return None + found = [] + for rec in range(0, len(lay) - 39, 8): + if struct.unpack_from(" len(lay) or curves + 8 * nc > len(lay): + continue + for i in range(n): + desc, = struct.unpack_from(" len(lay): + return None + token, index, sentinel, count, attr = struct.unpack_from(" nc: + return None + curve, = struct.unpack_from(" len(lay): + return None + values, = struct.unpack_from(" len(lay): + return None + at, size, step = struct.unpack_from(" len(lay): + return None + offsets = range(at, at + size * 4, 8) + keys = {} + previous = None + for off in offsets: + x, slope = struct.unpack_from(" len(lay): - continue - v = struct.unpack_from(f"<{n}f", lay, at) - if any(v[1::2]) or not any(k in xs for k in v[::2]) or any(k and k not in xs for k in v[::2]): - continue - out += [at + 8 * k for k in range(n // 2) if v[2 * k] in xs] - if o >= 8 and struct.unpack_from("` in `triforce_env.txt` fixes the filter) | -| Aspect ratio | 16:9 (the game's own), 16:10, 21:9, 32:9: the fixed shapes are for a screen or a window of that shape (a screen of another shape shows black bars); applies at the next start. Wider than 16:9, HUD position and Menu sides show too | +| Output resolution | Connected monitors by name, Custom with editable width and height, Use current window size, and 1536x864 (handheld: the game's handheld profile, as if the console were undocked), 1920x1080, 2048x1152 (the game's own), 2560x1440, 3840x2160, 5120x1440, 5120x2160, 5120x2880; applies at the next start. The finished picture is scaled to the window by AMD FSR 1 when it is enlarged (sharpened only by the Sharpness row) and by the plain copy otherwise, and always by the plain copy with HDR Native, which keeps its 10 bits (`RX_VK_UPSCALE=<0..3>` in `triforce_env.txt` fixes the filter) | +| Aspect ratio | 16:9 (the game's own), 16:10, 21:9, 32:9, 4:3: the fixed shapes are for a screen or a window of that shape (a screen of another shape shows black bars); 4:3 is a TV's of 1998, for N64 Classic; applies at the next start. Wider than 16:9, HUD position and Menu sides show too | +| Output shape | 16:9 (the game's own), 16:10, 21:9, 32:9: the picture's shape for a 16:9 Output resolution, at the same height. The fixed shapes are for a screen or a window of that shape (a screen of another shape shows black bars). An Output resolution that is not 16:9 (5120x1440, 5120x2160, or a screen's or Custom size of another shape) has its own shape: the row shows it and has nothing to choose. Applies at the next start | | FPS counter | Off, On, Full: On is the frame rate in the top right corner; Full shows NX2navi's performance overlay there in its place (under the options while they are open), in the options' look and see-through: the build, the GPU's and the CPU's load and temperature, video memory and memory, the frame rate with its 1% and 0.1% lows, the frame times and their graph, the GPU's and the replay's time and waits per frame, the picture's settings and the GPU's and CPU's names (a "-" where the PC does not say: temperature and power need an NVIDIA or AMD card). It measures only while shown | | Menu sounds | Off, 5% to 100% (80% unless you change it): the game's own interface sounds as you move through these settings, the tabs and the rows, read from your game files (a mod's when a mod replaces them). Under Master volume on the Audio tab; changes at once | | Controller in background | Off, On: the pad keeps playing while another window has focus | @@ -255,14 +257,15 @@ F8 to one of the controls yourself, the key stays the game's and the row takes t ## Achievements -*On by default.* `HOS_ACHIEVEMENTS=0` in `triforce_env.txt` beside the game turns them off. Things you do in the game are marked as earned, as a console's or a store's achievements are: a notice at the +*On by default.* The System tab of the Options opens with an **Achievements** group: **Achievements** turns them off and on, at once, and **Achievement notices** turns off the notice and its sound alone (what you earn is still earned and listed). `HOS_ACHIEVEMENTS=0` in `triforce_env.txt` beside the game turns them off whole. Things you do in the game are marked as earned, as a console's or a store's achievements are: a notice at the top of the screen shows the one you earned, with its icon and a sound at the **Menu sounds** row's volume. -- **The list:** **Achievements** on the System tab of the Options opens a page with every achievement, its icon, the +- **The list:** **View achievements**, the group's first row, opens a page with every achievement, its icon, the line about it, and whether and when you earned it. Left, Right, Up and Down move; **L** and **R** turn the page. + The notice says where it is. -- **25 come with Triforce:** the Spiritual Stones, the Master Sword, each medallion, the songs, Gold Skulltula tokens - and a few items. They are earned by what Link carries, read from the save data once a second while a save is loaded. +- **35 come with Triforce:** the Spiritual Stones, the Master Sword, each medallion, the songs, Gold Skulltula tokens + and a few items, and some odd ones (10 Magic Beans at once, a blade that will not last). They are earned by what Link carries, read from the save data once a second while a save is loaded. Nothing in the game or the save is changed. - **Earned once, for the game folder:** `triforce_achievements.txt` beside the game keeps them, with the time. Loading an older save takes none away; delete the file to start over. `triforce_log.txt` has a line for each one earned. @@ -287,6 +290,34 @@ They are Triforce's own: Steam and Xbox do not see them.

+## Save files + +*On by default.* Your saves so far are File 1, where they always were; nothing is moved. (`HOS_SAVE_FILES=0` in +`triforce_env.txt` beside the game turns it off.) You have three files to play, as the Nintendo 64 game did, and everything the game saves, its autosaves too, lives in +the file you chose: three playthroughs side by side. + +- **At the title:** the game starts on the file you played last and shows its title as ever. Its list has one more + entry under Mods, **Save Select**, which opens **Select a file**. The file marked *Playing* is the one the game + started on: choose it and you are back in the game's own list. Choose another and **the game starts again on that + file** (it reads its saves only at its start). +- **Each file's card** is laid out as the game's own load list: **the picture the game kept of the save** (Windows + only), when it was last saved, **where you were**, your **hearts**, and the plate with the **medallions and + Spiritual Stones** you hold. Triforce notes these as you play a file and keeps them beside it (`triforce_card.txt`): + a file shows them once it has been played with save files on. The place is the map's own name, and the hearts + appear only where the game's count of them is found (the log says which). +- **Your save so far is File 1.** Nothing is moved: File 1 is the `user` folder the game always had; File 2 and File 3 + are `user-2` and `user-3` beside it, made when you first play them. An empty file starts a new game. +- **While you play:** **Save files** on the System tab of the Options opens the same page. Save first: what is not + saved in the file you are playing is lost when the game starts again on another. +- **Each file has its own achievements:** what a file earned is kept in its folder (`triforce_achievements.txt`), and + the Achievements page shows the file you are playing. File 1 starts with what you had earned before. +- **Names:** `triforce_files.txt` beside the game keeps which file the next start plays and their names, a line each + (`1=Spanky`, 24 characters at most). Edit it while the game is closed. +- **To copy or erase a file,** close the game and copy or delete its folder. The Options' save export and import act on the + file you are playing; Triforce Setup's **Convert saves** acts on File 1. + +

+ ## If something goes wrong | What happens | What to try | diff --git a/recomplauncher.json b/recomplauncher.json index 1792e0b..f784788 100644 --- a/recomplauncher.json +++ b/recomplauncher.json @@ -199,12 +199,12 @@ { "id": "output", "label": "Output resolution", - "help": "The size of the game's whole frame before it is scaled to your window. Applies after a restart.", + "help": "The picture size before scaling to the window. The game menu and native launcher also offer handheld, connected screens and Custom sizes. Applies after a restart.", "choices": [ { - "label": "1536x864 (handheld)", + "label": "1920x1080", "set": { - "output_res": "7" + "output_res": "3" } }, { @@ -224,6 +224,12 @@ "set": { "output_res": "2" } + }, + { + "label": "5120x2880", + "set": { + "output_res": "5" + } } ], "defaults": { @@ -279,7 +285,7 @@ { "id": "ultrawide", "label": "Aspect ratio", - "help": "Monitor's shape widens the camera to fill a screen wider than 16:9. The HUD stays stretched. Applies after a restart.", + "help": "The picture's shape for a 16:9 Output resolution: a fixed 21:9 or 32:9 for a screen or a window of that shape (the game's own menu has 16:10 too). A Screen that is not 16:9 has the screen's own shape. Applies after a restart.", "choices": [ { "label": "16:9", @@ -288,9 +294,15 @@ } }, { - "label": "Monitor's shape", + "label": "21:9", "set": { - "ultrawide": "1" + "ultrawide": "2" + } + }, + { + "label": "32:9", + "set": { + "ultrawide": "3" } } ], diff --git a/setup/pack_tools.ps1 b/setup/pack_tools.ps1 index ca3f436..544b3f3 100644 --- a/setup/pack_tools.ps1 +++ b/setup/pack_tools.ps1 @@ -121,6 +121,9 @@ $toolsRoot = (Resolve-Path $tools).Path.TrimEnd('\') + '\' foreach ($d in $baseDirs) { foreach ($f in Get-ChildItem (Join-Path $tools $d) -Recurse -File) { $rel = $f.FullName.Substring($toolsRoot.Length).Replace('\', '/') + # ((Triforce, 11-22) not the bundled Python's bytecode caches: Python rewrites them as it runs (launcher Tools.Regenerated), + # and a listed one at another size stopped v0.7.0's updates of kept bases. They still ship in the zips) + if ($rel -match '\.pyc$' -or $rel -match '/__pycache__/') { continue } $s = [IO.File]::OpenRead($f.FullName) try { $h = -join ($sha.ComputeHash($s) | ForEach-Object { $_.ToString('x2') }) } finally { $s.Dispose() } $rows.Add("file`t$($f.Length)`t$h`t$rel") diff --git a/tests/achievements_host_test.c b/tests/achievements_host_test.c index a53c5f9..3551487 100644 --- a/tests/achievements_host_test.c +++ b/tests/achievements_host_test.c @@ -38,6 +38,14 @@ static int said(const char *text) { /* how often the log has it */ return n; } #include "achievements_constants.inc" +/* (host/save_files.c: off but for the "file1" and "file2" runs, which play a save file of that folder under the game's) */ +static char files_dir[440]; +static int files_first; +const char *hos_save_files_dir(int *first) { + if (!files_dir[0]) return NULL; + *first = files_first; + return files_dir; +} static int sounds; static int64_t sound_at; static void hos_menu_sound_play(int id, int64_t now_ns) { @@ -49,7 +57,10 @@ static void hos_menu_sound_play(int id, int64_t now_ns) { static int renderer; /* 0: no renderer yet (rx_option answers what it is given) */ static char incoming[600], row_text[160][400], notice_day[16][32]; static int incoming_n, row_bits[160], rows_added, rows_shown = -1, notices[16], nnotices; +static int row_on = 1, row_notices = 1; /* (the System tab's Achievements and Achievement notices rows) */ int rx_option(int id, int otherwise) { + if (id == HOS_OPT_ACH_ON) return renderer ? row_on : otherwise; + if (id == HOS_OPT_ACH_NOTICES) return renderer ? row_notices : otherwise; if (!renderer) return otherwise; CHECK(id == HOS_OPT_ACH_ASK); return 1; @@ -126,25 +137,68 @@ int main(int argc, char **argv) { renderer = 1; hos_achievements_frame(), at(10), hos_achievements_frame(), at(100); CHECK(!asked && !logged[0] && !rows_added && rows_shown < 0 && !nnotices && !sounds && !ready && !file("triforce_achievements.txt")[0]); + } else if (!strcmp(argv[2], "rows")) { /* the System tab's two rows, in a game folder of its own without a list of the player's */ + renderer = 1, row_on = 0; + hos_achievements_frame(); /* (the list is named all the same: its page shows what was earned) */ + CHECK(rows_shown == 35); + at(10), at(20); /* Achievements Off: nothing asked of the save data, nothing earned or written */ + CHECK(!asked && !said("earned \"") && !nnotices && !file("triforce_achievements.txt")[0]); + row_on = 1, row_notices = 0; /* On again, the notices Off: earned at the next check, told to the list one a check, no sound */ + at(30); + CHECK(asked && said("achievements: earned \"") == 5 && lines(file("triforce_achievements.txt")) == 6 && nnotices == 1); + at(31), at(32), at(33), at(34), at(35); /* (a tenth of a second apart: no notice's time between them) */ + CHECK(nnotices == 5 && !sounds && notices[4] == row_of("Three Stones")); + row_notices = 1; /* the notices On again: the next one earned has its sound */ + set(ACH_ITEM, "Item_Medal_Light", 1); + at(40); + CHECK(nnotices == 6 && sounds == 1 && notices[5] == row_of("Sage of Light")); + } else if (!strcmp(argv[2], "file2")) { /* the save files on, File 2 played: none of what the game folder earned is its */ + snprintf(files_dir, sizeof files_dir, "%s/user-2", game_dir); + const int lines_before = lines(file("triforce_achievements.txt")); + renderer = 1; + hos_achievements_frame(); + CHECK(said("achievements: 36 (1 of achievements.txt), 0 earned so far") == 1 && rows_shown == 36 && !(row_bits[0] & HOS_ACH_EARNED)); + at(20); + CHECK(said("achievements: earned \"") == 6 && said("earned \"Mine\" (6 of 36)") == 1 && !said("could not be written")); + CHECK(lines(file("user-2/triforce_achievements.txt")) == 7 && strstr(file_text, " Mine\n") && !strstr(file_text, "Spider Hunter")); + CHECK(lines(file("triforce_achievements.txt")) == lines_before && strstr(file_text, " Spider Hunter\n")); /* (the game folder's as it was) */ + } else if (!strcmp(argv[2], "file1")) { /* File 1, never played with files: it starts from what the game folder earned */ + snprintf(files_dir, sizeof files_dir, "%s/user", game_dir), files_first = 1; + renderer = 1; + hos_achievements_frame(); + CHECK(said("achievements: 36 (1 of achievements.txt), 7 earned so far") == 1 && (row_bits[row_of("Spider Hunter")] & HOS_ACH_EARNED)); + at(10); + CHECK(!said("earned \"") && !file("user/triforce_achievements.txt")[0]); /* (nothing new: nothing written yet) */ + set(ACH_ITEM, "Item_Medal_Light", 1); + at(20); + CHECK(said("earned \"Sage of Light\" (8 of 36)") == 1); + /* its own file from here: the eight, and the line no list has, kept; the game folder's without the eighth */ + CHECK(lines(file("user/triforce_achievements.txt")) == 10 && strstr(file_text, " Sage of Light\n") && strstr(file_text, "\ndeadbeef 5 Gone\n")); + CHECK(lines(file("triforce_achievements.txt")) == 9 && !strstr(file_text, "Sage of Light")); + } else if (!strcmp(argv[2], "again1")) { /* File 1's next start: its own file now, not the game folder's */ + snprintf(files_dir, sizeof files_dir, "%s/user", game_dir), files_first = 1; + renderer = 1; + hos_achievements_frame(); + CHECK(said("achievements: 36 (1 of achievements.txt), 8 earned so far") == 1); } else if (!strcmp(argv[2], "first")) { CHECK(hos_achievements_on()); hos_achievements_frame(); /* the first present, before the renderer answers: the lists are read, nothing is named */ - CHECK(said("achievements: 26 (1 of achievements.txt), 0 earned so far") == 1 && said("achievements: 2 left out") == 1); + CHECK(said("achievements: 36 (1 of achievements.txt), 0 earned so far") == 1 && said("achievements: 2 left out") == 1); CHECK(!rows_added && rows_shown < 0); at(20); /* six earned before the menu has the list: written and said at once, shown only once it has */ - CHECK(said("achievements: earned \"") == 6 && said("earned \"A Sword of Your Own\" (1 of 26)") == 1 && said("earned \"Mine\" (6 of 26)") == 1); + CHECK(said("achievements: earned \"") == 6 && said("earned \"A Sword of Your Own\" (1 of 36)") == 1 && said("earned \"Mine\" (6 of 36)") == 1); CHECK(said("earned \"Three Stones\"") == 1 && !said("Spider Hunter") && !said("could not be written")); CHECK(lines(file("triforce_achievements.txt")) == 7 && strstr(file_text, " A Sword of Your Own\n") && strstr(file_text, " Mine\n")); CHECK(!nnotices && !sounds); renderer = 1; hos_achievements_frame(); /* the list named, whole, in its order: name, the line about it, the day; the icon and earned */ - CHECK(rows_added == 26 && rows_shown == 26 && !nnotices); + CHECK(rows_added == 36 && rows_shown == 36 && !nnotices); CHECK(!strncmp(row_text[0], "A Sword of Your Own\nFind a blade in the forest.\n", 48) && is_day(row_text[0] + 48)); CHECK(row_bits[0] == (1 | 1 << 4 | HOS_ACH_EARNED)); /* (sword green, earned) */ CHECK(!strcmp(row_text[1], "First Melody\nLearn the royal family's song.\n") && row_bits[1] == 4); /* (a note, gold; not earned: no day) */ - CHECK(row_of("Mine") == 25 && row_bits[25] == (2 | 3 << 4 | HOS_ACH_EARNED) && row_bits[row_of("Twice as Tough")] == (6 | 7 << 4)); + CHECK(row_of("Mine") == 35 && row_bits[35] == (2 | 3 << 4 | HOS_ACH_EARNED) && row_bits[row_of("Twice as Tough")] == (6 | 7 << 4)); hos_achievements_frame(), hos_achievements_frame(); - CHECK(rows_added == 26); /* (named once) */ + CHECK(rows_added == 36); /* (named once) */ /* shown one at a time, each for its 4.5 s, in the list's order, with the sound and the day */ at(30); CHECK(nnotices == 1 && sounds == 1 && sound_at == 3 * S && notices[0] == 0 && is_day(notice_day[0])); @@ -153,18 +207,18 @@ int main(int argc, char **argv) { at(75); CHECK(nnotices == 2 && sounds == 2 && notices[1] == row_of("Forest's Thanks")); for (int t = 120; t <= 400; t += 10) at(t); - CHECK(nnotices == 6 && sounds == 6 && notices[5] == 25); - CHECK(said("achievements: earned \"") == 6 && said("achievements: 26 (") == 1 && lines(file("triforce_achievements.txt")) == 7); + CHECK(nnotices == 6 && sounds == 6 && notices[5] == 35); + CHECK(said("achievements: earned \"") == 6 && said("achievements: 36 (") == 1 && lines(file("triforce_achievements.txt")) == 7); } else { renderer = 1; hos_achievements_frame(); /* the next start: what was earned is, and is neither said nor shown again */ - CHECK(said("achievements: 26 (1 of achievements.txt), 6 earned so far") == 1 && rows_shown == 26); + CHECK(said("achievements: 36 (1 of achievements.txt), 6 earned so far") == 1 && rows_shown == 36); at(10); CHECK(!said("earned \"") && !nnotices && !sounds); CHECK((row_bits[0] & HOS_ACH_EARNED) && !(row_bits[row_of("Spider Hunter")] & HOS_ACH_EARNED)); have[5].value = 10; /* (the tenth token) */ at(20); - CHECK(said("earned \"Spider Hunter\" (7 of 26)") == 1 && nnotices == 1 && notices[0] == row_of("Spider Hunter") && is_day(notice_day[0])); + CHECK(said("earned \"Spider Hunter\" (7 of 36)") == 1 && nnotices == 1 && notices[0] == row_of("Spider Hunter") && is_day(notice_day[0])); /* the file whole again: the seven, and the line of an achievement no list has now, as it was */ CHECK(lines(file("triforce_achievements.txt")) == 9 && strstr(file_text, " Spider Hunter\n") && strstr(file_text, "\ndeadbeef 5 Gone\n")); CHECK(!file("triforce_achievements.txt.new")[0]); diff --git a/tests/achievements_test.c b/tests/achievements_test.c index ae5e155..b345b7d 100644 --- a/tests/achievements_test.c +++ b/tests/achievements_test.c @@ -52,7 +52,7 @@ static void built_in(int print) { for (int k = 0; k < list.a[i].nconds; k++) printf("%c %s %d\n", list.a[i].conds[k].kind, list.a[i].conds[k].what, list.a[i].conds[k].least); return; } - CHECK(n == 25 && list.n == 25 && refused == 0); + CHECK(n == 35 && list.n == 35 && refused == 0); for (int i = 0; i < list.n; i++) { const Ach *a = &list.a[i]; CHECK(a->name[0] && a->about[0] && a->nconds >= 1 && !a->earned && a->key == ach_key(a->name)); @@ -61,6 +61,7 @@ static void built_in(int print) { } CHECK(ach_key("") == 2166136261u && ach_key("a") == 0xe40c292cu); CHECK(list.a[0].icon == (1 | 1 << 4) && list.a[1].icon == 4 && list.a[24].icon == (6 | 7 << 4)); /* (sword green, a note, shield silver) */ + CHECK(list.a[28].nconds == 4 && list.a[31].nconds == 2 && list.a[31].conds[1].least == 50 && list.a[34].icon == (6 | 3 << 4)); /* (the tunics and boots; the bombs; shield blue) */ } static void form(void) { diff --git a/tests/display_startup_failure_test.cpp b/tests/display_startup_failure_test.cpp index 10d9980..75cd387 100644 --- a/tests/display_startup_failure_test.cpp +++ b/tests/display_startup_failure_test.cpp @@ -51,6 +51,8 @@ static int hos_sdl_init(unsigned flags) { return mode != "init_failure"; } static int hos_sdl_desktop_size(int* w, int* h) { *w = 2560; *h = 1440; return 1; } +// ((Triforce) hos_display_init reads every display for the Output resolution: tests/test_screen_size.py) +static void screens_read(int, int) {} static void* hos_sdl_window(const char*, int w, int h) { require(w == 1280 && h == 720, "changed default window size"); ++windows; diff --git a/tests/present_aspect_vulkan.cpp b/tests/present_aspect_vulkan.cpp index 8e0f3b3..339581d 100644 --- a/tests/present_aspect_vulkan.cpp +++ b/tests/present_aspect_vulkan.cpp @@ -22,6 +22,8 @@ Host* host = &host_object; VkImage framegen_scale(VkCommandBuffer,VkImageView,VkImage,uint32_t,uint32_t,const int*,uint32_t,uint32_t) { return VK_NULL_HANDLE; // This GPU fixture exercises direct blits; filtered routing is covered by L1. } +void n64_screen_begin(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) {} // ((Triforce, 11-22) N64 Classic's TV's screen: vk_n64.h) +void n64_screen_end() {} // @PRODUCTION_HELPERS@ void record_actual(VkCommandBuffer command,VkImage src,uint32_t sw,uint32_t sh,const int* crop,VkImage dst) { struct { VkCommandBuffer cmd; } f{command}; diff --git a/tests/present_geometry_trace_test.cpp b/tests/present_geometry_trace_test.cpp index 3de059c..65a1558 100644 --- a/tests/present_geometry_trace_test.cpp +++ b/tests/present_geometry_trace_test.cpp @@ -45,6 +45,8 @@ VkImage framegen_hdr(int, VkImageView, uint32_t, uint32_t, const int*, uint32_t, ++hdr_calls; return encoded ? 29 : VK_NULL_HANDLE; } VkImage framegen_scale(int, VkImageView, VkImage, uint32_t, uint32_t, const int*, uint32_t, uint32_t) { return scaled ? 9 : 0; } +void n64_screen_begin(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) {} // ((Triforce, 11-22) N64 Classic's TV's screen: vk_n64.h) +void n64_screen_end() {} void blit_crop_to_rect(int, VkImage, uint32_t, uint32_t, const int*, VkImage, int, PresentRect rect) { ++blits; drawn = rect; } void present(VkImage src = 1, uint32_t sw = 3440, uint32_t sh = 1440, const int* crop = nullptr, VkImageView view = 2) { struct { int cmd = 1; } f; VkImage dst = 3; diff --git a/tests/recorder_sync_test.cpp b/tests/recorder_sync_test.cpp index d947aad..4e41885 100644 --- a/tests/recorder_sync_test.cpp +++ b/tests/recorder_sync_test.cpp @@ -407,6 +407,9 @@ F(vkCmdSetCheckpointNV, (VkCommandBuffer cb, const void* m), handle(cb), handle( F(vkCmdWriteTimestamp2, (VkCommandBuffer cb, VkPipelineStageFlags2 s, VkQueryPool p, uint32_t q), handle(cb), put(s), handle(p), put(q); fx(cb, 1, (uint64_t)(uintptr_t)p << 16 | q);) F(vkCmdResetQueryPool, (VkCommandBuffer cb, VkQueryPool p, uint32_t f, uint32_t n), handle(cb), handle(p), put(f), put(n);) +// ((Triforce, 11-23) RX_VK_QUERY_RING) +F(vkCmdCopyQueryPoolResults, (VkCommandBuffer cb, VkQueryPool p, uint32_t f, uint32_t n, VkBuffer b, VkDeviceSize o, VkDeviceSize s, + VkQueryResultFlags fl), handle(cb), handle(p), put(f), put(n), handle(b), put(o), put(s), put(fl);) static VkResult VKAPI_CALL fake_vkBeginCommandBuffer(VkCommandBuffer cb, const VkCommandBufferBeginInfo* bi) { Guard g_(cb, "vkBeginCommandBuffer", false); @@ -725,6 +728,7 @@ static void frame() { const VkPipelineLayout layout = H(0x300); vkCmdResetQueryPool(up, H(0x400), 0, 64); vkCmdWriteTimestamp2(cmd, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, H(0x400), 0); + vkCmdCopyQueryPoolResults(cmd, H(0x400), 0, 2, H(0x410), 64, 8, VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT); // ((Triforce, 11-23)) copy_runs(up, 0); copy_runs(up, 2); { diff --git a/tests/replay_threads_tuner_test.cpp b/tests/replay_threads_tuner_test.cpp index 2a3fd96..0cee7fb 100644 --- a/tests/replay_threads_tuner_test.cpp +++ b/tests/replay_threads_tuner_test.cpp @@ -19,6 +19,10 @@ // cuttable) gets no verdict, nor the first window after it; a settled heavy scene where the helpers win still turns them on // without a trial, a window after it settled; a trial the scene changed under changes nothing and the next comes soon // after the scene settles. With settled off, each as before. +// "calm": (Triforce, 11-22) Tuner::settled's calm scene between trials: no trial on a loading screen (nothing cut), a trial +// due during an arrival waits for the calm scene, a scene that never calms still has its trials; the rule's "on" in the +// Market's steady texture load (this PC's, fix one's A/B) withdrawn when the area comes down to its settled frames, and kept +// where the scene stays; where the helpers win, on again two windows after a withdrawal. #include #include #include @@ -283,13 +287,13 @@ void rule_case() { CHECK(v.gain == v.saved && v.gain < 1.0 && v.kind != Verdict::kOn); } // the tuner on each scene, 20,000 presents - // (Triforce, 11-22: settled. On at the second window, the first with one before it to tell the scene settled; with + // (Triforce, 11-22: settled. On at the third window, the scene held kOnWindows windows (11-23; the second before); with // settled off at the first, as before) const Run heavy = run_scene(test4_heavy, 20000, true, 1); - CHECK(heavy.first_on == 2 * Tuner::kWindow); // (on at the second window, without a trial) + CHECK(heavy.first_on == Tuner::kOnWindows * Tuner::kWindow); // (on at the third window, without a trial) CHECK(heavy.first_trial > heavy.first_on); // (a trial came after, kEvery later) CHECK(heavy.changes == 0 && heavy.trials >= 6); // (and kept them, 12% shorter frames: no trial took them off) - CHECK(heavy.on_frames > 20000 - 240 - (heavy.trials + 1) * (Tuner::kSettle + Tuner::kTake)); // (but in the trials' serial parts) + CHECK(heavy.on_frames > 20000 - 360 - (heavy.trials + 1) * (Tuner::kSettle + Tuner::kTake)); // (but in the trials' serial parts) { const Run was = run_scene(test4_heavy, 20000, true, 1, nullptr, false, false); CHECK(was.first_on == Tuner::kWindow && was.first_trial > was.first_on && was.changes == 0 && was.trials >= 6); @@ -312,7 +316,7 @@ void rule_case() { // cannot pay, nothing at the title), the trials fewer where they decide, and none changed the way where it held { const Run h = run_scene(test4_heavy, 20000, true, 1, nullptr, true); - CHECK(h.first_on == 2 * Tuner::kWindow && h.first_trial > h.first_on && h.changes == 0); + CHECK(h.first_on == Tuner::kOnWindows * Tuner::kWindow && h.first_trial > h.first_on && h.changes == 0); CHECK(h.trials >= 2 && h.trials < heavy.trials); CHECK(h.on_frames > heavy.on_frames); // (fewer frames the other way) const Run g = run_scene(gpu_bound, 20000, true, 2, nullptr, true); @@ -648,7 +652,7 @@ const Scene kokiri{11.66, 7.4, 5.8, 2000, 1900, 4.0, 1.06}; struct Arrival { int on_verdicts = 0, trials = 0, changes = 0; - long long first_on = -1, on_frames = 0; + long long first_on = -1, on_frames = 0, first_in_use = -1; // (first_in_use: by the rule or a trial) std::vector unsettled; // (the presents of the windows the rule did not judge, before the first trial) }; /// Kokiri for two windows, the load's window, then `to` (each window the rule's: the first trial comes at present 600) @@ -666,6 +670,7 @@ Arrival run_arrival(const Scene& to, bool settled, uint32_t seed) { if (s.unsettled && !s.trial && !out.trials) out.unsettled.push_back(t.frames()); if (s.trial) out.trials++, out.changes += s.better; if (s.flip) on = !on; + if (on && out.first_in_use < 0) out.first_in_use = t.frames(); out.on_frames += on; } return out; @@ -718,14 +723,17 @@ void settled_case() { "windows not judged before the first trial; the helper threads in %lld of 6,000 frames (%lld)\n", n.on_verdicts, o.on_verdicts, o.first_on, (int)n.unsettled.size(), n.on_frames, o.on_frames); } - // a settled heavy scene where the helpers win (test4's): on without a trial, a window after it settled, and kept + // a settled heavy scene where the helpers win (test4's): on by its first trial, due at present 600, a window before the + // rule's third (11-23: kOnWindows; the rule turned them on at 600 before), and kept { const Arrival n = run_arrival(test4_heavy, true, 62), o = run_arrival(test4_heavy, false, 62); - CHECK(n.first_on == 5 * Tuner::kWindow); // (the heavy scene's second window: the first with one like it before) - CHECK(n.changes == 0 && n.on_frames > 6000 - 600 - (n.trials + 1) * (Tuner::kSettle + Tuner::kTake)); + const long long trial_end = 600 + Tuner::kTake + 2 * (Tuner::kSettle + Tuner::kTake); + CHECK(n.first_in_use > 0 && n.first_in_use <= trial_end); + CHECK(n.changes <= 1 && n.on_frames > 6000 - trial_end - (n.trials + 1) * (Tuner::kSettle + Tuner::kTake)); CHECK(o.first_on == 3 * Tuner::kWindow); - std::printf("settled: the load's window into test4's heavy scene: the helper threads on at present %lld without a trial " - "(%lld with settled off), kept by %d trials\n", n.first_on, o.first_on, n.trials); + std::printf("settled: the load's window into test4's heavy scene: the helper threads on at present %lld (%s; %lld with " + "settled off, by the rule), kept by %d trials\n", n.first_in_use, n.first_on > 0 ? "by the rule" : "by a trial", + o.first_on, n.trials - n.changes); } // a trial the scene changed under: nothing changes, and the next comes soon after the scene settles { @@ -743,6 +751,143 @@ void settled_case() { } } +// ---- (Triforce, 11-22) "calm": the calm scene between trials, the trial gate and the rule's "on" withdrawn ---- + +/// A run of stretches through a tuner with the rule, the back-off and settled (or not): (scene, presents) each; a scene whose +/// draws and times slide from one to the next is a stretch of `mix` steps. Counts per stretch index +struct Calm { + int trials = 0, withdrawn = 0, rule_on = 0; + std::vector trials_in, on_in; // (per stretch: trials that ended in it, presents with the helper threads on) + std::vector trial_ends; + long long first_on_after_withdrawal = -1, withdrawn_at = -1; +}; +Scene mix(const Scene& a, const Scene& b, double k) { + return {a.frame + (b.frame - a.frame) * k, a.replay + (b.replay - a.replay) * k, a.gpu + (b.gpu - a.gpu) * k, + a.draws + (b.draws - a.draws) * k, a.cut + (b.cut - a.cut) * k, a.op + (b.op - a.op) * k, + a.par_factor + (b.par_factor - a.par_factor) * k}; +} +struct Stretch { + Scene from, to; // (to: the scene it slides to over its presents; the same as from for a steady one) + int n; +}; +Calm run_calm(const std::vector& stretches, bool settled, uint32_t seed) { + Tuner t; + t.use_rule = true, t.backoff = true, t.settled = settled, t.threads = 4; + std::mt19937 r(seed); + bool on = false; + Calm out; + for (size_t k = 0; k < stretches.size(); k++) { + out.trials_in.push_back(0), out.on_in.push_back(0); + const Stretch& st = stretches[k]; + for (int i = 0; i < st.n; i++) { + const Scene sc = mix(st.from, st.to, st.n > 1 ? (double)i / (st.n - 1) : 0.0); + const Tuner::Step s = t.step(sample(sc, on, r), on, false); + if (s.trial) out.trials++, out.trials_in[k]++, out.trial_ends.push_back(t.frames()); + if (s.withdrawn) out.withdrawn++, out.withdrawn_at = t.frames(); + if (s.ruled && s.flip) { + out.rule_on++; + if (out.withdrawn_at >= 0 && out.first_on_after_withdrawal < 0) out.first_on_after_withdrawal = t.frames(); + } + if (s.flip) on = !on; + out.on_in[k] += on; + } + } + return out; +} + +void calm_case() { + // (a loading screen: nothing to cut; this PC's settled Market from fix one's A/B, the helpers 12% slower; the arrival's + // texture load there, as its log has it: 21.5 ms frames, the replay 17.3 ms of them, 2,174 to 2,537 draws nearly all cut) + const Scene loading{4.71, 0.6, 0.9, 6, 0, 0.1, 1.0}; + const Scene market_here{13.66, 8.44, 6.87, 798, 269, 3.6, 1.12}; + const Scene market_load{21.5, 17.3, 9.9, 2400, 2200, 12.0, 0.88}; + CHECK(rule(mean_of(market_load), 4).kind == Verdict::kOn); // (as the log's window at present 13080 has it) + // a loading screen after the helper threads went on in a heavy scene: no trial there (both ways the same work) + { + const std::vector run{{test4_heavy, test4_heavy, 4000}, {loading, loading, 20000}}; + const Calm n = run_calm(run, true, 71), o = run_calm(run, false, 71); + CHECK(n.rule_on == 1 && n.trials_in[1] == 0); + CHECK(o.trials_in[1] >= 3); + std::printf("calm: a loading screen after the helper threads went on: %d trials in 20,000 presents (%d with settled off)\n", + n.trials_in[1], o.trials_in[1]); + } + // a trial due during an arrival waits for the calm scene: none ends on the arrival's sliding frames + { + // (test7's busy scene, the trials decide; then 600 presents of an area coming in, its draws and times sliding to the + // settled Market's, the next trial due in them; then the Market) + const std::vector run{{test7_busy, test7_busy, 1300}, {test7_busy, market_here, 600}, {market_here, market_here, 6000}}; + const Calm n = run_calm(run, true, 72); + CHECK(n.trials_in[0] >= 1 && n.trials_in[1] == 0 && n.trials_in[2] >= 1); + std::printf("calm: an arrival with a trial due: %d trials on its sliding frames, %d in the settled scene after it\n", + n.trials_in[1], n.trials_in[2]); + } + // a scene that never calms (two scenes swapped every 60 to 359 presents) still has its trials, kEvery late at most + { + const Scene a{12.0, 9.6, 8.4, 1500, 1400, 3.4, 1.08}, b{12.0, 9.6, 8.4, 2400, 2250, 3.4, 1.08}; + std::vector run{{test7_busy, test7_busy, 1000}}; + std::mt19937 r(73); + for (int i = 0, alt = 0; i < 23000; alt = !alt) { + const int len = 60 + (int)(r() % 300); + run.push_back({alt ? a : b, alt ? a : b, len}), i += len; + } + const Calm n = run_calm(run, true, 73); + long long gap = 0; + for (size_t i = 1; i < n.trial_ends.size(); i++) gap = std::max(gap, n.trial_ends[i] - n.trial_ends[i - 1]); + // (the longest back-off, its wait for a calm scene and the trial's own frames) + CHECK(n.trials >= 10 && gap <= Tuner::kBackoffMax + Tuner::kEvery + Tuner::kTake + 2 * (Tuner::kSettle + Tuner::kTake)); + std::printf("calm: a scene that never settles: %d trials in 24,000 presents, at most %lld presents apart\n", n.trials, gap); + } + // the Market's arrival: the rule's "on" in the texture load's steady stretch is withdrawn when the area comes down to its + // settled frames, and the settled Market runs on the replay thread alone + { + const std::vector run{{test7_busy, test7_busy, 3000}, {loading, loading, 300}, {market_load, market_load, 240}, + {market_load, market_here, 480}, {market_here, market_here, 1200}}; + const Calm n = run_calm(run, true, 74); + CHECK(n.rule_on == 1 && n.withdrawn == 1); + // (the settled Market's 1,200 presents: the helper threads off but in a trial's other way at most) + CHECK(n.on_in[4] <= Tuner::kSettle + Tuner::kTake); + CHECK(n.on_in[3] < 480); // (off during the area's coming down) + std::printf("calm: the Market's arrival: the rule's \"on\" in the texture load withdrawn at present %lld, the helper threads " + "in %d of the 480 presents coming down and %d of the settled Market's 1,200\n", n.withdrawn_at, n.on_in[3], + n.on_in[4]); + } + // (11-23) the Market's arrival on 0.7 (testq #973, 3 launches): the texture load comes down a window at a time, two windows + // alike at ~2,300 draws (the rule's "on" there, 16.6 ms frames, the replay 12.8 ms, 3.6 us a draw), then 1,634, then ~870, + // then the settled Market (12.4 ms, the replay 5.6, 652 draws, 138 cut; the helpers ~18% slower, trial 1 of the stock run). + // Three windows alike to the first: no "on" in that slide; two alike (kOnWindows 2, the gate before): "on" in it + { + const Scene field7{11.5, 5.2, 6.0, 700, 150, 2.5, 1.10}; + const Scene load7{16.6, 12.8, 9.2, 2300, 2200, 8.3, 0.92}, mid7{14.6, 9.9, 8.0, 1634, 1450, 6.0, 1.0}, + low7{13.4, 6.6, 6.7, 870, 420, 3.4, 1.12}, market7{12.4, 5.6, 6.2, 652, 138, 2.5, 1.18}; + CHECK(rule(mean_of(load7), 4).kind == Verdict::kOn && rule(mean_of(market7), 4).kind == Verdict::kOff); + int on_runs = 0, on_frames = 0; + for (uint32_t seed = 0; seed < 20; seed++) { + const std::vector run{{field7, field7, 2000}, {loading, loading, 300}, {load7, load7, 240}, + {mid7, mid7, 120}, {low7, low7, 120}, {market7, market7, 1400}}; + const Calm n = run_calm(run, true, 80 + seed); + on_runs += n.rule_on > 0; + for (size_t k = 2; k < n.on_in.size(); k++) on_frames += n.on_in[k]; + } + CHECK(on_runs == 0 && on_frames == 0); + std::printf("calm: the Market's arrival on 0.7 (its texture load coming down a window at a time): the rule's \"on\" in %d " + "of 20 runs, the helper threads in %d of their arrival and Market frames\n", on_runs, on_frames); + } + // where the helpers win (test4's): a steady scene keeps the rule's "on" (nothing withdrawn); a change to another heavy scene + // where they win withdraws it, and the rule turns them on again kOnWindows windows on + { + const Calm steady = run_calm({{test4_heavy, test4_heavy, 20000}}, true, 75); + CHECK(steady.withdrawn == 0 && steady.on_in[0] > 20000 - Tuner::kOnWindows * Tuner::kWindow - (steady.trials + 1) * (Tuner::kSettle + Tuner::kTake)); + const Scene heavier{14.5, 12.0, 7.4, 3900, 3700, 9.9, 0.86}; + CHECK(rule(mean_of(heavier), 4).kind == Verdict::kOn); + const Calm n = run_calm({{test4_heavy, test4_heavy, 700}, {heavier, heavier, 3000}}, true, 76); + CHECK(n.withdrawn == 1 && n.first_on_after_withdrawal > n.withdrawn_at); + CHECK(n.first_on_after_withdrawal - n.withdrawn_at <= Tuner::kOnWindows * Tuner::kWindow); + std::printf("calm: test4's heavy scene: %d withdrawn in 20,000 presents; a change to a heavier one: withdrawn at %lld, the " + "rule's \"on\" again %lld presents later\n", steady.withdrawn, n.withdrawn_at, + n.first_on_after_withdrawal - n.withdrawn_at); + } +} + int main(int argc, char** argv) { const std::string c = argc > 1 ? argv[1] : ""; if (c == "same") same_case(); @@ -750,6 +895,7 @@ int main(int argc, char** argv) { else if (c == "rule") rule_case(); else if (c == "backoff") backoff_case(); else if (c == "settled") settled_case(); + else if (c == "calm") calm_case(); else return std::printf("which case?\n"), 2; return failures ? 1 : 0; } diff --git a/tests/save_file_rows_test.cpp b/tests/save_file_rows_test.cpp new file mode 100644 index 0000000..d4c02ea --- /dev/null +++ b/tests/save_file_rows_test.cpp @@ -0,0 +1,175 @@ +// gpu/vk/save_file_rows.h alone (tests/test_save_files.py): the files as the host names them, the file chosen and what the +// host says of it, and the choice under the keys. +#include +#include +#include "save_file_rows.h" + +static int fails; +#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0) + +namespace sf = save_file_rows; + +static void say(sf::List& list, const char* text) { + for (const char* p = text; *p; p++) list.text((unsigned char)*p); +} + +int main() { + static sf::List list; + // nothing shown, asked or chosen until the list is whole + say(list, "Spanky\n2026-11-18 08:41"); + list.add(sf::kSaved); + say(list, "Bukwheat\n"); + list.add(sf::kSaved | sf::kCurrent | 64); + list.add(0); // (no name, no save) + CHECK(list.shown() == 0 && !list.asks() && list.current() == -1 && !list.choose(0) && list.take_ask() == 0); + list.done(3); + CHECK(list.shown() == 3 && list.asks() && list.current() == 1); + CHECK(!strcmp(list.names[0], "Spanky") && !strcmp(list.whens[0], "2026-11-18 08:41") && list.saved(0)); + CHECK(!strcmp(list.names[1], "Bukwheat") && !list.whens[1][0] && list.saved(1) && list.bits[1] == (sf::kSaved | sf::kCurrent)); + CHECK(!strcmp(list.names[2], "(no name)") && !list.saved(2) && !list.saved(3) && !list.saved(-1)); + // a list sent again changes nothing + say(list, "Again\n"); + list.add(sf::kCurrent); + list.done(1); + CHECK(list.shown() == 3 && list.current() == 1 && !strcmp(list.names[0], "Spanky")); + + // the file this run plays: played at once, nothing asked of the host + CHECK(list.choose(1) && list.take_ask() == 0); + // another: asked of the host, once; its word taken once + CHECK(!list.choose(0) && list.take_ask() == 1 && list.take_ask() == 0 && list.take_said() == sf::kNothing); + list.said(1); + CHECK(list.take_said() == sf::kRestart && list.take_said() == sf::kNothing); + CHECK(!list.choose(2) && list.take_ask() == 3); + list.said(2); + CHECK(list.take_said() == sf::kFailed); + list.said(7); + CHECK(list.take_said() == sf::kNothing); + list.said(1); + CHECK(!list.choose(0) && list.take_said() == sf::kNothing); // (a word that came before this ask is not its answer) + CHECK(!list.choose(3) && !list.choose(-1) && list.take_ask() == 1 && list.take_ask() == 0); // (no such file: nothing more asked) + + // the start that follows a choice: the title asks there too; fewer files than named, and more than there is room for + static sf::List after; + say(after, "One\n"); + after.add(sf::kCurrent); + say(after, "Two\n"); + after.add(0); + after.done(2 | sf::kChosen); + CHECK(after.shown() == 2 && after.asks() && after.chosen() && after.current() == 0 && !list.chosen()); + static sf::List many; + for (int i = 0; i < 6; i++) many.text('a' + i), many.add(0); + many.done(6); + CHECK(many.shown() == sf::kSlots && many.asks() && many.current() == -1 && !many.choose(0) && many.take_ask() == 1); + // a name longer than its room: cut, never inside a letter + static sf::List wide; + for (int i = 0; i < 23; i++) wide.text('n'); + wide.text(0xC3), wide.text(0xA9), wide.text('\n'); + for (int i = 0; i < 60; i++) wide.text('w'); + wide.add(0); + wide.done(1); + CHECK(strlen(wide.names[0]) == 23 && strlen(wide.whens[0]) <= (size_t)sf::kWhen - 1); + + // a file's picture and its card: the file the picture is in; where it was played last, its stones and medallions, its hearts + static sf::List cards; + say(cards, "One\n11/18/2026 1:40 a.m.\nC:\\Games\\Triforce\\user\\save\\0123\\slot_03\\caption.sav\nKokiri Forest|1c9|7"); + cards.add(sf::kSaved | sf::kCurrent); + say(cards, "Two\n\n\n|0|0"); + cards.add(0); + say(cards, "Three\n\n\nLake Hylia|ffff|21"); // (bits that are no item's, and more hearts than there are: not kept) + cards.add(0); + cards.done(3); + CHECK(!strcmp(cards.pictures[0], "C:\\Games\\Triforce\\user\\save\\0123\\slot_03\\caption.sav") && !strcmp(cards.whens[0], "11/18/2026 1:40 a.m.")); + CHECK(!strcmp(cards.places[0], "Kokiri Forest") && cards.items[0] == 0x1c9 && cards.hearts[0] == 7); + CHECK(cards.slots[0] == -1 && !cards.made[0][0] && cards.slots[1] == -1 && cards.slots[2] == -1); // (a card without the slot saved in last) + static sf::List slotted; // (the slot the game saved in last, and when: a slot that is none is not known) + say(slotted, "A\n\n\nKokiri Forest|1c9|7|3|11/18/2026 1:43 a.m."); + slotted.add(sf::kSaved); + say(slotted, "B\n\n\nLake Hylia|0|3|-1|"); + slotted.add(sf::kSaved); + say(slotted, "C\n\n\nLake Hylia|0|3|12|11/18/2026 1:43 a.m."); + slotted.add(sf::kSaved); + slotted.done(3); + CHECK(slotted.slots[0] == 3 && !strcmp(slotted.made[0], "11/18/2026 1:43 a.m.") && slotted.hearts[0] == 7 && !strcmp(slotted.places[0], "Kokiri Forest")); + CHECK(slotted.slots[1] == -1 && !slotted.made[1][0] && slotted.hearts[1] == 3 && slotted.slots[2] == -1 && !slotted.made[2][0]); + CHECK(!cards.pictures[1][0] && !cards.places[1][0] && !cards.items[1] && !cards.hearts[1] && !strcmp(cards.names[1], "Two")); + CHECK(!strcmp(cards.places[2], "Lake Hylia") && cards.items[2] == 0x1ff && cards.hearts[2] == 0); + static sf::List bare; // (a host that sends no card, and one whose card has no bars: nothing of it) + say(bare, "Old\n\n"); + bare.add(0); + say(bare, "Odd\n\n\nno bars here"); + bare.add(0); + bare.done(2); + CHECK(!bare.places[0][0] && !bare.items[0] && !bare.places[1][0] && !bare.hearts[1] && bare.shown() == 2); + // a save's picture among a file's bytes: from the first FF D8 FF to the last FF D9 after it + { + const unsigned char file[] = {1, 2, 0xFF, 0xD9, 3, 0xFF, 0xD8, 0xFF, 0xE0, 9, 9, 0xFF, 0xD9, 9, 0xFF, 0xD9, 7, 7}; + size_t at = 0, len = 0; + CHECK(sf::jpeg_in(file, sizeof file, &at, &len) && at == 5 && len == 11); + CHECK(!sf::jpeg_in(file, 7, &at, &len) && !sf::jpeg_in(file, 12, &at, &len) && sf::jpeg_in(file, 13, &at, &len) && at == 5 && len == 8); + const unsigned char none[] = {0xFF, 0xD9, 0xFF, 0xD8, 0, 0xFF, 0xD8}; + CHECK(!sf::jpeg_in(none, sizeof none, &at, &len) && !sf::jpeg_in(none, 0, &at, &len) && !sf::jpeg_in(file + 5, 3, &at, &len)); + } + + // when a save was made, as its caption has it: a calendar time outside the picture, the latest of those found + { + unsigned char file[96] = {}; + const unsigned char early[] = {0xEA, 0x07, 11, 18, 1, 28, 9}, late[] = {0xEA, 0x07, 11, 18, 1, 43, 5}; // (2026-11-18 01:28:09, 01:43:05) + memcpy(file + 4, early, 7), memcpy(file + 80, late, 7); + sf::SaveTime t = sf::caption_time(file, sizeof file, 20, 40, 2026, 4102444800LL); // (the picture: bytes 20 to 59) + CHECK(t.kind == 1 && t.year == 2026 && t.month == 11 && t.day == 18 && t.hour == 1 && t.minute == 43 && t.second == 5); + memcpy(file + 30, "\xEA\x07\x0C\x1F\x17\x3B\x3B", 7); // (a later one inside the picture: not a time) + t = sf::caption_time(file, sizeof file, 20, 40, 2026, 4102444800LL); + CHECK(t.kind == 1 && t.minute == 43); + t = sf::caption_time(file, 40, 20, 20, 2026, 4102444800LL); // (cut short of the later one) + CHECK(t.kind == 1 && t.minute == 28); + // what is no time: a year, month, day, hour, minute or second out of range + const unsigned char bad[][7] = {{0xE0, 0x07, 11, 18, 1, 28, 9}, {0x35, 0x08, 1, 1, 0, 0, 0}, {0xEA, 0x07, 0, 18, 1, 28, 9}, {0xEA, 0x07, 13, 18, 1, 28, 9}, + {0xEA, 0x07, 11, 0, 1, 28, 9}, {0xEA, 0x07, 11, 32, 1, 28, 9}, {0xEA, 0x07, 11, 18, 24, 28, 9}, + {0xEA, 0x07, 11, 18, 1, 60, 9}, {0xEA, 0x07, 11, 18, 1, 28, 60}}; + for (const auto& b : bad) { + unsigned char one[16] = {}; + memset(one, 0xFF, sizeof one), memcpy(one + 3, b, 7); + CHECK(sf::caption_time(one, sizeof one, sizeof one, 0, 2026, 4102444800LL).kind == 0); + } + // a time that cannot be a save's: of a year to come (2093, among a caption's other bytes), or before this game + { + unsigned char one[16] = {}; + memcpy(one + 2, "\x2D\x08\x09\x19\x09\x15\x00", 7); // (2093-09-25 09:21:00) + CHECK(sf::caption_time(one, sizeof one, sizeof one, 0, 2026, 4102444800LL).kind == 0 && sf::caption_time(one, sizeof one, sizeof one, 0, 2093, 4102444800LL).kind == 1); + memcpy(one + 2, "\xE8\x07\x09\x19\x09\x15\x00", 7); // (2024) + CHECK(sf::caption_time(one, sizeof one, sizeof one, 0, 2026, 4102444800LL).kind == 0); + const unsigned char later[] = {0x16, 0xCD, 0x5B, 0x69, 0, 0, 0, 0}; + unsigned char two[16]; + memset(two, 0xFF, sizeof two), memcpy(two + 4, later, 8); + CHECK(sf::caption_time(two, sizeof two, sizeof two, 0, 2026, 0x695BCD15).kind == 0 && sf::caption_time(two, sizeof two, sizeof two, 0, 2026, 0x695BCD16).kind == 2); + } + // no calendar time: a count of seconds since 1970, 64 bits, its upper half 0; the latest; none outside 2017 to 2100 + unsigned char secs[64]; + memset(secs, 0xFF, sizeof secs); + const unsigned char a[] = {0x15, 0xCD, 0x5B, 0x69, 0, 0, 0, 0}, b2[] = {0x16, 0xCD, 0x5B, 0x69, 0, 0, 0, 0}, old[] = {0x00, 0x00, 0x00, 0x40, 0, 0, 0, 0}; + memcpy(secs + 8, a, 8), memcpy(secs + 24, b2, 8), memcpy(secs + 40, old, 8); + t = sf::caption_time(secs, sizeof secs, sizeof secs, 0, 2026, 4102444800LL); + CHECK(t.kind == 2 && t.seconds == 0x695BCD16); + CHECK(sf::caption_time(secs, 8, 8, 0, 2026, 4102444800LL).kind == 0 && sf::caption_time(secs, 0, 0, 0, 2026, 4102444800LL).kind == 0); + // which of two saves is the later; one that tells a time is later than one that tells none + sf::SaveTime x, y, none; + x.kind = y.kind = 1, x.year = y.year = 2026, x.month = y.month = 11, x.day = 18, y.day = 17, y.hour = 23; + CHECK(x.after(y) && !y.after(x) && !x.after(x) && x.after(none) && !none.after(x) && !none.after(none)); + char text[32]; + sf::game_time(text, sizeof text, 2026, 11, 18, 1, 40); + CHECK(!strcmp(text, "11/18/2026 1:40 a.m.")); + sf::game_time(text, sizeof text, 2026, 1, 5, 0, 5); CHECK(!strcmp(text, "1/5/2026 12:05 a.m.")); + sf::game_time(text, sizeof text, 2026, 1, 5, 12, 0); CHECK(!strcmp(text, "1/5/2026 12:00 p.m.")); + sf::game_time(text, sizeof text, 2026, 1, 5, 23, 59); CHECK(!strcmp(text, "1/5/2026 11:59 p.m.")); + } + + // the choice: Up and Down, Home and End, kept to the files + int choice = 0; + CHECK(!sf::move(choice, -1, false, false, 3) && choice == 0 && sf::move(choice, 1, false, false, 3) && choice == 1); + CHECK(sf::move(choice, 5, false, false, 3) && choice == 2 && !sf::move(choice, 1, false, false, 3)); + CHECK(sf::move(choice, 0, true, false, 3) && choice == 0 && sf::move(choice, 0, false, true, 3) && choice == 2); + CHECK(!sf::move(choice, 1, false, false, 0) && choice == 2); + + if (!fails) printf("PASS\n"); + return fails != 0; +} diff --git a/tests/save_files_host_test.c b/tests/save_files_host_test.c new file mode 100644 index 0000000..534f1e4 --- /dev/null +++ b/tests/save_files_host_test.c @@ -0,0 +1,216 @@ +/* Save files on the host's side: host/save_files.c's own text (save_files_actual.inc, cut by tests/test_save_files.py) + against a stand-in menu, a stand-in for the files' folders and a game folder of the test's. Run four times: "off" + with HOS_SAVE_FILES=0, then "first" without it (on by default since 11-23), then "first", "second" and "third" with it on the same folder, each a start of the game. */ +#include +#include +#include +#include +#include +#include + +static int fails; +#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0) + +/* ---- what host/save_files.c takes from hos.h, hos_paths.h and windows.h ---- */ +#define MAX_PATH 260 +typedef unsigned long DWORD; +typedef void *HANDLE; +#define INVALID_HANDLE_VALUE ((HANDLE)(intptr_t)-1) +#define MOVEFILE_REPLACE_EXISTING 1 +#define S 1000000000LL +typedef struct { DWORD dwLowDateTime, dwHighDateTime; } FILETIME; +typedef struct { FILETIME ftLastWriteTime; char cFileName[MAX_PATH]; } WIN32_FIND_DATAA; +static int MoveFileExA(const char *from, const char *to, int flags) { + (void)flags; + remove(to); + return rename(from, to) == 0; +} +/* the files' folders: which have a save, when its account.sav was written (unix time; 0: the time is not told), and + when each of its slots' caption.sav was (0: no such slot) */ +static int has_save[3]; +static int64_t save_time[3], slot_time[3][12]; +static int finds; +static int file_of(const char *pattern) { return strstr(pattern, "user-3\\save\\") ? 2 : strstr(pattern, "user-2\\save\\") ? 1 : strstr(pattern, "user\\save\\") ? 0 : -1; } +static HANDLE FindFirstFileA(const char *pattern, WIN32_FIND_DATAA *fd) { + const int file = file_of(pattern); + finds++; + CHECK(file >= 0); + memset(fd, 0, sizeof *fd); + if (file < 0 || !has_save[file]) return INVALID_HANDLE_VALUE; + if (strstr(pattern, "\\save\\*")) { + snprintf(fd->cFileName, sizeof fd->cFileName, "."); /* (the folder itself first, as a listing has it) */ + return (HANDLE)(intptr_t)(100 + file); + } + const char *slot = strstr(pattern, "\\save\\0123456789abcdef0123456789abcdef\\slot_"); + CHECK(slot || strstr(pattern, "\\save\\0123456789abcdef0123456789abcdef\\account.sav") != NULL); + CHECK(!slot || !strcmp(slot + 46, "\\caption.sav")); /* (a slot's caption is named, never opened here; its progress never) */ + const int64_t at = slot ? slot_time[file][atoi(slot + 44) % 12] : save_time[file]; + if (slot && !at) return INVALID_HANDLE_VALUE; + const uint64_t ft = at ? (uint64_t)at * 10000000ULL + 116444736000000000ULL : 0; + fd->ftLastWriteTime.dwLowDateTime = (DWORD)(ft & 0xffffffffu), fd->ftLastWriteTime.dwHighDateTime = (DWORD)(ft >> 32); + return (HANDLE)(intptr_t)(200 + file); +} +static int FindNextFileA(HANDLE h, WIN32_FIND_DATAA *fd) { + if ((intptr_t)h < 100 || (intptr_t)h >= 200 || fd->cFileName[0] != '.') return 0; + snprintf(fd->cFileName, sizeof fd->cFileName, "0123456789abcdef0123456789abcdef"); + return 1; +} +static int FindClose(HANDLE h) { (void)h; return 1; } +static char logged[1 << 14]; +static void hos_log(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + const size_t at = strlen(logged); + vsnprintf(logged + at, sizeof logged - at - 2, fmt, ap); + va_end(ap); + strcat(logged, "\n"); +} +static int said(const char *text) { return strstr(logged, text) != NULL; } + +/* ---- the menu's side of HOS_OPT_FILES_* (gpu/vk/save_file_rows.h is tested by itself) ---- */ +#include "save_files_constants.inc" +static int renderer, asked, ask_next; /* renderer 0: none yet (rx_option answers what it is given) */ +static char incoming[1200], row_text[8][1200]; +static int incoming_n, row_bits[8], rows_added, rows_count = -1, answers[8], nanswers; +int rx_option(int id, int otherwise) { + asked++; + CHECK(id == HOS_OPT_FILES_ASK); + if (!renderer) return otherwise; + const int ask = ask_next; + ask_next = 0; + return ask; +} +void rx_option_set(int id, int value) { + CHECK(renderer); + if (id == HOS_OPT_FILES_TEXT) { + CHECK(value > 0 && value < 256 && incoming_n + 1 < (int)sizeof incoming); + incoming[incoming_n++] = (char)value; + } else if (id == HOS_OPT_FILES_ADD) { + incoming[incoming_n] = 0, incoming_n = 0; + CHECK(rows_count < 0 && rows_added < 8); + snprintf(row_text[rows_added], sizeof row_text[0], "%s", incoming); + row_bits[rows_added++] = value; + } else if (id == HOS_OPT_FILES_COUNT) { + CHECK(rows_count < 0 && !incoming_n); + rows_count = value; + } else if (id == HOS_OPT_FILES_SAID) { + CHECK(rows_count >= 0 && nanswers < 8); + answers[nanswers++] = value; + } else CHECK(!"an option of another feature set"); +} + +#include "save_files.h" +#include "save_files_actual.inc" + +static char file_text[2048]; +static const char *file(const char *dir, const char *name) { /* a file of the game folder as it is now ("" when there is none) */ + char path[600]; + snprintf(path, sizeof path, "%s/%s", dir, name); + FILE *f = fopen(path, "rb"); + file_text[f ? fread(file_text, 1, sizeof file_text - 1, f) : 0] = 0; + if (f) fclose(f); + return file_text; +} +static const char *file_at(const char *path) { /* a file by its whole path, as the host names it */ + FILE *f = fopen(path, "rb"); + file_text[f ? fread(file_text, 1, sizeof file_text - 1, f) : 0] = 0; + if (f) fclose(f); + return file_text; +} +static int ends(const char *text, const char *end) { return strlen(text) >= strlen(end) && !strcmp(text + strlen(text) - strlen(end), end); } + +int main(int argc, char **argv) { + if (argc != 3) return 2; + const char *game = argv[1], *mode = argv[2]; + char base[400]; + snprintf(base, sizeof base, "%s\\user", game); + has_save[0] = 1, save_time[0] = 1763456789; + slot_time[0][0] = 1763456000, slot_time[0][3] = 1763456789, slot_time[0][5] = 1763456789; /* (slots 3 and 5 written together, last) */ + const char *dir = hos_save_files_start(game, base); + if (!strcmp(mode, "off")) { /* HOS_SAVE_FILES=0: the game's own folder, nothing read, written, said or asked of the menu */ + renderer = 1, ask_next = 2; + CHECK(!hos_save_files_on() && dir == base); + hos_save_files_frame(), hos_save_files_frame(); + hos_save_card_note("KokiriForest", 1, 12, 100 * S); /* (and no card kept) */ + CHECK(!asked && !finds && !logged[0] && !rows_added && rows_count < 0 && !nanswers && !file(game, "triforce_files.txt")[0]); + } else if (!strcmp(mode, "first")) { /* no triforce_files.txt yet: file 1, the game's own folder, and no file made for that */ + CHECK(hos_save_files_on() && !strcmp(dir, base) && said("save files: file 1 of 3, \"File 1\": its saves are in ") && !said("chosen at the title")); + CHECK(!file(game, "triforce_files.txt")[0]); + hos_save_files_frame(); /* (no renderer yet: nothing named) */ + CHECK(asked == 1 && !rows_added && !finds); + renderer = 1; + hos_save_files_frame(); /* the files named, whole: name, when last saved; which has a save, which is this run's */ + CHECK(rows_added == 3 && rows_count == 3 && !nanswers); + /* (when it was last saved, as the game's load list writes a time: 11/18/2025 1:06 a.m.) */ + const char *when_end = strstr(row_text[0], ".m.\n"); + CHECK(!strncmp(row_text[0], "File 1\n1", 8) && when_end && strstr(row_text[0], "/2025 ") && row_bits[0] == (HOS_FILE_SAVED | HOS_FILE_CURRENT)); + /* (where its slots are, up to a slot's number: the menu reads each one's picture and time itself; no card kept for it yet) */ + CHECK(when_end && !strncmp(when_end + 4, base, strlen(base)) && ends(row_text[0], "\\user\\save\\0123456789abcdef0123456789abcdef\\slot_\n|0|0|-1|")); + CHECK(!strcmp(row_text[1], "File 2\n\n\n|0|0|-1|") && row_bits[1] == 0 && !strcmp(row_text[2], "File 3\n\n\n|0|0|-1|") && row_bits[2] == 0); + hos_save_files_frame(); + CHECK(rows_added == 3); /* (named once) */ + /* a file that is none, and this run's own: nothing kept, nothing said */ + ask_next = 9, hos_save_files_frame(), ask_next = 1, hos_save_files_frame(); + CHECK(!nanswers && !file(game, "triforce_files.txt")[0]); + /* another file: kept as the next start's, with the time, and the menu told */ + ask_next = 2, hos_save_files_frame(); + CHECK(nanswers == 1 && answers[0] == 1 && said("save files: file 2, \"File 2\", chosen: the game starts again on it")); + CHECK(strstr(file(game, "triforce_files.txt"), "\ncurrent=2\n") && strstr(file_text, "\nchosen=1") && !file(game, "triforce_files.txt.new")[0]); + /* this run goes on with its own file: the same choice again is asked for again (the restart had not come yet) */ + ask_next = 2, hos_save_files_frame(); + CHECK(nanswers == 2 && answers[1] == 1); + } else if (!strcmp(mode, "second")) { /* the start that follows the choice: file 2's folder, and the menu told that it is that restart */ + has_save[1] = 1, save_time[1] = 0; + CHECK(ends(dir, "\\user-2") && !strncmp(dir, base, strlen(base)) && said("file 2 of 3, \"File 2\"") && said("(chosen at the title: the game restarted for it)")); + CHECK(strstr(file(game, "triforce_files.txt"), "\ncurrent=2\n") && !strstr(file_text, "chosen")); /* (the choice is taken) */ + renderer = 1; + hos_save_files_frame(); + /* (file 2: started on, its account.sav made, nothing saved in it yet: no save, as its card says) */ + CHECK(rows_count == (3 | HOS_FILES_CHOSEN) && row_bits[0] == HOS_FILE_SAVED && row_bits[1] == HOS_FILE_CURRENT); + CHECK(!strcmp(row_text[1], "File 2\n\n\n|0|0|-1|")); /* (a save whose time is not told: no time shown; no slot found: no picture) */ + } else { /* a later start: the same file, the names the player gave, and the title asks again (an old choice is none) */ + CHECK(ends(dir, "\\user-2") && said("file 2 of 3, \"Bukwheat\"") && !said("chosen at the title")); + CHECK(!strstr(file(game, "triforce_files.txt"), "chosen") && strstr(file_text, "\n1=Spanky\n2=Bukwheat\n3=File 3\n")); + renderer = 1; + hos_save_files_frame(); + /* (file 2's card, as its folder kept it when it was last played: its place, its stones and medallions, its hearts) */ + CHECK(rows_count == 3 && !strncmp(row_text[0], "Spanky\n", 7) && strstr(row_text[0], ".m.\n") && row_bits[1] == HOS_FILE_CURRENT); + CHECK(!strcmp(row_text[1], "Bukwheat\n\n\nKokiri Forest|1c9|7|-1|") && ends(row_text[0], "\\slot_\n|0|0|-1|") && !strcmp(row_text[2], "File 3\n\n\n|0|0|-1|")); + /* the file played: what the game tells of it is kept in its folder when it is not what is kept there already, and + not more often than every five seconds; a map with no name (no save loaded) is not a place */ + char card[700]; + snprintf(card, sizeof card, "%s\\user-2\\triforce_card.txt", game); + hos_save_card_note("KokiriForest", 0x1c9, 28, 10 * S); + CHECK(strstr(file_at(card), "place=Kokiri Forest\r\nitems=1c9\r\nhearts=7")); /* (as it was: the test's own bytes, not written again) */ + hos_save_card_note("", 0, 0, 11 * S), hos_save_card_note(NULL, 0, 0, 11 * S); + hos_save_card_note("DeathMountain_Crater", 0x1cb, 32, 12 * S); + CHECK(strstr(file_at(card), "\nplace=Death Mountain Crater\nitems=1cb\nhearts=8\n") && file_text[0] == '#'); + hos_save_card_note("LakeHylia", 0x1cb, 32, 13 * S); /* (too soon after the last) */ + CHECK(strstr(file_at(card), "place=Death Mountain Crater\n")); + hos_save_card_note("LakeHylia", 0xffff, 33, 18 * S); /* (bits that are no item's are not kept; a life that is no count of hearts: none) */ + CHECK(strstr(file_at(card), "\nplace=Lake Hylia\nitems=1ff\nhearts=0\n")); + /* the game saves: a slot's file opened to be written is the slot saved in last, kept with the card and its time; a + path that names no slot is none */ + hos_save_card_wrote("save:/option.sav"), hos_save_card_wrote("save:/slot_12/caption.sav"), hos_save_card_wrote(NULL); + hos_save_card_note("LakeHylia", 0x1ff, 33, 24 * S); + CHECK(!strstr(file_at(card), "slot=")); + /* (kept at once, with what was last told: a save made in the pause menu, where Link is not updated, and the game closed) */ + hos_save_card_note("ZoraDomain", 0x1ff, 16, 22 * S); /* (told, under five seconds after the last write: not kept by itself) */ + CHECK(strstr(file_at(card), "place=Lake Hylia\n")); + hos_save_card_wrote("save:/slot_03/caption.sav"); + CHECK(strstr(file_at(card), "\nplace=Zora Domain\nitems=1ff\nhearts=4\nslot=3\nsaved=1")); + const size_t once = strlen(file_text); + hos_save_card_wrote("save:/slot_03/progress.sav"); /* (the same save's other file: the same time) */ + CHECK(strlen(file_at(card)) == once); + hos_save_card_note("LakeHylia", 0x1ff, 33, 30 * S); + CHECK(strstr(file_at(card), "\nplace=Lake Hylia\nitems=1ff\nhearts=0\nslot=3\nsaved=1") && !said("could not be written")); + hos_save_card_wrote("save:/slot_01/caption.sav"); /* (another slot: that one, with the place as last told) */ + CHECK(strstr(file_at(card), "\nplace=Lake Hylia\nitems=1ff\nhearts=0\nslot=1\nsaved=1")); + snprintf(card, sizeof card, "%s\\user-2\\triforce_card.txt.new", game); + CHECK(!file_at(card)[0] && !said("could not be written")); + ask_next = 1, hos_save_files_frame(); /* back to file 1 */ + CHECK(nanswers == 1 && answers[0] == 1 && strstr(file(game, "triforce_files.txt"), "\ncurrent=1\n") && strstr(file_text, "\n2=Bukwheat\n")); + } + if (!fails) printf("PASS\n"); + return fails != 0; +} diff --git a/tests/save_files_test.c b/tests/save_files_test.c new file mode 100644 index 0000000..0ab4d94 --- /dev/null +++ b/tests/save_files_test.c @@ -0,0 +1,115 @@ +/* host/save_files.h alone (tests/test_save_files.py): the form of triforce_files.txt and what is not taken from it, the + files' folders, and the start that follows a choice. */ +#include +#include +#include +#include "save_files.h" + +static int fails; +#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0) + +int main(void) { + SaveFiles f, g; + char text[512], dir[64]; + + /* no file, or an empty one: file 1, and the names "File N" */ + save_files_parse(&f, ""); + CHECK(f.current == 0 && f.chosen == 0 && !strcmp(f.names[0], "File 1") && !strcmp(f.names[1], "File 2") && !strcmp(f.names[2], "File 3")); + + /* its three lines, in any order, with Windows' line ends; what is none of them is passed over */ + save_files_parse(&f, "# a note\r\n2=Bukwheat\r\ncurrent=2\r\nchosen=1763456789\r\nsomething else\r\n1=Spanky \r\n=x\n4=No such file\n0=Nor this\n"); + CHECK(f.current == 1 && f.chosen == 1763456789 && !strcmp(f.names[0], "Spanky") && !strcmp(f.names[1], "Bukwheat") && !strcmp(f.names[2], "File 3")); + + /* a file's number that is none: file 1; a time that is none: no choice; a name that is empty or has a control: not taken */ + save_files_parse(&f, "current=0\nchosen=-5\n1=\n2=a\tb\n3=Last line, no line feed"); + CHECK(f.current == 0 && f.chosen == 0 && !strcmp(f.names[0], "File 1") && !strcmp(f.names[1], "File 2") && !strcmp(f.names[2], "Last line, no line feed")); + save_files_parse(&f, "current=4\n"); + CHECK(f.current == 0); + save_files_parse(&f, "current=3\ncurrent=x\n"); + CHECK(f.current == 2); + + /* a name cut at SAVE_FILE_NAME bytes, never inside a letter */ + save_files_parse(&f, "1=abcdefghijklmnopqrstuvwxyz\n2=abcdefghijklmnopqrstuvw\xc3\xa9z\n"); + CHECK(!strcmp(f.names[0], "abcdefghijklmnopqrstuvwx") && strlen(f.names[0]) == SAVE_FILE_NAME); + CHECK(!strcmp(f.names[1], "abcdefghijklmnopqrstuvw")); /* (23 letters and a letter of two bytes: 25, one too many) */ + + /* written and read back */ + save_files_parse(&f, "current=3\nchosen=1700000000\n1=Spanky\n3=Third one\n"); + const size_t n = save_files_write(&f, text, sizeof text); + CHECK(n == strlen(text) && text[0] == '#' && strstr(text, "\ncurrent=3\n") && strstr(text, "\nchosen=1700000000\n") && strstr(text, "\n1=Spanky\n2=File 2\n3=Third one\n")); + save_files_parse(&g, text); + CHECK(!memcmp(&f, &g, sizeof f)); + f.chosen = 0; + CHECK(save_files_write(&f, text, sizeof text) && !strstr(text, "chosen")); /* (no choice: no line) */ + CHECK(save_files_write(&f, text, 20) == 0 && save_files_write(&f, text, 100) == 0); + + /* the folders: file 1 the game's own, the others its name with their number */ + CHECK(save_files_folder("C:\\Games\\Triforce\\user", 0, dir, sizeof dir) && !strcmp(dir, "C:\\Games\\Triforce\\user")); + CHECK(save_files_folder("C:\\Games\\Triforce\\user", 1, dir, sizeof dir) && !strcmp(dir, "C:\\Games\\Triforce\\user-2")); + CHECK(save_files_folder("/home/me/.local/share/hookshot/", 2, dir, sizeof dir) && !strcmp(dir, "/home/me/.local/share/hookshot-3")); + CHECK(save_files_folder("user\\", 0, dir, sizeof dir) && !strcmp(dir, "user")); + CHECK(!save_files_folder("user", 3, dir, sizeof dir) && !save_files_folder("user", -1, dir, sizeof dir)); + CHECK(!save_files_folder("user", 1, dir, 6) && save_files_folder("user", 1, dir, 7) && !save_files_folder("user", 0, dir, 4)); + + /* the start that follows a choice: within SAVE_FILES_CHOSEN_S of it, and not before it */ + f.chosen = 1000; + CHECK(save_files_chosen_now(&f, 1000) && save_files_chosen_now(&f, 1000 + SAVE_FILES_CHOSEN_S) && !save_files_chosen_now(&f, 1001 + SAVE_FILES_CHOSEN_S)); + CHECK(!save_files_chosen_now(&f, 999)); + f.chosen = 0; + CHECK(!save_files_chosen_now(&f, 5)); + + /* a file's card: a map's own name as words */ + char place[SAVE_CARD_PLACE + 1], small[8]; + save_card_place("KokiriForest", place, sizeof place); + CHECK(!strcmp(place, "Kokiri Forest")); + save_card_place("Inside_GanonCastle01", place, sizeof place); + CHECK(!strcmp(place, "Inside Ganon Castle 01")); + save_card_place("HyruleField", place, sizeof place); CHECK(!strcmp(place, "Hyrule Field")); + save_card_place("DekuTree_B1F", place, sizeof place); CHECK(!strcmp(place, "Deku Tree B1F")); + save_card_place("Area2Boss", place, sizeof place); CHECK(!strcmp(place, "Area 2 Boss")); + save_card_place("__Lost__Woods__", place, sizeof place); CHECK(!strcmp(place, "Lost Woods")); + save_card_place("", place, sizeof place); CHECK(!place[0]); + /* (a map that says Link's age at its name's end: the place without it, as the game's own load list has it) */ + save_card_place("KokiriForest_Adult", place, sizeof place); CHECK(!strcmp(place, "Kokiri Forest")); + save_card_place("KokiriForestChild", place, sizeof place); CHECK(!strcmp(place, "Kokiri Forest")); + save_card_place("Adult", place, sizeof place); CHECK(!strcmp(place, "Adult")); + save_card_place("ChildhoodHome", place, sizeof place); CHECK(!strcmp(place, "Childhood Home")); + save_card_place("KokiriForest", small, sizeof small); CHECK(!strcmp(small, "Kokiri") && strlen(small) < sizeof small); + /* hearts: the game's count of Link's life, in quarters of a heart; what is no such count: none */ + CHECK(save_card_hearts(12) == 3 && save_card_hearts(28) == 7 && save_card_hearts(80) == 20 && save_card_hearts(84) == 0); + CHECK(save_card_hearts(0) == 0 && save_card_hearts(8) == 0 && save_card_hearts(13) == 0 && save_card_hearts(-12) == 0 && save_card_hearts(7) == 0); + /* triforce_card.txt: read, written and read back; what is none of its lines passed over, numbers that are none 0 */ + SaveCard c, d; + save_card_parse(&c, "# a note\r\nplace=Kokiri Forest\r\nitems=1c9\r\nhearts=7\r\nwhat=this\r\n"); + CHECK(!strcmp(c.place, "Kokiri Forest") && c.items == 0x1c9 && c.hearts == 7); + const size_t cn = save_card_write(&c, text, sizeof text); + CHECK(cn == strlen(text) && text[0] == '#' && strstr(text, "\nplace=Kokiri Forest\nitems=1c9\nhearts=7\n")); + save_card_parse(&d, text); + CHECK(save_card_same(&c, &d) && save_card_write(&c, text, 40) == 0); + d.hearts = 8; CHECK(!save_card_same(&c, &d)); + d = c, d.items ^= 1; CHECK(!save_card_same(&c, &d)); + d = c, d.place[0] = 'L'; CHECK(!save_card_same(&c, &d)); + save_card_parse(&c, "items=fffff\nhearts=21\nplace=A|B\tC\n"); + CHECK(c.items == 0x1ff && c.hearts == 0 && !strcmp(c.place, "A B C")); /* (the bar and a control are the list's own: spaces) */ + save_card_parse(&c, ""); + CHECK(!c.place[0] && !c.items && !c.hearts && !c.slot1 && !c.saved); + /* the slot the game saved in last, and when: kept with the card; a slot that is none is not known */ + save_card_parse(&c, "place=Kokiri Forest Adult\nitems=1\nhearts=3\nslot=3\nsaved=1763456789\n"); + CHECK(c.slot1 == 4 && c.saved == 1763456789 && !strcmp(c.place, "Kokiri Forest")); /* (and a place kept with its age: without) */ + CHECK(save_card_write(&c, text, sizeof text) && strstr(text, "\nhearts=3\nslot=3\nsaved=1763456789\n")); + save_card_parse(&d, text); + CHECK(save_card_same(&c, &d)); + d.slot1 = 1; CHECK(!save_card_same(&c, &d)); + d = c; d.saved++; CHECK(!save_card_same(&c, &d)); + save_card_parse(&c, "slot=12\nsaved=-4\n"); CHECK(!c.slot1 && !c.saved); + save_card_parse(&c, "slot=0\n"); CHECK(c.slot1 == 1); + save_card_parse(&c, "slot=\nslot=x\n"); CHECK(!c.slot1); + CHECK(save_card_slot_of("save:/slot_03/caption.sav") == 3 && save_card_slot_of("save:/slot_11/progress.sav") == 11 && save_card_slot_of("save:\\slot_00\\x") == 0); + CHECK(save_card_slot_of("save:/slot_12/caption.sav") < 0 && save_card_slot_of("save:/option.sav") < 0 && save_card_slot_of("save:/slot_3/x") < 0); + CHECK(save_card_slot_of("save:/slot_03") < 0 && save_card_slot_of("") < 0 && save_card_slot_of(NULL) < 0); + save_card_parse(&c, "hearts=x\nitems=\nplace=\n"); + CHECK(!c.place[0] && !c.items && !c.hearts); + + if (!fails) printf("PASS\n"); + return fails != 0; +} diff --git a/tests/startup_screen_preview.py b/tests/startup_screen_preview.py index a30d9fa..27880cc 100644 --- a/tests/startup_screen_preview.py +++ b/tests/startup_screen_preview.py @@ -50,7 +50,10 @@ def build(cxx, work, headers="", opt="-O2"): work.mkdir(parents=True, exist_ok=True) logo_rgba.write(str(work / "hookshot_logo.h")) win = os.name == "nt" - target = ["--target=x86_64-pc-windows-msvc", "-fms-extensions", "-D_CRT_SECURE_NO_WARNINGS"] if win and "clang" in cxx else [] + # (the game's own target: llvm-mingw's GNU one with HOOKSHOT_MINGW, as the builds have it, else MSVC; the a64 kit's toolchain) + sys.path.insert(0, str(ROOT / "third_party" / "a64-kit" / "tools")) + import toolchain + target = toolchain.native_target() if win and "clang" in cxx else [] includes = ["-I" + str(ROOT / "gpu" / "vk"), "-I" + str(IMGUI), "-I" + str(ZSTD), "-I" + str(work), "-I" + header_dir("vulkanheaders", "vulkan/vulkan.h", headers)] if os.name != "nt": # (the Win32 names the back end's headers use, as its own build has them on POSIX) diff --git a/tests/test_aa_passes.py b/tests/test_aa_passes.py index dc6a477..6ebb299 100644 --- a/tests/test_aa_passes.py +++ b/tests/test_aa_passes.py @@ -81,6 +81,8 @@ static bool before_bloom = false; // (the Upscale before bloom row: the upscal bool temporal_before_bloom() { return before_bloom; } bool fsr3_wanted() { return false; } bool fsr3_native() { return false; } +static int n64_front = 0; // ((Triforce, N64 Classic) vk_n64.cpp n64_in_front: the preset while its 3D pass draws, 0 none) +int n64_in_front() { return n64_front; } static uint64_t frame_no = 10; uint64_t texture_frame_no() { return frame_no; } VkResult shared_cache_compute(const VkComputePipelineCreateInfo* ci, VkPipeline* out) { @@ -157,6 +159,9 @@ static int logic(const char* env) { } upscaling = ur::DLAA, frame_no++; CHECK(aa_mode() == ar::FXAA); // (the switch over an upscaler too: a lab's A/B of the game's SMAA under it) + n64_front = 1, frame_no++; + CHECK(aa_mode() == ar::FXAA); // ((Triforce, N64 Classic) and over N64 Classic's Off) + n64_front = 0; std::puts("aa passes: RX_VK_AA is the run's choice"); return 0; } @@ -229,6 +234,16 @@ static int logic(const char* env) { CHECK(!aa_asked() && aa_state() == ar::QUIET); frame_no++; CHECK(!aa_asked() && !aa_leave_out(ar::kWeightsKey)); + // ((Triforce, 11-22, N64 Classic) its 3D pass draws: the game's SMAA is left out with the game's own chosen, its edge and + // weight passes too once a composition is replaced; and the game's own again when it stops, as after any other choice + n64_front = 1, frame_no++; + CHECK(aa_asked() && aa_mode() == ar::OFF); + aa_composed(true, nullptr); + frame_no++; + CHECK(aa_leave_out(ar::kEdgesKey) && aa_leave_out(ar::kWeightsKey)); + n64_front = 0, frame_no++; + CHECK(aa_asked() && !aa_leave_out(ar::kEdgesKey) && aa_mode() == ar::GAME); + CHECK(!aa_asked() && aa_state() == ar::QUIET); // FXAA with none of the game's compositions met for a minute (another game version): said once in the log, and to the row opts.aa = ar::FXAA; const size_t before = said.size(); diff --git a/tests/test_aa_row.py b/tests/test_aa_row.py index 8aa071f..b56cabb 100644 --- a/tests/test_aa_row.py +++ b/tests/test_aa_row.py @@ -248,6 +248,7 @@ int main() { ''' MENU = r'''#include "@ROOT@/gpu/vk/aa_rows.h" +#include "@ROOT@/gpu/vk/n64_rules.h" #include #include #include @@ -267,11 +268,20 @@ int aa_env_choice() { return env_now; } int aa_state() { return state_now; } bool reflex_available() { return true; } namespace mkwvk::dlssg { bool reflex_on() { return false; } } /* ((Triforce) Reflex through Streamline: row_fixed asks it) */ +/* ((Triforce) what else sets the picture's shape and Custom's size, tests/test_output_resolution.py: row_fixed asks them) */ +int shape_owner() { return 0; } +bool custom_env(long* = nullptr, long* = nullptr) { return false; } bool antilag_available() { return true; } unsigned upscalers_available() { return ~0u; } bool filter_needed() { return true; } const char* dlss_preset_env() { return nullptr; } int output_choice(int v) { return v; } +/* ((Triforce, 11-22, N64 Classic) its 3D pass drawing in the upscaler's place (vk_n64.cpp n64_in_front), RX_VK_N64, and the + Remembered page's rows (none here) */ +int n64_front = mkwvk::n64_rules::OFF; +int n64_in_front() { return n64_front; } +bool n64_env_set() { return false; } +int n64_rem_row(const int*) { return -1; } @TEXT@ @HINT@ @FIXED@ @@ -317,10 +327,11 @@ int main() { opts.aa = v, up_now = ur::GAME, env_now = -1, state_now = aa_rows::QUIET; CHECK(!std::strcmp(tx_aa(v), names[v]) && !row_fixed(&opts.aa)); CHECK(hn_aa(v, -1) && hn_aa(v, -1) == hn_aa(v, 0)); - /* every line a value can have, for the help's height: its own, DLSS's, FSR's, the switch's, the missing passes' */ + /* every line a value can have, for the help's height: its own, DLSS's, FSR's, the switch's, the missing passes', N64 + Classic's */ int n = 0; while (hn_aa(v, n)) n++; - CHECK(n == 5 && !hn_aa(v, 5) && !hn_aa(v, 6)); + CHECK(n == 6 && !hn_aa(v, 6) && !hn_aa(v, 7)); for (int w = 0; w < v; w++) CHECK(std::strcmp(hn_aa(v, 0), hn_aa(w, 0))); /* replaced: nothing more to say */ state_now = aa_rows::REPLACED; @@ -353,6 +364,14 @@ int main() { state_now = aa_rows::MISSING; CHECK(hn_aa(v, -1) == hn_aa(v, env == aa_rows::GAME ? 3 : 4)); } + /* ((Triforce, 11-22, N64 Classic) while its 3D pass draws: the row says so, has nothing to choose, keeps the choice, and + its line says why; RX_VK_AA's run is vk_aa.cpp's to take over it (tests/test_aa_passes.py) */ + for (int v = 0; v < aa_rows::kValues; v++) { + opts.aa = v, up_now = ur::GAME, env_now = -1, state_now = aa_rows::MISSING, n64_front = mkwvk::n64_rules::FAITHFUL; + CHECK(!std::strcmp(tx_aa(v), "N64 Classic") && row_fixed(&opts.aa) && opts.aa == v); + CHECK(hn_aa(v, -1) == hn_aa(v, 5) && std::strstr(hn_aa(v, -1), "N64 Classic") && std::strstr(hn_aa(v, -1), "kept")); + } + n64_front = mkwvk::n64_rules::OFF; /* the other rows' fixing is theirs: the row's own value does not fix another. ((Triforce, options_version 7) DLAA is the Render resolution's Native (100%) step: that row has its steps) */ up_now = ur::DLAA, env_now = -1; @@ -395,8 +414,13 @@ def main(): # the renderer's side: what is in effect is the row's rule, asked with what upscales as the menu's Upscaler row shows it mode = definition(aa, "int aa_mode") - check("ar::chosen(opts.aa, env_choice())" in mode and "ar::effective(choice, upscaler_now(), temporal_before_bloom(), env_choice() >= 0)" in mode, + choice = definition(aa, "int choice_now") + check("const int choice = choice_now();" in mode and "ar::chosen(opts.aa, env_choice())" in choice and + "ar::effective(choice, upscaler_now(), temporal_before_bloom(), env_choice() >= 0)" in mode, "aa_mode does not take the row's choice (RX_VK_AA over it) through aa_rows.h's effective") + # ((Triforce, 11-22, N64 Classic) Off while its 3D pass draws the gameplay upscale; RX_VK_AA still over it) + check("return env_choice() >= 0 ? choice : n64_rules::anti_aliasing(n64_in_front(), choice);" in choice, + "the row's choice no longer gives way to N64 Classic's 3D pass, or RX_VK_AA no longer goes over that") check("frame_read.load(std::memory_order_acquire) == frame" in mode and "std::lock_guard lk(s.mu);" in mode, "aa_mode no longer takes the choice once a frame") check(re.sub(r"\s+", " ", definition(aa, "int upscaler_now")).endswith( @@ -407,7 +431,7 @@ def main(): check('getenv("RX_VK_AA")' in aa and 'getenv("RX_VK_AA_KEEP")' in aa, "vk_aa.cpp no longer reads its two switches") # the game's own chosen and nothing left to free: a dispatch asks a comparison and nothing else check(re.sub(r"\s+", " ", definition(aa, "bool aa_asked")) == - "bool aa_asked() { return ar::chosen(opts.aa, env_choice()) != ar::GAME || engaged.load(std::memory_order_relaxed) || upscaler_asks(); }", + "bool aa_asked() { return choice_now() != ar::GAME || engaged.load(std::memory_order_relaxed) || upscaler_asks(); }", "aa_asked is no longer the row's choice, whether anything is left to free and whether an upscaler leaves the SMAA out") asks = definition(aa, "bool upscaler_asks") check("ar::effective(ar::GAME, upscaler_now(), temporal_before_bloom(), env_choice() >= 0) != ar::GAME" in asks and diff --git a/tests/test_achievements.py b/tests/test_achievements.py index 859fd84..9b2c0d6 100644 --- a/tests/test_achievements.py +++ b/tests/test_achievements.py @@ -124,8 +124,25 @@ def check_sources(): "ach_list.done(value);", "if (ach_list.earn(value)) menu_refresh = true;"): check(line in setter, "the menu does not take the host's achievements: " + line) table = menu[menu.index("Row rows[] = {"):] - check(table.index('"Bug capture (F8)"') < table.index('{TAB_SYSTEM, "Achievements", nullptr, 0, 0, 0, nullptr,') < table.index('MENU_HEADING(TAB_SYSTEM, "Mod cheats")') - and 'constexpr char kAchRow[] = "Achievements";' in menu, "the Achievements row is not on the System tab after Bug capture (F8)") + # (11-23) a group of their own, the System tab's first: the list's page, then the two switches + system = [m.start() for m in re.finditer(r"TAB_SYSTEM", table)] + order = [table.index(part) for part in ('MENU_HEADING(TAB_SYSTEM, "Achievements"),', '{TAB_SYSTEM, "View achievements", nullptr, 0, 0, 0, nullptr,', + '{TAB_SYSTEM, "Achievements", &opts.achievements, 0, 1, 1, tx_onoff,', + '{TAB_SYSTEM, "Achievement notices", &opts.achievement_notices, 0, 1, 1, tx_onoff,', + 'MENU_HEADING(TAB_SYSTEM, "Game"),')] + check(order == sorted(order) and system[0] > order[0] and system[0] - order[0] < 40 and 'constexpr char kAchRow[] = "View achievements";' in menu, + "the Achievements group is not the System tab's first, with its page's row and its two switches") + check(re.search(r"\bint achievements = 1;", read("gpu", "vk", "vk_menu.h")) and re.search(r"\bint achievement_notices = 1;", read("gpu", "vk", "vk_menu.h")), + "the Achievements rows are not On unless set") + check("if (id == HOS_OPT_ACH_ON) return opts.achievements != 0;" in replay and "if (id == HOS_OPT_ACH_NOTICES) return opts.achievement_notices != 0;" in replay, + "the renderer does not tell the host the Achievements rows") + check("if (!hos_achievements_on() || !rx_option(HOS_OPT_ACH_ON, 1)) return;" in own and "if (!quiet) hos_menu_sound_play(HOS_MENU_SOUND_SYS_DECIDE, now_ns);" in own, + "the host earns with the Achievements row Off, or plays the notice's sound with the notices Off") + tick = block(menu, "void menu_tick() {") + check("earned >= 0 && opts.achievement_notices) ach_notice = earned, ach_notice_at = prof_now();" in tick, "a notice shows with the Achievement notices row Off") + notice = block(menu, "void draw_ach_notice(ui::Ctx& c) {") + check('constexpr char kAchWhere[] = "See all: Options > System";' in menu and "ui::kSoft, kAchWhere);" in notice and "ui::size_of(c.f.body, 12 * s, kAchWhere).x" in notice, + "the notice does not say where the list is, or is not as wide as that line") check("(strcmp(rows[i].name, kAchRow) || rows[i].tab != TAB_SYSTEM || ach_list.shown() > 0) &&" in block(menu, "bool row_shown("), "the Achievements row shows before the host named them") press = menu[menu.index("else if (press[7] && is_ach_row(r)) page = kAchPage"):] @@ -134,10 +151,13 @@ def check_sources(): check("else if (page == kAchPage) draw_achievements(k);" in block(menu, "void draw_menu(ui::Ctx& c, bool perf_under) {"), "the Achievements page is not drawn") page = number(menu, "kAchPage") check(page not in (0, 1, 3, 4, 5, 6, number(menu, "kModsPage"), number(menu, "kModsRowPage")), "kAchPage is another page's number") - for record in ("void menu_record(", "void menu_record_image("): - body = block(menu, record) - check("ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000" in body and "&& !earned)" in body - and "if (earned) draw_ach_notice(c);" in body, "%s an achievement's notice is not drawn, or not while nothing else shows" % record) + body = block(menu, "void menu_record_image(") + check("ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000" in body and "&& !earned)" in body + and "if (earned) draw_ach_notice(c);" in body, "menu_record_image: an achievement's notice is not drawn, or not while nothing else shows") + # ((Triforce, 11-23) N64 Classic split menu_record: what shows (showing_now) and the drawing (draw_overlays), the notice in both) + check("s.earned = !s.start && ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000" in block(menu, "Showing showing_now(") + and "if (s.earned) draw_ach_notice(c);" in block(menu, "void draw_overlays(") + and "&& !s.earned)" in block(menu, "void menu_record("), "menu_record: an achievement's notice is not drawn, or not while nothing else shows") check(number(own, "SHOWN_MS") > int(re.search(r"kAchNoticeMs = (\d+);", menu).group(1)), "the host shows the next notice before this one is gone") return api, own @@ -181,7 +201,7 @@ def main(): check(own.count(marker) == 1, "host/achievements.c no longer includes menu_sound.h last") (tmp / "achievements_actual.inc").write_text(own[own.index(marker) + len(marker):], encoding="utf-8") (tmp / "achievements_constants.inc").write_text( - "".join(block(api, start) + ";\n" for start in ("enum { HOS_OPT_ACH_TEXT = 165", "enum { HOS_ACH_EARNED = 256", "enum { HOS_MENU_SOUND_OPEN = 1")), + "".join(block(api, start) + ";\n" for start in ("enum { HOS_OPT_ACH_TEXT = 165", "enum { HOS_OPT_ACH_ON = 185", "enum { HOS_ACH_EARNED = 256", "enum { HOS_MENU_SOUND_OPEN = 1")), encoding="utf-8") exe = tmp / "host.exe" run([a.cc] + warnings + ["-Wno-unused-function", "-I" + str(ROOT / "host"), "-I" + str(tmp), str(ROOT / "tests" / "achievements_host_test.c"), @@ -204,6 +224,20 @@ def main(): f.write(b"deadbeef 5 Gone\n") run([str(exe), str(game), "second"], says="PASS", cwd=str(tmp), env=on) check(sorted(f.name for f in game.iterdir()) == ["achievements.txt", "triforce_achievements.txt"], "the game folder has other files now") + # (11-23) the System tab's two rows, in a game folder of its own + rows_game = tmp / "rows game" + rows_game.mkdir() + run([str(exe), str(rows_game), "rows"], says="PASS", cwd=str(tmp), env=on) + # the save files on (host/save_files.c): what a file earned is kept in its own folder, and is no other file's. + # File 1 starts from what the game folder earned before; the game folder's own is left as it was + before = earned.read_bytes() + (game / "user").mkdir(), (game / "user-2").mkdir() + run([str(exe), str(game), "file2"], says="PASS", cwd=str(tmp), env=on) + run([str(exe), str(game), "file1"], says="PASS", cwd=str(tmp), env=on) + run([str(exe), str(game), "again1"], says="PASS", cwd=str(tmp), env=on) + check(earned.read_bytes() == before, "the game folder's earned achievements were changed by a save file's") + check(sorted(f.name for f in (game / "user-2").iterdir()) == ["triforce_achievements.txt"] and + sorted(f.name for f in (game / "user").iterdir()) == ["triforce_achievements.txt"], "a save file's folder has other files now") check((game / "achievements.txt").read_bytes() == OWN_LIST.encode("utf-8"), "the player's own list was changed") print("PASS: achievements: the list and what it refuses, earning, the file of the earned ones, the host's naming and notices, " "the menu's list and page, and on unless HOS_ACHIEVEMENTS=0") diff --git a/tests/test_acquire_ahead.py b/tests/test_acquire_ahead.py new file mode 100644 index 0000000..f779dbc --- /dev/null +++ b/tests/test_acquire_ahead.py @@ -0,0 +1,90 @@ +"""(Triforce, 11-23) The next swapchain image acquired ahead on the present thread (RX_VK_ACQUIRE_AHEAD, gpu/vk/vk_replay.cpp +acquire_ahead; no game, no GPU). + +On AMD's Windows driver an acquired image comes back with the compositor's next refresh, and present_image waited for it +(the acquire's fence, RX_VK_ACQUIRE_FENCE) on the thread that replays the frame: 2.4 to 4.2 ms of every frame on an RX 6700 +XT, 16% of that thread in a profile. The present thread now acquires the next image right after its present and waits for it +there, while the frame is replayed; present_image finds it held and free. + +Read from the source, as the rest of the present's rules are (tests/test_present_thread.py): +- when: only on the present thread, after present_out and before it says it is done; with the acquire's fence, without DLSS + frame generation, on AMD's Windows driver unless RX_VK_ACQUIRE_AHEAD says otherwise; and the present thread is wanted for it; +- what: nothing while an image is held, with no swapchain, or while a resize or a lost surface waits for present_image; the + acquire signals the fence and no semaphore; the image waited for at most 250 ms; held, marked free when it was; +- no present_image_mu: present_image holds it while it settles this thread's work, and would wait for itself; +- present_image takes a held image marked free without waiting, and every other held image as before. + + python -I -B tests/test_acquire_ahead.py +""" +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def block(text, marker): + start = text.index(marker) + end = text.index('{', start) + 1 + depth = 1 + while depth: + depth += (text[end] == '{') - (text[end] == '}') + end += 1 + return text[start:end] + + +def before(text, *parts): + at = -1 + for p in parts: + i = text.find(p, at + 1) + if i < 0: + return False + at = i + return True + + +def main(): + replay = (ROOT / "gpu/vk/vk_replay.cpp").read_text(encoding="utf-8") + fails = [] + + def check(ok, why): + if not ok: + fails.append(why) + + wanted = block(replay, "bool acquire_ahead_wanted() {") + check("#ifdef _WIN32" in wanted and 'getenv("RX_VK_ACQUIRE_AHEAD")' in wanted, "the switch is not read, or not on Windows alone") + check("if (asked == 0 || !acquire_fence_on() || dlssg::active()) return false;" in wanted, + "it runs without the acquire's fence, with DLSS frame generation, or with the switch at 0") + check("return asked > 0 || dev.props.vendorID == 0x1002;" in wanted, "it is not AMD's by default, or =1 does not turn it on") + + ahead = block(replay, "void acquire_ahead() {") + check("present_image_mu" not in ahead.split("//")[0] and "std::lock_guard lk(present_image_mu)" not in ahead, + "it takes present_image_mu, which present_image holds while it waits for this thread") + check(before(ahead, "if (held_image.on || !dev.swapchain || dev.swap_resize.load(std::memory_order_acquire) ||", + "surface_lost_noted.load(std::memory_order_acquire)", "return;", "vkAcquireNextImageKHR("), + "it acquires while an image is held, with no swapchain, or before present_image made the swapchain again") + check("vkAcquireNextImageKHR(dev.device, dev.swapchain, UINT64_MAX, VK_NULL_HANDLE, fence, &index);" in ahead, + "the acquire does not signal the fence alone") + check(before(ahead, "if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) {", "return;", "image_free(250000000ull)", + "held_image = {true, index, dev.swap_generation, 0, false, ready == VK_SUCCESS};"), + "the image is not waited for at most 250 ms and held, marked free when it was") + + main_ = block(replay, "void present_thread_main() {") + check(before(main_, "present_out(o, qk, true);", "}", "acquire_ahead();", "present_hand.done();"), + "it does not run on the present thread after its present, with the queue's lock let go, before the thread is done") + ptw = block(replay, "bool present_thread_wanted() {") + check("acquire_ahead_wanted()" in ptw, "the present thread is not wanted for it") + + pi = block(replay, "void present_image(VkImage src, uint32_t sw, uint32_t sh, const int crop[4], VkImageView view) {") + check(before(pi, "present_thread_settle();", "held_image.on && held_image.free ? VK_SUCCESS : image_free("), + "present_image does not settle the present thread first, or waits again for an image waited free") + held = block(replay, "struct HeldImage {") + check("bool free = false;" in held, "a held image has no mark for having been waited free") + + if fails: + for f in fails: + print("FAIL: " + f) + raise SystemExit(1) + print("acquire ahead: ok") + + +if __name__ == "__main__": + main() diff --git a/tests/test_bench_helpers.py b/tests/test_bench_helpers.py new file mode 100644 index 0000000..8878242 --- /dev/null +++ b/tests/test_bench_helpers.py @@ -0,0 +1,84 @@ +"""(Triforce, 11-22) The benchmark's helper-thread test (host/hos_bench.c HOS_BENCH_HELPERS, gpu/vk/vk_replay.cpp par_forced, +launcher/Logic/Benchmark.cs). The source read: no game, no GPU. + +- the renderer: HOS_OPT_HELPERS_FORCE's option_set holds the way (0 off, 1 on, -1 the tuner again), par_tune_present applies + it before the tuner is told the frame (so a held frame is neither a trial's nor a window's), and its option says the helper + threads a test can use (0 without the tuner: the row's Off, RX_VK_PARALLEL); +- the host: the test asks once what it can use, holds a scene's first way during that scene's settling, turns the order from + scene to scene, measures both halves, settles again after the switch, writes both halves and the threads used, and gives + the way back to the tuner once the run ends; +- the launcher: it sets HOS_BENCH_HELPERS=1 and the row's Automatic for the run (the row's Off has no helper threads), and + the start dialog has the choice. + + python -I -B tests/test_bench_helpers.py +""" +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def check(ok, what): + if not ok: + raise SystemExit("FAIL: " + what) + + +def function(text, head): + start = text.find(head) + check(start >= 0, "%s is missing" % head.rstrip(" {(")) + return text[start:text.index("\n}\n", start) + 3] + + +def in_order(text, steps, what): + at = 0 + for s in steps: + i = text.find(s, at) + check(i >= 0, "%s: %r is missing or out of order" % (what, s)) + at = i + len(s) + + +def main(): + api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8") + check("enum { HOS_OPT_HELPERS_FORCE = 170 };" in api, "HOS_OPT_HELPERS_FORCE is not option 170 (165 to 169 are the achievements')") + replay = (ROOT / "gpu" / "vk" / "vk_replay.cpp").read_text(encoding="utf-8") + check("std::atomic par_forced{-1};" in replay, "par_forced: the tuner decides unless the benchmark holds a way") + in_order(function(replay, "void par_tune_present() {"), + ["if (!par_auto()) return;", "const replay_threads::Frame fr = par_frame_now(ms);", + "if (const int forced = par_forced.load(std::memory_order_relaxed); forced >= 0) {", "par_auto_on = forced == 1;", + "return;", "tuner.step(fr, par_auto_on, par_stream_order_only());"], + "par_tune_present: a held way before the tuner") + check("if (id == HOS_OPT_HELPERS_FORCE) return par_forced.store(value < 0 ? -1 : value ? 1 : 0, std::memory_order_relaxed);" + in replay, "option_set HOS_OPT_HELPERS_FORCE no longer holds the way") + check("if (id == HOS_OPT_HELPERS_FORCE) return par_auto() ? par_threads_max() : 0;" in replay, + "option HOS_OPT_HELPERS_FORCE no longer says the threads a test can use") + + bench = (ROOT / "host" / "hos_bench.c").read_text(encoding="utf-8") + check('getenv("HOS_BENCH_HELPERS")' in bench and "B.helper_threads = -1;" in bench, "HOS_BENCH_HELPERS is not read") + present = function(bench, "void hos_bench_present(int64_t now) {") + in_order(present, ["case MKWVK_BENCH_SETTLE:", "B.helper_threads = rx_option(HOS_OPT_HELPERS_FORCE, 0);", + "if (helper_test() && !B.way_set) {", "B.way = B.scene % 2, B.way_set = 1, B.t_phase = now;", + "rx_option_set(HOS_OPT_HELPERS_FORCE, B.way);", "if (now - B.t_phase >= SETTLE_NS) {"], + "the settling: the scene's first way held, the order turned from scene to scene") + in_order(present, ["case MKWVK_BENCH_MEASURE:", "if (helper_test()) {", "stats_of(&B.halves[B.way]);", "if (B.half == 0) {", + "B.half = 1, B.way ^= 1;", "rx_option_set(HOS_OPT_HELPERS_FORCE, B.way);", + "B.phase = MKWVK_BENCH_SETTLE, B.t_phase = now;", "scene_done();"], + "the measurement: both halves, settled again after the switch") + in_order(present, ["if (helper_test() && B.phase >= MKWVK_BENCH_DONE", "rx_option_set(HOS_OPT_HELPERS_FORCE, -1);"], + "the run's end: the tuner decides again") + check("B.half = 0, B.way_set = 0;" in function(bench, "static void go_scene(int64_t now) {"), "a new scene's halves") + results = function(bench, "static void write_results(int stopped) {") + in_order(results, ['if (r->tested) {', '\\"helpers\\":{\\"first\\":\\"%s\\",\\"off\\":', "json_half(f, &r->way[0]);", + '\\"on\\":', "json_half(f, &r->way[1]);"], "the results: both halves") + check('if (B.helpers) fprintf(f, ",\\"helper_test\\":{\\"threads\\":%d}"' in results, "the results: the threads used") + + launcher = (ROOT / "launcher" / "Logic" / "Benchmark.cs").read_text(encoding="utf-8") + check('if (helperTest) si.Environment["HOS_BENCH_HELPERS"] = "1";' in launcher, "the launcher does not ask for the test") + check("keys[KHelpers] = HelpersAutomatic;" in launcher, "the launcher does not give the test Automatic's helper threads") + backend = (ROOT / "launcher" / "App" / "Backend.Bench.cs").read_text(encoding="utf-8") + check('("helpers", "With the helper-thread test", false)' in backend and '"helpers" => RunBench(compare: false, helperTest: true)' + in backend, "the start dialog has no helper-thread test") + print("PASS: the benchmark's helper-thread test holds each way past the tuner, measures both halves in turned order, " + "writes them, and gives the way back; the launcher asks for it and suggests the row") + + +if __name__ == "__main__": + main() diff --git a/tests/test_bug_capture.py b/tests/test_bug_capture.py index b4225a9..b634d10 100644 --- a/tests/test_bug_capture.py +++ b/tests/test_bug_capture.py @@ -86,9 +86,16 @@ def check_sources(): check("InterlockedCompareExchange(&capture_state, 2, 1) != 1" in work, "a capture can be written twice at once") # the picture: before the overlays, not during the start-up screen, three presents before it is read record = block(menu, "void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {") - call = "if (!start) bugshot_record(cmd, index, w, h);" - check(call in record and record.index(call) < min(record.index(s) for s in ("ui::begin(", "ui::idle()", "draw_menu(", "draw_fps(", "ui::record(")), + call = "if (!s.start) bugshot_record(cmd, index, w, h);" + check(call in record and record.index(call) < min(record.index(s) for s in ("ui::begin(", "ui::idle()", "draw_overlays(", "ui::record(")), "the capture's picture is not taken before the overlays are drawn (or is taken of the start-up screen)") + # ((Triforce, 11-22, N64 Classic) the options drawn under its TV before the window pass: never while a capture waits for + # this frame's picture; a copy under way goes on at menu_record all the same) + layer = block(menu, "VkImageView menu_tv_layer(VkCommandBuffer cmd) {") + check("bugshot_state() == 1" in layer and layer.index("bugshot_state() == 1") < layer.index("draw_overlays("), + "the options are drawn under N64 Classic's TV, into the picture, while a capture waits for it") + check(record.index("bugshot_record(cmd, index, w, h);") < record.index("ui::record_rest(cmd, index, w, h);"), + "menu_record does not go on with a capture's copy when the options were drawn under the TV") rec = block(shot, "void bugshot_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {") order = [rec.index(s) for s in ("barrier(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);", "vkCmdCopyImageToBuffer(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &c);", diff --git a/tests/test_debug_tab_layout.py b/tests/test_debug_tab_layout.py index 6005740..2c4cbbd 100644 --- a/tests/test_debug_tab_layout.py +++ b/tests/test_debug_tab_layout.py @@ -163,7 +163,7 @@ def main(): action = function(menu, "void action_cell(") check("choice_cell(c, a, b, word, sel, false, !fixed, fixed);" in action, "action_cell is not the orange plate with its arrow") check("else action_cell(c, va, vb, v.empty() ? buttons[r.cheat] : v, selected, r.cheat == 9);" in draw - and 'else action_cell(c, va, vb, ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open", selected);' in draw, + and 'else action_cell(c, va, vb, r.name == kUseWindowSize ? "Copy" : ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open", selected);' in draw, "the Debug tab's buttons and the page, save, Restart and Quit rows are not one style") check(", false, true, false, true)" not in draw, "a row still draws its button as the dark panel") # the rows clipped as the other tabs': none under the header @@ -176,6 +176,10 @@ def main(): # a still is drawn settled: only menu_record, a window's frames, steps the easing image = function(menu, "void menu_record_image(") record = function(menu, "void menu_record(VkCommandBuffer cmd, uint32_t index") + # ((Triforce, 11-22) the window's frames are drawn by draw_overlays, for menu_record and N64 Classic's menu_tv_layer alike) + overlays = function(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under)") + check("draw_overlays(w, h, s, nullptr);" in record and "draw_overlays(" not in image, "menu_record does not draw by draw_overlays") + record = overlays check("if (!ease_live) ease_step = 1.0f;" in image and image.index("if (!ease_live) ease_step = 1.0f;") < image.index("draw_menu(c"), "a still does not draw the lists where the selection asks") check("ease_live = true;" in record and "ease_live = true" not in image, "the window's frames do not keep their easing") diff --git a/tests/test_fg_scale_sharpen.py b/tests/test_fg_scale_sharpen.py index 73a2681..75c54d2 100644 --- a/tests/test_fg_scale_sharpen.py +++ b/tests/test_fg_scale_sharpen.py @@ -2,6 +2,7 @@ window pixel (inside the same picture pixel when the window is the larger, so Sharpness did next to nothing), and its per-pixel math, the shader's own sharpen() compiled as C++, is the picture unchanged at 0, never past the lightest or darkest pixel around it nor outside 0..1 (no halos, no clipping) at any setting, and steeper edges as the setting rises. +The shader's side_outside() is compiled too: full side fill outside the middle, with both soft edges wholly inside it. fg_scale_comp_spv.h names the hash of the fg_scale.comp it was made from (its first line), checked against the shader as it is now with or without glslang; with glslangValidator the shader compiles, and with the version the header names, the rest of the header is its output byte for byte. --write makes the header: glslang's output with that line on top. @@ -80,6 +81,10 @@ static float min(float a, float b) { return std::min(a, b); } static float max(float a, float b) { return std::max(a, b); } static float clamp(float v, float lo, float hi) { return std::min(std::max(v, lo), hi); } static vec3 clamp(vec3 v, vec3 lo, vec3 hi) { return min(max(v, lo), hi); } +static float smoothstep(float lo, float hi, float x) { + const float t = clamp((x - lo) / (hi - lo), 0.0f, 1.0f); + return t * t * (3.0f - 2.0f * t); +} ''' FIXTURE = r''' @@ -90,7 +95,36 @@ static vec3 rnd3() { return {rnd(), rnd(), rnd()}; } static float ch(vec3 v, int i) { return i == 0 ? v.r : i == 1 ? v.g : v.b; } // a blurred edge (the picture as it reaches the window pass), sampled one picture pixel apart around x static float edge(float x) { return 0.1f + 0.8f / (1.0f + std::exp(-2.0f * x)); } +static void check_sides() { + // Player's 3840x1600, both fixed wide pictures, and the normalized pixel-cap picture. + const int pictures[][2] = {{3840, 2848}, {5120, 2560}, {5120, 3840}, {7224, 3616}}; + const float feather = 0.006f; + for (const auto& picture : pictures) { + const int width = picture[0]; + const float x0 = float(width - picture[1]) / (2.0f * width), x1 = 1.0f - x0; + float previous = 1.0f; + for (int pixel = 0; pixel < width; ++pixel) { + const float x = (pixel + 0.5f) / width; + const float outside = side_outside(x, x0, x1); + CHECK(outside >= 0.0f && outside <= 1.0f); + if (x <= x0 || x >= x1) CHECK(outside == 1.0f); + else if (x >= x0 + feather && x <= x1 - feather) CHECK(outside == 0.0f); + else CHECK(outside > 0.0f && outside < 1.0f); + if (x < 0.5f) CHECK(outside <= previous); + else CHECK(outside >= previous); + previous = outside; + } + CHECK(side_outside(x0, x0, x1) == 1.0f); + CHECK(side_outside(x1, x0, x1) == 1.0f); + CHECK(side_outside(x0 + feather, x0, x1) == 0.0f); + CHECK(side_outside(x1 - feather, x0, x1) == 0.0f); + CHECK(std::abs(side_outside(x0 + feather * 0.5f, x0, x1) - 0.5f) < 1e-4f); + CHECK(std::abs(side_outside(x1 - feather * 0.5f, x0, x1) - 0.5f) < 1e-4f); + } + std::puts("PASS: side fill is whole outside the middle; monotonic 0.006 soft edges stay inside at 3840, 5120 and 7224"); +} int main() { + check_sides(); const float amounts[] = {0.0f, 0.1f, 0.4f, 0.8f, 1.0f}; for (int i = 0; i < 200000; i++) { const vec3 c = rnd3(), n = rnd3(), s = rnd3(), w = rnd3(), e = rnd3(); @@ -159,7 +193,11 @@ def main(): raise SystemExit("missing the neighbour at %s" % tap) lobe = re.search(r"const float kMaxLobe = [^;]*;", text).group(0) fn = block(text, "vec3 sharpen(") - fixture = SHIM + lobe.replace("const float", "static const float") + "\nstatic " + fn + FIXTURE + sides = block(text, "float side_outside(") + side_branch = block(body, "if (pc.side != 0 && pc.x1 > pc.x0)") + if "outside = side_outside(uv.x, pc.x0, pc.x1);" not in side_branch: + raise SystemExit("the side pass does not use the tested side_outside rule") + fixture = SHIM + lobe.replace("const float", "static const float") + "\nstatic " + fn + "\nstatic " + sides + FIXTURE with tempfile.TemporaryDirectory(prefix="fg-sharpen-") as tmp: cpp = Path(tmp) / "fixture.cpp" exe = Path(tmp) / "fixture" diff --git a/tests/test_fps_cap_monitor.py b/tests/test_fps_cap_monitor.py index 4b5fcd2..0b2a1e0 100644 --- a/tests/test_fps_cap_monitor.py +++ b/tests/test_fps_cap_monitor.py @@ -163,8 +163,9 @@ def main(): check("1000000000LL / fps_max()" in loop, "the vsync event's period is taken once, before Monitor's rate is known") presented = block(vi, "void hos_vi_native_presented(void) {") # ((Triforce, 11-22, PRESENT-30) the period is pace_fps()'s, which is the cap unless a movie plays at a cap of 60) - check("const int interval = fps_max() < 60 ? 1 : present_interval;" in presented and "pace_fps() * interval" in presented - and "return movie_pace_fps(movie_raise, fps_max());" in block(vi, "static int pace_fps(void) {"), + # ((Triforce, 11-22, N64 Classic, step 7) and N64 Classic's rate, which paces by itself too (host/n64_pace.h; tests/test_n64_pace.py) + check("const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval);" in presented and "pace_fps() * interval" in presented + and "return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max()));" in block(vi, "static int pace_fps(void) {"), "a cap under 60 that settles late is paced with the game's own interval on top") readme = (ROOT / "readme.md").read_text(encoding="utf-8") check("| Frame rate cap | 30, 40, 45, 60, 90, 120, 144, 165, 240, Monitor's rate" in readme, diff --git a/tests/test_frame_rate_cap_step.py b/tests/test_frame_rate_cap_step.py index 4d12504..7d5d04a 100644 --- a/tests/test_frame_rate_cap_step.py +++ b/tests/test_frame_rate_cap_step.py @@ -53,9 +53,11 @@ FIXTURE = r'''#define _CRT_SECURE_NO_WARNINGS #include #include "step_steady.h" #include "movie_pace.h" /* ((Triforce, 11-22, PRESENT-30) realtime_step goes by pace_fps: the cap here, no movie plays) */ +#include "n64_pace.h" /* ((Triforce, N64 Classic) and no rate of N64 Classic's: n64_rate stays 0 */ #define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); exit(1); } } while (0) static int64_t pace_period_ns; /* (the period the presents are paced by: hos_vi_native_presented) */ static int movie_raise; /* (nn_vi.c's, set once a present by movie_pace_decide: tests/test_movie_pace.py) */ +static int n64_rate; /* ((Triforce, N64 Classic) nn_vi.c's, set beside it: tests/test_n64_pace.py) */ static uint8_t guest[0x4000]; #define GP(a) ((void *)(guest + (a))) #define MOD 0x1000u diff --git a/tests/test_framegen_preset.py b/tests/test_framegen_preset.py index ccca71b..ee47d38 100644 --- a/tests/test_framegen_preset.py +++ b/tests/test_framegen_preset.py @@ -71,7 +71,8 @@ void restart_values(int*) {} struct { void note(const int*) {} } restart_state; bool can_mic() { return false; } void mic_chosen() {} -int step_output_choice(int id, int dir) { return id + dir; } +struct { unsigned w, h; } remembered_custom{}; +bool output_step(int, bool) { return false; } const char* tx_framegen_row(int) { return ""; } const char* hn_framegen_row(int, int) { return ""; } const char* tx_fps_cap(int) { return ""; } diff --git a/tests/test_gpu_busy.py b/tests/test_gpu_busy.py new file mode 100644 index 0000000..889ff57 --- /dev/null +++ b/tests/test_gpu_busy.py @@ -0,0 +1,93 @@ +"""(Triforce, 11-23) The dynamic resolution's GPU time as the union of the recordings' intervals (gpu/vk/gpu_busy.h; no game, no GPU). + +The clock summed each recording's interval; with AMD's early first timestamps a frame's intervals overlap and the sum +counted the overlaps again (14.9 ms against a 7.8 ms span on an RX 6700 XT), so Resolution Auto drew the 3D at its smallest +on a card half idle. Run here: intervals apart, overlapping, inside one another, touching, empty or backwards, read back out +of order; and a frame of overlapping recordings, whose sum is near twice its span and whose union is the span. The source +is read for the two places that collect the intervals, the clock that uses the union, and its switch. + + python -I -B tests/test_gpu_busy.py [--cxx g++] +""" +import argparse +import subprocess +import sys +import tempfile +from pathlib import Path + +RUN_ALL_ARGS = ["--cxx", "g++"] + +ROOT = Path(__file__).resolve().parents[1] + +FIXTURE = r''' +#include +#include "gpu_busy.h" +using mkwvk::gpu_busy::Union; +static int fails; +#define CHECK(c, what) do { if (!(c)) { fails++; std::printf("FAIL line %d: %s\n", __LINE__, what); } } while (0) +int main() { + { Union u; u.add(0, 10); u.add(20, 30); CHECK(u.ticks == 20 && u.end == 30, "apart: both counted"); } + { Union u; u.add(0, 10); u.add(5, 15); CHECK(u.ticks == 15, "overlapping: the overlap once"); } + { Union u; u.add(0, 10); u.add(2, 8); CHECK(u.ticks == 10 && u.end == 10, "inside: nothing more"); } + { Union u; u.add(0, 10); u.add(10, 12); CHECK(u.ticks == 12, "touching: both"); } + { Union u; u.add(5, 5); u.add(9, 3); CHECK(u.ticks == 0 && u.end == 0, "empty or backwards: nothing"); } + { Union u; u.add(10, 20); u.add(0, 15); CHECK(u.ticks == 10, "out of order: only what lies past the end, never over"); } + { /* a frame: 24 recordings of 0.6 ms each, each begun 0.3 ms after the last (its first timestamp while the last still + runs): their sum is twice the span, their union the span */ + Union u; + unsigned long long sum = 0; + for (int i = 0; i < 24; i++) { + const unsigned long long a = 300ull * i, b = a + 600; + u.add(a, b), sum += b - a; + } + CHECK(sum == 14400 && u.ticks == 7500, "a frame of overlapping recordings: the union is its span"); + /* the next frame after an idle gap counts on from there */ + u.add(20000, 21000); + CHECK(u.ticks == 8500, "after a gap: the next frame's on top"); + } + if (!fails) std::printf("all checks passed\n"); + return fails != 0; +} +''' + + +def check_source(): + rep = (ROOT / "gpu/vk/vk_replay.cpp").read_text(encoding="utf-8") + for needle, why in ( + ('#include "gpu_busy.h"', "the header is not included"), + ("gpu_busy_add(t[0], t[1]);", "the uploads' intervals are not in the union"), + ("gpu_busy_add(t[0], t[tn - 1]);", "the recordings' intervals are not in the union"), + ('getenv("RX_VK_DYNRES_UNION")', "RX_VK_DYNRES_UNION is not read"), + ("const int64_t g = ts_dyn_union() ? gpu_busy_ns() : st_gpu_ns + st_gpu_up_ns;", + "the dynamic resolution's clock does not take the union"), + ("const double dw = (double)(st_wait_ns - waited_last) + (double)host_waits.take(nullptr, nullptr);", + "the clock does not count the host's other waits for the GPU"), + ("const ::gpu_wait_kinds::Exclude compositor;", "the compositor's image counts as a wait for the GPU"), + ("if (ts_ema_behind_ns >= 2e6) ts_gpu_limited = true;\n else if (ts_ema_behind_ns < 1e6) ts_gpu_limited = false;", + "the card is not called the limit at 2 ms of waits a frame, and let go of it under 1 ms"), + ("const bool gpu_limit = !ts_dyn_union() || ts_gpu_limited;", + "the clock does not tell a card that holds the replay back from one that does not"), + ("ts_dyn_scale = std::clamp(ts_ema_gpu_ns / ts_ema_span_ns, 0.02, gpu_limit ? 8.0 : 1.0);", + "the clock is not held to the span while the card is not the frame's limit")): + if needle not in rep: + raise SystemExit("gpu/vk/vk_replay.cpp: " + why) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cxx", default="g++") + args = parser.parse_args() + check_source() + with tempfile.TemporaryDirectory(prefix="gpu-busy-") as d: + tmp = Path(d) + (tmp / "t.cpp").write_text(FIXTURE, encoding="utf-8") + exe = tmp / ("t.exe" if sys.platform == "win32" else "t") + subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-O1", "-I", str(ROOT / "gpu/vk"), + str(tmp / "t.cpp"), "-o", str(exe)], check=True) + run = subprocess.run([str(exe)], text=True, capture_output=True, timeout=60) + sys.stdout.write(run.stdout) + if run.returncode or "all checks passed" not in run.stdout: + raise SystemExit("the union's checks failed" + run.stderr) + + +if __name__ == "__main__": + main() diff --git a/tests/test_gpu_waits.py b/tests/test_gpu_waits.py index a9b18ae..8ab6b1d 100644 --- a/tests/test_gpu_waits.py +++ b/tests/test_gpu_waits.py @@ -87,7 +87,9 @@ def main(): check(min(order) >= 0 and order == sorted(order), "status_tick: the trace's gpu_waits_ms is not this frame's, from a reader of its own, before lab") check('if (f) fputs(",lab\\n", f);' in tick and tick.index("frame_trace::kColumns);") < tick.index('if (f) fputs(",lab\\n", f);'), "status_tick: lab is no longer the trace's last column") - check(rep.count("gpu_wait_kinds::Reader") == 2, "vk_replay.cpp: the readers of the waits are not the line's and the trace's") + # ((Triforce, 11-23) and the dynamic resolution's clock's, ts_dyn_present: tests/test_gpu_busy.py) + check(rep.count("gpu_wait_kinds::Reader") == 3 and "static ::gpu_wait_kinds::Reader host_waits;" in rep, + "vk_replay.cpp: the readers of the waits are not the line's, the trace's and the dynamic resolution's clock's") trace_h = (VK / "frame_trace.h").read_text(encoding="utf-8") check('wb_held_ms,qs_bg_ms,"\n "gpu_waits_ms";' in trace_h and "s.qs_bg, s.gpu_waits);" in trace_h, "frame_trace.h: gpu_waits_ms is not the split's last column") kinds = (VK / "gpu_wait_kinds.h").read_text(encoding="utf-8") diff --git a/tests/test_l3_home.py b/tests/test_l3_home.py new file mode 100644 index 0000000..bdf2252 --- /dev/null +++ b/tests/test_l3_home.py @@ -0,0 +1,213 @@ +"""(Triforce, 11-23) One L3 for the game's main thread, its presenting thread and the replay's core (host/hos_l3_home.h, +host/hos_thread.c; no game, no CPU of the kind). + +On a processor with two or more L3 caches of the same size (AMD's two-die Ryzen 9 parts), the die of the lowest +logical processor the process may use is the home: the core kept for the replay is its last core, and the main and +presenting threads are kept on its other cores, so that what the main thread writes is in the L3 the replay reads it +from. Run here on authored topologies: + +- a 5900X (2 dies of 6 cores, SMT on and off), a 5950X (2 of 8), a 7950X: the first die; the kept core its last; the two + threads on its other cores, the other threads as before; +- a 5600X, a 7800X3D, an Intel processor of two kinds (one L3): nothing; +- a 7950X3D (L3 caches of different sizes): nothing here (host/hos_x3d.h has it); +- a 3900X (four 3-core CCXs), a 3700X (two 4-core CCXs): nothing, too few cores; +- a process held to one die, or without logical processor 0: the die of its lowest processor, or nothing; +- more than one processor group, a list that puts a processor under two L3 caches: nothing. + +The source is read for what cannot run here: HOS_L3_HOME=0 turns it off, the cache die goes first, the log says what was +found, the kept core is chosen among the home's cores, and hos_thread_pin keeps the two threads there. + + python -I -B tests/test_l3_home.py [--cc gcc] +""" +import argparse +import subprocess +import sys +import tempfile +from pathlib import Path + +RUN_ALL_ARGS = ["--cc", "gcc"] + +ROOT = Path(__file__).resolve().parents[1] + + +def block(text, marker): + start = text.index(marker) + end = text.index('{', start) + 1 + depth = 1 + while depth: + depth += (text[end] == '{') - (text[end] == '}') + end += 1 + return text[start:end] + + +FIXTURE = r''' +#include +#include +#include "hos_l3_home.h" + +static int fails; +#define CHECK(cond, what) do { if (!(cond)) { fails++; printf("FAIL line %d: %s\n", __LINE__, what); } } while (0) + +@PICK_RESERVED@ + +#define MB(n) ((uint64_t)(n) << 20) +#define KB(n) ((uint64_t)(n) << 10) +static HosCache caches[512]; +static uint64_t cores[256]; +static unsigned char classes[256]; +static int ncaches, ncores; +static void fresh(void) { ncaches = ncores = 0; } +static void add_cores(int n, int per, int first, uint64_t l2, unsigned char cls) { + for (int i = 0; i < n; i++) { + const uint64_t m = ((1ull << per) - 1) << (first + i * per); + cores[ncores] = m, classes[ncores++] = cls; + caches[ncaches++] = (HosCache){1, m, KB(32)}; + caches[ncaches++] = (HosCache){2, m, l2}; + } +} +static void add_l3(uint64_t mask, uint64_t bytes) { caches[ncaches++] = (HosCache){3, mask, bytes}; } +static HosL3Home h; +static uint64_t pick(uint64_t allowed, int groups) { return hos_l3_home_pick(caches, ncaches, cores, ncores, allowed, groups, &h); } +/* the replay's core as hos_thread.c picks it: among the home's cores when there is one */ +static uint64_t reserved(uint64_t home) { + uint64_t m[256]; + unsigned char c[256]; + int n = 0; + for (int i = 0; i < ncores; i++) + if (!home || (cores[i] & home)) m[n] = cores[i], c[n++] = classes[i]; + return pick_reserved_core(m, c, n); +} + +int main(void) { + /* Ryzen 9 5900X: 12 cores with SMT, two dies of 6, an L3 of 32 MB each */ + fresh(); + add_cores(12, 2, 0, KB(512), 0); + add_l3(0xFFF, MB(32)), add_l3(0xFFF000, MB(32)); + CHECK(pick(0xFFFFFF, 1) == 0xFFF && h.why == HOS_L3_HOME_USED && h.cores == 6 && h.domains == 2, "5900X: the first die"); + CHECK(reserved(0xFFF) == 0xC00, "5900X: the kept core is the first die's last (it was the processor's last, 0xC00000)"); + CHECK(reserved(0) == 0xC00000, "5900X: without a home, the processor's last core, as before"); + CHECK(hos_l3_home_thread_mask(0xFFFFFF, 0xFFF, 0xC00) == 0x3FF, "5900X: the two threads on the first die's other five cores"); + CHECK(hos_l3_home_thread_mask(0xFFFFFF, 0, 0xC00000) == 0, "no home: the two threads get nothing of their own"); + /* (the same, the process without logical processor 0: the die of its lowest) */ + CHECK(pick(0xFFFFFE, 1) == 0xFFE && h.cores == 6, "5900X without LP 0: the first die, what is left of it"); + CHECK(pick(0xFFFFFC, 1) == 0 && h.home == 0xFFC && h.why == HOS_L3_HOME_FEW && h.cores == 5, "5900X without core 0: five cores, too few"); + CHECK(pick(0xFFF000, 1) == 0 && h.why == HOS_L3_HOME_ONE, "5900X held to the second die: one L3, nothing"); + CHECK(pick(0xFFFFFF, 2) == 0 && h.why == HOS_L3_HOME_GROUPS, "more than one processor group: nothing"); + + /* Ryzen 9 5900X with SMT off: 12 logical processors */ + fresh(); + add_cores(12, 1, 0, KB(512), 0); + add_l3(0x3F, MB(32)), add_l3(0xFC0, MB(32)); + CHECK(pick(0xFFF, 1) == 0x3F && h.cores == 6, "5900X, SMT off: the first die"); + /* (6 logical processors on the die: pick_reserved_core keeps none under 8, so the two threads have all six) */ + CHECK(reserved(0x3F) == 0, "5900X, SMT off: no core kept on the die"); + CHECK(hos_l3_home_thread_mask(0xFFF, 0x3F, 0) == 0x3F, "5900X, SMT off: the two threads on the whole first die"); + + /* Ryzen 9 5950X / 7950X: 16 cores with SMT, two dies of 8 */ + fresh(); + add_cores(16, 2, 0, MB(1), 0); + add_l3(0xFFFF, MB(32)), add_l3(0xFFFF0000, MB(32)); + CHECK(pick(0xFFFFFFFF, 1) == 0xFFFF && h.cores == 8, "5950X: the first die"); + CHECK(reserved(0xFFFF) == 0xC000, "5950X: the first die's last core"); + + /* Ryzen 5 5600X: 6 cores, one L3 */ + fresh(); + add_cores(6, 2, 0, KB(512), 0); + add_l3(0xFFF, MB(32)); + CHECK(pick(0xFFF, 1) == 0 && h.why == HOS_L3_HOME_ONE, "5600X: one L3, nothing"); + + /* Ryzen 7 7800X3D: one L3 of 96 MB */ + fresh(); + add_cores(8, 2, 0, MB(1), 0); + add_l3(0xFFFF, MB(96)); + CHECK(pick(0xFFFF, 1) == 0 && h.why == HOS_L3_HOME_ONE, "7800X3D: nothing"); + + /* Ryzen 9 7950X3D: L3 caches of 96 and 32 MB: hos_x3d.h's */ + fresh(); + add_cores(16, 2, 0, MB(1), 0); + add_l3(0xFFFF, MB(96)), add_l3(0xFFFF0000, MB(32)); + CHECK(pick(0xFFFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_MIXED, "7950X3D: nothing here"); + + /* Ryzen 9 3900X: four CCXs of 3 cores, 16 MB each; Ryzen 7 3700X: two of 4 */ + fresh(); + add_cores(12, 2, 0, KB(512), 0); + add_l3(0x3F, MB(16)), add_l3(0xFC0, MB(16)), add_l3(0x3F000, MB(16)), add_l3(0xFC0000, MB(16)); + CHECK(pick(0xFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_FEW && h.cores == 3 && h.domains == 4, "3900X: too few cores"); + fresh(); + add_cores(8, 2, 0, KB(512), 0); + add_l3(0xFF, MB(16)), add_l3(0xFF00, MB(16)); + CHECK(pick(0xFFFF, 1) == 0 && h.why == HOS_L3_HOME_FEW, "3700X: too few cores"); + + /* Intel Core i7-13700K: 8 performance cores with SMT, 8 efficiency cores, one L3 */ + fresh(); + add_cores(8, 2, 0, MB(2), 1); + add_cores(8, 1, 16, MB(4), 0); + add_l3(0xFFFFFF, MB(30)); + CHECK(pick(0xFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_ONE, "13700K: one L3, nothing"); + + /* a list that puts a processor under two L3 caches */ + fresh(); + add_cores(12, 2, 0, KB(512), 0); + add_l3(0xFFF, MB(32)), add_l3(0xFF0FF0, MB(32)); + CHECK(pick(0xFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_NONE, "overlapping L3 caches: nothing"); + fresh(); + add_cores(4, 2, 0, KB(512), 0); + CHECK(pick(0xFF, 1) == 0 && h.why == HOS_L3_HOME_NONE, "no L3 listed: nothing"); + + /* the two threads, by name */ + CHECK(hos_l3_home_thread("sead::MainThread") && hos_l3_home_thread("MainThread") && hos_l3_home_thread("Presentation Thread"), + "the main and presenting threads"); + CHECK(!hos_l3_home_thread("OptimizeChangeBank") && !hos_l3_home_thread("AudioThread") && !hos_l3_home_thread("") && + !hos_l3_home_thread(0), "no other thread"); + + if (!fails) printf("all checks passed\n"); + return fails != 0; +} +''' + + +def check_source(thread): + detect = block(thread, "static uint64_t x3d_detect(") + cpus = block(thread, "static uint64_t hos_x3d_cpus(") + last = block(thread, "static uint64_t last_fastest_core(") + pin = block(thread, "void hos_thread_pin(") + for text, needle, why in ( + (thread, '#include "hos_l3_home.h"', "the header is not included"), + (detect, "hos_l3_home_pick(caches, ncaches, cores, ncores, (uint64_t)proc, (int)GetActiveProcessorGroupCount(), home);", + "the home is not picked from the caches the cache die's rule reads"), + (cpus, 'getenv("HOS_L3_HOME")', "HOS_L3_HOME is not read"), + (cpus, "if (!mask && h.why == HOS_L3_HOME_USED && !home_off) l3_home_mask = h.home;", + "the home is used with a cache die, with HOS_L3_HOME=0, or when the rule did not fire"), + (cpus, 'hos_log("cpu: logical processors %#llx share one of %d L3 caches', "what was found is not logged"), + (last, "const uint64_t home = die ? 0 : l3_home_mask;", "the kept core is not chosen with the home"), + (last, "(!home || ((uint64_t)e->Processor.GroupMask[0].Mask & home))", "the kept core is not among the home's cores"), + (pin, "if (l3_home_mask && hos_l3_home_thread(name)) {", "the two threads are not kept on the home"), + (pin, "hos_l3_home_thread_mask((uint64_t)proc, l3_home_mask, reserved)", "the two threads' affinity is not the header's")): + if needle not in text: + raise SystemExit("host/hos_thread.c: " + why) + # (the reserved core first: hos_reserved_cpus reads the caches before the home is looked at) + if pin.index("hos_reserved_cpus()") > pin.index("if (l3_home_mask && hos_l3_home_thread(name)) {"): + raise SystemExit("host/hos_thread.c: hos_thread_pin reads the home before the caches are read") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cc", default="gcc") + args = parser.parse_args() + thread = (ROOT / "host/hos_thread.c").read_text(encoding="utf-8") + check_source(thread) + fixture = FIXTURE.replace("@PICK_RESERVED@", block(thread, "static uint64_t pick_reserved_core(")) + with tempfile.TemporaryDirectory(prefix="l3home-") as d: + tmp = Path(d) + (tmp / "t.c").write_text(fixture, encoding="utf-8") + exe = tmp / ("t.exe" if sys.platform == "win32" else "t") + subprocess.run([args.cc, "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-O1", "-I", str(ROOT / "host"), + str(tmp / "t.c"), "-o", str(exe)], check=True) + run = subprocess.run([str(exe)], text=True, capture_output=True, timeout=60) + sys.stdout.write(run.stdout) + if run.returncode or "all checks passed" not in run.stdout: + raise SystemExit("the home's checks failed" + run.stderr) + + +if __name__ == "__main__": + main() diff --git a/tests/test_lazy_wb_host.py b/tests/test_lazy_wb_host.py index 18344e9..2556ed2 100644 --- a/tests/test_lazy_wb_host.py +++ b/tests/test_lazy_wb_host.py @@ -37,6 +37,10 @@ ALLOWED = { ("achievements.c", "read_text", "fread"): "into a buffer it mallocs", ("achievements.c", "earned_save", "fwrite"): "from a static buffer of its own, the earned achievements' text", ("bug_capture.c", "read_part", "fread"): "into a buffer it mallocs", + ("save_files.c", "files_read", "fread"): "into a static buffer of its own, triforce_files.txt's text", + ("save_files.c", "files_save", "fwrite"): "from a static buffer of its own, triforce_files.txt's text", + ("save_files.c", "card_of", "fread"): "into a buffer on its stack, a file's triforce_card.txt", + ("save_files.c", "card_keep", "fwrite"): "from a buffer on its stack, this file's triforce_card.txt", ("nn_fs.c", "hos_fs_rom_file", "ReadFile"): "a RomFS file for the menu sounds (host/menu_sound.c), into a buffer it mallocs", ("bug_capture.c", "write_file", "fwrite"): "the report's own files: the options file and a log read into host memory", ("discord_rpc.c", "ipc_write", "WriteFile"): "Discord's pipe: a JSON message the host built", diff --git a/tests/test_menu_restart_slots.py b/tests/test_menu_restart_slots.py index d7a3412..2b5e5e6 100644 --- a/tests/test_menu_restart_slots.py +++ b/tests/test_menu_restart_slots.py @@ -18,7 +18,7 @@ def main(): table = table[:table.index("\n};")] restart = [] for entry in re.split(r"\n \{TAB_", table)[1:]: - name = re.match(r'\w+, "([^"]+)"', entry).group(1) + name = re.match(r'\w+, ("[^"]+"|\w+),', entry).group(1).strip('"') flags = re.findall(r"\b(true|false)\b", entry) if flags and flags[0] == "true": restart.append(name) diff --git a/tests/test_menu_sound_events.py b/tests/test_menu_sound_events.py index 645e3a1..3febf56 100644 --- a/tests/test_menu_sound_events.py +++ b/tests/test_menu_sound_events.py @@ -10,6 +10,11 @@ volume) is cut out of vk_menu.cpp with its label and the options file's reading, hooks in menu_tick (the state before and after, nothing put with the row at 0), the renderer's two options, and the row's lines in readme.md and docs/development.md. tests/test_menu_sound.py has the host's side. +((Triforce, 11-22, N64 Classic) The Remembered page, opened from Graphics' Remembered settings row: a page of its own to the +ear, as the Motion page is (its row and its Back take their press for themselves): opened with decide, left with cancel, its +Copy Faithful and Reset to defaults a decide. Read in vk_menu.cpp: sound_state gives it its own page, and those two rows keep +their press for the sound.) + python -I -B tests/test_menu_sound_events.py [--cxx g++] """ import argparse @@ -128,6 +133,13 @@ int main() { CHECK(sound_of(on_page(rows(3, 4), 1, 6), rows(3, 4), In().back_()) == kCancel); CHECK(sound_of(rows(3, 2), on_page(rows(3, 2), 7), In()) == kDecide); CHECK(sound_of(on_page(rows(3, 2), 7, 1), rows(3, 2), In()) == kCancel); + /* ((Triforce, N64 Classic) the Remembered page, likewise (its page, 10, under Graphics' tab): even onto the same row number + and value, opening is a decide and Back a cancel; its two action rows a decide; Up and Down on it the cursor */ + CHECK(sound_of(rows(2, 2), on_page(rows(2, 2), 10, 2), In()) == kDecide); + CHECK(sound_of(on_page(rows(2, 2), 10, 2), rows(2, 2), In()) == kCancel); + CHECK(sound_of(on_page(rows(2, 2), 10, 23), on_page(rows(2, 2), 10, 23), In().confirm_()) == kDecide); + CHECK(sound_of(on_page(rows(2, 2), 10, 3), on_page(rows(2, 2), 10, 4), In().move_()) == kCursor); + CHECK(sound_of(rows(2, 2), rows(2, 2), In()) == kNone); /* (as Graphics' rows alone: nothing, which was the silence) */ /* out of a mode by Back: an amount, a flag's On and Off, a Restart waiting for its second press */ CHECK(sound_of(on_page(rows(5, 0), 4, 3, 0, kModeEdit), on_page(rows(5, 0), 4, 3), In().back_()) == kCancel); CHECK(sound_of(with_mode(rows(4, 1), kModeConfirm), rows(4, 1), In().back_()) == kCancel); @@ -269,6 +281,16 @@ def main(): check("menu_sound::kSysCursor == HOS_MENU_SOUND_SYS_CURSOR" in menu and "menu_sound::kSysDecide == HOS_MENU_SOUND_SYS_DECIDE" in menu and "menu_sound::kFanfare == HOS_MENU_SOUND_FANFARE" in menu and "menu_sound::kLast + 1 == HOS_MENU_SOUND_N" in menu, "vk_menu.cpp does not hold the Mods entry's sounds (the fanfare, the system menu's cursor and decide) against vk_api.h's") + # ((Triforce, 11-22, N64 Classic) the Remembered page: its own page to the ear, and its two actions' press kept for the sound + check("constexpr int kSoundPageN64 = 10;" in menu, "vk_menu.cpp: the Remembered page has no page of its own to the ear (10)") + state = block(menu, "static menu_sound::State sound_state() {") + check("const bool n64_page = page == 0 && cur_tab == TAB_N64;" in state and + "s.page = motion ? kSoundPageMotion : n64_page ? kSoundPageN64 : page;" in state and + "cur_tab == TAB_N64 ? (int)TAB_GRAPHICS : cur_tab" in state, + "sound_state: the Remembered page is not its own page under Graphics' tab") + check("else if (press[7] && n64_action(r)) n64_act(n64_action(r)), changed = true;" in tick and + "else if (press[7] && is_n64_page_row(r)) cur_tab = TAB_N64," in tick, + "menu_tick: Copy Faithful and Reset to defaults do not keep their press for the sound (decide)") events = (vk / "menu_sound_events.h").read_text(encoding="utf-8") check("if (sound <= kNone || sound > kLast) return false;" in events, "the sounds' queue does not take every sound up to kLast (the Mods entry's are dropped)") diff --git a/tests/test_merged_rows.py b/tests/test_merged_rows.py index fbd5465..4413610 100644 --- a/tests/test_merged_rows.py +++ b/tests/test_merged_rows.py @@ -222,6 +222,7 @@ LOAD = r""" #include "@VK@/framegen_rows.h" #include "@VK@/merged_rows.h" #include "@VK@/ultrawide_rows.h" +#include "@VK@/output_sizes.h" #include "@VK@/replay_threads.h" #include "@VK@/ini_merge.h" #define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); return 1; } } while (0) @@ -247,7 +248,7 @@ constexpr int kRows = sizeof rows / sizeof rows[0]; std::string path; std::string ini_path() { return path; } ini_merge::Map ini_base; -std::string mic_want; +std::string mic_want, gpu_want; std::string mic_key(const char* name) { return name; } void refresh_mics() {} void mic_tell_host() {} @@ -318,7 +319,7 @@ int main(int argc, char** argv) { FILE* w = std::fopen(argv[2], "w"); for (const Row& r : rows) if (ini_row(r)) std::fprintf(w, "%s=%d\n", ini_key(r), *r.value); - std::fprintf(w, "options_version=%d\n", mr7::kVersion); + std::fprintf(w, "options_version=%d\n", OUTPUT_OPTIONS_VERSION); std::fclose(w); } opts = Options{}; @@ -393,10 +394,12 @@ def load_fixture(): stubs = "\n".join("const char* %s(int%s) { return nullptr; }" % (n, ", int" if n.startswith("hn_") else "") for n in names) mod_rows = menu[menu.index("#define MOD_CHEAT_ROW(i)"):menu.index("static_assert(mod_cheat_rows::kSlots")] merged = menu[menu.index("struct Merged {"):menu.index("Row rows[] = {")] - out = menu[menu.index("struct Out {"):menu.index("int step_output_choice(int id, int dir) {")] + out = menu[menu.index("struct Out {"):menu.index("// The connected screens as the host found them")] + out += "\nOut remembered_custom{};\nOut main_screen() { return {2560, 1440}; }\n" + out += definition(menu, "void custom_rows_read") + "\n" + definition(menu, "void read_remembered_custom") init = definition(menu, "void menu_init") reading = block(init, init.index('if (FILE* f = fopen(ini_path().c_str(), "r")) {')) - check("merged_rows::migrate(version, before7, opts.output_res, opts.lstick_dead_zone, opts.rstick_dead_zone);" in reading, + check("merged_rows::migrate(legacy_output && version == 8 ? 7 : version, before7," in reading, "menu_init's reading of the file does not migrate an older one") sync = definition(menu, "void merged_sync") fixture = LOAD @@ -415,7 +418,7 @@ def main(): parser.add_argument("--cxx", default="g++") args = parser.parse_args() menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8") - check('out += "options_version=8\\n";' in definition(menu, "void save"), "save does not write options_version=8") + check('out += "options_version=9\\n";' in definition(menu, "void save"), "save does not write options_version=9") check("for (const char* dropped : merged_rows::kDropped) mine |= key == dropped;" in definition(menu, "void save"), "save writes back the lines of the rows that went") with tempfile.TemporaryDirectory(prefix="merged-rows-") as tmp: diff --git a/tests/test_mods_title_entry.py b/tests/test_mods_title_entry.py index 9314971..62d8455 100644 --- a/tests/test_mods_title_entry.py +++ b/tests/test_mods_title_entry.py @@ -538,7 +538,7 @@ def main(): check("my < e[1] && my > e[1] - (quit_here ? 6 : 4) * e[4]) mods_row_sel = 0, press[1] = true;" in tick, "the mouse moving up off the title's entry does not give the cursor back") check(tick.count("(mods_list_fresh() || mods_title_fading())") == 0 and - menu.count("mods_row = !open && !start && (mods_list_fresh() || mods_title_fading());") == 1 and + menu.count("s.mods_row = !s.open && !s.start && (mods_list_fresh() || mods_title_fading());") == 1 and menu.count("mods_row = !open && (mods_list_fresh() || mods_title_fading());") == 1, "the title's entry is not drawn on while it fades after its list (menu_record, menu_record_image)") diff --git a/tests/test_movie_pace.py b/tests/test_movie_pace.py index 45b8fd2..5e10323 100644 --- a/tests/test_movie_pace.py +++ b/tests/test_movie_pace.py @@ -98,6 +98,7 @@ FIXTURE = r'''#define _CRT_SECURE_NO_WARNINGS #include "step_steady.h" #include "pace_steady.h" #include "movie_pace.h" +#include "n64_pace.h" /* ((Triforce, N64 Classic) pace_fps and movie_pace_decide take its rate: none here (rx_option says 0)) */ static int fails = 0; #define CHECK(x) do { if (!(x)) { printf("FAIL:%d %s\n", __LINE__, #x); fails++; } } while (0) typedef long long LONG64; @@ -124,6 +125,7 @@ int rx_option(int id, int otherwise) { (void)id; return otherwise; } static int steady_row; /* (the options file's steady_frame_rate) */ int hos_ini_option(const char *key, int otherwise) { return strcmp(key, "steady_frame_rate") ? otherwise : steady_row; } enum { HOS_OPT_DISPLAY_CAP = 60 }; +enum { HOS_OPT_N64_FPS = 61 }; static volatile long long presents; volatile uint64_t hos_gfx_module = MOD; volatile int hos_fixed_resolution, hos_dynres_runs; @@ -240,7 +242,8 @@ def main(): vi = (HOST / "nn_vi.c").read_text(encoding="utf-8") check('#include "movie_pace.h"' in vi, "nn_vi.c does not take movie_pace.h") - check("return movie_pace_fps(movie_raise, fps_max());" in block(vi, "static int pace_fps(void) {"), "pace_fps is not the rule's") + check("return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max()));" in block(vi, "static int pace_fps(void) {"), + "pace_fps is not the rule's (N64 Classic's rate over it: tests/test_n64_pace.py)") decide = block(vi, "static void movie_pace_decide(void) {") check('if (on < 0) on = !(getenv("HOS_MOVIE_PACE") && *getenv("HOS_MOVIE_PACE") && atoi(getenv("HOS_MOVIE_PACE")) == 0);' in decide, "HOS_MOVIE_PACE is not read once, on unless 0") @@ -255,7 +258,7 @@ def main(): check("movie_seen();" in block(vi, "uint32_t hos_movie_frames(uint64_t player) {")[:400], "a movie player's update is not noted") presented = block(vi, "void hos_vi_native_presented(void) {") - order = [presented.index(s) for s in ("const int interval = fps_max() < 60 ? 1 : present_interval;", "movie_pace_decide();", + order = [presented.index(s) for s in ("const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval);", "movie_pace_decide();", "const int64_t period = steady_period(1000000000LL / pace_fps() * interval, now);", "pace_period_ns = period;", "realtime_step(now);")] check(order == sorted(order) and presented.count("movie_pace_decide();") == 1, @@ -278,7 +281,8 @@ def main(): movie = vi[vi.index("static volatile LONG64 movie_seen_ns;"):vi.index("static int pace_handed(void) {")] host = "\n".join([block(vi, "static int fps_cap_of("), block(vi, "static int fps_max(void) {"), movie, "static int movie_raise;", - block(vi, "static int pace_fps(void) {"), decide, block(vi, "static float text_scale("), + "static int n64_rate;", block(vi, "static int pace_fps(void) {"), block(vi, "static void n64_pace_decide(void) {"), + decide, block(vi, "static float text_scale("), block(vi, "static int realtime_rate("), step]) with tempfile.TemporaryDirectory(prefix="movie-pace-") as tmp: src, exe = Path(tmp) / "rules.c", Path(tmp) / "rules.exe" diff --git a/tests/test_n64_3d.py b/tests/test_n64_3d.py new file mode 100644 index 0000000..8861c10 --- /dev/null +++ b/tests/test_n64_3d.py @@ -0,0 +1,191 @@ +"""N64 Classic's 3D pass (gpu/vk/shaders/n64_3d.comp; vk_draw.cpp n64_upscale and taau_stand_in) and what steps aside for +it while it draws: DLSS and FSR 4 (vk_temporal.cpp temporal_mode), FSR 3.1 (vk_fsr3.cpp fsr3_wanted) and the game's SMAA +(vk_aa.cpp). Step 2 of n64-classic-mode-plan.md, behind RX_VK_N64 (vk_n64.cpp). No game, no GPU. + +n64_3d_comp_spv.h names the hash of the sources it was compiled from (n64_3d.comp and n64_common.glsl, its first line), +checked against the files as they are, with or without glslang; with glslangValidator of the version the header names, +the rest of the header is the pass compiled now, byte for byte. --write makes the header. + +Read in the sources: the shader includes n64_common.glsl and keeps each channel with it on the grid's own pixels, takes +the square root encoding off the network's input, drops a texel that is not a number, and shows each output pixel from +its grid row whole and a place along it; n64_upscale's push constants are the shader's, in its order, its grid image is +RGBA16F storage made again at a new size, and its two dispatches have a barrier between; taau_stand_in asks n64_3d_now, +hands it to upscale_off.h, looks at the input for the grid's size, draws under the recording lock and still takes the +picture before the HUD; temporal_mode, fsr3_wanted and the Anti-aliasing row's choice ask n64_rules.h with +n64_in_front; vk_n64.cpp reads the switches and leaves a RenoDX run's RGBA16F scene alone; the development guide names +the switches. The rule each of these asks is run by tests/test_n64_rules.py and tests/test_upscale_off.py. + + python -I -B tests/test_n64_3d.py [--glslang glslangValidator] [--write] +""" +import argparse +import hashlib +import re +import shutil +import subprocess +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +VK = ROOT / "gpu" / "vk" +SHADERS = VK / "shaders" +PARTS = ("n64_3d.comp", "n64_common.glsl") +HEADER = SHADERS / "n64_3d_comp_spv.h" +FLAGS = ["-V", "--target-env", "vulkan1.2", "--vn", "N64_3D_COMP_SPV"] + + +def fail(what): + raise SystemExit("FAIL: " + what) + + +def source_line(): + """the header's first line: the hash of the pass's sources (each by its name and its bytes, line ends as LF) and how it is made""" + digest = hashlib.sha256() + for part in PARTS: + digest.update(part.encode() + b"\0" + (SHADERS / part).read_bytes().replace(b"\r\n", b"\n") + b"\0") + return ("// %s sha256 %s (tests/test_n64_3d.py --write: glslangValidator %s)\n" + % (" + ".join(PARTS), digest.hexdigest(), " ".join(FLAGS))).encode() + + +def compiled(glslang, tmp): + out = Path(tmp) / "n64_3d.h" + r = subprocess.run([glslang, *FLAGS, "-o", str(out), str(SHADERS / "n64_3d.comp")], capture_output=True, text=True) + if r.returncode: + fail("n64_3d.comp does not compile:\n%s%s" % (r.stdout, r.stderr)) + return out.read_bytes().replace(b"\r\n", b"\n") + + +def glslang_version(glslang): + got = subprocess.run([glslang, "--version"], capture_output=True, text=True).stdout + m = re.search(r"Glslang Version: \d+:(\d+)\.(\d+)\.(\d+)", got) + return m and "11%02d.%s.%s" % (int(m.group(1)), m.group(2), m.group(3)) + + +def function(src, head): + at = src.index(head) + return src[at:src.index("\n}\n", at)] + + +def in_order(text, parts, what): + at = [text.find(p) for p in parts] + if min(at) < 0 or at != sorted(at): + fail("%s: %s" % (what, [p for p, a in zip(parts, at) if a < 0] or at)) + + +def check_shader(): + comp = (SHADERS / "n64_3d.comp").read_text(encoding="utf-8") + in_order(comp, ['#extension GL_GOOGLE_include_directive : require', '#include "n64_common.glsl"', "void make(ivec2 g)", + "void show(ivec2 o)", "void main()"], "n64_3d.comp no longer includes n64_common.glsl before its two passes") + make = function(comp, "void make(ivec2 g)") + for need in ("for (int j = 0; j < 4; j++)", "for (int i = 0; i < 4; i++)", "vec3 c = s * s;", + "if (any(isnan(c)) || any(isinf(c))) c = vec3(0.0);", "n64_keep(c.r, pc.bits, pc.dither, g.x, g.y)", + "n64_keep(c.g, pc.bits, pc.dither, g.x, g.y)", "n64_keep(c.b, pc.bits, pc.dither, g.x, g.y)", + "imageStore(grid_img, g,"): + if need not in make: + fail("make: %s is gone (16 taps in linear light, no NaN, each channel kept on the grid's own pixel)" % need) + show = function(comp, "void show(ivec2 o)") + for need in ("n64_row(o.y, pc.grid.y, pc.size.y)", "n64_column(o.x, pc.grid.x, pc.size.x)", "imageLoad(grid_img,", + "mix(a, b, t)", "imageStore(dst, o,"): + if need not in show: + fail("show: %s is gone (a grid row whole, linear along it)" % need) + push = re.search(r"layout\(push_constant\) uniform P \{(.*?)\} pc;", comp, re.S) + fields = re.findall(r"^\s*(\w+) (\w+);", push.group(1), re.M) if push else [] + if fields != [("ivec2", "grid"), ("ivec2", "size"), ("int", "pass"), ("int", "bits"), ("float", "dither")]: + fail("n64_3d.comp's push constants are not grid, size, pass, bits, dither: %s" % fields) + for b in ("layout(binding = 0) uniform sampler2D src;", "layout(binding = 1, rgba16f) uniform image2D grid_img;", + "layout(binding = 2, r11f_g11f_b10f) uniform writeonly image2D dst;"): + if b not in comp: + fail("n64_3d.comp: %s is not its binding" % b) + + +def check_draw(): + draw = (VK / "vk_draw.cpp").read_text(encoding="utf-8") + for inc in ('#include "vk_n64.h"', '#include "shaders/n64_3d_comp_spv.h"'): + if inc not in draw: + fail("vk_draw.cpp does not %s" % inc) + up = function(draw, "static bool n64_upscale(") + for need in ("struct Push {\n int32_t grid[2], size[2];\n int32_t pass, bits;\n float dither;\n };", + "mi.codeSize = sizeof N64_3D_COMP_SPV, mi.pCode = N64_3D_COMP_SPV;", + "const VkPushConstantRange pr{VK_SHADER_STAGE_COMPUTE_BIT, 0, (uint32_t)sizeof(Push)};", + "const n64_rules::Grid g = n64_rules::grid(look.lines, ow, oh);", + "ic.format = VK_FORMAT_R16G16B16A16_SFLOAT", "ic.usage = VK_IMAGE_USAGE_STORAGE_BIT", + "if (texture_frame_no() - old[i].frame < 120)", + "Push pc{{(int32_t)g.w, (int32_t)g.h}, {(int32_t)ow, (int32_t)oh}, 0, look.colour_bits, look.dither};", + "descriptors_disturbed();"): + if need not in up: + fail("n64_upscale: %s is gone" % need.split("\n")[0]) + in_order(up, ["vkCmdDispatch(cmd, (g.w + 7) / 8, (g.h + 7) / 8, 1);", 'full_barrier(cmd, "barrier (N64 Classic\'s grid)");', + "pc.pass = 1;", "vkCmdDispatch(cmd, (ow + 7) / 8, (oh + 7) / 8, 1);"], + "n64_upscale: the grid, a barrier, then the picture from it") + stand = function(draw, "bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {") + in_order(stand, ["const bool n64 = n64_3d_now();", "const bool shaped = (off || n64) &&", + "upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped, n64);", + "if (ch.by_shape || ch.n64) {", "ParLock lk;", + "if (ch.n64) done = n64_upscale(cmd, dw().imgs[0].imageView, in, dw().imgs[ntex].imageView, out, level);", + "if (done) hudless_after_dispatch(cmd, p.key);"], + "taau_stand_in no longer asks n64_3d_now, looks at the input, draws N64 Classic's pass under the lock and takes the picture") + + +def check_asides(): + temporal = (VK / "vk_temporal.cpp").read_text(encoding="utf-8") + mode = function(temporal, "int temporal_mode() {") + in_order(mode, ["v = n64_rules::upscaler(n64_in_front(), v);", "if (!ur::is_dlss(v) && !ur::is_fsr4(v)) return ur::GAME;"], + "temporal_mode: DLSS and FSR 4 no longer step aside for N64 Classic's 3D pass, over the switches too") + fsr3 = function((VK / "vk_fsr3.cpp").read_text(encoding="utf-8"), "bool fsr3_wanted() {") + in_order(fsr3, ["if (env == 0) return false;", + "if (n64_rules::upscaler(n64_in_front(), upscaler_rows::FSR3) != upscaler_rows::FSR3) return false;", + "return (env > 0 ||"], "fsr3_wanted: FSR 3.1 no longer steps aside for N64 Classic's 3D pass") + aa = (VK / "vk_aa.cpp").read_text(encoding="utf-8") + choice = function(aa, "int choice_now() {") + if "return env_choice() >= 0 ? choice : n64_rules::anti_aliasing(n64_in_front(), choice);" not in choice: + fail("vk_aa.cpp choice_now: the game's SMAA is no longer left out for N64 Classic's 3D pass, or RX_VK_AA no longer goes over it") + if "const int choice = choice_now();" not in function(aa, "int aa_mode() {") or "bool aa_asked() { return choice_now() != ar::GAME ||" not in aa: + fail("vk_aa.cpp: aa_mode and aa_asked no longer ask choice_now") + n64 = (VK / "vk_n64.cpp").read_text(encoding="utf-8") + for need in ('env_number("RX_VK_N64", -1)', 'env_number("RX_VK_N64_LINES", -1)', 'getenv("RX_VK_N64_LOD")', + 'env_number("RX_VK_N64_TV", -1)', 'env_number("RX_VK_N64_MASK", -1)', 'env_number("RX_VK_N64_FPS", -1)', + "temporal_scene_format(VK_FORMAT_R16G16B16A16_SFLOAT)", "return n64_rules::three_d_runs(l, rgba16f);", + "int n64_in_front() { return n64_3d_now() ? n64_shown() : (int)n64_rules::OFF; }"): + if need not in n64: + fail("vk_n64.cpp: %s is gone" % need) + docs = (ROOT / "docs" / "development.md").read_text(encoding="utf-8") + if "`RX_VK_N64=<0..2>`" not in docs or "`RX_VK_N64_LINES=`" not in docs: + fail("docs/development.md: RX_VK_N64 and the lab's switches are not in the switches table") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--glslang", default=None) + parser.add_argument("--write", action="store_true") + args = parser.parse_args() + glslang = args.glslang or shutil.which("glslangValidator") + if args.write: + if not glslang: + fail("--write needs glslangValidator") + with tempfile.TemporaryDirectory(prefix="n64-3d-") as tmp: + HEADER.write_bytes(source_line() + compiled(glslang, tmp)) + print("wrote %s" % HEADER.relative_to(ROOT)) + check_shader() + check_draw() + check_asides() + if not HEADER.exists(): + fail("n64_3d_comp_spv.h is missing: run with --write") + header = HEADER.read_bytes().replace(b"\r\n", b"\n") + first, _, rest = header.partition(b"\n") + if first + b"\n" != source_line(): + fail("n64_3d_comp_spv.h was not made from n64_3d.comp and n64_common.glsl as they are now: run with --write") + if glslang: + named = rest.split(b"\n", 1)[0].decode("ascii", "replace").strip().lstrip("/ ").strip() + if glslang_version(glslang) == named: + with tempfile.TemporaryDirectory(prefix="n64-3d-") as tmp: + if compiled(glslang, tmp) != rest: + fail("n64_3d_comp_spv.h is not n64_3d.comp compiled: run with --write") + print("(the SPIR-V header is its source compiled, byte for byte)") + else: + print("(glslangValidator is not version %s: the header was not compiled again)" % named) + else: + print("(glslangValidator is not on the PATH: the header's hash was checked, not its bytes)") + print("PASS: N64 Classic's 3D pass, its place in the gameplay upscale, and what steps aside for it") + + +if __name__ == "__main__": + main() diff --git a/tests/test_n64_pace.py b/tests/test_n64_pace.py new file mode 100644 index 0000000..61d0a3f --- /dev/null +++ b/tests/test_n64_pace.py @@ -0,0 +1,198 @@ +"""N64 Classic's frame rate (host/n64_pace.h; host/nn_vi.c n64_pace_decide and pace_fps; gpu/vk/vk_replay.cpp's answer to +HOS_OPT_N64_FPS). Step 7 of n64-classic-mode-plan.md. No game. + +Compiles n64_pace.h alone, as tests/test_movie_pace.py does movie_pace.h: the switch read as HOS_MOVIE_PACE is; the rate +taken only under the cap, at 15 and up, with no movie playing and the switch on; the pace N64 Classic's where it has one, +else the cap's and a movie's; the present's interval 1 at its rate. + +Runs nn_vi.c's own fps_cap_of, fps_max, movie_seen, movie_plays, pace_fps, movie_pace_decide and n64_pace_decide, cut out of +the file, on a clock of its own, with the renderer's answer stood in for: at caps of 60, 45, 120 and 30 and rates of 20, +17, 60, 30, 10 and none, a stretch of play, a movie, play again and the renderer's rate gone; with HOS_N64_PACE=0 too. +At the 60 cap a movie still raises the pace to 240 over N64 Classic's 20, and the 20 is back a quarter second after the +movie's last picture; each change is said once in the log. + +Reads the sources: nn_vi.c takes n64_pace.h, its pace_fps is the rule's over the movie's, movie_pace_decide asks +n64_pace_decide once a present, the present's interval is 1 at the rate, and the vsync event and fps_max still go by the +cap; vk_api.h's HOS_OPT_N64_FPS is a number of its own; vk_replay.cpp answers it with n64_rules.h's rate while the 3D +pass draws; the development guide names HOS_N64_PACE. + + python -I -B tests/test_n64_pace.py [--cc clang] +""" +import argparse +import os +import re +import subprocess +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +HOST = ROOT / "host" +RUN_ALL_ARGS = ["--cc", "clang"] + + +def check(ok, why): + if not ok: + raise SystemExit("FAIL: " + why) + + +def block(source, marker): + """From marker to the first line that starts with a closing brace""" + start = source.index(marker) + return source[start:start + re.search(r"^}", source[start:], re.M).end()] + + +RULES = r""" +#include +#include "n64_pace.h" +static int fails = 0; +#define CHECK(x) do { if (!(x)) { printf("FAIL:%d %s\n", __LINE__, #x); fails++; } } while (0) +int main(void) { + CHECK(n64_pace_on(NULL) && n64_pace_on("") && n64_pace_on("1") && !n64_pace_on("0") && !n64_pace_on("off")); + CHECK(N64_PACE_LOWEST == 15); + /* n64_pace_rate(on, asked, movie, cap) */ + CHECK(n64_pace_rate(1, 20, 0, 60) == 20 && n64_pace_rate(1, 17, 0, 60) == 17 && n64_pace_rate(1, 30, 0, 60) == 30); + CHECK(n64_pace_rate(1, 20, 1, 60) == 0); /* a movie plays */ + CHECK(n64_pace_rate(0, 20, 0, 60) == 0); /* HOS_N64_PACE=0 */ + CHECK(n64_pace_rate(1, 60, 0, 60) == 0 && n64_pace_rate(1, 60, 0, 45) == 0); /* never at or above the cap */ + CHECK(n64_pace_rate(1, 60, 0, 120) == 60 && n64_pace_rate(1, 30, 0, 30) == 0); + CHECK(n64_pace_rate(1, 14, 0, 60) == 0 && n64_pace_rate(1, 15, 0, 60) == 15 && n64_pace_rate(1, 0, 0, 60) == 0); + for (int cap = 30; cap <= 240; cap++) + for (int asked = 0; asked <= 250; asked++) { + const int r = n64_pace_rate(1, asked, 0, cap); + CHECK(r == 0 || (r == asked && r < cap && r >= 15)); /* only ever lower, and the step's to take */ + } + /* n64_pace_fps(rate, paced) */ + CHECK(n64_pace_fps(20, 60) == 20 && n64_pace_fps(0, 240) == 240 && n64_pace_fps(0, 60) == 60 && n64_pace_fps(17, 45) == 17); + /* n64_pace_interval(rate, interval) */ + CHECK(n64_pace_interval(20, 2) == 1 && n64_pace_interval(20, 1) == 1 && n64_pace_interval(0, 2) == 2 && n64_pace_interval(0, 1) == 1); + return fails ? 1 : 0; +} +""" + +FIXTURE = r'''#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include +#include +#include "pace_steady.h" +#include "movie_pace.h" +#include "n64_pace.h" +typedef long long LONG64; +static int64_t clock_ns = 1000000000LL; +int64_t hos_now_ns(void) { return clock_ns; } +static char log_text[1 << 15]; +static void hos_log(const char *fmt, ...) { + va_list ap; + const size_t n = strlen(log_text); + va_start(ap, fmt); + if (n + 600 < sizeof log_text) vsnprintf(log_text + n, 500, fmt, ap), strcat(log_text, "\n"); + va_end(ap); +} +static int logged(const char *text) { + int n = 0; + for (const char *p = log_text; (p = strstr(p, text)) != NULL; p += strlen(text)) n++; + return n; +} +enum { HOS_OPT_DISPLAY_CAP = 60 }; +enum { HOS_OPT_N64_FPS = 61 }; +static int n64_asked; /* (the renderer's answer: vk_replay.cpp, n64_rules.h fps) */ +int rx_option(int id, int otherwise) { return id == HOS_OPT_N64_FPS ? n64_asked : otherwise; } +int hos_ini_option(const char *key, int otherwise) { (void)key; return otherwise; } +static volatile long long presents; +@HOST@ +/* a present: the clock on by a frame, the decision as hos_vi_native_presented takes it */ +static int present(void) { + clock_ns += 16666667; + movie_pace_decide(); + return pace_fps(); +} +int main(int argc, char **argv) { + if (argc < 2) return 2; + n64_asked = atoi(argv[1]); + int play = 0, movie = 0, after = 0, gone = 0; + for (int i = 0; i < 30; i++) play = present(); + for (int i = 0; i < 30; i++) movie_seen(), movie = present(); /* a movie: its player updates every frame */ + clock_ns += 260000000LL; /* a quarter second after its last picture */ + for (int i = 0; i < 30; i++) after = present(); + n64_asked = 0; /* the renderer asks none: N64 Classic off */ + for (int i = 0; i < 30; i++) gone = present(); + printf("%d %d %d %d %d %d %d\n", fps_max(), play, movie, after, gone, logged("vi: N64 Classic: frames paced at "), + logged("vi: N64 Classic: frames paced at the cap again")); + return 0; +} +''' + +# (the cap, by HOS_FPS_MAX; the rate the renderer asks; HOS_N64_PACE) -> the cap, the pace in play, in the movie, after it, +# with the rate gone; the changes said, those back to the cap said +CASES = ( + ((60, 20, None), "60 20 240 20 60 4 2"), # (a movie at the 60 cap: 240 over the 20, and back) + ((60, 17, None), "60 17 240 17 60 4 2"), + ((45, 20, None), "45 20 45 20 45 4 2"), # (no movie raise at 45: the cap's while it plays) + ((120, 60, None), "120 60 120 60 120 4 2"), + ((30, 30, None), "30 30 30 30 30 0 0"), # (at the cap: nothing to lower) + ((60, 10, None), "60 60 240 60 60 0 0"), # (under the step's floor: not taken) + ((60, 0, None), "60 60 240 60 60 0 0"), # (N64 Classic off) + ((60, 20, "0"), "60 60 240 60 60 0 0"), # (HOS_N64_PACE=0) +) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cc", default="clang") + args = parser.parse_args() + vi = (HOST / "nn_vi.c").read_text(encoding="utf-8") + check('#include "n64_pace.h"' in vi, "nn_vi.c does not take n64_pace.h") + check("return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max()));" in block(vi, "static int pace_fps(void) {"), + "pace_fps is not N64 Classic's rate over the cap's and the movie's") + decide = block(vi, "static void movie_pace_decide(void) {") + check(decide.rstrip().endswith("n64_pace_decide(); /* ((Triforce, N64 Classic, step 7) its rate, beside the movie's */\n}"), + "movie_pace_decide does not ask n64_pace_decide once a present, after the movie's decision") + n64 = block(vi, "static void n64_pace_decide(void) {") + for need in ('n64_pace_on(getenv("HOS_N64_PACE"))', "n64_rate = n64_pace_rate(on, on ? rx_option(HOS_OPT_N64_FPS, 0) : 0, movie_plays(), fps_max());"): + check(need in n64, "n64_pace_decide: %s is gone" % need) + presented = block(vi, "void hos_vi_native_presented(void) {") + check("const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval);" in presented and + presented.index("const int interval =") < presented.index("movie_pace_decide();") < presented.index("pace_fps() * interval"), + "the present's interval is not 1 at N64 Classic's rate, or the period is not taken after the decision") + check("1000000000LL / fps_max()" in block(vi, "static DWORD WINAPI vsync_main(void *p) {"), "the vsync event no longer goes by the cap") + api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8") + check("enum { HOS_OPT_N64_FPS = 61 };" in api and "enum { HOS_OPT_DISPLAY_CAP = 60 };" in api, + "vk_api.h: HOS_OPT_N64_FPS is not 61, beside HOS_OPT_DISPLAY_CAP") + taken = [int(v) for v in re.findall(r"HOS_OPT_\w+ = (\d+)", api)] + check(taken.count(61) == 1 and not re.search(r"HOS_OPT_DISPLAY_CAP = 60, ", api), "vk_api.h: another option has 61") + replay = (ROOT / "gpu" / "vk" / "vk_replay.cpp").read_text(encoding="utf-8") + check("if (id == HOS_OPT_N64_FPS) return n64_3d_now() ? n64_rules::fps(n64_look()) : 0;" in replay and '#include "vk_n64.h"' in replay, + "vk_replay.cpp does not answer HOS_OPT_N64_FPS with n64_rules.h's rate while the 3D pass draws") + dev = (ROOT / "docs" / "development.md").read_text(encoding="utf-8") + check("`HOS_N64_PACE=0`" in dev and "`HOS_OPT_N64_FPS`" in dev, "docs/development.md: HOS_N64_PACE and HOS_OPT_N64_FPS are not said") + + movie = vi[vi.index("static volatile LONG64 movie_seen_ns;"):vi.index("static int pace_handed(void) {")] + host = "\n".join([block(vi, "static int fps_cap_of("), block(vi, "static int fps_max(void) {"), movie, "static int movie_raise;", + "static int n64_rate;", block(vi, "static int pace_fps(void) {"), n64, decide]) + with tempfile.TemporaryDirectory(prefix="n64-pace-") as tmp: + src, exe = Path(tmp) / "rules.c", Path(tmp) / "rules.exe" + src.write_text(RULES, encoding="utf-8") + subprocess.run([args.cc, "-std=gnu11", "-O1", "-Wall", "-Wextra", "-Werror", "-I", str(HOST), str(src), "-o", str(exe)], check=True) + r = subprocess.run([str(exe)], capture_output=True, text=True) + check(r.returncode == 0, "the rules:\n" + r.stdout) + src, exe = Path(tmp) / "fixture.c", Path(tmp) / "fixture.exe" + src.write_text(FIXTURE.replace("@HOST@", host), encoding="utf-8") + subprocess.run([args.cc, "-std=gnu11", "-O1", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I", str(HOST), str(src), + "-o", str(exe), "-lm"], check=True) + bad = [] + for (cap, asked, pace_env), expect in CASES: + env = {k: v for k, v in os.environ.items() if not k.startswith(("HOS_", "RX_"))} + env["HOS_FPS_MAX"] = str(cap) + if pace_env is not None: + env["HOS_N64_PACE"] = pace_env + got = subprocess.run([str(exe), str(asked)], capture_output=True, text=True, env=env).stdout.strip() + if got != expect: + bad.append("cap %d, asked %d, HOS_N64_PACE %s: %s, expected %s" % (cap, asked, pace_env, got, expect)) + if bad: + raise SystemExit("FAIL:\n " + "\n ".join(bad)) + print("PASS: N64 Classic's frame rate paces the game under the cap, gives way to movies, and goes with the mode") + + +if __name__ == "__main__": + main() diff --git a/tests/test_n64_row.py b/tests/test_n64_row.py new file mode 100644 index 0000000..b517375 --- /dev/null +++ b/tests/test_n64_row.py @@ -0,0 +1,214 @@ +"""N64 Classic in the Insert menu (gpu/vk/vk_menu.cpp, vk_menu.h; vk_n64.cpp): the Graphics tab's N64 Classic row, the +Remembered page its Remembered settings row opens, F7, and the rows it stands in front of. Step 5 of n64-classic-mode-plan.md. +No game, no GPU. + +Read in the sources: + +- vk_menu.h: the row Off by default, F7's last preset Faithful, the Remembered page's values n64_rules.h's defaults; +- the rows: a heading and the N64 Classic row after the Anti-aliasing row on the Graphics tab, Off to Remembered, taken at + once; Remembered settings, a row with no value; the Remembered page (TAB_N64, a page of its own after the Controls page, + before the hidden rows) with a row for each of n64_rules.h's Rows, the frame rate first under Pace, each from + N64_ROW, which takes its range and step from n64_rules.h kSpec, and Copy Faithful and Reset to defaults; F7's last preset a + hidden row, saved under its name's key, n64_classic_last; +- each row's value names, as many as its range has values; +- the page's values a plain array in Options (n64_rules.h's defaults), so the tests that cut Options out compile it as it + is; ini_key's table of names gives each page row kSpec's key (its saturation is Colour saturation: RenoDX has Saturation); +- row_shown: Remembered settings with Remembered chosen; row_fixed: the Upscaler and the Anti-aliasing while the 3D pass + draws in their place, the row with RX_VK_N64 set, a page row with nothing to do (n64_rules.h row_fixed); the Upscaler and + the Anti-aliasing then say N64 Classic, and the Anti-aliasing's line says why; +- menu_tick: Remembered settings opens its page and Copy Faithful and Reset to defaults act on a press, before a row with no + value opens the Controls page; back and the tab keys leave the page for Graphics, and the Motion page's lines are as they + were; F7 turns the row between Off and the last preset, saves it, says so at the foot of the screen, and does nothing + while RX_VK_N64 is set; +- the page is drawn under Graphics, its actions' guide says Apply and its Back; the tab strip, the sounds and the tab step + take it as Graphics; every slot array has a slot for it; +- vk_n64.cpp: the mode from the row, RX_VK_N64 over it, Remembered's look from the page; +- the readme and the development guide name the row, the page, F7 and the switch. + +The rules themselves (the presets, the page's ranges, the rows with nothing to do, F7) are run by tests/test_n64_rules.py. + + python -I -B tests/test_n64_row.py +""" +import re +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +VK = ROOT / "gpu" / "vk" + + +def fail(what): + raise SystemExit("FAIL: " + what) + + +def check(cond, what): + if not cond: + fail(what) + + +def block(text, head): + at = text.index(head) + end = text.index("{", at) + 1 + depth = 1 + while depth: + depth += (text[end] == "{") - (text[end] == "}") + end += 1 + return text[at:end] + + +def in_order(text, parts, what): + at = [text.find(p) for p in parts] + check(min(at) >= 0 and at == sorted(at), "%s: %s" % (what, [p for p, a in zip(parts, at) if a < 0] or at)) + + +def spec(): + """n64_rules.h's Row names in order and kSpec's (lo, hi, step) for each""" + rules = (VK / "n64_rules.h").read_text(encoding="utf-8") + names = re.search(r"enum Row \{ (.*?), kRows \};", rules).group(1).split(", ") + global defaults, keys + table = re.search(r"constexpr RowSpec kSpec\[kRows\] = \{(.*?)\n\};", rules, re.S).group(1) + entries = re.findall(r'\{"(\w+)", (-?\d+), (-?\d+), (\d+), (-?\d+)\}', table) + check(len(entries) == len(names), "n64_rules.h: kSpec has not one entry for each Row") + defaults = {n: int(e[4]) for n, e in zip(names, entries)} + keys = {n: e[0] for n, e in zip(names, entries)} + return names, {n: (int(e[1]), int(e[2]), int(e[3])) for n, e in zip(names, entries)} + + +def main(): + header = (VK / "vk_menu.h").read_text(encoding="utf-8") + menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8") + n64 = (VK / "vk_n64.cpp").read_text(encoding="utf-8") + names, ranges = spec() + + for need in ("int n64_classic = 0;", "int n64_last = 1;"): + check(need in header, "vk_menu.h: %s is gone (Off by default, F7's Faithful)" % need) + # (the page's values a plain array, so the tests that cut Options out compile it as it is: n64_rules.h's defaults) + arr = re.search(r"int n64_rem\[(\d+)\] = \{([^}]*)\};", header) + check(arr and int(arr.group(1)) == len(names) and [int(v) for v in arr.group(2).split(",")] == [defaults[n] for n in names], + "vk_menu.h: Options's n64_rem is not n64_rules.h kSpec's defaults, one for each Row") + + # ---- the rows ---- + check("TAB_N64 = TAB_PAGE + 1," in menu and "TAB_HIDDEN = TAB_N64 + 1" in menu, + "TAB_N64 is not a page of its own after the Controls page and before the hidden rows") + in_order(menu, ['MENU_HEADING(TAB_GRAPHICS, "Anti-aliasing"),', 'MENU_HEADING(TAB_GRAPHICS, "N64 Classic"),', + '{TAB_GRAPHICS, "N64 Classic", &opts.n64_classic, 0, n64_rules::kPresets - 1, 1, tx_n64,', + '{TAB_GRAPHICS, "Remembered settings", nullptr, 0, 0, 0, nullptr,', + 'MENU_HEADING(TAB_GRAPHICS, "Frame generation"),'], + "the N64 Classic row and Remembered settings are not after the Anti-aliasing on the Graphics tab") + row = menu[menu.index('{TAB_GRAPHICS, "N64 Classic", &opts.n64_classic'):] + row = row[:row.index("},") + 2] + check("hn_n64, false, true}," in row and "F7" in row and "Changes at once" in row, + "the N64 Classic row: its help says F7 and at once, its hint is hn_n64, it takes no restart") + macro = menu[menu.index("#define N64_ROW(row, title, text, help)"):] + macro = macro[:macro.index("false, true}") + 12] + for part in ("{TAB_N64, title, &opts.n64_rem[n64_rules::row],", "n64_rules::kSpec[n64_rules::row].lo", + "n64_rules::kSpec[n64_rules::row].hi", "n64_rules::kSpec[n64_rules::row].step", "text, help, nullptr, false, true}"): + check(part in macro, "N64_ROW no longer takes %s" % part) + page = re.findall(r"N64_ROW\((\w+), \"([^\"]+)\", (\w+),", menu) + check([p[0] for p in page] == names, "the Remembered page's rows are not n64_rules.h's Rows, in order: %s" % [p[0] for p in page]) + in_order(menu, ['MENU_HEADING(TAB_N64, "Pace"),', 'N64_ROW(FPS, "Frame rate", tx_n64_fps,', 'MENU_HEADING(TAB_N64, "The 3D"),'], + "the Remembered page does not open with its Pace, the frame rate") + for need in ('{TAB_N64, "Copy Faithful", nullptr, 0, 0, 0, nullptr,', '{TAB_N64, "Reset to defaults", nullptr, 0, 0, 0, nullptr,', + '{TAB_HIDDEN, "N64 Classic last", &opts.n64_last, n64_rules::FAITHFUL, n64_rules::REMEMBERED, 1, nullptr, nullptr},'): + check(need in menu, "the rows: %s is gone" % need) + # (each value's name: as many as its range has values) + for row_name, title, text in page: + lo, hi, step = ranges[row_name] + if text in ("tx_percent", "tx_onoff"): + continue + fn = block(menu, "const char* %s(int v) {" % text) + if text == "tx_n64_blur": + check('if (v <= 0) return "Off";' in fn and "v * n64_rules::kBlurStep" in fn, "Texture blur's names are not Off, then +0.5 a step") + continue + count = len(re.findall(r'"[^"]*"', fn.split("};")[0])) + check(count == (hi - lo) // step + 1 and "std::clamp(v, 0, %d)" % hi in fn, + "%s has %d names for %d values" % (text, count, (hi - lo) // step + 1)) + check(ranges["TV"] == (0, 1, 1) and ranges["SCANLINES"][2] == 5 and ranges["SATURATION"] == (50, 150, 5), + "a page row named by tx_onoff or tx_percent no longer has the range those names suit") + + # ---- the saved keys, shown, fixed ---- + key = block(menu, "const char* ini_key(const Row& r) {") + kept = dict(re.findall(r'\{"([^"]+)", "([^"]+)"\}', key[:key.index("for (const auto& k : kept)")])) + for row_name, title, _ in page: + check(kept.get(title) == keys[row_name], "ini_key: the page's %s is not saved under %s" % (title, keys[row_name])) + check(sum(1 for t in kept if t in [p[1] for p in page]) == len(page) and "Saturation" not in [p[1] for p in page], + "ini_key: a page row's name is another row's (RenoDX has Saturation)") + check("return value && value >= first && value < first + n64_rules::kRows ? (int)(value - first) : -1;" in block(menu, "int n64_rem_row(const int* value) {"), + "n64_rem_row is not the place of a value among opts.n64_rem's") + shown = block(menu, "bool row_shown(int i) {") + check("(!is_n64_page_row(rows[i]) || n64_preset() == n64_rules::REMEMBERED) &&" in shown, + "row_shown: Remembered settings is not shown with Remembered alone") + fixed = block(menu, "bool row_fixed(const int* value) {") + for need in ("((value == &opts.dlss || value == &opts.aa) && n64_in_front() != n64_rules::OFF)", + "(value == &opts.n64_classic && n64_env_set())", + "(n64_rem_row(value) >= 0 && n64_rules::row_fixed(n64_rules::rows_of(opts.n64_rem), n64_rem_row(value)))"): + check(need in fixed, "row_fixed: %s is gone" % need) + for fn in ("const char* tx_upscaler(int) {", "const char* tx_aa(int v) {"): + body = block(menu, fn) + check(body.split("{", 1)[1].lstrip().startswith('if (n64_in_front() != n64_rules::OFF) return "N64 Classic";'), + "%s does not say N64 Classic while its 3D pass draws" % fn) + hint = block(menu, "const char* hn_aa(int v, int variant) {") + check("variant = n64_in_front() != n64_rules::OFF ? 5 :" in hint and "case 5: return n64;" in hint, + "the Anti-aliasing's line does not say N64 Classic smooths the edges") + check("return t[v >= 0 && v < n64_rules::kPresets ? v : 0];" in block(menu, "const char* hn_n64(int v, int variant) {") and + "return n64_rules::name(n64_env_set() ? n64_preset() : v);" in block(menu, "const char* tx_n64(int v) {"), + "the N64 Classic row's text or line is not its value's, RX_VK_N64's over it") + act = block(menu, "void n64_act(int action) {") + check("const n64_rules::Rows to = action == 1 ? n64_rules::kFaithful : n64_rules::defaults();" in act and + "std::copy(std::begin(to.v), std::end(to.v), opts.n64_rem);" in act and "save();" in act, + "Copy Faithful and Reset to defaults do not set the page from Faithful or the defaults, and save") + + # ---- the keys ---- + tick = block(menu, "void menu_tick() {") + in_order(tick, ["else if (press[7] && is_motion_row(r)) cur_tab = TAB_MOTION", + "else if (press[7] && is_n64_page_row(r)) cur_tab = TAB_N64, tab_selected[TAB_N64] = 0, press[7] = false, changed = true;", + "else if (press[7] && n64_action(r)) n64_act(n64_action(r)), changed = true;", # ((11-22) its press the sound's) + "else if (press[7] && !r.value && can_bind()) page = 1"], + "menu_tick: Remembered settings and the page's actions are not taken before a row with no value opens the Controls page") + for need in ("if (press[5] && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS, press[5] = false, changed = true;", + "else if (press[5] && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS, press[5] = false, changed = true;", + "if ((tab_left || tab_right) && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS;", + "if (press[5] && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS, press[5] = false, changed = true;", + "if ((tab_left || tab_right) && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS;"): + check(need in tick, "menu_tick: %s is gone" % need) + f7 = tick[tick.index("static bool f7_held = false;"):tick.index("f7_held = f7_down;")] + in_order(f7, ["opts.n64_last = opts.n64_classic;", "const bool f7_down = mine && (GetAsyncKeyState(VK_F7) & 0x8000) != 0;", + "if (f7_down && !f7_held && !n64_env_set()) {", "toggle.last = opts.n64_last;", + "opts.n64_classic = toggle.pressed(opts.n64_classic);", "opts.n64_last = toggle.last;", "save();", + 'snprintf(notice_text, sizeof notice_text, "N64 Classic: %s", n64_rules::name(opts.n64_classic));'], + "F7: the last preset kept, a press turns the row (not with RX_VK_N64), saves it and says so") + + # ---- the page drawn, its slots ---- + check("draw_tabs(c, cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab == TAB_N64 ? TAB_GRAPHICS : cur_tab, embed_open, true);" in menu, + "the Remembered page is not drawn under Graphics") + check('if (n64_action(selr)) prompt_list[0] = {ui::kConfirm, "Apply"};' in menu and + 'if (cur_tab == TAB_N64) prompt_list[1] = {ui::kBack, "Back"}, prompts_n = 2;' in menu, + "the Remembered page's guides do not say Apply and Back") + check("s.tab = motion ? (int)TAB_CONTROLS : cur_tab == TAB_N64 ? (int)TAB_GRAPHICS : cur_tab;" in menu and + "cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab == TAB_N64 ? TAB_GRAPHICS : cur_tab;" in block(menu, "void tab_move(int dir) {"), + "the sounds or the tab step do not take the Remembered page as Graphics") + for arr in ("int tab_selected[TAB_N64 + 1]", "float scroll_at[TAB_N64 + 1];", "int wheel_rows[TAB_N64 + 1];", + "int scrolled_to[TAB_N64 + 1] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};", "float scroll_want[TAB_N64 + 1];", + 'static_assert(TAB_N64 + 1 == 9,'): + check(arr in menu, "a slot array has no slot for the Remembered page: %s" % arr) + + # ---- vk_n64.cpp, the readme, the guide ---- + # ((step 8) the look is the preset shown, which follows the row through the TV's switch, and is the row's before a present) + for need in ("int n64_preset() { return n64_rules::chosen(opts.n64_classic, env_n64()); }", "bool n64_env_set() { return env_n64() >= 0; }", + "n64_rules::look_of(n64_shown(), n64_rules::rows_of(opts.n64_rem))", "return s >= 0 ? s : n64_preset();", + '#include "vk_menu.h"'): + check(need in n64, "vk_n64.cpp: %s is gone" % need) + readme = (ROOT / "readme.md").read_text(encoding="utf-8") + entry = readme[readme.index("| N64 Classic |"):] + entry = entry[:entry.index("\n")] + for need in ("Off, Faithful, Remembered", "**F7**", "**Remembered settings**", "at 20 frames a second", "Frame rate (Frame rate cap", + "Colour saturation", "Copy Faithful", + "Reset to defaults", "`RX_VK_N64=0`"): + check(need in entry, "readme.md: the N64 Classic row does not say %s" % need) + check("Upscaling, Anti-aliasing, N64 Classic, Frame generation" in readme, "readme.md: the Graphics tab's groups leave N64 Classic out") + docs = (ROOT / "docs" / "development.md").read_text(encoding="utf-8") + check("over the Insert menu's N64 Classic row and its Remembered page" in docs, "docs/development.md: RX_VK_N64 is not said to go over the row") + print("PASS: N64 Classic's row, the Remembered page, F7, and the rows it stands in front of") + + +if __name__ == "__main__": + main() diff --git a/tests/test_n64_rules.py b/tests/test_n64_rules.py new file mode 100644 index 0000000..cf2c09d --- /dev/null +++ b/tests/test_n64_rules.py @@ -0,0 +1,469 @@ +"""N64 Classic's rules (gpu/vk/n64_rules.h) and its 3D pass's per-pixel maths (gpu/vk/shaders/n64_common.glsl). No game, +no GPU. Step 1 of n64-classic-mode-plan.md: nothing in the renderer calls them yet. + +Compiled and run: + +- the N64 Classic row (Off, Faithful, Remembered) and RX_VK_N64 over it; +- the Remembered page's rows: their keys (unique, n64_rem_), ranges, steps and defaults, a saved value brought back to its + row, the rows shown fixed while they have nothing to do (Dither with full colour, the TV's rows with the TV off, Mask + strength with no mask); +- the looks: Faithful's fixed values (20 frames a second, 240 lines, 15-bit colour with the full dither, +2.5 texture + blur, the TV), Remembered's defaults, Faithful ignoring the page, Copy Faithful giving Remembered exactly Faithful's + look, Reset giving the defaults, the lab's switches over either; +- the 3D grid's size for the host's 4:3, 16:9 and 21:9 pictures; the TV's colour bleed in the picture's widths by its + shape; the texture blur under a card's limit, and the draws + that are the scene for it (a scene's size and shape for the picture: the dynamic resolution's sizes, not the shadow maps, + the HUD or a quarter-size buffer); the scanlines' strength and the mask's Auto by the picture's height on the screen; +- what the mode stands in front of while it is on (the Upscaler, the Anti-aliasing, Sharpness) and when each pass runs + (no 3D pass on RenoDX's RGBA16F scene, no TV on HDR Native's PQ picture or under DLSS frame generation); +- the frame rate the host is told and the rate the frames are then paced by under every cap; +- F7 between Off and the last preset, and the TV's half-second switch with the change at its middle: the preset shown + through a switch (none at a start, a new choice while it closes, another after the middle, at once where none can be + drawn), and the TV pass drawing it over any look; +- n64_common.glsl, compiled as C++ over a small GLSL stand-in (it is written in what the two share, as aa_common.glsl is): + the 4 x 4 Bayer cell is each of 0 to 15 once, its thresholds centred; every level of 5 and 6 bits comes back exactly at + any dither strength; a value between levels averages to itself over a cell; the output is always a level, inside 0..1; + and for step 2's pass (shaders/n64_3d.comp): the sRGB curve both ways, a channel kept at 15-bit colour on a display + level (white, HDR's highlights and full colour as they are, below black and NaN black), every grid row in order with 4 + to 6 output rows each, and the column's place along a line. + +With glslangValidator on the PATH, n64_common.glsl also compiles as GLSL inside a stand-in compute shader. + + python -I -B tests/test_n64_rules.py [--cxx clang++] +""" +import argparse +import re +import shutil +import subprocess +import tempfile +from pathlib import Path + +RUN_ALL_ARGS = ["--cxx", "{cxx}"] + +ROOT = Path(__file__).resolve().parents[1] +VK = ROOT / "gpu" / "vk" +SHADERS = VK / "shaders" + +DRIVER = r''' +#include "n64_rules.h" + +#include +#include +#include +#include + +// (just enough of GLSL for n64_common.glsl, in a namespace of its own) +namespace glsl { +static float floor(float a) { return std::floor(a); } +static float clamp(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; } +#include "shaders/n64_common.glsl" +} // namespace glsl + +using namespace mkwvk::n64_rules; +namespace ur = mkwvk::upscaler_rows; +namespace ar = mkwvk::aa_rows; + +static int checks, fails; +static void want(bool ok, const char* what) { + checks++; + if (!ok) fails++, std::printf("FAIL %s\n", what); +} +static bool near(float a, float b, float eps = 1e-6f) { return std::fabs(a - b) <= eps; } + +static void row_and_rows() { + want(chosen(0, -1) == OFF && chosen(1, -1) == FAITHFUL && chosen(2, -1) == REMEMBERED, "the row's own values"); + want(chosen(7, -1) == OFF && chosen(-3, -1) == OFF, "a value past the row is Off"); + want(chosen(0, 2) == REMEMBERED && chosen(2, 0) == OFF && chosen(1, 9) == OFF, "RX_VK_N64 over the row"); + want(!std::strcmp(name(OFF), "Off") && !std::strcmp(name(FAITHFUL), "Faithful") && + !std::strcmp(name(REMEMBERED), "Remembered") && !std::strcmp(name(5), "Off"), "the row's names"); + + bool keys = true; + for (int i = 0; i < kRows; i++) { + if (std::strncmp(kSpec[i].key, "n64_rem_", 8)) keys = false; + for (int j = 0; j < i; j++) + if (!std::strcmp(kSpec[i].key, kSpec[j].key)) keys = false; + const RowSpec& s = kSpec[i]; + if (s.lo > s.hi || s.step <= 0 || s.def < s.lo || s.def > s.hi || (s.def - s.lo) % s.step || (s.hi - s.lo) % s.step) + keys = false; + } + want(keys, "each row's key is its own and n64_rem_, its default on its steps inside its range"); + want(std::strncmp(kLastKey, "n64_rem_", 8) != 0, "F7's last preset has a key of its own"); + + const Rows d = defaults(); + bool defs = true; + for (int i = 0; i < kRows; i++) defs &= d.v[i] == kSpec[i].def; + want(defs, "Reset: every row at its default"); + const Rows f = clamped(kFaithful); + bool on_rows = true; + for (int i = 0; i < kRows; i++) on_rows &= f.v[i] == kFaithful.v[i]; + want(on_rows, "Faithful's values are values the page's rows can hold (Copy Faithful copies them as they are)"); + + want(clamp_row(FPS, 9) == 4 && clamp_row(FPS, -2) == 0, "the frame rate brought back to its row"); + want(clamp_row(SCANLINES, 37) == 35 && clamp_row(SCANLINES, 200) == 80 && clamp_row(SCANLINES, -5) == 0, + "scanlines: on a step of 5, inside 0..80"); + want(clamp_row(MASK_STRENGTH, 0) == 5 && clamp_row(SATURATION, 151) == 150 && clamp_row(SATURATION, 52) == 50, + "mask strength and saturation inside their rows, on their steps"); + want(clamp_row(-1, 3) == 0 && clamp_row(kRows, 3) == 0, "no row: 0"); + Rows wild{}; + for (int i = 0; i < kRows; i++) wild.v[i] = 999; + const Look w = look_of(REMEMBERED, wild); + want(w.on && w.fps == 17 && w.lines == 720 && w.colour_bits == 0 && near(w.lod_bias, 3.0f) && w.tv && + near(w.scanlines, 0.8f) && w.mask == MASK_SHADOW && near(w.saturation, 1.5f), + "a file's values past every row: each row's last value, nothing read past a table"); + + Rows r = d; + want(row_fixed(r, DITHER), "Dither fixed while Colour is Full"); + r.v[COLOUR] = 0; + want(!row_fixed(r, DITHER), "Dither changeable with 15-bit colour"); + r.v[TV] = 0; + bool tv_rows = true; + for (int i = SCANLINES; i <= SATURATION; i++) tv_rows &= row_fixed(r, i); + want(tv_rows, "the TV's rows fixed while CRT TV is off"); + want(!row_fixed(r, FPS) && !row_fixed(r, LINES) && !row_fixed(r, COLOUR) && !row_fixed(r, BLUR) && !row_fixed(r, TV), + "the frame rate, the 3D's rows and CRT TV itself never fixed"); + r.v[TV] = 1, r.v[MASK] = MASK_OFF; + want(row_fixed(r, MASK_STRENGTH) && !row_fixed(r, MASK), "Mask strength fixed with no mask"); +} + +static void looks() { + const Look f = look_of(FAITHFUL, defaults()); + want(f.on && f.fps == 20 && f.lines == 240 && f.colour_bits == 5 && near(f.dither, 1.0f) && near(f.lod_bias, 2.5f), + "Faithful's 3D: 20 frames a second, 240 lines, 15-bit colour, the full dither, +2.5 blur"); + want(f.tv && near(f.scanlines, 0.6f) && f.mask == MASK_AUTO && near(f.mask_strength, 0.3f) && near(f.bleed, 3.0f) && + near(f.glow, 0.1f) && near(f.curvature, 0.03f) && near(f.saturation, 1.0f), + "Faithful's TV: 60% scanlines, Auto's mask at 30%, a composite cable's bleed, 10% glow, curved, the game's colour"); + const Look m = look_of(REMEMBERED, defaults()); + want(m.on && m.fps == 0 && m.lines == 480 && m.colour_bits == 0 && m.dither == 0.0f && near(m.lod_bias, 1.5f), + "Remembered's 3D: the cap's rate, 480 lines, full colour, no dither, +1.5 blur"); + want(m.tv && near(m.scanlines, 0.35f) && m.mask == MASK_AUTO && near(m.mask_strength, 0.15f) && near(m.bleed, 1.5f) && + near(m.glow, 0.25f) && near(m.curvature, 0.015f) && near(m.saturation, 1.1f), "Remembered's TV defaults"); + + Rows odd = defaults(); + odd.v[FPS] = 1, odd.v[LINES] = 3, odd.v[TV] = 0, odd.v[BLUR] = 0; + want(same(look_of(FAITHFUL, odd), f), "Faithful ignores the Remembered page"); + want(!same(look_of(REMEMBERED, odd), m), "Remembered follows its page"); + Rows copied = kFaithful; // (Copy Faithful) + want(same(look_of(REMEMBERED, copied), f), "after Copy Faithful, Remembered looks exactly as Faithful does, rate and all"); + want(same(look_of(REMEMBERED, defaults()), m), "after Reset, Remembered's defaults"); + + Rows full = defaults(); + full.v[COLOUR] = 2, full.v[DITHER] = 2; + want(look_of(REMEMBERED, full).dither == 0.0f, "full colour: no dither, whatever the Dither row holds"); + Rows notv = defaults(); + notv.v[TV] = 0; + const Look n = look_of(REMEMBERED, notv); + want(!n.tv && n.scanlines == 0.0f && n.mask == MASK_OFF && n.mask_strength == 0.0f && n.bleed == 0.0f && n.glow == 0.0f && + n.curvature == 0.0f && n.saturation == 1.0f && n.lines == 480 && near(n.lod_bias, 1.5f), + "CRT TV off: none of the TV, the 3D as it was"); + const Look off = look_of(OFF, defaults()); + want(!off.on && fps(off) == 0 && lod_bias(off, 16.0f) == 0.0f && !three_d_runs(off, false) && !tv_runs(off, false, false), + "Off: nothing at all"); + + Env e; + want(same(with_env(f, e), f), "no switch set: the look as it is"); + e.lines = 360, e.tv = 0, e.fps = 0, e.lod = 0.0f, e.mask = MASK_APERTURE; + const Look fe = with_env(f, e); + want(fe.lines == 360 && !fe.tv && fe.fps == 0 && fe.lod_bias == 0.0f && fe.mask == MASK_APERTURE, + "the lab's switches over Faithful's fixed look"); + want(!with_env(off, e).on, "the switches do not turn the mode on"); +} + +static void grid_and_screen() { + const auto is = [](Grid g, uint32_t w, uint32_t h) { return g.w == w && g.h == h; }; + want(is(grid(240, 1920, 1440), 320, 240), "4:3 at 240 lines: 320 x 240"); + want(is(grid(240, 2560, 1440), 427, 240) && is(grid(240, 2048, 1152), 427, 240), "16:9 at 240 lines: 427 x 240"); + want(is(grid(240, 3416, 1440), 569, 240), "the host's 21:9 picture (3416 x 1440) at 240 lines: 569 x 240"); + want(is(grid(480, 1920, 1440), 640, 480) && is(grid(480, 2560, 1440), 853, 480) && is(grid(480, 3416, 1440), 1139, 480), + "480 lines: 640, 853, 1139"); + want(is(grid(720, 1280, 400), 1280, 400), "never more lines than the picture"); + want(is(grid(240, 0, 1440), 0, 0) && is(grid(0, 2560, 1440), 0, 0) && is(grid(240, 2560, 0), 0, 0), "a size not known: none"); + + const Look f = look_of(FAITHFUL, defaults()); + want(near(lod_bias(f, 16.0f), 2.5f) && near(lod_bias(f, 2.0f), 2.0f) && lod_bias(f, 0.0f) == 0.0f, + "the blur under the card's limit (Vulkan's least, 2, cuts Faithful's 2.5)"); + want(near(scanline_strength(0.6f, 1440), 0.6f) && near(scanline_strength(0.6f, 2160), 0.6f), "1440 and 2160: full"); + want(near(scanline_strength(0.6f, 720), 0.6f) && near(scanline_strength(0.6f, 800), 0.6f), + "the Steam Deck's 720 and 800: 3 a line and more, full"); + want(near(scanline_strength(0.6f, 600), 0.3f) && scanline_strength(0.6f, 360) == 0.0f && scanline_strength(0.6f, 0) == 0.0f, + "2.5 pixels a line: half; 1.5: none"); + want(mask_shown(MASK_AUTO, 800) == MASK_OFF && mask_shown(MASK_AUTO, 1080) == MASK_OFF, "Auto: no mask at 800 or 1080"); + want(mask_shown(MASK_AUTO, 1440) == MASK_SLOT && mask_shown(MASK_AUTO, 2160) == MASK_SLOT, "Auto: the slot mask at 1440 and up"); + want(mask_shown(MASK_APERTURE, 800) == MASK_APERTURE && mask_shown(MASK_SHADOW, 1080) == MASK_SHADOW, + "a picked mask on any screen"); + want(mask_shown(MASK_OFF, 2160) == MASK_OFF && mask_shown(9, 2160) == MASK_OFF, "Off and a value past the row: none"); + + // (step 4) the colour bleed in the picture's widths: a pixel of the 240-line grid, 1/427 of a 16:9 picture, 1/320 of 4:3 + want(near(tv_bleed_uv(3.0f, 1920, 1440), 3.0f / 320.0f) && near(tv_bleed_uv(3.0f, 2560, 1440), 3.0f * 1440.0f / (240.0f * 2560.0f)) && + near(tv_bleed_uv(1.5f, 3416, 1440), 1.5f * 1440.0f / (240.0f * 3416.0f)), "the bleed in the picture's widths, by its shape"); + want(tv_bleed_uv(0.0f, 2560, 1440) == 0.0f && tv_bleed_uv(3.0f, 0, 1440) == 0.0f && tv_bleed_uv(3.0f, 2560, 0) == 0.0f, + "no bleed, or a size not known: none"); + + // (step 3) the draws that are the scene for the texture blur, by their size and shape for the picture the pass drew + want(scene_draw(1536, 864, 2048, 1152) && scene_draw(2048, 1152, 2560, 1440) && scene_draw(1707, 960, 2560, 1440), + "the game's dynamic resolution's sizes for the picture: the scene"); + want(scene_draw(854, 480, 2560, 1440), "a third of the picture (Ultra Performance's share): the scene"); + want(scene_draw(1440, 1080, 1920, 1440) && scene_draw(2560, 1080, 3416, 1440), "the host's 4:3 and 21:9 pictures' scenes"); + want(!scene_draw(2560, 1440, 2560, 1440), "the picture's own size (the HUD, the output's passes): not the scene"); + want(!scene_draw(1024, 1024, 2560, 1440) && !scene_draw(2048, 2048, 2560, 1440) && !scene_draw(1024, 1024, 1920, 1440), + "square shadow maps: not the scene, at 16:9 or at 4:3"); + want(!scene_draw(640, 360, 2560, 1440), "a quarter of the picture, past a third: not the scene"); + want(!scene_draw(1280, 540, 2560, 1440), "half its width, another shape: not the scene"); + want(!scene_draw(2600, 1440, 2560, 1440), "wider than the picture: not the scene"); + want(!scene_draw(1536, 864, 0, 0) && !scene_draw(0, 864, 2048, 1152), "a size not known: not the scene"); +} + +static void in_front_and_passes() { + want(upscaler(FAITHFUL, ur::DLSS) == ur::GAME && upscaler(REMEMBERED, ur::FSR4_AA) == ur::GAME && + upscaler(OFF, ur::DLSS) == ur::DLSS, "DLSS and FSR step aside while the mode is on, and only then"); + want(anti_aliasing(FAITHFUL, ar::SMAA) == ar::OFF && anti_aliasing(OFF, ar::FXAA) == ar::FXAA, + "the game's SMAA left out while the mode is on"); + want(sharpness(REMEMBERED, 50) == 0 && sharpness(OFF, 50) == 50, "no window Sharpness while the mode is on"); + want(fixes_rows(FAITHFUL) && fixes_rows(REMEMBERED) && !fixes_rows(OFF), "the overridden rows fixed while it is on"); + const Look f = look_of(FAITHFUL, defaults()); + want(three_d_runs(f, false) && !three_d_runs(f, true), "the 3D pass: not on RenoDX's RGBA16F scene"); + want(tv_runs(f, false, false) && !tv_runs(f, true, false) && !tv_runs(f, false, true), + "the TV: not on HDR Native's PQ picture, not under DLSS frame generation"); + Rows notv = defaults(); + notv.v[TV] = 0; + want(!tv_runs(look_of(REMEMBERED, notv), false, false) && three_d_runs(look_of(REMEMBERED, notv), false), + "CRT TV off: the 3D pass alone"); +} + +static void frame_rate() { + const Look f = look_of(FAITHFUL, defaults()); + bool twenty = true; + for (int cap : {30, 40, 45, 60, 90, 120, 144, 165, 240}) twenty &= paced(fps(f), cap) == 20; + want(fps(f) == 20 && twenty, "Faithful: 20 under every cap the game offers"); + const Look m = look_of(REMEMBERED, defaults()); + want(fps(m) == 0 && paced(fps(m), 60) == 60 && paced(fps(m), 144) == 144, "Remembered's default: the cap's own rate"); + Rows r = defaults(); + r.v[FPS] = 1; // (60) + want(paced(fps(look_of(REMEMBERED, r)), 45) == 45 && paced(fps(look_of(REMEMBERED, r)), 120) == 60, + "a Remembered 60: 45 under a cap of 45, 60 under 120"); + r.v[FPS] = 4; + want(fps(look_of(REMEMBERED, r)) == 17 && paced(17, 60) == 17, "17, the cartridge on a 50 Hz TV"); + r.v[FPS] = 2; + want(fps(look_of(REMEMBERED, r)) == 30, "30"); + want(paced(fps(look_of(OFF, defaults())), 60) == 60, "Off: the cap's"); +} + +static void toggle_and_anim() { + Toggle t; + want(t.pressed(OFF) == FAITHFUL, "F7 from Off the first time: Faithful"); + want(t.pressed(FAITHFUL) == OFF, "F7 with a preset on: Off"); + t.noted(REMEMBERED); + want(t.pressed(OFF) == REMEMBERED, "F7 from Off: the last preset chosen on the row"); + want(t.pressed(REMEMBERED) == OFF && t.pressed(OFF) == REMEMBERED, "and back again"); + t.noted(OFF); + want(t.last == REMEMBERED, "Off chosen on the row is no preset to come back to"); + + want(anim(-0.1f).done && !anim(-0.1f).after, "before a switch: the picture as it is"); + const AnimFrame start = anim(0.0f), end = anim(kAnimSeconds); + want(!start.done && near(start.scale_x, 1.0f) && near(start.scale_y, 1.0f) && start.flash == 0.0f && !start.after, + "the switch starts from the whole picture"); + want(end.done && end.after && near(end.scale_x, 1.0f) && near(end.scale_y, 1.0f) && end.flash == 0.0f, + "and is over at half a second, with the new look whole"); + want(!anim(kAnimSeconds / 2 - 0.001f).after && anim(kAnimSeconds / 2).after, "the new look from the middle on"); + const AnimFrame mid = anim(kAnimSeconds / 2); + want(near(mid.scale_x, kAnimDot) && near(mid.scale_y, kAnimLine) && near(mid.flash, 1.0f), "a bright dot at the middle"); + bool closing = true, opening = true; + AnimFrame prev = start; + for (int i = 1; i <= 100; i++) { + const AnimFrame a = anim(kAnimSeconds / 2 * i / 100.0f); + closing &= a.scale_y <= prev.scale_y + 1e-6f && a.scale_x <= prev.scale_x + 1e-6f; + prev = a; + } + for (int i = 1; i <= 100; i++) { + const AnimFrame a = anim(kAnimSeconds / 2 + kAnimSeconds / 2 * i / 100.0f); + opening &= a.scale_y + 1e-6f >= prev.scale_y && a.scale_x + 1e-6f >= prev.scale_x; + prev = a; + } + want(closing && opening, "it closes to the dot, then opens from it, never back and forth"); + + // (step 8) the switch, once a present: the preset shown, and the TV's frame of it + Switch sw; + Switch::Now n = sw.at(10.0, FAITHFUL, true); + want(n.shown == FAITHFUL && n.frame.done, "the first present: the preset as it is, no switch (a start does not switch the TV on)"); + want(sw.at(10.1, FAITHFUL, true).frame.done, "nothing chosen anew: nothing runs"); + n = sw.at(11.0, OFF, true); + want(n.shown == FAITHFUL && !n.frame.done && !n.frame.after, "F7 off: the switch begins, Faithful still shown"); + want(sw.at(11.2, OFF, true).shown == FAITHFUL && sw.at(11.25, OFF, true).shown == OFF, "Off from the middle on"); + n = sw.at(11.5, OFF, true); + want(n.shown == OFF && n.frame.done, "over at half a second: Off, nothing running"); + sw.at(12.0, REMEMBERED, true); + n = sw.at(12.1, FAITHFUL, true); + want(n.shown == OFF && !n.frame.done && sw.to == FAITHFUL && sw.t0 == 12.0, + "a new choice while the picture still closes: what opens instead, the same switch"); + want(sw.at(12.3, FAITHFUL, true).shown == FAITHFUL, "and it opens on it"); + n = sw.at(12.4, REMEMBERED, true); + want(n.shown == FAITHFUL && sw.from == FAITHFUL && sw.to == REMEMBERED && sw.t0 == 12.4, + "a new choice after the middle: a new switch from what is shown"); + want(sw.at(12.9, REMEMBERED, true).shown == REMEMBERED && sw.at(12.9, REMEMBERED, true).frame.done, "and over"); + n = sw.at(13.0, OFF, false); + want(n.shown == OFF && n.frame.done, "no switch to draw (RX_VK_N64_TV_ANIM=0, HDR Native, DLSS frame generation): at once"); + Look off = look_of(OFF, defaults()); + want(!tv_draws(off, AnimFrame{}, false, false) && tv_draws(off, anim(0.1f), false, false), + "the TV pass draws the switch over an Off look, and nothing once it is over"); + want(!tv_draws(off, anim(0.1f), true, false) && !tv_draws(off, anim(0.1f), false, true) && + tv_draws(look_of(FAITHFUL, defaults()), AnimFrame{}, false, false), "never on HDR Native's picture nor under DLSS frame generation"); +} + +static void glsl_maths() { + using namespace glsl; + bool perm = true; + int seen = 0; + float sum = 0.0f, lo = 1.0f, hi = -1.0f; + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) { + const int b = n64_bayer4(x, y); + if (b < 0 || b > 15 || (seen & (1 << b))) perm = false; + seen |= 1 << (b & 15); + const float d = n64_dither_offset(x, y); + sum += d, lo = d < lo ? d : lo, hi = d > hi ? d : hi; + } + want(perm && seen == 0xffff, "the 4 x 4 cell holds each of 0 to 15 once"); + want(near(sum, 0.0f, 1e-5f) && near(lo, -15.0f / 32.0f) && near(hi, 15.0f / 32.0f), "its thresholds centred, -15/32 to 15/32"); + want(n64_bayer4(0, 0) == 0 && n64_bayer4(1, 0) == 8 && n64_bayer4(0, 1) == 12 && n64_bayer4(1, 1) == 4 && + n64_bayer4(2, 2) == 1, "the Bayer matrix's own order"); + want(n64_dither_offset(4, 0) == n64_dither_offset(0, 0) && n64_dither_offset(5, 6) == n64_dither_offset(1, 2), + "the cell repeats every 4 grid pixels"); + + bool levels = true; + for (int bits : {5, 6}) { + const int top = (1 << bits) - 1; + for (int k = 0; k <= top; k++) + for (float s : {0.0f, 0.5f, 1.0f}) + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + levels &= n64_quantize((float)k / (float)top, bits, s, x, y) == (float)k / (float)top; + } + want(levels, "every level of 5 and of 6 bits comes back exactly, at any dither strength, in every cell"); + + bool mean = true, on_level = true, nearest = true; + for (int i = 0; i <= 1000; i++) { + const float v = i / 1000.0f; + float total = 0.0f; + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) { + const float q = n64_quantize(v, 5, 1.0f, x, y); + total += q; + on_level &= near(q * 31.0f, std::round(q * 31.0f), 1e-4f) && q >= 0.0f && q <= 1.0f; + } + mean &= std::fabs(total / 16.0f - v) <= 1.0f / 16.0f / 31.0f + 1e-6f; + const float q0 = n64_quantize(v, 5, 0.0f, 3, 1); + nearest &= std::fabs(q0 - v) <= 0.5f / 31.0f + 1e-6f && near(q0 * 31.0f, std::round(q0 * 31.0f), 1e-4f); + } + want(mean, "a value between levels averages to itself over a cell, within a 16th of a step"); + want(on_level, "the output is always one of the 32 levels, inside 0..1"); + want(nearest, "no dither: the nearest level"); + want(n64_quantize(-0.2f, 5, 1.0f, 0, 0) == 0.0f && n64_quantize(1.3f, 5, 1.0f, 3, 3) == 1.0f, "below 0 and past 1: the ends"); + want(n64_quantize(0.123f, 0, 1.0f, 2, 1) == 0.123f && n64_quantize(1.7f, 0, 1.0f, 2, 1) == 1.7f, + "full colour: the value as it is"); + + // (step 2's pass: the sRGB curve both ways, a channel as the grid keeps it, where an output pixel finds the grid) + bool round = true; + for (int i = 0; i <= 1000; i++) { + const float v = i / 1000.0f; + round &= near(n64_decode(n64_encode(v)), v, 2e-5f) && near(n64_encode(n64_decode(v)), v, 2e-5f); + } + want(round && near(n64_encode(0.5f), 0.735357f, 1e-4f), "the sRGB curve, both ways"); + bool kept = true; + for (int i = 0; i <= 200; i++) { + const float v = i / 200.0f * 0.999f; + const float k = n64_keep(v, 5, 1.0f, i & 3, (i >> 2) & 3); + kept &= near(n64_encode(k) * 31.0f, std::round(n64_encode(k) * 31.0f), 2e-3f) && k >= 0.0f && k <= 1.0f; + } + want(kept, "kept at 15-bit colour: every channel on one of the 32 display levels"); + want(n64_keep(0.42f, 0, 1.0f, 1, 1) == 0.42f && n64_keep(1.0f, 5, 1.0f, 1, 1) == 1.0f && n64_keep(3.5f, 5, 1.0f, 0, 0) == 3.5f, + "full colour, white and light above it (HDR's highlights) as they are"); + want(n64_keep(-0.3f, 5, 1.0f, 0, 0) == 0.0f && n64_keep(std::nanf(""), 5, 1.0f, 0, 0) == 0.0f, "below black, or not a number: black"); + bool bands = true; + for (int y = 0; y < 1440; y++) bands &= n64_row(y, 240, 1440) == y / 6; + want(bands, "1440 output rows on 240 grid rows: 6 each, hard edges"); + int first = 0, last = 0, shortest = 99, tallest = 0, height = 0; + bool climbs = true; + for (int y = 0; y < 1152; y++) { + const int r = n64_row(y, 240, 1152); + if (y == 0) first = r; + if (y && r != last) { + climbs &= r == last + 1; + shortest = height < shortest ? height : shortest, tallest = height > tallest ? height : tallest, height = 0; + } + last = r, height++; + } + want(first == 0 && last == 239 && climbs && shortest >= 4 && tallest <= 5, "1152 rows on 240: every grid row, in order, 4 or 5 output rows each"); + want(n64_row(2159, 240, 2160) == 239 && n64_row(0, 240, 2160) == 0, "the first and the last output row: the first and the last grid row"); + want(near(n64_column(3, 427, 427), 3.0f) && near(n64_column(0, 320, 1920), -5.0f / 12.0f) && + near(n64_column(1919, 320, 1920), 319.0f + 5.0f / 12.0f), "the column: the grid pixel's centre at the same size, inside the grid's edges at 6x"); +} + +int main() { + row_and_rows(); + looks(); + grid_and_screen(); + in_front_and_passes(); + frame_rate(); + toggle_and_anim(); + glsl_maths(); + if (fails) std::printf("n64 rules: FAILED (%d of %d checks)\n", fails, checks); + else std::printf("n64 rules: all %d checks passed\n", checks); + return fails != 0; +} +''' + +STAND_IN_SHADER = '''#version 450 +#extension GL_GOOGLE_include_directive : require +#include "n64_common.glsl" +layout(local_size_x = 8, local_size_y = 8) in; +layout(binding = 0, rgba8) uniform writeonly image2D dst; +void main() { + const ivec2 g = ivec2(gl_GlobalInvocationID.xy); + imageStore(dst, g, vec4(n64_quantize(0.4, 5, 1.0, g.x, g.y), 0.0, 0.0, 1.0)); +} +''' + + +def check_sources(): + rules = (VK / "n64_rules.h").read_text(encoding="utf-8") + if re.search(r'#include\s*[<"](vulkan|vk_)', rules): + raise SystemExit("FAIL: n64_rules.h includes Vulkan or the renderer: its rules are to stay plain") + common = (SHADERS / "n64_common.glsl").read_text(encoding="utf-8") + code = "\n".join(line.split("//", 1)[0] for line in common.splitlines()) + if "#version" in code or "[" in code or re.search(r"\.\s*[xyzwrgba]{2,4}\b", code): + raise SystemExit("FAIL: n64_common.glsl is an include in what GLSL and C++ share: no #version, no arrays, no swizzles") + + +def check_glsl(tmp): + glslang = shutil.which("glslangValidator") + if not glslang: + print("(glslangValidator is not on the PATH: n64_common.glsl was not compiled as GLSL)") + return + comp = Path(tmp) / "stand_in.comp" + comp.write_text(STAND_IN_SHADER, encoding="utf-8") + r = subprocess.run([glslang, "-V", "--target-env", "vulkan1.3", "-I" + str(SHADERS), str(comp), "-o", str(Path(tmp) / "s.spv")], + capture_output=True, text=True) + if r.returncode: + raise SystemExit("FAIL: n64_common.glsl does not compile as GLSL:\n" + r.stdout + r.stderr) + print("(n64_common.glsl compiles as GLSL in a stand-in compute shader)") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--cxx", default="clang++") + args = parser.parse_args() + check_sources() + with tempfile.TemporaryDirectory(prefix="n64-rules-") as tmp: + cpp, exe = Path(tmp) / "n64_rules_test.cpp", Path(tmp) / "n64-rules.exe" + cpp.write_text(DRIVER, encoding="utf-8") + subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I" + str(VK), str(cpp), + "-o", str(exe)], check=True) + r = subprocess.run([str(exe)], capture_output=True, text=True) + print(r.stdout.rstrip()) + if r.returncode: + raise SystemExit("FAIL: N64 Classic's rules") + check_glsl(tmp) + print("PASS: N64 Classic's rules and its 3D pass's per-pixel maths") + + +if __name__ == "__main__": + main() diff --git a/tests/test_n64_tv.py b/tests/test_n64_tv.py new file mode 100644 index 0000000..050802e --- /dev/null +++ b/tests/test_n64_tv.py @@ -0,0 +1,463 @@ +"""N64 Classic's TV (gpu/vk/shaders/n64_tv.comp and n64_tv.glsl; vk_framegen.cpp framegen_scale, init_tv; upscaler_rows.h +kTvFilter, tv_filter; vk_menu.cpp menu_note_present_sizes; vk_n64.cpp n64_tv_now). Step 4 of n64-classic-mode-plan.md, behind +RX_VK_N64 as the steps before. No game, no GPU. + +Compiled and run: n64_tv.glsl, written in what GLSL and C++ share, over a small GLSL stand-in (as aa_common.glsl is): no +scanlines leave every channel as it is; the beam never takes light below 0 nor more than doubles it, its mean over a line by +its closed form is the mean summed, a flat picture keeps its brightness within 15% at the presets' scanlines at any level, +and a bright line is wider; the aperture grille and the shadow mask light one channel a pixel, the grille repeats every 3 +pixels and the slot mask every 6 by 4 with one dark row in 4, neighbouring triads' 2 apart, each mask lights the three +colours alike and dims the picture less than a fifth at 30%; the colour to the composite signal and back, grey carrying no +colour, the bleed's weights; the screen's curve, which keeps the picture in order and loses its corners, the vignette and +the rounded corners only on a curved screen. And upscaler_rows.h's tv_filter: the TV's value while it runs, past the filters +RX_VK_UPSCALE names. + +n64_tv_comp_spv.h names the hash of the sources it was compiled from (n64_tv.comp, n64_common.glsl, n64_tv.glsl), checked +with or without glslang; with glslangValidator of the version the header names, the rest of the header is the pass compiled +now, byte for byte. --write makes the header. + +Read in the sources: the shader's bindings and push constants, and the C++ struct framegen_scale pushes, field for field; the +shader decodes the picture and encodes it again, warps it, takes the beam and the mask per channel at the window's own +pixels; framegen_scale runs the TV before AMD FSR 1 and the filter, only with n64_tv_now and its pipeline made, makes the +picture at 1/8 for the glow, draws ultrawide's menu sides first into an image of the window's size, and gives the TV the +screen's scanline strength and mask (n64_rules.h), the bleed in the picture's widths and (step 8) the switch's frame (the +squash to a line and a dot, the flash), ticked once a present from vk_replay.cpp; init_tv's pipeline; the filter the +present takes is tv_filter's over window_filter's; n64_tv_now asks n64_rules.h tv_runs with DLSS frame generation; the +development guide names the switches. + +(11-22, after the owner's test: "None of the classic visual effects apply to any of the custom UI") The options' own screens +under the TV: the shader lays their layer over the picture where it reads the picture (every tap, the bleed's too), before +the TV's steps; framegen_scale says the TV drew (vk_n64.h n64_screen_drawn) and asks vk_menu.cpp menu_tv_layer for the layer +before its pass, binding it fourth; the present says where the picture goes before the window pass and is done after it; +menu_tv_layer draws the options into ImGui's background list and the layer (vk_imgui.cpp record_layer, cleared, GENERAL +for the pass), menu_record the rest over the window (record_rest). Compiled: n64_rules.h screen_point, the mouse's, takes a +window pixel to the very place of the picture n64_tv.comp samples for it (its squash and n64_warp), and leaves points +beside the place as they are. + + python -I -B tests/test_n64_tv.py [--cxx clang++] [--glslang glslangValidator] [--write] +""" +import argparse +import hashlib +import re +import shutil +import subprocess +import tempfile +from pathlib import Path + +RUN_ALL_ARGS = ["--cxx", "{cxx}"] + +ROOT = Path(__file__).resolve().parents[1] +VK = ROOT / "gpu" / "vk" +SHADERS = VK / "shaders" +PARTS = ("n64_tv.comp", "n64_common.glsl", "n64_tv.glsl") +HEADER = SHADERS / "n64_tv_comp_spv.h" +FLAGS = ["-V", "--target-env", "vulkan1.2", "--vn", "N64_TV_COMP_SPV"] + +DRIVER = r''' +#include "n64_rules.h" +#include "upscaler_rows.h" + +#include +#include +#include + +// (just enough of GLSL for n64_common.glsl and n64_tv.glsl, in a namespace of its own) +namespace glsl { +static float floor(float a) { return std::floor(a); } +static float clamp(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; } +static float pow(float a, float b) { return std::pow(a, b); } +static float exp(float a) { return std::exp(a); } +static float sqrt(float a) { return std::sqrt(a); } +static float max(float a, float b) { return a < b ? b : a; } +static float abs(float a) { return std::fabs(a); } +#include "shaders/n64_common.glsl" +#include "shaders/n64_tv.glsl" +} // namespace glsl + +using namespace glsl; +static int checks, fails; +static void want(bool ok, const char* what) { + checks++; + if (!ok) fails++, std::printf("FAIL %s\n", what); +} + +int main() { + // ---- the beam ---- + bool flat = true, bounded = true; + for (int i = 0; i <= 100; i++) + for (int l = 0; l <= 10; l++) { + const float f = -0.5f + i / 100.0f, level = l / 10.0f; + flat &= n64_scan(f, level, 0.0f) == 1.0f; + for (float s : {0.35f, 0.6f, 0.8f, 1.0f}) { + const float m = n64_scan(f, level, s); + bounded &= m >= 0.0f && m <= 2.0f; + } + } + want(flat, "no scanlines: every channel as it is"); + want(bounded, "the beam never takes light below 0 nor more than doubles it"); + bool means = true, kept = true; + float worst = 1.0f; + for (int l = 0; l <= 20; l++) { + const float level = l / 20.0f; + double sum = 0.0; + const int n = 4000; + for (int i = 0; i < n; i++) sum += n64_beam(-0.5f + (i + 0.5f) / n, level); + means &= std::fabs(sum / n - n64_beam_mean(level)) < 2e-3; + for (float s : {0.35f, 0.6f, 0.8f}) { + double a = 0.0; + for (int i = 0; i < n; i++) a += n64_scan(-0.5f + (i + 0.5f) / n, level, s); + a /= n; + kept &= a >= 0.85 && a <= 1.1; + worst = (float)a < worst ? (float)a : worst; + } + } + want(means, "the beam's mean over a line, by its closed form, within two thousandths"); + want(kept, "a flat picture keeps its brightness within 15% at the presets' scanlines, any level"); + std::printf("(the darkest flat picture through the scanlines: %.3f of its light)\n", worst); + want(n64_beam(0.4f, 1.0f) > n64_beam(0.4f, 0.2f) && n64_beam(0.0f, 0.5f) == 1.0f, "a bright line is wider; the line's middle is its peak"); + + // ---- the mask ---- + bool one = true, repeats = true, breaks = true, none_off = true; + for (int y = 0; y < 12; y++) + for (int x = 0; x < 12; x++) { + for (int type : {2, 4}) { + float lit = 0.0f; + for (int c = 0; c < 3; c++) lit += n64_mask_lit(x, y, type, c); + one &= lit == 1.0f; + } + for (int c = 0; c < 3; c++) { + repeats &= n64_mask_lit(x, y, 2, c) == n64_mask_lit(x + 3, y + 1, 2, c); + repeats &= n64_mask_lit(x, y, 3, c) == n64_mask_lit(x + 6, y + 4, 3, c); + none_off &= n64_mask(x, y, 1, c, 0.5f) == 1.0f && n64_mask(x, y, 2, c, 0.0f) == 1.0f; + } + } + for (int x = 0; x < 12; x++) { + int dark = 0, row = -1; + for (int y = 0; y < 4; y++) { + float lit = 0.0f; + for (int c = 0; c < 3; c++) lit += n64_mask_lit(x, y, 3, c); + if (lit == 0.0f) dark++, row = y; + else breaks &= lit == 1.0f; + } + breaks &= dark == 1 && row == ((x / 3) % 2 ? 2 : 0); + } + want(one, "the aperture grille and the shadow mask light one channel a pixel"); + want(repeats, "the grille repeats every 3 pixels, the slot mask every 6 by 4"); + want(breaks, "the slot mask: one dark row in 4, neighbouring triads' 2 rows apart"); + want(none_off, "no mask, or no strength: every channel as it is"); + bool even = true; + for (int type : {2, 3, 4}) { + double sum[3] = {0, 0, 0}; + for (int y = 0; y < 4; y++) + for (int x = 0; x < 6; x++) + for (int c = 0; c < 3; c++) sum[c] += n64_mask(x, y, type, c, 0.3f); + even &= std::fabs(sum[0] - sum[1]) < 1e-4 && std::fabs(sum[1] - sum[2]) < 1e-4 && sum[0] / 24.0 > 0.8 && sum[0] / 24.0 < 1.0; + } + want(even, "each mask lights the three colours alike (no cast), dimming the picture less than a fifth at 30%"); + + // ---- the composite signal ---- + bool round = true, grey = true; + for (int i = 0; i <= 10; i++) + for (int j = 0; j <= 10; j++) { + const float r = i / 10.0f, g = j / 10.0f, b = (i * j % 11) / 10.0f; + const float y = n64_y(r, g, b), ii = n64_i(r, g, b), q = n64_q(r, g, b); + round &= std::fabs(n64_red(y, ii, q) - r) < 2e-3f && std::fabs(n64_green(y, ii, q) - g) < 2e-3f && + std::fabs(n64_blue(y, ii, q) - b) < 2e-3f; + grey &= std::fabs(n64_i(r, r, r)) < 1e-6f && std::fabs(n64_q(r, r, r)) < 1e-6f; + } + want(round, "the colour to the signal and back, within two thousandths"); + want(grey, "grey carries no colour: the bleed leaves it grey"); + float wsum = 0.0f; + for (int t = -2; t <= 2; t++) wsum += n64_bleed_weight(t); + want(std::fabs(wsum - 1.0f) < 1e-6f && n64_bleed_weight(-1) == n64_bleed_weight(1) && n64_bleed_weight(0) > n64_bleed_weight(2), + "the bleed's weights: symmetric, the middle heaviest, one in all"); + + // ---- the screen ---- + want(n64_warp(0.3f, -0.7f, 0.0f) == 0.3f && n64_warp(0.0f, 0.9f, 0.05f) == 0.0f, "a flat screen, and the middle: as they are"); + want(n64_warp(1.0f, 1.0f, 0.03f) > 1.0f && n64_warp(0.98f, 0.98f, 0.015f) > 1.0f, "a curved screen loses the picture's corners"); + bool outward = true; + for (int i = 1; i <= 100; i++) outward &= n64_warp(i / 100.0f, 0.5f, 0.03f) > n64_warp((i - 1) / 100.0f, 0.5f, 0.03f); + want(outward, "the warp keeps the picture in order"); + bool vig = true; + for (int i = 0; i <= 10; i++) + for (int j = 0; j <= 10; j++) { + vig &= n64_vignette(i / 10.0f, j / 10.0f, 0.0f) == 1.0f; + vig &= n64_vignette(i / 10.0f, j / 10.0f, 0.05f) >= 0.399f; + } + want(vig && n64_vignette(0.5f, 0.5f, 0.03f) == 1.0f && n64_vignette(0.02f, 0.02f, 0.03f) < 0.8f, + "the vignette: none on a flat screen, darker corners on a curved one, never below 0.4"); + want(n64_corner(0.0f, 0.0f, 0.03f) == 1.0f && n64_corner(1.0f, 1.0f, 0.03f) == 0.0f && n64_corner(1.0f, 1.0f, 0.0f) == 1.0f && + n64_corner(0.99f, 0.0f, 0.03f) == 1.0f, "the rounded corners: only at the corners, only on a curved screen"); + + // ---- (11-22) the mouse: the place of the picture the TV samples for a window pixel, as n64_tv.comp finds it ---- + namespace nr = mkwvk::n64_rules; + bool same_place = true, beside = true; + const float px0 = 240.0f, py0 = 0.0f, pw = 1440.0f, ph = 1080.0f; // (a 4:3 picture in a 16:9 window) + for (float curve : {0.0f, 0.015f, 0.03f, 0.05f}) + for (float ax : {1.0f, 0.5f}) + for (int gy = 0; gy < 1080; gy += 27) + for (int gx = 0; gx < 1440; gx += 31) { + // (n64_tv.comp: the pixel's middle in -1..1 of the place, the squash, the warp, the picture's uv) + float a = (gx + 0.5f) / pw * 2.0f - 1.0f, b = (gy + 0.5f) / ph * 2.0f - 1.0f; + a /= ax, b /= 1.0f; + const float u = n64_warp(a, b, curve) * 0.5f + 0.5f, v = n64_warp(b, a, curve) * 0.5f + 0.5f; + const nr::ScreenPoint s = nr::screen_point(px0 + gx + 0.5f, py0 + gy + 0.5f, px0, py0, pw, ph, curve, ax, 1.0f); + same_place &= std::fabs(s.x - (px0 + u * pw)) < 1e-2f && std::fabs(s.y - (py0 + v * ph)) < 1e-2f; + } + for (float x : {0.0f, 100.0f, 239.0f, 1681.0f, 1919.0f}) { + const nr::ScreenPoint s = nr::screen_point(x, 500.0f, px0, py0, pw, ph, 0.03f, 1.0f, 1.0f); + beside &= s.x == x && s.y == 500.0f; + } + const nr::ScreenPoint none = nr::screen_point(700.0f, 300.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.03f, 1.0f, 1.0f); + want(same_place, "the mouse: a window pixel taken to the place of the picture n64_tv.comp samples for it, at every curve and squash"); + want(beside && none.x == 700.0f && none.y == 300.0f, "the mouse: beside the picture's place, or with no place, the point as it is"); + const nr::ScreenPoint mid = nr::screen_point(960.0f, 540.0f, px0, py0, pw, ph, 0.03f, 1.0f, 1.0f); + const nr::ScreenPoint edge = nr::screen_point(px0 + 10.0f, 540.0f, px0, py0, pw, ph, 0.03f, 1.0f, 1.0f); + want(mid.x == 960.0f && mid.y == 540.0f && edge.x < px0 + 10.0f, "the mouse: the middle as it is; near an edge, out toward it, as the curve drew it"); + + // ---- the window's filter with the TV ---- + namespace ur = mkwvk::upscaler_rows; + want(ur::tv_filter(3, true) == ur::kTvFilter && ur::tv_filter(0, true) == ur::kTvFilter && ur::tv_filter(3, false) == 3 && + ur::tv_filter(0, false) == 0, "the TV's filter while it runs, at 1:1 too; else the filter as it was chosen"); + want(ur::kTvFilter > 3 && ur::window_filter(2560, 1440, 3840, 2160, false) != ur::kTvFilter, + "the TV's value is past the filters RX_VK_UPSCALE names and window_filter gives"); + + if (fails) std::printf("n64 tv: FAILED (%d of %d checks)\n", fails, checks); + else std::printf("n64 tv: all %d checks passed\n", checks); + return fails != 0; +} +''' + + +def fail(what): + raise SystemExit("FAIL: " + what) + + +def source_line(): + """the header's first line: the hash of the pass's sources (each by its name and its bytes, line ends as LF) and how it is made""" + digest = hashlib.sha256() + for part in PARTS: + digest.update(part.encode() + b"\0" + (SHADERS / part).read_bytes().replace(b"\r\n", b"\n") + b"\0") + return ("// %s sha256 %s (tests/test_n64_tv.py --write: glslangValidator %s)\n" + % (" + ".join(PARTS), digest.hexdigest(), " ".join(FLAGS))).encode() + + +def compiled(glslang, tmp): + out = Path(tmp) / "n64_tv.h" + r = subprocess.run([glslang, *FLAGS, "-o", str(out), str(SHADERS / "n64_tv.comp")], capture_output=True, text=True) + if r.returncode: + fail("n64_tv.comp does not compile:\n%s%s" % (r.stdout, r.stderr)) + return out.read_bytes().replace(b"\r\n", b"\n") + + +def glslang_version(glslang): + got = subprocess.run([glslang, "--version"], capture_output=True, text=True).stdout + m = re.search(r"Glslang Version: \d+:(\d+)\.(\d+)\.(\d+)", got) + return m and "11%02d.%s.%s" % (int(m.group(1)), m.group(2), m.group(3)) + + +def block(src, head): + at = src.index(head) + end = src.index("{", at) + 1 + depth = 1 + while depth: + depth += (src[end] == "{") - (src[end] == "}") + end += 1 + return src[at:end] + + +def in_order(text, parts, what): + at = [text.find(p) for p in parts] + if min(at) < 0 or at != sorted(at): + fail("%s: %s" % (what, [p for p, a in zip(parts, at) if a < 0] or at)) + + +def check_sources(): + comp = (SHADERS / "n64_tv.comp").read_text(encoding="utf-8") + in_order(comp, ['#extension GL_GOOGLE_include_directive : require', '#include "n64_common.glsl"', '#include "n64_tv.glsl"', + "void main()"], "n64_tv.comp no longer includes n64_common.glsl and n64_tv.glsl") + for b in ("layout(binding = 0) uniform sampler2D src;", "layout(binding = 1, rgba8) uniform writeonly image2D dst;", + "layout(binding = 2) uniform sampler2D small;", "layout(binding = 3) uniform sampler2D menu;"): + if b not in comp: + fail("n64_tv.comp: %s is not its binding" % b) + push = re.search(r"layout\(push_constant\) uniform P \{(.*?)\} pc;", comp, re.S) + fields = re.findall(r"^\s*(\w+) (\w+);", push.group(1), re.M) if push else [] + want = [("float", "lines"), ("float", "scan"), ("float", "mask"), ("float", "bleed"), ("float", "glow"), ("float", "curve"), + ("float", "saturation"), ("int", "mask_type"), ("float", "anim_x"), ("float", "anim_y"), ("float", "flash"), + ("int", "menu")] + if fields != want: + fail("n64_tv.comp's push constants are not %s: %s" % (want, fields)) + # ((11-22) the options' layer over the picture wherever the picture is read, before main's steps) + read = block(comp, "vec3 encoded(vec2 uv) {") + in_order(read, ["vec3 c = clamp(textureLod(src, uv, 0.0).rgb, 0.0, 1.0);", "if (pc.menu != 0) {", + "const vec4 m = clamp(textureLod(menu, uv, 0.0), 0.0, 1.0);", "c = m.rgb + c * (1.0 - m.a);", + "return clamp(c, 0.0, 1.0);"], + "n64_tv.comp: encoded no longer lays the options' layer (premultiplied) over the picture") + if comp.index("vec3 encoded(vec2 uv) {") > comp.index("void main()") or "textureLod(src," in block(comp, "void main()"): + fail("n64_tv.comp: main reads the picture past encoded (the options' layer would be left out of a tap)") + # ((11-22, the owner's second look) the glow's 1/8 copy made again with the options over the picture: the block's mean of + # encoded, before the TV's own steps; else the glow blurred the game's own panes through the options' plates) + in_order(block(comp, "void main()"), ["if (pc.menu == 2) {", "for (int x = 0; x < 4; x++) sum += encoded(at + (vec2(x, y) - 1.5) * 0.25 * block);", + "imageStore(dst, g, vec4(sum / 16.0, 1.0));\n return;", "vec2 p = (vec2(g) + 0.5) / vec2(d) * 2.0 - 1.0;"], + "n64_tv.comp: menu 2 does not make the 1/8 copy from the picture with the options over it, before the TV's steps") + main = block(comp, "void main()") + in_order(main, ["if (abs(p.x) > pc.anim_x || abs(p.y) > pc.anim_y) {", "imageStore(dst, g, vec4(0.0, 0.0, 0.0, 1.0));", + "p /= vec2(pc.anim_x, pc.anim_y);", "n64_warp(p.x, p.y, pc.curve)", "if (abs(w.x) > 1.0 || abs(w.y) > 1.0) {", + "n64_bleed_weight(t)", + "vec3 c = decode3(e);", "mix(vec3(luma), c, pc.saturation)", "fract(uv.y * pc.lines) - 0.5", + "n64_scan(f, c.r, pc.scan)", "n64_mask(g.x, g.y, pc.mask_type, 0, pc.mask)", "pc.glow * decode3(", + "n64_vignette(uv.x, uv.y, pc.curve) * n64_corner(w.x, w.y, pc.curve)", + "c = mix(c, vec3(0.9, 0.95, 1.0), clamp(pc.flash, 0.0, 1.0) * 0.8);", "encode3(clamp(c, 0.0, 1.0)) + dither(g)"], + "n64_tv.comp's steps are no longer the switch's squash, the curve, the bleed, linear light, the beam, the mask, the glow, " + "the vignette, the switch's flash") + for ch in ("n64_scan(f, c.g, pc.scan)", "n64_scan(f, c.b, pc.scan)", "n64_mask(g.x, g.y, pc.mask_type, 1, pc.mask)", + "n64_mask(g.x, g.y, pc.mask_type, 2, pc.mask)"): + if ch not in main: + fail("n64_tv.comp: the beam and the mask are not each channel's (%s)" % ch) + + framegen = (VK / "vk_framegen.cpp").read_text(encoding="utf-8") + for inc in ('#include "vk_n64.h"', '#include "shaders/n64_tv_comp_spv.h"'): + if inc not in framegen: + fail("vk_framegen.cpp does not %s" % inc) + init = block(framegen, "bool init_tv() {") + if "make_pipe(scale.tv, N64_TV_COMP_SPV, sizeof N64_TV_COMP_SPV, {S, I, S, S}, 48)" not in init or "init_scale()" not in init: + fail("init_tv: the TV's pipeline is not n64_tv.comp's, with its four bindings and 48 bytes of push constants") + scale = block(framegen, "VkImage framegen_scale(") + tv = block(scale, "if (!pq && n64_tv_now(pq) && init_tv()) {") + in_order(scale, ["if (!pq && n64_tv_now(pq) && init_tv()) {", "const bool fsr1 = opts.upscale == 3"], + "framegen_scale: the TV no longer runs before AMD FSR 1 and the filter") + in_order(tv, ["const n64_rules::AnimFrame f = n64_anim();", "const uint32_t smw = std::max(1u, source.w / 8), smh = std::max(1u, source.h / 8);", + "pass(cmd, filter, {{src, scale.linear}, {scale.small.view, VK_NULL_HANDLE}, {src, scale.linear}}, smw, smh, &sp, sizeof sp);", + "if (wide.side) {", "picture = scale.tv_img.view;", "const int mask = n64_rules::mask_shown(look.mask, dh);", + "n64_screen_drawn(look.curvature, f.scale_x, f.scale_y);", "const VkImageView menu = menu_tv_layer(cmd);", + "struct { float lines, scan, mask, bleed, glow, curve, saturation; int mask_type; float anim_x, anim_y, flash; int menu; } tp{", + "(float)n64_rules::kTvLines, n64_rules::scanline_strength(look.scanlines, dh), look.mask_strength,", + "n64_rules::tv_bleed_uv(look.bleed, source.w, source.h), look.glow, look.curvature, look.saturation, mask,", + "f.scale_x, f.scale_y, f.flash, menu ? 1 : 0};", + "if (menu) {", "tp.menu = 2;", + "pass(cmd, scale.tv, {{picture, scale.linear}, {scale.small.view, VK_NULL_HANDLE}, {picture, scale.linear}, {menu, scale.linear}},", + "smw, smh, &tp, sizeof tp);", "tp.menu = 1;", + "pass(cmd, scale.tv, {{picture, scale.linear}, {scale.scaled.view, VK_NULL_HANDLE}, {scale.small.view, scale.linear},", + "{menu ? menu : scale.small.view, scale.linear}}, dw, dh, &tp, sizeof tp);", + "if (f.done && now != told) {", + "return scale.scaled.image;"], + "framegen_scale's TV: the 1/8 copy, the menu sides first, the screen's scanlines and mask, the bleed, the pass, its image") + menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8") + # ((11-22) the options under the TV: drawn into ImGui's background list and the layer; the rest over the window after) + layer = block(menu, "VkImageView menu_tv_layer(VkCommandBuffer cmd) {") + in_order(layer, ["if (!on || !n64_screen_place(&x, &y, &pw, &ph, &w, &h)) return VK_NULL_HANDLE;", + "if (s.start || !(s.open || s.game_tab || s.mods_row) || bugshot_state() == 1 || dev.hdr || !ui::begin(w, h))", + "draw_overlays(w, h, s, ImGui::GetBackgroundDrawList());", "ui::record_layer(cmd, x, y, pw, ph);", + "tv_drawn = true, tv_layer = layer != VK_NULL_HANDLE"], + "menu_tv_layer: the options are not drawn under the TV only while they show, into the background list and the layer") + record = block(menu, "void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {") + in_order(record, ["if (tv_drawn) {", "bugshot_record(cmd, index, w, h);", "ui::record_rest(cmd, index, w, h);", "return;", + "draw_overlays(w, h, s, nullptr);"], + "menu_record: the rest of a frame drawn under the TV is not drawn over the window, or the frame as before is gone") + tail = record.rstrip()[-400:] + if not record.rstrip().endswith("ui::record(cmd, index, w, h);\n}") or tail.find("draw_overlays(w, h, s, nullptr);") < 0: + fail("menu_record: the frame as before no longer ends drawn over the window") + overlays = block(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {") + for need in ("if (under) m.d = under;", "if (s.open) draw_menu(m, full && !over_row);", "if (s.game_tab) draw_game_tab(m);", + "else if (s.mods_row) draw_mods_row_shut(m);", "draw_fps(c, ", "if (s.note) draw_notice(c);"): + if need not in overlays: + fail("draw_overlays: %s is gone (the options under the TV, the counter and the notice over it)" % need) + imgui = (VK / "vk_imgui.cpp").read_text(encoding="utf-8") + rl = block(imgui, "VkImageView record_layer(VkCommandBuffer cmd, uint32_t x, uint32_t y, uint32_t w, uint32_t h) {") + in_order(rl, ["part_of({ImGui::GetBackgroundDrawList()}, (float)x, (float)y, w, h);", "ca.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;", + "ImGui_ImplVulkan_RenderDrawData(&d, cmd);", "VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT", + "return layer.sample;"], + "record_layer: the background list is not drawn into a cleared layer at the picture's place, GENERAL for the TV's pass") + if "ii.ImageCount = 8;" not in imgui: + fail("vk_imgui.cpp: the backend's vertex buffers are not enough for two draws a frame over three frames in flight") + # ((11-22) the game's own menus' mouse under the curve: the renderer's screen_point, last of its table, at version 19 (16-18 ultrawide's on next/update)) + api = (VK / "vk_api.h").read_text(encoding="utf-8") + if not re.search(r"void \(\*screen_point\)\(int \*x, int \*y, int w, int h\);\s*\} MkwVkRenderer;", api) or \ + "#define MKWVK_API_VERSION 19" not in api: + fail("vk_api.h: MkwVkRenderer has no screen_point last, at version 19") + if "void rx_screen_point(int *x, int *y, int w, int h) { if (vk && vk->screen_point) vk->screen_point(x, y, w, h); }" not in \ + (ROOT / "host" / "rx_backend.c").read_text(encoding="utf-8"): + fail("host/rx_backend.c: rx_screen_point does not ask the renderer") + oot = block((ROOT / "host" / "oot_menu.c").read_text(encoding="utf-8"), "static void mouse_tick_locked(Ctx *c, uint64_t screen) {") + in_order(oot, ["const int got = hos_mouse_game_pointer(&px, &py, &w, &h, &pressed, &wheel);", "if (!got) return;", + "rx_screen_point(&px, &py, w, h);", "hit.x = (float)(px - w / 2) * scale"], + "host/oot_menu.c: the game's menus' cursor is not taken through the TV's curve before it is tested") + present = block((VK / "vk_replay.cpp").read_text(encoding="utf-8"), "void present_image(") + in_order(present, ["n64_screen_begin(rect.x, rect.y, rect.w, rect.h, dev.swap_extent.width, dev.swap_extent.height);", + "framegen_scale(f.cmd, view, src, sw, sh, crop, rect.w, rect.h)", "n64_screen_end();", + "menu_record(f.cmd, index, dev.swap_extent.width, dev.swap_extent.height);"], + "present_image: the TV's screen is not begun before the window pass and ended after it, before the overlays") + note = block(menu, "void menu_note_present_sizes(") + if "const int filter = ur::tv_filter(ur::window_filter(picture_w, picture_h, place.w, place.h, native_hdr), n64_tv_now(native_hdr));" not in note: + fail("menu_note_present_sizes: the filter the present takes is not tv_filter's over window_filter's") + if "opts.upscale = std::min(std::max(atoi(e), 0), 3);" not in menu: + fail("RX_VK_UPSCALE can name the TV's filter value (it stops at 3)") + rows = (VK / "upscaler_rows.h").read_text(encoding="utf-8") + if "constexpr int kTvFilter = 4;" not in rows or "inline int tv_filter(int filter, bool tv) { return tv ? kTvFilter : filter; }" not in rows: + fail("upscaler_rows.h: kTvFilter or tv_filter is gone") + n64 = (VK / "vk_n64.cpp").read_text(encoding="utf-8") + if "bool n64_tv_now(bool native_pq) { return n64_rules::tv_draws(n64_look(), n64_anim(), native_pq, dlssg::active()); }" not in n64: + fail("vk_n64.cpp: n64_tv_now does not ask n64_rules.h tv_draws with the switch and DLSS frame generation") + # ((step 8) the switch: ticked once a present beside the texture blur's, with HDR Native's picture; the look the preset shown) + tick = block(n64, "void n64_tick(bool native_pq) {") + for need in ("switch_rule.at(t, n64_preset(), anim_on() && !native_pq && !dlssg::active());", "anim_now = now.frame;", + "shown_now.store(now.shown, std::memory_order_relaxed);"): + if need not in tick: + fail("n64_tick: %s is gone" % need) + if 'env_number("RX_VK_N64_TV_ANIM", 1) != 0' not in n64 or "n64_rules::look_of(n64_shown()," not in n64: + fail("vk_n64.cpp: RX_VK_N64_TV_ANIM is not read, or the look is not the preset shown") + replay = (VK / "vk_replay.cpp").read_text(encoding="utf-8") + if " upscale_lod_tick();" not in replay or "n64_tick(present_native_pq.load(std::memory_order_relaxed));" not in replay or \ + replay.index(" upscale_lod_tick();") > replay.index("n64_tick(present_native_pq.load("): + fail("vk_replay.cpp: the switch is not ticked once a present, after the texture blur's tick") + docs = (ROOT / "docs" / "development.md").read_text(encoding="utf-8") + if "`RX_VK_N64_TV=0` leaves it out" not in docs or "`RX_VK_N64_MASK=<0..4>`" not in docs or "`RX_VK_N64_TV_ANIM=0`" not in docs or \ + "`RX_VK_N64_TV_MENU=0`" not in docs: + fail("docs/development.md: the TV's switches are not in the switches table") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--cxx", default="clang++") + parser.add_argument("--glslang", default=None) + parser.add_argument("--write", action="store_true") + args = parser.parse_args() + glslang = args.glslang or shutil.which("glslangValidator") + if args.write: + if not glslang: + fail("--write needs glslangValidator") + with tempfile.TemporaryDirectory(prefix="n64-tv-") as tmp: + HEADER.write_bytes(source_line() + compiled(glslang, tmp)) + print("wrote %s" % HEADER.relative_to(ROOT)) + check_sources() + with tempfile.TemporaryDirectory(prefix="n64-tv-") as tmp: + cpp, exe = Path(tmp) / "n64_tv_test.cpp", Path(tmp) / "n64-tv.exe" + cpp.write_text(DRIVER, encoding="utf-8") + subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I" + str(VK), str(cpp), + "-o", str(exe)], check=True) + r = subprocess.run([str(exe)], capture_output=True, text=True) + print(r.stdout.rstrip()) + if r.returncode: + fail("N64 Classic's TV, per pixel") + if not HEADER.exists(): + fail("n64_tv_comp_spv.h is missing: run with --write") + header = HEADER.read_bytes().replace(b"\r\n", b"\n") + first, _, rest = header.partition(b"\n") + if first + b"\n" != source_line(): + fail("n64_tv_comp_spv.h was not made from n64_tv.comp, n64_common.glsl and n64_tv.glsl as they are now: run with --write") + if glslang: + named = rest.split(b"\n", 1)[0].decode("ascii", "replace").strip().lstrip("/ ").strip() + if glslang_version(glslang) == named: + with tempfile.TemporaryDirectory(prefix="n64-tv-") as tmp: + if compiled(glslang, tmp) != rest: + fail("n64_tv_comp_spv.h is not n64_tv.comp compiled: run with --write") + print("(the SPIR-V header is its source compiled, byte for byte)") + else: + print("(glslangValidator is not version %s: the header was not compiled again)" % named) + else: + print("(glslangValidator is not on the PATH: the header's hash was checked, not its bytes)") + print("PASS: N64 Classic's TV, per pixel and in the window pass") + + +if __name__ == "__main__": + main() diff --git a/tests/test_oot_menu_linux_half.py b/tests/test_oot_menu_linux_half.py index b211c26..10e5850 100644 --- a/tests/test_oot_menu_linux_half.py +++ b/tests/test_oot_menu_linux_half.py @@ -85,6 +85,8 @@ uint8_t *fake_heap; static uint64_t heap_top = FAKE_BASE + 0x1000; int64_t hos_now_ns(void) { return 1000000000LL; } void hos_log(const char *fmt, ...) { (void)fmt; } +static uint64_t menu_class; +void oot_menu_screen_tick(uint64_t vt) { menu_class = vt; } void rx_option_set(int id, int value) { (void)id, (void)value; } void hos_oot_menu_tick(Ctx *c, uint64_t screen); static int bench, asked, asked_entry, asked_entries; @@ -128,11 +130,11 @@ int main(void) { const uint64_t title_vt = 0x84c106e8ULL, title = screen_of(title_vt, 4); bench = 1; hos_oot_menu_tick(&ctx, title); /* (no button focused yet: the title still fading in) */ - CHECK(asked == 0 && !taps[0]); + CHECK(asked == 0 && !taps[0] && menu_class == title_vt); *(uint8_t *)GP(button[2] + 56) = 1; bench = 0; hos_oot_menu_tick(&ctx, title); /* (benchmark mode off: a player's menus, nothing pressed) */ - CHECK(asked == 0 && !taps[0]); + CHECK(asked == 0 && !taps[0] && menu_class == title_vt); bench = 1; hos_oot_menu_tick(&ctx, title); CHECK(asked == 1 && asked_screen == title && asked_vt == title_vt && asked_entry == 2 && asked_entries == 4); @@ -170,6 +172,7 @@ class OotMenuBenchOtherHalfTest(unittest.TestCase): (tmp / "gpu" / "vk" / "vk_api.h").write_text(VK_API_H, encoding="utf-8") (tmp / "host" / "hos_bench.h").write_text(BENCH_H, encoding="utf-8") shutil.copy(SRC, tmp / "host" / "oot_menu.c") + shutil.copy(ROOT / "host/oot_title_movie.h", tmp / "host/oot_title_movie.h") shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") (tmp / "host" / "t.c").write_text(FIXTURE, encoding="utf-8") binary = tmp / "t.exe" diff --git a/tests/test_oot_menu_mouse.py b/tests/test_oot_menu_mouse.py index 4b3165b..f971f16 100644 --- a/tests/test_oot_menu_mouse.py +++ b/tests/test_oot_menu_mouse.py @@ -97,12 +97,15 @@ void rx_option_set(int id, int value) { if (id == HOS_OPT_GAME_OPTIONS) game_options_said = value; } int rx_option(int id, int otherwise) { return id == HOS_OPT_MODS_SELECTED ? mods_selected : otherwise; } +int hos_save_files_on(void) { return 0; } /* ((Triforce) no save files here: no Save Select under Mods (tests/test_save_files.py)) */ int hos_mouse_wheel_take(void) { const int w = wheel_next; wheel_next = 0; return w; } /* (the wheel only, mouse kept) */ int hos_mouse_game_pointer(int *x, int *y, int *w, int *h, uint32_t *pressed, int *wheel) { *x = ptr_x, *y = ptr_y, *w = 3840, *h = 2160, *pressed = pressed_next, *wheel = wheel_next; pressed_next = 0, wheel_next = 0; return pointer_hidden ? 2 : 1; } +/* ((Triforce, 11-22) N64 Classic's TV's curve (rx_backend.c): no TV here, the point as it is */ +void rx_screen_point(int *x, int *y, int w, int h) { (void)x, (void)y, (void)w, (void)h; } static char taps[1024]; void hos_hid_tap(const char *press) { strncat(taps, press, sizeof taps - strlen(taps) - 2), strcat(taps, ";"); } void hos_hid_stick(int lx, int ly, int rx, int ry, int hold_ms) { (void)lx, (void)ly, (void)rx, (void)ry, (void)hold_ms; } @@ -609,7 +612,8 @@ class OotOptionsScreenTests(unittest.TestCase): shutil.copy(ROOT / "host" / "oot_menu.c", tmp / "host" / "oot_menu.c") shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") # (set_item_key's buffer check) (tmp / "host" / "hos_bench.h").write_text(HOS_BENCH_H, encoding="utf-8") # ((Triforce, 11-19) benchmark mode: off here) - (tmp / "host" / "t.c").write_text(OPTIONS_FIXTURE, encoding="utf-8") + shutil.copy(ROOT / "host" / "oot_title_movie.h", tmp / "host" / "oot_title_movie.h") # (oot_menu_screen_tick) + (tmp / "host" / "t.c").write_text(OPTIONS_FIXTURE + MENU_TICK, encoding="utf-8") binary = tmp / "t.exe" other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] if sys.platform == "win32" else [] build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", str(tmp / "host" / "t.c")] + @@ -624,6 +628,9 @@ class OotOptionsScreenTests(unittest.TestCase): self.assertEqual(run.returncode, 0, run.stdout + run.stderr) +# ((Triforce) host/oot_title_movie.c's, which every menu screen's update tells its class: tests/test_oot_title_movie.py has +# what is made of it; here only taken) +MENU_TICK = "\nvoid oot_menu_screen_tick(unsigned long long screen_class) { (void)screen_class; }\n" # ((Triforce, 11-19) host/hos_bench.h's two calls oot_menu.c makes, benchmark mode off: the menus as a player has them) HOS_BENCH_H = """#pragma once #include @@ -653,7 +660,8 @@ class OotMenuMouseTests(unittest.TestCase): shutil.copy(ROOT / "host" / "oot_menu.c", tmp / "host" / "oot_menu.c") shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") # (set_item_key's buffer check) (tmp / "host" / "hos_bench.h").write_text(HOS_BENCH_H, encoding="utf-8") # ((Triforce, 11-19) benchmark mode: off here) - (tmp / "host" / "t.c").write_text(FIXTURE, encoding="utf-8") + shutil.copy(ROOT / "host" / "oot_title_movie.h", tmp / "host" / "oot_title_movie.h") # (oot_menu_screen_tick) + (tmp / "host" / "t.c").write_text(FIXTURE + MENU_TICK, encoding="utf-8") binary = tmp / "t.exe" build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", "-D_WIN32_WINNT=0x0601", str(tmp / "host" / "t.c"), str(tmp / "host" / "oot_menu.c"), "-o", str(binary)], diff --git a/tests/test_oot_title_movie.py b/tests/test_oot_title_movie.py new file mode 100644 index 0000000..4e760e1 --- /dev/null +++ b/tests/test_oot_title_movie.py @@ -0,0 +1,216 @@ +"""Exercise the lifted movie and viewport sites with open movie handles and synthetic presents. + +And the menu sides beside the filled title movie (host/oot_title_movie.h, host/rx_backend.c host_wide_menus): none while +the movie alone shows; the picture's own margin while a menu opened over it runs (the file select, the file's box, the +Options, the system menus' backdrop: host/oot_menu.c tells each menu screen's class every frame it runs), and for +OOT_MENU_PRESENTS presents after its last update; none again after that. The title's own list is a menu screen too and is +no menu over the title. In play (no filled movie) the margin is the picture's whatever runs. +""" +import argparse +import os +from pathlib import Path +import subprocess +import sys +import tempfile + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "nx2")) +import oot_wide + +RUN_ALL_ARGS = ["--cxx", "{cxx}"] + +SOURCE = r""" +#include +#include +#include +#include +#include +extern "C" { +#include "oot_title_movie.h" +volatile int64_t hos_present_count; +int logs; +void hos_log(const char *, ...) { ++logs; } +} +volatile float hos_wide_ratio = 2.4f; +volatile float hos_wide_margin = (1 - (16.f / 9) / 2.4f) / 2; +struct Ctx { uint64_t x[32]; }; +uint32_t recomp_load32(Ctx *, uintptr_t p) { uint32_t v; memcpy(&v, (void *)p, 4); return v; } +void recomp_store32(Ctx *, uintptr_t p, uint32_t v) { memcpy((void *)p, &v, 4); } +void movie(Ctx *c) { MOVIE_SITE } +void viewport(Ctx *c) { VIEWPORT_SITE } +void playback() { + Ctx c{}; + float bounds[10]{}; + c.x[29] = (uintptr_t)bounds + 40; + auto draw = [&](bool cover) { + bounds[2] = 0; + bounds[4] = 3840; + movie(&c); + if (cover) assert(bounds[2] == 0 && bounds[4] == 3840); + else assert(bounds[2] > 0 && bounds[4] < 3840); + c.x[2] = 0; + c.x[4] = 1600; + std::thread other([&] { viewport(&c); }); + other.join(); + assert(c.x[2] == 0 && c.x[4] == 1600); + viewport(&c); + assert((int32_t)c.x[2] == (cover ? -280 : 0)); + assert(c.x[4] == (cover ? 2160 : 1600)); + c.x[2] = 0; + c.x[4] = 1600; + viewport(&c); + assert(c.x[2] == 0 && c.x[4] == 1600); + }; + auto title = oot_movie_file("rom:/Event/Movie/Dm_Title_0005.webm"); + auto story = oot_movie_file("rom:/Event/Movie/Dm_Story_0010.WEBM"); + assert(title == OOT_MOVIE_TITLE && story == OOT_MOVIE_OTHER); + assert(oot_movie_file("rom:/Else/Dm_Title_0005.webm") == OOT_MOVIE_OTHER); + assert(oot_movie_file("rom:/Event/Movie/Dm_Title_0005.webm.bak") == OOT_MOVIE_NONE); + draw(false); + oot_movie_file_change(title, 1); + oot_movie_file_change(title, 1); + assert(!oot_movie_cover_recent() && logs == 0); + draw(true); + assert(oot_movie_cover_recent() && logs == 1); + oot_movie_file_change(story, 1); + draw(false); + hos_present_count = 2; + assert(oot_movie_cover_recent() && logs == 1); + hos_present_count = 3; + assert(!oot_movie_cover_recent() && logs == 2); + oot_movie_file_change(title, -1); + draw(false); + oot_movie_file_change(story, -1); + hos_wide_ratio = 32.f / 9; + draw(false); + hos_wide_ratio = 2.4f; + draw(true); + oot_movie_file_change(title, -1); + draw(false); +} +// The menu sides' margin as host/rx_backend.c host_wide_menus gives it to the renderer +volatile uint32_t hos_wide_keep_mask; +static int mods_mode; +enum { HOS_OPT_MODS_MUSIC = 161 }; +int rx_option(int id, int otherwise) { return id == HOS_OPT_MODS_MUSIC ? mods_mode : otherwise; } +BACKEND_SITES +static float margin_now() { return host_wide_menus(0xd); } +void menus() { + const uint64_t title_list = 0x84c106e8, files = 0x84c0eba0, file_box = 0x84c0f840, options = 0x84c0f108, + backdrop = 0x84c04fb0, pause = 0x84c0baa8, hud = 0x84c08300; + const float margin = hos_wide_margin; + assert(margin > 0.1f); + assert(!oot_title_menu_class(title_list) && !oot_title_menu_class(pause) && !oot_title_menu_class(hud) && !oot_title_menu_class(0)); + for (uint64_t c : {files, file_box, options, backdrop}) assert(oot_title_menu_class(c)); + Ctx c{}; + float bounds[10]{}; + c.x[29] = (uintptr_t)bounds + 40; + auto frame = [&](bool title_movie, std::initializer_list screens) { // (one frame of the game: its screens, its draw, its present) + for (uint64_t s : screens) oot_menu_screen_tick(s); + if (title_movie) { + bounds[2] = 0, bounds[4] = 3840; + movie(&c); + c.x[2] = 0, c.x[4] = 1600; + viewport(&c); + assert(c.x[4] == 2160); // (the movie still fills the picture under a menu: the sides blur it) + } + hos_present_count = hos_present_count + 1; + }; + hos_present_count = 100; + auto title = oot_movie_file("rom:/Event/Movie/Dm_Title_0005.webm"); + oot_movie_file_change(title, 1); + // the title alone, its own list running: no sides, and no menu's backdrop for the renderer + for (int i = 0; i < 10; i++) frame(true, {title_list}), assert(margin_now() == 0.0f && !oot_menu_backdrop_runs()); + // 0.7's renderer-owned Mods page has no guest class. The title list alone does not request sides. + mods_mode = 1; + assert(margin_now() == 0.0f && !host_wide_backdrop()); + mods_mode = 2; + for (int i = 0; i < 10; i++) frame(true, {title_list}), assert(margin_now() == margin && host_wide_backdrop()); + mods_mode = 1; + assert(margin_now() == 0.0f && !host_wide_backdrop()); + mods_mode = 0; + // the file select opened over it, with the backdrop or without, the title's list still running or not: the row's sides + for (int i = 0; i < 10; i++) frame(true, {title_list, files}), assert(margin_now() == margin && oot_menu_backdrop_runs()); + for (int i = 0; i < 5; i++) frame(true, {files, file_box}), assert(margin_now() == margin); + for (int i = 0; i < 5; i++) frame(true, {backdrop}), assert(margin_now() == margin); + for (int i = 0; i < 5; i++) frame(true, {title_list, options}), assert(margin_now() == margin); + // closed: the menu's last pictures keep the sides, then the title alone has none again + for (int i = 0; i < OOT_MENU_PRESENTS - 1; i++) frame(true, {title_list}), assert(margin_now() == margin); + assert(oot_menu_backdrop_runs()); + frame(true, {title_list}); + assert(margin_now() == 0.0f && !oot_menu_backdrop_runs()); + for (int i = 0; i < 10; i++) frame(true, {title_list}), assert(margin_now() == 0.0f); + // screens that are no menu over the title change nothing there + frame(true, {title_list, pause, hud}), assert(margin_now() == 0.0f); + // in play, no filled movie: the picture's margin with a menu and without + oot_movie_file_change(title, -1); + for (int i = 0; i < 6; i++) frame(false, {hud}); + assert(margin_now() == margin && !oot_menu_backdrop_runs()); // (play, the item wheel's too: its blur is the wheel's) + frame(false, {pause, backdrop}), assert(margin_now() == margin); + assert(oot_wide_menu_margin(0.25f, 0, 0) == 0.25f && oot_wide_menu_margin(0.25f, 0, 1) == 0.25f); + assert(oot_wide_menu_margin(0.25f, 1, 0) == 0.0f && oot_wide_menu_margin(0.25f, 1, 1) == 0.25f); + assert(oot_menu_recent(10, 7) && !oot_menu_recent(10, 6) && !oot_menu_recent(10, -1)); +} +int main() { + playback(); + menus(); + int32_t y = 0, height = 1600; + assert(oot_title_movie_cover(3840.f / 1600, &y, &height)); + assert(y == -280 && height == 2160); + // Offset viewport, with an odd number of cropped rows. + y = 13; + height = 1440; + assert(oot_title_movie_cover(3440.f / 1440, &y, &height)); + assert(height == 1935 && y == 13 - 247); + // Near 12:5, rounding to a multiple of eight can land on either side. + for (float ratio : {872.f/362, 864.f/361, 3848.f/1603}) { + y = 0; + height = 1080; + assert(oot_title_movie_cover(ratio, &y, &height) && y < 0 && height > 1080); + } + for (float ratio : {16.f/10, 16.f/9, 2.425f, 32.f/9}) { + y = 7; + height = 1080; + assert(!oot_title_movie_cover(ratio, &y, &height)); + assert(y == 7 && height == 1080); + } +} +""" + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cxx", required=True) + args = parser.parse_args() + # the renderer's margin is the header's rule, and every menu screen's update tells its class, in both halves of + # host/oot_menu.c (the Windows one with the mouse, the other without) + backend = (ROOT / "host/rx_backend.c").read_text(encoding="utf-8") + sites = backend[backend.index("static float host_wide_menus("):backend.index("int hos_mouse_pointer(")] + menu = (ROOT / "host/oot_menu.c").read_text(encoding="utf-8") + windows, other = menu.split("#else\n/* Not Windows:", 1) + assert "oot_menu_screen_tick(peek64(screen));" in windows and "oot_menu_screen_tick(vt);" in other, \ + "host/oot_menu.c: a half does not tell the menu screens' classes" + for name, value in (("OPTIONS_SCREEN_VTABLE", "0x84c0f108ULL"),): + assert f"#define {name} {value}" in menu, "host/oot_menu.c: the Options screen's class is another" + bench = (ROOT / "host/hos_bench.c").read_text(encoding="utf-8") + assert "#define FILES_VT 0x84c0eba0ULL" in bench and "#define FILE_BOX_VT 0x84c0f840ULL" in bench and \ + "#define TITLE_VT 0x84c106e8ULL" in bench, "host/hos_bench.c: the start's screens' classes are others" + assert " 0x84c04fb0ULL, /* the pause and system menus' background */" in (ROOT / "host/oot_wide_hud.h").read_text(encoding="utf-8"), \ + "host/oot_wide_hud.h: the system menus' backdrop's class is another" + with tempfile.TemporaryDirectory() as tmp: + source = Path(tmp, "geometry.cpp") + source.write_text(SOURCE.replace("MOVIE_SITE", oot_wide.MOVIE).replace("VIEWPORT_SITE", oot_wide.THUMB).replace("BACKEND_SITES", sites)) + exe = Path(tmp, "geometry.exe") + host = ROOT / "host" + obj = Path(tmp, "movie.o") + includes = [] if os.name == "nt" else ["-I", str(host / "posix")] + subprocess.run([args.cxx, "-x", "c", *includes, "-c", str(host / "oot_title_movie.c"), + "-o", str(obj)], check=True) + subprocess.run([args.cxx, "-I", str(host), str(source), str(obj), "-pthread", "-o", str(exe)], check=True) + env = os.environ.copy() + env.pop("HOS_WIDE_KEEP", None) + subprocess.run([str(exe)], env=env, check=True) + + +if __name__ == "__main__": + main() diff --git a/tests/test_oot_wide_save_picture.py b/tests/test_oot_wide_save_picture.py index bac37ba..94df33e 100644 --- a/tests/test_oot_wide_save_picture.py +++ b/tests/test_oot_wide_save_picture.py @@ -26,6 +26,7 @@ FIXTURE = r""" #include typedef struct { uint64_t x[32]; } Ctx; volatile float hos_wide_ratio; +int hos_movie_cover_viewport(uint64_t *y, uint64_t *h) { (void)y; (void)h; return 0; } /* no movie drew */ #define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); exit(1); } } while (0) static void site(Ctx *c) { SITE_C diff --git a/tests/test_options_writers.py b/tests/test_options_writers.py index f46bd42..b296de8 100644 --- a/tests/test_options_writers.py +++ b/tests/test_options_writers.py @@ -78,6 +78,7 @@ struct Host { int (*binding)(int set, int i, int k); }; const Host host_v{[](int set, int i, int k) { return binds[set][i][k]; }}; const Host* host = &host_v; bool can_bind() { return true; } +struct { unsigned w, h; } remembered_custom{}; std::string mic_want; std::string the_path; std::string ini_path() { return the_path; } @@ -128,6 +129,8 @@ int main(int argc, char** argv) { const std::string key = colon == std::string::npos ? "" : step.substr(colon + 1, eq - colon - 1); const std::string value = eq == std::string::npos ? "" : step.substr(eq + 1); if (what == "load") load(); + else if (what == "remember") remembered_custom = {3437, 1440}; + else if (what == "clear") remembered_custom = {}; else if (what == "save") save(); else if (what == "outside") outside(key, value); else if (what == "game") { @@ -194,6 +197,12 @@ def main(): return lines(path) start = "alpha=1\nbeta=1\ngamma=1\noptions_version=6\ndiscord_app_id=42\npad_a=3\nkey_a=65,0\nkey_up=87,0\n" + key = "output_custom_size" + check(key not in run("absent", start, ["load", "save", "save"]), "no empty Custom line added") + check(run("remember", start, ["load", "remember", "save"]).get(key) == "3437x1440", "entered Custom written") + check(run("clear", start, ["load", "remember", "save", "clear", "save"]).get(key) == "", "existing Custom cleared") + check(run("external", start, ["load", "outside:output_custom_size=800x600", "save", "save"]).get(key) == "800x600", + "Custom added outside survives unrelated saves") got = run("both", start, ["load", "outside:beta=7", "game:alpha=2", "save"]) check(got.get("alpha") == "2" and got.get("beta") == "7", "a row changed outside and another in the game within a second: both survive (%s)" % got) diff --git a/tests/test_output_migration.py b/tests/test_output_migration.py new file mode 100644 index 0000000..5e4e27f --- /dev/null +++ b/tests/test_output_migration.py @@ -0,0 +1,58 @@ +"""Keep stock 0.6 and native 0.5.2 options distinct despite their shared version 8.""" +import argparse +import subprocess +import tempfile +from pathlib import Path + +RUN_ALL_ARGS = ["--cxx", "{cxx}"] +ROOT = Path(__file__).resolve().parents[1] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--cxx", default="clang++") + args = parser.parse_args() + source = r''' +#include "gpu/vk/output_sizes.h" +#include "gpu/vk/merged_rows.h" +#include +int main() { + static_assert(OUTPUT_SCREEN == 8 && OUTPUT_CUSTOM == 9); + static_assert(OUTPUT_OPTIONS_VERSION == 9); + // Stock 0.6's handheld, and fixed sizes with a different aspect row. + assert(output_file_read(7, 8, 2, 0) == 7); + assert(output_file_read(4, 8, 2, 0) == 1); + assert(output_file_read(6, 8, 3, 0) == 2); + // Native files always wrote size fields, including under fixed choices. + assert(output_file_read(7, 8, 2, 1) == OUTPUT_SCREEN); + assert(output_file_read(8, 8, 2, 1) == OUTPUT_CUSTOM); + assert(output_file_read(4, 8, 2, 1) == 4); + assert(output_file_read(6, 8, 3, 1) == 6); + assert(output_file_read(7, 7, 2, 0) == OUTPUT_SCREEN); + assert(output_file_read(8, 7, 2, 0) == OUTPUT_CUSTOM); + for (int v = 0; v <= OUTPUT_LAST; ++v) + for (int row = 0; row != 4; ++row) + assert(output_file_read(v, 9, row, 1) == v); + // The player's active pair remains the native 12:5 picture. + unsigned w, h; + assert(output_size_used(3840, 1600, &w, &h)); + assert(w == 3840 && h == 1600 && output_frame_width(h) == 2848); + // Native v8 predates stock's merged rows: retain handheld and stick meaning. + mkwvk::merged_rows::Before7 old; + old.handheld = 1; old.stick_shared = 3; + int out = OUTPUT_CUSTOM, left = -1, right = 30; + mkwvk::merged_rows::migrate(7, old, out, left, right); + assert(out == 7 && left == 15 && right == 30); +} +''' + with tempfile.TemporaryDirectory() as tmp: + cpp = Path(tmp) / "migration.cpp" + exe = Path(tmp) / "migration.exe" + cpp.write_text(source, encoding="utf-8") + subprocess.run([args.cxx, "-std=c++17", "-I", str(ROOT), str(cpp), "-o", str(exe)], check=True) + subprocess.run([str(exe)], check=True) + print("PASS: stock/native migration and version-9 round trip") + + +if __name__ == "__main__": + main() diff --git a/tests/test_output_resolution.py b/tests/test_output_resolution.py index 73f32be..c67589c 100644 --- a/tests/test_output_resolution.py +++ b/tests/test_output_resolution.py @@ -1,4 +1,18 @@ -"""Exercise the host and menu's docked output sizes without a game dump.""" +"""Exercise the host and menu's docked output sizes without a game dump. + +The rule (gpu/vk/output_sizes.h): the Output resolution is the picture's size, the game's frame 16:9 at its height. A size +that is not 16:9 (5120x1440, 5120x2160, a screen's or a Custom one of such a shape) is a picture of exactly that size, +whatever the Ultrawide row says; a 16:9 size takes the row's shape. + +The row offers the fixed sizes and the size of every connected screen, by the monitor's name. A screen's size is saved as +a size (Custom's, output_width= and output_height=), never as a place in the list of screens: the same options file gives +the same picture whichever screens are connected, in whatever order, and a size whose screen is gone is Custom. An old +file's output_res=7 (Screen) is the screen the window opens on, as it was, and the menu keeps it as that size. + +host/nn_applet.c's own code (the size, the frame, the shape, the render target pool) and gpu/vk/vk_menu.cpp's (the row's +choices, their texts and order, the picture shown), cut out and run on the same options file and the same screens, must +agree. +""" import argparse import os import subprocess @@ -9,6 +23,49 @@ RUN_ALL_ARGS = ["--cxx", "{cxx}"] ROOT = Path(__file__).resolve().parents[1] +FIXED = ((2048, 1152), (2560, 1440), (3840, 2160), (1920, 1080), (5120, 1440), (5120, 2880), (5120, 2160), (1536, 864)) + + +def size(text): + """'3840x1600' as (w, h)""" + w, h = text.split("x") + return int(w), int(h) + + +def names(screens, at): + """The screens of a size by name: once each, counted where several share one; one without a name is 'Screen'""" + seen = [] + for used, name in screens: + if size(used) == at: + seen.append(name or "Screen") + return ", ".join(("%dx " % seen.count(n) if seen.count(n) > 1 else "") + n for n in dict.fromkeys(seen)) + + +def row_labels(screens, custom, env=False, legacy=None, remembered=None): + """The row's choices in its order, by this file's own rule: the fixed sizes (a screen of one of them named there, but not + at the game's own 2048x1152), each other screen size once, the old Screen while it is still chosen, and Custom unless a + screen has its size. Smallest to largest by width then height, of one size in that order, one with no size at the end. + screens: (the size the game takes it at, name); custom: its size, None for none; legacy: the old Screen's size or ''""" + entries = [] + for v, at in enumerate(FIXED): + who = "handheld" if v == 7 else names(screens, at) if v else "" + entries.append((at, "%dx%d" % at + (" (%s)" % who if who else ""))) + own = [] + for used, _ in screens: + if not env and size(used) not in FIXED[1:7] and size(used) not in own: + own.append(size(used)) + entries.append((size(used), "%s (%s)" % (used, names(screens, size(used))))) + if legacy is not None: + who = names(screens, size(legacy)) if legacy else "" + entries.append((size(legacy) if legacy else None, ("%s (%s)" % (legacy, who) if who else "Screen (%s)" % legacy) if legacy + else "Screen (not known)")) + if custom is None or size(custom) not in own: + entries.append((size(custom) if custom else None, "Custom (%s)" % (custom or "not set"))) + if remembered and remembered != custom and size(remembered) not in own: + entries.append((size(remembered), "Custom (%s)" % remembered)) + entries.sort(key=lambda e: (e[0] is None, e[0] or (0, 0))) # (stable: of one size as added) + return "|".join(label for _, label in entries) + def main(): parser = argparse.ArgumentParser(description=__doc__) @@ -17,22 +74,117 @@ def main(): host = (ROOT / "host/nn_applet.c").read_text(encoding="utf-8") menu = (ROOT / "gpu/vk/vk_menu.cpp").read_text(encoding="utf-8") + + def check(cond, what): + if not cond: + raise SystemExit("FAIL: " + what) + + # the Custom size's rows: output_width= and output_height= by their names, with a restart, shown while Custom or a screen's + # size is chosen, fixed while HOS_OUTPUT_SIZE sets the size; the file's version says that the 5120-wide sizes are pictures + for name, value, lo, hi in (("Output width", "output_width", "OUTPUT_MIN_W", "OUTPUT_MAX_W"), + ("Output height", "output_height", "OUTPUT_MIN_H", "OUTPUT_MAX_H")): + row = menu.find('{TAB_DISPLAY, "%s", &opts.%s, %s, %s, 8, ' % (name, value, lo, hi)) + check(row > menu.find('{TAB_DISPLAY, "Output resolution", &opts.output_res') > 0, "the menu has no %s row under Output resolution" % name) + check(menu[row:menu.index("},", row)].rstrip().endswith("nullptr, true"), "the %s row is not read at the start (a restart)" % name) + shown = menu[menu.index("bool row_shown(int i) {"):menu.index("\n}\n", menu.index("bool row_shown(int i) {"))] + check("((rows[i].value != &opts.output_width && rows[i].value != &opts.output_height) ||" in shown + and "output_choice(opts.output_res) == OUTPUT_CUSTOM) &&" in shown, "the Custom size's rows show without Custom chosen") + check("if ((value == &opts.output_width || value == &opts.output_height) && custom_env()) return true;" in menu, + "the Custom size's rows can be changed while HOS_OUTPUT_SIZE sets the size") + check('out += "options_version=9\\n";' in menu, "the options file is not written as version 8 (output_sizes.h OUTPUT_OPTIONS_VERSION)") + check("#define OUTPUT_OPTIONS_VERSION 9" in (ROOT / "gpu/vk/output_sizes.h").read_text(encoding="utf-8"), + "output_sizes.h: the 5120-wide sizes are not pictures from options_version 8") + check("rows[i].name != kUseWindowSize || (opts.output_res == OUTPUT_CUSTOM && !custom_env())" in shown + and "use_window_size(dev.swap_extent.width, dev.swap_extent.height);" in menu, + "the Custom copy action must use the drawable size and respect the environment override") + # the row walks its choices, a screen's size among them, and menu_init takes the screens and an old file's Screen + check('custom_rows_read(side("output_width"), side("output_height"));' in menu[menu.index("void menu_init() {"):], + "menu_init does not read Custom's size from the file's own two numbers (custom_rows_read)") + sizes_h = (ROOT / "gpu/vk/output_sizes.h").read_text(encoding="utf-8") + used = sizes_h[sizes_h.index("static inline int output_size_used("):sizes_h.index("/* output_width= and output_height= as an options file")] + check("output_width_range(uh, wide, &lo, &hi);" in used and "for (" not in used and "while (" not in used, + "output_sizes.h: output_size_used does not choose the width in one step from the widths its height allows") + check("output_custom_read(&w, &h);" in host, "nn_applet.c does not read Custom's size as the menu does (output_custom_read)") + check("if (!output_step(dir, true)) return;" in menu[menu.index("void set_row(Row& r, int v, int dir, bool keep"):], + "set_row does not walk the Output resolution row's choices (output_step)") + init = menu[menu.index("void menu_init() {"):] + check("screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0);" in init and + init.index("output_adopt_screen();") > init.index("screen_add(list[i].w"), "menu_init does not take the host's screens, then an old file's Screen") + # (walking the row past a screen's size leaves that size in the Custom rows: no restart is asked for them under a fixed size) + check("restart_inert(rows[i]) ? restart_state.start[restart_slot[i]] : restart_value_of(rows[i])" in menu, + "the Custom size's rows ask for a restart while a fixed size is chosen") + # the screens go from the host to the menu through MkwVkHost, at its end (the interface's version with it) + api = (ROOT / "gpu/vk/vk_api.h").read_text(encoding="utf-8") + check(" int (*screens)(MkwVkScreen *out, int cap);\n" in api and api.index("int (*screens)(") > api.index("int (*bench)("), + "vk_api.h: MkwVkHost has no screens after bench") + backend = (ROOT / "host/rx_backend.c").read_text(encoding="utf-8") + check("host_romfs_dir, host_wide_menus, hos_bench_state, hos_prompts_pad_face, host_screens, " in backend, + "rx_backend.c does not give the menu the host's screens") + fixture = r''' #include #include +#include #include #include #include #include #include +#include +#include +#include +#include "gpu/vk/output_sizes.h" +#include "gpu/vk/ultrawide_rows.h" +#include "host/hos_screens.h" using DWORD = unsigned long; constexpr int MAX_PATH = 260; +constexpr int SM_CXSCREEN = 0, SM_CYSCREEN = 1; +// (the connected screens: TEST_SCREENS=x=;..., a '*' before the size of the one the window opens on, else the +// first; none set: no screen known) +int hos_screens(HosScreen *out, int cap) { + const char *e = getenv("TEST_SCREENS"); + int n = 0, opens = -1; + std::string all = e ? e : ""; + while (!all.empty() && n < cap) { + std::string one = all.substr(0, all.find(';')); + all = all.find(';') == std::string::npos ? "" : all.substr(all.find(';') + 1); + const bool star = one[0] == '*'; + if (star) one = one.substr(1), opens = n; + long w = 0, h = 0; + if (!output_parse_size(one.substr(0, one.find('=')).c_str(), &w, &h)) abort(); + out[n] = HosScreen{(int)w, (int)h, 0, {}}; + snprintf(out[n].name, sizeof out[n].name, "%s", one.find('=') == std::string::npos ? "" : one.substr(one.find('=') + 1).c_str()); + n++; + } + if (n) out[opens < 0 ? 0 : opens].opens = 1; + return n; +} +void hos_screen_size(int *w, int *h) { // (host/display.c: the one the window opens on) + HosScreen list[16]; + const int n = hos_screens(list, 16); + *w = *h = 0; + for (int i = 0; i < n; i++) + if (list[i].opens) *w = list[i].w, *h = list[i].h; +} +int GetSystemMetrics(int i) { // (the main monitor, for an old file's Monitor's shape: the first screen) + HosScreen list[16]; + return hos_screens(list, 16) ? (i == SM_CYSCREEN ? list[0].h : list[0].w) : 0; +} DWORD hos_game_path_a(char *path, int size) { return snprintf(path, size, "./hookshot.exe"); } -void hos_log(const char *, ...) {} +#include +static std::string logged; // (the host's log lines of the run, each ended) +void hos_log(const char *format, ...) { + char line[600]; + va_list args; + va_start(args, format); + vsnprintf(line, sizeof line, format, args); + va_end(args); + logged += line, logged += '\n'; +} volatile uint64_t hos_wide_out = 0; // (host/hos_main.c: the widescreen picture, 0 = none; nn_applet.c reads it) int hos_scene_rgba16f(void) { return 0; } // (host/nn_vi.c: the scene's colour target, the game's own here; tests/test_rt_pool_minimum.py has the RGBA16F cases) -struct { int handheld, output_res; } opts; +struct { int handheld, output_res, output_width, output_height, ultrawide; } opts; namespace mkwvk { int up_now = 0; // (the Upscaler shown: 0 the game's own, 1 DLSS, 2 DLAA) int upscaler() { return up_now; } @@ -41,83 +193,401 @@ int upscaler() { return up_now; } #include "gpu/vk/merged_rows.h" // ((Triforce, options_version 7) the Output resolution's handheld profile, 7) using namespace mkwvk; namespace ur = upscaler_rows; +#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); failed = 1; } } while (0) +#define CHECK_STR(got, want) do { const std::string g_ = (got), w_ = (want); if (g_ != w_) { \ + fprintf(stderr, "FAIL:%d %s is \"%s\", expected \"%s\"\n", __LINE__, #got, g_.c_str(), w_.c_str()); failed = 1; } } while (0) +static int failed; +static std::string wxh(unsigned w, unsigned h) { return std::to_string(w) + "x" + std::to_string(h); } +// (the second build: the menu's code as it is off Windows, whatever this PC is. After every system header) +#ifdef FIXTURE_OFF_WINDOWS +#undef _WIN32 +#endif ''' + host[host.index("int hos_ini_option(const char *key, int otherwise);"):host.index("HLE(_ZN2nn2oe16GetOperationModeEv)")] + menu[ menu.index("struct Out {"):menu.index("/// The Render resolution: the value chosen")] + menu[ - menu.index("const char* tx_output_res("):menu.index("const char* tx_speed(")] + r''' + menu.index("const char* tx_output_res("):menu.index("const char* tx_speed(")] + menu[ + menu.index("const char* tx_ultrawide(int v) {"):menu.index("const char* tx_wide_hud(")] + r''' +struct Row { int* value; }; +Row rows[] = {{&opts.output_width}, {&opts.output_height}}; +static int saves; +void save() { ++saves; } +void set_row(Row& row, int value, int, bool keep) { *row.value = value; if (keep) save(); } +''' + menu[menu.index("void use_window_size("):menu.index("// ---- (hookshot) the Controls page:")] + r''' +static std::string labels() { + std::string all; + for (const OutEntry& x : output_entries()) all += (all.empty() ? "" : "|") + output_label(x); + return all; +} int main(int argc, char **argv) { - assert(argc == 5); + assert(argc == 10); const int mode = atoi(argv[1]); - const unsigned w = atoi(argv[2]), h = atoi(argv[3]); - assert(output_mode() == mode); - assert(hos_output_size(0) == w && hos_output_size(1) == h); - assert(hos_rt_pool_size(305ull << 20) == ((mode == 2 ? 687ull : mode == 4 ? 610ull : mode == 5 || mode == 6 ? 900ull : 512ull) << 20)); // (512 MB at least: nn_applet.c) - // ((Triforce, options_version 7) 7 is 1536x864, the handheld profile, the smallest: first in the row) - assert(kLastOutput == 7 && merged_rows::kHandheldOutput == 7); - assert(output_choice(-1) == 0 && output_choice(4) == 4 && output_choice(5) == 5 && output_choice(6) == 6 && output_choice(7) == 7 && - output_choice(8) == 0); - assert(step_output_choice(7, -1) == 7 && step_output_choice(7, 1) == 3 && step_output_choice(3, -1) == 7); - assert(strcmp(tx_output_res(7), "1536x864 (handheld)") == 0); - assert(step_output_choice(3, 1) == 0 && step_output_choice(0, -1) == 3); - assert(step_output_choice(0, 1) == 1 && step_output_choice(1, -1) == 0); - assert(step_output_choice(1, 1) == 2 && step_output_choice(2, -1) == 1); - assert(step_output_choice(2, 1) == 4); - assert(step_output_choice(4, -1) == 2 && step_output_choice(4, 1) == 6); // ((Triforce) 5120x2160 between 5120x1440 and 5120x2880) - assert(step_output_choice(6, -1) == 4 && step_output_choice(6, 1) == 5); - assert(step_output_choice(5, -1) == 6 && step_output_choice(5, 1) == 5); - opts.output_res = mode; + // ---- the host: the size chosen, the game's frame, the size's own shape + CHECK(output_mode() == mode); + CHECK_STR(wxh(hos_output_size(0), hos_output_size(1)), argv[2]); + CHECK_STR(std::to_string((int)(hos_output_ratio() * 10000.0f + 0.5f)), argv[5]); + // (the picture as host/hos_main.c makes it: the size's own shape, else the Ultrawide row's; tests/test_ultrawide_shapes.py + // runs that block itself) + const int version = hos_ini_option("options_version", 0); + const int row = ultrawide_row_read(hos_ini_option("ultrawide", 0), version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + unsigned pw = 0, ph = 0; + const float own = hos_output_ratio(); + if (output_picture(hos_output_size(1), own > 0.0f ? own : ultrawide_row_ratio(row), own > 0.0f, &pw, &ph)) + hos_wide_out = (uint64_t)ph << 32 | pw; + const std::string picture = pw ? wxh(pw, ph) : std::string(mode ? argv[2] : "2048x1152"); + if (mode) CHECK_STR(picture, argv[8]); + CHECK_STR(std::to_string(hos_rt_pool_size(305ull << 20) >> 20), argv[4]); // (512 MB at least: nn_applet.c) + // (TEST_LOG pins the explanation of an older file's migrated choice or picture) + if (const char* want = getenv("TEST_LOG")) { + if (logged.find(want) == std::string::npos) fprintf(stderr, "FAIL: the log has no \"%s\":\n%s", want, logged.c_str()), failed = 1; + } + + // ---- the menu, as menu_init has it from the same file and the same screens opts.handheld = handheld(); - assert(strcmp(tx_output_res(mode), argv[4]) == 0); - if (opts.handheld) opts.output_res = 7; // (the menu's row: the handheld profile, as menu_init reads it, merged_rows.h migrate) + // (Custom's rows from the file's own two numbers, 0 with no line: menu_init) + custom_rows_read(hos_ini_option("output_width", 0), hos_ini_option("output_height", 0)); + HosScreen list[16]; + const int n = hos_screens(list, 16); + for (int i = 0; i < n; i++) screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0); + // (an old file's Ultrawide row by the main monitor, the host's on every system: main_screen) + opts.ultrawide = ultrawide_row_read(std::min(std::max(hos_ini_option("ultrawide", 0), 0), 3), version, (int)main_screen().w, (int)main_screen().h); + CHECK(opts.ultrawide == std::min(std::max(row, 0), 3)); + opts.output_res = output_file_read(hos_ini_option("output_res", 0), version, opts.ultrawide, output_size_fields()); + if (const char* e = getenv("HOS_OUTPUT_RES")) opts.output_res = output_choice(atoi(e)); + if (opts.handheld) opts.output_res = 7; + output_adopt_screen(); + CHECK(kLastOutput == 9); + CHECK(output_choice(-1) == 0 && output_choice(4) == 4 && output_choice(6) == 6 && output_choice(7) == 7 && output_choice(8) == 8 && output_choice(9) == 9 && output_choice(10) == 0); + // (the row's choices, smallest to largest: the fixed sizes, the screens' among them by name, Custom; and the one chosen) + CHECK_STR(labels(), argv[6]); + CHECK_STR(tx_output_res(opts.output_res), argv[3]); + // (the menu's choice runs what the host runs: its frame and its picture, the Render resolution's 100%) + if (!opts.handheld) { + CHECK_STR(wxh(output_frame(opts.output_res).w, output_frame(opts.output_res).h), mode ? argv[2] : "2048x1152"); + CHECK(output_shaped(opts.output_res) == (own > 0.0f)); + } unsigned scene_w, scene_h; game_size(1.0f, scene_w, scene_h); - assert(scene_w == (opts.handheld ? 1536 : mode ? w : 2048)); - assert(scene_h == (opts.handheld ? 864 : mode ? h : 1152)); - if (mode == 3) assert(strcmp(tx_resolution(2), "75% (1440x810)") == 0); - if (mode == 3) { // (DLSS at 1080p: its modes' render sizes, each a twelfth of the output, exact; DLAA the full size) + CHECK_STR(wxh(scene_w, scene_h), argv[8]); + CHECK_STR(tx_shape(opts.ultrawide), argv[7]); // (the Ultrawide row: its choice, or the size's own shape) + CHECK(shape_owner() == (own > 0.0f ? 1 : 0)); + // (the Custom rows: their sides as chosen, HOS_OUTPUT_SIZE's while it is set; the size the game makes of them is the row's) + CHECK_STR(std::string(tx_custom_width(opts.output_width)) + "x" + tx_custom_height(opts.output_height), argv[9]); + if (mode == 3 && !pw) CHECK_STR(tx_resolution(2), "75% (1440x810)"); + if (mode == 3 && !pw) { // (DLSS at 1080p: its modes' render sizes, each a twelfth of the output, exact; DLAA the full size) up_now = ur::DLSS; - assert(strcmp(tx_resolution(3), "Quality (67%)") == 0 && strcmp(tx_resolution(6), "Ultra Performance (33%)") == 0); + CHECK(strcmp(tx_resolution(3), "Quality (67%)") == 0 && strcmp(tx_resolution(6), "Ultra Performance (33%)") == 0); const unsigned want[][3] = {{3, 1280, 720}, {5, 1120, 630}, {4, 960, 540}, {6, 640, 360}}; for (const auto& m : want) { game_size(ur::percent(m[0]) / 100.0f, scene_w, scene_h); - assert(scene_w == m[1] && scene_h == m[2] && scene_w * 1080 == scene_h * 1920); + CHECK(scene_w == m[1] && scene_h == m[2] && scene_w * 1080 == scene_h * 1920); } up_now = ur::DLAA; // ((Triforce, options_version 7) the Render resolution's Native (100%) step) - assert(strcmp(tx_resolution(1), "Native (100%)") == 0); + CHECK(strcmp(tx_resolution(1), "Native (100%)") == 0); up_now = ur::GAME; } + if (pw == 3840 && ph == 1600) CHECK_STR(tx_resolution(2), "75% (2880x1200)"); // (the 3D's size is the picture's share) + + // ---- a size from outside keeps its shape (5:4 to 32:9) whatever its sides, stays within every limit and on its side of + // 16:9, and what comes out is taken as itself when given again (the menu saves it and the host reads it back): at once, + // by how its width is chosen (output_width_range), with no second try + for (long w = 200; w <= 12000; w += 61) + for (long h = 120; h <= 6000; h += 37) { + unsigned uw = 0, uh = 0, vw = 0, vh = 0; + CHECK(output_size_used(w, h, &uw, &uh) && output_size_used(uw, uh, &vw, &vh)); + const double in = std::min(std::max((double)w / h, OUTPUT_SHAPE_MIN), OUTPUT_SHAPE_MAX), out = (double)uw / uh; + const bool side = output_shape_is_game(in) ? output_shape_is_game(out) + : !output_shape_is_game(out) && (in > 16.0 / 9.0) == (out > 16.0 / 9.0); + if (uw != vw || uh != vh || uw % 8 || uw < OUTPUT_MIN_W || uw > OUTPUT_MAX_W || uh < OUTPUT_MIN_H || uh > OUTPUT_MAX_H || + (double)uw * uh > OUTPUT_MAX_PIXELS || std::fabs(out / in - 1.0) > 0.011 || // (8 pixels of width, or 16:9's 1%) + out > OUTPUT_SHAPE_MAX || out < OUTPUT_SHAPE_MIN || !side) { + fprintf(stderr, "FAIL: %ldx%ld is taken as %ux%u (again: %ux%u)\n", w, h, uw, uh, vw, vh); + failed = 1; + } + } + { + unsigned uw = 0, uh = 0; + CHECK(output_size_used(7680, 4320, &uw, &uh) && uw == 5120 && uh == 2880); // (not 7680x2880's 2.67:1) + CHECK(output_size_used(3840, 1600, &uw, &uh) && uw == 3840 && uh == 1600); + CHECK(!output_size_used(0, 1440, &uw, &uh) && !output_size_used(2560, -1, &uw, &uh)); + } + + // ---- walking the row: each step is the next choice of the row as it is then, to both ends; a screen's size is taken as + // Custom's size (a size, not a place among the screens), a fixed size as its number + for (int dir = -1; dir <= 1; dir += 2) { + for (int guard = 0; guard < 64; guard++) { + const std::vector before = output_entries(); + const int at = output_entry_now(before); + CHECK(output_step(dir, false) == (dir < 0 ? at > 0 : at + 1 < (int)before.size())); + if (!output_step(dir, true)) break; + const OutEntry& to = before[at + dir]; + CHECK_STR(tx_output_res(opts.output_res), output_label(to)); + CHECK(opts.output_res == to.id); + if (to.native.h) { + CHECK(opts.output_res == OUTPUT_CUSTOM && custom_size().w == to.size.w && custom_size().h == to.size.h); + // (saved as the game takes it: what the rows hold is the picture, and reads back as itself) + CHECK(opts.output_width == (int)to.size.w && opts.output_height == (int)to.size.h); + } + } + CHECK(!output_step(dir, false)); + } + // A non-rounded input survives a screen selection, restart and unplug. The disconnected + // picture continues to use the saved screen size until the player chooses Custom again. + if (!custom_env()) { + screens.clear(); + screen_add(3840, 1600, "Monitor", true); + opts.output_res = OUTPUT_CUSTOM; + remembered_custom = {}; + custom_rows_read(3437, 1440); + CHECK(output_step(1, true)); + CHECK(opts.output_width == 3840 && opts.output_height == 1600); + CHECK(remembered_custom.w == 3437 && remembered_custom.h == 1440); + remembered_custom = {}; + opts.output_res = 2; + read_remembered_custom("3437x1440"); + CHECK(remembered_custom.w == 3437 && remembered_custom.h == 1440); + screens.clear(); + CHECK(labels().find("Custom (3840x1600)") == std::string::npos); + CHECK(labels().find("Custom (3440x1440)") != std::string::npos); + opts.output_res = OUTPUT_CUSTOM; + screens.clear(); + CHECK_STR(tx_output_res(opts.output_res), "Custom (3840x1600)"); + CHECK(output_step(-1, true)); + CHECK(opts.output_width == 3437 && opts.output_height == 1440 && !remembered_custom.h); + use_window_size(0, 1080); + CHECK(!saves && opts.output_width == 3437 && opts.output_height == 1440); + use_window_size(7680, 4320); + CHECK(saves == 1 && opts.output_width == 5120 && opts.output_height == 2880); + use_window_size(3840, 1600); + CHECK(saves == 2 && opts.output_width == 3840 && opts.output_height == 1600); + } + return failed; } ''' + v8 = "options_version=9\n" + lg, dell = "LG ULTRAGEAR", "DELL U2720Q" + + def case(saved, mode, frame, now, pool, *, picture=None, shape=0, row="16:9", ini="", handheld=0, res=None, screens=(), + env_size=None, custom="2560x1440", rows=None, legacy=None, log=None, remembered="2560x1440"): + """saved, handheld, HOS_OUTPUT_RES, the screens ((native size, name) or (native, name, the size the game takes it + at), a '*' before the native size of the one the window opens on), the ini's other lines, HOS_OUTPUT_SIZE -> the + host's mode and frame, the row's text now, the pool in MB, the size's own shape x 10000, the Ultrawide row's text, + the picture, Custom's size as the game takes it (None: none), the Custom rows' texts, the old Screen still chosen, + and an optional migration log expectation; remembered is Custom's saved size before adopting Screen""" + # Cases retain the audited branch's numbering in their declarations. + # Current fixtures use 8/9; old-version fixtures exercise migration from 7/8. + old_screen = res == "7" or res is None and saved == 7 + if ini.startswith("options_version=9") and saved in (7, 8): saved += 1 + if mode in (7, 8): mode += 1 + if res in ("7", "8"): res = str(int(res) + 1) + if handheld: now, custom = "1536x864 (handheld)", "2560x1440" + used = [(s[2] if len(s) > 2 else s[0].lstrip("*"), s[1]) for s in screens] + return (saved, handheld, res, ";".join(s[0] + ("=" + s[1] if s[1] else "") for s in screens), ini, env_size, mode, frame, now, + pool, shape, row_labels(used, custom, env_size is not None, legacy, + remembered if old_screen and not handheld and env_size is None + and now.split(" (")[0] not in ("%dx%d" % f for f in FIXED[1:7]) and screens else None), row, + picture or ("2048x1152" if mode == 0 else frame), rows or custom or "Not setxNot set", log) + cases = ( - (0, 0, None, 0, 2560, 1440, "2048x1152"), - (1, 0, None, 1, 2560, 1440, "2560x1440"), - (2, 0, None, 2, 3840, 2160, "3840x2160"), - (3, 0, None, 3, 1920, 1080, "1920x1080"), - (1, 0, "3", 3, 1920, 1080, "1920x1080"), - (3, 1, "3", 0, 2560, 1440, "2048x1152"), - (4, 1, None, 0, 2560, 1440, "2048x1152"), - (7, 0, None, 0, 2560, 1440, "2048x1152"), - (5, 0, None, 5, 5120, 2880, "5120x2880"), - (4, 0, None, 4, 5120, 1440, "5120x1440"), - (6, 0, None, 6, 5120, 2160, "5120x2160"), - (1, 0, "6", 6, 5120, 2160, "5120x2160"), - # ((Triforce, options_version 7) the handheld profile as the Output resolution's 7, saved or for a run) - (1, 0, "7", 0, 2560, 1440, "2048x1152"), - (8, 0, None, 0, 2560, 1440, "2048x1152"), + # ---- the fixed 16:9 sizes: the game's frame, and its picture with Ultrawide on 16:9 + case(0, 0, "2560x1440", "2048x1152", 512, ini=v8), + # A monitor at the handheld profile's size is still a docked Custom picture. + case(7, 7, "1536x864", "1536x864 (Screen)", 512, ini=v8, + screens=[("1536x864", "")], custom="1536x864"), + case(1, 1, "2560x1440", "2560x1440", 512, ini=v8), + case(2, 2, "3840x2160", "3840x2160", 687, ini=v8), + case(3, 3, "1920x1080", "1920x1080", 512, ini=v8), + case(1, 3, "1920x1080", "1920x1080", 512, ini=v8, res="3"), + # (the handheld profile runs the game's own output; the row keeps the choice for docked) + case(3, 0, "2560x1440", "1920x1080", 512, ini=v8, res="3", handheld=1, picture="1536x864"), + case(4, 0, "2560x1440", "5120x1440", 512, ini=v8, handheld=1, picture="1536x864"), + case(10, 0, "2560x1440", "2048x1152", 512, ini=v8), + case(5, 5, "5120x2880", "5120x2880", 900, ini=v8), + # (a 16:9 size takes the Ultrawide row's shape at its height: 21:9 is 64:27 in whole multiples of 8 pixels; at the 4K + # output a 32:9 picture is kept to 3840x2160's pixels, as before) + case(1, 1, "2560x1440", "2560x1440", 512, ini=v8 + "ultrawide=2\n", picture="3416x1440", row="21:9"), + case(3, 3, "1920x1080", "1920x1080", 512, ini=v8 + "ultrawide=1\n", picture="1728x1080", row="16:10"), + case(2, 2, "3840x2160", "3840x2160", 687, ini=v8 + "ultrawide=3\n", picture="5400x1520", row="32:9"), + case(0, 0, "2560x1440", "2048x1152", 610, ini=v8 + "ultrawide=3\n", picture="4096x1152", row="32:9"), + # ---- the fixed sizes that are not 16:9: the picture itself, the frame 16:9 at its height, whatever the row says + case(4, 4, "2560x1440", "5120x1440", 610, ini=v8, picture="5120x1440", shape=35556, row="32:9 (5120x1440)"), + case(6, 6, "3840x2160", "5120x2160", 900, ini=v8, picture="5120x2160", shape=23704, row="21:9 (5120x2160)"), + case(1, 6, "3840x2160", "5120x2160", 900, ini=v8, res="6", picture="5120x2160", shape=23704, row="21:9 (5120x2160)"), + case(4, 4, "2560x1440", "5120x1440", 610, ini=v8 + "ultrawide=2\n", picture="5120x1440", shape=35556, + row="32:9 (5120x1440)"), + # (a file from before options_version 8, where they were the game's frame: with the row on their own shape or on 16:9 + # they stay, the picture theirs; with the row on another shape the 16:9 size of their height, the same picture) + case(4, 4, "2560x1440", "5120x1440", 610, ini="options_version=7\nultrawide=3\n", picture="5120x1440", shape=35556, + row="32:9 (5120x1440)"), + case(4, 4, "2560x1440", "5120x1440", 610, ini="options_version=7\n", picture="5120x1440", shape=35556, + row="32:9 (5120x1440)"), + case(4, 1, "2560x1440", "2560x1440", 512, ini="options_version=7\nultrawide=2\n", picture="3416x1440", row="21:9", + log="oe: output resolution 5120x1440 with Ultrawide on another shape, from before options_version 9: " + "2560x1440 now, the same picture"), + case(6, 6, "3840x2160", "5120x2160", 900, ini="options_version=7\nultrawide=2\n", picture="5120x2160", shape=23704, + row="21:9 (5120x2160)"), + case(6, 2, "3840x2160", "3840x2160", 687, ini="options_version=7\nultrawide=3\n", picture="5400x1520", row="32:9"), + case(6, 2, "3840x2160", "3840x2160", 687, ini="options_version=7\nultrawide=1\n", picture="3456x2160", row="16:10"), + # (before options_version 6 the row's 1 was the monitor's shape: on a 5120x1440 monitor 32:9, 5120x1440's own; the + # screen of a fixed size is named at that size) + case(4, 4, "2560x1440", "5120x1440 (Screen)", 610, ini="options_version=5\nultrawide=1\n", screens=[("5120x1440", "")], + picture="5120x1440", shape=35556, row="32:9 (5120x1440)"), + # (the same row at a 16:9 size, on a 3440x1440 monitor: 21:9 for the host and for the menu, on every system) + case(1, 1, "2560x1440", "2560x1440", 512, ini="options_version=5\nultrawide=1\n", screens=[("3440x1440", lg)], + picture="3416x1440", row="21:9"), + + # Stock 0.7 ignores the retired profile line at version 8; native 0.6's version 9 still carries it. + case(1, 1, "2560x1440", "2560x1440", 512, ini="options_version=8\nhandheld_profile=1\n"), + # Native 0.5.2's numbers move past stock 0.6's handheld without changing the choice or picture. + case(8, 8, "2848x1600", "Custom (3840x1600)", 512, + ini="options_version=8\noutput_width=3840\noutput_height=1600\n", picture="3840x1600", shape=24000, + row="2.40:1 (3840x1600)", custom="3840x1600", + log="oe: output resolution Custom (8) from native 0.5.2: now 9 under options_version 9, the same choice"), + case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, + ini="options_version=8\noutput_width=3840\noutput_height=1600\n", screens=[("3840x1600", "")], + picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600", + log="oe: output resolution Screen (7) from native 0.5.2: now 8 under options_version 9, the same choice", + remembered="3840x1600"), + + # ---- the connected screens: each one's size is a choice, by its name; choosing it saves that size (Custom's) + case(8, 8, "2848x1600", "3840x1600 (2x %s)" % lg, 512, ini=v8 + "output_width=3840\noutput_height=1600\n", + screens=[("3840x1600", lg), ("3840x1600", lg), ("2560x1440", dell)], picture="3840x1600", shape=24000, + row="2.40:1 (3840x1600)", custom="3840x1600"), # (two of one size: one choice; the 2560x1440 one names the fixed size) + # (the same file with the screens in another order, with one of them gone, and with none: the same picture) + case(8, 8, "2848x1600", "3840x1600 (2x %s)" % lg, 512, ini=v8 + "output_width=3840\noutput_height=1600\n", + screens=[("2560x1440", dell), ("3840x1600", lg), ("3840x1600", lg)], picture="3840x1600", shape=24000, + row="2.40:1 (3840x1600)", custom="3840x1600"), + case(8, 8, "2848x1600", "3840x1600 (%s)" % lg, 512, ini=v8 + "output_width=3840\noutput_height=1600\n", + screens=[("3840x1600", lg)], picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), + case(8, 8, "2848x1600", "Custom (3840x1600)", 512, ini=v8 + "output_width=3840\noutput_height=1600\n", + screens=[("2560x1440", dell)], picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), + case(8, 8, "2848x1600", "Custom (3840x1600)", 512, ini=v8 + "output_width=3840\noutput_height=1600\n", + picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), + # (screens of different names at one size, one with no name, and one whose size the game takes smaller) + case(1, 1, "2560x1440", "2560x1440", 512, ini=v8, + screens=[("3440x1440", dell), ("3440x1440", lg), ("1920x1200", ""), ("7680x2160", "Odyssey", "7224x2032")]), + + # ---- an old file's Screen (output_res=7): the screen the window opens on, as it was; the menu keeps it as that size + case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini=v8, screens=[("3840x1600", "")], picture="3840x1600", shape=24000, + row="2.40:1 (3840x1600)", custom="3840x1600"), + case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini=v8 + "ultrawide=2\n", screens=[("3840x1600", "")], + picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), # (not the row's 21:9, 3792x1600) + case(7, 7, "2560x1440", "3440x1440 (%s)" % lg, 512, ini=v8, screens=[("3440x1440", lg)], picture="3440x1440", shape=23889, + row="2.39:1 (3440x1440)", custom="3440x1440"), + case(7, 7, "1920x1080", "2560x1080 (Screen)", 512, ini=v8, screens=[("2560x1080", "")], picture="2560x1080", shape=23704, + row="21:9 (2560x1080)", custom="2560x1080"), + # (an old-version file with Screen or Custom and an Ultrawide row still gets the size's own picture) + case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini="options_version=7\nultrawide=2\n", screens=[("3840x1600", "")], + picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), + case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini="options_version=7\noutput_width=3440\noutput_height=1440\nultrawide=3\n", + picture="3440x1440", shape=23889, row="2.39:1 (3440x1440)", custom="3440x1440"), + case(7, 7, "1920x1080", "2560x1080 (Screen)", 512, ini="options_version=7\nultrawide=2\n", screens=[("2560x1080", "")], + picture="2560x1080", shape=23704, row="21:9 (2560x1080)", custom="2560x1080"), + # (an old-version size above the pixel cap keeps its own shape when reduced) + case(8, 8, "3616x2032", "Custom (7224x2032)", 900, ini="options_version=7\noutput_width=7680\noutput_height=2160\nultrawide=1\n", + picture="7224x2032", shape=35551, row="32:9 (7224x2032)", custom="7224x2032", rows="7680x2160"), + # (the one the window opens on, not the first of the list) + case(7, 7, "2848x1600", "3840x1600 (%s)" % lg, 512, ini=v8, screens=[("2560x1440", dell), ("*3840x1600", lg)], + picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), + # (a screen of a fixed size: that fixed choice, the same picture) + case(7, 7, "2560x1440", "5120x1440 (Screen)", 610, ini=v8, screens=[("5120x1440", "")], picture="5120x1440", shape=35556, + row="32:9 (5120x1440)"), + case(7, 7, "3840x2160", "5120x2160 (Screen)", 900, ini=v8, screens=[("5120x2160", "")], picture="5120x2160", shape=23704, + row="21:9 (5120x2160)"), + case(7, 7, "2560x1440", "2560x1440 (Screen)", 512, ini=v8, screens=[("2560x1440", "")]), + case(7, 7, "2560x1440", "2560x1440 (Screen)", 512, ini=v8 + "ultrawide=2\n", screens=[("2560x1440", "")], + picture="3416x1440", row="21:9"), + case(1, 7, "2136x1200", "1920x1200 (Screen)", 512, ini=v8, res="7", screens=[("1920x1200", "")], picture="1920x1200", + shape=16000, row="16:10 (1920x1200)", custom="1920x1200"), + case(7, 7, "1824x1024", "1280x1024 (Screen)", 512, ini=v8, screens=[("1280x1024", "")], picture="1280x1024", shape=12500, + row="1.25:1 (1280x1024)", custom="1280x1024"), + # (a 16:9 screen 1366 wide: the game's frame at its height; more pixels than 5120x2880's: smaller in its shape) + # (saved as the size the game takes, which reads back as itself) + case(7, 7, "1368x768", "1368x768 (Screen)", 512, ini=v8, screens=[("1366x768", "", "1368x768")], custom="1368x768"), + case(7, 7, "3616x2032", "7224x2032 (Screen)", 900, ini=v8, screens=[("7680x2160", "", "7224x2032")], picture="7224x2032", + shape=35551, row="32:9 (7224x2032)", custom="7224x2032"), + # (a screen taller than 2880 keeps its shape: 7680x4320 is 16:9, the fixed 5120x2880, not 7680x2880's 2.67:1; a + # 5120x3200 one stays 16:10) + case(7, 7, "5120x2880", "5120x2880 (8K)", 900, ini=v8, screens=[("7680x4320", "8K", "5120x2880")]), + case(7, 7, "5120x2880", "4608x2880 (Screen)", 900, ini=v8, screens=[("5120x3200", "", "4608x2880")], picture="4608x2880", + shape=16000, row="16:10 (4608x2880)", custom="4608x2880"), + case(7, 1, "2560x1440", "2560x1440", 512, ini=v8), # (no screen known: 2560x1440) + case(7, 0, "2560x1440", "3840x1600 (Screen)", 512, ini=v8, handheld=1, screens=[("3840x1600", "")], picture="1536x864", + custom="3840x1600"), + # (HOS_OUTPUT_SIZE is Custom's size for the run: the old Screen stays what it is, and no screen's size can be chosen) + case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini=v8, screens=[("3840x1600", "")], env_size="1920x1080", + picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="1920x1080", legacy="3840x1600"), + + # ---- Custom: the ini's size (the Output width and Output height rows), HOS_OUTPUT_SIZE over it + case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini=v8 + "output_width=3440\noutput_height=1440\n", + screens=[("3840x1600", "")], picture="3440x1440", shape=23889, row="2.39:1 (3440x1440)", custom="3440x1440"), + case(8, 8, "1920x1080", "Custom (1920x1080)", 512, ini=v8 + "output_width=3440\noutput_height=1440\n", + env_size="1920x1080", custom="1920x1080"), + case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini=v8 + "output_width=3437\noutput_height=1440\n", + picture="3440x1440", shape=23889, row="2.39:1 (3440x1440)", custom="3440x1440", rows="3437x1440"), + # (a size past the limits keeps its shape and is made smaller or larger in it, for the host as for the menu, whose + # rows then hold the size taken: 10000x5000 is 2:1 at 5120x2880's pixels, 100x100 the squarest picture, 5:4) + case(8, 8, "4824x2712", "Custom (5424x2712)", 900, ini=v8 + "output_width=10000\noutput_height=5000\n", + picture="5424x2712", shape=20000, row="2.00:1 (5424x2712)", custom="5424x2712"), + case(8, 8, "5120x2880", "Custom (5120x2880)", 900, ini=v8 + "output_width=7680\noutput_height=4320\n", + custom="5120x2880"), + case(8, 8, "5120x2880", "Custom (5120x2880)", 900, ini=v8, env_size="7680x4320", custom="5120x2880", rows="7680x4320"), + case(8, 8, "912x512", "Custom (640x512)", 512, ini=v8 + "output_width=100\noutput_height=100\n", picture="640x512", + shape=12500, row="1.25:1 (640x512)", custom="640x512"), + # (the rows' own ends, as the rows can be set: 7680x2880 is 8:3, at 5120x2880's pixels) + case(8, 8, "4168x2344", "Custom (6248x2344)", 900, ini=v8 + "output_width=7680\noutput_height=2880\n", + picture="6248x2344", shape=26655, row="2.67:1 (6248x2344)", custom="6248x2344", rows="7680x2880"), + case(8, 8, "2560x1440", "Custom (2560x1440)", 512, + ini=v8 + "output_width=0\noutput_height=-3\n"), # (a side that is not a size: the row's default) + case(8, 8, "3840x2160", "Custom (5120x2160)", 900, ini=v8 + "output_width=5120\noutput_height=2160\n", + picture="5120x2160", shape=23704, row="21:9 (5120x2160)", custom="5120x2160"), + case(8, 8, "1920x1080", "Custom (3840x1080)", 512, ini=v8 + "output_width=7680\noutput_height=1080\n", + picture="3840x1080", shape=35556, row="32:9 (3840x1080)", custom="3840x1080", rows="7680x1080"), # (32:9 at most) + # (a 16:9 Custom takes the Ultrawide row's shape, as a fixed 16:9 size does) + case(8, 8, "2560x1440", "Custom (2560x1440)", 610, ini=v8 + "output_width=2560\noutput_height=1440\nultrawide=3\n", + picture="5120x1440", row="32:9"), + # (no lines yet: the rows' defaults, 2560x1440, for the host as for the menu; one line: the other side's default) + case(8, 8, "2560x1440", "Custom (2560x1440)", 512, ini=v8), + case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini=v8 + "output_width=3440\n", picture="3440x1440", shape=23889, + row="2.39:1 (3440x1440)", custom="3440x1440"), + case(8, 1, "2560x1440", "Custom (not set)", 512, ini=v8 + "output_width=3440\noutput_height=1440\n", env_size="3440", + custom=None), # (HOS_OUTPUT_SIZE not WxH: not taken, and not the ini's either: the host's 2560x1440) ) with tempfile.TemporaryDirectory(prefix="output-resolution-") as tmp: work = Path(tmp) source, exe = work / "fixture.cpp", work / "fixture.exe" source.write_text(fixture, encoding="utf-8") - subprocess.run([args.cxx, "-std=c++17", "-I", str(ROOT), str(source), "-o", str(exe)], check=True) - for saved, handheld, override, mode, w, h, label in cases: - (work / "triforce_options.ini").write_text(f"output_res={saved}\nhandheld_profile={handheld}\n", encoding="ascii") + # (twice: as this system builds the menu, and as a system that is not Windows does, where it takes the main monitor + # from the host's screens; every case must hold for both) + exes = (exe, work / "fixture_off_windows.exe") + subprocess.run([args.cxx, "-std=c++17", "-I", str(ROOT), str(source), "-o", str(exes[0])], check=True) + subprocess.run([args.cxx, "-std=c++17", "-DFIXTURE_OFF_WINDOWS", "-I", str(ROOT), str(source), "-o", str(exes[1])], check=True) + bad = 0 + for (saved, handheld, override, screens, ini, env_size, mode, frame, now, pool, shape, labels, row, picture, + rows, log) in cases: + (work / "triforce_options.ini").write_text(f"output_res={saved}\nhandheld_profile={handheld}\n{ini}", encoding="ascii") env = os.environ.copy() - for key in ("HOS_OUTPUT_RES", "HOS_HANDHELD", "HOS_RT_POOL_MB"): + for key in ("HOS_OUTPUT_RES", "HOS_HANDHELD", "HOS_RT_POOL_MB", "HOS_OUTPUT_SIZE", "HOS_ASPECT", "TEST_SCREENS", "TEST_LOG"): env.pop(key, None) + if log is not None: + env["TEST_LOG"] = log if override is not None: env["HOS_OUTPUT_RES"] = override - subprocess.run([str(exe), str(mode), str(w), str(h), label], cwd=work, env=env, check=True) - print("PASS: output sizes, menu order, 1080p override, handheld, render-target budgets and DLSS sizes at 1080p, 5120x1440, 5120x2160 and 5120x2880") + if screens: + env["TEST_SCREENS"] = screens + if env_size is not None: + env["HOS_OUTPUT_SIZE"] = env_size + for built in exes: + run = subprocess.run([str(built), str(mode), frame, now, str(pool), str(shape), labels, row, picture, rows], + cwd=work, env=env, capture_output=True, text=True) + if run.returncode: + bad += 1 + print(f"{built.name}: output_res={saved} handheld={handheld} HOS_OUTPUT_RES={override} screens={screens} " + f"HOS_OUTPUT_SIZE={env_size} {ini!r}:\n{run.stderr}") + break + if bad: + raise SystemExit(f"FAIL: {bad} of {len(cases)} cases") + print("PASS: output sizes as pictures (fixed, the connected screens' by name, Custom: frame, shape, limits, the old Screen " + "and the old 5120-wide frames), the row's choices and their order, the Ultrawide row's shape for 16:9 sizes, 1080p " + "override, handheld, render-target budgets and DLSS sizes") if __name__ == "__main__": diff --git a/tests/test_pause_mods_anim.py b/tests/test_pause_mods_anim.py index cb218a5..4549020 100644 --- a/tests/test_pause_mods_anim.py +++ b/tests/test_pause_mods_anim.py @@ -171,12 +171,16 @@ def main(): "draw_quit_ask(k);" in dm and dm.index("menu_window_w = c.w, menu_window_h = c.h;") < dm.index("draw_quit_ask(k);"), "the dialog is not drawn through its Out, or its dim is not the whole window's") # ((11-19) the performance panel over the dialog's dim, as over the game's own dialogs: drawn after the menu on Mods' page) - for fn in ("void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {", - "void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {"): - rec = function(menu, fn) - check("const bool over_row = open && page == kModsRowPage;" in rec and "if (open) draw_menu(c, full && !over_row);" in rec and - rec.index("if (open) draw_menu(c, full && !over_row);") < rec.index("if (full && over_row) draw_perf(c);"), - "the performance panel is under Quit's dim (" + fn.split("(")[0] + ")") + # ((Triforce, 11-22) the window's frames by draw_overlays (menu_record's, and N64 Classic's menu_tv_layer's: m the options' + # own screens' context, under its TV when it takes them), the stills by menu_record_image) + rec = function(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {") + check("const bool over_row = s.open && page == kModsRowPage;" in rec and "if (s.open) draw_menu(m, full && !over_row);" in rec and + rec.index("if (s.open) draw_menu(m, full && !over_row);") < rec.index("if (full && over_row) draw_perf(c);"), + "the performance panel is under Quit's dim (void draw_overlays)") + rec = function(menu, "void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {") + check("const bool over_row = open && page == kModsRowPage;" in rec and "if (open) draw_menu(c, full && !over_row);" in rec and + rec.index("if (open) draw_menu(c, full && !over_row);") < rec.index("if (full && over_row) draw_perf(c);"), + "the performance panel is under Quit's dim (void menu_record_image)") # ((11-19) the mouse over the dialog: its buttons only, Mods and Quit under the dim gone from the hit map; none on its Out) check("hits.clear(0, 0, c.w, c.h);" in ask and ask.index("hits.clear(0, 0, c.w, c.h);") < ask.index("for (int i = 0; i < 3; i++) {"), "Mods and Quit under the dialog's dim still take clicks (a second click on Quit's place is A on Quit Game)") @@ -185,7 +189,7 @@ def main(): # the input tick = function(menu, "void menu_tick() {") enter = tick[tick.index("bool entered_by_down = false;"):tick.index("if (!open_now.load() || page != kModsPage) {")] - check("entered_by_down = enter == 1 || enter == 5;" in enter and "if (enter == 3) quit_open();" in enter, + check("entered_by_down = enter == 1 || enter == 5;" in enter and "if (enter == 3 && !mods_title_list()) quit_open();" in enter, "the enter word does not tell of a Down, or a click on Quit does not open its dialog with its In") check("mods_row_sel = enter == 3 || enter == 4 ? 1 : 0," in enter and "const bool clicked = enter == 2 || enter == 3;" in enter and "mods_sound(clicked ? HOS_MENU_SOUND_SYS_DECIDE : HOS_MENU_SOUND_SYS_CURSOR);" in enter, diff --git a/tests/test_perf_overlay.py b/tests/test_perf_overlay.py index c4a3322..b90d66d 100644 --- a/tests/test_perf_overlay.py +++ b/tests/test_perf_overlay.py @@ -83,8 +83,19 @@ def check_source(): # an open menu (its BringWindowToDisplayBack): draw_menu draws it over its dim, before its pages; the game tab's header over # it; (Triforce, 11-19) over the Mods entry's Quit dialog and its dim instead. tests/test_fps_overlay_order.py runs # menu_record for the order) - for name in ("void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {", - "void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {"): + # ((Triforce, 11-22) the window's frames by draw_overlays, what shows asked by showing_now (menu_record's, and N64 Classic's + # menu_tv_layer's: m the options' own screens' context, under its TV when it takes them; the panel with them under the game + # tab's header and the Mods entry, the counter over it all) + showing = block(menu, "Showing showing_now() {") + check("s.fps = opts.show_fps && !s.start;" in showing, "the counter's and the panel's switch is not the row (showing_now)") + record = block(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {") + check("const bool full = s.fps && opts.show_fps == 2;" in record and "if (s.open) draw_menu(m, full && !over_row);" in record and + "if (full) draw_perf(s.game_tab || s.mods_row ? m : c);" in record and "if (full && over_row) draw_perf(c);" in record and + "if (s.fps && !full) draw_fps(c, (s.open && page != kModsRowPage) || s.game_tab);" in record, + "Full does not draw the panel alone, under the menu (draw_overlays)") + check(record.index("if (full) draw_perf(") < record.index("if (s.game_tab) draw_game_tab(m);"), "the game tab's header is not over the panel") + check(record.count("draw_perf(") == 2, "the panel is drawn more than under the menu and over the Mods entry's dialog") + for name in ("void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {",): record = block(menu, name) check("const bool fps = opts.show_fps && !start;" in record or "const bool fps = opts.show_fps && !startup_on.load(std::memory_order_acquire);" in record, "the counter's and the panel's switch is not the row") @@ -157,7 +168,7 @@ def check_source(): 'cell(v.frame[3], "%.2f ms", f.shader_ms);', 'cell(v.frame[4], "%.1f per frame", f.uploads);', 'c.dim = perf_machine::cell_text(c.t, sizeof c.t, fmt, x);', 'present_sizes.load(std::memory_order_relaxed)', 'set(2, perf_upscaling_text(t, sizeof t));', 'set(3, tx_aa(opts.aa));', - 'perf_rate_text(tx_fps_cap(opts.fps_cap), t, sizeof t);', 'set(5, tx_onoff(opts.vsync));', 'set(6, tx_ultrawide(opts.ultrawide));', + 'perf_rate_text(tx_fps_cap(opts.fps_cap), t, sizeof t);', 'set(5, tx_onoff(opts.vsync));', 'set(6, shape_now(opts.ultrawide));', 'sscanf(tx_output_res(opts.output_res), "%ux%u", &ow, &oh) == 2 && oh) snprintf(t, sizeof t, "%up", oh);', 'set(8, tx_hdr(opts.hdr));', 'set(9, perf_framegen_text(t, sizeof t));', 'perf_title(v.title, sizeof v.title);'): check(needle in sample, "the panel's text is not NX2navi's, or not from where it is measured: " + needle) @@ -291,7 +302,8 @@ def check_source(): "the panel's text size is not baked at once when it changes") check("ImFont* font = c.f.body ? c.f.body : c.f.strong; // (draw_perf's)" in block(menu, "void bake_perf(const ui::Ctx& c, float px) {") and "ImFont* font = c.f.body ? c.f.body : c.f.strong;" in draw, "the panel's glyphs are baked in another font than draw_perf's") - check(record.index("prebake(c);") < record.index("if (open) draw_menu(c, full && !over_row);"), "the bake is not before the drawing") + overlays = block(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {") # ((11-22) the drawing's) + check(overlays.index("prebake(c);") < overlays.index("if (s.open) draw_menu(m, full && !over_row);"), "the bake is not before the drawing") check("if (r == kPerfFG && !v.fg) continue;" in draw, "the FG row shows without frame generation") check("if (v.setting[i][0]) label(kPerfSetting[i])" in draw, "a setting without a value is not left out") # (no panel of its own making: the options' plate, separator and font; the game's art read at run time from the player's diff --git a/tests/test_present_aspect.py b/tests/test_present_aspect.py index 4d85803..5d9bd12 100644 --- a/tests/test_present_aspect.py +++ b/tests/test_present_aspect.py @@ -72,6 +72,8 @@ VkImage framegen_scale(int, VkImageView, VkImage, uint32_t, uint32_t, const int* ++scales; scale_w = w; scale_h = h; return filtered ? 99 : VK_NULL_HANDLE; } +void n64_screen_begin(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) {} // ((Triforce, 11-22) N64 Classic's TV's screen: vk_n64.h) +void n64_screen_end() {} void blit_crop_to_rect(int, VkImage src, uint32_t, uint32_t, const int* crop, VkImage, int, PresentRect rect) { ++blits; drawn = rect; drawn_crop = crop; drawn_source = src; } diff --git a/tests/test_present_image_free.py b/tests/test_present_image_free.py index 7233543..e4a8110 100644 --- a/tests/test_present_image_free.py +++ b/tests/test_present_image_free.py @@ -82,6 +82,7 @@ struct { std::atomic swap_resize{0}; } dev; namespace dlssg { bool on = false; bool active() { return on; } } +namespace gpu_wait_kinds { struct Exclude {}; } // ((Triforce, 11-23) image_free's compositor wait, not counted) // (PRESENT-45: a lost surface's handling at the acquire; none is lost here, tests/test_present_surface_lost.py runs it) bool surface_recover(VkResult) { return false; } void invalidate_lost_surface() {} diff --git a/tests/test_present_period_line.py b/tests/test_present_period_line.py index bd1a5f0..51ccfef 100644 --- a/tests/test_present_period_line.py +++ b/tests/test_present_period_line.py @@ -65,6 +65,10 @@ static int fps_max(void) { return 240; } static int64_t steady_period(int64_t base, int64_t now) { (void)now; return base; } /* ((Triforce) the Steady frame rate row off) */ static void movie_pace_decide(void) {} /* ((Triforce, 11-22, PRESENT-30) no movie plays here: paced by the cap) */ static int pace_fps(void) { return fps_max(); } +/* ((Triforce, 11-22, N64 Classic, step 7) its rate (nn_vi.c's, host/n64_pace.h's rule): none here, so the interval is as it + was; tests/test_n64_pace.py runs it */ +static int n64_rate; +static int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; } void hos_bench_present(int64_t now) { (void)now; } /* (benchmark mode's note of each present: not on here) */ ''' diff --git a/tests/test_present_surface_lost.py b/tests/test_present_surface_lost.py index 907f633..07172bd 100644 --- a/tests/test_present_surface_lost.py +++ b/tests/test_present_surface_lost.py @@ -148,6 +148,7 @@ bool vk_ft_on() { return false; } template void vk_ft(const char*, A...) {} bool dlssg_active = false; namespace dlssg { bool active() { return dlssg_active; } } +namespace gpu_wait_kinds { struct Exclude {}; } // ((Triforce, 11-23) image_free's compositor wait, not counted) namespace pace { int64_t steady_floor_ns() { return 0; } void steady_held(int64_t) {} diff --git a/tests/test_present_thread.py b/tests/test_present_thread.py index b48035f..f918a81 100644 --- a/tests/test_present_thread.py +++ b/tests/test_present_thread.py @@ -101,7 +101,7 @@ int main() { const int64_t ns = h.settle(); if (ns >= 0) waited += ns, waits++; h.hand({k, 0}); - for (volatile int spin = 0; spin < (k % 3) * 2000; spin = spin + 1) {} /* (the next frame's build) */ + for (volatile int spin = 0; spin < (k % 3) * 2000;) { spin = spin + 1; } /* (the next frame's build) */ } h.settle(); t.join(); @@ -193,7 +193,9 @@ def check_source(): "the pacing's wait lets go of a lock the present thread never took") # the rule and the switch wanted = block(replay, "bool present_thread_wanted() {") - check("present_thread_use(present_thread_on(), smooth_mine, framegen_on(), dlssg::active(), antilag_running())" in wanted, + # ((Triforce, 11-23) the switch, or the next image acquired ahead (tests/test_acquire_ahead.py)) + check("present_thread_use(on, smooth_mine, framegen_on(), dlssg::active(), antilag_running())" in wanted and + "const bool on = present_thread_on() || (!never && acquire_ahead_wanted());" in wanted, "the present thread is not limited to the game's pictures without frame generation, DLSS frame generation or Anti-Lag 2") on = block(replay, "bool present_thread_on() {") check('getenv("RX_VK_PRESENT_THREAD")' in on and "e && *e && atoi(e) == 1" in on, "RX_VK_PRESENT_THREAD is not off unless =1 (off by default since 11-16)") @@ -208,8 +210,13 @@ def check_source(): check("vkQueuePresentKHR(" not in text and "vkAcquireNextImageKHR(" not in text, f.name + " presents or acquires itself") if f.name not in ("vk_replay.cpp", "vk_main.cpp"): check("create_swapchain(" not in text, f.name + " makes the swapchain") - check(replay.count("vkQueuePresentKHR(") == 2 and out.count("vkQueuePresentKHR(") == 2 and replay.count("vkAcquireNextImageKHR(") == 1, - "vk_replay.cpp presents or acquires outside present_out and present_image") + # ((Triforce, 11-23) and acquire_ahead, on the present thread after its present_out: RX_VK_ACQUIRE_AHEAD, tests/test_acquire_ahead.py) + ahead = block(replay, "void acquire_ahead() {") + check(replay.count("vkQueuePresentKHR(") == 2 and out.count("vkQueuePresentKHR(") == 2 and replay.count("vkAcquireNextImageKHR(") == 2 + and ahead.count("vkAcquireNextImageKHR(") == 1, + "vk_replay.cpp presents or acquires outside present_out, present_image and acquire_ahead") + check(before(main, "present_out(o, qk, true);", "acquire_ahead();", "present_hand.done();"), + "the next image is not acquired ahead on the present thread, after its present and before it says so") # NVIDIA Reflex: the present's id and markers are the frame's whose submit ended, not the next frame's reflex = (vk / "vk_reflex.cpp").read_text(encoding="utf-8") ends = block(reflex, "void reflex_submit_ends() {") diff --git a/tests/test_present_trace.py b/tests/test_present_trace.py index ddb1ea9..d9523bf 100644 --- a/tests/test_present_trace.py +++ b/tests/test_present_trace.py @@ -51,6 +51,10 @@ static int fps_max(void) { return 60; } /* (nn_vi.c's Frame rate cap: the cons static int64_t steady_period(int64_t base, int64_t now) { (void)now; return base; } /* ((Triforce) the Steady frame rate row off) */ static void movie_pace_decide(void) {} /* ((Triforce, 11-22, PRESENT-30) no movie plays here: paced by the cap) */ static int pace_fps(void) { return fps_max(); } +/* ((Triforce, 11-22, N64 Classic, step 7) its rate (nn_vi.c's, host/n64_pace.h's rule): none here, so the interval is as it + was; tests/test_n64_pace.py runs it */ +static int n64_rate; +static int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; } void hos_bench_present(int64_t now) { (void)now; } /* (benchmark mode's note of each present: not on here) */ ''' diff --git a/tests/test_prompt_keys_table.py b/tests/test_prompt_keys_table.py index 4d920a5..3a97d86 100644 --- a/tests/test_prompt_keys_table.py +++ b/tests/test_prompt_keys_table.py @@ -293,9 +293,10 @@ def main(): check('snprintf(out, cap, "%s/prompts_auto.txt", hos_user_dir ? hos_user_dir : "user");' in block(prompts, "static void auto_path(") and "auto_path(path, sizeof path);" in block(prompts, "static int remembered_face(") and "auto_path(path, sizeof path);" in follow and "prompts/auto.txt" not in follow, "Auto's device used last is kept in prompts/, which Setup makes again at an update") - check(re.search(r"int \(\*prompt_pad_face\)\(void\);\s*\} MkwVkHost;", api) is not None and - "#define MKWVK_API_VERSION 15" in api, "gpu/vk/vk_api.h has no prompt_pad_face last, at version 15") - check("hos_bench_state, hos_prompts_pad_face,\n};" in (ROOT / "host/rx_backend.c").read_text(encoding="utf-8"), + check(re.search(r"int \(\*prompt_pad_face\)\(void\);", api) is not None and + "#define MKWVK_API_VERSION 19" in api, "gpu/vk/vk_api.h has no prompt_pad_face, at version 19 (15 had it; 16-18 ultrawide's " + "screens and wide_backdrop, 19 the renderer's screen_point, N64 Classic's)") + check("hos_bench_state, hos_prompts_pad_face, host_screens, host_wide_backdrop,\n};" in (ROOT / "host/rx_backend.c").read_text(encoding="utf-8"), "host/rx_backend.c does not give the back end hos_prompts_pad_face") imgui = (ROOT / "gpu/vk/vk_imgui.cpp").read_text(encoding="utf-8") check('"prompts/External.pad." + std::to_string(pad) + ".bfotf.zs"' in imgui and diff --git a/tests/test_query_ring.py b/tests/test_query_ring.py new file mode 100644 index 0000000..8df1a45 --- /dev/null +++ b/tests/test_query_ring.py @@ -0,0 +1,85 @@ +"""(Triforce, 11-23) The recordings' timestamps through a ring the GPU copies them into (RX_VK_QUERY_RING, gpu/vk/vk_replay.cpp; +no game, no GPU). + +vkGetQueryPoolResults cost about 0.6 ms a frame on AMD's Windows driver on the thread that replays the frame, and with the recorder +thread each call is a boundary that waits for it. A slot's next use copies its last use's timestamps into a mapped, host-coherent +ring before it resets them; the slot's turn after that reads them from memory. Read from the source: +- the ring: made with the pools, host-coherent or not used (an invalidate would be a recorder boundary), the switch; +- the copy: in the command buffer just begun (no pass open), before the reset (query commands run in submission order), each + value with its availability word, never waiting on the GPU (a use that was never submitted would hang it), behind a + transfer-to-host barrier, through vk_work.h (the recorder's list, so the recorder thread keeps it in order); +- the read: only what was copied, only when the copying use was submitted, each value's availability checked; the old path kept + when there is no ring; the upload command buffer's timestamps as before. + + python -I -B tests/test_query_ring.py +""" +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def block(text, marker): + start = text.index(marker) + end = text.index('{', start) + 1 + depth = 1 + while depth: + depth += (text[end] == '{') - (text[end] == '}') + end += 1 + return text[start:end] + + +def before(text, *parts): + at = -1 + for p in parts: + i = text.find(p, at + 1) + if i < 0: + return False + at = i + return True + + +def main(): + vk = ROOT / "gpu/vk" + replay = (vk / "vk_replay.cpp").read_text(encoding="utf-8") + rec = (vk / "vk_recorder.h").read_text(encoding="utf-8") + work = (vk / "vk_work.h").read_text(encoding="utf-8") + fails = [] + + def check(ok, why): + if not ok: + fails.append(why) + + check("V(vkCmdCopyQueryPoolResults)" in rec, "the copy is not in the recorder's list of calls") + check("#define vkCmdCopyQueryPoolResults(...) (::mkwvk::rec::rx_vkCmdCopyQueryPoolResults(RX_WORK_ON(__VA_ARGS__)))" in work, + "vk_work.h does not send the copy through the recorder") + make = block(replay, "void query_ring_make() {") + check('getenv("RX_VK_QUERY_RING")' in block(replay, "bool query_ring_on() {"), "RX_VK_QUERY_RING is not read") + check(before(make, "create_buffer_cached(", "VK_MEMORY_PROPERTY_HOST_COHERENT_BIT", "destroy_buffer(ts_ring, ts_ring_alloc);", + "ts_ring_map = "), "the ring is used without host-coherent memory") + begin = block(replay, "void gpu_time_begin(Recording& r) {") + check(before(begin, "query_ring_make();", "if (ts_ring_map && ts_pending[r.slot]) {", "vkCmdCopyQueryPoolResults(r.cmd, ts_pool,", + "VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT", "VK_PIPELINE_STAGE_2_HOST_BIT", + "vkCmdPipelineBarrier2(r.cmd, &di);", "ts_ring_copied[r.slot] = true;", + "vkCmdResetQueryPool(r.cmd, ts_pool, ts_count() * r.slot, ts_count());"), + "the copy is not made before the reset, with availability, behind a host barrier") + copy = begin[begin.index("vkCmdCopyQueryPoolResults("):begin.index("VkMemoryBarrier2")] + check("WAIT_BIT" not in copy, "the copy waits on the GPU for queries a use that was never submitted would never write") + collect = block(replay, "void gpu_time_collect(Recording& r) {") + check(before(collect, "if (ts_ring_map) {", "if (!ts_ring_copied[r.slot] || !r.submitted) return;", "ts_ring_copied[r.slot] = false;", + "got = got && w[2 * i + 1] != 0;", "} else {", "vkGetQueryPoolResults(dev.device, ts_pool,"), + "the ring is read without its copy, its submit or the availability words, or the old read is gone") + check(collect.index("ts_up_pool && ts_up_pending[r.slot]") < collect.index("if (ts_ring_map) {"), + "the upload command buffer's timestamps are no longer read as before") + for f in sorted(vk.glob("*.cpp")): + text = f.read_text(encoding="utf-8", errors="replace") + if "vkCmdCopyQueryPoolResults(" in text and f.name != "vk_replay.cpp" and '#include "vk_work.h"' not in text: + check(False, f.name + " copies query results outside the recorder") + if fails: + for f in fails: + print("FAIL: " + f) + raise SystemExit(1) + print("query ring: ok") + + +if __name__ == "__main__": + main() diff --git a/tests/test_recomplauncher_json.py b/tests/test_recomplauncher_json.py index df2025f..1dc6666 100644 --- a/tests/test_recomplauncher_json.py +++ b/tests/test_recomplauncher_json.py @@ -1,4 +1,5 @@ -"""Game-free checks of recomplauncher.json: it parses, and every settings key is a row of the in-game menu. +"""Game-free checks of recomplauncher.json: it parses, every settings key is a row of the in-game menu, and no value it +writes means something else under another options_version. Run with: python -I tests/test_recomplauncher_json.py """ @@ -26,6 +27,29 @@ class RecompLauncherJsonTests(unittest.TestCase): self.assertTrue(keys) self.assertEqual(keys - rows, set()) + def test_values_mean_the_same_in_every_options_version(self): + """The manifest writes key=value lines and never options_version (it has no way to: a line it wrote into an older + file would also switch off that file's other rules). So a value it writes is read by the rules of whatever + version the file has, or of none in a file it makes. It may only offer values no rule changes: + - ultrawide=1 was "Monitor's shape" before options_version 6 and is 16:10 from 6 on (gpu/vk/ultrawide_rows.h); + - output_res=4 and 6 (5120x1440, 5120x2160) are read as 2560x1440 and 3840x2160 before 8 when ultrawide is on + another shape than theirs (gpu/vk/output_sizes.h output_res_read).""" + manifest = json.loads((ROOT / "recomplauncher.json").read_text(encoding="utf-8")) + written = {(key, value) for setting in manifest["settings"] for choice in setting["choices"] + for key, value in choice["set"].items()} + self.assertNotIn("options_version", {key for key, _ in written}) + moved = {("ultrawide", "1"), ("output_res", "4"), ("output_res", "6"), ("output_res", "7"), ("output_res", "8")} + self.assertEqual(written & moved, set()) + rows_h = (ROOT / "gpu" / "vk" / "ultrawide_rows.h").read_text(encoding="utf-8") + sizes_h = (ROOT / "gpu" / "vk" / "output_sizes.h").read_text(encoding="utf-8") + # (the rules those three come from, as the headers have them: a new rule there is a new value to leave out here) + self.assertIn("return version < 6 && row == 1 ? ultrawide_row_nearest(screen_w, screen_h) : row;", rows_h) + self.assertIn(" if (v == 4 && ultrawide_row != 0 && ultrawide_row != 3) return 1;\n" + " if (v == 6 && ultrawide_row != 0 && ultrawide_row != 2) return 2;\n return v;", sizes_h) + # (what it still offers of the two rows: the 16:9 sizes and Screen, and the shapes 16:9, 21:9 and 32:9) + self.assertEqual({value for key, value in written if key == "output_res"}, {"0", "1", "2", "3", "5"}) + self.assertEqual({value for key, value in written if key == "ultrawide"}, {"0", "2", "3"}) + def test_appimage_carries_it(self): self.assertIn('cp recomplauncher.json "$APPDIR/recomplauncher.json"', (ROOT / "scripts" / "linux" / "appimage.sh").read_text(encoding="utf-8")) diff --git a/tests/test_replay_threads_tuner.py b/tests/test_replay_threads_tuner.py index 789b2c9..623e746 100644 --- a/tests/test_replay_threads_tuner.py +++ b/tests/test_replay_threads_tuner.py @@ -19,6 +19,11 @@ par_tune_present at each present). No game, no GPU. "settled": (11-22) the rule gives an area's load window, and the first after it, no verdict (with settled off: on at the load, as Kaefergeneral's log had it); a settled heavy scene like test4's still turns the helpers on without a trial, a window after it settled; a trial the scene changed under changes nothing and the next comes once the scene settles. + "calm": (11-22) no trial on a loading screen, a trial due during an arrival waits for the calm scene, one that never calms + still has its trials; the rule's "on" in the Market's steady texture load withdrawn when the area comes down, kept where + the scene stays, and given again three windows after a withdrawal where the helpers win; (11-23) the rule's "on" needs + three windows alike to the first of them, so 0.7's Market arrival, its texture load coming down a window at a time, gets + none (with two alike, the gate before: in 20 of 20 runs). 2. The source read: par_tune_present returns at once unless the tuner decides (the Debug row's Off, RX_VK_PARALLEL), hands each frame to Tuner::step with the way in use, and applies its change; the rule is RX_VK_PARALLEL_RULE's to turn off, and counts the replay thread among the threads that record segments only where it does (RX_VK_PARALLEL_OWN); the back-off is @@ -86,20 +91,22 @@ def main(): check("`RX_VK_PARALLEL_RULE=0`" in guide, "docs/development.md does not say what RX_VK_PARALLEL_RULE=0 does") check("`RX_VK_PARALLEL_BACKOFF=0`" in guide, "docs/development.md does not say what RX_VK_PARALLEL_BACKOFF=0 does") check("`RX_VK_TUNER_SETTLED=0`" in guide, "docs/development.md does not say what RX_VK_TUNER_SETTLED=0 does") + # ((Triforce) 11-22) the rule's "on" withdrawn is logged, as its "on" is + check("if (s.withdrawn) {" in tune and "withdrawn at present %lld: its scene changed" in tune, "par_tune_present does not log a withdrawn \"on\"") with tempfile.TemporaryDirectory(prefix="replay-tuner-") as tmp: exe = Path(tmp) / "tuner.exe" built = subprocess.run([args.cxx, "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror", "-I", str(VK), str(ROOT / "tests" / "replay_threads_tuner_test.cpp"), "-o", str(exe)], capture_output=True, text=True) check(built.returncode == 0, "the fixture did not build:\n" + built.stderr[-4000:]) env = {k: v for k, v in os.environ.items() if not k.startswith("RX_VK_")} - for case in ("same", "prev", "rule", "backoff", "settled"): + for case in ("same", "prev", "rule", "backoff", "settled", "calm"): r = subprocess.run([str(exe), case], env=env, capture_output=True, text=True, timeout=300) print((r.stdout + r.stderr).strip()) check(r.returncode == 0, "replay_threads_tuner_test %s" % case) print("PASS: the helper threads' tuner decides as it did inline with the rule off; with it, on without a trial where the " "replay is plainly the frame's limit, no trial where the GPU or the game's threads are, trials in between; the " "back-off makes them rarer and shorter once the way holds, early where the scene changes, off as before; both judge " - "settled scenes only") + "settled scenes only, no trial where nothing is cut, and the rule's \"on\" holds for its scene") if __name__ == "__main__": diff --git a/tests/test_rt_pool_minimum.py b/tests/test_rt_pool_minimum.py index 0d55143..8e52b7b 100644 --- a/tests/test_rt_pool_minimum.py +++ b/tests/test_rt_pool_minimum.py @@ -3,7 +3,8 @@ The 305 MiB default crashed in Castle Town's guard house; 512 MiB resolved the reported conversation/camera reproduction. Keep existing 4K/ultrawide growth and explicit HOS_RT_POOL_MB overrides, including overrides below the floor; the 5120x2880 -output's pool is kept to 900 MiB. +output's pool is kept to 900 MiB, and so is that of every output of more pixels than +3840x2160's, whether they are the frame's or the widescreen picture's. """ import argparse import importlib.util @@ -56,7 +57,15 @@ static const struct { {3840, 2160, 0, 305, NULL, 687}, {2560, 1440, WIDE(3440, 1440), 305, NULL, 512}, {2560, 1440, WIDE(5120, 1440), 305, NULL, 610}, - {3840, 2160, WIDE(7680, 2160), 305, NULL, 1373}, + /* ((Triforce) a 7680 x 2160 picture: the 1373 MiB it scales to failed the game's reservation at boot (host/hos_main.c), + as every pool over 900 MiB has; host/hos_main.c no longer makes that picture either) */ + {3840, 2160, WIDE(7680, 2160), 305, NULL, 900}, + /* ((Triforce) a 5120 x 2160 picture with the frame 3840 x 2160, the Output resolution 5120x2160: 915 MiB scaled, kept to + 900 as the 5120 x 2160 frame before it; 3840 x 1600 and 5120 x 1440 pictures keep their scaled pools) */ + {3840, 2160, WIDE(5120, 2160), 305, NULL, 900}, + {3840, 2160, WIDE(5120, 2160), 305, "1000", 1000}, + {2848, 1600, WIDE(3840, 1600), 305, NULL, 512}, + {5120, 2880, WIDE(7224, 2032), 305, NULL, 900}, {2560, 1440, WIDE(1920, 1080), 305, NULL, 512}, {2560, 1440, 0, 305, "256", 256}, {3840, 2160, WIDE(7680, 2160), 305, "768", 768}, @@ -81,6 +90,18 @@ int main(void) { failed = 1; } } + /* TEX-85: a cap reached by a widescreen picture pins storage just like a fixed 5K output. + A picture over 4K whose scaled pool still has room is not pinned. Explicit budgets always are. */ + output_width = 3840; output_height = 2160; hos_wide_out = WIDE(5120, 2160); override = NULL; + if (hos_rt_pool_size(305 * MIB) != 900 * MIB || rt_pool_pinned != 1) return 3; + hos_wide_out = WIDE(4096, 2160); + if (hos_rt_pool_size(305 * MIB) >= 900 * MIB || rt_pool_pinned != 0) return 4; + scene_rgba16f = 1; hos_wide_out = WIDE(4608, 2160); + if (hos_rt_pool_size(305 * MIB) != 900 * MIB || rt_pool_pinned != 1) return 5; + scene_rgba16f = 0; hos_wide_out = WIDE(3840, 2400); + if (hos_rt_pool_size(360 * MIB) != 900 * MIB || rt_pool_pinned != 1) return 7; /* exactly at the cap */ + hos_wide_out = 0; override = "512"; + if (hos_rt_pool_size(305 * MIB) != 512 * MIB || rt_pool_pinned != 1) return 6; /* (local, RenoDX port) an RGBA16F scene: 128 MiB more, but not over an explicit HOS_RT_POOL_MB */ scene_rgba16f = 1; output_width = 2560; output_height = 1440; hos_wide_out = 0; @@ -111,7 +132,7 @@ int main(void) { source.write_text(fixture) subprocess.run([compiler, "-std=c11", "-O2", str(source), "-o", str(binary)], check=True) subprocess.run([str(binary)], check=True, timeout=5) - print("PASS: 512 MiB floor, 4K/ultrawide growth and explicit overrides, the 5120-wide outputs' 900 MiB (16 cases), " + print("PASS: 512 MiB floor, 4K/ultrawide growth and explicit overrides, the 900 MiB of the outputs over 3840x2160's pixels, frame or picture (20 cases), " "an RGBA16F scene's 128 MiB more, and the 5K output's 900 MiB with it") diff --git a/tests/test_rumble_menu.py b/tests/test_rumble_menu.py index 73ae650..84ee2b3 100644 --- a/tests/test_rumble_menu.py +++ b/tests/test_rumble_menu.py @@ -87,8 +87,9 @@ bool can_mic() { return false; } /* (the Upscaler row's choices, which set_row steps through: the game's own only, here) */ unsigned upscalers_available() { return 1; } void mic_chosen() {} -// (set_row steps the Output row through vk_menu.cpp's step_output_choice (#1144): not what this checks) -int step_output_choice(int id, int dir) { return id + dir; } +// (set_row steps the Output row through vk_menu.cpp's output_step, its choices (#1144): not what this checks) +struct { unsigned w, h; } remembered_custom{}; +bool output_step(int, bool) { return false; } %(set_row)s /* (menu_tick's arrows: Left, Right, and Enter as Right; a click on the value's left or right half presses them) */ void arrow(Row& r, bool right) { %(arrow)s } diff --git a/tests/test_save_files.py b/tests/test_save_files.py new file mode 100644 index 0000000..9e3973a --- /dev/null +++ b/tests/test_save_files.py @@ -0,0 +1,250 @@ +"""Save files (host/save_files.h, host/save_files.c, host/hos_main.c, gpu/vk/save_file_rows.h, gpu/vk/vk_menu.cpp; no game). + +As the Nintendo 64 game had them: the title asks which file to play, and the game's saves and autosaves live in that +file. A file is a folder the game saves in; the game reads its saves once, at its start, so another file is another +start. On unless HOS_SAVE_FILES=0 (11-23). Compiled and run here: + +- tests/save_files_test.c: host/save_files.h alone. triforce_files.txt's three lines and what is not taken from it, + written and read back; the files' folders; the start that follows a choice; a file's card (a map's name as words, + hearts from the game's count of life, triforce_card.txt read and written); +- tests/save_files_host_test.c: host/save_files.c's own text against a stand-in menu, a stand-in for the files' + folders and a game folder of the test's, four starts. Without the switch the game's own folder, and nothing read, + written or asked; with it file 1 without a triforce_files.txt, the files named to the menu once, whole; a file chosen + kept as the next start's and the menu told; the next start on that file's folder, saying that it follows a choice; + and a later start on the same file, with the player's names, asking again; +- tests/save_file_rows_test.cpp: gpu/vk/save_file_rows.h alone. Nothing shown or asked until the list is whole; this + run's file played at once and another asked of the host once; the host's word taken once; the choice under the keys. + +Read in the sources: the folder is chosen at the start, before the game's memory is made, and not when --user named +one; the files are named at the game's present; the host and the menu have the same ids, the same room; the title's +list has Save Select under Mods, which alone opens the file select there (nothing opens by itself); the menu restarts +the game on the host's word as Restart now does, has the row and the page; and no save is opened by the host. + + python -I -B tests/test_save_files.py [--cc gcc] [--cxx g++] +""" +import argparse +import os +from pathlib import Path +import re +import subprocess +import tempfile + +RUN_ALL_ARGS = ["--cc", "gcc", "--cxx", "g++"] + +ROOT = Path(__file__).resolve().parents[1] + + +def check(cond, what): + if not cond: + raise SystemExit("FAIL: " + what) + + +def block(text, marker): + start = text.index(marker) + end = text.index("{", start) + 1 + depth = 1 + while depth: + depth += (text[end] == "{") - (text[end] == "}") + end += 1 + return text[start:end] + + +def run(command, says=None, **more): + """A compiler or a fixture run; a fixture must say `says`""" + flags = (subprocess.CREATE_NO_WINDOW | subprocess.BELOW_NORMAL_PRIORITY_CLASS) if os.name == "nt" else 0 + result = subprocess.run(command, creationflags=flags, capture_output=True, text=True, encoding="utf-8", errors="replace", **more) + check(result.returncode == 0 and (says is None or says in result.stdout), + "%s:\n%s%s" % (" ".join(str(c) for c in command[:1] + command[-2:]), result.stdout, result.stderr)) + return result.stdout + + +def number_of(text, name): + return int(re.search(r"\b%s = (\d+)\b" % name, text).group(1)) + + +def check_sources(): + read = lambda *parts: ROOT.joinpath(*parts).read_text(encoding="utf-8") + host, own, header, api = read("host", "hos_main.c"), read("host", "save_files.c"), read("host", "save_files.h"), read("gpu", "vk", "vk_api.h") + native, rows, menu, replay = read("host", "nvn_native.c"), read("gpu", "vk", "save_file_rows.h"), read("gpu", "vk", "vk_menu.cpp"), read("gpu", "vk", "vk_replay.cpp") + # the folder: chosen at the start, in a game folder, before the game's memory is made; a folder named with --user stays + check("const int user_given = hos_user_dir != NULL; /* (--user) */" in host + and "if (!user_given) hos_user_dir = hos_save_files_start(dir, hos_user_dir);" in host and host.count("hos_save_files_start(") == 1, + "host/hos_main.c does not take the file's folder at the start, or takes it over --user") + check(host.index("const int user_given = hos_user_dir != NULL;") < host.index("hos_save_files_start(dir, hos_user_dir)") + < host.index('if (!hos_user_dir) hos_user_dir = "user";') < host.index("if (!reserve_guest())"), + "the file's folder is not chosen before the game's memory is made") + start = block(own, "const char *hos_save_files_start(") + check(start.index("if (!hos_save_files_on()) return base_user;") < start.index("files_read();"), "triforce_files.txt is read with the save files off") + check("on = !(e && e[0] == '0' && !e[1]);" in block(own, "int hos_save_files_on("), "the save files are not on unless HOS_SAVE_FILES=0") + frame = block(own, "void hos_save_files_frame(") + check(frame.index("if (!started) return;") < frame.index("rx_option("), "the menu is asked with the save files off") + check("files.current = was, files.chosen = 0;" in frame, "a run does not go on with the file it started on") + # no save is opened: a file's folder is listed, its files are not read + # the game saves: a slot's file opened to be written tells the card which slot, from the game's file call and nowhere else + fs = read("host", "nn_fs.c") + opened = block(fs, "HLE(_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci) {") + check("if (want_write) { void hos_save_card_wrote(const char *guest_path); hos_save_card_wrote(g); }" in opened + and opened.index("if (want_write && !writable)") < opened.index("hos_save_card_wrote(g)") and fs.count("hos_save_card_wrote(g)") == 1, + "host/nn_fs.c does not tell the slot the game saves in") + check("const int slot = started ? save_card_slot_of(guest_path) : -1;" in block(own, "void hos_save_card_wrote("), "a slot is noted with the save files off") + # (a slot's caption.sav is named for the menu, which reads the save's picture out of it; triforce_progress.txt is host/achievements.c's) + for word in ("recomp_", "A64_PTR", "GP(", "a64_lookup", "CreateFileA", "ReadFile", "progress.sav"): + check(word not in own, "host/save_files.c reaches into the game or a save: " + word) + check(own.count("fopen(") == 4 and own.count("fread(") == 2 and own.count("files_path") >= 4 and own.count("card_path(") == 3, + "host/save_files.c opens a file that is neither triforce_files.txt nor a file's triforce_card.txt") + # a file's card: told from the running game at Link's update, not read out of a save; the switch first, a save loaded, nothing written + update = block(host, "static void oot_update_player_cheats(") + check("oot_save_card_tick(c, now);" in update and host.count("oot_save_card_tick(") == 2 and host.count("hos_save_card_note(") == 1, + "host/hos_main.c does not tell a file's card at Link's update, from one place") + card = block(host, "static void oot_save_card_tick(") + check("if (!hos_save_files_on() || now < next) return;" in card and card.index("hos_save_files_on()") < card.index("oot_pouch_count(") + and "if (oot_pouch_count(c, oot_item_names[0]) < 0) return;" in card and card.index("oot_pouch_count(") < card.index("hos_save_card_note("), + "the game is asked for a file's card before the switch is, or while no save is loaded") + life = block(host, "static int oot_max_life(") + for word in ("recomp_store", "oot_gd_set", "oot_item_give", "oot_flag_set", "A64_PTR"): + check(word not in card and word not in life, "telling a file's card writes into the game: " + word) + items = dict(re.findall(r'OOT_ITEM\("[^"]+", "([^"]+)", ([01])\)', read("gpu", "vk", "oot_cheat_items.h"))) + held = re.findall(r'"((?:Item|Weapon|Armor)_\w+)"', card) + check(len(held) == number_of(header, "SAVE_CARD_STONES") + number_of(header, "SAVE_CARD_MEDALS") == 9 and all(name in items for name in held) + and [name.split("_")[1] for name in held] == ["Stone"] * 3 + ["Medal"] * 6, + "the card's stones and medallions are not nine items gpu/vk/oot_cheat_items.h names, the stones first: %s" % held) + check(number_of(header, "SAVE_CARD_STONES") == number_of(rows, "kStones") and number_of(header, "SAVE_CARD_MEDALS") == number_of(rows, "kMedals") + and number_of(header, "SAVE_CARD_HEARTS") == number_of(rows, "kHearts") and number_of(header, "SAVE_CARD_PLACE") + 1 == number_of(rows, "kPlace"), + "the host's card and the menu's have not the same room") + load = block(menu, "void files_pictures_load(") + check("save_file_rows::jpeg_in(" in load and "save_file_rows::caption_time(" in load and "mods::decode_image(" in load and load.index("if (p.state) continue;") < load.index("fopen(") + and "if (from >= 0 && !t.after(latest)) continue;" in load and "if (known >= 0 && slot != known) continue;" in load + and "fwrite" not in load and '"rb"' in load, "the menu does not read a save's picture once, from the file the host named, without writing") + # named at the game's present, from one place + present = block(native, "NV(nvnQueuePresentTexture) {") + check("hos_save_files_frame();" in present and native.count("hos_save_files_frame();") == 1, "the save files are not named to the menu at the game's present") + # the host and the menu: the same ids, bits and room + enum = block(api, "enum { HOS_OPT_FILES_TEXT") + names = re.findall(r"\bHOS_OPT_\w+", enum) + check("HOS_OPT_FILES_TEXT = 180" in enum and names == ["HOS_OPT_FILES_TEXT", "HOS_OPT_FILES_ADD", "HOS_OPT_FILES_COUNT", "HOS_OPT_FILES_ASK", "HOS_OPT_FILES_SAID"], + "the option ids are not 180 to 184") + others = re.sub(r"enum \{ HOS_OPT_FILES_TEXT[^}]*\}", "", api) + for value in range(180, 185): + check(not re.search(r"= %d\b" % value, others), "another option has the id %d" % value) + check("enum { HOS_FILE_SAVED = 1, HOS_FILE_CURRENT = 2, HOS_FILES_CHOSEN = 256 };" in api and "constexpr int kSaved = 1, kCurrent = 2;" in rows + and "constexpr int kChosen = 256;" in rows, "the files' bits are not the same on both sides") + number = lambda text, name: int(re.search(r"\b%s = (\d+)\b" % name, text).group(1)) + check(number(header, "SAVE_FILES") == number(rows, "kSlots") and number(header, "SAVE_FILE_NAME") + 1 == number(rows, "kName"), + "the host's files and the menu's have not the same room") + # the menu: told by the host, asks at the title once, restarts on the host's word, the row and the page + check("if (id == HOS_OPT_FILES_ASK) return menu_take_file_ask();" in replay and "int menu_take_file_ask() { return save_files.take_ask(); }" in menu, + "the renderer does not hand the file chosen to the host") + setter = block(menu, "void menu_option_set(") + for line in ("if (id == HOS_OPT_FILES_TEXT) return save_files.text(value);", "if (id == HOS_OPT_FILES_ADD) return save_files.add(value);", + "save_files.done(value);", "save_files.said(value);"): + check(line in setter, "the menu does not take the host's files: " + line) + tick = block(menu, "void menu_tick() {") + # the title: no page opens by itself; Save Select, an entry under Mods on the title's list, opens the file select + check("files_offered" not in menu and tick.count("files_open(true)") == 2, "the file select opens by itself, or not from Save Select alone") + shown = block(menu, "bool files_row_shown(") + check("save_files.shown() > 0" in shown and "HOS_MODS_LIST_TITLE" in shown, "Save Select shows off the title, or before the host named the files") + # (0.7.0: the title's entries are the game's own part, and the System list has Quit under Mods. Save Select is that second + # entry on the title: the same part a pitch lower, mods_row_sel 1, the host's words 3 and 4) + entry = block(menu, "void draw_title_files(") + check(entry.index("std::swap(title_anim, files_title_anim);") < entry.index('title_label = "Save Select", title_entry = 1;') < entry.index("draw_title_mods(c, sel, cx, cy, k, pitch);") + < entry.index('title_label = "Mods", title_entry = 0;') and entry.count("std::swap(title_anim, files_title_anim);") == 2, + "Save Select is not the title's own entry with its own label and animation, or leaves Mods' changed") + part = block(menu, "void draw_title_mods(ui::Ctx& c, bool sel, float cx, float cy, float k, float pitch) {") + check("const char* const label = title_label;" in part and "menu_hit::kButton, title_entry);" in part + and part.index("if (title_entry) return;") < part.index("mods_entry_px[0] ="), "Save Select has Mods' label, hit or place") + row = block(menu, "void draw_mods_row(ui::Ctx& c, bool sel) {") + check("if (files_row_shown()) draw_title_files(c, sel && mods_row_sel == 1, cx, cy - pitch, k, pitch), sel = sel && mods_row_sel == 0;" in row + and row.index("draw_title_files(") < row.index("draw_title_mods(c, sel, cx, cy, k, pitch);"), + "Save Select is not drawn a pitch under the title's Mods, the cursor on one of the two") + cursor = tick[tick.index("} else if (open_now.load() && page == kModsRowPage) {"):tick.index("} else if (open_now.load() && page == kModsPage) {")] + a_files, down_files = "} else if (press[7] && files_here && mods_row_sel == 1) {", "} else if (press[2] && files_here && mods_row_sel == 0) {" + check("const bool files_here = files_row_shown();" in cursor and "if (!quit_here && !files_here) mods_row_sel = 0;" in cursor + and cursor.index(a_files) < cursor.index(down_files) < cursor.index("} else if (press[7]) { // (A: Mods opens; on Quit its dialog)") + and cursor.index(down_files) < cursor.index("} else if (press[1] && mods_row_sel == 1) {") < cursor.index("} else if (press[1] || press[5]"), + "the cursor does not move between Mods and Save Select, or A on Save Select opens Mods or Quit's dialog") + # (the Down that brought the cursor onto Mods is not also the entries' own: 0.7.0's entered_by_down) + check(tick.index("if (entered_by_down) press[2] = false;") < tick.index("} else if (open_now.load() && page == kModsRowPage) {"), + "the Down that comes onto Mods goes on to Save Select at once") + enter = tick[tick.index("bool entered_by_down = false;"):tick.index("if (!open_now.load() || page != kModsPage) {")] + check(enter.index("if (enter == 3 && !mods_title_list()) quit_open();") < enter.index("if (enter == 3 && files_row_shown()) files_open(true);"), + "a click on Save Select does not open the file select, or opens Quit's dialog on the title") + mouse = read("host", "oot_menu.c") + list_tick = block(mouse, "static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {") + check(list_tick.index("quit_entry = title ? (Rect){0, 0, 0, 0} :") < list_tick.index("if (title && hos_save_files_on()) {") + < list_tick.index("quit_entry = (Rect){mx - 550, my - pitch / 2, mx + 550, my + pitch / 2};") + and "my = (r.y0 + r.y1) / 2 - 2 * pitch;" in list_tick and "files_entry" not in mouse, + "the host has no box for Save Select under the title's Mods, or has one with the save files off") + check("(page == kFilesPage && files_at_title)" in block(menu, "int menu_mods_selected("), "the game is given input while the title's file select is open") + word = tick[tick.index("if (const int said = save_files.take_said()) {"):] + word = word[:word.index("if (!open_now.load() || page != kModsPage)")] + check("if (said == save_file_rows::kRestart) {" in word and word.index("save();") < word.index("PostMessageA(window, WM_APP + 9, 0, 0);") + and "pipeline_cache_save(true);" in word and "else files_failed = true;" in word, + "the game is not restarted on the host's word as Restart now restarts it") + page = tick[tick.index("} else if (open_now.load() && page == kFilesPage) {"):tick.index("} else if (open_now.load() && page == kAchPage) {")] + check("if (files_wait >= 0) {}" in page and page.index("if (files_wait >= 0) {}") < page.index("else if (press[7]) {") + and "if (save_files.choose(files_choice)) leave(true);" in page and "else files_wait = files_choice, changed = true;" in page, + "a file can be chosen again while the host is asked, or this run's file is not played at once") + table = menu[menu.index("Row rows[] = {"):] + check(table.index('"Bug capture (F8)"') < table.index('{TAB_SYSTEM, "Save files", nullptr, 0, 0, 0, nullptr,') < table.index('MENU_HEADING(TAB_SYSTEM, "Mod cheats")') + and 'constexpr char kFilesRow[] = "Save files";' in menu, "the Save files row is not on the System tab after Bug capture (F8)") + check("(strcmp(rows[i].name, kFilesRow) || rows[i].tab != TAB_SYSTEM || save_files.shown() > 0) &&" in block(menu, "bool row_shown("), + "the Save files row shows before the host named the files") + press = tick[tick.index("else if (press[7] && is_files_row(r)) files_open(false)"):] + check(press.index("is_files_row(r)") < press.index("else if (press[7] && !r.value && can_bind()) page = 1"), + "the Save files row opens the Controls page: it is asked after the rows without a value") + check("else if (page == kFilesPage) draw_files(k);" in block(menu, "void draw_menu(ui::Ctx& c, bool perf_under) {"), "the file select is not drawn") + pages = [number(menu, name) for name in ("kFilesPage", "kAchPage", "kModsPage", "kModsRowPage")] + check(len(set(pages + [0, 1, 3, 4, 5, 6])) == len(pages) + 6, "kFilesPage is another page's number") + return api, own + + +def main(): + p = argparse.ArgumentParser(description=__doc__) + p.add_argument("--cc", default="cc") + p.add_argument("--cxx", default="c++") + a = p.parse_args() + api, own = check_sources() + with tempfile.TemporaryDirectory(prefix="triforce-save-files-") as tmp: + tmp = Path(tmp) + warnings = ["-std=c11", "-Wall", "-Wextra", "-Werror"] + exe = tmp / "form.exe" + run([a.cc] + warnings + ["-I" + str(ROOT / "host"), str(ROOT / "tests" / "save_files_test.c"), "-o", str(exe)]) + run([str(exe)], says="PASS") + exe = tmp / "rows.exe" + run([a.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-I" + str(ROOT / "gpu" / "vk"), str(ROOT / "tests" / "save_file_rows_test.cpp"), + "-o", str(exe)]) + run([str(exe)], says="PASS") + # the host's side: host/save_files.c from after its includes on, with the menu's ids from vk_api.h + marker = '#include "save_files.h"\n' + check(own.count(marker) == 1, "host/save_files.c no longer includes save_files.h last") + (tmp / "save_files_actual.inc").write_text(own[own.index(marker) + len(marker):], encoding="utf-8") + (tmp / "save_files_constants.inc").write_text( + "".join(block(api, start) + ";\n" for start in ("enum { HOS_OPT_FILES_TEXT = 180", "enum { HOS_FILE_SAVED = 1")), encoding="utf-8") + exe = tmp / "host.exe" + run([a.cc] + warnings + ["-Wno-unused-function", "-I" + str(ROOT / "host"), "-I" + str(tmp), str(ROOT / "tests" / "save_files_host_test.c"), + "-o", str(exe)]) + game = tmp / "game folder" + game.mkdir() + kept = game / "triforce_files.txt" + env = {k: v for k, v in os.environ.items() if k != "HOS_SAVE_FILES"} + # ((Triforce) 11-23: on by default: off only with HOS_SAVE_FILES=0; the first start runs with it not set at all) + run([str(exe), str(game), "off"], says="PASS", cwd=str(tmp), env=dict(env, HOS_SAVE_FILES="0")) + check(not kept.exists(), "a file was written with the save files off") + on = dict(env, HOS_SAVE_FILES="1") + run([str(exe), str(game), "first"], says="PASS", cwd=str(tmp), env=env) + run([str(exe), str(game), "second"], says="PASS", cwd=str(tmp), env=on) + check(kept.read_text(encoding="utf-8").splitlines()[1:] == ["current=2", "1=File 1", "2=File 2", "3=File 3"], "triforce_files.txt after a choice was taken: %r" % kept.read_text(encoding="utf-8")) + kept.write_bytes(b"current=2\r\nchosen=1000\r\n1=Spanky\r\n2=Bukwheat\r\n") # (the player's names, and a choice long past) + # (file 2's card, as the host kept it in the file's folder, which it names with Windows' separator) + if os.name == "nt": + (game / "user-2").mkdir() + with open(str(game) + "\\user-2\\triforce_card.txt", "wb") as f: + f.write(b"# a note\r\nplace=Kokiri Forest\r\nitems=1c9\r\nhearts=7\r\n") + run([str(exe), str(game), "third"], says="PASS", cwd=str(tmp), env=on) + check(sorted(f.name for f in game.iterdir() if f.name != "user-2") == ["triforce_files.txt"], "the game folder has other files now: no folder is made for a file here") + print("PASS: save files: triforce_files.txt, the files' folders, the host's naming and a file chosen for the next start, " + "the menu's list and its file select, and off unless asked for") + + +if __name__ == "__main__": + main() diff --git a/tests/test_save_tx.py b/tests/test_save_tx.py index 554c541..53b01d1 100644 --- a/tests/test_save_tx.py +++ b/tests/test_save_tx.py @@ -140,9 +140,9 @@ int main(int argc, char **argv) { /* a Commit killed before each of its steps, then the next start */ int reached_end = 0; for (int at = 1; at <= 12 && !reached_end; at++) { - char sub[32]; - snprintf(sub, sizeof sub, "%s\\k%d", argv[1], at); - snprintf(user, sizeof user, "%s", sub); + /* (each step its own folder: a 32-byte name cut every temporary path to the same C:\Users\\AppData\Local\T, + so the steps shared one folder there, and test runs at the same time wrote into each other's) */ + snprintf(user, sizeof user, "%s\\k%d", argv[1], at); save_tx_paths(&p, user, "0123456789abcdef0000000000000001"); new_run(); CHECK(save_tx_mount(&p, NULL, 0) == 1); diff --git a/tests/test_screen_size.py b/tests/test_screen_size.py new file mode 100644 index 0000000..ccb405a --- /dev/null +++ b/tests/test_screen_size.py @@ -0,0 +1,220 @@ +"""The connected screens as the Windows host finds them (host/display.c hos_screens, hos_screen_size), for the Output +resolution: every monitor's size in pixels, its own name, and which one the game's window opens on. + +The window is made at CW_USEDEFAULT, after the game has taken its output size. Windows names the monitor it was started +from in STARTUPINFO's hStdOutput when the shell started it from a taskbar or a jump list (and no standard handles are +passed there): that monitor then, else the main one. A monitor's name is its EDID's, through the display configuration; +one that has none (a laptop's panel) has an empty name. The functions themselves, cut out and run against stand-ins for +the Windows calls they make, so the check runs on every OS: + + python -I -B tests/test_screen_size.py [--cc gcc] +""" +import argparse +import subprocess +import tempfile +from pathlib import Path + +RUN_ALL_ARGS = ["--cc", "gcc"] + +ROOT = Path(__file__).resolve().parents[1] + +FIXTURE = r''' +#include +#include +#include +#include +#include "host/hos_screens.h" + +/* ---- stand-ins for what host/display.c takes from windows.h ---- */ +typedef void *HANDLE, *HMONITOR, *HDC; +typedef unsigned long DWORD; +typedef long LONG; +typedef int BOOL; +typedef unsigned int UINT32, UINT; +typedef intptr_t LPARAM; +typedef uint16_t WCHAR; +typedef struct { LONG left, top, right, bottom; } RECT, *LPRECT; +typedef struct { DWORD cbSize; RECT rcMonitor, rcWork; DWORD dwFlags; } MONITORINFO; +typedef struct { DWORD cbSize; RECT rcMonitor, rcWork; DWORD dwFlags; char szDevice[32]; } MONITORINFOEXA; +typedef struct { DWORD cb; DWORD dwFlags; HANDLE hStdInput, hStdOutput, hStdError; } STARTUPINFOW; +typedef struct { uint32_t LowPart; int32_t HighPart; } LUID; +typedef struct { LUID adapterId; UINT32 id; } DISPLAYCONFIG_PATH_SOURCE_INFO, DISPLAYCONFIG_PATH_TARGET_INFO; +typedef struct { DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo; DISPLAYCONFIG_PATH_TARGET_INFO targetInfo; UINT32 flags; } DISPLAYCONFIG_PATH_INFO; +typedef struct { UINT32 infoType; } DISPLAYCONFIG_MODE_INFO; +typedef struct { int type; UINT32 size; LUID adapterId; UINT32 id; } DISPLAYCONFIG_DEVICE_INFO_HEADER; +typedef struct { DISPLAYCONFIG_DEVICE_INFO_HEADER header; WCHAR viewGdiDeviceName[32]; } DISPLAYCONFIG_SOURCE_DEVICE_NAME; +typedef struct { + DISPLAYCONFIG_DEVICE_INFO_HEADER header; + struct { UINT32 friendlyNameFromEdid : 1; } flags; + WCHAR monitorFriendlyDeviceName[64]; +} DISPLAYCONFIG_TARGET_DEVICE_NAME; +#define CALLBACK +#define TRUE 1 +#define STARTF_USESTDHANDLES 0x100 +#define MONITORINFOF_PRIMARY 1 +#define SM_CXSCREEN 0 +#define SM_CYSCREEN 1 +#define ERROR_SUCCESS 0 +#define QDC_ONLY_ACTIVE_PATHS 2 +#define CP_UTF8 65001 +enum { DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2 }; + +/* ---- the system: three monitors. The main one is second in the system's order; one has no name of its own ---- */ +static const struct { + RECT at; + int primary; + const char *device, *name; /* (name NULL: none in its EDID) */ +} monitors[3] = { + {{-3440, 160, 0, 1600}, 0, "\\\\.\\DISPLAY2", "LG ULTRAGEAR"}, + {{0, 0, 3840, 1600}, 1, "\\\\.\\DISPLAY1", "38GN950"}, + {{3840, 0, 5760, 1200}, 0, "\\\\.\\DISPLAY3", NULL}, +}; +static HMONITOR handle(int i) { return (HMONITOR)(uintptr_t)(0x10001 + i * 2); } +static int monitor_of(HMONITOR m) { + for (int i = 0; i < 3; i++) + if (m == handle(i)) return i; + return -1; +} +static STARTUPINFOW started; +static int no_configuration; /* (1: the display configuration says nothing, as in a remote session) */ +static void GetStartupInfoW(STARTUPINFOW *si) { *si = started; } +static BOOL GetMonitorInfoA(HMONITOR m, MONITORINFO *mi) { + const int i = monitor_of(m); + if (i < 0 || (mi->cbSize != sizeof(MONITORINFO) && mi->cbSize != sizeof(MONITORINFOEXA))) return 0; + mi->rcMonitor = monitors[i].at, mi->dwFlags = monitors[i].primary ? MONITORINFOF_PRIMARY : 0; + if (mi->cbSize == sizeof(MONITORINFOEXA)) snprintf(((MONITORINFOEXA *)mi)->szDevice, 32, "%s", monitors[i].device); + return 1; +} +static int GetSystemMetrics(int i) { return i == SM_CXSCREEN ? 3840 : i == SM_CYSCREEN ? 1600 : -1; } +static BOOL EnumDisplayMonitors(HDC dc, LPRECT clip, BOOL (*each)(HMONITOR, HDC, LPRECT, LPARAM), LPARAM param) { + (void)dc, (void)clip; + for (int i = 0; i < 3; i++) + if (!each(handle(i), NULL, NULL, param)) break; + return 1; +} +/* (the display configuration's paths: in another order than the monitors, each source with its GDI device) */ +static const int path_monitor[3] = {2, 0, 1}; +static LONG GetDisplayConfigBufferSizes(UINT32 flags, UINT32 *paths, UINT32 *modes) { + if (flags != QDC_ONLY_ACTIVE_PATHS || no_configuration) return 1; + *paths = 3, *modes = 6; + return ERROR_SUCCESS; +} +static LONG QueryDisplayConfig(UINT32 flags, UINT32 *np, DISPLAYCONFIG_PATH_INFO *paths, UINT32 *nm, DISPLAYCONFIG_MODE_INFO *modes, void *topology) { + (void)modes, (void)topology; + if (flags != QDC_ONLY_ACTIVE_PATHS || *np < 3 || *nm < 6) return 1; + for (UINT32 i = 0; i < 3; i++) { + paths[i].sourceInfo.adapterId.LowPart = 7, paths[i].sourceInfo.id = 100 + i; + paths[i].targetInfo.adapterId.LowPart = 7, paths[i].targetInfo.id = 200 + i; + } + *np = 3; + return ERROR_SUCCESS; +} +static void widen(WCHAR *out, int cap, const char *text) { + int i = 0; + for (; text[i] && i + 1 < cap; i++) out[i] = (unsigned char)text[i]; + out[i] = 0; +} +static LONG DisplayConfigGetDeviceInfo(DISPLAYCONFIG_DEVICE_INFO_HEADER *h) { + if (h->adapterId.LowPart != 7) return 1; + if (h->type == DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME && h->size == sizeof(DISPLAYCONFIG_SOURCE_DEVICE_NAME) && h->id >= 100 && h->id < 103) { + widen(((DISPLAYCONFIG_SOURCE_DEVICE_NAME *)h)->viewGdiDeviceName, 32, monitors[path_monitor[h->id - 100]].device); + return ERROR_SUCCESS; + } + if (h->type == DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME && h->size == sizeof(DISPLAYCONFIG_TARGET_DEVICE_NAME) && h->id >= 200 && h->id < 203) { + DISPLAYCONFIG_TARGET_DEVICE_NAME *t = (DISPLAYCONFIG_TARGET_DEVICE_NAME *)h; + const char *name = monitors[path_monitor[h->id - 200]].name; + t->flags.friendlyNameFromEdid = name != NULL; + widen(t->monitorFriendlyDeviceName, 64, name ? name : "Generic PnP Monitor"); + return ERROR_SUCCESS; + } + return 1; +} +static int WideCharToMultiByte(UINT page, DWORD flags, const WCHAR *wide, int n, char *out, int cap, const char *dflt, BOOL *used) { + int i = 0; + (void)flags, (void)dflt, (void)used; + if (page != CP_UTF8 || n != -1) abort(); /* (UTF-8, never the system's code page: tests/test_utf8_paths.py) */ + for (; wide[i]; i++) { + if (i + 1 >= cap) return 0; + out[i] = (char)wide[i]; + } + out[i] = 0; + return i + 1; +} + +@FUNCTIONS@ + +#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); failed = 1; } } while (0) +int main(void) { + int failed = 0, w, h; + HosScreen s[8]; + /* started from another program, or a shortcut on the main monitor: every monitor, the main one the window's */ + memset(&started, 0, sizeof started); + CHECK(hos_screens(s, 8) == 3); + CHECK(s[0].w == 3440 && s[0].h == 1440 && !s[0].opens && !strcmp(s[0].name, "LG ULTRAGEAR")); + CHECK(s[1].w == 3840 && s[1].h == 1600 && s[1].opens && !strcmp(s[1].name, "38GN950")); + CHECK(s[2].w == 1920 && s[2].h == 1200 && !s[2].opens && !strcmp(s[2].name, "")); /* (no name of its own: none) */ + w = h = -1, hos_screen_size(&w, &h); + CHECK(w == 3840 && h == 1600); + /* started from the first monitor's taskbar: the window opens there, whatever its place on the desktop */ + started.hStdOutput = handle(0); + CHECK(hos_screens(s, 8) == 3 && s[0].opens && !s[1].opens && !s[2].opens); + w = h = -1, hos_screen_size(&w, &h); + CHECK(w == 3440 && h == 1440); + /* standard handles passed (a console, a pipe): hStdOutput is one of them, not a monitor */ + started.dwFlags = STARTF_USESTDHANDLES; + CHECK(hos_screens(s, 8) == 3 && !s[0].opens && s[1].opens); + w = h = -1, hos_screen_size(&w, &h); + CHECK(w == 3840 && h == 1600); + /* a handle there that is no monitor: the main monitor */ + started.dwFlags = 0, started.hStdOutput = (HANDLE)&started; + CHECK(hos_screens(s, 8) == 3 && s[1].opens); + w = h = -1, hos_screen_size(&w, &h); + CHECK(w == 3840 && h == 1600); + /* fewer asked for than there are; and no display configuration: the sizes all the same, without names */ + memset(&started, 0, sizeof started); + CHECK(hos_screens(s, 2) == 2 && s[1].opens); + no_configuration = 1; + CHECK(hos_screens(s, 8) == 3 && s[0].w == 3440 && !s[0].name[0] && !s[1].name[0] && s[1].opens); + if (!failed) puts("screens: every monitor's size and name, and the one the window opens on"); + return failed; +} +''' + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cc", default="gcc") + args = parser.parse_args() + source = (ROOT / "host/display.c").read_text(encoding="utf-8") + start = source.index("static HMONITOR shell_monitor(void) {") + end = source.index("int hos_screens(HosScreen *out, int cap) {") + functions = source[start:source.index("\n}\n", end) + 3] + # the window is still made at the default position, which is what puts it on that monitor + create = source[source.index("hwnd = CreateWindowA("):] + if "WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,\n CW_USEDEFAULT," not in create[:create.index(";")]: + raise SystemExit("FAIL: host/display.c no longer makes the window at CW_USEDEFAULT: hos_screen_size names another monitor") + # the Linux window: SDL's displays, read on the main thread before the game; the main one is the window's + sdl = (ROOT / "host/posix/display_sdl.c").read_text(encoding="utf-8") + if "void hos_screen_size(int *w, int *h) { *w = hos_posix_window[1], *h = hos_posix_window[2]; }" not in sdl: + raise SystemExit("FAIL: host/posix/display_sdl.c: hos_screen_size is not the desktop size hos_display_init read") + init = sdl[sdl.index("int hos_display_init(void) {"):sdl.index("void hos_display_start(void) {")] + if "screens_read(w, h);" not in init or "int hos_screens(HosScreen *out, int cap) {" not in sdl or "hos_sdl_displays(d, 16)" not in sdl: + raise SystemExit("FAIL: host/posix/display_sdl.c does not read SDL's displays in hos_display_init for hos_screens") + lib = (ROOT / "host/hos_sdl.c").read_text(encoding="utf-8") + if 'three ? "SDL_GetDisplays" : "SDL_GetNumVideoDisplays"' not in lib or '"SDL_GetDisplayName"' not in lib: + raise SystemExit("FAIL: host/hos_sdl.c does not list the displays with SDL3's and SDL2's own calls") + applet = (ROOT / "host/nn_applet.c").read_text(encoding="utf-8") + if "hos_screen_size(&sw, &sh);" not in applet: + raise SystemExit("FAIL: host/nn_applet.c does not take the old Screen's size from hos_screen_size") + with tempfile.TemporaryDirectory(prefix="screen-size-") as tmp: + work = Path(tmp) + c_file, exe = work / "fixture.c", work / "fixture.exe" + c_file.write_text(FIXTURE.replace("@FUNCTIONS@", functions), encoding="utf-8") + subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-I", str(ROOT), str(c_file), "-o", str(exe)], check=True) + subprocess.run([str(exe)], check=True) + print("PASS: the connected screens: each monitor's size and name, and the one the window opens on (the shell's, else the " + "main one)") + + +if __name__ == "__main__": + main() diff --git a/tests/test_shadow_slot.py b/tests/test_shadow_slot.py index b4bcceb..372325f 100644 --- a/tests/test_shadow_slot.py +++ b/tests/test_shadow_slot.py @@ -93,9 +93,9 @@ def main(): "the storage alignment is not the larger of the texture's own and its slot's") applet = (HOST / "nn_applet.c").read_text(encoding="utf-8") pool = block(applet, "uint64_t hos_rt_pool_size(uint64_t game) {") - check("__atomic_store_n(&rt_pool_pinned, e != NULL || v != asked || (is_five_k && scaled > five_k)," in pool and + check("__atomic_store_n(&rt_pool_pinned, e != NULL || (is_five_k && v == five_k)," in pool and "static int rt_pool_pinned = -1;" in applet and "int hos_rt_pool_pinned(void) {" in applet, - "the target heap does not say whether it is pinned (HOS_RT_POOL_MB, the 5120-wide cap), or not that it is not known yet") + "the target heap does not say whether it is pinned (HOS_RT_POOL_MB, the picture pixel cap), or not that it is not known yet") dev = (ROOT / "docs" / "development.md").read_text(encoding="utf-8") check("`HOS_SHADOW_BUCKET=`" in dev, "docs/development.md: HOS_SHADOW_BUCKET is not in the switches table") diff --git a/tests/test_sharpen_rules.py b/tests/test_sharpen_rules.py index f2f6a55..c57cc4e 100644 --- a/tests/test_sharpen_rules.py +++ b/tests/test_sharpen_rules.py @@ -20,6 +20,9 @@ no GPU. ultrawide sides, and HDR Native's picture goes through RGBA16F images; the bias is in the sampler's key and follows the upscaler each present, only in the draws into the scene (the flag from the draw's targets through build_descriptors, kept_texture's key and sampler_for's table to sampler_make; never a dispatch); the Sharpness row's text and default. + ((Triforce, 11-22, N64 Classic, step 3) And N64 Classic's texture blur: its look's positive bias while its 3D pass + draws, taken as it is, never past the card's limit; with it, a draw of a scene's size and shape for the picture the + pass drew is the scene (its pass notes both sizes), after the upscalers' own test of the scene.) The old lines fail. python -I -B tests/test_sharpen_rules.py [--cxx g++] @@ -387,6 +390,22 @@ def checks(t): 'sharpen_rules::lod_bias_switch(getenv("RX_VK_UPSCALE_LOD_BIAS"), &fixed)' in tick and "want = sharpen_rules::lod_bias_want(mode, fixed, upscale_lod_render.load(" in tick, "the bias does not follow the upscaler or RX_VK_UPSCALE_LOD_BIAS, or the samplers are not made anew") + # ((Triforce, 11-22, N64 Classic, step 3) its texture blur: the look's positive bias while its 3D pass draws, taken as it is, + # never past the card's limit; the scene by its size and shape for the picture its pass drew, which n64_upscale notes + # with the scene's size; the upscalers' own path as it was + check("const bool n64 = n64_3d_now();" in tick and + "want = n64_rules::lod_bias(n64_look(), dev.props.limits.maxSamplerLodBias);" in tick and + "const float next = n64 ? want : sharpen_rules::lod_bias_step(mode, now, want);" in tick and + tick.index("const bool n64 = n64_3d_now();") < tick.index("} else if (!off && (temporal_wanted() || fsr3_wanted())) {"), + "N64 Classic's blur is not the tick's while its 3D pass draws, or is not taken as it is") + check("if (upscale_lod_bias.load(std::memory_order_relaxed) > 0.0f) {" in scene and + "return n64_rules::scene_draw(w, h, (uint32_t)o, (uint32_t)(o >> 32));" in scene and + scene.index("sharpen_rules::lod_scene_now(") < scene.index("n64_rules::scene_draw("), + "with N64 Classic's blur, a draw of a scene's size and shape for its picture is not the scene") + n64_up = function(draw, "static bool n64_upscale(") + check("upscale_lod_note(in->width, in->height, ow);" in n64_up and + "n64_lod_output.store((uint64_t)oh << 32 | ow, std::memory_order_relaxed);" in n64_up, + "N64 Classic's pass does not note the scene's size and its picture's for the blur") check("upscale_lod_tick();" in t["replay"], "the bias is not taken at each present") check("void sampler_bias_changed() { samp_gen.fetch_add(1, std::memory_order_acq_rel); }" in t["bank"], "a change of the bias does not move the samplers' generation") @@ -425,6 +444,13 @@ MUTATIONS = [ "color[i] = {at.width, at.height, 0};"), ("descriptors across passes", "draw", " if (last_desc_scene != scene) last_desc_valid = false;\n", ""), ("dispatch biased", "draw", " build_descriptors(s, p);\n", " build_descriptors(s, p, false, draw_in_scene(at));\n"), + ("N64 blur in the upscalers' quarters", "draw", "const float next = n64 ? want : sharpen_rules::lod_bias_step(mode, now, want);", + "const float next = sharpen_rules::lod_bias_step(mode, now, want);"), + ("N64 blur never the scene", "draw", " return n64_rules::scene_draw(w, h, (uint32_t)o, (uint32_t)(o >> 32));\n", + " return false;\n"), + ("N64 scene size not noted", "draw", " upscale_lod_note(in->width, in->height, ow);\n", ""), + ("N64 blur past the card", "draw", "want = n64_rules::lod_bias(n64_look(), dev.props.limits.maxSamplerLodBias);", + "want = n64_look().lod_bias;"), ("DLSS unsharpened", "temporal", "s.pre_picture = {picture,", "s.pre_picture = {s.output.view,"), ("RCAS over HDR", "temporal", "temporal_sharpness() > 0.0f && sharpen_rules::lone_rcas(pre != nullptr, scene_rgba16f) &&\n", "temporal_sharpness() > 0.0f &&\n"), @@ -470,7 +496,8 @@ def main(): subprocess.run([a.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-I", str(VK), str(cpp), "-o", str(exe)], check=True) subprocess.run([str(exe)], check=True, timeout=60) print("PASS: Sharpness before the HUD (FSR 3.1's RCAS with its boost, FSR 4's own, RCAS over DLSS), none at the window " - "then; FSR 1 only where it enlarges and off at 0; HDR Native through RGBA16F; the texture LOD bias under DLSS and FSR") + "then; FSR 1 only where it enlarges and off at 0; HDR Native through RGBA16F; the texture LOD bias under DLSS and FSR, " + "and N64 Classic's texture blur") if __name__ == "__main__": diff --git a/tests/test_steady_period.py b/tests/test_steady_period.py index a59e298..a37c4be 100644 --- a/tests/test_steady_period.py +++ b/tests/test_steady_period.py @@ -128,6 +128,10 @@ int hos_ini_option(const char *key, int otherwise) { return strcmp(key, "steady_ static int fps_max(void) { return 240; } static void movie_pace_decide(void) {} /* ((Triforce, 11-22, PRESENT-30) no movie plays here: paced by the cap) */ static int pace_fps(void) { return fps_max(); } +/* ((Triforce, 11-22, N64 Classic, step 7) its rate (nn_vi.c's, host/n64_pace.h's rule): none here, so the interval is as it + was; tests/test_n64_pace.py runs it */ +static int n64_rate; +static int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; } void hos_bench_present(int64_t now) { (void)now; } /* (benchmark mode's note of each present: not on here) */ /* ---- host/nn_vi.c's state these functions use, and the rest of hos_vi_native_presented's stand-ins ---- */ static volatile LONG64 presents; diff --git a/tests/test_stick_dead_zone.py b/tests/test_stick_dead_zone.py index 112d5e8..313cef6 100644 --- a/tests/test_stick_dead_zone.py +++ b/tests/test_stick_dead_zone.py @@ -87,7 +87,7 @@ def main(): merged = (ROOT / "gpu" / "vk" / "merged_rows.h").read_text(encoding="utf-8") check('"stick_dead_zone"' in merged[merged.index("constexpr const char* kDropped[]"):], "an old stick_dead_zone= line is kept") check('if (!strcmp(line, "stick_dead_zone")) before7.stick_shared = atoi(eq + 1);' in menu and - "merged_rows::migrate(version, before7, opts.output_res, opts.lstick_dead_zone, opts.rstick_dead_zone);" in menu, + "merged_rows::migrate(legacy_output && version == 8 ? 7 : version, before7," in menu, "menu_init does not move an older file's shared dead zone into each stick's own") check("\n| Left stick dead zone, Right stick dead zone | Default (24%), or 0% to 50%" in readme, "readme.md's settings table has no Left and Right stick dead zone row") diff --git a/tests/test_taau_env_lookup.py b/tests/test_taau_env_lookup.py index ac2648e..d0db75e 100644 --- a/tests/test_taau_env_lookup.py +++ b/tests/test_taau_env_lookup.py @@ -100,6 +100,18 @@ static bool typed_upscale(VkCommandBuffer cmd,VkImageView input,VkImageView outp ++upscale_calls;forwarded_cmd=cmd;forwarded_input=input;forwarded_output=output;forwarded_texture=out; forwarded_level=level;forwarded_key=key;forwarded_text=text;forwarded_temporal=temporal;return upscale_result; } +/* ((Triforce, 11-22, N64 Classic) its 3D pass on (vk_n64.cpp n64_3d_now), and the pass itself (vk_draw.cpp n64_upscale), + spied as typed_upscale is: it too is refused outside the recording lock */ +static bool n64_now; +static bool n64_3d_now(){return n64_now;} +static int n64_calls, n64_lock_depth=-1; +static const Texture* n64_input; +static VkImageView n64_in_view, n64_out_view; +static bool n64_upscale(VkCommandBuffer,VkImageView input,const Texture* in,VkImageView output,Texture* out,uint32_t level){ + if(lock_depth<=0) return false; + ++n64_calls;n64_lock_depth=lock_depth;n64_input=in;n64_in_view=input;n64_out_view=output;forwarded_texture=out; + forwarded_level=level;return upscale_result; +} ''' SUFFIX = r''' @@ -147,6 +159,41 @@ int main(int argc,char** argv){ printf("%s failures=%u eligible=%d\n",argv[1],failures,upscale_calls); return failures?1:0; } + else if(!strcmp(argv[1],"n64")){ + /* ((Triforce, 11-22, N64 Classic) its 3D pass on, on a card that runs the networks: every gameplay network, by key or + by its shape, is drawn by it and not by the stretch, over the upscaler Off too; its input is looked at for the + grid's size; the picture is still taken for frame generation; a program that is no network is left alone */ + Shader::Backend::SPIRV::mma_software=false; + dev.push_descriptor=true;dw().imgs={{11},{44}}; + NvnState state{};Stage stage;stage.info.texture_descriptors={{1,23}};stage.info.image_descriptors={{1,23}}; + auto run=[&](uint64_t key,bool matrix){Program q{key,{}};stage.info.uses_cooperative_matrix=matrix;q.stages.push_back(stage); + return taau_stand_in(19,state,q);}; + const uint64_t networks[]={0xfd029a317a9a4b94ull,0x9dc98871eb7fc101ull}; + const uint64_t shares[]={0x6676619641320ba7ull,0xf10782f9e58b6a7cull,0x72ba090c70fe2614ull,0x0775215f8da720e6ull}; + check(!run(networks[0],true) && !n64_calls && !upscale_calls,"N64 Classic off: none of it"); + n64_now=true; + int calls=0; + for(uint64_t k:networks){ + const int hud=hudless_calls; + check(run(k,true) && n64_calls==++calls && !upscale_calls,"N64 Classic: a gameplay network by key is drawn by its 3D pass, not the stretch"); + check(n64_lock_depth==1 && n64_in_view==11 && n64_out_view==44 && n64_input==&scene_texture && forwarded_texture==&texture && + forwarded_level==7,"N64 Classic: the network's input view and texture and its output, under the recording lock"); + check(hudless_calls==hud+1 && hudless_key==k && hudless_lock_depth==0,"N64 Classic: the picture is still taken for frame generation, outside the lock"); + } + check(sample_view_calls==2,"N64 Classic: a network known by key has its input looked at, for the grid's size"); + for(uint64_t k:shares)check(run(k,true) && n64_calls==++calls && !upscale_calls,"N64 Classic: a share's network (by its shape) is drawn by its 3D pass"); + check(!run(0x1111111111111111ull,false) && n64_calls==calls,"N64 Classic: a program that is no network is left alone"); + scene_texture.format=VK_FORMAT_B10G11R11_UFLOAT_PACK32; + check(!run(shares[0],true) && n64_calls==calls,"N64 Classic: a network of that shape whose input is not the scene's format is left alone"); + check(run(networks[0],true) && n64_calls==++calls,"N64 Classic: a network known by key is taken whatever its input's format"); + off_now=true; + check(run(networks[1],true) && n64_calls==++calls && !upscale_calls,"N64 Classic over the upscaler Off"); + upscale_result=false; + const int hud=hudless_calls; + check(!run(networks[1],true) && hudless_calls==hud,"N64 Classic: when its pass draws nothing, nothing is taken and the game's network runs"); + printf("%s failures=%u eligible=%d\n",argv[1],failures,n64_calls); + return failures?1:0; + } else if(!strcmp(argv[1],"off-software")){ /* (Off where the first network is already stood in for: Off's plain stretch, not the stand-in's FXAA) */ dev.push_descriptor=true;dw().imgs={{11},{44}};off_now=true; @@ -228,13 +275,13 @@ def main(): command = [args.cxx, '-std=c++17', '-Wall', '-Wextra', '-Werror', *args.cxx_arg, str(source), '-o', str(exe)] subprocess.run(command, cwd=folder, check=True) failed = False - for case in ('software', 'hardware', 'no-f16', 'empty', 'disabled', 'custom', 'prefixes', 'off', 'off-software'): + for case in ('software', 'hardware', 'no-f16', 'empty', 'disabled', 'custom', 'prefixes', 'off', 'off-software', 'n64'): result = subprocess.run([str(exe), case], cwd=folder) print(case, 'exit', result.returncode, flush=True) failed |= result.returncode != 0 if failed: raise SystemExit(1) - print('PASS: seven key configurations; rejected lookups removed, eligible per-call forwarding preserved; the upscaler Off') + print('PASS: seven key configurations; rejected lookups removed, eligible per-call forwarding preserved; the upscaler Off; N64 Classic\'s 3D pass') if __name__ == '__main__': diff --git a/tests/test_ui_record.py b/tests/test_ui_record.py index ec18bdc..e173bfa 100644 --- a/tests/test_ui_record.py +++ b/tests/test_ui_record.py @@ -81,7 +81,7 @@ void vkCmdBeginRendering(VkCommandBuffer, const VkRenderingInfo* ri) { calls += "["; } void vkCmdEndRendering(VkCommandBuffer) { calls += "]"; } -''' + block(src, "void layout(VkCommandBuffer cmd,") + "\n" + block(src, "void record_to(VkCommandBuffer cmd,") + "\n" + block(src, "void record(VkCommandBuffer cmd,") + r''' +''' + block(src, "void layout(VkCommandBuffer cmd,") + "\n" + block(src, "bool textures(VkCommandBuffer cmd, ImDrawData* dd) {") + "\n" + block(src, "void render_over(VkCommandBuffer cmd, VkImage image,") + "\n" + block(src, "void record_to(VkCommandBuffer cmd,") + "\n" + block(src, "void record(VkCommandBuffer cmd,") + r''' int main() { VkCommandBuffer cmd = (VkCommandBuffer)0x10; dev.swap_images = {(VkImage)0x100, (VkImage)0x101, (VkImage)0x102}; diff --git a/tests/test_ultrawide_shapes.py b/tests/test_ultrawide_shapes.py index 6ddbbb1..b6eead5 100644 --- a/tests/test_ultrawide_shapes.py +++ b/tests/test_ultrawide_shapes.py @@ -1,11 +1,16 @@ """The Ultrawide row's shapes by name: the game's own 16:9, and a fixed 16:10, 21:9 or 32:9 for a screen or a window of that -shape (the owner, 11-16: "remove monitors shape as a option keep 16:9 16:10 21:9 32:9"). An options file from before +shape (the owner, 11-16: "remove monitors shape as a option keep 16:9 16:10 21:9 32:9"), and ((Triforce, 11-22, N64 Classic) a +fixed 4:3, a TV's of 1998: the host's path for a shape narrower than 16:9, the HUD across the width). An options file from before options_version 6 whose row is 1 had the main monitor's shape, no longer a choice: it is read as the shape nearest the main monitor's (gpu/vk/ultrawide_rows.h). host/hos_main.c's own ultrawide_ratio and its widescreen sizes (the block tests/test_widescreen_shapes.py checks with screen ratios), cut out and run: the row's value, the file's version and the main monitor's size in, the picture, the scene, the camera's ratio and the HUD's share out. And the menu's side: the row's range, what it says for each value, and the old row's 1 read the same way in menu_init (gpu/vk/vk_menu.cpp). +The row is the shape of a 16:9 Output resolution. One that is not 16:9 (5120x1440, 5120x2160, a Screen or Custom of such a +shape) is the picture by itself (gpu/vk/output_sizes.h): the host takes its shape before the row's, and the row then shows +that shape with nothing to choose, instead of a value the game does not run. tests/test_output_resolution.py runs those. + python -I -B tests/test_ultrawide_shapes.py [--cc gcc] [--cxx g++] """ import argparse @@ -42,6 +47,7 @@ HOST = r''' #include #include #include +#include "gpu/vk/output_sizes.h" volatile uint64_t hos_wide_out, hos_wide_scene; volatile float hos_wide_ratio, hos_wide_squeeze, hos_wide_margin; @@ -51,7 +57,7 @@ uint32_t hos_output_size(int height) { return height ? out_h : out_h * 16 / 9; } static void hos_log(const char *f, ...) { (void)f; } @ROWS@ @RATIO@ -static void wide(float want) { +static void wide(float want, int sized) { @SIZES@ } @@ -59,7 +65,7 @@ int main(int argc, char **argv) { if (argc < 6) return 2; out_h = (unsigned)atoi(argv[5]); const float want = ultrawide_ratio(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); - wide(want); + wide(want, 0); /* (the row's shape, at a 16:9 Output resolution) */ printf("%.4f %llux%llu %llux%llu %.4f %.4f %.4f %.4f\n", (double)want, (unsigned long long)(hos_wide_out & 0xffffffffu), (unsigned long long)(hos_wide_out >> 32), (unsigned long long)(hos_wide_scene & 0xffffffffu), (unsigned long long)(hos_wide_scene >> 32), @@ -80,23 +86,27 @@ MENU = r''' @HINT@ int main() { CHECK(!std::strcmp(tx_ultrawide(0), "16:9") && !std::strcmp(tx_ultrawide(1), "16:10")); - CHECK(!std::strcmp(tx_ultrawide(2), "21:9") && !std::strcmp(tx_ultrawide(3), "32:9")); + CHECK(!std::strcmp(tx_ultrawide(2), "21:9") && !std::strcmp(tx_ultrawide(3), "32:9") && !std::strcmp(tx_ultrawide(4), "4:3")); CHECK(ultrawide_row_ratio(0) == 0.0f && ultrawide_row_ratio(1) == 1.6f && ultrawide_row_ratio(-2) == 0.0f); /* (the shapes' ratios) */ - /* (wider than 16:9, where the HUD position and the menu sides have sides to act on: 21:9 and 32:9, not 16:10) */ + CHECK(ultrawide_row_ratio(4) == (float)(4.0 / 3.0) && ultrawide_row_ratio(9) == (float)(4.0 / 3.0)); /* (4:3, the row's last) */ + /* (wider than 16:9, where the HUD position and the menu sides have sides to act on: 21:9 and 32:9, not 16:10 nor 4:3) */ CHECK(!ultrawide_row_wider(0) && !ultrawide_row_wider(1) && ultrawide_row_wider(2) && ultrawide_row_wider(3)); - CHECK(!ultrawide_row_wider(-1) && ultrawide_row_wider(4)); - CHECK(!std::strcmp(tx_ultrawide(-1), "16:9") && !std::strcmp(tx_ultrawide(4), "32:9")); /* (past the row: its nearest end) */ - for (int v = 0; v <= 3; v++) CHECK(hn_ultrawide(v, -1) && hn_ultrawide(v, 0) == hn_ultrawide(v, -1) && !hn_ultrawide(v, 1)); + CHECK(!ultrawide_row_wider(-1) && !ultrawide_row_wider(4) && !ultrawide_row_wider(7)); + CHECK(!std::strcmp(tx_ultrawide(-1), "16:9") && !std::strcmp(tx_ultrawide(7), "4:3")); /* (past the row: its nearest end) */ + for (int v = 0; v <= 4; v++) CHECK(hn_ultrawide(v, -1) && hn_ultrawide(v, 0) == hn_ultrawide(v, -1) && !hn_ultrawide(v, 1)); CHECK(std::strstr(hn_ultrawide(1, -1), "16:10") && std::strstr(hn_ultrawide(2, -1), "21:9") && std::strstr(hn_ultrawide(3, -1), "32:9")); - for (int v = 1; v <= 3; v++) CHECK(std::strstr(hn_ultrawide(v, -1), "black bars")); - CHECK(!hn_ultrawide(4, -1) && !hn_ultrawide(-1, -1)); - for (int v = 0; v <= 3; v++) CHECK(!std::strstr(tx_ultrawide(v), "onitor") && !std::strstr(hn_ultrawide(v, -1), "onitor")); + CHECK(std::strstr(hn_ultrawide(4, -1), "4:3") && std::strstr(hn_ultrawide(4, -1), "HUD across")); + for (int v = 1; v <= 4; v++) CHECK(std::strstr(hn_ultrawide(v, -1), "black bars")); + CHECK(!hn_ultrawide(5, -1) && !hn_ultrawide(-1, -1)); + for (int v = 0; v <= 4; v++) CHECK(!std::strstr(tx_ultrawide(v), "onitor") && !std::strstr(hn_ultrawide(v, -1), "onitor")); /* (the old row's 1, Monitor's shape, read by the main monitor's shape before options_version 6; as chosen from 6 on) */ CHECK(ultrawide_row_read(1, 5, 2560, 1440) == 0 && ultrawide_row_read(1, 5, 1920, 1200) == 1 && ultrawide_row_read(1, 5, 2560, 1600) == 1); CHECK(ultrawide_row_read(1, 5, 3440, 1440) == 2 && ultrawide_row_read(1, 5, 2560, 1080) == 2 && ultrawide_row_read(1, 5, 5120, 1440) == 3); CHECK(ultrawide_row_read(1, 5, 1024, 768) == 1 && ultrawide_row_read(1, 5, 0, 0) == 0 && ultrawide_row_read(1, 0, 3440, 1440) == 2); CHECK(ultrawide_row_read(1, 6, 3440, 1440) == 1 && ultrawide_row_read(1, 7, 2560, 1440) == 1); - for (int r = 0; r <= 3; r++) if (r != 1) CHECK(ultrawide_row_read(r, 5, 3440, 1440) == r && ultrawide_row_read(r, 6, 1920, 1200) == r); + for (int r = 0; r <= 4; r++) if (r != 1) CHECK(ultrawide_row_read(r, 5, 3440, 1440) == r && ultrawide_row_read(r, 6, 1920, 1200) == r); + /* (an old file's Monitor's shape on a 4:3 monitor: still the nearest of the first four, as before the row had 4:3) */ + CHECK(ultrawide_row_read(1, 5, 1600, 1200) == 1); std::puts("ultrawide row: all checks passed"); return 0; } @@ -120,24 +130,54 @@ def main(): "hos_main.c does not take the picture's shape from the Ultrawide row") env = host.index('const char *e = getenv("HOS_ASPECT");') check("if (!e) {" in host[env:host.index("want = ultrawide_ratio(", env)], "HOS_ASPECT no longer goes over the Ultrawide row") + # the Output resolution's own shape goes before the row's (the size is the picture), and the row is read only without one + own = host[env:host.index("want = ultrawide_ratio(", env)] + check("want = hos_output_ratio();" in own and "sized = want > 0.0f;" in own and "if (!e && !sized) {" in own, + "hos_main.c does not take the Output resolution's own shape before the Ultrawide row's") + check("if (output_picture(hos_output_size(1), want, sized, &ow, &oh)) {" in host, + "hos_main.c does not make the picture with output_sizes.h's output_picture") menu = (ROOT / "gpu/vk/vk_menu.cpp").read_text(encoding="utf-8") # ((Triforce, options_version 7) the Ultrawide group's Aspect ratio row; its key is still ultrawide, which hos_main.c reads) - row = re.search(r'\{TAB_DISPLAY, "Aspect ratio", &opts\.ultrawide, 0, 3, 1, tx_ultrawide,.*?hn_ultrawide, true\},', menu, re.S) - check(row, "the Aspect ratio row is not 16:9, 16:10, 21:9, 32:9 with a restart") + row = re.search(r'\{TAB_DISPLAY, "Aspect ratio", &opts\.ultrawide, 0, 4, 1, tx_shape,.*?hn_shape, true\},', menu, re.S) + check(row, "the Aspect ratio row is not 16:9, 16:10, 21:9, 32:9, 4:3 with a restart") check('{"Aspect ratio", "ultrawide"}' in function(menu, "const char* ini_key(const Row& r) {"), "the Aspect ratio row is not kept as ultrawide=") + # (its text and its line are the four shapes' while the row decides; what decides in its place is said, and the row fixed) + check("if (owner == 0) return tx_ultrawide(v);" in function(menu, "const char* tx_shape(int v) {"), + "the Ultrawide row does not show its own choice while it decides the shape") + check("case 0: return hn_ultrawide(v, 0);" in function(menu, "const char* hn_shape(int v, int variant) {"), + "the Ultrawide row's line is not its value's while it decides the shape") + check('int shape_owner() { return getenv("HOS_ASPECT") ? 2 : output_shaped(opts.output_res) ? 1 : 0; }' in menu, + "the menu does not take the shape's owner as the host does: HOS_ASPECT, the Output resolution's own shape, the row") + check("if (value == &opts.ultrawide && shape_owner() != 0) return true;" in function(menu, "bool row_fixed(const int* value) {"), + "the Ultrawide row can be changed while the Output resolution's own shape or HOS_ASPECT decides the picture's") check("Monitor's shape" not in function(menu, "const char* tx_ultrawide(int v) {"), "the Ultrawide row still offers Monitor's shape") # (the HUD position and the menu sides shown with a shape wider than 16:9 alone: 16:10, the row's 1, is narrower) shown = function(menu, "bool row_shown(int i) {") - check("((rows[i].value != &opts.wide_hud && rows[i].value != &opts.wide_menus) || ultrawide_row_wider(opts.ultrawide))" in shown, + check("((rows[i].value != &opts.wide_hud && rows[i].value != &opts.wide_menus) || (output_picture_of(opts.output_res, opts.ultrawide).w > output_picture_of(opts.output_res, opts.ultrawide).h * (16.0 / 9.0) * 1.01))" in shown, "row_shown does not show the HUD position and the menu sides with 21:9 and 32:9 alone") init = function(menu, "void menu_init() {") - check("opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));" - in init, "menu_init does not read an old file's Monitor's shape as the nearest shape, as the host does") + # (with the main monitor the host reads it by, on every system: off Windows the renderer has no GetSystemMetrics and takes + # the screen the window opens on from the host's list, which is what the host's GetSystemMetrics is there; it read 0 x 0, + # and the menu showed 16:9 for a picture the host made 21:9) + check("opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, (int)main_screen().w, (int)main_screen().h);" in init, + "menu_init does not read an old file's Monitor's shape as the nearest shape, as the host does") + main_screen = function(menu, "Out main_screen() {") + check("#ifdef _WIN32\n return Out{(uint32_t)std::max(GetSystemMetrics(SM_CXSCREEN), 0), (uint32_t)std::max(GetSystemMetrics(SM_CYSCREEN), 0)};\n" + "#else\n return screen_opening() ? screen_opening()->native : Out{0, 0};\n#endif" in main_screen, + "the menu's main monitor is not the host's: GetSystemMetrics on Windows, the screen the window opens on elsewhere") + check(init.index("screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0);") < init.index("opts.ultrawide = ultrawide_row_read("), + "menu_init reads an old Ultrawide row before it has the host's screens") + posix = (ROOT / "host/posix/win32_posix.c").read_text(encoding="utf-8") + check("if (index == SM_CXSCREEN) return window_state()[1];" in posix and "if (index == SM_CYSCREEN) return window_state()[2];" in posix, + "host/posix/win32_posix.c: GetSystemMetrics is no longer the desktop's main display, which the menu takes it to be") + check(init.index("opts.output_res = output_file_read(opts.output_res, version, opts.ultrawide,") > + init.index("opts.ultrawide = ultrawide_row_read("), + "menu_init does not read an old file's 5120-wide output with the Ultrawide row as that file had it") readme = (ROOT / "readme.md").read_text(encoding="utf-8") - check("| Aspect ratio | 16:9 (the game's own), 16:10, 21:9, 32:9" in readme, "readme.md's settings table does not list the Aspect ratio row's four shapes") + check("| Aspect ratio | 16:9 (the game's own), 16:10, 21:9, 32:9, 4:3" in readme, "readme.md's settings table does not list the Aspect ratio row's five shapes") guide = (ROOT / "docs/development.md").read_text(encoding="utf-8") - check("| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9 (before `options_version` 6, 1 was the monitor's shape" in guide, + check("| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9, 4 4:3 (before `options_version` 6, 1 was the monitor's shape" in guide, "docs/development.md's options table has no ultrawide") # (row, the options file's version, the main monitor, the output's height) -> the shape asked, the picture, the scene, the @@ -165,9 +205,14 @@ def main(): # 32:9 by name ((3, 6, 1920, 1080, 1440), "3.5556 5120x1440 3840x1080 3.5556 0.5000 0.2500 3.5556"), ((3, 5, 2560, 1440, 1080), "3.5556 3840x1080 2880x810 3.5556 0.5000 0.2500 3.5556"), + # ((Triforce, N64 Classic) 4:3 by name: the game's height, narrower, its cameras 4:3, the HUD across the whole width + ((4, 6, 1920, 1080, 1440), "1.3333 1920x1440 1440x1080 1.3333 1.0000 0.0000 1.3333"), + ((4, 6, 3440, 1440, 1440), "1.3333 1920x1440 1440x1080 1.3333 1.0000 0.0000 1.3333"), + ((4, 5, 1920, 1080, 1080), "1.3333 1440x1080 1080x810 1.3333 1.0000 0.0000 1.3333"), + ((4, 6, 1920, 1080, 1152), "1.3333 1536x1152 1152x864 1.3333 1.0000 0.0000 1.3333"), # a value past the row: its nearest end, as the menu reads it ((-1, 6, 3440, 1440, 1440), "0.0000 0x0 0x0 0.0000 0.0000 0.0000 0.0000"), - ((7, 6, 1920, 1080, 1440), "3.5556 5120x1440 3840x1080 3.5556 0.5000 0.2500 3.5556"), + ((7, 6, 1920, 1080, 1440), "1.3333 1920x1440 1440x1080 1.3333 1.0000 0.0000 1.3333"), ) with tempfile.TemporaryDirectory(prefix="ultrawide-") as tmp: work = Path(tmp) @@ -175,9 +220,8 @@ def main(): source.write_text(HOST.replace("@ROWS@", rows_h) .replace("@RATIO@", function(host, "static float ultrawide_ratio(int row, int version, int screen_w, int screen_h) {")) .replace("@SIZES@", sizes(host)), encoding="utf-8") - # (the header is pasted in, not included: the menu's own helpers in it, ultrawide_row_wider, go unused by the host's side) - subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-variable", "-Wno-unused-function", str(source), - "-o", str(exe), "-lm"], check=True) + subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-variable", "-Wno-unused-function", "-I", str(ROOT), + str(source), "-o", str(exe), "-lm"], check=True) bad = [] for case, expect in cases: got = subprocess.run([str(exe)] + [str(v) for v in case], capture_output=True, text=True, check=True).stdout.strip() @@ -186,7 +230,7 @@ def main(): if bad: raise SystemExit("FAIL:\n " + "\n ".join(bad)) # at the 4K output the fixed shapes stay within 3840 x 2160's pixels (the render targets' pool) - for r in (1, 2, 3): + for r in (1, 2, 3, 4): got = subprocess.run([str(exe), str(r), "6", "1920", "1080", "2160"], capture_output=True, text=True, check=True).stdout.split() w, h = (int(v) for v in got[1].split("x")) check(w * h <= 3840 * 2160 and w % 8 == 0 and h % 8 == 0 and abs(w / h - float(got[0])) < 0.02, @@ -203,7 +247,7 @@ def main(): .replace("@HINT@", hint.group(0)), encoding="utf-8") subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", str(source), "-o", str(exe)], check=True) subprocess.run([str(exe)], check=True) - print("PASS: the Ultrawide row's 16:9, 16:10, 21:9 and 32:9, and an old file's monitor's shape read as the nearest of them") + print("PASS: the Ultrawide row's 16:9, 16:10, 21:9, 32:9 and 4:3, and an old file's monitor's shape read as the nearest of the first four") if __name__ == "__main__": diff --git a/tests/test_upscale_off.py b/tests/test_upscale_off.py index cf32d87..4773df6 100644 --- a/tests/test_upscale_off.py +++ b/tests/test_upscale_off.py @@ -47,6 +47,30 @@ int main() { want("Off, the listed network", choose(true, true, true, true), true, false, false); want("Off, a listed other program", choose(true, true, false, false), true, true, false); want("Off, a listed program of the shape", choose(true, true, false, true), true, true, false); + // ((Triforce, 11-22, N64 Classic) its 3D pass on: every gameplay network, by key or by its shape, is its pass's, over Off and + // over the list; anything else as without it, and without it every answer as the four-input rule's + using upscale_off::Choice; + const auto n64 = [](const char* what, Choice c, bool stand_in, bool by_shape, bool is_n64) { + checks++; + if (c.stand_in != stand_in || (stand_in && (c.temporal == is_n64 && is_n64)) || c.by_shape != by_shape || c.n64 != is_n64) + fails++, printf("FAIL %s: stand_in %d temporal %d by_shape %d n64 %d\n", what, c.stand_in, c.temporal, c.by_shape, c.n64); + }; + // listed off by_key shaped n64 + n64("N64, a network by key", choose(false, false, true, true, true), true, false, true); + n64("N64, a network by key, any shape", choose(false, false, true, false, true), true, false, true); + n64("N64, a share's network", choose(false, false, false, true, true), true, true, true); + n64("N64, the listed network", choose(true, false, true, true, true), true, false, true); + n64("N64, a listed program of the shape", choose(true, false, false, true, true), true, true, true); + n64("N64 and Off, a network by key", choose(false, true, true, true, true), true, false, true); + n64("N64, a program that is neither", choose(false, false, false, false, true), false, false, false); + n64("N64, a listed other program", choose(true, false, false, false, true), true, false, false); + bool same = true; + for (int i = 0; i < 16; i++) { + const Choice a = choose(i & 1, i & 2, i & 4, i & 8), b = choose(i & 1, i & 2, i & 4, i & 8, false); + same &= a.stand_in == b.stand_in && a.temporal == b.temporal && a.by_shape == b.by_shape && !a.n64 && !b.n64; + } + checks++; + if (!same) fails++, printf("FAIL without N64 Classic the five-input rule is not the four-input one\n"); if (fails) printf("upscale off: FAILED (%d of %d checks)\n", fails, checks); else printf("upscale off: all %d checks passed\n", checks); return fails != 0; @@ -69,7 +93,7 @@ def check_source(): stand = function(draw, "bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {") order = [stand.find(n) for n in ( "const bool off = upscale_off_on();", - "upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped);", + "upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped, n64);", "if (!ch.stand_in) return false;", "if (ch.by_shape) {", "if (!in || in->format != VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) return false;", diff --git a/tests/test_wide_hud.py b/tests/test_wide_hud.py index ef0c09f..dac2b07 100644 --- a/tests/test_wide_hud.py +++ b/tests/test_wide_hud.py @@ -1,20 +1,21 @@ """The HUD on a picture wider than 16:9 (host/oot_wide_hud.h, host/oot_wide_hud.c, nx2/prompt_assets.py HUD_SIDE_PANES). -With the Insert menu's Ultrawide HUD row on Screen edges the hearts and the item slot sit in the picture's top corners -and the small map at its right edge; on Middle everything keeps the middle 16:9, as before. The rules checked here, +Screen edges moves the side-anchored HUD panes and animation states. Middle keeps the HUD in the middle 16:9. The rules checked here, without the game: - A layout in the middle: its projection times the squeeze, nothing moved. A kept one (a fade, a menu's background): untouched. A 16:9 picture (squeeze 1) or no squeeze: untouched. - A layout at an edge (the lab's switch): a point at the 16:9 grid's right edge lands on the picture's right edge, one at its left edge on the picture's left edge, and the layout keeps its shape. -- A pane moved in a layout (the hearts', the item slot's, the small map's) goes as far as a whole layout moved by its +- A pane moved in a layout goes as far as a whole layout moved by its projection: a corner pane lands on the picture's corner through the middle projection. -- prompts/wide.bin: one entry per pane and copy of each layout, and one per animation key that puts a pane at the small - map's place (the keys at 0 and other curves are left); a layout that is not the one known gives none. +- prompts/wide.bin: one entry per pane and copy of each layout, and one per bound x key at an edge, with the endpoint delta + adjusted where needed. A changed layout is skipped independently. python -I -B tests/test_wide_hud.py """ +from contextlib import redirect_stderr +from io import StringIO import shutil import struct import subprocess @@ -109,20 +110,49 @@ def layout(name, panes, curves=()): for k in range(n): struct.pack_into(" 0}, {1920.0, 1626.0, 1270.0, 1536.0, 1470.0, 1490.0, 1706.0}) + + self.assertEqual({x for _, side, x in got if side < 0}, {-1920.0, -1720.0, -1140.0, -3460}) + self.assertEqual({x for _, side, x in got if side > 0}, {1920.0, 1626.0, 1270.0, 1536.0, 1470.0, 1490.0, 1706.0, 2110, 1796, 660, 1716, 1770, 1740, 0, 724, 1300}) first = blarc.index(layout("PlayerStatus_00", GOOD)) self.assertTrue(all(off >= first for off, _, _ in got)) # (the other layout's pane of the same name: left) self.assertNotIn(1666.0, {x for _, _, x in got}) # (the whole-screen map's own pane: left) @@ -177,25 +216,99 @@ class WideHudTest(unittest.TestCase): self.assertEqual(len(raw), 8 + 12 * len(got)) self.assertEqual(struct.unpack_from(" +#include "gpu/vk/wide_sides_rule.h" +using mkwvk::wide_sides_rule::show; +static int failed; +#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); failed = 1; } } while (0) +int main() { + const float margin = (1.0f - (16.0f / 9.0f) / 2.4f) / 2.0f; // (3840x1600) + const int64_t never = 0; + for (int row = 1; row <= 2; row++) { // (out of focus, black) + // play: the world drawn this frame, or within the grace + for (int64_t ago = 0; ago <= 3; ago++) CHECK(show(row, margin, 1000, 1000 - ago, never, false) == 0); + CHECK(show(row, margin, 1000, 1000, never, true) == 0); // (whatever the host says of the menus) + // a menu with no world: the pause menu, the map, a loading screen + CHECK(show(row, margin, 1000, 996, never, false) == row); + CHECK(show(row, margin, 1000, 996, 996, false) == row); // (a blur long ago) + // the item wheel: the blur of the last picture, no centred menu + for (int64_t ago = 0; ago <= 3; ago++) CHECK(show(row, margin, 1000, 900, 1000 - ago, false) == 0); + // the file select over the title, as in the run: the sides on at present 3087, the blur drawn from 3089 on, the + // world never drawn, the menu's screen running throughout + for (int64_t now = 3087; now <= 4772; now += 5) CHECK(show(row, margin, now, never, now >= 3089 ? now : never, true) == row); + // and what turned them off there: the same frames without the host's word + CHECK(show(row, margin, 3087, never, never, false) == row && show(row, margin, 3089, never, 3089, false) == 0); + // the title alone: no margin from the host + CHECK(show(row, 0.0f, 3000, never, never, false) == 0 && show(row, 0.0f, 3000, never, 3000, true) == 0); + } + // the row on Full width, and a 16:9 picture + CHECK(show(0, margin, 1000, 900, never, false) == 0 && show(0, margin, 1000, 900, 1000, true) == 0); + CHECK(show(1, 0.0f, 1000, 900, never, false) == 0 && show(1, -0.1f, 1000, 900, never, false) == 0); + if (!failed) std::puts("wide sides: play, a menu, the item wheel, a centred backdrop drawn by the wheel's program"); + return failed; +} +''' + + +def check(cond, what): + if not cond: + raise SystemExit("FAIL: " + what) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cxx", default="g++") + args = parser.parse_args() + framegen = (ROOT / "gpu/vk/vk_framegen.cpp").read_text(encoding="utf-8") + start = framegen.index("WideSides wide_sides() {") + sides = framegen[start:framegen.index("\n}\n", start)] + check("const bool centred_menu = host->wide_backdrop && host->wide_backdrop() != 0;" in sides, + "wide_sides does not ask the host whether a menu with the centred backdrop runs") + check("wide_sides_rule::show(opts.wide_menus, margin, presents_now, world_drawn_at.load(std::memory_order_relaxed),\n" + " wheel_drawn_at.load(std::memory_order_relaxed), centred_menu);" in sides, + "wide_sides does not decide by wide_sides_rule.h") + check("presents_now - wheel_drawn_at" not in sides, "wide_sides still takes every blur of the last picture for the item wheel") + draw = (ROOT / "gpu/vk/vk_draw.cpp").read_text(encoding="utf-8") + check("if (cp->key == 0x02ff9920c2571cc2ULL) wheel_drawn_at.store(presents_now, std::memory_order_relaxed);" in draw, + "vk_draw.cpp no longer notes the blur of the last picture") + api = (ROOT / "gpu/vk/vk_api.h").read_text(encoding="utf-8") + check(" int (*wide_backdrop)(void);\n} MkwVkHost;" in api and "#define MKWVK_API_VERSION 18" in api, + "vk_api.h: MkwVkHost does not end with wide_backdrop at version 18") + backend = (ROOT / "host/rx_backend.c").read_text(encoding="utf-8") + check("return oot_menu_backdrop_runs() || rx_option(HOS_OPT_MODS_MUSIC, 0) == 2;" in backend and + "hos_bench_state, hos_prompts_pad_face, host_screens, host_wide_backdrop,\n};" in backend, + "rx_backend.c does not answer wide_backdrop with the menu screens that run, at the table's end") + with tempfile.TemporaryDirectory(prefix="wide-sides-") as tmp: + source, exe = Path(tmp) / "fixture.cpp", Path(tmp) / "fixture.exe" + source.write_text(FIXTURE, encoding="utf-8") + subprocess.run([args.cxx, "-std=c++17", "-Wall", "-Wextra", "-Werror", "-I", str(ROOT), str(source), "-o", str(exe)], check=True) + subprocess.run([str(exe)], check=True) + print("PASS: ultrawide's menu sides for play, a menu, the item wheel, and a centred backdrop the wheel's program draws") + + +if __name__ == "__main__": + main() diff --git a/tests/test_widescreen_shapes.py b/tests/test_widescreen_shapes.py index 0d9bf7c..821f80e 100644 --- a/tests/test_widescreen_shapes.py +++ b/tests/test_widescreen_shapes.py @@ -1,5 +1,7 @@ """host/hos_main.c's widescreen sizes, game-free: the picture, scene, camera ratio and HUD for screens wider and -narrower than 16:9 (a 4:3 CRT, 16:10, 5:4 and narrower, 21:9, 32:9), and the game's own picture for 16:9. +narrower than 16:9 (a 4:3 CRT, 16:10, 5:4 and narrower, 21:9, 32:9), and the game's own picture for 16:9. A shape of the +Ultrawide row's or HOS_ASPECT's is kept to 3840x2160's pixels; an Output resolution of its own shape (3840x1600, 5120x2160) +is the picture, pixel for pixel (gpu/vk/output_sizes.h output_picture). python -I -B tests/test_widescreen_shapes.py [--cc gcc] """ @@ -32,6 +34,7 @@ def main(): #include #include #include +#include "gpu/vk/output_sizes.h" volatile uint64_t hos_wide_out, hos_wide_scene; volatile float hos_wide_ratio, hos_wide_squeeze, hos_wide_margin; @@ -40,13 +43,13 @@ static unsigned out_h = 1440; uint32_t hos_output_size(int height) { return height ? out_h : out_h * 16 / 9; } static void hos_log(const char *f, ...) { (void)f; } -static void wide(float want) { +static void wide(float want, int sized) { /* (as host/hos_main.c has them: a float shape) */ ''' + block() + r''' } int main(int argc, char **argv) { out_h = (unsigned)atoi(argv[2]); - wide((float)atof(argv[1])); + wide((float)atof(argv[1]), argc > 3 && atoi(argv[3])); printf("%llux%llu %llux%llu %.4f %.4f %.4f\n", (unsigned long long)(hos_wide_out & 0xffffffffu), (unsigned long long)(hos_wide_out >> 32), (unsigned long long)(hos_wide_scene & 0xffffffffu), (unsigned long long)(hos_wide_scene >> 32), @@ -66,20 +69,37 @@ int main(int argc, char **argv) { ("2.3889", 1440, "3440x1440 2584x1080 2.3889 0.7442 0.1279"), # 21:9 (3440 x 1440), as before ("3.5556", 1440, "5120x1440 3840x1080 3.5556 0.5000 0.2500"), # 32:9, as before ("0", 1440, "0x0 0x0 0.0000 0.0000 0.0000"), # Ultrawide off + # a shape of the row's or HOS_ASPECT's at the 4K output: at most 3840x2160's pixels, the shape kept + ("2.3704", 2160, "4416x1864 3312x1398 2.3691 0.7504 0.1248"), + ("3.5556", 2160, "5400x1520 4048x1140 3.5526 0.5004 0.2498"), + ) + # (the Output resolution's own shape, its width over its height: the picture is that size) + sized = ( + (3840, 1600, "3840x1600 2880x1200 2.4000 0.7407 0.1296"), + (3440, 1440, "3440x1440 2584x1080 2.3889 0.7442 0.1279"), + (2560, 1080, "2560x1080 1920x810 2.3704 0.7500 0.1250"), + (5120, 1440, "5120x1440 3840x1080 3.5556 0.5000 0.2500"), + (5120, 2160, "5120x2160 3840x1620 2.3704 0.7500 0.1250"), # (more than 3840x2160's pixels: not made smaller) + (1920, 1200, "1920x1200 1440x900 1.6000 1.0000 0.0000"), + (7224, 2032, "7224x2032 5416x1524 3.5551 0.5001 0.2500"), # (a 7680x2160 screen as output_size_used takes it) ) with tempfile.TemporaryDirectory(prefix="widescreen-") as tmp: work = Path(tmp) source, exe = work / "fixture.c", work / "fixture.exe" source.write_text(fixture, encoding="utf-8") - subprocess.run([args.cc, "-std=c11", str(source), "-o", str(exe), "-lm"], check=True) + subprocess.run([args.cc, "-std=c11", "-I", str(ROOT), str(source), "-o", str(exe), "-lm"], check=True) bad = [] for want, height, expect in cases: got = subprocess.run([str(exe), want, str(height)], capture_output=True, text=True, check=True).stdout.strip() if got != expect: bad.append("ratio %s at %u: %s, expected %s" % (want, height, got, expect)) + for w, h, expect in sized: + got = subprocess.run([str(exe), repr(w / h), str(h), "1"], capture_output=True, text=True, check=True).stdout.strip() + if got != expect: + bad.append("the output size %ux%u: %s, expected %s" % (w, h, got, expect)) if bad: raise SystemExit("FAIL:\n " + "\n ".join(bad)) - print("PASS: widescreen sizes for 4:3, 16:10, 5:4, 16:9, 21:9 and 32:9 screens") + print("PASS: widescreen sizes for 4:3, 16:10, 5:4, 16:9, 21:9 and 32:9 screens, and for output sizes of their own shape") if __name__ == "__main__":