mirror of
https://github.com/pithings/unkernel.git
synced 2026-12-05 19:09:43 +08:00
* 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>
21 lines
732 B
Zig
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;
|
|
}
|
|
}
|