Skip to content

Commit bae2047

Browse files
committed
Enforce dest_alpha->0 in opaque dest blitter
1 parent 3db1f0c commit bae2047

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src_c/simd_blitters_avx2.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ alphablit_alpha_avx2_argb_no_surf_alpha_opaque_dst(SDL_BlitInfo *info)
201201

202202
__m256i src_alpha, temp;
203203

204+
/* The location of the destination's missing alpha channel can be masked
205+
* out by composing all the other channels' masks. */
206+
__m256i mask_out_alpha = _mm256_set1_epi32(
207+
(info->dst->Rmask | info->dst->Gmask | info->dst->Bmask));
208+
204209
/* Original 'Straight Alpha' blending equation:
205210
--------------------------------------------
206211
dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
@@ -237,14 +242,21 @@ alphablit_alpha_avx2_argb_no_surf_alpha_opaque_dst(SDL_BlitInfo *info)
237242
dstRGBA >>= 8
238243
*/
239244

240-
RUN_AVX2_BLITTER(RUN_16BIT_SHUFFLE_OUT(
241-
src_alpha = _mm256_shuffle_epi8(shuff_src, shuff_out_alpha);
242-
temp = _mm256_sub_epi16(shuff_src, shuff_dst);
243-
temp = _mm256_mullo_epi16(temp, src_alpha);
244-
shuff_dst = _mm256_slli_epi16(shuff_dst, 8);
245-
shuff_dst = _mm256_add_epi16(shuff_dst, temp);
246-
shuff_dst = _mm256_add_epi16(shuff_dst, shuff_src);
247-
shuff_dst = _mm256_srli_epi16(shuff_dst, 8);))
245+
RUN_AVX2_BLITTER(
246+
RUN_16BIT_SHUFFLE_OUT(
247+
src_alpha = _mm256_shuffle_epi8(shuff_src, shuff_out_alpha);
248+
temp = _mm256_sub_epi16(shuff_src, shuff_dst);
249+
temp = _mm256_mullo_epi16(temp, src_alpha);
250+
shuff_dst = _mm256_slli_epi16(shuff_dst, 8);
251+
shuff_dst = _mm256_add_epi16(shuff_dst, temp);
252+
shuff_dst = _mm256_add_epi16(shuff_dst, shuff_src);
253+
shuff_dst = _mm256_srli_epi16(shuff_dst, 8););
254+
255+
/* It seems like the destination pixel alpha shouldn't matter, since
256+
* it is RGBX, but it has to be zero. I suspect this is a weak spot
257+
* in the other blitting routines, that they need alpha 0 from these
258+
* surfaces. */
259+
pixels_dst = _mm256_and_si256(pixels_dst, mask_out_alpha);)
248260
}
249261
#else
250262
void

0 commit comments

Comments
 (0)