Fix AVX2 YV24 source alpha packing#491
Open
msg7086 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix corrupted source-alpha output in the AVX2
YV24 -> BGR32conversion path (convert_yv24_to_rgb_avx2<4, true>).How the issue was found
The issue was found by an external unit test using fixed Y, U, V, and alpha anchors. The test compares the output against an independent fixed-point YUV-to-RGB reference.
SSE2 and SSSE3 preserved source alpha correctly. The AVX2 path produced zero or incorrectly ordered alpha bytes. For example, one output alpha value was expected to be
64but was written as0.Root cause
The AVX2 RGB result vectors are lane-local after the packing operations. Their effective byte order for alpha interleaving is:
The old code expanded each 8-bit alpha value to a 16-bit value before calling
_mm256_unpacklo_epi8:_mm256_unpacklo_epi8expects packed 8-bit alpha bytes. It therefore consumed the inserted00bytes as alpha values, and the subsequent lane permutation also did not match the packed RGB lane order.The fix keeps alpha packed as bytes and arranges its dwords to match the RGB vectors:
Only the low eight bytes of each 128-bit alpha lane are consumed by
_mm256_unpacklo_epi8, so the duplicated upper dwords inalpha_hiare not observed.Testing
The regression was discovered and confirmed in the external AviSynthPlus unit-test framework before transferring this minimal fix. No performance test was performed. Only correctness of the fix was tested.