Fill a window one pixel wider than the picture, and let the probes use the shader census of either game version.

gfx_fit_rect rounded the picture up to an even size, so at 1167x656 a 16:9 picture was 1166 wide and the last column
stayed black, which failed --probe-vkexec; it now takes the window's parity, which keeps the bars equal at any size.
The present check of --probe-vkexec expects the picture's rectangle and black bars, as --probe-window does, so it
passes on a 16:10 screen too. --probe-shader, the draw part of --probe-vkexec and the pipeline self-test looked only
for build/v121/shaders; probe_census_dir takes the running version's census first, then the other one's. The Linux
notes say what the probes need over SSH.
This commit is contained in:
Wellington Dias committed 2026-10-30 14:55:55 -03:00
1 parent 08df794360
commit 7766716e16
6 files changed
+54 -57

No files matched your search

+2 -3
View File
@@ -518,9 +518,8 @@ void gfx_fit_rect(int cw, int ch, int dw, int dh, int out[4]) {
if (cw <= 0 || ch <= 0 || !strcmp(cfg_value("TOTK_PICTURE_FIT"), "stretch")) return;
if ((int64_t)dw * ch > (int64_t)dh * cw) out[2] = (int)(((int64_t)dh * cw + ch / 2) / ch); // window wider: pillarbox
else out[3] = (int)(((int64_t)dw * ch + cw / 2) / cw); // taller: letterbox
out[2] += out[2] & 1, out[3] += out[3] & 1; // even sizes keep the bars equal
if (out[2] > dw) out[2] = dw;
if (out[3] > dh) out[3] = dh;
// A side of the window's parity keeps the two bars equal; a picture one pixel short of the window fills it
out[2] += (dw - out[2]) & 1, out[3] += (dh - out[3]) & 1;
out[0] = (dw - out[2]) / 2, out[1] = (dh - out[3]) / 2;
}
+24 -16
View File
@@ -1,5 +1,5 @@
// --probe-shader: the shader service client (gfx_shader.c) against 32 census shaders. Needs build/xlate/totk_xlate.exe and
// build/v121/shaders/ (tools/shader_census.py); uses a throwaway cache directory.
// a census, build/<version>/shaders/ (tools/shader_census.py, probe_census_dir); uses a throwaway cache directory.
// 1. Translate 32 shaders (mixed stages) through gfx_shader_get; each SPIR-V starts with the magic 0x07230203.
// 2. Drop the memory cache and ask again: 32 hits from disk, 0 service requests. A third pass returns the same pointers.
// 3. Send a malformed line straight to the service: it answers with an error line and still serves a valid request.
@@ -8,6 +8,7 @@
#include <string.h>
#include "gfx.h"
#include "host.h"
#include "platform/platform.h"
int gfx_shader_raw_request(const char *line, char *reply, size_t reply_size);
@@ -48,16 +49,21 @@ static const char *str_field(const char *from, const char *to, const char *name,
static int hexval(char c) { return c <= '9' ? c - '0' : (c | 32) - 'a' + 10; }
// The repository root: the nearest parent of totk.exe holding build/v121/shaders/jobs.json.
static int find_root(char *root, size_t n) {
char exe[PLAT_PATH_MAX * 2];
int len = plat_exe_path(exe, sizeof exe);
if (!len || len >= sizeof exe) return 0;
for (char *cut = plat_last_sep(exe); cut; cut = plat_last_sep(exe)) {
*cut = 0;
char p[PLAT_PATH_MAX * 2 + 40];
snprintf(p, sizeof p, "%s/build/v121/shaders/jobs.json", exe);
if (plat_file_exists(p)) return snprintf(root, n, "%s", exe) < (int)n;
// The shader census the probes translate (tools/shader_census.py --version <ver>): build/<ver>/shaders in the nearest
// parent of totk.exe that has one with a jobs.json, the running game version's first, then the other's (any census
// serves a probe). 1 with that folder in dir.
int probe_census_dir(char *dir, size_t n) {
const char *const versions[2] = {RT_V143 ? "v143" : "v121", RT_V143 ? "v121" : "v143"};
for (int v = 0; v < 2; v++) {
char exe[PLAT_PATH_MAX * 2];
int len = plat_exe_path(exe, sizeof exe);
if (!len || len >= sizeof exe) return 0;
for (char *cut = plat_last_sep(exe); cut; cut = plat_last_sep(exe)) {
*cut = 0;
char p[PLAT_PATH_MAX * 2 + 40];
snprintf(p, sizeof p, "%s/build/%s/shaders/jobs.json", exe, versions[v]);
if (plat_file_exists(p)) return snprintf(dir, n, "%s/build/%s/shaders", exe, versions[v]) < (int)n;
}
}
return 0;
}
@@ -95,7 +101,7 @@ static int pick_entries(const char *jobs, Entry *out) {
return got;
}
static char root[PLAT_PATH_MAX * 2];
static char root[PLAT_PATH_MAX * 2]; // the census folder (probe_census_dir)
// Builds the program the game would hand NVN for a census entry and translates it.
static const GfxShader *translate(const Entry *e, int *err) {
@@ -103,7 +109,7 @@ static const GfxShader *translate(const Entry *e, int *err) {
uint8_t c1[8192], control[0x880] = {0};
if (e->c1_len > sizeof c1) return *err = 1, NULL;
for (size_t b = 0; b < e->c1_len; b++) c1[b] = (uint8_t)(hexval(e->c1[b * 2]) << 4 | hexval(e->c1[b * 2 + 1]));
snprintf(path, sizeof path, "%s/build/v121/shaders/code/%s.code", root, e->key);
snprintf(path, sizeof path, "%s/code/%s.code", root, e->key);
size_t body_size;
char *body = slurp(path, &body_size);
if (!body) return *err = 1, NULL;
@@ -137,8 +143,10 @@ static void remove_dir(const char *dir) {
int probe_shader(void) {
char path[PLAT_PATH_MAX * 2 + 64];
CHECK(find_root(root, sizeof root), "build/v121/shaders/jobs.json not found (run tools/shader_census.py)");
snprintf(path, sizeof path, "%s/build/v121/shaders/jobs.json", root);
CHECK(probe_census_dir(root, sizeof root),
"no build/v%d/shaders/jobs.json above the exe (run tools/shader_census.py --version v%d)", rt_game_version,
rt_game_version);
snprintf(path, sizeof path, "%s/jobs.json", root);
size_t jobs_size;
char *jobs = slurp(path, &jobs_size);
CHECK(jobs, "cannot read %s", path);
@@ -206,7 +214,7 @@ int probe_shader(void) {
*o = 0;
const Entry *e = &entries[0];
snprintf(line, sizeof line,
"{\"job\":{\"key\":\"%.64sa\",\"stage\":\"%s\",\"debug\":false,\"c1\":\"%.*s\",\"code\":\"%s/build/v121/shaders/code/%.64s.code\"},\"out\":\"%s\"}",
"{\"job\":{\"key\":\"%.64sa\",\"stage\":\"%s\",\"debug\":false,\"c1\":\"%.*s\",\"code\":\"%s/code/%.64s.code\"},\"out\":\"%s\"}",
e->key, e->stage == GFX_STAGE_VS ? "vs" : e->stage == GFX_STAGE_FS ? "ps" : "cs", (int)(e->c1_len * 2), e->c1,
esc_root, e->key, dir_json);
FAIL_IF(!gfx_shader_raw_request(line, reply, sizeof reply), "service did not answer a valid request after the malformed one");
+1
View File
@@ -295,6 +295,7 @@ int probe_vkdevice(void); // vk_device.c
int probe_nvn(void), probe_nvn_tex(void); // nvn_probe.c, nvn_tex_probe.c
int probe_window(void); // gfx_window_probe.c
int probe_shader(void); // gfx_shader.c
int probe_census_dir(char *dir, size_t n); // gfx_shader_probe.c: build/<version>/shaders for the probes
int probe_vkmem(void), probe_vkexec(void), probe_astc(void); // tex_probe.c, vk_exec_probe.c, astc_probe.c
int probe_movie(void); // movie_probe.c: host VP9 movie::Decoder on one RomFS movie
int vk_pipeline_prepare_shaders(void); // vk_pipeline.c: --prepare-shaders (tools/prepare_shaders.py)
+13 -20
View File
@@ -142,11 +142,16 @@ static int test_present(const GfxBackend *b, uint8_t *guest, int *w_out, int *h_
if (fmt == VK_FORMAT_B8G8R8A8_UNORM) want[0] = to_byte(rgba[2]), want[1] = to_byte(rgba[1]), want[2] = to_byte(rgba[0]);
else if (fmt == VK_FORMAT_R8G8B8A8_UNORM) want[0] = to_byte(rgba[0]), want[1] = to_byte(rgba[1]), want[2] = to_byte(rgba[2]);
else CHECK(0, "swapchain format %d is not UNORM RGBA/BGRA", (int)fmt);
uint32_t wv;
uint32_t wv, black = 0xff000000u; // opaque black in both byte orders
memcpy(&wv, want, 4);
int r[4]; // the picture's rectangle; black bars around it when the window's shape differs (gfx_present.c)
gfx_fit_rect(TEX_W, TEX_H, w, h, r);
const uint32_t *p = (const uint32_t *)px;
for (long k = 0, n = (long)w * h; k < n; k++)
CHECK(p[k] == wv, "presented pixel %ld is %08x, expected %08x", k, p[k], wv);
for (long k = 0, n = (long)w * h; k < n; k++) {
int x = (int)(k % w), y = (int)(k / w);
uint32_t e = x >= r[0] && x < r[0] + r[2] && y >= r[1] && y < r[1] + r[3] ? wv : black;
CHECK(p[k] == e, "presented pixel %ld (%d, %d) is %08x, expected %08x", k, x, y, p[k], e);
}
vk_present_capture(0);
b->texture_release(&t);
b->pool_fini(&pool);
@@ -240,7 +245,7 @@ static int test_clear(const GfxBackend *b, uint8_t *guest, int *n_inside) {
}
// ---- draw part: the pipeline self-test, then a hand-built stream that clears an RGBA8 target, binds a census
// vertex + fragment pair and draws one triangle; a census compute shader is dispatched. The census (build/v121/shaders,
// vertex + fragment pair and draws one triangle; a census compute shader is dispatched. The census (probe_census_dir,
// tools/shader_census.py) is read the way vk_pipeline_selftest reads it: a pair is a fragment shader and a vertex
// shader of the same source file.
@@ -308,19 +313,6 @@ static char *dr_read(const char *path, long *size) {
return b;
}
static int dr_root(char *root, size_t n) {
char exe[PLAT_PATH_MAX * 2];
int len = plat_exe_path(exe, sizeof exe);
if (!len || len >= sizeof exe) return 0;
for (char *cut = plat_last_sep(exe); cut; cut = plat_last_sep(exe)) {
*cut = 0;
char p[PLAT_PATH_MAX * 2 + 40];
snprintf(p, sizeof p, "%s/build/v121/shaders/jobs.json", exe);
if (plat_file_exists(p)) return snprintf(root, n, "%s", exe) < (int)n;
}
return 0;
}
static int dr_hex(char c) { return c <= '9' ? c - '0' : (c | 32) - 'a' + 10; }
// A program of one census shader as the game hands it to NVN: control section, code with its 0x30-byte header.
@@ -330,7 +322,7 @@ static prog_t *dr_prog(const char *root, const DrawEnt *e[], int n) {
p->magic = NVN_PROG_MAGIC, p->serial = ++serial;
for (int i = 0; i < n; i++) {
char path[PLAT_PATH_MAX * 2 + 128];
snprintf(path, sizeof path, "%s/build/v121/shaders/code/%.64s.code", root, e[i]->key);
snprintf(path, sizeof path, "%s/code/%.64s.code", root, e[i]->key);
long body;
char *raw = dr_read(path, &body);
if (!raw) return free(p), NULL;
@@ -396,8 +388,9 @@ static uint8_t *draw_prefix(uint8_t *q, prog_t *prog, const pool_t *pool, tex_t
static int test_draw(const GfxBackend *b, uint8_t *guest, int *n_drawn, int *n_tries, int *n_cs) {
char root[PLAT_PATH_MAX * 2], path[PLAT_PATH_MAX * 2 + 64];
CHECK(dr_root(root, sizeof root), "build/v121/shaders/jobs.json not found");
snprintf(path, sizeof path, "%s/build/v121/shaders/jobs.json", root);
CHECK(probe_census_dir(root, sizeof root), "no build/v%d/shaders/jobs.json above the exe (run tools/shader_census.py)",
rt_game_version);
snprintf(path, sizeof path, "%s/jobs.json", root);
long size;
char *jobs = dr_read(path, &size);
DrawEnt *e = malloc(sizeof *e * 20000);
+7 -17
View File
@@ -3111,7 +3111,7 @@ void vk_pipeline_shutdown(void) {
plat_mutex_unlock(&P.lock);
}
// ---- self-test: census shaders (build/v121/shaders, tools/shader_census.py) through gfx_shader_get into pipelines.
// ---- self-test: census shaders (probe_census_dir, tools/shader_census.py) through gfx_shader_get into pipelines.
// Graphics pairs are a fragment shader and a vertex shader of the same source file, spread over the census; compute
// shaders are spread the same way. Every pipeline is built twice (the second call must hit the cache) and the
// dynamic state of the first graphics pipeline is recorded into a throwaway command buffer.
@@ -3141,7 +3141,7 @@ static int census_cmp(const void *x, const void *y) {
static char *census_read(const char *root, size_t *size) {
char path[PLAT_PATH_MAX * 2 + 64];
snprintf(path, sizeof path, "%s/build/v121/shaders/jobs.json", root);
snprintf(path, sizeof path, "%s/jobs.json", root);
FILE *f = fopen(path, "rb");
if (!f) return NULL;
fseek(f, 0, SEEK_END);
@@ -3188,7 +3188,7 @@ static const GfxShader *census_shader(const char *root, const CensusEntry *e) {
uint8_t control[0x880] = {0};
if (e->c1_len > sizeof c1) return NULL;
for (size_t b = 0; b < e->c1_len; b++) c1[b] = (uint8_t)(hexv(e->c1[b * 2]) << 4 | hexv(e->c1[b * 2 + 1]));
snprintf(path, sizeof path, "%s/build/v121/shaders/code/%.64s.code", root, e->key);
snprintf(path, sizeof path, "%s/code/%.64s.code", root, e->key);
FILE *f = fopen(path, "rb");
if (!f) return NULL;
fseek(f, 0, SEEK_END);
@@ -3208,19 +3208,6 @@ static const GfxShader *census_shader(const char *root, const CensusEntry *e) {
return s;
}
static int census_root(char *root, size_t n) {
char exe[PLAT_PATH_MAX * 2];
int len = plat_exe_path(exe, sizeof exe);
if (!len || len >= sizeof exe) return 0;
for (char *cut = plat_last_sep(exe); cut; cut = plat_last_sep(exe)) {
*cut = 0;
char p[PLAT_PATH_MAX * 2 + 40];
snprintf(p, sizeof p, "%s/build/v121/shaders/jobs.json", exe);
if (plat_file_exists(p)) return snprintf(root, n, "%s", exe) < (int)n;
}
return 0;
}
// A state for a census pair: one target per fragment output (RGBA8 of the output's type), D32S8 depth with the test on,
// alpha blending on target 0, one RGBA32 attribute per vertex input, interleaved in stream 0.
static void selftest_state(VkPipeState *s, const GfxShader *vs, const GfxShader *fs) {
@@ -3275,7 +3262,10 @@ int vk_pipeline_selftest(void) {
enum { MAXN = 20000, WANT_PAIRS = 64, WANT_CS = 16 };
char root[PLAT_PATH_MAX * 2];
if (!vk_init() || !ensure_init()) { printf("vk_pipeline selftest: FAILED: no Vulkan device\n"); return 1; }
if (!census_root(root, sizeof root)) { printf("vk_pipeline selftest: FAILED: build/v121/shaders/jobs.json not found\n"); return 1; }
if (!probe_census_dir(root, sizeof root)) { // the census folder, build/<version>/shaders
printf("vk_pipeline selftest: FAILED: no build/v%d/shaders/jobs.json above the exe\n", rt_game_version);
return 1;
}
size_t size;
char *jobs = census_read(root, &size);
CensusEntry *e = malloc(sizeof *e * MAXN);