Skip to content

A program's own quoted draws and canvas: sprites by its shaders, meshes by its shader pairs - #1096

Merged
paul-hammant merged 3 commits into
mainfrom
feat/screen-draws
Nov 26, 2026
Merged

paul-hammant merged 3 commits into
mainfrom
feat/screen-draws

Conversation

@paul-hammant

@paul-hammant paul-hammant commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #1094 (a program's screen pass). Two commits:

  1. A program can draw its own quoted pixel shader many times a frame, each draw in a rectangle of its own with its own inputs: sprites drawn by a shader.
  2. A program can draw meshes of its own with its own quoted vertex and pixel shader pairs, depth-tested, into a canvas of its own, shown in the frame as its shaders wrote it.

1. Quoted draws

  • engine_screen_draw(e, s, spirv, x, y, w, h) queues a draw with the shader's inputs as they are when it is queued; the program sets them again and queues again. Draws are drawn after the screen pass, in order, blended over what is there as premultiplied colours are (destination alpha kept), every frame until engine_screen_draws_clear.
  • engine_set_screen_clip(e, x, y, w, h) cuts the draws queued after it to a rectangle (a widget's canvas); a draw may run off it or off the frame.
  • Vulkan: one pass per shader, made from its ae3d.quotegen SPIR-V the first time it is queued and kept, its descriptor sets grown (doubled, device idle) as more draws are queued; vkquote.prepare_with writes each draw's block as it was queued; vkpipes.BLEND_PREMULTIPLIED. OpenGL: the tree's GLSL compiled once per shape, scissor for the clip, the renderer's blend and depth state restored after.
  • examples/screen_draws.ae: a ruled backdrop, a fill draw per line, and 40 shaded discs cut to a rectangle. docs/screen-pass.md has a section on it; changes/2026-11-26-screen-draws.md.

What drove it: a molecule viewer draws its ball shader once per atom, over its backdrop. Held to reference frames drawn by another renderer, every atom is drawn where and as they have it (the same draw list, line for line, for four molecules turned and on each backdrop), and no pixel is more than 2/255 from them, on Vulkan and on OpenGL.

The raymarchers' counts in docs/screen-pass.md and the screen pass's change note are re-measured with the reference values rounded to the 8 bits a frame shows: 34 and 36 of 360,000 (were 44, 46), 111 and 87 of 307,200 (163, 143).

2. A program's canvas

  • engine_canvas_new(e, w, h) makes a canvas: a colour and a depth image of the program's. engine_mesh_new(e, mesh) puts an ae3d.core mesh of the program's on the GPU. engine_canvas_draw(e, canvas, vs, ps, spirv, mesh, cull, textures, count) queues a mesh drawn by the pair, with both shaders' inputs as they are when it is queued, depth-tested and written. Draws stay queued until engine_canvas_begin(e, canvas, rgba) clears them and sets the clear colour. engine_canvas_show(e, canvas, x, y, w, h) shows the canvas through the view blit, each frame, as engine_view_blit does, so what the shaders wrote is what is shown.
  • engine_canvas_lens(e, m) makes an OpenGL-shaped projection the running renderer's: unchanged on OpenGL, clip-corrected on Vulkan as vkdesc.clip_correct does ae3d's own camera's.
  • Vulkan:
    • ae3d.vkcanvas holds the canvas's images, render pass and framebuffer. It is a module of its own, not part of vktargets, because a view swaps every variable of vktargets in and out.
    • The canvases are drawn at the start of the frame's commands.
    • vkquote.program_pair_new makes a pass from a program's SPIR-V. The pass borrows its shaders, may be culled or not, and takes a vertex shader with no input too.
    • vkpipes treats the canvas pass as single-sample with depth.
  • OpenGL: an offscreen view target with depth; one program per pair shape, compiled once and kept.
  • ae3d.quotegen.add_pair writes a pair's SPIR-V, and gpu.pair_hash is what that SPIR-V is checked against. gpu.set_m4 sets a capture from a shaderlib mat4. quotegen now makes the folder of the module it writes, and reports the emitter's error instead of handing glslang an empty shader.
  • examples/canvas.ae draws a turning globe into a 480 x 480 canvas. docs/canvas.md; changes/2026-11-26-program-canvas.md.

What drove it: a flight over a land draws its sky, and its land (a grid its vertex shader raises into hills), into a canvas. Held to reference frames drawn by another renderer, at three places on its way no more than 71 of 307,200 pixels are more than 2/255 from them, on Vulkan and on OpenGL.

Checked before this PR

  • Mac (M6, MoltenVK / OpenGL 4.1): canvas gives the same picture on Vulkan and OpenGL to 1/255 at every pixel of 576,000; screen_pass gives the same picture on Vulkan and OpenGL, every pixel of 576,000, and screen_draws all but one pixel, 1/255 apart; the Vulkan validation layer reports nothing for any of the three (scripts/validate.sh), nor for the flight program.
  • ae-x64 (Ubuntu 22.04, gcc): AE3D_CI_TIER=apps AE3D_CI_SHARD=0/2 ./ci.sh, every example built with warnings as errors (canvas included), everything passed; the runs were skipped there for want of a display.
  • Not run: the examples on Linux with a display (this PR's CI does, under Xvfb and lavapipe), Windows.

🤖 Generated with Claude Code

@paul-hammant paul-hammant changed the title A program's own quoted draws: its shaders as sprites, many a frame A program's own quoted draws and canvas: sprites by its shaders, meshes by its shader pairs Nov 26, 2026
paul-hammant and others added 2 commits November 26, 2026 12:57
engine_screen_draw queues a draw of a program's quoted pixel shader in a
rectangle of the frame, with the shader's inputs as they are when it is
queued; the draws are drawn over every frame after the screen pass, in
their order, blended over what is there as premultiplied colours are,
until engine_screen_draws_clear. engine_set_screen_clip cuts those queued
after it to a rectangle. A shader's pass is made the first time it is
queued and kept: on Vulkan from its ae3d.quotegen SPIR-V, its sets grown
as more draws are queued (vkquote.prepare_with takes each draw's block as
it was queued; vkpipes.BLEND_PREMULTIPLIED); on OpenGL its GLSL compiled.

examples/screen_draws.ae: a ruled backdrop of fill draws and balls cut to
a rectangle, the same on Vulkan and OpenGL, every pixel. The raymarchers'
counts in docs/screen-pass.md and the screen pass's change note
are re-measured with the reference values rounded to the 8 bits a frame
shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
engine_canvas_new makes a canvas, a picture with depth of the program's,
that its meshes (engine_mesh_new) are drawn into with its own quoted
vertex and pixel shader pairs (engine_canvas_draw), depth-tested, each
frame before the frame's own passes; engine_canvas_show shows it in a
rectangle of the frame as its shaders wrote it, through the view blit. A
draw takes both shaders' inputs as they are when it is queued; draws stay
queued till engine_canvas_begin. engine_canvas_lens makes an
OpenGL-shaped projection the running renderer's, as ae3d's own camera's
is clip-corrected on Vulkan.

Vulkan: ae3d.vkcanvas (a colour and a depth image, a render pass of its
own, a framebuffer; not in vktargets, whose variables a view swaps),
vkquote.program_pair_new (a pair from a program's words, borrowed,
depth-tested, culled or not), vkframe's canvas draws (one pass a pair,
grown as more of its draws are queued; prepare_with takes the vertex
shader's block too). OpenGL: an offscreen view target with depth, a
program a pair's shape. ae3d.quotegen.add_pair writes a pair's SPIR-V,
gpu.pair_hash is what it is checked by, gpu.set_m4 sets a capture from a
shaderlib mat4; quotegen makes the folder of the module it writes.

examples/canvas.ae: a turning globe in a canvas, the same on Vulkan and
OpenGL to 1/255 at every pixel, nothing from the validation layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drawn whole, its frame is 14 million triangles, seconds a frame on
llvmpipe, and the run passed CI's 300 s limit on Linux (main too). As
bench_black_hole does: probe a frame drawn whole first, by the GPU's own
scene-pass time (a frame's call returns before the GPU is done), and skip
past 500 ms; the frame count from AE3D_BENCH_FRAMES. On ae-x64's llvmpipe
it now skips in 30 s; on an M6 it measures as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant
paul-hammant merged commit 57c3c34 into main Nov 26, 2026
10 checks passed
@paul-hammant
paul-hammant deleted the feat/screen-draws branch November 26, 2026 18:48
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