Skip to content

fix(decoder): clear the sync-validation hazards in the copy path - #63

Open
trmosala wants to merge 1 commit into
hgaiser:mainfrom
trmosala:fix/decoder-copy-barrier-scopes
Open

trmosala wants to merge 1 commit into
hgaiser:mainfrom
trmosala:fix/decoder-copy-barrier-scopes

Conversation

@trmosala

Copy link
Copy Markdown
Contributor

With the validation layer's synchronization checks on, decoding any stream that takes the copying path reports WRITE_AFTER_WRITE hazards between vkCmdDecodeVideoKHR and the copy's layout transition. I mentioned these in #61; this is the cause and a fix.

The copy on the transfer queue is ordered against the decode queue with timeline semaphores whose stage mask is COPY. Its barriers use NONE as the source stage of the transitions into the transfer layouts, and as the destination stage of the transition back. That puts the transitions outside the scope the semaphores cover, which is what the layer says:

vkCmdPipelineBarrier2KHR (...) performs image layout transition on the VkImage ..., which was
previously written by vkCmdDecodeVideoKHR (... submitted on VkQueue ...).
The current synchronization allows VK_ACCESS_2_TRANSFER_READ_BIT|VK_ACCESS_2_TRANSFER_WRITE_BIT
accesses at VK_PIPELINE_STAGE_2_COPY_BIT, but layout transition does not synchronize with these accesses.

Using COPY for those three stage masks chains each transition to the wait before it and the signal after it.

Results (RTX 4080 SUPER, NVIDIA 620.70.06, validation layer 1.4.363 with core, sync and thread-safety checks)

cargo test --test decode_streams --test sample_planes -- --ignored with PIXELFORGE_VALIDATION=1:

tests sync hazards other findings
main (v0.13.0) 36 pass 11 (the layer's per-message cap) 0
this branch 36 pass 0 0

Output stays byte-identical to ffmpeg and dav1d in those tests. I have only run this on NVIDIA, where I never saw wrong pixels from it, so I can't say whether it shows up as corruption on drivers where the transition does real work.

🤖 Created and tested with Claude Fable 5.2 in Claude Code.

The reorder copy runs on the transfer queue and is ordered against the
decode queue with timeline semaphores whose stage mask is COPY. Its
barriers used NONE as the source stage of the transitions into the
transfer layouts and as the destination stage of the transition back,
so the transitions were outside the scope those semaphores cover. The
validation layer reports that as a WRITE_AFTER_WRITE hazard against
vkCmdDecodeVideoKHR.

Use COPY for those stages, so each transition is chained to the wait
before it and the signal after it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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