mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 22:58:37 +00:00
One squashed commit of a fork that was developed on a Linux/Proton machine and tested on two native Windows machines. On all of them the retail 1.0.2.1 package now launches, shows its launch movie, first-run pages and landing prompt, runs the story load to its end with the loading slideshow drawing its artwork, and enters the world phase. A first world frame is not verified yet. docs/linux_proton.md has the setup, a healthy boot's timeline, the machines and where it stops. Runtime: frames in the title's own window; DirectStorage pinned reads, page-list scatter/gather, BCPack and unshuffle with a locally generated predictor file; pooled, device-local and deferred image backing for streamed and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table that degrades instead of refusing a submission; a descriptor hash finalizer (off until a library carries it); directly indexed heap offsets for compute dispatches and VS/PS/GS draws; title buffer windows outside a fragmented arena; opt-in device-local copies of streamed buffer views; write-fault retries under the tracker lock, shared trackers and write-watched title memory for native Windows; device-loss, compute-input and memory probes. Translator: loop bounds at structured exits, the eight FidelityFX programs that use a packed-dot form the disassembler skips, buffer bounds modes per view kind, a compaction option, the hash finalizer option. Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows boot script, the paired compute translation script. No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted by people on the machines named in docs/linux_proton.md. Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
94 lines
4.2 KiB
C++
94 lines
4.2 KiB
C++
// The two pure decisions behind D3D-704: how large a session cache may be (LEONIDA_PIPELINE_CACHE_BYTES) and
|
|
// whether a blob's VkPipelineCacheHeaderVersionOne names this device. No Vulkan, no GPU, no files.
|
|
#include "../src/pipeline_cache_store.h"
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <limits>
|
|
#include <string>
|
|
|
|
#define CHECK(condition) do { \
|
|
if (!(condition)) { \
|
|
std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); \
|
|
return 1; \
|
|
} \
|
|
} while (0)
|
|
|
|
namespace store = leonida::pipeline_cache_store;
|
|
|
|
static void put32(std::uint8_t* p, std::uint32_t value) {
|
|
for (int i = 0; i < 4; ++i) p[i] = static_cast<std::uint8_t>(value >> (8 * i));
|
|
}
|
|
|
|
static int test_limit() {
|
|
using store::default_save_limit;
|
|
// Absent, empty and the default knob.
|
|
CHECK(store::parse_save_limit(nullptr).bytes == default_save_limit);
|
|
CHECK(store::parse_save_limit(nullptr).valid);
|
|
CHECK(store::parse_save_limit("").bytes == default_save_limit);
|
|
// 0 is the documented "off", not a typo, and leading zeros are still a number.
|
|
CHECK(store::parse_save_limit("0").bytes == 0);
|
|
CHECK(store::parse_save_limit("0").valid);
|
|
CHECK(store::parse_save_limit("007").bytes == 7);
|
|
CHECK(store::parse_save_limit("1048576").bytes == 1048576);
|
|
const std::string largest = std::to_string(std::numeric_limits<std::size_t>::max());
|
|
CHECK(store::parse_save_limit(largest.c_str()).bytes == std::numeric_limits<std::size_t>::max());
|
|
// Anything that is not a plain byte count falls back to the default and says the value was rejected.
|
|
for (const char* text : {"-1", "+1", " 1", "1 ", "12x", "0x10", "1.5", "99999999999999999999999999"}) {
|
|
const auto limit = store::parse_save_limit(text);
|
|
CHECK(!limit.valid);
|
|
CHECK(limit.bytes == default_save_limit);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int test_header() {
|
|
leonida::cached_pso::Identity identity;
|
|
identity.vendor = 0x1002;
|
|
identity.device = 0x73ff;
|
|
identity.driver = 0x02000d0b;
|
|
|
|
std::uint8_t header[store::header_bytes] = {};
|
|
put32(header, store::header_bytes);
|
|
put32(header + 4, store::header_version_one);
|
|
put32(header + 8, identity.vendor);
|
|
put32(header + 12, identity.device);
|
|
for (int i = 0; i < 16; ++i) header[16 + i] = identity.cache_uuid[i] = static_cast<std::uint8_t>(i + 1);
|
|
CHECK(store::header_matches(header, sizeof(header), identity));
|
|
// Extra payload past the header does not matter: the driver reads the header and then its own data.
|
|
std::uint8_t blob[store::header_bytes + 8] = {};
|
|
std::memcpy(blob, header, sizeof(header));
|
|
CHECK(store::header_matches(blob, sizeof(blob), identity));
|
|
|
|
// Too short and null are "no cache", never a read past the end.
|
|
CHECK(!store::header_matches(header, store::header_bytes - 1, identity));
|
|
CHECK(!store::header_matches(nullptr, store::header_bytes, identity));
|
|
|
|
// The four fields a driver checks before trusting a blob from another device, driver or header version.
|
|
auto differs = [&](int offset, std::uint32_t value) {
|
|
std::uint8_t changed[store::header_bytes];
|
|
std::memcpy(changed, header, sizeof(changed));
|
|
put32(changed + offset, value);
|
|
return !store::header_matches(changed, sizeof(changed), identity);
|
|
};
|
|
CHECK(differs(0, store::header_bytes + 4));
|
|
CHECK(differs(4, store::header_version_one + 1));
|
|
CHECK(differs(8, identity.vendor + 1));
|
|
CHECK(differs(12, identity.device + 1));
|
|
std::uint8_t uuid[store::header_bytes];
|
|
std::memcpy(uuid, header, sizeof(uuid));
|
|
uuid[16] ^= 0xff;
|
|
CHECK(!store::header_matches(uuid, sizeof(uuid), identity));
|
|
// vendorID/deviceID are u32s little-endian; the same bytes read the other way name another device.
|
|
leonida::cached_pso::Identity swapped = identity;
|
|
swapped.vendor = 0x02100000;
|
|
CHECK(!store::header_matches(header, sizeof(header), swapped));
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
if (const int failed = test_limit()) return failed;
|
|
return test_header();
|
|
}
|