Skip the pass-hazard scan of every sampled texture. #416

Merged
SkippySteve merged 2 commits from fix/replay-lookups into main 2026-11-08 00:28:20 +00:00
SkippySteve commented 2026-11-08 00:21:06 +00:00 (Migrated from github.com)

Problem

draw_hazards walks every texture the open pass has sampled, on every draw, to see whether this draw writes one of them. A dense Kokiri frame is about 1627 draws and the submit is about 12.7 ms (issue #384). The list grows through the pass, so the check is draws times textures sampled so far.

The read-only bind memo and the uniform gap landed in #392 and #397 while this was being prepared. Those stay as they are.

Change

A pass keeps sampled_targets (colour i is bit i, depth is bit 8). The bit is set when a sampled texture is first recorded, after the hazard check, so only earlier draws count. The second scan is that mask. A new pass clears it with the sampled list. The list itself stays, for the pass trace.

A draw that samples a target it also writes is still left as it is. A draw that samples a target an earlier draw wrote still takes the first loop, over this draw's own samples.

Why this is safe

The bit uses the same slot as the old loop: colour target i, or depth as bit 8. It is recorded after draw_hazards, which is when the old loop would have seen the texture on the next draw. Starting a pass clears the mask in begin_pass together with pass.sampled.

Testing

python -I -B tests/test_pass_hazard.py
python -I -B tests/test_ub_memo.py
python -I -B tests/test_ub_gap.py
python -I -B tests/test_bind_memo.py
python -I -B tests/test_vertex_bind.py
python -I -B tests/test_same_draw.py

All passed on current main plus this change. With vk_draw.cpp restored and the new test kept, test_pass_hazard.py fails because the scan of pass.sampled is still there.

No renderer rebuild, and no Kokiri fps measurement, for this change.

Scope

Left out: the AMD vkQueueSubmit stalls (#312), the movie upscale threshold (#336), and skipping a repeated vkCmdBindIndexBuffer. The exposure flicker (#371) is already on main.

Happy to rename the mask if another name fits the file better.

## Problem `draw_hazards` walks every texture the open pass has sampled, on every draw, to see whether this draw writes one of them. A dense Kokiri frame is about 1627 draws and the submit is about 12.7 ms (issue #384). The list grows through the pass, so the check is draws times textures sampled so far. The read-only bind memo and the uniform gap landed in #392 and #397 while this was being prepared. Those stay as they are. ## Change A pass keeps `sampled_targets` (colour i is bit i, depth is bit 8). The bit is set when a sampled texture is first recorded, after the hazard check, so only earlier draws count. The second scan is that mask. A new pass clears it with the sampled list. The list itself stays, for the pass trace. A draw that samples a target it also writes is still left as it is. A draw that samples a target an earlier draw wrote still takes the first loop, over this draw's own samples. ## Why this is safe The bit uses the same slot as the old loop: colour target i, or depth as bit 8. It is recorded after `draw_hazards`, which is when the old loop would have seen the texture on the next draw. Starting a pass clears the mask in `begin_pass` together with `pass.sampled`. ## Testing ``` python -I -B tests/test_pass_hazard.py python -I -B tests/test_ub_memo.py python -I -B tests/test_ub_gap.py python -I -B tests/test_bind_memo.py python -I -B tests/test_vertex_bind.py python -I -B tests/test_same_draw.py ``` All passed on current main plus this change. With `vk_draw.cpp` restored and the new test kept, `test_pass_hazard.py` fails because the scan of `pass.sampled` is still there. No renderer rebuild, and no Kokiri fps measurement, for this change. ## Scope Left out: the AMD `vkQueueSubmit` stalls (#312), the movie upscale threshold (#336), and skipping a repeated `vkCmdBindIndexBuffer`. The exposure flicker (#371) is already on main. Happy to rename the mask if another name fits the file better.
shayderrr commented 2026-11-08 00:28:16 +00:00 (Migrated from github.com)

Thanks!

Thanks!
Commenting is not possible because the repository is archived.
No description provided.