diff --git a/AGENTS.md b/AGENTS.md index 9c4661f916..2e866443fc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,7 +17,7 @@ for it: | [docs/DebuggerThreading.md](docs/DebuggerThreading.md) | `Core_RunOnCPUThread` / `g_frameMutex` / shutdown-lock rules - required reading before touching debugger code | | [docs/HLEModules.md](docs/HLEModules.md) | Adding an HLE module or function, and the seven build files a new source file goes in | | [docs/translations.md](docs/translations.md) | Translating UI strings with Tools/langtool | -| [docs/pspautotests.md](docs/pspautotests.md) | Workflow for improving PPSSPP using pspautotests | +| [docs/pspautotests.md](docs/pspautotests.md) | Workflow for improving PPSSPP using pspautotests, and running the tests that need the real firmware modules (`--disable-hle`, a firmware memstick) | | [docs/pspautotests-hardware.md](docs/pspautotests-hardware.md) | Writing a new pspautotest, and running it on a real PSP over PSPLink to record its `.expected` | | [docs/frametest.md](docs/frametest.md) | Framedump rendering tests, and replaying a dump on a real PSP | | [docs/sceGe.md](docs/sceGe.md) | How the firmware queues display lists, what SIGNAL and FINISH interrupts do and in which order, and how `ProcessDLQueue()` keeps that order | diff --git a/Core/CmdLine.cpp b/Core/CmdLine.cpp index 45a1fba82a..92526ad8cd 100644 --- a/Core/CmdLine.cpp +++ b/Core/CmdLine.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -51,6 +52,34 @@ enum class ParseParamResult { BadValue, }; +// Decimal, or hex with 0x, optionally signed. Not base 0, which would read a leading 0 as octal. +// Up to 0xFFFFFFFF is accepted so a full 32-bit mask can be given, and wraps into the int. +static bool ParseIntParam(const std::string &value, int *out) { + const char *p = value.c_str(); + bool negative = false; + if (*p == '-' || *p == '+') { + negative = *p == '-'; + p++; + } + int base = 10; + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + base = 16; + p += 2; + } + // strtoull would take another sign or leading spaces here. + if (!isxdigit((unsigned char)*p)) { + return false; + } + char *end = nullptr; + errno = 0; + const unsigned long long magnitude = strtoull(p, &end, base); + if (*end != '\0' || errno == ERANGE || magnitude > (negative ? 0x80000000ULL : 0xFFFFFFFFULL)) { + return false; + } + *out = negative ? (int)(0 - (uint32_t)magnitude) : (int)(uint32_t)magnitude; + return true; +} + ParseParamResult SetValue(CommandLineOptions *options, const CommandLineParam ¶m, const std::string &value) { uint8_t *optionsPtr = reinterpret_cast(options); switch (param.type) { @@ -77,7 +106,7 @@ ParseParamResult SetValue(CommandLineOptions *options, const CommandLineParam &p { // Not std::stoi - that throws on junk, which takes the process down with no diagnostic. int v; - if (sscanf(value.c_str(), "%d", &v) != 1) { + if (!ParseIntParam(value, &v)) { PRINT_STDERR("Error: Invalid value for integer parameter --%s: '%s'.\n", param.longName, value.c_str()); return ParseParamResult::BadValue; } diff --git a/Core/HW/AvcDecoder.cpp b/Core/HW/AvcDecoder.cpp index 2d808c100d..8944455416 100644 --- a/Core/HW/AvcDecoder.cpp +++ b/Core/HW/AvcDecoder.cpp @@ -169,6 +169,8 @@ void AvcDecoder::Flush() { timings_.clear(); lastTiming_ = AvcTiming(); bufferingTick_ = 0; + lastRemovalTick_ = 0; + removalStep_ = 2; firstTiming_ = true; nextIndex_ = 0; released_ = 0; @@ -429,11 +431,24 @@ int AvcDecoder::DecodePictures(const u8 *data, int size) { if (parser_->dts_ref_dts_delta != INT_MIN && parser_->pts_dts_delta != INT_MIN) { timed = true; if (parser_->dts_sync_point > 0) { - bufferingTick_ = firstTiming_ ? 0 : bufferingTick_ + parser_->dts_ref_dts_delta; + if (firstTiming_) { + bufferingTick_ = 0; + } else if (parser_->dts_ref_dts_delta > 0) { + bufferingTick_ += parser_->dts_ref_dts_delta; + } else { + // A new stream fed in without a flush (Burnout Legends' intro movies) starts its + // clock over. Carry on from the last access unit, or every picture after this + // one waits until the new clock catches up with the old one. + bufferingTick_ = lastRemovalTick_ + removalStep_; + } removalTick = bufferingTick_; } else { removalTick = bufferingTick_ + parser_->dts_ref_dts_delta; } + if (!firstTiming_ && removalTick > lastRemovalTick_) { + removalStep_ = removalTick - lastRemovalTick_; + } + lastRemovalTick_ = removalTick; firstTiming_ = false; outputTicks_[index] = removalTick + parser_->pts_dts_delta; lastTiming_.picTiming = true; diff --git a/Core/HW/AvcDecoder.h b/Core/HW/AvcDecoder.h index 192ffc6aa1..ff4608a351 100644 --- a/Core/HW/AvcDecoder.h +++ b/Core/HW/AvcDecoder.h @@ -138,6 +138,9 @@ private: std::map timings_; AvcTiming lastTiming_; s64 bufferingTick_ = 0; + // The last access unit's removal tick, and how far apart the last two were (2 ticks a frame). + s64 lastRemovalTick_ = 0; + s64 removalStep_ = 2; bool firstTiming_ = true; int nextIndex_ = 0; int released_ = 0; diff --git a/docs/pspautotests.md b/docs/pspautotests.md index 24134285fc..052652f47b 100644 --- a/docs/pspautotests.md +++ b/docs/pspautotests.md @@ -57,6 +57,32 @@ Instead of a single PRX, you can pass a directory (e.g. `pspautotests/tests/thre same idea in emulated time, and both can be set at once. `--timeout` is the old name for `--timeout-wall`. - `--graphics=software` — uses software GPU backend (required for headless; no real GPU available). +### Tests that need the real firmware modules + +A pspautotest is homebrew, so headless runs every library on our HLE for it +(`iForceEnableHLE` in `headless/Headless.cpp`), even the ones the app runs from the firmware by +default. Some tests only mean anything against the real module: `video/mp4/avchold` and +`video/mpeg/decodeend` test the Media Engine through Sony's `libmp4.prx`, `mp4msv.prx` and +`mpeg.prx`, which call our `sceVideocodec` HLE. Run on our HLE, `avchold` reports +`0 samples, 0 decodes` for every stream (our sceMp4 is stubs: the log says `UNIMPL sceMp4Create`), +and it fails without exercising the decoder at all. + +To run them as the hardware does, pass both: + +- `--disable-hle=N`, the `DisableHLEFlags` bits (`Core/ConfigValues.h`) of the libraries to run + for real, in decimal or `0x` hex. sceMpeg is 0x10 and sceMp4 is 0x100, so the video tests take + `--disable-hle=0x110`. +- `--memstick=` pointing at a memory stick with a firmware dump in `PSP/NAND/flash0/kd`. `test.py` + otherwise hands headless the empty one beside the exe. Since the flag is explicit, headless exits + with an error naming the missing module rather than falling back to HLE. + +``` +python test.py video/mp4/avchold video/mpeg/decodeend --graphics=software --memstick= --disable-hle=0x110 +``` + +CI has no firmware dump, so these tests stay in `tests_next`, and a change to the video path +needs this run done by hand. + ### What you'll see **Passing test:** diff --git a/pspautotests b/pspautotests index 74cdeea078..51fc2c4d87 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 74cdeea078403a9d877b99e28c3cad85ba7f3d7f +Subproject commit 51fc2c4d87fc09df9e87a62e1755ae4816cda13a diff --git a/test.py b/test.py index d8b974add4..fe430cad47 100755 --- a/test.py +++ b/test.py @@ -675,9 +675,9 @@ tests_next = [ #"utility/savedata/saveemptyfilename", "utility/savedata/secureversion", "utility/savedata/sizes", - "video/mp4/avchold", + "video/mp4/avchold", # needs Sony's mp4 and mpeg modules: --disable-hle=0x110, see docs/pspautotests.md "video/mpeg/basic", - "video/mpeg/decodeend", + "video/mpeg/decodeend", # needs Sony's mpeg module, as avchold "video/mpeg/deletetiming", "video/pmf/pmf", "video/pmf_simple/pmf_simple", diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index da1860fb52..f82f42f424 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -3391,6 +3391,33 @@ bool TestCmdLine() { EXPECT_TRUE(options.memStickInserted.has_value()); EXPECT_FALSE(options.memStickInserted.value_or(true)); } + // Integers take decimal or 0x hex. A leading 0 is still decimal, and a full 32-bit mask wraps + // into the int rather than being refused. + { + const char *argv[] = { + "ppsspp", + "--disable-hle=0x110", + "--force-hle=0xFFFFFFFF", + "--cpu-mhz=0333", + "--resolution-scale=-2", + }; + int argc = ARRAY_SIZE(argv); + CommandLineOptions options; + EXPECT_EQ_INT((int)options.Parse(argc, argv, CmdLineMode::Headless), (int)CommandLineParseResult::Continue); + EXPECT_EQ_INT(options.disableHLE.value_or(0), 0x110); + EXPECT_EQ_INT(options.forceHLE.value_or(0), -1); + EXPECT_EQ_INT(options.lockedCPUSpeed.value_or(0), 333); + EXPECT_EQ_INT(options.resolutionScale.value_or(0), -2); + } + // Trailing junk used to be ignored, so 0x110 quietly meant 0. + { + const char *bad[] = { "--disable-hle=0x110junk", "--disable-hle=12abc", "--disable-hle=0x", "--disable-hle= 5", "--disable-hle=0x100000000", "--disable-hle=--1" }; + for (const char *arg : bad) { + const char *argv[] = { "ppsspp", arg }; + CommandLineOptions options; + EXPECT_EQ_INT((int)options.Parse(ARRAY_SIZE(argv), argv, CmdLineMode::Headless), (int)CommandLineParseResult::Error); + } + } // Test GL version override { const char *argv[] = {