Let the flight recorder dump on its own when one frame flashes.

With flight = 1 and its thumbnails kept, the recorder now also writes a dump when a frame's picture differs strongly from the frame before and the frame after while those two agree, which is what a one-frame flicker looks like. Each thumbnail is reduced to 16x9 cells of mean brightness where the present thread already sees it complete, and a frame is a flash when at least three cells are more than 24 of 255 brighter or darker than in both neighbours, the neighbours being alike in those cells, around them and over the picture as a whole. A camera cut, a fade, a pan and shapes crossing the picture are no flash, and a frame beside one without a thumbnail is not judged. The dump is the one F8 writes, named "flash" with the frame's number in its header line, at most one every 30 seconds. flight_flash = 0 turns it off; flight_flash_diff and flight_flash_cells set the two thresholds.

On the thumbnails of earlier dumps the defaults flag the frames whose scene was white once and nothing in the runs without that fault. tests/flight_flash_check.py checks the test itself on drawn pictures.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 15:15:45 -05:00
parent 95dc476ee7
commit 202fd47ceb
9 changed files with 534 additions and 4 deletions

View File

@@ -19,6 +19,7 @@
#include "cfg.h"
#include "coop.h"
#include "flight.h"
#include "flight_flash.h"
#include "fs.h"
#include "gfx.h"
#include "gfx_wsys.h"
@@ -657,6 +658,18 @@ int vk_thumbs_read(uint64_t frame, uint8_t *rgba) {
return ok != 0;
}
// The flight recorder's flash trigger (flight.c flight_cells) gets the cell means of frame's thumbnail, which has just
// completed in its ring slot (g_pl held). flash_cells reads a quarter of the slot's pixels, about 15 us measured on
// ordinary memory (tests/flight_flash_check.py time); the ring is mapped host memory allocated for random access
// (ensure_thumbs), which is cached memory where the device has it, as vk_thumbs_read's copy of a whole slot relies on.
static void thumb_cells(uint64_t frame) {
unsigned ring = (unsigned)(frame % (uint64_t)g_th_n);
uint8_t cells[FLASH_CELLS];
vmaInvalidateAllocation(vk_ctx()->vma, g_th_alloc, TH_BYTES * ring, TH_BYTES);
flash_cells(g_th_ptr + TH_BYTES * ring, FLIGHT_THUMB_W, FLIGHT_THUMB_H, cells);
flight_cells(frame, cells);
}
void vk_present_capture(int on) {
plat_rmutex_lock(&g_pl);
g_capture = on;
@@ -1451,8 +1464,10 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w
vkResetFences(c->device, 1, &g_fence[slot]);
if (g_sc_hdr) vk_hdr_metadata(g_sc, 0); // a changed peak or white goes to the display
if (g_th_pending[slot]) { // that fence has signalled: the thumbnail its submission wrote is complete
g_th_tag[g_th_pending[slot] % (uint64_t)g_th_n] = g_th_pending[slot];
uint64_t done = g_th_pending[slot];
g_th_tag[done % (uint64_t)g_th_n] = done;
g_th_pending[slot] = 0;
if (flight_flash_on && g_th_ptr) thumb_cells(done);
}
int cx = 0, cy = 0, cw = w, ch = h;