Files
unkernel/js/core/pixel-simd.zig
Kotaro Chikuba c554197790 js: convert XRGB8888 framebuffer pixels with Wasm SIMD (#188)
* js: convert XRGB8888 framebuffer pixels with Wasm SIMD

* js: keep the pixel SIMD scratch buffer off address 0

* js: move the frame conversion test to test/display.test.ts and check the embedded module

The test needs no kernel. It now also covers readRGBA()'s packed and padded paths and a shared source, and rebuilds pixel-simd.zig where zig 0.16 is on PATH to compare it with the embedded bytes.

---------

Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-12-05 00:49:32 +01:00

21 lines
732 B
Zig

// SPDX-License-Identifier: MIT
// Copyright (C) 2026 mizchi
const Bytes = @Vector(16, u8);
const rgba_order: @Vector(16, i32) = .{ 2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15 };
const opaque_alpha: Bytes = .{ 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255 };
var scratch: [1024 * 1024]u8 align(16) = undefined;
export fn scratchOffset() usize {
return @intFromPtr(&scratch);
}
export fn rgba(length: usize) void {
if (length > scratch.len or length % @sizeOf(Bytes) != 0) return;
var i: usize = 0;
while (i < length) : (i += @sizeOf(Bytes)) {
const lanes: *Bytes = @ptrCast(@alignCast(&scratch[i]));
lanes.* = @shuffle(u8, lanes.*, undefined, rgba_order) | opaque_alpha;
}
}