Skip to content

pagh-gl-demo: PDP/1 ShmSurface integration + three CPU scenes (PR5) - #173

Merged
ccclosed merged 3 commits into
devfrom
feat/tinygl-pr5-compositor
Nov 21, 2026
Merged

ccclosed merged 3 commits into
devfrom
feat/tinygl-pr5-compositor

Conversation

@ccclosed

Copy link
Copy Markdown
Owner

Что это

PR5 спеки docs/tinygl-port-spec.md (она пришла в dev с #168; ветка смержена с origin/dev = 02d79f14): композитор/PDP-интеграция и демо для CPU-порта TinyGL. Вариант A (upstream C 0.4.1 + тонкий FFI, MIT). Версия pagh/Cargo.toml не меняется — MINOR только в финальном acceptance PR6.

Сцены и дайджесты (640×480, FNV-1a-64 по словам пикселей)

сцена кадр digest что доказывает
triangle 0 0x13e6981740ce9b4d perspective + clip + Gouraud (центр 0x00677a83)
cube 0 0xedbd26e7dcbf0507 6 граней, depth + back-face culling
cube 1 0x6bf2cc8b656d31a5 кадр n = 25° + n·15°
cube 2 0x921eaf892e9d44a5
gears (lighting on) 0 0x3d6fcc428ccbb634 ~1.1k треугольников, материал/нормали
gears (on) 1 0x2a04fc59b4722ea0 кадр n = n·1.5° × передаточное
gears (lighting off) 0 0x900ca56f270b8033 плоский glColor3f
gears (off) 1 0xe8d5da9652a9eb7b

Host и musl совпали байт-в-байт, включая QEMU-гостя: кадры 0/1 в госте — те же 0x3d6fcc428ccbb634 / 0x2a04fc59b4722ea0. Для gears базовый профиль зуба считается собственным рядом Тейлора без libm (f64, только IEEE-арифметика), повороты кадра уходят в C glRotatef — поэтому геометрия не зависит от glibc/musl.

PDP/1 + ShmSurface (без копии кадра)

memfd_create → ftruncate(w·h·4) → mmap(MAP_SHARED) (pagh_ui::shm::ShmSurface) → hello/welcome (нужен welcome.flags bit 2) → create → SHM_OFFER с fd через SCM_RIGHTS → SHM_READY → ZB_open(..., mapping_ptr) + glInit → COMMIT+DAMAGE (header flags SHM). На configure — новый memfd/offer/release; на SHM_RELEASE — повторный offer. Fallback на full-frame upload отсутствует намеренно (спека §4.5): без ShmSurface демо падает с внятной ошибкой.

Evidence реального композитора:

  • host e2e (pagh-desktop headless + настоящий бинарник демо по AF_UNIX): shm_offers=1, shm_commits>=60, пиксель окна изменился, PNG рабочего стола с окном «TinyGL — gears»;
  • QEMU fbdev (1280×800) + --launch-target gl=... --autostart gl: окно с шестерёнками в кадре, TINYGL gears frame=0 digest=0x3d6fcc428ccbb634, скриншот qtinygl-pr5-qemu-window.png.

Frame time (замеры; TCG — верхняя граница, не бенчмарк GPU)

  • host, headless 640×480, gears: ft≈0.76/0.77/1.18 ms.
  • QEMU TCG, живое окно 640×480, gears (≈840 кадров за 45 с, ~19 fps): ft=28.000/35.000/98.000 ms (wall) cycles=71885377/87591977/249819290.

Тесты

  • rust-apps/tinygl: 58 host-тестов (+3 lighting: GL_LIGHTING меняет заливку, материал красит пиксель без glColor3f, NaN/∞ отвергаются до C).
  • rust-apps/pagh-gl-demo: 14 host и 14 musl (5 CLI + 8 render goldens + 1 PDP/SHM e2e). Pinned-дайджесты, точечная геометрия (центр Gouraud, грань куба, дырка/зуб шестерёнки), детерминизм, --frames 0 только с --connect, реальный композитор по AF_UNIX (shm_offers/shm_commits, композитный пиксель).
  • Musl e2e тоже зелёный: musl-тестовый бинарник поднимает musl-композитор и musl-демо; дайджесты совпадают.
  • static musl: tools/build-rust-app.sh rust-apps/pagh-gl-demo → 313 552 байта, static-pie linked, readelf -l | grep -c INTERP = 0, cc=musl-gcc.

Гейты 6/6 (на финальном SHA)

cargo fmt --all -- --check              exit 0
python3 tools/build.py build            exit 0 (linked pagh.elf)
python3 tools/build.py build --release  exit 0 (linked pagh.elf)
python3 tools/host_tests.py             850 passed, 0 failed
python3 tools/check_safety.py           OK (7 critical files)
python3 tools/check_agents_md.py        OK

Честные ограничения

CPU-only fixed-function GL 1.1 subset; без GPU/DRM/NVIDIA, shaders/GLSL/GL2+/FBO/VBO/EGL/GLX/Wayland. 16-битный Z; stride == width*4; width % 4 == 0 (композиторский configure с другой шириной — честная ошибка, не молчаливое ужатие). Один Context на процесс. gl_fatal_error upstream = exit(1). Освещение — только GL_LIGHT0..7/glMaterialfv (без glColorMaterial, spot/attenuation). Автоматическая GL-фаза в tools/e2e.py и MINOR/README acceptance — PR6, здесь их нет. Замеры TCG — верхняя граница.

Остатки / заметки

  • PR6: _desktop_gl_phase() в tools/e2e.py, acceptance §7 целиком, MINOR bump, README-ограничения.
  • Авроран-скрипт и диск для QEMU-прогона лежат в /home/oleg/.cache/pagh-agent-notes/ (не коммитятся); заметки — qtinygl-pr5.md.
  • Ветка feat/tinygl-pr5-compositor; не мержить — lead review.

The demo's gears scene needs GL_LIGHTING/GL_LIGHT0 and material state to show
the same geometry with lighting off/on (spec §6.1). Upstream 0.4.1 already
implements this in light.c; expose it through the safe layer instead of
poking C from the demo:

- ffi: glLightfv/glMaterialfv plus the GL_* pnames used (AMBIENT, DIFFUSE,
  SPECULAR, POSITION, EMISSION, SHININESS, AMBIENT_AND_DIFFUSE);
- Context: Light/LightParam/MaterialFace/MaterialParam enums and
  light()/material() with finite-value validation (NaN/∞ would produce a
  NaN-coloured frame, not a usable error);
- Capability gains Lighting/Light0/Normalize.

No C sources change. Tests render the same quad with lighting off and a red
material on, assert the pixel is red-dominant, green material reaches the
pixel without glColor3f, and NaN/∞ are rejected by our Err before C.
PR5 of the TinyGL port spec: the demo renders triangle/cube/gears straight
into the window's mmap(MAP_SHARED) memfd and sends only COMMIT+DAMAGE — no
frame copy over the socket. Without --connect it renders headless into
Vec<u32> and prints TINYGL digest markers.

- surface.rs: memfd/mmap via pagh_ui::shm, pixels exposed as &mut [u32] for
  ZB_open (stride is exactly width*4, width % 4 checked before C);
- client.rs: minimal PDP/1 client on the public pagh_ui protocol/shm API:
  hello/welcome (requires welcome.flags bit 2), create, SHM_OFFER with
  SCM_RIGHTS, SHM_READY, COMMIT (header flags SHM), resize via a new memfd and
  SHM_RELEASE(old), ping/pong, configure/close/error. There is deliberately no
  full-frame fallback: spec §4.5 asks for an explicit failure instead;
- scenes: our own code under tinygl::Context — triangle (Gouraud, fixed
  angle), cube (six faces, depth+culling, frame n = 25° + n*15°), gears
  (~1.1k triangles generated from a tooth profile, lighting off/on). Frame n
  is a pure function of n; Instant/rdtsc are used only for measurements;
- gears trigonometry uses a local Taylor series instead of libm so the base
  profile is bit-identical on glibc and musl; rotations go through C glRotatef;
- CLI: triangle|cube|gears, --connect, --frames, --size, --out (PPM),
  --hash, --lighting on|off, --help;
- tests: pinned FNV-1a digests for all scenes (lighting on/off) with geometry
  point checks (Gouraud centre, cube face, gear through-hole/tooth),
  determinism, CLI parsing, and a real e2e against the host pagh-desktop
  compositor over AF_UNIX proving shm_offers/shm_commits and a composed
  window pixel, plus a PNG screenshot artifact.

Host and musl runs produce identical digests; the static-pie musl binary is
checked by tools/build-rust-app.sh (no INTERP). Version is not bumped: MINOR
belongs to the final acceptance PR6.
@ccclosed
ccclosed merged commit 77856e9 into dev Nov 21, 2026
8 checks passed
@ccclosed
ccclosed deleted the feat/tinygl-pr5-compositor branch November 21, 2026 18:30
ccclosed pushed a commit that referenced this pull request Nov 22, 2026
Sync with dev=e7f2bdc3 (#169 VT/session routing, #173 tinygl PR5,
#174 vtfb1 respawn, docs).

Conflicts, both at appended/summary text:
- AGENTS.md: kept the USB S1 description for this branch (S1 is present
  here) and stated explicitly that it reaches dev only after this PR;
  #169/#173/#174 prose is kept verbatim.
- src/test.rs: kept BOTH the new #174
  "desktop-b::/dev/vtfb1 respawn after session exit (device path)" and the
  USB "usb::BOT/SCSI/uevent layouts and /usb root rule" routines.

All USB S1 files (xhci/usb_msc/usb_scsi/usb_msc_proto/usb_storage/
usb_uevent*/vfs block nodes/mount syscalls) are untouched by dev; the
dev-side terminal/tinygl/respawn changes are preserved.

Post-merge evidence: gates 6/6 (host 872/0), QEMU usb-storage acceptance
46/46, release-kernel selftest 125 routines / 0 failed / 1 skipped
(NVMe absent).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant