Skip to content

MLIR WASM: gfx + preload parity with C path (doom-flow scale) #221

Closed

Description

@godofecht

Summary

./flow wasm --backend=mlir already works for small console programs (Flow → MLIR → LLVM → emcc), but browser gfx games and file-backed apps still depend on --backend=c. The doom-flow GitHub Pages demo is a real stress case: full Doom in Flow, gfx_present game loop, ASYNCIFY, WAD preload, and flow_rt_support.c. Today it must use the C backend. Please treat Flow → MLIR → WASM as first-class for gfx loops and document/test it at gallery (and eventually doom-flow) scale.

Motivation

The natural story for Flow-in-the-browser is:

*.flow  →  MLIR  →  LLVM IR  →  emcc  →  .wasm

That path exists (--backend=mlir / FLOW_CPU_BACKEND=mlir), but production browser demos still advertise/ship:

*.flow  →  C  →  emcc  →  .wasm

For doom-flow we had to explain “we’re not on MLIR yet” in the README/site. Users reasonably expect the MLIR path once native --backend=mlir exists.

Live demo (C path today): https://godofecht.github.io/doom-flow/

Current state (as of filing)

Area Status
./flow wasm … --backend=mlir Works for examples/wasm/hello_wasm.flow (smoke + tests/integration/test_wasm_backends.py)
Gallery games (snake_gfx, etc.) C only (ROADMAP: gallery stays C)
wasm_build.py gfx link Can attach runtime/gfx_wasm.c + -sASYNCIFY for either backend when gfx is detected — not gallery-validated on MLIR
--fs / --preload / --threads Refuse MLIR (“crossings currently require --backend=c”)
doom-flow browser build Custom scripts/build_wasm.sh: Flow→C→emcc + gfx_wasm.c + flow_rt_support.c + --preload-file DOOM1.WAD@/doom1.wad + larger ASYNCIFY/memory

Relevant docs: docs/language/wasm.md, docs/demos/wasm.md, docs/language/wasm-crossings.md, ROADMAP.md.
Related closed roadmap: #121 (WASM target — Flow→C→emcc partial). No open issue for MLIR WASM gfx/doom-scale.

What doom-flow needs on MLIR

  1. Gfx loop under --backend=mlir
    Same contract as C: while + gfx_present → ASYNCIFY + runtime/gfx_wasm.c, verified in-browser (snake-class minimum).

  2. Runtime link set
    Stock wasm_build.py only adds gfx_wasm.c. Doom also needs runtime/flow_rt_support.c (fnptr trampolines / errno / host helpers). Either teach flow wasm to pick package [native] extras, or document a supported link hook.

  3. Filesystem preload on MLIR
    Unblock --preload / MEMFS (or equivalent) for --backend=mlir. Doom ships shareware IWAD via --preload-file …@/doom1.wad.

  4. Sizing knobs
    Doom needs roughly ASYNCIFY_STACK_SIZE≥65536, INITIAL_MEMORY≥64MB (stock defaults are smaller). Expose or auto-scale for large programs.

  5. wasm32 vs pointer-as-i64
    Doom still has LP64-era *_OFF_* / (ptr as i64) patterns in places. Clarify MLIR’s wasm32 pointer model vs C→emcc so ports don’t silently mis-index tables (we already hit this class of bug once on music layouts).

  6. Language gaps that bite large apps
    Capturing closures / effects on MLIR; missing runtime symbols; docs warn “larger programs may need extra emcc flags.” Need a clear “supported for gfx games” bar.

Proposed acceptance criteria

  • ./flow wasm examples/games/snake_gfx.flow --backend=mlir builds and runs in a browser (ASYNCIFY frame loop)
  • At least one CI / integration smoke for MLIR gfx (not only hello_wasm)
  • --preload DIR@/mount (or documented equivalent) works with --backend=mlir
  • Documented way to link extra runtime C (flow_rt_support.c) on the MLIR wasm path
  • docs/language/wasm.md + LANGUAGE_SPEC §9.3 updated so dual-backend status matches reality
  • Stretch: doom-flow Pages build can switch to --backend=mlir without a custom C-only script

Workarounds today

# doom-flow (C path — works)
FLOW_DIR=~/flow ./scripts/build_wasm.sh

# Flow hello on MLIR (works; not gfx)
./flow wasm examples/wasm/hello_wasm.flow --backend=mlir

Context links

Happy to help validate patches against doom-flow’s WASM build once the MLIR path grows the hooks above.

Activity

  1. godofecht commented on Aug 7, 2026

    @godofecht
    ContributorAuthor

    Child issues (split from this epic)

    # Title
    #222 MLIR: map unsigned Flow types (u8/…) to iN
    #223 MLIR: null pointer literals → llvm.mlir.zero
    #224 MLIR: memref vs llvm.getelementptr mixing
    #225 flow wasm --backend=mlir: honor --preload / --link

    Validation target

    doom-flow Pages currently ships C → emcc (scripts/build_wasm.sh). Once snake-class gfx + preload work on MLIR, we can dual-build and A/B.

    Observed “assets missing” on doom WASM (C path)

    Not IWAD 404 — WAD loads (adding doom1.wad). Apparent gaps are:

    1. Silent audio — FEATURE_SOUND / music soft-skipped on wasm
    2. Black walls/sky in 3D view — likely wasm32 struct-layout / render bug (TITLEPIC/HUD OK)

    Those are separate from the MLIR epic but motivate keeping the C path healthy while MLIR catches up.

  2. godofecht commented on Aug 7, 2026

    @godofecht
    ContributorAuthor

    Progress toward this epic:

    Still open for doom-scale MLIR: #223 (null ptr), #224 (memref/gep), #225 (preload/link).

  3. godofecht commented on Aug 7, 2026

    @godofecht
    ContributorAuthor

    Progress

    PR #229 lands:

    Child Status
    #222 unsigned → iN done in PR
    #224 memref vs GEP done in PR
    #223 null → llvm.mlir.zero still open
    #225 preload/link on MLIR still open

    Validated locally: ./flow wasm examples/games/snake_gfx.flow --backend=mlir builds a gfx canvas page (ASYNCIFY + gfx_wasm.c).

    Next for doom-scale: #225 (--preload / --link / memory knobs) then try dual-building doom-flow.

  4. godofecht commented on Aug 7, 2026

    @godofecht
    ContributorAuthor

    Children #222–#225 landed via #229. Remaining stretch: doom-flow Pages dual-build on the MLIR path (preload + link + gfx knobs are now in stock ./flow wasm --backend=mlir).

  5. added a commit that references this issue on Aug 7, 2026
  6. godofecht commented on Aug 7, 2026

    @godofecht
    ContributorAuthor

    Closed — acceptance met

    Criterion Status
    snake_gfx --backend=mlir gfx+ASYNCIFY page ✅
    MLIR gfx integration smoke ✅ test_wasm_mlir_gfx_snake in #231
    --preload / --link on MLIR ✅ #229 / #225
    Docs (wasm.md, LANGUAGE_SPEC §9.3, ROADMAP) ✅ #229 + #231
    Stretch: doom-flow dual-build hook ✅ BACKEND=mlir in doom-flow scripts/build_wasm.sh

    Not in scope for this close: full doom.flow MLIR lower still fails (KeyError: mlir_name …). Tracked as #230.

    Children #222–#225 already closed via #229.

  7. added a commit that references this issue on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions