Skip to content

Commit 2d82a34

Browse files
authored
Merge pull request #2019 from Starbuck5/avx2-alpha-blitter
AVX2 alpha blitters
2 parents 3cbcf7b + a955b88 commit 2d82a34

File tree

3 files changed

+396
-12
lines changed

3 files changed

+396
-12
lines changed

src_c/alphablit.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,43 @@ SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
215215
src->format->Rmask == dst->format->Rmask &&
216216
src->format->Gmask == dst->format->Gmask &&
217217
src->format->Bmask == dst->format->Bmask) {
218-
/* If our source and destination are the same ARGB 32bit
219-
format we can use SSE2/NEON to speed up the blend */
218+
/* If our source and destination are the same ARGB
219+
32bit format we can use SSE2/NEON/AVX2 to speed
220+
up the blend */
221+
if (pg_has_avx2() && (src != dst)) {
222+
if (info.src_blanket_alpha != 255) {
223+
alphablit_alpha_avx2_argb_surf_alpha(
224+
&info);
225+
}
226+
else if (SDL_ISPIXELFORMAT_ALPHA(
227+
dst->format->format) &&
228+
info.dst_blend !=
229+
SDL_BLENDMODE_NONE) {
230+
alphablit_alpha_avx2_argb_no_surf_alpha(
231+
&info);
232+
}
233+
else {
234+
alphablit_alpha_avx2_argb_no_surf_alpha_opaque_dst(
235+
&info);
236+
}
237+
break;
238+
}
220239
#if PG_ENABLE_SSE_NEON
221240
if ((pg_HasSSE_NEON()) && (src != dst)) {
222241
if (info.src_blanket_alpha != 255) {
223242
alphablit_alpha_sse2_argb_surf_alpha(
224243
&info);
225244
}
245+
else if (SDL_ISPIXELFORMAT_ALPHA(
246+
dst->format->format) &&
247+
info.dst_blend !=
248+
SDL_BLENDMODE_NONE) {
249+
alphablit_alpha_sse2_argb_no_surf_alpha(
250+
&info);
251+
}
226252
else {
227-
if (SDL_ISPIXELFORMAT_ALPHA(
228-
dst->format->format) &&
229-
info.dst_blend != SDL_BLENDMODE_NONE) {
230-
alphablit_alpha_sse2_argb_no_surf_alpha(
231-
&info);
232-
}
233-
else {
234-
alphablit_alpha_sse2_argb_no_surf_alpha_opaque_dst(
235-
&info);
236-
}
253+
alphablit_alpha_sse2_argb_no_surf_alpha_opaque_dst(
254+
&info);
237255
}
238256
break;
239257
}

src_c/simd_blitters.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ premul_surf_color_by_alpha_sse2(SDL_Surface *src, SDL_Surface *dst);
6363
int
6464
pg_has_avx2();
6565
void
66+
alphablit_alpha_avx2_argb_no_surf_alpha_opaque_dst(SDL_BlitInfo *info);
67+
void
68+
alphablit_alpha_avx2_argb_no_surf_alpha(SDL_BlitInfo *info);
69+
void
70+
alphablit_alpha_avx2_argb_surf_alpha(SDL_BlitInfo *info);
71+
void
6672
blit_blend_rgba_mul_avx2(SDL_BlitInfo *info);
6773
void
6874
blit_blend_rgb_mul_avx2(SDL_BlitInfo *info);

0 commit comments

Comments
 (0)