Cycles: upgrade Embree to version 4.0 #105974
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105974
Loading…
Reference in New Issue
No description provided.
Delete Branch "xavierh/blender:cycles_embree4"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Upgrade to new Embree 4 while staying compatible with Embree 3.
For more information about Embree 3->4 API changes:
https://github.com/embree/embree/blob/master/doc/src/api.md#upgrading-from-embree-3-to-embree-4
This is not yet enabling HW RT on Arc GPUs using Embree, that PR will come next.
Here we start with landing embree 4 hopefully smoothly on all CPU platforms.
9ae1b7bb90
to4adf43de88
@blender-bot build
29154f8303
to683fc0d376
@blender-bot build
Tested the change on Intel macOS. It compiles fine, tests are passing, and there are no speed changes for the Embree3. The code I only checked from a top level, didn't do careful line-by-line investigation, but from this perspective it also seems good.
Unfortunately, I can not currently test Embree4 as the dependency builder fails on my machine with an absolutely unrelated error (also happens in the main branch).
great! Here is one more commit to enable building embree with GPU support (before we can use it in next PR), not sure if you want to have it split in a separate PR or keep it here with overall Embree 4 update.
It requires using SYCL compiler to compile Embree. Easy on Linux with deps builder.
On Windows... it's easy in case deps builder can use Ninja (that's how I've tested it), if not, well, as VS cmake generator doesn't support using an external compiler, that's more complicated -> @LazyDodo any opinion on
c90211d280
?Haven't looked at it in detail, I can say I have been slowly been migrating most deps over to ninja on windows. If embree isn't already using it I have no objections to switching it over, it'll happen sooner or later, so it may as well be now.
I kinda took "It requires using SYCL compiler to compile Embree." to mean just the intel GPU kernels would build with dpcpp. But by the looks of it, it replaces GCC/MSVC completely with DPCPP even the CPU based code-paths for non intel gpu-users would now be build by it.
I'm OK with the intel specific GPU code being build with essentially the "flavor of the day" dpcpp version, using it for all code is making me a bit uncomfortable.
All Embree* code. dpcpp changes vs LLVM are almost exclusive to the SYCL code path so for CPU, it's not as nightly as the name implies.
If that's a no-go, as dpcpp matured quite much since we took nightlies, it should be fine switching to tagged releases. Latest one is https://github.com/intel/llvm/releases/tag/2022-12 - do you want to udpate this dep first?
Lets wait to see what @brecht and @Sergey 's feelings are on this.
My personal preference would be not to have DPCPP in the mix at all for non intel GPU code paths, but I could be alone in that. Let's first figure out first what we want, and we'll find a way to get there together.
By itself I don't mind Embree being compiled with DPCPP, to me it's not any different than what we have for OpenImageDenoise and ISPC.
What I do really dislike is the ever growing complexity of building Intel libraries, compilers and GPU kernels. As I've suggested before I would much rather have GPU support in Intel libraries be provided through header files that we can compile ourselves as part of the Blender build, for OpenImageDenoise, OpenPGL and Embree.
The way this is being done now is very complicated not just for Blender but other software that wants to use these libraries, as well as Linux distributions. The amount of complexity for this GPU backend compared to the number of Blender users that benefit from it is really off.
I don't think there is much we can do to change that immediately, but I really hope GPU support in OpenImageDenoise and OpenPGL is not going to make this significantly more complicated again.
small change needed to get this to build with dpcpp on windows, clang++ wanted to use
lld-link
as its linker, which wasn't enabled causing cmake to error out during compiler discovery.@ -25,0 +34,4 @@
)
endif()
if(WIN32)
if(CMAKE_GENERATOR MATCHES "Visual*")
This can be removed, the top level (the one that manages the order the deps get build in) generator will still be msbuild, but the embree dep will build with ninja because you added
CMAKE_GENERATOR
inExternalProject_Add
This is different though, OIDN has only ever had one way of building its kernels, here we change the compiler for the normal CPU kernels that have always build with msvc/gcc just fine to dpcpp for all embree users just to satisfy the needs of a single GPU target.
I'm all for taking some risk with intel's GPU arch, I don't even mind the complexity and all that much, it's all being done in isolation, intel GPU support never had the opportunity to cause behavioral changes for any of the other code paths, this changes that, intel GPU or not, you are now running dpcpp output, some pause and reflection ought to be had, even if we agree it's OK in the end.
837f3da67c
tob48c680419
@ -25,0 +49,4 @@
-DCMAKE_C_FLAGS_MINSIZEREL=${EMBREE_CMAKE_COMPILER_FLAGS_MinSizeRel}
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${EMBREE_CMAKE_COMPILER_FLAGS_RelWithDebInfo}
-DCMAKE_C_FLAGS_DEBUG=${EMBREE_CMAKE_COMPILER_FLAGS_Debug}
)
Can we move this to
options.cmake
and call thisBLENDER_CLANG_CMAKE_FLAGS
?So we can more easily keep it in sync with the Visual Studio flags.
@ -69,0 +113,4 @@
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/embree/lib/tasking.lib ${HARVEST_TARGET}/embree/lib/tasking_d.lib
DEPENDEES install
)
else()
Can deduplicate code here with a second call to
ExternalProject_Add_Step(external_embree after_install
for the sycl/rthwif libraries?@ -70,0 +82,4 @@
IF(EMBREE_EMBREE4_LIBRARY)
SET(EMBREE_SHARED TRUE)
SET(_embree_LIBRARIES ${EMBREE_EMBREE4_LIBRARY})
BREAK()
This logic is still rather fuzzy to me. It seems like it will prefer embree3 over embree4, and break before
embree_rthwif
is found?Can you detect the Embree version first (e.g. with the existence of a header file, or parsing the version number from a header file), and then set the libraries to search for based on that?
@ -84,0 +104,4 @@
SET(EMBREE_MAJOR_VERSION 3)
endif()
if(EMBREE_EMBREE4_SYCL_LIBRARY)
SET(EMBREE_WITH_GPU_SUPPORT TRUE)
I'd prefer to have
EMBREE_LIBRARIES_GPU
instead of this, so we can link to them depending if oneAPI is used.@ -318,3 +318,3 @@
endif()
if(WITH_CYCLES AND WITH_CYCLES_DEVICE_ONEAPI)
if(WITH_CYCLES AND (WITH_CYCLES_DEVICE_ONEAPI OR EMBREE_WITH_GPU_SUPPORT))
Can we not link to
embree_rthwif
andembree4_sycl
instead of this? Or doesembree4
have a dependency on this?@ -850,1 +851,4 @@
set(EMBREE_INCLUDE_DIRS ${LIBDIR}/embree/include)
if(NOT EXISTS ${LIBDIR}/embree/lib/sys.lib)
set(EMBREE_SHARED TRUE)
Is the plan to switch Embree to be a shared library? Since we generally don't have code for both cases in Windows, rather just what we actually use.
I'd be fine with, as we have other shared libraries as well now and maybe it's easier. Not sure if there are any performance implications.
@ -1030,2 +1030,4 @@
PyModule_AddObject(mod, "with_embree", Py_True);
Py_INCREF(Py_True);
PyModule_AddIntConstant(mod, "embree_major_version", EMBREE_MAJOR_VERSION);
# ifdef EMBREE_WITH_GPU_SUPPORT
WITH_EMBREE_GPU
andwith_embree_gpu
I think would be more consistent naming.@ -64,0 +66,4 @@
list(APPEND LIB debug ${SYCL_LIBRARY_DEBUG} optimized ${SYCL_LIBRARY})
else()
list(APPEND LIB ${SYCL_LIBRARY})
endif()
Can this Windows specific logic be kept in
platform_win32.cmake
? We normally don't need to do this debug/optimized distinction in places like this.@ -70,0 +82,4 @@
IF(EMBREE_EMBREE4_LIBRARY)
SET(EMBREE_SHARED TRUE)
SET(_embree_LIBRARIES ${EMBREE_EMBREE4_LIBRARY})
BREAK()
The whole foreach is for the case in which there are no static libraries, as initially.
In that case, there is no embree_rthwif to find and either EMBREE_EMBREE4_LIBRARY or EMBREE_EMBREE3_LIBRARY will exist but not both.
We can determine embree version with the include_dir search (embree4/rtcore.h vs embree3/rtcore.h)
@ -318,3 +318,3 @@
endif()
if(WITH_CYCLES AND WITH_CYCLES_DEVICE_ONEAPI)
if(WITH_CYCLES AND (WITH_CYCLES_DEVICE_ONEAPI OR EMBREE_WITH_GPU_SUPPORT))
embree4 depends on embree_rthwif and embree4_sycl when it's built with GPU support.
@ -850,1 +851,4 @@
set(EMBREE_INCLUDE_DIRS ${LIBDIR}/embree/include)
if(NOT EXISTS ${LIBDIR}/embree/lib/sys.lib)
set(EMBREE_SHARED TRUE)
It's not really a plan but there were already traces for support of Embree as shared lib in the current codebase, and it got useful to me to debug one issue coming from static linking, so I kept it working.
@ -1030,2 +1030,4 @@
PyModule_AddObject(mod, "with_embree", Py_True);
Py_INCREF(Py_True);
PyModule_AddIntConstant(mod, "embree_major_version", EMBREE_MAJOR_VERSION);
# ifdef EMBREE_WITH_GPU_SUPPORT
EMBREE_WITH_GPU_SUPPORT
means embree is built with GPU support, which has implications like the dependency on sycl and its compiler.In my view,
WITH_EMBREE_GPU
would mean it's used from a code path but in current PR, it's not.@ -84,0 +104,4 @@
SET(EMBREE_MAJOR_VERSION 3)
endif()
if(EMBREE_EMBREE4_SYCL_LIBRARY)
SET(EMBREE_WITH_GPU_SUPPORT TRUE)
We can't, when build with dpcpp it'll have sycl references in sys.lib and embree4.lib, regardless if oneAPI is ON or OFF, we're gonna have to link sycl.
@ -318,3 +318,3 @@
endif()
if(WITH_CYCLES AND WITH_CYCLES_DEVICE_ONEAPI)
if(WITH_CYCLES AND (WITH_CYCLES_DEVICE_ONEAPI OR EMBREE_WITH_GPU_SUPPORT))
Ok, it should check
WITH_CYCLES_EMBREE
as well then.@ -1030,2 +1030,4 @@
PyModule_AddObject(mod, "with_embree", Py_True);
Py_INCREF(Py_True);
PyModule_AddIntConstant(mod, "embree_major_version", EMBREE_MAJOR_VERSION);
# ifdef EMBREE_WITH_GPU_SUPPORT
Since it's not used in this PR, let's just leave it out then and add something when its purpose is clear.
89b2383643
tod3f32875fe
d3f32875fe
to2e91f1a31f
To makes things smoother, I propose to first land with just dynamic library + CPU-only support.
I've rebased and squashed the remaining commits while dropping the changes related to building Embree with SYCL support, these will go into the next PR for Embree GPU support.
Xavier Hallade referenced this pull request2023-03-29 14:26:07 +02:00
This looks fine overall now, just one comment.
@ -32,0 +43,4 @@
)
ENDIF()
FILE(READ ${EMBREE_INCLUDE_DIR}/embree${EMBREE_MAJOR_VERSION}/rtcore_config.h _embree_config_header)
Should this check if EMBREE_INCLUDE_DIR was found, to gracefully handle Embree not being found?
@blender-bot build
Accepting assuming the build succeeds.
I'd like a closer look before landing
part of the review only, i still need to check out the blender side of things but that build is still running and i'm heading home for the day.
@ -63,2 +58,2 @@
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/embree/lib/sys.lib ${HARVEST_TARGET}/embree/lib/sys_d.lib
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/embree/lib/tasking.lib ${HARVEST_TARGET}/embree/lib/tasking_d.lib
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/embree/lib/embree4_d.dll ${HARVEST_TARGET}/embree/lib/embree4_d.dll
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/embree/lib/embree4_d.lib ${HARVEST_TARGET}/embree/lib/embree4_d.lib
for convenience here's what this whole block needs to be
@ -25,0 +49,4 @@
-DCMAKE_C_FLAGS_MINSIZEREL=${BLENDER_CLANG_CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${BLENDER_CLANG_CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_C_FLAGS_DEBUG=${EMBREE_CLANG_CMAKE_C_FLAGS_DEBUG}
-DCMAKE_CXX_STANDARD=17
done with e8ca1f142a.
@ -66,3 +59,1 @@
)
endif()
ExternalProject_Add_Step(external_embree after_install
Good catch. Runtime DLLs appeared when switching back to MSVC and I missed using bin when slicing the patch back to have only embree4 + dynamic library.
Thanks for the block. I've pushed the change.
@ -69,0 +113,4 @@
)
if(TARGET external_dpcpp)
ExternalProject_Add_Step(external_embree after_install
COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/embree/lib/embree4_sycl.lib ${HARVEST_TARGET}/embree/lib/embree4_sycl_d.lib
done in d91bc2eea7
@ -32,0 +43,4 @@
)
ENDIF()
IF(EMBREE_INCLUDE_DIR)
ok yes, I've just pushed this change.
@ -850,1 +851,4 @@
set(EMBREE_INCLUDE_DIRS ${LIBDIR}/embree/include)
if(EXISTS ${LIBDIR}/embree/include/embree4/rtcore_config.h)
set(EMBREE_MAJOR_VERSION 4)
as discussed, I now let it be built as a shared library.
@ -1030,2 +1030,4 @@
PyModule_AddObject(mod, "with_embree", Py_True);
Py_INCREF(Py_True);
PyModule_AddIntConstant(mod, "embree_major_version", EMBREE_MAJOR_VERSION);
# ifdef EMBREE_WITH_GPU_SUPPORT
Instead of
EMBREE_WITH_GPU_SUPPORT
, we could useEMBREE_SYCL_SUPPORT
as it's defined in embree config.1f36ad325c
to350fa6fe6c
Provisionary accepted, hinging on that
PLATFORM_BUNDLED_LIBRARIES
fix being done, no need for further review.@ -875,0 +916,4 @@
endif()
endif()
if(NOT EMBREE_STATIC_LIB)
list(APPEND PLATFORM_BUNDLED_LIBRARIES ${EMBREE_ROOT_DIR}/bin/embree${EMBREE_MAJOR_VERSION}$<$<CONFIG:Debug>:_d>.dll)
PLATFORM_BUNDLED_LIBRARIES
wasn't really meant to work yet on windows and just dropped the libs right next to the blender binary. I added support for using theblender.shared
folder in #106348 , this does however mean that the final filenames need to be known at configure time, which precludes the use of generator expressions.should do the trick (also merge main, as #106348 only landed minutes ago)