Port changes to the "raycast" module build files from 3.x

This commit is contained in:
jfons 2021-05-04 12:06:54 +02:00
parent b5e4d63a0b
commit 575543ce53
5 changed files with 118 additions and 98 deletions

View File

@ -131,6 +131,11 @@ Comment: doctest
Copyright: 2016-2020, Viktor Kirilov
License: Expat
Files: ./thirdparty/embree-aarch64/
Comment: Embree-aarch64
Copyright: 2009-2021 Intel Corporation
License: Apache-2.0
Files: ./thirdparty/enet/
Comment: ENet
Copyright: 2002-2020, Lee Salzman

View File

@ -145,6 +145,7 @@ opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise e
# Thirdparty libraries
opts.Add(BoolVariable("builtin_bullet", "Use the built-in Bullet library", True))
opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundles", True))
opts.Add(BoolVariable("builtin_embree", "Use the built-in Embree library", True))
opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True))
opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True))

View File

@ -3,84 +3,101 @@
Import("env")
Import("env_modules")
embree_src = [
"common/sys/sysinfo.cpp",
"common/sys/alloc.cpp",
"common/sys/filename.cpp",
"common/sys/library.cpp",
"common/sys/thread.cpp",
"common/sys/string.cpp",
"common/sys/regression.cpp",
"common/sys/mutex.cpp",
"common/sys/condition.cpp",
"common/sys/barrier.cpp",
"common/math/constants.cpp",
"common/simd/sse.cpp",
"common/lexers/stringstream.cpp",
"common/lexers/tokenstream.cpp",
"common/tasking/taskschedulerinternal.cpp",
"common/algorithms/parallel_for.cpp",
"common/algorithms/parallel_reduce.cpp",
"common/algorithms/parallel_prefix_sum.cpp",
"common/algorithms/parallel_for_for.cpp",
"common/algorithms/parallel_for_for_prefix_sum.cpp",
"common/algorithms/parallel_partition.cpp",
"common/algorithms/parallel_sort.cpp",
"common/algorithms/parallel_set.cpp",
"common/algorithms/parallel_map.cpp",
"common/algorithms/parallel_filter.cpp",
"kernels/common/device.cpp",
"kernels/common/stat.cpp",
"kernels/common/acceln.cpp",
"kernels/common/accelset.cpp",
"kernels/common/state.cpp",
"kernels/common/rtcore.cpp",
"kernels/common/rtcore_builder.cpp",
"kernels/common/scene.cpp",
"kernels/common/alloc.cpp",
"kernels/common/geometry.cpp",
"kernels/common/scene_triangle_mesh.cpp",
"kernels/geometry/primitive4.cpp",
"kernels/builders/primrefgen.cpp",
"kernels/bvh/bvh.cpp",
"kernels/bvh/bvh_statistics.cpp",
"kernels/bvh/bvh4_factory.cpp",
"kernels/bvh/bvh8_factory.cpp",
"kernels/bvh/bvh_collider.cpp",
"kernels/bvh/bvh_rotate.cpp",
"kernels/bvh/bvh_refit.cpp",
"kernels/bvh/bvh_builder.cpp",
"kernels/bvh/bvh_builder_morton.cpp",
"kernels/bvh/bvh_builder_sah.cpp",
"kernels/bvh/bvh_builder_sah_spatial.cpp",
"kernels/bvh/bvh_builder_sah_mb.cpp",
"kernels/bvh/bvh_builder_twolevel.cpp",
"kernels/bvh/bvh_intersector1_bvh4.cpp",
]
embree_dir = "#thirdparty/embree-aarch64/"
env_embree = env_modules.Clone()
embree_sources = [embree_dir + file for file in embree_src]
env_embree.Prepend(CPPPATH=[embree_dir, embree_dir + "include"])
env_embree.Append(CPPFLAGS=["-DEMBREE_TARGET_SSE2", "-DEMBREE_LOWEST_ISA", "-DTASKING_INTERNAL", "-DNDEBUG"])
if not env_embree.msvc:
env_embree.Append(CPPFLAGS=["-msse2", "-mxsave"])
if env["platform"] == "windows":
env_embree.Append(CPPFLAGS=["-mstackrealign"])
if env["platform"] == "windows":
if env.msvc:
env.Append(LINKFLAGS=["psapi.lib"])
env_embree.Append(CPPFLAGS=["-D__SSE2__", "-D__SSE__"])
else:
env.Append(LIBS=["psapi"])
env_embree.disable_warnings()
env_embree.add_source_files(env.modules_sources, embree_sources)
env_raycast = env_modules.Clone()
env_raycast.Prepend(CPPPATH=[embree_dir, embree_dir + "include", embree_dir + "common"])
env_raycast.add_source_files(env.modules_sources, "*.cpp")
# Thirdparty source files
thirdparty_obj = []
if env["builtin_embree"]:
thirdparty_dir = "#thirdparty/embree-aarch64/"
embree_src = [
"common/sys/sysinfo.cpp",
"common/sys/alloc.cpp",
"common/sys/filename.cpp",
"common/sys/library.cpp",
"common/sys/thread.cpp",
"common/sys/string.cpp",
"common/sys/regression.cpp",
"common/sys/mutex.cpp",
"common/sys/condition.cpp",
"common/sys/barrier.cpp",
"common/math/constants.cpp",
"common/simd/sse.cpp",
"common/lexers/stringstream.cpp",
"common/lexers/tokenstream.cpp",
"common/tasking/taskschedulerinternal.cpp",
"common/algorithms/parallel_for.cpp",
"common/algorithms/parallel_reduce.cpp",
"common/algorithms/parallel_prefix_sum.cpp",
"common/algorithms/parallel_for_for.cpp",
"common/algorithms/parallel_for_for_prefix_sum.cpp",
"common/algorithms/parallel_partition.cpp",
"common/algorithms/parallel_sort.cpp",
"common/algorithms/parallel_set.cpp",
"common/algorithms/parallel_map.cpp",
"common/algorithms/parallel_filter.cpp",
"kernels/common/device.cpp",
"kernels/common/stat.cpp",
"kernels/common/acceln.cpp",
"kernels/common/accelset.cpp",
"kernels/common/state.cpp",
"kernels/common/rtcore.cpp",
"kernels/common/rtcore_builder.cpp",
"kernels/common/scene.cpp",
"kernels/common/alloc.cpp",
"kernels/common/geometry.cpp",
"kernels/common/scene_triangle_mesh.cpp",
"kernels/geometry/primitive4.cpp",
"kernels/builders/primrefgen.cpp",
"kernels/bvh/bvh.cpp",
"kernels/bvh/bvh_statistics.cpp",
"kernels/bvh/bvh4_factory.cpp",
"kernels/bvh/bvh8_factory.cpp",
"kernels/bvh/bvh_collider.cpp",
"kernels/bvh/bvh_rotate.cpp",
"kernels/bvh/bvh_refit.cpp",
"kernels/bvh/bvh_builder.cpp",
"kernels/bvh/bvh_builder_morton.cpp",
"kernels/bvh/bvh_builder_sah.cpp",
"kernels/bvh/bvh_builder_sah_spatial.cpp",
"kernels/bvh/bvh_builder_sah_mb.cpp",
"kernels/bvh/bvh_builder_twolevel.cpp",
"kernels/bvh/bvh_intersector1_bvh4.cpp",
]
thirdparty_sources = [thirdparty_dir + file for file in embree_src]
env_raycast.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "include"])
env_raycast.Append(CPPDEFINES=["EMBREE_TARGET_SSE2", "EMBREE_LOWEST_ISA", "TASKING_INTERNAL", "NDEBUG"])
if not env.msvc:
if env["arch"] in ["x86", "x86_64"]:
env_raycast.Append(CPPFLAGS=["-msse2", "-mxsave"])
if env["platform"] == "windows":
env_raycast.Append(CPPFLAGS=["-mstackrealign"])
if env["platform"] == "windows":
if env.msvc:
env.Append(LINKFLAGS=["psapi.lib"])
env_raycast.Append(CPPDEFINES=["__SSE2__", "__SSE__"])
else:
env.Append(LIBS=["psapi"])
env_thirdparty = env_raycast.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env.modules_sources += thirdparty_obj
# Godot source files
module_obj = []
env_raycast.add_source_files(module_obj, "*.cpp")
env.modules_sources += module_obj
# Needed to force rebuilding the module files when the thirdparty library is updated.
env.Depends(module_obj, thirdparty_obj)

View File

@ -32,14 +32,8 @@
#include "lightmap_raycaster.h"
// From Embree.
#include <math/vec2.h>
#include <math/vec3.h>
#include <pmmintrin.h>
using namespace embree;
LightmapRaycaster *LightmapRaycasterEmbree::create_embree_raycaster() {
return memnew(LightmapRaycasterEmbree);
}
@ -127,23 +121,22 @@ void LightmapRaycasterEmbree::add_mesh(const Vector<Vector3> &p_vertices, const
ERR_FAIL_COND(vertex_count % 3 != 0);
ERR_FAIL_COND(vertex_count != p_uv2s.size());
ERR_FAIL_COND(!p_normals.is_empty() && vertex_count != p_normals.size());
Vector3 *embree_vertices = (Vector3 *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3, sizeof(Vector3), vertex_count);
memcpy(embree_vertices, p_vertices.ptr(), sizeof(Vector3) * vertex_count);
Vector2 *embree_light_uvs = (Vector2 *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 0, RTC_FORMAT_FLOAT2, sizeof(Vector2), vertex_count);
memcpy(embree_light_uvs, p_uv2s.ptr(), sizeof(Vector2) * vertex_count);
Vec3fa *embree_vertices = (Vec3fa *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3, sizeof(Vec3fa), vertex_count);
Vec2fa *embree_light_uvs = (Vec2fa *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 0, RTC_FORMAT_FLOAT2, sizeof(Vec2fa), vertex_count);
uint32_t *embree_triangles = (uint32_t *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(uint32_t) * 3, vertex_count / 3);
Vec3fa *embree_normals = nullptr;
if (!p_normals.is_empty()) {
embree_normals = (Vec3fa *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 1, RTC_FORMAT_FLOAT3, sizeof(Vec3fa), vertex_count);
for (int i = 0; i < vertex_count; i++) {
embree_triangles[i] = i;
}
for (int i = 0; i < vertex_count; i++) {
embree_vertices[i] = Vec3fa(p_vertices[i].x, p_vertices[i].y, p_vertices[i].z);
embree_light_uvs[i] = Vec2fa(p_uv2s[i].x, p_uv2s[i].y);
if (embree_normals != nullptr) {
embree_normals[i] = Vec3fa(p_normals[i].x, p_normals[i].y, p_normals[i].z);
}
embree_triangles[i] = i;
if (!p_normals.is_empty()) {
Vector3 *embree_normals = (Vector3 *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 1, RTC_FORMAT_FLOAT3, sizeof(Vector3), vertex_count);
memcpy(embree_normals, p_normals.ptr(), sizeof(Vector3) * vertex_count);
}
rtcCommitGeometry(embree_mesh);

View File

@ -325,6 +325,10 @@ def configure(env):
if not env["builtin_pcre2"]:
env.ParseConfig("pkg-config libpcre2-32 --cflags --libs")
if not env["builtin_embree"]:
# No pkgconfig file so far, hardcode expected lib name.
env.Append(LIBS=["embree3"])
## Flags
if os.system("pkg-config --exists alsa") == 0: # 0 means found