mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 06:29:58 -04:00
Make F8 write a bug capture and add a test run that starts from one.
F8 now always writes a folder under logs/captures: the area, Link's position and rotation, the camera of the frame on screen and the game's own, the presented frame as a PNG, frame times around the press, the machine, the settings that differ from the defaults, the end of the log, the save, and the game's flags and texts. A note on screen names the capture. The flight recorder's F8 dump goes into the capture's folder. NX2NAVI_CAPTURE_REPLAY starts a run on a capture's settings, teleports to its area, walks Link to where he stood and puts the free camera where the camera was; tools/capture_run.py prepares the profile from the capture's save, runs it and compares the two captures. docs/bug-capture.md has the files and the steps. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -675,6 +675,65 @@ int vk_present_captured(const uint8_t **px, int *w, int *h, VkFormat *fmt) {
|
||||
static float g_pic[4]; // gfx_picture_rect
|
||||
static volatile int32_t g_pic_ok;
|
||||
|
||||
// ---- vk_present_grab (vk.h): one presented frame's pixels for a bug capture. The request is taken by the next
|
||||
// present (g_pl held), which copies the read-back buffer and calls back; the PNG is made by the caller's own thread.
|
||||
static void (*volatile g_grab_cb)(VkGrab *g, void *ctx);
|
||||
static void *g_grab_ctx;
|
||||
|
||||
int vk_present_grab(void (*cb)(VkGrab *g, void *ctx), void *ctx) {
|
||||
plat_rmutex_lock(&g_pl);
|
||||
int ok = !g_grab_cb;
|
||||
if (ok) g_grab_ctx = ctx, g_grab_cb = cb;
|
||||
plat_rmutex_unlock(&g_pl);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void vk_present_grab_cancel(void) {
|
||||
plat_rmutex_lock(&g_pl);
|
||||
g_grab_cb = NULL;
|
||||
plat_rmutex_unlock(&g_pl);
|
||||
}
|
||||
|
||||
void vk_present_grab_rgba(const VkGrab *g, uint8_t *out) {
|
||||
size_t n = (size_t)g->w * (size_t)g->h * 4;
|
||||
if (g->hdr) {
|
||||
vk_hdr_to_srgb8(g->px, out, n / 4, g->a2r);
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < n; i += 4) {
|
||||
out[i] = g->px[i + (g->bgra ? 2 : 0)];
|
||||
out[i + 1] = g->px[i + 1];
|
||||
out[i + 2] = g->px[i + (g->bgra ? 0 : 2)];
|
||||
out[i + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
void vk_present_grab_free(VkGrab *g) {
|
||||
if (g) free(g->px);
|
||||
free(g);
|
||||
}
|
||||
|
||||
// The present that took the request: the read-back buffer holds this frame (g_cap_ptr, the fence waited for).
|
||||
static void grab_deliver(int image_w, int image_h) {
|
||||
void (*cb)(VkGrab *g, void *ctx) = g_grab_cb;
|
||||
void *ctx = g_grab_ctx;
|
||||
g_grab_cb = NULL;
|
||||
size_t n = (size_t)g_cap_w * (size_t)g_cap_h * 4;
|
||||
VkGrab *g = calloc(1, sizeof *g);
|
||||
if (g && (g->px = malloc(n))) {
|
||||
memcpy(g->px, g_cap_ptr, n);
|
||||
g->w = g_cap_w, g->h = g_cap_h;
|
||||
g->bgra = g_sc_fmt == VK_FORMAT_B8G8R8A8_UNORM || g_sc_fmt == VK_FORMAT_B8G8R8A8_SRGB;
|
||||
g->hdr = g_sc_hdr != 0, g->a2r = g_sc_fmt == VK_FORMAT_A2R10G10B10_UNORM_PACK32;
|
||||
g->image_w = image_w, g->image_h = image_h, g->scaler = g_scaler;
|
||||
if (__atomic_load_n(&g_pic_ok, __ATOMIC_ACQUIRE)) memcpy(g->pic, g_pic, sizeof g->pic);
|
||||
} else {
|
||||
free(g);
|
||||
g = NULL;
|
||||
}
|
||||
cb(g, ctx); // NULL: no memory for the copy
|
||||
}
|
||||
|
||||
// The captured swapchain image as a PNG (the menu's test hook), RGBA with opaque alpha. From an HDR10 swapchain the
|
||||
// log also gets the luminance in nits of the picture's rectangle (vk_hdr_luminance_stats: the black floor of a dark
|
||||
// scene, for one), and <path>.pq10 keeps the raw pixels: "PQ10", width, height, 1 when A2R10G10B10 (u32 each), then
|
||||
@@ -1495,7 +1554,8 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w
|
||||
next_ns = plat_now_ns() + (uint64_t)(every * 1e9);
|
||||
}
|
||||
}
|
||||
int cap = (g_capture || menu_shot) && ensure_capture_buffer();
|
||||
int grab = src && g_grab_cb; // a bug capture asked for this frame (vk_present_grab)
|
||||
int cap = (g_capture || menu_shot || grab) && ensure_capture_buffer();
|
||||
int thumb = src && g_th_n && ensure_thumbs();
|
||||
|
||||
VkCommandBuffer cb = g_cb[slot];
|
||||
@@ -1654,6 +1714,11 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w
|
||||
g_cap_h = (int)g_sc_ext.height;
|
||||
g_cap_valid = 1;
|
||||
if (menu_shot) save_capture(menu_shot);
|
||||
if (grab) grab_deliver(cw, ch);
|
||||
} else if (grab) { // no read-back buffer: the request ends without pixels
|
||||
void (*cb)(VkGrab *g, void *ctx) = g_grab_cb;
|
||||
g_grab_cb = NULL;
|
||||
cb(NULL, g_grab_ctx);
|
||||
}
|
||||
out:
|
||||
plat_rmutex_unlock(&g_pl);
|
||||
|
||||
Reference in New Issue
Block a user