upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorASTROWwwW <astrxwledev@gmail.com>2026-11-23 19:39:53 +0100
committerASTROWwwW <astrxwledev@gmail.com>2026-11-23 19:39:53 +0100
commitb487b6d8ccf1d15d723367752a71439c3db077e5 (patch)
treec3f78c0e21c56e7da1dd4e5a024c845389dd4da0 /runtime
parent5caef48a194d1a39d0568427cdbb4da22a482817 (diff)
parentbc5fc47b9c7b57f155166963b880154a7c0aa95d (diff)
Merge branch 'pr7746' into ladder-frame
# Conflicts: # make_game.py # runtime/src/shader_library.h # runtime/test/shader_library_test.cpp
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/shader_library.h12
-rw-r--r--runtime/test/shader_library_corpus_test.cpp8
-rw-r--r--runtime/test/shader_library_test.cpp60
3 files changed, 74 insertions, 6 deletions
diff --git a/runtime/src/shader_library.h b/runtime/src/shader_library.h
index 1513432e3..210b54ec6 100644
--- a/runtime/src/shader_library.h
+++ b/runtime/src/shader_library.h
@@ -729,7 +729,9 @@ public:
729 // fssm_sha256 like the game's own shaders (docs/embedded_shaders.md); 729 // fssm_sha256 like the game's own shaders (docs/embedded_shaders.md);
730 // - <dir>/library/index.json, the compute programs of the pipeline library in shaders.rpf, which the executable 730 // - <dir>/library/index.json, the compute programs of the pipeline library in shaders.rpf, which the executable
731 // creates with slot 67; entries named "library/<name>" and found by fspx_code_sha256 and fspx_state_sha256 731 // creates with slot 67; entries named "library/<name>" and found by fspx_code_sha256 and fspx_state_sha256
732 // like the FSPX ones (docs/shader_library.md). 732 // like the FSPX ones (docs/shader_library.md);
733 // - <dir>/exe/index.json, game_scarlett_master.exe's embedded FSSM programs, entries named "exe/<name>" and
734 // found by fssm_sha256 like the game's own shaders (docs/embedded_shaders.md).
733 // Entries with neither fssm_sha256 nor fspx_code_sha256 cannot be found by content and are skipped. The folders 735 // Entries with neither fssm_sha256 nor fspx_code_sha256 cannot be found by content and are skipped. The folders
734 // are optional: a missing or unreadable index there leaves the main one, and the other folders', loaded. 736 // are optional: a missing or unreadable index there leaves the main one, and the other folders', loaded.
735 bool load(const std::filesystem::path& dir, std::string* error = nullptr) { 737 bool load(const std::filesystem::path& dir, std::string* error = nullptr) {
@@ -743,7 +745,7 @@ public:
743 } catch (...) { 745 } catch (...) {
744 return fail("index.json could not be read"); 746 return fail("index.json could not be read");
745 } 747 }
746 for (const char* folder : {"fspx", "bvh", "library"}) { 748 for (const char* folder : {"fspx", "bvh", "library", "exe"}) {
747 try { 749 try {
748 const auto ignore = [](const std::string&) { return false; }; 750 const auto ignore = [](const std::string&) { return false; };
749 const std::filesystem::path sub = dir / folder; 751 const std::filesystem::path sub = dir / folder;
@@ -764,6 +766,9 @@ public:
764 // Entries loaded from <dir>/bvh/index.json. No RPF container reaches these either: XboxBvhBuilder.dll passes 766 // Entries loaded from <dir>/bvh/index.json. No RPF container reaches these either: XboxBvhBuilder.dll passes
765 // their containers itself. 767 // their containers itself.
766 std::size_t bvh_size() const { return bvh_count_; } 768 std::size_t bvh_size() const { return bvh_count_; }
769 // Entries loaded from <dir>/exe/index.json. No RPF container reaches these either: game_scarlett_master.exe
770 // embeds their containers itself.
771 std::size_t exe_size() const { return exe_count_; }
767 772
768 // The first entry for this program. Two containers can hold the same FSSM program with different input 773 // The first entry for this program. Two containers can hold the same FSSM program with different input
769 // signatures; `candidates` returns all of them. 774 // signatures; `candidates` returns all of them.
@@ -867,6 +872,7 @@ private:
867 count_ = 0; 872 count_ = 0;
868 fspx_count_ = 0; 873 fspx_count_ = 0;
869 bvh_count_ = 0; 874 bvh_count_ = 0;
875 exe_count_ = 0;
870 } 876 }
871 for (const auto& [name, meta] : root.object) { 877 for (const auto& [name, meta] : root.object) {
872 const Json* hash = meta.find("fssm_sha256"); 878 const Json* hash = meta.find("fssm_sha256");
@@ -932,6 +938,7 @@ private:
932 if (by_fssm) entries_[{e.stage, e.fssm_sha256}].push_back(std::move(e)); 938 if (by_fssm) entries_[{e.stage, e.fssm_sha256}].push_back(std::move(e));
933 if (by_fspx && (prefix == "fspx/" || prefix == "library/")) ++fspx_count_; 939 if (by_fspx && (prefix == "fspx/" || prefix == "library/")) ++fspx_count_;
934 if (prefix == "bvh/") ++bvh_count_; 940 if (prefix == "bvh/") ++bvh_count_;
941 if (prefix == "exe/") ++exe_count_;
935 ++count_; 942 ++count_;
936 } 943 }
937 return true; 944 return true;
@@ -941,6 +948,7 @@ private:
941 std::size_t count_ = 0; 948 std::size_t count_ = 0;
942 std::size_t fspx_count_ = 0; 949 std::size_t fspx_count_ = 0;
943 std::size_t bvh_count_ = 0; 950 std::size_t bvh_count_ = 0;
951 std::size_t exe_count_ = 0;
944 // Entries by (stage, fssm_sha256) and by (stage, fspx_code_sha256), in index order. 952 // Entries by (stage, fssm_sha256) and by (stage, fspx_code_sha256), in index order.
945 Entries entries_; 953 Entries entries_;
946 Entries fspx_entries_; 954 Entries fspx_entries_;
diff --git a/runtime/test/shader_library_corpus_test.cpp b/runtime/test/shader_library_corpus_test.cpp
index 7fdba2374..bb0be8c72 100644
--- a/runtime/test/shader_library_corpus_test.cpp
+++ b/runtime/test/shader_library_corpus_test.cpp
@@ -192,16 +192,16 @@ int main() {
192 } 192 }
193 193
194 if (containers == 0) fail("no .dxbc containers in", dxbc_dir); 194 if (containers == 0) fail("no .dxbc containers in", dxbc_dir);
195 const std::size_t rpf_entries = library.size() - library.fspx_size() - library.bvh_size(); 195 const std::size_t rpf_entries = library.size() - library.fspx_size() - library.bvh_size() - library.exe_size();
196 if (reached.size() != rpf_entries) 196 if (reached.size() != rpf_entries)
197 fail(std::to_string(reached.size() > rpf_entries ? reached.size() - rpf_entries : rpf_entries - reached.size()) + 197 fail(std::to_string(reached.size() > rpf_entries ? reached.size() - rpf_entries : rpf_entries - reached.size()) +
198 " RPF index entries not matched one to one", 198 " RPF index entries not matched one to one",
199 spirv_dir); 199 spirv_dir);
200 std::printf("%zu containers, %zu RPF index entries, %zu reached, %zu FSPX index entries, %zu BVH builder index " 200 std::printf("%zu containers, %zu RPF index entries, %zu reached, %zu FSPX index entries, %zu BVH builder index "
201 "entries; %zu containers with more than one program; " 201 "entries, %zu executable index entries; %zu containers with more than one program; "
202 "%zu not translated; %d failures\n", 202 "%zu not translated; %d failures\n",
203 containers, rpf_entries, reached.size(), library.fspx_size(), library.bvh_size(), multi, untranslated, 203 containers, rpf_entries, reached.size(), library.fspx_size(), library.bvh_size(), library.exe_size(),
204 failures); 204 multi, untranslated, failures);
205 if (untranslated) 205 if (untranslated)
206 std::fprintf(stderr, "%zu container(s) have no index entry: the translator left them out, so the lookup had " 206 std::fprintf(stderr, "%zu container(s) have no index entry: the translator left them out, so the lookup had "
207 "nothing to find. Run the shaders stage again with a current translator.\n", 207 "nothing to find. Run the shaders stage again with a current translator.\n",
diff --git a/runtime/test/shader_library_test.cpp b/runtime/test/shader_library_test.cpp
index 948eb7084..40837ecc2 100644
--- a/runtime/test/shader_library_test.cpp
+++ b/runtime/test/shader_library_test.cpp
@@ -465,6 +465,66 @@ int main() {
465 std::filesystem::remove_all(dir); 465 std::filesystem::remove_all(dir);
466 } 466 }
467 467
468 // Executable embedded shaders (<dir>/exe/index.json): graphics (vs/ps) FSSM programs indexed alongside the game's
469 // own shaders, counted apart via exe_size(), and optional when missing or malformed.
470 {
471 const auto vs_container = container({{fixed, 25}});
472 const auto ps_container = container({{stored, 40}});
473 const std::string vs_hash = sha256_hex(fssm_program(vs_container));
474 const std::string ps_hash = sha256_hex(fssm_program(ps_container));
475 const auto code = fspx_code(0x5000);
476 const std::uint32_t words[5] = {0x07230203, 0x00010500, 0, 1, 0};
477 const auto write = [&](const std::filesystem::path& file, const std::string& text) {
478 std::ofstream out(file, std::ios::binary | std::ios::trunc);
479 out << text;
480 };
481 const std::string game = "\"cs_game\": {\"stage\": \"cs\", \"fssm_sha256\": \"" + hash + "\"}";
482 const std::string vs_entry = "{\"stage\": \"vs\", \"fssm_sha256\": \"" + vs_hash +
483 "\", \"input_signature\": [{\"semantic\": \"POSITION\", \"semantic_index\": 0, "
484 "\"register\": 0, \"system_value\": 0, \"component_type\": \"float\"}]}";
485 const std::string ps_entry = "{\"stage\": \"ps\", \"fssm_sha256\": \"" + ps_hash + "\"}";
486 std::filesystem::create_directories(dir / "fspx");
487 std::filesystem::create_directories(dir / "bvh");
488 std::filesystem::create_directories(dir / "exe");
489 write(dir / "index.json", "{" + game + "}");
490 write(dir / "fspx" / "index.json",
491 "{\"upscaler_00\": {\"stage\": \"cs\", \"fspx_code_sha256\": \"" + sha256_hex(code) + "\"}}");
492 write(dir / "bvh" / "index.json",
493 "{\"BuilderProgram\": {\"stage\": \"cs\", \"fssm_sha256\": \"" + hash + "\"}}");
494 write(dir / "exe" / "index.json",
495 "{\"container_00\": " + vs_entry + ",\n \"container_01\": " + ps_entry +
496 ",\n \"NoKey\": {\"error\": \"ValueError: synthetic\"}}");
497 {
498 std::ofstream spv(dir / "exe" / "container_00.spv", std::ios::binary);
499 spv.write(reinterpret_cast<const char*>(words), sizeof(words));
500 std::ofstream spv_ps(dir / "exe" / "container_01.spv", std::ios::binary);
501 spv_ps.write(reinterpret_cast<const char*>(words), sizeof(words));
502 }
503 ShaderLibrary exe;
504 CHECK(exe.load(dir.string(), &error) && exe.size() == 5 && exe.fspx_size() == 1 && exe.bvh_size() == 1 &&
505 exe.exe_size() == 2);
506 const ShaderEntry* vs = exe.find("vs", vs_hash);
507 const ShaderEntry* ps = exe.find("ps", ps_hash);
508 CHECK(vs && vs->name == "exe/container_00" && vs->input_signature.size() == 1 &&
509 vs->input_signature[0].semantic == "POSITION" && exe.spirv(*vs).size() == 5);
510 CHECK(ps && ps->name == "exe/container_01" && exe.spirv(*ps).size() == 5);
511 CHECK(exe.candidates("ps", vs_hash).empty() && exe.candidates("vs", ps_hash).empty() &&
512 exe.fspx_candidates("vs", vs_hash).empty());
513 // Same program in main index and exe/: main comes first (index order).
514 write(dir / "index.json", "{" + game + ",\n \"vs_same\": " + vs_entry + "}");
515 CHECK(exe.load(dir.string(), &error) && exe.size() == 6 && exe.exe_size() == 2);
516 const auto both = exe.candidates("vs", vs_hash);
517 CHECK(both.size() == 2 && both[0]->name == "vs_same" && both[1]->name == "exe/container_00");
518 write(dir / "index.json", "{" + game + "}");
519 // Broken or missing exe/index.json leaves main, fspx, and bvh loaded and resets exe_size() to 0.
520 write(dir / "exe" / "index.json", "{broken");
521 CHECK(exe.load(dir.string(), &error) && exe.size() == 3 && exe.exe_size() == 0 && exe.bvh_size() == 1 &&
522 exe.fspx_size() == 1 && !exe.find("vs", vs_hash));
523 std::filesystem::remove(dir / "exe" / "index.json");
524 CHECK(exe.load(dir.string(), &error) && exe.size() == 3 && exe.exe_size() == 0 && exe.find("cs", hash));
525 std::filesystem::remove_all(dir);
526 }
527
468 // XboxBvhBuilder.dll's programs (docs/embedded_shaders.md): FSSM in a DXIL container like the game's shaders, 528 // XboxBvhBuilder.dll's programs (docs/embedded_shaders.md): FSSM in a DXIL container like the game's shaders,
469 // translated into <dir>/bvh (entries named "bvh/<name>") and found by fssm_sha256, the game shaders' key. 529 // translated into <dir>/bvh (entries named "bvh/<name>") and found by fssm_sha256, the game shaders' key.
470 { 530 {