Skip to content

Commit

Permalink
jak3: dump of all vu programs (#3340)
Browse files Browse the repository at this point in the history
With the exception of `sprite` and the new `hfrag` renderer, everything
appears to be identical to Jak 2.
  • Loading branch information
Hat-Kid authored Jan 27, 2024
1 parent 9aa2913 commit 17f5f74
Show file tree
Hide file tree
Showing 89 changed files with 94,582 additions and 18 deletions.
3 changes: 2 additions & 1 deletion decompiler/VuDisasm/VuDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ VuDisassembler::VuDisassembler(VuKind kind) : m_kind(kind) {
// m_upper_op6_table[0b100011].set(VuInstrK::MADDi); // 35
// m_upper_op6_table[0b100100].set(VuInstrK::SUBq); // 36
// m_upper_op6_table[0b100101].set(VuInstrK::MSUBq); // 37
// m_upper_op6_table[0b100110].set(VuInstrK::SUBi); // 38
m_upper_op6_table[0b100110].set(VuInstrK::SUBi); // 38
// m_upper_op6_table[0b100111].set(VuInstrK::MSUBi); // 39
m_upper_op6_table[0b101000].set(VuInstrK::ADD); // 40
m_upper_op6_table[0b101001].set(VuInstrK::MADD); // 41
Expand Down Expand Up @@ -148,6 +148,7 @@ VuDisassembler::VuDisassembler(VuKind kind) : m_kind(kind) {
add_op(VuInstrK::MULi, "muli").iemdt().dst_mask().vft_zero().dst_vfd().src_vfs().src_i();
add_op(VuInstrK::ADDi, "addi").iemdt().dst_mask().vft_zero().dst_vfd().src_vfs().src_i();
add_op(VuInstrK::MULAq, "mula").iemdt().dst_mask().dst_acc().vft_zero().src_vfs().src_q();
add_op(VuInstrK::SUBi, "subi").iemdt().dst_mask().vft_zero().dst_vfd().src_vfs().src_i();

m_lower_op6_table[0b000000].set(VuInstrK::LQ);
m_lower_op6_table[0b000001].set(VuInstrK::SQ);
Expand Down
2 changes: 1 addition & 1 deletion decompiler/VuDisasm/VuInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum class VuInstrK {
// ADDAq,
ADDAbc,
SUB,
// SUBi, // 10
SUBi, // 10
// SUBq,
SUBbc,
// SUBA,
Expand Down
266 changes: 250 additions & 16 deletions test/decompiler/test_VuDisasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,240 @@ std::string get_expected(const std::string& name) {
}
} // namespace

// TEST(VuDisasm, DumpResults_Jak3) {
// struct VuData {
// std::string name;
// std::vector<u32> data;
// VuDisassembler::VuKind kind;
// std::string disasm;
//
// VuData(const std::string& name, VuDisassembler::VuKind kind)
// : name(name), data(get_test_data("jak3/" + name)), kind(kind) {
// VuDisassembler vu_disasm(kind);
// disasm = vu_disasm.to_string(vu_disasm.disassemble(data.data(), data.size() * 4, false));
// }
// };
// auto path = file_util::get_file_path({"test/decompiler/vu_reference/jak3"});
// for (const auto& entry : fs::directory_iterator(path)) {
// if (entry.is_regular_file() &&
// entry.path().filename().string().find("result") == std::string::npos) {
// auto name = entry.path().filename().stem().string();
// auto kind = name.find("vu0") != std::string::npos ? VuDisassembler::VuKind::VU0
// : VuDisassembler::VuKind::VU1;
// VuData prog(name, kind);
// file_util::write_text_file(path + "/" + prog.name + "-result.txt", prog.disasm);
// }
// }
// }

// TEST(VuDisasm, DumpResults_Jak2) {
// struct VuData {
// std::string name;
// std::vector<u32> data;
// VuDisassembler::VuKind kind;
// std::string disasm;
//
// VuData(const std::string& name, VuDisassembler::VuKind kind)
// : name(name), data(get_test_data("jak2/" + name)), kind(kind) {
// VuDisassembler vu_disasm(kind);
// disasm = vu_disasm.to_string(vu_disasm.disassemble(data.data(), data.size() * 4, false));
// }
// };
// auto path = file_util::get_file_path({"test/decompiler/vu_reference/jak2"});
// for (const auto& entry : fs::directory_iterator(path)) {
// if (entry.is_regular_file() &&
// entry.path().filename().string().find("result") == std::string::npos) {
// auto name = entry.path().filename().stem().string();
// auto kind = name.find("vu0") != std::string::npos ? VuDisassembler::VuKind::VU0
// : VuDisassembler::VuKind::VU1;
// VuData prog(name, kind);
// file_util::write_text_file(path + "/" + prog.name + "-result.txt", prog.disasm);
// }
// }
// }

TEST(VuDisasm, ShadowVu0_Jak3) {
auto data = get_test_data("jak3/shadow-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/shadow-vu0"));
}

TEST(VuDisasm, ShadowVu1_Jak3) {
auto data = get_test_data("jak3/shadow-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/shadow-vu1"));
}

TEST(VuDisasm, OceanTexture_Jak3) {
auto data = get_test_data("jak3/ocean-texture-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/ocean-texture-vu1"));
}

TEST(VuDisasm, OceanMid_Jak3) {
auto data = get_test_data("jak3/ocean-mid-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/ocean-mid-vu1"));
}

TEST(VuDisasm, OceanNear_Jak3) {
auto data = get_test_data("jak3/ocean-near-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/ocean-near-vu1"));
}

TEST(VuDisasm, OceanVu0_Jak3) {
auto data = get_test_data("jak3/ocean-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/ocean-vu0"));
}

TEST(VuDisasm, MercnericVu0_Jak3) {
auto data = get_test_data("jak3/mercneric-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/mercneric-vu0"));
}

TEST(VuDisasm, GenericVu0_Jak3) {
auto data = get_test_data("jak3/generic-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/generic-vu0"));
}

TEST(VuDisasm, GenericVu1_Jak3) {
auto data = get_test_data("jak3/generic-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/generic-vu1"));
}

TEST(VuDisasm, Merc_Jak3) {
auto data = get_test_data("jak3/merc-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/merc-vu1"));
}

TEST(VuDisasm, Emerc_Jak3) {
auto data = get_test_data("jak3/emerc-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/emerc-vu1"));
}

TEST(VuDisasm, ShrubVu1_Jak3) {
auto data = get_test_data("jak3/shrub-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/shrub-vu1"));
}

TEST(VuDisasm, Sprite_Jak3) {
auto data = get_test_data("jak3/sprite-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/sprite-vu1"));
}

TEST(VuDisasm, SpriteDistort_Jak3) {
auto data = get_test_data("jak3/sprite-distort-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/sprite-distort-vu1"));
}

TEST(VuDisasm, SpriteGlow_Jak3) {
auto data = get_test_data("jak3/sprite-glow-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/sprite-glow-vu1"));
}

TEST(VuDisasm, Hfrag_Jak3) {
auto data = get_test_data("jak3/hfrag-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/hfrag-vu1"));
}

TEST(VuDisasm, Tfrag_Jak3) {
auto data = get_test_data("jak3/tfrag-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/tfrag-vu1"));
}

TEST(VuDisasm, TfragNear_Jak3) {
auto data = get_test_data("jak3/tnear-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/tnear-vu1"));
}

TEST(VuDisasm, Tie_Jak3) {
auto data = get_test_data("jak3/tie-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/tie-vu1"));
}

TEST(VuDisasm, TieNear_Jak3) {
auto data = get_test_data("jak3/tie-near-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/tie-near-vu1"));
}

TEST(VuDisasm, Etie_Jak3) {
auto data = get_test_data("jak3/etie-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/etie-vu1"));
}

TEST(VuDisasm, EtieNear_Jak3) {
auto data = get_test_data("jak3/etn-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/etn-vu1"));
}

TEST(VuDisasm, BackgroundVu0_Jak3) {
auto data = get_test_data("jak3/background-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/background-vu0"));
}

TEST(VuDisasm, CollideVu0_Jak3) {
auto data = get_test_data("jak3/collide-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/collide-vu0"));
}

TEST(VuDisasm, BonesVu0_Jak3) {
auto data = get_test_data("jak3/bones-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/bones-vu0"));
}

TEST(VuDisasm, ForegroundVu0_Jak3) {
auto data = get_test_data("jak3/foreground-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak3/foreground-vu0"));
}

TEST(VuDisasm, ShadowVu0_Jak2) {
auto data = get_test_data("jak2/shadow-vu0");
VuDisassembler disasm(VuDisassembler::VuKind::VU0);
Expand All @@ -45,24 +279,24 @@ TEST(VuDisasm, ShadowVu1_Jak2) {
}

TEST(VuDisasm, OceanTexture_Jak2) {
auto data = get_test_data("jak2/ocean-texture");
auto data = get_test_data("jak2/ocean-texture-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/ocean-texture"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/ocean-texture-vu1"));
}

TEST(VuDisasm, OceanMid_Jak2) {
auto data = get_test_data("jak2/ocean-mid");
auto data = get_test_data("jak2/ocean-mid-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/ocean-mid"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/ocean-mid-vu1"));
}

TEST(VuDisasm, OceanNear_Jak2) {
auto data = get_test_data("jak2/ocean-near");
auto data = get_test_data("jak2/ocean-near-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/ocean-near"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/ocean-near-vu1"));
}

TEST(VuDisasm, OceanVu0_Jak2) {
Expand All @@ -87,38 +321,38 @@ TEST(VuDisasm, Emerc) {
}

TEST(VuDisasm, Shrub_Jak2) {
auto data = get_test_data("jak2/shrub");
auto data = get_test_data("jak2/shrub-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/shrub"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/shrub-vu1"));
}

TEST(VuDisasm, Sprite_Jak2) {
auto data = get_test_data("jak2/sprite");
auto data = get_test_data("jak2/sprite-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/sprite"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/sprite-vu1"));
}

TEST(VuDisasm, SpriteDistort_Jak2) {
auto data = get_test_data("jak2/sprite-distort");
auto data = get_test_data("jak2/sprite-distort-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/sprite-distort"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/sprite-distort-vu1"));
}

TEST(VuDisasm, SpriteGlow_Jak2) {
auto data = get_test_data("jak2/sprite-glow");
auto data = get_test_data("jak2/sprite-glow-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/sprite-glow"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/sprite-glow-vu1"));
}

TEST(VuDisasm, Tie_Jak2) {
auto data = get_test_data("jak2/tie");
auto data = get_test_data("jak2/tie-vu1");
VuDisassembler disasm(VuDisassembler::VuKind::VU1);
auto prog = disasm.disassemble(data.data(), data.size() * 4, false);
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/tie"));
EXPECT_EQ(disasm.to_string(prog), get_expected("jak2/tie-vu1"));
}

TEST(VuDisasm, etie_Jak2) {
Expand Down
Loading

0 comments on commit 17f5f74

Please sign in to comment.