From a9ee890d97a8adc10a9572d90a600aecea4bb151 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:36:10 +0100 Subject: [PATCH 1/6] Use nearest-neighbour framebuffer scaling for fbdoom --- .../recipes-apps/doom/fbdoom_0.0.1.bb | 1 + .../0004-nearest-neighbour-scaling.patch | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch diff --git a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb index cf1a35ad..2f0b2bdb 100644 --- a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb +++ b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb @@ -12,6 +12,7 @@ SRC_URI = " \ file://0001-touchscreen-support-ig.patch \ file://0002-skip-exit-confirmation.patch \ file://0003-bilinear-fit-scaling.patch \ + file://0004-nearest-neighbour-scaling.patch \ file://play-doom.sh \ " SRC_URI[sha256sum] = "c1d1f430e623b5b02693a2ab42988f951fb66ae3bd3add06e557bdf36af0e24f" diff --git a/meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch b/meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch new file mode 100644 index 00000000..2181abfa --- /dev/null +++ b/meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch @@ -0,0 +1,101 @@ +Subject: [PATCH] Use nearest-neighbour framebuffer scaling + +Upstream-Status: Inappropriate [COSMOS framebuffer policy] + +--- a/fbdoom/i_video_fbdev.c ++++ b/fbdoom/i_video_fbdev.c +@@ -77,12 +77,7 @@ + static struct fb_fix_screeninfo finfo; + static int scaled_width, scaled_height, scaled_x, scaled_y; + +-typedef struct { +- int first, second; +- unsigned int weight; +-} scale_sample_t; +- +-static scale_sample_t *scale_x, *scale_y; ++static int *scale_x, *scale_y; + + int X_width; + int X_height; +@@ -124,9 +119,9 @@ + static uint16_t rgb565_palette[256]; + + /* Pixel-center mapping with clamped edges, calculated only at startup. */ +-static scale_sample_t *make_scale_map(int source, int destination) +-{ +- scale_sample_t *map; ++static int *make_scale_map(int source, int destination) ++{ ++ int *map; + int i; + + if ((size_t)destination > SIZE_MAX / sizeof(*map)) +@@ -136,15 +131,7 @@ + if (!map) + I_Error("Unable to allocate framebuffer scale map"); + for (i = 0; i < destination; ++i) { +- int64_t position = ((2 * (int64_t)i + 1) * source * 128) +- / destination - 128; +- if (position < 0) +- position = 0; +- if (position > (source - 1) * 256) +- position = (source - 1) * 256; +- map[i].first = position >> 8; +- map[i].second = map[i].first + (map[i].first < source - 1); +- map[i].weight = position & 255; ++ map[i] = ((2 * (int64_t)i + 1) * source) / (2 * destination); + } + return map; + } +@@ -175,18 +162,8 @@ + scaled_y = (fb.yres - scaled_height) / 2; + scale_x = make_scale_map(SCREENWIDTH, scaled_width); + scale_y = make_scale_map(SCREENHEIGHT, scaled_height); +- printf("I_InitGraphics: Bilinear scaling to %dx%d at (%d,%d)\n", ++ printf("I_InitGraphics: Nearest-neighbour scaling to %dx%d at (%d,%d)\n", + scaled_width, scaled_height, scaled_x, scaled_y); +-} +- +-/* Blend RGB channels, never palette indices. Weights have eight fraction bits. */ +-static unsigned int bilinear(unsigned int a, unsigned int b, +- unsigned int c, unsigned int d, +- unsigned int wx, unsigned int wy) +-{ +- unsigned int top = a * (256 - wx) + b * wx; +- unsigned int bottom = c * (256 - wx) + d * wx; +- return (top * (256 - wy) + bottom * wy + 32768) >> 16; + } + + static uint32_t pack_channel(unsigned int value, struct fb_bitfield field) +@@ -480,20 +457,20 @@ + uint32_t alpha = fb.transp.length + ? ((1u << fb.transp.length) - 1) << fb.transp.offset : 0; + ++ uint32_t palette[256]; ++ ++ /* Rebuild after palette/gamma changes, outside the per-pixel loop. */ ++ for (x = 0; x < 256; ++x) ++ palette[x] = alpha | pack_channel(colors[x].r, fb.red) ++ | pack_channel(colors[x].g, fb.green) ++ | pack_channel(colors[x].b, fb.blue); ++ + for (y = 0; y < scaled_height; ++y) { +- scale_sample_t sy = scale_y[y]; +- const byte *top = I_VideoBuffer + sy.first * SCREENWIDTH; +- const byte *bottom = I_VideoBuffer + sy.second * SCREENWIDTH; ++ const byte *in = I_VideoBuffer + scale_y[y] * SCREENWIDTH; + byte *out = I_VideoBuffer_FB + (size_t)(scaled_y + y) * finfo.line_length + + (size_t)scaled_x * bytes; + for (x = 0; x < scaled_width; ++x) { +- scale_sample_t sx = scale_x[x]; +- struct color a = colors[top[sx.first]], b = colors[top[sx.second]]; +- struct color c = colors[bottom[sx.first]], d = colors[bottom[sx.second]]; +- uint32_t pixel = alpha +- | pack_channel(bilinear(a.r, b.r, c.r, d.r, sx.weight, sy.weight), fb.red) +- | pack_channel(bilinear(a.g, b.g, c.g, d.g, sx.weight, sy.weight), fb.green) +- | pack_channel(bilinear(a.b, b.b, c.b, d.b, sx.weight, sy.weight), fb.blue); ++ uint32_t pixel = palette[in[scale_x[x]]]; + for (byte_index = 0; byte_index < bytes; ++byte_index) + *out++ = pixel >> (byte_index * 8); + } From 4654e33a5656d07622a089754f453ed697718942 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:41:58 +0100 Subject: [PATCH 2/6] Optimize fbdoom pixel stores and repeated scaled rows --- .../recipes-apps/doom/fbdoom_0.0.1.bb | 1 + ...5-speed-up-nearest-neighbour-scaling.patch | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch diff --git a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb index 2f0b2bdb..e103b0c3 100644 --- a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb +++ b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb @@ -13,6 +13,7 @@ SRC_URI = " \ file://0002-skip-exit-confirmation.patch \ file://0003-bilinear-fit-scaling.patch \ file://0004-nearest-neighbour-scaling.patch \ + file://0005-speed-up-nearest-neighbour-scaling.patch \ file://play-doom.sh \ " SRC_URI[sha256sum] = "c1d1f430e623b5b02693a2ab42988f951fb66ae3bd3add06e557bdf36af0e24f" diff --git a/meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch b/meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch new file mode 100644 index 00000000..cdf30c69 --- /dev/null +++ b/meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch @@ -0,0 +1,44 @@ +Subject: [PATCH] Use native pixel stores and reuse repeated scaled rows + +Upstream-Status: Inappropriate [COSMOS framebuffer scaling] + +--- a/fbdoom/i_video_fbdev.c ++++ b/fbdoom/i_video_fbdev.c +@@ -131,7 +131,7 @@ + if (!map) + I_Error("Unable to allocate framebuffer scale map"); + for (i = 0; i < destination; ++i) { +- map[i] = ((2 * (int64_t)i + 1) * source) / (2 * destination); ++ map[i] = ((2 * (int64_t)i + 1) * source) / (2 * (int64_t)destination); + } + return map; + } +@@ -469,10 +469,24 @@ + const byte *in = I_VideoBuffer + scale_y[y] * SCREENWIDTH; + byte *out = I_VideoBuffer_FB + (size_t)(scaled_y + y) * finfo.line_length + + (size_t)scaled_x * bytes; +- for (x = 0; x < scaled_width; ++x) { +- uint32_t pixel = palette[in[scale_x[x]]]; +- for (byte_index = 0; byte_index < bytes; ++byte_index) +- *out++ = pixel >> (byte_index * 8); ++ /* Nearest-neighbour upscaling repeats source rows. */ ++ if (y > 0 && scale_y[y] == scale_y[y - 1]) { ++ memcpy(out, out - finfo.line_length, (size_t)scaled_width * bytes); ++ } else if (bytes == 4 && ((uintptr_t)out & 3) == 0) { ++ uint32_t *pixels = (uint32_t *)out; ++ for (x = 0; x < scaled_width; ++x) ++ pixels[x] = palette[in[scale_x[x]]]; ++ } else if (bytes == 2 && ((uintptr_t)out & 1) == 0) { ++ uint16_t *pixels = (uint16_t *)out; ++ for (x = 0; x < scaled_width; ++x) ++ pixels[x] = palette[in[scale_x[x]]]; ++ } else { ++ /* Preserve packed 24-bit and unaligned framebuffer layouts. */ ++ for (x = 0; x < scaled_width; ++x) { ++ uint32_t pixel = palette[in[scale_x[x]]]; ++ for (byte_index = 0; byte_index < bytes; ++byte_index) ++ *out++ = pixel >> (byte_index * 8); ++ } + } + } + From 7e991053f46ce17cbd3bc27fc0b7a134057cdf1f Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:54:29 +0100 Subject: [PATCH 3/6] Reduce fbdoom framebuffer transfer overhead on simpledrm --- .../recipes-apps/doom/fbdoom_0.0.1.bb | 1 + ...-buffer-simpledrm-framebuffer-writes.patch | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 meta-opencentauri/recipes-apps/doom/files/0006-buffer-simpledrm-framebuffer-writes.patch diff --git a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb index e103b0c3..f9e753c7 100644 --- a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb +++ b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb @@ -14,6 +14,7 @@ SRC_URI = " \ file://0003-bilinear-fit-scaling.patch \ file://0004-nearest-neighbour-scaling.patch \ file://0005-speed-up-nearest-neighbour-scaling.patch \ + file://0006-buffer-simpledrm-framebuffer-writes.patch \ file://play-doom.sh \ " SRC_URI[sha256sum] = "c1d1f430e623b5b02693a2ab42988f951fb66ae3bd3add06e557bdf36af0e24f" diff --git a/meta-opencentauri/recipes-apps/doom/files/0006-buffer-simpledrm-framebuffer-writes.patch b/meta-opencentauri/recipes-apps/doom/files/0006-buffer-simpledrm-framebuffer-writes.patch new file mode 100644 index 00000000..130b6deb --- /dev/null +++ b/meta-opencentauri/recipes-apps/doom/files/0006-buffer-simpledrm-framebuffer-writes.patch @@ -0,0 +1,50 @@ +Subject: [PATCH] Buffer simpledrm frame writes and coalesce packed rows + +Avoid per-page mmap write faults on simpledrm. Keep mmap for other +framebuffer drivers and preserve padded/offset viewport handling. + +Upstream-Status: Inappropriate [COSMOS framebuffer integration] + +--- a/fbdoom/i_video_fbdev.c ++++ b/fbdoom/i_video_fbdev.c +@@ -224,10 +224,15 @@ + + /* mmap the framebuffer for direct access */ + fb_screensize = finfo.smem_len; +- fb_mmap = mmap(0, fb_screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0); ++ /* simpledrm tracks mmap writes with page faults. A buffered write avoids ++ * those faults and lets the driver mark the whole frame dirty at once. */ ++ if (strncmp(finfo.id, "simpledrmdrmfb", sizeof(finfo.id)) == 0) ++ fb_mmap = MAP_FAILED; ++ else ++ fb_mmap = mmap(0, fb_screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0); + if (fb_mmap == MAP_FAILED) { + fb_mmap = NULL; +- printf("I_InitGraphics: mmap failed, falling back to write()\n"); ++ printf("I_InitGraphics: using buffered framebuffer writes\n"); + } else { + printf("I_InitGraphics: mmap OK, screensize=%zu, line_length=%u\n", + fb_screensize, finfo.line_length); +@@ -491,15 +496,18 @@ + } + + /* Include the zero-filled borders and respect stride and viewport offsets. */ +- for (y = 0; y < fb.yres; ++y) { ++ /* A tightly packed viewport can be transferred with one write. */ ++ int rows_per_write = row_bytes == finfo.line_length ? fb.yres : 1; ++ for (y = 0; y < fb.yres; y += rows_per_write) { ++ size_t copy_bytes = row_bytes * rows_per_write; + byte *row = I_VideoBuffer_FB + (size_t)y * finfo.line_length; + size_t target = offset + (size_t)y * finfo.line_length; + if (fb_mmap) { +- memcpy(fb_mmap + target, row, row_bytes); ++ memcpy(fb_mmap + target, row, copy_bytes); + } else { + size_t done = 0; +- while (done < row_bytes) { +- ssize_t n = pwrite(fd_fb, row + done, row_bytes - done, target + done); ++ while (done < copy_bytes) { ++ ssize_t n = pwrite(fd_fb, row + done, copy_bytes - done, target + done); + if (n < 0 && errno == EINTR) + continue; + if (n <= 0) From 2d2edd5718b86af317ca689249539c534368a689 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:55:10 +0100 Subject: [PATCH 4/6] Consolidate fbdoom framebuffer scaling patches --- .../recipes-apps/doom/fbdoom_0.0.1.bb | 4 +- ... 0003-nearest-neighbour-fit-scaling.patch} | 130 +++++++++--------- .../0004-nearest-neighbour-scaling.patch | 101 -------------- ...5-speed-up-nearest-neighbour-scaling.patch | 44 ------ 4 files changed, 66 insertions(+), 213 deletions(-) rename meta-opencentauri/recipes-apps/doom/files/{0003-bilinear-fit-scaling.patch => 0003-nearest-neighbour-fit-scaling.patch} (83%) delete mode 100644 meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch delete mode 100644 meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch diff --git a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb index f9e753c7..b596b8a7 100644 --- a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb +++ b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb @@ -11,9 +11,7 @@ SRC_URI = " \ https://www.jbserver.com/downloads/games/doom/misc/shareware/doom1.wad.zip \ file://0001-touchscreen-support-ig.patch \ file://0002-skip-exit-confirmation.patch \ - file://0003-bilinear-fit-scaling.patch \ - file://0004-nearest-neighbour-scaling.patch \ - file://0005-speed-up-nearest-neighbour-scaling.patch \ + file://0003-nearest-neighbour-fit-scaling.patch \ file://0006-buffer-simpledrm-framebuffer-writes.patch \ file://play-doom.sh \ " diff --git a/meta-opencentauri/recipes-apps/doom/files/0003-bilinear-fit-scaling.patch b/meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch similarity index 83% rename from meta-opencentauri/recipes-apps/doom/files/0003-bilinear-fit-scaling.patch rename to meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch index 1cad507f..ad0f34f2 100644 --- a/meta-opencentauri/recipes-apps/doom/files/0003-bilinear-fit-scaling.patch +++ b/meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch @@ -1,3 +1,12 @@ +Subject: [PATCH] Fit the framebuffer with efficient nearest-neighbour scaling + +Preserve aspect ratio and center the image, respecting framebuffer stride, +viewport offsets, and packed 16/24/32-bit truecolor layouts. Precompute +pixel-center sampling maps and palette colors, use native pixel stores +where aligned, and reuse repeated source rows during upscaling. + +Upstream-Status: Inappropriate [COSMOS framebuffer integration] + --- a/fbdoom/i_video_fbdev.c +++ b/fbdoom/i_video_fbdev.c @@ -31,12 +31,15 @@ @@ -27,7 +36,7 @@ int usemouse = 0; struct color { -@@ -73,7 +73,16 @@ +@@ -73,7 +73,11 @@ /* framebuffer file descriptor */ int fd_fb = 0; static uint8_t *fb_mmap = NULL; @@ -36,16 +45,11 @@ +static struct fb_fix_screeninfo finfo; +static int scaled_width, scaled_height, scaled_x, scaled_y; + -+typedef struct { -+ int first, second; -+ unsigned int weight; -+} scale_sample_t; -+ -+static scale_sample_t *scale_x, *scale_y; ++static int *scale_x, *scale_y; int X_width; int X_height; -@@ -114,52 +123,75 @@ +@@ -114,52 +118,57 @@ static uint16_t rgb565_palette[256]; @@ -96,9 +100,9 @@ - in++; - } +/* Pixel-center mapping with clamped edges, calculated only at startup. */ -+static scale_sample_t *make_scale_map(int source, int destination) ++static int *make_scale_map(int source, int destination) +{ -+ scale_sample_t *map; ++ int *map; + int i; + + if ((size_t)destination > SIZE_MAX / sizeof(*map)) @@ -108,15 +112,7 @@ + if (!map) + I_Error("Unable to allocate framebuffer scale map"); + for (i = 0; i < destination; ++i) { -+ int64_t position = ((2 * (int64_t)i + 1) * source * 128) -+ / destination - 128; -+ if (position < 0) -+ position = 0; -+ if (position > (source - 1) * 256) -+ position = (source - 1) * 256; -+ map[i].first = position >> 8; -+ map[i].second = map[i].first + (map[i].first < source - 1); -+ map[i].weight = position & 255; ++ map[i] = ((2 * (int64_t)i + 1) * source) / (2 * (int64_t)destination); + } + return map; +} @@ -147,27 +143,17 @@ + scaled_y = (fb.yres - scaled_height) / 2; + scale_x = make_scale_map(SCREENWIDTH, scaled_width); + scale_y = make_scale_map(SCREENHEIGHT, scaled_height); -+ printf("I_InitGraphics: Bilinear scaling to %dx%d at (%d,%d)\n", ++ printf("I_InitGraphics: Nearest-neighbour scaling to %dx%d at (%d,%d)\n", + scaled_width, scaled_height, scaled_x, scaled_y); +} + -+/* Blend RGB channels, never palette indices. Weights have eight fraction bits. */ -+static unsigned int bilinear(unsigned int a, unsigned int b, -+ unsigned int c, unsigned int d, -+ unsigned int wx, unsigned int wy) -+{ -+ unsigned int top = a * (256 - wx) + b * wx; -+ unsigned int bottom = c * (256 - wx) + d * wx; -+ return (top * (256 - wy) + bottom * wy + 32768) >> 16; -+} -+ +static uint32_t pack_channel(unsigned int value, struct fb_bitfield field) +{ + return field.length ? (value >> (8 - field.length)) << field.offset : 0; } void I_InitGraphics (void) -@@ -175,7 +207,31 @@ +@@ -175,7 +184,31 @@ } /* fetch framebuffer info */ @@ -200,7 +186,7 @@ /* change params if needed */ //ioctl(fd_fb, FBIOPUT_VSCREENINFO, &fb); printf("I_InitGraphics: framebuffer: x_res: %d, y_res: %d, x_virtual: %d, y_virtual: %d, bpp: %d, grayscale: %d\n", -@@ -187,36 +243,27 @@ +@@ -187,36 +220,27 @@ printf("I_InitGraphics: DOOM screen size: w x h: %d x %d\n", SCREENWIDTH, SCREENHEIGHT); @@ -245,7 +231,7 @@ screenvisible = true; -@@ -232,6 +279,8 @@ +@@ -232,6 +256,8 @@ } Z_Free (I_VideoBuffer); free(I_VideoBuffer_FB); @@ -254,7 +240,7 @@ } void I_StartFrame (void) -@@ -424,59 +473,53 @@ +@@ -424,59 +450,67 @@ void I_FinishUpdate (void) { @@ -294,41 +280,35 @@ + uint32_t alpha = fb.transp.length + ? ((1u << fb.transp.length) - 1) << fb.transp.offset : 0; + ++ uint32_t palette[256]; ++ ++ /* Rebuild after palette/gamma changes, outside the per-pixel loop. */ ++ for (x = 0; x < 256; ++x) ++ palette[x] = alpha | pack_channel(colors[x].r, fb.red) ++ | pack_channel(colors[x].g, fb.green) ++ | pack_channel(colors[x].b, fb.blue); ++ + for (y = 0; y < scaled_height; ++y) { -+ scale_sample_t sy = scale_y[y]; -+ const byte *top = I_VideoBuffer + sy.first * SCREENWIDTH; -+ const byte *bottom = I_VideoBuffer + sy.second * SCREENWIDTH; ++ const byte *in = I_VideoBuffer + scale_y[y] * SCREENWIDTH; + byte *out = I_VideoBuffer_FB + (size_t)(scaled_y + y) * finfo.line_length + + (size_t)scaled_x * bytes; -+ for (x = 0; x < scaled_width; ++x) { -+ scale_sample_t sx = scale_x[x]; -+ struct color a = colors[top[sx.first]], b = colors[top[sx.second]]; -+ struct color c = colors[bottom[sx.first]], d = colors[bottom[sx.second]]; -+ uint32_t pixel = alpha -+ | pack_channel(bilinear(a.r, b.r, c.r, d.r, sx.weight, sy.weight), fb.red) -+ | pack_channel(bilinear(a.g, b.g, c.g, d.g, sx.weight, sy.weight), fb.green) -+ | pack_channel(bilinear(a.b, b.b, c.b, d.b, sx.weight, sy.weight), fb.blue); -+ for (byte_index = 0; byte_index < bytes; ++byte_index) -+ *out++ = pixel >> (byte_index * 8); -+ } -+ } -+ -+ /* Include the zero-filled borders and respect stride and viewport offsets. */ -+ for (y = 0; y < fb.yres; ++y) { -+ byte *row = I_VideoBuffer_FB + (size_t)y * finfo.line_length; -+ size_t target = offset + (size_t)y * finfo.line_length; -+ if (fb_mmap) { -+ memcpy(fb_mmap + target, row, row_bytes); ++ /* Nearest-neighbour upscaling repeats source rows. */ ++ if (y > 0 && scale_y[y] == scale_y[y - 1]) { ++ memcpy(out, out - finfo.line_length, (size_t)scaled_width * bytes); ++ } else if (bytes == 4 && ((uintptr_t)out & 3) == 0) { ++ uint32_t *pixels = (uint32_t *)out; ++ for (x = 0; x < scaled_width; ++x) ++ pixels[x] = palette[in[scale_x[x]]]; ++ } else if (bytes == 2 && ((uintptr_t)out & 1) == 0) { ++ uint16_t *pixels = (uint16_t *)out; ++ for (x = 0; x < scaled_width; ++x) ++ pixels[x] = palette[in[scale_x[x]]]; + } else { -+ size_t done = 0; -+ while (done < row_bytes) { -+ ssize_t n = pwrite(fd_fb, row + done, row_bytes - done, target + done); -+ if (n < 0 && errno == EINTR) -+ continue; -+ if (n <= 0) -+ I_Error("Unable to write framebuffer: %s", -+ n < 0 ? strerror(errno) : "short write"); -+ done += n; ++ /* Preserve packed 24-bit and unaligned framebuffer layouts. */ ++ for (x = 0; x < scaled_width; ++x) { ++ uint32_t pixel = palette[in[scale_x[x]]]; ++ for (byte_index = 0; byte_index < bytes; ++byte_index) ++ *out++ = pixel >> (byte_index * 8); } -#else - //cmap_to_rgb565((void*)line_out, (void*)line_in, SCREENWIDTH); @@ -354,6 +334,26 @@ - write(fd_fb, I_VideoBuffer_FB, draw_bytes); - } + } ++ ++ /* Include the zero-filled borders and respect stride and viewport offsets. */ ++ for (y = 0; y < fb.yres; ++y) { ++ byte *row = I_VideoBuffer_FB + (size_t)y * finfo.line_length; ++ size_t target = offset + (size_t)y * finfo.line_length; ++ if (fb_mmap) { ++ memcpy(fb_mmap + target, row, row_bytes); ++ } else { ++ size_t done = 0; ++ while (done < row_bytes) { ++ ssize_t n = pwrite(fd_fb, row + done, row_bytes - done, target + done); ++ if (n < 0 && errno == EINTR) ++ continue; ++ if (n <= 0) ++ I_Error("Unable to write framebuffer: %s", ++ n < 0 ? strerror(errno) : "short write"); ++ done += n; ++ } ++ } ++ } + /* Notify DRM fbdev emulation that the buffer changed. */ + ioctl(fd_fb, FBIOPAN_DISPLAY, &fb); } diff --git a/meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch b/meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch deleted file mode 100644 index 2181abfa..00000000 --- a/meta-opencentauri/recipes-apps/doom/files/0004-nearest-neighbour-scaling.patch +++ /dev/null @@ -1,101 +0,0 @@ -Subject: [PATCH] Use nearest-neighbour framebuffer scaling - -Upstream-Status: Inappropriate [COSMOS framebuffer policy] - ---- a/fbdoom/i_video_fbdev.c -+++ b/fbdoom/i_video_fbdev.c -@@ -77,12 +77,7 @@ - static struct fb_fix_screeninfo finfo; - static int scaled_width, scaled_height, scaled_x, scaled_y; - --typedef struct { -- int first, second; -- unsigned int weight; --} scale_sample_t; -- --static scale_sample_t *scale_x, *scale_y; -+static int *scale_x, *scale_y; - - int X_width; - int X_height; -@@ -124,9 +119,9 @@ - static uint16_t rgb565_palette[256]; - - /* Pixel-center mapping with clamped edges, calculated only at startup. */ --static scale_sample_t *make_scale_map(int source, int destination) --{ -- scale_sample_t *map; -+static int *make_scale_map(int source, int destination) -+{ -+ int *map; - int i; - - if ((size_t)destination > SIZE_MAX / sizeof(*map)) -@@ -136,15 +131,7 @@ - if (!map) - I_Error("Unable to allocate framebuffer scale map"); - for (i = 0; i < destination; ++i) { -- int64_t position = ((2 * (int64_t)i + 1) * source * 128) -- / destination - 128; -- if (position < 0) -- position = 0; -- if (position > (source - 1) * 256) -- position = (source - 1) * 256; -- map[i].first = position >> 8; -- map[i].second = map[i].first + (map[i].first < source - 1); -- map[i].weight = position & 255; -+ map[i] = ((2 * (int64_t)i + 1) * source) / (2 * destination); - } - return map; - } -@@ -175,18 +162,8 @@ - scaled_y = (fb.yres - scaled_height) / 2; - scale_x = make_scale_map(SCREENWIDTH, scaled_width); - scale_y = make_scale_map(SCREENHEIGHT, scaled_height); -- printf("I_InitGraphics: Bilinear scaling to %dx%d at (%d,%d)\n", -+ printf("I_InitGraphics: Nearest-neighbour scaling to %dx%d at (%d,%d)\n", - scaled_width, scaled_height, scaled_x, scaled_y); --} -- --/* Blend RGB channels, never palette indices. Weights have eight fraction bits. */ --static unsigned int bilinear(unsigned int a, unsigned int b, -- unsigned int c, unsigned int d, -- unsigned int wx, unsigned int wy) --{ -- unsigned int top = a * (256 - wx) + b * wx; -- unsigned int bottom = c * (256 - wx) + d * wx; -- return (top * (256 - wy) + bottom * wy + 32768) >> 16; - } - - static uint32_t pack_channel(unsigned int value, struct fb_bitfield field) -@@ -480,20 +457,20 @@ - uint32_t alpha = fb.transp.length - ? ((1u << fb.transp.length) - 1) << fb.transp.offset : 0; - -+ uint32_t palette[256]; -+ -+ /* Rebuild after palette/gamma changes, outside the per-pixel loop. */ -+ for (x = 0; x < 256; ++x) -+ palette[x] = alpha | pack_channel(colors[x].r, fb.red) -+ | pack_channel(colors[x].g, fb.green) -+ | pack_channel(colors[x].b, fb.blue); -+ - for (y = 0; y < scaled_height; ++y) { -- scale_sample_t sy = scale_y[y]; -- const byte *top = I_VideoBuffer + sy.first * SCREENWIDTH; -- const byte *bottom = I_VideoBuffer + sy.second * SCREENWIDTH; -+ const byte *in = I_VideoBuffer + scale_y[y] * SCREENWIDTH; - byte *out = I_VideoBuffer_FB + (size_t)(scaled_y + y) * finfo.line_length - + (size_t)scaled_x * bytes; - for (x = 0; x < scaled_width; ++x) { -- scale_sample_t sx = scale_x[x]; -- struct color a = colors[top[sx.first]], b = colors[top[sx.second]]; -- struct color c = colors[bottom[sx.first]], d = colors[bottom[sx.second]]; -- uint32_t pixel = alpha -- | pack_channel(bilinear(a.r, b.r, c.r, d.r, sx.weight, sy.weight), fb.red) -- | pack_channel(bilinear(a.g, b.g, c.g, d.g, sx.weight, sy.weight), fb.green) -- | pack_channel(bilinear(a.b, b.b, c.b, d.b, sx.weight, sy.weight), fb.blue); -+ uint32_t pixel = palette[in[scale_x[x]]]; - for (byte_index = 0; byte_index < bytes; ++byte_index) - *out++ = pixel >> (byte_index * 8); - } diff --git a/meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch b/meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch deleted file mode 100644 index cdf30c69..00000000 --- a/meta-opencentauri/recipes-apps/doom/files/0005-speed-up-nearest-neighbour-scaling.patch +++ /dev/null @@ -1,44 +0,0 @@ -Subject: [PATCH] Use native pixel stores and reuse repeated scaled rows - -Upstream-Status: Inappropriate [COSMOS framebuffer scaling] - ---- a/fbdoom/i_video_fbdev.c -+++ b/fbdoom/i_video_fbdev.c -@@ -131,7 +131,7 @@ - if (!map) - I_Error("Unable to allocate framebuffer scale map"); - for (i = 0; i < destination; ++i) { -- map[i] = ((2 * (int64_t)i + 1) * source) / (2 * destination); -+ map[i] = ((2 * (int64_t)i + 1) * source) / (2 * (int64_t)destination); - } - return map; - } -@@ -469,10 +469,24 @@ - const byte *in = I_VideoBuffer + scale_y[y] * SCREENWIDTH; - byte *out = I_VideoBuffer_FB + (size_t)(scaled_y + y) * finfo.line_length - + (size_t)scaled_x * bytes; -- for (x = 0; x < scaled_width; ++x) { -- uint32_t pixel = palette[in[scale_x[x]]]; -- for (byte_index = 0; byte_index < bytes; ++byte_index) -- *out++ = pixel >> (byte_index * 8); -+ /* Nearest-neighbour upscaling repeats source rows. */ -+ if (y > 0 && scale_y[y] == scale_y[y - 1]) { -+ memcpy(out, out - finfo.line_length, (size_t)scaled_width * bytes); -+ } else if (bytes == 4 && ((uintptr_t)out & 3) == 0) { -+ uint32_t *pixels = (uint32_t *)out; -+ for (x = 0; x < scaled_width; ++x) -+ pixels[x] = palette[in[scale_x[x]]]; -+ } else if (bytes == 2 && ((uintptr_t)out & 1) == 0) { -+ uint16_t *pixels = (uint16_t *)out; -+ for (x = 0; x < scaled_width; ++x) -+ pixels[x] = palette[in[scale_x[x]]]; -+ } else { -+ /* Preserve packed 24-bit and unaligned framebuffer layouts. */ -+ for (x = 0; x < scaled_width; ++x) { -+ uint32_t pixel = palette[in[scale_x[x]]]; -+ for (byte_index = 0; byte_index < bytes; ++byte_index) -+ *out++ = pixel >> (byte_index * 8); -+ } - } - } - From 8171284057eb6aa6d56c8b730f0a66c03ab3c6af Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:55:53 +0100 Subject: [PATCH 5/6] Renumber fbdoom framebuffer write patch --- meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb | 2 +- ...tes.patch => 0004-buffer-simpledrm-framebuffer-writes.patch} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename meta-opencentauri/recipes-apps/doom/files/{0006-buffer-simpledrm-framebuffer-writes.patch => 0004-buffer-simpledrm-framebuffer-writes.patch} (100%) diff --git a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb index b596b8a7..c34e0daf 100644 --- a/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb +++ b/meta-opencentauri/recipes-apps/doom/fbdoom_0.0.1.bb @@ -12,7 +12,7 @@ SRC_URI = " \ file://0001-touchscreen-support-ig.patch \ file://0002-skip-exit-confirmation.patch \ file://0003-nearest-neighbour-fit-scaling.patch \ - file://0006-buffer-simpledrm-framebuffer-writes.patch \ + file://0004-buffer-simpledrm-framebuffer-writes.patch \ file://play-doom.sh \ " SRC_URI[sha256sum] = "c1d1f430e623b5b02693a2ab42988f951fb66ae3bd3add06e557bdf36af0e24f" diff --git a/meta-opencentauri/recipes-apps/doom/files/0006-buffer-simpledrm-framebuffer-writes.patch b/meta-opencentauri/recipes-apps/doom/files/0004-buffer-simpledrm-framebuffer-writes.patch similarity index 100% rename from meta-opencentauri/recipes-apps/doom/files/0006-buffer-simpledrm-framebuffer-writes.patch rename to meta-opencentauri/recipes-apps/doom/files/0004-buffer-simpledrm-framebuffer-writes.patch From 19056116a21afcdebc1b8d4b7392c3ae91dc31e8 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:25:14 +0100 Subject: [PATCH 6/6] Remove patch note --- .../doom/files/0003-nearest-neighbour-fit-scaling.patch | 9 --------- .../files/0004-buffer-simpledrm-framebuffer-writes.patch | 7 ------- 2 files changed, 16 deletions(-) diff --git a/meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch b/meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch index ad0f34f2..aead9af0 100644 --- a/meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch +++ b/meta-opencentauri/recipes-apps/doom/files/0003-nearest-neighbour-fit-scaling.patch @@ -1,12 +1,3 @@ -Subject: [PATCH] Fit the framebuffer with efficient nearest-neighbour scaling - -Preserve aspect ratio and center the image, respecting framebuffer stride, -viewport offsets, and packed 16/24/32-bit truecolor layouts. Precompute -pixel-center sampling maps and palette colors, use native pixel stores -where aligned, and reuse repeated source rows during upscaling. - -Upstream-Status: Inappropriate [COSMOS framebuffer integration] - --- a/fbdoom/i_video_fbdev.c +++ b/fbdoom/i_video_fbdev.c @@ -31,12 +31,15 @@ diff --git a/meta-opencentauri/recipes-apps/doom/files/0004-buffer-simpledrm-framebuffer-writes.patch b/meta-opencentauri/recipes-apps/doom/files/0004-buffer-simpledrm-framebuffer-writes.patch index 130b6deb..42187948 100644 --- a/meta-opencentauri/recipes-apps/doom/files/0004-buffer-simpledrm-framebuffer-writes.patch +++ b/meta-opencentauri/recipes-apps/doom/files/0004-buffer-simpledrm-framebuffer-writes.patch @@ -1,10 +1,3 @@ -Subject: [PATCH] Buffer simpledrm frame writes and coalesce packed rows - -Avoid per-page mmap write faults on simpledrm. Keep mmap for other -framebuffer drivers and preserve padded/offset viewport handling. - -Upstream-Status: Inappropriate [COSMOS framebuffer integration] - --- a/fbdoom/i_video_fbdev.c +++ b/fbdoom/i_video_fbdev.c @@ -224,10 +224,15 @@