Skip to content

Commit

Permalink
Upgrade Embree to the latest official release.
Browse files Browse the repository at this point in the history
Since Embree v3.13.0 supports AARCH64, switch back to the
official repo instead of using Embree-aarch64.

`thirdparty/embree/patches/godot-changes.patch` should now contain
an accurate diff of the changes done to the library.

(cherry picked from commit 767e374)
  • Loading branch information
JFonS authored and akien-mga committed May 22, 2021
1 parent 2660faf commit a69cc9f
Show file tree
Hide file tree
Showing 343 changed files with 12,069 additions and 10,374 deletions.
2 changes: 1 addition & 1 deletion COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ License: Expat

Files: ./thirdparty/embree/
Comment: Embree
Copyright: 2009-2021 Intel Corporation
Copyright: 2009-2021, Intel Corporation
License: Apache-2.0

Files: ./thirdparty/enet/
Expand Down
16 changes: 5 additions & 11 deletions modules/raycast/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ if env["builtin_embree"]:
"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",
Expand Down Expand Up @@ -82,13 +72,17 @@ if env["builtin_embree"]:
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)

if not env["arch"] in ["x86", "x86_64"] or env.msvc:
# Embree needs those, it will automatically use SSE2NEON in ARM
env_thirdparty.Append(CPPDEFINES=["__SSE2__", "__SSE__"])

env.modules_sources += thirdparty_obj


Expand Down
3 changes: 1 addition & 2 deletions modules/raycast/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ def can_build(env, platform):
if not env["tools"]:
return False

# Depends on Embree library, which supports only x86_64 (originally)
# and aarch64 (thanks to the embree-aarch64 fork).
# Depends on Embree library, which only supports x86_64 and aarch64.

if platform == "android":
return env["android_arch"] in ["arm64v8", "x86_64"]
Expand Down
15 changes: 3 additions & 12 deletions modules/raycast/godot_update_embree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"common/algorithms",
"common/lexers",
"common/simd",
"common/simd/arm",
"include/embree3",
"kernels/subdiv",
"kernels/geometry",
Expand All @@ -32,16 +33,6 @@
"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",
Expand Down Expand Up @@ -78,7 +69,7 @@
if os.path.exists(dir_name):
shutil.rmtree(dir_name)

subprocess.run(["git", "clone", "https://github.com/lighttransport/embree-aarch64.git", "embree-tmp"])
subprocess.run(["git", "clone", "https://github.com/embree/embree.git", "embree-tmp"])
os.chdir("embree-tmp")

commit_hash = str(subprocess.check_output(["git", "rev-parse", "HEAD"], universal_newlines=True)).strip()
Expand Down Expand Up @@ -197,7 +188,7 @@
with open(os.path.join(dest_dir, "include/embree3/rtcore_config.h"), "w") as config_file:
config_file.write(
f"""
// Copyright 2009-2020 Intel Corporation
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
Expand Down
9 changes: 5 additions & 4 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ Files extracted from upstream source:

- all .cpp, .h, and .txt files in ConvectionKernels/


## embree

- Upstream: https://github.com/lighttransport/embree-aarch64
- Version: 3.12.1 (6ef362f99af80c9dfe8dd2bfc582d9067897edc6, 2020)
- Upstream: https://github.com/embree/embree
- Version: 3.13.0 (7c53133eb21424f7f0ae1e25bf357e358feaf6ab, 2021)
- License: Apache 2.0

Files extracted from upstream:

- All cpp files listed in `modules/raycast/godot_update_embree.py`
- All header files in the directories listed in `modules/raycast/godot_update_embree.py`

The `modules/raycast/godot_update_embree.py`script can be used to pull the
relevant files from the latest Embree-aarch64 release and apply some automatic changes.
The `modules/raycast/godot_update_embree.py` script can be used to pull the
relevant files from the latest Embree release and apply some automatic changes.

Some changes have been made in order to remove exceptions and fix minor build errors.
They are marked with `// -- GODOT start --` and `// -- GODOT end --`
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/embree/common/algorithms/parallel_any_of.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2009-2020 Intel Corporation
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once
Expand Down
56 changes: 0 additions & 56 deletions thirdparty/embree/common/algorithms/parallel_filter.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion thirdparty/embree/common/algorithms/parallel_filter.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2009-2020 Intel Corporation
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once
Expand Down
48 changes: 0 additions & 48 deletions thirdparty/embree/common/algorithms/parallel_for.cpp

This file was deleted.

73 changes: 15 additions & 58 deletions thirdparty/embree/common/algorithms/parallel_for.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2009-2020 Intel Corporation
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once
Expand All @@ -8,12 +8,6 @@
#include "../math/math.h"
#include "../math/range.h"

#if defined(TASKING_GCD) && defined(BUILD_IOS)
#include <dispatch/dispatch.h>
#include <algorithm>
#include <type_traits>
#endif

namespace embree
{
/* parallel_for without range */
Expand All @@ -29,28 +23,10 @@ namespace embree
if (!TaskScheduler::wait())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
}
#elif defined(TASKING_GCD) && defined(BUILD_IOS)

const size_t baselineNumBlocks = (TaskScheduler::threadCount() > 1)? TaskScheduler::threadCount() : 1;
const size_t length = N;
const size_t blockSize = (length + baselineNumBlocks-1) / baselineNumBlocks;
const size_t numBlocks = (length + blockSize-1) / blockSize;

dispatch_apply(numBlocks, DISPATCH_APPLY_AUTO, ^(size_t currentBlock) {

const size_t start = (currentBlock * blockSize);
const size_t blockLength = std::min(length - start, blockSize);
const size_t end = start + blockLength;

for(size_t i=start; i < end; i++)
{
func(i);
}
});


#elif defined(TASKING_TBB)
#if TBB_INTERFACE_VERSION >= 12002
tbb::task_group_context context;
Expand All @@ -60,7 +36,7 @@ namespace embree
if (context.is_group_execution_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#else
tbb::parallel_for(Index(0),N,Index(1),[&](Index i) {
Expand All @@ -69,7 +45,7 @@ namespace embree
if (tbb::task::self().is_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#endif

Expand All @@ -92,28 +68,9 @@ namespace embree
if (!TaskScheduler::wait())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --

#elif defined(TASKING_GCD) && defined(BUILD_IOS)

const size_t baselineNumBlocks = (TaskScheduler::threadCount() > 1)? 4*TaskScheduler::threadCount() : 1;
const size_t length = last - first;
const size_t blockSizeByThreads = (length + baselineNumBlocks-1) / baselineNumBlocks;
size_t blockSize = std::max<size_t>(minStepSize,blockSizeByThreads);
blockSize += blockSize % 4;

const size_t numBlocks = (length + blockSize-1) / blockSize;

dispatch_apply(numBlocks, DISPATCH_APPLY_AUTO, ^(size_t currentBlock) {

const size_t start = first + (currentBlock * blockSize);
const size_t end = std::min<size_t>(last, start + blockSize);

func( embree::range<Index>(start,end) );
});


#elif defined(TASKING_TBB)
#if TBB_INTERFACE_VERSION >= 12002
tbb::task_group_context context;
Expand All @@ -123,7 +80,7 @@ namespace embree
if (context.is_group_execution_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#else
tbb::parallel_for(tbb::blocked_range<Index>(first,last,minStepSize),[&](const tbb::blocked_range<Index>& r) {
Expand All @@ -132,7 +89,7 @@ namespace embree
if (tbb::task::self().is_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#endif

Expand Down Expand Up @@ -167,7 +124,7 @@ namespace embree
if (context.is_group_execution_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#else
tbb::parallel_for(Index(0),N,Index(1),[&](Index i) {
Expand All @@ -176,7 +133,7 @@ namespace embree
if (tbb::task::self().is_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#endif
}
Expand All @@ -192,18 +149,18 @@ namespace embree
func(i);
},ap,context);
if (context.is_group_execution_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
// -- GODOT end --
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
// -- GODOT end --
#else
tbb::parallel_for(Index(0),N,Index(1),[&](Index i) {
func(i);
},ap);
if (tbb::task::self().is_cancelled())
// -- GODOT start --
// throw std::runtime_error("task cancelled");
abort();
abort();
// -- GODOT end --
#endif
}
Expand Down
Loading

0 comments on commit a69cc9f

Please sign in to comment.