summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-05-04 17:55:25 +0200
committerGitHub <noreply@github.com>2021-05-04 17:55:25 +0200
commitdfbabcdaeb9c6865d0643f8294c43b6d149d7490 (patch)
treec8350ce08b508b5614b14520d572d673d95a3cb6
parent4472eb3e4f4c68c3f36382ed199a2d7b5f76ab9e (diff)
parent575543ce5359a21357d7760b18f9f4e5f9919c57 (diff)
Merge pull request #48453 from JFonS/improve_raycast_module_scsub
Port changes to the "raycast" module build files from 3.x
-rw-r--r--COPYRIGHT.txt5
-rw-r--r--SConstruct1
-rw-r--r--modules/raycast/SCsub169
-rw-r--r--modules/raycast/lightmap_raycaster.cpp29
-rw-r--r--platform/linuxbsd/detect.py4
5 files changed, 114 insertions, 94 deletions
diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt
index 9e63da3fc4..cfd983bb0a 100644
--- a/COPYRIGHT.txt
+++ b/COPYRIGHT.txt
@@ -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
diff --git a/SConstruct b/SConstruct
index 2d9802f293..6516b42e59 100644
--- a/SConstruct
+++ b/SConstruct
@@ -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))
diff --git a/modules/raycast/SCsub b/modules/raycast/SCsub
index 68e9df5263..57120bff26 100644
--- a/modules/raycast/SCsub
+++ b/modules/raycast/SCsub
@@ -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"])
+env_raycast = env_modules.Clone()
+
+# 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":
- env_embree.Append(CPPFLAGS=["-mstackrealign"])
+ if env.msvc:
+ env.Append(LINKFLAGS=["psapi.lib"])
+ env_raycast.Append(CPPDEFINES=["__SSE2__", "__SSE__"])
+ else:
+ env.Append(LIBS=["psapi"])
-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_thirdparty = env_raycast.Clone()
+ env_thirdparty.disable_warnings()
+ env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
+ env.modules_sources += thirdparty_obj
-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"])
+# Godot source files
+
+module_obj = []
+
+env_raycast.add_source_files(module_obj, "*.cpp")
+env.modules_sources += module_obj
-env_raycast.add_source_files(env.modules_sources, "*.cpp")
+# Needed to force rebuilding the module files when the thirdparty library is updated.
+env.Depends(module_obj, thirdparty_obj)
diff --git a/modules/raycast/lightmap_raycaster.cpp b/modules/raycast/lightmap_raycaster.cpp
index 9039622d3d..56bdb5900b 100644
--- a/modules/raycast/lightmap_raycaster.cpp
+++ b/modules/raycast/lightmap_raycaster.cpp
@@ -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,25 +121,24 @@ 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());
- 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);
+ 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);
- 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);
- }
+ 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);
+ uint32_t *embree_triangles = (uint32_t *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(uint32_t) * 3, vertex_count / 3);
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);
rtcSetGeometryIntersectFilterFunction(embree_mesh, filter_function);
rtcSetGeometryUserData(embree_mesh, this);
diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index adbbcaac31..1876960c57 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -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