From 575543ce5359a21357d7760b18f9f4e5f9919c57 Mon Sep 17 00:00:00 2001 From: jfons Date: Tue, 4 May 2021 12:06:54 +0200 Subject: Port changes to the "raycast" module build files from 3.x --- modules/raycast/SCsub | 169 ++++++++++++++++++--------------- modules/raycast/lightmap_raycaster.cpp | 29 +++--- 2 files changed, 104 insertions(+), 94 deletions(-) (limited to 'modules/raycast') 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 -#include - #include -using namespace embree; - LightmapRaycaster *LightmapRaycasterEmbree::create_embree_raycaster() { return memnew(LightmapRaycasterEmbree); } @@ -127,25 +121,24 @@ void LightmapRaycasterEmbree::add_mesh(const Vector &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); -- cgit v1.2.3