renderer: finalize bindings after every range-changing operation #532
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!532
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/532/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@CheesyPoofs346 on GitHub · 2026-09-09 07:20 UTC · original
CheesyPoofs346:renderer-finalize-bindings→main· +162 −15 · 6 files · 1 commits · closed without mergingProblem. A binding captured during draw preparation can be left pointing at a buffer that a later operation in the same draw retired.
NativeStorageBuffercaptures aVkBufferhandle, an offset and a packed byte adjustment; any laterObtainBuffercan reachCreateBuffer, which replaces the buffers covering a range with one wider buffer and retires the originals. Retirement is deferred past GPU completion, so the captured handle stays usable but stops being current: a later upload lands in the replacement, and a write through the stale alias lands in storage nothing else reads.RebindBuffers(pixel)can retire whatRebindBuffers(vertex)captured, andRebindImagesreachesCreateBufferthroughResolveTexture -> FindImage -> InitializeImage -> ObtainBufferForImage, so it can retire buffers both stages captured. Theshader_dataupload carries the packed memory offsets and ran before any of the image work, so the offsets and the handles could disagree.Change. Split obtaining from publishing. Obtaining keeps its position and all of its side effects — synchronize, upload, dirty-state change, LRU touch — unchanged and unrepeated, and records how each binding was served.
PublishBuffersthen re-resolves every cache-backed binding from its guest range (aBufferIdis exactly what retirement invalidates) through a new non-allocatingBufferCache::FindPublishedOwner, and rewrites the descriptor, the packed offset and theshader_data/flattened_srtuploads from one settled snapshot.FinalizeBindingsruns three passes over the whole stage span — rebind buffers, rebind images, publish — so no stage is finalized against a state a later stage changes; both the graphics and compute paths call it, so rebinding without publishing is not expressible. Stream-backed bindings are republished as issued:ObtainBuffer's stream fast path returns a ring allocation holding a private copy that no guest range owns, so re-resolving one by address would discard it. Apublishedflag is cleared by anything that can retire a buffer and asserted inCommitBindings.Effect. No measured performance change; performance was not measured for this and no improvement is claimed. Publication adds a page-table lookup per cache-backed binding and moves two uploads later in the same draw. This closes a silent-corruption path: bindings that read bytes that were never uploaded to the buffer they point at, and writes that land in a retired buffer.
Verification. Builds clean on this base. The equivalent change in a downstream tree is covered by a device-backed regression that proves the defect by GPU readback — the captured handle reads the pre-update byte while the live owner reads the updated one, with a control check first so the stale result cannot be attributed to missing upload tracking — and additionally checks that a stream-backed binding keeps its allocation, offset and contents, that publication fails loudly rather than allocating when a range has no owner, and that rebinding clears publication. That tree also ran two full GTA V city drives with the change, exit code 0, no errors and no publication failures; the driver reported no visual problems.
Limitations. Marked draft for these:
ObtainBufferduring test setup, unresolved, so this PR carries no automated regression. The fix itself is a re-implementation against this tree's structure, not the downstream patch.ObtainBufferin the downstream test), writable aliases (is_writtenbindings), andCommitBindingsitself — thepublishedassertion is verified by reading, not by running.ShaderRecompilerComputeTestsover the SDL-window approach the downstream harness uses, if a regression is added here.References
No external specification. Correctness argument only:
NativeStorageBuffercapturesbuffer->Handle()intoprepared.buffers, andCreateBufferretires the buffers it replaces whileBindGraphicsResourcescontinues to rebind further stages and images afterwards.@CheesyPoofs346 on GitHub · 2026-09-10 04:11 UTC · original
Do not merge — this introduces visible geometry corruption.
A/B on the same scene and save, two builds differing only by this change: with it, large parts of interior geometry explode into flat dark shards (ceilings, walls, whole surfaces) while characters and most props render correctly; without it the same scene is clean. The corruption is selective, which points at one of the non-uniform paths in publication — the per-draw dedup hit path or formatted/texel buffers — rather than the offset arithmetic being wrong for every binding.
That also corrects the Effect section above: I wrote that performance was not measured, which was true, but I did not state that behaviour was unverified in a real scene. It is now verified to be wrong.
Investigating; will update or close.
Pull request closed