Skip to content

A program's own quoted screen pass, on Vulkan and OpenGL - #1094

Merged
paul-hammant merged 4 commits into
mainfrom
feat/screen-pass
Nov 26, 2026
Merged

paul-hammant merged 4 commits into
mainfrom
feat/screen-pass

Conversation

@paul-hammant

Copy link
Copy Markdown
Collaborator

engine_set_screen_pass(e, shader, spirv): a full-screen pixel shader of the program's, written with quote, drawn over every frame after the tone curve and FXAA, on Vulkan and OpenGL. The program keeps the shader and sets its inputs between frames by name (gpu.set_float, set_vec2, ...). docs/screen-pass.md has the whole of it.

Until now a program could not draw a quoted shader of its own on Vulkan at all: SPIR-V came only from tools/generate_shaders over ae3d's own shaders, a pass took a fixed shader id, the frame's passes were each wired in by hand, and a quoted pass that sampled no texture was refused.

What's added

  • ae3d.quotegen: a program's own generator makes its passes' SPIR-V at build time (glslangValidator on PATH), an Aether module of words plus the tree's hash (gpu.QuotedSpirv). A shader changed since stops the program when its pass is made, naming it and its generator, as ae3d's own do (vkquote.fresh / stale).
  • vkpipes.shader_words, vkquote.program_pass_new: a pass from words the caller keeps, borrowing the program's shader, allowed to sample no texture (the descriptor pool is sized only for the kinds it has).
  • vkframe and gl draw it before the view blits; the engine applies it when the backend comes up, as it does the upscaler.
  • examples/screen_pass.ae (shader in examples/lib/screenpass, SPIR-V written by tools/screen_pass_spirv.ae), a change fragment, a README bullet.

Checked

  • tools/generate_shaders --check: unchanged, 71 shaders.
  • examples/screen_pass.ae on Vulkan and OpenGL (Apple M6): identical, every one of 576,000 pixels; builds warning-free.
  • The Aether port of Chris Hinsley's Raymarch draws his film shader this way: within 1/255 of his native code's frame on all but 44 of 360,000 pixels on Vulkan, 46 on OpenGL. Changing the shader without regenerating stops it with the stale message.
  • Not yet: the suites tier on a Linux lab host (ae-x64) is still running; I'll add its result here.

Questions for @nicolas-maman:

  1. Is "after the tone curve and FXAA, before the view blits" the right place for a program's pass, or would you rather offer a choice (before the composite as scene light too)?
  2. quotegen accepts any glslang, holding the words to the tree's hash rather than byte for byte to 16.6.0 as ae3d's own are. OK for programs?

🤖 Generated with Claude Code

paul-hammant and others added 4 commits November 25, 2026 22:43
engine_set_screen_pass(e, shader, spirv) draws a full-screen pixel shader
of the program's, written with quote, over every frame once the tone
curve and FXAA are done, its colours shown as it writes them. The
program keeps the shader and sets its inputs between frames by name
(gpu.set_float, set_vec2, ...).

On Vulkan a program's quoted shader could not be drawn at all: SPIR-V
came only from tools/generate_shaders over ae3d's own shaders, a pass
took a fixed shader id, the frame's passes were each wired in by hand,
and a quoted pass that sampled no texture was refused.

- ae3d.quotegen: a program's own generator makes its passes' SPIR-V at
  build time (glslangValidator on PATH) into an Aether module of words
  and the tree's hash (gpu.QuotedSpirv). A shader changed since stops
  the program when its pass is made, naming it and its generator
  (vkquote.stale), as ae3d's own do (fresh).
- vkpipes.shader_words, vkquote.program_pass_new: a pass from words the
  caller keeps, borrowing the program's shader, with no texture if it
  samples none (the descriptor pool sized only for what it has).
- vkframe and gl draw it before the view blits; engine applies it when
  the backend comes up, as the upscaler is.
- examples/screen_pass.ae, its shader in examples/lib/screenpass and its
  SPIR-V written by tools/screen_pass_spirv.ae: the same picture on both
  backends, every one of 576,000 pixels. docs/screen-pass.md.

Checked: tools/generate_shaders --check unchanged (71 shaders); the
example on Vulkan and OpenGL (M6), warning-free; the Aether port of
Chris Hinsley's Raymarch, drawn this way, within 1/255 of his native
code's frame on all but 44 of 360,000 pixels on Vulkan, 46 on OpenGL;
a stale shader stops it with the message above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
engine_set_screen_pass_rect(e, x, y, w, h) draws a program's screen pass in
a rectangle of the frame, its quad filling it, so a program can put its
own controls beside the picture. In the framebuffer's pixels from the top
left; 0 wide is the whole frame, as before. The viewport on OpenGL
(counted from the bottom there), vkframe.viewport_at on Vulkan, each put
back after the draw.

Found by the Aether port of Chris Hinsley's Surface, whose 640 x 480
canvas sits under a panel of ae3d.menu sliders: within 1/255 of his
native code's frame on all but 163 of 307,200 pixels on Vulkan, 143 on
OpenGL. docs/screen-pass.md says where the quad's uv runs on each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ci.sh type-checks each examples/lib module alone, a program importing it
and nothing else. examples/lib/screenpass_spirv imported only
`ae3d.gpu (QuotedSpirv)`, and on Aether 0.945.0, ae3d's CI pin, a module
reached only through selective imports has its own imports left out:
ae3d.gpu's std.string was, and string.length was undefined (fixed in
Aether 0.946.0, aether #3877). The module now imports ae3d.gpu whole too.
Checked with 0.945.0's aetherc: the probe fails with the old header and
compiles with the new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant

Copy link
Copy Markdown
Collaborator Author

Three commits since the PR opened:

  • 3443671: the screen pass in a rectangle of the frame. engine_set_screen_pass_rect(e, x, y, w, h) draws the program's pass in a rectangle (framebuffer pixels from the top left; 0 wide is the whole frame, as before), so a program can put controls beside its picture. On OpenGL it sets the viewport (counted from the bottom); on Vulkan it uses vkframe.viewport_at. Both put the viewport back after the draw. Found by the port of Chris Hinsley's Surface: his 640 x 480 canvas under a panel of ae3d.menu sliders, within 1/255 of his native code's frame on all but 163 of 307,200 pixels on Vulkan and 143 on OpenGL. docs/screen-pass.md says which way the quad's uv runs on each backend.
  • 6bdcca1: fixes the Linux CI failure (examples/lib/screenpass_spirv). The module quotegen writes imported ae3d.gpu (QuotedSpirv) only. On Aether 0.945.0, CI's pin, a module reached only through selective imports loses its own imports, so ae3d.gpu's std.string was left out. It now imports ae3d.gpu whole as well. Checked with 0.945.0's aetherc: the old header fails the probe as CI did, and the new one compiles. The Aether bug itself is fixed in 0.946.0.
  • c896ab4: a doc line that rendered as a list item.

Earlier run's macOS failures: test_items (under 200 µs a swing) and test_motion_cost (the powered/animated ratio 2.71 against 2.6). Both are timing limits, and this PR touches neither.

Lab: the suites tier on ae-x64 (llvmpipe), on the first commit. 305 ok, 177 skipped, 14 FAIL lines across 9 suites/benchmarks. I believe none comes from this PR, but I haven't run main there to prove it:

  • test_net_spawn, test_net_udp, test_overlay: build failures from a toolchain mix-up on that host (the generated C and the installed runtime header disagree on aether_unwind_track_place).
  • test_damage, test_instance_cull, bench_instance_cull, bench_lamp_instances: timing limits, on a VM shared with other jobs at the time.
  • test_anisotropy (llvmpipe's filtering) and test_vk_stages (still running at 300 s).

The two questions in the description still stand. One more, from the Surface port: an open ae3d.menu lays a 35% black veil over the frame. For a panel that is part of the app's window (Surface's sliders), the port gives its menu a theme with no veil. Would you rather a menu could be marked as a panel?

🤖 Generated with Claude Code

@paul-hammant
paul-hammant merged commit ad9f546 into main Nov 26, 2026
19 of 20 checks passed
@paul-hammant
paul-hammant deleted the feat/screen-pass branch November 26, 2026 06:02
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