mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.2.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
53
gpu/vk/tests/lower_test.cpp
Normal file
53
gpu/vk/tests/lower_test.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// (hookshot) Offline test of the Ampere -> Maxwell lowering (shader_recompiler/frontend/ampere/lower_to_maxwell.h).
|
||||
// Runs LowerToMaxwell over native programs a run dumped (RX_VK_DUMP_FAILED=<folder>: <stage>_<key>.bin, 16-byte
|
||||
// instructions) and groups what still fails by reason and opcode, with the first failing instructions' words.
|
||||
// lower_test <folder> [samples per reason] (built by nx2/lower_test.py)
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "shader_recompiler/frontend/ampere/lower_to_maxwell.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) { std::fprintf(stderr, "usage: lower_test <folder> [samples]\n"); return 2; }
|
||||
const int samples = argc > 2 ? std::atoi(argv[2]) : 3;
|
||||
struct Group { int n = 0; std::vector<std::string> examples; };
|
||||
std::map<std::string, Group> groups;
|
||||
int total = 0, ok = 0;
|
||||
for (const auto& e : std::filesystem::directory_iterator(argv[1])) {
|
||||
if (e.path().extension() != ".bin") continue;
|
||||
FILE* f = std::fopen(e.path().string().c_str(), "rb");
|
||||
if (!f) continue;
|
||||
std::vector<Shader::Ampere::Instruction> code;
|
||||
Shader::Ampere::Instruction in;
|
||||
while (std::fread(&in, sizeof in, 1, f) == 1) code.push_back(in);
|
||||
std::fclose(f);
|
||||
total++;
|
||||
const auto r = Shader::Ampere::LowerToMaxwell(code);
|
||||
if (r) { ok++; if (std::getenv("LOWER_TEST_LIST_OK")) std::printf("ok %s\n", e.path().filename().string().c_str()); continue; }
|
||||
const unsigned at = r.error_offset / 16;
|
||||
const unsigned op = at < code.size() ? code[at].Bits(0, 12) : 0xFFFFFFFFu;
|
||||
char key[200];
|
||||
std::snprintf(key, sizeof key, "%s (op %#x)", std::string(r.error).c_str(), op);
|
||||
Group& g = groups[key];
|
||||
g.n++;
|
||||
if ((int)g.examples.size() < samples && at < code.size()) {
|
||||
char ex[200];
|
||||
const auto& w = code[at].words;
|
||||
std::snprintf(ex, sizeof ex, "%s +%#x: %08x %08x %08x %08x", e.path().filename().string().c_str(), r.error_offset,
|
||||
w[0], w[1], w[2], w[3]);
|
||||
g.examples.push_back(ex);
|
||||
}
|
||||
}
|
||||
std::printf("%d programs, %d lower, %d fail\n", total, ok, total - ok);
|
||||
std::vector<std::pair<int, std::string>> order;
|
||||
for (auto& [k, g] : groups) order.push_back({-g.n, k});
|
||||
std::sort(order.begin(), order.end());
|
||||
for (auto& [n, k] : order) {
|
||||
std::printf("%5d %s\n", -n, k.c_str());
|
||||
for (auto& ex : groups[k].examples) std::printf(" %s\n", ex.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
93
gpu/vk/tests/present_rect_test.cpp
Normal file
93
gpu/vk/tests/present_rect_test.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// Game-free regression for the production Vulkan presentation rectangle helper.
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "../vk_present_rect.h"
|
||||
|
||||
namespace {
|
||||
int failures = 0;
|
||||
|
||||
void expect(const char* name, mkwvk::PresentRect got, mkwvk::PresentRect want) {
|
||||
if (got.x == want.x && got.y == want.y && got.w == want.w && got.h == want.h) return;
|
||||
std::fprintf(stderr, "%s: got {%u,%u,%u,%u}, wanted {%u,%u,%u,%u}\n", name, got.x, got.y, got.w, got.h,
|
||||
want.x, want.y, want.w, want.h);
|
||||
failures++;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
using mkwvk::PresentRect;
|
||||
using mkwvk::PresentAspect;
|
||||
constexpr PresentAspect wide{43.0 / 18.0};
|
||||
const PresentRect fit_16_10 = mkwvk::present_rect(1920, 1080, nullptr, 1600, 1000);
|
||||
expect("16:9 into 16:10", fit_16_10, {0, 50, 1600, 900});
|
||||
expect("16:9 same aspect", mkwvk::present_rect(1920, 1080, nullptr, 1920, 1080), {0, 0, 1920, 1080});
|
||||
expect("logical ultrawide picture fills its own aspect even in a 16:9 texture",
|
||||
mkwvk::present_rect(1920, 1080, nullptr, 3440, 1440, wide), {0, 0, 3440, 1440});
|
||||
expect("ultrawide camera keeps its aspect after maximize",
|
||||
mkwvk::present_rect(1920, 1080, nullptr, 1920, 1009, wide), {0, 102, 1920, 804});
|
||||
expect("ultrawide picture in a 16:9 window",
|
||||
mkwvk::present_rect(1920, 1080, nullptr, 1280, 720, wide), {0, 92, 1280, 536});
|
||||
expect("ultrawide restore",
|
||||
mkwvk::present_rect(1920, 1080, nullptr, 1720, 720, wide), {0, 0, 1720, 720});
|
||||
expect("float camera ratio keeps the full 32:9 destination",
|
||||
mkwvk::present_rect(1920, 1080, nullptr, 5120, 1440, {static_cast<float>(32.0 / 9.0)}),
|
||||
{0, 0, 5120, 1440});
|
||||
expect("logical portrait content", mkwvk::present_rect(1920, 1080, nullptr, 1600, 1000, {0.5}),
|
||||
{550, 0, 500, 1000});
|
||||
expect("ultrawide source aspect fits naturally",
|
||||
mkwvk::present_rect(3440, 1440, nullptr, 3440, 1440), {0, 0, 3440, 1440});
|
||||
expect("ultrawide source remains wider than 16:9",
|
||||
mkwvk::present_rect(3440, 1440, nullptr, 1600, 1000), {0, 165, 1600, 669});
|
||||
expect("portrait target", mkwvk::present_rect(1920, 1080, nullptr, 1000, 1600), {0, 519, 1000, 562});
|
||||
expect("odd resized destination", mkwvk::present_rect(1920, 1080, nullptr, 1601, 1001), {0, 50, 1601, 900});
|
||||
|
||||
const int crop_16_9[4] = {160, 90, 2240, 1260};
|
||||
expect("cropped 16:9 content", mkwvk::present_rect(2560, 1440, crop_16_9, 1600, 1000), {0, 50, 1600, 900});
|
||||
const int crop_odd[4] = {7, 11, 1900, 1069};
|
||||
expect("odd crop and resized target", mkwvk::present_rect(1920, 1080, crop_odd, 1600, 1000), {0, 50, 1600, 900});
|
||||
const int crop_at_edge[4] = {90, 70, 20, 20};
|
||||
expect("small crop clamps to source edge", mkwvk::present_rect(100, 80, crop_at_edge, 160, 100), {30, 0, 100, 100});
|
||||
expect("zero source falls back to destination", mkwvk::present_rect(0, 0, nullptr, 160, 100), {0, 0, 160, 100});
|
||||
|
||||
const int padded_crop[4] = {16, 8, 2560, 1440};
|
||||
expect("logical aspect belongs to the cropped picture, not the allocation",
|
||||
mkwvk::present_rect(4096, 2160, padded_crop, 1920, 1009, wide), {0, 102, 1920, 804});
|
||||
expect("generated frame keeps the same display aspect after crop is materialized",
|
||||
mkwvk::present_rect(2560, 1440, nullptr, 1920, 1009, wide), {0, 102, 1920, 804});
|
||||
const double invalid[] = {0, -1, std::numeric_limits<double>::infinity(),
|
||||
-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::quiet_NaN()};
|
||||
for (double ratio : invalid) {
|
||||
expect("invalid logical aspect falls back to the actual crop",
|
||||
mkwvk::present_rect(100, 80, crop_at_edge, 160, 100, {ratio}), {30, 0, 100, 100});
|
||||
}
|
||||
const uint32_t sizes[] = {1, 2, 7, 720, 1280, 1601, 3440, std::numeric_limits<uint32_t>::max()};
|
||||
const double ratios[] = {std::numeric_limits<double>::denorm_min(), 0.5, 1, 16.0 / 9.0, 43.0 / 18.0,
|
||||
static_cast<float>(32.0 / 9.0), 1e30, std::numeric_limits<double>::max()};
|
||||
for (uint32_t dw : sizes) for (uint32_t dh : sizes) for (double ratio : ratios) {
|
||||
const PresentRect rect = mkwvk::present_rect(1920, 1080, nullptr, dw, dh, {ratio});
|
||||
if (!rect.w || !rect.h || static_cast<uint64_t>(rect.x) + rect.w > dw ||
|
||||
static_cast<uint64_t>(rect.y) + rect.h > dh || (rect.w != dw && rect.h != dh)) {
|
||||
std::fprintf(stderr, "logical fit outside destination %u x %u, aspect %.17g\n", dw, dh, ratio);
|
||||
failures++;
|
||||
continue;
|
||||
}
|
||||
const uint32_t right = dw - rect.x - rect.w, bottom = dh - rect.y - rect.h;
|
||||
if ((right > rect.x ? right - rect.x : rect.x - right) > 1 ||
|
||||
(bottom > rect.y ? bottom - rect.y : rect.y - bottom) > 1) {
|
||||
std::fprintf(stderr, "logical fit is not centered\n");
|
||||
failures++;
|
||||
}
|
||||
// Ignore the unavoidable one-pixel clamp at extreme aspects.
|
||||
if (rect.w > 1 && rect.h > 1 &&
|
||||
std::fabs(static_cast<long double>(rect.w) - rect.h * static_cast<long double>(ratio)) >
|
||||
0.5001L * (ratio > 1 ? ratio : 1)) {
|
||||
std::fprintf(stderr, "logical fit exceeds half-pixel rounding error\n");
|
||||
failures++;
|
||||
}
|
||||
expect("crop and generated frame agree", mkwvk::present_rect(4096, 2160, padded_crop, dw, dh, {ratio}), rect);
|
||||
}
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
61
gpu/vk/tests/regmap_marker_test.cpp
Normal file
61
gpu/vk/tests/regmap_marker_test.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Game-free regression for the Ampere -> Maxwell lowering's register renaming (lower_to_maxwell.h): a renamed high GPR's
|
||||
// marker must not be a number another field of the same instruction names. OoT's Castle Town flower colour pass had
|
||||
// FMUL R252, R216, c[..] (native 864 of mesh code e3fc8fcf540f7a48): R252 took R216 as its marker, the prefix mapped
|
||||
// R216 to both 252 and 216, the product went to R216 and R252 stayed undefined: the flowers' vertices broke and they
|
||||
// glowed with the sky colour left behind.
|
||||
// clang++ -std=c++20 -I gpu/vk/eden -I gpu/vk/compat gpu/vk/tests/regmap_marker_test.cpp -o regmap_marker_test
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
|
||||
#include "shader_recompiler/frontend/ampere/lower_to_maxwell.h"
|
||||
|
||||
namespace {
|
||||
using Shader::Ampere::Instruction;
|
||||
|
||||
// Numbers mapped to two different targets by the prefixes before one lowered word.
|
||||
int collisions(const Shader::Ampere::LoweredProgram& lowered) {
|
||||
int bad = 0;
|
||||
std::map<u32, u32> current;
|
||||
for (const u64 w : lowered.instructions) {
|
||||
if ((w >> 48) != 0xefe0) {
|
||||
current.clear();
|
||||
continue;
|
||||
}
|
||||
const u32 runs = static_cast<u32>((w >> 40) & 3);
|
||||
constexpr u32 number_at[2]{0, 20}, target_at[2]{8, 28};
|
||||
for (u32 i = 0; i < runs && i < 2; ++i) {
|
||||
const u32 number = static_cast<u32>((w >> number_at[i]) & 0xff);
|
||||
const u32 target = static_cast<u32>((w >> target_at[i]) & 0xff);
|
||||
const u32 length = static_cast<u32>((w >> (36 + 2 * i)) & 3) + 1;
|
||||
for (u32 k = 0; k < length; ++k) {
|
||||
const auto it = current.find(number + k);
|
||||
if (it != current.end() && it->second != target + k) bad++;
|
||||
current[number + k] = target + k;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bad;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const Instruction program[] = {
|
||||
{{0x00047ab9, 0x0001e400, 0x00000a00, 0x000fe200}}, // ULDC.64 UR4, c[0x0][0x1e4] (the uniform bank: high GPRs from R216)
|
||||
{{0xd8fc7a20, 0x00cc0c00, 0x00410000, 0x000fe200}}, // FMUL R252, R216, c[0x3][0x30]
|
||||
{{0x0000794d, 0x00000000, 0x03800000, 0x000fea00}}, // EXIT
|
||||
};
|
||||
const auto lowered = Shader::Ampere::LowerToMaxwell(std::span<const Instruction>(program, 3));
|
||||
int failures = 0;
|
||||
if (!lowered) {
|
||||
std::fprintf(stderr, "not lowered: %.*s\n", static_cast<int>(lowered.error.size()), lowered.error.data());
|
||||
failures++;
|
||||
} else if (!lowered.register_map_words) {
|
||||
std::fprintf(stderr, "no extended registers: the case is not exercised\n");
|
||||
failures++;
|
||||
} else if (const int bad = collisions(lowered)) {
|
||||
std::fprintf(stderr, "%d register numbers mapped to two registers in one prefix\n", bad);
|
||||
failures++;
|
||||
}
|
||||
std::printf("%s\n", failures ? "FAILED" : "ok");
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user