Skip to content

Commit ffdffe0

Browse files
committed
Merge pull request godotengine#101345 from akien-mga/embree-4.3.3
embree: Update to 4.4.0
2 parents 4e6451d + 57640dd commit ffdffe0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1446
-751
lines changed

modules/raycast/godot_update_embree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
from typing import Any, Callable
99

10-
git_tag = "v4.3.1"
10+
git_tag = "v4.4.0"
1111

1212
include_dirs = [
1313
"common/tasking",

thirdparty/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Files extracted from upstream source:
199199
## embree
200200

201201
- Upstream: https://github.com/embree/embree
202-
- Version: 4.3.1 (daa8de0e714e18ad5e5c9841b67c1950d9c91c51, 2024)
202+
- Version: 4.4.0 (ff9381774dc99fea81a932ad276677aad6a3d4dd, 2025)
203203
- License: Apache 2.0
204204

205205
Files extracted from upstream:
@@ -216,7 +216,6 @@ Patches:
216216
- `0003-emscripten-nthreads.patch` (GH-69799)
217217
- `0004-mingw-no-cpuidex.patch` (GH-92488)
218218
- `0005-mingw-llvm-arm64.patch` (GH-93364)
219-
- `0006-include-order-dllexport.patch` (GH-94256)
220219

221220
The `modules/raycast/godot_update_embree.py` script can be used to pull the
222221
relevant files from the latest Embree release and apply patches automatically.

thirdparty/embree/common/lexers/stringstream.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ namespace embree
3939
std::vector<char> str; str.reserve(64);
4040
while (cin->peek() != EOF && !isSeparator(cin->peek())) {
4141
int c = cin->get();
42-
//if (!isValidChar(c)) throw std::runtime_error("invalid character "+std::string(1,c)+" in input");
43-
if (!isValidChar(c)) {
44-
abort();
45-
}
42+
if (!isValidChar(c)) abort(); //throw std::runtime_error("invalid character "+std::string(1,c)+" in input");
4643
str.push_back((char)c);
4744
}
4845
str.push_back(0);

thirdparty/embree/common/math/vec2fa_sycl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ namespace embree
9595
__forceinline Vec2fa abs ( const Vec2fa& a ) { return Vec2fa(sycl::fabs(a.x),sycl::fabs(a.y)); }
9696
__forceinline Vec2fa sign ( const Vec2fa& a ) { return Vec2fa(sycl::sign(a.x),sycl::sign(a.y)); }
9797

98-
//__forceinline Vec2fa rcp ( const Vec2fa& a ) { return Vec2fa(sycl::recip(a.x),sycl::recip(a.y)); }
99-
__forceinline Vec2fa rcp ( const Vec2fa& a ) { return Vec2fa(__sycl_std::__invoke_native_recip<float>(a.x),__sycl_std::__invoke_native_recip<float>(a.y)); }
98+
//__forceinline Vec2fa rcp ( const Vec2fa& a ) { return Vec2fa(sycl::native::recip(a.x),sycl::native::recip(a.y)); }
99+
__forceinline Vec2fa rcp ( const Vec2fa& a ) { return Vec2fa(sycl::native::recip(a.x),sycl::native::recip(a.y)); }
100100
__forceinline Vec2fa sqrt ( const Vec2fa& a ) { return Vec2fa(sycl::sqrt(a.x),sycl::sqrt(a.y)); }
101101
__forceinline Vec2fa sqr ( const Vec2fa& a ) { return Vec2fa(a.x*a.x,a.y*a.y); }
102102

thirdparty/embree/common/math/vec3fa_sycl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace embree
9292
__forceinline Vec3fa sign ( const Vec3fa& a ) { return Vec3fa(sycl::sign(a.x),sycl::sign(a.y),sycl::sign(a.z)); }
9393

9494
//__forceinline Vec3fa rcp ( const Vec3fa& a ) { return Vec3fa(sycl::recip(a.x),sycl::recip(a.y),sycl::recip(a.z)); }
95-
__forceinline Vec3fa rcp ( const Vec3fa& a ) { return Vec3fa(__sycl_std::__invoke_native_recip<float>(a.x),__sycl_std::__invoke_native_recip<float>(a.y),__sycl_std::__invoke_native_recip<float>(a.z)); }
95+
__forceinline Vec3fa rcp ( const Vec3fa& a ) { return Vec3fa(sycl::native::recip(a.x),sycl::native::recip(a.y),sycl::native::recip(a.z)); }
9696
__forceinline Vec3fa sqrt ( const Vec3fa& a ) { return Vec3fa(sycl::sqrt(a.x),sycl::sqrt(a.y),sycl::sqrt(a.z)); }
9797
__forceinline Vec3fa sqr ( const Vec3fa& a ) { return Vec3fa(a.x*a.x,a.y*a.y,a.z*a.z); }
9898

@@ -393,7 +393,7 @@ namespace embree
393393
__forceinline Vec3fx sign ( const Vec3fx& a ) { return Vec3fx(sycl::sign(a.x),sycl::sign(a.y),sycl::sign(a.z),sycl::sign(a.z)); }
394394

395395
//__forceinline Vec3fx rcp ( const Vec3fx& a ) { return Vec3fx(sycl::recip(a.x),sycl::recip(a.y),sycl::recip(a.z)); }
396-
__forceinline Vec3fx rcp ( const Vec3fx& a ) { return Vec3fx(__sycl_std::__invoke_native_recip<float>(a.x),__sycl_std::__invoke_native_recip<float>(a.y),__sycl_std::__invoke_native_recip<float>(a.z),__sycl_std::__invoke_native_recip<float>(a.w)); }
396+
__forceinline Vec3fx rcp ( const Vec3fx& a ) { return Vec3fx(sycl::native::recip(a.x),sycl::native::recip(a.y),sycl::native::recip(a.z),sycl::native::recip(a.w)); }
397397
__forceinline Vec3fx sqrt ( const Vec3fx& a ) { return Vec3fx(sycl::sqrt(a.x),sycl::sqrt(a.y),sycl::sqrt(a.z),sycl::sqrt(a.w)); }
398398
__forceinline Vec3fx sqr ( const Vec3fx& a ) { return Vec3fx(a.x*a.x,a.y*a.y,a.z*a.z,a.w*a.w); }
399399

@@ -614,4 +614,12 @@ namespace embree
614614

615615
//__forceinline Vec3ia::Vec3ia( const Vec3fx& a )
616616
// : x((int)a.x), y((int)a.y), z((int)a.z) {}
617+
618+
}
619+
620+
#if __SYCL_COMPILER_VERSION >= 20210801
621+
namespace sycl {
622+
template<> struct is_device_copyable<embree::Vec3fa> : std::true_type {};
623+
template<> struct is_device_copyable<const embree::Vec3fa> : std::true_type {};
617624
}
625+
#endif

thirdparty/embree/common/sys/alloc.cpp

Lines changed: 56 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -12,88 +12,23 @@
1212

1313
namespace embree
1414
{
15-
size_t total_allocations = 0;
16-
17-
#if defined(EMBREE_SYCL_SUPPORT)
18-
19-
__thread sycl::context* tls_context_tutorial = nullptr;
20-
__thread sycl::device* tls_device_tutorial = nullptr;
21-
22-
__thread sycl::context* tls_context_embree = nullptr;
23-
__thread sycl::device* tls_device_embree = nullptr;
24-
25-
void enableUSMAllocEmbree(sycl::context* context, sycl::device* device)
26-
{
27-
//if (tls_context_embree != nullptr) throw std::runtime_error("USM allocation already enabled");
28-
//if (tls_device_embree != nullptr) throw std::runtime_error("USM allocation already enabled");
29-
if (tls_context_embree != nullptr) {
30-
abort();
31-
}
32-
if (tls_device_embree != nullptr) {
33-
abort();
34-
}
35-
tls_context_embree = context;
36-
tls_device_embree = device;
37-
}
38-
39-
void disableUSMAllocEmbree()
40-
{
41-
//if (tls_context_embree == nullptr) throw std::runtime_error("USM allocation not enabled");
42-
//if (tls_device_embree == nullptr) throw std::runtime_error("USM allocation not enabled");
43-
if (tls_context_embree == nullptr) {
44-
abort();
45-
}
46-
if (tls_device_embree == nullptr) {
47-
abort();
48-
}
49-
tls_context_embree = nullptr;
50-
tls_device_embree = nullptr;
51-
}
52-
53-
void enableUSMAllocTutorial(sycl::context* context, sycl::device* device)
54-
{
55-
//if (tls_context_tutorial != nullptr) throw std::runtime_error("USM allocation already enabled");
56-
//if (tls_device_tutorial != nullptr) throw std::runtime_error("USM allocation already enabled");
57-
tls_context_tutorial = context;
58-
tls_device_tutorial = device;
59-
}
60-
61-
void disableUSMAllocTutorial()
62-
{
63-
//if (tls_context_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled");
64-
//if (tls_device_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled");
65-
if (tls_context_tutorial == nullptr) {
66-
abort();
67-
}
68-
if (tls_device_tutorial == nullptr) {
69-
abort();
70-
}
71-
72-
tls_context_tutorial = nullptr;
73-
tls_device_tutorial = nullptr;
74-
}
75-
76-
#endif
77-
7815
void* alignedMalloc(size_t size, size_t align)
7916
{
8017
if (size == 0)
8118
return nullptr;
8219

8320
assert((align & (align-1)) == 0);
8421
void* ptr = _mm_malloc(size,align);
85-
//if (size != 0 && ptr == nullptr)
86-
// throw std::bad_alloc();
87-
if (size != 0 && ptr == nullptr) {
88-
abort();
89-
}
22+
if (size != 0 && ptr == nullptr)
23+
abort(); //throw std::bad_alloc();
9024
return ptr;
9125
}
9226

9327
void alignedFree(void* ptr)
9428
{
95-
if (ptr)
29+
if (ptr) {
9630
_mm_free(ptr);
31+
}
9732
}
9833

9934
#if defined(EMBREE_SYCL_SUPPORT)
@@ -107,67 +42,66 @@ namespace embree
10742
return nullptr;
10843

10944
assert((align & (align-1)) == 0);
110-
total_allocations++;
11145

11246
void* ptr = nullptr;
113-
if (mode == EMBREE_USM_SHARED_DEVICE_READ_ONLY)
47+
if (mode == EmbreeUSMMode::DEVICE_READ_ONLY)
11448
ptr = sycl::aligned_alloc_shared(align,size,*device,*context,sycl::ext::oneapi::property::usm::device_read_only());
11549
else
11650
ptr = sycl::aligned_alloc_shared(align,size,*device,*context);
117-
118-
//if (size != 0 && ptr == nullptr)
119-
// throw std::bad_alloc();
120-
if (size != 0 && ptr == nullptr) {
121-
abort();
122-
}
51+
52+
if (size != 0 && ptr == nullptr)
53+
abort(); //throw std::bad_alloc();
12354

12455
return ptr;
12556
}
126-
127-
static MutexSys g_alloc_mutex;
128-
129-
void* alignedSYCLMalloc(size_t size, size_t align, EmbreeUSMMode mode)
130-
{
131-
if (tls_context_tutorial) return alignedSYCLMalloc(tls_context_tutorial, tls_device_tutorial, size, align, mode);
132-
if (tls_context_embree ) return alignedSYCLMalloc(tls_context_embree, tls_device_embree, size, align, mode);
133-
return nullptr;
134-
}
13557

136-
void alignedSYCLFree(sycl::context* context, void* ptr)
58+
void* alignedSYCLMalloc(sycl::context* context, sycl::device* device, size_t size, size_t align, EmbreeUSMMode mode, EmbreeMemoryType type)
13759
{
13860
assert(context);
139-
if (ptr) {
140-
sycl::free(ptr,*context);
141-
}
142-
}
61+
assert(device);
62+
63+
if (size == 0)
64+
return nullptr;
14365

144-
void alignedSYCLFree(void* ptr)
145-
{
146-
if (tls_context_tutorial) return alignedSYCLFree(tls_context_tutorial, ptr);
147-
if (tls_context_embree ) return alignedSYCLFree(tls_context_embree, ptr);
148-
}
66+
assert((align & (align-1)) == 0);
14967

150-
#endif
68+
void* ptr = nullptr;
69+
if (type == EmbreeMemoryType::USM_SHARED) {
70+
if (mode == EmbreeUSMMode::DEVICE_READ_ONLY)
71+
ptr = sycl::aligned_alloc_shared(align,size,*device,*context,sycl::ext::oneapi::property::usm::device_read_only());
72+
else
73+
ptr = sycl::aligned_alloc_shared(align,size,*device,*context);
74+
}
75+
else if (type == EmbreeMemoryType::USM_HOST) {
76+
ptr = sycl::aligned_alloc_host(align,size,*context);
77+
}
78+
else if (type == EmbreeMemoryType::USM_DEVICE) {
79+
ptr = sycl::aligned_alloc_device(align,size,*device,*context);
80+
}
81+
else {
82+
ptr = alignedMalloc(size,align);
83+
}
15184

152-
void* alignedUSMMalloc(size_t size, size_t align, EmbreeUSMMode mode)
85+
if (size != 0 && ptr == nullptr)
86+
abort(); //throw std::bad_alloc();
87+
88+
return ptr;
89+
}
90+
91+
void alignedSYCLFree(sycl::context* context, void* ptr)
15392
{
154-
#if defined(EMBREE_SYCL_SUPPORT)
155-
if (tls_context_embree || tls_context_tutorial)
156-
return alignedSYCLMalloc(size,align,mode);
157-
else
158-
#endif
159-
return alignedMalloc(size,align);
93+
assert(context);
94+
if (ptr) {
95+
sycl::usm::alloc type = sycl::get_pointer_type(ptr, *context);
96+
if (type == sycl::usm::alloc::host || type == sycl::usm::alloc::device || type == sycl::usm::alloc::shared)
97+
sycl::free(ptr,*context);
98+
else {
99+
alignedFree(ptr);
100+
}
101+
}
160102
}
161103

162-
void alignedUSMFree(void* ptr)
163-
{
164-
#if defined(EMBREE_SYCL_SUPPORT)
165-
if (tls_context_embree || tls_context_tutorial)
166-
return alignedSYCLFree(ptr);
167-
else
168104
#endif
169-
return alignedFree(ptr);
170-
}
171105

172106
static bool huge_pages_enabled = false;
173107
static MutexSys os_init_mutex;
@@ -265,10 +199,7 @@ namespace embree
265199
/* fall back to 4k pages */
266200
int flags = MEM_COMMIT | MEM_RESERVE;
267201
char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE);
268-
//if (ptr == nullptr) throw std::bad_alloc();
269-
if (ptr == nullptr) {
270-
abort();
271-
}
202+
if (ptr == nullptr) abort(); //throw std::bad_alloc();
272203
hugepages = false;
273204
return ptr;
274205
}
@@ -284,11 +215,8 @@ namespace embree
284215
if (bytesNew >= bytesOld)
285216
return bytesOld;
286217

287-
//if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT))
288-
// throw std::bad_alloc();
289-
if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) {
290-
abort();
291-
}
218+
if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT))
219+
abort(); //throw std::bad_alloc();
292220

293221
return bytesNew;
294222
}
@@ -298,11 +226,8 @@ namespace embree
298226
if (bytes == 0)
299227
return;
300228

301-
//if (!VirtualFree(ptr,0,MEM_RELEASE))
302-
// throw std::bad_alloc();
303-
if (!VirtualFree(ptr,0,MEM_RELEASE)) {
304-
abort();
305-
}
229+
if (!VirtualFree(ptr,0,MEM_RELEASE))
230+
abort(); //throw std::bad_alloc();
306231
}
307232

308233
void os_advise(void *ptr, size_t bytes)
@@ -406,10 +331,7 @@ namespace embree
406331

407332
/* fallback to 4k pages */
408333
void* ptr = (char*) mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
409-
//if (ptr == MAP_FAILED) throw std::bad_alloc();
410-
if (ptr == MAP_FAILED) {
411-
abort();
412-
}
334+
if (ptr == MAP_FAILED) abort(); //throw std::bad_alloc();
413335
hugepages = false;
414336

415337
/* advise huge page hint for THP */
@@ -425,11 +347,8 @@ namespace embree
425347
if (bytesNew >= bytesOld)
426348
return bytesOld;
427349

428-
//if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1)
429-
// throw std::bad_alloc();
430-
if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) {
431-
abort();
432-
}
350+
if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1)
351+
abort(); //throw std::bad_alloc();
433352

434353
return bytesNew;
435354
}
@@ -442,11 +361,8 @@ namespace embree
442361
/* for hugepages we need to also align the size */
443362
const size_t pageSize = hugepages ? PAGE_SIZE_2M : PAGE_SIZE_4K;
444363
bytes = (bytes+pageSize-1) & ~(pageSize-1);
445-
//if (munmap(ptr,bytes) == -1)
446-
// throw std::bad_alloc();
447-
if (munmap(ptr,bytes) == -1) {
448-
abort();
449-
}
364+
if (munmap(ptr,bytes) == -1)
365+
abort(); //throw std::bad_alloc();
450366
}
451367

452368
/* hint for transparent huge pages (THP) */

0 commit comments

Comments
 (0)