Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/check/must_check_gates.sdn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ must_check_gates |id, tier, push_blocking, mode, command, ci_job, inputs, descri
push-native-build-entry-memory-budget, push, false, tree, "sh scripts/check/check-native-build-entry-memory-budget.shs", -, -, "advisory: native-build worker heap budget probe; needs a runnable bin/simple and a real build, which a bare push host lacks"
push-rect-batch-spirv-pinned, push, true, tree, "sh scripts/check/check-rect-batch-spirv-pinned.shs", -, -, "blocking: the checked-in rect-batch SPIR-V words must be exactly what glslangValidator produces from the checked-in GLSL right now; fast (~1s), no device needed, fail-closed with its own 4-fixture selftest run before every scan"
push-blit-spirv-pinned, push, true, tree, "sh scripts/check/check-blit-spirv-pinned.shs", -, -, "blocking: the checked-in blit SPIR-V words must be exactly what glslangValidator produces from the checked-in GLSL right now; fast (~1s), no device needed, fail-closed with its own 5-fixture selftest run before every scan"
push-blur-rect-spirv-pinned, push, true, tree, "sh scripts/check/check-blur-rect-spirv-pinned.shs", -, -, "blocking: the checked-in blur-rect SPIR-V words must be exactly what glslangValidator produces from shaders/blur_rect.comp right now; fast (~1s), no device needed, fail-closed with its own 4-fixture selftest run before every scan"
push-glass-material-spirv-pinned, push, true, tree, "sh scripts/check/check-glass-material-spirv-pinned.shs", -, -, "blocking: the checked-in glass-material SPIR-V words must be exactly what glslangValidator produces from shaders/glass_material.comp right now; fast (~1s), no device needed, fail-closed with its own 4-fixture selftest run before every scan"
push-chrome-dynlib-probe, push, false, tree, "sh scripts/check/check-chrome-dynlib-probe.shs", -, -, "advisory: two-stage probe of the Chrome (CEF) render dynlib ABI; stage A needs a runnable Simple binary a fresh checkout lacks and stage B needs a pinned CEF drop most push hosts lack, so it answers ERROR - nothing was checked there rather than a fabricated pass"
compiler-stage1, bootstrap, true, receipt, "scripts/bootstrap/bootstrap-from-scratch.sh --full-bootstrap --deploy", -, -, "Stage 1 seed compiler completed"
compiler-stage2, bootstrap, true, receipt, "scripts/bootstrap/bootstrap-from-scratch.sh --full-bootstrap --deploy", -, -, "Stage 2 compiler completed"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Vulkan font atlas re-uploaded per text run; css-layout.html submits 3x per frame

Status: FIXED 2026-09-12
Gate: `scripts/check/check-web-vulkan-gpu-boundary-audit.shs`
Binary: `build/cargo-r2/release/simple` (identity `39528776 1789199850`, unchanged across every run below)

## (a) The atlas was copied to the device once per text run

Every run that inserts a glyph bumps the owner's published `atlas_owner_sequence`,
so the slot plan is `WRITE_IN_PLACE`, and that branch copied the FULL 1024x1024
atlas (4 MiB) each time -- ~15 copies, ~60 MB, on a page with one atlas. All but
the last are dead: within a flush the atlas only GROWS (cells are inserted, never
relocated -- the invariant `WRITE_IN_PLACE` already rests on), so the final state
is a superset of every intermediate one, and every dispatch that reads the atlas
is recorded into the SAME not-yet-submitted command buffer.

Fix: the typed (`u32`) lane PARKS the copy (`font_atlas_deferred_*` on the
backend) and drains it in `_flush_pending_compute`, immediately before the
submit. A park aimed at a different buffer drains the previous one first, so the
count is bounded by distinct slots written, never by runs. The byte fallback lane
is unchanged. Release paths (`_font_atlas_release_slots`, backend teardown)
DISCARD a park rather than drain it -- the buffer it names is being freed.
A failed drain poisons only that slot (owner `""`, sequence -1) and marks
`atlas-deferred-upload-failed`.

## (b) css-layout.html reported submits_per_frame=3

Two independent causes, both found with the tagged `SIMPLE_VK_ORDER_TRACE=1`
flush trace:

1. **A zero-area opaque rect.** `_draw_rect_filled_impl`'s device arm had no
`w <= 0 or h <= 0` guard (the alpha and masked arms did), so `(0 + 15) / 16`
gave 0 workgroups. `_enqueue_framebuffer_compute` rejects that with a bare 0
and no trace, and `_dispatch_framebuffer_checked` read the 0 as the measured
M4 bind-chain flake: it flushed the whole pending batch (an extra SUBMIT),
retried with the SAME invalid arguments, failed identically, and latched the
CPU fallback. Two such rects per frame. Fixed at the call site, and
generally: `_dispatch_framebuffer_checked` now rejects degenerate arguments
up front (`dispatch-reject` trace, no flush, no futile retry).

2. **One owner holding two slots.** A relocating `WRITE_FRESH` moved an owner to
a new slot while the OLD slot kept the owner's name at a stale sequence.
`_font_atlas_slot_index` returns the first match, so every later run for that
owner found the stale slot, could neither reuse nor write in place, and
eventually exhausted the table into a `FLUSH_THEN_WRITE` -- the third submit.
A successful write now disowns every other slot naming that owner.
`VULKAN_FONT_ATLAS_SLOT_MAX` 4 -> 8 (an "owner" folds point SIZE into its
identity, so css-layout presents five owners from two families); the env
measurement control accepts 1..8.

## Evidence (gate before / after, same binary)

| page | metric | before | after |
|---|---|---|---|
| overview.html | uploads_per_frame | 23 | **13** |
| overview.html | upload_ms | 43 | **19** |
| overview.html | submits_per_frame | 1 | 1 |
| overview.html | frame_digest | a15c50cd | **a15c50cd** |
| overview.html | verdict | PASS | PASS |
| css-layout.html | uploads_per_frame | 47 | **25** |
| css-layout.html | upload_ms | 57 | **32** |
| css-layout.html | submits_per_frame | **3** | **1** |
| css-layout.html | fence_waits | 3 | **1** |
| css-layout.html | frame_digest | 743c2081 | **743c2081** |
| css-layout.html | verdict | FAIL | **PASS** |

`frame_digest` identical on both pages is the pixel oracle: the op counts fell
and the rendered words did not move. `cpu_fallback_count=0` on both.

## Specs (interpreter, `simple run`)

Green: `backend_vulkan_font_atlas_slot_plan_spec` 12/12,
`backend_vulkan_font_typed_upload_spec` 4/4,
`backend_vulkan_font_quad_partition_spec` 7/7,
`backend_vulkan_drawing_spec` 44/44.

PRE-EXISTING RED, not caused by this change: `backend_vulkan_blend_cpu_parity_spec`,
`backend_vulkan_device_glass_blur_spec`, `backend_vulkan_font_spec`,
`backend_vulkan_rect_batch_one_dispatch_spec` all report `outcome=ERROR
executed=0` from an unresolved `use gpu.engine2d.engine.{Engine2D}` (E1034, a
non-`std.`-prefixed import in the SPEC file). Unrelated to these files.

## Still open

`uploads_per_frame` is ~5/frame for overview and ~7/frame for css-layout rather
than one-per-changed-owner: the frame performs several flushes (font-lane,
read_pixels, present), and each drains at most once, so the residual is
flush-count x owner-switches, not per-run. Collapsing the per-frame flush count
itself is a separate lane.
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,19 @@ three 1,048,576-pixel repacks removed, one per restore. `continuity=2`
no longer spec-only. `pack_full == 2` is still not reached: 2 resets remain (the
two cold first-sightings) plus the sub-batch partition's share of the 10 full
decisions.

## Atlas upload-once + degenerate-dispatch fix (2026-09-12, same binary 39528776/1789199850)

`SIMPLE_EXECUTION_MODE=interpreter SIMPLE_2D_BACKEND=vulkan SIMPLE_VK_READBACK=native`
`SIMPLE_VK_{IMAGE,RECT,FONT}_UPLOAD=u32`, 900x760, 2 frames, via
`scripts/check/check-web-vulkan-gpu-boundary-audit.shs`.

| page | uploads/frame | upload_ms | submits/frame | fence_waits | frame_digest | verdict |
|---|---|---|---|---|---|---|
| overview before | 23 | 43 | 1 | 1 | a15c50cd | PASS |
| overview after | 13 | 19 | 1 | 1 | a15c50cd | PASS |
| css-layout before | 47 | 57 | 3 | 3 | 743c2081 | FAIL |
| css-layout after | 25 | 32 | 1 | 1 | 743c2081 | PASS |

Digests unchanged on both pages. Detail and mechanism:
`doc/08_tracking/bug/vulkan_font_atlas_reupload_per_run_and_css_layout_submits_2026-09-12.md`.
12 changes: 12 additions & 0 deletions scripts/check/check-push-must-pass.shs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ run_manifest_push_gates() {
# backend_vulkan_blit_spirv.spl are byte-identical to what
# glslangValidator produces from it right now.
run_push_gate "$_id" "$_blocking" "$ROOT/scripts/check/check-blit-spirv-pinned.shs" || { rm -f "$_push_rows"; return 1; } ;;
'push-blur-rect-spirv-pinned:tree:sh scripts/check/check-blur-rect-spirv-pinned.shs')
# Blocking: fast (~1s), no device required, fail-closed with its
# own 4-fixture selftest run before every scan. Recompiles
# shaders/blur_rect.comp and asserts the pinned SPIR-V words in
# backend_vulkan_blur_rect_spirv.spl are byte-identical to what
# glslangValidator produces from it right now.
run_push_gate "$_id" "$_blocking" "$ROOT/scripts/check/check-blur-rect-spirv-pinned.shs" || { rm -f "$_push_rows"; return 1; } ;;
'push-glass-material-spirv-pinned:tree:sh scripts/check/check-glass-material-spirv-pinned.shs')
# Blocking: same shape as the sibling SPIR-V pin gates above,
# for shaders/glass_material.comp ->
# backend_vulkan_glass_material_spirv.spl.
run_push_gate "$_id" "$_blocking" "$ROOT/scripts/check/check-glass-material-spirv-pinned.shs" || { rm -f "$_push_rows"; return 1; } ;;
'push-chrome-dynlib-probe:tree:sh scripts/check/check-chrome-dynlib-probe.shs')
# Advisory by manifest: stage B needs a pinned CEF drop most
# push hosts lack, and stage A needs a runnable Simple binary a
Expand Down
41 changes: 41 additions & 0 deletions src/lib/gc_async_mut/gpu/engine2d/backend_vulkan.spl
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,27 @@ class VulkanBackend:
# buffer. Cleared wholesale by `_clear_pending_compute_state`, which runs at
# the end of every flush path including the failure ones.
font_atlas_slot_referenced: [bool]
# DEFERRED ATLAS UPLOAD (typed `u32` lane only).
#
# A text run that inserts glyphs bumps the owner's published sequence, so
# the slot plan is WRITE_IN_PLACE and the whole 1024x1024 atlas used to be
# copied to the device once PER RUN -- 15 copies (~60 MB) for a page that
# has exactly one atlas. Every one of those copies but the last is dead:
# the atlas only ever GROWS within a frame (cells are inserted, never
# relocated, which is the same invariant `WRITE_IN_PLACE` already rests on),
# so the final state is a superset of every intermediate one, and every
# dispatch that reads the atlas is recorded into the SAME pending command
# buffer and runs only after the flush. Parking the copy and performing it
# once, immediately before the submit, is therefore observationally
# identical and collapses the count to one upload per slot per flush.
#
# Only one park is held at a time: a write aimed at a DIFFERENT buffer
# drains the parked one first, so the count is bounded by the number of
# distinct slots written, never by the number of runs. 0 = nothing parked.
font_atlas_deferred_buffer: i64
font_atlas_deferred_slot: i64
font_atlas_deferred_pixels: [u32]
font_atlas_deferred_uploads: i64
# Index into the tables above of the slot `d_font_atlas` currently aliases.
# -1 = none bound yet.
font_atlas_active_slot: i64 = -1
Expand Down Expand Up @@ -571,6 +592,10 @@ class VulkanBackend:
font_atlas_slot_owners: [],
font_atlas_slot_sequences: [],
font_atlas_slot_referenced: [],
font_atlas_deferred_buffer: 0,
font_atlas_deferred_slot: -1,
font_atlas_deferred_pixels: [],
font_atlas_deferred_uploads: 0,
font_atlas_active_slot: -1,
font_atlas_slot_hits: 0,
font_atlas_slot_inplace_writes: 0,
Expand Down Expand Up @@ -1092,6 +1117,13 @@ impl RenderBackend for VulkanBackend:
for slot_handle in self.font_atlas_slot_handles:
if slot_handle != 0:
vulkan_sffi_free_buffer(slot_handle)
# A parked upload names a buffer that is about to be freed. Discarding
# it is the only correct action -- draining would copy into a doomed
# buffer, and keeping it would leave a dangling handle for the next
# flush to write through.
self.font_atlas_deferred_buffer = 0
self.font_atlas_deferred_slot = -1
self.font_atlas_deferred_pixels = []
val atlas_was_slotted = self.font_atlas_slot_handles.len() > 0
self.font_atlas_slot_handles = []
self.font_atlas_slot_owners = []
Expand Down Expand Up @@ -1249,6 +1281,15 @@ impl RenderBackend for VulkanBackend:
val masked_pixels: [u32] = [color; w * h]
self.draw_image(x, y, w, h, masked_pixels)
return
if w <= 0 or h <= 0:
# A zero-area opaque rect paints nothing. The alpha and masked arms
# above already return here; this arm did not, and `(0 + 15) / 16`
# is 0 workgroups, which the enqueue rejects as invalid. The reject
# was then read as a transient bind-chain failure, costing a full
# flush (an extra SUBMIT), a futile retry and a CPU-fallback latch.
# Measured on css-layout.html: 2 such rects per frame, which is the
# entire `submits_per_frame=3` overshoot.
return
val pc = _pack_rect_pc(x, y, w, h, color, self.w, self.h, self.clip_x, self.clip_y, self.clip_w, self.clip_h, self.clip_enabled)
val gx = (_i64(w) + 15) / 16
val gy = (_i64(h) + 15) / 16
Expand Down
55 changes: 51 additions & 4 deletions src/lib/gc_async_mut/gpu/engine2d/backend_vulkan_font.spl
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,18 @@ impl VulkanBackend:
# the selfcheck the pixels go wrong, which is the point.
slot_plan = VK_FONT_SLOT_REUSE_NO_WRITE
slot_index = 0
if vulkan_order_trace_enabled():
# Permanent, zero-cost-when-off evidence for the atlas upload-once
# invariant. The decision note below shares a fixed 4000-char budget
# with the continuity notes and truncates after ~30 runs, which is
# exactly the population an upload census has to see; this line does
# not, and is armed by the same flag the GPU-boundary audit already
# sets, so a re-upload regression is visible in the gate's own log.
vulkan_order_trace(
"font-slot owner={atlas_owner} slot={slot_index} slot_seq={slot_sequence}" +
" host_seq_before={host_sequence_before} batch_seq={batch.atlas_owner_sequence}" +
" referenced={slot_referenced} continuity={continuity} spare={spare_slot}" +
" plan={slot_plan} dirty={batch.dirty_rects.len()}")
if vulkan_font_selfcheck_enabled():
vulkan_font_decision_note(
"owner={atlas_owner} slot={slot_index} slot_seq={slot_sequence}" +
Expand Down Expand Up @@ -1431,10 +1443,30 @@ impl VulkanBackend:
var mirror_ready = false
var packed_on_host = false
if typed_upload:
val _t_up_typed = vulkan_timing_now_us()
atlas_uploaded = vulkan_sffi_copy_to_buffer_u32(
self.d_font_atlas, batch.atlas_pixels, 0)
vulkan_timing_add(VK_T_FONT_ATLAS_UPLOAD, _t_up_typed)
# UPLOAD ONCE PER SLOT PER FLUSH, not once per text run.
#
# Every run that inserts a glyph bumps the owner's sequence and
# so lands here, and this copy used to move the FULL atlas (4 MB
# at 1024x1024) each time -- 15 copies, ~60 MB, for a page with
# one atlas. All but the last are dead: within a flush the atlas
# only grows (`WRITE_IN_PLACE` already rests on cells being
# inserted, never relocated), so the final state is a superset
# of every intermediate one, and every dispatch that reads the
# atlas is recorded into the same not-yet-submitted command
# buffer. Parking the copy and draining it immediately before
# the submit is therefore observationally identical.
#
# A park aimed at a DIFFERENT buffer than the one already parked
# drains that one first, so the upload count is bounded by the
# number of distinct slots written in the frame -- never by the
# number of runs.
if (self.font_atlas_deferred_buffer != 0 and
self.font_atlas_deferred_buffer != self.d_font_atlas):
self.font_atlas_drain_deferred_upload()
self.font_atlas_deferred_buffer = self.d_font_atlas
self.font_atlas_deferred_slot = target_slot
self.font_atlas_deferred_pixels = batch.atlas_pixels
atlas_uploaded = self.d_font_atlas != 0
# The device now holds exactly this atlas, so the "mirror" (the
# atlas words themselves) is truth by construction.
mirror_ready = atlas_uploaded
Expand Down Expand Up @@ -1514,6 +1546,21 @@ impl VulkanBackend:
self.font_atlas_slot_owners[target_slot] = ""
self.font_atlas_slot_sequences[target_slot] = -1
return _vulkan_font_evidence(pipeline, "failed", "atlas-upload-failed", self.d_font_atlas, 0, 0, 0, batch.quads.len(), 0, false, false, framebuffer, 0, 0, 0, false)
# ONE SLOT PER OWNER. A relocating (`WRITE_FRESH`) run takes a
# different slot than the one this owner already held, and the old
# slot used to keep the owner's NAME while its bytes stayed at the
# stale sequence. `_font_atlas_slot_index` returns the FIRST match,
# so every later run for that owner found the stale slot, could not
# reuse or write in place, and eventually exhausted the table into a
# `FLUSH_THEN_WRITE` -- an extra submit per frame on css-layout.html
# even with eight slots. Disowning the stale copies keeps the lookup
# single-valued and returns their buffers to the spare pool.
var stale: i64 = 0
while stale < self.font_atlas_slot_owners.len().to_i64():
if stale != target_slot and self.font_atlas_slot_owners[stale] == atlas_owner:
self.font_atlas_slot_owners[stale] = ""
self.font_atlas_slot_sequences[stale] = -1
stale = stale + 1
# The slot now holds exactly this owner's atlas at this sequence, so
# the next run for this owner can reuse it with no write at all.
self.font_atlas_slot_owners[target_slot] = atlas_owner
Expand Down
Loading
Loading