Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISA_SIMD illegal instructions crashes on windows x64 #1381

Closed
crazyhappygame opened this issue Oct 7, 2023 · 24 comments
Closed

ISA_SIMD illegal instructions crashes on windows x64 #1381

crazyhappygame opened this issue Oct 7, 2023 · 24 comments
Labels
enhancement New feature or request simd
Milestone

Comments

@crazyhappygame
Copy link
Contributor

crazyhappygame commented Oct 7, 2023

  • axmol version: v2.0.0/1.0.0
  • devices test on: win10
  • developing environments
    • NDK version: r23c
    • Xcode version: 14.2
    • Visual Studio:
      • VS version: 2022 (17.7.4)
      • MSVC version: 1929, 1934, 19.35, 19.36, 19.37
      • Windows SDK version: 10.0.22621.0
    • cmake version: 3.25.2
      Steps to Reproduce:
  1. compile and run cpp-tests
  2. Press "Start Auto Test"
  3. Application crashes on second test "Texture2d" Screenshot from debugger
    image

Is v2.0.0 ready for production or it is better to stay with v1.0.0

@rh101
Copy link
Contributor

rh101 commented Oct 8, 2023

  • axmol version: v2.0.0

Is that based on the v2.0.0 tag?

If you navigate to the test that caused the crash manually (don't use auto-test), does it still crash? Exactly which test causes the crash?

I couldn't reproduce this issue with the latest dev branch snapshot, so perhaps it's something that was already fixed.

@crazyhappygame
Copy link
Contributor Author

Yes. I used V2.0.0 tag
Yes. It still crashes manually.

I checked latest version e9f0939 and I still have the same crash

Steps:

  1. Checkout latest version
$ git checkout dev
$ git pull
$ git log | head
...
e9f093916e6aaf0ac6810c28bf11b7b084745e59
...
  1. start build.ps1 without any parameters
build1k: PowerShell 5.1.19041.3031 on Microsoft Windows 10.0.19045.0
build1k:
Name                           Value
----                           -----
dll                            False
xt                             cmake
d                              G:\dev\axmol
sdk
p
xc                             {}
cc
prefix                         G:\dev\axmol\tools\external
xb                             {--target, HelloCpp, --config, Debug}
a                              x64



build1k: proj_dir=G:\dev\axmol, prefix=G:\dev\axmol\tools\external
build1k: Using glslcc: G:\dev\axmol\tools\external\glslcc\glslcc.exe, version: 1.9.3
build1k: Using cmake: C:\Program Files\CMake\bin\cmake.exe, version: 3.27.7
build1k: Using nuget: G:\dev\axmol\tools\external\nuget\nuget.exe, version: 5.5.1
build1k: Building target win32 on windows with toolchain msvc ...
build1k: CONFIG_ALL_OPTIONS=-A x64, Count=2
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.37.32824.0
-- The CXX compiler identification is MSVC 19.37.32824.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- GLSLCC_OUT_DIR=G:/dev/axmol/build_x64/runtime/axslc
-- GLSLCC_FIND_PROG_ROOT=G:/dev/axmol/tools/external/glslcc
-- GLSLCC_FRAG_SOURCE_FILE_EXTENSIONS=.frag;.fsh
-- GLSLCC_VERT_SOURCE_FILE_EXTENSIONS=.vert;.vsh
-- CMAKE_HOST_SYSTEM_VERSION: 10.0.19045
-- CMAKE_SYSTEM_VERSION: 10.0.19045CMake Warning at cmake/Modules/AXConfigDefine.cmake:48 (message):

  Forcing set CMAKE_C_STANDARD to 99 when winsdk < 10.0.22000.0
Call Stack (most recent call first):
-- CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION: 10.0.19041.0
  cmake/Modules/AXBuildSet.cmake:47 (include)
  CMakeLists.txt:46 (include)


-- CMAKE_C_STANDARD=99
-- Building axmol with c++20
-- Using Windows MSVC generate axmol project, MSVC_VERSION:1937
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe
-- The ASM_NASM compiler identification is NASM
-- Found assembler: C:/Users/Mariusz/AppData/Local/bin/NASM/nasm.exe
-- CMAKE_HOST_SYSTEM_NAME:Windows
-- CMAKE_SYSTEM_NAME:Windows
-- CMAKE_GENERATOR_PLATFORM:x64
-- CMAKE_SYSTEM_PROCESSOR:AMD64
-- CMAKE_CXX_COMPILER_ID:MSVC
-- FUZZ_MSVC=TRUE, FULL_CLANG=
-- PROJECT_NAME:axmol
-- PROJECT_SOURCE_DIR:G:/dev/axmol
-- _AX_ROOT:G:/dev/axmol
-- CMAKE_MODULE_PATH:G:/dev/axmol/cmake/Modules/
-- PROJECT_BINARY_DIR:G:/dev/axmol/build_x64
-- ENGINE_BINARY_PATH:G:/dev/axmol/build_x64/engine
-- ARCH_ALIAS:x64
CMake Warning (dev) at core/CMakeLists.txt:87 (message):
  AX_USE_GL=ON, AX_USE_METAL=OFF, AX_GLES_PROFILE=300
This warning is for project developers.  Use -Wno-dev to suppress it.

-- AX_ENABLE_VLC_MEDIA=OFF
-- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.36.1.windows.1")
,,,,
  1. Open build_x64\axmol.sln
  2. Run in debugger Cpp-test
  3. Press Press "Start Auto Test" or press "Texture2d" (second test on the list) - crash

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

I can't reproduece this issue

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

compiler bug?, clean and rebuild may solve your problem

@crazyhappygame
Copy link
Contributor Author

I clean/rebuild multiplie times. It works fine for V1.0.0 it fails on V2.0.0 and latest.

"Illegal instructions" means that compiled code is not compatible with my CPU ...

It looks like my CPU (Intel(R) Xeon(R) CPU X5670 @ 2.93GHz ) does not support vmovss

		construct_block_size_descriptor_2d(x_texels, y_texels, can_omit_modes, mode_cutoff, bsd);
00007FF732D79AD7  mov         rax,qword ptr [bsd]  
00007FF732D79ADC  mov         qword ptr [rsp+20h],rax  
00007FF732D79AE1  vmovss      xmm3,dword ptr [mode_cutoff]  

image

If that works for V1.0.0 and does not for V2.0.0 my guess would be that thirdparty\astcenc latest changes does not support older CPUs

@rh101
Copy link
Contributor

rh101 commented Oct 8, 2023

If that works for V1.0.0 and does not for V2.0.0 my guess would be that thirdparty\astcenc latest changes does not support older CPUs

Unless I'm mistaken, both V2.0.0 and V1.0.0 are using the exact same version of astcenc (Version: 4.5.0). Perhaps it's a configuration issue?

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

Yes, the version of astcenc is same

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

My cpu works:
image

@rh101
Copy link
Contributor

rh101 commented Oct 8, 2023

Could something have changed in Axmol 2.0.0 with the cmake configuration to accidentally detect incorrect support for those instructions?

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

@crazyhappygame please check your cmake output:
image

@rh101
Copy link
Contributor

rh101 commented Oct 8, 2023

AVX instruction sets are not supported on the Intel Xeon CPU X5670, so if it's somehow detecting that they are, then that would be the issue.

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

@crazyhappygame
Copy link
Contributor Author

Yes .I have:

-- Found ZLIB: G:/dev/axmol/thirdparty/zlib/prebuilt/win32/x64/zlib.lib (found version "1.3")
-- Found PNG: png (found version "1.6.40")
CMake Warning (dev) at thirdparty/astcenc/CMakeLists.txt:89 (message):
  ASTC_ISA_SIMD=avx2
This warning is for project developers.  Use -Wno-dev to suppress it.

@rh101
Copy link
Contributor

rh101 commented Oct 8, 2023

The problem is likely to be in this file: https://github.com/axmolengine/axmol/commits/dev/thirdparty/CMakeLists.txt

A lot of changes were made to it between Axmol v1.0.0 to v2.0.0, and it's where the instruction set configuration seems to be set up.

The correct output for the Xeon X5670 should be:
ASTC_ISA_SIMD=sse4.2

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

Yes .I have:

-- Found ZLIB: G:/dev/axmol/thirdparty/zlib/prebuilt/win32/x64/zlib.lib (found version "1.3")
-- Found PNG: png (found version "1.6.40")
CMake Warning (dev) at thirdparty/astcenc/CMakeLists.txt:89 (message):
  ASTC_ISA_SIMD=avx2
This warning is for project developers.  Use -Wno-dev to suppress it.

And on your machine, the axmol1.0 cmake output ASTC_ISA_SIMD =?

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

The problem is likely to be in this file: https://github.com/axmolengine/axmol/commits/dev/thirdparty/CMakeLists.txt

A lot of changes were made to it between Axmol v1.0.0 to v2.0.0, and it's where the instruction set configuration seems to be set up.

The correct output for the Xeon X5670 should be: ASTC_ISA_SIMD=sse4.2

Use check_c_source_runs instead check_c_source_compiles should works:

    include(CheckCSourceRuns)
    check_c_source_runs("#include <immintrin.h>
        #include <stdint.h>
        int main()
        {
            __m256 m = _mm256_set_ps(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
            return (int)*(float*)&m;
        }" AX_HAVE_AVX2_INTRINSICS)

@crazyhappygame
Copy link
Contributor Author

for axmol v1.0.0 on my machine I have:

21:12:08  CMake Warning (dev) at external/axmol/thirdparty/astcenc/CMakeLists.txt:84 (message):
21:12:08    ASTC_ISA_SIMD=sse2
21:12:08  This warning is for project developers.  Use -Wno-dev to suppress it.

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

Strange: the SIMD instrinsics Detetion logic is really same between axmol 1.0 and 2.0: https://github.com/axmolengine/axmol/blob/dev/thirdparty/CMakeLists.txt#L63
https://github.com/axmolengine/axmol/blob/1.0/thirdparty/CMakeLists.txt#L63

@rh101
Copy link
Contributor

rh101 commented Oct 8, 2023

for axmol v1.0.0 on my machine I have:

21:12:08  CMake Warning (dev) at external/axmol/thirdparty/astcenc/CMakeLists.txt:84 (message):
21:12:08    ASTC_ISA_SIMD=sse2
21:12:08  This warning is for project developers.  Use -Wno-dev to suppress it.

This is also strange, since the Intel product page shows this:
Instruction Set Extensions Intel® SSE4.2

So it should be ASTC_ISA_SIMD=sse4.2

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

image

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

And if you build x64, should never use SSE2: https://github.com/axmolengine/axmol/blob/1.0/thirdparty/astcenc/CMakeLists.txt#L47

if (NOT DEFINED ASTC_ISA_SIMD)
    if (NOT (ARCH_ALIAS STREQUAL "x86") AND NOT TVOS)
        set(ASTC_HAVE_AVX2_INTRINSICS ${AX_HAVE_AVX2_INTRINSICS})
        set(ASTC_HAVE_SSE42_INTRINSICS ${AX_HAVE_SSE42_INTRINSICS})
        set(ASTC_HAVE_SSE41_INTRINSICS ${AX_HAVE_SSE41_INTRINSICS})
        if (AX_HAVE_NEON_INTRINSICS)
            set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
            set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
            check_cxx_source_compiles("#include <arm_neon.h>
                    int main()
                    {
                        int32x4_t ret4 = vdupq_n_s32(0);
                        uint32x4_t v{};
                        float16x4_t f16 = vcvt_f16_f32(v);
                        return vgetq_lane_s32(ret4, 0);
                    }" ASTC_HAVE_NEON_INTRINSICS)
            set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
            unset(OLD_REQUIRED_FLAGS)
        endif()
    else()
        set(ASTC_HAVE_SSE2_INTRINSICS ${AX_HAVE_SSE2_INTRINSICS})
        message(AUTHOR_WARNING "Skipping AVX2/SSE4/NEON detection for astc-encoder when build target 'x86' and 'tvos'")
    endif()

    ### set ASTC_ISA_SIMD
    if(ASTC_HAVE_AVX2_INTRINSICS)
        set(ASTC_ISA_SIMD "avx2")
    elseif(ASTC_HAVE_SSE42_INTRINSICS)
        set(ASTC_ISA_SIMD "sse4.2")
    elseif(ASTC_HAVE_SSE41_INTRINSICS)
        set(ASTC_ISA_SIMD "sse4.1")
    elseif(ASTC_HAVE_SSE2_INTRINSICS)
        set(ASTC_ISA_SIMD "sse2")
    elseif(ASTC_HAVE_NEON_INTRINSICS)
        set(ASTC_ISA_SIMD "neon")
    else()
        set(ASTC_ISA_SIMD "none")
    endif()

    message(AUTHOR_WARNING "ASTC_ISA_SIMD=${ASTC_ISA_SIMD}")
endif()

@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

@crazyhappygame You build axmol-1.0 x86 via -A Win32? if true, will only check sse2 and use it

@halx99 halx99 added this to the 2.1.0 milestone Oct 8, 2023
@halx99 halx99 added simd enhancement New feature or request labels Oct 8, 2023
@halx99 halx99 changed the title axmol v2.0.0 - cpp-tests crashes on windows ISA_SIMD illegal instructions crashes on windows Oct 8, 2023
@halx99 halx99 changed the title ISA_SIMD illegal instructions crashes on windows ISA_SIMD illegal instructions crashes on windows x64 Oct 8, 2023
@halx99 halx99 closed this as completed in 6c13196 Oct 8, 2023
halx99 added a commit that referenced this issue Oct 8, 2023
Add cmake option `AX_ISA_LEVEL`

Note: we set default AX_ISA_LEVEL to 2 for sse4.1 for axmol app can runs on large amount devices
If you want axmol app runs on more old devices, you can specify in cmake cmdline `-DAX_ISA_LEVEL=2`,
otherwise, host compiler generated instructions will crash on old devices which not support high level
SIMD instructions.
halx99 added a commit that referenced this issue Oct 8, 2023
Add cmake option `AX_ISA_LEVEL`

Note: we set default AX_ISA_LEVEL to 2 for sse4.1 for axmol app can runs on large amount devices
If you want axmol app runs on more old devices, you can specify in cmake cmdline `-DAX_ISA_LEVEL=1` or
`-DAX_ISA_LEVEL=0` to disable SIMD acceleration for thirdparty astcenc and webp
otherwise, host compiler generated instructions will crash on old devices which not support high level
SIMD instructions.
halx99 added a commit that referenced this issue Oct 8, 2023
Add cmake option `AX_ISA_LEVEL`

Note: we set default AX_ISA_LEVEL to 2 for sse4.1 for axmol app can runs on large amount devices
If you want axmol app runs on more old devices, you can specify in cmake cmdline `-DAX_ISA_LEVEL=1` or
`-DAX_ISA_LEVEL=0` to disable SIMD acceleration for thirdparty astcenc and webp
otherwise, host compiler generated instructions will crash on old devices which not support high level
SIMD instructions.
@halx99
Copy link
Collaborator

halx99 commented Oct 8, 2023

The commit fcd3312 improve SIMD instructions detction, and should fix this issue, note: this is not axmol2 spec issue, when build axmol1 x64 should have this issue. both axmol1 & 2 x86 never trigger this issue due to max ISA_SIMD is sse2

@crazyhappygame
Copy link
Contributor Author

Thank you.
For latest version on my machine I see

CMake Warning (dev) at thirdparty/astcenc/CMakeLists.txt:56 (message):
  ASTC_ISA_SIMD=sse4.1

No crashes any more. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request simd
Projects
None yet
Development

No branches or pull requests

3 participants