1616#include < evr.h>
1717#include < wrl/client.h>
1818#include < intrin.h>
19- #include < immintrin.h>
19+ #if defined(_M_IX86) || defined(_M_X64)
20+ #include < immintrin.h>
21+ #define NVP_HAS_AVX2_INTRINSICS 1
22+ #else
23+ #define NVP_HAS_AVX2_INTRINSICS 0
24+ #endif
2025
2126using Microsoft::WRL ::ComPtr;
2227using namespace VideoPlayerUtils ;
@@ -49,22 +54,26 @@ VideoPlayerInstance::~VideoPlayerInstance() {
4954}
5055
5156// ---------------------------------------------------------------------------
52- // SIMD alpha fix (MFVideoFormat_RGB32 leaves the alpha byte undefined).
53- // Runtime-dispatched: AVX2 when available, otherwise scalar.
57+ // Alpha fix (MFVideoFormat_RGB32 leaves the alpha byte undefined).
58+ // On x86/x64: runtime-dispatched AVX2 with scalar fallback.
59+ // On ARM64 (and anywhere AVX2 intrinsics aren't available): scalar only.
5460// ---------------------------------------------------------------------------
61+ #if NVP_HAS_AVX2_INTRINSICS
5562static bool DetectAvx2 () {
5663 int info[4 ] = {};
5764 __cpuid (info, 0 );
5865 if (info[0 ] < 7 ) return false ;
5966 __cpuidex (info, 7 , 0 );
6067 return (info[1 ] & (1 << 5 )) != 0 ; // EBX bit 5 = AVX2
6168}
69+ #endif
6270
6371static void ForceAlphaOpaque (BYTE * data, size_t pixelCount) {
64- static const bool kHasAvx2 = DetectAvx2 ();
6572 uint32_t * px = reinterpret_cast <uint32_t *>(data);
66-
6773 size_t i = 0 ;
74+
75+ #if NVP_HAS_AVX2_INTRINSICS
76+ static const bool kHasAvx2 = DetectAvx2 ();
6877 if (kHasAvx2 ) {
6978 const __m256i mask = _mm256_set1_epi32 (static_cast <int >(0xFF000000u ));
7079 for (; i + 8 <= pixelCount; i += 8 ) {
@@ -73,6 +82,8 @@ static void ForceAlphaOpaque(BYTE* data, size_t pixelCount) {
7382 _mm256_storeu_si256 (reinterpret_cast <__m256i*>(px + i), v);
7483 }
7584 }
85+ #endif
86+
7687 for (; i < pixelCount; ++i) px[i] |= 0xFF000000u ;
7788}
7889
0 commit comments