Open xana43 opened 6 months ago
Upon further testing, it seems like Embree is the only thing causing compilation issues when using -march, when I disable the embree module godot compiles just fine at this x86 version. Every other module works perfectly fine.
Embree uses preprocessor defines (such as __AVX2__
) to decide what features to use. By passing -march=x86-64-v3
, AVX2 support is enabled, which makes the compiler set the corresponding defines, thus changing the behavior of the code.
The undefined reference to 'embree::avx2::...
errors are due to Embree's AVX2 code making use of implementation code omitted from Godot's copy of the Embree library (specifically, the kernels/geometry/primitive8.cpp
, kernels/bvh/bvh_intersector1_bvh8.cpp
, kernels/bvh/bvh_intersector_hybrid4_bvh8.cpp
, kernels/bvh/bvh_intersector_hybrid8_bvh4.cpp
and kernels/bvh/bvh_intersector_hybrid8_bvh8.cpp
files).
The undefined reference to 'embree::BVHN<4>::...
errors are due to defining EMBREE_TARGET_SSE2
when SSE2 is not the target being compiled. Specifically, it seems to be due to this bit of code in kernels/bvh/bvh.cpp
:
#if !defined(__AVX__) || !defined(EMBREE_TARGET_SSE2) && !defined(EMBREE_TARGET_SSE42) || defined(__aarch64__)
template class BVHN<4>;
#endif
which causes BVHN<4>
to not be defined if the compiler supports AVX and EMBREE_TARGET_SSE2
is defined.
By adding the missing files, and changing the define from EMBREE_TARGET_SSE2
to EMBREE_TARGET_AVX2
(or just EMBREE_TARGET_AVX
), Embree will build with -march=x86-64-v3
.
While adding the missing files would probably be OK for a regular Godot build (dead code elimination would probably negate the binary size impact of the added code), I'm not sure how we'd go about selecting the right EMBREE_TARGET_*
define for the compiler flags used.
The proper solution would probably be to prevent the compiler flags from enabling new instruction sets, using -mno-avx
and such. It would fix the issue, although Embree would still only be built with SSE2 support. To have Embree built with AVX/AVX2 support, we'd need to explicitly add it as a build option.
Tested versions
found in Godot v4.2.3.rc (c8356fb9d) (when I pulled version 4.2.2 there was a commit that changed it's version to 4.2.3 but nothing else was changed)
System information
Godot v4.2.3.rc (c8356fb9d) - Fedora Linux 40 (KDE Plasma) - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 7900 XT (RADV NAVI31) () - AMD Ryzen 9 7950X 16-Core Processor (32 Threads)
Issue description
When compiling the godot editor with the option
-march=x86-64-v3
it errors out giving this error NOTE: using-march=x86-64-v2
or-march=x86-64
does not error outSteps to reproduce
add
-march=x86-64-v3
to CCFLAGS and LINKFLAGSMinimal reproduction project (MRP)
N/A