Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BozoEngine
Submodule BozoEngine updated 42 files
+4 −0 docs/native-image-processing.md
+22 −2 docs/specs/libraries.md
+24 −7 runtime/app/device_pad.cpp
+53 −4 runtime/app/input_bindings.cpp
+187 −6 runtime/app/panel.cpp
+112 −1 runtime/app/video_settings.cpp
+309 −9 runtime/app/window.cpp
+2 −1 runtime/audio/audio_state.cpp
+48 −6 runtime/audio/libsd.cpp
+43 −0 runtime/audio/mixer.cpp
+4 −0 runtime/ee/kernel.cpp
+54 −1 runtime/host/free_host.cpp
+8 −4 runtime/include/bozo/app/device_pad.h
+36 −3 runtime/include/bozo/app/frame_pacer.h
+14 −1 runtime/include/bozo/app/input_bindings.h
+9 −2 runtime/include/bozo/app/panel.h
+23 −0 runtime/include/bozo/app/video_settings.h
+21 −3 runtime/include/bozo/app/window.h
+8 −1 runtime/include/bozo/audio/libsd.h
+12 −0 runtime/include/bozo/audio/mixer.h
+1 −0 runtime/include/bozo/ee/kernel.h
+7 −0 runtime/include/bozo/host/free_host.h
+5 −0 runtime/include/bozo/libs/libraries.h
+19 −0 runtime/include/bozo/libs/mpeg.h
+3 −0 runtime/include/bozo/native/compiled_libraries.h
+38 −0 runtime/include/bozo/ops_fpu.h
+129 −3 runtime/include/bozo/ops_vu0.h
+6 −0 runtime/include/bozo/port.h
+9 −1 runtime/include/bozo/render/gl.h
+25 −0 runtime/include/bozo/render/renderer.h
+17 −0 runtime/libs/cd.cpp
+2 −1 runtime/libs/gs.cpp
+2 −0 runtime/libs/libraries.cpp
+100 −13 runtime/libs/mpeg.cpp
+29 −1 runtime/native/compiled_libraries.cpp
+235 −28 runtime/render/present_gl.cpp
+16 −2 runtime/render/renderer.cpp
+6 −0 tests/CMakeLists.txt
+17 −1 tests/render/image_processing_gpu_tests.cpp
+20 −3 tests/render/image_processing_tests.cpp
+17 −0 tests/runtime/runtime_tests.cpp
+156 −0 tests/runtime/vu0_simd_tests.cpp
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,15 @@ screen); the variables give their state at launch (`runtime/tmb_cheats.cpp`).
| `--pad-script [n=]<file>` | Frame-keyed scripted input for player n (1–4); repeat for multiple players |
| `--quit-after <frames>` | End an unattended windowed run |
| `--capture-dir <dir> --capture-frames n,n` | Capture chosen game frames |
| `--hidden` | Test run that never shows the window: captures read the game's offscreen picture (add `--no-sound` so nothing plays; `--wav` still records) |
| `--capture-scene` | Captures read the game's picture without overlays, in a shown window |
| `PS2X_CAPTURE_WINDOW_DIR=<dir>` | F8/F9 capture destination |
| `PS2X_CAPTURE_SEQUENCE=<n>`, `PS2X_CAPTURE_SEQUENCE_AT=<s>[,<s>...]` | Consecutive presents at F8 or the chosen times, with interpolation timing metadata |
| `PS2X_CAPTURE_BURST_AT=<s>[,<s>...]` | Start/stop an F9-style burst at the chosen times |
| `PS2X_CAPTURE_DIR=<dir>`, `PS2X_CAPTURE_INTERVAL=<s>` | Periodic picture captures |
| `--audio-stats`, `--audio-latency <ms>` | Audio queue/underrun diagnostics and queue target |
| `--wav <file>`, `PS2X_AUDIO_RECORD=<file>` | Record the native mixer output |
| `--no-sound` | Disable device playback for a diagnostic run |
| `--no-sound` | Disable device playback (test runs; `--wav` still records) |
| `PS2X_SETTINGS_OPEN=Controls\|Video\|Cheats` | Open F2 directly on a tab for UI tests |
| `PS2X_LOG_FILE=<file>\|0`, `PS2X_NO_DIALOGS=1`, `PS2X_TEST_CRASH=<s>` | Another log/none, suppress unattended dialogs, or intentionally test crash handling |
| `TMB_CHEATS_LOG=1`, `TMB_CHEATS_TOGGLE=<s>` | Cheat diagnostics and periodic switching for tests |
Expand Down
5 changes: 4 additions & 1 deletion bozo/tmb_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
// --window (builds with TMB_WINDOW): the same pinned run, its frames shown in a window as they are made (BozoEngine's
// window, the renderer's present), to capture the pictures of chosen frames (milestone M5's pixel comparison):
// tmb-check <log.clg> ... --window --capture-frames n,n,... [--capture-dir dir] [--width w --height h]
// [--render-scale s] [--aspect a]
// [--render-scale s] [--aspect a] [--hidden]
// --capture-frames n: the picture once n frames have ended, i.e. the reference record n - 1's frame (frame_<n>.png). The
// run is held at that frame's end until the window has read it back, so the picture is exactly that frame's. The window
// is 640x448 at render scale 1 by default; --aspect is the picture's shape inside it (4:3 by default, letterboxed).
// --hidden: the window is never shown, and the captures read the game's offscreen picture (the same pixels).
#include "run_main.h"

#if TMB_CHECK_WINDOW
Expand Down Expand Up @@ -86,6 +87,8 @@ namespace
window.renderScale = std::stof(value());
else if (a == "--aspect")
window.aspect = std::stof(value());
else if (a == "--hidden")
window.hidden = true;
else
rest.push_back(args[k]);
}
Expand Down
12 changes: 10 additions & 2 deletions bozo/tmb_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
//
// tmb [--iso image] [--elf SCUS_971.01] [--card-dir dir] [--width w --height h] [--fullscreen] [--no-vsync]
// [--render-scale s] [--capture-dir dir] [--capture-frames n,n,...] [--quit-after n] [--pad-script [n=]file]...
// [--no-sound] [--audio-latency ms] [--audio-stats] [--wav file]
// [--no-sound] [--audio-latency ms] [--audio-stats] [--wav file] [--hidden] [--capture-scene]
// [--save-state file --save-state-at n] [--load-state file [--load-state-at n]]
//
// --hidden: a test run that shows nothing (the window is never shown; --capture-frames reads the game's offscreen
// picture). --capture-scene: captures read that picture (no overlays) in a shown window too.
//
// The user folder (%APPDATA%\TMB_Recomp, as the fork's TMB; PS2X_USER_DIR overrides it) holds input.ini, the memory
// cards (mc0, mc1; --card-dir overrides) and the logs (logs/TMB_Recomp.log). Without --elf the game data is looked for
Expand Down Expand Up @@ -119,6 +123,10 @@ int main(int argc, char **argv)
if (!item.empty())
window.captureFrames.push_back(std::stoull(item));
}
else if (a == "--hidden")
window.hidden = true; // a test run that shows nothing: captures read the game's offscreen picture
else if (a == "--capture-scene")
window.captureScene = true; // captures read the game's picture (no overlays) even in a shown window
else if (a == "--quit-after")
window.quitAfterFrames = std::stoull(value());
else if (a == "--print")
Expand All @@ -142,7 +150,7 @@ int main(int argc, char **argv)
else
{
std::fprintf(stderr, "usage: tmb [--iso image] [--elf path] [--card-dir dir] [--width w] [--height h] [--fullscreen] "
"[--no-vsync] [--render-scale s] [--capture-dir dir] [--capture-frames n,n,...] [--quit-after n] "
"[--no-vsync] [--render-scale s] [--capture-dir dir] [--capture-frames n,n,...] [--quit-after n] [--hidden] [--capture-scene] "
"[--pad-script [n=]file]... [--print] [--no-sound] [--audio-latency ms] [--audio-stats] [--wav file] "
"[--save-state file --save-state-at n] [--load-state file [--load-state-at n]]\n");
return 2;
Expand Down
16 changes: 16 additions & 0 deletions tests/host_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// The host's floating-point control word (MXCSR) in the native tests.
//
// BozoEngine's ps2f takes the host's own float add / mul where it gives the PS2's bits (operands and result normal,
// rounded to nearest: BozoEngine e1518bf). So the game's original code is exact only when the host rounds to nearest,
// as the game runs, and it leaves the sticky status flags set as SSE does. The tests run the original at the caller's
// word rounding to nearest (its flush-to-zero and denormals-are-zero kept, which both sides follow), the native code at
// the caller's varied word, and compare the control word without the six status flags (nothing reads them).
#pragma once

namespace tmb::test
{
// The word the original runs at: the caller's, rounding to nearest, the status flags clear.
inline unsigned referenceControl(unsigned control) { return control & ~0x603fu; }
// The control part equal: rounding, flush to zero, denormals-are-zero, the masks (not the status flags).
inline bool sameControl(unsigned a, unsigned b) { return ((a ^ b) & ~0x3fu) == 0; }
}
14 changes: 8 additions & 6 deletions tests/native_contact_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
// Compare actual generated original blocks against the production instruction dispatcher, including ordered aliases.
#include "host_control.h"
#include "tmb_contact_math.h"
#include "tmb_native_math.h"
#include "tmb_contact_original.h"
Expand Down Expand Up @@ -201,7 +202,7 @@ namespace
if (kind == 6 && ctx.pc == 0xbad0000) return;
throw std::runtime_error("contact continuation did not reach query boundary");
};
const auto control = ((saved | 0x1f80u) & ~0xe040u) | (mode << 13u) | (n & 1 ? 0x8040u : 0u);
const auto control = tmb::test::referenceControl(((saved | 0x1f80u) & ~0xe040u) | (mode << 13u) | (n & 1 ? 0x8040u : 0u)); // generated code on both sides: the game's rounding
auto a = initial, b = initial;
_mm_setcsr(control); run(false, a); const auto refControl = _mm_getcsr(); const auto refYields = services.yields;
for (unsigned i = 0; i < outputs; ++i) std::memcpy(ram + output[i] + 12, payload(output[i]) + 12, 4);
Expand All @@ -215,10 +216,10 @@ namespace
const bool untouched = !std::memcmp(reinterpret_cast<uint8_t *>(&initial) + vuAt, reinterpret_cast<uint8_t *>(&b) + vuAt, vuBytes);
std::memset(reinterpret_cast<uint8_t *>(&a) + vuAt, 0, vuBytes);
std::memset(reinterpret_cast<uint8_t *>(&b) + vuAt, 0, vuBytes);
if (std::memcmp(&a, &b, sizeof(a)) || !untouched || after != refControl || refYields != services.yields ||
if (std::memcmp(&a, &b, sizeof(a)) || !untouched || !tmb::test::sameControl(after, refControl) || refYields != services.yields ||
std::memcmp(expectedAll.get(), ram + base, bytes) || std::memcmp(expectedAll.get() + bytes, ram + globals, globalBytes) ||
(n < 4 && std::memcmp(whole.get(), ram, bozo::kFlatBytes)))
{ std::fprintf(stderr, "FAIL contact continuation %u case %u mode %u CPU%d VU%d FP%d data%d globals%d\n",kind,n,mode,std::memcmp(&a,&b,sizeof(a)),untouched,after==refControl,std::memcmp(expectedAll.get(),ram+base,bytes),std::memcmp(expectedAll.get()+bytes,ram+globals,globalBytes)); throw std::runtime_error("contact continuation differs"); }
{ std::fprintf(stderr, "FAIL contact continuation %u case %u mode %u CPU%d VU%d FP%d data%d globals%d\n",kind,n,mode,std::memcmp(&a,&b,sizeof(a)),untouched,tmb::test::sameControl(after, refControl),std::memcmp(expectedAll.get(),ram+base,bytes),std::memcmp(expectedAll.get()+bytes,ram+globals,globalBytes)); throw std::runtime_error("contact continuation differs"); }
++cases;
}
host.enabled = true; rt.services = nullptr;
Expand Down Expand Up @@ -279,11 +280,12 @@ int main()
if (site.translation) setRegU32(&initial, site.translation, (translation | alias) + ((n >> 8u) & 15u));
R5900Context original = initial, native = initial;
const unsigned control = ((savedControl | 0x1f80u) & ~0xe040u) | (mode << 13u) | (n & 1u ? 0x8040u : 0u);
_mm_setcsr(control);
_mm_setcsr(tmb::test::referenceControl(control));
originalBlock(index, ram, original, rt.get());
std::memcpy(expected.data(), arena, arenaBytes);
if (n < 8) { std::memcpy(whole.get(), ram, bozo::kFlatBytes); ++wholeCases; }
std::memcpy(arena, input.data(), arenaBytes);
_mm_setcsr(control);
for (uint32_t pc = site.first; pc <= site.last; pc += 4)
{
if (!handler(ram, &native, rt.get(), pc)) return 2;
Expand All @@ -292,10 +294,10 @@ int main()
const unsigned after = _mm_getcsr();
_mm_setcsr(savedControl);
if (std::memcmp(arena, expected.data(), arenaBytes) || std::memcmp(&native, &initial, sizeof(initial)) ||
after != control || (n < 8 && std::memcmp(whole.get(), ram, bozo::kFlatBytes)))
!tmb::test::sameControl(after, control) || (n < 8 && std::memcmp(whole.get(), ram, bozo::kFlatBytes)))
{
std::fprintf(stderr, "FAIL contact block %u case %u mode %u: memory %d CPU/VU %d host %d\n", index, n, mode,
std::memcmp(arena, expected.data(), arenaBytes), std::memcmp(&native, &initial, sizeof(initial)), after == control);
std::memcmp(arena, expected.data(), arenaBytes), std::memcmp(&native, &initial, sizeof(initial)), tmb::test::sameControl(after, control));
return 4;
}
host.enabled = false;
Expand Down
15 changes: 8 additions & 7 deletions tests/native_direction_callers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
// Run the generated BSP collision setup through its real XYZ consumers. No copied game code is committed.
#include "host_control.h"
#include "tmb_port.h"
#include "tmb_native_math.h"
#include "bozo/libs/libraries.h"
Expand Down Expand Up @@ -123,7 +124,7 @@ void testDirectionCallers()
const float radius = 6.5f; std::memcpy(&initial.fu[20], &radius, 4);
std::memcpy(input.get(), ram + 0x10000, arenaBytes);
std::memcpy(input.get() + arenaBytes, ram + globals, globalBytes);
const unsigned control = ((saved | 0x1f80) & ~0xe040u) | (mode << 13) | (n & 1 ? 0x8040 : 0);
const unsigned control = tmb::test::referenceControl(((saved | 0x1f80) & ~0xe040u) | (mode << 13) | (n & 1 ? 0x8040 : 0)); // generated code on both sides: the game's rounding
const auto run = [&](RecompiledFunction direction, R5900Context &ctx)
{
services.yields = 0; rt->functions.setOverride(0x1da298, direction);
Expand All @@ -145,7 +146,7 @@ void testDirectionCallers()
std::memcpy(ram + 0x10000, input.get(), arenaBytes);
std::memcpy(ram + globals, input.get() + arenaBytes, globalBytes);
run(nativeDirection, b); const unsigned after = _mm_getcsr(); _mm_setcsr(saved);
if (!cpuEqual(a, b) || !vuUntouched(initial, b) || after != control || referenceYields != services.yields ||
if (!cpuEqual(a, b) || !vuUntouched(initial, b) || !tmb::test::sameControl(after, control) || referenceYields != services.yields ||
std::memcmp(expected.get(), ram + 0x10000, arenaBytes) ||
std::memcmp(expected.get() + arenaBytes, ram + globals, globalBytes) ||
(n < 4 && std::memcmp(whole.get(), ram, bozo::kFlatBytes)))
Expand Down Expand Up @@ -248,7 +249,7 @@ void testDirectionCallers()
setRegU32(&initial, 6, address(output)); word(output + 12, bits());
// Both light directions may execute in one continuation; both opaque W words must stay untouched.
std::memcpy(input.get(), ram + 0x10000, arenaBytes);
const unsigned control = ((saved | 0x1f80) & ~0xe040u) | (mode << 13) | (n & 1 ? 0x8040 : 0);
const unsigned control = tmb::test::referenceControl(((saved | 0x1f80) & ~0xe040u) | (mode << 13) | (n & 1 ? 0x8040 : 0)); // generated code on both sides: the game's rounding
const auto run = [&](RecompiledFunction direction, R5900Context &ctx)
{
services.yields = 0; rt->functions.setOverride(0x1da298, direction);
Expand All @@ -269,12 +270,12 @@ void testDirectionCallers()
_mm_setcsr(control); run(nativeDirection, b);
const unsigned after = _mm_getcsr(); _mm_setcsr(saved);
// Original scalar normalization can raise host exception flags; compare its complete FP effects too.
if (!cpuEqual(a, b) || !vuUntouched(initial, b) || after != referenceControl || referenceYields != services.yields ||
if (!cpuEqual(a, b) || !vuUntouched(initial, b) || !tmb::test::sameControl(after, referenceControl) || referenceYields != services.yields ||
std::memcmp(expected.get(), ram + 0x10000, arenaBytes) ||
(n < 4 && std::memcmp(whole.get(), ram, bozo::kFlatBytes)))
{
std::fprintf(stderr, "FAIL vehicle/light caller %x case %u mode %u CPU%d data%d FP%d yields %u/%u\n",
caller, n, mode, cpuEqual(a, b), std::memcmp(expected.get(), ram + 0x10000, arenaBytes), after == referenceControl,
caller, n, mode, cpuEqual(a, b), std::memcmp(expected.get(), ram + 0x10000, arenaBytes), tmb::test::sameControl(after, referenceControl),
referenceYields, services.yields);
throw std::runtime_error("vehicle/light direction consumer differs");
}
Expand Down Expand Up @@ -307,7 +308,7 @@ void testDirectionCallers()
const uint32_t alias = n % 3 == 0 ? 0x80000000 : n % 3 == 1 ? 0x20000000 : 0;
setRegU32(&initial, 4, vehicle | alias); setRegU32(&initial, 5, n % 4);
setRegU32(&initial, 29, sp | alias); initial.pc = 0x118178; initial.cycleLimit = 0;
const unsigned control = ((saved | 0x1f80) & ~0xe040u) | (mode << 13) | (n & 1 ? 0x8040 : 0);
const unsigned control = tmb::test::referenceControl(((saved | 0x1f80) & ~0xe040u) | (mode << 13) | (n & 1 ? 0x8040 : 0)); // generated code on both sides: the game's rounding
const auto run = [&](R5900Context &ctx)
{
services.yields = 0;
Expand All @@ -324,7 +325,7 @@ void testDirectionCallers()
const uint32_t poisonedW = bits(); std::memcpy(ram + result + 12, &poisonedW, 4);
_mm_setcsr(control); run(b); const auto after = _mm_getcsr(); _mm_setcsr(saved);
std::memcpy(ram + result + 12, input.get() + result - 0x10000 + 12, 4);
require(!std::memcmp(&a, &b, sizeof(a)) && after == referenceControl && services.yields == referenceYields &&
require(!std::memcmp(&a, &b, sizeof(a)) && tmb::test::sameControl(after, referenceControl) && services.yields == referenceYields &&
!std::memcmp(expected.get(), ram + 0x10000, arenaBytes) &&
(n >= 4 || !std::memcmp(whole.get(), ram, bozo::kFlatBytes)), "contact position W affected XYZ consumer");
++contactCases;
Expand Down
Loading
Loading