diff --git a/modules/raycast/SCsub b/modules/raycast/SCsub index 209ebab388d..f3a8e307630 100644 --- a/modules/raycast/SCsub +++ b/modules/raycast/SCsub @@ -15,10 +15,10 @@ if env["builtin_embree"]: embree_src = [ "common/sys/sysinfo.cpp", "common/sys/alloc.cpp", + "common/sys/estring.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", @@ -36,6 +36,7 @@ if env["builtin_embree"]: "kernels/common/rtcore.cpp", "kernels/common/rtcore_builder.cpp", "kernels/common/scene.cpp", + "kernels/common/scene_verify.cpp", "kernels/common/alloc.cpp", "kernels/common/geometry.cpp", "kernels/common/scene_triangle_mesh.cpp", @@ -56,8 +57,6 @@ if env["builtin_embree"]: "kernels/bvh/bvh_builder_twolevel.cpp", "kernels/bvh/bvh_intersector1_bvh4.cpp", "kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp", - "kernels/bvh/bvh_intersector_stream_bvh4.cpp", - "kernels/bvh/bvh_intersector_stream_filters.cpp", ] thirdparty_sources = [thirdparty_dir + file for file in embree_src] diff --git a/modules/raycast/godot_update_embree.py b/modules/raycast/godot_update_embree.py index f7af937c8b7..c1790603650 100644 --- a/modules/raycast/godot_update_embree.py +++ b/modules/raycast/godot_update_embree.py @@ -1,6 +1,13 @@ -import glob, os, shutil, subprocess, re +import glob +import os +import re +import shutil +import stat +import subprocess +from types import TracebackType +from typing import Any, Callable, Tuple, Type -git_tag = "v3.13.5" +git_tag = "v4.3.1" include_dirs = [ "common/tasking", @@ -15,7 +22,7 @@ include_dirs = [ "common/simd", "common/simd/arm", "common/simd/wasm", - "include/embree3", + "include/embree4", "kernels/subdiv", "kernels/geometry", ] @@ -23,10 +30,10 @@ include_dirs = [ cpp_files = [ "common/sys/sysinfo.cpp", "common/sys/alloc.cpp", + "common/sys/estring.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", @@ -44,6 +51,7 @@ cpp_files = [ "kernels/common/rtcore.cpp", "kernels/common/rtcore_builder.cpp", "kernels/common/scene.cpp", + "kernels/common/scene_verify.cpp", "kernels/common/alloc.cpp", "kernels/common/geometry.cpp", "kernels/common/scene_triangle_mesh.cpp", @@ -65,26 +73,58 @@ cpp_files = [ "kernels/bvh/bvh_intersector1.cpp", "kernels/bvh/bvh_intersector1_bvh4.cpp", "kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp", - "kernels/bvh/bvh_intersector_stream_bvh4.cpp", - "kernels/bvh/bvh_intersector_stream_filters.cpp", "kernels/bvh/bvh_intersector_hybrid.cpp", - "kernels/bvh/bvh_intersector_stream.cpp", ] -os.chdir("../../thirdparty") +config_files = [ + "kernels/config.h.in", + "kernels/rtcore_config.h.in", +] + +license_file = "LICENSE.txt" + +os.chdir(f"{os.path.dirname(__file__)}/../../thirdparty") dir_name = "embree" if os.path.exists(dir_name): shutil.rmtree(dir_name) +# In case something went wrong and embree-tmp stayed on the system. +if os.path.exists("embree-tmp"): + shutil.rmtree("embree-tmp") + subprocess.run(["git", "clone", "https://github.com/embree/embree.git", "embree-tmp"]) os.chdir("embree-tmp") subprocess.run(["git", "checkout", git_tag]) commit_hash = str(subprocess.check_output(["git", "rev-parse", "HEAD"], universal_newlines=True)).strip() + +def on_rm_error( + function: Callable[..., Any], path: str, excinfo: Tuple[Type[Exception], Exception, TracebackType] +) -> None: + """ + Error handler for `shutil.rmtree()`. + + If the error is due to read-only files, + it will change the file permissions and retry. + """ + os.chmod(path, stat.S_IWRITE) + os.unlink(path) + + +# 3.12 Python and beyond should replace `onerror` with `onexc`. +# We remove the .git directory because it contains +# a lot of read-only files that are problematic on Windows. +shutil.rmtree(".git", onerror=on_rm_error) + all_files = set(cpp_files) +for config_file in config_files: + all_files.add(config_file) + +all_files.add(license_file) + dest_dir = os.path.join("..", dir_name) for include_dir in include_dirs: headers = glob.iglob(os.path.join(include_dir, "*.h")) @@ -105,87 +145,8 @@ with open(os.path.join(dest_dir, "kernels/hash.h"), "w", encoding="utf-8", newli """ ) -with open(os.path.join(dest_dir, "kernels/config.h"), "w", encoding="utf-8", newline="\n") as config_file: - config_file.write( - """// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -/* #undef EMBREE_RAY_MASK */ -/* #undef EMBREE_STAT_COUNTERS */ -/* #undef EMBREE_BACKFACE_CULLING */ -/* #undef EMBREE_BACKFACE_CULLING_CURVES */ -#define EMBREE_FILTER_FUNCTION -/* #undef EMBREE_IGNORE_INVALID_RAYS */ -#define EMBREE_GEOMETRY_TRIANGLE -/* #undef EMBREE_GEOMETRY_QUAD */ -/* #undef EMBREE_GEOMETRY_CURVE */ -/* #undef EMBREE_GEOMETRY_SUBDIVISION */ -/* #undef EMBREE_GEOMETRY_USER */ -/* #undef EMBREE_GEOMETRY_INSTANCE */ -/* #undef EMBREE_GEOMETRY_GRID */ -/* #undef EMBREE_GEOMETRY_POINT */ -#define EMBREE_RAY_PACKETS -/* #undef EMBREE_COMPACT_POLYS */ - -#define EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR 2.0 -#define EMBREE_DISC_POINT_SELF_INTERSECTION_AVOIDANCE - -#if defined(EMBREE_GEOMETRY_TRIANGLE) - #define IF_ENABLED_TRIS(x) x -#else - #define IF_ENABLED_TRIS(x) -#endif - -#if defined(EMBREE_GEOMETRY_QUAD) - #define IF_ENABLED_QUADS(x) x -#else - #define IF_ENABLED_QUADS(x) -#endif - -#if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT) - #define IF_ENABLED_CURVES_OR_POINTS(x) x -#else - #define IF_ENABLED_CURVES_OR_POINTS(x) -#endif - -#if defined(EMBREE_GEOMETRY_CURVE) - #define IF_ENABLED_CURVES(x) x -#else - #define IF_ENABLED_CURVES(x) -#endif - -#if defined(EMBREE_GEOMETRY_POINT) - #define IF_ENABLED_POINTS(x) x -#else - #define IF_ENABLED_POINTS(x) -#endif - -#if defined(EMBREE_GEOMETRY_SUBDIVISION) - #define IF_ENABLED_SUBDIV(x) x -#else - #define IF_ENABLED_SUBDIV(x) -#endif - -#if defined(EMBREE_GEOMETRY_USER) - #define IF_ENABLED_USER(x) x -#else - #define IF_ENABLED_USER(x) -#endif - -#if defined(EMBREE_GEOMETRY_INSTANCE) - #define IF_ENABLED_INSTANCE(x) x -#else - #define IF_ENABLED_INSTANCE(x) -#endif - -#if defined(EMBREE_GEOMETRY_GRID) - #define IF_ENABLED_GRIDS(x) x -#else - #define IF_ENABLED_GRIDS(x) -#endif -""" - ) - +for config_file in config_files: + os.rename(os.path.join(dest_dir, config_file), os.path.join(dest_dir, config_file[:-3])) with open("CMakeLists.txt", "r", encoding="utf-8") as cmake_file: cmake_content = cmake_file.read() @@ -193,70 +154,25 @@ with open("CMakeLists.txt", "r", encoding="utf-8") as cmake_file: minor_version = int(re.compile(r"EMBREE_VERSION_MINOR\s(\d+)").findall(cmake_content)[0]) patch_version = int(re.compile(r"EMBREE_VERSION_PATCH\s(\d+)").findall(cmake_content)[0]) +shutil.move(os.path.join(dest_dir, "kernels/rtcore_config.h"), os.path.join(dest_dir, ("include/embree4/"))) + with open( - os.path.join(dest_dir, "include/embree3/rtcore_config.h"), "w", encoding="utf-8", newline="\n" -) as config_file: - config_file.write( - f"""// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#define RTC_VERSION_MAJOR {major_version} -#define RTC_VERSION_MINOR {minor_version} -#define RTC_VERSION_PATCH {patch_version} -#define RTC_VERSION {major_version}{minor_version:02d}{patch_version:02d} -#define RTC_VERSION_STRING "{major_version}.{minor_version}.{patch_version}" - -#define RTC_MAX_INSTANCE_LEVEL_COUNT 1 - -#define EMBREE_MIN_WIDTH 0 -#define RTC_MIN_WIDTH EMBREE_MIN_WIDTH - -#if !defined(EMBREE_STATIC_LIB) -# define EMBREE_STATIC_LIB -#endif -/* #undef EMBREE_API_NAMESPACE*/ - -#if defined(EMBREE_API_NAMESPACE) -# define RTC_NAMESPACE -# define RTC_NAMESPACE_BEGIN namespace {{ -# define RTC_NAMESPACE_END }} -# define RTC_NAMESPACE_USE using namespace; -# define RTC_API_EXTERN_C -# undef EMBREE_API_NAMESPACE -#else -# define RTC_NAMESPACE_BEGIN -# define RTC_NAMESPACE_END -# define RTC_NAMESPACE_USE -# if defined(__cplusplus) -# define RTC_API_EXTERN_C extern "C" -# else -# define RTC_API_EXTERN_C -# endif -#endif - -#if defined(ISPC) -# define RTC_API_IMPORT extern "C" unmasked -# define RTC_API_EXPORT extern "C" unmasked -#elif defined(EMBREE_STATIC_LIB) -# define RTC_API_IMPORT RTC_API_EXTERN_C -# define RTC_API_EXPORT RTC_API_EXTERN_C -#elif defined(_WIN32) -# define RTC_API_IMPORT RTC_API_EXTERN_C __declspec(dllimport) -# define RTC_API_EXPORT RTC_API_EXTERN_C __declspec(dllexport) -#else -# define RTC_API_IMPORT RTC_API_EXTERN_C -# define RTC_API_EXPORT RTC_API_EXTERN_C __attribute__ ((visibility ("default"))) -#endif - -#if defined(RTC_EXPORT_API) -# define RTC_API RTC_API_EXPORT -#else -# define RTC_API RTC_API_IMPORT -#endif -""" - ) + os.path.join(dest_dir, "include/embree4/rtcore_config.h"), "r+", encoding="utf-8", newline="\n" +) as rtcore_config: + lines = rtcore_config.readlines() + rtcore_config.seek(0) + for i, line in enumerate(lines): + if line.startswith("#define RTC_VERSION_MAJOR"): + lines[i : i + 5] = [ + f"#define RTC_VERSION_MAJOR {major_version}\n", + f"#define RTC_VERSION_MINOR {minor_version}\n", + f"#define RTC_VERSION_PATCH {patch_version}\n", + f"#define RTC_VERSION {major_version}{minor_version:02d}{patch_version:02d}\n", + f'#define RTC_VERSION_STRING "{major_version}.{minor_version}.{patch_version}"\n', + ] + break + rtcore_config.writelines(lines) + rtcore_config.truncate() os.chdir("..") shutil.rmtree("embree-tmp") @@ -264,4 +180,4 @@ shutil.rmtree("embree-tmp") subprocess.run(["git", "restore", "embree/patches"]) for patch in os.listdir("embree/patches"): - subprocess.run(["git", "apply", "embree/patches/" + patch]) + subprocess.run(["git", "apply", f"embree/patches/{patch}"]) diff --git a/modules/raycast/lightmap_raycaster_embree.cpp b/modules/raycast/lightmap_raycaster_embree.cpp index 2a66c36d538..84d9e19a3f2 100644 --- a/modules/raycast/lightmap_raycaster_embree.cpp +++ b/modules/raycast/lightmap_raycaster_embree.cpp @@ -69,11 +69,12 @@ void LightmapRaycasterEmbree::filter_function(const struct RTCFilterFunctionNArg } bool LightmapRaycasterEmbree::intersect(Ray &r_ray) { - RTCIntersectContext context; - - rtcInitIntersectContext(&context); - - rtcIntersect1(embree_scene, &context, (RTCRayHit *)&r_ray); + RTCRayQueryContext context; + rtcInitRayQueryContext(&context); + RTCIntersectArguments args; + rtcInitIntersectArguments(&args); + args.context = &context; + rtcIntersect1(embree_scene, (RTCRayHit *)&r_ray, &args); return r_ray.geomID != RTC_INVALID_GEOMETRY_ID; } diff --git a/modules/raycast/lightmap_raycaster_embree.h b/modules/raycast/lightmap_raycaster_embree.h index d1999e329e2..2b4530a3685 100644 --- a/modules/raycast/lightmap_raycaster_embree.h +++ b/modules/raycast/lightmap_raycaster_embree.h @@ -37,7 +37,7 @@ #include "core/object/object.h" #include "scene/3d/lightmapper.h" -#include +#include class LightmapRaycasterEmbree : public LightmapRaycaster { GDCLASS(LightmapRaycasterEmbree, LightmapRaycaster); diff --git a/modules/raycast/raycast_occlusion_cull.cpp b/modules/raycast/raycast_occlusion_cull.cpp index 1153832febe..94d8b267d1a 100644 --- a/modules/raycast/raycast_occlusion_cull.cpp +++ b/modules/raycast/raycast_occlusion_cull.cpp @@ -488,11 +488,13 @@ void RaycastOcclusionCull::Scenario::update() { } void RaycastOcclusionCull::Scenario::_raycast(uint32_t p_idx, const RaycastThreadData *p_raycast_data) const { - RTCIntersectContext ctx; - rtcInitIntersectContext(&ctx); - ctx.flags = RTC_INTERSECT_CONTEXT_FLAG_COHERENT; - - rtcIntersect16((const int *)&p_raycast_data->masks[p_idx * TILE_RAYS], ebr_scene[current_scene_idx], &ctx, &p_raycast_data->rays[p_idx]); + RTCRayQueryContext context; + rtcInitRayQueryContext(&context); + RTCIntersectArguments args; + rtcInitIntersectArguments(&args); + args.flags = RTC_RAY_QUERY_FLAG_COHERENT; + args.context = &context; + rtcIntersect16((const int *)&p_raycast_data->masks[p_idx * TILE_RAYS], ebr_scene[current_scene_idx], &p_raycast_data->rays[p_idx], &args); } void RaycastOcclusionCull::Scenario::raycast(CameraRayTile *r_rays, const uint32_t *p_valid_masks, uint32_t p_tile_count) const { diff --git a/modules/raycast/raycast_occlusion_cull.h b/modules/raycast/raycast_occlusion_cull.h index a9c1ebb6924..335a6856728 100644 --- a/modules/raycast/raycast_occlusion_cull.h +++ b/modules/raycast/raycast_occlusion_cull.h @@ -40,7 +40,7 @@ #include "scene/resources/mesh.h" #include "servers/rendering/renderer_scene_occlusion_cull.h" -#include +#include class RaycastOcclusionCull : public RendererSceneOcclusionCull { typedef RTCRayHit16 CameraRayTile; diff --git a/modules/raycast/static_raycaster_embree.cpp b/modules/raycast/static_raycaster_embree.cpp index f9076d30dde..a6ad340397f 100644 --- a/modules/raycast/static_raycaster_embree.cpp +++ b/modules/raycast/static_raycaster_embree.cpp @@ -53,9 +53,12 @@ void StaticRaycasterEmbree::free() { } bool StaticRaycasterEmbree::intersect(Ray &r_ray) { - RTCIntersectContext context; - rtcInitIntersectContext(&context); - rtcIntersect1(embree_scene, &context, (RTCRayHit *)&r_ray); + RTCRayQueryContext context; + rtcInitRayQueryContext(&context); + RTCIntersectArguments args; + rtcInitIntersectArguments(&args); + args.context = &context; + rtcIntersect1(embree_scene, (RTCRayHit *)&r_ray, &args); return r_ray.geomID != RTC_INVALID_GEOMETRY_ID; } diff --git a/modules/raycast/static_raycaster_embree.h b/modules/raycast/static_raycaster_embree.h index 24e1c7b92f9..3ffab32badc 100644 --- a/modules/raycast/static_raycaster_embree.h +++ b/modules/raycast/static_raycaster_embree.h @@ -35,7 +35,7 @@ #include "core/math/static_raycaster.h" -#include +#include class StaticRaycasterEmbree : public StaticRaycaster { GDCLASS(StaticRaycasterEmbree, StaticRaycaster); diff --git a/thirdparty/README.md b/thirdparty/README.md index 0520440e52a..be386a3920f 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -172,13 +172,15 @@ Files extracted from upstream source: ## embree - Upstream: https://github.com/embree/embree -- Version: 3.13.5 (698442324ccddd11725fb8875275dc1384f7fb40, 2022) +- Version: 4.3.1 (daa8de0e714e18ad5e5c9841b67c1950d9c91c51, 2024) - 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` +- All config files listed in `modules/raycast/godot_update_embree.py` +- `LICENSE.txt` 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. diff --git a/thirdparty/embree/LICENSE.txt b/thirdparty/embree/LICENSE.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/thirdparty/embree/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/thirdparty/embree/common/algorithms/parallel_any_of.h b/thirdparty/embree/common/algorithms/parallel_any_of.h index a64e4a18895..a95c1f6490a 100644 --- a/thirdparty/embree/common/algorithms/parallel_any_of.h +++ b/thirdparty/embree/common/algorithms/parallel_any_of.h @@ -12,7 +12,8 @@ namespace embree template __forceinline bool parallel_any_of (Index first, Index last, UnaryPredicate pred) { - bool ret = false; + std::atomic_bool ret; + ret = false; #if defined(TASKING_TBB) #if TBB_INTERFACE_VERSION >= 12002 diff --git a/thirdparty/embree/common/algorithms/parallel_for.h b/thirdparty/embree/common/algorithms/parallel_for.h index 6d411e4852e..fd5213e70a9 100644 --- a/thirdparty/embree/common/algorithms/parallel_for.h +++ b/thirdparty/embree/common/algorithms/parallel_for.h @@ -5,7 +5,7 @@ #include "../tasking/taskscheduler.h" #include "../sys/array.h" -#include "../math/math.h" +#include "../math/emath.h" #include "../math/range.h" namespace embree @@ -14,17 +14,17 @@ namespace embree template __forceinline void parallel_for( const Index N, const Func& func) { -#if defined(TASKING_INTERNAL) +#if defined(TASKING_INTERNAL) && !defined(TASKING_TBB) if (N) { + TaskScheduler::TaskGroupContext context; TaskScheduler::spawn(Index(0),N,Index(1),[&] (const range& r) { assert(r.size() == 1); func(r.begin()); - }); - if (!TaskScheduler::wait()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + },&context); + TaskScheduler::wait(); + if (context.cancellingException != nullptr) { + std::rethrow_exception(context.cancellingException); + } } #elif defined(TASKING_TBB) #if TBB_INTERFACE_VERSION >= 12002 @@ -33,19 +33,13 @@ namespace embree func(i); },context); if (context.is_group_execution_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #else tbb::parallel_for(Index(0),N,Index(1),[&](Index i) { func(i); }); if (tbb::task::self().is_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #endif #elif defined(TASKING_PPL) @@ -62,13 +56,13 @@ namespace embree __forceinline void parallel_for( const Index first, const Index last, const Index minStepSize, const Func& func) { assert(first <= last); -#if defined(TASKING_INTERNAL) - TaskScheduler::spawn(first,last,minStepSize,func); - if (!TaskScheduler::wait()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- +#if defined(TASKING_INTERNAL) && !defined(TASKING_TBB) + TaskScheduler::TaskGroupContext context; + TaskScheduler::spawn(first,last,minStepSize,func,&context); + TaskScheduler::wait(); + if (context.cancellingException != nullptr) { + std::rethrow_exception(context.cancellingException); + } #elif defined(TASKING_TBB) #if TBB_INTERFACE_VERSION >= 12002 @@ -77,19 +71,13 @@ namespace embree func(range(r.begin(),r.end())); },context); if (context.is_group_execution_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #else tbb::parallel_for(tbb::blocked_range(first,last,minStepSize),[&](const tbb::blocked_range& r) { func(range(r.begin(),r.end())); }); if (tbb::task::self().is_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #endif #elif defined(TASKING_PPL) @@ -121,19 +109,13 @@ namespace embree func(i); },tbb::simple_partitioner(),context); if (context.is_group_execution_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #else tbb::parallel_for(Index(0),N,Index(1),[&](Index i) { func(i); },tbb::simple_partitioner()); if (tbb::task::self().is_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #endif } @@ -148,19 +130,13 @@ namespace embree func(i); },ap,context); if (context.is_group_execution_cancelled()) - // -- GODOT start -- - // throw std::runtime_error("task cancelled"); - abort(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #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(); - // -- GODOT end -- + throw std::runtime_error("task cancelled"); #endif } diff --git a/thirdparty/embree/common/algorithms/parallel_partition.h b/thirdparty/embree/common/algorithms/parallel_partition.h index a1cbdc8e047..53d4d6f0dbc 100644 --- a/thirdparty/embree/common/algorithms/parallel_partition.h +++ b/thirdparty/embree/common/algorithms/parallel_partition.h @@ -175,8 +175,8 @@ namespace embree /* calculate all left and right ranges that are on the wrong global side */ size_t numMisplacedRangesLeft = 0; size_t numMisplacedRangesRight = 0; - size_t numMisplacedItemsLeft = 0; - size_t numMisplacedItemsRight = 0; + size_t numMisplacedItemsLeft MAYBE_UNUSED = 0; + size_t numMisplacedItemsRight MAYBE_UNUSED = 0; for (size_t i=0; i __forceinline Value parallel_reduce( const Index first, const Index last, const Index minStepSize, const Value& identity, const Func& func, const Reduction& reduction ) { -#if defined(TASKING_INTERNAL) +#if defined(TASKING_INTERNAL) && !defined(TASKING_TBB) /* fast path for small number of iterations */ Index taskCount = (last-first+minStepSize-1)/minStepSize; diff --git a/thirdparty/embree/common/lexers/stream.h b/thirdparty/embree/common/lexers/stream.h index a40c15f8eb5..9ad72af4e6d 100644 --- a/thirdparty/embree/common/lexers/stream.h +++ b/thirdparty/embree/common/lexers/stream.h @@ -6,7 +6,7 @@ #include "../sys/platform.h" #include "../sys/ref.h" #include "../sys/filename.h" -#include "../sys/string.h" +#include "../sys/estring.h" #include #include @@ -122,17 +122,16 @@ namespace embree class FileStream : public Stream { public: - - FileStream (FILE* file, const std::string& name = "file") - : file(file), lineNumber(1), colNumber(0), charNumber(0), name(std::shared_ptr(new std::string(name))) {} - FileStream (const FileName& fileName) : lineNumber(1), colNumber(0), charNumber(0), name(std::shared_ptr(new std::string(fileName.str()))) { - file = fopen(fileName.c_str(),"r"); - if (file == nullptr) THROW_RUNTIME_ERROR("cannot open file " + fileName.str()); + if (ifs) ifs.close(); + ifs.open(fileName.str()); + if (!ifs.is_open()) THROW_RUNTIME_ERROR("cannot open file " + fileName.str()); + } + ~FileStream() { + if (ifs) ifs.close(); } - ~FileStream() { if (file) fclose(file); } public: ParseLocation location() { @@ -140,14 +139,15 @@ namespace embree } int next() { - int c = fgetc(file); + int c = ifs.get(); if (c == '\n') { lineNumber++; colNumber = 0; } else if (c != '\r') colNumber++; charNumber++; return c; } + private: - FILE* file; + std::ifstream ifs; ssize_t lineNumber; /// the line number the token is from ssize_t colNumber; /// the character number in the current line ssize_t charNumber; /// the character in the file diff --git a/thirdparty/embree/common/lexers/stringstream.cpp b/thirdparty/embree/common/lexers/stringstream.cpp index a037869506d..c93da0b420c 100644 --- a/thirdparty/embree/common/lexers/stringstream.cpp +++ b/thirdparty/embree/common/lexers/stringstream.cpp @@ -41,7 +41,9 @@ namespace embree int c = cin->get(); // -- GODOT start -- // if (!isValidChar(c)) throw std::runtime_error("invalid character "+std::string(1,c)+" in input"); - if (!isValidChar(c)) abort(); + if (!isValidChar(c)) { + abort(); + } // -- GODOT end -- str.push_back((char)c); } diff --git a/thirdparty/embree/common/lexers/tokenstream.cpp b/thirdparty/embree/common/lexers/tokenstream.cpp index 6ed6f2045a7..fe9de641dbc 100644 --- a/thirdparty/embree/common/lexers/tokenstream.cpp +++ b/thirdparty/embree/common/lexers/tokenstream.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "tokenstream.h" -#include "../math/math.h" +#include "../math/emath.h" namespace embree { diff --git a/thirdparty/embree/common/math/affinespace.h b/thirdparty/embree/common/math/affinespace.h index 9d4a0f08468..f3e54046391 100644 --- a/thirdparty/embree/common/math/affinespace.h +++ b/thirdparty/embree/common/math/affinespace.h @@ -337,7 +337,7 @@ namespace embree if (D) *D = sqrtf(D_x); return true; } - + __forceinline void AffineSpace3fa_store_unaligned(const AffineSpace3fa &source, AffineSpace3fa* ptr) { Vec3fa::storeu(&ptr->l.vx, source.l.vx); diff --git a/thirdparty/embree/common/math/bbox.h b/thirdparty/embree/common/math/bbox.h index e4eb3df9a4b..651b29a8fe7 100644 --- a/thirdparty/embree/common/math/bbox.h +++ b/thirdparty/embree/common/math/bbox.h @@ -56,6 +56,11 @@ namespace embree return BBox(min(a.lower, b.lower), max(a.upper, b.upper)); } + /*! intersects two boxes */ + __forceinline static const BBox intersect (const BBox& a, const BBox& b) { + return BBox(max(a.lower, b.lower), min(a.upper, b.upper)); + } + /*! enlarge box by some scaling factor */ __forceinline BBox enlarge_by(const float a) const { return BBox(lower - T(a)*abs(lower), upper + T(a)*abs(upper)); diff --git a/thirdparty/embree/common/math/col3.h b/thirdparty/embree/common/math/col3.h index 3f50c043934..4576bc517dd 100644 --- a/thirdparty/embree/common/math/col3.h +++ b/thirdparty/embree/common/math/col3.h @@ -3,7 +3,7 @@ #pragma once -#include "math.h" +#include "emath.h" namespace embree { diff --git a/thirdparty/embree/common/math/col4.h b/thirdparty/embree/common/math/col4.h index 788508516bb..4ef916cc3a2 100644 --- a/thirdparty/embree/common/math/col4.h +++ b/thirdparty/embree/common/math/col4.h @@ -3,7 +3,7 @@ #pragma once -#include "math.h" +#include "emath.h" namespace embree { diff --git a/thirdparty/embree/common/math/color.h b/thirdparty/embree/common/math/color.h index e62e4ad2a4d..8b28ff94472 100644 --- a/thirdparty/embree/common/math/color.h +++ b/thirdparty/embree/common/math/color.h @@ -3,6 +3,10 @@ #pragma once +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +# include "color_sycl.h" +#else + #include "constants.h" #include "col3.h" #include "col4.h" @@ -64,6 +68,10 @@ namespace embree d.b = (unsigned char)(s[2]); d.a = (unsigned char)(s[3]); } + __forceinline void set(float &f) const + { + f = 0.2126f*r+0.7125f*g+0.0722f*b; // sRGB luminance. + } //////////////////////////////////////////////////////////////////////////////// /// Constants @@ -256,3 +264,5 @@ namespace embree return cout << "(" << a.r << ", " << a.g << ", " << a.b << ")"; } } + +#endif diff --git a/thirdparty/embree/common/math/color_sycl.h b/thirdparty/embree/common/math/color_sycl.h new file mode 100644 index 00000000000..41b89ddecc7 --- /dev/null +++ b/thirdparty/embree/common/math/color_sycl.h @@ -0,0 +1,219 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "constants.h" +#include "col3.h" +#include "col4.h" + +#include "../simd/sse.h" + +namespace embree +{ + //////////////////////////////////////////////////////////////////////////////// + /// SSE RGBA Color Class + //////////////////////////////////////////////////////////////////////////////// + + struct Color4 + { + struct { float r,g,b,a; }; + + //////////////////////////////////////////////////////////////////////////////// + /// Construction + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Color4 () {} + //__forceinline Color4 ( const __m128 a ) : m128(a) {} + + __forceinline explicit Color4 (const float v) : r(v), g(v), b(v), a(v) {} + __forceinline Color4 (const float r, const float g, const float b, const float a) : r(r), g(g), b(b), a(a) {} + + __forceinline explicit Color4 ( const Col3uc& other ) : r(other.r/255.0f), g(other.g/255.0f), b(other.b/255.0f), a(1.0f) {} + __forceinline explicit Color4 ( const Col3f& other ) : r(other.r), g(other.g), b(other.b), a(1.0f) {} + __forceinline explicit Color4 ( const Col4uc& other ) : r(other.r/255.0f), g(other.g/255.0f), b(other.b/255.0f), a(other.a/255.0f) {} + __forceinline explicit Color4 ( const Col4f& other ) : r(other.r), g(other.g), b(other.b), a(other.a) {} + + //__forceinline Color4 ( const Color4& other ) : m128(other.m128) {} + //__forceinline Color4& operator=( const Color4& other ) { m128 = other.m128; return *this; } + + //__forceinline operator const __m128&() const { return m128; } + //__forceinline operator __m128&() { return m128; } + + //////////////////////////////////////////////////////////////////////////////// + /// Set + //////////////////////////////////////////////////////////////////////////////// + + __forceinline void set(Col3f& d) const { d.r = r; d.g = g; d.b = b; } + __forceinline void set(Col4f& d) const { d.r = r; d.g = g; d.b = b; d.a = a; } + + __forceinline void set(Col3uc& d) const + { + d.r = (unsigned char)(clamp(r)*255.0f); + d.g = (unsigned char)(clamp(g)*255.0f); + d.b = (unsigned char)(clamp(b)*255.0f); + } + + __forceinline void set(Col4uc& d) const + { + d.r = (unsigned char)(clamp(r)*255.0f); + d.g = (unsigned char)(clamp(g)*255.0f); + d.b = (unsigned char)(clamp(b)*255.0f); + d.a = (unsigned char)(clamp(a)*255.0f); + } + __forceinline void set(float &f) const + { + f = 0.2126f*r+0.7125f*g+0.0722f*b; // sRGB luminance. + } + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Color4( ZeroTy ) : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {} + __forceinline Color4( OneTy ) : r(1.0f), g(1.0f), b(1.0f), a(1.0f) {} + //__forceinline Color4( PosInfTy ) : m128(_mm_set1_ps(pos_inf)) {} + //__forceinline Color4( NegInfTy ) : m128(_mm_set1_ps(neg_inf)) {} + }; + + //////////////////////////////////////////////////////////////////////////////// + /// SSE RGB Color Class + //////////////////////////////////////////////////////////////////////////////// + + struct Color + { + struct { float r,g,b; }; + + //////////////////////////////////////////////////////////////////////////////// + /// Construction + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Color () {} + //__forceinline Color ( const __m128 a ) : m128(a) {} + + __forceinline explicit Color (const float v) : r(v), g(v), b(v) {} + __forceinline Color (const float r, const float g, const float b) : r(r), g(g), b(b) {} + + //__forceinline Color ( const Color& other ) : m128(other.m128) {} + //__forceinline Color& operator=( const Color& other ) { m128 = other.m128; return *this; } + + //__forceinline Color ( const Color4& other ) : m128(other.m128) {} + //__forceinline Color& operator=( const Color4& other ) { m128 = other.m128; return *this; } + + //__forceinline operator const __m128&() const { return m128; } + //__forceinline operator __m128&() { return m128; } + + //////////////////////////////////////////////////////////////////////////////// + /// Set + //////////////////////////////////////////////////////////////////////////////// + + __forceinline void set(Col3f& d) const { d.r = r; d.g = g; d.b = b; } + __forceinline void set(Col4f& d) const { d.r = r; d.g = g; d.b = b; d.a = 1.0f; } + +#if 0 + __forceinline void set(Col3uc& d) const + { + vfloat4 s = clamp(vfloat4(m128))*255.0f; + d.r = (unsigned char)(s[0]); + d.g = (unsigned char)(s[1]); + d.b = (unsigned char)(s[2]); + } + __forceinline void set(Col4uc& d) const + { + vfloat4 s = clamp(vfloat4(m128))*255.0f; + d.r = (unsigned char)(s[0]); + d.g = (unsigned char)(s[1]); + d.b = (unsigned char)(s[2]); + d.a = 255; + } +#endif + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Color( ZeroTy ) : r(0.0f), g(0.0f), b(0.0f) {} + __forceinline Color( OneTy ) : r(1.0f), g(1.0f), b(1.0f) {} + //__forceinline Color( PosInfTy ) : m128(_mm_set1_ps(pos_inf)) {} + //__forceinline Color( NegInfTy ) : m128(_mm_set1_ps(neg_inf)) {} + }; + + //////////////////////////////////////////////////////////////////////////////// + /// Unary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const Color operator +( const Color& a ) { return a; } + __forceinline const Color operator -( const Color& a ) { return Color(-a.r, -a.g, -a.b); } + __forceinline const Color abs ( const Color& a ) { return Color(abs(a.r), abs(a.g), abs(a.b)); } + __forceinline const Color rcp ( const Color& a ) { return Color(1.0f/a.r, 1.0f/a.g, 1.0f/a.b); } + __forceinline const Color rsqrt( const Color& a ) { return Color(1.0f/sqrt(a.r), 1.0f/sqrt(a.g), 1.0f/sqrt(a.b)); } + __forceinline const Color sqrt ( const Color& a ) { return Color(sqrt(a.r), sqrt(a.g), sqrt(a.b)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Binary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const Color operator +( const Color& a, const Color& b ) { return Color(a.r+b.r, a.g+b.g, a.b+b.b); } + __forceinline const Color operator -( const Color& a, const Color& b ) { return Color(a.r-b.r, a.g-b.g, a.b-b.b); } + __forceinline const Color operator *( const Color& a, const Color& b ) { return Color(a.r*b.r, a.g*b.g, a.b*b.b); } + __forceinline const Color operator *( const Color& a, const float b ) { return a * Color(b); } + __forceinline const Color operator *( const float a, const Color& b ) { return Color(a) * b; } + __forceinline const Color operator /( const Color& a, const Color& b ) { return a * rcp(b); } + __forceinline const Color operator /( const Color& a, const float b ) { return a * rcp(b); } + + __forceinline const Color min( const Color& a, const Color& b ) { return Color(min(a.r,b.r), min(a.g,b.g), min(a.b,b.b)); } + __forceinline const Color max( const Color& a, const Color& b ) { return Color(max(a.r,b.r), max(a.g,b.g), max(a.b,b.b)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Assignment Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const Color operator+=(Color& a, const Color& b) { return a = a + b; } + __forceinline const Color operator-=(Color& a, const Color& b) { return a = a - b; } + __forceinline const Color operator*=(Color& a, const Color& b) { return a = a * b; } + __forceinline const Color operator/=(Color& a, const Color& b) { return a = a / b; } + __forceinline const Color operator*=(Color& a, const float b ) { return a = a * b; } + __forceinline const Color operator/=(Color& a, const float b ) { return a = a / b; } + + //////////////////////////////////////////////////////////////////////////////// + /// Reductions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float reduce_add(const Color& v) { return v.r+v.g+v.b; } + __forceinline float reduce_mul(const Color& v) { return v.r*v.g*v.b; } + __forceinline float reduce_min(const Color& v) { return min(v.r,v.g,v.b); } + __forceinline float reduce_max(const Color& v) { return max(v.r,v.g,v.b); } + + //////////////////////////////////////////////////////////////////////////////// + /// Comparison Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool operator ==( const Color& a, const Color& b ) { return a.r == b.r && a.g == b.g && a.b == b.b; } + __forceinline bool operator !=( const Color& a, const Color& b ) { return a.r != b.r || a.g != b.g || a.b != b.b; } + __forceinline bool operator < ( const Color& a, const Color& b ) { + if (a.r != b.r) return a.r < b.r; + if (a.g != b.g) return a.g < b.g; + if (a.b != b.b) return a.b < b.b; + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Select + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const Color select( bool s, const Color& t, const Color& f ) { + return s ? t : f; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Special Operators + //////////////////////////////////////////////////////////////////////////////// + + /*! computes luminance of a color */ + __forceinline float luminance (const Color& a) { return madd(0.212671f,a.r,madd(0.715160f,a.g,0.072169f*a.b)); } + + /*! output operator */ + inline std::ostream& operator<<(std::ostream& cout, const Color& a) { + return cout << "(" << a.r << ", " << a.g << ", " << a.b << ")"; + } +} diff --git a/thirdparty/embree/common/math/math.h b/thirdparty/embree/common/math/emath.h similarity index 97% rename from thirdparty/embree/common/math/math.h rename to thirdparty/embree/common/math/emath.h index 7930c177271..22a89a7669a 100644 --- a/thirdparty/embree/common/math/math.h +++ b/thirdparty/embree/common/math/emath.h @@ -8,6 +8,10 @@ #include "constants.h" #include +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +# include "math_sycl.h" +#else + #if defined(__ARM_NEON) #include "../simd/arm/emulation.h" #else @@ -44,6 +48,9 @@ namespace embree __forceinline int toInt (const float& a) { return int(a); } __forceinline float toFloat(const int& a) { return float(a); } + __forceinline int asInt (const float& a) { return *((int*)&a); } + __forceinline float asFloat(const int& a) { return *((float*)&a); } + #if defined(__WIN32__) __forceinline bool finite ( const float x ) { return _finite(x) != 0; } #endif @@ -351,7 +358,11 @@ __forceinline float nmsub ( const float a, const float b, const float c) { retur __forceinline int select(bool s, int t, int f) { return s ? t : f; } __forceinline float select(bool s, float t, float f) { return s ? t : f; } - __forceinline bool all(bool s) { return s; } + __forceinline bool none(bool s) { return !s; } + __forceinline bool all (bool s) { return s; } + __forceinline bool any (bool s) { return s; } + + __forceinline unsigned movemask (bool s) { return (unsigned)s; } __forceinline float lerp(const float v0, const float v1, const float t) { return madd(1.0f-t,v0,t*v1); @@ -453,3 +464,5 @@ __forceinline float nmsub ( const float a, const float b, const float c) { retur return x | (y << 1) | (z << 2); } } + +#endif diff --git a/thirdparty/embree/common/math/lbbox.h b/thirdparty/embree/common/math/lbbox.h index 2b397a05c88..76191997806 100644 --- a/thirdparty/embree/common/math/lbbox.h +++ b/thirdparty/embree/common/math/lbbox.h @@ -179,6 +179,48 @@ namespace embree bounds1 = b1; } + /*! calculates the linear bounds for target_time_range of primitive with it's time_range_in and bounds */ + __forceinline LBBox(const BBox1f& time_range_in, const LBBox lbounds, const BBox1f& target_time_range) + { + const BBox3f bounds0 = lbounds.bounds0; + const BBox3f bounds1 = lbounds.bounds1; + + /* normalize global target_time_range to local time_range_in */ + const BBox1f time_range((target_time_range.lower-time_range_in.lower)/time_range_in.size(), + (target_time_range.upper-time_range_in.lower)/time_range_in.size()); + + const BBox1f clipped_time_range(max(0.0f,time_range.lower), min(1.0f,time_range.upper)); + + /* compute bounds at begin and end of clipped time range */ + BBox b0 = lerp(bounds0,bounds1,clipped_time_range.lower); + BBox b1 = lerp(bounds0,bounds1,clipped_time_range.upper); + + /* make sure that b0 is properly bounded at time_range_in.lower */ + { + const BBox bt = lerp(b0, b1, (0.0f - time_range.lower) / time_range.size()); + const T dlower = min(bounds0.lower-bt.lower, T(zero)); + const T dupper = max(bounds0.upper-bt.upper, T(zero)); + b0.lower += dlower; b1.lower += dlower; + b0.upper += dupper; b1.upper += dupper; + } + + /* make sure that b1 is properly bounded at time_range_in.upper */ + { + const BBox bt = lerp(b0, b1, (1.0f - time_range.lower) / time_range.size()); + const T dlower = min(bounds1.lower-bt.lower, T(zero)); + const T dupper = max(bounds1.upper-bt.upper, T(zero)); + b0.lower += dlower; b1.lower += dlower; + b0.upper += dupper; b1.upper += dupper; + } + + this->bounds0 = b0; + this->bounds1 = b1; + } + + /*! calculates the linear bounds for target_time_range of primitive with it's time_range_in and bounds */ + __forceinline LBBox(const BBox1f& time_range_in, const BBox& bounds0, const BBox& bounds1, const BBox1f& target_time_range) + : LBBox(time_range_in,LBBox(bounds0,bounds1),target_time_range) {} + public: __forceinline bool empty() const { diff --git a/thirdparty/embree/common/math/linearspace2.h b/thirdparty/embree/common/math/linearspace2.h index 184ee695fbb..e58f61ea6bc 100644 --- a/thirdparty/embree/common/math/linearspace2.h +++ b/thirdparty/embree/common/math/linearspace2.h @@ -18,6 +18,7 @@ namespace embree /*! default matrix constructor */ __forceinline LinearSpace2 ( ) {} + __forceinline LinearSpace2 ( const LinearSpace2& other ) { vx = other.vx; vy = other.vy; } __forceinline LinearSpace2& operator=( const LinearSpace2& other ) { vx = other.vx; vy = other.vy; return *this; } diff --git a/thirdparty/embree/common/math/linearspace3.h b/thirdparty/embree/common/math/linearspace3.h index 9eaa2cc2bb6..f6d2318fa0b 100644 --- a/thirdparty/embree/common/math/linearspace3.h +++ b/thirdparty/embree/common/math/linearspace3.h @@ -19,6 +19,7 @@ namespace embree /*! default matrix constructor */ __forceinline LinearSpace3 ( ) {} + __forceinline LinearSpace3 ( const LinearSpace3& other ) { vx = other.vx; vy = other.vy; vz = other.vz; } __forceinline LinearSpace3& operator=( const LinearSpace3& other ) { vx = other.vx; vy = other.vy; vz = other.vz; return *this; } @@ -90,17 +91,20 @@ namespace embree Vector vx,vy,vz; }; +#if !defined(__SYCL_DEVICE_ONLY__) + /*! compute transposed matrix */ template<> __forceinline const LinearSpace3 LinearSpace3::transposed() const { vfloat4 rx,ry,rz; transpose((vfloat4&)vx,(vfloat4&)vy,(vfloat4&)vz,vfloat4(zero),rx,ry,rz); return LinearSpace3(Vec3fa(rx),Vec3fa(ry),Vec3fa(rz)); } - +#endif + template __forceinline const LinearSpace3 transposed(const LinearSpace3& xfm) { return xfm.transposed(); } - + //////////////////////////////////////////////////////////////////////////////// // Unary Operators //////////////////////////////////////////////////////////////////////////////// diff --git a/thirdparty/embree/common/math/math_sycl.h b/thirdparty/embree/common/math/math_sycl.h new file mode 100644 index 00000000000..ffb047569c1 --- /dev/null +++ b/thirdparty/embree/common/math/math_sycl.h @@ -0,0 +1,279 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../sys/platform.h" +#include "../sys/intrinsics.h" +#include "constants.h" +#include + +namespace embree +{ + __forceinline bool isvalid ( const float& v ) { + return (v > -FLT_LARGE) & (v < +FLT_LARGE); + } + + __forceinline int cast_f2i(float f) { + return __builtin_bit_cast(int,f); + } + + __forceinline float cast_i2f(int i) { + return __builtin_bit_cast(float,i); + } + + __forceinline int toInt (const float& a) { return int(a); } + __forceinline float toFloat(const int& a) { return float(a); } + + __forceinline float asFloat(const int a) { return __builtin_bit_cast(float,a); } + __forceinline int asInt (const float a) { return __builtin_bit_cast(int,a); } + + //__forceinline bool finite ( const float x ) { return _finite(x) != 0; } + __forceinline float sign ( const float x ) { return x<0?-1.0f:1.0f; } + __forceinline float sqr ( const float x ) { return x*x; } + + __forceinline float rcp ( const float x ) { + return sycl::native::recip(x); + } + + __forceinline float signmsk(const float a) { return asFloat(asInt(a) & 0x80000000); } + //__forceinline float signmsk ( const float x ) { + // return _mm_cvtss_f32(_mm_and_ps(_mm_set_ss(x),_mm_castsi128_ps(_mm_set1_epi32(0x80000000)))); + //} + //__forceinline float xorf( const float x, const float y ) { + // return _mm_cvtss_f32(_mm_xor_ps(_mm_set_ss(x),_mm_set_ss(y))); + //} + //__forceinline float andf( const float x, const unsigned y ) { + // return _mm_cvtss_f32(_mm_and_ps(_mm_set_ss(x),_mm_castsi128_ps(_mm_set1_epi32(y)))); + //} + + __forceinline float rsqrt( const float x ) { + return sycl::rsqrt(x); + } + + //__forceinline float nextafter(float x, float y) { if ((x0)) return x*(1.1f+float(ulp)); else return x*(0.9f-float(ulp)); } + //__forceinline double nextafter(double x, double y) { return _nextafter(x, y); } + //__forceinline int roundf(float f) { return (int)(f + 0.5f); } + + __forceinline float abs ( const float x ) { return sycl::fabs(x); } + __forceinline float acos ( const float x ) { return sycl::acos(x); } + __forceinline float asin ( const float x ) { return sycl::asin(x); } + __forceinline float atan ( const float x ) { return sycl::atan(x); } + __forceinline float atan2( const float y, const float x ) { return sycl::atan2(y, x); } + __forceinline float cos ( const float x ) { return sycl::cos(x); } + __forceinline float cosh ( const float x ) { return sycl::cosh(x); } + __forceinline float exp ( const float x ) { return sycl::exp(x); } + __forceinline float fmod ( const float x, const float y ) { return sycl::fmod(x, y); } + __forceinline float log ( const float x ) { return sycl::log(x); } + __forceinline float log10( const float x ) { return sycl::log10(x); } + __forceinline float pow ( const float x, const float y ) { return sycl::pow(x, y); } + __forceinline float sin ( const float x ) { return sycl::sin(x); } + __forceinline float sinh ( const float x ) { return sycl::sinh(x); } + __forceinline float sqrt ( const float x ) { return sycl::sqrt(x); } + __forceinline float tan ( const float x ) { return sycl::tan(x); } + __forceinline float tanh ( const float x ) { return sycl::tanh(x); } + __forceinline float floor( const float x ) { return sycl::floor(x); } + __forceinline float ceil ( const float x ) { return sycl::ceil(x); } + __forceinline float frac ( const float x ) { return x-floor(x); } + + //__forceinline double abs ( const double x ) { return ::fabs(x); } + //__forceinline double sign ( const double x ) { return x<0?-1.0:1.0; } + //__forceinline double acos ( const double x ) { return ::acos (x); } + //__forceinline double asin ( const double x ) { return ::asin (x); } + //__forceinline double atan ( const double x ) { return ::atan (x); } + //__forceinline double atan2( const double y, const double x ) { return ::atan2(y, x); } + //__forceinline double cos ( const double x ) { return ::cos (x); } + //__forceinline double cosh ( const double x ) { return ::cosh (x); } + //__forceinline double exp ( const double x ) { return ::exp (x); } + //__forceinline double fmod ( const double x, const double y ) { return ::fmod (x, y); } + //__forceinline double log ( const double x ) { return ::log (x); } + //__forceinline double log10( const double x ) { return ::log10(x); } + //__forceinline double pow ( const double x, const double y ) { return ::pow (x, y); } + //__forceinline double rcp ( const double x ) { return 1.0/x; } + //__forceinline double rsqrt( const double x ) { return 1.0/::sqrt(x); } + //__forceinline double sin ( const double x ) { return ::sin (x); } + //__forceinline double sinh ( const double x ) { return ::sinh (x); } + //__forceinline double sqr ( const double x ) { return x*x; } + //__forceinline double sqrt ( const double x ) { return ::sqrt (x); } + //__forceinline double tan ( const double x ) { return ::tan (x); } + //__forceinline double tanh ( const double x ) { return ::tanh (x); } + //__forceinline double floor( const double x ) { return ::floor (x); } + //__forceinline double ceil ( const double x ) { return ::ceil (x); } + +/* +#if defined(__SSE4_1__) + __forceinline float mini(float a, float b) { + const __m128i ai = _mm_castps_si128(_mm_set_ss(a)); + const __m128i bi = _mm_castps_si128(_mm_set_ss(b)); + const __m128i ci = _mm_min_epi32(ai,bi); + return _mm_cvtss_f32(_mm_castsi128_ps(ci)); + } +#endif + +#if defined(__SSE4_1__) + __forceinline float maxi(float a, float b) { + const __m128i ai = _mm_castps_si128(_mm_set_ss(a)); + const __m128i bi = _mm_castps_si128(_mm_set_ss(b)); + const __m128i ci = _mm_max_epi32(ai,bi); + return _mm_cvtss_f32(_mm_castsi128_ps(ci)); + } +#endif +*/ + + template + __forceinline T twice(const T& a) { return a+a; } + + __forceinline int min(int a, int b) { return sycl::min(a,b); } + __forceinline unsigned min(unsigned a, unsigned b) { return sycl::min(a,b); } + __forceinline int64_t min(int64_t a, int64_t b) { return sycl::min(a,b); } + __forceinline float min(float a, float b) { return sycl::fmin(a,b); } + __forceinline double min(double a, double b) { return sycl::fmin(a,b); } +#if defined(__X86_64__) + __forceinline size_t min(size_t a, size_t b) { return sycl::min(a,b); } +#endif + + template __forceinline T min(const T& a, const T& b, const T& c) { return min(min(a,b),c); } + template __forceinline T min(const T& a, const T& b, const T& c, const T& d) { return min(min(a,b),min(c,d)); } + template __forceinline T min(const T& a, const T& b, const T& c, const T& d, const T& e) { return min(min(min(a,b),min(c,d)),e); } + +// template __forceinline T mini(const T& a, const T& b, const T& c) { return mini(mini(a,b),c); } +// template __forceinline T mini(const T& a, const T& b, const T& c, const T& d) { return mini(mini(a,b),mini(c,d)); } +// template __forceinline T mini(const T& a, const T& b, const T& c, const T& d, const T& e) { return mini(mini(mini(a,b),mini(c,d)),e); } + + __forceinline int max(int a, int b) { return sycl::max(a,b); } + __forceinline unsigned max(unsigned a, unsigned b) { return sycl::max(a,b); } + __forceinline int64_t max(int64_t a, int64_t b) { return sycl::max(a,b); } + __forceinline float max(float a, float b) { return sycl::fmax(a,b); } + __forceinline double max(double a, double b) { return sycl::fmax(a,b); } +#if defined(__X86_64__) + __forceinline size_t max(size_t a, size_t b) { return sycl::max(a,b); } +#endif + + template __forceinline T max(const T& a, const T& b, const T& c) { return max(max(a,b),c); } + template __forceinline T max(const T& a, const T& b, const T& c, const T& d) { return max(max(a,b),max(c,d)); } + template __forceinline T max(const T& a, const T& b, const T& c, const T& d, const T& e) { return max(max(max(a,b),max(c,d)),e); } + +// template __forceinline T maxi(const T& a, const T& b, const T& c) { return maxi(maxi(a,b),c); } +// template __forceinline T maxi(const T& a, const T& b, const T& c, const T& d) { return maxi(maxi(a,b),maxi(c,d)); } +// template __forceinline T maxi(const T& a, const T& b, const T& c, const T& d, const T& e) { return maxi(maxi(maxi(a,b),maxi(c,d)),e); } + + template __forceinline T clamp(const T& x, const T& lower = T(zero), const T& upper = T(one)) { return max(min(x,upper),lower); } + template __forceinline T clampz(const T& x, const T& upper) { return max(T(zero), min(x,upper)); } + + template __forceinline T deg2rad ( const T& x ) { return x * T(1.74532925199432957692e-2f); } + template __forceinline T rad2deg ( const T& x ) { return x * T(5.72957795130823208768e1f); } + template __forceinline T sin2cos ( const T& x ) { return sqrt(max(T(zero),T(one)-x*x)); } + template __forceinline T cos2sin ( const T& x ) { return sin2cos(x); } + + __forceinline float madd ( const float a, const float b, const float c) { return +sycl::fma(+a,b,+c); } + __forceinline float msub ( const float a, const float b, const float c) { return +sycl::fma(+a,b,-c); } + __forceinline float nmadd ( const float a, const float b, const float c) { return +sycl::fma(-a,b,+c); } + __forceinline float nmsub ( const float a, const float b, const float c) { return -sycl::fma(+a,b,+c); } + + /*! random functions */ +/* + template T random() { return T(0); } + template<> __forceinline int random() { return int(rand()); } + template<> __forceinline uint32_t random() { return uint32_t(rand()) ^ (uint32_t(rand()) << 16); } + template<> __forceinline float random() { return rand()/float(RAND_MAX); } + template<> __forceinline double random() { return rand()/double(RAND_MAX); } +*/ + + /*! selects */ + __forceinline bool select(bool s, bool t , bool f) { return s ? t : f; } + __forceinline int select(bool s, int t, int f) { return s ? t : f; } + __forceinline float select(bool s, float t, float f) { return s ? t : f; } + + __forceinline bool none(bool s) { return !s; } + __forceinline bool all (bool s) { return s; } + __forceinline bool any (bool s) { return s; } + + __forceinline unsigned movemask (bool s) { return (unsigned)s; } + + __forceinline float lerp(const float v0, const float v1, const float t) { + return madd(1.0f-t,v0,t*v1); + } + + template + __forceinline T lerp2(const float x0, const float x1, const float x2, const float x3, const T& u, const T& v) { + return madd((1.0f-u),madd((1.0f-v),T(x0),v*T(x2)),u*madd((1.0f-v),T(x1),v*T(x3))); + } + + /*! exchange */ + template __forceinline void xchg ( T& a, T& b ) { const T tmp = a; a = b; b = tmp; } + + /* load/store */ + template struct mem; + + template<> struct mem { + static __forceinline float load (bool mask, const void* ptr) { return mask ? *(float*)ptr : 0.0f; } + static __forceinline float loadu(bool mask, const void* ptr) { return mask ? *(float*)ptr : 0.0f; } + + static __forceinline void store (bool mask, void* ptr, const float v) { if (mask) *(float*)ptr = v; } + static __forceinline void storeu(bool mask, void* ptr, const float v) { if (mask) *(float*)ptr = v; } + }; + + /*! bit reverse operation */ + template + __forceinline T bitReverse(const T& vin) + { + T v = vin; + v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1); + v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2); + v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4); + v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8); + v = ( v >> 16 ) | ( v << 16); + return v; + } + + /*! bit interleave operation */ + template + __forceinline T bitInterleave(const T& xin, const T& yin, const T& zin) + { + T x = xin, y = yin, z = zin; + x = (x | (x << 16)) & 0x030000FF; + x = (x | (x << 8)) & 0x0300F00F; + x = (x | (x << 4)) & 0x030C30C3; + x = (x | (x << 2)) & 0x09249249; + + y = (y | (y << 16)) & 0x030000FF; + y = (y | (y << 8)) & 0x0300F00F; + y = (y | (y << 4)) & 0x030C30C3; + y = (y | (y << 2)) & 0x09249249; + + z = (z | (z << 16)) & 0x030000FF; + z = (z | (z << 8)) & 0x0300F00F; + z = (z | (z << 4)) & 0x030C30C3; + z = (z | (z << 2)) & 0x09249249; + + return x | (y << 1) | (z << 2); + } + + /*! bit interleave operation for 64bit data types*/ + template + __forceinline T bitInterleave64(const T& xin, const T& yin, const T& zin){ + T x = xin & 0x1fffff; + T y = yin & 0x1fffff; + T z = zin & 0x1fffff; + + x = (x | x << 32) & 0x1f00000000ffff; + x = (x | x << 16) & 0x1f0000ff0000ff; + x = (x | x << 8) & 0x100f00f00f00f00f; + x = (x | x << 4) & 0x10c30c30c30c30c3; + x = (x | x << 2) & 0x1249249249249249; + + y = (y | y << 32) & 0x1f00000000ffff; + y = (y | y << 16) & 0x1f0000ff0000ff; + y = (y | y << 8) & 0x100f00f00f00f00f; + y = (y | y << 4) & 0x10c30c30c30c30c3; + y = (y | y << 2) & 0x1249249249249249; + + z = (z | z << 32) & 0x1f00000000ffff; + z = (z | z << 16) & 0x1f0000ff0000ff; + z = (z | z << 8) & 0x100f00f00f00f00f; + z = (z | z << 4) & 0x10c30c30c30c30c3; + z = (z | z << 2) & 0x1249249249249249; + + return x | (y << 1) | (z << 2); + } +} diff --git a/thirdparty/embree/common/math/range.h b/thirdparty/embree/common/math/range.h index 909fadb9956..f397615ea26 100644 --- a/thirdparty/embree/common/math/range.h +++ b/thirdparty/embree/common/math/range.h @@ -4,7 +4,7 @@ #pragma once #include "../sys/platform.h" -#include "../math/math.h" +#include "../math/emath.h" namespace embree { diff --git a/thirdparty/embree/common/math/vec2.h b/thirdparty/embree/common/math/vec2.h index f6d98ffa0dc..4e641ec249e 100644 --- a/thirdparty/embree/common/math/vec2.h +++ b/thirdparty/embree/common/math/vec2.h @@ -3,7 +3,7 @@ #pragma once -#include "math.h" +#include "emath.h" namespace embree { @@ -34,7 +34,7 @@ namespace embree __forceinline Vec2( const T& x, const T& y ) : x(x), y(y) {} __forceinline Vec2( const Vec2& other ) { x = other.x; y = other.y; } - __forceinline Vec2( const Vec2fa& other ); + Vec2( const Vec2fa& other ); template __forceinline Vec2( const Vec2& a ) : x(T(a.x)), y(T(a.y)) {} template __forceinline Vec2& operator =( const Vec2& other ) { x = other.x; y = other.y; return *this; } @@ -232,4 +232,5 @@ namespace embree #if defined(__AVX512F__) template<> __forceinline Vec2::Vec2(const Vec2fa& a) : x(a.x), y(a.y) {} #endif + } diff --git a/thirdparty/embree/common/math/vec2fa.h b/thirdparty/embree/common/math/vec2fa.h index 4f222894c2d..d57e549e684 100644 --- a/thirdparty/embree/common/math/vec2fa.h +++ b/thirdparty/embree/common/math/vec2fa.h @@ -4,7 +4,12 @@ #pragma once #include "../sys/alloc.h" -#include "math.h" +#include "emath.h" + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +# include "vec2fa_sycl.h" +#else + #include "../simd/sse.h" namespace embree @@ -316,3 +321,5 @@ namespace embree typedef Vec2fa Vec2fa_t; } + +#endif diff --git a/thirdparty/embree/common/math/vec2fa_sycl.h b/thirdparty/embree/common/math/vec2fa_sycl.h new file mode 100644 index 00000000000..62d62bdd01d --- /dev/null +++ b/thirdparty/embree/common/math/vec2fa_sycl.h @@ -0,0 +1,270 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../sys/alloc.h" +#include "emath.h" +#include "../simd/sse.h" + +namespace embree +{ + struct Vec3fa; + + //////////////////////////////////////////////////////////////////////////////// + /// SSE Vec2fa Type + //////////////////////////////////////////////////////////////////////////////// + + struct __aligned(16) Vec2fa + { + //ALIGNED_STRUCT_(16); + + typedef float Scalar; + enum { N = 2 }; + struct { float x,y; }; + + //////////////////////////////////////////////////////////////////////////////// + /// Constructors, Assignment & Cast Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa( ) {} + //__forceinline Vec2fa( const __m128 a ) : m128(a) {} + explicit Vec2fa(const Vec3fa& a); + + __forceinline explicit Vec2fa( const vfloat<4>& a ) { + x = a[0]; + y = a[1]; + } + + __forceinline Vec2fa ( const Vec2& other ) { x = other.x; y = other.y; } + __forceinline Vec2fa& operator =( const Vec2& other ) { x = other.x; y = other.y; return *this; } + + __forceinline Vec2fa ( const Vec2fa& other ) { x = other.x; y = other.y; } + __forceinline Vec2fa& operator =( const Vec2fa& other ) { x = other.x; y = other.y; return *this; } + + __forceinline explicit Vec2fa( const float a ) : x(a), y(a) {} + __forceinline Vec2fa( const float x, const float y) : x(x), y(y) {} + + //__forceinline explicit Vec2fa( const __m128i a ) : m128(_mm_cvtepi32_ps(a)) {} + + //__forceinline operator const __m128&() const { return m128; } + //__forceinline operator __m128&() { return m128; } + + //////////////////////////////////////////////////////////////////////////////// + /// Loads and Stores + //////////////////////////////////////////////////////////////////////////////// + + static __forceinline Vec2fa load( const void* const a ) { + const float* ptr = (const float*)a; + return Vec2fa(ptr[0],ptr[1]); + } + + static __forceinline Vec2fa loadu( const void* const a ) { + const float* ptr = (const float*)a; + return Vec2fa(ptr[0],ptr[1]); + } + + static __forceinline void storeu ( void* a, const Vec2fa& v ) { + float* ptr = (float*)a; + ptr[0] = v.x; ptr[1] = v.y; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa( ZeroTy ) : x(0.0f), y(0.0f) {} + __forceinline Vec2fa( OneTy ) : x(1.0f), y(1.0f) {} + __forceinline Vec2fa( PosInfTy ) : x(+INFINITY), y(+INFINITY) {} + __forceinline Vec2fa( NegInfTy ) : x(-INFINITY), y(-INFINITY) {} + + //////////////////////////////////////////////////////////////////////////////// + /// Array Access + //////////////////////////////////////////////////////////////////////////////// + + //__forceinline const float& operator []( const size_t index ) const { assert(index < 2); return (&x)[index]; } + //__forceinline float& operator []( const size_t index ) { assert(index < 2); return (&x)[index]; } + }; + + //////////////////////////////////////////////////////////////////////////////// + /// Unary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa operator +( const Vec2fa& a ) { return a; } + __forceinline Vec2fa operator -( const Vec2fa& a ) { return Vec2fa(-a.x,-a.y); } + __forceinline Vec2fa abs ( const Vec2fa& a ) { return Vec2fa(sycl::fabs(a.x),sycl::fabs(a.y)); } + __forceinline Vec2fa sign ( const Vec2fa& a ) { return Vec2fa(sycl::sign(a.x),sycl::sign(a.y)); } + + //__forceinline Vec2fa rcp ( const Vec2fa& a ) { return Vec2fa(sycl::recip(a.x),sycl::recip(a.y)); } + __forceinline Vec2fa rcp ( const Vec2fa& a ) { return Vec2fa(__sycl_std::__invoke_native_recip(a.x),__sycl_std::__invoke_native_recip(a.y)); } + __forceinline Vec2fa sqrt ( const Vec2fa& a ) { return Vec2fa(sycl::sqrt(a.x),sycl::sqrt(a.y)); } + __forceinline Vec2fa sqr ( const Vec2fa& a ) { return Vec2fa(a.x*a.x,a.y*a.y); } + + __forceinline Vec2fa rsqrt( const Vec2fa& a ) { return Vec2fa(sycl::rsqrt(a.x),sycl::rsqrt(a.y)); } + + __forceinline Vec2fa zero_fix(const Vec2fa& a) { + const float x = sycl::fabs(a.x) < min_rcp_input ? min_rcp_input : a.x; + const float y = sycl::fabs(a.y) < min_rcp_input ? min_rcp_input : a.y; + return Vec2fa(x,y); + } + __forceinline Vec2fa rcp_safe(const Vec2fa& a) { + return rcp(zero_fix(a)); + } + __forceinline Vec2fa log ( const Vec2fa& a ) { + return Vec2fa(sycl::log(a.x),sycl::log(a.y)); + } + + __forceinline Vec2fa exp ( const Vec2fa& a ) { + return Vec2fa(sycl::exp(a.x),sycl::exp(a.y)); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Binary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa operator +( const Vec2fa& a, const Vec2fa& b ) { return Vec2fa(a.x+b.x, a.y+b.y); } + __forceinline Vec2fa operator -( const Vec2fa& a, const Vec2fa& b ) { return Vec2fa(a.x-b.x, a.y-b.y); } + __forceinline Vec2fa operator *( const Vec2fa& a, const Vec2fa& b ) { return Vec2fa(a.x*b.x, a.y*b.y); } + __forceinline Vec2fa operator *( const Vec2fa& a, const float b ) { return a * Vec2fa(b); } + __forceinline Vec2fa operator *( const float a, const Vec2fa& b ) { return Vec2fa(a) * b; } + __forceinline Vec2fa operator /( const Vec2fa& a, const Vec2fa& b ) { return Vec2fa(a.x/b.x, a.y/b.y); } + __forceinline Vec2fa operator /( const Vec2fa& a, const float b ) { return Vec2fa(a.x/b, a.y/b); } + __forceinline Vec2fa operator /( const float a, const Vec2fa& b ) { return Vec2fa(a/b.x, a/b.y); } + + __forceinline Vec2fa min( const Vec2fa& a, const Vec2fa& b ) { + return Vec2fa(sycl::fmin(a.x,b.x), sycl::fmin(a.y,b.y)); + } + __forceinline Vec2fa max( const Vec2fa& a, const Vec2fa& b ) { + return Vec2fa(sycl::fmax(a.x,b.x), sycl::fmax(a.y,b.y)); + } + +/* +#if defined(__SSE4_1__) + __forceinline Vec2fa mini(const Vec2fa& a, const Vec2fa& b) { + const vint4 ai = _mm_castps_si128(a); + const vint4 bi = _mm_castps_si128(b); + const vint4 ci = _mm_min_epi32(ai,bi); + return _mm_castsi128_ps(ci); + } +#endif + +#if defined(__SSE4_1__) + __forceinline Vec2fa maxi(const Vec2fa& a, const Vec2fa& b) { + const vint4 ai = _mm_castps_si128(a); + const vint4 bi = _mm_castps_si128(b); + const vint4 ci = _mm_max_epi32(ai,bi); + return _mm_castsi128_ps(ci); + } +#endif + + __forceinline Vec2fa pow ( const Vec2fa& a, const float& b ) { + return Vec2fa(powf(a.x,b),powf(a.y,b)); + } +*/ + + //////////////////////////////////////////////////////////////////////////////// + /// Ternary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa madd ( const Vec2fa& a, const Vec2fa& b, const Vec2fa& c) { return Vec2fa(madd(a.x,b.x,c.x), madd(a.y,b.y,c.y)); } + __forceinline Vec2fa msub ( const Vec2fa& a, const Vec2fa& b, const Vec2fa& c) { return Vec2fa(msub(a.x,b.x,c.x), msub(a.y,b.y,c.y)); } + __forceinline Vec2fa nmadd ( const Vec2fa& a, const Vec2fa& b, const Vec2fa& c) { return Vec2fa(nmadd(a.x,b.x,c.x), nmadd(a.y,b.y,c.y)); } + __forceinline Vec2fa nmsub ( const Vec2fa& a, const Vec2fa& b, const Vec2fa& c) { return Vec2fa(nmsub(a.x,b.x,c.x), nmsub(a.y,b.y,c.y)); } + + __forceinline Vec2fa madd ( const float a, const Vec2fa& b, const Vec2fa& c) { return madd(Vec2fa(a),b,c); } + __forceinline Vec2fa msub ( const float a, const Vec2fa& b, const Vec2fa& c) { return msub(Vec2fa(a),b,c); } + __forceinline Vec2fa nmadd ( const float a, const Vec2fa& b, const Vec2fa& c) { return nmadd(Vec2fa(a),b,c); } + __forceinline Vec2fa nmsub ( const float a, const Vec2fa& b, const Vec2fa& c) { return nmsub(Vec2fa(a),b,c); } + + //////////////////////////////////////////////////////////////////////////////// + /// Assignment Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa& operator +=( Vec2fa& a, const Vec2fa& b ) { return a = a + b; } + __forceinline Vec2fa& operator -=( Vec2fa& a, const Vec2fa& b ) { return a = a - b; } + __forceinline Vec2fa& operator *=( Vec2fa& a, const Vec2fa& b ) { return a = a * b; } + __forceinline Vec2fa& operator *=( Vec2fa& a, const float b ) { return a = a * b; } + __forceinline Vec2fa& operator /=( Vec2fa& a, const Vec2fa& b ) { return a = a / b; } + __forceinline Vec2fa& operator /=( Vec2fa& a, const float b ) { return a = a / b; } + + //////////////////////////////////////////////////////////////////////////////// + /// Reductions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float reduce_add(const Vec2fa& v) { return v.x+v.y; } + __forceinline float reduce_mul(const Vec2fa& v) { return v.x*v.y; } + __forceinline float reduce_min(const Vec2fa& v) { return sycl::fmin(v.x,v.y); } + __forceinline float reduce_max(const Vec2fa& v) { return sycl::fmax(v.x,v.y); } + + //////////////////////////////////////////////////////////////////////////////// + /// Comparison Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool operator ==( const Vec2fa& a, const Vec2fa& b ) { return a.x == b.x && a.y == b.y; } + __forceinline bool operator !=( const Vec2fa& a, const Vec2fa& b ) { return a.x != b.x || a.y != b.y; } + + //////////////////////////////////////////////////////////////////////////////// + /// Euclidian Space Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float dot ( const Vec2fa& a, const Vec2fa& b ) { + return reduce_add(a*b); + } + + __forceinline Vec2fa cross ( const Vec2fa& a ) { + return Vec2fa(-a.y,a.x); + } + + __forceinline float sqr_length ( const Vec2fa& a ) { return dot(a,a); } + __forceinline float rcp_length ( const Vec2fa& a ) { return rsqrt(dot(a,a)); } + __forceinline float rcp_length2( const Vec2fa& a ) { return rcp(dot(a,a)); } + __forceinline float length ( const Vec2fa& a ) { return sqrt(dot(a,a)); } + __forceinline Vec2fa normalize( const Vec2fa& a ) { return a*rsqrt(dot(a,a)); } + __forceinline float distance ( const Vec2fa& a, const Vec2fa& b ) { return length(a-b); } + + //////////////////////////////////////////////////////////////////////////////// + /// Select + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa select( bool s, const Vec2fa& t, const Vec2fa& f ) { + return Vec2fa(s ? t.x : f.x, s ? t.y : f.y); + } + + __forceinline Vec2fa lerp(const Vec2fa& v0, const Vec2fa& v1, const float t) { + return madd(1.0f-t,v0,t*v1); + } + + __forceinline int maxDim ( const Vec2fa& a ) + { + const Vec2fa b = abs(a); + if (b.x > b.y) return 0; + else return 1; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Rounding Functions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec2fa trunc( const Vec2fa& a ) { return Vec2fa(sycl::trunc(a.x),sycl::trunc(a.y)); } + __forceinline Vec2fa floor( const Vec2fa& a ) { return Vec2fa(sycl::floor(a.x),sycl::floor(a.y)); } + __forceinline Vec2fa ceil ( const Vec2fa& a ) { return Vec2fa(sycl::ceil (a.x),sycl::ceil (a.y)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Output Operators + //////////////////////////////////////////////////////////////////////////////// + + inline embree_ostream operator<<(embree_ostream cout, const Vec2fa& a) { + return cout << "(" << a.x << ", " << a.y << ")"; + } + + /*template<> + __forceinline vfloat_impl<4>::vfloat_impl(const Vec2fa& a) + { + v = 0; + const unsigned int lid = get_sub_group_local_id(); + if (lid == 0) v = a.x; + if (lid == 1) v = a.y; + }*/ + + typedef Vec2fa Vec2fa_t; +} diff --git a/thirdparty/embree/common/math/vec3.h b/thirdparty/embree/common/math/vec3.h index 254f6c4011e..d5e78befe83 100644 --- a/thirdparty/embree/common/math/vec3.h +++ b/thirdparty/embree/common/math/vec3.h @@ -3,7 +3,7 @@ #pragma once -#include "math.h" +#include "emath.h" namespace embree { @@ -286,6 +286,8 @@ namespace embree template<> __forceinline Vec3::Vec3(const Vec3fa& a) { x = a.x; y = a.y; z = a.z; } +#if !defined(__SYCL_DEVICE_ONLY__) + #if defined(__AVX__) template<> __forceinline Vec3::Vec3(const Vec3fa& a) { x = a.x; y = a.y; z = a.z; @@ -333,4 +335,23 @@ namespace embree #if defined(__AVX512F__) template<> __forceinline Vec3::Vec3(const Vec3fa& a) : x(a.x), y(a.y), z(a.z) {} #endif + +#else + +#if defined(__SSE__) + template<> __forceinline Vec3::Vec3(const Vec3fa& a) { + x = a.x; y = a.y; z = a.z; + } +#endif +#if defined(__AVX__) + template<> __forceinline Vec3::Vec3(const Vec3fa& a) { + x = a.x; y = a.y; z = a.z; + } +#endif +#if defined(__AVX512F__) + template<> __forceinline Vec3::Vec3(const Vec3fa& a) { + x = a.x; y = a.y; z = a.z; + } +#endif +#endif } diff --git a/thirdparty/embree/common/math/vec3ba.h b/thirdparty/embree/common/math/vec3ba.h index a021b522dcf..bf24a2a3b67 100644 --- a/thirdparty/embree/common/math/vec3ba.h +++ b/thirdparty/embree/common/math/vec3ba.h @@ -4,7 +4,12 @@ #pragma once #include "../sys/alloc.h" -#include "math.h" +#include "emath.h" + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +# include "vec3ba_sycl.h" +#else + #include "../simd/sse.h" namespace embree @@ -118,3 +123,5 @@ namespace embree return cout << "(" << (a.x ? "1" : "0") << ", " << (a.y ? "1" : "0") << ", " << (a.z ? "1" : "0") << ")"; } } + +#endif diff --git a/thirdparty/embree/common/math/vec3ba_sycl.h b/thirdparty/embree/common/math/vec3ba_sycl.h new file mode 100644 index 00000000000..a2fa13de6cf --- /dev/null +++ b/thirdparty/embree/common/math/vec3ba_sycl.h @@ -0,0 +1,115 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../sys/alloc.h" +#include "emath.h" +#include "../simd/sse.h" + +namespace embree +{ + //////////////////////////////////////////////////////////////////////////////// + /// SSE Vec3ba Type + //////////////////////////////////////////////////////////////////////////////// + + struct __aligned(16) Vec3ba + { + //ALIGNED_STRUCT_(16); + + struct { bool x,y,z; }; + + typedef bool Scalar; + enum { N = 3 }; + + //////////////////////////////////////////////////////////////////////////////// + /// Constructors, Assignment & Cast Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ba( ) {} + //__forceinline Vec3ba( const __m128 input ) : m128(input) {} + + __forceinline Vec3ba( const Vec3ba& other ) : x(other.x), y(other.y), z(other.z) {} + __forceinline Vec3ba& operator =(const Vec3ba& other) { x = other.x; y = other.y; z = other.z; return *this; } + + __forceinline explicit Vec3ba( bool a ) : x(a), y(a), z(a) {} + __forceinline Vec3ba( bool a, bool b, bool c) : x(a), y(b), z(c) {} + + //__forceinline operator const __m128&() const { return m128; } + //__forceinline operator __m128&() { return m128; } + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ba( FalseTy ) : x(false), y(false), z(false) {} + __forceinline Vec3ba( TrueTy ) : x(true), y(true), z(true) {} + + //////////////////////////////////////////////////////////////////////////////// + /// Array Access + //////////////////////////////////////////////////////////////////////////////// + + //__forceinline const int& operator []( const size_t index ) const { assert(index < 3); return (&x)[index]; } + //__forceinline int& operator []( const size_t index ) { assert(index < 3); return (&x)[index]; } + }; + + + //////////////////////////////////////////////////////////////////////////////// + /// Unary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ba operator !( const Vec3ba& a ) { return Vec3ba(!a.x,!a.y,!a.z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Binary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ba operator &( const Vec3ba& a, const Vec3ba& b ) { return Vec3ba(a.x & b.x, a.y & b.y, a.z & b.z); } + __forceinline Vec3ba operator |( const Vec3ba& a, const Vec3ba& b ) { return Vec3ba(a.x | b.x, a.y | b.y, a.z | b.z); } + __forceinline Vec3ba operator ^( const Vec3ba& a, const Vec3ba& b ) { return Vec3ba(a.x != b.x, a.y != b.y, a.z != b.z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Assignment Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ba& operator &=( Vec3ba& a, const Vec3ba& b ) { return a = a & b; } + __forceinline Vec3ba& operator |=( Vec3ba& a, const Vec3ba& b ) { return a = a | b; } + __forceinline Vec3ba& operator ^=( Vec3ba& a, const Vec3ba& b ) { return a = a ^ b; } + + //////////////////////////////////////////////////////////////////////////////// + /// Comparison Operators + Select + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool operator ==( const Vec3ba& a, const Vec3ba& b ) { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + __forceinline bool operator !=( const Vec3ba& a, const Vec3ba& b ) { + return a.x != b.x || a.y != b.y || a.z != b.z; + } +/* + __forceinline bool operator < ( const Vec3ba& a, const Vec3ba& b ) { + if (a.x != b.x) return a.x < b.x; + if (a.y != b.y) return a.y < b.y; + if (a.z != b.z) return a.z < b.z; + return false; + } +*/ + //////////////////////////////////////////////////////////////////////////////// + /// Reduction Operations + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool reduce_and( const Vec3ba& a ) { return a.x & a.y & a.z; } + __forceinline bool reduce_or ( const Vec3ba& a ) { return a.x | a.y | a.z; } + + __forceinline bool all ( const Vec3ba& b ) { return reduce_and(b); } + __forceinline bool any ( const Vec3ba& b ) { return reduce_or(b); } + __forceinline bool none ( const Vec3ba& b ) { return !reduce_or(b); } + + //////////////////////////////////////////////////////////////////////////////// + /// Output Operators + //////////////////////////////////////////////////////////////////////////////// + + inline embree_ostream operator<<(embree_ostream cout, const Vec3ba& a) { + return cout; + } +} diff --git a/thirdparty/embree/common/math/vec3fa.h b/thirdparty/embree/common/math/vec3fa.h index 8564cf6d104..967e75da74e 100644 --- a/thirdparty/embree/common/math/vec3fa.h +++ b/thirdparty/embree/common/math/vec3fa.h @@ -4,7 +4,12 @@ #pragma once #include "../sys/alloc.h" -#include "math.h" +#include "emath.h" + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +# include "vec3fa_sycl.h" +#else + #include "../simd/sse.h" namespace embree @@ -441,7 +446,6 @@ namespace embree //__forceinline Vec3fx& operator =( const Vec3& other ) { m128 = _mm_set_ps(0, other.z, other.y, other.x); return *this; } __forceinline Vec3fx ( const Vec3fx& other ) { m128 = other.m128; } - __forceinline Vec3fx& operator =( const Vec3fx& other ) { m128 = other.m128; return *this; } __forceinline explicit Vec3fx( const float a ) : m128(_mm_set1_ps(a)) {} @@ -783,3 +787,5 @@ namespace embree typedef Vec3fx Vec3ff; } + +#endif diff --git a/thirdparty/embree/common/math/vec3fa_sycl.h b/thirdparty/embree/common/math/vec3fa_sycl.h new file mode 100644 index 00000000000..5fdb00ab999 --- /dev/null +++ b/thirdparty/embree/common/math/vec3fa_sycl.h @@ -0,0 +1,617 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../sys/alloc.h" +#include "emath.h" +#include "../simd/sse.h" + +namespace embree +{ + //////////////////////////////////////////////////////////////////////////////// + /// SSE Vec3fa Type + //////////////////////////////////////////////////////////////////////////////// + + struct __aligned(16) Vec3fa + { + //ALIGNED_STRUCT_(16); + + typedef float Scalar; + enum { N = 3 }; + struct { float x,y,z, do_not_use; }; + + //////////////////////////////////////////////////////////////////////////////// + /// Constructors, Assignment & Cast Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa( ) {} + //__forceinline Vec3fa( const __m128 a ) : m128(a) {} + //__forceinline explicit Vec3fa(const vfloat4& a) : x(a[0]), y(a[1]), z(a[2]) {} + + __forceinline Vec3fa ( const Vec3& other ) { x = other.x; y = other.y; z = other.z; } + //__forceinline Vec3fa& operator =( const Vec3& other ) { x = other.x; y = other.y; z = other.z; return *this; } + + __forceinline Vec3fa ( const Vec3fa& other ) { x = other.x; y = other.y; z = other.z; } + __forceinline Vec3fa& operator =( const Vec3fa& other ) { x = other.x; y = other.y; z = other.z; return *this; } + + __forceinline explicit Vec3fa( const float a ) : x(a), y(a), z(a) {} + __forceinline Vec3fa( const float x, const float y, const float z) : x(x), y(y), z(z) {} + + __forceinline explicit Vec3fa( const Vec3ia& a ) : x((float)a.x), y((float)a.y), z((float)a.z) {} + + //__forceinline operator const __m128&() const { return m128; } + //__forceinline operator __m128&() { return m128; } + __forceinline operator vfloat4() const { return vfloat4(x,y,z,0.0f); } // FIXME: we should not need this!! + + //friend __forceinline Vec3fa copy_a( const Vec3fa& a, const Vec3fa& b ) { Vec3fa c = a; c.a = b.a; return c; } + + //////////////////////////////////////////////////////////////////////////////// + /// Loads and Stores + //////////////////////////////////////////////////////////////////////////////// + + static __forceinline Vec3fa load( const void* const a ) { + const float* ptr = (const float*)a; + return Vec3fa(ptr[0],ptr[1],ptr[2]); + } + + static __forceinline Vec3fa loadu( const void* const a ) { + const float* ptr = (const float*)a; + return Vec3fa(ptr[0],ptr[1],ptr[2]); + } + + static __forceinline void storeu ( void* a, const Vec3fa& v ) { + float* ptr = (float*)a; + ptr[0] = v.x; ptr[1] = v.y; ptr[2] = v.z; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa( ZeroTy ) : x(0.0f), y(0.0f), z(0.0f) {} + __forceinline Vec3fa( OneTy ) : x(1.0f), y(1.0f), z(1.0f) {} + __forceinline Vec3fa( PosInfTy ) : x(+INFINITY), y(+INFINITY), z(+INFINITY) {} + __forceinline Vec3fa( NegInfTy ) : x(-INFINITY), y(-INFINITY), z(-INFINITY) {} + + //////////////////////////////////////////////////////////////////////////////// + /// Array Access + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const float& operator []( const size_t index ) const { assert(index < 3); return (&x)[index]; } + __forceinline float& operator []( const size_t index ) { assert(index < 3); return (&x)[index]; } + }; + + //////////////////////////////////////////////////////////////////////////////// + /// Unary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa operator +( const Vec3fa& a ) { return a; } + __forceinline Vec3fa operator -( const Vec3fa& a ) { return Vec3fa(-a.x,-a.y,-a.z); } + __forceinline Vec3fa abs ( const Vec3fa& a ) { return Vec3fa(sycl::fabs(a.x),sycl::fabs(a.y),sycl::fabs(a.z)); } + __forceinline Vec3fa sign ( const Vec3fa& a ) { return Vec3fa(sycl::sign(a.x),sycl::sign(a.y),sycl::sign(a.z)); } + + //__forceinline Vec3fa rcp ( const Vec3fa& a ) { return Vec3fa(sycl::recip(a.x),sycl::recip(a.y),sycl::recip(a.z)); } + __forceinline Vec3fa rcp ( const Vec3fa& a ) { return Vec3fa(__sycl_std::__invoke_native_recip(a.x),__sycl_std::__invoke_native_recip(a.y),__sycl_std::__invoke_native_recip(a.z)); } + __forceinline Vec3fa sqrt ( const Vec3fa& a ) { return Vec3fa(sycl::sqrt(a.x),sycl::sqrt(a.y),sycl::sqrt(a.z)); } + __forceinline Vec3fa sqr ( const Vec3fa& a ) { return Vec3fa(a.x*a.x,a.y*a.y,a.z*a.z); } + + __forceinline Vec3fa rsqrt( const Vec3fa& a ) { return Vec3fa(sycl::rsqrt(a.x),sycl::rsqrt(a.y),sycl::rsqrt(a.z)); } + + __forceinline Vec3fa zero_fix(const Vec3fa& a) { + const float x = sycl::fabs(a.x) < min_rcp_input ? min_rcp_input : a.x; + const float y = sycl::fabs(a.y) < min_rcp_input ? min_rcp_input : a.y; + const float z = sycl::fabs(a.z) < min_rcp_input ? min_rcp_input : a.z; + return Vec3fa(x,y,z); + } + __forceinline Vec3fa rcp_safe(const Vec3fa& a) { + return rcp(zero_fix(a)); + } + __forceinline Vec3fa log ( const Vec3fa& a ) { + return Vec3fa(sycl::log(a.x),sycl::log(a.y),sycl::log(a.z)); + } + + __forceinline Vec3fa exp ( const Vec3fa& a ) { + return Vec3fa(sycl::exp(a.x),sycl::exp(a.y),sycl::exp(a.z)); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Binary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa operator +( const Vec3fa& a, const Vec3fa& b ) { return Vec3fa(a.x+b.x, a.y+b.y, a.z+b.z); } + __forceinline Vec3fa operator -( const Vec3fa& a, const Vec3fa& b ) { return Vec3fa(a.x-b.x, a.y-b.y, a.z-b.z); } + __forceinline Vec3fa operator *( const Vec3fa& a, const Vec3fa& b ) { return Vec3fa(a.x*b.x, a.y*b.y, a.z*b.z); } + __forceinline Vec3fa operator *( const Vec3fa& a, const float b ) { return a * Vec3fa(b); } + __forceinline Vec3fa operator *( const float a, const Vec3fa& b ) { return Vec3fa(a) * b; } + __forceinline Vec3fa operator /( const Vec3fa& a, const Vec3fa& b ) { return Vec3fa(a.x/b.x, a.y/b.y, a.z/b.z); } + __forceinline Vec3fa operator /( const Vec3fa& a, const float b ) { return Vec3fa(a.x/b, a.y/b, a.z/b); } + __forceinline Vec3fa operator /( const float a, const Vec3fa& b ) { return Vec3fa(a/b.x, a/b.y, a/b.z); } + + __forceinline Vec3fa min( const Vec3fa& a, const Vec3fa& b ) { + return Vec3fa(sycl::fmin(a.x,b.x), sycl::fmin(a.y,b.y), sycl::fmin(a.z,b.z)); + } + __forceinline Vec3fa max( const Vec3fa& a, const Vec3fa& b ) { + return Vec3fa(sycl::fmax(a.x,b.x), sycl::fmax(a.y,b.y), sycl::fmax(a.z,b.z)); + } + +/* +#if defined(__SSE4_1__) + __forceinline Vec3fa mini(const Vec3fa& a, const Vec3fa& b) { + const vint4 ai = _mm_castps_si128(a); + const vint4 bi = _mm_castps_si128(b); + const vint4 ci = _mm_min_epi32(ai,bi); + return _mm_castsi128_ps(ci); + } +#endif + +#if defined(__SSE4_1__) + __forceinline Vec3fa maxi(const Vec3fa& a, const Vec3fa& b) { + const vint4 ai = _mm_castps_si128(a); + const vint4 bi = _mm_castps_si128(b); + const vint4 ci = _mm_max_epi32(ai,bi); + return _mm_castsi128_ps(ci); + } +#endif +*/ + __forceinline Vec3fa pow ( const Vec3fa& a, const float& b ) { + return Vec3fa(powf(a.x,b),powf(a.y,b),powf(a.z,b)); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Ternary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa madd ( const Vec3fa& a, const Vec3fa& b, const Vec3fa& c) { return Vec3fa(madd(a.x,b.x,c.x), madd(a.y,b.y,c.y), madd(a.z,b.z,c.z)); } + __forceinline Vec3fa msub ( const Vec3fa& a, const Vec3fa& b, const Vec3fa& c) { return Vec3fa(msub(a.x,b.x,c.x), msub(a.y,b.y,c.y), msub(a.z,b.z,c.z)); } + __forceinline Vec3fa nmadd ( const Vec3fa& a, const Vec3fa& b, const Vec3fa& c) { return Vec3fa(nmadd(a.x,b.x,c.x), nmadd(a.y,b.y,c.y), nmadd(a.z,b.z,c.z)); } + __forceinline Vec3fa nmsub ( const Vec3fa& a, const Vec3fa& b, const Vec3fa& c) { return Vec3fa(nmsub(a.x,b.x,c.x), nmsub(a.y,b.y,c.y), nmsub(a.z,b.z,c.z)); } + + __forceinline Vec3fa madd ( const float a, const Vec3fa& b, const Vec3fa& c) { return madd(Vec3fa(a),b,c); } + __forceinline Vec3fa msub ( const float a, const Vec3fa& b, const Vec3fa& c) { return msub(Vec3fa(a),b,c); } + __forceinline Vec3fa nmadd ( const float a, const Vec3fa& b, const Vec3fa& c) { return nmadd(Vec3fa(a),b,c); } + __forceinline Vec3fa nmsub ( const float a, const Vec3fa& b, const Vec3fa& c) { return nmsub(Vec3fa(a),b,c); } + + //////////////////////////////////////////////////////////////////////////////// + /// Assignment Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa& operator +=( Vec3fa& a, const Vec3fa& b ) { return a = a + b; } + __forceinline Vec3fa& operator -=( Vec3fa& a, const Vec3fa& b ) { return a = a - b; } + __forceinline Vec3fa& operator *=( Vec3fa& a, const Vec3fa& b ) { return a = a * b; } + __forceinline Vec3fa& operator *=( Vec3fa& a, const float b ) { return a = a * b; } + __forceinline Vec3fa& operator /=( Vec3fa& a, const Vec3fa& b ) { return a = a / b; } + __forceinline Vec3fa& operator /=( Vec3fa& a, const float b ) { return a = a / b; } + + //////////////////////////////////////////////////////////////////////////////// + /// Reductions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float reduce_add(const Vec3fa& v) { return v.x+v.y+v.z; } + __forceinline float reduce_mul(const Vec3fa& v) { return v.x*v.y*v.z; } + __forceinline float reduce_min(const Vec3fa& v) { return sycl::fmin(sycl::fmin(v.x,v.y),v.z); } + __forceinline float reduce_max(const Vec3fa& v) { return sycl::fmax(sycl::fmax(v.x,v.y),v.z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Comparison Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool operator ==( const Vec3fa& a, const Vec3fa& b ) { return a.x == b.x && a.y == b.y && a.z == b.z; } + __forceinline bool operator !=( const Vec3fa& a, const Vec3fa& b ) { return a.x != b.x || a.y != b.y || a.z != b.z; } + + __forceinline Vec3ba eq_mask( const Vec3fa& a, const Vec3fa& b ) { return Vec3ba(a.x == b.x, a.y == b.y, a.z == b.z); } + __forceinline Vec3ba neq_mask(const Vec3fa& a, const Vec3fa& b ) { return Vec3ba(a.x != b.x, a.y != b.y, a.z != b.z); } + __forceinline Vec3ba lt_mask( const Vec3fa& a, const Vec3fa& b ) { return Vec3ba(a.x < b.x, a.y < b.y, a.z < b.z); } + __forceinline Vec3ba le_mask( const Vec3fa& a, const Vec3fa& b ) { return Vec3ba(a.x <= b.x, a.y <= b.y, a.z <= b.z); } + __forceinline Vec3ba gt_mask( const Vec3fa& a, const Vec3fa& b ) { return Vec3ba(a.x > b.x, a.y > b.y, a.z > b.z); } + __forceinline Vec3ba ge_mask( const Vec3fa& a, const Vec3fa& b ) { return Vec3ba(a.x >= b.x, a.y >= b.y, a.z >= b.z); } + + __forceinline bool isvalid ( const Vec3fa& v ) { + return all(gt_mask(v,Vec3fa(-FLT_LARGE)) & lt_mask(v,Vec3fa(+FLT_LARGE))); + } + + __forceinline bool is_finite ( const Vec3fa& a ) { + return all(ge_mask(a,Vec3fa(-FLT_MAX)) & le_mask(a,Vec3fa(+FLT_MAX))); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Euclidian Space Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float dot ( const Vec3fa& a, const Vec3fa& b ) { + return reduce_add(a*b); + } + + __forceinline Vec3fa cross ( const Vec3fa& a, const Vec3fa& b ) { + return Vec3fa(msub(a.y,b.z,a.z*b.y), msub(a.z,b.x,a.x*b.z), msub(a.x,b.y,a.y*b.x)); + } + + __forceinline float sqr_length ( const Vec3fa& a ) { return dot(a,a); } + __forceinline float rcp_length ( const Vec3fa& a ) { return rsqrt(dot(a,a)); } + __forceinline float rcp_length2( const Vec3fa& a ) { return rcp(dot(a,a)); } + __forceinline float length ( const Vec3fa& a ) { return sqrt(dot(a,a)); } + __forceinline Vec3fa normalize( const Vec3fa& a ) { return a*rsqrt(dot(a,a)); } + __forceinline float distance ( const Vec3fa& a, const Vec3fa& b ) { return length(a-b); } + __forceinline float halfArea ( const Vec3fa& d ) { return madd(d.x,(d.y+d.z),d.y*d.z); } + __forceinline float area ( const Vec3fa& d ) { return 2.0f*halfArea(d); } + + __forceinline Vec3fa normalize_safe( const Vec3fa& a ) { + const float d = dot(a,a); if (unlikely(d == 0.0f)) return a; else return a*rsqrt(d); + } + + /*! differentiated normalization */ + __forceinline Vec3fa dnormalize(const Vec3fa& p, const Vec3fa& dp) + { + const float pp = dot(p,p); + const float pdp = dot(p,dp); + return (pp*dp-pdp*p)*rcp(pp)*rsqrt(pp); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Select + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa select( bool s, const Vec3fa& t, const Vec3fa& f ) { + return Vec3fa(s ? t.x : f.x, s ? t.y : f.y, s ? t.z : f.z); + } + + __forceinline Vec3fa select( const Vec3ba& s, const Vec3fa& t, const Vec3fa& f ) { + return Vec3fa(s.x ? t.x : f.x, s.y ? t.y : f.y, s.z ? t.z : f.z); + } + + __forceinline Vec3fa lerp(const Vec3fa& v0, const Vec3fa& v1, const float t) { + return madd(1.0f-t,v0,t*v1); + } + + __forceinline int maxDim ( const Vec3fa& a ) + { + const Vec3fa b = abs(a); + if (b.x > b.y) { + if (b.x > b.z) return 0; else return 2; + } else { + if (b.y > b.z) return 1; else return 2; + } + } + + //////////////////////////////////////////////////////////////////////////////// + /// Rounding Functions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fa trunc( const Vec3fa& a ) { return Vec3fa(sycl::trunc(a.x),sycl::trunc(a.y),sycl::trunc(a.z)); } + __forceinline Vec3fa floor( const Vec3fa& a ) { return Vec3fa(sycl::floor(a.x),sycl::floor(a.y),sycl::floor(a.z)); } + __forceinline Vec3fa ceil ( const Vec3fa& a ) { return Vec3fa(sycl::ceil (a.x),sycl::ceil (a.y),sycl::ceil (a.z)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Output Operators + //////////////////////////////////////////////////////////////////////////////// + + inline embree_ostream operator<<(embree_ostream cout, const Vec3fa& a) { + return cout << "(" << a.x << ", " << a.y << ", " << a.z << ")"; + } + + __forceinline Vec2fa::Vec2fa(const Vec3fa& a) + : x(a.x), y(a.y) {} + + __forceinline Vec3ia::Vec3ia( const Vec3fa& a ) + : x((int)a.x), y((int)a.y), z((int)a.z) {} + + typedef Vec3fa Vec3fa_t; + + + + //////////////////////////////////////////////////////////////////////////////// + /// SSE Vec3fx Type + //////////////////////////////////////////////////////////////////////////////// + + struct __aligned(16) Vec3fx + { + //ALIGNED_STRUCT_(16); + + typedef float Scalar; + enum { N = 3 }; + struct { float x,y,z; union { int a; unsigned u; float w; }; }; + + //////////////////////////////////////////////////////////////////////////////// + /// Constructors, Assignment & Cast Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx( ) {} + //__forceinline Vec3fx( const __m128 a ) : m128(a) {} + __forceinline explicit Vec3fx(const vfloat4& a) : x(a[0]), y(a[1]), z(a[2]), w(a[3]) {} + + __forceinline explicit Vec3fx(const Vec3fa& v) : x(v.x), y(v.y), z(v.z), w(0.0f) {} + __forceinline operator Vec3fa() const { return Vec3fa(x,y,z); } + + __forceinline explicit Vec3fx ( const Vec3& other ) { x = other.x; y = other.y; z = other.z; } + //__forceinline Vec3fx& operator =( const Vec3& other ) { x = other.x; y = other.y; z = other.z; return *this; } + + //__forceinline Vec3fx ( const Vec3fx& other ) { *(sycl::float4*)this = *(const sycl::float4*)&other; } + //__forceinline Vec3fx& operator =( const Vec3fx& other ) { *(sycl::float4*)this = *(const sycl::float4*)&other; return *this; } + + __forceinline explicit Vec3fx( const float a ) : x(a), y(a), z(a), w(a) {} + __forceinline Vec3fx( const float x, const float y, const float z) : x(x), y(y), z(z), w(z) {} + + __forceinline Vec3fx( const Vec3fa& other, const int a1) : x(other.x), y(other.y), z(other.z), a(a1) {} + __forceinline Vec3fx( const Vec3fa& other, const unsigned a1) : x(other.x), y(other.y), z(other.z), u(a1) {} + __forceinline Vec3fx( const Vec3fa& other, const float w1) : x(other.x), y(other.y), z(other.z), w(w1) {} + + //__forceinline Vec3fx( const float x, const float y, const float z, const int a) : x(x), y(y), z(z), a(a) {} // not working properly! + //__forceinline Vec3fx( const float x, const float y, const float z, const unsigned a) : x(x), y(y), z(z), u(a) {} // not working properly! + __forceinline Vec3fx( const float x, const float y, const float z, const float w) : x(x), y(y), z(z), w(w) {} + + __forceinline explicit Vec3fx( const Vec3ia& a ) : x((float)a.x), y((float)a.y), z((float)a.z), w(0.0f) {} + + //__forceinline operator const __m128&() const { return m128; } + //__forceinline operator __m128&() { return m128; } + __forceinline operator vfloat4() const { return vfloat4(x,y,z,w); } + + //friend __forceinline Vec3fx copy_a( const Vec3fx& a, const Vec3fx& b ) { Vec3fx c = a; c.a = b.a; return c; } + + //////////////////////////////////////////////////////////////////////////////// + /// Loads and Stores + //////////////////////////////////////////////////////////////////////////////// + + static __forceinline Vec3fx load( const void* const a ) { + const float* ptr = (const float*)a; + return Vec3fx(ptr[0],ptr[1],ptr[2],ptr[3]); + } + + static __forceinline Vec3fx loadu( const void* const a ) { + const float* ptr = (const float*)a; + return Vec3fx(ptr[0],ptr[1],ptr[2],ptr[3]); + } + + static __forceinline void storeu ( void* a, const Vec3fx& v ) { + float* ptr = (float*)a; + ptr[0] = v.x; ptr[1] = v.y; ptr[2] = v.z; ptr[3] = v.w; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx( ZeroTy ) : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} + __forceinline Vec3fx( OneTy ) : x(1.0f), y(1.0f), z(1.0f), w(1.0f) {} + __forceinline Vec3fx( PosInfTy ) : x(+INFINITY), y(+INFINITY), z(+INFINITY), w(+INFINITY) {} + __forceinline Vec3fx( NegInfTy ) : x(-INFINITY), y(-INFINITY), z(-INFINITY), w(-INFINITY) {} + + //////////////////////////////////////////////////////////////////////////////// + /// Array Access + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const float& operator []( const size_t index ) const { assert(index < 3); return (&x)[index]; } + __forceinline float& operator []( const size_t index ) { assert(index < 3); return (&x)[index]; } + }; + + //////////////////////////////////////////////////////////////////////////////// + /// Unary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx operator +( const Vec3fx& a ) { return a; } + __forceinline Vec3fx operator -( const Vec3fx& a ) { return Vec3fx(-a.x,-a.y,-a.z,-a.w); } + __forceinline Vec3fx abs ( const Vec3fx& a ) { return Vec3fx(sycl::fabs(a.x),sycl::fabs(a.y),sycl::fabs(a.z),sycl::fabs(a.w)); } + __forceinline Vec3fx sign ( const Vec3fx& a ) { return Vec3fx(sycl::sign(a.x),sycl::sign(a.y),sycl::sign(a.z),sycl::sign(a.z)); } + + //__forceinline Vec3fx rcp ( const Vec3fx& a ) { return Vec3fx(sycl::recip(a.x),sycl::recip(a.y),sycl::recip(a.z)); } + __forceinline Vec3fx rcp ( const Vec3fx& a ) { return Vec3fx(__sycl_std::__invoke_native_recip(a.x),__sycl_std::__invoke_native_recip(a.y),__sycl_std::__invoke_native_recip(a.z),__sycl_std::__invoke_native_recip(a.w)); } + __forceinline Vec3fx sqrt ( const Vec3fx& a ) { return Vec3fx(sycl::sqrt(a.x),sycl::sqrt(a.y),sycl::sqrt(a.z),sycl::sqrt(a.w)); } + __forceinline Vec3fx sqr ( const Vec3fx& a ) { return Vec3fx(a.x*a.x,a.y*a.y,a.z*a.z,a.w*a.w); } + + __forceinline Vec3fx rsqrt( const Vec3fx& a ) { return Vec3fx(sycl::rsqrt(a.x),sycl::rsqrt(a.y),sycl::rsqrt(a.z),sycl::rsqrt(a.w)); } + + __forceinline Vec3fx zero_fix(const Vec3fx& a) { + const float x = sycl::fabs(a.x) < min_rcp_input ? min_rcp_input : a.x; + const float y = sycl::fabs(a.y) < min_rcp_input ? min_rcp_input : a.y; + const float z = sycl::fabs(a.z) < min_rcp_input ? min_rcp_input : a.z; + return Vec3fx(x,y,z); + } + __forceinline Vec3fx rcp_safe(const Vec3fx& a) { + return rcp(zero_fix(a)); + } + __forceinline Vec3fx log ( const Vec3fx& a ) { + return Vec3fx(sycl::log(a.x),sycl::log(a.y),sycl::log(a.z)); + } + + __forceinline Vec3fx exp ( const Vec3fx& a ) { + return Vec3fx(sycl::exp(a.x),sycl::exp(a.y),sycl::exp(a.z)); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Binary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx operator +( const Vec3fx& a, const Vec3fx& b ) { return Vec3fx(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); } + __forceinline Vec3fx operator -( const Vec3fx& a, const Vec3fx& b ) { return Vec3fx(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w); } + __forceinline Vec3fx operator *( const Vec3fx& a, const Vec3fx& b ) { return Vec3fx(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w); } + __forceinline Vec3fx operator *( const Vec3fx& a, const float b ) { return a * Vec3fx(b); } + __forceinline Vec3fx operator *( const float a, const Vec3fx& b ) { return Vec3fx(a) * b; } + __forceinline Vec3fx operator /( const Vec3fx& a, const Vec3fx& b ) { return Vec3fx(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w); } + __forceinline Vec3fx operator /( const Vec3fx& a, const float b ) { return Vec3fx(a.x/b, a.y/b, a.z/b, a.w/b); } + __forceinline Vec3fx operator /( const float a, const Vec3fx& b ) { return Vec3fx(a/b.x, a/b.y, a/b.z, a/b.w); } + + __forceinline Vec3fx min( const Vec3fx& a, const Vec3fx& b ) { + return Vec3fx(sycl::fmin(a.x,b.x), sycl::fmin(a.y,b.y), sycl::fmin(a.z,b.z), sycl::fmin(a.w,b.w)); + } + __forceinline Vec3fx max( const Vec3fx& a, const Vec3fx& b ) { + return Vec3fx(sycl::fmax(a.x,b.x), sycl::fmax(a.y,b.y), sycl::fmax(a.z,b.z), sycl::fmax(a.w,b.w)); + } + +/* +#if defined(__SSE4_1__) + __forceinline Vec3fx mini(const Vec3fx& a, const Vec3fx& b) { + const vint4 ai = _mm_castps_si128(a); + const vint4 bi = _mm_castps_si128(b); + const vint4 ci = _mm_min_epi32(ai,bi); + return _mm_castsi128_ps(ci); + } +#endif + +#if defined(__SSE4_1__) + __forceinline Vec3fx maxi(const Vec3fx& a, const Vec3fx& b) { + const vint4 ai = _mm_castps_si128(a); + const vint4 bi = _mm_castps_si128(b); + const vint4 ci = _mm_max_epi32(ai,bi); + return _mm_castsi128_ps(ci); + } +#endif + + __forceinline Vec3fx pow ( const Vec3fx& a, const float& b ) { + return Vec3fx(powf(a.x,b),powf(a.y,b),powf(a.z,b)); + } +*/ + + //////////////////////////////////////////////////////////////////////////////// + /// Ternary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx madd ( const Vec3fx& a, const Vec3fx& b, const Vec3fx& c) { return Vec3fx(madd(a.x,b.x,c.x), madd(a.y,b.y,c.y), madd(a.z,b.z,c.z), madd(a.w,b.w,c.w)); } + __forceinline Vec3fx msub ( const Vec3fx& a, const Vec3fx& b, const Vec3fx& c) { return Vec3fx(msub(a.x,b.x,c.x), msub(a.y,b.y,c.y), msub(a.z,b.z,c.z), msub(a.w,b.w,c.w)); } + __forceinline Vec3fx nmadd ( const Vec3fx& a, const Vec3fx& b, const Vec3fx& c) { return Vec3fx(nmadd(a.x,b.x,c.x), nmadd(a.y,b.y,c.y), nmadd(a.z,b.z,c.z), nmadd(a.w,b.w,c.w)); } + __forceinline Vec3fx nmsub ( const Vec3fx& a, const Vec3fx& b, const Vec3fx& c) { return Vec3fx(nmsub(a.x,b.x,c.x), nmsub(a.y,b.y,c.y), nmsub(a.z,b.z,c.z), nmsub(a.w,b.w,c.w)); } + + __forceinline Vec3fx madd ( const float a, const Vec3fx& b, const Vec3fx& c) { return madd(Vec3fx(a),b,c); } + __forceinline Vec3fx msub ( const float a, const Vec3fx& b, const Vec3fx& c) { return msub(Vec3fx(a),b,c); } + __forceinline Vec3fx nmadd ( const float a, const Vec3fx& b, const Vec3fx& c) { return nmadd(Vec3fx(a),b,c); } + __forceinline Vec3fx nmsub ( const float a, const Vec3fx& b, const Vec3fx& c) { return nmsub(Vec3fx(a),b,c); } + + //////////////////////////////////////////////////////////////////////////////// + /// Assignment Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx& operator +=( Vec3fx& a, const Vec3fx& b ) { return a = a + b; } + __forceinline Vec3fx& operator -=( Vec3fx& a, const Vec3fx& b ) { return a = a - b; } + __forceinline Vec3fx& operator *=( Vec3fx& a, const Vec3fx& b ) { return a = a * b; } + __forceinline Vec3fx& operator *=( Vec3fx& a, const float b ) { return a = a * b; } + __forceinline Vec3fx& operator /=( Vec3fx& a, const Vec3fx& b ) { return a = a / b; } + __forceinline Vec3fx& operator /=( Vec3fx& a, const float b ) { return a = a / b; } + + //////////////////////////////////////////////////////////////////////////////// + /// Reductions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float reduce_add(const Vec3fx& v) { return v.x+v.y+v.z; } + __forceinline float reduce_mul(const Vec3fx& v) { return v.x*v.y*v.z; } + __forceinline float reduce_min(const Vec3fx& v) { return sycl::fmin(sycl::fmin(v.x,v.y),v.z); } + __forceinline float reduce_max(const Vec3fx& v) { return sycl::fmax(sycl::fmax(v.x,v.y),v.z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Comparison Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool operator ==( const Vec3fx& a, const Vec3fx& b ) { return a.x == b.x && a.y == b.y && a.z == b.z; } + __forceinline bool operator !=( const Vec3fx& a, const Vec3fx& b ) { return a.x != b.x || a.y != b.y || a.z != b.z; } + + __forceinline Vec3ba eq_mask( const Vec3fx& a, const Vec3fx& b ) { return Vec3ba(a.x == b.x, a.y == b.y, a.z == b.z); } + __forceinline Vec3ba neq_mask(const Vec3fx& a, const Vec3fx& b ) { return Vec3ba(a.x != b.x, a.y != b.y, a.z != b.z); } + __forceinline Vec3ba lt_mask( const Vec3fx& a, const Vec3fx& b ) { return Vec3ba(a.x < b.x, a.y < b.y, a.z < b.z); } + __forceinline Vec3ba le_mask( const Vec3fx& a, const Vec3fx& b ) { return Vec3ba(a.x <= b.x, a.y <= b.y, a.z <= b.z); } + __forceinline Vec3ba gt_mask( const Vec3fx& a, const Vec3fx& b ) { return Vec3ba(a.x > b.x, a.y > b.y, a.z > b.z); } + __forceinline Vec3ba ge_mask( const Vec3fx& a, const Vec3fx& b ) { return Vec3ba(a.x >= b.x, a.y >= b.y, a.z >= b.z); } + + __forceinline bool isvalid ( const Vec3fx& v ) { + return all(gt_mask(v,Vec3fx(-FLT_LARGE)) & lt_mask(v,Vec3fx(+FLT_LARGE))); + } + + __forceinline bool is_finite ( const Vec3fx& a ) { + return all(ge_mask(a,Vec3fx(-FLT_MAX)) & le_mask(a,Vec3fx(+FLT_MAX))); + } + + __forceinline bool isvalid4 ( const Vec3fx& v ) { + const bool valid_x = v.x >= -FLT_LARGE & v.x <= +FLT_LARGE; + const bool valid_y = v.y >= -FLT_LARGE & v.y <= +FLT_LARGE; + const bool valid_z = v.z >= -FLT_LARGE & v.z <= +FLT_LARGE; + const bool valid_w = v.w >= -FLT_LARGE & v.w <= +FLT_LARGE; + return valid_x & valid_y & valid_z & valid_w; + } + + __forceinline bool is_finite4 ( const Vec3fx& v ) { + const bool finite_x = v.x >= -FLT_MAX & v.x <= +FLT_MAX; + const bool finite_y = v.y >= -FLT_MAX & v.y <= +FLT_MAX; + const bool finite_z = v.z >= -FLT_MAX & v.z <= +FLT_MAX; + const bool finite_w = v.w >= -FLT_MAX & v.w <= +FLT_MAX; + return finite_x & finite_y & finite_z & finite_w; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Euclidian Space Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline float dot ( const Vec3fx& a, const Vec3fx& b ) { + return reduce_add(a*b); + } + + __forceinline Vec3fx cross ( const Vec3fx& a, const Vec3fx& b ) { + return Vec3fx(msub(a.y,b.z,a.z*b.y), msub(a.z,b.x,a.x*b.z), msub(a.x,b.y,a.y*b.x)); + } + + __forceinline float sqr_length ( const Vec3fx& a ) { return dot(a,a); } + __forceinline float rcp_length ( const Vec3fx& a ) { return rsqrt(dot(a,a)); } + __forceinline float rcp_length2( const Vec3fx& a ) { return rcp(dot(a,a)); } + __forceinline float length ( const Vec3fx& a ) { return sqrt(dot(a,a)); } + __forceinline Vec3fx normalize( const Vec3fx& a ) { return a*rsqrt(dot(a,a)); } + __forceinline float distance ( const Vec3fx& a, const Vec3fx& b ) { return length(a-b); } + __forceinline float halfArea ( const Vec3fx& d ) { return madd(d.x,(d.y+d.z),d.y*d.z); } + __forceinline float area ( const Vec3fx& d ) { return 2.0f*halfArea(d); } + + __forceinline Vec3fx normalize_safe( const Vec3fx& a ) { + const float d = dot(a,a); if (unlikely(d == 0.0f)) return a; else return a*rsqrt(d); + } + + /*! differentiated normalization */ + __forceinline Vec3fx dnormalize(const Vec3fx& p, const Vec3fx& dp) + { + const float pp = dot(p,p); + const float pdp = dot(p,dp); + return (pp*dp-pdp*p)*rcp(pp)*rsqrt(pp); + } + + //////////////////////////////////////////////////////////////////////////////// + /// Select + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx select( bool s, const Vec3fx& t, const Vec3fx& f ) { + return Vec3fx(s ? t.x : f.x, s ? t.y : f.y, s ? t.z : f.z, s ? t.w : f.w); + } + + __forceinline Vec3fx select( const Vec3ba& s, const Vec3fx& t, const Vec3fx& f ) { + return Vec3fx(s.x ? t.x : f.x, s.y ? t.y : f.y, s.z ? t.z : f.z); + } + + __forceinline Vec3fx lerp(const Vec3fx& v0, const Vec3fx& v1, const float t) { + return madd(1.0f-t,v0,t*v1); + } + + __forceinline int maxDim ( const Vec3fx& a ) + { + const Vec3fx b = abs(a); + if (b.x > b.y) { + if (b.x > b.z) return 0; else return 2; + } else { + if (b.y > b.z) return 1; else return 2; + } + } + + //////////////////////////////////////////////////////////////////////////////// + /// Rounding Functions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3fx trunc( const Vec3fx& a ) { return Vec3fx(sycl::trunc(a.x),sycl::trunc(a.y),sycl::trunc(a.z),sycl::trunc(a.w)); } + __forceinline Vec3fx floor( const Vec3fx& a ) { return Vec3fx(sycl::floor(a.x),sycl::floor(a.y),sycl::floor(a.z),sycl::floor(a.w)); } + __forceinline Vec3fx ceil ( const Vec3fx& a ) { return Vec3fx(sycl::ceil (a.x),sycl::ceil (a.y),sycl::ceil (a.z),sycl::ceil (a.w)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Output Operators + //////////////////////////////////////////////////////////////////////////////// + + inline embree_ostream operator<<(embree_ostream cout, const Vec3fx& a) { + return cout << "(" << a.x << ", " << a.y << ", " << a.z << "," << a.w << ")"; + } + + typedef Vec3fx Vec3ff; + + //__forceinline Vec2fa::Vec2fa(const Vec3fx& a) + // : x(a.x), y(a.y) {} + + //__forceinline Vec3ia::Vec3ia( const Vec3fx& a ) + // : x((int)a.x), y((int)a.y), z((int)a.z) {} +} diff --git a/thirdparty/embree/common/math/vec3ia.h b/thirdparty/embree/common/math/vec3ia.h index d4cc3125cd3..1472fe9135c 100644 --- a/thirdparty/embree/common/math/vec3ia.h +++ b/thirdparty/embree/common/math/vec3ia.h @@ -4,7 +4,12 @@ #pragma once #include "../sys/alloc.h" -#include "math.h" +#include "emath.h" + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +# include "vec3ia_sycl.h" +#else + #include "../simd/sse.h" namespace embree @@ -194,3 +199,5 @@ namespace embree return cout << "(" << a.x << ", " << a.y << ", " << a.z << ")"; } } + +#endif diff --git a/thirdparty/embree/common/math/vec3ia_sycl.h b/thirdparty/embree/common/math/vec3ia_sycl.h new file mode 100644 index 00000000000..5a3d3963739 --- /dev/null +++ b/thirdparty/embree/common/math/vec3ia_sycl.h @@ -0,0 +1,178 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../sys/alloc.h" +#include "emath.h" +#include "../simd/sse.h" + +namespace embree +{ + //////////////////////////////////////////////////////////////////////////////// + /// SSE Vec3ia Type + //////////////////////////////////////////////////////////////////////////////// + + struct __aligned(16) Vec3ia + { + ALIGNED_STRUCT_(16); + + struct { int x,y,z; }; + + typedef int Scalar; + enum { N = 3 }; + + //////////////////////////////////////////////////////////////////////////////// + /// Constructors, Assignment & Cast Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ia( ) {} + //__forceinline Vec3ia( const __m128i a ) : m128(a) {} + + __forceinline Vec3ia( const Vec3ia& other ) : x(other.x), y(other.y), z(other.z) {} + __forceinline Vec3ia& operator =(const Vec3ia& other) { x = other.x; y = other.y; z = other.z; return *this; } + + __forceinline explicit Vec3ia( const int a ) : x(a), y(a), z(a) {} + __forceinline Vec3ia( const int x, const int y, const int z) : x(x), y(y), z(z) {} + //__forceinline explicit Vec3ia( const __m128 a ) : m128(_mm_cvtps_epi32(a)) {} + __forceinline explicit Vec3ia(const vint4& a) : x(a[0]), y(a[1]), z(a[2]) {} + + __forceinline explicit Vec3ia( const Vec3fa& a ); + + //__forceinline operator const __m128i&() const { return m128; } + //__forceinline operator __m128i&() { return m128; } + __forceinline operator vint4() const { return vint4(x,y,z,z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Constants + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ia( ZeroTy ) : x(0), y(0), z(0) {} + __forceinline Vec3ia( OneTy ) : x(1), y(1), z(1) {} + __forceinline Vec3ia( PosInfTy ) : x(0x7FFFFFFF), y(0x7FFFFFFF), z(0x7FFFFFFF) {} + __forceinline Vec3ia( NegInfTy ) : x(0x80000000), y(0x80000000), z(0x80000000) {} + + //////////////////////////////////////////////////////////////////////////////// + /// Array Access + //////////////////////////////////////////////////////////////////////////////// + + __forceinline const int& operator []( const size_t index ) const { assert(index < 3); return (&x)[index]; } + __forceinline int& operator []( const size_t index ) { assert(index < 3); return (&x)[index]; } + }; + + + //////////////////////////////////////////////////////////////////////////////// + /// Unary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ia operator +( const Vec3ia& a ) { return Vec3ia(+a.x,+a.y,+a.z); } + __forceinline Vec3ia operator -( const Vec3ia& a ) { return Vec3ia(-a.x,-a.y,-a.z); } + __forceinline Vec3ia abs ( const Vec3ia& a ) { return Vec3ia(sycl::abs(a.x),sycl::abs(a.y),sycl::abs(a.z)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Binary Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ia operator +( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(a.x+b.x, a.y+b.y, a.z+b.z); } + __forceinline Vec3ia operator +( const Vec3ia& a, const int b ) { return a+Vec3ia(b); } + __forceinline Vec3ia operator +( const int a, const Vec3ia& b ) { return Vec3ia(a)+b; } + + __forceinline Vec3ia operator -( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(a.x-b.x, a.y-b.y, a.z-b.z); } + __forceinline Vec3ia operator -( const Vec3ia& a, const int b ) { return a-Vec3ia(b); } + __forceinline Vec3ia operator -( const int a, const Vec3ia& b ) { return Vec3ia(a)-b; } + + __forceinline Vec3ia operator *( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(a.x*b.x, a.y*b.y, a.z*b.z); } + __forceinline Vec3ia operator *( const Vec3ia& a, const int b ) { return a * Vec3ia(b); } + __forceinline Vec3ia operator *( const int a, const Vec3ia& b ) { return Vec3ia(a) * b; } + + __forceinline Vec3ia operator &( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(a.x&b.x, a.y&b.y, a.z&b.z); } + __forceinline Vec3ia operator &( const Vec3ia& a, const int b ) { return a & Vec3ia(b); } + __forceinline Vec3ia operator &( const int a, const Vec3ia& b ) { return Vec3ia(a) & b; } + + __forceinline Vec3ia operator |( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(a.x|b.x, a.y|b.y, a.z|b.z); } + __forceinline Vec3ia operator |( const Vec3ia& a, const int b ) { return a | Vec3ia(b); } + __forceinline Vec3ia operator |( const int a, const Vec3ia& b ) { return Vec3ia(a) | b; } + + __forceinline Vec3ia operator ^( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(a.x^b.x, a.y^b.y, a.z^b.z); } + __forceinline Vec3ia operator ^( const Vec3ia& a, const int b ) { return a ^ Vec3ia(b); } + __forceinline Vec3ia operator ^( const int a, const Vec3ia& b ) { return Vec3ia(a) ^ b; } + + __forceinline Vec3ia operator <<( const Vec3ia& a, const int n ) { return Vec3ia(a.x<>( const Vec3ia& a, const int n ) { return Vec3ia(a.x>>n, a.y>>n, a.z>>n); } + + __forceinline Vec3ia sll ( const Vec3ia& a, const int b ) { return Vec3ia(a.x<>b, a.y>>b, a.z>>b); } + __forceinline Vec3ia srl ( const Vec3ia& a, const int b ) { return Vec3ia(unsigned(a.x)>>b, unsigned(a.y)>>b, unsigned(a.z)>>b); } + + //////////////////////////////////////////////////////////////////////////////// + /// Assignment Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ia& operator +=( Vec3ia& a, const Vec3ia& b ) { return a = a + b; } + __forceinline Vec3ia& operator +=( Vec3ia& a, const int& b ) { return a = a + b; } + + __forceinline Vec3ia& operator -=( Vec3ia& a, const Vec3ia& b ) { return a = a - b; } + __forceinline Vec3ia& operator -=( Vec3ia& a, const int& b ) { return a = a - b; } + + __forceinline Vec3ia& operator *=( Vec3ia& a, const Vec3ia& b ) { return a = a * b; } + __forceinline Vec3ia& operator *=( Vec3ia& a, const int& b ) { return a = a * b; } + + __forceinline Vec3ia& operator &=( Vec3ia& a, const Vec3ia& b ) { return a = a & b; } + __forceinline Vec3ia& operator &=( Vec3ia& a, const int& b ) { return a = a & b; } + + __forceinline Vec3ia& operator |=( Vec3ia& a, const Vec3ia& b ) { return a = a | b; } + __forceinline Vec3ia& operator |=( Vec3ia& a, const int& b ) { return a = a | b; } + + __forceinline Vec3ia& operator <<=( Vec3ia& a, const int& b ) { return a = a << b; } + __forceinline Vec3ia& operator >>=( Vec3ia& a, const int& b ) { return a = a >> b; } + + //////////////////////////////////////////////////////////////////////////////// + /// Reductions + //////////////////////////////////////////////////////////////////////////////// + + __forceinline int reduce_add(const Vec3ia& v) { return v.x+v.y+v.z; } + __forceinline int reduce_mul(const Vec3ia& v) { return v.x*v.y*v.z; } + __forceinline int reduce_min(const Vec3ia& v) { return sycl::min(sycl::min(v.x,v.y),v.z); } + __forceinline int reduce_max(const Vec3ia& v) { return sycl::max(sycl::max(v.x,v.y),v.z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Comparison Operators + //////////////////////////////////////////////////////////////////////////////// + + __forceinline bool operator ==( const Vec3ia& a, const Vec3ia& b ) { return a.x == b.x & a.y == b.y & a.z == b.z; } + __forceinline bool operator !=( const Vec3ia& a, const Vec3ia& b ) { return a.x != b.x & a.y != b.y & a.z != b.z; } + +/* + __forceinline bool operator < ( const Vec3ia& a, const Vec3ia& b ) { + if (a.x != b.x) return a.x < b.x; + if (a.y != b.y) return a.y < b.y; + if (a.z != b.z) return a.z < b.z; + return false; + } +*/ + __forceinline Vec3ba eq_mask( const Vec3ia& a, const Vec3ia& b ) { return Vec3ba(a.x == b.x, a.y == b.y, a.z == b.z); } + __forceinline Vec3ba lt_mask( const Vec3ia& a, const Vec3ia& b ) { return Vec3ba(a.x < b.x, a.y < b.y, a.z < b.z); } + __forceinline Vec3ba gt_mask( const Vec3ia& a, const Vec3ia& b ) { return Vec3ba(a.x > b.x, a.y > b.y, a.z > b.z); } + + //////////////////////////////////////////////////////////////////////////////// + /// Select + //////////////////////////////////////////////////////////////////////////////// + + __forceinline Vec3ia select( const Vec3ba& m, const Vec3ia& t, const Vec3ia& f ) { + const int x = m.x ? t.x : f.x; + const int y = m.y ? t.y : f.y; + const int z = m.z ? t.z : f.z; + return Vec3ia(x,y,z); + } + + __forceinline Vec3ia min( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(sycl::min(a.x,b.x), sycl::min(a.y,b.y), sycl::min(a.z,b.z)); } + __forceinline Vec3ia max( const Vec3ia& a, const Vec3ia& b ) { return Vec3ia(sycl::max(a.x,b.x), sycl::max(a.y,b.y), sycl::max(a.z,b.z)); } + + //////////////////////////////////////////////////////////////////////////////// + /// Output Operators + //////////////////////////////////////////////////////////////////////////////// + + inline embree_ostream operator<<(embree_ostream cout, const Vec3ia& a) { + return cout; + } +} diff --git a/thirdparty/embree/common/math/vec4.h b/thirdparty/embree/common/math/vec4.h index 10c53f47b43..5647859257a 100644 --- a/thirdparty/embree/common/math/vec4.h +++ b/thirdparty/embree/common/math/vec4.h @@ -3,7 +3,7 @@ #pragma once -#include "math.h" +#include "emath.h" #include "vec3.h" namespace embree @@ -221,6 +221,8 @@ namespace embree { template<> __forceinline Vec4::Vec4( const Vec3fx& a ) { x = a.x; y = a.y; z = a.z; w = a.w; } +#if !defined(__SYCL_DEVICE_ONLY__) + #if defined(__AVX__) template<> __forceinline Vec4::Vec4( const Vec3fx& a ) { x = a.x; y = a.y; z = a.z; w = a.w; @@ -240,4 +242,25 @@ namespace embree #if defined(__AVX512F__) template<> __forceinline Vec4::Vec4( const Vec3fx& a ) : x(a.x), y(a.y), z(a.z), w(a.w) {} #endif + +#else + +#if defined(__SSE__) + template<> __forceinline Vec4::Vec4(const Vec3fx& a) { + x = a.x; y = a.y; z = a.z; w = a.w; + } +#endif +#if defined(__AVX__) + template<> __forceinline Vec4::Vec4(const Vec3fx& a) { + x = a.x; y = a.y; z = a.z; w = a.w; + } +#endif +#if defined(__AVX512F__) + template<> __forceinline Vec4::Vec4(const Vec3fx& a) { + x = a.x; y = a.y; z = a.z; w = a.w; + } +#endif + +#endif } + diff --git a/thirdparty/embree/common/simd/arm/emulation.h b/thirdparty/embree/common/simd/arm/emulation.h index 43272980198..8eea1ffe714 100644 --- a/thirdparty/embree/common/simd/arm/emulation.h +++ b/thirdparty/embree/common/simd/arm/emulation.h @@ -34,6 +34,7 @@ __forceinline __m128 _mm_broadcast_ss (float const * mem_addr) #define _MM_SET_EXCEPTION_MASK(x) // #define _MM_SET_FLUSH_ZERO_MODE(x) +/* __forceinline int _mm_getcsr() { return 0; @@ -43,6 +44,7 @@ __forceinline void _mm_mfence() { __sync_synchronize(); } +*/ __forceinline __m128i _mm_load4epu8_epi32(__m128i *ptr) { diff --git a/thirdparty/embree/common/simd/arm/sse2neon.h b/thirdparty/embree/common/simd/arm/sse2neon.h index 43416662d72..b18d41e783f 100644 --- a/thirdparty/embree/common/simd/arm/sse2neon.h +++ b/thirdparty/embree/common/simd/arm/sse2neon.h @@ -4,8 +4,6 @@ // This header file provides a simple API translation layer // between SSE intrinsics to their corresponding Arm/Aarch64 NEON versions // -// This header file does not yet translate all of the SSE intrinsics. -// // Contributors to this work are: // John W. Ratcliff // Brandon Rowlett @@ -13,8 +11,8 @@ // Eric van Beurden // Alexander Potylitsin // Hasindu Gamaarachchi -// Jim Huang -// Mark Cheng +// Jim Huang +// Mark Cheng // Malcolm James MacLeod // Devin Hussey (easyaspi314) // Sebastian Pop @@ -22,9 +20,12 @@ // Danila Kutenin // François Turban (JishinMaster) // Pei-Hsuan Hung -// Yang-Hao Yuan +// Yang-Hao Yuan // Syoyo Fujita // Brecht Van Lommel +// Jonathan Hue +// Cuda Chen +// Aymen Qader /* * sse2neon is freely redistributable under the MIT License. @@ -54,7 +55,7 @@ * This would slow down the computation a bit, but gives consistent result with * x86 SSE. (e.g. would solve a hole or NaN pixel in the rendering result) */ -/* _mm_min_ps and _mm_max_ps */ +/* _mm_min|max_ps|ss|pd|sd */ #ifndef SSE2NEON_PRECISE_MINMAX #define SSE2NEON_PRECISE_MINMAX (0) #endif @@ -91,9 +92,61 @@ #define _sse2neon_unlikely(x) (x) #endif +/* C language does not allow initializing a variable with a function call. */ +#ifdef __cplusplus +#define _sse2neon_const static const +#else +#define _sse2neon_const const +#endif + #include #include +#if defined(_WIN32) +/* Definitions for _mm_{malloc,free} are provided by + * from both MinGW-w64 and MSVC. + */ +#define SSE2NEON_ALLOC_DEFINED +#endif + +/* If using MSVC */ +#ifdef _MSC_VER +#include +#if (defined(_M_AMD64) || defined(__x86_64__)) || \ + (defined(_M_ARM) || defined(__arm__)) +#define SSE2NEON_HAS_BITSCAN64 +#endif +#endif + +/* Compiler barrier */ +#define SSE2NEON_BARRIER() \ + do { \ + __asm__ __volatile__("" ::: "memory"); \ + (void) 0; \ + } while (0) + +/* Memory barriers + * __atomic_thread_fence does not include a compiler barrier; instead, + * the barrier is part of __atomic_load/__atomic_store's "volatile-like" + * semantics. + */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#include +#endif + +FORCE_INLINE void _sse2neon_smp_mb(void) +{ + SSE2NEON_BARRIER(); +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(__STDC_NO_ATOMICS__) + atomic_thread_fence(memory_order_seq_cst); +#elif defined(__GNUC__) || defined(__clang__) + __atomic_thread_fence(__ATOMIC_SEQ_CST); +#else + /* FIXME: MSVC support */ +#endif +} + /* Architecture-specific build options */ /* FIXME: #pragma GCC push_options is only available on GCC */ #if defined(__GNUC__) @@ -114,27 +167,70 @@ #pragma GCC push_options #pragma GCC target("+simd") #endif +#elif __ARM_ARCH == 8 +#if !defined(__ARM_NEON) || !defined(__ARM_NEON__) +#error \ + "You must enable NEON instructions (e.g. -mfpu=neon-fp-armv8) to use SSE2NEON." +#endif +#if !defined(__clang__) +#pragma GCC push_options +#endif #else #error "Unsupported target. Must be either ARMv7-A+NEON or ARMv8-A." #endif #endif #include +#if !defined(__aarch64__) && (__ARM_ARCH == 8) +#if defined __has_include && __has_include() +#include +#endif +#endif + +/* Apple Silicon cache lines are double of what is commonly used by Intel, AMD + * and other Arm microarchtectures use. + * From sysctl -a on Apple M1: + * hw.cachelinesize: 128 + */ +#if defined(__APPLE__) && (defined(__aarch64__) || defined(__arm64__)) +#define SSE2NEON_CACHELINE_SIZE 128 +#else +#define SSE2NEON_CACHELINE_SIZE 64 +#endif /* Rounding functions require either Aarch64 instructions or libm failback */ #if !defined(__aarch64__) #include #endif +/* On ARMv7, some registers, such as PMUSERENR and PMCCNTR, are read-only + * or even not accessible in user mode. + * To write or access to these registers in user mode, + * we have to perform syscall instead. + */ +#if !defined(__aarch64__) +#include +#endif + /* "__has_builtin" can be used to query support for built-in functions * provided by gcc/clang and other compilers that support it. */ #ifndef __has_builtin /* GCC prior to 10 or non-clang compilers */ /* Compatibility with gcc <= 9 */ -#if __GNUC__ <= 9 +#if defined(__GNUC__) && (__GNUC__ <= 9) #define __has_builtin(x) HAS##x #define HAS__builtin_popcount 1 #define HAS__builtin_popcountll 1 + +// __builtin_shuffle introduced in GCC 4.7.0 +#if (__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) +#define HAS__builtin_shuffle 1 +#else +#define HAS__builtin_shuffle 0 +#endif + +#define HAS__builtin_shufflevector 0 +#define HAS__builtin_nontemporal_store 0 #else #define __has_builtin(x) 0 #endif @@ -159,6 +255,26 @@ #define _MM_SHUFFLE(fp3, fp2, fp1, fp0) \ (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | ((fp0))) +#if __has_builtin(__builtin_shufflevector) +#define _sse2neon_shuffle(type, a, b, ...) \ + __builtin_shufflevector(a, b, __VA_ARGS__) +#elif __has_builtin(__builtin_shuffle) +#define _sse2neon_shuffle(type, a, b, ...) \ + __extension__({ \ + type tmp = {__VA_ARGS__}; \ + __builtin_shuffle(a, b, tmp); \ + }) +#endif + +#ifdef _sse2neon_shuffle +#define vshuffle_s16(a, b, ...) _sse2neon_shuffle(int16x4_t, a, b, __VA_ARGS__) +#define vshuffleq_s16(a, b, ...) _sse2neon_shuffle(int16x8_t, a, b, __VA_ARGS__) +#define vshuffle_s32(a, b, ...) _sse2neon_shuffle(int32x2_t, a, b, __VA_ARGS__) +#define vshuffleq_s32(a, b, ...) _sse2neon_shuffle(int32x4_t, a, b, __VA_ARGS__) +#define vshuffle_s64(a, b, ...) _sse2neon_shuffle(int64x1_t, a, b, __VA_ARGS__) +#define vshuffleq_s64(a, b, ...) _sse2neon_shuffle(int64x2_t, a, b, __VA_ARGS__) +#endif + /* Rounding mode macros. */ #define _MM_FROUND_TO_NEAREST_INT 0x00 #define _MM_FROUND_TO_NEG_INF 0x01 @@ -166,6 +282,13 @@ #define _MM_FROUND_TO_ZERO 0x03 #define _MM_FROUND_CUR_DIRECTION 0x04 #define _MM_FROUND_NO_EXC 0x08 +#define _MM_FROUND_RAISE_EXC 0x00 +#define _MM_FROUND_NINT (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC) +#define _MM_FROUND_FLOOR (_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC) +#define _MM_FROUND_CEIL (_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC) +#define _MM_FROUND_TRUNC (_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC) +#define _MM_FROUND_RINT (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC) +#define _MM_FROUND_NEARBYINT (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC) #define _MM_ROUND_NEAREST 0x0000 #define _MM_ROUND_DOWN 0x2000 #define _MM_ROUND_UP 0x4000 @@ -198,10 +321,17 @@ typedef float64x2_t __m128d; /* 128-bit vector containing 2 doubles */ #else typedef float32x4_t __m128d; #endif -// Note: upstream sse2neon declares __m128i as int64x2_t. However, there's -// many places within embree that assume __m128i can be indexed as a -// 4 element u32. -typedef int32x4_t __m128i; /* 128-bit vector containing integers */ +typedef int64x2_t __m128i; /* 128-bit vector containing integers */ + +// __int64 is defined in the Intrinsics Guide which maps to different datatype +// in different data model +#if !(defined(_WIN32) || defined(_WIN64) || defined(__int64)) +#if (defined(__x86_64__) || defined(__i386__)) +#define __int64 long long +#else +#define __int64 int64_t +#endif +#endif /* type-safe casting between types */ @@ -233,28 +363,28 @@ typedef int32x4_t __m128i; /* 128-bit vector containing integers */ #define vreinterpretq_s32_m128(x) vreinterpretq_s32_f32(x) #define vreinterpretq_s64_m128(x) vreinterpretq_s64_f32(x) -#define vreinterpretq_m128i_s8(x) vreinterpretq_s32_s8(x) -#define vreinterpretq_m128i_s16(x) vreinterpretq_s32_s16(x) -#define vreinterpretq_m128i_s32(x) (x) -#define vreinterpretq_m128i_s64(x) vreinterpretq_s32_s64(x) +#define vreinterpretq_m128i_s8(x) vreinterpretq_s64_s8(x) +#define vreinterpretq_m128i_s16(x) vreinterpretq_s64_s16(x) +#define vreinterpretq_m128i_s32(x) vreinterpretq_s64_s32(x) +#define vreinterpretq_m128i_s64(x) (x) -#define vreinterpretq_m128i_u8(x) vreinterpretq_s32_u8(x) -#define vreinterpretq_m128i_u16(x) vreinterpretq_s32_u16(x) -#define vreinterpretq_m128i_u32(x) vreinterpretq_s32_u32(x) -#define vreinterpretq_m128i_u64(x) vreinterpretq_s32_u64(x) +#define vreinterpretq_m128i_u8(x) vreinterpretq_s64_u8(x) +#define vreinterpretq_m128i_u16(x) vreinterpretq_s64_u16(x) +#define vreinterpretq_m128i_u32(x) vreinterpretq_s64_u32(x) +#define vreinterpretq_m128i_u64(x) vreinterpretq_s64_u64(x) -#define vreinterpretq_f32_m128i(x) vreinterpretq_f32_s32(x) -#define vreinterpretq_f64_m128i(x) vreinterpretq_f64_s32(x) +#define vreinterpretq_f32_m128i(x) vreinterpretq_f32_s64(x) +#define vreinterpretq_f64_m128i(x) vreinterpretq_f64_s64(x) -#define vreinterpretq_s8_m128i(x) vreinterpretq_s8_s32(x) -#define vreinterpretq_s16_m128i(x) vreinterpretq_s16_s32(x) -#define vreinterpretq_s32_m128i(x) (x) -#define vreinterpretq_s64_m128i(x) vreinterpretq_s64_s32(x) +#define vreinterpretq_s8_m128i(x) vreinterpretq_s8_s64(x) +#define vreinterpretq_s16_m128i(x) vreinterpretq_s16_s64(x) +#define vreinterpretq_s32_m128i(x) vreinterpretq_s32_s64(x) +#define vreinterpretq_s64_m128i(x) (x) -#define vreinterpretq_u8_m128i(x) vreinterpretq_u8_s32(x) -#define vreinterpretq_u16_m128i(x) vreinterpretq_u16_s32(x) -#define vreinterpretq_u32_m128i(x) vreinterpretq_u32_s32(x) -#define vreinterpretq_u64_m128i(x) vreinterpretq_u64_s32(x) +#define vreinterpretq_u8_m128i(x) vreinterpretq_u8_s64(x) +#define vreinterpretq_u16_m128i(x) vreinterpretq_u16_s64(x) +#define vreinterpretq_u32_m128i(x) vreinterpretq_u32_s64(x) +#define vreinterpretq_u64_m128i(x) vreinterpretq_u64_s64(x) #define vreinterpret_m64_s8(x) vreinterpret_s64_s8(x) #define vreinterpret_m64_s16(x) vreinterpret_s64_s16(x) @@ -394,7 +524,7 @@ FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t, uint8_t); // Older gcc does not define vld1q_u8_x4 type #if defined(__GNUC__) && !defined(__clang__) && \ - ((__GNUC__ <= 10 && defined(__arm__)) || \ + ((__GNUC__ <= 12 && defined(__arm__)) || \ (__GNUC__ == 10 && __GNUC_MINOR__ < 3 && defined(__aarch64__)) || \ (__GNUC__ <= 9 && defined(__aarch64__))) FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) @@ -414,6 +544,57 @@ FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) } #endif +#if !defined(__aarch64__) +/* emulate vaddv u8 variant */ +FORCE_INLINE uint8_t _sse2neon_vaddv_u8(uint8x8_t v8) +{ + const uint64x1_t v1 = vpaddl_u32(vpaddl_u16(vpaddl_u8(v8))); + return vget_lane_u8(vreinterpret_u8_u64(v1), 0); +} +#else +// Wraps vaddv_u8 +FORCE_INLINE uint8_t _sse2neon_vaddv_u8(uint8x8_t v8) +{ + return vaddv_u8(v8); +} +#endif + +#if !defined(__aarch64__) +/* emulate vaddvq u8 variant */ +FORCE_INLINE uint8_t _sse2neon_vaddvq_u8(uint8x16_t a) +{ + uint8x8_t tmp = vpadd_u8(vget_low_u8(a), vget_high_u8(a)); + uint8_t res = 0; + for (int i = 0; i < 8; ++i) + res += tmp[i]; + return res; +} +#else +// Wraps vaddvq_u8 +FORCE_INLINE uint8_t _sse2neon_vaddvq_u8(uint8x16_t a) +{ + return vaddvq_u8(a); +} +#endif + +#if !defined(__aarch64__) +/* emulate vaddvq u16 variant */ +FORCE_INLINE uint16_t _sse2neon_vaddvq_u16(uint16x8_t a) +{ + uint32x4_t m = vpaddlq_u16(a); + uint64x2_t n = vpaddlq_u32(m); + uint64x1_t o = vget_low_u64(n) + vget_high_u64(n); + + return vget_lane_u32((uint32x2_t) o, 0); +} +#else +// Wraps vaddvq_u16 +FORCE_INLINE uint16_t _sse2neon_vaddvq_u16(uint16x8_t a) +{ + return vaddvq_u16(a); +} +#endif + /* Function Naming Conventions * The naming convention of SSE intrinsics is straightforward. A generic SSE * intrinsic function is given as follows: @@ -491,16 +672,12 @@ FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) +------+------+------+------+------+------+-------------+ */ -/* Constants for use with _mm_prefetch. */ +/* Constants for use with _mm_prefetch. */ enum _mm_hint { - _MM_HINT_NTA = 0, /* load data to L1 and L2 cache, mark it as NTA */ - _MM_HINT_T0 = 1, /* load data to L1 and L2 cache */ - _MM_HINT_T1 = 2, /* load data to L2 cache only */ - _MM_HINT_T2 = 3, /* load data to L2 cache only, mark it as NTA */ - _MM_HINT_ENTA = 4, /* exclusive version of _MM_HINT_NTA */ - _MM_HINT_ET0 = 5, /* exclusive version of _MM_HINT_T0 */ - _MM_HINT_ET1 = 6, /* exclusive version of _MM_HINT_T1 */ - _MM_HINT_ET2 = 7 /* exclusive version of _MM_HINT_T2 */ + _MM_HINT_NTA = 0, /* load data to L1 and L2 cache, mark it as NTA */ + _MM_HINT_T0 = 1, /* load data to L1 and L2 cache */ + _MM_HINT_T1 = 2, /* load data to L2 cache only */ + _MM_HINT_T2 = 3, /* load data to L2 cache only, mark it as NTA */ }; // The bit field mapping to the FPCR(floating-point control register) @@ -661,7 +838,8 @@ FORCE_INLINE void _sse2neon_kadd_f32(float *sum, float *c, float y) *sum = t; } -#if defined(__ARM_FEATURE_CRYPTO) +#if defined(__ARM_FEATURE_CRYPTO) && \ + (defined(__aarch64__) || __has_builtin(__builtin_arm_crypto_vmullp64)) // Wraps vmull_p64 FORCE_INLINE uint64x2_t _sse2neon_vmull_p64(uint64x1_t _a, uint64x1_t _b) { @@ -970,6 +1148,11 @@ FORCE_INLINE __m128i _mm_shuffle_epi_3332(__m128i a) vreinterpretq_m128i_s16(ret); \ }) +/* MMX */ + +//_mm_empty is a no-op on arm +FORCE_INLINE void _mm_empty(void) {} + /* SSE */ // Adds the four single-precision, floating-point values of a and b. @@ -1035,7 +1218,7 @@ FORCE_INLINE __m128 _mm_andnot_ps(__m128 a, __m128 b) // dst[i+15:i] := (a[i+15:i] + b[i+15:i] + 1) >> 1 // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_avg_pu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_pu16 FORCE_INLINE __m64 _mm_avg_pu16(__m64 a, __m64 b) { return vreinterpret_m64_u16( @@ -1050,7 +1233,7 @@ FORCE_INLINE __m64 _mm_avg_pu16(__m64 a, __m64 b) // dst[i+7:i] := (a[i+7:i] + b[i+7:i] + 1) >> 1 // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_avg_pu8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_pu8 FORCE_INLINE __m64 _mm_avg_pu8(__m64 a, __m64 b) { return vreinterpret_m64_u8( @@ -1333,7 +1516,7 @@ FORCE_INLINE int _mm_comineq_ss(__m128 a, __m128 b) // dst[95:64] := a[95:64] // dst[127:96] := a[127:96] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvt_pi2ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_pi2ps FORCE_INLINE __m128 _mm_cvt_pi2ps(__m128 a, __m64 b) { return vreinterpretq_m128_f32( @@ -1349,10 +1532,10 @@ FORCE_INLINE __m128 _mm_cvt_pi2ps(__m128 a, __m64 b) // dst[i+31:i] := Convert_FP32_To_Int32(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvt_ps2pi +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_ps2pi FORCE_INLINE __m64 _mm_cvt_ps2pi(__m128 a) { -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) return vreinterpret_m64_s32( vget_low_s32(vcvtnq_s32_f32(vrndiq_f32(vreinterpretq_f32_m128(a))))); #else @@ -1368,7 +1551,7 @@ FORCE_INLINE __m64 _mm_cvt_ps2pi(__m128 a) // dst[31:0] := Convert_Int32_To_FP32(b[31:0]) // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvt_si2ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_si2ss FORCE_INLINE __m128 _mm_cvt_si2ss(__m128 a, int b) { return vreinterpretq_m128_f32( @@ -1377,10 +1560,10 @@ FORCE_INLINE __m128 _mm_cvt_si2ss(__m128 a, int b) // Convert the lower single-precision (32-bit) floating-point element in a to a // 32-bit integer, and store the result in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvt_ss2si +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_ss2si FORCE_INLINE int _mm_cvt_ss2si(__m128 a) { -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) return vgetq_lane_s32(vcvtnq_s32_f32(vrndiq_f32(vreinterpretq_f32_m128(a))), 0); #else @@ -1399,7 +1582,7 @@ FORCE_INLINE int _mm_cvt_ss2si(__m128 a) // dst[m+31:m] := Convert_Int16_To_FP32(a[i+15:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpi16_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi16_ps FORCE_INLINE __m128 _mm_cvtpi16_ps(__m64 a) { return vreinterpretq_m128_f32( @@ -1415,7 +1598,7 @@ FORCE_INLINE __m128 _mm_cvtpi16_ps(__m64 a) // dst[95:64] := a[95:64] // dst[127:96] := a[127:96] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpi32_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi32_ps FORCE_INLINE __m128 _mm_cvtpi32_ps(__m128 a, __m64 b) { return vreinterpretq_m128_f32( @@ -1425,7 +1608,7 @@ FORCE_INLINE __m128 _mm_cvtpi32_ps(__m128 a, __m64 b) // Convert packed signed 32-bit integers in a to packed single-precision // (32-bit) floating-point elements, store the results in the lower 2 elements -// of dst, then covert the packed signed 32-bit integers in b to +// of dst, then convert the packed signed 32-bit integers in b to // single-precision (32-bit) floating-point element, and store the results in // the upper 2 elements of dst. // @@ -1434,7 +1617,7 @@ FORCE_INLINE __m128 _mm_cvtpi32_ps(__m128 a, __m64 b) // dst[95:64] := Convert_Int32_To_FP32(b[31:0]) // dst[127:96] := Convert_Int32_To_FP32(b[63:32]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpi32x2_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi32x2_ps FORCE_INLINE __m128 _mm_cvtpi32x2_ps(__m64 a, __m64 b) { return vreinterpretq_m128_f32(vcvtq_f32_s32( @@ -1450,7 +1633,7 @@ FORCE_INLINE __m128 _mm_cvtpi32x2_ps(__m64 a, __m64 b) // dst[m+31:m] := Convert_Int8_To_FP32(a[i+7:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpi8_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi8_ps FORCE_INLINE __m128 _mm_cvtpi8_ps(__m64 a) { return vreinterpretq_m128_f32(vcvtq_f32_s32( @@ -1472,23 +1655,11 @@ FORCE_INLINE __m128 _mm_cvtpi8_ps(__m64 a) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtps_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pi16 FORCE_INLINE __m64 _mm_cvtps_pi16(__m128 a) { - const __m128 i16Min = _mm_set_ps1((float) INT16_MIN); - const __m128 i16Max = _mm_set_ps1((float) INT16_MAX); - const __m128 i32Max = _mm_set_ps1((float) INT32_MAX); - const __m128i maxMask = _mm_castps_si128( - _mm_and_ps(_mm_cmpge_ps(a, i16Max), _mm_cmple_ps(a, i32Max))); - const __m128i betweenMask = _mm_castps_si128( - _mm_and_ps(_mm_cmpgt_ps(a, i16Min), _mm_cmplt_ps(a, i16Max))); - const __m128i minMask = _mm_cmpeq_epi32(_mm_or_si128(maxMask, betweenMask), - _mm_setzero_si128()); - __m128i max = _mm_and_si128(maxMask, _mm_set1_epi32(INT16_MAX)); - __m128i min = _mm_and_si128(minMask, _mm_set1_epi32(INT16_MIN)); - __m128i cvt = _mm_and_si128(betweenMask, _mm_cvtps_epi32(a)); - __m128i res32 = _mm_or_si128(_mm_or_si128(max, min), cvt); - return vreinterpret_m64_s16(vmovn_s32(vreinterpretq_s32_m128i(res32))); + return vreinterpret_m64_s16( + vqmovn_s32(vreinterpretq_s32_m128i(_mm_cvtps_epi32(a)))); } // Convert packed single-precision (32-bit) floating-point elements in a to @@ -1499,7 +1670,7 @@ FORCE_INLINE __m64 _mm_cvtps_pi16(__m128 a) // dst[i+31:i] := Convert_FP32_To_Int32(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtps_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pi32 #define _mm_cvtps_pi32(a) _mm_cvt_ps2pi(a) // Convert packed single-precision (32-bit) floating-point elements in a to @@ -1517,28 +1688,11 @@ FORCE_INLINE __m64 _mm_cvtps_pi16(__m128 a) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtps_pi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pi8 FORCE_INLINE __m64 _mm_cvtps_pi8(__m128 a) { - const __m128 i8Min = _mm_set_ps1((float) INT8_MIN); - const __m128 i8Max = _mm_set_ps1((float) INT8_MAX); - const __m128 i32Max = _mm_set_ps1((float) INT32_MAX); - const __m128i maxMask = _mm_castps_si128( - _mm_and_ps(_mm_cmpge_ps(a, i8Max), _mm_cmple_ps(a, i32Max))); - const __m128i betweenMask = _mm_castps_si128( - _mm_and_ps(_mm_cmpgt_ps(a, i8Min), _mm_cmplt_ps(a, i8Max))); - const __m128i minMask = _mm_cmpeq_epi32(_mm_or_si128(maxMask, betweenMask), - _mm_setzero_si128()); - __m128i max = _mm_and_si128(maxMask, _mm_set1_epi32(INT8_MAX)); - __m128i min = _mm_and_si128(minMask, _mm_set1_epi32(INT8_MIN)); - __m128i cvt = _mm_and_si128(betweenMask, _mm_cvtps_epi32(a)); - __m128i res32 = _mm_or_si128(_mm_or_si128(max, min), cvt); - int16x4_t res16 = vmovn_s32(vreinterpretq_s32_m128i(res32)); - int8x8_t res8 = vmovn_s16(vcombine_s16(res16, res16)); - uint32_t bitMask[2] = {0xFFFFFFFF, 0}; - int8x8_t mask = vreinterpret_s8_u32(vld1_u32(bitMask)); - - return vreinterpret_m64_s8(vorr_s8(vand_s8(mask, res8), vdup_n_s8(0))); + return vreinterpret_m64_s8(vqmovn_s16( + vcombine_s16(vreinterpret_s16_m64(_mm_cvtps_pi16(a)), vdup_n_s16(0)))); } // Convert packed unsigned 16-bit integers in a to packed single-precision @@ -1550,7 +1704,7 @@ FORCE_INLINE __m64 _mm_cvtps_pi8(__m128 a) // dst[m+31:m] := Convert_UInt16_To_FP32(a[i+15:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpu16_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpu16_ps FORCE_INLINE __m128 _mm_cvtpu16_ps(__m64 a) { return vreinterpretq_m128_f32( @@ -1567,7 +1721,7 @@ FORCE_INLINE __m128 _mm_cvtpu16_ps(__m64 a) // dst[m+31:m] := Convert_UInt8_To_FP32(a[i+7:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpu8_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpu8_ps FORCE_INLINE __m128 _mm_cvtpu8_ps(__m64 a) { return vreinterpretq_m128_f32(vcvtq_f32_u32( @@ -1581,7 +1735,7 @@ FORCE_INLINE __m128 _mm_cvtpu8_ps(__m64 a) // dst[31:0] := Convert_Int32_To_FP32(b[31:0]) // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi32_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_ss #define _mm_cvtsi32_ss(a, b) _mm_cvt_si2ss(a, b) // Convert the signed 64-bit integer b to a single-precision (32-bit) @@ -1591,7 +1745,7 @@ FORCE_INLINE __m128 _mm_cvtpu8_ps(__m64 a) // dst[31:0] := Convert_Int64_To_FP32(b[63:0]) // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi64_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64_ss FORCE_INLINE __m128 _mm_cvtsi64_ss(__m128 a, int64_t b) { return vreinterpretq_m128_f32( @@ -1602,7 +1756,7 @@ FORCE_INLINE __m128 _mm_cvtsi64_ss(__m128 a, int64_t b) // // dst[31:0] := a[31:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtss_f32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_f32 FORCE_INLINE float _mm_cvtss_f32(__m128 a) { return vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); @@ -1613,7 +1767,7 @@ FORCE_INLINE float _mm_cvtss_f32(__m128 a) // // dst[31:0] := Convert_FP32_To_Int32(a[31:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtss_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_si32 #define _mm_cvtss_si32(a) _mm_cvt_ss2si(a) // Convert the lower single-precision (32-bit) floating-point element in a to a @@ -1621,10 +1775,10 @@ FORCE_INLINE float _mm_cvtss_f32(__m128 a) // // dst[63:0] := Convert_FP32_To_Int64(a[31:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtss_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_si64 FORCE_INLINE int64_t _mm_cvtss_si64(__m128 a) { -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) return (int64_t) vgetq_lane_f32(vrndiq_f32(vreinterpretq_f32_m128(a)), 0); #else float32_t data = vgetq_lane_f32( @@ -1641,7 +1795,7 @@ FORCE_INLINE int64_t _mm_cvtss_si64(__m128 a) // dst[i+31:i] := Convert_FP32_To_Int32_Truncate(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtt_ps2pi +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtt_ps2pi FORCE_INLINE __m64 _mm_cvtt_ps2pi(__m128 a) { return vreinterpret_m64_s32( @@ -1653,7 +1807,7 @@ FORCE_INLINE __m64 _mm_cvtt_ps2pi(__m128 a) // // dst[31:0] := Convert_FP32_To_Int32_Truncate(a[31:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtt_ss2si +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtt_ss2si FORCE_INLINE int _mm_cvtt_ss2si(__m128 a) { return vgetq_lane_s32(vcvtq_s32_f32(vreinterpretq_f32_m128(a)), 0); @@ -1667,7 +1821,7 @@ FORCE_INLINE int _mm_cvtt_ss2si(__m128 a) // dst[i+31:i] := Convert_FP32_To_Int32_Truncate(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttps_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttps_pi32 #define _mm_cvttps_pi32(a) _mm_cvtt_ps2pi(a) // Convert the lower single-precision (32-bit) floating-point element in a to a @@ -1675,7 +1829,7 @@ FORCE_INLINE int _mm_cvtt_ss2si(__m128 a) // // dst[31:0] := Convert_FP32_To_Int32_Truncate(a[31:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttss_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttss_si32 #define _mm_cvttss_si32(a) _mm_cvtt_ss2si(a) // Convert the lower single-precision (32-bit) floating-point element in a to a @@ -1683,7 +1837,7 @@ FORCE_INLINE int _mm_cvtt_ss2si(__m128 a) // // dst[63:0] := Convert_FP32_To_Int64_Truncate(a[31:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttss_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttss_si64 FORCE_INLINE int64_t _mm_cvttss_si64(__m128 a) { return (int64_t) vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); @@ -1725,21 +1879,23 @@ FORCE_INLINE __m128 _mm_div_ss(__m128 a, __m128 b) // Extract a 16-bit integer from a, selected with imm8, and store the result in // the lower element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_extract_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_pi16 #define _mm_extract_pi16(a, imm) \ (int32_t) vget_lane_u16(vreinterpret_u16_m64(a), (imm)) // Free aligned memory that was allocated with _mm_malloc. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_free +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_free +#if !defined(SSE2NEON_ALLOC_DEFINED) FORCE_INLINE void _mm_free(void *addr) { free(addr); } +#endif // Macro: Get the flush zero bits from the MXCSR control and status register. // The flush zero may contain any of the following flags: _MM_FLUSH_ZERO_ON or // _MM_FLUSH_ZERO_OFF -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_MM_GET_FLUSH_ZERO_MODE +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_FLUSH_ZERO_MODE FORCE_INLINE unsigned int _sse2neon_mm_get_flush_zero_mode() { union { @@ -1752,9 +1908,9 @@ FORCE_INLINE unsigned int _sse2neon_mm_get_flush_zero_mode() } r; #if defined(__aarch64__) - asm volatile("mrs %0, FPCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value)); /* read */ #else - asm volatile("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ #endif return r.field.bit24 ? _MM_FLUSH_ZERO_ON : _MM_FLUSH_ZERO_OFF; @@ -1763,7 +1919,7 @@ FORCE_INLINE unsigned int _sse2neon_mm_get_flush_zero_mode() // Macro: Get the rounding mode bits from the MXCSR control and status register. // The rounding mode may contain any of the following flags: _MM_ROUND_NEAREST, // _MM_ROUND_DOWN, _MM_ROUND_UP, _MM_ROUND_TOWARD_ZERO -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_MM_GET_ROUNDING_MODE +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_ROUNDING_MODE FORCE_INLINE unsigned int _MM_GET_ROUNDING_MODE() { union { @@ -1776,9 +1932,9 @@ FORCE_INLINE unsigned int _MM_GET_ROUNDING_MODE() } r; #if defined(__aarch64__) - asm volatile("mrs %0, FPCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value)); /* read */ #else - asm volatile("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ #endif if (r.field.bit22) { @@ -1790,7 +1946,7 @@ FORCE_INLINE unsigned int _MM_GET_ROUNDING_MODE() // Copy a to dst, and insert the 16-bit integer i into dst at the location // specified by imm8. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_insert_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_pi16 #define _mm_insert_pi16(a, b, imm) \ __extension__({ \ vreinterpret_m64_s16( \ @@ -1812,7 +1968,7 @@ FORCE_INLINE __m128 _mm_load_ps(const float *p) // dst[95:64] := MEM[mem_addr+31:mem_addr] // dst[127:96] := MEM[mem_addr+31:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_load_ps1 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_ps1 #define _mm_load_ps1 _mm_load1_ps // Loads an single - precision, floating - point value into the low word and @@ -1873,7 +2029,7 @@ FORCE_INLINE __m128 _mm_loadl_pi(__m128 a, __m64 const *p) // dst[95:64] := MEM[mem_addr+63:mem_addr+32] // dst[127:96] := MEM[mem_addr+31:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadr_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadr_ps FORCE_INLINE __m128 _mm_loadr_ps(const float *p) { float32x4_t v = vrev64q_f32(vld1q_f32(p)); @@ -1894,7 +2050,7 @@ FORCE_INLINE __m128 _mm_loadu_ps(const float *p) // dst[15:0] := MEM[mem_addr+15:mem_addr] // dst[MAX:16] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadu_si16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si16 FORCE_INLINE __m128i _mm_loadu_si16(const void *p) { return vreinterpretq_m128i_s16( @@ -1906,7 +2062,7 @@ FORCE_INLINE __m128i _mm_loadu_si16(const void *p) // dst[63:0] := MEM[mem_addr+63:mem_addr] // dst[MAX:64] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadu_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si64 FORCE_INLINE __m128i _mm_loadu_si64(const void *p) { return vreinterpretq_m128i_s64( @@ -1916,6 +2072,7 @@ FORCE_INLINE __m128i _mm_loadu_si64(const void *p) // Allocate aligned blocks of memory. // https://software.intel.com/en-us/ // cpp-compiler-developer-guide-and-reference-allocating-and-freeing-aligned-memory-blocks +#if !defined(SSE2NEON_ALLOC_DEFINED) FORCE_INLINE void *_mm_malloc(size_t size, size_t align) { void *ptr; @@ -1927,11 +2084,12 @@ FORCE_INLINE void *_mm_malloc(size_t size, size_t align) return ptr; return NULL; } +#endif // Conditionally store 8-bit integer elements from a into memory using mask // (elements are not stored when the highest bit is not set in the corresponding // element) and a non-temporal memory hint. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_maskmove_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskmove_si64 FORCE_INLINE void _mm_maskmove_si64(__m64 a, __m64 mask, char *mem_addr) { int8x8_t shr_mask = vshr_n_s8(vreinterpret_s8_m64(mask), 7); @@ -1945,7 +2103,7 @@ FORCE_INLINE void _mm_maskmove_si64(__m64 a, __m64 mask, char *mem_addr) // Conditionally store 8-bit integer elements from a into memory using mask // (elements are not stored when the highest bit is not set in the corresponding // element) and a non-temporal memory hint. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_maskmovq +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_maskmovq #define _m_maskmovq(a, mask, mem_addr) _mm_maskmove_si64(a, mask, mem_addr) // Compare packed signed 16-bit integers in a and b, and store packed maximum @@ -1956,7 +2114,7 @@ FORCE_INLINE void _mm_maskmove_si64(__m64 a, __m64 mask, char *mem_addr) // dst[i+15:i] := MAX(a[i+15:i], b[i+15:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pi16 FORCE_INLINE __m64 _mm_max_pi16(__m64 a, __m64 b) { return vreinterpret_m64_s16( @@ -1971,7 +2129,7 @@ FORCE_INLINE __m128 _mm_max_ps(__m128 a, __m128 b) #if SSE2NEON_PRECISE_MINMAX float32x4_t _a = vreinterpretq_f32_m128(a); float32x4_t _b = vreinterpretq_f32_m128(b); - return vbslq_f32(vcltq_f32(_b, _a), _a, _b); + return vreinterpretq_m128_f32(vbslq_f32(vcgtq_f32(_a, _b), _a, _b)); #else return vreinterpretq_m128_f32( vmaxq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); @@ -1986,7 +2144,7 @@ FORCE_INLINE __m128 _mm_max_ps(__m128 a, __m128 b) // dst[i+7:i] := MAX(a[i+7:i], b[i+7:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_pu8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pu8 FORCE_INLINE __m64 _mm_max_pu8(__m64 a, __m64 b) { return vreinterpret_m64_u8( @@ -2011,7 +2169,7 @@ FORCE_INLINE __m128 _mm_max_ss(__m128 a, __m128 b) // dst[i+15:i] := MIN(a[i+15:i], b[i+15:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_min_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pi16 FORCE_INLINE __m64 _mm_min_pi16(__m64 a, __m64 b) { return vreinterpret_m64_s16( @@ -2026,7 +2184,7 @@ FORCE_INLINE __m128 _mm_min_ps(__m128 a, __m128 b) #if SSE2NEON_PRECISE_MINMAX float32x4_t _a = vreinterpretq_f32_m128(a); float32x4_t _b = vreinterpretq_f32_m128(b); - return vbslq_f32(vcltq_f32(_a, _b), _a, _b); + return vreinterpretq_m128_f32(vbslq_f32(vcltq_f32(_a, _b), _a, _b)); #else return vreinterpretq_m128_f32( vminq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); @@ -2041,7 +2199,7 @@ FORCE_INLINE __m128 _mm_min_ps(__m128 a, __m128 b) // dst[i+7:i] := MIN(a[i+7:i], b[i+7:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_min_pu8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pu8 FORCE_INLINE __m64 _mm_min_pu8(__m64 a, __m64 b) { return vreinterpret_m64_u8( @@ -2095,7 +2253,7 @@ FORCE_INLINE __m128 _mm_movelh_ps(__m128 __A, __m128 __B) // Create mask from the most significant bit of each 8-bit element in a, and // store the result in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_movemask_pi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_pi8 FORCE_INLINE int _mm_movemask_pi8(__m64 a) { uint8x8_t input = vreinterpret_u8_m64(a); @@ -2159,7 +2317,7 @@ FORCE_INLINE __m128 _mm_mul_ps(__m128 a, __m128 b) // dst[31:0] := a[31:0] * b[31:0] // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mul_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_ss FORCE_INLINE __m128 _mm_mul_ss(__m128 a, __m128 b) { return _mm_move_ss(a, _mm_mul_ps(a, b)); @@ -2168,7 +2326,7 @@ FORCE_INLINE __m128 _mm_mul_ss(__m128 a, __m128 b) // Multiply the packed unsigned 16-bit integers in a and b, producing // intermediate 32-bit integers, and store the high 16 bits of the intermediate // integers in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mulhi_pu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_pu16 FORCE_INLINE __m64 _mm_mulhi_pu16(__m64 a, __m64 b) { return vreinterpret_m64_u16(vshrn_n_u32( @@ -2192,7 +2350,7 @@ FORCE_INLINE __m128 _mm_or_ps(__m128 a, __m128 b) // dst[i+7:i] := (a[i+7:i] + b[i+7:i] + 1) >> 1 // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pavgb +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pavgb #define _m_pavgb(a, b) _mm_avg_pu8(a, b) // Average packed unsigned 16-bit integers in a and b, and store the results in @@ -2203,74 +2361,87 @@ FORCE_INLINE __m128 _mm_or_ps(__m128 a, __m128 b) // dst[i+15:i] := (a[i+15:i] + b[i+15:i] + 1) >> 1 // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pavgw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pavgw #define _m_pavgw(a, b) _mm_avg_pu16(a, b) // Extract a 16-bit integer from a, selected with imm8, and store the result in // the lower element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pextrw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pextrw #define _m_pextrw(a, imm) _mm_extract_pi16(a, imm) // Copy a to dst, and insert the 16-bit integer i into dst at the location // specified by imm8. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=m_pinsrw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=m_pinsrw #define _m_pinsrw(a, i, imm) _mm_insert_pi16(a, i, imm) // Compare packed signed 16-bit integers in a and b, and store packed maximum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pmaxsw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmaxsw #define _m_pmaxsw(a, b) _mm_max_pi16(a, b) // Compare packed unsigned 8-bit integers in a and b, and store packed maximum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pmaxub +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmaxub #define _m_pmaxub(a, b) _mm_max_pu8(a, b) // Compare packed signed 16-bit integers in a and b, and store packed minimum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pminsw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pminsw #define _m_pminsw(a, b) _mm_min_pi16(a, b) // Compare packed unsigned 8-bit integers in a and b, and store packed minimum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pminub +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pminub #define _m_pminub(a, b) _mm_min_pu8(a, b) // Create mask from the most significant bit of each 8-bit element in a, and // store the result in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pmovmskb +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmovmskb #define _m_pmovmskb(a) _mm_movemask_pi8(a) // Multiply the packed unsigned 16-bit integers in a and b, producing // intermediate 32-bit integers, and store the high 16 bits of the intermediate // integers in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pmulhuw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmulhuw #define _m_pmulhuw(a, b) _mm_mulhi_pu16(a, b) -// Loads one cache line of data from address p to a location closer to the -// processor. https://msdn.microsoft.com/en-us/library/84szxsww(v=vs.100).aspx -FORCE_INLINE void _mm_prefetch(const void *p, int i) +// Fetch the line of data from memory that contains address p to a location in +// the cache heirarchy specified by the locality hint i. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_prefetch +FORCE_INLINE void _mm_prefetch(char const *p, int i) { - (void) i; - __builtin_prefetch(p); + switch (i) { + case _MM_HINT_NTA: + __builtin_prefetch(p, 0, 0); + break; + case _MM_HINT_T0: + __builtin_prefetch(p, 0, 3); + break; + case _MM_HINT_T1: + __builtin_prefetch(p, 0, 2); + break; + case _MM_HINT_T2: + __builtin_prefetch(p, 0, 1); + break; + } } // Compute the absolute differences of packed unsigned 8-bit integers in a and // b, then horizontally sum each consecutive 8 differences to produce four // unsigned 16-bit integers, and pack these unsigned 16-bit integers in the low // 16 bits of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=m_psadbw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=m_psadbw #define _m_psadbw(a, b) _mm_sad_pu8(a, b) // Shuffle 16-bit integers in a using the control in imm8, and store the results // in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_m_pshufw +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pshufw #define _m_pshufw(a, imm) _mm_shuffle_pi16(a, imm) // Compute the approximate reciprocal of packed single-precision (32-bit) // floating-point elements in a, and store the results in dst. The maximum // relative error for this approximation is less than 1.5*2^-12. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_rcp_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rcp_ps FORCE_INLINE __m128 _mm_rcp_ps(__m128 in) { float32x4_t recip = vrecpeq_f32(vreinterpretq_f32_m128(in)); @@ -2290,7 +2461,7 @@ FORCE_INLINE __m128 _mm_rcp_ps(__m128 in) // dst[31:0] := (1.0 / a[31:0]) // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_rcp_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rcp_ss FORCE_INLINE __m128 _mm_rcp_ss(__m128 a) { return _mm_move_ss(a, _mm_rcp_ps(a)); @@ -2317,7 +2488,7 @@ FORCE_INLINE __m128 _mm_rsqrt_ps(__m128 in) // (32-bit) floating-point element in a, store the result in the lower element // of dst, and copy the upper 3 packed elements from a to the upper elements of // dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_rsqrt_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rsqrt_ss FORCE_INLINE __m128 _mm_rsqrt_ss(__m128 in) { return vsetq_lane_f32(vgetq_lane_f32(_mm_rsqrt_ps(in), 0), in, 0); @@ -2327,7 +2498,7 @@ FORCE_INLINE __m128 _mm_rsqrt_ss(__m128 in) // b, then horizontally sum each consecutive 8 differences to produce four // unsigned 16-bit integers, and pack these unsigned 16-bit integers in the low // 16 bits of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sad_pu8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_pu8 FORCE_INLINE __m64 _mm_sad_pu8(__m64 a, __m64 b) { uint64x1_t t = vpaddl_u32(vpaddl_u16( @@ -2339,7 +2510,7 @@ FORCE_INLINE __m64 _mm_sad_pu8(__m64 a, __m64 b) // Macro: Set the flush zero bits of the MXCSR control and status register to // the value in unsigned 32-bit integer a. The flush zero may contain any of the // following flags: _MM_FLUSH_ZERO_ON or _MM_FLUSH_ZERO_OFF -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_MM_SET_FLUSH_ZERO_MODE +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_FLUSH_ZERO_MODE FORCE_INLINE void _sse2neon_mm_set_flush_zero_mode(unsigned int flag) { // AArch32 Advanced SIMD arithmetic always uses the Flush-to-zero setting, @@ -2354,17 +2525,17 @@ FORCE_INLINE void _sse2neon_mm_set_flush_zero_mode(unsigned int flag) } r; #if defined(__aarch64__) - asm volatile("mrs %0, FPCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value)); /* read */ #else - asm volatile("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ #endif r.field.bit24 = (flag & _MM_FLUSH_ZERO_MASK) == _MM_FLUSH_ZERO_ON; #if defined(__aarch64__) - asm volatile("msr FPCR, %0" ::"r"(r)); /* write */ + __asm__ __volatile__("msr FPCR, %0" ::"r"(r)); /* write */ #else - asm volatile("vmsr FPSCR, %0" ::"r"(r)); /* write */ + __asm__ __volatile__("vmsr FPSCR, %0" ::"r"(r)); /* write */ #endif } @@ -2387,7 +2558,7 @@ FORCE_INLINE __m128 _mm_set_ps1(float _w) // the value in unsigned 32-bit integer a. The rounding mode may contain any of // the following flags: _MM_ROUND_NEAREST, _MM_ROUND_DOWN, _MM_ROUND_UP, // _MM_ROUND_TOWARD_ZERO -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_MM_SET_ROUNDING_MODE +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_ROUNDING_MODE FORCE_INLINE void _MM_SET_ROUNDING_MODE(int rounding) { union { @@ -2400,9 +2571,9 @@ FORCE_INLINE void _MM_SET_ROUNDING_MODE(int rounding) } r; #if defined(__aarch64__) - asm volatile("mrs %0, FPCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value)); /* read */ #else - asm volatile("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ #endif switch (rounding) { @@ -2424,19 +2595,18 @@ FORCE_INLINE void _MM_SET_ROUNDING_MODE(int rounding) } #if defined(__aarch64__) - asm volatile("msr FPCR, %0" ::"r"(r)); /* write */ + __asm__ __volatile__("msr FPCR, %0" ::"r"(r)); /* write */ #else - asm volatile("vmsr FPSCR, %0" ::"r"(r)); /* write */ + __asm__ __volatile__("vmsr FPSCR, %0" ::"r"(r)); /* write */ #endif } // Copy single-precision (32-bit) floating-point element a to the lower element // of dst, and zero the upper 3 elements. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_set_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_ss FORCE_INLINE __m128 _mm_set_ss(float a) { - float ALIGN_STRUCT(16) data[4] = {a, 0, 0, 0}; - return vreinterpretq_m128_f32(vld1q_f32(data)); + return vreinterpretq_m128_f32(vsetq_lane_f32(a, vdupq_n_f32(0), 0)); } // Sets the four single-precision, floating-point values to w. @@ -2449,11 +2619,18 @@ FORCE_INLINE __m128 _mm_set1_ps(float _w) return vreinterpretq_m128_f32(vdupq_n_f32(_w)); } +// FIXME: _mm_setcsr() implementation supports changing the rounding mode only. FORCE_INLINE void _mm_setcsr(unsigned int a) { _MM_SET_ROUNDING_MODE(a); } +// FIXME: _mm_getcsr() implementation supports reading the rounding mode only. +FORCE_INLINE unsigned int _mm_getcsr() +{ + return _MM_GET_ROUNDING_MODE(); +} + // Sets the four single-precision, floating-point values to the four inputs in // reverse order. // https://msdn.microsoft.com/en-us/library/vstudio/d2172ct3(v=vs.100).aspx @@ -2472,11 +2649,11 @@ FORCE_INLINE __m128 _mm_setzero_ps(void) // Shuffle 16-bit integers in a using the control in imm8, and store the results // in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_shuffle_pi16 -#if __has_builtin(__builtin_shufflevector) +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pi16 +#ifdef _sse2neon_shuffle #define _mm_shuffle_pi16(a, imm) \ __extension__({ \ - vreinterpret_m64_s16(__builtin_shufflevector( \ + vreinterpret_m64_s16(vshuffle_s16( \ vreinterpret_s16_m64(a), vreinterpret_s16_m64(a), (imm & 0x3), \ ((imm >> 2) & 0x3), ((imm >> 4) & 0x3), ((imm >> 6) & 0x3))); \ }) @@ -2499,25 +2676,48 @@ FORCE_INLINE __m128 _mm_setzero_ps(void) }) #endif -// Guarantees that every preceding store is globally visible before any -// subsequent store. -// https://msdn.microsoft.com/en-us/library/5h2w73d1%28v=vs.90%29.aspx +// Perform a serializing operation on all store-to-memory instructions that were +// issued prior to this instruction. Guarantees that every store instruction +// that precedes, in program order, is globally visible before any store +// instruction which follows the fence in program order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sfence FORCE_INLINE void _mm_sfence(void) { - __sync_synchronize(); + _sse2neon_smp_mb(); +} + +// Perform a serializing operation on all load-from-memory and store-to-memory +// instructions that were issued prior to this instruction. Guarantees that +// every memory access that precedes, in program order, the memory fence +// instruction is globally visible before any memory instruction which follows +// the fence in program order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mfence +FORCE_INLINE void _mm_mfence(void) +{ + _sse2neon_smp_mb(); +} + +// Perform a serializing operation on all load-from-memory instructions that +// were issued prior to this instruction. Guarantees that every load instruction +// that precedes, in program order, is globally visible before any load +// instruction which follows the fence in program order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_lfence +FORCE_INLINE void _mm_lfence(void) +{ + _sse2neon_smp_mb(); } // FORCE_INLINE __m128 _mm_shuffle_ps(__m128 a, __m128 b, __constrange(0,255) // int imm) -#if __has_builtin(__builtin_shufflevector) -#define _mm_shuffle_ps(a, b, imm) \ - __extension__({ \ - float32x4_t _input1 = vreinterpretq_f32_m128(a); \ - float32x4_t _input2 = vreinterpretq_f32_m128(b); \ - float32x4_t _shuf = __builtin_shufflevector( \ - _input1, _input2, (imm) & (0x3), ((imm) >> 2) & 0x3, \ - (((imm) >> 4) & 0x3) + 4, (((imm) >> 6) & 0x3) + 4); \ - vreinterpretq_m128_f32(_shuf); \ +#ifdef _sse2neon_shuffle +#define _mm_shuffle_ps(a, b, imm) \ + __extension__({ \ + float32x4_t _input1 = vreinterpretq_f32_m128(a); \ + float32x4_t _input2 = vreinterpretq_f32_m128(b); \ + float32x4_t _shuf = \ + vshuffleq_s32(_input1, _input2, (imm) & (0x3), ((imm) >> 2) & 0x3, \ + (((imm) >> 4) & 0x3) + 4, (((imm) >> 6) & 0x3) + 4); \ + vreinterpretq_m128_f32(_shuf); \ }) #else // generic #define _mm_shuffle_ps(a, b, imm) \ @@ -2652,7 +2852,7 @@ FORCE_INLINE void _mm_store_ps(float *p, __m128 a) // MEM[mem_addr+95:mem_addr+64] := a[31:0] // MEM[mem_addr+127:mem_addr+96] := a[31:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_store_ps1 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_ps1 FORCE_INLINE void _mm_store_ps1(float *p, __m128 a) { float32_t a0 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); @@ -2675,7 +2875,7 @@ FORCE_INLINE void _mm_store_ss(float *p, __m128 a) // MEM[mem_addr+95:mem_addr+64] := a[31:0] // MEM[mem_addr+127:mem_addr+96] := a[31:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_store1_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store1_ps #define _mm_store1_ps _mm_store_ps1 // Stores the upper two single-precision, floating-point values of a to the @@ -2711,7 +2911,7 @@ FORCE_INLINE void _mm_storel_pi(__m64 *p, __m128 a) // MEM[mem_addr+95:mem_addr+64] := a[63:32] // MEM[mem_addr+127:mem_addr+96] := a[31:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storer_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storer_ps FORCE_INLINE void _mm_storer_ps(float *p, __m128 a) { float32x4_t tmp = vrev64q_f32(vreinterpretq_f32_m128(a)); @@ -2727,14 +2927,14 @@ FORCE_INLINE void _mm_storeu_ps(float *p, __m128 a) } // Stores 16-bits of integer data a at the address p. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storeu_si16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si16 FORCE_INLINE void _mm_storeu_si16(void *p, __m128i a) { vst1q_lane_s16((int16_t *) p, vreinterpretq_s16_m128i(a), 0); } // Stores 64-bits of integer data a at the address p. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storeu_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si64 FORCE_INLINE void _mm_storeu_si64(void *p, __m128i a) { vst1q_lane_s64((int64_t *) p, vreinterpretq_s64_m128i(a), 0); @@ -2742,7 +2942,7 @@ FORCE_INLINE void _mm_storeu_si64(void *p, __m128i a) // Store 64-bits of integer data from a into memory using a non-temporal memory // hint. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_stream_pi +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_pi FORCE_INLINE void _mm_stream_pi(__m64 *p, __m64 a) { vst1_s64((int64_t *) p, vreinterpret_s64_m64(a)); @@ -2750,11 +2950,11 @@ FORCE_INLINE void _mm_stream_pi(__m64 *p, __m64 a) // Store 128-bits (composed of 4 packed single-precision (32-bit) floating- // point elements) from a into memory using a non-temporal memory hint. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_stream_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_ps FORCE_INLINE void _mm_stream_ps(float *p, __m128 a) { #if __has_builtin(__builtin_nontemporal_store) - __builtin_nontemporal_store(a, (float32x4_t *) p); + __builtin_nontemporal_store(reinterpret_cast(a), (float32x4_t *) p); #else vst1q_f32(p, vreinterpretq_f32_m128(a)); #endif @@ -2782,7 +2982,7 @@ FORCE_INLINE __m128 _mm_sub_ps(__m128 a, __m128 b) // dst[31:0] := a[31:0] - b[31:0] // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sub_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_ss FORCE_INLINE __m128 _mm_sub_ss(__m128 a, __m128 b) { return _mm_move_ss(a, _mm_sub_ps(a, b)); @@ -2791,7 +2991,7 @@ FORCE_INLINE __m128 _mm_sub_ss(__m128 a, __m128 b) // Macro: Transpose the 4x4 matrix formed by the 4 rows of single-precision // (32-bit) floating-point elements in row0, row1, row2, and row3, and store the // transposed matrix in these vectors (row0 now contains column 0, etc.). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=MM_TRANSPOSE4_PS +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=MM_TRANSPOSE4_PS #define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) \ do { \ float32x4x2_t ROW01 = vtrnq_f32(row0, row1); \ @@ -2816,7 +3016,7 @@ FORCE_INLINE __m128 _mm_sub_ss(__m128 a, __m128 b) #define _mm_ucomineq_ss _mm_comineq_ss // Return vector of type __m128i with undefined elements. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_undefined_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_undefined_si128 FORCE_INLINE __m128i _mm_undefined_si128(void) { #if defined(__GNUC__) || defined(__clang__) @@ -2831,7 +3031,7 @@ FORCE_INLINE __m128i _mm_undefined_si128(void) } // Return vector of type __m128 with undefined elements. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_undefined_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_undefined_ps FORCE_INLINE __m128 _mm_undefined_ps(void) { #if defined(__GNUC__) || defined(__clang__) @@ -2944,7 +3144,7 @@ FORCE_INLINE __m128i _mm_add_epi8(__m128i a, __m128i b) // Add packed double-precision (64-bit) floating-point elements in a and b, and // store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_add_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_pd FORCE_INLINE __m128d _mm_add_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -2967,7 +3167,7 @@ FORCE_INLINE __m128d _mm_add_pd(__m128d a, __m128d b) // dst[63:0] := a[63:0] + b[63:0] // dst[127:64] := a[127:64] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_add_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_sd FORCE_INLINE __m128d _mm_add_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -2986,7 +3186,7 @@ FORCE_INLINE __m128d _mm_add_sd(__m128d a, __m128d b) // // dst[63:0] := a[63:0] + b[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_add_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_si64 FORCE_INLINE __m64 _mm_add_si64(__m64 a, __m64 b) { return vreinterpret_m64_s64( @@ -3016,7 +3216,7 @@ FORCE_INLINE __m128i _mm_adds_epi16(__m128i a, __m128i b) // dst[i+7:i] := Saturate8( a[i+7:i] + b[i+7:i] ) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_adds_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epi8 FORCE_INLINE __m128i _mm_adds_epi8(__m128i a, __m128i b) { return vreinterpretq_m128i_s8( @@ -3025,7 +3225,7 @@ FORCE_INLINE __m128i _mm_adds_epi8(__m128i a, __m128i b) // Add packed unsigned 16-bit integers in a and b using saturation, and store // the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_adds_epu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epu16 FORCE_INLINE __m128i _mm_adds_epu16(__m128i a, __m128i b) { return vreinterpretq_m128i_u16( @@ -3049,7 +3249,7 @@ FORCE_INLINE __m128i _mm_adds_epu8(__m128i a, __m128i b) // dst[i+63:i] := a[i+63:i] AND b[i+63:i] // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_and_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_and_pd FORCE_INLINE __m128d _mm_and_pd(__m128d a, __m128d b) { return vreinterpretq_m128d_s64( @@ -3072,11 +3272,11 @@ FORCE_INLINE __m128i _mm_and_si128(__m128i a, __m128i b) // elements in a and then AND with b, and store the results in dst. // // FOR j := 0 to 1 -// i := j*64 -// dst[i+63:i] := ((NOT a[i+63:i]) AND b[i+63:i]) +// i := j*64 +// dst[i+63:i] := ((NOT a[i+63:i]) AND b[i+63:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_andnot_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_andnot_pd FORCE_INLINE __m128d _mm_andnot_pd(__m128d a, __m128d b) { // *NOTE* argument swap @@ -3129,17 +3329,17 @@ FORCE_INLINE __m128i _mm_avg_epu8(__m128i a, __m128i b) // Shift a left by imm8 bytes while shifting in zeros, and store the results in // dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_bslli_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_bslli_si128 #define _mm_bslli_si128(a, imm) _mm_slli_si128(a, imm) // Shift a right by imm8 bytes while shifting in zeros, and store the results in // dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_bsrli_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_bsrli_si128 #define _mm_bsrli_si128(a, imm) _mm_srli_si128(a, imm) // Cast vector of type __m128d to type __m128. This intrinsic is only used for // compilation and does not generate any instructions, thus it has zero latency. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_castpd_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castpd_ps FORCE_INLINE __m128 _mm_castpd_ps(__m128d a) { return vreinterpretq_m128_s64(vreinterpretq_s64_m128d(a)); @@ -3147,7 +3347,7 @@ FORCE_INLINE __m128 _mm_castpd_ps(__m128d a) // Cast vector of type __m128d to type __m128i. This intrinsic is only used for // compilation and does not generate any instructions, thus it has zero latency. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_castpd_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castpd_si128 FORCE_INLINE __m128i _mm_castpd_si128(__m128d a) { return vreinterpretq_m128i_s64(vreinterpretq_s64_m128d(a)); @@ -3155,7 +3355,7 @@ FORCE_INLINE __m128i _mm_castpd_si128(__m128d a) // Cast vector of type __m128 to type __m128d. This intrinsic is only used for // compilation and does not generate any instructions, thus it has zero latency. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_castps_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castps_pd FORCE_INLINE __m128d _mm_castps_pd(__m128 a) { return vreinterpretq_m128d_s32(vreinterpretq_s32_m128(a)); @@ -3171,7 +3371,7 @@ FORCE_INLINE __m128i _mm_castps_si128(__m128 a) // Cast vector of type __m128i to type __m128d. This intrinsic is only used for // compilation and does not generate any instructions, thus it has zero latency. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_castsi128_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castsi128_pd FORCE_INLINE __m128d _mm_castsi128_pd(__m128i a) { #if defined(__aarch64__) @@ -3189,13 +3389,29 @@ FORCE_INLINE __m128 _mm_castsi128_ps(__m128i a) return vreinterpretq_m128_s32(vreinterpretq_s32_m128i(a)); } -// Cache line containing p is flushed and invalidated from all caches in the -// coherency domain. : -// https://msdn.microsoft.com/en-us/library/ba08y07y(v=vs.100).aspx +// Invalidate and flush the cache line that contains p from all levels of the +// cache hierarchy. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_clflush +#if defined(__APPLE__) +#include +#endif FORCE_INLINE void _mm_clflush(void const *p) { (void) p; - // no corollary for Neon? + + /* sys_icache_invalidate is supported since macOS 10.5. + * However, it does not work on non-jailbroken iOS devices, although the + * compilation is successful. + */ +#if defined(__APPLE__) + sys_icache_invalidate((void *) (uintptr_t) p, SSE2NEON_CACHELINE_SIZE); +#elif defined(__GNUC__) || defined(__clang__) + uintptr_t ptr = (uintptr_t) p; + __builtin___clear_cache((char *) ptr, + (char *) ptr + SSE2NEON_CACHELINE_SIZE); +#else + /* FIXME: MSVC support */ +#endif } // Compares the 8 signed or unsigned 16-bit integers in a and the 8 signed or @@ -3226,7 +3442,7 @@ FORCE_INLINE __m128i _mm_cmpeq_epi8(__m128i a, __m128i b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for equality, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpeq_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_pd FORCE_INLINE __m128d _mm_cmpeq_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3244,7 +3460,7 @@ FORCE_INLINE __m128d _mm_cmpeq_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for equality, store the result in the lower element of dst, and copy the // upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpeq_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_sd FORCE_INLINE __m128d _mm_cmpeq_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_cmpeq_pd(a, b)); @@ -3252,7 +3468,7 @@ FORCE_INLINE __m128d _mm_cmpeq_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for greater-than-or-equal, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpge_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_pd FORCE_INLINE __m128d _mm_cmpge_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3274,7 +3490,7 @@ FORCE_INLINE __m128d _mm_cmpge_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for greater-than-or-equal, store the result in the lower element of dst, // and copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpge_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_sd FORCE_INLINE __m128d _mm_cmpge_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3333,7 +3549,7 @@ FORCE_INLINE __m128i _mm_cmpgt_epi8(__m128i a, __m128i b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for greater-than, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpgt_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_pd FORCE_INLINE __m128d _mm_cmpgt_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3355,7 +3571,7 @@ FORCE_INLINE __m128d _mm_cmpgt_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for greater-than, store the result in the lower element of dst, and copy // the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpgt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_sd FORCE_INLINE __m128d _mm_cmpgt_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3375,7 +3591,7 @@ FORCE_INLINE __m128d _mm_cmpgt_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for less-than-or-equal, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmple_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_pd FORCE_INLINE __m128d _mm_cmple_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3397,7 +3613,7 @@ FORCE_INLINE __m128d _mm_cmple_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for less-than-or-equal, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmple_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_sd FORCE_INLINE __m128d _mm_cmple_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3451,7 +3667,7 @@ FORCE_INLINE __m128i _mm_cmplt_epi8(__m128i a, __m128i b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for less-than, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmplt_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_pd FORCE_INLINE __m128d _mm_cmplt_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3473,7 +3689,7 @@ FORCE_INLINE __m128d _mm_cmplt_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for less-than, store the result in the lower element of dst, and copy the // upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmplt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_sd FORCE_INLINE __m128d _mm_cmplt_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3492,7 +3708,7 @@ FORCE_INLINE __m128d _mm_cmplt_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for not-equal, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpneq_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_pd FORCE_INLINE __m128d _mm_cmpneq_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3510,7 +3726,7 @@ FORCE_INLINE __m128d _mm_cmpneq_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for not-equal, store the result in the lower element of dst, and copy the // upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpneq_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_sd FORCE_INLINE __m128d _mm_cmpneq_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_cmpneq_pd(a, b)); @@ -3518,7 +3734,7 @@ FORCE_INLINE __m128d _mm_cmpneq_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for not-greater-than-or-equal, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpnge_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_pd FORCE_INLINE __m128d _mm_cmpnge_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3543,7 +3759,7 @@ FORCE_INLINE __m128d _mm_cmpnge_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for not-greater-than-or-equal, store the result in the lower element of // dst, and copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpnge_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_sd FORCE_INLINE __m128d _mm_cmpnge_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_cmpnge_pd(a, b)); @@ -3551,7 +3767,7 @@ FORCE_INLINE __m128d _mm_cmpnge_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for not-greater-than, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_cmpngt_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_cmpngt_pd FORCE_INLINE __m128d _mm_cmpngt_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3576,7 +3792,7 @@ FORCE_INLINE __m128d _mm_cmpngt_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for not-greater-than, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpngt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpngt_sd FORCE_INLINE __m128d _mm_cmpngt_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_cmpngt_pd(a, b)); @@ -3584,7 +3800,7 @@ FORCE_INLINE __m128d _mm_cmpngt_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for not-less-than-or-equal, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpnle_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_pd FORCE_INLINE __m128d _mm_cmpnle_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3609,7 +3825,7 @@ FORCE_INLINE __m128d _mm_cmpnle_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for not-less-than-or-equal, store the result in the lower element of dst, // and copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpnle_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_sd FORCE_INLINE __m128d _mm_cmpnle_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_cmpnle_pd(a, b)); @@ -3617,7 +3833,7 @@ FORCE_INLINE __m128d _mm_cmpnle_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // for not-less-than, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpnlt_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_pd FORCE_INLINE __m128d _mm_cmpnlt_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3642,7 +3858,7 @@ FORCE_INLINE __m128d _mm_cmpnlt_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b for not-less-than, store the result in the lower element of dst, and copy // the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpnlt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_sd FORCE_INLINE __m128d _mm_cmpnlt_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_cmpnlt_pd(a, b)); @@ -3650,7 +3866,7 @@ FORCE_INLINE __m128d _mm_cmpnlt_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // to see if neither is NaN, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpord_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_pd FORCE_INLINE __m128d _mm_cmpord_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3682,7 +3898,7 @@ FORCE_INLINE __m128d _mm_cmpord_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b to see if neither is NaN, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpord_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_sd FORCE_INLINE __m128d _mm_cmpord_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3704,7 +3920,7 @@ FORCE_INLINE __m128d _mm_cmpord_sd(__m128d a, __m128d b) // Compare packed double-precision (64-bit) floating-point elements in a and b // to see if either is NaN, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpunord_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_pd FORCE_INLINE __m128d _mm_cmpunord_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3737,7 +3953,7 @@ FORCE_INLINE __m128d _mm_cmpunord_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b to see if either is NaN, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmpunord_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_sd FORCE_INLINE __m128d _mm_cmpunord_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3759,7 +3975,7 @@ FORCE_INLINE __m128d _mm_cmpunord_sd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point element in a and b // for greater-than-or-equal, and return the boolean result (0 or 1). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_comige_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comige_sd FORCE_INLINE int _mm_comige_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3774,7 +3990,7 @@ FORCE_INLINE int _mm_comige_sd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point element in a and b // for greater-than, and return the boolean result (0 or 1). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_comigt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comigt_sd FORCE_INLINE int _mm_comigt_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3789,7 +4005,7 @@ FORCE_INLINE int _mm_comigt_sd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point element in a and b // for less-than-or-equal, and return the boolean result (0 or 1). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_comile_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comile_sd FORCE_INLINE int _mm_comile_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3804,7 +4020,7 @@ FORCE_INLINE int _mm_comile_sd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point element in a and b // for less-than, and return the boolean result (0 or 1). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_comilt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comilt_sd FORCE_INLINE int _mm_comilt_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3819,7 +4035,7 @@ FORCE_INLINE int _mm_comilt_sd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point element in a and b // for equality, and return the boolean result (0 or 1). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_comieq_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comieq_sd FORCE_INLINE int _mm_comieq_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -3840,7 +4056,7 @@ FORCE_INLINE int _mm_comieq_sd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point element in a and b // for not-equal, and return the boolean result (0 or 1). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_comineq_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comineq_sd FORCE_INLINE int _mm_comineq_sd(__m128d a, __m128d b) { return !_mm_comieq_sd(a, b); @@ -3855,7 +4071,7 @@ FORCE_INLINE int _mm_comineq_sd(__m128d a, __m128d b) // dst[m+63:m] := Convert_Int32_To_FP64(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtepi32_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi32_pd FORCE_INLINE __m128d _mm_cvtepi32_pd(__m128i a) { #if defined(__aarch64__) @@ -3885,13 +4101,21 @@ FORCE_INLINE __m128 _mm_cvtepi32_ps(__m128i a) // dst[i+31:i] := Convert_FP64_To_Int32(a[k+63:k]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpd_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_epi32 FORCE_INLINE __m128i _mm_cvtpd_epi32(__m128d a) { +// vrnd32xq_f64 not supported on clang +#if defined(__ARM_FEATURE_FRINT) && !defined(__clang__) + float64x2_t rounded = vrnd32xq_f64(vreinterpretq_f64_m128d(a)); + int64x2_t integers = vcvtq_s64_f64(rounded); + return vreinterpretq_m128i_s32( + vcombine_s32(vmovn_s64(integers), vdup_n_s32(0))); +#else __m128d rnd = _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); double d0 = ((double *) &rnd)[0]; double d1 = ((double *) &rnd)[1]; return _mm_set_epi32(0, 0, (int32_t) d1, (int32_t) d0); +#endif } // Convert packed double-precision (64-bit) floating-point elements in a to @@ -3903,7 +4127,7 @@ FORCE_INLINE __m128i _mm_cvtpd_epi32(__m128d a) // dst[i+31:i] := Convert_FP64_To_Int32(a[k+63:k]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpd_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_pi32 FORCE_INLINE __m64 _mm_cvtpd_pi32(__m128d a) { __m128d rnd = _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); @@ -3924,7 +4148,7 @@ FORCE_INLINE __m64 _mm_cvtpd_pi32(__m128d a) // ENDFOR // dst[127:64] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpd_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_ps FORCE_INLINE __m128 _mm_cvtpd_ps(__m128d a) { #if defined(__aarch64__) @@ -3946,7 +4170,7 @@ FORCE_INLINE __m128 _mm_cvtpd_ps(__m128d a) // dst[m+63:m] := Convert_Int32_To_FP64(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtpi32_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi32_pd FORCE_INLINE __m128d _mm_cvtpi32_pd(__m64 a) { #if defined(__aarch64__) @@ -3972,7 +4196,9 @@ FORCE_INLINE __m128d _mm_cvtpi32_pd(__m64 a) // does not support! It is supported on ARMv8-A however. FORCE_INLINE __m128i _mm_cvtps_epi32(__m128 a) { -#if defined(__aarch64__) +#if defined(__ARM_FEATURE_FRINT) + return vreinterpretq_m128i_s32(vcvtq_s32_f32(vrnd32xq_f32(a))); +#elif defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) switch (_MM_GET_ROUNDING_MODE()) { case _MM_ROUND_NEAREST: return vreinterpretq_m128i_s32(vcvtnq_s32_f32(a)); @@ -4029,7 +4255,7 @@ FORCE_INLINE __m128i _mm_cvtps_epi32(__m128 a) // dst[i+63:i] := Convert_FP32_To_FP64(a[k+31:k]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtps_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pd FORCE_INLINE __m128d _mm_cvtps_pd(__m128 a) { #if defined(__aarch64__) @@ -4046,7 +4272,7 @@ FORCE_INLINE __m128d _mm_cvtps_pd(__m128 a) // // dst[63:0] := a[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsd_f64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_f64 FORCE_INLINE double _mm_cvtsd_f64(__m128d a) { #if defined(__aarch64__) @@ -4061,7 +4287,7 @@ FORCE_INLINE double _mm_cvtsd_f64(__m128d a) // // dst[31:0] := Convert_FP64_To_Int32(a[63:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsd_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si32 FORCE_INLINE int32_t _mm_cvtsd_si32(__m128d a) { #if defined(__aarch64__) @@ -4078,7 +4304,7 @@ FORCE_INLINE int32_t _mm_cvtsd_si32(__m128d a) // // dst[63:0] := Convert_FP64_To_Int64(a[63:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsd_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si64 FORCE_INLINE int64_t _mm_cvtsd_si64(__m128d a) { #if defined(__aarch64__) @@ -4095,14 +4321,14 @@ FORCE_INLINE int64_t _mm_cvtsd_si64(__m128d a) // // dst[63:0] := Convert_FP64_To_Int64(a[63:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsd_si64x +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si64x #define _mm_cvtsd_si64x _mm_cvtsd_si64 // Convert the lower double-precision (64-bit) floating-point element in b to a // single-precision (32-bit) floating-point element, store the result in the // lower element of dst, and copy the upper 3 packed elements from a to the // upper elements of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsd_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_ss FORCE_INLINE __m128 _mm_cvtsd_ss(__m128 a, __m128d b) { #if defined(__aarch64__) @@ -4119,7 +4345,7 @@ FORCE_INLINE __m128 _mm_cvtsd_ss(__m128 a, __m128d b) // // dst[31:0] := a[31:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi128_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si32 FORCE_INLINE int _mm_cvtsi128_si32(__m128i a) { return vgetq_lane_s32(vreinterpretq_s32_m128i(a), 0); @@ -4129,20 +4355,20 @@ FORCE_INLINE int _mm_cvtsi128_si32(__m128i a) // // dst[63:0] := a[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi128_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si64 FORCE_INLINE int64_t _mm_cvtsi128_si64(__m128i a) { return vgetq_lane_s64(vreinterpretq_s64_m128i(a), 0); } // Copy the lower 64-bit integer in a to dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi128_si64x +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si64x #define _mm_cvtsi128_si64x(a) _mm_cvtsi128_si64(a) // Convert the signed 32-bit integer b to a double-precision (64-bit) // floating-point element, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi32_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_sd FORCE_INLINE __m128d _mm_cvtsi32_sd(__m128d a, int32_t b) { #if defined(__aarch64__) @@ -4159,7 +4385,7 @@ FORCE_INLINE __m128d _mm_cvtsi32_sd(__m128d a, int32_t b) // // dst[63:0] := a[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi128_si64x +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si64x #define _mm_cvtsi128_si64x(a) _mm_cvtsi128_si64(a) // Moves 32-bit integer a to the least significant 32 bits of an __m128 object, @@ -4179,7 +4405,7 @@ FORCE_INLINE __m128i _mm_cvtsi32_si128(int a) // Convert the signed 64-bit integer b to a double-precision (64-bit) // floating-point element, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi64_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64_sd FORCE_INLINE __m128d _mm_cvtsi64_sd(__m128d a, int64_t b) { #if defined(__aarch64__) @@ -4204,13 +4430,13 @@ FORCE_INLINE __m128i _mm_cvtsi64_si128(int64_t a) // Copy 64-bit integer a to the lower element of dst, and zero the upper // element. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi64x_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64x_si128 #define _mm_cvtsi64x_si128(a) _mm_cvtsi64_si128(a) // Convert the signed 64-bit integer b to a double-precision (64-bit) // floating-point element, store the result in the lower element of dst, and // copy the upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtsi64x_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64x_sd #define _mm_cvtsi64x_sd(a, b) _mm_cvtsi64_sd(a, b) // Convert the lower single-precision (32-bit) floating-point element in b to a @@ -4221,7 +4447,7 @@ FORCE_INLINE __m128i _mm_cvtsi64_si128(int64_t a) // dst[63:0] := Convert_FP32_To_FP64(b[31:0]) // dst[127:64] := a[127:64] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtss_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_sd FORCE_INLINE __m128d _mm_cvtss_sd(__m128d a, __m128 b) { double d = (double) vgetq_lane_f32(vreinterpretq_f32_m128(b), 0); @@ -4236,7 +4462,7 @@ FORCE_INLINE __m128d _mm_cvtss_sd(__m128d a, __m128 b) // Convert packed double-precision (64-bit) floating-point elements in a to // packed 32-bit integers with truncation, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttpd_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttpd_epi32 FORCE_INLINE __m128i _mm_cvttpd_epi32(__m128d a) { double a0 = ((double *) &a)[0]; @@ -4246,7 +4472,7 @@ FORCE_INLINE __m128i _mm_cvttpd_epi32(__m128d a) // Convert packed double-precision (64-bit) floating-point elements in a to // packed 32-bit integers with truncation, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttpd_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttpd_pi32 FORCE_INLINE __m64 _mm_cvttpd_pi32(__m128d a) { double a0 = ((double *) &a)[0]; @@ -4268,7 +4494,7 @@ FORCE_INLINE __m128i _mm_cvttps_epi32(__m128 a) // // dst[63:0] := Convert_FP64_To_Int32_Truncate(a[63:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttsd_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si32 FORCE_INLINE int32_t _mm_cvttsd_si32(__m128d a) { double ret = *((double *) &a); @@ -4280,7 +4506,7 @@ FORCE_INLINE int32_t _mm_cvttsd_si32(__m128d a) // // dst[63:0] := Convert_FP64_To_Int64_Truncate(a[63:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttsd_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si64 FORCE_INLINE int64_t _mm_cvttsd_si64(__m128d a) { #if defined(__aarch64__) @@ -4296,7 +4522,7 @@ FORCE_INLINE int64_t _mm_cvttsd_si64(__m128d a) // // dst[63:0] := Convert_FP64_To_Int64_Truncate(a[63:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvttsd_si64x +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si64x #define _mm_cvttsd_si64x(a) _mm_cvttsd_si64(a) // Divide packed double-precision (64-bit) floating-point elements in a by @@ -4307,7 +4533,7 @@ FORCE_INLINE int64_t _mm_cvttsd_si64(__m128d a) // dst[i+63:i] := a[i+63:i] / b[i+63:i] // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_div_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_pd FORCE_INLINE __m128d _mm_div_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -4327,7 +4553,7 @@ FORCE_INLINE __m128d _mm_div_pd(__m128d a, __m128d b) // lower double-precision (64-bit) floating-point element in b, store the result // in the lower element of dst, and copy the upper element from a to the upper // element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_div_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_sd FORCE_INLINE __m128d _mm_div_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -4363,7 +4589,7 @@ FORCE_INLINE __m128d _mm_div_sd(__m128d a, __m128d b) // // dst[127:0] := MEM[mem_addr+127:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_load_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_pd FORCE_INLINE __m128d _mm_load_pd(const double *p) { #if defined(__aarch64__) @@ -4381,7 +4607,7 @@ FORCE_INLINE __m128d _mm_load_pd(const double *p) // dst[63:0] := MEM[mem_addr+63:mem_addr] // dst[127:64] := MEM[mem_addr+63:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_load_pd1 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_pd1 #define _mm_load_pd1 _mm_load1_pd // Load a double-precision (64-bit) floating-point element from memory into the @@ -4391,7 +4617,7 @@ FORCE_INLINE __m128d _mm_load_pd(const double *p) // dst[63:0] := MEM[mem_addr+63:mem_addr] // dst[127:64] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_load_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_sd FORCE_INLINE __m128d _mm_load_sd(const double *p) { #if defined(__aarch64__) @@ -4416,7 +4642,7 @@ FORCE_INLINE __m128i _mm_load_si128(const __m128i *p) // dst[63:0] := MEM[mem_addr+63:mem_addr] // dst[127:64] := MEM[mem_addr+63:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_load1_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load1_pd FORCE_INLINE __m128d _mm_load1_pd(const double *p) { #if defined(__aarch64__) @@ -4433,7 +4659,7 @@ FORCE_INLINE __m128d _mm_load1_pd(const double *p) // dst[63:0] := a[63:0] // dst[127:64] := MEM[mem_addr+63:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadh_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadh_pd FORCE_INLINE __m128d _mm_loadh_pd(__m128d a, const double *p) { #if defined(__aarch64__) @@ -4446,7 +4672,7 @@ FORCE_INLINE __m128d _mm_loadh_pd(__m128d a, const double *p) } // Load 64-bit integer from memory into the first element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadl_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_epi64 FORCE_INLINE __m128i _mm_loadl_epi64(__m128i const *p) { /* Load the lower 64 bits of the value pointed to by p into the @@ -4463,7 +4689,7 @@ FORCE_INLINE __m128i _mm_loadl_epi64(__m128i const *p) // dst[63:0] := MEM[mem_addr+63:mem_addr] // dst[127:64] := a[127:64] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadl_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_pd FORCE_INLINE __m128d _mm_loadl_pd(__m128d a, const double *p) { #if defined(__aarch64__) @@ -4483,7 +4709,7 @@ FORCE_INLINE __m128d _mm_loadl_pd(__m128d a, const double *p) // dst[63:0] := MEM[mem_addr+127:mem_addr+64] // dst[127:64] := MEM[mem_addr+63:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadr_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadr_pd FORCE_INLINE __m128d _mm_loadr_pd(const double *p) { #if defined(__aarch64__) @@ -4496,7 +4722,7 @@ FORCE_INLINE __m128d _mm_loadr_pd(const double *p) } // Loads two double-precision from unaligned memory, floating-point values. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadu_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_pd FORCE_INLINE __m128d _mm_loadu_pd(const double *p) { return _mm_load_pd(p); @@ -4514,7 +4740,7 @@ FORCE_INLINE __m128i _mm_loadu_si128(const __m128i *p) // dst[31:0] := MEM[mem_addr+31:mem_addr] // dst[MAX:32] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loadu_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si32 FORCE_INLINE __m128i _mm_loadu_si32(const void *p) { return vreinterpretq_m128i_s32( @@ -4533,6 +4759,12 @@ FORCE_INLINE __m128i _mm_madd_epi16(__m128i a, __m128i b) { int32x4_t low = vmull_s16(vget_low_s16(vreinterpretq_s16_m128i(a)), vget_low_s16(vreinterpretq_s16_m128i(b))); +#if defined(__aarch64__) + int32x4_t high = + vmull_high_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b)); + + return vreinterpretq_m128i_s32(vpaddq_s32(low, high)); +#else int32x4_t high = vmull_s16(vget_high_s16(vreinterpretq_s16_m128i(a)), vget_high_s16(vreinterpretq_s16_m128i(b))); @@ -4540,13 +4772,14 @@ FORCE_INLINE __m128i _mm_madd_epi16(__m128i a, __m128i b) int32x2_t high_sum = vpadd_s32(vget_low_s32(high), vget_high_s32(high)); return vreinterpretq_m128i_s32(vcombine_s32(low_sum, high_sum)); +#endif } // Conditionally store 8-bit integer elements from a into memory using mask // (elements are not stored when the highest bit is not set in the corresponding // element) and a non-temporal memory hint. mem_addr does not need to be aligned // on any particular boundary. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_maskmoveu_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskmoveu_si128 FORCE_INLINE void _mm_maskmoveu_si128(__m128i a, __m128i mask, char *mem_addr) { int8x16_t shr_mask = vshrq_n_s8(vreinterpretq_s8_m128i(mask), 7); @@ -4577,12 +4810,18 @@ FORCE_INLINE __m128i _mm_max_epu8(__m128i a, __m128i b) // Compare packed double-precision (64-bit) floating-point elements in a and b, // and store packed maximum values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pd FORCE_INLINE __m128d _mm_max_pd(__m128d a, __m128d b) { #if defined(__aarch64__) +#if SSE2NEON_PRECISE_MINMAX + float64x2_t _a = vreinterpretq_f64_m128d(a); + float64x2_t _b = vreinterpretq_f64_m128d(b); + return vreinterpretq_m128d_f64(vbslq_f64(vcgtq_f64(_a, _b), _a, _b)); +#else return vreinterpretq_m128d_f64( vmaxq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#endif #else uint64_t a0 = (uint64_t) vget_low_u64(vreinterpretq_u64_m128d(a)); uint64_t a1 = (uint64_t) vget_high_u64(vreinterpretq_u64_m128d(a)); @@ -4599,7 +4838,7 @@ FORCE_INLINE __m128d _mm_max_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b, store the maximum value in the lower element of dst, and copy the upper // element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_sd FORCE_INLINE __m128d _mm_max_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -4607,8 +4846,8 @@ FORCE_INLINE __m128d _mm_max_sd(__m128d a, __m128d b) #else double *da = (double *) &a; double *db = (double *) &b; - double c[2] = {fmax(da[0], db[0]), da[1]}; - return vld1q_f32((float32_t *) c); + double c[2] = {da[0] > db[0] ? da[0] : db[0], da[1]}; + return vreinterpretq_m128d_f32(vld1q_f32((float32_t *) c)); #endif } @@ -4632,12 +4871,18 @@ FORCE_INLINE __m128i _mm_min_epu8(__m128i a, __m128i b) // Compare packed double-precision (64-bit) floating-point elements in a and b, // and store packed minimum values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_min_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pd FORCE_INLINE __m128d _mm_min_pd(__m128d a, __m128d b) { #if defined(__aarch64__) +#if SSE2NEON_PRECISE_MINMAX + float64x2_t _a = vreinterpretq_f64_m128d(a); + float64x2_t _b = vreinterpretq_f64_m128d(b); + return vreinterpretq_m128d_f64(vbslq_f64(vcltq_f64(_a, _b), _a, _b)); +#else return vreinterpretq_m128d_f64( vminq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#endif #else uint64_t a0 = (uint64_t) vget_low_u64(vreinterpretq_u64_m128d(a)); uint64_t a1 = (uint64_t) vget_high_u64(vreinterpretq_u64_m128d(a)); @@ -4653,7 +4898,7 @@ FORCE_INLINE __m128d _mm_min_pd(__m128d a, __m128d b) // Compare the lower double-precision (64-bit) floating-point elements in a and // b, store the minimum value in the lower element of dst, and copy the upper // element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_min_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_sd FORCE_INLINE __m128d _mm_min_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -4661,8 +4906,8 @@ FORCE_INLINE __m128d _mm_min_sd(__m128d a, __m128d b) #else double *da = (double *) &a; double *db = (double *) &b; - double c[2] = {fmin(da[0], db[0]), da[1]}; - return vld1q_f32((float32_t *) c); + double c[2] = {da[0] < db[0] ? da[0] : db[0], da[1]}; + return vreinterpretq_m128d_f32(vld1q_f32((float32_t *) c)); #endif } @@ -4672,7 +4917,7 @@ FORCE_INLINE __m128d _mm_min_sd(__m128d a, __m128d b) // dst[63:0] := a[63:0] // dst[127:64] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_move_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_epi64 FORCE_INLINE __m128i _mm_move_epi64(__m128i a) { return vreinterpretq_m128i_s64( @@ -4686,7 +4931,7 @@ FORCE_INLINE __m128i _mm_move_epi64(__m128i a) // dst[63:0] := b[63:0] // dst[127:64] := a[127:64] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_move_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_sd FORCE_INLINE __m128d _mm_move_sd(__m128d a, __m128d b) { return vreinterpretq_m128d_f32( @@ -4780,7 +5025,7 @@ FORCE_INLINE int _mm_movemask_epi8(__m128i a) // Set each bit of mask dst based on the most significant bit of the // corresponding packed double-precision (64-bit) floating-point element in a. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_movemask_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_pd FORCE_INLINE int _mm_movemask_pd(__m128d a) { uint64x2_t input = vreinterpretq_u64_m128d(a); @@ -4792,7 +5037,7 @@ FORCE_INLINE int _mm_movemask_pd(__m128d a) // // dst[63:0] := a[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_movepi64_pi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movepi64_pi64 FORCE_INLINE __m64 _mm_movepi64_pi64(__m128i a) { return vreinterpret_m64_s64(vget_low_s64(vreinterpretq_s64_m128i(a))); @@ -4804,7 +5049,7 @@ FORCE_INLINE __m64 _mm_movepi64_pi64(__m128i a) // dst[63:0] := a[63:0] // dst[127:64] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_movpi64_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movpi64_epi64 FORCE_INLINE __m128i _mm_movpi64_epi64(__m64 a) { return vreinterpretq_m128i_s64( @@ -4826,7 +5071,7 @@ FORCE_INLINE __m128i _mm_mul_epu32(__m128i a, __m128i b) // Multiply packed double-precision (64-bit) floating-point elements in a and b, // and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mul_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_pd FORCE_INLINE __m128d _mm_mul_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -4845,7 +5090,7 @@ FORCE_INLINE __m128d _mm_mul_pd(__m128d a, __m128d b) // Multiply the lower double-precision (64-bit) floating-point element in a and // b, store the result in the lower element of dst, and copy the upper element // from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_mul_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_mul_sd FORCE_INLINE __m128d _mm_mul_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_mul_pd(a, b)); @@ -4856,7 +5101,7 @@ FORCE_INLINE __m128d _mm_mul_sd(__m128d a, __m128d b) // // dst[63:0] := a[31:0] * b[31:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mul_su32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_su32 FORCE_INLINE __m64 _mm_mul_su32(__m64 a, __m64 b) { return vreinterpret_m64_u64(vget_low_u64( @@ -4892,7 +5137,7 @@ FORCE_INLINE __m128i _mm_mulhi_epi16(__m128i a, __m128i b) // Multiply the packed unsigned 16-bit integers in a and b, producing // intermediate 32-bit integers, and store the high 16 bits of the intermediate // integers in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mulhi_epu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_epu16 FORCE_INLINE __m128i _mm_mulhi_epu16(__m128i a, __m128i b) { uint16x4_t a3210 = vget_low_u16(vreinterpretq_u16_m128i(a)); @@ -4931,7 +5176,7 @@ FORCE_INLINE __m128i _mm_mullo_epi16(__m128i a, __m128i b) // Compute the bitwise OR of packed double-precision (64-bit) floating-point // elements in a and b, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_or_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_or_pd FORCE_INLINE __m128d _mm_or_pd(__m128d a, __m128d b) { return vreinterpretq_m128d_s64( @@ -5001,7 +5246,7 @@ FORCE_INLINE __m128i _mm_packus_epi16(const __m128i a, const __m128i b) // Pause the processor. This is typically used in spin-wait loops and depending // on the x86 processor typical values are in the 40-100 cycle range. The -// 'yield' instruction isn't a good fit beacuse it's effectively a nop on most +// 'yield' instruction isn't a good fit because it's effectively a nop on most // Arm cores. Experience with several databases has shown has shown an 'isb' is // a reasonable approximation. FORCE_INLINE void _mm_pause() @@ -5013,7 +5258,7 @@ FORCE_INLINE void _mm_pause() // b, then horizontally sum each consecutive 8 differences to produce two // unsigned 16-bit integers, and pack these unsigned 16-bit integers in the low // 16 bits of 64-bit elements in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sad_epu8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_epu8 FORCE_INLINE __m128i _mm_sad_epu8(__m128i a, __m128i b) { uint16x8_t t = vpaddlq_u8(vabdq_u8((uint8x16_t) a, (uint8x16_t) b)); @@ -5089,7 +5334,7 @@ FORCE_INLINE __m128i _mm_set_epi8(signed char b15, // Set packed double-precision (64-bit) floating-point elements in dst with the // supplied values. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_set_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_pd FORCE_INLINE __m128d _mm_set_pd(double e1, double e0) { double ALIGN_STRUCT(16) data[2] = {e0, e1}; @@ -5102,15 +5347,19 @@ FORCE_INLINE __m128d _mm_set_pd(double e1, double e0) // Broadcast double-precision (64-bit) floating-point value a to all elements of // dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_set_pd1 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_pd1 #define _mm_set_pd1 _mm_set1_pd // Copy double-precision (64-bit) floating-point element a to the lower element // of dst, and zero the upper element. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_set_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_sd FORCE_INLINE __m128d _mm_set_sd(double a) { +#if defined(__aarch64__) + return vreinterpretq_m128d_f64(vsetq_lane_f64(a, vdupq_n_f64(0), 0)); +#else return _mm_set_pd(0, a); +#endif } // Sets the 8 signed 16-bit integer values to w. @@ -5147,7 +5396,7 @@ FORCE_INLINE __m128i _mm_set1_epi64(__m64 _i) } // Sets the 2 signed 64-bit integer values to i. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_set1_epi64x +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi64x FORCE_INLINE __m128i _mm_set1_epi64x(int64_t _i) { return vreinterpretq_m128i_s64(vdupq_n_s64(_i)); @@ -5168,7 +5417,7 @@ FORCE_INLINE __m128i _mm_set1_epi8(signed char w) // Broadcast double-precision (64-bit) floating-point value a to all elements of // dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_set1_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_pd FORCE_INLINE __m128d _mm_set1_pd(double d) { #if defined(__aarch64__) @@ -5207,7 +5456,7 @@ FORCE_INLINE __m128i _mm_setr_epi32(int i3, int i2, int i1, int i0) } // Set packed 64-bit integers in dst with the supplied values in reverse order. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_setr_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi64 FORCE_INLINE __m128i _mm_setr_epi64(__m64 e1, __m64 e0) { return vreinterpretq_m128i_s64(vcombine_s64(e1, e0)); @@ -5242,14 +5491,14 @@ FORCE_INLINE __m128i _mm_setr_epi8(signed char b0, // Set packed double-precision (64-bit) floating-point elements in dst with the // supplied values in reverse order. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_setr_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_pd FORCE_INLINE __m128d _mm_setr_pd(double e1, double e0) { return _mm_set_pd(e0, e1); } // Return vector of type __m128d with all elements set to zero. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_setzero_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setzero_pd FORCE_INLINE __m128d _mm_setzero_pd(void) { #if defined(__aarch64__) @@ -5270,14 +5519,14 @@ FORCE_INLINE __m128i _mm_setzero_si128(void) // https://msdn.microsoft.com/en-us/library/56f67xbk%28v=vs.90%29.aspx // FORCE_INLINE __m128i _mm_shuffle_epi32(__m128i a, // __constrange(0,255) int imm) -#if __has_builtin(__builtin_shufflevector) -#define _mm_shuffle_epi32(a, imm) \ - __extension__({ \ - int32x4_t _input = vreinterpretq_s32_m128i(a); \ - int32x4_t _shuf = __builtin_shufflevector( \ - _input, _input, (imm) & (0x3), ((imm) >> 2) & 0x3, \ - ((imm) >> 4) & 0x3, ((imm) >> 6) & 0x3); \ - vreinterpretq_m128i_s32(_shuf); \ +#ifdef _sse2neon_shuffle +#define _mm_shuffle_epi32(a, imm) \ + __extension__({ \ + int32x4_t _input = vreinterpretq_s32_m128i(a); \ + int32x4_t _shuf = \ + vshuffleq_s32(_input, _input, (imm) & (0x3), ((imm) >> 2) & 0x3, \ + ((imm) >> 4) & 0x3, ((imm) >> 6) & 0x3); \ + vreinterpretq_m128i_s32(_shuf); \ }) #else // generic #define _mm_shuffle_epi32(a, imm) \ @@ -5340,12 +5589,12 @@ FORCE_INLINE __m128i _mm_setzero_si128(void) // dst[63:0] := (imm8[0] == 0) ? a[63:0] : a[127:64] // dst[127:64] := (imm8[1] == 0) ? b[63:0] : b[127:64] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_shuffle_pd -#if __has_builtin(__builtin_shufflevector) -#define _mm_shuffle_pd(a, b, imm8) \ - vreinterpretq_m128d_s64(__builtin_shufflevector( \ - vreinterpretq_s64_m128d(a), vreinterpretq_s64_m128d(b), imm8 & 0x1, \ - ((imm8 & 0x2) >> 1) + 2)) +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pd +#ifdef _sse2neon_shuffle +#define _mm_shuffle_pd(a, b, imm8) \ + vreinterpretq_m128d_s64( \ + vshuffleq_s64(vreinterpretq_s64_m128d(a), vreinterpretq_s64_m128d(b), \ + imm8 & 0x1, ((imm8 & 0x2) >> 1) + 2)) #else #define _mm_shuffle_pd(a, b, imm8) \ _mm_castsi128_pd(_mm_set_epi64x( \ @@ -5355,15 +5604,15 @@ FORCE_INLINE __m128i _mm_setzero_si128(void) // FORCE_INLINE __m128i _mm_shufflehi_epi16(__m128i a, // __constrange(0,255) int imm) -#if __has_builtin(__builtin_shufflevector) -#define _mm_shufflehi_epi16(a, imm) \ - __extension__({ \ - int16x8_t _input = vreinterpretq_s16_m128i(a); \ - int16x8_t _shuf = __builtin_shufflevector( \ - _input, _input, 0, 1, 2, 3, ((imm) & (0x3)) + 4, \ - (((imm) >> 2) & 0x3) + 4, (((imm) >> 4) & 0x3) + 4, \ - (((imm) >> 6) & 0x3) + 4); \ - vreinterpretq_m128i_s16(_shuf); \ +#ifdef _sse2neon_shuffle +#define _mm_shufflehi_epi16(a, imm) \ + __extension__({ \ + int16x8_t _input = vreinterpretq_s16_m128i(a); \ + int16x8_t _shuf = \ + vshuffleq_s16(_input, _input, 0, 1, 2, 3, ((imm) & (0x3)) + 4, \ + (((imm) >> 2) & 0x3) + 4, (((imm) >> 4) & 0x3) + 4, \ + (((imm) >> 6) & 0x3) + 4); \ + vreinterpretq_m128i_s16(_shuf); \ }) #else // generic #define _mm_shufflehi_epi16(a, imm) _mm_shufflehi_epi16_function((a), (imm)) @@ -5371,11 +5620,11 @@ FORCE_INLINE __m128i _mm_setzero_si128(void) // FORCE_INLINE __m128i _mm_shufflelo_epi16(__m128i a, // __constrange(0,255) int imm) -#if __has_builtin(__builtin_shufflevector) +#ifdef _sse2neon_shuffle #define _mm_shufflelo_epi16(a, imm) \ __extension__({ \ int16x8_t _input = vreinterpretq_s16_m128i(a); \ - int16x8_t _shuf = __builtin_shufflevector( \ + int16x8_t _shuf = vshuffleq_s16( \ _input, _input, ((imm) & (0x3)), (((imm) >> 2) & 0x3), \ (((imm) >> 4) & 0x3), (((imm) >> 6) & 0x3), 4, 5, 6, 7); \ vreinterpretq_m128i_s16(_shuf); \ @@ -5396,7 +5645,7 @@ FORCE_INLINE __m128i _mm_setzero_si128(void) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sll_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi16 FORCE_INLINE __m128i _mm_sll_epi16(__m128i a, __m128i count) { uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); @@ -5419,7 +5668,7 @@ FORCE_INLINE __m128i _mm_sll_epi16(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sll_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi32 FORCE_INLINE __m128i _mm_sll_epi32(__m128i a, __m128i count) { uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); @@ -5442,7 +5691,7 @@ FORCE_INLINE __m128i _mm_sll_epi32(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sll_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi64 FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count) { uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); @@ -5465,7 +5714,7 @@ FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_slli_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi16 FORCE_INLINE __m128i _mm_slli_epi16(__m128i a, int imm) { if (_sse2neon_unlikely(imm & ~15)) @@ -5486,7 +5735,7 @@ FORCE_INLINE __m128i _mm_slli_epi16(__m128i a, int imm) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_slli_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi32 FORCE_INLINE __m128i _mm_slli_epi32(__m128i a, int imm) { if (_sse2neon_unlikely(imm & ~31)) @@ -5507,7 +5756,7 @@ FORCE_INLINE __m128i _mm_slli_epi32(__m128i a, int imm) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_slli_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi64 FORCE_INLINE __m128i _mm_slli_epi64(__m128i a, int imm) { if (_sse2neon_unlikely(imm & ~63)) @@ -5525,19 +5774,23 @@ FORCE_INLINE __m128i _mm_slli_epi64(__m128i a, int imm) // FI // dst[127:0] := a[127:0] << (tmp*8) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_slli_si128 -FORCE_INLINE __m128i _mm_slli_si128(__m128i a, int imm) -{ - if (_sse2neon_unlikely(imm & ~15)) - return _mm_setzero_si128(); - uint8x16_t tmp[2] = {vdupq_n_u8(0), vreinterpretq_u8_m128i(a)}; - return vreinterpretq_m128i_u8( - vld1q_u8(((uint8_t const *) tmp) + (16 - imm))); -} +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_si128 +#define _mm_slli_si128(a, imm) \ + __extension__({ \ + int8x16_t ret; \ + if (_sse2neon_unlikely(imm == 0)) \ + ret = vreinterpretq_s8_m128i(a); \ + else if (_sse2neon_unlikely((imm) & ~15)) \ + ret = vdupq_n_s8(0); \ + else \ + ret = vextq_s8(vdupq_n_s8(0), vreinterpretq_s8_m128i(a), \ + ((imm <= 0 || imm > 15) ? 0 : (16 - imm))); \ + vreinterpretq_m128i_s8(ret); \ + }) // Compute the square root of packed double-precision (64-bit) floating-point // elements in a, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sqrt_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_pd FORCE_INLINE __m128d _mm_sqrt_pd(__m128d a) { #if defined(__aarch64__) @@ -5552,7 +5805,7 @@ FORCE_INLINE __m128d _mm_sqrt_pd(__m128d a) // Compute the square root of the lower double-precision (64-bit) floating-point // element in b, store the result in the lower element of dst, and copy the // upper element from a to the upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sqrt_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_sd FORCE_INLINE __m128d _mm_sqrt_sd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -5574,7 +5827,7 @@ FORCE_INLINE __m128d _mm_sqrt_sd(__m128d a, __m128d b) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sra_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sra_epi16 FORCE_INLINE __m128i _mm_sra_epi16(__m128i a, __m128i count) { int64_t c = (int64_t) vget_low_s64((int64x2_t) count); @@ -5595,7 +5848,7 @@ FORCE_INLINE __m128i _mm_sra_epi16(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sra_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sra_epi32 FORCE_INLINE __m128i _mm_sra_epi32(__m128i a, __m128i count) { int64_t c = (int64_t) vget_low_s64((int64x2_t) count); @@ -5616,7 +5869,7 @@ FORCE_INLINE __m128i _mm_sra_epi32(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srai_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srai_epi16 FORCE_INLINE __m128i _mm_srai_epi16(__m128i a, int imm) { const int count = (imm & ~15) ? 15 : imm; @@ -5635,21 +5888,21 @@ FORCE_INLINE __m128i _mm_srai_epi16(__m128i a, int imm) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srai_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srai_epi32 // FORCE_INLINE __m128i _mm_srai_epi32(__m128i a, __constrange(0,255) int imm) -#define _mm_srai_epi32(a, imm) \ - __extension__({ \ - __m128i ret; \ - if (_sse2neon_unlikely((imm) == 0)) { \ - ret = a; \ - } else if (_sse2neon_likely(0 < (imm) && (imm) < 32)) { \ - ret = vreinterpretq_m128i_s32( \ - vshlq_s32(vreinterpretq_s32_m128i(a), vdupq_n_s32(-imm))); \ - } else { \ - ret = vreinterpretq_m128i_s32( \ - vshrq_n_s32(vreinterpretq_s32_m128i(a), 31)); \ - } \ - ret; \ +#define _mm_srai_epi32(a, imm) \ + __extension__({ \ + __m128i ret; \ + if (_sse2neon_unlikely((imm) == 0)) { \ + ret = a; \ + } else if (_sse2neon_likely(0 < (imm) && (imm) < 32)) { \ + ret = vreinterpretq_m128i_s32( \ + vshlq_s32(vreinterpretq_s32_m128i(a), vdupq_n_s32(-(imm)))); \ + } else { \ + ret = vreinterpretq_m128i_s32( \ + vshrq_n_s32(vreinterpretq_s32_m128i(a), 31)); \ + } \ + ret; \ }) // Shift packed 16-bit integers in a right by count while shifting in zeros, and @@ -5664,7 +5917,7 @@ FORCE_INLINE __m128i _mm_srai_epi16(__m128i a, int imm) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srl_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi16 FORCE_INLINE __m128i _mm_srl_epi16(__m128i a, __m128i count) { uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); @@ -5687,7 +5940,7 @@ FORCE_INLINE __m128i _mm_srl_epi16(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srl_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi32 FORCE_INLINE __m128i _mm_srl_epi32(__m128i a, __m128i count) { uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); @@ -5710,7 +5963,7 @@ FORCE_INLINE __m128i _mm_srl_epi32(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srl_epi64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi64 FORCE_INLINE __m128i _mm_srl_epi64(__m128i a, __m128i count) { uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); @@ -5733,17 +5986,17 @@ FORCE_INLINE __m128i _mm_srl_epi64(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srli_epi16 -#define _mm_srli_epi16(a, imm) \ - __extension__({ \ - __m128i ret; \ - if (_sse2neon_unlikely(imm & ~15)) { \ - ret = _mm_setzero_si128(); \ - } else { \ - ret = vreinterpretq_m128i_u16( \ - vshlq_u16(vreinterpretq_u16_m128i(a), vdupq_n_s16(-imm))); \ - } \ - ret; \ +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi16 +#define _mm_srli_epi16(a, imm) \ + __extension__({ \ + __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~15)) { \ + ret = _mm_setzero_si128(); \ + } else { \ + ret = vreinterpretq_m128i_u16( \ + vshlq_u16(vreinterpretq_u16_m128i(a), vdupq_n_s16(-(imm)))); \ + } \ + ret; \ }) // Shift packed 32-bit integers in a right by imm8 while shifting in zeros, and @@ -5758,18 +6011,18 @@ FORCE_INLINE __m128i _mm_srl_epi64(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srli_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi32 // FORCE_INLINE __m128i _mm_srli_epi32(__m128i a, __constrange(0,255) int imm) -#define _mm_srli_epi32(a, imm) \ - __extension__({ \ - __m128i ret; \ - if (_sse2neon_unlikely(imm & ~31)) { \ - ret = _mm_setzero_si128(); \ - } else { \ - ret = vreinterpretq_m128i_u32( \ - vshlq_u32(vreinterpretq_u32_m128i(a), vdupq_n_s32(-imm))); \ - } \ - ret; \ +#define _mm_srli_epi32(a, imm) \ + __extension__({ \ + __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~31)) { \ + ret = _mm_setzero_si128(); \ + } else { \ + ret = vreinterpretq_m128i_u32( \ + vshlq_u32(vreinterpretq_u32_m128i(a), vdupq_n_s32(-(imm)))); \ + } \ + ret; \ }) // Shift packed 64-bit integers in a right by imm8 while shifting in zeros, and @@ -5784,17 +6037,17 @@ FORCE_INLINE __m128i _mm_srl_epi64(__m128i a, __m128i count) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srli_epi64 -#define _mm_srli_epi64(a, imm) \ - __extension__({ \ - __m128i ret; \ - if (_sse2neon_unlikely(imm & ~63)) { \ - ret = _mm_setzero_si128(); \ - } else { \ - ret = vreinterpretq_m128i_u64( \ - vshlq_u64(vreinterpretq_u64_m128i(a), vdupq_n_s64(-imm))); \ - } \ - ret; \ +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi64 +#define _mm_srli_epi64(a, imm) \ + __extension__({ \ + __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~63)) { \ + ret = _mm_setzero_si128(); \ + } else { \ + ret = vreinterpretq_m128i_u64( \ + vshlq_u64(vreinterpretq_u64_m128i(a), vdupq_n_s64(-(imm)))); \ + } \ + ret; \ }) // Shift a right by imm8 bytes while shifting in zeros, and store the results in @@ -5806,19 +6059,22 @@ FORCE_INLINE __m128i _mm_srl_epi64(__m128i a, __m128i count) // FI // dst[127:0] := a[127:0] >> (tmp*8) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_srli_si128 -FORCE_INLINE __m128i _mm_srli_si128(__m128i a, int imm) -{ - if (_sse2neon_unlikely(imm & ~15)) - return _mm_setzero_si128(); - uint8x16_t tmp[2] = {vreinterpretq_u8_m128i(a), vdupq_n_u8(0)}; - return vreinterpretq_m128i_u8(vld1q_u8(((uint8_t const *) tmp) + imm)); -} +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_si128 +#define _mm_srli_si128(a, imm) \ + __extension__({ \ + int8x16_t ret; \ + if (_sse2neon_unlikely((imm) & ~15)) \ + ret = vdupq_n_s8(0); \ + else \ + ret = vextq_s8(vreinterpretq_s8_m128i(a), vdupq_n_s8(0), \ + (imm > 15 ? 0 : imm)); \ + vreinterpretq_m128i_s8(ret); \ + }) // Store 128-bits (composed of 2 packed double-precision (64-bit) floating-point // elements) from a into memory. mem_addr must be aligned on a 16-byte boundary // or a general-protection exception may be generated. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_store_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_pd FORCE_INLINE void _mm_store_pd(double *mem_addr, __m128d a) { #if defined(__aarch64__) @@ -5831,7 +6087,7 @@ FORCE_INLINE void _mm_store_pd(double *mem_addr, __m128d a) // Store the lower double-precision (64-bit) floating-point element from a into // 2 contiguous elements in memory. mem_addr must be aligned on a 16-byte // boundary or a general-protection exception may be generated. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_store_pd1 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_pd1 FORCE_INLINE void _mm_store_pd1(double *mem_addr, __m128d a) { #if defined(__aarch64__) @@ -5847,7 +6103,7 @@ FORCE_INLINE void _mm_store_pd1(double *mem_addr, __m128d a) // Store the lower double-precision (64-bit) floating-point element from a into // memory. mem_addr does not need to be aligned on any particular boundary. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_store_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_store_sd FORCE_INLINE void _mm_store_sd(double *mem_addr, __m128d a) { #if defined(__aarch64__) @@ -5867,7 +6123,7 @@ FORCE_INLINE void _mm_store_si128(__m128i *p, __m128i a) // Store the lower double-precision (64-bit) floating-point element from a into // 2 contiguous elements in memory. mem_addr must be aligned on a 16-byte // boundary or a general-protection exception may be generated. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#expand=9,526,5601&text=_mm_store1_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#expand=9,526,5601&text=_mm_store1_pd #define _mm_store1_pd _mm_store_pd1 // Store the upper double-precision (64-bit) floating-point element from a into @@ -5875,7 +6131,7 @@ FORCE_INLINE void _mm_store_si128(__m128i *p, __m128i a) // // MEM[mem_addr+63:mem_addr] := a[127:64] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storeh_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeh_pd FORCE_INLINE void _mm_storeh_pd(double *mem_addr, __m128d a) { #if defined(__aarch64__) @@ -5889,9 +6145,7 @@ FORCE_INLINE void _mm_storeh_pd(double *mem_addr, __m128d a) // https://msdn.microsoft.com/en-us/library/hhwf428f%28v=vs.90%29.aspx FORCE_INLINE void _mm_storel_epi64(__m128i *a, __m128i b) { - uint64x1_t hi = vget_high_u64(vreinterpretq_u64_m128i(*a)); - uint64x1_t lo = vget_low_u64(vreinterpretq_u64_m128i(b)); - *a = vreinterpretq_m128i_u64(vcombine_u64(lo, hi)); + vst1_u64((uint64_t *) a, vget_low_u64(vreinterpretq_u64_m128i(b))); } // Store the lower double-precision (64-bit) floating-point element from a into @@ -5899,7 +6153,7 @@ FORCE_INLINE void _mm_storel_epi64(__m128i *a, __m128i b) // // MEM[mem_addr+63:mem_addr] := a[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storel_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storel_pd FORCE_INLINE void _mm_storel_pd(double *mem_addr, __m128d a) { #if defined(__aarch64__) @@ -5916,7 +6170,7 @@ FORCE_INLINE void _mm_storel_pd(double *mem_addr, __m128d a) // MEM[mem_addr+63:mem_addr] := a[127:64] // MEM[mem_addr+127:mem_addr+64] := a[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storer_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storer_pd FORCE_INLINE void _mm_storer_pd(double *mem_addr, __m128d a) { float32x4_t f = vreinterpretq_f32_m128d(a); @@ -5926,21 +6180,21 @@ FORCE_INLINE void _mm_storer_pd(double *mem_addr, __m128d a) // Store 128-bits (composed of 2 packed double-precision (64-bit) floating-point // elements) from a into memory. mem_addr does not need to be aligned on any // particular boundary. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storeu_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_pd FORCE_INLINE void _mm_storeu_pd(double *mem_addr, __m128d a) { _mm_store_pd(mem_addr, a); } // Stores 128-bits of integer data a at the address p. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storeu_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si128 FORCE_INLINE void _mm_storeu_si128(__m128i *p, __m128i a) { vst1q_s32((int32_t *) p, vreinterpretq_s32_m128i(a)); } // Stores 32-bits of integer data a at the address p. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_storeu_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si32 FORCE_INLINE void _mm_storeu_si32(void *p, __m128i a) { vst1q_lane_s32((int32_t *) p, vreinterpretq_s32_m128i(a), 0); @@ -5950,11 +6204,11 @@ FORCE_INLINE void _mm_storeu_si32(void *p, __m128i a) // elements) from a into memory using a non-temporal memory hint. mem_addr must // be aligned on a 16-byte boundary or a general-protection exception may be // generated. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_stream_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_pd FORCE_INLINE void _mm_stream_pd(double *p, __m128d a) { #if __has_builtin(__builtin_nontemporal_store) - __builtin_nontemporal_store(a, (float32x4_t *) p); + __builtin_nontemporal_store(reinterpret_cast(a), (float32x4_t *) p); #elif defined(__aarch64__) vst1q_f64(p, vreinterpretq_f64_m128d(a)); #else @@ -5978,15 +6232,24 @@ FORCE_INLINE void _mm_stream_si128(__m128i *p, __m128i a) // Store 32-bit integer a into memory using a non-temporal hint to minimize // cache pollution. If the cache line containing address mem_addr is already in // the cache, the cache will be updated. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_stream_si32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si32 FORCE_INLINE void _mm_stream_si32(int *p, int a) { vst1q_lane_s32((int32_t *) p, vdupq_n_s32(a), 0); } +// Store 64-bit integer a into memory using a non-temporal hint to minimize +// cache pollution. If the cache line containing address mem_addr is already in +// the cache, the cache will be updated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si64 +FORCE_INLINE void _mm_stream_si64(__int64 *p, __int64 a) +{ + vst1_s64((int64_t *) p, vdup_n_s64((int64_t) a)); +} + // Subtract packed 16-bit integers in b from packed 16-bit integers in a, and // store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sub_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi16 FORCE_INLINE __m128i _mm_sub_epi16(__m128i a, __m128i b) { return vreinterpretq_m128i_s16( @@ -6020,7 +6283,7 @@ FORCE_INLINE __m128i _mm_sub_epi64(__m128i a, __m128i b) // Subtract packed 8-bit integers in b from packed 8-bit integers in a, and // store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sub_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi8 FORCE_INLINE __m128i _mm_sub_epi8(__m128i a, __m128i b) { return vreinterpretq_m128i_s8( @@ -6036,7 +6299,7 @@ FORCE_INLINE __m128i _mm_sub_epi8(__m128i a, __m128i b) // dst[i+63:i] := a[i+63:i] - b[i+63:i] // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_sub_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_sub_pd FORCE_INLINE __m128d _mm_sub_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -6056,7 +6319,7 @@ FORCE_INLINE __m128d _mm_sub_pd(__m128d a, __m128d b) // the lower double-precision (64-bit) floating-point element in a, store the // result in the lower element of dst, and copy the upper element from a to the // upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sub_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_sd FORCE_INLINE __m128d _mm_sub_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_sub_pd(a, b)); @@ -6066,7 +6329,7 @@ FORCE_INLINE __m128d _mm_sub_sd(__m128d a, __m128d b) // // dst[63:0] := a[63:0] - b[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sub_si64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_si64 FORCE_INLINE __m64 _mm_sub_si64(__m64 a, __m64 b) { return vreinterpret_m64_s64( @@ -6135,7 +6398,7 @@ FORCE_INLINE __m128i _mm_subs_epu8(__m128i a, __m128i b) #define _mm_ucomineq_sd _mm_comineq_sd // Return vector of type __m128d with undefined elements. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_undefined_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_undefined_pd FORCE_INLINE __m128d _mm_undefined_pd(void) { #if defined(__GNUC__) || defined(__clang__) @@ -6240,7 +6503,7 @@ FORCE_INLINE __m128i _mm_unpackhi_epi8(__m128i a, __m128i b) // } // dst[127:0] := INTERLEAVE_HIGH_QWORDS(a[127:0], b[127:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_unpackhi_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_pd FORCE_INLINE __m128d _mm_unpackhi_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -6343,7 +6606,7 @@ FORCE_INLINE __m128i _mm_unpacklo_epi8(__m128i a, __m128i b) // } // dst[127:0] := INTERLEAVE_QWORDS(a[127:0], b[127:0]) // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_unpacklo_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_pd FORCE_INLINE __m128d _mm_unpacklo_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -6364,7 +6627,7 @@ FORCE_INLINE __m128d _mm_unpacklo_pd(__m128d a, __m128d b) // dst[i+63:i] := a[i+63:i] XOR b[i+63:i] // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_xor_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_xor_pd FORCE_INLINE __m128d _mm_xor_pd(__m128d a, __m128d b) { return vreinterpretq_m128d_s64( @@ -6394,10 +6657,10 @@ FORCE_INLINE __m128i _mm_xor_si128(__m128i a, __m128i b) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_addsub_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_addsub_pd FORCE_INLINE __m128d _mm_addsub_pd(__m128d a, __m128d b) { - __m128d mask = _mm_set_pd(1.0f, -1.0f); + _sse2neon_const __m128d mask = _mm_set_pd(1.0f, -1.0f); #if defined(__aarch64__) return vreinterpretq_m128d_f64(vfmaq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b), @@ -6410,10 +6673,10 @@ FORCE_INLINE __m128d _mm_addsub_pd(__m128d a, __m128d b) // Alternatively add and subtract packed single-precision (32-bit) // floating-point elements in a to/from packed elements in b, and store the // results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=addsub_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=addsub_ps FORCE_INLINE __m128 _mm_addsub_ps(__m128 a, __m128 b) { - __m128 mask = {-1.0f, 1.0f, -1.0f, 1.0f}; + _sse2neon_const __m128 mask = _mm_setr_ps(-1.0f, 1.0f, -1.0f, 1.0f); #if defined(__aarch64__) || defined(__ARM_FEATURE_FMA) /* VFPv4+ */ return vreinterpretq_m128_f32(vfmaq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(mask), @@ -6425,7 +6688,7 @@ FORCE_INLINE __m128 _mm_addsub_ps(__m128 a, __m128 b) // Horizontally add adjacent pairs of double-precision (64-bit) floating-point // elements in a and b, and pack the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hadd_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_pd FORCE_INLINE __m128d _mm_hadd_pd(__m128d a, __m128d b) { #if defined(__aarch64__) @@ -6459,13 +6722,14 @@ FORCE_INLINE __m128 _mm_hadd_ps(__m128 a, __m128 b) // Horizontally subtract adjacent pairs of double-precision (64-bit) // floating-point elements in a and b, and pack the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hsub_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_pd FORCE_INLINE __m128d _mm_hsub_pd(__m128d _a, __m128d _b) { #if defined(__aarch64__) - return vreinterpretq_m128d_f64(vsubq_f64( - vuzp1q_f64(vreinterpretq_f64_m128d(_a), vreinterpretq_f64_m128d(_b)), - vuzp2q_f64(vreinterpretq_f64_m128d(_a), vreinterpretq_f64_m128d(_b)))); + float64x2_t a = vreinterpretq_f64_m128d(_a); + float64x2_t b = vreinterpretq_f64_m128d(_b); + return vreinterpretq_m128d_f64( + vsubq_f64(vuzp1q_f64(a, b), vuzp2q_f64(a, b))); #else double *da = (double *) &_a; double *db = (double *) &_b; @@ -6474,18 +6738,18 @@ FORCE_INLINE __m128d _mm_hsub_pd(__m128d _a, __m128d _b) #endif } -// Horizontally substract adjacent pairs of single-precision (32-bit) +// Horizontally subtract adjacent pairs of single-precision (32-bit) // floating-point elements in a and b, and pack the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hsub_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_ps FORCE_INLINE __m128 _mm_hsub_ps(__m128 _a, __m128 _b) { + float32x4_t a = vreinterpretq_f32_m128(_a); + float32x4_t b = vreinterpretq_f32_m128(_b); #if defined(__aarch64__) - return vreinterpretq_m128_f32(vsubq_f32( - vuzp1q_f32(vreinterpretq_f32_m128(_a), vreinterpretq_f32_m128(_b)), - vuzp2q_f32(vreinterpretq_f32_m128(_a), vreinterpretq_f32_m128(_b)))); + return vreinterpretq_m128_f32( + vsubq_f32(vuzp1q_f32(a, b), vuzp2q_f32(a, b))); #else - float32x4x2_t c = - vuzpq_f32(vreinterpretq_f32_m128(_a), vreinterpretq_f32_m128(_b)); + float32x4x2_t c = vuzpq_f32(a, b); return vreinterpretq_m128_f32(vsubq_f32(c.val[0], c.val[1])); #endif } @@ -6496,7 +6760,7 @@ FORCE_INLINE __m128 _mm_hsub_ps(__m128 _a, __m128 _b) // // dst[127:0] := MEM[mem_addr+127:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_lddqu_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_lddqu_si128 #define _mm_lddqu_si128 _mm_loadu_si128 // Load a double-precision (64-bit) floating-point element from memory into both @@ -6505,15 +6769,15 @@ FORCE_INLINE __m128 _mm_hsub_ps(__m128 _a, __m128 _b) // dst[63:0] := MEM[mem_addr+63:mem_addr] // dst[127:64] := MEM[mem_addr+63:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_loaddup_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loaddup_pd #define _mm_loaddup_pd _mm_load1_pd // Duplicate the low double-precision (64-bit) floating-point element from a, // and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_movedup_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movedup_pd FORCE_INLINE __m128d _mm_movedup_pd(__m128d a) { -#if (__aarch64__) +#if defined(__aarch64__) return vreinterpretq_m128d_f64( vdupq_laneq_f64(vreinterpretq_f64_m128d(a), 0)); #else @@ -6524,11 +6788,14 @@ FORCE_INLINE __m128d _mm_movedup_pd(__m128d a) // Duplicate odd-indexed single-precision (32-bit) floating-point elements // from a, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_movehdup_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movehdup_ps FORCE_INLINE __m128 _mm_movehdup_ps(__m128 a) { -#if __has_builtin(__builtin_shufflevector) - return vreinterpretq_m128_f32(__builtin_shufflevector( +#if defined(__aarch64__) + return vreinterpretq_m128_f32( + vtrn2q_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a))); +#elif defined(_sse2neon_shuffle) + return vreinterpretq_m128_f32(vshuffleq_s32( vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a), 1, 1, 3, 3)); #else float32_t a1 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 1); @@ -6540,11 +6807,14 @@ FORCE_INLINE __m128 _mm_movehdup_ps(__m128 a) // Duplicate even-indexed single-precision (32-bit) floating-point elements // from a, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_moveldup_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_moveldup_ps FORCE_INLINE __m128 _mm_moveldup_ps(__m128 a) { -#if __has_builtin(__builtin_shufflevector) - return vreinterpretq_m128_f32(__builtin_shufflevector( +#if defined(__aarch64__) + return vreinterpretq_m128_f32( + vtrn1q_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a))); +#elif defined(_sse2neon_shuffle) + return vreinterpretq_m128_f32(vshuffleq_s32( vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a), 0, 0, 2, 2)); #else float32_t a0 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); @@ -6564,7 +6834,7 @@ FORCE_INLINE __m128 _mm_moveldup_ps(__m128 a) // dst[i+15:i] := ABS(a[i+15:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_abs_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_epi16 FORCE_INLINE __m128i _mm_abs_epi16(__m128i a) { return vreinterpretq_m128i_s16(vabsq_s16(vreinterpretq_s16_m128i(a))); @@ -6578,7 +6848,7 @@ FORCE_INLINE __m128i _mm_abs_epi16(__m128i a) // dst[i+31:i] := ABS(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_abs_epi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_epi32 FORCE_INLINE __m128i _mm_abs_epi32(__m128i a) { return vreinterpretq_m128i_s32(vabsq_s32(vreinterpretq_s32_m128i(a))); @@ -6592,7 +6862,7 @@ FORCE_INLINE __m128i _mm_abs_epi32(__m128i a) // dst[i+7:i] := ABS(a[i+7:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_abs_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_epi8 FORCE_INLINE __m128i _mm_abs_epi8(__m128i a) { return vreinterpretq_m128i_s8(vabsq_s8(vreinterpretq_s8_m128i(a))); @@ -6606,7 +6876,7 @@ FORCE_INLINE __m128i _mm_abs_epi8(__m128i a) // dst[i+15:i] := ABS(a[i+15:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_abs_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_pi16 FORCE_INLINE __m64 _mm_abs_pi16(__m64 a) { return vreinterpret_m64_s16(vabs_s16(vreinterpret_s16_m64(a))); @@ -6620,7 +6890,7 @@ FORCE_INLINE __m64 _mm_abs_pi16(__m64 a) // dst[i+31:i] := ABS(a[i+31:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_abs_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_pi32 FORCE_INLINE __m64 _mm_abs_pi32(__m64 a) { return vreinterpret_m64_s32(vabs_s32(vreinterpret_s32_m64(a))); @@ -6634,7 +6904,7 @@ FORCE_INLINE __m64 _mm_abs_pi32(__m64 a) // dst[i+7:i] := ABS(a[i+7:i]) // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_abs_pi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_pi8 FORCE_INLINE __m64 _mm_abs_pi8(__m64 a) { return vreinterpret_m64_s8(vabs_s8(vreinterpret_s8_m64(a))); @@ -6646,24 +6916,21 @@ FORCE_INLINE __m64 _mm_abs_pi8(__m64 a) // tmp[255:0] := ((a[127:0] << 128)[255:0] OR b[127:0]) >> (imm8*8) // dst[127:0] := tmp[127:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_alignr_epi8 -FORCE_INLINE __m128i _mm_alignr_epi8(__m128i a, __m128i b, int imm) -{ - if (_sse2neon_unlikely(imm & ~31)) - return _mm_setzero_si128(); - int idx; - uint8x16_t tmp[2]; - if (imm >= 16) { - idx = imm - 16; - tmp[0] = vreinterpretq_u8_m128i(a); - tmp[1] = vdupq_n_u8(0); - } else { - idx = imm; - tmp[0] = vreinterpretq_u8_m128i(b); - tmp[1] = vreinterpretq_u8_m128i(a); - } - return vreinterpretq_m128i_u8(vld1q_u8(((uint8_t const *) tmp) + idx)); -} +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_alignr_epi8 +#define _mm_alignr_epi8(a, b, imm) \ + __extension__({ \ + uint8x16_t _a = vreinterpretq_u8_m128i(a); \ + uint8x16_t _b = vreinterpretq_u8_m128i(b); \ + __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~31)) \ + ret = vreinterpretq_m128i_u8(vdupq_n_u8(0)); \ + else if (imm >= 16) \ + ret = _mm_srli_si128(a, imm >= 16 ? imm - 16 : 0); \ + else \ + ret = \ + vreinterpretq_m128i_u8(vextq_u8(_b, _a, imm < 16 ? imm : 0)); \ + ret; \ + }) // Concatenate 8-byte blocks in a and b into a 16-byte temporary result, shift // the result right by imm8 bytes, and store the low 8 bytes in dst. @@ -6671,7 +6938,7 @@ FORCE_INLINE __m128i _mm_alignr_epi8(__m128i a, __m128i b, int imm) // tmp[127:0] := ((a[63:0] << 64)[127:0] OR b[63:0]) >> (imm8*8) // dst[63:0] := tmp[63:0] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_alignr_pi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_alignr_pi8 #define _mm_alignr_pi8(a, b, imm) \ __extension__({ \ __m64 ret; \ @@ -6679,13 +6946,13 @@ FORCE_INLINE __m128i _mm_alignr_epi8(__m128i a, __m128i b, int imm) ret = vreinterpret_m64_s8(vdup_n_s8(0)); \ } else { \ uint8x8_t tmp_low, tmp_high; \ - if (imm >= 8) { \ - const int idx = imm - 8; \ + if ((imm) >= 8) { \ + const int idx = (imm) -8; \ tmp_low = vreinterpret_u8_m64(a); \ tmp_high = vdup_n_u8(0); \ ret = vreinterpret_m64_u8(vext_u8(tmp_low, tmp_high, idx)); \ } else { \ - const int idx = imm; \ + const int idx = (imm); \ tmp_low = vreinterpret_u8_m64(b); \ tmp_high = vreinterpret_u8_m64(a); \ ret = vreinterpret_m64_u8(vext_u8(tmp_low, tmp_high, idx)); \ @@ -6715,14 +6982,18 @@ FORCE_INLINE __m128i _mm_hadd_epi32(__m128i _a, __m128i _b) { int32x4_t a = vreinterpretq_s32_m128i(_a); int32x4_t b = vreinterpretq_s32_m128i(_b); +#if defined(__aarch64__) + return vreinterpretq_m128i_s32(vpaddq_s32(a, b)); +#else return vreinterpretq_m128i_s32( vcombine_s32(vpadd_s32(vget_low_s32(a), vget_high_s32(a)), vpadd_s32(vget_low_s32(b), vget_high_s32(b)))); +#endif } // Horizontally add adjacent pairs of 16-bit integers in a and b, and pack the // signed 16-bit results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hadd_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_pi16 FORCE_INLINE __m64 _mm_hadd_pi16(__m64 a, __m64 b) { return vreinterpret_m64_s16( @@ -6731,7 +7002,7 @@ FORCE_INLINE __m64 _mm_hadd_pi16(__m64 a, __m64 b) // Horizontally add adjacent pairs of 32-bit integers in a and b, and pack the // signed 32-bit results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hadd_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_pi32 FORCE_INLINE __m64 _mm_hadd_pi32(__m64 a, __m64 b) { return vreinterpret_m64_s32( @@ -6762,7 +7033,7 @@ FORCE_INLINE __m128i _mm_hadds_epi16(__m128i _a, __m128i _b) // Horizontally add adjacent pairs of signed 16-bit integers in a and b using // saturation, and pack the signed 16-bit results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hadds_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadds_pi16 FORCE_INLINE __m64 _mm_hadds_pi16(__m64 _a, __m64 _b) { int16x4_t a = vreinterpret_s16_m64(_a); @@ -6775,101 +7046,96 @@ FORCE_INLINE __m64 _mm_hadds_pi16(__m64 _a, __m64 _b) #endif } -// Computes pairwise difference of each argument as a 16-bit signed or unsigned -// integer values a and b. -FORCE_INLINE __m128i _mm_hsub_epi16(__m128i _a, __m128i _b) -{ - int32x4_t a = vreinterpretq_s32_m128i(_a); - int32x4_t b = vreinterpretq_s32_m128i(_b); - // Interleave using vshrn/vmovn - // [a0|a2|a4|a6|b0|b2|b4|b6] - // [a1|a3|a5|a7|b1|b3|b5|b7] - int16x8_t ab0246 = vcombine_s16(vmovn_s32(a), vmovn_s32(b)); - int16x8_t ab1357 = vcombine_s16(vshrn_n_s32(a, 16), vshrn_n_s32(b, 16)); - // Subtract - return vreinterpretq_m128i_s16(vsubq_s16(ab0246, ab1357)); -} - -// Computes pairwise difference of each argument as a 32-bit signed or unsigned -// integer values a and b. -FORCE_INLINE __m128i _mm_hsub_epi32(__m128i _a, __m128i _b) -{ - int64x2_t a = vreinterpretq_s64_m128i(_a); - int64x2_t b = vreinterpretq_s64_m128i(_b); - // Interleave using vshrn/vmovn - // [a0|a2|b0|b2] - // [a1|a2|b1|b3] - int32x4_t ab02 = vcombine_s32(vmovn_s64(a), vmovn_s64(b)); - int32x4_t ab13 = vcombine_s32(vshrn_n_s64(a, 32), vshrn_n_s64(b, 32)); - // Subtract - return vreinterpretq_m128i_s32(vsubq_s32(ab02, ab13)); -} - // Horizontally subtract adjacent pairs of 16-bit integers in a and b, and pack // the signed 16-bit results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hsub_pi16 -FORCE_INLINE __m64 _mm_hsub_pi16(__m64 _a, __m64 _b) +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_epi16 +FORCE_INLINE __m128i _mm_hsub_epi16(__m128i _a, __m128i _b) { - int32x4_t ab = - vcombine_s32(vreinterpret_s32_m64(_a), vreinterpret_s32_m64(_b)); - - int16x4_t ab_low_bits = vmovn_s32(ab); - int16x4_t ab_high_bits = vshrn_n_s32(ab, 16); - - return vreinterpret_m64_s16(vsub_s16(ab_low_bits, ab_high_bits)); + int16x8_t a = vreinterpretq_s16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); +#if defined(__aarch64__) + return vreinterpretq_m128i_s16( + vsubq_s16(vuzp1q_s16(a, b), vuzp2q_s16(a, b))); +#else + int16x8x2_t c = vuzpq_s16(a, b); + return vreinterpretq_m128i_s16(vsubq_s16(c.val[0], c.val[1])); +#endif } // Horizontally subtract adjacent pairs of 32-bit integers in a and b, and pack // the signed 32-bit results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_hsub_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_epi32 +FORCE_INLINE __m128i _mm_hsub_epi32(__m128i _a, __m128i _b) +{ + int32x4_t a = vreinterpretq_s32_m128i(_a); + int32x4_t b = vreinterpretq_s32_m128i(_b); +#if defined(__aarch64__) + return vreinterpretq_m128i_s32( + vsubq_s32(vuzp1q_s32(a, b), vuzp2q_s32(a, b))); +#else + int32x4x2_t c = vuzpq_s32(a, b); + return vreinterpretq_m128i_s32(vsubq_s32(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of 16-bit integers in a and b, and pack +// the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_pi16 +FORCE_INLINE __m64 _mm_hsub_pi16(__m64 _a, __m64 _b) +{ + int16x4_t a = vreinterpret_s16_m64(_a); + int16x4_t b = vreinterpret_s16_m64(_b); +#if defined(__aarch64__) + return vreinterpret_m64_s16(vsub_s16(vuzp1_s16(a, b), vuzp2_s16(a, b))); +#else + int16x4x2_t c = vuzp_s16(a, b); + return vreinterpret_m64_s16(vsub_s16(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of 32-bit integers in a and b, and pack +// the signed 32-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_hsub_pi32 FORCE_INLINE __m64 _mm_hsub_pi32(__m64 _a, __m64 _b) { -#if defined(__aarch64__) int32x2_t a = vreinterpret_s32_m64(_a); int32x2_t b = vreinterpret_s32_m64(_b); - return vreinterpret_m64_s32(vsub_s32(vtrn1_s32(a, b), vtrn2_s32(a, b))); +#if defined(__aarch64__) + return vreinterpret_m64_s32(vsub_s32(vuzp1_s32(a, b), vuzp2_s32(a, b))); #else - int32x2x2_t trn_ab = - vtrn_s32(vreinterpret_s32_m64(_a), vreinterpret_s32_m64(_b)); - return vreinterpret_m64_s32(vsub_s32(trn_ab.val[0], trn_ab.val[1])); + int32x2x2_t c = vuzp_s32(a, b); + return vreinterpret_m64_s32(vsub_s32(c.val[0], c.val[1])); #endif } // Computes saturated pairwise difference of each argument as a 16-bit signed // integer values a and b. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hsubs_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsubs_epi16 FORCE_INLINE __m128i _mm_hsubs_epi16(__m128i _a, __m128i _b) { -#if defined(__aarch64__) int16x8_t a = vreinterpretq_s16_m128i(_a); int16x8_t b = vreinterpretq_s16_m128i(_b); - return vreinterpretq_s64_s16( +#if defined(__aarch64__) + return vreinterpretq_m128i_s16( vqsubq_s16(vuzp1q_s16(a, b), vuzp2q_s16(a, b))); #else - int32x4_t a = vreinterpretq_s32_m128i(_a); - int32x4_t b = vreinterpretq_s32_m128i(_b); - // Interleave using vshrn/vmovn - // [a0|a2|a4|a6|b0|b2|b4|b6] - // [a1|a3|a5|a7|b1|b3|b5|b7] - int16x8_t ab0246 = vcombine_s16(vmovn_s32(a), vmovn_s32(b)); - int16x8_t ab1357 = vcombine_s16(vshrn_n_s32(a, 16), vshrn_n_s32(b, 16)); - // Saturated subtract - return vreinterpretq_m128i_s16(vqsubq_s16(ab0246, ab1357)); + int16x8x2_t c = vuzpq_s16(a, b); + return vreinterpretq_m128i_s16(vqsubq_s16(c.val[0], c.val[1])); #endif } // Horizontally subtract adjacent pairs of signed 16-bit integers in a and b // using saturation, and pack the signed 16-bit results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_hsubs_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsubs_pi16 FORCE_INLINE __m64 _mm_hsubs_pi16(__m64 _a, __m64 _b) { int16x4_t a = vreinterpret_s16_m64(_a); int16x4_t b = vreinterpret_s16_m64(_b); #if defined(__aarch64__) - return vreinterpret_s64_s16(vqsub_s16(vuzp1_s16(a, b), vuzp2_s16(a, b))); + return vreinterpret_m64_s16(vqsub_s16(vuzp1_s16(a, b), vuzp2_s16(a, b))); #else - int16x4x2_t res = vuzp_s16(a, b); - return vreinterpret_s64_s16(vqsub_s16(res.val[0], res.val[1])); + int16x4x2_t c = vuzp_s16(a, b); + return vreinterpret_m64_s16(vqsub_s16(c.val[0], c.val[1])); #endif } @@ -6921,7 +7187,7 @@ FORCE_INLINE __m128i _mm_maddubs_epi16(__m128i _a, __m128i _b) // signed 8-bit integer from b, producing intermediate signed 16-bit integers. // Horizontally add adjacent pairs of intermediate signed 16-bit integers, and // pack the saturated results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_maddubs_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maddubs_pi16 FORCE_INLINE __m64 _mm_maddubs_pi16(__m64 _a, __m64 _b) { uint16x4_t a = vreinterpret_u16_m64(_a); @@ -6975,7 +7241,7 @@ FORCE_INLINE __m128i _mm_mulhrs_epi16(__m128i a, __m128i b) // Multiply packed signed 16-bit integers in a and b, producing intermediate // signed 32-bit integers. Truncate each intermediate integer to the 18 most // significant bits, round by adding 1, and store bits [16:1] to dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mulhrs_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhrs_pi16 FORCE_INLINE __m64 _mm_mulhrs_pi16(__m64 a, __m64 b) { int32x4_t mul_extend = @@ -6987,7 +7253,7 @@ FORCE_INLINE __m64 _mm_mulhrs_pi16(__m64 a, __m64 b) // Shuffle packed 8-bit integers in a according to shuffle control mask in the // corresponding 8-bit element of b, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_shuffle_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_epi8 FORCE_INLINE __m128i _mm_shuffle_epi8(__m128i a, __m128i b) { int8x16_t tbl = vreinterpretq_s8_m128i(a); // input a @@ -7028,11 +7294,11 @@ FORCE_INLINE __m128i _mm_shuffle_epi8(__m128i a, __m128i b) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_shuffle_pi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pi8 FORCE_INLINE __m64 _mm_shuffle_pi8(__m64 a, __m64 b) { const int8x8_t controlMask = - vand_s8(vreinterpret_s8_m64(b), vdup_n_s8((int8_t)(0x1 << 7 | 0x07))); + vand_s8(vreinterpret_s8_m64(b), vdup_n_s8((int8_t) (0x1 << 7 | 0x07))); int8x8_t res = vtbl1_s8(vreinterpret_s8_m64(a), controlMask); return vreinterpret_m64_s8(res); } @@ -7142,7 +7408,7 @@ FORCE_INLINE __m128i _mm_sign_epi8(__m128i _a, __m128i _b) int8x16_t zeroMask = vreinterpretq_s8_u8(vceqq_s8(b, vdupq_n_s8(0))); #endif - // bitwise select either a or nagative 'a' (vnegq_s8(a) return nagative 'a') + // bitwise select either a or negative 'a' (vnegq_s8(a) return negative 'a') // based on ltMask int8x16_t masked = vbslq_s8(ltMask, vnegq_s8(a), a); // res = masked & (~zeroMask) @@ -7166,7 +7432,7 @@ FORCE_INLINE __m128i _mm_sign_epi8(__m128i _a, __m128i _b) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sign_pi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_pi16 FORCE_INLINE __m64 _mm_sign_pi16(__m64 _a, __m64 _b) { int16x4_t a = vreinterpret_s16_m64(_a); @@ -7183,7 +7449,7 @@ FORCE_INLINE __m64 _mm_sign_pi16(__m64 _a, __m64 _b) int16x4_t zeroMask = vreinterpret_s16_u16(vceq_s16(b, vdup_n_s16(0))); #endif - // bitwise select either a or nagative 'a' (vneg_s16(a) return nagative 'a') + // bitwise select either a or negative 'a' (vneg_s16(a) return negative 'a') // based on ltMask int16x4_t masked = vbsl_s16(ltMask, vneg_s16(a), a); // res = masked & (~zeroMask) @@ -7207,7 +7473,7 @@ FORCE_INLINE __m64 _mm_sign_pi16(__m64 _a, __m64 _b) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sign_pi32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_pi32 FORCE_INLINE __m64 _mm_sign_pi32(__m64 _a, __m64 _b) { int32x2_t a = vreinterpret_s32_m64(_a); @@ -7224,7 +7490,7 @@ FORCE_INLINE __m64 _mm_sign_pi32(__m64 _a, __m64 _b) int32x2_t zeroMask = vreinterpret_s32_u32(vceq_s32(b, vdup_n_s32(0))); #endif - // bitwise select either a or nagative 'a' (vneg_s32(a) return nagative 'a') + // bitwise select either a or negative 'a' (vneg_s32(a) return negative 'a') // based on ltMask int32x2_t masked = vbsl_s32(ltMask, vneg_s32(a), a); // res = masked & (~zeroMask) @@ -7248,7 +7514,7 @@ FORCE_INLINE __m64 _mm_sign_pi32(__m64 _a, __m64 _b) // FI // ENDFOR // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sign_pi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_pi8 FORCE_INLINE __m64 _mm_sign_pi8(__m64 _a, __m64 _b) { int8x8_t a = vreinterpret_s8_m64(_a); @@ -7265,7 +7531,7 @@ FORCE_INLINE __m64 _mm_sign_pi8(__m64 _a, __m64 _b) int8x8_t zeroMask = vreinterpret_s8_u8(vceq_s8(b, vdup_n_s8(0))); #endif - // bitwise select either a or nagative 'a' (vneg_s8(a) return nagative 'a') + // bitwise select either a or negative 'a' (vneg_s8(a) return negative 'a') // based on ltMask int8x8_t masked = vbsl_s8(ltMask, vneg_s8(a), a); // res = masked & (~zeroMask) @@ -7309,7 +7575,7 @@ FORCE_INLINE __m64 _mm_sign_pi8(__m64 _a, __m64 _b) // Blend packed double-precision (64-bit) floating-point elements from a and b // using control mask imm8, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_blend_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blend_pd #define _mm_blend_pd(a, b, imm) \ __extension__({ \ const uint64_t _mask[2] = { \ @@ -7323,7 +7589,7 @@ FORCE_INLINE __m64 _mm_sign_pi8(__m64 _a, __m64 _b) // Blend packed single-precision (32-bit) floating-point elements from a and b // using mask, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_blend_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blend_ps FORCE_INLINE __m128 _mm_blend_ps(__m128 _a, __m128 _b, const char imm8) { const uint32_t ALIGN_STRUCT(16) @@ -7360,7 +7626,7 @@ FORCE_INLINE __m128i _mm_blendv_epi8(__m128i _a, __m128i _b, __m128i _mask) // Blend packed double-precision (64-bit) floating-point elements from a and b // using mask, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_blendv_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blendv_pd FORCE_INLINE __m128d _mm_blendv_pd(__m128d _a, __m128d _b, __m128d _mask) { uint64x2_t mask = @@ -7378,7 +7644,7 @@ FORCE_INLINE __m128d _mm_blendv_pd(__m128d _a, __m128d _b, __m128d _mask) // Blend packed single-precision (32-bit) floating-point elements from a and b // using mask, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_blendv_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blendv_ps FORCE_INLINE __m128 _mm_blendv_ps(__m128 _a, __m128 _b, __m128 _mask) { // Use a signed shift right to create a mask with the sign bit @@ -7392,7 +7658,7 @@ FORCE_INLINE __m128 _mm_blendv_ps(__m128 _a, __m128 _b, __m128 _mask) // Round the packed double-precision (64-bit) floating-point elements in a up // to an integer value, and store the results as packed double-precision // floating-point elements in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_ceil_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_pd FORCE_INLINE __m128d _mm_ceil_pd(__m128d a) { #if defined(__aarch64__) @@ -7406,10 +7672,10 @@ FORCE_INLINE __m128d _mm_ceil_pd(__m128d a) // Round the packed single-precision (32-bit) floating-point elements in a up to // an integer value, and store the results as packed single-precision // floating-point elements in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_ceil_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_ps FORCE_INLINE __m128 _mm_ceil_ps(__m128 a) { -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) return vreinterpretq_m128_f32(vrndpq_f32(vreinterpretq_f32_m128(a))); #else float *f = (float *) &a; @@ -7421,7 +7687,7 @@ FORCE_INLINE __m128 _mm_ceil_ps(__m128 a) // an integer value, store the result as a double-precision floating-point // element in the lower element of dst, and copy the upper element from a to the // upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_ceil_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_sd FORCE_INLINE __m128d _mm_ceil_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_ceil_pd(b)); @@ -7435,7 +7701,7 @@ FORCE_INLINE __m128d _mm_ceil_sd(__m128d a, __m128d b) // dst[31:0] := CEIL(b[31:0]) // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_ceil_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_ss FORCE_INLINE __m128 _mm_ceil_ss(__m128 a, __m128 b) { return _mm_move_ss(a, _mm_ceil_ps(b)); @@ -7542,7 +7808,7 @@ FORCE_INLINE __m128i _mm_cvtepu32_epi64(__m128i a) // Zero extend packed unsigned 8-bit integers in a to packed 16-bit integers, // and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cvtepu8_epi16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu8_epi16 FORCE_INLINE __m128i _mm_cvtepu8_epi16(__m128i a) { uint8x16_t u8x16 = vreinterpretq_u8_m128i(a); /* xxxx xxxx HGFE DCBA */ @@ -7575,7 +7841,7 @@ FORCE_INLINE __m128i _mm_cvtepu8_epi64(__m128i a) // Conditionally multiply the packed double-precision (64-bit) floating-point // elements in a and b using the high 4 bits in imm8, sum the four products, and // conditionally store the sum in dst using the low 4 bits of imm8. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_dp_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_dp_pd FORCE_INLINE __m128d _mm_dp_pd(__m128d a, __m128d b, const int imm) { // Generate mask value from constant immediate bit value @@ -7621,7 +7887,7 @@ FORCE_INLINE __m128d _mm_dp_pd(__m128d a, __m128d b, const int imm) // Conditionally multiply the packed single-precision (32-bit) floating-point // elements in a and b using the high 4 bits in imm8, sum the four products, // and conditionally store the sum in dst using the low 4 bits of imm. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_dp_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_dp_ps FORCE_INLINE __m128 _mm_dp_ps(__m128 a, __m128 b, const int imm) { #if defined(__aarch64__) @@ -7677,7 +7943,7 @@ FORCE_INLINE __m128 _mm_dp_ps(__m128 a, __m128 b, const int imm) // Extracts the selected signed or unsigned 8-bit integer from a and zero // extends. // FORCE_INLINE int _mm_extract_epi8(__m128i a, __constrange(0,16) int imm) -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_extract_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi8 #define _mm_extract_epi8(a, imm) vgetq_lane_u8(vreinterpretq_u8_m128i(a), (imm)) // Extracts the selected single-precision (32-bit) floating-point from a. @@ -7687,7 +7953,7 @@ FORCE_INLINE __m128 _mm_dp_ps(__m128 a, __m128 b, const int imm) // Round the packed double-precision (64-bit) floating-point elements in a down // to an integer value, and store the results as packed double-precision // floating-point elements in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_floor_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_pd FORCE_INLINE __m128d _mm_floor_pd(__m128d a) { #if defined(__aarch64__) @@ -7701,10 +7967,10 @@ FORCE_INLINE __m128d _mm_floor_pd(__m128d a) // Round the packed single-precision (32-bit) floating-point elements in a down // to an integer value, and store the results as packed single-precision // floating-point elements in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_floor_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_ps FORCE_INLINE __m128 _mm_floor_ps(__m128 a) { -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) return vreinterpretq_m128_f32(vrndmq_f32(vreinterpretq_f32_m128(a))); #else float *f = (float *) &a; @@ -7716,7 +7982,7 @@ FORCE_INLINE __m128 _mm_floor_ps(__m128 a) // an integer value, store the result as a double-precision floating-point // element in the lower element of dst, and copy the upper element from a to the // upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_floor_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_sd FORCE_INLINE __m128d _mm_floor_sd(__m128d a, __m128d b) { return _mm_move_sd(a, _mm_floor_pd(b)); @@ -7730,7 +7996,7 @@ FORCE_INLINE __m128d _mm_floor_sd(__m128d a, __m128d b) // dst[31:0] := FLOOR(b[31:0]) // dst[127:32] := a[127:32] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_floor_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_ss FORCE_INLINE __m128 _mm_floor_ss(__m128 a, __m128 b) { return _mm_move_ss(a, _mm_floor_ps(b)); @@ -7769,7 +8035,7 @@ FORCE_INLINE __m128 _mm_floor_ss(__m128 a, __m128 b) // Copy a to tmp, then insert a single-precision (32-bit) floating-point // element from b into tmp using the control in imm8. Store tmp to dst using // the mask in imm8 (elements are zeroed out when the corresponding bit is set). -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=insert_ps +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=insert_ps #define _mm_insert_ps(a, b, imm8) \ __extension__({ \ float32x4_t tmp1 = \ @@ -7808,7 +8074,7 @@ FORCE_INLINE __m128i _mm_max_epi32(__m128i a, __m128i b) // Compare packed signed 8-bit integers in a and b, and store packed maximum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epi8 FORCE_INLINE __m128i _mm_max_epi8(__m128i a, __m128i b) { return vreinterpretq_m128i_s8( @@ -7817,7 +8083,7 @@ FORCE_INLINE __m128i _mm_max_epi8(__m128i a, __m128i b) // Compare packed unsigned 16-bit integers in a and b, and store packed maximum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_epu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu16 FORCE_INLINE __m128i _mm_max_epu16(__m128i a, __m128i b) { return vreinterpretq_m128i_u16( @@ -7826,7 +8092,7 @@ FORCE_INLINE __m128i _mm_max_epu16(__m128i a, __m128i b) // Compare packed unsigned 32-bit integers in a and b, and store packed maximum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_epu32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu32 FORCE_INLINE __m128i _mm_max_epu32(__m128i a, __m128i b) { return vreinterpretq_m128i_u32( @@ -7851,7 +8117,7 @@ FORCE_INLINE __m128i _mm_min_epi32(__m128i a, __m128i b) // Compare packed signed 8-bit integers in a and b, and store packed minimum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_min_epi8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epi8 FORCE_INLINE __m128i _mm_min_epi8(__m128i a, __m128i b) { return vreinterpretq_m128i_s8( @@ -7860,7 +8126,7 @@ FORCE_INLINE __m128i _mm_min_epi8(__m128i a, __m128i b) // Compare packed unsigned 16-bit integers in a and b, and store packed minimum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_min_epu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epu16 FORCE_INLINE __m128i _mm_min_epu16(__m128i a, __m128i b) { return vreinterpretq_m128i_u16( @@ -7869,7 +8135,7 @@ FORCE_INLINE __m128i _mm_min_epu16(__m128i a, __m128i b) // Compare packed unsigned 32-bit integers in a and b, and store packed minimum // values in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_max_epu32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu32 FORCE_INLINE __m128i _mm_min_epu32(__m128i a, __m128i b) { return vreinterpretq_m128i_u32( @@ -7892,15 +8158,22 @@ FORCE_INLINE __m128i _mm_min_epu32(__m128i a, __m128i b) // dst[18:16] := index[2:0] // dst[127:19] := 0 // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_minpos_epu16 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_minpos_epu16 FORCE_INLINE __m128i _mm_minpos_epu16(__m128i a) { __m128i dst; uint16_t min, idx = 0; - // Find the minimum value #if defined(__aarch64__) + // Find the minimum value min = vminvq_u16(vreinterpretq_u16_m128i(a)); + + // Get the index of the minimum value + static const uint16_t idxv[] = {0, 1, 2, 3, 4, 5, 6, 7}; + uint16x8_t minv = vdupq_n_u16(min); + uint16x8_t cmeq = vceqq_u16(minv, vreinterpretq_u16_m128i(a)); + idx = vminvq_u16(vornq_u16(vld1q_u16(idxv), cmeq)); #else + // Find the minimum value __m64 tmp; tmp = vreinterpret_m64_u16( vmin_u16(vget_low_u16(vreinterpretq_u16_m128i(a)), @@ -7910,7 +8183,6 @@ FORCE_INLINE __m128i _mm_minpos_epu16(__m128i a) tmp = vreinterpret_m64_u16( vpmin_u16(vreinterpret_u16_m64(tmp), vreinterpret_u16_m64(tmp))); min = vget_lane_u16(vreinterpret_u16_m64(tmp), 0); -#endif // Get the index of the minimum value int i; for (i = 0; i < 8; i++) { @@ -7920,6 +8192,7 @@ FORCE_INLINE __m128i _mm_minpos_epu16(__m128i a) } a = _mm_srli_si128(a, 2); } +#endif // Generate result dst = _mm_setzero_si128(); dst = vreinterpretq_m128i_u16( @@ -7935,7 +8208,7 @@ FORCE_INLINE __m128i _mm_minpos_epu16(__m128i a) // quadruplets from a. One quadruplet is selected from b starting at on the // offset specified in imm8. Eight quadruplets are formed from sequential 8-bit // integers selected from a starting at the offset specified in imm8. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mpsadbw_epu8 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mpsadbw_epu8 FORCE_INLINE __m128i _mm_mpsadbw_epu8(__m128i a, __m128i b, const int imm) { uint8x16_t _a, _b; @@ -7982,13 +8255,13 @@ FORCE_INLINE __m128i _mm_mpsadbw_epu8(__m128i a, __m128i b, const int imm) int16x8_t c04, c15, c26, c37; uint8x8_t low_b = vget_low_u8(_b); - c04 = vabsq_s16(vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(_a), low_b))); - _a = vextq_u8(_a, _a, 1); - c15 = vabsq_s16(vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(_a), low_b))); - _a = vextq_u8(_a, _a, 1); - c26 = vabsq_s16(vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(_a), low_b))); - _a = vextq_u8(_a, _a, 1); - c37 = vabsq_s16(vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(_a), low_b))); + c04 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a), low_b)); + uint8x16_t _a_1 = vextq_u8(_a, _a, 1); + c15 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a_1), low_b)); + uint8x16_t _a_2 = vextq_u8(_a, _a, 2); + c26 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a_2), low_b)); + uint8x16_t _a_3 = vextq_u8(_a, _a, 3); + c37 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a_3), low_b)); #if defined(__aarch64__) // |0|4|2|6| c04 = vpaddq_s16(c04, c26); @@ -8056,7 +8329,7 @@ FORCE_INLINE __m128i _mm_packus_epi32(__m128i a, __m128i b) // Round the packed double-precision (64-bit) floating-point elements in a using // the rounding parameter, and store the results as packed double-precision // floating-point elements in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_round_pd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_round_pd FORCE_INLINE __m128d _mm_round_pd(__m128d a, int rounding) { #if defined(__aarch64__) @@ -8128,7 +8401,7 @@ FORCE_INLINE __m128d _mm_round_pd(__m128d a, int rounding) // software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_round_ps FORCE_INLINE __m128 _mm_round_ps(__m128 a, int rounding) { -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(__ARM_FEATURE_DIRECTED_ROUNDING) switch (rounding) { case (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC): return vreinterpretq_m128_f32(vrndnq_f32(vreinterpretq_f32_m128(a))); @@ -8185,7 +8458,7 @@ FORCE_INLINE __m128 _mm_round_ps(__m128 a, int rounding) // the rounding parameter, store the result as a double-precision floating-point // element in the lower element of dst, and copy the upper element from a to the // upper element of dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_round_sd +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_round_sd FORCE_INLINE __m128d _mm_round_sd(__m128d a, __m128d b, int rounding) { return _mm_move_sd(a, _mm_round_pd(b, rounding)); @@ -8205,7 +8478,7 @@ FORCE_INLINE __m128d _mm_round_sd(__m128d a, __m128d b, int rounding) // (_MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC) // truncate, and suppress // exceptions _MM_FROUND_CUR_DIRECTION // use MXCSR.RC; see // _MM_SET_ROUNDING_MODE -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_round_ss +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_round_ss FORCE_INLINE __m128 _mm_round_ss(__m128 a, __m128 b, int rounding) { return _mm_move_ss(a, _mm_round_ps(b, rounding)); @@ -8217,7 +8490,7 @@ FORCE_INLINE __m128 _mm_round_ss(__m128 a, __m128 b, int rounding) // // dst[127:0] := MEM[mem_addr+127:mem_addr] // -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_stream_load_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_load_si128 FORCE_INLINE __m128i _mm_stream_load_si128(__m128i *p) { #if __has_builtin(__builtin_nontemporal_store) @@ -8229,16 +8502,16 @@ FORCE_INLINE __m128i _mm_stream_load_si128(__m128i *p) // Compute the bitwise NOT of a and then AND with a 128-bit vector containing // all 1's, and return 1 if the result is zero, otherwise return 0. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_test_all_ones +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_test_all_ones FORCE_INLINE int _mm_test_all_ones(__m128i a) { - return (uint64_t)(vgetq_lane_s64(a, 0) & vgetq_lane_s64(a, 1)) == + return (uint64_t) (vgetq_lane_s64(a, 0) & vgetq_lane_s64(a, 1)) == ~(uint64_t) 0; } // Compute the bitwise AND of 128 bits (representing integer data) in a and // mask, and return 1 if the result is zero, otherwise return 0. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_test_all_zeros +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_test_all_zeros FORCE_INLINE int _mm_test_all_zeros(__m128i a, __m128i mask) { int64x2_t a_and_mask = @@ -8251,7 +8524,7 @@ FORCE_INLINE int _mm_test_all_zeros(__m128i a, __m128i mask) // the bitwise NOT of a and then AND with mask, and set CF to 1 if the result is // zero, otherwise set CF to 0. Return 1 if both the ZF and CF values are zero, // otherwise return 0. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=mm_test_mix_ones_zero +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_test_mix_ones_zero FORCE_INLINE int _mm_test_mix_ones_zeros(__m128i a, __m128i mask) { uint64x2_t zf = @@ -8266,12 +8539,11 @@ FORCE_INLINE int _mm_test_mix_ones_zeros(__m128i a, __m128i mask) // and set ZF to 1 if the result is zero, otherwise set ZF to 0. Compute the // bitwise NOT of a and then AND with b, and set CF to 1 if the result is zero, // otherwise set CF to 0. Return the CF value. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_testc_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_testc_si128 FORCE_INLINE int _mm_testc_si128(__m128i a, __m128i b) { int64x2_t s64 = - vandq_s64(vreinterpretq_s64_s32(vmvnq_s32(vreinterpretq_s32_m128i(a))), - vreinterpretq_s64_m128i(b)); + vbicq_s64(vreinterpretq_s64_m128i(b), vreinterpretq_s64_m128i(a)); return !(vgetq_lane_s64(s64, 0) | vgetq_lane_s64(s64, 1)); } @@ -8280,14 +8552,14 @@ FORCE_INLINE int _mm_testc_si128(__m128i a, __m128i b) // bitwise NOT of a and then AND with b, and set CF to 1 if the result is zero, // otherwise set CF to 0. Return 1 if both the ZF and CF values are zero, // otherwise return 0. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_testnzc_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_testnzc_si128 #define _mm_testnzc_si128(a, b) _mm_test_mix_ones_zeros(a, b) // Compute the bitwise AND of 128 bits (representing integer data) in a and b, // and set ZF to 1 if the result is zero, otherwise set ZF to 0. Compute the // bitwise NOT of a and then AND with b, and set CF to 1 if the result is zero, // otherwise set CF to 0. Return the ZF value. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_testz_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_testz_si128 FORCE_INLINE int _mm_testz_si128(__m128i a, __m128i b) { int64x2_t s64 = @@ -8297,6 +8569,756 @@ FORCE_INLINE int _mm_testz_si128(__m128i a, __m128i b) /* SSE4.2 */ +const static uint16_t _sse2neon_cmpestr_mask16b[8] ALIGN_STRUCT(16) = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, +}; +const static uint8_t _sse2neon_cmpestr_mask8b[16] ALIGN_STRUCT(16) = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, +}; + +/* specify the source data format */ +#define _SIDD_UBYTE_OPS 0x00 /* unsigned 8-bit characters */ +#define _SIDD_UWORD_OPS 0x01 /* unsigned 16-bit characters */ +#define _SIDD_SBYTE_OPS 0x02 /* signed 8-bit characters */ +#define _SIDD_SWORD_OPS 0x03 /* signed 16-bit characters */ + +/* specify the comparison operation */ +#define _SIDD_CMP_EQUAL_ANY 0x00 /* compare equal any: strchr */ +#define _SIDD_CMP_RANGES 0x04 /* compare ranges */ +#define _SIDD_CMP_EQUAL_EACH 0x08 /* compare equal each: strcmp */ +#define _SIDD_CMP_EQUAL_ORDERED 0x0C /* compare equal ordered */ + +/* specify the polarity */ +#define _SIDD_POSITIVE_POLARITY 0x00 +#define _SIDD_MASKED_POSITIVE_POLARITY 0x20 +#define _SIDD_NEGATIVE_POLARITY 0x10 /* negate results */ +#define _SIDD_MASKED_NEGATIVE_POLARITY \ + 0x30 /* negate results only before end of string */ + +/* specify the output selection in _mm_cmpXstri */ +#define _SIDD_LEAST_SIGNIFICANT 0x00 +#define _SIDD_MOST_SIGNIFICANT 0x40 + +/* specify the output selection in _mm_cmpXstrm */ +#define _SIDD_BIT_MASK 0x00 +#define _SIDD_UNIT_MASK 0x40 + +/* Pattern Matching for C macros. + * https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms + */ + +/* catenate */ +#define SSE2NEON_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__ +#define SSE2NEON_CAT(a, b) SSE2NEON_PRIMITIVE_CAT(a, b) + +#define SSE2NEON_IIF(c) SSE2NEON_PRIMITIVE_CAT(SSE2NEON_IIF_, c) +/* run the 2nd parameter */ +#define SSE2NEON_IIF_0(t, ...) __VA_ARGS__ +/* run the 1st parameter */ +#define SSE2NEON_IIF_1(t, ...) t + +#define SSE2NEON_COMPL(b) SSE2NEON_PRIMITIVE_CAT(SSE2NEON_COMPL_, b) +#define SSE2NEON_COMPL_0 1 +#define SSE2NEON_COMPL_1 0 + +#define SSE2NEON_DEC(x) SSE2NEON_PRIMITIVE_CAT(SSE2NEON_DEC_, x) +#define SSE2NEON_DEC_1 0 +#define SSE2NEON_DEC_2 1 +#define SSE2NEON_DEC_3 2 +#define SSE2NEON_DEC_4 3 +#define SSE2NEON_DEC_5 4 +#define SSE2NEON_DEC_6 5 +#define SSE2NEON_DEC_7 6 +#define SSE2NEON_DEC_8 7 +#define SSE2NEON_DEC_9 8 +#define SSE2NEON_DEC_10 9 +#define SSE2NEON_DEC_11 10 +#define SSE2NEON_DEC_12 11 +#define SSE2NEON_DEC_13 12 +#define SSE2NEON_DEC_14 13 +#define SSE2NEON_DEC_15 14 +#define SSE2NEON_DEC_16 15 + +/* detection */ +#define SSE2NEON_CHECK_N(x, n, ...) n +#define SSE2NEON_CHECK(...) SSE2NEON_CHECK_N(__VA_ARGS__, 0, ) +#define SSE2NEON_PROBE(x) x, 1, + +#define SSE2NEON_NOT(x) SSE2NEON_CHECK(SSE2NEON_PRIMITIVE_CAT(SSE2NEON_NOT_, x)) +#define SSE2NEON_NOT_0 SSE2NEON_PROBE(~) + +#define SSE2NEON_BOOL(x) SSE2NEON_COMPL(SSE2NEON_NOT(x)) +#define SSE2NEON_IF(c) SSE2NEON_IIF(SSE2NEON_BOOL(c)) + +#define SSE2NEON_EAT(...) +#define SSE2NEON_EXPAND(...) __VA_ARGS__ +#define SSE2NEON_WHEN(c) SSE2NEON_IF(c)(SSE2NEON_EXPAND, SSE2NEON_EAT) + +/* recursion */ +/* deferred expression */ +#define SSE2NEON_EMPTY() +#define SSE2NEON_DEFER(id) id SSE2NEON_EMPTY() +#define SSE2NEON_OBSTRUCT(...) __VA_ARGS__ SSE2NEON_DEFER(SSE2NEON_EMPTY)() +#define SSE2NEON_EXPAND(...) __VA_ARGS__ + +#define SSE2NEON_EVAL(...) \ + SSE2NEON_EVAL1(SSE2NEON_EVAL1(SSE2NEON_EVAL1(__VA_ARGS__))) +#define SSE2NEON_EVAL1(...) \ + SSE2NEON_EVAL2(SSE2NEON_EVAL2(SSE2NEON_EVAL2(__VA_ARGS__))) +#define SSE2NEON_EVAL2(...) \ + SSE2NEON_EVAL3(SSE2NEON_EVAL3(SSE2NEON_EVAL3(__VA_ARGS__))) +#define SSE2NEON_EVAL3(...) __VA_ARGS__ + +#define SSE2NEON_REPEAT(count, macro, ...) \ + SSE2NEON_WHEN(count) \ + (SSE2NEON_OBSTRUCT(SSE2NEON_REPEAT_INDIRECT)()( \ + SSE2NEON_DEC(count), macro, \ + __VA_ARGS__) SSE2NEON_OBSTRUCT(macro)(SSE2NEON_DEC(count), \ + __VA_ARGS__)) +#define SSE2NEON_REPEAT_INDIRECT() SSE2NEON_REPEAT + +#define SSE2NEON_SIZE_OF_byte 8 +#define SSE2NEON_NUMBER_OF_LANES_byte 16 +#define SSE2NEON_SIZE_OF_word 16 +#define SSE2NEON_NUMBER_OF_LANES_word 8 + +#define SSE2NEON_COMPARE_EQUAL_THEN_FILL_LANE(i, type) \ + mtx[i] = vreinterpretq_m128i_##type(vceqq_##type( \ + vdupq_n_##type(vgetq_lane_##type(vreinterpretq_##type##_m128i(b), i)), \ + vreinterpretq_##type##_m128i(a))); + +#define SSE2NEON_FILL_LANE(i, type) \ + vec_b[i] = \ + vdupq_n_##type(vgetq_lane_##type(vreinterpretq_##type##_m128i(b), i)); + +#define PCMPSTR_RANGES(a, b, mtx, data_type_prefix, type_prefix, size, \ + number_of_lanes, byte_or_word) \ + do { \ + SSE2NEON_CAT( \ + data_type_prefix, \ + SSE2NEON_CAT(size, \ + SSE2NEON_CAT(x, SSE2NEON_CAT(number_of_lanes, _t)))) \ + vec_b[number_of_lanes]; \ + __m128i mask = SSE2NEON_IIF(byte_or_word)( \ + vreinterpretq_m128i_u16(vdupq_n_u16(0xff)), \ + vreinterpretq_m128i_u32(vdupq_n_u32(0xffff))); \ + SSE2NEON_EVAL(SSE2NEON_REPEAT(number_of_lanes, SSE2NEON_FILL_LANE, \ + SSE2NEON_CAT(type_prefix, size))) \ + for (int i = 0; i < number_of_lanes; i++) { \ + mtx[i] = SSE2NEON_CAT(vreinterpretq_m128i_u, \ + size)(SSE2NEON_CAT(vbslq_u, size)( \ + SSE2NEON_CAT(vreinterpretq_u, \ + SSE2NEON_CAT(size, _m128i))(mask), \ + SSE2NEON_CAT(vcgeq_, SSE2NEON_CAT(type_prefix, size))( \ + vec_b[i], \ + SSE2NEON_CAT( \ + vreinterpretq_, \ + SSE2NEON_CAT(type_prefix, \ + SSE2NEON_CAT(size, _m128i(a))))), \ + SSE2NEON_CAT(vcleq_, SSE2NEON_CAT(type_prefix, size))( \ + vec_b[i], \ + SSE2NEON_CAT( \ + vreinterpretq_, \ + SSE2NEON_CAT(type_prefix, \ + SSE2NEON_CAT(size, _m128i(a))))))); \ + } \ + } while (0) + +#define PCMPSTR_EQ(a, b, mtx, size, number_of_lanes) \ + do { \ + SSE2NEON_EVAL(SSE2NEON_REPEAT(number_of_lanes, \ + SSE2NEON_COMPARE_EQUAL_THEN_FILL_LANE, \ + SSE2NEON_CAT(u, size))) \ + } while (0) + +#define SSE2NEON_CMP_EQUAL_ANY_IMPL(type) \ + static int _sse2neon_cmp_##type##_equal_any(__m128i a, int la, __m128i b, \ + int lb) \ + { \ + __m128i mtx[16]; \ + PCMPSTR_EQ(a, b, mtx, SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type)); \ + return SSE2NEON_CAT( \ + _sse2neon_aggregate_equal_any_, \ + SSE2NEON_CAT( \ + SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(x, SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, \ + type))))(la, lb, mtx); \ + } + +#define SSE2NEON_CMP_RANGES_IMPL(type, data_type, us, byte_or_word) \ + static int _sse2neon_cmp_##us##type##_ranges(__m128i a, int la, __m128i b, \ + int lb) \ + { \ + __m128i mtx[16]; \ + PCMPSTR_RANGES( \ + a, b, mtx, data_type, us, SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type), byte_or_word); \ + return SSE2NEON_CAT( \ + _sse2neon_aggregate_ranges_, \ + SSE2NEON_CAT( \ + SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(x, SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, \ + type))))(la, lb, mtx); \ + } + +#define SSE2NEON_CMP_EQUAL_ORDERED_IMPL(type) \ + static int _sse2neon_cmp_##type##_equal_ordered(__m128i a, int la, \ + __m128i b, int lb) \ + { \ + __m128i mtx[16]; \ + PCMPSTR_EQ(a, b, mtx, SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type)); \ + return SSE2NEON_CAT( \ + _sse2neon_aggregate_equal_ordered_, \ + SSE2NEON_CAT( \ + SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(x, \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type))))( \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type), la, lb, mtx); \ + } + +static int _sse2neon_aggregate_equal_any_8x16(int la, int lb, __m128i mtx[16]) +{ + int res = 0; + int m = (1 << la) - 1; + uint8x8_t vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + uint8x8_t t_lo = vtst_u8(vdup_n_u8(m & 0xff), vec_mask); + uint8x8_t t_hi = vtst_u8(vdup_n_u8(m >> 8), vec_mask); + uint8x16_t vec = vcombine_u8(t_lo, t_hi); + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u8( + vandq_u8(vec, vreinterpretq_u8_m128i(mtx[j]))); + mtx[j] = vreinterpretq_m128i_u8( + vshrq_n_u8(vreinterpretq_u8_m128i(mtx[j]), 7)); + int tmp = _sse2neon_vaddvq_u8(vreinterpretq_u8_m128i(mtx[j])) ? 1 : 0; + res |= (tmp << j); + } + return res; +} + +static int _sse2neon_aggregate_equal_any_16x8(int la, int lb, __m128i mtx[16]) +{ + int res = 0; + int m = (1 << la) - 1; + uint16x8_t vec = + vtstq_u16(vdupq_n_u16(m), vld1q_u16(_sse2neon_cmpestr_mask16b)); + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u16( + vandq_u16(vec, vreinterpretq_u16_m128i(mtx[j]))); + mtx[j] = vreinterpretq_m128i_u16( + vshrq_n_u16(vreinterpretq_u16_m128i(mtx[j]), 15)); + int tmp = _sse2neon_vaddvq_u16(vreinterpretq_u16_m128i(mtx[j])) ? 1 : 0; + res |= (tmp << j); + } + return res; +} + +/* clang-format off */ +#define SSE2NEON_GENERATE_CMP_EQUAL_ANY(prefix) \ + prefix##IMPL(byte) \ + prefix##IMPL(word) +/* clang-format on */ + +SSE2NEON_GENERATE_CMP_EQUAL_ANY(SSE2NEON_CMP_EQUAL_ANY_) + +static int _sse2neon_aggregate_ranges_16x8(int la, int lb, __m128i mtx[16]) +{ + int res = 0; + int m = (1 << la) - 1; + uint16x8_t vec = + vtstq_u16(vdupq_n_u16(m), vld1q_u16(_sse2neon_cmpestr_mask16b)); + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u16( + vandq_u16(vec, vreinterpretq_u16_m128i(mtx[j]))); + mtx[j] = vreinterpretq_m128i_u16( + vshrq_n_u16(vreinterpretq_u16_m128i(mtx[j]), 15)); + __m128i tmp = vreinterpretq_m128i_u32( + vshrq_n_u32(vreinterpretq_u32_m128i(mtx[j]), 16)); + uint32x4_t vec_res = vandq_u32(vreinterpretq_u32_m128i(mtx[j]), + vreinterpretq_u32_m128i(tmp)); +#if defined(__aarch64__) + int t = vaddvq_u32(vec_res) ? 1 : 0; +#else + uint64x2_t sumh = vpaddlq_u32(vec_res); + int t = vgetq_lane_u64(sumh, 0) + vgetq_lane_u64(sumh, 1); +#endif + res |= (t << j); + } + return res; +} + +static int _sse2neon_aggregate_ranges_8x16(int la, int lb, __m128i mtx[16]) +{ + int res = 0; + int m = (1 << la) - 1; + uint8x8_t vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + uint8x8_t t_lo = vtst_u8(vdup_n_u8(m & 0xff), vec_mask); + uint8x8_t t_hi = vtst_u8(vdup_n_u8(m >> 8), vec_mask); + uint8x16_t vec = vcombine_u8(t_lo, t_hi); + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u8( + vandq_u8(vec, vreinterpretq_u8_m128i(mtx[j]))); + mtx[j] = vreinterpretq_m128i_u8( + vshrq_n_u8(vreinterpretq_u8_m128i(mtx[j]), 7)); + __m128i tmp = vreinterpretq_m128i_u16( + vshrq_n_u16(vreinterpretq_u16_m128i(mtx[j]), 8)); + uint16x8_t vec_res = vandq_u16(vreinterpretq_u16_m128i(mtx[j]), + vreinterpretq_u16_m128i(tmp)); + int t = _sse2neon_vaddvq_u16(vec_res) ? 1 : 0; + res |= (t << j); + } + return res; +} + +#define SSE2NEON_CMP_RANGES_IS_BYTE 1 +#define SSE2NEON_CMP_RANGES_IS_WORD 0 + +/* clang-format off */ +#define SSE2NEON_GENERATE_CMP_RANGES(prefix) \ + prefix##IMPL(byte, uint, u, prefix##IS_BYTE) \ + prefix##IMPL(byte, int, s, prefix##IS_BYTE) \ + prefix##IMPL(word, uint, u, prefix##IS_WORD) \ + prefix##IMPL(word, int, s, prefix##IS_WORD) +/* clang-format on */ + +SSE2NEON_GENERATE_CMP_RANGES(SSE2NEON_CMP_RANGES_) + +#undef SSE2NEON_CMP_RANGES_IS_BYTE +#undef SSE2NEON_CMP_RANGES_IS_WORD + +static int _sse2neon_cmp_byte_equal_each(__m128i a, int la, __m128i b, int lb) +{ + uint8x16_t mtx = + vceqq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b)); + int m0 = (la < lb) ? 0 : ((1 << la) - (1 << lb)); + int m1 = 0x10000 - (1 << la); + int tb = 0x10000 - (1 << lb); + uint8x8_t vec_mask, vec0_lo, vec0_hi, vec1_lo, vec1_hi; + uint8x8_t tmp_lo, tmp_hi, res_lo, res_hi; + vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + vec0_lo = vtst_u8(vdup_n_u8(m0), vec_mask); + vec0_hi = vtst_u8(vdup_n_u8(m0 >> 8), vec_mask); + vec1_lo = vtst_u8(vdup_n_u8(m1), vec_mask); + vec1_hi = vtst_u8(vdup_n_u8(m1 >> 8), vec_mask); + tmp_lo = vtst_u8(vdup_n_u8(tb), vec_mask); + tmp_hi = vtst_u8(vdup_n_u8(tb >> 8), vec_mask); + + res_lo = vbsl_u8(vec0_lo, vdup_n_u8(0), vget_low_u8(mtx)); + res_hi = vbsl_u8(vec0_hi, vdup_n_u8(0), vget_high_u8(mtx)); + res_lo = vbsl_u8(vec1_lo, tmp_lo, res_lo); + res_hi = vbsl_u8(vec1_hi, tmp_hi, res_hi); + res_lo = vand_u8(res_lo, vec_mask); + res_hi = vand_u8(res_hi, vec_mask); + + int res = _sse2neon_vaddv_u8(res_lo) + (_sse2neon_vaddv_u8(res_hi) << 8); + return res; +} + +static int _sse2neon_cmp_word_equal_each(__m128i a, int la, __m128i b, int lb) +{ + uint16x8_t mtx = + vceqq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b)); + int m0 = (la < lb) ? 0 : ((1 << la) - (1 << lb)); + int m1 = 0x100 - (1 << la); + int tb = 0x100 - (1 << lb); + uint16x8_t vec_mask = vld1q_u16(_sse2neon_cmpestr_mask16b); + uint16x8_t vec0 = vtstq_u16(vdupq_n_u16(m0), vec_mask); + uint16x8_t vec1 = vtstq_u16(vdupq_n_u16(m1), vec_mask); + uint16x8_t tmp = vtstq_u16(vdupq_n_u16(tb), vec_mask); + mtx = vbslq_u16(vec0, vdupq_n_u16(0), mtx); + mtx = vbslq_u16(vec1, tmp, mtx); + mtx = vandq_u16(mtx, vec_mask); + return _sse2neon_vaddvq_u16(mtx); +} + +#define SSE2NEON_AGGREGATE_EQUAL_ORDER_IS_UBYTE 1 +#define SSE2NEON_AGGREGATE_EQUAL_ORDER_IS_UWORD 0 + +#define SSE2NEON_AGGREGATE_EQUAL_ORDER_IMPL(size, number_of_lanes, data_type) \ + static int _sse2neon_aggregate_equal_ordered_##size##x##number_of_lanes( \ + int bound, int la, int lb, __m128i mtx[16]) \ + { \ + int res = 0; \ + int m1 = SSE2NEON_IIF(data_type)(0x10000, 0x100) - (1 << la); \ + uint##size##x8_t vec_mask = SSE2NEON_IIF(data_type)( \ + vld1_u##size(_sse2neon_cmpestr_mask##size##b), \ + vld1q_u##size(_sse2neon_cmpestr_mask##size##b)); \ + uint##size##x##number_of_lanes##_t vec1 = SSE2NEON_IIF(data_type)( \ + vcombine_u##size(vtst_u##size(vdup_n_u##size(m1), vec_mask), \ + vtst_u##size(vdup_n_u##size(m1 >> 8), vec_mask)), \ + vtstq_u##size(vdupq_n_u##size(m1), vec_mask)); \ + uint##size##x##number_of_lanes##_t vec_minusone = vdupq_n_u##size(-1); \ + uint##size##x##number_of_lanes##_t vec_zero = vdupq_n_u##size(0); \ + for (int j = 0; j < lb; j++) { \ + mtx[j] = vreinterpretq_m128i_u##size(vbslq_u##size( \ + vec1, vec_minusone, vreinterpretq_u##size##_m128i(mtx[j]))); \ + } \ + for (int j = lb; j < bound; j++) { \ + mtx[j] = vreinterpretq_m128i_u##size( \ + vbslq_u##size(vec1, vec_minusone, vec_zero)); \ + } \ + unsigned SSE2NEON_IIF(data_type)(char, short) *ptr = \ + (unsigned SSE2NEON_IIF(data_type)(char, short) *) mtx; \ + for (int i = 0; i < bound; i++) { \ + int val = 1; \ + for (int j = 0, k = i; j < bound - i && k < bound; j++, k++) \ + val &= ptr[k * bound + j]; \ + res += val << i; \ + } \ + return res; \ + } + +/* clang-format off */ +#define SSE2NEON_GENERATE_AGGREGATE_EQUAL_ORDER(prefix) \ + prefix##IMPL(8, 16, prefix##IS_UBYTE) \ + prefix##IMPL(16, 8, prefix##IS_UWORD) +/* clang-format on */ + +SSE2NEON_GENERATE_AGGREGATE_EQUAL_ORDER(SSE2NEON_AGGREGATE_EQUAL_ORDER_) + +#undef SSE2NEON_AGGREGATE_EQUAL_ORDER_IS_UBYTE +#undef SSE2NEON_AGGREGATE_EQUAL_ORDER_IS_UWORD + +/* clang-format off */ +#define SSE2NEON_GENERATE_CMP_EQUAL_ORDERED(prefix) \ + prefix##IMPL(byte) \ + prefix##IMPL(word) +/* clang-format on */ + +SSE2NEON_GENERATE_CMP_EQUAL_ORDERED(SSE2NEON_CMP_EQUAL_ORDERED_) + +#define SSE2NEON_CMPESTR_LIST \ + _(CMP_UBYTE_EQUAL_ANY, cmp_byte_equal_any) \ + _(CMP_UWORD_EQUAL_ANY, cmp_word_equal_any) \ + _(CMP_SBYTE_EQUAL_ANY, cmp_byte_equal_any) \ + _(CMP_SWORD_EQUAL_ANY, cmp_word_equal_any) \ + _(CMP_UBYTE_RANGES, cmp_ubyte_ranges) \ + _(CMP_UWORD_RANGES, cmp_uword_ranges) \ + _(CMP_SBYTE_RANGES, cmp_sbyte_ranges) \ + _(CMP_SWORD_RANGES, cmp_sword_ranges) \ + _(CMP_UBYTE_EQUAL_EACH, cmp_byte_equal_each) \ + _(CMP_UWORD_EQUAL_EACH, cmp_word_equal_each) \ + _(CMP_SBYTE_EQUAL_EACH, cmp_byte_equal_each) \ + _(CMP_SWORD_EQUAL_EACH, cmp_word_equal_each) \ + _(CMP_UBYTE_EQUAL_ORDERED, cmp_byte_equal_ordered) \ + _(CMP_UWORD_EQUAL_ORDERED, cmp_word_equal_ordered) \ + _(CMP_SBYTE_EQUAL_ORDERED, cmp_byte_equal_ordered) \ + _(CMP_SWORD_EQUAL_ORDERED, cmp_word_equal_ordered) + +enum { +#define _(name, func_suffix) name, + SSE2NEON_CMPESTR_LIST +#undef _ +}; +typedef int (*cmpestr_func_t)(__m128i a, int la, __m128i b, int lb); +static cmpestr_func_t _sse2neon_cmpfunc_table[] = { +#define _(name, func_suffix) _sse2neon_##func_suffix, + SSE2NEON_CMPESTR_LIST +#undef _ +}; + +FORCE_INLINE int _sse2neon_sido_negative(int res, int lb, int imm8, int bound) +{ + switch (imm8 & 0x30) { + case _SIDD_NEGATIVE_POLARITY: + res ^= 0xffffffff; + break; + case _SIDD_MASKED_NEGATIVE_POLARITY: + res ^= (1 << lb) - 1; + break; + default: + break; + } + + return res & ((bound == 8) ? 0xFF : 0xFFFF); +} + +FORCE_INLINE int _sse2neon_clz(unsigned int x) +{ +#if _MSC_VER + DWORD cnt = 0; + if (_BitScanForward(&cnt, x)) + return cnt; + return 32; +#else + return x != 0 ? __builtin_clz(x) : 32; +#endif +} + +FORCE_INLINE int _sse2neon_ctz(unsigned int x) +{ +#if _MSC_VER + DWORD cnt = 0; + if (_BitScanReverse(&cnt, x)) + return 31 - cnt; + return 32; +#else + return x != 0 ? __builtin_ctz(x) : 32; +#endif +} + +FORCE_INLINE int _sse2neon_ctzll(unsigned long long x) +{ +#if _MSC_VER + unsigned long cnt; +#ifdef defined(SSE2NEON_HAS_BITSCAN64) + (defined(_M_AMD64) || defined(__x86_64__)) + if((_BitScanForward64(&cnt, x)) + return (int)(cnt); +#else + if (_BitScanForward(&cnt, (unsigned long) (x))) + return (int) cnt; + if (_BitScanForward(&cnt, (unsigned long) (x >> 32))) + return (int) (cnt + 32); +#endif + return 64; +#else + return x != 0 ? __builtin_ctzll(x) : 64; +#endif +} + +#define SSE2NEON_MIN(x, y) (x) < (y) ? (x) : (y) + +#define SSE2NEON_CMPSTR_SET_UPPER(var, imm) \ + const int var = (imm & 0x01) ? 8 : 16 + +#define SSE2NEON_CMPESTRX_LEN_PAIR(a, b, la, lb) \ + int tmp1 = la ^ (la >> 31); \ + la = tmp1 - (la >> 31); \ + int tmp2 = lb ^ (lb >> 31); \ + lb = tmp2 - (lb >> 31); \ + la = SSE2NEON_MIN(la, bound); \ + lb = SSE2NEON_MIN(lb, bound) + +// Compare all pairs of character in string a and b, +// then aggregate the result. +// As the only difference of PCMPESTR* and PCMPISTR* is the way to calculate the +// length of string, we use SSE2NEON_CMP{I,E}STRX_GET_LEN to get the length of +// string a and b. +#define SSE2NEON_COMP_AGG(a, b, la, lb, imm8, IE) \ + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); \ + SSE2NEON_##IE##_LEN_PAIR(a, b, la, lb); \ + int r2 = (_sse2neon_cmpfunc_table[imm8 & 0x0f])(a, la, b, lb); \ + r2 = _sse2neon_sido_negative(r2, lb, imm8, bound) + +#define SSE2NEON_CMPSTR_GENERATE_INDEX(r2, bound, imm8) \ + return (r2 == 0) ? bound \ + : ((imm8 & 0x40) ? (31 - _sse2neon_clz(r2)) \ + : _sse2neon_ctz(r2)) + +#define SSE2NEON_CMPSTR_GENERATE_MASK(dst) \ + __m128i dst = vreinterpretq_m128i_u8(vdupq_n_u8(0)); \ + if (imm8 & 0x40) { \ + if (bound == 8) { \ + uint16x8_t tmp = vtstq_u16(vdupq_n_u16(r2), \ + vld1q_u16(_sse2neon_cmpestr_mask16b)); \ + dst = vreinterpretq_m128i_u16(vbslq_u16( \ + tmp, vdupq_n_u16(-1), vreinterpretq_u16_m128i(dst))); \ + } else { \ + uint8x16_t vec_r2 = \ + vcombine_u8(vdup_n_u8(r2), vdup_n_u8(r2 >> 8)); \ + uint8x16_t tmp = \ + vtstq_u8(vec_r2, vld1q_u8(_sse2neon_cmpestr_mask8b)); \ + dst = vreinterpretq_m128i_u8( \ + vbslq_u8(tmp, vdupq_n_u8(-1), vreinterpretq_u8_m128i(dst))); \ + } \ + } else { \ + if (bound == 16) { \ + dst = vreinterpretq_m128i_u16( \ + vsetq_lane_u16(r2 & 0xffff, vreinterpretq_u16_m128i(dst), 0)); \ + } else { \ + dst = vreinterpretq_m128i_u8( \ + vsetq_lane_u8(r2 & 0xff, vreinterpretq_u8_m128i(dst), 0)); \ + } \ + } \ + return dst + +// Compare packed strings in a and b with lengths la and lb using the control +// in imm8, and returns 1 if b did not contain a null character and the +// resulting mask was zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestra +FORCE_INLINE int _mm_cmpestra(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + int lb_cpy = lb; + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + return !r2 & (lb_cpy > bound); +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns 1 if the resulting mask was non-zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrc +FORCE_INLINE int _mm_cmpestrc(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + return r2 != 0; +} + +// Compare packed strings in a and b with lengths la and lb using the control +// in imm8, and store the generated index in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestri +FORCE_INLINE int _mm_cmpestri(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + SSE2NEON_CMPSTR_GENERATE_INDEX(r2, bound, imm8); +} + +// Compare packed strings in a and b with lengths la and lb using the control +// in imm8, and store the generated mask in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrm +FORCE_INLINE __m128i +_mm_cmpestrm(__m128i a, int la, __m128i b, int lb, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + SSE2NEON_CMPSTR_GENERATE_MASK(dst); +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns bit 0 of the resulting bit mask. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestro +FORCE_INLINE int _mm_cmpestro(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + return r2 & 1; +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns 1 if any character in a was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrs +FORCE_INLINE int _mm_cmpestrs(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + return la <= (bound - 1); +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns 1 if any character in b was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrz +FORCE_INLINE int _mm_cmpestrz(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + return lb <= (bound - 1); +} + +#define SSE2NEON_CMPISTRX_LENGTH(str, len, imm8) \ + do { \ + if (imm8 & 0x01) { \ + uint16x8_t equal_mask_##str = \ + vceqq_u16(vreinterpretq_u16_m128i(str), vdupq_n_u16(0)); \ + uint8x8_t res_##str = vshrn_n_u16(equal_mask_##str, 4); \ + uint64_t matches_##str = \ + vget_lane_u64(vreinterpret_u64_u8(res_##str), 0); \ + len = _sse2neon_ctzll(matches_##str) >> 3; \ + } else { \ + uint16x8_t equal_mask_##str = vreinterpretq_u16_u8( \ + vceqq_u8(vreinterpretq_u8_m128i(str), vdupq_n_u8(0))); \ + uint8x8_t res_##str = vshrn_n_u16(equal_mask_##str, 4); \ + uint64_t matches_##str = \ + vget_lane_u64(vreinterpret_u64_u8(res_##str), 0); \ + len = _sse2neon_ctzll(matches_##str) >> 2; \ + } \ + } while (0) + +#define SSE2NEON_CMPISTRX_LEN_PAIR(a, b, la, lb) \ + int la, lb; \ + do { \ + SSE2NEON_CMPISTRX_LENGTH(a, la, imm8); \ + SSE2NEON_CMPISTRX_LENGTH(b, lb, imm8); \ + } while (0) + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if b did not contain a null character and the resulting +// mask was zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistra +FORCE_INLINE int _mm_cmpistra(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + return !r2 & (lb >= bound); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if the resulting mask was non-zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrc +FORCE_INLINE int _mm_cmpistrc(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + return r2 != 0; +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and store the generated index in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistri +FORCE_INLINE int _mm_cmpistri(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + SSE2NEON_CMPSTR_GENERATE_INDEX(r2, bound, imm8); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and store the generated mask in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrm +FORCE_INLINE __m128i _mm_cmpistrm(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + SSE2NEON_CMPSTR_GENERATE_MASK(dst); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns bit 0 of the resulting bit mask. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistro +FORCE_INLINE int _mm_cmpistro(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + return r2 & 1; +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if any character in a was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrs +FORCE_INLINE int _mm_cmpistrs(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + int la; + SSE2NEON_CMPISTRX_LENGTH(a, la, imm8); + return la <= (bound - 1); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if any character in b was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrz +FORCE_INLINE int _mm_cmpistrz(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + int lb; + SSE2NEON_CMPISTRX_LENGTH(b, lb, imm8); + return lb <= (bound - 1); +} + // Compares the 2 signed 64-bit integers in a and the 2 signed 64-bit integers // in b for greater than. FORCE_INLINE __m128i _mm_cmpgt_epi64(__m128i a, __m128i b) @@ -8320,6 +9342,8 @@ FORCE_INLINE uint32_t _mm_crc32_u16(uint32_t crc, uint16_t v) __asm__ __volatile__("crc32ch %w[c], %w[c], %w[v]\n\t" : [c] "+r"(crc) : [v] "r"(v)); +#elif (__ARM_ARCH == 8) && defined(__ARM_FEATURE_CRC32) + crc = __crc32ch(crc, v); #else crc = _mm_crc32_u8(crc, v & 0xff); crc = _mm_crc32_u8(crc, (v >> 8) & 0xff); @@ -8336,6 +9360,8 @@ FORCE_INLINE uint32_t _mm_crc32_u32(uint32_t crc, uint32_t v) __asm__ __volatile__("crc32cw %w[c], %w[c], %w[v]\n\t" : [c] "+r"(crc) : [v] "r"(v)); +#elif (__ARM_ARCH == 8) && defined(__ARM_FEATURE_CRC32) + crc = __crc32cw(crc, v); #else crc = _mm_crc32_u16(crc, v & 0xffff); crc = _mm_crc32_u16(crc, (v >> 16) & 0xffff); @@ -8353,8 +9379,8 @@ FORCE_INLINE uint64_t _mm_crc32_u64(uint64_t crc, uint64_t v) : [c] "+r"(crc) : [v] "r"(v)); #else - crc = _mm_crc32_u32((uint32_t)(crc), v & 0xffffffff); - crc = _mm_crc32_u32((uint32_t)(crc), (v >> 32) & 0xffffffff); + crc = _mm_crc32_u32((uint32_t) (crc), v & 0xffffffff); + crc = _mm_crc32_u32((uint32_t) (crc), (v >> 32) & 0xffffffff); #endif return crc; } @@ -8368,6 +9394,8 @@ FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v) __asm__ __volatile__("crc32cb %w[c], %w[c], %w[v]\n\t" : [c] "+r"(crc) : [v] "r"(v)); +#elif (__ARM_ARCH == 8) && defined(__ARM_FEATURE_CRC32) + crc = __crc32cb(crc, v); #else crc ^= v; for (int bit = 0; bit < 8; bit++) { @@ -8384,7 +9412,7 @@ FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v) #if !defined(__ARM_FEATURE_CRYPTO) /* clang-format off */ -#define SSE2NEON_AES_DATA(w) \ +#define SSE2NEON_AES_SBOX(w) \ { \ w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), \ w(0xc5), w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), \ @@ -8424,53 +9452,115 @@ FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v) w(0xe6), w(0x42), w(0x68), w(0x41), w(0x99), w(0x2d), w(0x0f), \ w(0xb0), w(0x54), w(0xbb), w(0x16) \ } +#define SSE2NEON_AES_RSBOX(w) \ + { \ + w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), \ + w(0x38), w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), \ + w(0xd7), w(0xfb), w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), \ + w(0x2f), w(0xff), w(0x87), w(0x34), w(0x8e), w(0x43), w(0x44), \ + w(0xc4), w(0xde), w(0xe9), w(0xcb), w(0x54), w(0x7b), w(0x94), \ + w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d), w(0xee), w(0x4c), \ + w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e), w(0x08), \ + w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2), \ + w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), \ + w(0x25), w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), \ + w(0x98), w(0x16), w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), \ + w(0x65), w(0xb6), w(0x92), w(0x6c), w(0x70), w(0x48), w(0x50), \ + w(0xfd), w(0xed), w(0xb9), w(0xda), w(0x5e), w(0x15), w(0x46), \ + w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84), w(0x90), w(0xd8), \ + w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a), w(0xf7), \ + w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06), \ + w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), \ + w(0x02), w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), \ + w(0x8a), w(0x6b), w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), \ + w(0x67), w(0xdc), w(0xea), w(0x97), w(0xf2), w(0xcf), w(0xce), \ + w(0xf0), w(0xb4), w(0xe6), w(0x73), w(0x96), w(0xac), w(0x74), \ + w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85), w(0xe2), w(0xf9), \ + w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e), w(0x47), \ + w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89), \ + w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), \ + w(0x1b), w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), \ + w(0x79), w(0x20), w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), \ + w(0xcd), w(0x5a), w(0xf4), w(0x1f), w(0xdd), w(0xa8), w(0x33), \ + w(0x88), w(0x07), w(0xc7), w(0x31), w(0xb1), w(0x12), w(0x10), \ + w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f), w(0x60), w(0x51), \ + w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d), w(0x2d), \ + w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef), \ + w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), \ + w(0xb0), w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), \ + w(0x99), w(0x61), w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), \ + w(0x77), w(0xd6), w(0x26), w(0xe1), w(0x69), w(0x14), w(0x63), \ + w(0x55), w(0x21), w(0x0c), w(0x7d) \ + } /* clang-format on */ /* X Macro trick. See https://en.wikipedia.org/wiki/X_Macro */ #define SSE2NEON_AES_H0(x) (x) -static const uint8_t SSE2NEON_sbox[256] = SSE2NEON_AES_DATA(SSE2NEON_AES_H0); +static const uint8_t _sse2neon_sbox[256] = SSE2NEON_AES_SBOX(SSE2NEON_AES_H0); +static const uint8_t _sse2neon_rsbox[256] = SSE2NEON_AES_RSBOX(SSE2NEON_AES_H0); #undef SSE2NEON_AES_H0 +/* x_time function and matrix multiply function */ +#if !defined(__aarch64__) +#define SSE2NEON_XT(x) (((x) << 1) ^ ((((x) >> 7) & 1) * 0x1b)) +#define SSE2NEON_MULTIPLY(x, y) \ + (((y & 1) * x) ^ ((y >> 1 & 1) * SSE2NEON_XT(x)) ^ \ + ((y >> 2 & 1) * SSE2NEON_XT(SSE2NEON_XT(x))) ^ \ + ((y >> 3 & 1) * SSE2NEON_XT(SSE2NEON_XT(SSE2NEON_XT(x)))) ^ \ + ((y >> 4 & 1) * SSE2NEON_XT(SSE2NEON_XT(SSE2NEON_XT(SSE2NEON_XT(x)))))) +#endif + // In the absence of crypto extensions, implement aesenc using regular neon // intrinsics instead. See: // https://www.workofard.com/2017/01/accelerated-aes-for-the-arm64-linux-kernel/ // https://www.workofard.com/2017/07/ghash-for-low-end-cores/ and // https://github.com/ColinIanKing/linux-next-mirror/blob/b5f466091e130caaf0735976648f72bd5e09aa84/crypto/aegis128-neon-inner.c#L52 // for more information Reproduced with permission of the author. -FORCE_INLINE __m128i _mm_aesenc_si128(__m128i EncBlock, __m128i RoundKey) +FORCE_INLINE __m128i _mm_aesenc_si128(__m128i a, __m128i RoundKey) { #if defined(__aarch64__) - static const uint8_t shift_rows[] = {0x0, 0x5, 0xa, 0xf, 0x4, 0x9, - 0xe, 0x3, 0x8, 0xd, 0x2, 0x7, - 0xc, 0x1, 0x6, 0xb}; - static const uint8_t ror32by8[] = {0x1, 0x2, 0x3, 0x0, 0x5, 0x6, 0x7, 0x4, - 0x9, 0xa, 0xb, 0x8, 0xd, 0xe, 0xf, 0xc}; + static const uint8_t shift_rows[] = { + 0x0, 0x5, 0xa, 0xf, 0x4, 0x9, 0xe, 0x3, + 0x8, 0xd, 0x2, 0x7, 0xc, 0x1, 0x6, 0xb, + }; + static const uint8_t ror32by8[] = { + 0x1, 0x2, 0x3, 0x0, 0x5, 0x6, 0x7, 0x4, + 0x9, 0xa, 0xb, 0x8, 0xd, 0xe, 0xf, 0xc, + }; uint8x16_t v; - uint8x16_t w = vreinterpretq_u8_m128i(EncBlock); + uint8x16_t w = vreinterpretq_u8_m128i(a); - // shift rows + /* shift rows */ w = vqtbl1q_u8(w, vld1q_u8(shift_rows)); - // sub bytes - v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(SSE2NEON_sbox), w); - v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(SSE2NEON_sbox + 0x40), w - 0x40); - v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(SSE2NEON_sbox + 0x80), w - 0x80); - v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(SSE2NEON_sbox + 0xc0), w - 0xc0); + /* sub bytes */ + // Here, we separate the whole 256-bytes table into 4 64-bytes tables, and + // look up each of the table. After each lookup, we load the next table + // which locates at the next 64-bytes. In the meantime, the index in the + // table would be smaller than it was, so the index parameters of + // `vqtbx4q_u8()` need to be added the same constant as the loaded tables. + v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_sbox), w); + // 'w-0x40' equals to 'vsubq_u8(w, vdupq_n_u8(0x40))' + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x40), w - 0x40); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x80), w - 0x80); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0xc0), w - 0xc0); - // mix columns - w = (v << 1) ^ (uint8x16_t)(((int8x16_t) v >> 7) & 0x1b); + /* mix columns */ + w = (v << 1) ^ (uint8x16_t) (((int8x16_t) v >> 7) & 0x1b); w ^= (uint8x16_t) vrev32q_u16((uint16x8_t) v); w ^= vqtbl1q_u8(v ^ w, vld1q_u8(ror32by8)); - // add round key + /* add round key */ return vreinterpretq_m128i_u8(w) ^ RoundKey; -#else /* ARMv7-A NEON implementation */ -#define SSE2NEON_AES_B2W(b0, b1, b2, b3) \ - (((uint32_t)(b3) << 24) | ((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | \ - (b0)) +#else /* ARMv7-A implementation for a table-based AES */ +#define SSE2NEON_AES_B2W(b0, b1, b2, b3) \ + (((uint32_t) (b3) << 24) | ((uint32_t) (b2) << 16) | \ + ((uint32_t) (b1) << 8) | (uint32_t) (b0)) +// muliplying 'x' by 2 in GF(2^8) #define SSE2NEON_AES_F2(x) ((x << 1) ^ (((x >> 7) & 1) * 0x011b /* WPOLY */)) +// muliplying 'x' by 3 in GF(2^8) #define SSE2NEON_AES_F3(x) (SSE2NEON_AES_F2(x) ^ x) #define SSE2NEON_AES_U0(p) \ SSE2NEON_AES_B2W(SSE2NEON_AES_F2(p), p, p, SSE2NEON_AES_F3(p)) @@ -8480,11 +9570,14 @@ FORCE_INLINE __m128i _mm_aesenc_si128(__m128i EncBlock, __m128i RoundKey) SSE2NEON_AES_B2W(p, SSE2NEON_AES_F3(p), SSE2NEON_AES_F2(p), p) #define SSE2NEON_AES_U3(p) \ SSE2NEON_AES_B2W(p, p, SSE2NEON_AES_F3(p), SSE2NEON_AES_F2(p)) + + // this generates a table containing every possible permutation of + // shift_rows() and sub_bytes() with mix_columns(). static const uint32_t ALIGN_STRUCT(16) aes_table[4][256] = { - SSE2NEON_AES_DATA(SSE2NEON_AES_U0), - SSE2NEON_AES_DATA(SSE2NEON_AES_U1), - SSE2NEON_AES_DATA(SSE2NEON_AES_U2), - SSE2NEON_AES_DATA(SSE2NEON_AES_U3), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U0), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U1), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U2), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U3), }; #undef SSE2NEON_AES_B2W #undef SSE2NEON_AES_F2 @@ -8494,11 +9587,15 @@ FORCE_INLINE __m128i _mm_aesenc_si128(__m128i EncBlock, __m128i RoundKey) #undef SSE2NEON_AES_U2 #undef SSE2NEON_AES_U3 - uint32_t x0 = _mm_cvtsi128_si32(EncBlock); - uint32_t x1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(EncBlock, 0x55)); - uint32_t x2 = _mm_cvtsi128_si32(_mm_shuffle_epi32(EncBlock, 0xAA)); - uint32_t x3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(EncBlock, 0xFF)); + uint32_t x0 = _mm_cvtsi128_si32(a); // get a[31:0] + uint32_t x1 = + _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0x55)); // get a[63:32] + uint32_t x2 = + _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xAA)); // get a[95:64] + uint32_t x3 = + _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xFF)); // get a[127:96] + // finish the modulo addition step in mix_columns() __m128i out = _mm_set_epi32( (aes_table[0][x3 & 0xff] ^ aes_table[1][(x0 >> 8) & 0xff] ^ aes_table[2][(x1 >> 16) & 0xff] ^ aes_table[3][x2 >> 24]), @@ -8513,34 +9610,210 @@ FORCE_INLINE __m128i _mm_aesenc_si128(__m128i EncBlock, __m128i RoundKey) #endif } +// Perform one round of an AES decryption flow on data (state) in a using the +// round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdec_si128 +FORCE_INLINE __m128i _mm_aesdec_si128(__m128i a, __m128i RoundKey) +{ +#if defined(__aarch64__) + static const uint8_t inv_shift_rows[] = { + 0x0, 0xd, 0xa, 0x7, 0x4, 0x1, 0xe, 0xb, + 0x8, 0x5, 0x2, 0xf, 0xc, 0x9, 0x6, 0x3, + }; + static const uint8_t ror32by8[] = { + 0x1, 0x2, 0x3, 0x0, 0x5, 0x6, 0x7, 0x4, + 0x9, 0xa, 0xb, 0x8, 0xd, 0xe, 0xf, 0xc, + }; + + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + // inverse shift rows + w = vqtbl1q_u8(w, vld1q_u8(inv_shift_rows)); + + // inverse sub bytes + v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_rsbox), w); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0x40), w - 0x40); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0x80), w - 0x80); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0xc0), w - 0xc0); + + // inverse mix columns + // muliplying 'v' by 4 in GF(2^8) + w = (v << 1) ^ (uint8x16_t) (((int8x16_t) v >> 7) & 0x1b); + w = (w << 1) ^ (uint8x16_t) (((int8x16_t) w >> 7) & 0x1b); + v ^= w; + v ^= (uint8x16_t) vrev32q_u16((uint16x8_t) w); + + w = (v << 1) ^ (uint8x16_t) (((int8x16_t) v >> 7) & + 0x1b); // muliplying 'v' by 2 in GF(2^8) + w ^= (uint8x16_t) vrev32q_u16((uint16x8_t) v); + w ^= vqtbl1q_u8(v ^ w, vld1q_u8(ror32by8)); + + // add round key + return vreinterpretq_m128i_u8(w) ^ RoundKey; + +#else /* ARMv7-A NEON implementation */ + /* FIXME: optimized for NEON */ + uint8_t i, e, f, g, h, v[4][4]; + uint8_t *_a = (uint8_t *) &a; + for (i = 0; i < 16; ++i) { + v[((i / 4) + (i % 4)) % 4][i % 4] = _sse2neon_rsbox[_a[i]]; + } + + // inverse mix columns + for (i = 0; i < 4; ++i) { + e = v[i][0]; + f = v[i][1]; + g = v[i][2]; + h = v[i][3]; + + v[i][0] = SSE2NEON_MULTIPLY(e, 0x0e) ^ SSE2NEON_MULTIPLY(f, 0x0b) ^ + SSE2NEON_MULTIPLY(g, 0x0d) ^ SSE2NEON_MULTIPLY(h, 0x09); + v[i][1] = SSE2NEON_MULTIPLY(e, 0x09) ^ SSE2NEON_MULTIPLY(f, 0x0e) ^ + SSE2NEON_MULTIPLY(g, 0x0b) ^ SSE2NEON_MULTIPLY(h, 0x0d); + v[i][2] = SSE2NEON_MULTIPLY(e, 0x0d) ^ SSE2NEON_MULTIPLY(f, 0x09) ^ + SSE2NEON_MULTIPLY(g, 0x0e) ^ SSE2NEON_MULTIPLY(h, 0x0b); + v[i][3] = SSE2NEON_MULTIPLY(e, 0x0b) ^ SSE2NEON_MULTIPLY(f, 0x0d) ^ + SSE2NEON_MULTIPLY(g, 0x09) ^ SSE2NEON_MULTIPLY(h, 0x0e); + } + + return vreinterpretq_m128i_u8(vld1q_u8((uint8_t *) v)) ^ RoundKey; +#endif +} + // Perform the last round of an AES encryption flow on data (state) in a using // the round key in RoundKey, and store the result in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_aesenclast_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenclast_si128 FORCE_INLINE __m128i _mm_aesenclast_si128(__m128i a, __m128i RoundKey) { - /* FIXME: optimized for NEON */ - uint8_t v[4][4] = { - {SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 0)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 5)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 10)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 15)]}, - {SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 4)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 9)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 14)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 3)]}, - {SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 8)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 13)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 2)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 7)]}, - {SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 12)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 1)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 6)], - SSE2NEON_sbox[vreinterpretq_nth_u8_m128i(a, 11)]}, +#if defined(__aarch64__) + static const uint8_t shift_rows[] = { + 0x0, 0x5, 0xa, 0xf, 0x4, 0x9, 0xe, 0x3, + 0x8, 0xd, 0x2, 0x7, 0xc, 0x1, 0x6, 0xb, }; - for (int i = 0; i < 16; i++) - vreinterpretq_nth_u8_m128i(a, i) = - v[i / 4][i % 4] ^ vreinterpretq_nth_u8_m128i(RoundKey, i); - return a; + + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + // shift rows + w = vqtbl1q_u8(w, vld1q_u8(shift_rows)); + + // sub bytes + v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_sbox), w); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x40), w - 0x40); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x80), w - 0x80); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0xc0), w - 0xc0); + + // add round key + return vreinterpretq_m128i_u8(v) ^ RoundKey; + +#else /* ARMv7-A implementation */ + uint8_t v[16] = { + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 0)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 5)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 10)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 15)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 4)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 9)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 14)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 3)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 8)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 13)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 2)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 7)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 12)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 1)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 6)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 11)], + }; + + return vreinterpretq_m128i_u8(vld1q_u8(v)) ^ RoundKey; +#endif +} + +// Perform the last round of an AES decryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdeclast_si128 +FORCE_INLINE __m128i _mm_aesdeclast_si128(__m128i a, __m128i RoundKey) +{ +#if defined(__aarch64__) + static const uint8_t inv_shift_rows[] = { + 0x0, 0xd, 0xa, 0x7, 0x4, 0x1, 0xe, 0xb, + 0x8, 0x5, 0x2, 0xf, 0xc, 0x9, 0x6, 0x3, + }; + + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + // inverse shift rows + w = vqtbl1q_u8(w, vld1q_u8(inv_shift_rows)); + + // inverse sub bytes + v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_rsbox), w); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0x40), w - 0x40); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0x80), w - 0x80); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0xc0), w - 0xc0); + + // add round key + return vreinterpretq_m128i_u8(v) ^ RoundKey; + +#else /* ARMv7-A NEON implementation */ + /* FIXME: optimized for NEON */ + uint8_t v[4][4]; + uint8_t *_a = (uint8_t *) &a; + for (int i = 0; i < 16; ++i) { + v[((i / 4) + (i % 4)) % 4][i % 4] = _sse2neon_rsbox[_a[i]]; + } + + return vreinterpretq_m128i_u8(vld1q_u8((uint8_t *) v)) ^ RoundKey; +#endif +} + +// Perform the InvMixColumns transformation on a and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesimc_si128 +FORCE_INLINE __m128i _mm_aesimc_si128(__m128i a) +{ +#if defined(__aarch64__) + static const uint8_t ror32by8[] = { + 0x1, 0x2, 0x3, 0x0, 0x5, 0x6, 0x7, 0x4, + 0x9, 0xa, 0xb, 0x8, 0xd, 0xe, 0xf, 0xc, + }; + uint8x16_t v = vreinterpretq_u8_m128i(a); + uint8x16_t w; + + // multiplying 'v' by 4 in GF(2^8) + w = (v << 1) ^ (uint8x16_t) (((int8x16_t) v >> 7) & 0x1b); + w = (w << 1) ^ (uint8x16_t) (((int8x16_t) w >> 7) & 0x1b); + v ^= w; + v ^= (uint8x16_t) vrev32q_u16((uint16x8_t) w); + + // multiplying 'v' by 2 in GF(2^8) + w = (v << 1) ^ (uint8x16_t) (((int8x16_t) v >> 7) & 0x1b); + w ^= (uint8x16_t) vrev32q_u16((uint16x8_t) v); + w ^= vqtbl1q_u8(v ^ w, vld1q_u8(ror32by8)); + return vreinterpretq_m128i_u8(w); + +#else /* ARMv7-A NEON implementation */ + uint8_t i, e, f, g, h, v[4][4]; + vst1q_u8((uint8_t *) v, vreinterpretq_u8_m128i(a)); + for (i = 0; i < 4; ++i) { + e = v[i][0]; + f = v[i][1]; + g = v[i][2]; + h = v[i][3]; + + v[i][0] = SSE2NEON_MULTIPLY(e, 0x0e) ^ SSE2NEON_MULTIPLY(f, 0x0b) ^ + SSE2NEON_MULTIPLY(g, 0x0d) ^ SSE2NEON_MULTIPLY(h, 0x09); + v[i][1] = SSE2NEON_MULTIPLY(e, 0x09) ^ SSE2NEON_MULTIPLY(f, 0x0e) ^ + SSE2NEON_MULTIPLY(g, 0x0b) ^ SSE2NEON_MULTIPLY(h, 0x0d); + v[i][2] = SSE2NEON_MULTIPLY(e, 0x0d) ^ SSE2NEON_MULTIPLY(f, 0x09) ^ + SSE2NEON_MULTIPLY(g, 0x0e) ^ SSE2NEON_MULTIPLY(h, 0x0b); + v[i][3] = SSE2NEON_MULTIPLY(e, 0x0b) ^ SSE2NEON_MULTIPLY(f, 0x0d) ^ + SSE2NEON_MULTIPLY(g, 0x09) ^ SSE2NEON_MULTIPLY(h, 0x0e); + } + + return vreinterpretq_m128i_u8(vld1q_u8((uint8_t *) v)); +#endif } // Emits the Advanced Encryption Standard (AES) instruction aeskeygenassist. @@ -8548,19 +9821,43 @@ FORCE_INLINE __m128i _mm_aesenclast_si128(__m128i a, __m128i RoundKey) // https://kazakov.life/2017/11/01/cryptocurrency-mining-on-ios-devices/ // for details. // -// https://msdn.microsoft.com/en-us/library/cc714138(v=vs.120).aspx -FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i key, const int rcon) +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aeskeygenassist_si128 +FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i a, const int rcon) { - uint32_t X1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(key, 0x55)); - uint32_t X3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(key, 0xFF)); +#if defined(__aarch64__) + uint8x16_t _a = vreinterpretq_u8_m128i(a); + uint8x16_t v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_sbox), _a); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x40), _a - 0x40); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x80), _a - 0x80); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0xc0), _a - 0xc0); + + uint32x4_t select_mask = {0xffffffff, 0x0, 0xffffffff, 0x0}; + uint64x2_t v_mask = vshrq_n_u64(vreinterpretq_u64_u8(v), 32); + uint32x4_t x = vbslq_u32(select_mask, vreinterpretq_u32_u64(v_mask), + vreinterpretq_u32_u8(v)); + uint32x4_t ror_x = vorrq_u32(vshrq_n_u32(x, 8), vshlq_n_u32(x, 24)); + uint32x4_t ror_xor_x = veorq_u32(ror_x, vdupq_n_u32(rcon)); + + return vreinterpretq_m128i_u32(vbslq_u32(select_mask, x, ror_xor_x)); + +#else /* ARMv7-A NEON implementation */ + uint32_t X1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0x55)); + uint32_t X3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xFF)); for (int i = 0; i < 4; ++i) { - ((uint8_t *) &X1)[i] = SSE2NEON_sbox[((uint8_t *) &X1)[i]]; - ((uint8_t *) &X3)[i] = SSE2NEON_sbox[((uint8_t *) &X3)[i]]; + ((uint8_t *) &X1)[i] = _sse2neon_sbox[((uint8_t *) &X1)[i]]; + ((uint8_t *) &X3)[i] = _sse2neon_sbox[((uint8_t *) &X3)[i]]; } return _mm_set_epi32(((X3 >> 8) | (X3 << 24)) ^ rcon, X3, ((X1 >> 8) | (X1 << 24)) ^ rcon, X1); +#endif } -#undef SSE2NEON_AES_DATA +#undef SSE2NEON_AES_SBOX +#undef SSE2NEON_AES_RSBOX + +#if defined(__aarch64__) +#undef SSE2NEON_XT +#undef SSE2NEON_MULTIPLY +#endif #else /* __ARM_FEATURE_CRYPTO */ // Implements equivalent of 'aesenc' by combining AESE (with an empty key) and @@ -8576,7 +9873,19 @@ FORCE_INLINE __m128i _mm_aesenc_si128(__m128i a, __m128i b) vreinterpretq_u8_m128i(b)); } -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_aesenclast_si128 +// Perform one round of an AES decryption flow on data (state) in a using the +// round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdec_si128 +FORCE_INLINE __m128i _mm_aesdec_si128(__m128i a, __m128i RoundKey) +{ + return vreinterpretq_m128i_u8(veorq_u8( + vaesimcq_u8(vaesdq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0))), + vreinterpretq_u8_m128i(RoundKey))); +} + +// Perform the last round of an AES encryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenclast_si128 FORCE_INLINE __m128i _mm_aesenclast_si128(__m128i a, __m128i RoundKey) { return _mm_xor_si128(vreinterpretq_m128i_u8(vaeseq_u8( @@ -8584,6 +9893,27 @@ FORCE_INLINE __m128i _mm_aesenclast_si128(__m128i a, __m128i RoundKey) RoundKey); } +// Perform the last round of an AES decryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdeclast_si128 +FORCE_INLINE __m128i _mm_aesdeclast_si128(__m128i a, __m128i RoundKey) +{ + return vreinterpretq_m128i_u8( + vaesdq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0))) ^ + vreinterpretq_u8_m128i(RoundKey); +} + +// Perform the InvMixColumns transformation on a and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesimc_si128 +FORCE_INLINE __m128i _mm_aesimc_si128(__m128i a) +{ + return vreinterpretq_m128i_u8(vaesimcq_u8(a)); +} + +// Assist in expanding the AES cipher key by computing steps towards generating +// a round key for encryption cipher using data from a and an 8-bit round +// constant specified in imm8, and store the result in dst." +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aeskeygenassist_si128 FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i a, const int rcon) { // AESE does ShiftRows and SubBytes on A @@ -8605,7 +9935,7 @@ FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i a, const int rcon) // Perform a carry-less multiplication of two 64-bit integers, selected from a // and b according to imm8, and store the results in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_clmulepi64_si128 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_clmulepi64_si128 FORCE_INLINE __m128i _mm_clmulepi64_si128(__m128i _a, __m128i _b, const int imm) { uint64x2_t a = vreinterpretq_u64_m128i(_a); @@ -8640,9 +9970,9 @@ FORCE_INLINE unsigned int _sse2neon_mm_get_denormals_zero_mode() } r; #if defined(__aarch64__) - asm volatile("mrs %0, FPCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value)); /* read */ #else - asm volatile("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ #endif return r.field.bit24 ? _MM_DENORMALS_ZERO_ON : _MM_DENORMALS_ZERO_OFF; @@ -8650,7 +9980,7 @@ FORCE_INLINE unsigned int _sse2neon_mm_get_denormals_zero_mode() // Count the number of bits set to 1 in unsigned 32-bit integer a, and // return that count in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_popcnt_u32 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_popcnt_u32 FORCE_INLINE int _mm_popcnt_u32(unsigned int a) { #if defined(__aarch64__) @@ -8677,7 +10007,7 @@ FORCE_INLINE int _mm_popcnt_u32(unsigned int a) // Count the number of bits set to 1 in unsigned 64-bit integer a, and // return that count in dst. -// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_popcnt_u64 +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_popcnt_u64 FORCE_INLINE int64_t _mm_popcnt_u64(uint64_t a) { #if defined(__aarch64__) @@ -8717,17 +10047,55 @@ FORCE_INLINE void _sse2neon_mm_set_denormals_zero_mode(unsigned int flag) } r; #if defined(__aarch64__) - asm volatile("mrs %0, FPCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value)); /* read */ #else - asm volatile("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ #endif r.field.bit24 = (flag & _MM_DENORMALS_ZERO_MASK) == _MM_DENORMALS_ZERO_ON; #if defined(__aarch64__) - asm volatile("msr FPCR, %0" ::"r"(r)); /* write */ + __asm__ __volatile__("msr FPCR, %0" ::"r"(r)); /* write */ #else - asm volatile("vmsr FPSCR, %0" ::"r"(r)); /* write */ + __asm__ __volatile__("vmsr FPSCR, %0" ::"r"(r)); /* write */ +#endif +} + +// Return the current 64-bit value of the processor's time-stamp counter. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=rdtsc + +FORCE_INLINE uint64_t _rdtsc(void) +{ +#if defined(__aarch64__) + uint64_t val; + + /* According to ARM DDI 0487F.c, from Armv8.0 to Armv8.5 inclusive, the + * system counter is at least 56 bits wide; from Armv8.6, the counter + * must be 64 bits wide. So the system counter could be less than 64 + * bits wide and it is attributed with the flag 'cap_user_time_short' + * is true. + */ + __asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(val)); + + return val; +#else + uint32_t pmccntr, pmuseren, pmcntenset; + // Read the user mode Performance Monitoring Unit (PMU) + // User Enable Register (PMUSERENR) access permissions. + __asm__ __volatile__("mrc p15, 0, %0, c9, c14, 0" : "=r"(pmuseren)); + if (pmuseren & 1) { // Allows reading PMUSERENR for user mode code. + __asm__ __volatile__("mrc p15, 0, %0, c9, c12, 1" : "=r"(pmcntenset)); + if (pmcntenset & 0x80000000UL) { // Is it counting? + __asm__ __volatile__("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr)); + // The counter is set up to count every 64th cycle + return (uint64_t) (pmccntr) << 6; + } + } + + // Fallback to syscall as we can't enable PMUSERENR in user mode. + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint64_t) (tv.tv_sec) * 1000000 + tv.tv_usec; #endif } @@ -8740,4 +10108,4 @@ FORCE_INLINE void _sse2neon_mm_set_denormals_zero_mode(unsigned int flag) #pragma GCC pop_options #endif -#endif \ No newline at end of file +#endif diff --git a/thirdparty/embree/common/simd/avx.h b/thirdparty/embree/common/simd/avx.h index d3100306ee1..7c63749f565 100644 --- a/thirdparty/embree/common/simd/avx.h +++ b/thirdparty/embree/common/simd/avx.h @@ -31,4 +31,3 @@ #if defined(__AVX512F__) #include "avx512.h" #endif - diff --git a/thirdparty/embree/common/simd/simd.h b/thirdparty/embree/common/simd/simd.h index 34e37b08b1b..e777d2df018 100644 --- a/thirdparty/embree/common/simd/simd.h +++ b/thirdparty/embree/common/simd/simd.h @@ -3,7 +3,7 @@ #pragma once -#include "../math/math.h" +#include "../math/emath.h" /* include SSE wrapper classes */ #if defined(__SSE__) || defined(__ARM_NEON) diff --git a/thirdparty/embree/common/simd/varying.h b/thirdparty/embree/common/simd/varying.h index 9b98d326be5..20fd3cac483 100644 --- a/thirdparty/embree/common/simd/varying.h +++ b/thirdparty/embree/common/simd/varying.h @@ -15,7 +15,7 @@ namespace embree __forceinline const float& operator [](size_t index) const { assert(index < N); return f[index]; } __forceinline float& operator [](size_t index) { assert(index < N); return f[index]; } }; - + template struct vdouble_impl { @@ -31,7 +31,7 @@ namespace embree __forceinline const int& operator [](size_t index) const { assert(index < N); return i[index]; } __forceinline int& operator [](size_t index) { assert(index < N); return i[index]; } }; - + template struct vuint_impl { diff --git a/thirdparty/embree/common/simd/vboolf4_sse2.h b/thirdparty/embree/common/simd/vboolf4_sse2.h index 9e0fdf5c6f6..e96525c9a7f 100644 --- a/thirdparty/embree/common/simd/vboolf4_sse2.h +++ b/thirdparty/embree/common/simd/vboolf4_sse2.h @@ -119,7 +119,7 @@ namespace embree #if defined(__aarch64__) template __forceinline vboolf4 shuffle(const vboolf4& v) { - return vreinterpretq_f32_u8(vqtbl1q_u8( vreinterpretq_u8_s32(v), _MN_SHUFFLE(i0, i1, i2, i3))); + return vreinterpretq_f32_u8(vqtbl1q_u8( vreinterpretq_u8_s32((int32x4_t)v.v), _MN_SHUFFLE(i0, i1, i2, i3))); } template diff --git a/thirdparty/embree/common/simd/vfloat16_avx512.h b/thirdparty/embree/common/simd/vfloat16_avx512.h index 75c471cc0ce..b6160a438cd 100644 --- a/thirdparty/embree/common/simd/vfloat16_avx512.h +++ b/thirdparty/embree/common/simd/vfloat16_avx512.h @@ -316,6 +316,17 @@ namespace embree return madd(t,b-a,a); } + __forceinline bool isvalid (const vfloat16& v) { + return all((v > vfloat16(-FLT_LARGE)) & (v < vfloat16(+FLT_LARGE))); + } + + __forceinline void xchg(vboolf16 m, vfloat16& a, vfloat16& b) + { + vfloat16 c = a; + a = select(m,b,a); + b = select(m,c,b); + } + //////////////////////////////////////////////////////////////////////////////// /// Rounding Functions //////////////////////////////////////////////////////////////////////////////// diff --git a/thirdparty/embree/common/simd/vfloat4_sse2.h b/thirdparty/embree/common/simd/vfloat4_sse2.h index 6d7e11fe722..fccf11fe0c4 100644 --- a/thirdparty/embree/common/simd/vfloat4_sse2.h +++ b/thirdparty/embree/common/simd/vfloat4_sse2.h @@ -32,6 +32,8 @@ namespace embree __forceinline vfloat() {} __forceinline vfloat(const vfloat4& other) { v = other.v; } + //__forceinline vfloat(const vfloat4& other) = default; + __forceinline vfloat4& operator =(const vfloat4& other) { v = other.v; return *this; } __forceinline vfloat(__m128 a) : v(a) {} diff --git a/thirdparty/embree/common/simd/vint4_sse2.h b/thirdparty/embree/common/simd/vint4_sse2.h index eea03a771e1..e9e4a5a2c22 100644 --- a/thirdparty/embree/common/simd/vint4_sse2.h +++ b/thirdparty/embree/common/simd/vint4_sse2.h @@ -3,7 +3,7 @@ #pragma once -#include "../math/math.h" +#include "../math/emath.h" #define vboolf vboolf_impl #define vboold vboold_impl diff --git a/thirdparty/embree/common/simd/vuint4_sse2.h b/thirdparty/embree/common/simd/vuint4_sse2.h index f7817da6bec..c2e86c6633f 100644 --- a/thirdparty/embree/common/simd/vuint4_sse2.h +++ b/thirdparty/embree/common/simd/vuint4_sse2.h @@ -3,7 +3,7 @@ #pragma once -#include "../math/math.h" +#include "../math/emath.h" #define vboolf vboolf_impl #define vboold vboold_impl diff --git a/thirdparty/embree/common/sys/alloc.cpp b/thirdparty/embree/common/sys/alloc.cpp index abdd269069a..71616a39822 100644 --- a/thirdparty/embree/common/sys/alloc.cpp +++ b/thirdparty/embree/common/sys/alloc.cpp @@ -12,33 +12,177 @@ namespace embree { - void* alignedMalloc(size_t size, size_t align) + size_t total_allocations = 0; + +#if defined(EMBREE_SYCL_SUPPORT) + + __thread sycl::context* tls_context_tutorial = nullptr; + __thread sycl::device* tls_device_tutorial = nullptr; + + __thread sycl::context* tls_context_embree = nullptr; + __thread sycl::device* tls_device_embree = nullptr; + + void enableUSMAllocEmbree(sycl::context* context, sycl::device* device) + { + // -- GODOT start -- + // if (tls_context_embree != nullptr) throw std::runtime_error("USM allocation already enabled"); + // if (tls_device_embree != nullptr) throw std::runtime_error("USM allocation already enabled"); + if (tls_context_embree != nullptr) { + abort(); + } + if (tls_device_embree != nullptr) { + abort(); + } + // -- GODOT end -- + tls_context_embree = context; + tls_device_embree = device; + } + + void disableUSMAllocEmbree() + { + // -- GODOT start -- + // if (tls_context_embree == nullptr) throw std::runtime_error("USM allocation not enabled"); + // if (tls_device_embree == nullptr) throw std::runtime_error("USM allocation not enabled"); + if (tls_context_embree == nullptr) { + abort(); + } + if (tls_device_embree == nullptr) { + abort(); + } + // -- GODOT end -- + tls_context_embree = nullptr; + tls_device_embree = nullptr; + } + + void enableUSMAllocTutorial(sycl::context* context, sycl::device* device) + { + //if (tls_context_tutorial != nullptr) throw std::runtime_error("USM allocation already enabled"); + //if (tls_device_tutorial != nullptr) throw std::runtime_error("USM allocation already enabled"); + tls_context_tutorial = context; + tls_device_tutorial = device; + } + + void disableUSMAllocTutorial() + { + // -- GODOT start -- + // if (tls_context_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled"); + // if (tls_device_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled"); + if (tls_context_tutorial == nullptr) { + abort(); + } + if (tls_device_tutorial == nullptr) { + abort(); + } + // -- GODOT end -- + + tls_context_tutorial = nullptr; + tls_device_tutorial = nullptr; + } + +#endif + + void* alignedMalloc(size_t size, size_t align) { if (size == 0) return nullptr; - + assert((align & (align-1)) == 0); void* ptr = _mm_malloc(size,align); - - if (size != 0 && ptr == nullptr) - // -- GODOT start -- - // throw std::bad_alloc(); + // -- GODOT start -- + // if (size != 0 && ptr == nullptr) + // throw std::bad_alloc(); + if (size != 0 && ptr == nullptr) { abort(); - // -- GODOT end -- - + } + // -- GODOT end -- return ptr; } - + void alignedFree(void* ptr) { if (ptr) _mm_free(ptr); } +#if defined(EMBREE_SYCL_SUPPORT) + + void* alignedSYCLMalloc(sycl::context* context, sycl::device* device, size_t size, size_t align, EmbreeUSMMode mode) + { + assert(context); + assert(device); + + if (size == 0) + return nullptr; + + assert((align & (align-1)) == 0); + total_allocations++; + + void* ptr = nullptr; + if (mode == EMBREE_USM_SHARED_DEVICE_READ_ONLY) + ptr = sycl::aligned_alloc_shared(align,size,*device,*context,sycl::ext::oneapi::property::usm::device_read_only()); + else + ptr = sycl::aligned_alloc_shared(align,size,*device,*context); + + // -- GODOT start -- + // if (size != 0 && ptr == nullptr) + // throw std::bad_alloc(); + if (size != 0 && ptr == nullptr) { + abort(); + } + // -- GODOT end -- + + return ptr; + } + + static MutexSys g_alloc_mutex; + + void* alignedSYCLMalloc(size_t size, size_t align, EmbreeUSMMode mode) + { + if (tls_context_tutorial) return alignedSYCLMalloc(tls_context_tutorial, tls_device_tutorial, size, align, mode); + if (tls_context_embree ) return alignedSYCLMalloc(tls_context_embree, tls_device_embree, size, align, mode); + return nullptr; + } + + void alignedSYCLFree(sycl::context* context, void* ptr) + { + assert(context); + if (ptr) { + sycl::free(ptr,*context); + } + } + + void alignedSYCLFree(void* ptr) + { + if (tls_context_tutorial) return alignedSYCLFree(tls_context_tutorial, ptr); + if (tls_context_embree ) return alignedSYCLFree(tls_context_embree, ptr); + } + +#endif + + void* alignedUSMMalloc(size_t size, size_t align, EmbreeUSMMode mode) + { +#if defined(EMBREE_SYCL_SUPPORT) + if (tls_context_embree || tls_context_tutorial) + return alignedSYCLMalloc(size,align,mode); + else +#endif + return alignedMalloc(size,align); + } + + void alignedUSMFree(void* ptr) + { +#if defined(EMBREE_SYCL_SUPPORT) + if (tls_context_embree || tls_context_tutorial) + return alignedSYCLFree(ptr); + else +#endif + return alignedFree(ptr); + } + static bool huge_pages_enabled = false; static MutexSys os_init_mutex; - __forceinline bool isHugePageCandidate(const size_t bytes) + __forceinline bool isHugePageCandidate(const size_t bytes) { if (!huge_pages_enabled) return false; @@ -133,7 +277,9 @@ namespace embree char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE); // -- GODOT start -- // if (ptr == nullptr) throw std::bad_alloc(); - if (ptr == nullptr) abort(); + if (ptr == nullptr) { + abort(); + } // -- GODOT end -- hugepages = false; return ptr; @@ -150,11 +296,13 @@ namespace embree if (bytesNew >= bytesOld) return bytesOld; - if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) - // -- GODOT start -- - // throw std::bad_alloc(); + // -- GODOT start -- + // if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) + // throw std::bad_alloc(); + if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- return bytesNew; } @@ -164,11 +312,13 @@ namespace embree if (bytes == 0) return; - if (!VirtualFree(ptr,0,MEM_RELEASE)) - // -- GODOT start -- - // throw std::bad_alloc(); + // -- GODOT start -- + // if (!VirtualFree(ptr,0,MEM_RELEASE)) + // throw std::bad_alloc(); + if (!VirtualFree(ptr,0,MEM_RELEASE)) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- } void os_advise(void *ptr, size_t bytes) @@ -274,7 +424,9 @@ namespace embree void* ptr = (char*) mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); // -- GODOT start -- // if (ptr == MAP_FAILED) throw std::bad_alloc(); - if (ptr == MAP_FAILED) abort(); + if (ptr == MAP_FAILED) { + abort(); + } // -- GODOT end -- hugepages = false; @@ -291,11 +443,13 @@ namespace embree if (bytesNew >= bytesOld) return bytesOld; - if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) - // -- GODOT start -- - // throw std::bad_alloc(); + // -- GODOT start -- + // if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) + // throw std::bad_alloc(); + if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- return bytesNew; } @@ -308,11 +462,13 @@ namespace embree /* for hugepages we need to also align the size */ const size_t pageSize = hugepages ? PAGE_SIZE_2M : PAGE_SIZE_4K; bytes = (bytes+pageSize-1) & ~(pageSize-1); - if (munmap(ptr,bytes) == -1) - // -- GODOT start -- - // throw std::bad_alloc(); + // -- GODOT start -- + // if (munmap(ptr,bytes) == -1) + // throw std::bad_alloc(); + if (munmap(ptr,bytes) == -1) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- } /* hint for transparent huge pages (THP) */ diff --git a/thirdparty/embree/common/sys/alloc.h b/thirdparty/embree/common/sys/alloc.h index 4fa474ec1d1..28b17f988d8 100644 --- a/thirdparty/embree/common/sys/alloc.h +++ b/thirdparty/embree/common/sys/alloc.h @@ -9,20 +9,72 @@ namespace embree { -#define ALIGNED_STRUCT_(align) \ - void* operator new(size_t size) { return alignedMalloc(size,align); } \ - void operator delete(void* ptr) { alignedFree(ptr); } \ +#if defined(EMBREE_SYCL_SUPPORT) + + /* enables SYCL USM allocation */ + void enableUSMAllocEmbree(sycl::context* context, sycl::device* device); + void enableUSMAllocTutorial(sycl::context* context, sycl::device* device); + + /* disables SYCL USM allocation */ + void disableUSMAllocEmbree(); + void disableUSMAllocTutorial(); + +#endif + +#define ALIGNED_STRUCT_(align) \ + void* operator new(size_t size) { return alignedMalloc(size,align); } \ + void operator delete(void* ptr) { alignedFree(ptr); } \ void* operator new[](size_t size) { return alignedMalloc(size,align); } \ void operator delete[](void* ptr) { alignedFree(ptr); } - -#define ALIGNED_CLASS_(align) \ + +#define ALIGNED_STRUCT_USM_(align) \ + void* operator new(size_t size) { return alignedUSMMalloc(size,align); } \ + void operator delete(void* ptr) { alignedUSMFree(ptr); } \ + void* operator new[](size_t size) { return alignedUSMMalloc(size,align); } \ + void operator delete[](void* ptr) { alignedUSMFree(ptr); } + +#define ALIGNED_CLASS_(align) \ public: \ - ALIGNED_STRUCT_(align) \ + ALIGNED_STRUCT_(align) \ private: + +#define ALIGNED_CLASS_USM_(align) \ + public: \ + ALIGNED_STRUCT_USM_(align) \ + private: + + enum EmbreeUSMMode { + EMBREE_USM_SHARED = 0, + EMBREE_USM_SHARED_DEVICE_READ_WRITE = 0, + EMBREE_USM_SHARED_DEVICE_READ_ONLY = 1 + }; /*! aligned allocation */ void* alignedMalloc(size_t size, size_t align); void alignedFree(void* ptr); + + /*! aligned allocation using SYCL USM */ + void* alignedUSMMalloc(size_t size, size_t align = 16, EmbreeUSMMode mode = EMBREE_USM_SHARED_DEVICE_READ_ONLY); + void alignedUSMFree(void* ptr); + +#if defined(EMBREE_SYCL_SUPPORT) + + /*! aligned allocation using SYCL USM */ + void* alignedSYCLMalloc(sycl::context* context, sycl::device* device, size_t size, size_t align, EmbreeUSMMode mode); + void alignedSYCLFree(sycl::context* context, void* ptr); + + // deleter functor to use as deleter in std unique or shared pointers that + // capture raw pointers created by sycl::malloc and it's variants + template + struct sycl_deleter + { + void operator()(T const* ptr) + { + alignedUSMFree((void*)ptr); + } + }; + +#endif /*! allocator that performs aligned allocations */ template @@ -95,6 +147,37 @@ namespace embree bool hugepages; }; + /*! allocator that newer performs allocations */ + template + struct no_allocator + { + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + __forceinline pointer allocate( size_type n ) { + // -- GODOT start -- + // throw std::runtime_error("no allocation supported"); + abort(); + // -- GODOT end -- + } + + __forceinline void deallocate( pointer p, size_type n ) { + } + + __forceinline void construct( pointer p, const_reference val ) { + new (p) T(val); + } + + __forceinline void destroy( pointer p ) { + p->~T(); + } + }; + /*! allocator for IDs */ template struct IDPool diff --git a/thirdparty/embree/common/sys/atomic.h b/thirdparty/embree/common/sys/atomic.h index 67af254f366..cf9909aad93 100644 --- a/thirdparty/embree/common/sys/atomic.h +++ b/thirdparty/embree/common/sys/atomic.h @@ -36,7 +36,7 @@ namespace embree }; template - __forceinline void atomic_min(std::atomic& aref, const T& bref) + __forceinline void _atomic_min(std::atomic& aref, const T& bref) { const T b = bref.load(); while (true) { @@ -47,7 +47,7 @@ namespace embree } template - __forceinline void atomic_max(std::atomic& aref, const T& bref) + __forceinline void _atomic_max(std::atomic& aref, const T& bref) { const T b = bref.load(); while (true) { diff --git a/thirdparty/embree/common/sys/barrier.h b/thirdparty/embree/common/sys/barrier.h index c56513a2ed6..e1580f41a94 100644 --- a/thirdparty/embree/common/sys/barrier.h +++ b/thirdparty/embree/common/sys/barrier.h @@ -34,7 +34,7 @@ namespace embree void* opaque; }; - /*! fast active barrier using atomitc counter */ + /*! fast active barrier using atomic counter */ struct BarrierActive { public: diff --git a/thirdparty/embree/common/sys/string.cpp b/thirdparty/embree/common/sys/estring.cpp similarity index 98% rename from thirdparty/embree/common/sys/string.cpp rename to thirdparty/embree/common/sys/estring.cpp index f42fdc85364..c66c5c5b848 100644 --- a/thirdparty/embree/common/sys/string.cpp +++ b/thirdparty/embree/common/sys/estring.cpp @@ -1,7 +1,7 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "string.h" +#include "estring.h" #include #include diff --git a/thirdparty/embree/common/sys/string.h b/thirdparty/embree/common/sys/estring.h similarity index 50% rename from thirdparty/embree/common/sys/string.h rename to thirdparty/embree/common/sys/estring.h index 820076b21ca..63051ad3c37 100644 --- a/thirdparty/embree/common/sys/string.h +++ b/thirdparty/embree/common/sys/estring.h @@ -28,6 +28,42 @@ namespace embree std::streamsize precision; }; + struct IndentOStream : public std::streambuf + { + explicit IndentOStream(std::ostream &ostream, int indent = 2) + : streambuf(ostream.rdbuf()) + , start_of_line(true) + , ident_str(indent, ' ') + , stream(&ostream) + { + // set streambuf of ostream to this and save original streambuf + stream->rdbuf(this); + } + + virtual ~IndentOStream() + { + if (stream != NULL) { + // restore old streambuf + stream->rdbuf(streambuf); + } + } + + protected: + virtual int overflow(int ch) { + if (start_of_line && ch != '\n') { + streambuf->sputn(ident_str.data(), ident_str.size()); + } + start_of_line = ch == '\n'; + return streambuf->sputc(ch); + } + + private: + std::streambuf *streambuf; + bool start_of_line; + std::string ident_str; + std::ostream *stream; + }; + std::string toLowerCase(const std::string& s); std::string toUpperCase(const std::string& s); diff --git a/thirdparty/embree/common/sys/intrinsics.h b/thirdparty/embree/common/sys/intrinsics.h index 2c2f6eccdae..f5074bb29d7 100644 --- a/thirdparty/embree/common/sys/intrinsics.h +++ b/thirdparty/embree/common/sys/intrinsics.h @@ -64,7 +64,7 @@ namespace embree /// Windows Platform //////////////////////////////////////////////////////////////////////////////// -#if defined(__WIN32__) +#if defined(__WIN32__) && !defined(__INTEL_LLVM_COMPILER) __forceinline size_t read_tsc() { @@ -89,7 +89,7 @@ namespace embree #endif } -#if defined(__X86_64__) +#if defined(__X86_64__) || defined (__aarch64__) __forceinline size_t bsf(size_t v) { #if defined(__AVX2__) return _tzcnt_u64(v); @@ -113,7 +113,7 @@ namespace embree return i; } -#if defined(__X86_64__) +#if defined(__X86_64__) || defined (__aarch64__) __forceinline size_t bscf(size_t& v) { size_t i = bsf(v); @@ -138,7 +138,7 @@ namespace embree #endif } -#if defined(__X86_64__) +#if defined(__X86_64__) || defined (__aarch64__) __forceinline size_t bsr(size_t v) { #if defined(__AVX2__) return 63 -_lzcnt_u64(v); @@ -196,49 +196,6 @@ namespace embree #else -#if defined(__i386__) && defined(__PIC__) - - __forceinline void __cpuid(int out[4], int op) - { - asm volatile ("xchg{l}\t{%%}ebx, %1\n\t" - "cpuid\n\t" - "xchg{l}\t{%%}ebx, %1\n\t" - : "=a"(out[0]), "=r"(out[1]), "=c"(out[2]), "=d"(out[3]) - : "0"(op)); - } - - __forceinline void __cpuid_count(int out[4], int op1, int op2) - { - asm volatile ("xchg{l}\t{%%}ebx, %1\n\t" - "cpuid\n\t" - "xchg{l}\t{%%}ebx, %1\n\t" - : "=a" (out[0]), "=r" (out[1]), "=c" (out[2]), "=d" (out[3]) - : "0" (op1), "2" (op2)); - } - -#elif defined(__X86_ASM__) - - __forceinline void __cpuid(int out[4], int op) { -#if defined(__ARM_NEON) - if (op == 0) { // Get CPU name - out[0] = 0x41524d20; - out[1] = 0x41524d20; - out[2] = 0x41524d20; - out[3] = 0x41524d20; - } -#else - asm volatile ("cpuid" : "=a"(out[0]), "=b"(out[1]), "=c"(out[2]), "=d"(out[3]) : "a"(op)); -#endif - } - -#if !defined(__ARM_NEON) - __forceinline void __cpuid_count(int out[4], int op1, int op2) { - asm volatile ("cpuid" : "=a"(out[0]), "=b"(out[1]), "=c"(out[2]), "=d"(out[3]) : "a"(op1), "c"(op2)); - } -#endif - -#endif - __forceinline uint64_t read_tsc() { #if defined(__X86_ASM__) uint32_t high,low; @@ -263,6 +220,13 @@ namespace embree #endif #endif } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + __forceinline unsigned int bsf(unsigned v) { + return sycl::ctz(v); + } + +#else #if defined(__64BIT__) __forceinline unsigned bsf(unsigned v) @@ -280,6 +244,13 @@ namespace embree #endif } #endif +#endif + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + __forceinline size_t bsf(size_t v) { + return sycl::ctz(v); + } +#else __forceinline size_t bsf(size_t v) { #if defined(__AVX2__) && !defined(__aarch64__) @@ -294,6 +265,7 @@ namespace embree return __builtin_ctzl(v); #endif } +#endif __forceinline int bscf(int& v) { @@ -434,6 +406,41 @@ namespace embree #endif +#if !defined(__WIN32__) + +#if defined(__i386__) && defined(__PIC__) + + __forceinline void __cpuid(int out[4], int op) + { + asm volatile ("xchg{l}\t{%%}ebx, %1\n\t" + "cpuid\n\t" + "xchg{l}\t{%%}ebx, %1\n\t" + : "=a"(out[0]), "=r"(out[1]), "=c"(out[2]), "=d"(out[3]) + : "0"(op)); + } + + __forceinline void __cpuid_count(int out[4], int op1, int op2) + { + asm volatile ("xchg{l}\t{%%}ebx, %1\n\t" + "cpuid\n\t" + "xchg{l}\t{%%}ebx, %1\n\t" + : "=a" (out[0]), "=r" (out[1]), "=c" (out[2]), "=d" (out[3]) + : "0" (op1), "2" (op2)); + } + +#elif defined(__X86_ASM__) + + __forceinline void __cpuid(int out[4], int op) { + asm volatile ("cpuid" : "=a"(out[0]), "=b"(out[1]), "=c"(out[2]), "=d"(out[3]) : "a"(op)); + } + + __forceinline void __cpuid_count(int out[4], int op1, int op2) { + asm volatile ("cpuid" : "=a"(out[0]), "=b"(out[1]), "=c"(out[2]), "=d"(out[3]) : "a"(op1), "c"(op2)); + } + +#endif +#endif + //////////////////////////////////////////////////////////////////////////////// /// All Platforms //////////////////////////////////////////////////////////////////////////////// @@ -459,8 +466,16 @@ namespace embree #endif #endif -#if defined(__SSE4_2__) || defined(__ARM_NEON) +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + __forceinline unsigned int popcnt(unsigned int in) { + return sycl::popcount(in); + } + +#else + +#if defined(__SSE4_2__) || defined(__ARM_NEON) + __forceinline int popcnt(int in) { return _mm_popcnt_u32(in); } @@ -475,6 +490,8 @@ namespace embree } #endif +#endif + #endif #if defined(__X86_ASM__) diff --git a/thirdparty/embree/common/sys/mutex.h b/thirdparty/embree/common/sys/mutex.h index 26af6c582cf..0f7345cf454 100644 --- a/thirdparty/embree/common/sys/mutex.h +++ b/thirdparty/embree/common/sys/mutex.h @@ -86,8 +86,8 @@ namespace embree class PaddedSpinLock : public SpinLock { - private: - char padding[CPU_CACHELINE_SIZE - sizeof(SpinLock)]; + private: + MAYBE_UNUSED char padding[CPU_CACHELINE_SIZE - sizeof(SpinLock)]; }; /*! safe mutex lock and unlock helper */ template class Lock { diff --git a/thirdparty/embree/common/sys/platform.h b/thirdparty/embree/common/sys/platform.h index 728bf6ed7dd..d4a9b9e119a 100644 --- a/thirdparty/embree/common/sys/platform.h +++ b/thirdparty/embree/common/sys/platform.h @@ -3,7 +3,9 @@ #pragma once +#if !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS +#endif #include #include @@ -18,6 +20,30 @@ #include #include #include +#include + +#if defined(EMBREE_SYCL_SUPPORT) + +#define __SYCL_USE_NON_VARIADIC_SPIRV_OCL_PRINTF__ + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#pragma clang diagnostic ignored "-W#pragma-messages" + +#include + +#pragma clang diagnostic pop + +#include "sycl.h" + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) +#define CONSTANT __attribute__((opencl_constant)) +#else +#define CONSTANT +#endif + +#endif + //////////////////////////////////////////////////////////////////////////////// /// detect platform @@ -115,7 +141,7 @@ #else #define __restrict__ //__restrict // causes issues with MSVC #endif -#if !defined(__thread) +#if !defined(__thread) && !defined(__INTEL_LLVM_COMPILER) #define __thread __declspec(thread) #endif #if !defined(__aligned) @@ -148,6 +174,10 @@ #define MAYBE_UNUSED #endif +#if !defined(_unused) +#define _unused(x) ((void)(x)) +#endif + #if defined(_MSC_VER) && (_MSC_VER < 1900) // before VS2015 deleted functions are not supported properly #define DELETED #else @@ -155,7 +185,7 @@ #endif #if !defined(likely) -#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) || defined(__SYCL_DEVICE_ONLY__) #define likely(expr) (expr) #define unlikely(expr) (expr) #else @@ -171,22 +201,27 @@ /* debug printing macros */ #define STRING(x) #x #define TOSTRING(x) STRING(x) -#define PING embree_cout << __FILE__ << " (" << __LINE__ << "): " << __FUNCTION__ << embree_endl +#define PING embree_cout_uniform << __FILE__ << " (" << __LINE__ << "): " << __FUNCTION__ << embree_endl #define PRINT(x) embree_cout << STRING(x) << " = " << (x) << embree_endl #define PRINT2(x,y) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << embree_endl #define PRINT3(x,y,z) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << embree_endl #define PRINT4(x,y,z,w) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << ", " << STRING(w) << " = " << (w) << embree_endl +#define UPRINT(x) embree_cout_uniform << STRING(x) << " = " << (x) << embree_endl +#define UPRINT2(x,y) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << embree_endl +#define UPRINT3(x,y,z) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << embree_endl +#define UPRINT4(x,y,z,w) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << ", " << STRING(w) << " = " << (w) << embree_endl + #if defined(DEBUG) // only report file and line in debug mode // -- GODOT start -- - // #define THROW_RUNTIME_ERROR(str) + // #define THROW_RUNTIME_ERROR(str) \ // throw std::runtime_error(std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str)); #define THROW_RUNTIME_ERROR(str) \ printf("%s (%d): %s", __FILE__, __LINE__, std::string(str).c_str()), abort(); // -- GODOT end -- #else // -- GODOT start -- - // #define THROW_RUNTIME_ERROR(str) + // #define THROW_RUNTIME_ERROR(str) \ // throw std::runtime_error(str); #define THROW_RUNTIME_ERROR(str) \ abort(); @@ -323,13 +358,209 @@ __forceinline std::string toString(long long value) { #define DISABLE_DEPRECATED_WARNING __pragma(warning (disable: 4996)) // warning: function was declared deprecated #define ENABLE_DEPRECATED_WARNING __pragma(warning (enable : 4996)) // warning: function was declared deprecated #endif + +//////////////////////////////////////////////////////////////////////////////// +/// SYCL specific +//////////////////////////////////////////////////////////////////////////////// + + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + +#define sycl_printf0(format, ...) { \ + static const CONSTANT char fmt[] = format; \ + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) \ + sycl::ext::oneapi::experimental::printf(fmt, __VA_ARGS__ ); \ + } + +#define sycl_printf0_(format) { \ + static const CONSTANT char fmt[] = format; \ + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) \ + sycl::ext::oneapi::experimental::printf(fmt); \ + } + +#else + +#define sycl_printf0(format, ...) { \ + static const CONSTANT char fmt[] = format; \ + sycl::ext::oneapi::experimental::printf(fmt, __VA_ARGS__ ); \ + } + +#define sycl_printf0_(format) { \ + static const CONSTANT char fmt[] = format; \ + sycl::ext::oneapi::experimental::printf(fmt); \ + } + +#endif + +#define sycl_printf(format, ...) { \ + static const CONSTANT char fmt[] = format; \ + sycl::ext::oneapi::experimental::printf(fmt, __VA_ARGS__ ); \ + } + +#define sycl_printf_(format) { \ + static const CONSTANT char fmt[] = format; \ + sycl::ext::oneapi::experimental::printf(fmt); \ + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + +namespace embree +{ + struct sycl_ostream_ { + sycl_ostream_ (bool uniform) : uniform(uniform) {} + bool uniform = false; + }; + struct sycl_endl_ {}; + +#define embree_ostream embree::sycl_ostream_ +#define embree_cout embree::sycl_ostream_(false) +#define embree_cout_uniform embree::sycl_ostream_(true) +#define embree_endl embree::sycl_endl_() + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, int i) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%i",i); + } + else + sycl_printf("%i ",i); + + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, unsigned int i) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%u",i); + } else + sycl_printf("%u ",i); + + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, float f) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%f",f); + } else + sycl_printf("%f ",f); + + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, double d) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%f",d); + } else + sycl_printf("%f ",d); + + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, uint64_t l) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%lu",l); + } else + sycl_printf("%lu ",l); + + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, long l) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%l",l); + } else + sycl_printf("%l ",l); + + return cout; + } + + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, void* p) + { + if (cout.uniform) { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%p",p); + } else + sycl_printf("%p ",p); + + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, const char* c) + { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf("%s",c); + return cout; + } + + inline sycl_ostream_ operator <<(sycl_ostream_ cout, sycl_endl_) + { + if (get_sub_group_local_id() == sycl::ctz(intel_sub_group_ballot(true))) + sycl_printf_("\n"); + return cout; + } +} + +#else -/* embree output stream */ #define embree_ostream std::ostream& #define embree_cout std::cout #define embree_cout_uniform std::cout #define embree_endl std::endl - + +#endif + +#if defined(EMBREE_SYCL_SUPPORT) + + /* printing out sycle vector types */ + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::float4& v) { + return out << "(" << v.x() << "," << v.y() << "," << v.z() << "," << v.w() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::float3& v) { + return out << "(" << v.x() << "," << v.y() << "," << v.z() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::float2& v) { + return out << "(" << v.x() << "," << v.y() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::int4& v) { + return out << "(" << v.x() << "," << v.y() << "," << v.z() << "," << v.w() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::int3& v) { + return out << "(" << v.x() << "," << v.y() << "," << v.z() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::int2& v) { + return out << "(" << v.x() << "," << v.y() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::uint4& v) { + return out << "(" << v.x() << "," << v.y() << "," << v.z() << "," << v.w() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::uint3& v) { + return out << "(" << v.x() << "," << v.y() << "," << v.z() << ")"; + } + __forceinline embree_ostream operator<<(embree_ostream out, const sycl::uint2& v) { + return out << "(" << v.x() << "," << v.y() << ")"; + } + +#endif + +inline void tab(std::ostream& cout, int n) { + for (int i=0; i + __forceinline T cselect(const bool mask, const T &a, const T &b) + { + return sycl::select(b,a,(int)mask); + } + + template + __forceinline T cselect(const M &mask, const T &a, const T &b) + { + return sycl::select(b,a,mask); + } + + __forceinline const sycl::sub_group this_sub_group() { + return sycl::ext::oneapi::experimental::this_sub_group(); + } + + __forceinline const uint32_t get_sub_group_local_id() { + return this_sub_group().get_local_id()[0]; + } + + __forceinline const uint32_t get_sub_group_size() { + return this_sub_group().get_max_local_range().size(); + } + + __forceinline const uint32_t get_sub_group_id() { + return this_sub_group().get_group_id()[0]; + } + + __forceinline const uint32_t get_num_sub_groups() { + return this_sub_group().get_group_range().size(); + } + + __forceinline uint32_t sub_group_ballot(bool pred) { + return intel_sub_group_ballot(pred); + } + + __forceinline bool sub_group_all_of(bool pred) { + return sycl::all_of_group(this_sub_group(),pred); + } + + __forceinline bool sub_group_any_of(bool pred) { + return sycl::any_of_group(this_sub_group(),pred); + } + + __forceinline bool sub_group_none_of(bool pred) { + return sycl::none_of_group(this_sub_group(),pred); + } + + template __forceinline T sub_group_broadcast(T x, sycl::id<1> local_id) { + return sycl::group_broadcast(this_sub_group(),x,local_id); + } + + template __forceinline T sub_group_make_uniform(T x) { + return sub_group_broadcast(x,sycl::ctz(intel_sub_group_ballot(true))); + } + + __forceinline void assume_uniform_array(void* ptr) { +#ifdef __SYCL_DEVICE_ONLY__ + __builtin_IB_assume_uniform(ptr); +#endif + } + + template __forceinline T sub_group_reduce(T x, BinaryOperation binary_op) { + return sycl::reduce_over_group(this_sub_group(),x,binary_op); + } + + template __forceinline T sub_group_reduce(T x, T init, BinaryOperation binary_op) { + return sycl::reduce_over_group(this_sub_group(),x,init,binary_op); + } + + template __forceinline T sub_group_reduce_min(T x, T init) { + return sub_group_reduce(x, init, sycl::ext::oneapi::minimum()); + } + + template __forceinline T sub_group_reduce_min(T x) { + return sub_group_reduce(x, sycl::ext::oneapi::minimum()); + } + + template __forceinline T sub_group_reduce_max(T x) { + return sub_group_reduce(x, sycl::ext::oneapi::maximum()); + } + + template __forceinline T sub_group_reduce_add(T x) { + return sub_group_reduce(x, sycl::ext::oneapi::plus()); + } + + template __forceinline T sub_group_exclusive_scan(T x, BinaryOperation binary_op) { + return sycl::exclusive_scan_over_group(this_sub_group(),x,binary_op); + } + + template __forceinline T sub_group_exclusive_scan_min(T x) { + return sub_group_exclusive_scan(x,sycl::ext::oneapi::minimum()); + } + + template __forceinline T sub_group_exclusive_scan(T x, T init, BinaryOperation binary_op) { + return sycl::exclusive_scan_over_group(this_sub_group(),x,init,binary_op); + } + + template __forceinline T sub_group_inclusive_scan(T x, BinaryOperation binary_op) { + return sycl::inclusive_scan_over_group(this_sub_group(),x,binary_op); + } + + template __forceinline T sub_group_inclusive_scan(T x, BinaryOperation binary_op, T init) { + return sycl::inclusive_scan_over_group(this_sub_group(),x,binary_op,init); + } + + template __forceinline T sub_group_shuffle(T x, sycl::id<1> local_id) { + return this_sub_group().shuffle(x, local_id); + } + + template __forceinline T sub_group_shuffle_down(T x, uint32_t delta) { + return this_sub_group().shuffle_down(x, delta); + } + + template __forceinline T sub_group_shuffle_up(T x, uint32_t delta) { + return this_sub_group().shuffle_up(x, delta); + } + + template __forceinline T sub_group_load(const void* src) { + return this_sub_group().load(sycl::multi_ptr((T*)src)); + } + + template __forceinline void sub_group_store(void* dst, const T& x) { + this_sub_group().store(sycl::multi_ptr((T*)dst),x); + } +} + +#if __SYCL_COMPILER_VERSION < 20210801 +#undef all_of_group +#undef any_of_group +#undef none_of_group +#undef group_broadcast +#undef reduce_over_group +#undef exclusive_scan_over_group +#undef inclusive_scan_over_group +#endif diff --git a/thirdparty/embree/common/sys/sysinfo.cpp b/thirdparty/embree/common/sys/sysinfo.cpp index 7f7a009a1ed..d01eab3c9d9 100644 --- a/thirdparty/embree/common/sys/sysinfo.cpp +++ b/thirdparty/embree/common/sys/sysinfo.cpp @@ -1,9 +1,15 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 +#if defined(__INTEL_LLVM_COMPILER) +// prevents "'__thiscall' calling convention is not supported for this target" warning from TBB +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wignored-attributes" +#endif + #include "sysinfo.h" #include "intrinsics.h" -#include "string.h" +#include "estring.h" #include "ref.h" #if defined(__FREEBSD__) #include @@ -690,3 +696,6 @@ namespace embree } #endif +#if defined(__INTEL_LLVM_COMPILER) +#pragma clang diagnostic pop +#endif diff --git a/thirdparty/embree/common/sys/thread.cpp b/thirdparty/embree/common/sys/thread.cpp index 530c3c78106..8b072067e62 100644 --- a/thirdparty/embree/common/sys/thread.cpp +++ b/thirdparty/embree/common/sys/thread.cpp @@ -3,7 +3,7 @@ #include "thread.h" #include "sysinfo.h" -#include "string.h" +#include "estring.h" #include #if defined(__ARM_NEON) diff --git a/thirdparty/embree/common/sys/vector.h b/thirdparty/embree/common/sys/vector.h index d05e1deb187..226cd34c213 100644 --- a/thirdparty/embree/common/sys/vector.h +++ b/thirdparty/embree/common/sys/vector.h @@ -8,6 +8,8 @@ namespace embree { + class Device; + template class vector_t { @@ -25,6 +27,12 @@ namespace embree template __forceinline explicit vector_t (M alloc, size_t sz) : alloc(alloc), size_active(0), size_alloced(0), items(nullptr) { internal_resize_init(sz); } + + __forceinline vector_t (Device* alloc) + : vector_t(alloc,0) {} + + __forceinline vector_t(void* data, size_t bytes) + : size_active(0), size_alloced(bytes/sizeof(T)), items((T*)data) {} __forceinline ~vector_t() { clear(); @@ -65,6 +73,10 @@ namespace embree return *this; } + __forceinline allocator& getAlloc() { + return alloc; + } + /********************** Iterators ****************************/ __forceinline iterator begin() { return items; }; @@ -215,6 +227,10 @@ namespace embree if (new_alloced <= size_alloced) return size_alloced; + /* if current size is 0 allocate exact requested size */ + if (size_alloced == 0) + return new_alloced; + /* resize to next power of 2 otherwise */ size_t new_size_alloced = size_alloced; while (new_size_alloced < new_alloced) { @@ -237,8 +253,12 @@ namespace embree /*! vector class that performs aligned allocations */ template using avector = vector_t::value> >; - + /*! vector class that performs OS allocations */ template using ovector = vector_t >; + + /*! vector class with externally managed data buffer */ + template + using evector = vector_t>; } diff --git a/thirdparty/embree/common/tasking/taskscheduler.h b/thirdparty/embree/common/tasking/taskscheduler.h index 8f3dd876894..edfffe0e570 100644 --- a/thirdparty/embree/common/tasking/taskscheduler.h +++ b/thirdparty/embree/common/tasking/taskscheduler.h @@ -3,7 +3,7 @@ #pragma once -#if defined(TASKING_INTERNAL) +#if defined(TASKING_INTERNAL) && !defined(TASKING_TBB) # include "taskschedulerinternal.h" #elif defined(TASKING_TBB) # include "taskschedulertbb.h" diff --git a/thirdparty/embree/common/tasking/taskschedulerinternal.cpp b/thirdparty/embree/common/tasking/taskschedulerinternal.cpp index ad438588a35..88b88a30ec5 100644 --- a/thirdparty/embree/common/tasking/taskschedulerinternal.cpp +++ b/thirdparty/embree/common/tasking/taskschedulerinternal.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "taskschedulerinternal.h" -#include "../math/math.h" +#include "../math/emath.h" #include "../sys/sysinfo.h" #include @@ -50,11 +50,11 @@ namespace embree thread.task = this; // -- GODOT start -- // try { - // if (thread.scheduler->cancellingException == nullptr) + // if (context->cancellingException == nullptr) closure->execute(); // } catch (...) { - // if (thread.scheduler->cancellingException == nullptr) - // thread.scheduler->cancellingException = std::current_exception(); + // if (context->cancellingException == nullptr) + // context->cancellingException = std::current_exception(); // } // -- GODOT end -- thread.task = prevTask; @@ -152,7 +152,8 @@ namespace embree { Lock lock(g_mutex); assert(newNumThreads); - newNumThreads = min(newNumThreads, (size_t) getNumberOfLogicalThreads()); + if (newNumThreads == std::numeric_limits::max()) + newNumThreads = (size_t) getNumberOfLogicalThreads(); numThreads = newNumThreads; if (!startThreads && !running) return; @@ -232,7 +233,8 @@ namespace embree TaskScheduler::TaskScheduler() : threadCounter(0), anyTasksRunning(0), hasRootTask(false) { - threadLocal.resize(2*getNumberOfLogicalThreads()); // FIXME: this has to be 2x as in the compatibility join mode with rtcCommitScene the worker threads also join. When disallowing rtcCommitScene to join a build we can remove the 2x. + assert(threadPool); + threadLocal.resize(2 * TaskScheduler::threadCount()); // FIXME: this has to be 2x as in the compatibility join mode with rtcCommitScene the worker threads also join. When disallowing rtcCommitScene to join a build we can remove the 2x. for (size_t i=0; itasks.execute_local_internal(*thread,thread->task)) {}; - return thread->scheduler->cancellingException == nullptr; } -// -- GODOT start -- -// std::exception_ptr TaskScheduler::thread_loop(size_t threadIndex) void TaskScheduler::thread_loop(size_t threadIndex) -// -- GODOT end -- { /* allocate thread structure */ std::unique_ptr mthread(new Thread(threadIndex,this)); // too large for stack allocation @@ -354,11 +349,6 @@ namespace embree threadLocal[threadIndex].store(nullptr); swapThread(oldThread); - /* remember exception to throw */ - // -- GODOT start -- - // std::exception_ptr except = nullptr; - // if (cancellingException != nullptr) except = cancellingException; - // -- GODOT end -- /* wait for all threads to terminate */ threadCounter--; #if defined(__WIN32__) @@ -376,10 +366,6 @@ namespace embree yield(); #endif } - // -- GODOT start -- - // return except; - return; - // -- GODOT end -- } bool TaskScheduler::steal_from_other_threads(Thread& thread) diff --git a/thirdparty/embree/common/tasking/taskschedulerinternal.h b/thirdparty/embree/common/tasking/taskschedulerinternal.h index 6cc2495195e..e72d3b72bac 100644 --- a/thirdparty/embree/common/tasking/taskschedulerinternal.h +++ b/thirdparty/embree/common/tasking/taskschedulerinternal.h @@ -12,7 +12,7 @@ #include "../sys/ref.h" #include "../sys/atomic.h" #include "../math/range.h" -#include "../../include/embree3/rtcore.h" +#include "../../include/embree4/rtcore.h" #include @@ -38,6 +38,13 @@ namespace embree virtual void execute() = 0; }; + + struct TaskGroupContext { + TaskGroupContext() : cancellingException(nullptr) {} + + std::exception_ptr cancellingException; + }; + /*! builds a task interface from a closure */ template struct ClosureTaskFunction : public TaskFunction @@ -76,16 +83,16 @@ namespace embree : state(DONE) {} /*! construction of new task */ - __forceinline Task (TaskFunction* closure, Task* parent, size_t stackPtr, size_t N) - : dependencies(1), stealable(true), closure(closure), parent(parent), stackPtr(stackPtr), N(N) + __forceinline Task (TaskFunction* closure, Task* parent, TaskGroupContext* context, size_t stackPtr, size_t N) + : dependencies(1), stealable(true), closure(closure), parent(parent), context(context), stackPtr(stackPtr), N(N) { if (parent) parent->add_dependencies(+1); switch_state(DONE,INITIALIZED); } /*! construction of stolen task, stealing thread will decrement initial dependency */ - __forceinline Task (TaskFunction* closure, Task* parent) - : dependencies(1), stealable(false), closure(closure), parent(parent), stackPtr(-1), N(1) + __forceinline Task (TaskFunction* closure, Task* parent, TaskGroupContext* context) + : dependencies(1), stealable(false), closure(closure), parent(parent), context(context), stackPtr(-1), N(1) { switch_state(DONE,INITIALIZED); } @@ -95,7 +102,7 @@ namespace embree { if (!stealable) return false; if (!try_switch_state(INITIALIZED,DONE)) return false; - new (&child) Task(closure, this); + new (&child) Task(closure, this, context); return true; } @@ -110,6 +117,7 @@ namespace embree std::atomic stealable; //!< true if task can be stolen TaskFunction* closure; //!< the closure to execute Task* parent; //!< parent task to signal when we are finished + TaskGroupContext* context; size_t stackPtr; //!< stack location where closure is stored size_t N; //!< approximative size of task }; @@ -122,28 +130,32 @@ namespace embree __forceinline void* alloc(size_t bytes, size_t align = 64) { size_t ofs = bytes + ((align - stackPtr) & (align-1)); - if (stackPtr + ofs > CLOSURE_STACK_SIZE) - // -- GODOT start -- - // throw std::runtime_error("closure stack overflow"); + // -- GODOT start -- + // if (stackPtr + ofs > CLOSURE_STACK_SIZE) + // throw std::runtime_error("closure stack overflow"); + if (stackPtr + ofs > CLOSURE_STACK_SIZE) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- stackPtr += ofs; return &stack[stackPtr-bytes]; } template - __forceinline void push_right(Thread& thread, const size_t size, const Closure& closure) + __forceinline void push_right(Thread& thread, const size_t size, const Closure& closure, TaskGroupContext* context) { - if (right >= TASK_STACK_SIZE) - // -- GODOT start -- - // throw std::runtime_error("task stack overflow"); - abort(); - // -- GODOT end -- + // -- GODOT start -- + // if (right >= TASK_STACK_SIZE) + // throw std::runtime_error("task stack overflow"); + if (right >= TASK_STACK_SIZE) { + abort(); + } + // -- GODOT end -- /* allocate new task on right side of stack */ size_t oldStackPtr = stackPtr; TaskFunction* func = new (alloc(sizeof(ClosureTaskFunction))) ClosureTaskFunction(closure); - new (&(tasks[right.load()])) Task(func,thread.task,oldStackPtr,size); + new (&tasks[right.load()]) Task(func,thread.task,context,oldStackPtr,size); right++; /* also move left pointer */ @@ -178,7 +190,7 @@ namespace embree : threadIndex(threadIndex), task(nullptr), scheduler(scheduler) {} __forceinline size_t threadCount() { - return scheduler->threadCounter; + return scheduler->threadCounter; } size_t threadIndex; //!< ID of this thread @@ -244,10 +256,7 @@ namespace embree void wait_for_threads(size_t threadCount); /*! thread loop for all worker threads */ - // -- GODOT start -- - // std::exception_ptr thread_loop(size_t threadIndex); void thread_loop(size_t threadIndex); - // -- GODOT end -- /*! steals a task from a different thread */ bool steal_from_other_threads(Thread& thread); @@ -257,7 +266,7 @@ namespace embree /* spawn a new task at the top of the threads task stack */ template - void spawn_root(const Closure& closure, size_t size = 1, bool useThreadPool = true) + void spawn_root(const Closure& closure, TaskGroupContext* context, size_t size = 1, bool useThreadPool = true) { if (useThreadPool) startThreads(); @@ -267,7 +276,7 @@ namespace embree assert(threadLocal[threadIndex].load() == nullptr); threadLocal[threadIndex] = &thread; Thread* oldThread = swapThread(&thread); - thread.tasks.push_right(thread,size,closure); + thread.tasks.push_right(thread,size,closure,context); { Lock lock(mutex); anyTasksRunning++; @@ -286,51 +295,52 @@ namespace embree /* remember exception to throw */ std::exception_ptr except = nullptr; - if (cancellingException != nullptr) except = cancellingException; + if (context->cancellingException != nullptr) except = context->cancellingException; /* wait for all threads to terminate */ threadCounter--; while (threadCounter > 0) yield(); - cancellingException = nullptr; + context->cancellingException = nullptr; /* re-throw proper exception */ - if (except != nullptr) + if (except != nullptr) { std::rethrow_exception(except); + } } /* spawn a new task at the top of the threads task stack */ template - static __forceinline void spawn(size_t size, const Closure& closure) + static __forceinline void spawn(size_t size, const Closure& closure, TaskGroupContext* context) { Thread* thread = TaskScheduler::thread(); - if (likely(thread != nullptr)) thread->tasks.push_right(*thread,size,closure); - else instance()->spawn_root(closure,size); + if (likely(thread != nullptr)) thread->tasks.push_right(*thread,size,closure,context); + else instance()->spawn_root(closure,context,size); } /* spawn a new task at the top of the threads task stack */ template - static __forceinline void spawn(const Closure& closure) { - spawn(1,closure); + static __forceinline void spawn(const Closure& closure, TaskGroupContext* taskGroupContext) { + spawn(1,closure,taskGroupContext); } /* spawn a new task set */ template - static void spawn(const Index begin, const Index end, const Index blockSize, const Closure& closure) + static void spawn(const Index begin, const Index end, const Index blockSize, const Closure& closure, TaskGroupContext* context) { spawn(end-begin, [=]() - { - if (end-begin <= blockSize) { - return closure(range(begin,end)); - } - const Index center = (begin+end)/2; - spawn(begin,center,blockSize,closure); - spawn(center,end ,blockSize,closure); - wait(); - }); + { + if (end-begin <= blockSize) { + return closure(range(begin,end)); + } + const Index center = (begin+end)/2; + spawn(begin,center,blockSize,closure,context); + spawn(center,end ,blockSize,closure,context); + wait(); + },context); } /* work on spawned subtasks and wait until all have finished */ - dll_export static bool wait(); + dll_export static void wait(); /* returns the ID of the current thread */ dll_export static size_t threadID(); @@ -366,7 +376,6 @@ namespace embree std::atomic threadCounter; std::atomic anyTasksRunning; std::atomic hasRootTask; - std::exception_ptr cancellingException; MutexSys mutex; ConditionSys condition; diff --git a/thirdparty/embree/common/tasking/taskschedulertbb.h b/thirdparty/embree/common/tasking/taskschedulertbb.h index 042ba7bc4ce..e1f647eb067 100644 --- a/thirdparty/embree/common/tasking/taskschedulertbb.h +++ b/thirdparty/embree/common/tasking/taskschedulertbb.h @@ -15,6 +15,12 @@ # define NOMINMAX #endif +#if defined(__INTEL_LLVM_COMPILER) +// prevents "'__thiscall' calling convention is not supported for this target" warning from TBB +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wignored-attributes" +#endif + // We need to define these to avoid implicit linkage against // tbb_debug.lib under Windows. When removing these lines debug build // under Windows fails. @@ -25,6 +31,18 @@ #include "tbb/tbb.h" #include "tbb/parallel_sort.h" +#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8) +# define USE_TASK_ARENA 1 +#else +# define USE_TASK_ARENA 0 +#endif + +#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 9 +# define TASKING_TBB_USE_TASK_ISOLATION 1 +#else +# define TASKING_TBB_USE_TASK_ISOLATION 0 +#endif + namespace embree { struct TaskScheduler @@ -65,3 +83,7 @@ namespace embree }; }; + +#if defined(__INTEL_LLVM_COMPILER) +#pragma clang diagnostic pop +#endif \ No newline at end of file diff --git a/thirdparty/embree/include/embree3/rtcore_scene.h b/thirdparty/embree/include/embree3/rtcore_scene.h deleted file mode 100644 index 34d87a2ce49..00000000000 --- a/thirdparty/embree/include/embree3/rtcore_scene.h +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "rtcore_device.h" - -RTC_NAMESPACE_BEGIN - -/* Forward declarations for ray structures */ -struct RTCRayHit; -struct RTCRayHit4; -struct RTCRayHit8; -struct RTCRayHit16; -struct RTCRayHitNp; - -/* Scene flags */ -enum RTCSceneFlags -{ - RTC_SCENE_FLAG_NONE = 0, - RTC_SCENE_FLAG_DYNAMIC = (1 << 0), - RTC_SCENE_FLAG_COMPACT = (1 << 1), - RTC_SCENE_FLAG_ROBUST = (1 << 2), - RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION = (1 << 3) -}; - -/* Creates a new scene. */ -RTC_API RTCScene rtcNewScene(RTCDevice device); - -/* Returns the device the scene got created in. The reference count of - * the device is incremented by this function. */ -RTC_API RTCDevice rtcGetSceneDevice(RTCScene hscene); - -/* Retains the scene (increments the reference count). */ -RTC_API void rtcRetainScene(RTCScene scene); - -/* Releases the scene (decrements the reference count). */ -RTC_API void rtcReleaseScene(RTCScene scene); - - -/* Attaches the geometry to a scene. */ -RTC_API unsigned int rtcAttachGeometry(RTCScene scene, RTCGeometry geometry); - -/* Attaches the geometry to a scene using the specified geometry ID. */ -RTC_API void rtcAttachGeometryByID(RTCScene scene, RTCGeometry geometry, unsigned int geomID); - -/* Detaches the geometry from the scene. */ -RTC_API void rtcDetachGeometry(RTCScene scene, unsigned int geomID); - -/* Gets a geometry handle from the scene. This function is not thread safe and should get used during rendering. */ -RTC_API RTCGeometry rtcGetGeometry(RTCScene scene, unsigned int geomID); - -/* Gets a geometry handle from the scene. This function is thread safe and should NOT get used during rendering. */ -RTC_API RTCGeometry rtcGetGeometryThreadSafe(RTCScene scene, unsigned int geomID); - - -/* Commits the scene. */ -RTC_API void rtcCommitScene(RTCScene scene); - -/* Commits the scene from multiple threads. */ -RTC_API void rtcJoinCommitScene(RTCScene scene); - - -/* Progress monitor callback function */ -typedef bool (*RTCProgressMonitorFunction)(void* ptr, double n); - -/* Sets the progress monitor callback function of the scene. */ -RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene scene, RTCProgressMonitorFunction progress, void* ptr); - -/* Sets the build quality of the scene. */ -RTC_API void rtcSetSceneBuildQuality(RTCScene scene, enum RTCBuildQuality quality); - -/* Sets the scene flags. */ -RTC_API void rtcSetSceneFlags(RTCScene scene, enum RTCSceneFlags flags); - -/* Returns the scene flags. */ -RTC_API enum RTCSceneFlags rtcGetSceneFlags(RTCScene scene); - -/* Returns the axis-aligned bounds of the scene. */ -RTC_API void rtcGetSceneBounds(RTCScene scene, struct RTCBounds* bounds_o); - -/* Returns the linear axis-aligned bounds of the scene. */ -RTC_API void rtcGetSceneLinearBounds(RTCScene scene, struct RTCLinearBounds* bounds_o); - - -/* Perform a closest point query of the scene. */ -RTC_API bool rtcPointQuery(RTCScene scene, struct RTCPointQuery* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void* userPtr); - -/* Perform a closest point query with a packet of 4 points with the scene. */ -RTC_API bool rtcPointQuery4(const int* valid, RTCScene scene, struct RTCPointQuery4* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr); - -/* Perform a closest point query with a packet of 4 points with the scene. */ -RTC_API bool rtcPointQuery8(const int* valid, RTCScene scene, struct RTCPointQuery8* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr); - -/* Perform a closest point query with a packet of 4 points with the scene. */ -RTC_API bool rtcPointQuery16(const int* valid, RTCScene scene, struct RTCPointQuery16* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr); - -/* Intersects a single ray with the scene. */ -RTC_API void rtcIntersect1(RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHit* rayhit); - -/* Intersects a packet of 4 rays with the scene. */ -RTC_API void rtcIntersect4(const int* valid, RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHit4* rayhit); - -/* Intersects a packet of 8 rays with the scene. */ -RTC_API void rtcIntersect8(const int* valid, RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHit8* rayhit); - -/* Intersects a packet of 16 rays with the scene. */ -RTC_API void rtcIntersect16(const int* valid, RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHit16* rayhit); - -/* Intersects a stream of M rays with the scene. */ -RTC_API void rtcIntersect1M(RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHit* rayhit, unsigned int M, size_t byteStride); - -/* Intersects a stream of pointers to M rays with the scene. */ -RTC_API void rtcIntersect1Mp(RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHit** rayhit, unsigned int M); - -/* Intersects a stream of M ray packets of size N in SOA format with the scene. */ -RTC_API void rtcIntersectNM(RTCScene scene, struct RTCIntersectContext* context, struct RTCRayHitN* rayhit, unsigned int N, unsigned int M, size_t byteStride); - -/* Intersects a stream of M ray packets of size N in SOA format with the scene. */ -RTC_API void rtcIntersectNp(RTCScene scene, struct RTCIntersectContext* context, const struct RTCRayHitNp* rayhit, unsigned int N); - -/* Tests a single ray for occlusion with the scene. */ -RTC_API void rtcOccluded1(RTCScene scene, struct RTCIntersectContext* context, struct RTCRay* ray); - -/* Tests a packet of 4 rays for occlusion occluded with the scene. */ -RTC_API void rtcOccluded4(const int* valid, RTCScene scene, struct RTCIntersectContext* context, struct RTCRay4* ray); - -/* Tests a packet of 8 rays for occlusion with the scene. */ -RTC_API void rtcOccluded8(const int* valid, RTCScene scene, struct RTCIntersectContext* context, struct RTCRay8* ray); - -/* Tests a packet of 16 rays for occlusion with the scene. */ -RTC_API void rtcOccluded16(const int* valid, RTCScene scene, struct RTCIntersectContext* context, struct RTCRay16* ray); - -/* Tests a stream of M rays for occlusion with the scene. */ -RTC_API void rtcOccluded1M(RTCScene scene, struct RTCIntersectContext* context, struct RTCRay* ray, unsigned int M, size_t byteStride); - -/* Tests a stream of pointers to M rays for occlusion with the scene. */ -RTC_API void rtcOccluded1Mp(RTCScene scene, struct RTCIntersectContext* context, struct RTCRay** ray, unsigned int M); - -/* Tests a stream of M ray packets of size N in SOA format for occlusion with the scene. */ -RTC_API void rtcOccludedNM(RTCScene scene, struct RTCIntersectContext* context, struct RTCRayN* ray, unsigned int N, unsigned int M, size_t byteStride); - -/* Tests a stream of M ray packets of size N in SOA format for occlusion with the scene. */ -RTC_API void rtcOccludedNp(RTCScene scene, struct RTCIntersectContext* context, const struct RTCRayNp* ray, unsigned int N); - -/*! collision callback */ -struct RTCCollision { unsigned int geomID0; unsigned int primID0; unsigned int geomID1; unsigned int primID1; }; -typedef void (*RTCCollideFunc) (void* userPtr, struct RTCCollision* collisions, unsigned int num_collisions); - -/*! Performs collision detection of two scenes */ -RTC_API void rtcCollide (RTCScene scene0, RTCScene scene1, RTCCollideFunc callback, void* userPtr); - -#if defined(__cplusplus) - -/* Helper for easily combining scene flags */ -inline RTCSceneFlags operator|(RTCSceneFlags a, RTCSceneFlags b) { - return (RTCSceneFlags)((size_t)a | (size_t)b); -} - -#endif - -RTC_NAMESPACE_END - diff --git a/thirdparty/embree/include/embree3/rtcore.h b/thirdparty/embree/include/embree4/rtcore.h similarity index 100% rename from thirdparty/embree/include/embree3/rtcore.h rename to thirdparty/embree/include/embree4/rtcore.h diff --git a/thirdparty/embree/include/embree3/rtcore_buffer.h b/thirdparty/embree/include/embree4/rtcore_buffer.h similarity index 96% rename from thirdparty/embree/include/embree3/rtcore_buffer.h rename to thirdparty/embree/include/embree4/rtcore_buffer.h index 6b8eba97692..8721ce4a441 100644 --- a/thirdparty/embree/include/embree3/rtcore_buffer.h +++ b/thirdparty/embree/include/embree4/rtcore_buffer.h @@ -27,6 +27,8 @@ enum RTCBufferType RTC_BUFFER_TYPE_VERTEX_CREASE_WEIGHT = 21, RTC_BUFFER_TYPE_HOLE = 22, + RTC_BUFFER_TYPE_TRANSFORM = 23, + RTC_BUFFER_TYPE_FLAGS = 32 }; diff --git a/thirdparty/embree/include/embree3/rtcore_builder.h b/thirdparty/embree/include/embree4/rtcore_builder.h similarity index 100% rename from thirdparty/embree/include/embree3/rtcore_builder.h rename to thirdparty/embree/include/embree4/rtcore_builder.h diff --git a/thirdparty/embree/include/embree3/rtcore_common.h b/thirdparty/embree/include/embree4/rtcore_common.h similarity index 55% rename from thirdparty/embree/include/embree3/rtcore_common.h rename to thirdparty/embree/include/embree4/rtcore_common.h index 894628e47c4..57448ddaea2 100644 --- a/thirdparty/embree/include/embree3/rtcore_common.h +++ b/thirdparty/embree/include/embree4/rtcore_common.h @@ -12,7 +12,7 @@ RTC_NAMESPACE_BEGIN #if defined(_WIN32) -#if defined(_M_X64) +#if defined(_M_X64) || defined(_M_ARM64) typedef long long ssize_t; #else typedef int ssize_t; @@ -41,6 +41,12 @@ typedef int ssize_t; # define RTC_FORCEINLINE inline __attribute__((always_inline)) #endif +#if defined(__cplusplus) +# define RTC_OPTIONAL_ARGUMENT = nullptr +#else +# define RTC_OPTIONAL_ARGUMENT +#endif + /* Invalid geometry ID */ #define RTC_INVALID_GEOMETRY_ID ((unsigned int)-1) @@ -141,7 +147,9 @@ enum RTCFormat RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR = 0x9244, /* special 12-byte format for grids */ - RTC_FORMAT_GRID = 0xA001 + RTC_FORMAT_GRID = 0xA001, + + RTC_FORMAT_QUATERNION_DECOMPOSITION = 0xB001, }; /* Build quality levels */ @@ -167,12 +175,138 @@ struct RTC_ALIGN(16) RTCLinearBounds struct RTCBounds bounds1; }; -/* Intersection context flags */ -enum RTCIntersectContextFlags +/* Feature flags for SYCL specialization constants */ +enum RTCFeatureFlags { - RTC_INTERSECT_CONTEXT_FLAG_NONE = 0, - RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT = (0 << 0), // optimize for incoherent rays - RTC_INTERSECT_CONTEXT_FLAG_COHERENT = (1 << 0) // optimize for coherent rays + RTC_FEATURE_FLAG_NONE = 0, + + RTC_FEATURE_FLAG_MOTION_BLUR = 1 << 0, + + RTC_FEATURE_FLAG_TRIANGLE = 1 << 1, + RTC_FEATURE_FLAG_QUAD = 1 << 2, + RTC_FEATURE_FLAG_GRID = 1 << 3, + + RTC_FEATURE_FLAG_SUBDIVISION = 1 << 4, + + RTC_FEATURE_FLAG_CONE_LINEAR_CURVE = 1 << 5, + RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE = 1 << 6, + RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE = 1 << 7, + + RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE = 1 << 8, + RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE = 1 << 9, + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE = 1 << 10, + + RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE = 1 << 11, + RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE = 1 << 12, + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE = 1 << 13, + + RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE = 1 << 14, + RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE = 1 << 15, + RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE = 1 << 16, + + RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE = 1 << 17, + RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE = 1 << 18, + RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE = 1 << 19, + + RTC_FEATURE_FLAG_SPHERE_POINT = 1 << 20, + RTC_FEATURE_FLAG_DISC_POINT = 1 << 21, + RTC_FEATURE_FLAG_ORIENTED_DISC_POINT = 1 << 22, + + RTC_FEATURE_FLAG_POINT = + RTC_FEATURE_FLAG_SPHERE_POINT | + RTC_FEATURE_FLAG_DISC_POINT | + RTC_FEATURE_FLAG_ORIENTED_DISC_POINT, + + RTC_FEATURE_FLAG_ROUND_CURVES = + RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE | + RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE | + RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE | + RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE | + RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE, + + RTC_FEATURE_FLAG_FLAT_CURVES = + RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE | + RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE | + RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE | + RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE | + RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE, + + RTC_FEATURE_FLAG_NORMAL_ORIENTED_CURVES = + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE, + + RTC_FEATURE_FLAG_LINEAR_CURVES = + RTC_FEATURE_FLAG_CONE_LINEAR_CURVE | + RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE | + RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE, + + RTC_FEATURE_FLAG_BEZIER_CURVES = + RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE | + RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE, + + RTC_FEATURE_FLAG_BSPLINE_CURVES = + RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE | + RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE, + + RTC_FEATURE_FLAG_HERMITE_CURVES = + RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE | + RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE, + + RTC_FEATURE_FLAG_CURVES = + RTC_FEATURE_FLAG_CONE_LINEAR_CURVE | + RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE | + RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE | + RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE | + RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE | + RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE | + RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE | + RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE | + RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE | + RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE | + RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE | + RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE, + + RTC_FEATURE_FLAG_INSTANCE = 1 << 23, + + RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS = 1 << 24, + RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY = 1 << 25, + + RTC_FEATURE_FLAG_FILTER_FUNCTION = + RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS | + RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY, + + RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS = 1 << 26, + RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY = 1 << 27, + + RTC_FEATURE_FLAG_USER_GEOMETRY = + RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS | + RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY, + + RTC_FEATURE_FLAG_32_BIT_RAY_MASK = 1 << 28, + + RTC_FEATURE_FLAG_INSTANCE_ARRAY = 1 << 29, + + RTC_FEATURE_FLAG_ALL = 0xffffffff, +}; + +/* Ray query flags */ +enum RTCRayQueryFlags +{ + /* matching intel_ray_flags_t layout */ + RTC_RAY_QUERY_FLAG_NONE = 0, + RTC_RAY_QUERY_FLAG_INVOKE_ARGUMENT_FILTER = (1 << 1), // enable argument filter for each geometry + + /* embree specific flags */ + RTC_RAY_QUERY_FLAG_INCOHERENT = (0 << 16), // optimize for incoherent rays + RTC_RAY_QUERY_FLAG_COHERENT = (1 << 16), // optimize for coherent rays }; /* Arguments for RTCFilterFunctionN */ @@ -180,7 +314,7 @@ struct RTCFilterFunctionNArguments { int* valid; void* geometryUserPtr; - struct RTCIntersectContext* context; + struct RTCRayQueryContext* context; struct RTCRayN* ray; struct RTCHitN* hit; unsigned int N; @@ -189,38 +323,41 @@ struct RTCFilterFunctionNArguments /* Filter callback function */ typedef void (*RTCFilterFunctionN)(const struct RTCFilterFunctionNArguments* args); -/* Intersection context passed to intersect/occluded calls */ -struct RTCIntersectContext +/* Intersection callback function */ +struct RTCIntersectFunctionNArguments; +typedef void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* args); + +/* Occlusion callback function */ +struct RTCOccludedFunctionNArguments; +typedef void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* args); + +/* Ray query context passed to intersect/occluded calls */ +struct RTCRayQueryContext { - enum RTCIntersectContextFlags flags; // intersection flags - RTCFilterFunctionN filter; // filter function to execute - #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1 unsigned int instStackSize; // Number of instances currently on the stack. #endif unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance ids. - -#if RTC_MIN_WIDTH - float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance primitive ids. #endif }; -/* Initializes an intersection context. */ -RTC_FORCEINLINE void rtcInitIntersectContext(struct RTCIntersectContext* context) +/* Initializes an ray query context. */ +RTC_FORCEINLINE void rtcInitRayQueryContext(struct RTCRayQueryContext* context) { unsigned l = 0; - context->flags = RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT; - context->filter = NULL; - + #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1 context->instStackSize = 0; #endif - for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + + for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { context->instID[l] = RTC_INVALID_GEOMETRY_ID; - -#if RTC_MIN_WIDTH - context->minWidthDistanceFactor = 0.0f; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[l] = RTC_INVALID_GEOMETRY_ID; #endif + } } /* Point query structure for closest point query */ @@ -278,15 +415,28 @@ struct RTC_ALIGN(16) RTCPointQueryContext // instance ids. unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + // instance prim ids. + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; +#endif + // number of instances currently on the stack. unsigned int instStackSize; }; -/* Initializes an intersection context. */ +/* Initializes an ray query context. */ RTC_FORCEINLINE void rtcInitPointQueryContext(struct RTCPointQueryContext* context) { + unsigned l = 0; + context->instStackSize = 0; - context->instID[0] = RTC_INVALID_GEOMETRY_ID; + + for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { + context->instID[l] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[l] = RTC_INVALID_GEOMETRY_ID; +#endif + } } struct RTC_ALIGN(16) RTCPointQueryFunctionArguments @@ -308,7 +458,7 @@ struct RTC_ALIGN(16) RTCPointQueryFunctionArguments struct RTCPointQueryContext* context; // If the current instance transform M (= context->world2inst[context->instStackSize]) - // is a similarity matrix, i.e there is a constant factor similarityScale such that, + // is a similarity matrix, i.e there is a constant factor similarityScale such that // for all x,y: dist(Mx, My) = similarityScale * dist(x, y), // The similarity scale is 0, if the current instance transform is not a // similarity transform and vice versa. The similarity scale allows to compute @@ -322,5 +472,31 @@ struct RTC_ALIGN(16) RTCPointQueryFunctionArguments }; typedef bool (*RTCPointQueryFunction)(struct RTCPointQueryFunctionArguments* args); - + +#if defined(EMBREE_SYCL_SUPPORT) && defined(SYCL_LANGUAGE_VERSION) + +/* returns function pointer to be usable in SYCL kernel */ +template +inline decltype(F) rtcGetSYCLDeviceFunctionPointer(sycl::queue& queue) +{ + sycl::buffer fptr_buf(1); + { + auto fptr_acc = fptr_buf.get_host_access(); + fptr_acc[0] = 0; + } + + queue.submit([&](sycl::handler& cgh) { + auto fptr_acc = fptr_buf.get_access(cgh); + cgh.single_task([=]() { + fptr_acc[0] = reinterpret_cast(F); + }); + }); + queue.wait_and_throw(); + + auto fptr_acc = fptr_buf.get_host_access(); + return (decltype(F)) fptr_acc[0]; +} + +#endif + RTC_NAMESPACE_END diff --git a/thirdparty/embree/include/embree3/rtcore_config.h b/thirdparty/embree/include/embree4/rtcore_config.h similarity index 62% rename from thirdparty/embree/include/embree3/rtcore_config.h rename to thirdparty/embree/include/embree4/rtcore_config.h index 0b399ef040a..cb3a8678a70 100644 --- a/thirdparty/embree/include/embree3/rtcore_config.h +++ b/thirdparty/embree/include/embree4/rtcore_config.h @@ -3,21 +3,32 @@ #pragma once -#define RTC_VERSION_MAJOR 3 -#define RTC_VERSION_MINOR 13 -#define RTC_VERSION_PATCH 5 -#define RTC_VERSION 31305 -#define RTC_VERSION_STRING "3.13.5" +#if !defined(EMBREE_SYCL_SUPPORT) +// #cmakedefine EMBREE_SYCL_SUPPORT +#endif + +#define RTC_VERSION_MAJOR 4 +#define RTC_VERSION_MINOR 3 +#define RTC_VERSION_PATCH 1 +#define RTC_VERSION 40301 +#define RTC_VERSION_STRING "4.3.1" #define RTC_MAX_INSTANCE_LEVEL_COUNT 1 +// #cmakedefine EMBREE_GEOMETRY_INSTANCE_ARRAY +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + #define RTC_GEOMETRY_INSTANCE_ARRAY +#endif + +// #cmakedefine01 EMBREE_SYCL_GEOMETRY_CALLBACK + #define EMBREE_MIN_WIDTH 0 #define RTC_MIN_WIDTH EMBREE_MIN_WIDTH #if !defined(EMBREE_STATIC_LIB) -# define EMBREE_STATIC_LIB +#define EMBREE_STATIC_LIB #endif -/* #undef EMBREE_API_NAMESPACE*/ +// #cmakedefine EMBREE_API_NAMESPACE #if defined(EMBREE_API_NAMESPACE) # define RTC_NAMESPACE @@ -56,3 +67,14 @@ #else # define RTC_API RTC_API_IMPORT #endif + +#if defined(ISPC) +# define RTC_SYCL_INDIRECTLY_CALLABLE +#elif defined(__SYCL_DEVICE_ONLY__) +# define RTC_SYCL_INDIRECTLY_CALLABLE [[intel::device_indirectly_callable]] SYCL_EXTERNAL +# define RTC_SYCL_API SYCL_EXTERNAL +#else +# define RTC_SYCL_INDIRECTLY_CALLABLE +# define RTC_SYCL_API RTC_API +#endif + diff --git a/thirdparty/embree/include/embree3/rtcore_device.h b/thirdparty/embree/include/embree4/rtcore_device.h similarity index 80% rename from thirdparty/embree/include/embree3/rtcore_device.h rename to thirdparty/embree/include/embree4/rtcore_device.h index 2dd30476030..5ca99bca0a7 100644 --- a/thirdparty/embree/include/embree3/rtcore_device.h +++ b/thirdparty/embree/include/embree4/rtcore_device.h @@ -13,6 +13,24 @@ typedef struct RTCDeviceTy* RTCDevice; /* Creates a new Embree device. */ RTC_API RTCDevice rtcNewDevice(const char* config); +#if defined(EMBREE_SYCL_SUPPORT) && defined(SYCL_LANGUAGE_VERSION) + + +/* Creates a new Embree SYCL device. */ +RTC_API_EXTERN_C RTCDevice rtcNewSYCLDevice(sycl::context context, const char* config); + +/* Checks if SYCL device is supported by Embree. */ +RTC_API bool rtcIsSYCLDeviceSupported(const sycl::device sycl_device); + +/* SYCL selector for Embree supported devices */ +RTC_API int rtcSYCLDeviceSelector(const sycl::device sycl_device); + +/* Set the SYCL device to be used to allocate data */ +RTC_API void rtcSetDeviceSYCLDevice(RTCDevice device, const sycl::device sycl_device); + +#endif + + /* Retains the Embree device (increments the reference count). */ RTC_API void rtcRetainDevice(RTCDevice device); @@ -30,8 +48,8 @@ enum RTCDeviceProperty RTC_DEVICE_PROPERTY_NATIVE_RAY4_SUPPORTED = 32, RTC_DEVICE_PROPERTY_NATIVE_RAY8_SUPPORTED = 33, RTC_DEVICE_PROPERTY_NATIVE_RAY16_SUPPORTED = 34, - RTC_DEVICE_PROPERTY_RAY_STREAM_SUPPORTED = 35, + RTC_DEVICE_PROPERTY_BACKFACE_CULLING_SPHERES_ENABLED = 62, RTC_DEVICE_PROPERTY_BACKFACE_CULLING_CURVES_ENABLED = 63, RTC_DEVICE_PROPERTY_RAY_MASK_SUPPORTED = 64, RTC_DEVICE_PROPERTY_BACKFACE_CULLING_ENABLED = 65, @@ -66,7 +84,7 @@ enum RTCError RTC_ERROR_INVALID_OPERATION = 3, RTC_ERROR_OUT_OF_MEMORY = 4, RTC_ERROR_UNSUPPORTED_CPU = 5, - RTC_ERROR_CANCELLED = 6 + RTC_ERROR_CANCELLED = 6, }; /* Returns the error code. */ diff --git a/thirdparty/embree/include/embree3/rtcore_geometry.h b/thirdparty/embree/include/embree4/rtcore_geometry.h similarity index 91% rename from thirdparty/embree/include/embree3/rtcore_geometry.h rename to thirdparty/embree/include/embree4/rtcore_geometry.h index d1de17491cb..140d6721d5c 100644 --- a/thirdparty/embree/include/embree3/rtcore_geometry.h +++ b/thirdparty/embree/include/embree4/rtcore_geometry.h @@ -48,7 +48,8 @@ enum RTCGeometryType RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE = 60, // flat normal-oriented Catmull-Rom curves RTC_GEOMETRY_TYPE_USER = 120, // user-defined geometry - RTC_GEOMETRY_TYPE_INSTANCE = 121 // scene instance + RTC_GEOMETRY_TYPE_INSTANCE = 121, // scene instance + RTC_GEOMETRY_TYPE_INSTANCE_ARRAY = 122, // scene instance array }; /* Interpolation modes for subdivision surfaces */ @@ -86,30 +87,24 @@ struct RTCIntersectFunctionNArguments int* valid; void* geometryUserPtr; unsigned int primID; - struct RTCIntersectContext* context; + struct RTCRayQueryContext* context; struct RTCRayHitN* rayhit; unsigned int N; unsigned int geomID; }; -/* Intersection callback function */ -typedef void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* args); - /* Arguments for RTCOccludedFunctionN */ struct RTCOccludedFunctionNArguments { int* valid; void* geometryUserPtr; unsigned int primID; - struct RTCIntersectContext* context; + struct RTCRayQueryContext* context; struct RTCRayN* ray; unsigned int N; unsigned int geomID; }; -/* Occlusion callback function */ -typedef void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* args); - /* Arguments for RTCDisplacementFunctionN */ struct RTCDisplacementFunctionNArguments { @@ -192,6 +187,9 @@ RTC_API void rtcSetGeometryIntersectFilterFunction(RTCGeometry geometry, RTCFilt /* Sets the occlusion filter callback function of the geometry. */ RTC_API void rtcSetGeometryOccludedFilterFunction(RTCGeometry geometry, RTCFilterFunctionN filter); +/* Enables argument version of intersection or occlusion filter function. */ +RTC_API void rtcSetGeometryEnableFilterFunctionFromArguments(RTCGeometry geometry, bool enable); + /* Sets the user-defined data pointer of the geometry. */ RTC_API void rtcSetGeometryUserData(RTCGeometry geometry, void* ptr); @@ -214,15 +212,17 @@ RTC_API void rtcSetGeometryIntersectFunction(RTCGeometry geometry, RTCIntersectF RTC_API void rtcSetGeometryOccludedFunction(RTCGeometry geometry, RTCOccludedFunctionN occluded); /* Invokes the intersection filter from the intersection callback function. */ -RTC_API void rtcFilterIntersection(const struct RTCIntersectFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs); +RTC_SYCL_API void rtcInvokeIntersectFilterFromGeometry(const struct RTCIntersectFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs); /* Invokes the occlusion filter from the occlusion callback function. */ -RTC_API void rtcFilterOcclusion(const struct RTCOccludedFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs); - +RTC_SYCL_API void rtcInvokeOccludedFilterFromGeometry(const struct RTCOccludedFunctionNArguments* args, const struct RTCFilterFunctionNArguments* filterArgs); /* Sets the instanced scene of an instance geometry. */ RTC_API void rtcSetGeometryInstancedScene(RTCGeometry geometry, RTCScene scene); +/* Sets the instanced scenes of an instance array geometry. */ +RTC_API void rtcSetGeometryInstancedScenes(RTCGeometry geometry, RTCScene* scenes, size_t numScenes); + /* Sets the transformation of an instance for the specified time step. */ RTC_API void rtcSetGeometryTransform(RTCGeometry geometry, unsigned int timeStep, enum RTCFormat format, const void* xfm); @@ -232,6 +232,12 @@ RTC_API void rtcSetGeometryTransformQuaternion(RTCGeometry geometry, unsigned in /* Returns the interpolated transformation of an instance for the specified time. */ RTC_API void rtcGetGeometryTransform(RTCGeometry geometry, float time, enum RTCFormat format, void* xfm); +/* + * Returns the interpolated transformation of the instPrimID'th instance of an + * instance array for the specified time. If geometry is an regular instance, + * instPrimID must be 0. + */ +RTC_API void rtcGetGeometryTransformEx(RTCGeometry geometry, unsigned int instPrimID, float time, enum RTCFormat format, void* xfm); /* Sets the uniform tessellation rate of the geometry. */ RTC_API void rtcSetGeometryTessellationRate(RTCGeometry geometry, float tessellationRate); diff --git a/thirdparty/embree/include/embree3/rtcore_quaternion.h b/thirdparty/embree/include/embree4/rtcore_quaternion.h similarity index 100% rename from thirdparty/embree/include/embree3/rtcore_quaternion.h rename to thirdparty/embree/include/embree4/rtcore_quaternion.h diff --git a/thirdparty/embree/include/embree3/rtcore_ray.h b/thirdparty/embree/include/embree4/rtcore_ray.h similarity index 85% rename from thirdparty/embree/include/embree3/rtcore_ray.h rename to thirdparty/embree/include/embree4/rtcore_ray.h index a2ee6dabbb9..7fc3f00cf94 100644 --- a/thirdparty/embree/include/embree3/rtcore_ray.h +++ b/thirdparty/embree/include/embree4/rtcore_ray.h @@ -39,6 +39,9 @@ struct RTC_ALIGN(16) RTCHit unsigned int primID; // primitive ID unsigned int geomID; // geometry ID unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID +#endif }; /* Combined ray/hit structure for a single ray */ @@ -80,6 +83,9 @@ struct RTC_ALIGN(16) RTCHit4 unsigned int primID[4]; unsigned int geomID[4]; unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][4]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][4]; +#endif }; /* Combined ray/hit structure for a packet of 4 rays */ @@ -121,6 +127,9 @@ struct RTC_ALIGN(32) RTCHit8 unsigned int primID[8]; unsigned int geomID[8]; unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][8]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][8]; +#endif }; /* Combined ray/hit structure for a packet of 8 rays */ @@ -162,6 +171,9 @@ struct RTC_ALIGN(64) RTCHit16 unsigned int primID[16]; unsigned int geomID[16]; unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][16]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][16]; +#endif }; /* Combined ray/hit structure for a packet of 16 rays */ @@ -171,47 +183,6 @@ struct RTCRayHit16 struct RTCHit16 hit; }; -/* Ray structure for a packet/stream of N rays in pointer SOA layout */ -struct RTCRayNp -{ - float* org_x; - float* org_y; - float* org_z; - float* tnear; - - float* dir_x; - float* dir_y; - float* dir_z; - float* time; - - float* tfar; - unsigned int* mask; - unsigned int* id; - unsigned int* flags; -}; - -/* Hit structure for a packet/stream of N rays in pointer SOA layout */ -struct RTCHitNp -{ - float* Ng_x; - float* Ng_y; - float* Ng_z; - - float* u; - float* v; - - unsigned int* primID; - unsigned int* geomID; - unsigned int* instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; -}; - -/* Combined ray/hit structure for a packet/stream of N rays in pointer SOA layout */ -struct RTCRayHitNp -{ - struct RTCRayNp ray; - struct RTCHitNp hit; -}; - struct RTCRayN; struct RTCHitN; struct RTCRayHitN; @@ -242,9 +213,12 @@ RTC_FORCEINLINE float& RTCHitN_Ng_z(RTCHitN* hit, unsigned int N, unsigned int i RTC_FORCEINLINE float& RTCHitN_u(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[3*N+i]; } RTC_FORCEINLINE float& RTCHitN_v(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[4*N+i]; } -RTC_FORCEINLINE unsigned int& RTCHitN_primID(RTCHitN* hit, unsigned int N, unsigned int i) { return ((unsigned*)hit)[5*N+i]; } -RTC_FORCEINLINE unsigned int& RTCHitN_geomID(RTCHitN* hit, unsigned int N, unsigned int i) { return ((unsigned*)hit)[6*N+i]; } -RTC_FORCEINLINE unsigned int& RTCHitN_instID(RTCHitN* hit, unsigned int N, unsigned int i, unsigned int l) { return ((unsigned*)hit)[7*N+i+N*l]; } +RTC_FORCEINLINE unsigned int& RTCHitN_primID (RTCHitN* hit, unsigned int N, unsigned int i) { return ((unsigned*)hit)[5*N+i]; } +RTC_FORCEINLINE unsigned int& RTCHitN_geomID (RTCHitN* hit, unsigned int N, unsigned int i) { return ((unsigned*)hit)[6*N+i]; } +RTC_FORCEINLINE unsigned int& RTCHitN_instID (RTCHitN* hit, unsigned int N, unsigned int i, unsigned int l) { return ((unsigned*)hit)[7*N + N*l + i]; } +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) +RTC_FORCEINLINE unsigned int& RTCHitN_instPrimID(RTCHitN* hit, unsigned int N, unsigned int i, unsigned int l) { return ((unsigned*)hit)[7*N + N*RTC_MAX_INSTANCE_LEVEL_COUNT + N*l + i]; } +#endif /* Helper functions to extract RTCRayN and RTCHitN from RTCRayHitN */ RTC_FORCEINLINE RTCRayN* RTCRayHitN_RayN(RTCRayHitN* rayhit, unsigned int N) { return (RTCRayN*)&((float*)rayhit)[0*N]; } @@ -284,6 +258,9 @@ struct RTCHitNt unsigned int primID[N]; unsigned int geomID[N]; unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][N]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][N]; +#endif }; /* Helper structure for a combined ray/hit packet of compile-time size N */ @@ -322,8 +299,12 @@ RTC_FORCEINLINE RTCHit rtcGetHitFromHitN(RTCHitN* hitN, unsigned int N, unsigned hit.v = RTCHitN_v(hitN,N,i); hit.primID = RTCHitN_primID(hitN,N,i); hit.geomID = RTCHitN_geomID(hitN,N,i); - for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) + for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) { hit.instID[l] = RTCHitN_instID(hitN,N,i,l); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + hit.instPrimID[l] = RTCHitN_instPrimID(hitN,N,i,l); +#endif + } return hit; } @@ -336,8 +317,12 @@ RTC_FORCEINLINE void rtcCopyHitToHitN(RTCHitN* hitN, const RTCHit* hit, unsigned RTCHitN_v(hitN,N,i) = hit->v; RTCHitN_primID(hitN,N,i) = hit->primID; RTCHitN_geomID(hitN,N,i) = hit->geomID; - for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) + for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) { RTCHitN_instID(hitN,N,i,l) = hit->instID[l]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + RTCHitN_instPrimID(hitN,N,i,l) = hit->instPrimID[l]; +#endif + } } RTC_FORCEINLINE RTCRayHit rtcGetRayHitFromRayHitN(RTCRayHitN* rayhitN, unsigned int N, unsigned int i) @@ -366,8 +351,12 @@ RTC_FORCEINLINE RTCRayHit rtcGetRayHitFromRayHitN(RTCRayHitN* rayhitN, unsigned rh.hit.v = RTCHitN_v(hit,N,i); rh.hit.primID = RTCHitN_primID(hit,N,i); rh.hit.geomID = RTCHitN_geomID(hit,N,i); - for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) + for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) { rh.hit.instID[l] = RTCHitN_instID(hit,N,i,l); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + rh.hit.instPrimID[l] = RTCHitN_instPrimID(hit,N,i,l); +#endif + } return rh; } diff --git a/thirdparty/embree/include/embree4/rtcore_scene.h b/thirdparty/embree/include/embree4/rtcore_scene.h new file mode 100644 index 00000000000..e37af4f9622 --- /dev/null +++ b/thirdparty/embree/include/embree4/rtcore_scene.h @@ -0,0 +1,252 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "rtcore_device.h" + +RTC_NAMESPACE_BEGIN + +/* Forward declarations for ray structures */ +struct RTCRayHit; +struct RTCRayHit4; +struct RTCRayHit8; +struct RTCRayHit16; + +/* Scene flags */ +enum RTCSceneFlags +{ + RTC_SCENE_FLAG_NONE = 0, + RTC_SCENE_FLAG_DYNAMIC = (1 << 0), + RTC_SCENE_FLAG_COMPACT = (1 << 1), + RTC_SCENE_FLAG_ROBUST = (1 << 2), + RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS = (1 << 3) +}; + +/* Additional arguments for rtcIntersect1/4/8/16 calls */ +struct RTCIntersectArguments +{ + enum RTCRayQueryFlags flags; // intersection flags + enum RTCFeatureFlags feature_mask; // selectively enable features for traversal + struct RTCRayQueryContext* context; // optional pointer to ray query context + RTCFilterFunctionN filter; // filter function to execute + RTCIntersectFunctionN intersect; // user geometry intersection callback to execute +#if RTC_MIN_WIDTH + float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin +#endif +}; + +/* Initializes intersection arguments. */ +RTC_FORCEINLINE void rtcInitIntersectArguments(struct RTCIntersectArguments* args) +{ + args->flags = RTC_RAY_QUERY_FLAG_INCOHERENT; + args->feature_mask = RTC_FEATURE_FLAG_ALL; + args->context = NULL; + args->filter = NULL; + args->intersect = NULL; + +#if RTC_MIN_WIDTH + args->minWidthDistanceFactor = 0.0f; +#endif +} + +/* Additional arguments for rtcOccluded1/4/8/16 calls */ +struct RTCOccludedArguments +{ + enum RTCRayQueryFlags flags; // intersection flags + enum RTCFeatureFlags feature_mask; // selectively enable features for traversal + struct RTCRayQueryContext* context; // optional pointer to ray query context + RTCFilterFunctionN filter; // filter function to execute + RTCOccludedFunctionN occluded; // user geometry occlusion callback to execute + +#if RTC_MIN_WIDTH + float minWidthDistanceFactor; // curve radius is set to this factor times distance to ray origin +#endif +}; + +/* Initializes an intersection arguments. */ +RTC_FORCEINLINE void rtcInitOccludedArguments(struct RTCOccludedArguments* args) +{ + args->flags = RTC_RAY_QUERY_FLAG_INCOHERENT; + args->feature_mask = RTC_FEATURE_FLAG_ALL; + args->context = NULL; + args->filter = NULL; + args->occluded = NULL; + +#if RTC_MIN_WIDTH + args->minWidthDistanceFactor = 0.0f; +#endif +} + +/* Creates a new scene. */ +RTC_API RTCScene rtcNewScene(RTCDevice device); + +/* Returns the device the scene got created in. The reference count of + * the device is incremented by this function. */ +RTC_API RTCDevice rtcGetSceneDevice(RTCScene hscene); + +/* Retains the scene (increments the reference count). */ +RTC_API void rtcRetainScene(RTCScene scene); + +/* Releases the scene (decrements the reference count). */ +RTC_API void rtcReleaseScene(RTCScene scene); + + +/* Attaches the geometry to a scene. */ +RTC_API unsigned int rtcAttachGeometry(RTCScene scene, RTCGeometry geometry); + +/* Attaches the geometry to a scene using the specified geometry ID. */ +RTC_API void rtcAttachGeometryByID(RTCScene scene, RTCGeometry geometry, unsigned int geomID); + +/* Detaches the geometry from the scene. */ +RTC_API void rtcDetachGeometry(RTCScene scene, unsigned int geomID); + +/* Gets a geometry handle from the scene. This function is not thread safe and should get used during rendering. */ +RTC_API RTCGeometry rtcGetGeometry(RTCScene scene, unsigned int geomID); + +/* Gets a geometry handle from the scene. This function is thread safe and should NOT get used during rendering. */ +RTC_API RTCGeometry rtcGetGeometryThreadSafe(RTCScene scene, unsigned int geomID); + +/* Gets the user-defined data pointer of the geometry. This function is not thread safe and should get used during rendering. */ +RTC_SYCL_API void* rtcGetGeometryUserDataFromScene(RTCScene scene, unsigned int geomID); + +/* Returns the interpolated transformation of an instance for the specified time. */ +RTC_SYCL_API void rtcGetGeometryTransformFromScene(RTCScene scene, unsigned int geomID, float time, enum RTCFormat format, void* xfm); + + +/* Commits the scene. */ +RTC_API void rtcCommitScene(RTCScene scene); + +/* Commits the scene from multiple threads. */ +RTC_API void rtcJoinCommitScene(RTCScene scene); + + +/* Progress monitor callback function */ +typedef bool (*RTCProgressMonitorFunction)(void* ptr, double n); + +/* Sets the progress monitor callback function of the scene. */ +RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene scene, RTCProgressMonitorFunction progress, void* ptr); + +/* Sets the build quality of the scene. */ +RTC_API void rtcSetSceneBuildQuality(RTCScene scene, enum RTCBuildQuality quality); + +/* Sets the scene flags. */ +RTC_API void rtcSetSceneFlags(RTCScene scene, enum RTCSceneFlags flags); + +/* Returns the scene flags. */ +RTC_API enum RTCSceneFlags rtcGetSceneFlags(RTCScene scene); + +/* Returns the axis-aligned bounds of the scene. */ +RTC_API void rtcGetSceneBounds(RTCScene scene, struct RTCBounds* bounds_o); + +/* Returns the linear axis-aligned bounds of the scene. */ +RTC_API void rtcGetSceneLinearBounds(RTCScene scene, struct RTCLinearBounds* bounds_o); + + +/* Perform a closest point query of the scene. */ +RTC_API bool rtcPointQuery(RTCScene scene, struct RTCPointQuery* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void* userPtr); + +/* Perform a closest point query with a packet of 4 points with the scene. */ +RTC_API bool rtcPointQuery4(const int* valid, RTCScene scene, struct RTCPointQuery4* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr); + +/* Perform a closest point query with a packet of 4 points with the scene. */ +RTC_API bool rtcPointQuery8(const int* valid, RTCScene scene, struct RTCPointQuery8* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr); + +/* Perform a closest point query with a packet of 4 points with the scene. */ +RTC_API bool rtcPointQuery16(const int* valid, RTCScene scene, struct RTCPointQuery16* query, struct RTCPointQueryContext* context, RTCPointQueryFunction queryFunc, void** userPtr); + + +/* Intersects a single ray with the scene. */ +RTC_SYCL_API void rtcIntersect1(RTCScene scene, struct RTCRayHit* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT); + +/* Intersects a packet of 4 rays with the scene. */ +RTC_API void rtcIntersect4(const int* valid, RTCScene scene, struct RTCRayHit4* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT); + +/* Intersects a packet of 8 rays with the scene. */ +RTC_API void rtcIntersect8(const int* valid, RTCScene scene, struct RTCRayHit8* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT); + +/* Intersects a packet of 16 rays with the scene. */ +RTC_API void rtcIntersect16(const int* valid, RTCScene scene, struct RTCRayHit16* rayhit, struct RTCIntersectArguments* args RTC_OPTIONAL_ARGUMENT); + + +/* Forwards ray inside user geometry callback. */ +RTC_SYCL_API void rtcForwardIntersect1(const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID); + +/* Forwards ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_SYCL_API void rtcForwardIntersect1Ex(const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID); + +/* Forwards ray packet of size 4 inside user geometry callback. */ +RTC_API void rtcForwardIntersect4(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID); + +/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_API void rtcForwardIntersect4Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID, unsigned int primInstID); + +/* Forwards ray packet of size 8 inside user geometry callback. */ +RTC_API void rtcForwardIntersect8(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID); + +/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_API void rtcForwardIntersect8Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID, unsigned int primInstID); + +/* Forwards ray packet of size 16 inside user geometry callback. */ +RTC_API void rtcForwardIntersect16(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID); + +/* Forwards ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_API void rtcForwardIntersect16Ex(const int* valid, const struct RTCIntersectFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID, unsigned int primInstID); + + +/* Tests a single ray for occlusion with the scene. */ +RTC_SYCL_API void rtcOccluded1(RTCScene scene, struct RTCRay* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT); + +/* Tests a packet of 4 rays for occlusion occluded with the scene. */ +RTC_API void rtcOccluded4(const int* valid, RTCScene scene, struct RTCRay4* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT); + +/* Tests a packet of 8 rays for occlusion with the scene. */ +RTC_API void rtcOccluded8(const int* valid, RTCScene scene, struct RTCRay8* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT); + +/* Tests a packet of 16 rays for occlusion with the scene. */ +RTC_API void rtcOccluded16(const int* valid, RTCScene scene, struct RTCRay16* ray, struct RTCOccludedArguments* args RTC_OPTIONAL_ARGUMENT); + + +/* Forwards single occlusion ray inside user geometry callback. */ +RTC_SYCL_API void rtcForwardOccluded1(const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID); + +/* Forwards single occlusion ray inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_SYCL_API void rtcForwardOccluded1Ex(const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay* ray, unsigned int instID, unsigned int instPrimID); + +/* Forwards occlusion ray packet of size 4 inside user geometry callback. */ +RTC_API void rtcForwardOccluded4(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID); + +/* Forwards occlusion ray packet of size 4 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_API void rtcForwardOccluded4Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay4* ray, unsigned int instID, unsigned int instPrimID); + +/* Forwards occlusion ray packet of size 8 inside user geometry callback. */ +RTC_API void rtcForwardOccluded8(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID); + +/* Forwards occlusion ray packet of size 8 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_API void rtcForwardOccluded8Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay8* ray, unsigned int instID, unsigned int instPrimID); + +/* Forwards occlusion ray packet of size 16 inside user geometry callback. */ +RTC_API void rtcForwardOccluded16(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID); + +/* Forwards occlusion ray packet of size 16 inside user geometry callback. Extended to handle instance arrays using instPrimID parameter. */ +RTC_API void rtcForwardOccluded16Ex(const int* valid, const struct RTCOccludedFunctionNArguments* args, RTCScene scene, struct RTCRay16* ray, unsigned int instID, unsigned int instPrimID); + + +/*! collision callback */ +struct RTCCollision { unsigned int geomID0; unsigned int primID0; unsigned int geomID1; unsigned int primID1; }; +typedef void (*RTCCollideFunc) (void* userPtr, struct RTCCollision* collisions, unsigned int num_collisions); + +/*! Performs collision detection of two scenes */ +RTC_API void rtcCollide (RTCScene scene0, RTCScene scene1, RTCCollideFunc callback, void* userPtr); + +#if defined(__cplusplus) + +/* Helper for easily combining scene flags */ +inline RTCSceneFlags operator|(RTCSceneFlags a, RTCSceneFlags b) { + return (RTCSceneFlags)((size_t)a | (size_t)b); +} + +#endif + +RTC_NAMESPACE_END + diff --git a/thirdparty/embree/kernels/builders/bvh_builder_morton.h b/thirdparty/embree/kernels/builders/bvh_builder_morton.h index cba32ca73cc..87d47868101 100644 --- a/thirdparty/embree/kernels/builders/bvh_builder_morton.h +++ b/thirdparty/embree/kernels/builders/bvh_builder_morton.h @@ -5,6 +5,7 @@ #include "../common/builder.h" #include "../../common/algorithms/parallel_reduce.h" +#include "../../common/algorithms/parallel_sort.h" namespace embree { @@ -101,7 +102,7 @@ namespace embree } }; -#if defined (__AVX2__) +#if defined (__AVX2__) || defined(__SYCL_DEVICE_ONLY__) /*! for AVX2 there is a fast scalar bitInterleave */ struct MortonCodeGenerator diff --git a/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h b/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h index 6e73c0d250f..d4e3388db55 100644 --- a/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h +++ b/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h @@ -7,7 +7,7 @@ #define MBLUR_NUM_OBJECT_BINS 32 #include "../bvh/bvh.h" -#include "../common/primref_mb.h" +#include "../builders/primref_mb.h" #include "heuristic_binning_array_aligned.h" #include "heuristic_timesplit_array.h" @@ -141,16 +141,17 @@ namespace embree struct VirtualRecalculatePrimRef { Scene* scene; + const SubGridBuildData * const sgrids; - __forceinline VirtualRecalculatePrimRef (Scene* scene) - : scene(scene) {} + __forceinline VirtualRecalculatePrimRef (Scene* scene, const SubGridBuildData * const sgrids = nullptr) + : scene(scene), sgrids(sgrids) {} __forceinline PrimRefMB operator() (const PrimRefMB& prim, const BBox1f time_range) const { const unsigned geomID = prim.geomID(); const unsigned primID = prim.primID(); const Geometry* mesh = scene->get(geomID); - const LBBox3fa lbounds = mesh->vlinearBounds(primID, time_range); + const LBBox3fa lbounds = mesh->vlinearBounds(primID, time_range, sgrids); const range tbounds = mesh->timeSegmentRange(time_range); return PrimRefMB (lbounds, tbounds.size(), mesh->time_range, mesh->numTimeSegments(), geomID, primID); } @@ -166,7 +167,7 @@ namespace embree } __forceinline LBBox3fa linearBounds(const PrimRefMB& prim, const BBox1f time_range) const { - return scene->get(prim.geomID())->vlinearBounds(prim.primID(), time_range); + return scene->get(prim.geomID())->vlinearBounds(prim.primID(), time_range, sgrids); } __forceinline LBBox3fa linearBounds(const PrimRefMB& prim, const BBox1f time_range, const LinearSpace3fa& space) const { diff --git a/thirdparty/embree/kernels/builders/bvh_builder_sah.h b/thirdparty/embree/kernels/builders/bvh_builder_sah.h index 24c5faf8be1..7a0c0bdb8ec 100644 --- a/thirdparty/embree/kernels/builders/bvh_builder_sah.h +++ b/thirdparty/embree/kernels/builders/bvh_builder_sah.h @@ -7,13 +7,8 @@ #include "heuristic_spatial_array.h" #include "heuristic_openmerge_array.h" -#if defined(__AVX512F__) && !defined(__AVX512VL__) // KNL -# define NUM_OBJECT_BINS 16 -# define NUM_SPATIAL_BINS 16 -#else -# define NUM_OBJECT_BINS 32 -# define NUM_SPATIAL_BINS 16 -#endif +#define NUM_OBJECT_BINS 32 +#define NUM_SPATIAL_BINS 16 namespace embree { diff --git a/thirdparty/embree/kernels/builders/heuristic_binning.h b/thirdparty/embree/kernels/builders/heuristic_binning.h index 41be6183b8a..d66726d09bc 100644 --- a/thirdparty/embree/kernels/builders/heuristic_binning.h +++ b/thirdparty/embree/kernels/builders/heuristic_binning.h @@ -4,6 +4,7 @@ #pragma once #include "priminfo.h" +#include "priminfo_mb.h" #include "../../common/algorithms/parallel_reduce.h" #include "../../common/algorithms/parallel_partition.h" @@ -390,6 +391,63 @@ namespace embree } return Split(bestSAH,bestDim,bestPos,mapping); } + + /*! finds the best split by scanning binning information */ + __forceinline Split best_block_size(const BinMapping& mapping, const size_t blockSize) const + { + /* sweep from right to left and compute parallel prefix of merged bounds */ + vfloat4 rAreas[BINS]; + vuint4 rCounts[BINS]; + vuint4 count = 0; BBox bx = empty; BBox by = empty; BBox bz = empty; + for (size_t i=mapping.size()-1; i>0; i--) + { + count += counts(i); + rCounts[i] = count; + bx.extend(bounds(i,0)); rAreas[i][0] = expectedApproxHalfArea(bx); + by.extend(bounds(i,1)); rAreas[i][1] = expectedApproxHalfArea(by); + bz.extend(bounds(i,2)); rAreas[i][2] = expectedApproxHalfArea(bz); + rAreas[i][3] = 0.0f; + } + /* sweep from left to right and compute SAH */ + vuint4 blocks_add = blockSize-1; + vfloat4 blocks_factor = 1.0f/float(blockSize); + vuint4 ii = 1; vfloat4 vbestSAH = pos_inf; vuint4 vbestPos = 0; + count = 0; bx = empty; by = empty; bz = empty; + for (size_t i=1; i& mapping, const Split& split, SplitInfoT& info) const diff --git a/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h b/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h index ab3b97efb92..51dda9b49db 100644 --- a/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h +++ b/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h @@ -22,6 +22,9 @@ namespace embree __forceinline PrimInfoRange (size_t begin, size_t end, const CentGeomBBox3fa& centGeomBounds) : CentGeomBBox3fa(centGeomBounds), range(begin,end) {} + + __forceinline PrimInfoRange (range r, const CentGeomBBox3fa& centGeomBounds) + : CentGeomBBox3fa(centGeomBounds), range(r) {} __forceinline float leafSAH() const { return expectedApproxHalfArea(geomBounds)*float(size()); @@ -30,7 +33,45 @@ namespace embree __forceinline float leafSAH(size_t block_shift) const { return expectedApproxHalfArea(geomBounds)*float((size()+(size_t(1)<> block_shift); } + + __forceinline range get_range() const { + return range(begin(),end()); + } + + template + __forceinline void add_primref(const PrimRef& prim) + { + CentGeomBBox3fa::extend_primref(prim); + _end++; + } }; + + inline void performFallbackSplit(PrimRef* const prims, const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) + { + const size_t begin = pinfo.begin(); + const size_t end = pinfo.end(); + const size_t center = (begin + end)/2; + + CentGeomBBox3fa left(empty); + for (size_t i=begin; i + inline void performTypeSplit(const getTypeFunc& getType, Type type, PrimRef* const prims, range range, PrimInfoRange& linfo, PrimInfoRange& rinfo) + { + CentGeomBBox3fa local_left(empty), local_right(empty); + auto isLeft = [&] (const PrimRef& ref) { return type == getType(ref.geomID()); }; + const size_t center = serial_partitioning(prims,range.begin(),range.end(),local_left,local_right,isLeft,CentGeomBBox3fa::extend_ref); + linfo = PrimInfoRange(make_range(range.begin(),center ),local_left); + rinfo = PrimInfoRange(make_range(center ,range.end()),local_right); + } /*! Performs standard object binning */ template @@ -69,6 +110,24 @@ namespace embree return binner.best(mapping,logBlockSize); } + /*! finds the best split */ + __noinline const Split find_block_size(const PrimInfoRange& pinfo, const size_t blockSize) + { + if (likely(pinfo.size() < PARALLEL_THRESHOLD)) + return find_block_size_template(pinfo,blockSize); + else + return find_block_size_template(pinfo,blockSize); + } + + template + __forceinline const Split find_block_size_template(const PrimInfoRange& pinfo, const size_t blockSize) + { + Binner binner(empty); + const BinMapping mapping(pinfo); + bin_serial_or_parallel(binner,prims,pinfo.begin(),pinfo.end(),PARALLEL_FIND_BLOCK_SIZE,mapping); + return binner.best_block_size(mapping,blockSize); + } + /*! array partitioning */ __forceinline void split(const Split& split, const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) { @@ -121,21 +180,8 @@ namespace embree std::sort(&prims[pinfo.begin()],&prims[pinfo.end()]); } - void splitFallback(const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) - { - const size_t begin = pinfo.begin(); - const size_t end = pinfo.end(); - const size_t center = (begin + end)/2; - - CentGeomBBox3fa left(empty); - for (size_t i=begin; i& range, PrimInfoRange& linfo, PrimInfoRange& rinfo) @@ -156,6 +202,8 @@ namespace embree PrimRef* const prims; }; +#if !defined(RTHWIF_STANDALONE) + /*! Performs standard object binning */ template struct HeuristicArrayBinningMB @@ -196,5 +244,6 @@ namespace embree new (&rset) SetMB(right,set.prims,range(center,end ),set.time_range); } }; +#endif } } diff --git a/thirdparty/embree/kernels/builders/heuristic_spatial.h b/thirdparty/embree/kernels/builders/heuristic_spatial.h index 8b3499ac8d2..25abf025aed 100644 --- a/thirdparty/embree/kernels/builders/heuristic_spatial.h +++ b/thirdparty/embree/kernels/builders/heuristic_spatial.h @@ -3,7 +3,6 @@ #pragma once -#include "../common/scene.h" #include "priminfo.h" namespace embree diff --git a/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h b/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h index b968e01c90e..fe97862eb6d 100644 --- a/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h +++ b/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h @@ -3,7 +3,7 @@ #pragma once -#include "../common/primref_mb.h" +#include "../builders/primref_mb.h" #include "../../common/algorithms/parallel_filter.h" #define MBLUR_TIME_SPLIT_THRESHOLD 1.25f diff --git a/thirdparty/embree/kernels/builders/priminfo.h b/thirdparty/embree/kernels/builders/priminfo.h index fee515247a3..52f035e869d 100644 --- a/thirdparty/embree/kernels/builders/priminfo.h +++ b/thirdparty/embree/kernels/builders/priminfo.h @@ -3,9 +3,7 @@ #pragma once -#include "../common/default.h" -#include "../common/primref.h" -#include "../common/primref_mb.h" +#include "primref.h" namespace embree { @@ -41,6 +39,10 @@ namespace embree centBounds.extend(center); } + static void extend_ref (CentGeom& pinfo, const PrimRef& ref) { + pinfo.extend_primref(ref); + }; + template __forceinline void extend_center2(const PrimRef& prim) { @@ -84,6 +86,9 @@ namespace embree __forceinline PrimInfoT (EmptyTy) : CentGeom(empty), begin(0), end(0) {} + __forceinline PrimInfoT (size_t N) + : CentGeom(empty), begin(0), end(N) {} + __forceinline PrimInfoT (size_t begin, size_t end, const CentGeomBBox3fa& centGeomBounds) : CentGeom(centGeomBounds), begin(begin), end(end) {} @@ -158,205 +163,5 @@ namespace embree typedef PrimInfoT PrimInfo; //typedef PrimInfoT PrimInfoMB; - - /*! stores bounding information for a set of primitives */ - template - class PrimInfoMBT : public CentGeom - { - public: - using CentGeom::geomBounds; - using CentGeom::centBounds; - - __forceinline PrimInfoMBT () { - } - - __forceinline PrimInfoMBT (EmptyTy) - : CentGeom(empty), object_range(0,0), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} - - __forceinline PrimInfoMBT (size_t begin, size_t end) - : CentGeom(empty), object_range(begin,end), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} - - template - __forceinline void add_primref(const PrimRef& prim) - { - CentGeom::extend_primref(prim); - time_range.extend(prim.time_range); - object_range._end++; - num_time_segments += prim.size(); - if (max_num_time_segments < prim.totalTimeSegments()) { - max_num_time_segments = prim.totalTimeSegments(); - max_time_range = prim.time_range; - } - } - - __forceinline void merge(const PrimInfoMBT& other) - { - CentGeom::merge(other); - time_range.extend(other.time_range); - object_range._begin += other.object_range.begin(); - object_range._end += other.object_range.end(); - num_time_segments += other.num_time_segments; - if (max_num_time_segments < other.max_num_time_segments) { - max_num_time_segments = other.max_num_time_segments; - max_time_range = other.max_time_range; - } - } - - static __forceinline const PrimInfoMBT merge2(const PrimInfoMBT& a, const PrimInfoMBT& b) { - PrimInfoMBT r = a; r.merge(b); return r; - } - - __forceinline size_t begin() const { - return object_range.begin(); - } - - __forceinline size_t end() const { - return object_range.end(); - } - - /*! returns the number of primitives */ - __forceinline size_t size() const { - return object_range.size(); - } - - __forceinline float halfArea() const { - return time_range.size()*expectedApproxHalfArea(geomBounds); - } - - __forceinline float leafSAH() const { - return time_range.size()*expectedApproxHalfArea(geomBounds)*float(num_time_segments); - } - - __forceinline float leafSAH(size_t block_shift) const { - return time_range.size()*expectedApproxHalfArea(geomBounds)*float((num_time_segments+(size_t(1)<> block_shift); - } - - __forceinline float align_time(float ct) const - { - //return roundf(ct * float(numTimeSegments)) / float(numTimeSegments); - float t0 = (ct-max_time_range.lower)/max_time_range.size(); - float t1 = roundf(t0 * float(max_num_time_segments)) / float(max_num_time_segments); - return t1*max_time_range.size()+max_time_range.lower; - } - - /*! stream output */ - friend embree_ostream operator<<(embree_ostream cout, const PrimInfoMBT& pinfo) - { - return cout << "PrimInfo { " << - "object_range = " << pinfo.object_range << - ", time_range = " << pinfo.time_range << - ", time_segments = " << pinfo.num_time_segments << - ", geomBounds = " << pinfo.geomBounds << - ", centBounds = " << pinfo.centBounds << - "}"; - } - - public: - range object_range; //!< primitive range - size_t num_time_segments; //!< total number of time segments of all added primrefs - size_t max_num_time_segments; //!< maximum number of time segments of a primitive - BBox1f max_time_range; //!< time range of primitive with max_num_time_segments - BBox1f time_range; //!< merged time range of primitives when merging prims, or additionally clipped with build time range when used in SetMB - }; - - typedef PrimInfoMBT PrimInfoMB; - - struct SetMB : public PrimInfoMB - { - static const size_t PARALLEL_THRESHOLD = 3 * 1024; - static const size_t PARALLEL_FIND_BLOCK_SIZE = 1024; - static const size_t PARALLEL_PARTITION_BLOCK_SIZE = 128; - - typedef mvector* PrimRefVector; - - __forceinline SetMB() {} - - __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims) - : PrimInfoMB(pinfo_i), prims(prims) {} - - __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, range object_range_in, BBox1f time_range_in) - : PrimInfoMB(pinfo_i), prims(prims) - { - object_range = object_range_in; - time_range = intersect(time_range,time_range_in); - } - - __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, BBox1f time_range_in) - : PrimInfoMB(pinfo_i), prims(prims) - { - time_range = intersect(time_range,time_range_in); - } - - void deterministic_order() const - { - /* required as parallel partition destroys original primitive order */ - PrimRefMB* prim = prims->data(); - std::sort(&prim[object_range.begin()],&prim[object_range.end()]); - } - - template - __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef) const - { - auto reduce = [&](const range& r) -> LBBox3fa - { - LBBox3fa cbounds(empty); - for (size_t j = r.begin(); j < r.end(); j++) - { - PrimRefMB& ref = (*prims)[j]; - const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range); - cbounds.extend(bn); - }; - return cbounds; - }; - - return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), - reduce, - [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); - } - - template - __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const - { - auto reduce = [&](const range& r) -> LBBox3fa - { - LBBox3fa cbounds(empty); - for (size_t j = r.begin(); j < r.end(); j++) - { - PrimRefMB& ref = (*prims)[j]; - const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range, space); - cbounds.extend(bn); - }; - return cbounds; - }; - - return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), - reduce, - [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); - } - - template - const SetMB primInfo(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const - { - auto computePrimInfo = [&](const range& r) -> PrimInfoMB - { - PrimInfoMB pinfo(empty); - for (size_t j=r.begin(); j + class PrimInfoMBT : public CentGeom + { + public: + using CentGeom::geomBounds; + using CentGeom::centBounds; + + __forceinline PrimInfoMBT () { + } + + __forceinline PrimInfoMBT (EmptyTy) + : CentGeom(empty), object_range(0,0), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} + + __forceinline PrimInfoMBT (size_t begin, size_t end) + : CentGeom(empty), object_range(begin,end), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} + + template + __forceinline void add_primref(const PrimRef& prim) + { + CentGeom::extend_primref(prim); + time_range.extend(prim.time_range); + object_range._end++; + num_time_segments += prim.size(); + if (max_num_time_segments < prim.totalTimeSegments()) { + max_num_time_segments = prim.totalTimeSegments(); + max_time_range = prim.time_range; + } + } + + __forceinline void merge(const PrimInfoMBT& other) + { + CentGeom::merge(other); + time_range.extend(other.time_range); + object_range._begin += other.object_range.begin(); + object_range._end += other.object_range.end(); + num_time_segments += other.num_time_segments; + if (max_num_time_segments < other.max_num_time_segments) { + max_num_time_segments = other.max_num_time_segments; + max_time_range = other.max_time_range; + } + } + + static __forceinline const PrimInfoMBT merge2(const PrimInfoMBT& a, const PrimInfoMBT& b) { + PrimInfoMBT r = a; r.merge(b); return r; + } + + __forceinline size_t begin() const { + return object_range.begin(); + } + + __forceinline size_t end() const { + return object_range.end(); + } + + /*! returns the number of primitives */ + __forceinline size_t size() const { + return object_range.size(); + } + + __forceinline float halfArea() const { + return time_range.size()*expectedApproxHalfArea(geomBounds); + } + + __forceinline float leafSAH() const { + return time_range.size()*expectedApproxHalfArea(geomBounds)*float(num_time_segments); + } + + __forceinline float leafSAH(size_t block_shift) const { + return time_range.size()*expectedApproxHalfArea(geomBounds)*float((num_time_segments+(size_t(1)<> block_shift); + } + + __forceinline float align_time(float ct) const + { + //return roundf(ct * float(numTimeSegments)) / float(numTimeSegments); + float t0 = (ct-max_time_range.lower)/max_time_range.size(); + float t1 = roundf(t0 * float(max_num_time_segments)) / float(max_num_time_segments); + return t1*max_time_range.size()+max_time_range.lower; + } + + /*! stream output */ + friend embree_ostream operator<<(embree_ostream cout, const PrimInfoMBT& pinfo) + { + return cout << "PrimInfo { " << + "object_range = " << pinfo.object_range << + ", time_range = " << pinfo.time_range << + ", time_segments = " << pinfo.num_time_segments << + ", geomBounds = " << pinfo.geomBounds << + ", centBounds = " << pinfo.centBounds << + "}"; + } + + public: + range object_range; //!< primitive range + size_t num_time_segments; //!< total number of time segments of all added primrefs + size_t max_num_time_segments; //!< maximum number of time segments of a primitive + BBox1f max_time_range; //!< time range of primitive with max_num_time_segments + BBox1f time_range; //!< merged time range of primitives when merging prims, or additionally clipped with build time range when used in SetMB + }; + + typedef PrimInfoMBT PrimInfoMB; + + struct SetMB : public PrimInfoMB + { + static const size_t PARALLEL_THRESHOLD = 3 * 1024; + static const size_t PARALLEL_FIND_BLOCK_SIZE = 1024; + static const size_t PARALLEL_PARTITION_BLOCK_SIZE = 128; + + typedef mvector* PrimRefVector; + + __forceinline SetMB() {} + + __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims) + : PrimInfoMB(pinfo_i), prims(prims) {} + + __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, range object_range_in, BBox1f time_range_in) + : PrimInfoMB(pinfo_i), prims(prims) + { + object_range = object_range_in; + time_range = intersect(time_range,time_range_in); + } + + __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, BBox1f time_range_in) + : PrimInfoMB(pinfo_i), prims(prims) + { + time_range = intersect(time_range,time_range_in); + } + + void deterministic_order() const + { + /* required as parallel partition destroys original primitive order */ + PrimRefMB* prim = prims->data(); + std::sort(&prim[object_range.begin()],&prim[object_range.end()]); + } + + template + __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef) const + { + auto reduce = [&](const range& r) -> LBBox3fa + { + LBBox3fa cbounds(empty); + for (size_t j = r.begin(); j < r.end(); j++) + { + PrimRefMB& ref = (*prims)[j]; + const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range); + cbounds.extend(bn); + }; + return cbounds; + }; + + return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), + reduce, + [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); + } + + template + __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const + { + auto reduce = [&](const range& r) -> LBBox3fa + { + LBBox3fa cbounds(empty); + for (size_t j = r.begin(); j < r.end(); j++) + { + PrimRefMB& ref = (*prims)[j]; + const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range, space); + cbounds.extend(bn); + }; + return cbounds; + }; + + return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), + reduce, + [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); + } + + template + const SetMB primInfo(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const + { + auto computePrimInfo = [&](const range& r) -> PrimInfoMB + { + PrimInfoMB pinfo(empty); + for (size_t j=r.begin(); j& prims, mvector& sgrids, BuildProgressMonitor& progressMonitor) + { + ParallelForForPrefixSumState pstate; + Scene::Iterator2 iter(scene,types,mblur); + + /* first try */ + progressMonitor(0); + pstate.init(iter,size_t(1024)); + PrimInfo pinfo = parallel_for_for_prefix_sum0( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range& r, size_t k, size_t geomID) -> PrimInfo { + return mesh->createPrimRefArray(prims,sgrids,r,k,(unsigned)geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + + /* if we need to filter out geometry, run again */ + if (pinfo.size() != numPrimRefs) + { + progressMonitor(0); + pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range& r, size_t k, size_t geomID, const PrimInfo& base) -> PrimInfo { + return mesh->createPrimRefArray(prims,sgrids,r,base.size(),(unsigned)geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + } + return pinfo; + } + PrimInfo createPrimRefArrayMBlur(Scene* scene, Geometry::GTypeMask types, const size_t numPrimRefs, mvector& prims, BuildProgressMonitor& progressMonitor, size_t itime) { ParallelForForPrefixSumState pstate; @@ -104,6 +127,32 @@ namespace embree return pinfo; } + PrimInfoMB createPrimRefArrayMSMBlur(Scene* scene, Geometry::GTypeMask types, const size_t numPrimRefs, mvector& prims, mvector& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1) + { + ParallelForForPrefixSumState pstate; + Scene::Iterator2 iter(scene,types,true); + + /* first try */ + progressMonitor(0); + pstate.init(iter,size_t(1024)); + PrimInfoMB pinfo = parallel_for_for_prefix_sum0( pstate, iter, PrimInfoMB(empty), [&](Geometry* mesh, const range& r, size_t k, size_t geomID) -> PrimInfoMB { + return mesh->createPrimRefMBArray(prims,sgrids,t0t1,r,k,(unsigned)geomID); + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + + /* if we need to filter out geometry, run again */ + if (pinfo.size() != numPrimRefs) + { + progressMonitor(0); + pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfoMB(empty), [&](Geometry* mesh, const range& r, size_t k, size_t geomID, const PrimInfoMB& base) -> PrimInfoMB { + return mesh->createPrimRefMBArray(prims,sgrids,t0t1,r,base.size(),(unsigned)geomID); + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + } + + /* the BVH starts with that time range, even though primitives might have smaller/larger time range */ + pinfo.time_range = t0t1; + return pinfo; + } + template size_t createMortonCodeArray(Mesh* mesh, mvector& morton, BuildProgressMonitor& progressMonitor) { @@ -218,26 +267,8 @@ namespace embree /* second run to fill primrefs and SubGridBuildData arrays */ pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfo(empty), [&](GridMesh* mesh, const range& r, size_t k, size_t geomID, const PrimInfo& base) -> PrimInfo { - k = base.size(); - size_t p_index = k; - PrimInfo pinfo(empty); - for (size_t j=r.begin(); jvalid(j)) continue; - const GridMesh::Grid &g = mesh->grid(j); - for (unsigned int y=0; ybuildBounds(g,x,y,bounds)) continue; // get bounds of subgrid - const PrimRef prim(bounds,(unsigned)geomID,(unsigned)p_index); - pinfo.add_center2(prim); - sgrids[p_index] = SubGridBuildData(x | g.get3x3FlagsX(x), y | g.get3x3FlagsY(y), unsigned(j)); - prims[p_index++] = prim; - } - } - return pinfo; - }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + return mesh->createPrimRefArray(prims,sgrids,r,base.size(),geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); assert(pinfo.size() == numPrimitives); return pinfo; } @@ -269,40 +300,60 @@ namespace embree prims.resize(numPrimitives); /* second run to fill primrefs and SubGridBuildData arrays */ - pinfo = parallel_prefix_sum( pstate, size_t(0), mesh->size(), size_t(1024), PrimInfo(empty), [&](const range& r, const PrimInfo& base) -> PrimInfo - { - - size_t p_index = base.size(); - PrimInfo pinfo(empty); - for (size_t j=r.begin(); jvalid(j)) continue; - const GridMesh::Grid &g = mesh->grid(j); - for (unsigned int y=0; ybuildBounds(g,x,y,bounds)) continue; // get bounds of subgrid - const PrimRef prim(bounds,geomID_,unsigned(p_index)); - pinfo.add_center2(prim); - sgrids[p_index] = SubGridBuildData(x | g.get3x3FlagsX(x), y | g.get3x3FlagsY(y), unsigned(j)); - prims[p_index++] = prim; - } - } - return pinfo; - }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + pinfo = parallel_prefix_sum( pstate, size_t(0), mesh->size(), size_t(1024), PrimInfo(empty), [&](const range& r, const PrimInfo& base) -> PrimInfo { + return mesh->createPrimRefArray(prims,sgrids,r,base.size(),geomID_); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); return pinfo; } + + PrimInfoMB createPrimRefArrayMSMBlurGrid(Scene* scene, mvector& prims, mvector& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1) + { + /* first run to get #primitives */ + ParallelForForPrefixSumState pstate; + Scene::Iterator iter(scene); + + pstate.init(iter,size_t(1024)); + /* iterate over all meshes in the scene */ + PrimInfoMB pinfoMB = parallel_for_for_prefix_sum0( pstate, iter, PrimInfoMB(empty), [&](GridMesh* mesh, const range& r, size_t k, size_t /*geomID*/) -> PrimInfoMB { + + PrimInfoMB pinfoMB(empty); + for (size_t j=r.begin(); jvalid(j, mesh->timeSegmentRange(t0t1))) continue; + LBBox3fa bounds(empty); + PrimInfoMB gridMB(0,mesh->getNumSubGrids(j)); + pinfoMB.merge(gridMB); + } + return pinfoMB; + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + + size_t numPrimitives = pinfoMB.size(); + if (numPrimitives == 0) return pinfoMB; + + /* resize arrays */ + sgrids.resize(numPrimitives); + prims.resize(numPrimitives); + /* second run to fill primrefs and SubGridBuildData arrays */ + pinfoMB = parallel_for_for_prefix_sum1( pstate, iter, PrimInfoMB(empty), [&](GridMesh* mesh, const range& r, size_t k, size_t geomID, const PrimInfoMB& base) -> PrimInfoMB { + return mesh->createPrimRefMBArray(prims,sgrids,t0t1,r,base.size(),(unsigned)geomID); + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + + assert(pinfoMB.size() == numPrimitives); + pinfoMB.time_range = t0t1; + return pinfoMB; + } + #endif // ==================================================================================================== // ==================================================================================================== // ==================================================================================================== - + IF_ENABLED_TRIS (template size_t createMortonCodeArray(TriangleMesh* mesh COMMA mvector& morton COMMA BuildProgressMonitor& progressMonitor)); IF_ENABLED_QUADS(template size_t createMortonCodeArray(QuadMesh* mesh COMMA mvector& morton COMMA BuildProgressMonitor& progressMonitor)); IF_ENABLED_USER (template size_t createMortonCodeArray(UserGeometry* mesh COMMA mvector& morton COMMA BuildProgressMonitor& progressMonitor)); IF_ENABLED_INSTANCE (template size_t createMortonCodeArray(Instance* mesh COMMA mvector& morton COMMA BuildProgressMonitor& progressMonitor)); + IF_ENABLED_INSTANCE_ARRAY (template size_t createMortonCodeArray(InstanceArray* mesh COMMA mvector& morton COMMA BuildProgressMonitor& progressMonitor)); } } diff --git a/thirdparty/embree/kernels/builders/primrefgen.h b/thirdparty/embree/kernels/builders/primrefgen.h index c09a848ba39..0e2ab094fba 100644 --- a/thirdparty/embree/kernels/builders/primrefgen.h +++ b/thirdparty/embree/kernels/builders/primrefgen.h @@ -4,9 +4,8 @@ #pragma once #include "../common/scene.h" -#include "../common/primref.h" -#include "../common/primref_mb.h" #include "priminfo.h" +#include "priminfo_mb.h" #include "bvh_builder_morton.h" namespace embree @@ -16,19 +15,23 @@ namespace embree PrimInfo createPrimRefArray(Geometry* geometry, unsigned int geomID, size_t numPrimitives, mvector& prims, BuildProgressMonitor& progressMonitor); PrimInfo createPrimRefArray(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimitives, mvector& prims, BuildProgressMonitor& progressMonitor); + + PrimInfo createPrimRefArray(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimitives, mvector& prims, mvector& sgrids, BuildProgressMonitor& progressMonitor); PrimInfo createPrimRefArrayMBlur(Scene* scene, Geometry::GTypeMask types, size_t numPrimitives, mvector& prims, BuildProgressMonitor& progressMonitor, size_t itime = 0); PrimInfoMB createPrimRefArrayMSMBlur(Scene* scene, Geometry::GTypeMask types, size_t numPrimitives, mvector& prims, BuildProgressMonitor& progressMonitor, BBox1f t0t1 = BBox1f(0.0f,1.0f)); + PrimInfoMB createPrimRefArrayMSMBlur(Scene* scene, Geometry::GTypeMask types, size_t numPrimitives, mvector& prims, mvector& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1 = BBox1f(0.0f,1.0f)); + template size_t createMortonCodeArray(Mesh* mesh, mvector& morton, BuildProgressMonitor& progressMonitor); /* special variants for grids */ - PrimInfo createPrimRefArrayGrids(Scene* scene, mvector& prims, mvector& sgrids); + PrimInfo createPrimRefArrayGrids(Scene* scene, mvector& prims, mvector& sgrids); // FIXME: remove PrimInfo createPrimRefArrayGrids(GridMesh* mesh, mvector& prims, mvector& sgrids); - + + PrimInfoMB createPrimRefArrayMSMBlurGrid(Scene* scene, mvector& prims, mvector& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1 = BBox1f(0.0f,1.0f)); } } - diff --git a/thirdparty/embree/kernels/builders/primrefgen_presplit.h b/thirdparty/embree/kernels/builders/primrefgen_presplit.h index aa2026a85ef..db9010995d3 100644 --- a/thirdparty/embree/kernels/builders/primrefgen_presplit.h +++ b/thirdparty/embree/kernels/builders/primrefgen_presplit.h @@ -3,10 +3,12 @@ #pragma once -#include "../builders/primrefgen.h" +#include "../../common/algorithms/parallel_reduce.h" +#include "../../common/algorithms/parallel_sort.h" #include "../builders/heuristic_spatial.h" #include "../builders/splitter.h" +#include "../../common/algorithms/parallel_partition.h" #include "../../common/algorithms/parallel_for_for.h" #include "../../common/algorithms/parallel_for_for_prefix_sum.h" @@ -14,96 +16,46 @@ #define CHECK_PRESPLIT(x) #define GRID_SIZE 1024 +//#define MAX_PRESPLITS_PER_PRIMITIVE_LOG 6 #define MAX_PRESPLITS_PER_PRIMITIVE_LOG 5 #define MAX_PRESPLITS_PER_PRIMITIVE (1<(priority); - } - __forceinline bool operator < (const PresplitItem& item) const - { - return (priority < item.priority); + base = bounds.lower; + const Vec3fa diag = bounds.size(); + extend = max(diag.x,max(diag.y,diag.z)); + scale = extend == 0.0f ? 0.0f : GRID_SIZE / extend; } - template - __forceinline static float compute_priority(const PrimRef &ref, Scene *scene, const Vec2i &mc) - { - const unsigned int geomID = ref.geomID(); - const unsigned int primID = ref.primID(); - const float area_aabb = area(ref.bounds()); - const float area_prim = ((Mesh*)scene->get(geomID))->projectedPrimitiveArea(primID); - const unsigned int diff = 31 - lzcnt(mc.x^mc.y); - assert(area_prim <= area_aabb); - //const float priority = powf((area_aabb - area_prim) * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff),1.0f/4.0f); - const float priority = sqrtf(sqrtf( (area_aabb - area_prim) * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff) )); - assert(priority >= 0.0f && priority < FLT_LARGE); - return priority; - } - - - }; - - inline std::ostream &operator<<(std::ostream &cout, const PresplitItem& item) { - return cout << "index " << item.index << " priority " << item.priority; - }; - - template - void splitPrimitive(SplitterFactory &Splitter, - const PrimRef &prim, - const unsigned int geomID, - const unsigned int primID, - const unsigned int split_level, - const Vec3fa &grid_base, - const float grid_scale, - const float grid_extend, - PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], - unsigned int& numSubPrims) - { - assert(split_level <= MAX_PRESPLITS_PER_PRIMITIVE_LOG); - if (split_level == 0) - { - assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); - subPrims[numSubPrims++] = prim; - } - else + __forceinline bool split_pos(const PrimRef& prim, unsigned int& dim_o, float& fsplit_o) const { + /* compute morton code */ const Vec3fa lower = prim.lower; const Vec3fa upper = prim.upper; - const Vec3fa glower = (lower-grid_base)*Vec3fa(grid_scale)+Vec3fa(0.2f); - const Vec3fa gupper = (upper-grid_base)*Vec3fa(grid_scale)-Vec3fa(0.2f); + const Vec3fa glower = (lower-base)*Vec3fa(scale)+Vec3fa(0.2f); + const Vec3fa gupper = (upper-base)*Vec3fa(scale)-Vec3fa(0.2f); Vec3ia ilower(floor(glower)); Vec3ia iupper(floor(gupper)); - + /* this ignores dimensions that are empty */ - iupper = (Vec3ia)(select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper))); - + iupper = (Vec3ia)select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper)); + /* compute a morton code for the lower and upper grid coordinates. */ const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); - + /* if all bits are equal then we cannot split */ - if(unlikely(lower_code == upper_code)) - { - assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); - subPrims[numSubPrims++] = prim; - return; - } + if (unlikely(lower_code == upper_code)) + return false; /* compute octree level and dimension to perform the split in */ const unsigned int diff = 31 - lzcnt(lower_code^upper_code); @@ -115,25 +67,166 @@ namespace embree /* compute world space position of split */ const float inv_grid_size = 1.0f / GRID_SIZE; - const float fsplit = grid_base[dim] + isplit * inv_grid_size * grid_extend; + const float fsplit = base[dim] + isplit * inv_grid_size * extend; + assert(prim.lower[dim] <= fsplit && prim.upper[dim] >= fsplit); - assert(prim.lower[dim] <= fsplit && - prim.upper[dim] >= fsplit); - + dim_o = dim; + fsplit_o = fsplit; + return true; + } + + __forceinline Vec2i computeMC(const PrimRef& ref) const + { + const Vec3fa lower = ref.lower; + const Vec3fa upper = ref.upper; + const Vec3fa glower = (lower-base)*Vec3fa(scale)+Vec3fa(0.2f); + const Vec3fa gupper = (upper-base)*Vec3fa(scale)-Vec3fa(0.2f); + Vec3ia ilower(floor(glower)); + Vec3ia iupper(floor(gupper)); + + /* this ignores dimensions that are empty */ + iupper = (Vec3ia)select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper)); + + /* compute a morton code for the lower and upper grid coordinates. */ + const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); + const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); + return Vec2i(lower_code,upper_code); + } + + Vec3fa base; + float scale; + float extend; + }; + + struct PresplitItem + { + union { + float priority; + unsigned int data; + }; + unsigned int index; + + __forceinline operator unsigned() const { + return data; + } + + template + __forceinline static float compute_priority(const ProjectedPrimitiveAreaFunc& primitiveArea, const PrimRef &ref, const Vec2i &mc) + { + const float area_aabb = area(ref.bounds()); + const float area_prim = primitiveArea(ref); + if (area_prim == 0.0f) return 0.0f; + const unsigned int diff = 31 - lzcnt(mc.x^mc.y); + //assert(area_prim <= area_aabb); // may trigger due to numerical issues + const float area_diff = max(0.0f, area_aabb - area_prim); + //const float priority = powf(area_diff * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff),1.0f/4.0f); + const float priority = sqrtf(sqrtf( area_diff * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff) )); + //const float priority = sqrtf(sqrtf( area_diff ) ); + //const float priority = sqrtfarea_diff; + //const float priority = area_diff; // 104 fps !!!!!!!!!! + //const float priority = 0.2f*area_aabb + 0.8f*area_diff; // 104 fps + //const float priority = area_aabb * max(area_aabb/area_prim,32.0f); + //const float priority = area_prim; + assert(priority >= 0.0f && priority < FLT_LARGE); + return priority; + } + + }; + + inline std::ostream &operator<<(std::ostream &cout, const PresplitItem& item) { + return cout << "index " << item.index << " priority " << item.priority; + }; + +#if 1 + + template + void splitPrimitive(const Splitter& splitter, + const PrimRef& prim, + const unsigned int splitprims, + const SplittingGrid& grid, + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], + unsigned int& numSubPrims) + { + assert(splitprims > 0 && splitprims <= MAX_PRESPLITS_PER_PRIMITIVE); + + if (splitprims == 1) + { + assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); + subPrims[numSubPrims++] = prim; + } + else + { + unsigned int dim; float fsplit; + if (!grid.split_pos(prim, dim, fsplit)) + { + assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); + subPrims[numSubPrims++] = prim; + return; + } + /* split primitive */ - const auto splitter = Splitter(prim); - BBox3fa left,right; - splitter(prim.bounds(),dim,fsplit,left,right); - assert(!left.empty()); - assert(!right.empty()); + PrimRef left,right; + splitter(prim,dim,fsplit,left,right); + assert(!left.bounds().empty()); + assert(!right.bounds().empty()); - - splitPrimitive(Splitter,PrimRef(left ,geomID,primID),geomID,primID,split_level-1,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); - splitPrimitive(Splitter,PrimRef(right,geomID,primID),geomID,primID,split_level-1,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); + const unsigned int splitprims_left = splitprims/2; + const unsigned int splitprims_right = splitprims - splitprims_left; + splitPrimitive(splitter,left,splitprims_left,grid,subPrims,numSubPrims); + splitPrimitive(splitter,right,splitprims_right,grid,subPrims,numSubPrims); + } + } + +#else + + template + void splitPrimitive(const Splitter& splitter, + const PrimRef& prim, + const unsigned int targetSubPrims, + const SplittingGrid& grid, + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], + unsigned int& numSubPrims) + { + assert(targetSubPrims > 0 && targetSubPrims <= MAX_PRESPLITS_PER_PRIMITIVE); + + auto compare = [] ( const PrimRef& a, const PrimRef& b ) { + return area(a.bounds()) < area(b.bounds()); + }; + + subPrims[numSubPrims++] = prim; + + while (numSubPrims < targetSubPrims) + { + /* get top heap element */ + std::pop_heap(subPrims+0,subPrims+numSubPrims, compare); + PrimRef top = subPrims[--numSubPrims]; + + unsigned int dim; float fsplit; + if (!grid.split_pos(top, dim, fsplit)) + { + assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); + subPrims[numSubPrims++] = top; + return; + } + + /* split primitive */ + PrimRef left,right; + splitter(top,dim,fsplit,left,right); + assert(!left.bounds().empty()); + assert(!right.bounds().empty()); + + subPrims[numSubPrims++] = left; + std::push_heap(subPrims+0, subPrims+numSubPrims, compare); + + subPrims[numSubPrims++] = right; + std::push_heap(subPrims+0, subPrims+numSubPrims, compare); } } - +#endif + +#if !defined(RTHWIF_STANDALONE) + template PrimInfo createPrimRefArray_presplit(Geometry* geometry, unsigned int geomID, size_t numPrimRefs, mvector& prims, BuildProgressMonitor& progressMonitor) { @@ -155,30 +248,181 @@ namespace embree } return pinfo; } +#endif - __forceinline Vec2i computeMC(const Vec3fa &grid_base, const float grid_scale, const PrimRef &ref) + template + PrimInfo createPrimRefArray_presplit(size_t numPrimRefs, + PrimVector& prims, + const PrimInfo& pinfo, + const SplitPrimitiveFunc& splitPrimitive, + const ProjectedPrimitiveAreaFunc& primitiveArea) { - const Vec3fa lower = ref.lower; - const Vec3fa upper = ref.upper; - const Vec3fa glower = (lower-grid_base)*Vec3fa(grid_scale)+Vec3fa(0.2f); - const Vec3fa gupper = (upper-grid_base)*Vec3fa(grid_scale)-Vec3fa(0.2f); - Vec3ia ilower(floor(glower)); - Vec3ia iupper(floor(gupper)); - - /* this ignores dimensions that are empty */ - iupper = (Vec3ia)select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper)); - - /* compute a morton code for the lower and upper grid coordinates. */ - const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); - const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); - return Vec2i(lower_code,upper_code); - } - - template - PrimInfo createPrimRefArray_presplit(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimRefs, mvector& prims, BuildProgressMonitor& progressMonitor) - { static const size_t MIN_STEP_SIZE = 128; + /* use correct number of primitives */ + size_t numPrimitives = pinfo.size(); + const size_t numPrimitivesExt = prims.size(); + const size_t numSplitPrimitivesBudget = numPrimitivesExt - numPrimitives; + + /* allocate double buffer presplit items */ + avector preSplitItem0(numPrimitivesExt); + avector preSplitItem1(numPrimitivesExt); + + /* compute grid */ + SplittingGrid grid(pinfo.geomBounds); + + /* init presplit items and get total sum */ + const float psum = parallel_reduce( size_t(0), numPrimitives, size_t(MIN_STEP_SIZE), 0.0f, [&](const range& r) -> float { + float sum = 0.0f; + for (size_t i=r.begin(); i float { return a+b; }); + + /* compute number of splits per primitive */ + const float inv_psum = 1.0f / psum; + parallel_for( size_t(0), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range& r) -> void { + for (size_t i=r.begin(); i= numPrimitives) + return pinfo; + + size_t numPrimitivesToSplit = numPrimitives - center; + assert(preSplitItem0[center].data >= 1.0f); + + /* sort presplit items in ascending order */ + radix_sort_u32(preSplitItem0.data() + center,preSplitItem1.data() + center,numPrimitivesToSplit,1024); + + CHECK_PRESPLIT( + parallel_for( size_t(center+1), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range& r) -> void { + for (size_t i=r.begin(); i& t) -> size_t { + size_t sum = 0; + for (size_t i=t.begin(); i= 1 && splitprims <= MAX_PRESPLITS_PER_PRIMITIVE); + + unsigned int numSubPrims = 0; + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE]; + splitPrimitive(prims[primrefID],splitprims,grid,subPrims,numSubPrims); + assert(numSubPrims); + + numSubPrims--; // can reuse slot + sum+=numSubPrims; + preSplitItem0[i].data = (numSubPrims << 16) | splitprims; + + primOffset0[i-center] = numSubPrims; + } + return sum; + },[](const size_t& a, const size_t& b) -> size_t { return a+b; }); + + /* if we are over budget, need to shrink the range */ + if (totalNumSubPrims > numSplitPrimitivesBudget) + { + size_t new_center = numPrimitives-1; + size_t sum = 0; + for (;new_center>=center;new_center--) + { + const unsigned int numSubPrims = preSplitItem0[new_center].data >> 16; + if (unlikely(sum + numSubPrims >= numSplitPrimitivesBudget)) break; + sum += numSubPrims; + } + new_center++; + + primOffset0 += new_center - center; + numPrimitivesToSplit -= new_center - center; + center = new_center; + assert(numPrimitivesToSplit == (numPrimitives - center)); + } + + /* parallel prefix sum to compute offsets for storing sub-primitives */ + const unsigned int offset = parallel_prefix_sum(primOffset0,primOffset1,numPrimitivesToSplit,(unsigned int)0,std::plus()); + assert(numPrimitives+offset <= numPrimitivesExt); + + /* iterate over range, and split primitives into sub primitives and append them to prims array */ + parallel_for( size_t(center), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range& rn) -> void { + for (size_t j=rn.begin(); j= 1 && splitprims <= MAX_PRESPLITS_PER_PRIMITIVE); + + unsigned int numSubPrims = 0; + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE]; + splitPrimitive(prims[primrefID],splitprims,grid,subPrims,numSubPrims); + + const unsigned int numSubPrimsExpected MAYBE_UNUSED = preSplitItem0[j].data >> 16; + assert(numSubPrims-1 == numSubPrimsExpected); + + const size_t newID = numPrimitives + primOffset1[j-center]; + assert(newID+numSubPrims-1 <= numPrimitivesExt); + + prims[primrefID] = subPrims[0]; + for (size_t i=1;i& r) -> PrimInfo { + PrimInfo p(empty); + for (size_t j=r.begin(); j PrimInfo { return PrimInfo::merge(a,b); }); + + assert(pinfo1.size() == numPrimitives); + + return pinfo1; + } + +#if !defined(RTHWIF_STANDALONE) + + template + PrimInfo createPrimRefArray_presplit(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimRefs, mvector& prims, BuildProgressMonitor& progressMonitor) + { ParallelForForPrefixSumState pstate; Scene::Iterator2 iter(scene,types,mblur); @@ -198,179 +442,27 @@ namespace embree }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); } - /* use correct number of primitives */ - size_t numPrimitives = pinfo.size(); - const size_t alloc_numPrimitives = prims.size(); - const size_t numSplitPrimitivesBudget = alloc_numPrimitives - numPrimitives; - /* set up primitive splitter */ SplitterFactory Splitter(scene); - - - DBG_PRESPLIT( - const size_t org_numPrimitives = pinfo.size(); - PRINT(numPrimitives); - PRINT(alloc_numPrimitives); - PRINT(numSplitPrimitivesBudget); - ); - - /* allocate double buffer presplit items */ - const size_t presplit_allocation_size = sizeof(PresplitItem)*alloc_numPrimitives; - PresplitItem *presplitItem = (PresplitItem*)alignedMalloc(presplit_allocation_size,64); - PresplitItem *tmp_presplitItem = (PresplitItem*)alignedMalloc(presplit_allocation_size,64); - - /* compute grid */ - const Vec3fa grid_base = pinfo.geomBounds.lower; - const Vec3fa grid_diag = pinfo.geomBounds.size(); - const float grid_extend = max(grid_diag.x,max(grid_diag.y,grid_diag.z)); - const float grid_scale = grid_extend == 0.0f ? 0.0f : GRID_SIZE / grid_extend; - - /* init presplit items and get total sum */ - const float psum = parallel_reduce( size_t(0), numPrimitives, size_t(MIN_STEP_SIZE), 0.0f, [&](const range& r) -> float { - float sum = 0.0f; - for (size_t i=r.begin(); i(prims[i],scene,mc) : 0.0f; - /* FIXME: sum undeterministic */ - sum += presplitItem[i].priority; - } - return sum; - },[](const float& a, const float& b) -> float { return a+b; }); - - /* compute number of splits per primitive */ - const float inv_psum = 1.0f / psum; - parallel_for( size_t(0), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range& r) -> void { - for (size_t i=r.begin(); i 0.0f) - { - const float rel_p = (float)numSplitPrimitivesBudget * presplitItem[i].priority * inv_psum; - if (rel_p >= PRIORITY_CUTOFF_THRESHOLD) // need at least a split budget that generates two sub-prims - { - presplitItem[i].priority = max(min(ceilf(logf(rel_p)/logf(2.0f)),(float)MAX_PRESPLITS_PER_PRIMITIVE_LOG),1.0f); - //presplitItem[i].priority = min(floorf(logf(rel_p)/logf(2.0f)),(float)MAX_PRESPLITS_PER_PRIMITIVE_LOG); - assert(presplitItem[i].priority >= 0.0f && presplitItem[i].priority <= (float)MAX_PRESPLITS_PER_PRIMITIVE_LOG); - } - else - presplitItem[i].priority = 0.0f; - } - } - }); - - auto isLeft = [&] (const PresplitItem &ref) { return ref.priority < PRIORITY_CUTOFF_THRESHOLD; }; - size_t center = parallel_partitioning(presplitItem,0,numPrimitives,isLeft,1024); - - /* anything to split ? */ - if (center < numPrimitives) - { - size_t numPrimitivesToSplit = numPrimitives - center; - assert(presplitItem[center].priority >= 1.0f); - - /* sort presplit items in ascending order */ - radix_sort_u32(presplitItem + center,tmp_presplitItem + center,numPrimitivesToSplit,1024); - - CHECK_PRESPLIT( - parallel_for( size_t(center+1), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range& r) -> void { - for (size_t i=r.begin(); i& t) -> size_t { - size_t sum = 0; - for (size_t i=t.begin(); i= 1.0f); - const unsigned int primrefID = presplitItem[i].index; - const float prio = presplitItem[i].priority; - const unsigned int geomID = prims[primrefID].geomID(); - const unsigned int primID = prims[primrefID].primID(); - const unsigned int split_levels = (unsigned int)prio; - unsigned int numSubPrims = 0; - splitPrimitive(Splitter,prims[primrefID],geomID,primID,split_levels,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); - assert(numSubPrims); - numSubPrims--; // can reuse slot - sum+=numSubPrims; - presplitItem[i].data = (numSubPrims << MAX_PRESPLITS_PER_PRIMITIVE_LOG) | split_levels; - primOffset0[i-center] = numSubPrims; - } - return sum; - },[](const size_t& a, const size_t& b) -> size_t { return a+b; }); - /* if we are over budget, need to shrink the range */ - if (totalNumSubPrims > numSplitPrimitivesBudget) - { - size_t new_center = numPrimitives-1; - size_t sum = 0; - for (;new_center>=center;new_center--) - { - const unsigned int numSubPrims = presplitItem[new_center].data >> MAX_PRESPLITS_PER_PRIMITIVE_LOG; - if (unlikely(sum + numSubPrims >= numSplitPrimitivesBudget)) break; - sum += numSubPrims; - } - new_center++; - - primOffset0 += new_center - center; - numPrimitivesToSplit -= new_center - center; - center = new_center; - assert(numPrimitivesToSplit == (numPrimitives - center)); - } - - /* parallel prefix sum to compute offsets for storing sub-primitives */ - const unsigned int offset = parallel_prefix_sum(primOffset0,primOffset1,numPrimitivesToSplit,(unsigned int)0,std::plus()); - assert(numPrimitives+offset <= alloc_numPrimitives); - - /* iterate over range, and split primitives into sub primitives and append them to prims array */ - parallel_for( size_t(center), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range& rn) -> void { - for (size_t j=rn.begin(); j& r) -> PrimInfo { - PrimInfo p(empty); - for (size_t j=r.begin(); j PrimInfo { return PrimInfo::merge(a,b); }); - - assert(pinfo.size() == numPrimitives); + auto split_primitive = [&] (const PrimRef &prim, + const unsigned int splitprims, + const SplittingGrid& grid, + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], + unsigned int& numSubPrims) + { + const auto splitter = Splitter(prim); + splitPrimitive(splitter,prim,splitprims,grid,subPrims,numSubPrims); + }; - /* free double buffer presplit items */ - alignedFree(tmp_presplitItem); - alignedFree(presplitItem); - return pinfo; + auto primitiveArea = [&] (const PrimRef &ref) { + const unsigned int geomID = ref.geomID(); + const unsigned int primID = ref.primID(); + return ((Mesh*)scene->get(geomID))->projectedPrimitiveArea(primID); + }; + + return createPrimRefArray_presplit(numPrimRefs,prims,pinfo,split_primitive,primitiveArea); } +#endif } } diff --git a/thirdparty/embree/kernels/builders/splitter.h b/thirdparty/embree/kernels/builders/splitter.h index da89d0b1781..3daf55e8014 100644 --- a/thirdparty/embree/kernels/builders/splitter.h +++ b/thirdparty/embree/kernels/builders/splitter.h @@ -3,13 +3,51 @@ #pragma once +#if !defined(RTHWIF_STANDALONE) #include "../common/scene.h" -#include "../common/primref.h" +#endif + +#include "../builders/primref.h" namespace embree { namespace isa { + template + __forceinline void splitPolygon(const BBox3fa& bounds, + const size_t dim, + const float pos, + const Vec3fa (&v)[N+1], + BBox3fa& left_o, + BBox3fa& right_o) + { + BBox3fa left = empty, right = empty; + /* clip triangle to left and right box by processing all edges */ + for (size_t i=0; i= pos) right.extend(v0); // this point is on right side + + if ((v0d < pos && pos < v1d) || (v1d < pos && pos < v0d)) // the edge crosses the splitting location + { + assert((v1d-v0d) != 0.0f); + const float inv_length = 1.0f/(v1d-v0d); + const Vec3fa c = madd(Vec3fa((pos-v0d)*inv_length),v1-v0,v0); + left.extend(c); + right.extend(c); + } + } + + /* clip against current bounds */ + left_o = intersect(left,bounds); + right_o = intersect(right,bounds); + } + template __forceinline void splitPolygon(const BBox3fa& bounds, const size_t dim, @@ -78,7 +116,9 @@ namespace embree new (&left_o ) PrimRef(intersect(left ,prim.bounds()),prim.geomID(), prim.primID()); new (&right_o) PrimRef(intersect(right,prim.bounds()),prim.geomID(), prim.primID()); } - + +#if !defined(RTHWIF_STANDALONE) + struct TriangleSplitter { __forceinline TriangleSplitter(const Scene* scene, const PrimRef& prim) @@ -173,6 +213,13 @@ namespace embree __forceinline DummySplitter(const Scene* scene, const PrimRef& prim) { } + + __forceinline void operator() (const PrimRef& prim, const size_t dim, const float pos, PrimRef& left_o, PrimRef& right_o) const { + } + + __forceinline void operator() (const BBox3fa& prim, const size_t dim, const float pos, BBox3fa& left_o, BBox3fa& right_o) const { + } + }; struct DummySplitterFactory @@ -187,7 +234,7 @@ namespace embree private: const Scene* scene; }; - +#endif } } diff --git a/thirdparty/embree/kernels/bvh/bvh.h b/thirdparty/embree/kernels/bvh/bvh.h index 565eec5a582..e0ffb86af9f 100644 --- a/thirdparty/embree/kernels/bvh/bvh.h +++ b/thirdparty/embree/kernels/bvh/bvh.h @@ -85,7 +85,7 @@ namespace embree typedef BVHNodeRecord NodeRecord; typedef BVHNodeRecordMB NodeRecordMB; typedef BVHNodeRecordMB4D NodeRecordMB4D; - + public: /*! BVHN default constructor. */ diff --git a/thirdparty/embree/kernels/bvh/bvh4_factory.cpp b/thirdparty/embree/kernels/bvh/bvh4_factory.cpp index 890d5e7b7c0..d03940deeab 100644 --- a/thirdparty/embree/kernels/bvh/bvh4_factory.cpp +++ b/thirdparty/embree/kernels/bvh/bvh4_factory.cpp @@ -17,6 +17,7 @@ #include "../geometry/subdivpatch1.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/accelinstance.h" @@ -66,6 +67,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceIntersector1); DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH4GridMBIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Pluecker); @@ -104,6 +108,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceIntersector4Chunk); DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector4,BVH4GridMBIntersector4HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridPluecker); @@ -142,6 +149,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceIntersector8Chunk); DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector8,BVH4GridMBIntersector8HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridPluecker); @@ -180,33 +190,20 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceIntersector16Chunk); DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector16,BVH4GridMBIntersector16HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4IntersectorStreamPacketFallback); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4IntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4IntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4vIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4vIntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4VirtualIntersectorStream); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4InstanceIntersectorStream); - DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelTriangle4MeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelTriangle4vMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelTriangle4iMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4Curve4vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4Curve4iBuilder_OBB_New,void* COMMA Scene* COMMA size_t); @@ -237,7 +234,10 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); - + + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH4GridSceneBuilderSAH,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4GridMBSceneBuilderSAH,void* COMMA Scene* COMMA size_t); @@ -266,6 +266,7 @@ namespace embree IF_ENABLED_QUADS (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelQuadMeshSAH)); IF_ENABLED_USER (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelVirtualSAH)); IF_ENABLED_INSTANCE (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelInstanceSAH)); + IF_ENABLED_INSTANCE_ARRAY (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelInstanceArraySAH)); IF_ENABLED_CURVES_OR_POINTS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4Curve4vBuilder_OBB_New)); IF_ENABLED_CURVES_OR_POINTS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4Curve4iBuilder_OBB_New)); @@ -296,7 +297,10 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceSceneBuilderSAH)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceMBSceneBuilderSAH)); - + + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceArraySceneBuilderSAH)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceArrayMBSceneBuilderSAH)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4GridSceneBuilderSAH)); IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4GridMBSceneBuilderSAH)); @@ -349,6 +353,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceIntersector1)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceMBIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayMBIntersector1)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridIntersector1Moeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridMBIntersector1Moeller)) IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridIntersector1Pluecker)); @@ -389,7 +396,10 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceIntersector4Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceMBIntersector4Chunk)); - + + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayIntersector4Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayMBIntersector4Chunk)); + IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersector4HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridIntersector4HybridMoeller)); @@ -424,13 +434,16 @@ namespace embree IF_ENABLED_SUBDIV(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4SubdivPatch1Intersector8)); IF_ENABLED_SUBDIV(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4SubdivPatch1MBIntersector8)); - + IF_ENABLED_USER(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4VirtualIntersector8Chunk)); IF_ENABLED_USER(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4VirtualMBIntersector8Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceIntersector8Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceMBIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceArrayIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceArrayMBIntersector8Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4GridIntersector8HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4GridMBIntersector8HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4GridIntersector8HybridPluecker)); @@ -470,29 +483,13 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceIntersector16Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceMBIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceArrayIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceArrayMBIntersector16Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH4GridIntersector16HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH4GridMBIntersector16HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH4GridIntersector16HybridPluecker)); - /* select stream intersectors */ - SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4IntersectorStreamPacketFallback); - - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4IntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4IntersectorStreamMoellerNoFilter)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4iIntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4vIntersectorStreamPluecker)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4iIntersectorStreamPluecker)); - - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersectorStreamMoellerNoFilter)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4iIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersectorStreamPluecker)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4iIntersectorStreamPluecker)); - - IF_ENABLED_USER(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4VirtualIntersectorStream)); - - IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceIntersectorStream)); - #endif } @@ -509,7 +506,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersector4Hybrid(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersector8Hybrid(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersector16Hybrid(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -523,7 +519,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersectorRobust4Hybrid(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersectorRobust8Hybrid(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersectorRobust16Hybrid(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -545,7 +540,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersector4HybridMB(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersector8HybridMB(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersector16HybridMB(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -559,7 +553,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersectorRobust4HybridMB(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersectorRobust8HybridMB(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersectorRobust16HybridMB(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -581,8 +574,6 @@ namespace embree intersectors.intersector8_nofilter = BVH4Triangle4Intersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH4Triangle4Intersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH4Triangle4Intersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH4Triangle4IntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH4Triangle4IntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -597,7 +588,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Triangle4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -614,7 +604,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Triangle4iIntersector8HybridMoeller(); intersectors.intersector16 = BVH4Triangle4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4Triangle4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -627,7 +616,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4iIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Triangle4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -647,7 +635,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4vMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Triangle4vMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH4Triangle4vMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -660,7 +647,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4vMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4vMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4vMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -680,7 +666,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Triangle4iMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH4Triangle4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -693,7 +678,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4iMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -716,8 +700,6 @@ namespace embree intersectors.intersector8_nofilter = BVH4Quad4vIntersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH4Quad4vIntersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH4Quad4vIntersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH4Quad4vIntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH4Quad4vIntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -730,7 +712,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Quad4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Quad4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Quad4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -750,7 +731,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Quad4iIntersector8HybridMoeller(); intersectors.intersector16= BVH4Quad4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4Quad4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -763,7 +743,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Quad4iIntersector8HybridPluecker(); intersectors.intersector16= BVH4Quad4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Quad4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -783,7 +762,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Quad4iMBIntersector8HybridMoeller(); intersectors.intersector16= BVH4Quad4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -796,7 +774,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Quad4iMBIntersector8HybridPluecker(); intersectors.intersector16= BVH4Quad4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -829,7 +806,6 @@ namespace embree intersectors.intersector4 = BVH4VirtualIntersector4Chunk(); intersectors.intersector8 = BVH4VirtualIntersector8Chunk(); intersectors.intersector16 = BVH4VirtualIntersector16Chunk(); - intersectors.intersectorN = BVH4VirtualIntersectorStream(); #endif intersectors.collider = BVH4ColliderUserGeom(); return intersectors; @@ -844,7 +820,6 @@ namespace embree intersectors.intersector4 = BVH4VirtualMBIntersector4Chunk(); intersectors.intersector8 = BVH4VirtualMBIntersector8Chunk(); intersectors.intersector16 = BVH4VirtualMBIntersector16Chunk(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -858,7 +833,6 @@ namespace embree intersectors.intersector4 = BVH4InstanceIntersector4Chunk(); intersectors.intersector8 = BVH4InstanceIntersector8Chunk(); intersectors.intersector16 = BVH4InstanceIntersector16Chunk(); - intersectors.intersectorN = BVH4InstanceIntersectorStream(); #endif return intersectors; } @@ -872,7 +846,32 @@ namespace embree intersectors.intersector4 = BVH4InstanceMBIntersector4Chunk(); intersectors.intersector8 = BVH4InstanceMBIntersector8Chunk(); intersectors.intersector16 = BVH4InstanceMBIntersector16Chunk(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); +#endif + return intersectors; + } + + Accel::Intersectors BVH4Factory::BVH4InstanceArrayIntersectors(BVH4* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH4InstanceArrayIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH4InstanceArrayIntersector4Chunk(); + intersectors.intersector8 = BVH4InstanceArrayIntersector8Chunk(); + intersectors.intersector16 = BVH4InstanceArrayIntersector16Chunk(); +#endif + return intersectors; + } + + Accel::Intersectors BVH4Factory::BVH4InstanceArrayMBIntersectors(BVH4* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH4InstanceArrayMBIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH4InstanceArrayMBIntersector4Chunk(); + intersectors.intersector8 = BVH4InstanceArrayMBIntersector8Chunk(); + intersectors.intersector16 = BVH4InstanceArrayMBIntersector16Chunk(); #endif return intersectors; } @@ -886,7 +885,6 @@ namespace embree intersectors.intersector4 = BVH4SubdivPatch1Intersector4(); intersectors.intersector8 = BVH4SubdivPatch1Intersector8(); intersectors.intersector16 = BVH4SubdivPatch1Intersector16(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -900,7 +898,6 @@ namespace embree intersectors.intersector4 = BVH4SubdivPatch1MBIntersector4(); intersectors.intersector8 = BVH4SubdivPatch1MBIntersector8(); intersectors.intersector16 = BVH4SubdivPatch1MBIntersector16(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -1255,6 +1252,35 @@ namespace embree return new AccelInstance(accel,builder,intersectors); } + Accel* BVH4Factory::BVH4InstanceArray(Scene* scene, BuildVariant bvariant) + { + BVH4* accel = new BVH4(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH4InstanceArrayIntersectors(accel); + auto gtype = Geometry::MTY_INSTANCE_ARRAY; + + Builder* builder = nullptr; + if (scene->device->object_builder == "default") { + switch (bvariant) { + case BuildVariant::STATIC : builder = BVH4InstanceArraySceneBuilderSAH(accel,scene,gtype); break; + case BuildVariant::DYNAMIC : builder = BVH4BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); break; + case BuildVariant::HIGH_QUALITY: assert(false); break; + } + } + else if (scene->device->object_builder == "sah") { builder = BVH4InstanceArraySceneBuilderSAH(accel,scene,gtype); } + else if (scene->device->object_builder == "dynamic") { builder = BVH4BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); } + else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown builder "+scene->device->object_builder+" for BVH4"); + + return new AccelInstance(accel,builder,intersectors); + } + + Accel* BVH4Factory::BVH4InstanceArrayMB(Scene* scene) + { + BVH4* accel = new BVH4(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH4InstanceArrayMBIntersectors(accel); + Builder* builder = BVH4InstanceArrayMBSceneBuilderSAH(accel,scene,Geometry::MTY_INSTANCE_ARRAY); + return new AccelInstance(accel,builder,intersectors); + } + Accel::Intersectors BVH4Factory::BVH4GridIntersectors(BVH4* bvh, IntersectVariant ivariant) { Accel::Intersectors intersectors; @@ -1266,7 +1292,6 @@ namespace embree intersectors.intersector4 = BVH4GridIntersector4HybridMoeller(); intersectors.intersector8 = BVH4GridIntersector8HybridMoeller(); intersectors.intersector16 = BVH4GridIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif } else /* if (ivariant == IntersectVariant::ROBUST) */ @@ -1276,7 +1301,6 @@ namespace embree intersectors.intersector4 = BVH4GridIntersector4HybridPluecker(); intersectors.intersector8 = BVH4GridIntersector8HybridPluecker(); intersectors.intersector16 = BVH4GridIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif } return intersectors; @@ -1291,7 +1315,6 @@ namespace embree intersectors.intersector4 = BVH4GridMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4GridMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH4GridMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } diff --git a/thirdparty/embree/kernels/bvh/bvh4_factory.h b/thirdparty/embree/kernels/bvh/bvh4_factory.h index 30973971a40..abf51dd1081 100644 --- a/thirdparty/embree/kernels/bvh/bvh4_factory.h +++ b/thirdparty/embree/kernels/bvh/bvh4_factory.h @@ -48,6 +48,9 @@ namespace embree Accel* BVH4Instance(Scene* scene, bool isExpensive, BuildVariant bvariant = BuildVariant::STATIC); Accel* BVH4InstanceMB(Scene* scene, bool isExpensive); + Accel* BVH4InstanceArray(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC); + Accel* BVH4InstanceArrayMB(Scene* scene); + Accel* BVH4Grid(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); Accel* BVH4GridMB(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); @@ -77,7 +80,10 @@ namespace embree Accel::Intersectors BVH4InstanceIntersectors(BVH4* bvh); Accel::Intersectors BVH4InstanceMBIntersectors(BVH4* bvh); - + + Accel::Intersectors BVH4InstanceArrayIntersectors(BVH4* bvh); + Accel::Intersectors BVH4InstanceArrayMBIntersectors(BVH4* bvh); + Accel::Intersectors BVH4SubdivPatch1Intersectors(BVH4* bvh); Accel::Intersectors BVH4SubdivPatch1MBIntersectors(BVH4* bvh); @@ -122,7 +128,10 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceIntersector1); DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceMBIntersector1); - + + DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayMBIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH4GridMBIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Pluecker); @@ -161,6 +170,9 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceIntersector4Chunk); DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceMBIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayMBIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector4,BVH4GridMBIntersector4HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridPluecker); @@ -201,6 +213,9 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceIntersector8Chunk); DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector8,BVH4GridMBIntersector8HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridPluecker); @@ -241,30 +256,13 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceIntersector16Chunk); DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceMBIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayMBIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector16,BVH4GridMBIntersector16HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridPluecker); - // ============== - - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4IntersectorStreamPacketFallback); - - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4IntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4IntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4iIntersectorStreamPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4vIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4vIntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4iIntersectorStreamPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH4VirtualIntersectorStream); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH4InstanceIntersectorStream); - // SAH scene builders private: DEFINE_ISA_FUNCTION(Builder*,BVH4Curve4vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); @@ -294,6 +292,9 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH4GridSceneBuilderSAH,void* COMMA Scene* COMMA size_t); DEFINE_ISA_FUNCTION(Builder*,BVH4GridMBSceneBuilderSAH,void* COMMA Scene* COMMA size_t); @@ -312,5 +313,6 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); }; } diff --git a/thirdparty/embree/kernels/bvh/bvh8_factory.cpp b/thirdparty/embree/kernels/bvh/bvh8_factory.cpp index d4521af2412..7c0f7565faa 100644 --- a/thirdparty/embree/kernels/bvh/bvh8_factory.cpp +++ b/thirdparty/embree/kernels/bvh/bvh8_factory.cpp @@ -21,6 +21,7 @@ #include "../geometry/subdivpatch1.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/accelinstance.h" @@ -66,6 +67,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceIntersector1); DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH8GridMBIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Pluecker); @@ -101,6 +105,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceIntersector4Chunk); DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridPluecker); @@ -135,6 +142,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceIntersector8Chunk); DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridPluecker); @@ -169,27 +179,12 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceIntersector16Chunk); DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8IntersectorStreamPacketFallback); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8VirtualIntersectorStream); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8InstanceIntersectorStream); - DECLARE_ISA_FUNCTION(Builder*,BVH8Curve8vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8OBBCurve8iMBBuilder_OBB,void* COMMA Scene* COMMA size_t); @@ -212,6 +207,9 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4SceneBuilderFastSpatialSAH,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4vSceneBuilderFastSpatialSAH,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Quad4vSceneBuilderFastSpatialSAH,void* COMMA Scene* COMMA size_t); @@ -224,6 +222,7 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); BVH8Factory::BVH8Factory(int bfeatures, int ifeatures) { @@ -256,6 +255,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceSceneBuilderSAH)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceMBSceneBuilderSAH)); + + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceArraySceneBuilderSAH)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceArrayMBSceneBuilderSAH)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX(features,BVH8GridSceneBuilderSAH)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX(features,BVH8GridMBSceneBuilderSAH)); @@ -270,6 +272,7 @@ namespace embree IF_ENABLED_QUADS (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelQuadMeshSAH)); IF_ENABLED_USER (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelVirtualSAH)); IF_ENABLED_INSTANCE (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelInstanceSAH)); + IF_ENABLED_INSTANCE_ARRAY (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelInstanceArraySAH)); } void BVH8Factory::selectIntersectors(int features) @@ -313,6 +316,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersector1)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceMBIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayMBIntersector1)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector1Moeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridMBIntersector1Moeller)) IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector1Pluecker)); @@ -351,6 +357,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersector4Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceMBIntersector4Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayIntersector4Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayMBIntersector4Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector4HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector4HybridPluecker)); @@ -386,6 +395,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersector8Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceMBIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayMBIntersector8Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector8HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector8HybridPluecker)); @@ -421,29 +433,12 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceIntersector16Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceMBIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceArrayIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceArrayMBIntersector16Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH8GridIntersector16HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH8GridIntersector16HybridPluecker)); - /* select stream intersectors */ - - SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8IntersectorStreamPacketFallback); - - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4IntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4IntersectorStreamMoellerNoFilter)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4iIntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4vIntersectorStreamPluecker)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4iIntersectorStreamPluecker)); - - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4vIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4vIntersectorStreamMoellerNoFilter)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4iIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4vIntersectorStreamPluecker)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4iIntersectorStreamPluecker)); - - IF_ENABLED_USER(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8VirtualIntersectorStream)); - - IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersectorStream)); - #endif } @@ -460,7 +455,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersector4Hybrid(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersector8Hybrid(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersector16Hybrid(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -474,7 +468,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersectorRobust4Hybrid(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersectorRobust8Hybrid(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersectorRobust16Hybrid(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -496,7 +489,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersector4HybridMB(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersector8HybridMB(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersector16HybridMB(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -510,7 +502,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersectorRobust4HybridMB(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersectorRobust8HybridMB(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersectorRobust16HybridMB(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -532,8 +523,6 @@ namespace embree intersectors.intersector8_nofilter = BVH8Triangle4Intersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH8Triangle4Intersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH8Triangle4Intersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH8Triangle4IntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH8Triangle4IntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -554,7 +543,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Triangle4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -571,7 +559,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Triangle4iIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Triangle4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8Triangle4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -584,7 +571,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4iIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Triangle4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -604,7 +590,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4vMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Triangle4vMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Triangle4vMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -617,7 +602,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4vMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4vMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4vMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -637,7 +621,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Triangle4iMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Triangle4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -650,7 +633,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4iMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -673,8 +655,6 @@ namespace embree intersectors.intersector8_nofilter = BVH8Quad4vIntersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH8Quad4vIntersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH8Quad4vIntersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH8Quad4vIntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH8Quad4vIntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -687,7 +667,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Quad4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Quad4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Quad4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -707,7 +686,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Quad4iIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Quad4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8Quad4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -720,7 +698,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Quad4iIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Quad4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Quad4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -740,7 +717,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Quad4iMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Quad4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -753,7 +729,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Quad4iMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Quad4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -794,7 +769,6 @@ namespace embree intersectors.intersector4 = BVH8VirtualIntersector4Chunk(); intersectors.intersector8 = BVH8VirtualIntersector8Chunk(); intersectors.intersector16 = BVH8VirtualIntersector16Chunk(); - intersectors.intersectorN = BVH8VirtualIntersectorStream(); #endif intersectors.collider = BVH8ColliderUserGeom(); return intersectors; @@ -809,7 +783,6 @@ namespace embree intersectors.intersector4 = BVH8VirtualMBIntersector4Chunk(); intersectors.intersector8 = BVH8VirtualMBIntersector8Chunk(); intersectors.intersector16 = BVH8VirtualMBIntersector16Chunk(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -823,7 +796,19 @@ namespace embree intersectors.intersector4 = BVH8InstanceIntersector4Chunk(); intersectors.intersector8 = BVH8InstanceIntersector8Chunk(); intersectors.intersector16 = BVH8InstanceIntersector16Chunk(); - intersectors.intersectorN = BVH8InstanceIntersectorStream(); +#endif + return intersectors; + } + + Accel::Intersectors BVH8Factory::BVH8InstanceArrayIntersectors(BVH8* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH8InstanceArrayIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH8InstanceArrayIntersector4Chunk(); + intersectors.intersector8 = BVH8InstanceArrayIntersector8Chunk(); + intersectors.intersector16 = BVH8InstanceArrayIntersector16Chunk(); #endif return intersectors; } @@ -837,7 +822,19 @@ namespace embree intersectors.intersector4 = BVH8InstanceMBIntersector4Chunk(); intersectors.intersector8 = BVH8InstanceMBIntersector8Chunk(); intersectors.intersector16 = BVH8InstanceMBIntersector16Chunk(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); +#endif + return intersectors; + } + + Accel::Intersectors BVH8Factory::BVH8InstanceArrayMBIntersectors(BVH8* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH8InstanceArrayMBIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH8InstanceArrayMBIntersector4Chunk(); + intersectors.intersector8 = BVH8InstanceArrayMBIntersector8Chunk(); + intersectors.intersector16 = BVH8InstanceArrayMBIntersector16Chunk(); #endif return intersectors; } @@ -1086,6 +1083,28 @@ namespace embree return new AccelInstance(accel,builder,intersectors); } + Accel* BVH8Factory::BVH8InstanceArray(Scene* scene, BuildVariant bvariant) + { + BVH8* accel = new BVH8(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH8InstanceArrayIntersectors(accel); + auto gtype = Geometry::MTY_INSTANCE_ARRAY; + // Builder* builder = BVH8InstanceSceneBuilderSAH(accel,scene,gtype); + + Builder* builder = nullptr; + if (scene->device->object_builder == "default") { + switch (bvariant) { + case BuildVariant::STATIC : builder = BVH8InstanceArraySceneBuilderSAH(accel,scene,gtype); break; + case BuildVariant::DYNAMIC : builder = BVH8BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); break; + case BuildVariant::HIGH_QUALITY: assert(false); break; + } + } + else if (scene->device->object_builder == "sah") builder = BVH8InstanceArraySceneBuilderSAH(accel,scene,gtype); + else if (scene->device->object_builder == "dynamic") builder = BVH8BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); + else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown builder "+scene->device->object_builder+" for BVH8"); + + return new AccelInstance(accel,builder,intersectors); + } + Accel* BVH8Factory::BVH8InstanceMB(Scene* scene, bool isExpensive) { BVH8* accel = new BVH8(InstancePrimitive::type,scene); @@ -1095,6 +1114,15 @@ namespace embree return new AccelInstance(accel,builder,intersectors); } + Accel* BVH8Factory::BVH8InstanceArrayMB(Scene* scene) + { + BVH8* accel = new BVH8(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH8InstanceArrayMBIntersectors(accel); + auto gtype = Geometry::MTY_INSTANCE_ARRAY; + Builder* builder = BVH8InstanceArrayMBSceneBuilderSAH(accel,scene,gtype); + return new AccelInstance(accel,builder,intersectors); + } + Accel::Intersectors BVH8Factory::BVH8GridIntersectors(BVH8* bvh, IntersectVariant ivariant) { Accel::Intersectors intersectors; @@ -1106,7 +1134,6 @@ namespace embree intersectors.intersector4 = BVH8GridIntersector4HybridMoeller(); intersectors.intersector8 = BVH8GridIntersector8HybridMoeller(); intersectors.intersector16 = BVH8GridIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif } else /* if (ivariant == IntersectVariant::ROBUST) */ @@ -1116,7 +1143,6 @@ namespace embree intersectors.intersector4 = BVH8GridIntersector4HybridPluecker(); intersectors.intersector8 = BVH8GridIntersector8HybridPluecker(); intersectors.intersector16 = BVH8GridIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif } return intersectors; @@ -1131,7 +1157,6 @@ namespace embree intersectors.intersector4 = nullptr; intersectors.intersector8 = nullptr; intersectors.intersector16 = nullptr; - intersectors.intersectorN = nullptr; #endif return intersectors; } diff --git a/thirdparty/embree/kernels/bvh/bvh8_factory.h b/thirdparty/embree/kernels/bvh/bvh8_factory.h index 198d6f1df06..e55310b7038 100644 --- a/thirdparty/embree/kernels/bvh/bvh8_factory.h +++ b/thirdparty/embree/kernels/bvh/bvh8_factory.h @@ -39,6 +39,9 @@ namespace embree Accel* BVH8Instance(Scene* scene, bool isExpensive, BuildVariant bvariant = BuildVariant::STATIC); Accel* BVH8InstanceMB(Scene* scene, bool isExpensive); + Accel* BVH8InstanceArray(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC); + Accel* BVH8InstanceArrayMB(Scene* scene); + Accel* BVH8Grid(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); Accel* BVH8GridMB(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); @@ -70,6 +73,9 @@ namespace embree Accel::Intersectors BVH8InstanceIntersectors(BVH8* bvh); Accel::Intersectors BVH8InstanceMBIntersectors(BVH8* bvh); + Accel::Intersectors BVH8InstanceArrayIntersectors(BVH8* bvh); + Accel::Intersectors BVH8InstanceArrayMBIntersectors(BVH8* bvh); + Accel::Intersectors BVH8GridIntersectors(BVH8* bvh, IntersectVariant ivariant); Accel::Intersectors BVH8GridMBIntersectors(BVH8* bvh, IntersectVariant ivariant); @@ -111,6 +117,9 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceIntersector1); DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceMBIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayMBIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH8GridMBIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Pluecker); @@ -145,7 +154,10 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceIntersector4Chunk); DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceMBIntersector4Chunk); - + + DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayMBIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridPluecker); @@ -180,9 +192,12 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceIntersector8Chunk); DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridPluecker); - + DEFINE_SYMBOL2(Accel::Intersector16,BVH8OBBVirtualCurveIntersector16Hybrid); DEFINE_SYMBOL2(Accel::Intersector16,BVH8OBBVirtualCurveIntersector16HybridMB); DEFINE_SYMBOL2(Accel::Intersector16,BVH8OBBVirtualCurveIntersectorRobust16Hybrid); @@ -213,28 +228,13 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceIntersector16Chunk); DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceMBIntersector16Chunk); - + + DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayMBIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8IntersectorStreamPacketFallback); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8VirtualIntersectorStream); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8InstanceIntersectorStream); - // SAH scene builders private: DEFINE_ISA_FUNCTION(Builder*,BVH8Curve8vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); @@ -258,6 +258,9 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + + DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DEFINE_ISA_FUNCTION(Builder*,BVH8GridSceneBuilderSAH,void* COMMA Scene* COMMA size_t); DEFINE_ISA_FUNCTION(Builder*,BVH8GridMBSceneBuilderSAH,void* COMMA Scene* COMMA size_t); @@ -276,5 +279,6 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); }; } diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp index 4a4d8d71df6..7d6548cb2a4 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp @@ -17,6 +17,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #if defined(__64BIT__) # define ROTATE_TREE 1 // specifies number of tree rotation rounds to perform @@ -399,6 +400,50 @@ namespace embree unsigned int geomID_ = std::numeric_limits::max(); }; + template + struct CreateMortonLeaf + { + typedef BVHN BVH; + typedef typename BVH::NodeRef NodeRef; + typedef typename BVH::NodeRecord NodeRecord; + + __forceinline CreateMortonLeaf (InstanceArray* mesh, unsigned int geomID, BVHBuilderMorton::BuildPrim* morton) + : mesh(mesh), morton(morton), geomID_(geomID) {} + + __noinline NodeRecord operator() (const range& current, const FastAllocator::CachedAllocator& alloc) + { + vfloat4 lower(pos_inf); + vfloat4 upper(neg_inf); + size_t items = current.size(); + size_t start = current.begin(); + assert(items <= 1); + + /* allocate leaf node */ + InstanceArrayPrimitive* accel = (InstanceArrayPrimitive*) alloc.malloc1(items*sizeof(InstanceArrayPrimitive),BVH::byteAlignment); + NodeRef ref = BVH::encodeLeaf((char*)accel,items); + const InstanceArray* instance = this->mesh; + + BBox3fa bounds = empty; + for (size_t i=0; ibounds(primID)); + new (&accel[i]) InstanceArrayPrimitive(geomID_, primID); + } + + BBox3fx box_o = (BBox3fx&)bounds; +#if ROTATE_TREE + if (N == 4) + box_o.lower.a = current.size(); +#endif + return NodeRecord(ref,box_o); + } + private: + InstanceArray* mesh; + BVHBuilderMorton::BuildPrim* morton; + unsigned int geomID_ = std::numeric_limits::max(); + }; + template struct CalculateMeshBounds { @@ -523,7 +568,14 @@ namespace embree #if defined(EMBREE_GEOMETRY_INSTANCE) Builder* BVH4InstanceMeshBuilderMortonGeneral (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<4,Instance,InstancePrimitive>((BVH4*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } #if defined(__AVX__) - Builder* BVH8InstanceMeshBuilderMortonGeneral (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<8,Instance,InstancePrimitive>((BVH8*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } + Builder* BVH8InstanceMeshBuilderMortonGeneral (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<8,Instance,InstancePrimitive>((BVH8*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } +#endif +#endif + +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArrayMeshBuilderMortonGeneral (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } +#if defined(__AVX__) + Builder* BVH8InstanceArrayMeshBuilderMortonGeneral (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } #endif #endif diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp index fad02fcc045..e20c088bba4 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp @@ -15,6 +15,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/state.h" @@ -150,7 +151,7 @@ namespace embree const size_t leaf_bytes = size_t(1.2*Primitive::blocks(numPrimitives)*sizeof(Primitive)); bvh->alloc.init_estimate(node_bytes+leaf_bytes); settings.singleThreadThreshold = bvh->alloc.fixSingleThreadThreshold(N,DEFAULT_SINGLE_THREAD_THRESHOLD,numPrimitives,node_bytes+leaf_bytes); - prims.resize(numPrimitives); + prims.resize(numPrimitives); PrimInfo pinfo = mesh ? createPrimRefArray(mesh,geomID_,numPrimitives,prims,bvh->scene->progressInterface) : @@ -518,14 +519,35 @@ namespace embree #endif #if defined(EMBREE_GEOMETRY_INSTANCE) - Builder* BVH4InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderSAH<4,InstancePrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); } + Builder* BVH4InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<4,InstancePrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); + } Builder* BVH4InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNBuilderSAH<4,InstancePrimitive>((BVH4*)bvh,mesh,geomID,4,1.0f,1,inf,gtype); } #if defined(__AVX__) - Builder* BVH8InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); } + Builder* BVH8InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); + } Builder* BVH8InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { - return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,mesh,geomID,8,1.0f,1,inf,gtype); + return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,mesh,geomID,8,1.0f,1,1,gtype); + } +#endif +#endif + +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArraySceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<4,InstanceArrayPrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); + } + Builder* BVH4InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { + return new BVHNBuilderSAH<4,InstanceArrayPrimitive>((BVH4*)bvh,mesh,geomID,4,1.0f,1,1,gtype); + } +#if defined(__AVX__) + Builder* BVH8InstanceArraySceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<8,InstanceArrayPrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); + } + Builder* BVH8InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { + return new BVHNBuilderSAH<8,InstanceArrayPrimitive>((BVH8*)bvh,mesh,geomID,8,1.0f,1,1,gtype); } #endif #endif diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp index d163a80ab19..0dcf98a5be1 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp @@ -17,6 +17,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/state.h" @@ -695,6 +696,13 @@ namespace embree #endif #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArrayMBSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderMBlurSAH<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); } +#if defined(__AVX__) + Builder* BVH8InstanceArrayMBSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderMBlurSAH<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); } +#endif +#endif + #if defined(EMBREE_GEOMETRY_GRID) Builder* BVH4GridMBSceneBuilderSAH (void* bvh, Scene* scene, size_t mode) { return new BVHNBuilderMBlurSAHGrid<4>((BVH4*)bvh,scene,4,1.0f,4,4); } #if defined(__AVX__) diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp index 5d45ed37482..990b1d59ad9 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp @@ -1,6 +1,10 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 +#if !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + #include "bvh_builder_twolevel.h" #include "bvh_statistics.h" #include "../builders/bvh_builder_sah.h" @@ -333,6 +337,12 @@ namespace embree } #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4BuilderTwoLevelInstanceArraySAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype, bool useMortonBuilder) { + return new BVHNBuilderTwoLevel<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)bvh,scene,gtype,useMortonBuilder); + } +#endif + #if defined(__AVX__) #if defined(EMBREE_GEOMETRY_TRIANGLE) Builder* BVH8BuilderTwoLevelTriangle4MeshSAH (void* bvh, Scene* scene, bool useMortonBuilder) { @@ -364,6 +374,12 @@ namespace embree } #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH8BuilderTwoLevelInstanceArraySAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype, bool useMortonBuilder) { + return new BVHNBuilderTwoLevel<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)bvh,scene,gtype,useMortonBuilder); + } +#endif + #endif } } diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h index dc7ec7d2785..97ae41a87d8 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h +++ b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h @@ -7,7 +7,6 @@ #include "bvh_builder_twolevel_internal.h" #include "bvh.h" -#include "../common/primref.h" #include "../builders/priminfo.h" #include "../builders/primrefgen.h" diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h index 023b52b780b..b28afffae91 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h +++ b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h @@ -11,6 +11,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" namespace embree { @@ -32,6 +33,9 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshBuilderMortonGeneral,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshBuilderSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshRefitSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMeshBuilderMortonGeneral,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMeshBuilderSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMeshRefitSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); @@ -50,6 +54,9 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshBuilderMortonGeneral,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshBuilderSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshRefitSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMeshBuilderMortonGeneral,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMeshBuilderSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMeshRefitSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) namespace isa { @@ -89,6 +96,11 @@ namespace embree Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} }; template<> + struct MortonBuilder<4,InstanceArray,InstanceArrayPrimitive> { + MortonBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceArrayMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} + }; + template<> struct MortonBuilder<8,TriangleMesh,Triangle4> { MortonBuilder () {} Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshBuilderMortonGeneral(bvh,mesh,geomID,0);} @@ -118,6 +130,11 @@ namespace embree MortonBuilder () {} Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} }; + template<> + struct MortonBuilder<8,InstanceArray,InstanceArrayPrimitive> { + MortonBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceArrayMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} + }; template struct SAHBuilder {}; @@ -152,6 +169,11 @@ namespace embree Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} }; template<> + struct SAHBuilder<4,InstanceArray,InstanceArrayPrimitive> { + SAHBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceArrayMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} + }; + template<> struct SAHBuilder<8,TriangleMesh,Triangle4> { SAHBuilder () {} Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshBuilderSAH(bvh,mesh,geomID,0);} @@ -181,6 +203,11 @@ namespace embree SAHBuilder () {} Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} }; + template<> + struct SAHBuilder<8,InstanceArray,InstanceArrayPrimitive> { + SAHBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceArrayMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} + }; template struct RefitBuilder {}; @@ -215,6 +242,11 @@ namespace embree Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshRefitSAH(bvh,mesh,gtype,geomID,0);} }; template<> + struct RefitBuilder<4,InstanceArray,InstanceArrayPrimitive> { + RefitBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceArrayMeshRefitSAH(bvh,mesh,gtype,geomID,0);} + }; + template<> struct RefitBuilder<8,TriangleMesh,Triangle4> { RefitBuilder () {} Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshRefitSAH(bvh,mesh,geomID,0);} @@ -244,7 +276,12 @@ namespace embree RefitBuilder () {} Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshRefitSAH(bvh,mesh,gtype,geomID,0);} }; - + template<> + struct RefitBuilder<8,InstanceArray,InstanceArrayPrimitive> { + RefitBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceArrayMeshRefitSAH(bvh,mesh,gtype,geomID,0);} + }; + template struct MeshBuilder { MeshBuilder () {} diff --git a/thirdparty/embree/kernels/bvh/bvh_collider.cpp b/thirdparty/embree/kernels/bvh/bvh_collider.cpp index 9428c0b88e4..a22d701827d 100644 --- a/thirdparty/embree/kernels/bvh/bvh_collider.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_collider.cpp @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "bvh_collider.h" + #include "../geometry/triangle_triangle_intersector.h" +#include "../../common/algorithms/parallel_for.h" namespace embree { diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp index 9594f402c3f..1d797df88fe 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp @@ -19,6 +19,7 @@ #include "../geometry/subdivpatch1_intersector.h" #include "../geometry/object_intersector.h" #include "../geometry/instance_intersector.h" +#include "../geometry/instance_array_intersector.h" #include "../geometry/subgrid_intersector.h" #include "../geometry/subgrid_mb_intersector.h" #include "../geometry/curve_intersector_virtual.h" @@ -30,7 +31,7 @@ namespace embree template void BVHNIntersector1::intersect(const Accel::Intersectors* __restrict__ This, RayHit& __restrict__ ray, - IntersectContext* __restrict__ context) + RayQueryContext* __restrict__ context) { const BVH* __restrict__ bvh = (const BVH*)This->ptr; @@ -115,7 +116,7 @@ namespace embree template void BVHNIntersector1::occluded(const Accel::Intersectors* __restrict__ This, Ray& __restrict__ ray, - IntersectContext* __restrict__ context) + RayQueryContext* __restrict__ context) { const BVH* __restrict__ bvh = (const BVH*)This->ptr; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector1.h b/thirdparty/embree/kernels/bvh/bvh_intersector1.h index 2df3d6eddb1..3cec4e113b3 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector1.h +++ b/thirdparty/embree/kernels/bvh/bvh_intersector1.h @@ -26,8 +26,8 @@ namespace embree static const size_t stackSize = 1+(N-1)*BVH::maxDepth+3; // +3 due to 16-wide store public: - static void intersect (const Accel::Intersectors* This, RayHit& ray, IntersectContext* context); - static void occluded (const Accel::Intersectors* This, Ray& ray, IntersectContext* context); + static void intersect (const Accel::Intersectors* This, RayHit& ray, RayQueryContext* context); + static void occluded (const Accel::Intersectors* This, Ray& ray, RayQueryContext* context); static bool pointQuery(const Accel::Intersectors* This, PointQuery* query, PointQueryContext* context); }; } diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp index 831d6133675..1baecc7bbc4 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp @@ -48,6 +48,9 @@ namespace embree IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR1(BVH4InstanceIntersector1,BVHNIntersector1<4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersector1 >)); IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR1(BVH4InstanceMBIntersector1,BVHNIntersector1<4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersector1 >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR1(BVH4InstanceArrayIntersector1,BVHNIntersector1<4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersector1 >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR1(BVH4InstanceArrayMBIntersector1,BVHNIntersector1<4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersector1 >)); + IF_ENABLED_TRIS(DEFINE_INTERSECTOR1(QBVH4Triangle4iIntersector1Pluecker,BVHNIntersector1<4 COMMA BVH_QN1 COMMA false COMMA ArrayIntersector1 > >)); IF_ENABLED_QUADS(DEFINE_INTERSECTOR1(QBVH4Quad4iIntersector1Pluecker,BVHNIntersector1<4 COMMA BVH_QN1 COMMA false COMMA ArrayIntersector1 > >)); diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp index 1d393fd06b5..e9e22629847 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp @@ -20,6 +20,7 @@ #include "../geometry/subdivpatch1_intersector.h" #include "../geometry/object_intersector.h" #include "../geometry/instance_intersector.h" +#include "../geometry/instance_array_intersector.h" #include "../geometry/subgrid_intersector.h" #include "../geometry/subgrid_mb_intersector.h" #include "../geometry/curve_intersector_virtual.h" @@ -41,7 +42,7 @@ namespace embree Precalculations& pre, RayHitK& ray, const TravRayK& tray, - IntersectContext* context) + RayQueryContext* context) { /* stack state */ StackItemT stack[stackSizeSingle]; // stack of nodes @@ -105,7 +106,7 @@ namespace embree void BVHNIntersectorKHybrid::intersect(vint* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayHitK& __restrict__ ray, - IntersectContext* __restrict__ context) + RayQueryContext* __restrict__ context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -373,7 +374,7 @@ namespace embree void BVHNIntersectorKHybrid::intersectCoherent(vint* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayHitK& __restrict__ ray, - IntersectContext* context) + RayQueryContext* context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -539,7 +540,7 @@ namespace embree Precalculations& pre, RayK& ray, const TravRayK& tray, - IntersectContext* context) + RayQueryContext* context) { /* stack state */ NodeRef stack[stackSizeSingle]; // stack of nodes that still need to get traversed @@ -599,7 +600,7 @@ namespace embree void BVHNIntersectorKHybrid::occluded(vint* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayK& __restrict__ ray, - IntersectContext* context) + RayQueryContext* context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -784,7 +785,7 @@ namespace embree void BVHNIntersectorKHybrid::occludedCoherent(vint* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayK& __restrict__ ray, - IntersectContext* context) + RayQueryContext* context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -861,7 +862,7 @@ namespace embree #if defined(__AVX__) //STAT3(normal.trav_hit_boxes[popcnt(m_frustum_node)], 1, 1, 1); #endif - size_t num_child_hits = 0; + //size_t num_child_hits = 0; do { const size_t i = bscf(m_frustum_node); vfloat lnearP; @@ -875,7 +876,7 @@ namespace embree assert(child != BVH::emptyNode); BVHN::prefetch(child); if (likely(cur != BVH::emptyNode)) { - num_child_hits++; + //num_child_hits++; stackPtr->ptr = cur; stackPtr->mask = m_active; stackPtr++; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h index 50ebf375c46..1240bd5ab56 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h +++ b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h @@ -38,16 +38,16 @@ namespace embree private: static void intersect1(Accel::Intersectors* This, const BVH* bvh, NodeRef root, size_t k, Precalculations& pre, - RayHitK& ray, const TravRayK& tray, IntersectContext* context); + RayHitK& ray, const TravRayK& tray, RayQueryContext* context); static bool occluded1(Accel::Intersectors* This, const BVH* bvh, NodeRef root, size_t k, Precalculations& pre, - RayK& ray, const TravRayK& tray, IntersectContext* context); + RayK& ray, const TravRayK& tray, RayQueryContext* context); public: - static void intersect(vint* valid, Accel::Intersectors* This, RayHitK& ray, IntersectContext* context); - static void occluded (vint* valid, Accel::Intersectors* This, RayK& ray, IntersectContext* context); + static void intersect(vint* valid, Accel::Intersectors* This, RayHitK& ray, RayQueryContext* context); + static void occluded (vint* valid, Accel::Intersectors* This, RayK& ray, RayQueryContext* context); - static void intersectCoherent(vint* valid, Accel::Intersectors* This, RayHitK& ray, IntersectContext* context); - static void occludedCoherent (vint* valid, Accel::Intersectors* This, RayK& ray, IntersectContext* context); + static void intersectCoherent(vint* valid, Accel::Intersectors* This, RayHitK& ray, RayQueryContext* context); + static void occludedCoherent (vint* valid, Accel::Intersectors* This, RayK& ray, RayQueryContext* context); }; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp index 2137da6a255..72cefa9e8e8 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp @@ -48,6 +48,9 @@ namespace embree IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR4(BVH4InstanceIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceIntersectorK<4>> >)); IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR4(BVH4InstanceMBIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceIntersectorKMB<4>> >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR4(BVH4InstanceArrayIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceArrayIntersectorK<4>> >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR4(BVH4InstanceArrayMBIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceArrayIntersectorKMB<4>> >)); + IF_ENABLED_GRIDS(DEFINE_INTERSECTOR4(BVH4GridIntersector4HybridMoeller, BVHNIntersectorKHybrid<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA SubGridIntersectorKMoeller <4 COMMA 4 COMMA true> >)); //IF_ENABLED_GRIDS(DEFINE_INTERSECTOR4(BVH4GridIntersector4HybridMoeller, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA SubGridIntersectorKMoeller <4 COMMA 4 COMMA true> >)); diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_stream.cpp deleted file mode 100644 index 4a74d8468d9..00000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.cpp +++ /dev/null @@ -1,528 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "bvh_intersector_stream.h" - -#include "../geometry/intersector_iterators.h" -#include "../geometry/triangle_intersector.h" -#include "../geometry/trianglev_intersector.h" -#include "../geometry/trianglev_mb_intersector.h" -#include "../geometry/trianglei_intersector.h" -#include "../geometry/quadv_intersector.h" -#include "../geometry/quadi_intersector.h" -#include "../geometry/linei_intersector.h" -#include "../geometry/subdivpatch1_intersector.h" -#include "../geometry/object_intersector.h" -#include "../geometry/instance_intersector.h" - -#include "../common/scene.h" -#include - -namespace embree -{ - namespace isa - { - __aligned(64) static const int shiftTable[32] = { - (int)1 << 0, (int)1 << 1, (int)1 << 2, (int)1 << 3, (int)1 << 4, (int)1 << 5, (int)1 << 6, (int)1 << 7, - (int)1 << 8, (int)1 << 9, (int)1 << 10, (int)1 << 11, (int)1 << 12, (int)1 << 13, (int)1 << 14, (int)1 << 15, - (int)1 << 16, (int)1 << 17, (int)1 << 18, (int)1 << 19, (int)1 << 20, (int)1 << 21, (int)1 << 22, (int)1 << 23, - (int)1 << 24, (int)1 << 25, (int)1 << 26, (int)1 << 27, (int)1 << 28, (int)1 << 29, (int)1 << 30, (int)1 << 31 - }; - - template - __forceinline void BVHNIntersectorStream::intersect(Accel::Intersectors* __restrict__ This, - RayHitN** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - /* we may traverse an empty BVH in case all geometry was invalid */ - BVH* __restrict__ bvh = (BVH*) This->ptr; - if (bvh->root == BVH::emptyNode) - return; - - // Only the coherent code path is implemented - assert(context->isCoherent()); - intersectCoherent(This, (RayHitK**)inputPackets, numOctantRays, context); - } - - template - template - __forceinline void BVHNIntersectorStream::intersectCoherent(Accel::Intersectors* __restrict__ This, - RayHitK** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - assert(context->isCoherent()); - - BVH* __restrict__ bvh = (BVH*) This->ptr; - __aligned(64) StackItemMaskCoherent stack[stackSizeSingle]; // stack of nodes - assert(numOctantRays <= MAX_INTERNAL_STREAM_SIZE); - - __aligned(64) TravRayKStream packets[MAX_INTERNAL_STREAM_SIZE/K]; - __aligned(64) Frustum frustum; - - bool commonOctant = true; - const size_t m_active = initPacketsAndFrustum((RayK**)inputPackets, numOctantRays, packets, frustum, commonOctant); - if (unlikely(m_active == 0)) return; - - /* case of non-common origin */ - if (unlikely(!commonOctant)) - { - const size_t numPackets = (numOctantRays+K-1)/K; - for (size_t i = 0; i < numPackets; i++) - This->intersect(inputPackets[i]->tnear() <= inputPackets[i]->tfar, *inputPackets[i], context); - return; - } - - stack[0].mask = m_active; - stack[0].parent = 0; - stack[0].child = bvh->root; - - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - - StackItemMaskCoherent* stackPtr = stack + 1; - - while (1) pop: - { - if (unlikely(stackPtr == stack)) break; - - STAT3(normal.trav_stack_pop,1,1,1); - stackPtr--; - /*! pop next node */ - NodeRef cur = NodeRef(stackPtr->child); - size_t m_trav_active = stackPtr->mask; - assert(m_trav_active); - NodeRef parent = stackPtr->parent; - - while (1) - { - if (unlikely(cur.isLeaf())) break; - const AABBNode* __restrict__ const node = cur.getAABBNode(); - parent = cur; - - __aligned(64) size_t maskK[N]; - for (size_t i = 0; i < N; i++) - maskK[i] = m_trav_active; - vfloat dist; - const size_t m_node_hit = traverseCoherentStream(m_trav_active, packets, node, frustum, maskK, dist); - if (unlikely(m_node_hit == 0)) goto pop; - - BVHNNodeTraverserStreamHitCoherent::traverseClosestHit(cur, m_trav_active, vbool((int)m_node_hit), dist, (size_t*)maskK, stackPtr); - assert(m_trav_active); - } - - /* non-root and leaf => full culling test for all rays */ - if (unlikely(parent != 0 && cur.isLeaf())) - { - const AABBNode* __restrict__ const node = parent.getAABBNode(); - size_t boxID = 0xff; - for (size_t i = 0; i < N; i++) - if (node->child(i) == cur) { boxID = i; break; } - assert(boxID < N); - assert(cur == node->child(boxID)); - m_trav_active = intersectAABBNodePacket(m_trav_active, packets, node, boxID, frustum.nf); - } - - /*! this is a leaf node */ - assert(cur != BVH::emptyNode); - STAT3(normal.trav_leaves, 1, 1, 1); - size_t num; PrimitiveK* prim = (PrimitiveK*)cur.leaf(num); - - size_t bits = m_trav_active; - - /*! intersect stream of rays with all primitives */ - size_t lazy_node = 0; -#if defined(__SSE4_2__) - STAT_USER(1,(popcnt(bits)+K-1)/K*4); -#endif - while(bits) - { - size_t i = bsf(bits) / K; - const size_t m_isec = ((((size_t)1 << K)-1) << (i*K)); - assert(m_isec & bits); - bits &= ~m_isec; - - TravRayKStream& p = packets[i]; - vbool m_valid = p.tnear <= p.tfar; - PrimitiveIntersectorK::intersectK(m_valid, This, *inputPackets[i], context, prim, num, lazy_node); - p.tfar = min(p.tfar, inputPackets[i]->tfar); - }; - - } // traversal + intersection - } - - template - __forceinline void BVHNIntersectorStream::occluded(Accel::Intersectors* __restrict__ This, - RayN** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - /* we may traverse an empty BVH in case all geometry was invalid */ - BVH* __restrict__ bvh = (BVH*) This->ptr; - if (bvh->root == BVH::emptyNode) - return; - - if (unlikely(context->isCoherent())) - occludedCoherent(This, (RayK**)inputPackets, numOctantRays, context); - else - occludedIncoherent(This, (RayK**)inputPackets, numOctantRays, context); - } - - template - template - __noinline void BVHNIntersectorStream::occludedCoherent(Accel::Intersectors* __restrict__ This, - RayK** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - assert(context->isCoherent()); - - BVH* __restrict__ bvh = (BVH*)This->ptr; - __aligned(64) StackItemMaskCoherent stack[stackSizeSingle]; // stack of nodes - assert(numOctantRays <= MAX_INTERNAL_STREAM_SIZE); - - /* inactive rays should have been filtered out before */ - __aligned(64) TravRayKStream packets[MAX_INTERNAL_STREAM_SIZE/K]; - __aligned(64) Frustum frustum; - - bool commonOctant = true; - size_t m_active = initPacketsAndFrustum(inputPackets, numOctantRays, packets, frustum, commonOctant); - - /* valid rays */ - if (unlikely(m_active == 0)) return; - - /* case of non-common origin */ - if (unlikely(!commonOctant)) - { - const size_t numPackets = (numOctantRays+K-1)/K; - for (size_t i = 0; i < numPackets; i++) - This->occluded(inputPackets[i]->tnear() <= inputPackets[i]->tfar, *inputPackets[i], context); - return; - } - - stack[0].mask = m_active; - stack[0].parent = 0; - stack[0].child = bvh->root; - - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - - StackItemMaskCoherent* stackPtr = stack + 1; - - while (1) pop: - { - if (unlikely(stackPtr == stack)) break; - - STAT3(normal.trav_stack_pop,1,1,1); - stackPtr--; - /*! pop next node */ - NodeRef cur = NodeRef(stackPtr->child); - size_t m_trav_active = stackPtr->mask & m_active; - if (unlikely(!m_trav_active)) continue; - assert(m_trav_active); - NodeRef parent = stackPtr->parent; - - while (1) - { - if (unlikely(cur.isLeaf())) break; - const AABBNode* __restrict__ const node = cur.getAABBNode(); - parent = cur; - - __aligned(64) size_t maskK[N]; - for (size_t i = 0; i < N; i++) - maskK[i] = m_trav_active; - - vfloat dist; - const size_t m_node_hit = traverseCoherentStream(m_trav_active, packets, node, frustum, maskK, dist); - if (unlikely(m_node_hit == 0)) goto pop; - - BVHNNodeTraverserStreamHitCoherent::traverseAnyHit(cur, m_trav_active, vbool((int)m_node_hit), (size_t*)maskK, stackPtr); - assert(m_trav_active); - } - - /* non-root and leaf => full culling test for all rays */ - if (unlikely(parent != 0 && cur.isLeaf())) - { - const AABBNode* __restrict__ const node = parent.getAABBNode(); - size_t boxID = 0xff; - for (size_t i = 0; i < N; i++) - if (node->child(i) == cur) { boxID = i; break; } - assert(boxID < N); - assert(cur == node->child(boxID)); - m_trav_active = intersectAABBNodePacket(m_trav_active, packets, node, boxID, frustum.nf); - } - - /*! this is a leaf node */ - assert(cur != BVH::emptyNode); - STAT3(normal.trav_leaves, 1, 1, 1); - size_t num; PrimitiveK* prim = (PrimitiveK*)cur.leaf(num); - - size_t bits = m_trav_active & m_active; - /*! intersect stream of rays with all primitives */ - size_t lazy_node = 0; -#if defined(__SSE4_2__) - STAT_USER(1,(popcnt(bits)+K-1)/K*4); -#endif - while (bits) - { - size_t i = bsf(bits) / K; - const size_t m_isec = ((((size_t)1 << K)-1) << (i*K)); - assert(m_isec & bits); - bits &= ~m_isec; - TravRayKStream& p = packets[i]; - vbool m_valid = p.tnear <= p.tfar; - vbool m_hit = PrimitiveIntersectorK::occludedK(m_valid, This, *inputPackets[i], context, prim, num, lazy_node); - inputPackets[i]->tfar = select(m_hit & m_valid, vfloat(neg_inf), inputPackets[i]->tfar); - m_active &= ~((size_t)movemask(m_hit) << (i*K)); - } - - } // traversal + intersection - } - - - template - template - __forceinline void BVHNIntersectorStream::occludedIncoherent(Accel::Intersectors* __restrict__ This, - RayK** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - assert(!context->isCoherent()); - assert(types & BVH_FLAG_ALIGNED_NODE); - - __aligned(64) TravRayKStream packet[MAX_INTERNAL_STREAM_SIZE/K]; - - assert(numOctantRays <= 32); - const size_t numPackets = (numOctantRays+K-1)/K; - size_t m_active = 0; - for (size_t i = 0; i < numPackets; i++) - { - const vfloat tnear = inputPackets[i]->tnear(); - const vfloat tfar = inputPackets[i]->tfar; - vbool m_valid = (tnear <= tfar) & (tnear >= 0.0f); - m_active |= (size_t)movemask(m_valid) << (K*i); - const Vec3vf& org = inputPackets[i]->org; - const Vec3vf& dir = inputPackets[i]->dir; - vfloat packet_min_dist = max(tnear, 0.0f); - vfloat packet_max_dist = select(m_valid, tfar, neg_inf); - new (&packet[i]) TravRayKStream(org, dir, packet_min_dist, packet_max_dist); - } - - BVH* __restrict__ bvh = (BVH*)This->ptr; - - StackItemMaskT stack[stackSizeSingle]; // stack of nodes - StackItemMaskT* stackPtr = stack + 1; // current stack pointer - stack[0].ptr = bvh->root; - stack[0].mask = m_active; - - size_t terminated = ~m_active; - - /* near/far offsets based on first ray */ - const NearFarPrecalculations nf(Vec3fa(packet[0].rdir.x[0], packet[0].rdir.y[0], packet[0].rdir.z[0]), N); - - while (1) pop: - { - if (unlikely(stackPtr == stack)) break; - STAT3(shadow.trav_stack_pop,1,1,1); - stackPtr--; - NodeRef cur = NodeRef(stackPtr->ptr); - size_t cur_mask = stackPtr->mask & (~terminated); - if (unlikely(cur_mask == 0)) continue; - - while (true) - { - /*! stop if we found a leaf node */ - if (unlikely(cur.isLeaf())) break; - const AABBNode* __restrict__ const node = cur.getAABBNode(); - - const vint vmask = traverseIncoherentStream(cur_mask, packet, node, nf, shiftTable); - - size_t mask = movemask(vmask != vint(zero)); - if (unlikely(mask == 0)) goto pop; - - __aligned(64) unsigned int child_mask[N]; - vint::storeu(child_mask, vmask); // this explicit store here causes much better code generation - - /*! one child is hit, continue with that child */ - size_t r = bscf(mask); - assert(r < N); - cur = node->child(r); - BVHN::prefetch(cur,types); - cur_mask = child_mask[r]; - - /* simple in order sequence */ - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) continue; - stackPtr->ptr = cur; - stackPtr->mask = cur_mask; - stackPtr++; - - for (; ;) - { - r = bscf(mask); - assert(r < N); - - cur = node->child(r); - BVHN::prefetch(cur,types); - cur_mask = child_mask[r]; - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) break; - stackPtr->ptr = cur; - stackPtr->mask = cur_mask; - stackPtr++; - } - } - - /*! this is a leaf node */ - assert(cur != BVH::emptyNode); - STAT3(shadow.trav_leaves,1,1,1); - size_t num; PrimitiveK* prim = (PrimitiveK*)cur.leaf(num); - - size_t bits = cur_mask; - size_t lazy_node = 0; - - for (; bits != 0;) - { - const size_t rayID = bscf(bits); - - RayK &ray = *inputPackets[rayID / K]; - const size_t k = rayID % K; - if (PrimitiveIntersectorK::occluded(This, ray, k, context, prim, num, lazy_node)) - { - ray.tfar[k] = neg_inf; - terminated |= (size_t)1 << rayID; - } - - /* lazy node */ - if (unlikely(lazy_node)) - { - stackPtr->ptr = lazy_node; - stackPtr->mask = cur_mask; - stackPtr++; - } - } - - if (unlikely(terminated == (size_t)-1)) break; - } - } - - //////////////////////////////////////////////////////////////////////////////// - /// ArrayIntersectorKStream Definitions - //////////////////////////////////////////////////////////////////////////////// - - template - struct Triangle4IntersectorStreamMoeller { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Triangle4vIntersectorStreamPluecker { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Triangle4iIntersectorStreamMoeller { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Triangle4iIntersectorStreamPluecker { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Quad4vIntersectorStreamMoeller { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Quad4iIntersectorStreamMoeller { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Quad4vIntersectorStreamPluecker { - template using Type = ArrayIntersectorKStream>; - }; - - template - struct Quad4iIntersectorStreamPluecker { - template using Type = ArrayIntersectorKStream>; - }; - - struct ObjectIntersectorStream { - template using Type = ArrayIntersectorKStream>; - }; - - struct InstanceIntersectorStream { - template using Type = ArrayIntersectorKStream>; - }; - - // ===================================================================================================== - // ===================================================================================================== - // ===================================================================================================== - - template - void BVHNIntersectorStreamPacketFallback::intersect(Accel::Intersectors* __restrict__ This, - RayHitN** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - if (unlikely(context->isCoherent())) - intersectK(This, (RayHitK**)inputRays, numTotalRays, context); - else - intersectK(This, (RayHitK**)inputRays, numTotalRays, context); - } - - template - void BVHNIntersectorStreamPacketFallback::occluded(Accel::Intersectors* __restrict__ This, - RayN** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - if (unlikely(context->isCoherent())) - occludedK(This, (RayK**)inputRays, numTotalRays, context); - else - occludedK(This, (RayK**)inputRays, numTotalRays, context); - } - - template - template - __noinline void BVHNIntersectorStreamPacketFallback::intersectK(Accel::Intersectors* __restrict__ This, - RayHitK** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - /* fallback to packets */ - for (size_t i = 0; i < numTotalRays; i += K) - { - const vint vi = vint(int(i)) + vint(step); - vbool valid = vi < vint(int(numTotalRays)); - RayHitK& ray = *(inputRays[i / K]); - valid &= ray.tnear() <= ray.tfar; - This->intersect(valid, ray, context); - } - } - - template - template - __noinline void BVHNIntersectorStreamPacketFallback::occludedK(Accel::Intersectors* __restrict__ This, - RayK** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - /* fallback to packets */ - for (size_t i = 0; i < numTotalRays; i += K) - { - const vint vi = vint(int(i)) + vint(step); - vbool valid = vi < vint(int(numTotalRays)); - RayK& ray = *(inputRays[i / K]); - valid &= ray.tnear() <= ray.tfar; - This->occluded(valid, ray, context); - } - } - } -} diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.h b/thirdparty/embree/kernels/bvh/bvh_intersector_stream.h deleted file mode 100644 index c7e040fadbf..00000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.h +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "node_intersector_packet_stream.h" -#include "node_intersector_frustum.h" -#include "bvh_traverser_stream.h" - -namespace embree -{ - namespace isa - { - /*! BVH ray stream intersector. */ - template - class BVHNIntersectorStream - { - /* shortcuts for frequently used types */ - template using PrimitiveIntersectorK = typename PrimitiveIntersector::template Type; - template using PrimitiveK = typename PrimitiveIntersectorK::PrimitiveK; - typedef BVHN BVH; - typedef typename BVH::NodeRef NodeRef; - typedef typename BVH::BaseNode BaseNode; - typedef typename BVH::AABBNode AABBNode; - typedef typename BVH::AABBNodeMB AABBNodeMB; - - template - __forceinline static size_t initPacketsAndFrustum(RayK** inputPackets, size_t numOctantRays, - TravRayKStream* packets, Frustum& frustum, bool& commonOctant) - { - const size_t numPackets = (numOctantRays+K-1)/K; - - Vec3vf tmp_min_rdir(pos_inf); - Vec3vf tmp_max_rdir(neg_inf); - Vec3vf tmp_min_org(pos_inf); - Vec3vf tmp_max_org(neg_inf); - vfloat tmp_min_dist(pos_inf); - vfloat tmp_max_dist(neg_inf); - - size_t m_active = 0; - for (size_t i = 0; i < numPackets; i++) - { - const vfloat tnear = inputPackets[i]->tnear(); - const vfloat tfar = inputPackets[i]->tfar; - vbool m_valid = (tnear <= tfar) & (tnear >= 0.0f); - -#if defined(EMBREE_IGNORE_INVALID_RAYS) - m_valid &= inputPackets[i]->valid(); -#endif - - m_active |= (size_t)movemask(m_valid) << (i*K); - - vfloat packet_min_dist = max(tnear, 0.0f); - vfloat packet_max_dist = select(m_valid, tfar, neg_inf); - tmp_min_dist = min(tmp_min_dist, packet_min_dist); - tmp_max_dist = max(tmp_max_dist, packet_max_dist); - - const Vec3vf& org = inputPackets[i]->org; - const Vec3vf& dir = inputPackets[i]->dir; - - new (&packets[i]) TravRayKStream(org, dir, packet_min_dist, packet_max_dist); - - tmp_min_rdir = min(tmp_min_rdir, select(m_valid, packets[i].rdir, Vec3vf(pos_inf))); - tmp_max_rdir = max(tmp_max_rdir, select(m_valid, packets[i].rdir, Vec3vf(neg_inf))); - tmp_min_org = min(tmp_min_org , select(m_valid,org , Vec3vf(pos_inf))); - tmp_max_org = max(tmp_max_org , select(m_valid,org , Vec3vf(neg_inf))); - } - - m_active &= (numOctantRays == (8 * sizeof(size_t))) ? (size_t)-1 : (((size_t)1 << numOctantRays)-1); - - - const Vec3fa reduced_min_rdir(reduce_min(tmp_min_rdir.x), - reduce_min(tmp_min_rdir.y), - reduce_min(tmp_min_rdir.z)); - - const Vec3fa reduced_max_rdir(reduce_max(tmp_max_rdir.x), - reduce_max(tmp_max_rdir.y), - reduce_max(tmp_max_rdir.z)); - - const Vec3fa reduced_min_origin(reduce_min(tmp_min_org.x), - reduce_min(tmp_min_org.y), - reduce_min(tmp_min_org.z)); - - const Vec3fa reduced_max_origin(reduce_max(tmp_max_org.x), - reduce_max(tmp_max_org.y), - reduce_max(tmp_max_org.z)); - - commonOctant = - (reduced_max_rdir.x < 0.0f || reduced_min_rdir.x >= 0.0f) && - (reduced_max_rdir.y < 0.0f || reduced_min_rdir.y >= 0.0f) && - (reduced_max_rdir.z < 0.0f || reduced_min_rdir.z >= 0.0f); - - const float frustum_min_dist = reduce_min(tmp_min_dist); - const float frustum_max_dist = reduce_max(tmp_max_dist); - - frustum.init(reduced_min_origin, reduced_max_origin, - reduced_min_rdir, reduced_max_rdir, - frustum_min_dist, frustum_max_dist, - N); - - return m_active; - } - - template - __forceinline static size_t intersectAABBNodePacket(size_t m_active, - const TravRayKStream* packets, - const AABBNode* __restrict__ node, - size_t boxID, - const NearFarPrecalculations& nf) - { - assert(m_active); - const size_t startPacketID = bsf(m_active) / K; - const size_t endPacketID = bsr(m_active) / K; - size_t m_trav_active = 0; - for (size_t i = startPacketID; i <= endPacketID; i++) - { - const size_t m_hit = intersectNodeK(node, boxID, packets[i], nf); - m_trav_active |= m_hit << (i*K); - } - return m_trav_active; - } - - template - __forceinline static size_t traverseCoherentStream(size_t m_active, - TravRayKStream* packets, - const AABBNode* __restrict__ node, - const Frustum& frustum, - size_t* maskK, - vfloat& dist) - { - size_t m_node_hit = intersectNodeFrustum(node, frustum, dist); - const size_t first_index = bsf(m_active); - const size_t first_packetID = first_index / K; - const size_t first_rayID = first_index % K; - size_t m_first_hit = intersectNode1(node, packets[first_packetID], first_rayID, frustum.nf); - - /* this make traversal independent of the ordering of rays */ - size_t m_node = m_node_hit ^ m_first_hit; - while (unlikely(m_node)) - { - const size_t boxID = bscf(m_node); - const size_t m_current = m_active & intersectAABBNodePacket(m_active, packets, node, boxID, frustum.nf); - m_node_hit ^= m_current ? (size_t)0 : ((size_t)1 << boxID); - maskK[boxID] = m_current; - } - return m_node_hit; - } - - // TODO: explicit 16-wide path for KNL - template - __forceinline static vint traverseIncoherentStream(size_t m_active, - TravRayKStreamFast* __restrict__ packets, - const AABBNode* __restrict__ node, - const NearFarPrecalculations& nf, - const int shiftTable[32]) - { - const vfloat bminX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearX)); - const vfloat bminY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearY)); - const vfloat bminZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat bmaxX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farX)); - const vfloat bmaxY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farY)); - const vfloat bmaxZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farZ)); - assert(m_active); - vint vmask(zero); - do - { - STAT3(shadow.trav_nodes,1,1,1); - const size_t rayID = bscf(m_active); - assert(rayID < MAX_INTERNAL_STREAM_SIZE); - TravRayKStream &p = packets[rayID / K]; - const size_t i = rayID % K; - const vint bitmask(shiftTable[rayID]); - -#if defined (__aarch64__) - const vfloat tNearX = madd(bminX, p.rdir.x[i], p.neg_org_rdir.x[i]); - const vfloat tNearY = madd(bminY, p.rdir.y[i], p.neg_org_rdir.y[i]); - const vfloat tNearZ = madd(bminZ, p.rdir.z[i], p.neg_org_rdir.z[i]); - const vfloat tFarX = madd(bmaxX, p.rdir.x[i], p.neg_org_rdir.x[i]); - const vfloat tFarY = madd(bmaxY, p.rdir.y[i], p.neg_org_rdir.y[i]); - const vfloat tFarZ = madd(bmaxZ, p.rdir.z[i], p.neg_org_rdir.z[i]); -#else - const vfloat tNearX = msub(bminX, p.rdir.x[i], p.org_rdir.x[i]); - const vfloat tNearY = msub(bminY, p.rdir.y[i], p.org_rdir.y[i]); - const vfloat tNearZ = msub(bminZ, p.rdir.z[i], p.org_rdir.z[i]); - const vfloat tFarX = msub(bmaxX, p.rdir.x[i], p.org_rdir.x[i]); - const vfloat tFarY = msub(bmaxY, p.rdir.y[i], p.org_rdir.y[i]); - const vfloat tFarZ = msub(bmaxZ, p.rdir.z[i], p.org_rdir.z[i]); -#endif - - const vfloat tNear = maxi(tNearX, tNearY, tNearZ, vfloat(p.tnear[i])); - const vfloat tFar = mini(tFarX , tFarY , tFarZ, vfloat(p.tfar[i])); - - const vbool hit_mask = tNear <= tFar; -#if defined(__AVX2__) - vmask = vmask | (bitmask & vint(hit_mask)); -#else - vmask = select(hit_mask, vmask | bitmask, vmask); -#endif - } while(m_active); - return vmask; - } - - template - __forceinline static vint traverseIncoherentStream(size_t m_active, - TravRayKStreamRobust* __restrict__ packets, - const AABBNode* __restrict__ node, - const NearFarPrecalculations& nf, - const int shiftTable[32]) - { - const vfloat bminX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearX)); - const vfloat bminY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearY)); - const vfloat bminZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat bmaxX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farX)); - const vfloat bmaxY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farY)); - const vfloat bmaxZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farZ)); - assert(m_active); - vint vmask(zero); - do - { - STAT3(shadow.trav_nodes,1,1,1); - const size_t rayID = bscf(m_active); - assert(rayID < MAX_INTERNAL_STREAM_SIZE); - TravRayKStream &p = packets[rayID / K]; - const size_t i = rayID % K; - const vint bitmask(shiftTable[rayID]); - const vfloat tNearX = (bminX - p.org.x[i]) * p.rdir.x[i]; - const vfloat tNearY = (bminY - p.org.y[i]) * p.rdir.y[i]; - const vfloat tNearZ = (bminZ - p.org.z[i]) * p.rdir.z[i]; - const vfloat tFarX = (bmaxX - p.org.x[i]) * p.rdir.x[i]; - const vfloat tFarY = (bmaxY - p.org.y[i]) * p.rdir.y[i]; - const vfloat tFarZ = (bmaxZ - p.org.z[i]) * p.rdir.z[i]; - const vfloat tNear = maxi(tNearX, tNearY, tNearZ, vfloat(p.tnear[i])); - const vfloat tFar = mini(tFarX , tFarY , tFarZ, vfloat(p.tfar[i])); - const float round_down = 1.0f-2.0f*float(ulp); - const float round_up = 1.0f+2.0f*float(ulp); - const vbool hit_mask = round_down*tNear <= round_up*tFar; -#if defined(__AVX2__) - vmask = vmask | (bitmask & vint(hit_mask)); -#else - vmask = select(hit_mask, vmask | bitmask, vmask); -#endif - } while(m_active); - return vmask; - } - - - static const size_t stackSizeSingle = 1+(N-1)*BVH::maxDepth; - - public: - static void intersect(Accel::Intersectors* This, RayHitN** inputRays, size_t numRays, IntersectContext* context); - static void occluded (Accel::Intersectors* This, RayN** inputRays, size_t numRays, IntersectContext* context); - - private: - template - static void intersectCoherent(Accel::Intersectors* This, RayHitK** inputRays, size_t numRays, IntersectContext* context); - - template - static void occludedCoherent(Accel::Intersectors* This, RayK** inputRays, size_t numRays, IntersectContext* context); - - template - static void occludedIncoherent(Accel::Intersectors* This, RayK** inputRays, size_t numRays, IntersectContext* context); - }; - - - /*! BVH ray stream intersector with direct fallback to packets. */ - template - class BVHNIntersectorStreamPacketFallback - { - public: - static void intersect(Accel::Intersectors* This, RayHitN** inputRays, size_t numRays, IntersectContext* context); - static void occluded (Accel::Intersectors* This, RayN** inputRays, size_t numRays, IntersectContext* context); - - private: - template - static void intersectK(Accel::Intersectors* This, RayHitK** inputRays, size_t numRays, IntersectContext* context); - - template - static void occludedK(Accel::Intersectors* This, RayK** inputRays, size_t numRays, IntersectContext* context); - }; - } -} diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_bvh4.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_stream_bvh4.cpp deleted file mode 100644 index c3e5f137b8b..00000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_bvh4.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "bvh_intersector_stream.cpp" - -namespace embree -{ - namespace isa - { - - //////////////////////////////////////////////////////////////////////////////// - /// General BVHIntersectorStreamPacketFallback Intersector - //////////////////////////////////////////////////////////////////////////////// - - DEFINE_INTERSECTORN(BVH4IntersectorStreamPacketFallback,BVHNIntersectorStreamPacketFallback<4>); - - //////////////////////////////////////////////////////////////////////////////// - /// BVH4IntersectorStream Definitions - //////////////////////////////////////////////////////////////////////////////// - - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4iIntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Triangle4iIntersectorStreamMoeller>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4vIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Triangle4vIntersectorStreamPluecker>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4iIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Triangle4iIntersectorStreamPluecker>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4IntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Triangle4IntersectorStreamMoeller>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4IntersectorStreamMoellerNoFilter, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Triangle4IntersectorStreamMoeller>)); - - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4vIntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Quad4vIntersectorStreamMoeller>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4vIntersectorStreamMoellerNoFilter,BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Quad4vIntersectorStreamMoeller>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4iIntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Quad4iIntersectorStreamMoeller>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4vIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Quad4vIntersectorStreamPluecker>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4iIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Quad4iIntersectorStreamPluecker>)); - - IF_ENABLED_USER(DEFINE_INTERSECTORN(BVH4VirtualIntersectorStream,BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA ObjectIntersectorStream>)); - IF_ENABLED_INSTANCE(DEFINE_INTERSECTORN(BVH4InstanceIntersectorStream,BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA InstanceIntersectorStream>)); - } -} diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.cpp deleted file mode 100644 index b858eb163f4..00000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.cpp +++ /dev/null @@ -1,657 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "bvh_intersector_stream_filters.h" -#include "bvh_intersector_stream.h" - -namespace embree -{ - namespace isa - { - template - __noinline void RayStreamFilter::filterAOS(Scene* scene, void* _rayN, size_t N, size_t stride, IntersectContext* context) - { - RayStreamAOS rayN(_rayN); - - /* use fast path for coherent ray mode */ - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayTypeK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - for (size_t i = 0; i < N; i += MAX_INTERNAL_STREAM_SIZE) - { - const size_t size = min(N - i, MAX_INTERNAL_STREAM_SIZE); - - /* convert from AOS to SOA */ - for (size_t j = 0; j < size; j += K) - { - const vint vij = vint(int(i+j)) + vint(step); - const vbool valid = vij < vint(int(N)); - const vint offset = vij * int(stride); - const size_t packetIndex = j / K; - - RayTypeK ray = rayN.getRayByOffset(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - - rays[packetIndex] = ray; - rayPtrs[packetIndex] = &rays[packetIndex]; // rayPtrs might get reordered for occludedN - } - - /* trace stream */ - scene->intersectors.intersectN(rayPtrs, size, context); - - /* convert from SOA to AOS */ - for (size_t j = 0; j < size; j += K) - { - const vint vij = vint(int(i+j)) + vint(step); - const vbool valid = vij < vint(int(N)); - const vint offset = vij * int(stride); - const size_t packetIndex = j / K; - rayN.setHitByOffset(valid, offset, rays[packetIndex]); - } - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N;) - { - const Ray& ray = rayN.getRayByOffset(inputRayID * stride); - - /* skip invalid rays */ - if (unlikely(ray.tnear() > ray.tfar || ray.tfar < 0.0f)) { inputRayID++; continue; } // ignore invalid or already occluded rays -#if defined(EMBREE_IGNORE_INVALID_RAYS) - if (unlikely(!ray.valid())) { inputRayID++; continue; } -#endif - - const unsigned int octantID = movemask(vfloat4(Vec3fa(ray.dir)) < 0.0f) & 0x7; - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)inputRayID; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayIDs = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint offset = *(vint*)&rayIDs[j] * int(stride); - RayK& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByOffset(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint offset = *(vint*)&rayIDs[j] * int(stride); - rayN.setHitByOffset(valid, offset, rays[j/K]); - } - - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < N; i += K) - { - const vint vi = vint(int(i)) + vint(step); - vbool valid = vi < vint(int(N)); - const vint offset = vi * int(stride); - - RayTypeK ray = rayN.getRayByOffset(valid, offset); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByOffset(valid, offset, ray); - } - } - } - - template - __noinline void RayStreamFilter::filterAOP(Scene* scene, void** _rayN, size_t N, IntersectContext* context) - { - RayStreamAOP rayN(_rayN); - - /* use fast path for coherent ray mode */ - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayTypeK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - for (size_t i = 0; i < N; i += MAX_INTERNAL_STREAM_SIZE) - { - const size_t size = min(N - i, MAX_INTERNAL_STREAM_SIZE); - - /* convert from AOP to SOA */ - for (size_t j = 0; j < size; j += K) - { - const vint vij = vint(int(i+j)) + vint(step); - const vbool valid = vij < vint(int(N)); - const size_t packetIndex = j / K; - - RayTypeK ray = rayN.getRayByIndex(valid, vij); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - - rays[packetIndex] = ray; - rayPtrs[packetIndex] = &rays[packetIndex]; // rayPtrs might get reordered for occludedN - } - - /* trace stream */ - scene->intersectors.intersectN(rayPtrs, size, context); - - /* convert from SOA to AOP */ - for (size_t j = 0; j < size; j += K) - { - const vint vij = vint(int(i+j)) + vint(step); - const vbool valid = vij < vint(int(N)); - const size_t packetIndex = j / K; - - rayN.setHitByIndex(valid, vij, rays[packetIndex]); - } - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N;) - { - const Ray& ray = rayN.getRayByIndex(inputRayID); - - /* skip invalid rays */ - if (unlikely(ray.tnear() > ray.tfar || ray.tfar < 0.0f)) { inputRayID++; continue; } // ignore invalid or already occluded rays -#if defined(EMBREE_IGNORE_INVALID_RAYS) - if (unlikely(!ray.valid())) { inputRayID++; continue; } -#endif - - const unsigned int octantID = movemask(lt_mask(ray.dir,Vec3fa(0.0f))); - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)inputRayID; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayIDs = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint index = *(vint*)&rayIDs[j]; - RayK& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByIndex(valid, index); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint index = *(vint*)&rayIDs[j]; - rayN.setHitByIndex(valid, index, rays[j/K]); - } - - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < N; i += K) - { - const vint vi = vint(int(i)) + vint(step); - vbool valid = vi < vint(int(N)); - - RayTypeK ray = rayN.getRayByIndex(valid, vi); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByIndex(valid, vi, ray); - } - } - } - - template - __noinline void RayStreamFilter::filterSOA(Scene* scene, char* rayData, size_t N, size_t numPackets, size_t stride, IntersectContext* context) - { - const size_t rayDataAlignment = (size_t)rayData % (K*sizeof(float)); - const size_t offsetAlignment = (size_t)stride % (K*sizeof(float)); - - /* fast path for packets with the correct width and data alignment */ - if (likely(N == K && - !rayDataAlignment && - !offsetAlignment)) - { - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - size_t packetIndex = 0; - for (size_t i = 0; i < numPackets; i++) - { - const size_t offset = i * stride; - RayTypeK& ray = *(RayTypeK*)(rayData + offset); - rayPtrs[packetIndex++] = &ray; - - /* trace as stream */ - if (unlikely(packetIndex == MAX_INTERNAL_STREAM_SIZE / K)) - { - const size_t size = packetIndex*K; - scene->intersectors.intersectN(rayPtrs, size, context); - packetIndex = 0; - } - } - - /* flush remaining packets */ - if (unlikely(packetIndex > 0)) - { - const size_t size = packetIndex*K; - scene->intersectors.intersectN(rayPtrs, size, context); - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - RayStreamSOA rayN(rayData, K); - - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N*numPackets;) - { - const size_t offset = (inputRayID / K) * stride + (inputRayID % K) * sizeof(float); - - /* skip invalid rays */ - if (unlikely(!rayN.isValidByOffset(offset))) { inputRayID++; continue; } // ignore invalid or already occluded rays - #if defined(EMBREE_IGNORE_INVALID_RAYS) - __aligned(64) Ray ray = rayN.getRayByOffset(offset); - if (unlikely(!ray.valid())) { inputRayID++; continue; } - #endif - - const unsigned int octantID = (unsigned int)rayN.getOctantByOffset(offset); - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)offset; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayOffsets = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint offset = *(vint*)&rayOffsets[j]; - RayK& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByOffset(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint offset = *(vint*)&rayOffsets[j]; - rayN.setHitByOffset(valid, offset, rays[j/K]); - } - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < numPackets; i++) - { - const size_t offset = i * stride; - RayTypeK& ray = *(RayTypeK*)(rayData + offset); - const vbool valid = ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - } - } - } - else - { - /* fallback to packets for arbitrary packet size and alignment */ - for (size_t i = 0; i < numPackets; i++) - { - const size_t offsetN = i * stride; - RayStreamSOA rayN(rayData + offsetN, N); - - for (size_t j = 0; j < N; j += K) - { - const size_t offset = j * sizeof(float); - vbool valid = (vint(int(j)) + vint(step)) < vint(int(N)); - RayTypeK ray = rayN.getRayByOffset(valid, offset); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByOffset(valid, offset, ray); - } - } - } - } - - template - __noinline void RayStreamFilter::filterSOP(Scene* scene, const void* _rayN, size_t N, IntersectContext* context) - { - RayStreamSOP& rayN = *(RayStreamSOP*)_rayN; - - /* use fast path for coherent ray mode */ - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayTypeK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - for (size_t i = 0; i < N; i += MAX_INTERNAL_STREAM_SIZE) - { - const size_t size = min(N - i, MAX_INTERNAL_STREAM_SIZE); - - /* convert from SOP to SOA */ - for (size_t j = 0; j < size; j += K) - { - const vint vij = vint(int(i+j)) + vint(step); - const vbool valid = vij < vint(int(N)); - const size_t offset = (i+j) * sizeof(float); - const size_t packetIndex = j / K; - - RayTypeK ray = rayN.getRayByOffset(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - - rays[packetIndex] = ray; - rayPtrs[packetIndex] = &rays[packetIndex]; // rayPtrs might get reordered for occludedN - } - - /* trace stream */ - scene->intersectors.intersectN(rayPtrs, size, context); - - /* convert from SOA to SOP */ - for (size_t j = 0; j < size; j += K) - { - const vint vij = vint(int(i+j)) + vint(step); - const vbool valid = vij < vint(int(N)); - const size_t offset = (i+j) * sizeof(float); - const size_t packetIndex = j / K; - - rayN.setHitByOffset(valid, offset, rays[packetIndex]); - } - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N;) - { - const size_t offset = inputRayID * sizeof(float); - /* skip invalid rays */ - if (unlikely(!rayN.isValidByOffset(offset))) { inputRayID++; continue; } // ignore invalid or already occluded rays -#if defined(EMBREE_IGNORE_INVALID_RAYS) - __aligned(64) Ray ray = rayN.getRayByOffset(offset); - if (unlikely(!ray.valid())) { inputRayID++; continue; } -#endif - - const unsigned int octantID = (unsigned int)rayN.getOctantByOffset(offset); - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)offset; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayOffsets = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint offset = *(vint*)&rayOffsets[j]; - RayK& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByOffset(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint vi = vint(int(j)) + vint(step); - const vbool valid = vi < vint(int(numOctantRays)); - const vint offset = *(vint*)&rayOffsets[j]; - rayN.setHitByOffset(valid, offset, rays[j/K]); - } - - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < N; i += K) - { - const vint vi = vint(int(i)) + vint(step); - vbool valid = vi < vint(int(N)); - const size_t offset = i * sizeof(float); - - RayTypeK ray = rayN.getRayByOffset(valid, offset); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByOffset(valid, offset, ray); - } - } - } - - - void RayStreamFilter::intersectAOS(Scene* scene, RTCRayHit* _rayN, size_t N, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOS(scene, _rayN, N, stride, context); - else - filterAOS(scene, _rayN, N, stride, context); - } - - void RayStreamFilter::occludedAOS(Scene* scene, RTCRay* _rayN, size_t N, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOS(scene, _rayN, N, stride, context); - else - filterAOS(scene, _rayN, N, stride, context); - } - - void RayStreamFilter::intersectAOP(Scene* scene, RTCRayHit** _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOP(scene, (void**)_rayN, N, context); - else - filterAOP(scene, (void**)_rayN, N, context); - } - - void RayStreamFilter::occludedAOP(Scene* scene, RTCRay** _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOP(scene, (void**)_rayN, N, context); - else - filterAOP(scene, (void**)_rayN, N, context); - } - - void RayStreamFilter::intersectSOA(Scene* scene, char* rayData, size_t N, size_t numPackets, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOA(scene, rayData, N, numPackets, stride, context); - else - filterSOA(scene, rayData, N, numPackets, stride, context); - } - - void RayStreamFilter::occludedSOA(Scene* scene, char* rayData, size_t N, size_t numPackets, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOA(scene, rayData, N, numPackets, stride, context); - else - filterSOA(scene, rayData, N, numPackets, stride, context); - } - - void RayStreamFilter::intersectSOP(Scene* scene, const RTCRayHitNp* _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOP(scene, _rayN, N, context); - else - filterSOP(scene, _rayN, N, context); - } - - void RayStreamFilter::occludedSOP(Scene* scene, const RTCRayNp* _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOP(scene, _rayN, N, context); - else - filterSOP(scene, _rayN, N, context); - } - - - RayStreamFilterFuncs rayStreamFilterFuncs() { - return RayStreamFilterFuncs(RayStreamFilter::intersectAOS, RayStreamFilter::intersectAOP, RayStreamFilter::intersectSOA, RayStreamFilter::intersectSOP, - RayStreamFilter::occludedAOS, RayStreamFilter::occludedAOP, RayStreamFilter::occludedSOA, RayStreamFilter::occludedSOP); - } - }; -}; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.h b/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.h deleted file mode 100644 index e7df7c2ae22..00000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "../common/default.h" -#include "../common/ray.h" -#include "../common/scene.h" - -namespace embree -{ - namespace isa - { - class RayStreamFilter - { - public: - static void intersectAOS(Scene* scene, RTCRayHit* rays, size_t N, size_t stride, IntersectContext* context); - static void intersectAOP(Scene* scene, RTCRayHit** rays, size_t N, IntersectContext* context); - static void intersectSOA(Scene* scene, char* rays, size_t N, size_t numPackets, size_t stride, IntersectContext* context); - static void intersectSOP(Scene* scene, const RTCRayHitNp* rays, size_t N, IntersectContext* context); - - static void occludedAOS(Scene* scene, RTCRay* rays, size_t N, size_t stride, IntersectContext* context); - static void occludedAOP(Scene* scene, RTCRay** rays, size_t N, IntersectContext* context); - static void occludedSOA(Scene* scene, char* rays, size_t N, size_t numPackets, size_t stride, IntersectContext* context); - static void occludedSOP(Scene* scene, const RTCRayNp* rays, size_t N, IntersectContext* context); - - private: - template - static void filterAOS(Scene* scene, void* rays, size_t N, size_t stride, IntersectContext* context); - - template - static void filterAOP(Scene* scene, void** rays, size_t N, IntersectContext* context); - - template - static void filterSOA(Scene* scene, char* rays, size_t N, size_t numPackets, size_t stride, IntersectContext* context); - - template - static void filterSOP(Scene* scene, const void* rays, size_t N, IntersectContext* context); - }; - } -}; diff --git a/thirdparty/embree/kernels/bvh/bvh_refit.cpp b/thirdparty/embree/kernels/bvh/bvh_refit.cpp index bf5c8538ba9..9f8554112b7 100644 --- a/thirdparty/embree/kernels/bvh/bvh_refit.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_refit.cpp @@ -11,6 +11,9 @@ #include "../geometry/quadv.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" + +#include "../../common/algorithms/parallel_for.h" namespace embree { @@ -82,7 +85,7 @@ namespace embree template BBox3fa BVHNRefitter::refit_toplevel(NodeRef& ref, size_t &subtrees, - const BBox3fa *const subTreeBounds, + const BBox3fa *const subTreeBounds, const size_t depth) { if (depth >= MAX_SUB_TREE_EXTRACTION_DEPTH) @@ -236,12 +239,20 @@ namespace embree #if defined(EMBREE_GEOMETRY_INSTANCE) Builder* BVH4InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); Builder* BVH4InstanceMeshRefitSAH (void* accel, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<4,Instance,InstancePrimitive>((BVH4*)accel,BVH4InstanceMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } - #if defined(__AVX__) Builder* BVH8InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); Builder* BVH8InstanceMeshRefitSAH (void* accel, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<8,Instance,InstancePrimitive>((BVH8*)accel,BVH8InstanceMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } #endif #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); + Builder* BVH4InstanceArrayMeshRefitSAH (void* accel, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)accel,BVH4InstanceArrayMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } + +#if defined(__AVX__) + Builder* BVH8InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); + Builder* BVH8InstanceArrayMeshRefitSAH (void* accel, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)accel,BVH8InstanceArrayMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } +#endif +#endif } } diff --git a/thirdparty/embree/kernels/bvh/bvh_traverser_stream.h b/thirdparty/embree/kernels/bvh/bvh_traverser_stream.h deleted file mode 100644 index 852981e69de..00000000000 --- a/thirdparty/embree/kernels/bvh/bvh_traverser_stream.h +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "bvh.h" -#include "../common/ray.h" -#include "../common/stack_item.h" - -namespace embree -{ - namespace isa - { - template - class BVHNNodeTraverserStreamHitCoherent - { - typedef BVHN BVH; - typedef typename BVH::NodeRef NodeRef; - typedef typename BVH::BaseNode BaseNode; - - public: - template - static __forceinline void traverseClosestHit(NodeRef& cur, - size_t& m_trav_active, - const vbool& vmask, - const vfloat& tNear, - const T* const tMask, - StackItemMaskCoherent*& stackPtr) - { - const NodeRef parent = cur; - size_t mask = movemask(vmask); - assert(mask != 0); - const BaseNode* node = cur.baseNode(); - - /*! one child is hit, continue with that child */ - const size_t r0 = bscf(mask); - assert(r0 < 8); - cur = node->child(r0); - BVHN::prefetch(cur,types); - m_trav_active = tMask[r0]; - assert(cur != BVH::emptyNode); - if (unlikely(mask == 0)) return; - - const unsigned int* const tNear_i = (unsigned int*)&tNear; - - /*! two children are hit, push far child, and continue with closer child */ - NodeRef c0 = cur; - unsigned int d0 = tNear_i[r0]; - const size_t r1 = bscf(mask); - assert(r1 < 8); - NodeRef c1 = node->child(r1); - BVHN::prefetch(c1,types); - unsigned int d1 = tNear_i[r1]; - - assert(c0 != BVH::emptyNode); - assert(c1 != BVH::emptyNode); - if (likely(mask == 0)) { - if (d0 < d1) { - assert(tNear[r1] >= 0.0f); - stackPtr->mask = tMask[r1]; - stackPtr->parent = parent; - stackPtr->child = c1; - stackPtr++; - cur = c0; - m_trav_active = tMask[r0]; - return; - } - else { - assert(tNear[r0] >= 0.0f); - stackPtr->mask = tMask[r0]; - stackPtr->parent = parent; - stackPtr->child = c0; - stackPtr++; - cur = c1; - m_trav_active = tMask[r1]; - return; - } - } - - /*! slow path for more than two hits */ - size_t hits = movemask(vmask); - const vint dist_i = select(vmask, (asInt(tNear) & 0xfffffff8) | vint(step), 0); - const vint dist_i_sorted = usort_descending(dist_i); - const vint sorted_index = dist_i_sorted & 7; - - size_t i = 0; - for (;;) - { - const unsigned int index = sorted_index[i]; - assert(index < 8); - cur = node->child(index); - m_trav_active = tMask[index]; - assert(m_trav_active); - BVHN::prefetch(cur,types); - bscf(hits); - if (unlikely(hits==0)) break; - i++; - assert(cur != BVH::emptyNode); - assert(tNear[index] >= 0.0f); - stackPtr->mask = m_trav_active; - stackPtr->parent = parent; - stackPtr->child = cur; - stackPtr++; - } - } - - template - static __forceinline void traverseAnyHit(NodeRef& cur, - size_t& m_trav_active, - const vbool& vmask, - const T* const tMask, - StackItemMaskCoherent*& stackPtr) - { - const NodeRef parent = cur; - size_t mask = movemask(vmask); - assert(mask != 0); - const BaseNode* node = cur.baseNode(); - - /*! one child is hit, continue with that child */ - size_t r = bscf(mask); - cur = node->child(r); - BVHN::prefetch(cur,types); - m_trav_active = tMask[r]; - - /* simple in order sequence */ - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) return; - stackPtr->mask = m_trav_active; - stackPtr->parent = parent; - stackPtr->child = cur; - stackPtr++; - - for (; ;) - { - r = bscf(mask); - cur = node->child(r); - BVHN::prefetch(cur,types); - m_trav_active = tMask[r]; - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) return; - stackPtr->mask = m_trav_active; - stackPtr->parent = parent; - stackPtr->child = cur; - stackPtr++; - } - } - }; - } -} diff --git a/thirdparty/embree/kernels/bvh/node_intersector_packet_stream.h b/thirdparty/embree/kernels/bvh/node_intersector_packet_stream.h deleted file mode 100644 index 943fd7043f4..00000000000 --- a/thirdparty/embree/kernels/bvh/node_intersector_packet_stream.h +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "node_intersector.h" - -namespace embree -{ - namespace isa - { - ////////////////////////////////////////////////////////////////////////////////////// - // Ray packet structure used in stream traversal - ////////////////////////////////////////////////////////////////////////////////////// - - template - struct TravRayKStream; - - /* Fast variant */ - template - struct TravRayKStream - { - __forceinline TravRayKStream() {} - - __forceinline TravRayKStream(const Vec3vf& ray_org, const Vec3vf& ray_dir, const vfloat& ray_tnear, const vfloat& ray_tfar) - { - init(ray_org, ray_dir); - tnear = ray_tnear; - tfar = ray_tfar; - } - - __forceinline void init(const Vec3vf& ray_org, const Vec3vf& ray_dir) - { - rdir = rcp_safe(ray_dir); -#if defined(__aarch64__) - neg_org_rdir = -(ray_org * rdir); -#else - org_rdir = ray_org * rdir; -#endif - } - - Vec3vf rdir; -#if defined(__aarch64__) - Vec3vf neg_org_rdir; -#else - Vec3vf org_rdir; -#endif - vfloat tnear; - vfloat tfar; - }; - - template - using TravRayKStreamFast = TravRayKStream; - - /* Robust variant */ - template - struct TravRayKStream - { - __forceinline TravRayKStream() {} - - __forceinline TravRayKStream(const Vec3vf& ray_org, const Vec3vf& ray_dir, const vfloat& ray_tnear, const vfloat& ray_tfar) - { - init(ray_org, ray_dir); - tnear = ray_tnear; - tfar = ray_tfar; - } - - __forceinline void init(const Vec3vf& ray_org, const Vec3vf& ray_dir) - { - rdir = vfloat(1.0f)/(zero_fix(ray_dir)); - org = ray_org; - } - - Vec3vf rdir; - Vec3vf org; - vfloat tnear; - vfloat tfar; - }; - - template - using TravRayKStreamRobust = TravRayKStream; - - ////////////////////////////////////////////////////////////////////////////////////// - // Fast AABBNode intersection - ////////////////////////////////////////////////////////////////////////////////////// - - template - __forceinline size_t intersectNode1(const typename BVHN::AABBNode* __restrict__ node, - const TravRayKStreamFast& ray, size_t k, const NearFarPrecalculations& nf) - { - const vfloat bminX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearX)); - const vfloat bminY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearY)); - const vfloat bminZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat bmaxX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farX)); - const vfloat bmaxY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farY)); - const vfloat bmaxZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farZ)); - -#if defined (__aarch64__) - const vfloat rminX = madd(bminX, vfloat(ray.rdir.x[k]), vfloat(ray.neg_org_rdir.x[k])); - const vfloat rminY = madd(bminY, vfloat(ray.rdir.y[k]), vfloat(ray.neg_org_rdir.y[k])); - const vfloat rminZ = madd(bminZ, vfloat(ray.rdir.z[k]), vfloat(ray.neg_org_rdir.z[k])); - const vfloat rmaxX = madd(bmaxX, vfloat(ray.rdir.x[k]), vfloat(ray.neg_org_rdir.x[k])); - const vfloat rmaxY = madd(bmaxY, vfloat(ray.rdir.y[k]), vfloat(ray.neg_org_rdir.y[k])); - const vfloat rmaxZ = madd(bmaxZ, vfloat(ray.rdir.z[k]), vfloat(ray.neg_org_rdir.z[k])); -#else - const vfloat rminX = msub(bminX, vfloat(ray.rdir.x[k]), vfloat(ray.org_rdir.x[k])); - const vfloat rminY = msub(bminY, vfloat(ray.rdir.y[k]), vfloat(ray.org_rdir.y[k])); - const vfloat rminZ = msub(bminZ, vfloat(ray.rdir.z[k]), vfloat(ray.org_rdir.z[k])); - const vfloat rmaxX = msub(bmaxX, vfloat(ray.rdir.x[k]), vfloat(ray.org_rdir.x[k])); - const vfloat rmaxY = msub(bmaxY, vfloat(ray.rdir.y[k]), vfloat(ray.org_rdir.y[k])); - const vfloat rmaxZ = msub(bmaxZ, vfloat(ray.rdir.z[k]), vfloat(ray.org_rdir.z[k])); -#endif - const vfloat rmin = maxi(rminX, rminY, rminZ, vfloat(ray.tnear[k])); - const vfloat rmax = mini(rmaxX, rmaxY, rmaxZ, vfloat(ray.tfar[k])); - - const vbool vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit) & (((size_t)1 << N)-1); - } - - template - __forceinline size_t intersectNodeK(const typename BVHN::AABBNode* __restrict__ node, size_t i, - const TravRayKStreamFast& ray, const NearFarPrecalculations& nf) - { - char* ptr = (char*)&node->lower_x + i*sizeof(float); - const vfloat bminX = *(const float*)(ptr + nf.nearX); - const vfloat bminY = *(const float*)(ptr + nf.nearY); - const vfloat bminZ = *(const float*)(ptr + nf.nearZ); - const vfloat bmaxX = *(const float*)(ptr + nf.farX); - const vfloat bmaxY = *(const float*)(ptr + nf.farY); - const vfloat bmaxZ = *(const float*)(ptr + nf.farZ); - -#if defined (__aarch64__) - const vfloat rminX = madd(bminX, ray.rdir.x, ray.neg_org_rdir.x); - const vfloat rminY = madd(bminY, ray.rdir.y, ray.neg_org_rdir.y); - const vfloat rminZ = madd(bminZ, ray.rdir.z, ray.neg_org_rdir.z); - const vfloat rmaxX = madd(bmaxX, ray.rdir.x, ray.neg_org_rdir.x); - const vfloat rmaxY = madd(bmaxY, ray.rdir.y, ray.neg_org_rdir.y); - const vfloat rmaxZ = madd(bmaxZ, ray.rdir.z, ray.neg_org_rdir.z); -#else - const vfloat rminX = msub(bminX, ray.rdir.x, ray.org_rdir.x); - const vfloat rminY = msub(bminY, ray.rdir.y, ray.org_rdir.y); - const vfloat rminZ = msub(bminZ, ray.rdir.z, ray.org_rdir.z); - const vfloat rmaxX = msub(bmaxX, ray.rdir.x, ray.org_rdir.x); - const vfloat rmaxY = msub(bmaxY, ray.rdir.y, ray.org_rdir.y); - const vfloat rmaxZ = msub(bmaxZ, ray.rdir.z, ray.org_rdir.z); -#endif - - const vfloat rmin = maxi(rminX, rminY, rminZ, ray.tnear); - const vfloat rmax = mini(rmaxX, rmaxY, rmaxZ, ray.tfar); - - const vbool vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit); - } - - ////////////////////////////////////////////////////////////////////////////////////// - // Robust AABBNode intersection - ////////////////////////////////////////////////////////////////////////////////////// - - template - __forceinline size_t intersectNode1(const typename BVHN::AABBNode* __restrict__ node, - const TravRayKStreamRobust& ray, size_t k, const NearFarPrecalculations& nf) - { - const vfloat bminX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearX)); - const vfloat bminY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearY)); - const vfloat bminZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat bmaxX = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farX)); - const vfloat bmaxY = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farY)); - const vfloat bmaxZ = vfloat(*(const vfloat*)((const char*)&node->lower_x + nf.farZ)); - - const vfloat rminX = (bminX - vfloat(ray.org.x[k])) * vfloat(ray.rdir.x[k]); - const vfloat rminY = (bminY - vfloat(ray.org.y[k])) * vfloat(ray.rdir.y[k]); - const vfloat rminZ = (bminZ - vfloat(ray.org.z[k])) * vfloat(ray.rdir.z[k]); - const vfloat rmaxX = (bmaxX - vfloat(ray.org.x[k])) * vfloat(ray.rdir.x[k]); - const vfloat rmaxY = (bmaxY - vfloat(ray.org.y[k])) * vfloat(ray.rdir.y[k]); - const vfloat rmaxZ = (bmaxZ - vfloat(ray.org.z[k])) * vfloat(ray.rdir.z[k]); - const float round_up = 1.0f+3.0f*float(ulp); // FIXME: use per instruction rounding for AVX512 - const vfloat rmin = max(rminX, rminY, rminZ, vfloat(ray.tnear[k])); - const vfloat rmax = round_up *min(rmaxX, rmaxY, rmaxZ, vfloat(ray.tfar[k])); - - const vbool vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit) & (((size_t)1 << N)-1); - } - - template - __forceinline size_t intersectNodeK(const typename BVHN::AABBNode* __restrict__ node, size_t i, - const TravRayKStreamRobust& ray, const NearFarPrecalculations& nf) - { - char *ptr = (char*)&node->lower_x + i*sizeof(float); - const vfloat bminX = *(const float*)(ptr + nf.nearX); - const vfloat bminY = *(const float*)(ptr + nf.nearY); - const vfloat bminZ = *(const float*)(ptr + nf.nearZ); - const vfloat bmaxX = *(const float*)(ptr + nf.farX); - const vfloat bmaxY = *(const float*)(ptr + nf.farY); - const vfloat bmaxZ = *(const float*)(ptr + nf.farZ); - - const vfloat rminX = (bminX - ray.org.x) * ray.rdir.x; - const vfloat rminY = (bminY - ray.org.y) * ray.rdir.y; - const vfloat rminZ = (bminZ - ray.org.z) * ray.rdir.z; - const vfloat rmaxX = (bmaxX - ray.org.x) * ray.rdir.x; - const vfloat rmaxY = (bmaxY - ray.org.y) * ray.rdir.y; - const vfloat rmaxZ = (bmaxZ - ray.org.z) * ray.rdir.z; - - const float round_up = 1.0f+3.0f*float(ulp); - const vfloat rmin = max(rminX, rminY, rminZ, vfloat(ray.tnear)); - const vfloat rmax = round_up * min(rmaxX, rmaxY, rmaxZ, vfloat(ray.tfar)); - - const vbool vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit); - } - } -} diff --git a/thirdparty/embree/kernels/common/accel.h b/thirdparty/embree/kernels/common/accel.h index d24326ce92c..7d959377ae8 100644 --- a/thirdparty/embree/kernels/common/accel.h +++ b/thirdparty/embree/kernels/common/accel.h @@ -17,7 +17,7 @@ namespace embree { ALIGNED_CLASS_(16); public: - enum Type { TY_UNKNOWN = 0, TY_ACCELN = 1, TY_ACCEL_INSTANCE = 2, TY_BVH4 = 3, TY_BVH8 = 4 }; + enum Type { TY_UNKNOWN = 0, TY_ACCELN = 1, TY_ACCEL_INSTANCE = 2, TY_BVH4 = 3, TY_BVH8 = 4, TY_GPU = 5 }; public: AccelData (const Type type) @@ -73,61 +73,49 @@ namespace embree /*! Type of intersect function pointer for single rays. */ typedef void (*IntersectFunc)(Intersectors* This, /*!< this pointer to accel */ RTCRayHit& ray, /*!< ray to intersect */ - IntersectContext* context); + RayQueryContext* context); /*! Type of intersect function pointer for ray packets of size 4. */ typedef void (*IntersectFunc4)(const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRayHit4& ray, /*!< ray packet to intersect */ - IntersectContext* context); + RayQueryContext* context); /*! Type of intersect function pointer for ray packets of size 8. */ typedef void (*IntersectFunc8)(const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRayHit8& ray, /*!< ray packet to intersect */ - IntersectContext* context); + RayQueryContext* context); /*! Type of intersect function pointer for ray packets of size 16. */ typedef void (*IntersectFunc16)(const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRayHit16& ray, /*!< ray packet to intersect */ - IntersectContext* context); + RayQueryContext* context); - /*! Type of intersect function pointer for ray packets of size N. */ - typedef void (*IntersectFuncN)(Intersectors* This, /*!< this pointer to accel */ - RTCRayHitN** ray, /*!< ray stream to intersect */ - const size_t N, /*!< number of rays in stream */ - IntersectContext* context /*!< layout flags */); - - /*! Type of occlusion function pointer for single rays. */ typedef void (*OccludedFunc) (Intersectors* This, /*!< this pointer to accel */ RTCRay& ray, /*!< ray to test occlusion */ - IntersectContext* context); + RayQueryContext* context); /*! Type of occlusion function pointer for ray packets of size 4. */ typedef void (*OccludedFunc4) (const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRay4& ray, /*!< ray packet to test occlusion. */ - IntersectContext* context); + RayQueryContext* context); /*! Type of occlusion function pointer for ray packets of size 8. */ typedef void (*OccludedFunc8) (const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRay8& ray, /*!< ray packet to test occlusion. */ - IntersectContext* context); + RayQueryContext* context); /*! Type of occlusion function pointer for ray packets of size 16. */ typedef void (*OccludedFunc16) (const void* valid, /*!< pointer to valid mask */ Intersectors* This, /*!< this pointer to accel */ RTCRay16& ray, /*!< ray packet to test occlusion. */ - IntersectContext* context); + RayQueryContext* context); - /*! Type of intersect function pointer for ray packets of size N. */ - typedef void (*OccludedFuncN)(Intersectors* This, /*!< this pointer to accel */ - RTCRayN** ray, /*!< ray stream to test occlusion */ - const size_t N, /*!< number of rays in stream */ - IntersectContext* context /*!< layout flags */); typedef void (*ErrorFunc) (); struct Collider @@ -217,30 +205,13 @@ namespace embree const char* name; }; - struct IntersectorN - { - IntersectorN (ErrorFunc error = nullptr) - : intersect((IntersectFuncN)error), occluded((OccludedFuncN)error), name(nullptr) {} - - IntersectorN (IntersectFuncN intersect, OccludedFuncN occluded, const char* name) - : intersect(intersect), occluded(occluded), name(name) {} - - operator bool() const { return name; } - - public: - static const char* type; - IntersectFuncN intersect; - OccludedFuncN occluded; - const char* name; - }; - struct Intersectors { Intersectors() - : ptr(nullptr), leafIntersector(nullptr), collider(nullptr), intersector1(nullptr), intersector4(nullptr), intersector8(nullptr), intersector16(nullptr), intersectorN(nullptr) {} + : ptr(nullptr), leafIntersector(nullptr), collider(nullptr), intersector1(nullptr), intersector4(nullptr), intersector8(nullptr), intersector16(nullptr) {} Intersectors (ErrorFunc error) - : ptr(nullptr), leafIntersector(nullptr), collider(error), intersector1(error), intersector4(error), intersector8(error), intersector16(error), intersectorN(error) {} + : ptr(nullptr), leafIntersector(nullptr), collider(error), intersector1(error), intersector4(error), intersector8(error), intersector16(error) {} void print(size_t ident) { @@ -264,10 +235,6 @@ namespace embree for (size_t i=0; iptr; for (size_t i=0; iaccels.size(); i++) @@ -49,7 +49,7 @@ namespace embree This->accels[i]->intersectors.intersect(ray,context); } - void AccelN::intersect4 (const void* valid, Accel::Intersectors* This_in, RTCRayHit4& ray, IntersectContext* context) + void AccelN::intersect4 (const void* valid, Accel::Intersectors* This_in, RTCRayHit4& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) @@ -57,7 +57,7 @@ namespace embree This->accels[i]->intersectors.intersect4(valid,ray,context); } - void AccelN::intersect8 (const void* valid, Accel::Intersectors* This_in, RTCRayHit8& ray, IntersectContext* context) + void AccelN::intersect8 (const void* valid, Accel::Intersectors* This_in, RTCRayHit8& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) @@ -65,7 +65,7 @@ namespace embree This->accels[i]->intersectors.intersect8(valid,ray,context); } - void AccelN::intersect16 (const void* valid, Accel::Intersectors* This_in, RTCRayHit16& ray, IntersectContext* context) + void AccelN::intersect16 (const void* valid, Accel::Intersectors* This_in, RTCRayHit16& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) @@ -73,15 +73,7 @@ namespace embree This->accels[i]->intersectors.intersect16(valid,ray,context); } - void AccelN::intersectN (Accel::Intersectors* This_in, RTCRayHitN** ray, const size_t N, IntersectContext* context) - { - AccelN* This = (AccelN*)This_in->ptr; - for (size_t i=0; iaccels.size(); i++) - if (!This->accels[i]->isEmpty()) - This->accels[i]->intersectors.intersectN(ray,N,context); - } - - void AccelN::occluded (Accel::Intersectors* This_in, RTCRay& ray, IntersectContext* context) + void AccelN::occluded (Accel::Intersectors* This_in, RTCRay& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) { @@ -91,7 +83,7 @@ namespace embree } } - void AccelN::occluded4 (const void* valid, Accel::Intersectors* This_in, RTCRay4& ray, IntersectContext* context) + void AccelN::occluded4 (const void* valid, Accel::Intersectors* This_in, RTCRay4& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) { @@ -105,7 +97,7 @@ namespace embree } } - void AccelN::occluded8 (const void* valid, Accel::Intersectors* This_in, RTCRay8& ray, IntersectContext* context) + void AccelN::occluded8 (const void* valid, Accel::Intersectors* This_in, RTCRay8& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) { @@ -121,7 +113,7 @@ namespace embree } } - void AccelN::occluded16 (const void* valid, Accel::Intersectors* This_in, RTCRay16& ray, IntersectContext* context) + void AccelN::occluded16 (const void* valid, Accel::Intersectors* This_in, RTCRay16& ray, RayQueryContext* context) { AccelN* This = (AccelN*)This_in->ptr; for (size_t i=0; iaccels.size(); i++) { @@ -141,15 +133,6 @@ namespace embree } } - void AccelN::occludedN (Accel::Intersectors* This_in, RTCRayN** ray, const size_t N, IntersectContext* context) - { - AccelN* This = (AccelN*)This_in->ptr; - size_t M = N; - for (size_t i=0; iaccels.size(); i++) - if (!This->accels[i]->isEmpty()) - This->accels[i]->intersectors.occludedN(ray,M,context); - } - void AccelN::accels_print(size_t ident) { for (size_t i=0; iargs; + + IntersectFuncN intersectFunc = nullptr; + intersectFunc = intersectorN.intersect; - intersectorN.intersect(&args); + if (context->getIntersectFunction()) + intersectFunc = context->getIntersectFunction(); + + assert(intersectFunc); + intersectFunc(&args); + + return mask != 0; } /*! Tests if single ray is occluded by the scene. */ - __forceinline void occluded (Ray& ray, unsigned int geomID, unsigned int primID, IntersectContext* context) + __forceinline bool occluded (Ray& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context) { assert(primID < size()); - assert(intersectorN.occluded); - + int mask = -1; OccludedFunctionNArguments args; args.valid = &mask; @@ -173,16 +186,100 @@ namespace embree args.geomID = geomID; args.primID = primID; args.geometry = this; - - intersectorN.occluded(&args); + args.forward_scene = nullptr; + args.args = context->args; + + OccludedFuncN occludedFunc = nullptr; + occludedFunc = intersectorN.occluded; + + if (context->getOccludedFunction()) + occludedFunc = context->getOccludedFunction(); + + assert(occludedFunc); + occludedFunc(&args); + + return mask != 0; } - - /*! Intersects a packet of K rays with the scene. */ - template - __forceinline void intersect (const vbool& valid, RayHitK& ray, unsigned int geomID, unsigned int primID, IntersectContext* context) + + /*! Intersects a single ray with the scene. */ + __forceinline bool intersect (RayHit& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context, RTCScene& forward_scene) + { + assert(primID < size()); + + int mask = -1; + IntersectFunctionNArguments args; + args.valid = &mask; + args.geometryUserPtr = userPtr; + args.context = context->user; + args.rayhit = (RTCRayHitN*)&ray; + args.N = 1; + args.geomID = geomID; + args.primID = primID; + args.geometry = this; + args.forward_scene = nullptr; + args.args = nullptr; + + typedef void (*RTCIntersectFunctionSYCL)(const void* args); + RTCIntersectFunctionSYCL intersectFunc = nullptr; + +#if EMBREE_SYCL_GEOMETRY_CALLBACK + if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY) + intersectFunc = (RTCIntersectFunctionSYCL) intersectorN.intersect; +#endif + + if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS) + if (context->getIntersectFunction()) + intersectFunc = (RTCIntersectFunctionSYCL) context->getIntersectFunction(); + + if (intersectFunc) + intersectFunc(&args); + + forward_scene = args.forward_scene; + return mask != 0; + } + + /*! Tests if single ray is occluded by the scene. */ + __forceinline bool occluded (Ray& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context, RTCScene& forward_scene) + { + assert(primID < size()); + + int mask = -1; + OccludedFunctionNArguments args; + args.valid = &mask; + args.geometryUserPtr = userPtr; + args.context = context->user; + args.ray = (RTCRayN*)&ray; + args.N = 1; + args.geomID = geomID; + args.primID = primID; + args.geometry = this; + args.forward_scene = nullptr; + args.args = nullptr; + + typedef void (*RTCOccludedFunctionSYCL)(const void* args); + RTCOccludedFunctionSYCL occludedFunc = nullptr; + +#if EMBREE_SYCL_GEOMETRY_CALLBACK + if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY) + occludedFunc = (RTCOccludedFunctionSYCL) intersectorN.occluded; +#endif + + if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS) + if (context->getOccludedFunction()) + occludedFunc = (RTCOccludedFunctionSYCL) context->getOccludedFunction(); + + if (occludedFunc) + occludedFunc(&args); + + forward_scene = args.forward_scene; + return mask != 0; + } + + /*! Intersects a packet of K rays with the scene. */ + template + __forceinline void intersect (const vbool& valid, RayHitK& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context) { assert(primID < size()); - assert(intersectorN.intersect); vint mask = valid.mask32(); IntersectFunctionNArguments args; @@ -194,16 +291,24 @@ namespace embree args.geomID = geomID; args.primID = primID; args.geometry = this; - - intersectorN.intersect(&args); + args.forward_scene = nullptr; + args.args = context->args; + + IntersectFuncN intersectFunc = nullptr; + intersectFunc = intersectorN.intersect; + + if (context->getIntersectFunction()) + intersectFunc = context->getIntersectFunction(); + + assert(intersectFunc); + intersectFunc(&args); } /*! Tests if a packet of K rays is occluded by the scene. */ template - __forceinline void occluded (const vbool& valid, RayK& ray, unsigned int geomID, unsigned int primID, IntersectContext* context) + __forceinline void occluded (const vbool& valid, RayK& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context) { assert(primID < size()); - assert(intersectorN.occluded); vint mask = valid.mask32(); OccludedFunctionNArguments args; @@ -215,8 +320,17 @@ namespace embree args.geomID = geomID; args.primID = primID; args.geometry = this; + args.forward_scene = nullptr; + args.args = context->args; + + OccludedFuncN occludedFunc = nullptr; + occludedFunc = intersectorN.occluded; - intersectorN.occluded(&args); + if (context->getOccludedFunction()) + occludedFunc = context->getOccludedFunction(); + + assert(occludedFunc); + occludedFunc(&args); } public: diff --git a/thirdparty/embree/kernels/common/alloc.cpp b/thirdparty/embree/kernels/common/alloc.cpp index 38a76225f42..cc2f9976f25 100644 --- a/thirdparty/embree/kernels/common/alloc.cpp +++ b/thirdparty/embree/kernels/common/alloc.cpp @@ -10,7 +10,7 @@ namespace embree { __thread FastAllocator::ThreadLocal2* FastAllocator::thread_local_allocator2 = nullptr; - SpinLock FastAllocator::s_thread_local_allocators_lock; + MutexSys FastAllocator::s_thread_local_allocators_lock; std::vector> FastAllocator::s_thread_local_allocators; struct fast_allocator_regression_test : public RegressionTest diff --git a/thirdparty/embree/kernels/common/alloc.h b/thirdparty/embree/kernels/common/alloc.h index 12769df2c85..840d48c327b 100644 --- a/thirdparty/embree/kernels/common/alloc.h +++ b/thirdparty/embree/kernels/common/alloc.h @@ -6,11 +6,9 @@ #include "default.h" #include "device.h" #include "scene.h" -#include "primref.h" +#include "../builders/primref.h" -#if defined(APPLE) && defined(__aarch64__) -#include -#endif +#include "../../common/tasking/taskscheduler.h" namespace embree { @@ -18,7 +16,7 @@ namespace embree { /*! maximum supported alignment */ static const size_t maxAlignment = 64; - + /*! maximum allocation size */ /* default settings */ @@ -39,14 +37,14 @@ namespace embree public: /*! Constructor for usage with ThreadLocalData */ - __forceinline ThreadLocal (ThreadLocal2* parent) - : parent(parent), ptr(nullptr), cur(0), end(0), allocBlockSize(0), bytesUsed(0), bytesWasted(0) {} + __forceinline ThreadLocal (ThreadLocal2* parent) + : parent(parent), ptr(nullptr), cur(0), end(0), allocBlockSize(0), bytesUsed(0), bytesWasted(0) {} /*! initialize allocator */ - void init(FastAllocator* alloc) + void init(FastAllocator* alloc) { ptr = nullptr; - cur = end = 0; + cur = end = 0; bytesUsed = 0; bytesWasted = 0; allocBlockSize = 0; @@ -54,64 +52,62 @@ namespace embree } /* Allocate aligned memory from the threads memory block. */ - __forceinline void* malloc(FastAllocator* alloc, size_t bytes, size_t align = 16) + __forceinline void* malloc(FastAllocator* alloc, size_t bytes, size_t align = 16) { /* bind the thread local allocator to the proper FastAllocator*/ parent->bind(alloc); assert(align <= maxAlignment); - bytesUsed += bytes; + bytesUsed += bytes; /* try to allocate in local block */ - size_t ofs = (align - cur) & (align-1); + size_t ofs = (align - cur) & (align-1); cur += bytes + ofs; if (likely(cur <= end)) { bytesWasted += ofs; return &ptr[cur - bytes]; } - cur -= bytes + ofs; - + cur -= bytes + ofs; + /* if allocation is too large allocate with parent allocator */ if (4*bytes > allocBlockSize) { return alloc->malloc(bytes,maxAlignment,false); - } + } /* get new partial block if allocation failed */ size_t blockSize = allocBlockSize; ptr = (char*) alloc->malloc(blockSize,maxAlignment,true); - bytesWasted += end-cur; - cur = 0; end = blockSize; + bytesWasted += end-cur; + cur = 0; end = blockSize; /* retry allocation */ - ofs = (align - cur) & (align-1); + ofs = (align - cur) & (align-1); cur += bytes + ofs; if (likely(cur <= end)) { bytesWasted += ofs; return &ptr[cur - bytes]; } - cur -= bytes + ofs; + cur -= bytes + ofs; /* get new full block if allocation failed */ blockSize = allocBlockSize; ptr = (char*) alloc->malloc(blockSize,maxAlignment,false); - bytesWasted += end-cur; - cur = 0; end = blockSize; + bytesWasted += end-cur; + cur = 0; end = blockSize; /* retry allocation */ - ofs = (align - cur) & (align-1); + ofs = (align - cur) & (align-1); cur += bytes + ofs; if (likely(cur <= end)) { bytesWasted += ofs; return &ptr[cur - bytes]; } - cur -= bytes + ofs; + cur -= bytes + ofs; /* should never happen as large allocations get handled specially above */ assert(false); return nullptr; } - - /*! returns amount of used bytes */ __forceinline size_t getUsedBytes() const { return bytesUsed; } - + /*! returns amount of free bytes */ __forceinline size_t getFreeBytes() const { return end-cur; } - + /*! returns amount of wasted bytes */ __forceinline size_t getWastedBytes() const { return bytesWasted; } - + private: ThreadLocal2* parent; char* ptr; //!< pointer to memory block @@ -136,11 +132,7 @@ namespace embree { assert(alloc_i); if (alloc.load() == alloc_i) return; -#if defined(APPLE) && defined(__aarch64__) - std::scoped_lock lock(mutex); -#else - Lock lock(mutex); -#endif + Lock lock(mutex); //if (alloc.load() == alloc_i) return; // not required as only one thread calls bind if (alloc.load()) { alloc.load()->bytesUsed += alloc0.getUsedBytes() + alloc1.getUsedBytes(); @@ -158,11 +150,7 @@ namespace embree { assert(alloc_i); if (alloc.load() != alloc_i) return; -#if defined(APPLE) && defined(__aarch64__) - std::scoped_lock lock(mutex); -#else - Lock lock(mutex); -#endif + Lock lock(mutex); if (alloc.load() != alloc_i) return; // required as a different thread calls unbind alloc.load()->bytesUsed += alloc0.getUsedBytes() + alloc1.getUsedBytes(); alloc.load()->bytesFree += alloc0.getFreeBytes() + alloc1.getFreeBytes(); @@ -173,26 +161,47 @@ namespace embree } public: -#if defined(APPLE) && defined(__aarch64__) - std::mutex mutex; -#else - SpinLock mutex; //!< required as unbind is called from other threads -#endif + MutexSys mutex; std::atomic alloc; //!< parent allocator ThreadLocal alloc0; ThreadLocal alloc1; }; - FastAllocator (Device* device, bool osAllocation) - : device(device), slotMask(0), usedBlocks(nullptr), freeBlocks(nullptr), use_single_mode(false), defaultBlockSize(PAGE_SIZE), estimatedSize(0), - growSize(PAGE_SIZE), maxGrowSize(maxAllocationSize), log2_grow_size_scale(0), bytesUsed(0), bytesFree(0), bytesWasted(0), atype(osAllocation ? EMBREE_OS_MALLOC : ALIGNED_MALLOC), - primrefarray(device,0) + FastAllocator (Device* device, + bool osAllocation, + bool useUSM = false, + bool blockAllocation = true) + : device(device) + , slotMask(0) + , defaultBlockSize(PAGE_SIZE) + , estimatedSize(0) + , growSize(PAGE_SIZE) + , maxGrowSize(maxAllocationSize) + , usedBlocks(nullptr) + , freeBlocks(nullptr) + , useUSM(useUSM) + , blockAllocation(blockAllocation) + , use_single_mode(false) + , log2_grow_size_scale(0) + , bytesUsed(0) + , bytesFree(0) + , bytesWasted(0) + , atype(osAllocation ? EMBREE_OS_MALLOC : ALIGNED_MALLOC) + , primrefarray(device,0) { + // -- GODOT start -- + // if (osAllocation && useUSM) + // throw std::runtime_error("USM allocation cannot be combined with OS allocation."); + if (osAllocation && useUSM) { + abort(); + } + // -- GODOT end -- + for (size_t i=0; i lock(s_thread_local_allocators_lock); -#endif + Lock lock(s_thread_local_allocators_lock); s_thread_local_allocators.push_back(make_unique(alloc)); } return alloc; @@ -247,11 +252,7 @@ namespace embree __forceinline void join(ThreadLocal2* alloc) { -#if defined(APPLE) && defined(__aarch64__) - std::scoped_lock lock(s_thread_local_allocators_lock); -#else - Lock lock(thread_local_allocators_lock); -#endif + Lock lock(s_thread_local_allocators_lock); thread_local_allocators.push_back(alloc); } @@ -412,7 +413,7 @@ namespace embree slotMask = MAX_THREAD_USED_BLOCK_SLOTS-1; // FIXME: remove if (usedBlocks.load() || freeBlocks.load()) { reset(); return; } if (bytesReserve == 0) bytesReserve = bytesAllocate; - freeBlocks = Block::create(device,bytesAllocate,bytesReserve,nullptr,atype); + freeBlocks = Block::create(device,useUSM,bytesAllocate,bytesReserve,nullptr,atype); estimatedSize = bytesEstimate; initGrowSizeAndNumSlots(bytesEstimate,true); } @@ -478,8 +479,8 @@ namespace embree bytesUsed.store(0); bytesFree.store(0); bytesWasted.store(0); - if (usedBlocks.load() != nullptr) usedBlocks.load()->clear_list(device); usedBlocks = nullptr; - if (freeBlocks.load() != nullptr) freeBlocks.load()->clear_list(device); freeBlocks = nullptr; + if (usedBlocks.load() != nullptr) usedBlocks.load()->clear_list(device,useUSM); usedBlocks = nullptr; + if (freeBlocks.load() != nullptr) freeBlocks.load()->clear_list(device,useUSM); freeBlocks = nullptr; for (size_t i=0; imalloc(device,bytes,align,partial); + // -- GODOT start -- + // if (ptr == nullptr && !blockAllocation) + // throw std::bad_alloc(); + if (ptr == nullptr && !blockAllocation) { + abort(); + } + // -- GODOT end -- if (ptr) return ptr; } @@ -516,16 +524,12 @@ namespace embree /* parallel block creation in case of no freeBlocks, avoids single global mutex */ if (likely(freeBlocks.load() == nullptr)) { -#if defined(APPLE) && defined(__aarch64__) - std::scoped_lock lock(slotMutex[slot]); -#else - Lock lock(slotMutex[slot]); -#endif + Lock lock(slotMutex[slot]); if (myUsedBlocks == threadUsedBlocks[slot]) { const size_t alignedBytes = (bytes+(align-1)) & ~(align-1); const size_t allocSize = max(min(growSize,maxGrowSize),alignedBytes); assert(allocSize >= bytes); - threadBlocks[slot] = threadUsedBlocks[slot] = Block::create(device,allocSize,allocSize,threadBlocks[slot],atype); // FIXME: a large allocation might throw away a block here! + threadBlocks[slot] = threadUsedBlocks[slot] = Block::create(device,useUSM,allocSize,allocSize,threadBlocks[slot],atype); // FIXME: a large allocation might throw away a block here! // FIXME: a direct allocation should allocate inside the block here, and not in the next loop! a different thread could do some allocation and make the large allocation fail. } continue; @@ -533,24 +537,20 @@ namespace embree /* if this fails allocate new block */ { -#if defined(APPLE) && defined(__aarch64__) - std::scoped_lock lock(mutex); -#else - Lock lock(mutex); -#endif - if (myUsedBlocks == threadUsedBlocks[slot]) - { + Lock lock(mutex); + if (myUsedBlocks == threadUsedBlocks[slot]) + { if (freeBlocks.load() != nullptr) { - Block* nextFreeBlock = freeBlocks.load()->next; - freeBlocks.load()->next = usedBlocks; - __memory_barrier(); - usedBlocks = freeBlocks.load(); + Block* nextFreeBlock = freeBlocks.load()->next; + freeBlocks.load()->next = usedBlocks; + __memory_barrier(); + usedBlocks = freeBlocks.load(); threadUsedBlocks[slot] = freeBlocks.load(); - freeBlocks = nextFreeBlock; - } else { + freeBlocks = nextFreeBlock; + } else { const size_t allocSize = min(growSize*incGrowSizeScale(),maxGrowSize); - usedBlocks = threadUsedBlocks[slot] = Block::create(device,allocSize,allocSize,usedBlocks,atype); // FIXME: a large allocation should get delivered directly, like above! - } + usedBlocks = threadUsedBlocks[slot] = Block::create(device,useUSM,allocSize,allocSize,usedBlocks,atype); // FIXME: a large allocation should get delivered directly, like above! + } } } } @@ -559,11 +559,7 @@ namespace embree /*! add new block */ void addBlock(void* ptr, ssize_t bytes) { -#if defined(APPLE) && defined(__aarch64__) - std::scoped_lock lock(mutex); -#else - Lock lock(mutex); -#endif + Lock lock(mutex); const size_t sizeof_Header = offsetof(Block,data[0]); void* aptr = (void*) ((((size_t)ptr)+maxAlignment-1) & ~(maxAlignment-1)); size_t ofs = (size_t) aptr - (size_t) ptr; @@ -723,7 +719,12 @@ namespace embree void print_blocks() { - std::cout << " estimatedSize = " << estimatedSize << ", slotMask = " << slotMask << ", use_single_mode = " << use_single_mode << ", maxGrowSize = " << maxGrowSize << ", defaultBlockSize = " << defaultBlockSize << std::endl; + std::cout << " estimatedSize = " << estimatedSize + << ", slotMask = " << slotMask + << ", use_single_mode = " << use_single_mode + << ", maxGrowSize = " << maxGrowSize + << ", defaultBlockSize = " << defaultBlockSize + << std::endl; std::cout << " used blocks = "; if (usedBlocks.load() != nullptr) usedBlocks.load()->print_list(); @@ -738,7 +739,19 @@ namespace embree struct Block { - static Block* create(MemoryMonitorInterface* device, size_t bytesAllocate, size_t bytesReserve, Block* next, AllocationType atype) + __forceinline static void* blockAlignedMalloc(Device* device, bool useUSM, size_t bytesAllocate, size_t bytesAlignment) + { + if (useUSM) return device->malloc(bytesAllocate, bytesAlignment); + else return alignedMalloc (bytesAllocate, bytesAlignment); + } + + __forceinline static void blockAlignedFree(Device* device, bool useUSM, void* ptr) + { + if (useUSM) return device->free(ptr); + else return alignedFree(ptr); + } + + static Block* create(Device* device, bool useUSM, size_t bytesAllocate, size_t bytesReserve, Block* next, AllocationType atype) { /* We avoid using os_malloc for small blocks as this could * cause a risk of fragmenting the virtual address space and @@ -766,7 +779,7 @@ namespace embree { const size_t alignment = maxAlignment; if (device) device->memoryMonitor(bytesAllocate+alignment,false); - ptr = alignedMalloc(bytesAllocate,alignment); + ptr = blockAlignedMalloc(device,useUSM,bytesAllocate,alignment); /* give hint to transparently convert these pages to 2MB pages */ const size_t ptr_aligned_begin = ((size_t)ptr) & ~size_t(PAGE_SIZE_2M-1); @@ -780,7 +793,7 @@ namespace embree { const size_t alignment = maxAlignment; if (device) device->memoryMonitor(bytesAllocate+alignment,false); - ptr = alignedMalloc(bytesAllocate,alignment); + ptr = blockAlignedMalloc(device,useUSM,bytesAllocate,alignment); return new (ptr) Block(ALIGNED_MALLOC,bytesAllocate-sizeof_Header,bytesAllocate-sizeof_Header,next,alignment); } } @@ -812,23 +825,23 @@ namespace embree return head; } - void clear_list(MemoryMonitorInterface* device) + void clear_list(Device* device, bool useUSM) { Block* block = this; while (block) { Block* next = block->next; - block->clear_block(device); + block->clear_block(device, useUSM); block = next; } } - void clear_block (MemoryMonitorInterface* device) + void clear_block (Device* device, bool useUSM) { const size_t sizeof_Header = offsetof(Block,data[0]); const ssize_t sizeof_Alloced = wasted+sizeof_Header+getBlockAllocatedBytes(); if (atype == ALIGNED_MALLOC) { - alignedFree(this); + blockAlignedFree(device, useUSM, this); if (device) device->memoryMonitor(-sizeof_Alloced,true); } @@ -847,16 +860,16 @@ namespace embree size_t bytes = bytes_in; assert(align <= maxAlignment); bytes = (bytes+(align-1)) & ~(align-1); - if (unlikely(cur+bytes > reserveEnd && !partial)) return nullptr; - const size_t i = cur.fetch_add(bytes); + if (unlikely(cur+bytes > reserveEnd && !partial)) return nullptr; + const size_t i = cur.fetch_add(bytes); if (unlikely(i+bytes > reserveEnd && !partial)) return nullptr; if (unlikely(i > reserveEnd)) return nullptr; bytes_in = bytes = min(bytes,reserveEnd-i); - - if (i+bytes > allocEnd) { + + if (i+bytes > allocEnd) { if (device) device->memoryMonitor(i+bytes-max(i,allocEnd),true); } - return &data[i]; + return &data[i]; } void* ptr() { @@ -874,7 +887,7 @@ namespace embree } size_t getBlockFreeBytes() const { - return getBlockAllocatedBytes() - getBlockUsedBytes(); + return getBlockAllocatedBytes() - getBlockUsedBytes(); } size_t getBlockAllocatedBytes() const { @@ -963,40 +976,40 @@ namespace embree char data[1]; //!< here starts memory to use for allocations }; + public: + static const size_t blockHeaderSize = offsetof(Block,data[0]); + private: Device* device; - SpinLock mutex; size_t slotMask; - std::atomic threadUsedBlocks[MAX_THREAD_USED_BLOCK_SLOTS]; - std::atomic usedBlocks; - std::atomic freeBlocks; - - std::atomic threadBlocks[MAX_THREAD_USED_BLOCK_SLOTS]; -#if defined(APPLE) && defined(__aarch64__) - std::mutex slotMutex[MAX_THREAD_USED_BLOCK_SLOTS]; -#else - PaddedSpinLock slotMutex[MAX_THREAD_USED_BLOCK_SLOTS]; -#endif - - bool use_single_mode; size_t defaultBlockSize; size_t estimatedSize; size_t growSize; size_t maxGrowSize; + + MutexSys mutex; + MutexSys slotMutex[MAX_THREAD_USED_BLOCK_SLOTS]; + std::atomic threadUsedBlocks[MAX_THREAD_USED_BLOCK_SLOTS]; + std::atomic threadBlocks[MAX_THREAD_USED_BLOCK_SLOTS]; + std::atomic usedBlocks; + std::atomic freeBlocks; + + bool useUSM; + bool blockAllocation = true; + bool use_single_mode; + std::atomic log2_grow_size_scale; //!< log2 of scaling factor for grow size // FIXME: remove std::atomic bytesUsed; std::atomic bytesFree; std::atomic bytesWasted; + static __thread ThreadLocal2* thread_local_allocator2; - static SpinLock s_thread_local_allocators_lock; + static MutexSys s_thread_local_allocators_lock; static std::vector> s_thread_local_allocators; -#if defined(APPLE) && defined(__aarch64__) - std::mutex thread_local_allocators_lock; -#else - SpinLock thread_local_allocators_lock; -#endif + std::vector thread_local_allocators; AllocationType atype; + mvector primrefarray; //!< primrefarray used to allocate nodes }; } diff --git a/thirdparty/embree/kernels/common/buffer.h b/thirdparty/embree/kernels/common/buffer.h index 793012c04dc..831f5815e8a 100644 --- a/thirdparty/embree/kernels/common/buffer.h +++ b/thirdparty/embree/kernels/common/buffer.h @@ -13,8 +13,8 @@ namespace embree { public: /*! Buffer construction */ - Buffer() - : device(nullptr), ptr(nullptr), numBytes(0), shared(false) {} + //Buffer() + //: device(nullptr), ptr(nullptr), numBytes(0), shared(false) {} /*! Buffer construction */ Buffer(Device* device, size_t numBytes_in, void* ptr_in = nullptr) @@ -77,19 +77,17 @@ namespace embree /*! allocated buffer */ void alloc() { - if (device) - device->memoryMonitor(this->bytes(), false); + device->memoryMonitor(this->bytes(), false); size_t b = (this->bytes()+15) & ssize_t(-16); - ptr = (char*)alignedMalloc(b,16); + ptr = (char*)device->malloc(b,16); } /*! frees the buffer */ void free() { if (shared) return; - alignedFree(ptr); - if (device) - device->memoryMonitor(-ssize_t(this->bytes()), true); + device->free(ptr); + device->memoryMonitor(-ssize_t(this->bytes()), true); ptr = nullptr; } @@ -246,6 +244,24 @@ namespace embree public: typedef Vec3fa value_type; +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + + /*! access to the ith element of the buffer */ + __forceinline const Vec3fa operator [](size_t i) const + { + assert(ifilter != nullptr; + return args->filter != nullptr; + } + + RTCFilterFunctionN getFilter() const { + return args->filter; + } + + RTCIntersectFunctionN getIntersectFunction() const { + return args->intersect; + } + + RTCOccludedFunctionN getOccludedFunction() const { + return (RTCOccludedFunctionN) args->intersect; } __forceinline bool isCoherent() const { - return embree::isCoherent(user->flags); + return embree::isCoherent(args->flags); } __forceinline bool isIncoherent() const { - return embree::isIncoherent(user->flags); + return embree::isIncoherent(args->flags); } - + + __forceinline bool enforceArgumentFilterFunction() const { + return args->flags & RTC_RAY_QUERY_FLAG_INVOKE_ARGUMENT_FILTER; + } + +#if RTC_MIN_WIDTH + __forceinline float getMinWidthDistanceFactor() const { + return args->minWidthDistanceFactor; + } +#endif + public: - Scene* scene; - RTCIntersectContext* user; + Scene* scene = nullptr; + RTCRayQueryContext* user = nullptr; + RTCIntersectArguments* args = nullptr; }; template - __forceinline Vec4vf enlargeRadiusToMinWidth(const IntersectContext* context, const Geometry* geom, const Vec3vf& ray_org, const Vec4vf& v) + __forceinline Vec4vf enlargeRadiusToMinWidth(const RayQueryContext* context, const Geometry* geom, const Vec3vf& ray_org, const Vec4vf& v) { #if RTC_MIN_WIDTH const vfloat d = length(Vec3vf(v) - ray_org); - const vfloat r = clamp(context->user->minWidthDistanceFactor*d, v.w, geom->maxRadiusScale*v.w); + const vfloat r = clamp(context->getMinWidthDistanceFactor()*d, v.w, geom->maxRadiusScale*v.w); return Vec4vf(v.x,v.y,v.z,r); #else return v; @@ -47,16 +74,21 @@ namespace embree } template - __forceinline Vec3ff enlargeRadiusToMinWidth(const IntersectContext* context, const Geometry* geom, const Vec3fa& ray_org, const Vec3ff& v) + __forceinline Vec3ff enlargeRadiusToMinWidth(const RayQueryContext* context, const Geometry* geom, const Vec3fa& ray_org, const Vec3ff& v) { #if RTC_MIN_WIDTH const float d = length(Vec3fa(v) - ray_org); - const float r = clamp(context->user->minWidthDistanceFactor*d, v.w, geom->maxRadiusScale*v.w); + const float r = clamp(context->getMinWidthDistanceFactor()*d, v.w, geom->maxRadiusScale*v.w); return Vec3ff(v.x,v.y,v.z,r); #else return v; #endif } + + template + __forceinline Vec3ff enlargeRadiusToMinWidth(const RayQueryContext* context, const Geometry* geom, const Vec3fa& ray_org, const Vec4f& v) { + return enlargeRadiusToMinWidth(context,geom,ray_org,Vec3ff(v.x,v.y,v.z,v.w)); + } enum PointQueryType { @@ -66,7 +98,7 @@ namespace embree }; typedef bool (*PointQueryFunction)(struct RTCPointQueryFunctionArguments* args); - + struct PointQueryContext { public: @@ -78,6 +110,7 @@ namespace embree float similarityScale, void* userPtr) : scene(scene) + , tstate(nullptr) , query_ws(query_ws) , query_type(query_type) , func(func) @@ -88,16 +121,24 @@ namespace embree , geomID(RTC_INVALID_GEOMETRY_ID) , query_radius(query_ws->radius) { + update(); + } + + public: + __forceinline void update() + { if (query_type == POINT_QUERY_TYPE_AABB) { assert(similarityScale == 0.f); updateAABB(); } + else{ + query_radius = Vec3fa(query_ws->radius * similarityScale); + } if (userContext->instStackSize == 0) { assert(similarityScale == 1.f); } } - public: __forceinline void updateAABB() { if (likely(query_ws->radius == (float)inf || userContext->instStackSize == 0)) { @@ -113,12 +154,13 @@ namespace embree public: Scene* scene; + void* tstate; PointQuery* query_ws; // the original world space point query PointQueryType query_type; PointQueryFunction func; RTCPointQueryContext* userContext; - const float similarityScale; + float similarityScale; void* userPtr; diff --git a/thirdparty/embree/kernels/common/default.h b/thirdparty/embree/kernels/common/default.h index f15d61b7682..3b00ad3c880 100644 --- a/thirdparty/embree/kernels/common/default.h +++ b/thirdparty/embree/kernels/common/default.h @@ -13,11 +13,11 @@ #include "../../common/sys/mutex.h" #include "../../common/sys/vector.h" #include "../../common/sys/array.h" -#include "../../common/sys/string.h" +#include "../../common/sys/estring.h" #include "../../common/sys/regression.h" #include "../../common/sys/vector.h" -#include "../../common/math/math.h" +#include "../../common/math/emath.h" #include "../../common/math/transcendental.h" #include "../../common/simd/simd.h" #include "../../common/math/vec2.h" @@ -35,8 +35,6 @@ #include "../../common/math/range.h" #include "../../common/lexers/tokenstream.h" -#include "../../common/tasking/taskscheduler.h" - #define COMMA , #include "../config.h" @@ -217,7 +215,7 @@ namespace embree __forceinline int getTimeSegment(float time, float numTimeSegments, float& ftime) { const float timeScaled = time * numTimeSegments; - const float itimef = clamp(floorf(timeScaled), 0.0f, numTimeSegments-1.0f); + const float itimef = clamp(floor(timeScaled), 0.0f, numTimeSegments-1.0f); ftime = timeScaled - itimef; return int(itimef); } @@ -225,7 +223,7 @@ namespace embree __forceinline int getTimeSegment(float time, float start_time, float end_time, float numTimeSegments, float& ftime) { const float timeScaled = (time-start_time)/(end_time-start_time) * numTimeSegments; - const float itimef = clamp(floorf(timeScaled), 0.0f, numTimeSegments-1.0f); + const float itimef = clamp(floor(timeScaled), 0.0f, numTimeSegments-1.0f); ftime = timeScaled - itimef; return int(itimef); } diff --git a/thirdparty/embree/kernels/common/device.cpp b/thirdparty/embree/kernels/common/device.cpp index 833ec651392..07214532a1d 100644 --- a/thirdparty/embree/kernels/common/device.cpp +++ b/thirdparty/embree/kernels/common/device.cpp @@ -2,6 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "device.h" + +#include "../../common/tasking/taskscheduler.h" + #include "../hash.h" #include "scene_triangle_mesh.h" #include "scene_user_geometry.h" @@ -19,9 +22,12 @@ #include "../bvh/bvh4_factory.h" #include "../bvh/bvh8_factory.h" -#include "../../common/tasking/taskscheduler.h" #include "../../common/sys/alloc.h" +#if defined(EMBREE_SYCL_SUPPORT) +# include "../level_zero/ze_wrapper.h" +#endif + namespace embree { /*! some global variables that can be set via rtcSetParameter1i for debugging purposes */ @@ -30,13 +36,18 @@ namespace embree ssize_t Device::debug_int2 = 0; ssize_t Device::debug_int3 = 0; - DECLARE_SYMBOL2(RayStreamFilterFuncs,rayStreamFilterFuncs); - static MutexSys g_mutex; static std::map g_cache_size_map; static std::map g_num_threads_map; + + struct TaskArena + { +#if USE_TASK_ARENA + std::unique_ptr arena; +#endif + }; - Device::Device (const char* cfg) + Device::Device (const char* cfg) : arena(new TaskArena()) { /* check that CPU supports lowest ISA */ if (!hasISA(ISA)) { @@ -48,12 +59,12 @@ namespace embree case CPU::UNKNOWN: frequency_level = FREQUENCY_SIMD256; break; case CPU::XEON_ICE_LAKE: frequency_level = FREQUENCY_SIMD256; break; case CPU::CORE_ICE_LAKE: frequency_level = FREQUENCY_SIMD256; break; - case CPU::CORE_TIGER_LAKE: frequency_level = FREQUENCY_SIMD128; break; - case CPU::CORE_COMET_LAKE: frequency_level = FREQUENCY_SIMD128; break; - case CPU::CORE_CANNON_LAKE:frequency_level = FREQUENCY_SIMD128; break; - case CPU::CORE_KABY_LAKE: frequency_level = FREQUENCY_SIMD128; break; + case CPU::CORE_TIGER_LAKE: frequency_level = FREQUENCY_SIMD256; break; + case CPU::CORE_COMET_LAKE: frequency_level = FREQUENCY_SIMD256; break; + case CPU::CORE_CANNON_LAKE:frequency_level = FREQUENCY_SIMD256; break; + case CPU::CORE_KABY_LAKE: frequency_level = FREQUENCY_SIMD256; break; case CPU::XEON_SKY_LAKE: frequency_level = FREQUENCY_SIMD128; break; - case CPU::CORE_SKY_LAKE: frequency_level = FREQUENCY_SIMD128; break; + case CPU::CORE_SKY_LAKE: frequency_level = FREQUENCY_SIMD256; break; case CPU::XEON_BROADWELL: frequency_level = FREQUENCY_SIMD256; break; case CPU::CORE_BROADWELL: frequency_level = FREQUENCY_SIMD256; break; case CPU::XEON_HASWELL: frequency_level = FREQUENCY_SIMD256; break; @@ -66,11 +77,7 @@ namespace embree case CPU::CORE1: frequency_level = FREQUENCY_SIMD128; break; case CPU::XEON_PHI_KNIGHTS_MILL : frequency_level = FREQUENCY_SIMD512; break; case CPU::XEON_PHI_KNIGHTS_LANDING: frequency_level = FREQUENCY_SIMD512; break; -#if defined(__APPLE__) - case CPU::ARM: frequency_level = FREQUENCY_SIMD256; break; // Apple M1 supports high throughput for SIMD4 -#else - case CPU::ARM: frequency_level = FREQUENCY_SIMD128; break; -#endif + case CPU::ARM: frequency_level = FREQUENCY_SIMD256; break; } /* initialize global state */ @@ -126,13 +133,6 @@ namespace embree /* setup tasking system */ initTaskingSystem(numThreads); - - /* ray stream SOA to AOS conversion */ -#if defined(EMBREE_RAY_PACKETS) - RayStreamFilterFuncsType rayStreamFilterFuncs; - SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(enabled_cpu_features,rayStreamFilterFuncs); - rayStreamFilters = rayStreamFilterFuncs(); -#endif } Device::~Device () @@ -174,6 +174,9 @@ namespace embree #if defined (EMBREE_BACKFACE_CULLING_CURVES) v += "backfacecullingcurves "; #endif +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + v += "backfacecullingspheres "; +#endif #if defined(EMBREE_FILTER_FUNCTION) v += "intersection_filter "; #endif @@ -367,7 +370,7 @@ namespace embree #if USE_TASK_ARENA const size_t nThreads = min(maxNumThreads,TaskScheduler::threadCount()); const size_t uThreads = min(max(numUserThreads,(size_t)1),nThreads); - arena = make_unique(new tbb::task_arena((int)nThreads,(unsigned int)uThreads)); + arena->arena = make_unique(new tbb::task_arena((int)nThreads,(unsigned int)uThreads)); #endif } @@ -386,10 +389,23 @@ namespace embree TaskScheduler::create(maxNumThreads,State::set_affinity,State::start_threads); } #if USE_TASK_ARENA - arena.reset(); + arena->arena.reset(); #endif } + void Device::execute(bool join, const std::function& func) + { +#if USE_TASK_ARENA + if (join) { + arena->arena->execute(func); + } + else +#endif + { + func(); + } + } + void Device::setProperty(const RTCDeviceProperty prop, ssize_t val) { /* hidden internal properties */ @@ -450,12 +466,6 @@ namespace embree case RTC_DEVICE_PROPERTY_NATIVE_RAY16_SUPPORTED: return 0; #endif -#if defined(EMBREE_RAY_PACKETS) - case RTC_DEVICE_PROPERTY_RAY_STREAM_SUPPORTED: return 1; -#else - case RTC_DEVICE_PROPERTY_RAY_STREAM_SUPPORTED: return 0; -#endif - #if defined(EMBREE_RAY_MASK) case RTC_DEVICE_PROPERTY_RAY_MASK_SUPPORTED: return 1; #else @@ -474,6 +484,12 @@ namespace embree case RTC_DEVICE_PROPERTY_BACKFACE_CULLING_CURVES_ENABLED: return 0; #endif +#if defined(EMBREE_BACKFACE_CULLING_SPHERES) + case RTC_DEVICE_PROPERTY_BACKFACE_CULLING_SPHERES_ENABLED: return 1; +#else + case RTC_DEVICE_PROPERTY_BACKFACE_CULLING_SPHERES_ENABLED: return 0; +#endif + #if defined(EMBREE_COMPACT_POLYS) case RTC_DEVICE_PROPERTY_COMPACT_POLYS_ENABLED: return 1; #else @@ -557,4 +573,158 @@ namespace embree default: throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "unknown readable property"); break; }; } + + void* Device::malloc(size_t size, size_t align) { + return alignedMalloc(size,align); + } + + void Device::free(void* ptr) { + alignedFree(ptr); + } + + +#if defined(EMBREE_SYCL_SUPPORT) + + DeviceGPU::DeviceGPU(sycl::context sycl_context, const char* cfg) + : Device(cfg), gpu_context(sycl_context) + { + /* initialize ZeWrapper */ + if (ZeWrapper::init() != ZE_RESULT_SUCCESS) + throw_RTCError(RTC_ERROR_UNKNOWN, "cannot initialize ZeWrapper"); + + /* take first device as default device */ + auto devices = gpu_context.get_devices(); + if (devices.size() == 0) + throw_RTCError(RTC_ERROR_UNKNOWN, "SYCL context contains no device"); + gpu_device = devices[0]; + + /* check if RTAS build extension is available */ + sycl::platform platform = gpu_device.get_platform(); + ze_driver_handle_t hDriver = sycl::get_native(platform); + + uint32_t count = 0; + std::vector extensions; + ze_result_t result = ZeWrapper::zeDriverGetExtensionProperties(hDriver,&count,extensions.data()); + if (result != ZE_RESULT_SUCCESS) + throw_RTCError(RTC_ERROR_UNKNOWN, "zeDriverGetExtensionProperties failed"); + + extensions.resize(count); + result = ZeWrapper::zeDriverGetExtensionProperties(hDriver,&count,extensions.data()); + if (result != ZE_RESULT_SUCCESS) + throw_RTCError(RTC_ERROR_UNKNOWN, "zeDriverGetExtensionProperties failed"); + +#if defined(EMBREE_SYCL_L0_RTAS_BUILDER) + bool ze_rtas_builder = false; + for (uint32_t i=0; i(); + gpu_maxComputeUnits = getGPUDevice().get_info(); + + if (State::verbosity(1)) + { + sycl::platform platform = gpu_context.get_platform(); + std::cout << " Platform : " << platform.get_info() << std::endl; + std::cout << " Device : " << getGPUDevice().get_info() << std::endl; + std::cout << " Max Work Group Size : " << gpu_maxWorkGroupSize << std::endl; + std::cout << " Max Compute Units : " << gpu_maxComputeUnits << std::endl; + std::cout << std::endl; + } + + dispatchGlobalsPtr = zeRTASInitExp(gpu_device, gpu_context); + } + + DeviceGPU::~DeviceGPU() + { + rthwifCleanup(this,dispatchGlobalsPtr,gpu_context); + } + + void DeviceGPU::enter() { + enableUSMAllocEmbree(&gpu_context,&gpu_device); + } + + void DeviceGPU::leave() { + disableUSMAllocEmbree(); + } + + void* DeviceGPU::malloc(size_t size, size_t align) { + return alignedSYCLMalloc(&gpu_context,&gpu_device,size,align,EMBREE_USM_SHARED_DEVICE_READ_ONLY); + } + + void DeviceGPU::free(void* ptr) { + alignedSYCLFree(&gpu_context,ptr); + } + + void DeviceGPU::setSYCLDevice(const sycl::device sycl_device_in) { + gpu_device = sycl_device_in; + } + +#endif + + DeviceEnterLeave::DeviceEnterLeave (RTCDevice hdevice) + : device((Device*)hdevice) + { + assert(device); + device->refInc(); + device->enter(); + } + + DeviceEnterLeave::DeviceEnterLeave (RTCScene hscene) + : device(((Scene*)hscene)->device) + { + assert(device); + device->refInc(); + device->enter(); + } + + DeviceEnterLeave::DeviceEnterLeave (RTCGeometry hgeometry) + : device(((Geometry*)hgeometry)->device) + { + assert(device); + device->refInc(); + device->enter(); + } + + DeviceEnterLeave::DeviceEnterLeave (RTCBuffer hbuffer) + : device(((Buffer*)hbuffer)->device) + { + assert(device); + device->refInc(); + device->enter(); + } + + DeviceEnterLeave::~DeviceEnterLeave() { + device->leave(); + device->refDec(); + } } diff --git a/thirdparty/embree/kernels/common/device.h b/thirdparty/embree/kernels/common/device.h index 21c42c654d8..c9e8888a5af 100644 --- a/thirdparty/embree/kernels/common/device.h +++ b/thirdparty/embree/kernels/common/device.h @@ -11,10 +11,57 @@ namespace embree { class BVH4Factory; class BVH8Factory; + struct TaskArena; class Device : public State, public MemoryMonitorInterface { ALIGNED_CLASS_(16); + + public: + + /*! allocator that performs unified shared memory allocations */ + template + struct allocator + { + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + allocator() {} + + allocator(Device* device) + : device(device) {} + + __forceinline pointer allocate( size_type n ) { + assert(device); + return (pointer) device->malloc(n*sizeof(T),alignment); + } + + __forceinline void deallocate( pointer p, size_type n ) { + if (device) device->free(p); + } + + __forceinline void construct( pointer p, const_reference val ) { + new (p) T(val); + } + + __forceinline void destroy( pointer p ) { + p->~T(); + } + + Device* device = nullptr; + }; + + /*! vector class that performs aligned allocations from Device object */ + template + using vector = vector_t::value>>; + + template + using avector = vector_t>; public: @@ -54,6 +101,18 @@ namespace embree /*! gets a property */ ssize_t getProperty(const RTCDeviceProperty prop); + /*! enter device by setting up some global state */ + virtual void enter() {} + + /*! leave device by setting up some global state */ + virtual void leave() {} + + /*! buffer allocation */ + virtual void* malloc(size_t size, size_t align); + + /*! buffer deallocation */ + virtual void free(void* ptr); + private: /*! initializes the tasking system */ @@ -62,6 +121,13 @@ namespace embree /*! shuts down the tasking system */ void exitTaskingSystem(); + std::unique_ptr arena; + + public: + + // use tasking system arena to execute func + void execute(bool join, const std::function& func); + /*! some variables that can be set via rtcSetParameter1i for debugging purposes */ public: static ssize_t debug_int0; @@ -74,12 +140,55 @@ namespace embree #if defined(EMBREE_TARGET_SIMD8) std::unique_ptr bvh8_factory; #endif - -#if USE_TASK_ARENA - std::unique_ptr arena; + }; + +#if defined(EMBREE_SYCL_SUPPORT) + + class DeviceGPU : public Device + { + public: + + DeviceGPU(sycl::context sycl_context, const char* cfg); + ~DeviceGPU(); + + virtual void enter() override; + virtual void leave() override; + virtual void* malloc(size_t size, size_t align) override; + virtual void free(void* ptr) override; + + /* set SYCL device */ + void setSYCLDevice(const sycl::device sycl_device); + + private: + sycl::context gpu_context; + sycl::device gpu_device; + + unsigned int gpu_maxWorkGroupSize; + unsigned int gpu_maxComputeUnits; + + public: + void* dispatchGlobalsPtr = nullptr; + + public: + inline sycl::device &getGPUDevice() { return gpu_device; } + inline sycl::context &getGPUContext() { return gpu_context; } + + inline unsigned int getGPUMaxWorkGroupSize() { return gpu_maxWorkGroupSize; } + + void init_rthw_level_zero(); + void init_rthw_opencl(); + }; + #endif - - /* ray streams filter */ - RayStreamFilterFuncs rayStreamFilters; + + struct DeviceEnterLeave + { + DeviceEnterLeave (RTCDevice hdevice); + DeviceEnterLeave (RTCScene hscene); + DeviceEnterLeave (RTCGeometry hgeometry); + DeviceEnterLeave (RTCBuffer hbuffer); + ~DeviceEnterLeave(); + private: + Device* device; }; } diff --git a/thirdparty/embree/kernels/common/geometry.cpp b/thirdparty/embree/kernels/common/geometry.cpp index d8d3f65a5cf..79a6eb00d70 100644 --- a/thirdparty/embree/kernels/common/geometry.cpp +++ b/thirdparty/embree/kernels/common/geometry.cpp @@ -45,12 +45,13 @@ namespace embree Geometry::Geometry (Device* device, GType gtype, unsigned int numPrimitives, unsigned int numTimeSteps) : device(device), userPtr(nullptr), numPrimitives(numPrimitives), numTimeSteps(unsigned(numTimeSteps)), fnumTimeSegments(float(numTimeSteps-1)), time_range(0.0f,1.0f), - mask(-1), + mask(1), gtype(gtype), gsubtype(GTY_SUBTYPE_DEFAULT), quality(RTC_BUILD_QUALITY_MEDIUM), state((unsigned)State::MODIFIED), enabled(true), + argumentFilterEnabled(false), intersectionFilterN(nullptr), occlusionFilterN(nullptr), pointQueryFunc(nullptr) { device->refInc(); @@ -88,6 +89,11 @@ namespace embree Geometry::update(); } + BBox1f Geometry::getTimeRange () const + { + return time_range; + } + void Geometry::update() { ++modCounter_; // FIXME: required? @@ -227,11 +233,11 @@ namespace embree } } } - + bool Geometry::pointQuery(PointQuery* query, PointQueryContext* context) { assert(context->primID < size()); - + RTCPointQueryFunctionArguments args; args.query = (RTCPointQuery*)context->query_ws; args.userPtr = context->userPtr; @@ -239,7 +245,7 @@ namespace embree args.geomID = context->geomID; args.context = context->userContext; args.similarityScale = context->similarityScale; - + bool update = false; if(context->func) update |= context->func(&args); if(pointQueryFunc) update |= pointQueryFunc(&args); diff --git a/thirdparty/embree/kernels/common/geometry.h b/thirdparty/embree/kernels/common/geometry.h index 593990f5b1f..00e3c5ede3d 100644 --- a/thirdparty/embree/kernels/common/geometry.h +++ b/thirdparty/embree/kernels/common/geometry.h @@ -8,6 +8,7 @@ #include "buffer.h" #include "../common/point_query.h" #include "../builders/priminfo.h" +#include "../builders/priminfo_mb.h" namespace embree { @@ -26,12 +27,14 @@ namespace embree numUserGeometries(0), numMBUserGeometries(0), numInstancesCheap(0), numMBInstancesCheap(0), numInstancesExpensive(0), numMBInstancesExpensive(0), - numGrids(0), numMBGrids(0), + numInstanceArrays(0), numMBInstanceArrays(0), + numGrids(0), numMBGrids(0), + numSubGrids(0), numMBSubGrids(0), numPoints(0), numMBPoints(0) {} __forceinline size_t size() const { - return numTriangles + numQuads + numBezierCurves + numLineSegments + numSubdivPatches + numUserGeometries + numInstancesCheap + numInstancesExpensive + numGrids + numPoints - + numMBTriangles + numMBQuads + numMBBezierCurves + numMBLineSegments + numMBSubdivPatches + numMBUserGeometries + numMBInstancesCheap + numMBInstancesExpensive + numMBGrids + numMBPoints; + return numTriangles + numQuads + numBezierCurves + numLineSegments + numSubdivPatches + numUserGeometries + numInstancesCheap + numInstancesExpensive + numInstanceArrays + numGrids + numPoints + + numMBTriangles + numMBQuads + numMBBezierCurves + numMBLineSegments + numMBSubdivPatches + numMBUserGeometries + numMBInstancesCheap + numMBInstancesExpensive + numMBInstanceArrays + numMBGrids + numMBPoints; } __forceinline unsigned int enabledGeometryTypesMask() const @@ -44,8 +47,9 @@ namespace embree if (numUserGeometries) mask |= 1 << 4; if (numInstancesCheap) mask |= 1 << 5; if (numInstancesExpensive) mask |= 1 << 6; - if (numGrids) mask |= 1 << 7; - if (numPoints) mask |= 1 << 8; + if (numInstanceArrays) mask |= 1 << 7; + if (numGrids) mask |= 1 << 8; + if (numPoints) mask |= 1 << 9; unsigned int maskMB = 0; if (numMBTriangles) maskMB |= 1 << 0; @@ -55,8 +59,9 @@ namespace embree if (numMBUserGeometries) maskMB |= 1 << 4; if (numMBInstancesCheap) maskMB |= 1 << 5; if (numMBInstancesExpensive) maskMB |= 1 << 6; - if (numMBGrids) maskMB |= 1 << 7; - if (numMBPoints) maskMB |= 1 << 8; + if (numMBInstanceArrays) maskMB |= 1 << 7; + if (numMBGrids) maskMB |= 1 << 8; + if (numMBPoints) maskMB |= 1 << 9; return (mask<<8) + maskMB; } @@ -81,8 +86,12 @@ namespace embree ret.numMBInstancesCheap = numMBInstancesCheap + rhs.numMBInstancesCheap; ret.numInstancesExpensive = numInstancesExpensive + rhs.numInstancesExpensive; ret.numMBInstancesExpensive = numMBInstancesExpensive + rhs.numMBInstancesExpensive; + ret.numInstanceArrays = numInstanceArrays + rhs.numInstanceArrays; + ret.numMBInstanceArrays = numMBInstanceArrays + rhs.numMBInstanceArrays; ret.numGrids = numGrids + rhs.numGrids; ret.numMBGrids = numMBGrids + rhs.numMBGrids; + ret.numSubGrids = numSubGrids + rhs.numSubGrids; + ret.numMBSubGrids = numMBSubGrids + rhs.numMBSubGrids; ret.numPoints = numPoints + rhs.numPoints; ret.numMBPoints = numMBPoints + rhs.numMBPoints; @@ -106,8 +115,12 @@ namespace embree size_t numMBInstancesCheap; //!< number of enabled motion blurred cheap instances size_t numInstancesExpensive; //!< number of enabled expensive instances size_t numMBInstancesExpensive; //!< number of enabled motion blurred expensive instances + size_t numInstanceArrays; //!< number of enabled instance arrays + size_t numMBInstanceArrays; //!< number of enabled motion blurred instance arrays size_t numGrids; //!< number of enabled grid geometries size_t numMBGrids; //!< number of enabled motion blurred grid geometries + size_t numSubGrids; //!< number of enabled grid geometries + size_t numMBSubGrids; //!< number of enabled motion blurred grid geometries size_t numPoints; //!< number of enabled points size_t numMBPoints; //!< number of enabled motion blurred points }; @@ -115,6 +128,8 @@ namespace embree /*! Base class all geometries are derived from */ class Geometry : public RefCount { + ALIGNED_CLASS_USM_(16); + friend class Scene; public: @@ -154,6 +169,7 @@ namespace embree GTY_USER_GEOMETRY = 29, GTY_INSTANCE_CHEAP = 30, GTY_INSTANCE_EXPENSIVE = 31, + GTY_INSTANCE_ARRAY = 24, GTY_END = 32, GTY_BASIS_LINEAR = 0, @@ -222,7 +238,10 @@ namespace embree MTY_INSTANCE_CHEAP = 1ul << GTY_INSTANCE_CHEAP, MTY_INSTANCE_EXPENSIVE = 1ul << GTY_INSTANCE_EXPENSIVE, - MTY_INSTANCE = MTY_INSTANCE_CHEAP | MTY_INSTANCE_EXPENSIVE + MTY_INSTANCE = MTY_INSTANCE_CHEAP | MTY_INSTANCE_EXPENSIVE, + MTY_INSTANCE_ARRAY = 1ul << GTY_INSTANCE_ARRAY, + + MTY_ALL = -1 }; static const char* gtype_names[GTY_END]; @@ -248,8 +267,13 @@ namespace embree /*! tests if geometry is disabled */ __forceinline bool isDisabled() const { return !isEnabled(); } + /* checks if argument version of filter functions are enabled */ + __forceinline bool hasArgumentFilterFunctions() const { + return argumentFilterEnabled; + } + /*! tests if that geometry has some filter function set */ - __forceinline bool hasFilterFunctions () const { + __forceinline bool hasGeometryFilterFunctions () const { return (intersectionFilterN != nullptr) || (occlusionFilterN != nullptr); } @@ -265,6 +289,11 @@ namespace embree /*! returns geometry type mask */ __forceinline GTypeMask getTypeMask() const { return (GTypeMask)(1 << gtype); } + /*! returns true of geometry contains motion blur */ + __forceinline bool hasMotionBlur () const { + return numTimeSteps > 1; + } + /*! returns number of primitives */ __forceinline size_t size() const { return numPrimitives; } @@ -277,6 +306,9 @@ namespace embree /*! sets motion blur time range */ void setTimeRange (const BBox1f range); + /*! gets motion blur time range */ + BBox1f getTimeRange () const; + /*! sets number of vertex attributes */ virtual void setVertexAttributeCount (unsigned int N) { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); @@ -447,6 +479,11 @@ namespace embree /*! Set occlusion filter function for ray packets of size N. */ virtual void setOcclusionFilterFunctionN (RTCFilterFunctionN filterN); + /* Enables argument version of intersection or occlusion filter function. */ + virtual void enableFilterFunctionFromArguments (bool enable) { + argumentFilterEnabled = enable; + } + /*! for instances only */ public: @@ -455,6 +492,11 @@ namespace embree throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); } + /*! Sets the instanced scenes */ + virtual void setInstancedScenes(const RTCScene* scenes, size_t numScenes) { + throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); + } + /*! Sets transformation of the instance */ virtual void setTransform(const AffineSpace3fa& transform, unsigned int timeStep) { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); @@ -467,7 +509,12 @@ namespace embree /*! Returns the transformation of the instance */ virtual AffineSpace3fa getTransform(float time) { - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); + throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); + } + + /*! Returns the transformation of the instance */ + virtual AffineSpace3fa getTransform(size_t instance, float time) { + throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry"); } /*! for user geometries only */ @@ -498,18 +545,47 @@ namespace embree public: - virtual PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const { + virtual PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefArray not implemented for this geometry"); } + PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const { + return createPrimRefArray(prims.data(),r,k,geomID); + } + + PrimInfo createPrimRefArray(avector& prims, const range& r, size_t k, unsigned int geomID) const { + return createPrimRefArray(prims.data(),r,k,geomID); + } + + virtual PrimInfo createPrimRefArray(mvector& prims, mvector& sgrids, const range& r, size_t k, unsigned int geomID) const { + return createPrimRefArray(prims,r,k,geomID); + } + virtual PrimInfo createPrimRefArrayMB(mvector& prims, size_t itime, const range& r, size_t k, unsigned int geomID) const { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry"); } + /*! Calculates the PrimRef over the complete time interval */ + virtual PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { + throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry"); + } + + PrimInfo createPrimRefArrayMB(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { + return createPrimRefArrayMB(prims.data(),t0t1,r,k,geomID); + } + + PrimInfo createPrimRefArrayMB(avector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { + return createPrimRefArrayMB(prims.data(),t0t1,r,k,geomID); + } + virtual PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry"); } + virtual PrimInfoMB createPrimRefMBArray(mvector& prims, mvector& sgrids, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { + return createPrimRefMBArray(prims,t0t1,r,k,geomID); + } + virtual LinearSpace3fa computeAlignedSpace(const size_t primID) const { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"computeAlignedSpace not implemented for this geometry"); } @@ -541,6 +617,10 @@ namespace embree virtual LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry"); } + + virtual LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range, const SubGridBuildData * const sgrids) const { + return vlinearBounds(primID,time_range); + } virtual LBBox3fa vlinearBounds(const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry"); @@ -566,13 +646,14 @@ namespace embree unsigned int mask; //!< for masking out geometry unsigned int modCounter_ = 1; //!< counter for every modification - used to rebuild scenes when geo is modified - + struct { GType gtype : 8; //!< geometry type GSubType gsubtype : 8; //!< geometry subtype RTCBuildQuality quality : 3; //!< build quality for geometry unsigned state : 2; - bool enabled : 1; //!< true if geometry is enabled + bool enabled : 1; //!< true if geometry is enabled + bool argumentFilterEnabled : 1; //!< true if argument filter functions are enabled for this geometry }; RTCFilterFunctionN intersectionFilterN; diff --git a/thirdparty/embree/kernels/common/hit.h b/thirdparty/embree/kernels/common/hit.h index fd1a9d63911..cbaeb9b73ab 100644 --- a/thirdparty/embree/kernels/common/hit.h +++ b/thirdparty/embree/kernels/common/hit.h @@ -17,14 +17,26 @@ namespace embree __forceinline HitK() {} /* Constructs a hit */ - __forceinline HitK(const RTCIntersectContext* context, const vuint& geomID, const vuint& primID, const vfloat& u, const vfloat& v, const Vec3vf& Ng) + __forceinline HitK(const RTCRayQueryContext* context, const vuint& geomID, const vuint& primID, const vfloat& u, const vfloat& v, const Vec3vf& Ng) : Ng(Ng), u(u), v(v), primID(primID), geomID(geomID) { - for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { instID[l] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID[l] = RTC_INVALID_GEOMETRY_ID; +#endif + } + instance_id_stack::copy_UV(context->instID, instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(context->instPrimID, instPrimID); +#endif } + /* Constructs a hit */ + __forceinline HitK(const RTCRayQueryContext* context, const vuint& geomID, const vuint& primID, const Vec2vf& uv, const Vec3vf& Ng) + : HitK(context,geomID,primID,uv.x,uv.y,Ng) {} + /* Returns the size of the hit */ static __forceinline size_t size() { return K; } @@ -35,6 +47,9 @@ namespace embree vuint primID; // primitive ID vuint geomID; // geometry ID vuint instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID +#endif }; /* Specialization for a single hit */ @@ -45,12 +60,19 @@ namespace embree __forceinline HitK() {} /* Constructs a hit */ - __forceinline HitK(const RTCIntersectContext* context, unsigned int geomID, unsigned int primID, float u, float v, const Vec3fa& Ng) + __forceinline HitK(const RTCRayQueryContext* context, unsigned int geomID, unsigned int primID, float u, float v, const Vec3fa& Ng) : Ng(Ng.x,Ng.y,Ng.z), u(u), v(v), primID(primID), geomID(geomID) { - instance_id_stack::copy_UU(context->instID, instID); + instance_id_stack::copy_UU(context, context->instID, instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context, context->instPrimID, instPrimID); +#endif } + /* Constructs a hit */ + __forceinline HitK(const RTCRayQueryContext* context, unsigned int geomID, unsigned int primID, const Vec2f& uv, const Vec3fa& Ng) + : HitK<1>(context,geomID,primID,uv.x,uv.y,Ng) {} + /* Returns the size of the hit */ static __forceinline size_t size() { return 1; } @@ -61,6 +83,9 @@ namespace embree unsigned int primID; // primitive ID unsigned int geomID; // geometry ID unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID +#endif }; /* Shortcuts */ @@ -68,6 +93,7 @@ namespace embree typedef HitK<4> Hit4; typedef HitK<8> Hit8; typedef HitK<16> Hit16; + typedef HitK Hitx; /* Outputs hit to stream */ template @@ -84,6 +110,13 @@ namespace embree { cout << " " << ray.instID[l]; } +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + cout << " instPrimID ="; + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + { + cout << " " << ray.instPrimID[l]; + } +#endif cout << embree_endl; return cout << "}"; } @@ -97,10 +130,13 @@ namespace embree ray.primID = hit.primID; ray.geomID = hit.geomID; instance_id_stack::copy_UU(hit.instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(hit.instPrimID, ray.instPrimID); +#endif } template - __forceinline void copyHitToRay(const vbool &mask, RayHitK &ray, const HitK &hit) + __forceinline void copyHitToRay(const vbool& mask, RayHitK& ray, const HitK& hit) { vfloat::storeu(mask,&ray.Ng.x, hit.Ng.x); vfloat::storeu(mask,&ray.Ng.y, hit.Ng.y); @@ -110,5 +146,8 @@ namespace embree vuint::storeu(mask,&ray.primID, hit.primID); vuint::storeu(mask,&ray.geomID, hit.geomID); instance_id_stack::copy_VV(hit.instID, ray.instID, mask); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_VV(hit.instPrimID, ray.instPrimID, mask); +#endif } } diff --git a/thirdparty/embree/kernels/common/instance_stack.h b/thirdparty/embree/kernels/common/instance_stack.h index d3c0a643f18..32b57b48a3f 100644 --- a/thirdparty/embree/kernels/common/instance_stack.h +++ b/thirdparty/embree/kernels/common/instance_stack.h @@ -19,40 +19,108 @@ static_assert(RTC_MAX_INSTANCE_LEVEL_COUNT > 0, /* * Push an instance to the stack. */ -RTC_FORCEINLINE bool push(RTCIntersectContext* context, - unsigned instanceId) +template +RTC_FORCEINLINE bool push(Context context, + unsigned instanceId, + unsigned instancePrimId) { #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1 const bool spaceAvailable = context->instStackSize < RTC_MAX_INSTANCE_LEVEL_COUNT; - /* We assert here because instances are silently dropped when the stack is full. + /* We assert here because instances are silently dropped when the stack is full. This might be quite hard to find in production. */ - assert(spaceAvailable); - if (likely(spaceAvailable)) - context->instID[context->instStackSize++] = instanceId; + assert(spaceAvailable); + if (likely(spaceAvailable)) { + context->instID[context->instStackSize] = instanceId; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[context->instStackSize] = instancePrimId; +#endif + context->instStackSize++; + } return spaceAvailable; #else const bool spaceAvailable = (context->instID[0] == RTC_INVALID_GEOMETRY_ID); - assert(spaceAvailable); - if (likely(spaceAvailable)) + assert(spaceAvailable); + if (likely(spaceAvailable)) { context->instID[0] = instanceId; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[0] = instancePrimId; +#endif + } return spaceAvailable; #endif } - /* * Pop the last instance pushed to the stack. * Do not call on an empty stack. */ -RTC_FORCEINLINE void pop(RTCIntersectContext* context) +template +RTC_FORCEINLINE void pop(Context context) { assert(context); #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1 assert(context->instStackSize > 0); - context->instID[--context->instStackSize] = RTC_INVALID_GEOMETRY_ID; + --context->instStackSize; + context->instID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID; +#endif #else assert(context->instID[0] != RTC_INVALID_GEOMETRY_ID); context->instID[0] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[0] = RTC_INVALID_GEOMETRY_ID; +#endif +#endif +} + + +/* Push an instance to the stack. Used for point queries*/ +RTC_FORCEINLINE bool push(RTCPointQueryContext* context, + unsigned int instanceId, + unsigned int instancePrimId, + AffineSpace3fa const& w2i, + AffineSpace3fa const& i2w) +{ + assert(context); + const size_t stackSize = context->instStackSize; + assert(stackSize < RTC_MAX_INSTANCE_LEVEL_COUNT); + context->instID[stackSize] = instanceId; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[stackSize] = instancePrimId; +#endif + + AffineSpace3fa_store_unaligned(w2i,(AffineSpace3fa*)context->world2inst[stackSize]); + AffineSpace3fa_store_unaligned(i2w,(AffineSpace3fa*)context->inst2world[stackSize]); + +#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1 + if (unlikely(stackSize > 0)) + { + const AffineSpace3fa world2inst = AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->world2inst[stackSize ]) + * AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->world2inst[stackSize-1]); + const AffineSpace3fa inst2world = AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->inst2world[stackSize-1]) + * AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->inst2world[stackSize ]); + AffineSpace3fa_store_unaligned(world2inst,(AffineSpace3fa*)context->world2inst[stackSize]); + AffineSpace3fa_store_unaligned(inst2world,(AffineSpace3fa*)context->inst2world[stackSize]); + } +#endif + context->instStackSize++; + return true; +} + +template<> +RTC_FORCEINLINE void pop(RTCPointQueryContext* context) +{ + assert(context); +#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1 + assert(context->instStackSize > 0); +#else + assert(context->instID[0] != RTC_INVALID_GEOMETRY_ID); +#endif + --context->instStackSize; + context->instID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + context->instPrimID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID; #endif } @@ -77,6 +145,24 @@ RTC_FORCEINLINE void copy_UU(const unsigned* src, unsigned* tgt) #endif } +RTC_FORCEINLINE void copy_UU(const RTCRayQueryContext* context, const unsigned* src, unsigned* tgt) +{ +#if (RTC_MAX_INSTANCE_LEVEL_COUNT == 1) + tgt[0] = src[0]; + +#else + + unsigned int depth = context->instStackSize; + + for (unsigned l = 0; l < depth; ++l) + tgt[l] = src[l]; + + for (unsigned l = depth; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + tgt[l] = RTC_INVALID_GEOMETRY_ID; + +#endif +} + template RTC_FORCEINLINE void copy_UV(const unsigned* src, vuint* tgt) { diff --git a/thirdparty/embree/kernels/common/point_query.h b/thirdparty/embree/kernels/common/point_query.h index 7d55c91fff8..e92e22ae36e 100644 --- a/thirdparty/embree/kernels/common/point_query.h +++ b/thirdparty/embree/kernels/common/point_query.h @@ -120,6 +120,7 @@ namespace embree typedef PointQueryK<4> PointQuery4; typedef PointQueryK<8> PointQuery8; typedef PointQueryK<16> PointQuery16; + typedef PointQueryK PointQueryx; struct PointQueryN; /* Outputs point query to stream */ diff --git a/thirdparty/embree/kernels/common/ray.h b/thirdparty/embree/kernels/common/ray.h index 3c8ee3989c7..c8860133542 100644 --- a/thirdparty/embree/kernels/common/ray.h +++ b/thirdparty/embree/kernels/common/ray.h @@ -10,8 +10,6 @@ namespace embree { - static const size_t MAX_INTERNAL_STREAM_SIZE = 32; - /* Ray structure for K rays */ template struct RayK @@ -97,16 +95,24 @@ namespace embree : RayK(org, dir, tnear, tfar, time, mask, id, flags), geomID(RTC_INVALID_GEOMETRY_ID) { - for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { instID[l] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID[l] = RTC_INVALID_GEOMETRY_ID; +#endif + } } __forceinline RayHitK(const RayK& ray) : RayK(ray), geomID(RTC_INVALID_GEOMETRY_ID) { - for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { instID[l] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID[l] = RTC_INVALID_GEOMETRY_ID; +#endif + } } __forceinline RayHitK& operator =(const RayK& ray) @@ -121,8 +127,12 @@ namespace embree flags = ray.flags; geomID = RTC_INVALID_GEOMETRY_ID; - for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { instID[l] = RTC_INVALID_GEOMETRY_ID; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID[l] = RTC_INVALID_GEOMETRY_ID; +#endif + } return *this; } @@ -159,7 +169,10 @@ namespace embree vuint primID; // primitive ID vuint geomID; // geometry ID vuint instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID - }; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance prim ID +#endif +}; /* Specialization for a single ray */ template<> @@ -178,6 +191,11 @@ namespace embree return all(le_mask(abs(Vec3fa(org)), Vec3fa(FLT_LARGE)) & le_mask(abs(Vec3fa(dir)), Vec3fa(FLT_LARGE))) && abs(tnear()) <= float(inf) && abs(tfar) <= float(inf); } + /* checks if occlusion ray is done */ + __forceinline bool occluded() const { + return tfar < 0.0f; + } + /* Ray data */ Vec3ff org; // 3 floats for ray origin, 1 float for tnear //float tnear; // start of ray segment @@ -251,6 +269,9 @@ namespace embree unsigned int primID; // primitive ID unsigned int geomID; // geometry ID unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID +#endif }; /* Converts ray packet to single rays */ @@ -293,6 +314,9 @@ namespace embree ray.primID = primID[i]; ray.geomID = geomID[i]; instance_id_stack::copy_VU(instID, ray.instID, i); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_VU(instPrimID, ray.instPrimID, i); +#endif } /* Converts single rays to ray packet */ @@ -332,6 +356,9 @@ namespace embree primID[i] = ray.primID; geomID[i] = ray.geomID; instance_id_stack::copy_UV(ray.instID, instID, i); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(ray.instPrimID, instPrimID, i); +#endif } /* copies a ray packet element into another element*/ @@ -354,6 +381,9 @@ namespace embree primID[dest] = primID[source]; geomID[dest] = geomID[source]; instance_id_stack::copy_VV(instID, instID, source, dest); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_VV(instPrimID, instPrimID, source, dest); +#endif } /* Shortcuts */ @@ -361,12 +391,14 @@ namespace embree typedef RayK<4> Ray4; typedef RayK<8> Ray8; typedef RayK<16> Ray16; + typedef RayK Rayx; struct RayN; typedef RayHitK<1> RayHit; typedef RayHitK<4> RayHit4; typedef RayHitK<8> RayHit8; typedef RayHitK<16> RayHit16; + typedef RayHitK RayHitx; struct RayHitN; template @@ -428,6 +460,13 @@ namespace embree { cout << " " << ray.instID[l]; } +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + cout << " instPrimID ="; + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + { + cout << " " << ray.instPrimID[l]; + } +#endif cout << embree_endl; return cout << "}"; } @@ -464,6 +503,9 @@ namespace embree __forceinline unsigned int* primID(size_t offset = 0) { return (unsigned int*)&ptr[17*4*N+offset]; }; // primitive ID __forceinline unsigned int* geomID(size_t offset = 0) { return (unsigned int*)&ptr[18*4*N+offset]; }; // geometry ID __forceinline unsigned int* instID(size_t level, size_t offset = 0) { return (unsigned int*)&ptr[19*4*N+level*4*N+offset]; }; // instance ID +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + __forceinline unsigned int* instPrimID(size_t level, size_t offset = 0) { return (unsigned int*)&ptr[19*4*N+RTC_MAX_INSTANCE_LEVEL_COUNT*4*N+level*4*N+offset]; }; // instance primitive ID +#endif __forceinline Ray getRayByOffset(size_t offset) { @@ -578,9 +620,16 @@ namespace embree geomID(offset)[k] = ray.geomID[k]; instID(0, offset)[k] = ray.instID[0][k]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID(0, offset)[k] = ray.instPrimID[0][k]; +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) { instID(l, offset)[k] = ray.instID[l][k]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID(l, offset)[k] = ray.instPrimID[l][k]; +#endif + } #endif } } @@ -592,9 +641,16 @@ namespace embree vuint::storeu(valid, geomID(offset), ray.geomID); vuint::storeu(valid, instID(0, offset), ray.instID[0]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::storeu(valid, instPrimID(0, offset), ray.instPrimID[0]); +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) { vuint::storeu(valid, instID(l, offset), ray.instID[l]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::storeu(valid, instPrimID(l, offset), ray.instPrimID[l]); +#endif + } #endif } } @@ -698,9 +754,16 @@ namespace embree vuint::template scatter<1>(valid, geomID(), offset, ray.geomID); vuint::template scatter<1>(valid, instID(0), offset, ray.instID[0]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::template scatter<1>(valid, instPrimID(0), offset, ray.instPrimID[0]); +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) { vuint::template scatter<1>(valid, instID(l), offset, ray.instID[l]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::template scatter<1>(valid, instPrimID(l), offset, ray.instPrimID[l]); +#endif + } #endif #else size_t valid_bits = movemask(valid); @@ -720,9 +783,16 @@ namespace embree *geomID(ofs) = ray.geomID[k]; *instID(0, ofs) = ray.instID[0][k]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + *instPrimID(0, ofs) = ray.instPrimID[0][k]; +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) { *instID(l, ofs) = ray.instID[l][k]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + *instPrimID(l, ofs) = ray.instPrimID[l][k]; +#endif + } #endif } #endif @@ -792,8 +862,12 @@ namespace embree primID = (unsigned int*)&t.primID; geomID = (unsigned int*)&t.geomID; - for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) + for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) { instID[l] = (unsigned int*)&t.instID[l]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instPrimID[l] = (unsigned int*)&t.instPrimID[l]; +#endif + } } __forceinline Ray getRayByOffset(size_t offset) @@ -859,9 +933,16 @@ namespace embree if (likely(instID[0])) { *(unsigned int* __restrict__)((char*)instID[0] + offset) = ray.instID[0]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + *(unsigned int* __restrict__)((char*)instPrimID[0] + offset) = ray.instPrimID[0]; +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID; ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID; ++l) { *(unsigned int* __restrict__)((char*)instID[l] + offset) = ray.instID[l]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + *(unsigned int* __restrict__)((char*)instPrimID[l] + offset) = ray.instPrimID[l]; +#endif + } #endif } } @@ -892,9 +973,16 @@ namespace embree if (likely(instID[0])) { vuint::storeu(valid, (unsigned int* __restrict__)((char*)instID[0] + offset), ray.instID[0]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::storeu(valid, (unsigned int* __restrict__)((char*)instPrimID[0] + offset), ray.instPrimID[0]); +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) { vuint::storeu(valid, (unsigned int* __restrict__)((char*)instID[l] + offset), ray.instID[l]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::storeu(valid, (unsigned int* __restrict__)((char*)instPrimID[l] + offset), ray.instPrimID[l]); +#endif + } #endif } } @@ -1008,9 +1096,16 @@ namespace embree if (likely(instID[0])) { vuint::template scatter<1>(valid, (unsigned int*)instID[0], offset, ray.instID[0]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::template scatter<1>(valid, (unsigned int*)instPrimID[0], offset, ray.instPrimID[0]); +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) { vuint::template scatter<1>(valid, (unsigned int*)instID[l], offset, ray.instID[l]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::template scatter<1>(valid, (unsigned int*)instPrimID[l], offset, ray.instPrimID[l]); +#endif + } #endif } #else @@ -1032,9 +1127,16 @@ namespace embree if (likely(instID[0])) { *(unsigned int* __restrict__)((char*)instID[0] + ofs) = ray.instID[0][k]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + *(unsigned int* __restrict__)((char*)instPrimID[0] + ofs) = ray.instPrimID[0][k]; +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) { *(unsigned int* __restrict__)((char*)instID[l] + ofs) = ray.instID[l][k]; +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + *(unsigned int* __restrict__)((char*)instPrimID[l] + ofs) = ray.instPrimID[l][k]; +#endif + } #endif } } @@ -1091,7 +1193,10 @@ namespace embree unsigned int* __restrict__ primID; // primitive ID unsigned int* __restrict__ geomID; // geometry ID - unsigned int* __restrict__ instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID (optional) + unsigned int* __restrict__ instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + unsigned int* __restrict__ instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID (optional) +#endif }; @@ -1134,9 +1239,16 @@ namespace embree vuint::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->geomID, offset, ray.geomID); vuint::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instID[0], offset, ray.instID[0]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instPrimID[0], offset, ray.instPrimID[0]); +#endif #if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1) - for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) + for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) { vuint::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instID[l], offset, ray.instID[l]); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + vuint::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instPrimID[l], offset, ray.instPrimID[l]); +#endif + } #endif #else size_t valid_bits = movemask(valid); @@ -1154,6 +1266,9 @@ namespace embree ray_k->geomID = ray.geomID[k]; instance_id_stack::copy_VU(ray.instID, ray_k->instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_VU(ray.instPrimID, ray_k->instPrimID, k); +#endif } #endif } @@ -1183,7 +1298,7 @@ namespace embree Ray* __restrict__ ptr; }; - + template<> __forceinline Ray4 RayStreamAOS::getRayByOffset<4>(const vint4& offset) { @@ -1219,7 +1334,7 @@ namespace embree return ray; } - + #if defined(__AVX__) template<> __forceinline Ray8 RayStreamAOS::getRayByOffset<8>(const vint8& offset) @@ -1358,6 +1473,9 @@ namespace embree ray_k->primID = ray.primID[k]; ray_k->geomID = ray.geomID[k]; instance_id_stack::copy_VU(ray.instID, ray_k->instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_VU(ray.instPrimID, ray_k->instPrimID, k); +#endif } } } @@ -1383,7 +1501,7 @@ namespace embree Ray** __restrict__ ptr; }; - + template<> __forceinline Ray4 RayStreamAOP::getRayByIndex<4>(const vint4& index) { @@ -1419,7 +1537,7 @@ namespace embree return ray; } - + #if defined(__AVX__) template<> __forceinline Ray8 RayStreamAOP::getRayByIndex<8>(const vint8& index) diff --git a/thirdparty/embree/kernels/common/rtcore.cpp b/thirdparty/embree/kernels/common/rtcore.cpp index a6ea55bfc43..eb8d2c0a587 100644 --- a/thirdparty/embree/kernels/common/rtcore.cpp +++ b/thirdparty/embree/kernels/common/rtcore.cpp @@ -8,11 +8,14 @@ #include "scene.h" #include "context.h" #include "../geometry/filter.h" -#include "../../include/embree3/rtcore_ray.h" +#include "../../include/embree4/rtcore_ray.h" using namespace embree; RTC_NAMESPACE_BEGIN; +#define RTC_ENTER_DEVICE(arg) \ + DeviceEnterLeave enterleave(arg); + /* mutex to make API thread safe */ static MutexSys g_mutex; @@ -27,6 +30,57 @@ RTC_NAMESPACE_BEGIN; return (RTCDevice) nullptr; } +#if defined(EMBREE_SYCL_SUPPORT) + + RTC_API RTCDevice rtcNewSYCLDeviceInternal(sycl::context sycl_context, const char* config) + { + RTC_CATCH_BEGIN; + RTC_TRACE(rtcNewSYCLDevice); + Lock lock(g_mutex); + + DeviceGPU* device = new DeviceGPU(sycl_context,config); + return (RTCDevice) device->refInc(); + RTC_CATCH_END(nullptr); + return (RTCDevice) nullptr; + } + + RTC_API bool rtcIsSYCLDeviceSupported(const sycl::device device) + { + RTC_CATCH_BEGIN; + RTC_TRACE(rtcIsSYCLDeviceSupported); + return rthwifIsSYCLDeviceSupported(device) > 0; + RTC_CATCH_END(nullptr); + return false; + } + + RTC_API int rtcSYCLDeviceSelector(const sycl::device device) + { + RTC_CATCH_BEGIN; + RTC_TRACE(rtcSYCLDeviceSelector); + return rthwifIsSYCLDeviceSupported(device); + RTC_CATCH_END(nullptr); + return -1; + } + + RTC_API void rtcSetDeviceSYCLDevice(RTCDevice hdevice, const sycl::device sycl_device) + { + RTC_CATCH_BEGIN; + RTC_TRACE(rtcSetDeviceSYCLDevice); + RTC_VERIFY_HANDLE(hdevice); + + Lock lock(g_mutex); + + DeviceGPU* device = dynamic_cast((Device*) hdevice); + if (device == nullptr) + throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "passed device must be an Embree SYCL device") + + device->setSYCLDevice(sycl_device); + + RTC_CATCH_END(nullptr); + } + +#endif + RTC_API void rtcRetainDevice(RTCDevice hdevice) { Device* device = (Device*) hdevice; @@ -108,6 +162,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcNewBuffer); RTC_VERIFY_HANDLE(hdevice); + RTC_ENTER_DEVICE(hdevice); Buffer* buffer = new Buffer((Device*)hdevice, byteSize); return (RTCBuffer)buffer->refInc(); RTC_CATCH_END((Device*)hdevice); @@ -119,6 +174,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcNewSharedBuffer); RTC_VERIFY_HANDLE(hdevice); + RTC_ENTER_DEVICE(hdevice); Buffer* buffer = new Buffer((Device*)hdevice, byteSize, ptr); return (RTCBuffer)buffer->refInc(); RTC_CATCH_END((Device*)hdevice); @@ -131,6 +187,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetBufferData); RTC_VERIFY_HANDLE(hbuffer); + RTC_ENTER_DEVICE(hbuffer); return buffer->data(); RTC_CATCH_END2(buffer); return nullptr; @@ -142,6 +199,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcRetainBuffer); RTC_VERIFY_HANDLE(hbuffer); + RTC_ENTER_DEVICE(hbuffer); buffer->refInc(); RTC_CATCH_END2(buffer); } @@ -152,6 +210,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcReleaseBuffer); RTC_VERIFY_HANDLE(hbuffer); + RTC_ENTER_DEVICE(hbuffer); buffer->refDec(); RTC_CATCH_END2(buffer); } @@ -161,6 +220,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcNewScene); RTC_VERIFY_HANDLE(hdevice); + RTC_ENTER_DEVICE(hdevice); Scene* scene = new Scene((Device*)hdevice); return (RTCScene) scene->refInc(); RTC_CATCH_END((Device*)hdevice); @@ -184,6 +244,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetSceneProgressMonitorFunction); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); Lock lock(g_mutex); scene->setProgressMonitorFunction(progress,ptr); RTC_CATCH_END2(scene); @@ -195,13 +256,18 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetSceneBuildQuality); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); + // -- GODOT start -- + // if (quality != RTC_BUILD_QUALITY_LOW && + // quality != RTC_BUILD_QUALITY_MEDIUM && + // quality != RTC_BUILD_QUALITY_HIGH) + // throw std::runtime_error("invalid build quality"); if (quality != RTC_BUILD_QUALITY_LOW && quality != RTC_BUILD_QUALITY_MEDIUM && - quality != RTC_BUILD_QUALITY_HIGH) - // -- GODOT start -- - // throw std::runtime_error("invalid build quality"); + quality != RTC_BUILD_QUALITY_HIGH) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- scene->setBuildQuality(quality); RTC_CATCH_END2(scene); } @@ -212,6 +278,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetSceneFlags); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); scene->setSceneFlags(flags); RTC_CATCH_END2(scene); } @@ -222,6 +289,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetSceneFlags); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); return scene->getSceneFlags(); RTC_CATCH_END2(scene); return RTC_SCENE_FLAG_NONE; @@ -233,6 +301,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcCommitScene); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); scene->commit(false); RTC_CATCH_END2(scene); } @@ -243,6 +312,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcJoinCommitScene); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); scene->commit(true); RTC_CATCH_END2(scene); } @@ -253,6 +323,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetSceneBounds); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); BBox3fa bounds = scene->bounds.bounds(); bounds_o->lower_x = bounds.lower.x; @@ -272,6 +343,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetSceneBounds); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); if (bounds_o == nullptr) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"invalid destination pointer"); if (scene->isModified()) @@ -447,7 +519,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_END2_FALSE(scene); } - RTC_API void rtcIntersect1 (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit* rayhit) + RTC_API void rtcIntersect1 (RTCScene hscene, RTCRayHit* rayhit, RTCIntersectArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -458,7 +530,21 @@ RTC_NAMESPACE_BEGIN; if (((size_t)rayhit) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes"); #endif STAT3(normal.travs,1,1,1); - IntersectContext context(scene,user_context); + + RTCIntersectArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitIntersectArguments(&defaultArgs); + args = &defaultArgs; + } + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + scene->intersectors.intersect(*rayhit,&context); #if defined(DEBUG) ((RayHit*)rayhit)->verifyHit(); @@ -466,7 +552,45 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_END2(scene); } - RTC_API void rtcIntersect4 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit4* rayhit) + RTC_API void rtcForwardIntersect1 (const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID) + { + rtcForwardIntersect1Ex(args, hscene, iray_, instID, 0); + } + + RTC_API void rtcForwardIntersect1Ex(const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardIntersect1Ex); +#if defined(DEBUG) + RTC_VERIFY_HANDLE(hscene); + if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); + if (((size_t)iray_) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes"); +#endif + + Ray* iray = (Ray*) iray_; + RayHit* oray = (RayHit*)args->rayhit; + RTCRayQueryContext* user_context = args->context; + const Vec3ff ray_org_tnear = oray->org; + const Vec3ff ray_dir_time = oray->dir; + oray->org = iray->org; + oray->dir = iray->dir; + STAT3(normal.travs,1,1,1); + + RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args; + RayQueryContext context(scene,user_context,iargs); + + instance_id_stack::push(user_context, instID, instPrimID); + scene->intersectors.intersect(*(RTCRayHit*)oray,&context); + instance_id_stack::pop(user_context); + + oray->org = ray_org_tnear; + oray->dir = ray_dir_time; + + RTC_CATCH_END2(scene); + } + + RTC_API void rtcIntersect4 (const int* valid, RTCScene hscene, RTCRayHit4* rayhit, RTCIntersectArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -481,23 +605,119 @@ RTC_NAMESPACE_BEGIN; STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;); STAT3(normal.travs,cnt,cnt,cnt); - IntersectContext context(scene,user_context); -#if !defined(EMBREE_RAY_PACKETS) - RayHit4* ray4 = (RayHit4*) rayhit; - for (size_t i=0; i<4; i++) { - if (!valid[i]) continue; - RayHit ray1; ray4->get(i,ray1); - scene->intersectors.intersect((RTCRayHit&)ray1,&context); - ray4->set(i,ray1); + RTCIntersectArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitIntersectArguments(&defaultArgs); + args = &defaultArgs; + } + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + + if (likely(scene->intersectors.intersector4)) + scene->intersectors.intersect4(valid,*rayhit,&context); + + else { + RayHit4* ray4 = (RayHit4*) rayhit; + for (size_t i=0; i<4; i++) { + if (!valid[i]) continue; + RayHit ray1; ray4->get(i,ray1); + scene->intersectors.intersect((RTCRayHit&)ray1,&context); + ray4->set(i,ray1); + } } -#else - scene->intersectors.intersect4(valid,*rayhit,&context); -#endif RTC_CATCH_END2(scene); } + + template void copy(float* dst, float* src); + + template<> + __forceinline void copy<4>(float* dst, float* src) { + vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0])); + } + + template<> + __forceinline void copy<8>(float* dst, float* src) { + vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0])); + vfloat4::storeu(&dst[4],vfloat4::loadu(&src[4])); + } + + template<> + __forceinline void copy<16>(float* dst, float* src) { + vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0])); + vfloat4::storeu(&dst[4],vfloat4::loadu(&src[4])); + vfloat4::storeu(&dst[8],vfloat4::loadu(&src[8])); + vfloat4::storeu(&dst[12],vfloat4::loadu(&src[12])); + } + + template + __forceinline void rtcForwardIntersectN(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTCRayHit* oray = (RTCRayHit*)args->rayhit; + RTCRayQueryContext* user_context = args->context; + + __aligned(16) float ray_org_x[N]; + __aligned(16) float ray_org_y[N]; + __aligned(16) float ray_org_z[N]; + __aligned(16) float ray_dir_x[N]; + __aligned(16) float ray_dir_y[N]; + __aligned(16) float ray_dir_z[N]; + + copy(ray_org_x,oray->ray.org_x); + copy(ray_org_y,oray->ray.org_y); + copy(ray_org_z,oray->ray.org_z); + copy(ray_dir_x,oray->ray.dir_x); + copy(ray_dir_y,oray->ray.dir_y); + copy(ray_dir_z,oray->ray.dir_z); + + copy(oray->ray.org_x,iray->org_x); + copy(oray->ray.org_y,iray->org_y); + copy(oray->ray.org_z,iray->org_z); + copy(oray->ray.dir_x,iray->dir_x); + copy(oray->ray.dir_y,iray->dir_y); + copy(oray->ray.dir_z,iray->dir_z); + + STAT(size_t cnt=0; for (size_t i=0; iargs; + RayQueryContext context(scene,user_context,iargs); + + instance_id_stack::push(user_context, instID, instPrimID); + scene->intersectors.intersect(valid,*oray,&context); + instance_id_stack::pop(user_context); + + copy(oray->ray.org_x,ray_org_x); + copy(oray->ray.org_y,ray_org_y); + copy(oray->ray.org_z,ray_org_z); + copy(oray->ray.dir_x,ray_dir_x); + copy(oray->ray.dir_y,ray_dir_y); + copy(oray->ray.dir_z,ray_dir_z); + } + + RTC_API void rtcForwardIntersect4(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID) + { + RTC_TRACE(rtcForwardIntersect4); + return rtcForwardIntersect4Ex(valid, args, hscene, iray, instID, 0); + } + + RTC_API void rtcForwardIntersect4Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardIntersect4); + rtcForwardIntersectN(valid,args,hscene,iray,instID,instPrimID); + RTC_CATCH_END2(scene); + } - RTC_API void rtcIntersect8 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit8* rayhit) + RTC_API void rtcIntersect8 (const int* valid, RTCScene hscene, RTCRayHit8* rayhit, RTCIntersectArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -512,25 +732,53 @@ RTC_NAMESPACE_BEGIN; STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;); STAT3(normal.travs,cnt,cnt,cnt); - IntersectContext context(scene,user_context); -#if !defined(EMBREE_RAY_PACKETS) - RayHit8* ray8 = (RayHit8*) rayhit; - for (size_t i=0; i<8; i++) { - if (!valid[i]) continue; - RayHit ray1; ray8->get(i,ray1); - scene->intersectors.intersect((RTCRayHit&)ray1,&context); - ray8->set(i,ray1); + RTCIntersectArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitIntersectArguments(&defaultArgs); + args = &defaultArgs; } -#else - if (likely(scene->intersectors.intersector8)) + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + + if (likely(scene->intersectors.intersector8)) scene->intersectors.intersect8(valid,*rayhit,&context); + else - scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,8,1,sizeof(RTCRayHit8),&context); -#endif + { + RayHit8* ray8 = (RayHit8*) rayhit; + for (size_t i=0; i<8; i++) { + if (!valid[i]) continue; + RayHit ray1; ray8->get(i,ray1); + scene->intersectors.intersect((RTCRayHit&)ray1,&context); + ray8->set(i,ray1); + } + } + RTC_CATCH_END2(scene); } - - RTC_API void rtcIntersect16 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit16* rayhit) + + RTC_API void rtcForwardIntersect8(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID) + { + RTC_TRACE(rtcForwardIntersect8); + return rtcForwardIntersect8Ex(valid, args, hscene, iray, instID, 0); + } + + RTC_API void rtcForwardIntersect8Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardIntersect8Ex); + rtcForwardIntersectN(valid,args,hscene,iray,instID,instPrimID); + RTC_CATCH_END2(scene); + } + + RTC_API void rtcIntersect16 (const int* valid, RTCScene hscene, RTCRayHit16* rayhit, RTCIntersectArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -545,163 +793,52 @@ RTC_NAMESPACE_BEGIN; STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;); STAT3(normal.travs,cnt,cnt,cnt); - IntersectContext context(scene,user_context); -#if !defined(EMBREE_RAY_PACKETS) - RayHit16* ray16 = (RayHit16*) rayhit; - for (size_t i=0; i<16; i++) { - if (!valid[i]) continue; - RayHit ray1; ray16->get(i,ray1); - scene->intersectors.intersect((RTCRayHit&)ray1,&context); - ray16->set(i,ray1); + RTCIntersectArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitIntersectArguments(&defaultArgs); + args = &defaultArgs; } -#else + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + if (likely(scene->intersectors.intersector16)) scene->intersectors.intersect16(valid,*rayhit,&context); - else - scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,16,1,sizeof(RTCRayHit16),&context); -#endif - RTC_CATCH_END2(scene); - } - RTC_API void rtcIntersect1M (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit* rayhit, unsigned int M, size_t byteStride) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcIntersect1M); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)rayhit ) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes"); -#endif - STAT3(normal.travs,M,M,M); - IntersectContext context(scene,user_context); - - /* fast codepath for single rays */ - if (likely(M == 1)) { - if (likely(rayhit->ray.tnear <= rayhit->ray.tfar)) - scene->intersectors.intersect(*rayhit,&context); - } - - /* codepath for streams */ else { - scene->device->rayStreamFilters.intersectAOS(scene,rayhit,M,byteStride,&context); - } -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect1M not supported"); -#endif - RTC_CATCH_END2(scene); - } - - RTC_API void rtcIntersect1Mp (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit** rn, unsigned int M) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcIntersect1Mp); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)rn) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes"); -#endif - STAT3(normal.travs,M,M,M); - IntersectContext context(scene,user_context); - - /* fast codepath for single rays */ - if (likely(M == 1)) { - if (likely(rn[0]->ray.tnear <= rn[0]->ray.tfar)) - scene->intersectors.intersect(*rn[0],&context); - } - - /* codepath for streams */ - else { - scene->device->rayStreamFilters.intersectAOP(scene,rn,M,&context); - } -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect1Mp not supported"); -#endif - RTC_CATCH_END2(scene); - } - - RTC_API void rtcIntersectNM (RTCScene hscene, RTCIntersectContext* user_context, struct RTCRayHitN* rayhit, unsigned int N, unsigned int M, size_t byteStride) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcIntersectNM); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)rayhit) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes"); -#endif - STAT3(normal.travs,N*M,N*M,N*M); - IntersectContext context(scene,user_context); - - /* code path for single ray streams */ - if (likely(N == 1)) - { - /* fast code path for streams of size 1 */ - if (likely(M == 1)) { - if (likely(((RTCRayHit*)rayhit)->ray.tnear <= ((RTCRayHit*)rayhit)->ray.tfar)) - scene->intersectors.intersect(*(RTCRayHit*)rayhit,&context); - } - /* normal codepath for single ray streams */ - else { - scene->device->rayStreamFilters.intersectAOS(scene,(RTCRayHit*)rayhit,M,byteStride,&context); + RayHit16* ray16 = (RayHit16*) rayhit; + for (size_t i=0; i<16; i++) { + if (!valid[i]) continue; + RayHit ray1; ray16->get(i,ray1); + scene->intersectors.intersect((RTCRayHit&)ray1,&context); + ray16->set(i,ray1); } } - /* code path for ray packet streams */ - else { - scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,N,M,byteStride,&context); - } -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersectNM not supported"); -#endif + RTC_CATCH_END2(scene); } - RTC_API void rtcIntersectNp (RTCScene hscene, RTCIntersectContext* user_context, const RTCRayHitNp* rayhit, unsigned int N) + RTC_API void rtcForwardIntersect16(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID) + { + RTC_TRACE(rtcForwardIntersect16); + return rtcForwardIntersect16Ex(valid, args, hscene, iray, instID, 0); + } + + RTC_API void rtcForwardIntersect16Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID, unsigned int instPrimID) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; - RTC_TRACE(rtcIntersectNp); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)rayhit->ray.org_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_x not aligned to 4 bytes"); - if (((size_t)rayhit->ray.org_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_y not aligned to 4 bytes"); - if (((size_t)rayhit->ray.org_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_z not aligned to 4 bytes"); - if (((size_t)rayhit->ray.dir_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_x not aligned to 4 bytes"); - if (((size_t)rayhit->ray.dir_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_y not aligned to 4 bytes"); - if (((size_t)rayhit->ray.dir_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_z not aligned to 4 bytes"); - if (((size_t)rayhit->ray.tnear ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_x not aligned to 4 bytes"); - if (((size_t)rayhit->ray.tfar ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.tnear not aligned to 4 bytes"); - if (((size_t)rayhit->ray.time ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.time not aligned to 4 bytes"); - if (((size_t)rayhit->ray.mask ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.mask not aligned to 4 bytes"); - if (((size_t)rayhit->hit.Ng_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_x not aligned to 4 bytes"); - if (((size_t)rayhit->hit.Ng_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_y not aligned to 4 bytes"); - if (((size_t)rayhit->hit.Ng_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_z not aligned to 4 bytes"); - if (((size_t)rayhit->hit.u ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.u not aligned to 4 bytes"); - if (((size_t)rayhit->hit.v ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.v not aligned to 4 bytes"); - if (((size_t)rayhit->hit.geomID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.geomID not aligned to 4 bytes"); - if (((size_t)rayhit->hit.primID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.primID not aligned to 4 bytes"); - if (((size_t)rayhit->hit.instID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.instID not aligned to 4 bytes"); -#endif - STAT3(normal.travs,N,N,N); - IntersectContext context(scene,user_context); - scene->device->rayStreamFilters.intersectSOP(scene,rayhit,N,&context); -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersectNp not supported"); -#endif + RTC_TRACE(rtcForwardIntersect16Ex); + rtcForwardIntersectN(valid,args,hscene,iray,instID,instPrimID); RTC_CATCH_END2(scene); } - - RTC_API void rtcOccluded1 (RTCScene hscene, RTCIntersectContext* user_context, RTCRay* ray) + + RTC_API void rtcOccluded1 (RTCScene hscene, RTCRay* ray, RTCOccludedArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -712,12 +849,65 @@ RTC_NAMESPACE_BEGIN; if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes"); #endif - IntersectContext context(scene,user_context); + + RTCOccludedArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitOccludedArguments(&defaultArgs); + args = &defaultArgs; + } + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + scene->intersectors.occluded(*ray,&context); RTC_CATCH_END2(scene); } - - RTC_API void rtcOccluded4 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay4* ray) + + RTC_API void rtcForwardOccluded1 (const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID) + { + RTC_TRACE(rtcForwardOccluded1); + return rtcForwardOccluded1Ex(args, hscene, iray_, instID, 0); + } + + RTC_API void rtcForwardOccluded1Ex(const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardOccluded1Ex); + STAT3(shadow.travs,1,1,1); +#if defined(DEBUG) + RTC_VERIFY_HANDLE(hscene); + if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); + if (((size_t)iray_) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes"); +#endif + + Ray* iray = (Ray*)iray_; + Ray* oray = (Ray*)args->ray; + RTCRayQueryContext* user_context = args->context; + const Vec3ff ray_org_tnear = oray->org; + const Vec3ff ray_dir_time = oray->dir; + oray->org = iray->org; + oray->dir = iray->dir; + + RTCIntersectArguments* iargs = ((OccludedFunctionNArguments*) args)->args; + RayQueryContext context(scene,user_context,iargs); + + instance_id_stack::push(user_context, instID, instPrimID); + scene->intersectors.occluded(*(RTCRay*)oray,&context); + instance_id_stack::pop(user_context); + + oray->org = ray_org_tnear; + oray->dir = ray_dir_time; + + RTC_CATCH_END2(scene); + } + + RTC_API void rtcOccluded4 (const int* valid, RTCScene hscene, RTCRay4* ray, RTCOccludedArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -732,23 +922,98 @@ RTC_NAMESPACE_BEGIN; STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;); STAT3(shadow.travs,cnt,cnt,cnt); - IntersectContext context(scene,user_context); -#if !defined(EMBREE_RAY_PACKETS) - RayHit4* ray4 = (RayHit4*) ray; - for (size_t i=0; i<4; i++) { - if (!valid[i]) continue; - RayHit ray1; ray4->get(i,ray1); - scene->intersectors.occluded((RTCRay&)ray1,&context); - ray4->geomID[i] = ray1.geomID; + RTCOccludedArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitOccludedArguments(&defaultArgs); + args = &defaultArgs; + } + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + + if (likely(scene->intersectors.intersector4)) + scene->intersectors.occluded4(valid,*ray,&context); + + else { + RayHit4* ray4 = (RayHit4*) ray; + for (size_t i=0; i<4; i++) { + if (!valid[i]) continue; + RayHit ray1; ray4->get(i,ray1); + scene->intersectors.occluded((RTCRay&)ray1,&context); + ray4->geomID[i] = ray1.geomID; + } } -#else - scene->intersectors.occluded4(valid,*ray,&context); -#endif RTC_CATCH_END2(scene); } + + template + __forceinline void rtcForwardOccludedN (const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTCRay* oray = (RTCRay*)args->ray; + RTCRayQueryContext* user_context = args->context; + + __aligned(16) float ray_org_x[N]; + __aligned(16) float ray_org_y[N]; + __aligned(16) float ray_org_z[N]; + __aligned(16) float ray_dir_x[N]; + __aligned(16) float ray_dir_y[N]; + __aligned(16) float ray_dir_z[N]; + + copy(ray_org_x,oray->org_x); + copy(ray_org_y,oray->org_y); + copy(ray_org_z,oray->org_z); + copy(ray_dir_x,oray->dir_x); + copy(ray_dir_y,oray->dir_y); + copy(ray_dir_z,oray->dir_z); + + copy(oray->org_x,iray->org_x); + copy(oray->org_y,iray->org_y); + copy(oray->org_z,iray->org_z); + copy(oray->dir_x,iray->dir_x); + copy(oray->dir_y,iray->dir_y); + copy(oray->dir_z,iray->dir_z); + + STAT(size_t cnt=0; for (size_t i=0; iargs; + RayQueryContext context(scene,user_context,iargs); + + instance_id_stack::push(user_context, instID, instPrimID); + scene->intersectors.occluded(valid,*oray,&context); + instance_id_stack::pop(user_context); + + copy(oray->org_x,ray_org_x); + copy(oray->org_y,ray_org_y); + copy(oray->org_z,ray_org_z); + copy(oray->dir_x,ray_dir_x); + copy(oray->dir_y,ray_dir_y); + copy(oray->dir_z,ray_dir_z); + } + + RTC_API void rtcForwardOccluded4(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID) + { + RTC_TRACE(rtcForwardOccluded4); + return rtcForwardOccluded4Ex(valid, args, hscene, iray, instID, 0); + } + + RTC_API void rtcForwardOccluded4Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardOccluded4); + rtcForwardOccludedN(valid,args,hscene,iray,instID,instPrimID); + RTC_CATCH_END2(scene); + } - RTC_API void rtcOccluded8 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay8* ray) + RTC_API void rtcOccluded8 (const int* valid, RTCScene hscene, RTCRay8* ray, RTCOccludedArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -763,26 +1028,52 @@ RTC_NAMESPACE_BEGIN; STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;); STAT3(shadow.travs,cnt,cnt,cnt); - IntersectContext context(scene,user_context); -#if !defined(EMBREE_RAY_PACKETS) - RayHit8* ray8 = (RayHit8*) ray; - for (size_t i=0; i<8; i++) { - if (!valid[i]) continue; - RayHit ray1; ray8->get(i,ray1); - scene->intersectors.occluded((RTCRay&)ray1,&context); - ray8->set(i,ray1); + RTCOccludedArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitOccludedArguments(&defaultArgs); + args = &defaultArgs; } -#else + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + if (likely(scene->intersectors.intersector8)) scene->intersectors.occluded8(valid,*ray,&context); - else - scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,8,1,sizeof(RTCRay8),&context); -#endif + + else { + RayHit8* ray8 = (RayHit8*) ray; + for (size_t i=0; i<8; i++) { + if (!valid[i]) continue; + RayHit ray1; ray8->get(i,ray1); + scene->intersectors.occluded((RTCRay&)ray1,&context); + ray8->set(i,ray1); + } + } RTC_CATCH_END2(scene); } - - RTC_API void rtcOccluded16 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay16* ray) + + RTC_API void rtcForwardOccluded8(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID) + { + RTC_TRACE(rtcForwardOccluded8); + return rtcForwardOccluded8Ex(valid, args, hscene, iray, instID, 0); + } + + RTC_API void rtcForwardOccluded8Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardOccluded8Ex); + rtcForwardOccludedN(valid, args, hscene, iray, instID, instPrimID); + RTC_CATCH_END2(scene); + } + + RTC_API void rtcOccluded16 (const int* valid, RTCScene hscene, RTCRay16* ray, RTCOccludedArguments* args) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; @@ -797,159 +1088,58 @@ RTC_NAMESPACE_BEGIN; STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;); STAT3(shadow.travs,cnt,cnt,cnt); - IntersectContext context(scene,user_context); -#if !defined(EMBREE_RAY_PACKETS) - RayHit16* ray16 = (RayHit16*) ray; - for (size_t i=0; i<16; i++) { - if (!valid[i]) continue; - RayHit ray1; ray16->get(i,ray1); - scene->intersectors.occluded((RTCRay&)ray1,&context); - ray16->set(i,ray1); + RTCOccludedArguments defaultArgs; + if (unlikely(args == nullptr)) { + rtcInitOccludedArguments(&defaultArgs); + args = &defaultArgs; } -#else + RTCRayQueryContext* user_context = args->context; + + RTCRayQueryContext defaultContext; + if (unlikely(user_context == nullptr)) { + rtcInitRayQueryContext(&defaultContext); + user_context = &defaultContext; + } + RayQueryContext context(scene,user_context,args); + if (likely(scene->intersectors.intersector16)) scene->intersectors.occluded16(valid,*ray,&context); - else - scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,16,1,sizeof(RTCRay16),&context); -#endif + else { + RayHit16* ray16 = (RayHit16*) ray; + for (size_t i=0; i<16; i++) { + if (!valid[i]) continue; + RayHit ray1; ray16->get(i,ray1); + scene->intersectors.occluded((RTCRay&)ray1,&context); + ray16->set(i,ray1); + } + } + + RTC_CATCH_END2(scene); + } + + RTC_API void rtcForwardOccluded16(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID) + { + RTC_TRACE(rtcForwardOccluded16); + return rtcForwardOccluded16Ex(valid, args, hscene, iray, instID, 0); + } + + RTC_API void rtcForwardOccluded16Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID, unsigned int instPrimID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcForwardOccluded16Ex); + rtcForwardOccludedN(valid, args, hscene, iray, instID, instPrimID); RTC_CATCH_END2(scene); } - RTC_API void rtcOccluded1M(RTCScene hscene, RTCIntersectContext* user_context, RTCRay* ray, unsigned int M, size_t byteStride) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcOccluded1M); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes"); -#endif - STAT3(shadow.travs,M,M,M); - IntersectContext context(scene,user_context); - /* fast codepath for streams of size 1 */ - if (likely(M == 1)) { - if (likely(ray->tnear <= ray->tfar)) - scene->intersectors.occluded (*ray,&context); - } - /* codepath for normal streams */ - else { - scene->device->rayStreamFilters.occludedAOS(scene,ray,M,byteStride,&context); - } -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccluded1M not supported"); -#endif - RTC_CATCH_END2(scene); - } - - RTC_API void rtcOccluded1Mp(RTCScene hscene, RTCIntersectContext* user_context, RTCRay** ray, unsigned int M) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcOccluded1Mp); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes"); -#endif - STAT3(shadow.travs,M,M,M); - IntersectContext context(scene,user_context); - - /* fast codepath for streams of size 1 */ - if (likely(M == 1)) { - if (likely(ray[0]->tnear <= ray[0]->tfar)) - scene->intersectors.occluded (*ray[0],&context); - } - /* codepath for normal streams */ - else { - scene->device->rayStreamFilters.occludedAOP(scene,ray,M,&context); - } -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccluded1Mp not supported"); -#endif - RTC_CATCH_END2(scene); - } - - RTC_API void rtcOccludedNM(RTCScene hscene, RTCIntersectContext* user_context, RTCRayN* ray, unsigned int N, unsigned int M, size_t byteStride) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcOccludedNM); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (byteStride < sizeof(RTCRayHit)) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"byteStride too small"); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes"); -#endif - STAT3(shadow.travs,N*M,N*N,N*N); - IntersectContext context(scene,user_context); - - /* codepath for single rays */ - if (likely(N == 1)) - { - /* fast path for streams of size 1 */ - if (likely(M == 1)) { - if (likely(((RTCRay*)ray)->tnear <= ((RTCRay*)ray)->tfar)) - scene->intersectors.occluded (*(RTCRay*)ray,&context); - } - /* codepath for normal ray streams */ - else { - scene->device->rayStreamFilters.occludedAOS(scene,(RTCRay*)ray,M,byteStride,&context); - } - } - /* code path for ray packet streams */ - else { - scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,N,M,byteStride,&context); - } -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccludedNM not supported"); -#endif - RTC_CATCH_END2(scene); - } - - RTC_API void rtcOccludedNp(RTCScene hscene, RTCIntersectContext* user_context, const RTCRayNp* ray, unsigned int N) - { - Scene* scene = (Scene*) hscene; - RTC_CATCH_BEGIN; - RTC_TRACE(rtcOccludedNp); - -#if defined (EMBREE_RAY_PACKETS) -#if defined(DEBUG) - RTC_VERIFY_HANDLE(hscene); - if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); - if (((size_t)ray->org_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_x not aligned to 4 bytes"); - if (((size_t)ray->org_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_y not aligned to 4 bytes"); - if (((size_t)ray->org_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_z not aligned to 4 bytes"); - if (((size_t)ray->dir_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_x not aligned to 4 bytes"); - if (((size_t)ray->dir_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_y not aligned to 4 bytes"); - if (((size_t)ray->dir_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_z not aligned to 4 bytes"); - if (((size_t)ray->tnear ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_x not aligned to 4 bytes"); - if (((size_t)ray->tfar ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "tnear not aligned to 4 bytes"); - if (((size_t)ray->time ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "time not aligned to 4 bytes"); - if (((size_t)ray->mask ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 4 bytes"); -#endif - STAT3(shadow.travs,N,N,N); - IntersectContext context(scene,user_context); - scene->device->rayStreamFilters.occludedSOP(scene,ray,N,&context); -#else - throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccludedNp not supported"); -#endif - RTC_CATCH_END2(scene); - } - RTC_API void rtcRetainScene (RTCScene hscene) { Scene* scene = (Scene*) hscene; RTC_CATCH_BEGIN; RTC_TRACE(rtcRetainScene); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); scene->refInc(); RTC_CATCH_END2(scene); } @@ -960,6 +1150,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcReleaseScene); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); scene->refDec(); RTC_CATCH_END2(scene); } @@ -972,10 +1163,23 @@ RTC_NAMESPACE_BEGIN; RTC_TRACE(rtcSetGeometryInstancedScene); RTC_VERIFY_HANDLE(hgeometry); RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hgeometry); geometry->setInstancedScene(scene); RTC_CATCH_END2(geometry); } + RTC_API void rtcSetGeometryInstancedScenes(RTCGeometry hgeometry, RTCScene* scenes, size_t numScenes) + { + Geometry* geometry = (Geometry*) hgeometry; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcSetGeometryInstancedScene); + RTC_VERIFY_HANDLE(hgeometry); + RTC_VERIFY_HANDLE(scenes); + RTC_ENTER_DEVICE(hgeometry); + geometry->setInstancedScenes(scenes, numScenes); + RTC_CATCH_END2(geometry); + } + AffineSpace3fa loadTransform(RTCFormat format, const float* xfm) { AffineSpace3fa space = one; @@ -1009,43 +1213,14 @@ RTC_NAMESPACE_BEGIN; return space; } - void storeTransform(const AffineSpace3fa& space, RTCFormat format, float* xfm) - { - switch (format) - { - case RTC_FORMAT_FLOAT3X4_ROW_MAJOR: - xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vy.x; xfm[ 2] = space.l.vz.x; xfm[ 3] = space.p.x; - xfm[ 4] = space.l.vx.y; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vz.y; xfm[ 7] = space.p.y; - xfm[ 8] = space.l.vx.z; xfm[ 9] = space.l.vy.z; xfm[10] = space.l.vz.z; xfm[11] = space.p.z; - break; - - case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR: - xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; - xfm[ 3] = space.l.vy.x; xfm[ 4] = space.l.vy.y; xfm[ 5] = space.l.vy.z; - xfm[ 6] = space.l.vz.x; xfm[ 7] = space.l.vz.y; xfm[ 8] = space.l.vz.z; - xfm[ 9] = space.p.x; xfm[10] = space.p.y; xfm[11] = space.p.z; - break; - - case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR: - xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; xfm[ 3] = 0.f; - xfm[ 4] = space.l.vy.x; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vy.z; xfm[ 7] = 0.f; - xfm[ 8] = space.l.vz.x; xfm[ 9] = space.l.vz.y; xfm[10] = space.l.vz.z; xfm[11] = 0.f; - xfm[12] = space.p.x; xfm[13] = space.p.y; xfm[14] = space.p.z; xfm[15] = 1.f; - break; - - default: - throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format"); - break; - } - } - - RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeStep, RTCFormat format, const void* xfm) +RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeStep, RTCFormat format, const void* xfm) { Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryTransform); RTC_VERIFY_HANDLE(hgeometry); RTC_VERIFY_HANDLE(xfm); + RTC_ENTER_DEVICE(hgeometry); const AffineSpace3fa transform = loadTransform(format, (const float*)xfm); geometry->setTransform(transform, timeStep); RTC_CATCH_END2(geometry); @@ -1058,6 +1233,7 @@ RTC_NAMESPACE_BEGIN; RTC_TRACE(rtcSetGeometryTransformQuaternion); RTC_VERIFY_HANDLE(hgeometry); RTC_VERIFY_HANDLE(qd); + RTC_ENTER_DEVICE(hgeometry); AffineSpace3fx transform; transform.l.vx.x = qd->scale_x; @@ -1090,21 +1266,46 @@ RTC_NAMESPACE_BEGIN; Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryTransform); + //RTC_ENTER_DEVICE(hgeometry); // no allocation required const AffineSpace3fa transform = geometry->getTransform(time); storeTransform(transform, format, (float*)xfm); RTC_CATCH_END2(geometry); } - RTC_API void rtcFilterIntersection(const struct RTCIntersectFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args) + RTC_API void rtcGetGeometryTransformEx(RTCGeometry hgeometry, unsigned int instPrimID, float time, RTCFormat format, void* xfm) { - IntersectFunctionNArguments* args = (IntersectFunctionNArguments*) args_i; - isa::reportIntersection1(args, filter_args); + Geometry* geometry = (Geometry*) hgeometry; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcGetGeometryTransformEx); + //RTC_ENTER_DEVICE(hgeometry); // no allocation required + const AffineSpace3fa transform = geometry->getTransform(instPrimID, time); + storeTransform(transform, format, (float*)xfm); + RTC_CATCH_END2(geometry); } - RTC_API void rtcFilterOcclusion(const struct RTCOccludedFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args) + RTC_API void rtcGetGeometryTransformFromScene(RTCScene hscene, unsigned int geomID, float time, RTCFormat format, void* xfm) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcGetGeometryTransformFromScene); + //RTC_ENTER_DEVICE(hscene); // no allocation required + const AffineSpace3fa transform = scene->get(geomID)->getTransform(time); + storeTransform(transform, format, (float*)xfm); + RTC_CATCH_END2(scene); + } + + RTC_API void rtcInvokeIntersectFilterFromGeometry(const struct RTCIntersectFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args) + { + IntersectFunctionNArguments* args = (IntersectFunctionNArguments*) args_i; + if (args->geometry->intersectionFilterN) + args->geometry->intersectionFilterN(filter_args); + } + + RTC_API void rtcInvokeOccludedFilterFromGeometry(const struct RTCOccludedFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args) { OccludedFunctionNArguments* args = (OccludedFunctionNArguments*) args_i; - isa::reportOcclusion1(args,filter_args); + if (args->geometry->occlusionFilterN) + args->geometry->occlusionFilterN(filter_args); } RTC_API RTCGeometry rtcNewGeometry (RTCDevice hdevice, RTCGeometryType type) @@ -1112,6 +1313,7 @@ RTC_NAMESPACE_BEGIN; Device* device = (Device*) hdevice; RTC_CATCH_BEGIN; RTC_TRACE(rtcNewGeometry); + RTC_ENTER_DEVICE(hdevice); RTC_VERIFY_HANDLE(hdevice); switch (type) @@ -1262,6 +1464,18 @@ RTC_NAMESPACE_BEGIN; #endif } + case RTC_GEOMETRY_TYPE_INSTANCE_ARRAY: + { +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + createInstanceArrayTy createInstanceArray = nullptr; + SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createInstanceArray); + Geometry* geom = createInstanceArray(device); + return (RTCGeometry) geom->refInc(); +#else + throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_INSTANCE_ARRAY is not supported"); +#endif + } + case RTC_GEOMETRY_TYPE_GRID: { #if defined(EMBREE_GEOMETRY_GRID) @@ -1288,6 +1502,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryUserPrimitiveCount); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); if (unlikely(geometry->getType() != Geometry::GTY_USER_GEOMETRY)) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation only allowed for user geometries"); @@ -1302,6 +1517,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryTimeStepCount); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); if (timeStepCount > RTC_MAX_TIME_STEP_COUNT) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"number of time steps is out of range"); @@ -1316,6 +1532,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryTimeRange); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); if (startTime > endTime) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"startTime has to be smaller or equal to the endTime"); @@ -1330,6 +1547,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryVertexAttributeCount); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setVertexAttributeCount(N); RTC_CATCH_END2(geometry); } @@ -1340,6 +1558,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryTopologyCount); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setTopologyCount(N); RTC_CATCH_END2(geometry); } @@ -1350,14 +1569,20 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryBuildQuality); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); + // -- GODOT start -- + // if (quality != RTC_BUILD_QUALITY_LOW && + // quality != RTC_BUILD_QUALITY_MEDIUM && + // quality != RTC_BUILD_QUALITY_HIGH && + // quality != RTC_BUILD_QUALITY_REFIT) + // throw std::runtime_error("invalid build quality"); if (quality != RTC_BUILD_QUALITY_LOW && quality != RTC_BUILD_QUALITY_MEDIUM && quality != RTC_BUILD_QUALITY_HIGH && - quality != RTC_BUILD_QUALITY_REFIT) - // -- GODOT start -- - // throw std::runtime_error("invalid build quality"); + quality != RTC_BUILD_QUALITY_REFIT) { abort(); - // -- GODOT end -- + } + // -- GODOT end -- geometry->setBuildQuality(quality); RTC_CATCH_END2(geometry); } @@ -1383,6 +1608,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryMask); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setMask(mask); RTC_CATCH_END2(geometry); } @@ -1393,6 +1619,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometrySubdivisionMode); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setSubdivisionMode(topologyID,mode); RTC_CATCH_END2(geometry); } @@ -1403,6 +1630,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryVertexAttributeTopology); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setVertexAttributeTopology(vertexAttributeID, topologyID); RTC_CATCH_END2(geometry); } @@ -1415,6 +1643,7 @@ RTC_NAMESPACE_BEGIN; RTC_TRACE(rtcSetGeometryBuffer); RTC_VERIFY_HANDLE(hgeometry); RTC_VERIFY_HANDLE(hbuffer); + RTC_ENTER_DEVICE(hgeometry); if (geometry->device != buffer->device) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices"); @@ -1432,10 +1661,11 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetSharedGeometryBuffer); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); if (itemCount > 0xFFFFFFFFu) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large"); - + Ref buffer = new Buffer(geometry->device, itemCount*byteStride, (char*)ptr + byteOffset); geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount); RTC_CATCH_END2(geometry); @@ -1447,6 +1677,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetNewGeometryBuffer); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); if (itemCount > 0xFFFFFFFFu) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large"); @@ -1469,6 +1700,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryBufferData); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); return geometry->getBuffer(type, slot); RTC_CATCH_END2(geometry); return nullptr; @@ -1480,6 +1712,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcEnableGeometry); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->enable(); RTC_CATCH_END2(geometry); } @@ -1490,6 +1723,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcUpdateGeometryBuffer); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->updateBuffer(type, slot); RTC_CATCH_END2(geometry); } @@ -1500,6 +1734,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcDisableGeometry); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->disable(); RTC_CATCH_END2(geometry); } @@ -1510,6 +1745,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryTessellationRate); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setTessellationRate(tessellationRate); RTC_CATCH_END2(geometry); } @@ -1520,6 +1756,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryUserData); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setUserData(ptr); RTC_CATCH_END2(geometry); } @@ -1530,17 +1767,34 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryUserData); RTC_VERIFY_HANDLE(hgeometry); + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons ! return geometry->getUserData(); RTC_CATCH_END2(geometry); return nullptr; } + RTC_API void* rtcGetGeometryUserDataFromScene (RTCScene hscene, unsigned int geomID) + { + Scene* scene = (Scene*) hscene; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcGetGeometryUserDataFromScene); +#if defined(DEBUG) + RTC_VERIFY_HANDLE(hscene); + RTC_VERIFY_GEOMID(geomID); +#endif + //RTC_ENTER_DEVICE(hscene); // do not enable for performance reasons + return scene->get(geomID)->getUserData(); + RTC_CATCH_END2(scene); + return nullptr; + } + RTC_API void rtcSetGeometryBoundsFunction (RTCGeometry hgeometry, RTCBoundsFunction bounds, void* userPtr) { Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryBoundsFunction); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setBoundsFunction(bounds,userPtr); RTC_CATCH_END2(geometry); } @@ -1551,6 +1805,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryDisplacementFunction); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setDisplacementFunction(displacement); RTC_CATCH_END2(geometry); } @@ -1561,6 +1816,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryIntersectFunction); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setIntersectFunctionN(intersect); RTC_CATCH_END2(geometry); } @@ -1571,6 +1827,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryPointQueryFunction); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setPointQueryFunction(pointQuery); RTC_CATCH_END2(geometry); } @@ -1580,6 +1837,7 @@ RTC_NAMESPACE_BEGIN; Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryFirstHalfEdge); + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons return geometry->getFirstHalfEdge(faceID); RTC_CATCH_END2(geometry); return -1; @@ -1590,6 +1848,7 @@ RTC_NAMESPACE_BEGIN; Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryFace); + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons return geometry->getFace(edgeID); RTC_CATCH_END2(geometry); return -1; @@ -1600,6 +1859,7 @@ RTC_NAMESPACE_BEGIN; Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryNextHalfEdge); + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons return geometry->getNextHalfEdge(edgeID); RTC_CATCH_END2(geometry); return -1; @@ -1610,6 +1870,7 @@ RTC_NAMESPACE_BEGIN; Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryPreviousHalfEdge); + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons return geometry->getPreviousHalfEdge(edgeID); RTC_CATCH_END2(geometry); return -1; @@ -1620,6 +1881,7 @@ RTC_NAMESPACE_BEGIN; Geometry* geometry = (Geometry*) hgeometry; RTC_CATCH_BEGIN; RTC_TRACE(rtcGetGeometryOppositeHalfEdge); + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons return geometry->getOppositeHalfEdge(topologyID,edgeID); RTC_CATCH_END2(geometry); return -1; @@ -1631,6 +1893,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetOccludedFunctionN); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setOccludedFunctionN(occluded); RTC_CATCH_END2(geometry); } @@ -1641,6 +1904,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryIntersectFilterFunction); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setIntersectionFilterFunctionN(filter); RTC_CATCH_END2(geometry); } @@ -1651,10 +1915,22 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcSetGeometryOccludedFilterFunction); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->setOcclusionFilterFunctionN(filter); RTC_CATCH_END2(geometry); } + RTC_API void rtcSetGeometryEnableFilterFunctionFromArguments (RTCGeometry hgeometry, bool enable) + { + Geometry* geometry = (Geometry*) hgeometry; + RTC_CATCH_BEGIN; + RTC_TRACE(rtcSetGeometryEnableFilterFunctionFromArguments); + RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); + geometry->enableFilterFunctionFromArguments(enable); + RTC_CATCH_END2(geometry); + } + RTC_API void rtcInterpolate(const RTCInterpolateArguments* const args) { Geometry* geometry = (Geometry*) args->geometry; @@ -1663,6 +1939,7 @@ RTC_NAMESPACE_BEGIN; #if defined(DEBUG) RTC_VERIFY_HANDLE(args->geometry); #endif + //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons geometry->interpolate(args); RTC_CATCH_END2(geometry); } @@ -1675,6 +1952,7 @@ RTC_NAMESPACE_BEGIN; #if defined(DEBUG) RTC_VERIFY_HANDLE(args->geometry); #endif + // RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons geometry->interpolateN(args); RTC_CATCH_END2(geometry); } @@ -1685,6 +1963,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcCommitGeometry); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); return geometry->commit(); RTC_CATCH_END2(geometry); } @@ -1697,6 +1976,7 @@ RTC_NAMESPACE_BEGIN; RTC_TRACE(rtcAttachGeometry); RTC_VERIFY_HANDLE(hscene); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); if (scene->device != geometry->device) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices"); return scene->bind(RTC_INVALID_GEOMETRY_ID,geometry); @@ -1713,6 +1993,7 @@ RTC_NAMESPACE_BEGIN; RTC_VERIFY_HANDLE(hscene); RTC_VERIFY_HANDLE(hgeometry); RTC_VERIFY_GEOMID(geomID); + RTC_ENTER_DEVICE(hscene); if (scene->device != geometry->device) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices"); scene->bind(geomID,geometry); @@ -1726,6 +2007,7 @@ RTC_NAMESPACE_BEGIN; RTC_TRACE(rtcDetachGeometry); RTC_VERIFY_HANDLE(hscene); RTC_VERIFY_GEOMID(geomID); + RTC_ENTER_DEVICE(hscene); scene->detachGeometry(geomID); RTC_CATCH_END2(scene); } @@ -1736,6 +2018,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcRetainGeometry); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->refInc(); RTC_CATCH_END2(geometry); } @@ -1746,6 +2029,7 @@ RTC_NAMESPACE_BEGIN; RTC_CATCH_BEGIN; RTC_TRACE(rtcReleaseGeometry); RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); geometry->refDec(); RTC_CATCH_END2(geometry); } @@ -1759,6 +2043,7 @@ RTC_NAMESPACE_BEGIN; RTC_VERIFY_HANDLE(hscene); RTC_VERIFY_GEOMID(geomID); #endif + //RTC_ENTER_DEVICE(hscene); // do not enable for performance reasons return (RTCGeometry) scene->get(geomID); RTC_CATCH_END2(scene); return nullptr; diff --git a/thirdparty/embree/kernels/common/rtcore.h b/thirdparty/embree/kernels/common/rtcore.h index ac58a84d6f0..47526482c11 100644 --- a/thirdparty/embree/kernels/common/rtcore.h +++ b/thirdparty/embree/kernels/common/rtcore.h @@ -3,26 +3,14 @@ #pragma once -#include "../../include/embree3/rtcore.h" +#include "../../include/embree4/rtcore.h" RTC_NAMESPACE_USE namespace embree { /*! decoding of intersection flags */ - __forceinline bool isCoherent (RTCIntersectContextFlags flags) { return (flags & RTC_INTERSECT_CONTEXT_FLAG_COHERENT) == RTC_INTERSECT_CONTEXT_FLAG_COHERENT; } - __forceinline bool isIncoherent(RTCIntersectContextFlags flags) { return (flags & RTC_INTERSECT_CONTEXT_FLAG_COHERENT) == RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT; } - -#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8) -# define USE_TASK_ARENA 1 -#else -# define USE_TASK_ARENA 0 -#endif - -#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 9 -# define TASKING_TBB_USE_TASK_ISOLATION 1 -#else -# define TASKING_TBB_USE_TASK_ISOLATION 0 -#endif + __forceinline bool isCoherent (RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_COHERENT; } + __forceinline bool isIncoherent(RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_INCOHERENT; } /*! Macros used in the rtcore API implementation */ // -- GODOT start -- @@ -30,8 +18,8 @@ namespace embree #define RTC_CATCH_END(device) #define RTC_CATCH_END2(scene) #define RTC_CATCH_END2_FALSE(scene) return false; - #if 0 +// -- GODOT end -- #define RTC_CATCH_BEGIN try { #define RTC_CATCH_END(device) \ @@ -47,7 +35,7 @@ namespace embree #define RTC_CATCH_END2(scene) \ } catch (std::bad_alloc&) { \ - Device* device = scene ? scene->device : nullptr; \ + Device* device = scene ? scene->device : nullptr; \ Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \ } catch (rtcore_error& e) { \ Device* device = scene ? scene->device : nullptr; \ @@ -78,9 +66,9 @@ namespace embree Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ return false; \ } -#endif -// -- GODOT end -- +#endif + #define RTC_VERIFY_HANDLE(handle) \ if (handle == nullptr) { \ throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \ @@ -137,5 +125,38 @@ namespace embree // -- GODOT end -- #define RTC_BUILD_ARGUMENTS_HAS(settings,member) \ - (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member))) + (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member))) + + + inline void storeTransform(const AffineSpace3fa& space, RTCFormat format, float* xfm) + { + switch (format) + { + case RTC_FORMAT_FLOAT3X4_ROW_MAJOR: + xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vy.x; xfm[ 2] = space.l.vz.x; xfm[ 3] = space.p.x; + xfm[ 4] = space.l.vx.y; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vz.y; xfm[ 7] = space.p.y; + xfm[ 8] = space.l.vx.z; xfm[ 9] = space.l.vy.z; xfm[10] = space.l.vz.z; xfm[11] = space.p.z; + break; + + case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR: + xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; + xfm[ 3] = space.l.vy.x; xfm[ 4] = space.l.vy.y; xfm[ 5] = space.l.vy.z; + xfm[ 6] = space.l.vz.x; xfm[ 7] = space.l.vz.y; xfm[ 8] = space.l.vz.z; + xfm[ 9] = space.p.x; xfm[10] = space.p.y; xfm[11] = space.p.z; + break; + + case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR: + xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; xfm[ 3] = 0.f; + xfm[ 4] = space.l.vy.x; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vy.z; xfm[ 7] = 0.f; + xfm[ 8] = space.l.vz.x; xfm[ 9] = space.l.vz.y; xfm[10] = space.l.vz.z; xfm[11] = 0.f; + xfm[12] = space.p.x; xfm[13] = space.p.y; xfm[14] = space.p.z; xfm[15] = 1.f; + break; + + default: +#if !defined(__SYCL_DEVICE_ONLY__) + throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format"); +#endif + break; + } + } } diff --git a/thirdparty/embree/kernels/common/scene.cpp b/thirdparty/embree/kernels/common/scene.cpp index 65d31d0f81f..10cb3c4becb 100644 --- a/thirdparty/embree/kernels/common/scene.cpp +++ b/thirdparty/embree/kernels/common/scene.cpp @@ -3,12 +3,35 @@ #include "scene.h" +#include "../../common/tasking/taskscheduler.h" + #include "../bvh/bvh4_factory.h" #include "../bvh/bvh8_factory.h" + #include "../../common/algorithms/parallel_reduce.h" - + +#if defined(EMBREE_SYCL_SUPPORT) +# include "../sycl/rthwif_embree_builder.h" +#endif + + namespace embree { + + struct TaskGroup { + /*! global lock step task scheduler */ +#if defined(TASKING_INTERNAL) + MutexSys schedulerMutex; + Ref scheduler; +#elif defined(TASKING_TBB) && TASKING_TBB_USE_TASK_ISOLATION + tbb::isolated_task_group group; +#elif defined(TASKING_TBB) + tbb::task_group group; +#elif defined(TASKING_PPL) + concurrency::task_group group; +#endif + }; + /* error raising rtcIntersect and rtcOccluded functions */ void missing_rtcCommit() { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); } void invalid_rtcIntersect1() { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect and rtcOccluded not enabled"); } @@ -22,13 +45,20 @@ namespace embree flags_modified(true), enabled_geometry_types(0), scene_flags(RTC_SCENE_FLAG_NONE), quality_flags(RTC_BUILD_QUALITY_MEDIUM), - is_build(false), modified(true), + modified(true), + taskGroup(new TaskGroup()), progressInterface(this), progress_monitor_function(nullptr), progress_monitor_ptr(nullptr), progress_monitor_counter(0) { device->refInc(); intersectors = Accel::Intersectors(missing_rtcCommit); + /* use proper device and context for SYCL allocations */ +#if defined(EMBREE_SYCL_SUPPORT) + if (DeviceGPU* gpu_device = dynamic_cast(device)) + hwaccel = AccelBuffer(AccelAllocator(device,gpu_device->getGPUDevice(),gpu_device->getGPUContext()),0); +#endif + /* one can overwrite flags through device for debugging */ if (device->quality_flags != -1) quality_flags = (RTCBuildQuality) device->quality_flags; @@ -90,10 +120,11 @@ namespace embree void Scene::createTriangleAccel() { #if defined(EMBREE_GEOMETRY_TRIANGLE) + if (device->tri_accel == "default") { if (quality_flags != RTC_BUILD_QUALITY_LOW) - { + { int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel(); switch (mode) { case /*0b00*/ 0: @@ -168,11 +199,13 @@ namespace embree #endif else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown triangle acceleration structure "+device->tri_accel); #endif + } void Scene::createTriangleMBAccel() { #if defined(EMBREE_GEOMETRY_TRIANGLE) + if (device->tri_accel_mb == "default") { int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel(); @@ -211,6 +244,7 @@ namespace embree void Scene::createQuadAccel() { #if defined(EMBREE_GEOMETRY_QUAD) + if (device->quad_accel == "default") { if (quality_flags != RTC_BUILD_QUALITY_LOW) @@ -292,6 +326,7 @@ namespace embree void Scene::createQuadMBAccel() { #if defined(EMBREE_GEOMETRY_QUAD) + if (device->quad_accel_mb == "default") { int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel(); @@ -329,6 +364,7 @@ namespace embree void Scene::createHairAccel() { #if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT) + if (device->hair_accel == "default") { int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel(); @@ -366,6 +402,7 @@ namespace embree void Scene::createHairMBAccel() { #if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT) + if (device->hair_accel_mb == "default") { #if defined (EMBREE_TARGET_SIMD8) @@ -416,7 +453,8 @@ namespace embree void Scene::createUserGeometryAccel() { #if defined(EMBREE_GEOMETRY_USER) - if (device->object_accel == "default") + + if (device->object_accel == "default") { #if defined (EMBREE_TARGET_SIMD8) if (device->canUseAVX() && !isCompactAccel()) @@ -448,6 +486,7 @@ namespace embree void Scene::createUserGeometryMBAccel() { #if defined(EMBREE_GEOMETRY_USER) + if (device->object_accel_mb == "default" ) { #if defined (EMBREE_TARGET_SIMD8) if (device->canUseAVX() && !isCompactAccel()) @@ -467,6 +506,7 @@ namespace embree void Scene::createInstanceAccel() { #if defined(EMBREE_GEOMETRY_INSTANCE) + // if (device->object_accel == "default") { #if defined (EMBREE_TARGET_SIMD8) @@ -494,6 +534,7 @@ namespace embree void Scene::createInstanceMBAccel() { #if defined(EMBREE_GEOMETRY_INSTANCE) + //if (device->instance_accel_mb == "default") { #if defined (EMBREE_TARGET_SIMD8) @@ -550,10 +591,58 @@ namespace embree #endif } + void Scene::createInstanceArrayAccel() + { +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + + // if (device->object_accel == "default") + { +#if defined (EMBREE_TARGET_SIMD8) + if (device->canUseAVX() && !isCompactAccel()) { + if (quality_flags != RTC_BUILD_QUALITY_LOW) { + accels_add(device->bvh8_factory->BVH8InstanceArray(this, BVHFactory::BuildVariant::STATIC)); + } else { + accels_add(device->bvh8_factory->BVH8InstanceArray(this, BVHFactory::BuildVariant::DYNAMIC)); + } + } + else +#endif + { + if (quality_flags != RTC_BUILD_QUALITY_LOW) { + accels_add(device->bvh4_factory->BVH4InstanceArray(this, BVHFactory::BuildVariant::STATIC)); + } else { + accels_add(device->bvh4_factory->BVH4InstanceArray(this, BVHFactory::BuildVariant::DYNAMIC)); + } + } + } + // else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown instance accel "+device->instance_accel); +#endif + } + + void Scene::createInstanceArrayMBAccel() + { +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + + //if (device->instance_accel_mb == "default") + { +#if defined (EMBREE_TARGET_SIMD8) + if (device->canUseAVX() && !isCompactAccel()) + accels_add(device->bvh8_factory->BVH8InstanceArrayMB(this)); + else +#endif + accels_add(device->bvh4_factory->BVH4InstanceArrayMB(this)); + } + //else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown instance mblur accel "+device->instance_accel_mb); +#endif + } + + void Scene::createGridAccel() { - BVHFactory::IntersectVariant ivariant = isRobustAccel() ? BVHFactory::IntersectVariant::ROBUST : BVHFactory::IntersectVariant::FAST; #if defined(EMBREE_GEOMETRY_GRID) + + BVHFactory::IntersectVariant ivariant = isRobustAccel() ? BVHFactory::IntersectVariant::ROBUST : BVHFactory::IntersectVariant::FAST; + if (device->grid_accel == "default") { #if defined (EMBREE_TARGET_SIMD8) @@ -579,6 +668,7 @@ namespace embree void Scene::createGridMBAccel() { #if defined(EMBREE_GEOMETRY_GRID) + if (device->grid_accel_mb == "default") { accels_add(device->bvh4_factory->BVH4GridMB(this,BVHFactory::BuildVariant::STATIC)); @@ -588,13 +678,13 @@ namespace embree #endif } - + void Scene::clear() { } unsigned Scene::bind(unsigned geomID, Ref geometry) { - Lock lock(geometriesMutex); + Lock lock(geometriesMutex); if (geomID == RTC_INVALID_GEOMETRY_ID) { geomID = id_pool.allocate(); if (geomID == RTC_INVALID_GEOMETRY_ID) @@ -620,7 +710,7 @@ namespace embree void Scene::detachGeometry(size_t geomID) { - Lock lock(geometriesMutex); + Lock lock(geometriesMutex); if (geomID >= geometries.size()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"invalid geometry ID"); @@ -637,17 +727,77 @@ namespace embree geometryModCounters_[geomID] = 0; } - void Scene::updateInterface() + void Scene::build_cpu_accels() { - is_build = true; + /* select acceleration structures to build */ + unsigned int new_enabled_geometry_types = world.enabledGeometryTypesMask(); + + if (flags_modified || new_enabled_geometry_types != enabled_geometry_types) + { + accels_init(); + + /* we need to make all geometries modified, otherwise two level builder will + not rebuild currently not modified geometries */ + parallel_for(geometryModCounters_.size(), [&] ( const size_t i ) { + geometryModCounters_[i] = 0; + }); + + if (getNumPrimitives(TriangleMesh::geom_type,false)) createTriangleAccel(); + if (getNumPrimitives(TriangleMesh::geom_type,true)) createTriangleMBAccel(); + if (getNumPrimitives(QuadMesh::geom_type,false)) createQuadAccel(); + if (getNumPrimitives(QuadMesh::geom_type,true)) createQuadMBAccel(); + if (getNumPrimitives(GridMesh::geom_type,false)) createGridAccel(); + if (getNumPrimitives(GridMesh::geom_type,true)) createGridMBAccel(); + if (getNumPrimitives(SubdivMesh::geom_type,false)) createSubdivAccel(); + if (getNumPrimitives(SubdivMesh::geom_type,true)) createSubdivMBAccel(); + if (getNumPrimitives(Geometry::MTY_CURVES,false)) createHairAccel(); + if (getNumPrimitives(Geometry::MTY_CURVES,true)) createHairMBAccel(); + if (getNumPrimitives(UserGeometry::geom_type,false)) createUserGeometryAccel(); + if (getNumPrimitives(UserGeometry::geom_type,true)) createUserGeometryMBAccel(); + if (getNumPrimitives(Geometry::MTY_INSTANCE_CHEAP,false)) createInstanceAccel(); + if (getNumPrimitives(Geometry::MTY_INSTANCE_CHEAP,true)) createInstanceMBAccel(); + if (getNumPrimitives(Geometry::MTY_INSTANCE_EXPENSIVE,false)) createInstanceExpensiveAccel(); + if (getNumPrimitives(Geometry::MTY_INSTANCE_EXPENSIVE,true)) createInstanceExpensiveMBAccel(); + if (getNumPrimitives(Geometry::MTY_INSTANCE_ARRAY,false)) createInstanceArrayAccel(); + if (getNumPrimitives(Geometry::MTY_INSTANCE_ARRAY,true)) createInstanceArrayMBAccel(); + + flags_modified = false; + enabled_geometry_types = new_enabled_geometry_types; + } + + /* select fast code path if no filter function is present */ + accels_select(hasFilterFunction()); + + /* build all hierarchies of this scene */ + accels_build(); + + /* make static geometry immutable */ + if (!isDynamicAccel()) { + accels_immutable(); + flags_modified = true; // in non-dynamic mode we have to re-create accels + } + + if (device->verbosity(2)) { + std::cout << "created scene intersector" << std::endl; + accels_print(2); + std::cout << "selected scene intersector" << std::endl; + intersectors.print(2); + } + } + + void Scene::build_gpu_accels() + { +#if defined(EMBREE_SYCL_SUPPORT) + const BBox3f aabb = rthwifBuild(this,hwaccel); + bounds = LBBox(aabb); + hwaccel_bounds = aabb; +#endif } void Scene::commit_task () { - checkIfModifiedAndSet (); - if (!isModified()) { - return; - } + checkIfModifiedAndSet(); + if (!isModified()) return; /* print scene statistics */ if (device->verbosity(2)) @@ -666,58 +816,21 @@ namespace embree { geometries[i]->preCommit(); geometries[i]->addElementsToCount (c); - c.numFilterFunctions += (int) geometries[i]->hasFilterFunctions(); + c.numFilterFunctions += (int) geometries[i]->hasArgumentFilterFunctions(); + c.numFilterFunctions += (int) geometries[i]->hasGeometryFilterFunctions(); } } return c; }, std::plus() ); - - /* select acceleration structures to build */ - unsigned int new_enabled_geometry_types = world.enabledGeometryTypesMask(); - if (flags_modified || new_enabled_geometry_types != enabled_geometry_types) - { - accels_init(); - /* we need to make all geometries modified, otherwise two level builder will - not rebuild currently not modified geometries */ - parallel_for(geometryModCounters_.size(), [&] ( const size_t i ) { - geometryModCounters_[i] = 0; - }); - - if (getNumPrimitives(TriangleMesh::geom_type,false)) createTriangleAccel(); - if (getNumPrimitives(TriangleMesh::geom_type,true)) createTriangleMBAccel(); - if (getNumPrimitives(QuadMesh::geom_type,false)) createQuadAccel(); - if (getNumPrimitives(QuadMesh::geom_type,true)) createQuadMBAccel(); - if (getNumPrimitives(GridMesh::geom_type,false)) createGridAccel(); - if (getNumPrimitives(GridMesh::geom_type,true)) createGridMBAccel(); - if (getNumPrimitives(SubdivMesh::geom_type,false)) createSubdivAccel(); - if (getNumPrimitives(SubdivMesh::geom_type,true)) createSubdivMBAccel(); - if (getNumPrimitives(Geometry::MTY_CURVES,false)) createHairAccel(); - if (getNumPrimitives(Geometry::MTY_CURVES,true)) createHairMBAccel(); - if (getNumPrimitives(UserGeometry::geom_type,false)) createUserGeometryAccel(); - if (getNumPrimitives(UserGeometry::geom_type,true)) createUserGeometryMBAccel(); - if (getNumPrimitives(Geometry::MTY_INSTANCE_CHEAP,false)) createInstanceAccel(); - if (getNumPrimitives(Geometry::MTY_INSTANCE_CHEAP,true)) createInstanceMBAccel(); - if (getNumPrimitives(Geometry::MTY_INSTANCE_EXPENSIVE,false)) createInstanceExpensiveAccel(); - if (getNumPrimitives(Geometry::MTY_INSTANCE_EXPENSIVE,true)) createInstanceExpensiveMBAccel(); - - flags_modified = false; - enabled_geometry_types = new_enabled_geometry_types; - } - - /* select fast code path if no filter function is present */ - accels_select(hasFilterFunction()); - - /* build all hierarchies of this scene */ - accels_build(); - - /* make static geometry immutable */ - if (!isDynamicAccel()) { - accels_immutable(); - flags_modified = true; // in non-dynamic mode we have to re-create accels - } +#if defined(EMBREE_SYCL_SUPPORT) + if (DeviceGPU* gpu_device = dynamic_cast(device)) + build_gpu_accels(); + else +#endif + build_cpu_accels(); /* call postCommit function of each geometry */ parallel_for(geometries.size(), [&] ( const size_t i ) { @@ -727,16 +840,7 @@ namespace embree geometryModCounters_[i] = geometries[i]->getModCounter(); } }); - - updateInterface(); - if (device->verbosity(2)) { - std::cout << "created scene intersector" << std::endl; - accels_print(2); - std::cout << "selected scene intersector" << std::endl; - intersectors.print(2); - } - setModified(false); } @@ -771,11 +875,11 @@ namespace embree /* allocates own taskscheduler for each build */ Ref scheduler = nullptr; { - Lock lock(schedulerMutex); - scheduler = this->scheduler; + Lock lock(taskGroup->schedulerMutex); + scheduler = taskGroup->scheduler; if (scheduler == null) { buildLock.lock(); - this->scheduler = scheduler = new TaskScheduler; + taskGroup->scheduler = scheduler = new TaskScheduler; } } @@ -792,13 +896,13 @@ namespace embree /* initiate build */ // -- GODOT start -- // try { - scheduler->spawn_root([&]() { commit_task(); Lock lock(schedulerMutex); this->scheduler = nullptr; }, 1, !join); + TaskScheduler::TaskGroupContext context; + scheduler->spawn_root([&]() { commit_task(); Lock lock(taskGroup->schedulerMutex); taskGroup->scheduler = nullptr; }, &context, 1, !join); // } // catch (...) { // accels_clear(); - // updateInterface(); - // Lock lock(schedulerMutex); - // this->scheduler = nullptr; + // Lock lock(taskGroup->schedulerMutex); + // taskGroup->scheduler = nullptr; // throw; // } // -- GODOT end -- @@ -809,7 +913,7 @@ namespace embree #if defined(TASKING_TBB) void Scene::commit (bool join) - { + { #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR < 8) if (join) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcJoinCommitScene not supported with this TBB version"); @@ -827,16 +931,7 @@ namespace embree #endif do { - -#if USE_TASK_ARENA - if (join) { - device->arena->execute([&]{ group.wait(); }); - } - else -#endif - { - group.wait(); - } + device->execute(join, [&](){ taskGroup->group.wait(); }); pause_cpu(); yield(); @@ -857,26 +952,14 @@ namespace embree tbb::task_group_context ctx( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::fp_settings ); #endif //ctx.set_priority(tbb::priority_high); - -#if USE_TASK_ARENA - if (join) + device->execute(join, [&]() { - device->arena->execute([&]{ - group.run([&]{ - tbb::parallel_for (size_t(0), size_t(1), size_t(1), [&] (size_t) { commit_task(); }, ctx); - }); - group.wait(); - }); - } - else -#endif - { - group.run([&]{ + taskGroup->group.run([&]{ tbb::parallel_for (size_t(0), size_t(1), size_t(1), [&] (size_t) { commit_task(); }, ctx); }); - group.wait(); - } - + taskGroup->group.wait(); + }); + /* reset MXCSR register again */ _mm_setcsr(mxcsr); } @@ -886,7 +969,6 @@ namespace embree _mm_setcsr(mxcsr); accels_clear(); - updateInterface(); throw; } } @@ -915,10 +997,10 @@ namespace embree try { - group.run([&]{ + taskGroup->group.run([&]{ concurrency::parallel_for(size_t(0), size_t(1), size_t(1), [&](size_t) { commit_task(); }); }); - group.wait(); + taskGroup->group.wait(); /* reset MXCSR register again */ _mm_setcsr(mxcsr); @@ -929,7 +1011,6 @@ namespace embree _mm_setcsr(mxcsr); accels_clear(); - updateInterface(); throw; } } diff --git a/thirdparty/embree/kernels/common/scene.h b/thirdparty/embree/kernels/common/scene.h index 5ed80a63f68..d9acca1065d 100644 --- a/thirdparty/embree/kernels/common/scene.h +++ b/thirdparty/embree/kernels/common/scene.h @@ -6,11 +6,11 @@ #include "default.h" #include "device.h" #include "builder.h" -#include "../../common/algorithms/parallel_any_of.h" #include "scene_triangle_mesh.h" #include "scene_quad_mesh.h" #include "scene_user_geometry.h" #include "scene_instance.h" +#include "scene_instance_array.h" #include "scene_curves.h" #include "scene_line_segments.h" #include "scene_subdiv_mesh.h" @@ -21,12 +21,18 @@ #include "acceln.h" #include "geometry.h" +#if defined(EMBREE_SYCL_SUPPORT) +#include "../sycl/rthwif_embree_builder.h" +#endif + namespace embree { + struct TaskGroup; + /*! Base class all scenes are derived from */ class Scene : public AccelN { - ALIGNED_CLASS_(std::alignment_of::value); + ALIGNED_CLASS_USM_(std::alignment_of::value); public: template @@ -140,6 +146,7 @@ namespace embree ~Scene () noexcept; private: + /*! class is non-copyable */ Scene (const Scene& other) DELETED; // do not implement Scene& operator= (const Scene& other) DELETED; // do not implement @@ -159,6 +166,8 @@ namespace embree void createInstanceMBAccel(); void createInstanceExpensiveAccel(); void createInstanceExpensiveMBAccel(); + void createInstanceArrayAccel(); + void createInstanceArrayMBAccel(); void createGridAccel(); void createGridMBAccel(); @@ -176,13 +185,13 @@ namespace embree void setSceneFlags(RTCSceneFlags scene_flags); RTCSceneFlags getSceneFlags() const; - + + void build_cpu_accels(); + void build_gpu_accels(); void commit (bool join); void commit_task (); void build () {} - void updateInterface(); - /* return number of geometries */ __forceinline size_t size() const { return geometries.size(); } @@ -205,20 +214,9 @@ namespace embree } protected: - - __forceinline void checkIfModifiedAndSet () - { - if (isModified ()) return; - - auto geometryIsModified = [this](size_t geomID)->bool { - return isGeometryModified(geomID); - }; - if (parallel_any_of (size_t(0), geometries.size (), geometryIsModified)) { - setModified (); - } - } - + void checkIfModifiedAndSet (); + public: /* get mesh by ID */ @@ -247,7 +245,7 @@ namespace embree } __forceinline Ref get_locked(size_t i) { - Lock lock(geometriesMutex); + Lock lock(geometriesMutex); assert(i < geometries.size()); return geometries[i]; } @@ -259,8 +257,8 @@ namespace embree __forceinline bool isStaticAccel() const { return !(scene_flags & RTC_SCENE_FLAG_DYNAMIC); } __forceinline bool isDynamicAccel() const { return scene_flags & RTC_SCENE_FLAG_DYNAMIC; } - __forceinline bool hasContextFilterFunction() const { - return scene_flags & RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION; + __forceinline bool hasArgumentFilterFunction() const { + return scene_flags & RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS; } __forceinline bool hasGeometryFilterFunction() { @@ -268,21 +266,21 @@ namespace embree } __forceinline bool hasFilterFunction() { - return hasContextFilterFunction() || hasGeometryFilterFunction(); + return hasArgumentFilterFunction() || hasGeometryFilterFunction(); } - /* test if scene got already build */ - __forceinline bool isBuild() const { return is_build; } + void* createQBVH6Accel(); - public: - IDPool id_pool; - vector> geometries; //!< list of all user geometries - vector geometryModCounters_; - vector vertices; - public: Device* device; + public: + IDPool id_pool; + Device::vector> geometries = device; //!< list of all user geometries + avector geometryModCounters_; + Device::vector vertices = device; + + public: /* these are to detect if we need to recreate the acceleration structures */ bool flags_modified; unsigned int enabled_geometry_types; @@ -290,24 +288,20 @@ namespace embree RTCSceneFlags scene_flags; RTCBuildQuality quality_flags; MutexSys buildMutex; - SpinLock geometriesMutex; - bool is_build; + MutexSys geometriesMutex; + +#if defined(EMBREE_SYCL_SUPPORT) + public: + BBox3f hwaccel_bounds = empty; + AccelBuffer hwaccel; +#endif + private: bool modified; //!< true if scene got modified public: - - /*! global lock step task scheduler */ -#if defined(TASKING_INTERNAL) - MutexSys schedulerMutex; - Ref scheduler; -#elif defined(TASKING_TBB) && TASKING_TBB_USE_TASK_ISOLATION - tbb::isolated_task_group group; -#elif defined(TASKING_TBB) - tbb::task_group group; -#elif defined(TASKING_PPL) - concurrency::task_group group; -#endif + + std::unique_ptr taskGroup; public: struct BuildProgressMonitorInterface : public BuildProgressMonitor { @@ -363,12 +357,28 @@ namespace embree if (mask & Geometry::MTY_INSTANCE_EXPENSIVE) count += mblur ? world.numMBInstancesExpensive : world.numInstancesExpensive; - + + if (mask & Geometry::MTY_INSTANCE_ARRAY) + count += mblur ? world.numMBInstanceArrays : world.numInstanceArrays; + if (mask & Geometry::MTY_GRID_MESH) count += mblur ? world.numMBGrids : world.numGrids; return count; } + + __forceinline size_t getNumSubPrimitives(Geometry::GTypeMask mask, bool mblur) const + { + size_t count = 0; + + if (mask & Geometry::MTY_GRID_MESH) + count += mblur ? world.numMBSubGrids : world.numSubGrids; + + Geometry::GTypeMask new_mask = (Geometry::GTypeMask)(mask & ~Geometry::MTY_GRID_MESH); + count += getNumPrimitives(new_mask, mblur); + + return count; + } template __forceinline unsigned getNumTimeSteps() diff --git a/thirdparty/embree/kernels/common/scene_curves.h b/thirdparty/embree/kernels/common/scene_curves.h index a1ea45d3c78..fd6ed81d7de 100644 --- a/thirdparty/embree/kernels/common/scene_curves.h +++ b/thirdparty/embree/kernels/common/scene_curves.h @@ -119,6 +119,15 @@ namespace embree p3 = vertex(i+3,itime); } + /*! gathers the curve normals starting with i'th vertex */ + __forceinline void gather_normals(Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i) const + { + n0 = normal(i+0); + n1 = normal(i+1); + n2 = normal(i+2); + n3 = normal(i+3); + } + /*! gathers the curve starting with i'th vertex */ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i) const { @@ -177,6 +186,13 @@ namespace embree p3 = madd(Vec3ff(t0),a3,t1*b3); } + /*! loads curve vertices for specified time */ + __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, size_t i, float time) const + { + if (hasMotionBlur()) gather(p0,p1,p2,p3,i,time); + else gather(p0,p1,p2,p3,i); + } + /*! loads curve vertices for specified time */ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i, float time) const { @@ -199,8 +215,15 @@ namespace embree n3 = madd(Vec3ff(t0),an3,t1*bn3); } + /*! loads curve vertices for specified time for mblur and non-mblur case */ + __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i, float time) const + { + if (hasMotionBlur()) gather(p0,p1,p2,p3,n0,n1,n2,n3,i,time); + else gather(p0,p1,p2,p3,n0,n1,n2,n3,i); + } + template - __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const + __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const { Vec3ff v0,v1,v2,v3; Vec3fa n0,n1,n2,n3; unsigned int vertexID = curve(primID); @@ -212,7 +235,7 @@ namespace embree } template - __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const + __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const { float ftime; const size_t itime = timeSegment(time, ftime); @@ -221,6 +244,19 @@ namespace embree return clerp(curve0,curve1,ftime); } + template + __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurveSafe(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const + { + float ftime = 0.0f; + const size_t itime = hasMotionBlur() ? timeSegment(time, ftime) : 0; + const TensorLinearCubicBezierSurface3fa curve0 = getNormalOrientedCurve(context,ray_org,primID,itime+0); + if (hasMotionBlur()) { + const TensorLinearCubicBezierSurface3fa curve1 = getNormalOrientedCurve(context,ray_org,primID,itime+1); + return clerp(curve0,curve1,ftime); + } + return curve0; + } + /*! gathers the hermite curve starting with i'th vertex */ __forceinline void gather_hermite(Vec3ff& p0, Vec3ff& t0, Vec3ff& p1, Vec3ff& t1, size_t i) const { @@ -255,6 +291,13 @@ namespace embree t1 = madd(Vec3ff(f0),at1,f1*bt1); } + /*! loads curve vertices for specified time for mblur and non-mblur geometry */ + __forceinline void gather_hermite_safe(Vec3ff& p0, Vec3ff& t0, Vec3ff& p1, Vec3ff& t1, size_t i, float time) const + { + if (hasMotionBlur()) gather_hermite(p0,t0,p1,t1,i,time); + else gather_hermite(p0,t0,p1,t1,i); + } + /*! gathers the hermite curve starting with i'th vertex */ __forceinline void gather_hermite(Vec3ff& p0, Vec3ff& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3ff& t1, Vec3fa& n1, Vec3fa& dn1, size_t i) const { @@ -282,7 +325,7 @@ namespace embree } /*! loads curve vertices for specified time */ - __forceinline void gather_hermite(Vec3ff& p0, Vec3fa& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3fa& t1, Vec3fa& n1, Vec3fa& dn1, size_t i, float time) const + __forceinline void gather_hermite(Vec3ff& p0, Vec3ff& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3ff& t1, Vec3fa& n1, Vec3fa& dn1, size_t i, float time) const { float ftime; const size_t itime = timeSegment(time, ftime); @@ -301,8 +344,15 @@ namespace embree dn1= madd(Vec3ff(f0),adn1,f1*bdn1); } + /*! loads curve vertices for specified time */ + __forceinline void gather_hermite_safe(Vec3ff& p0, Vec3ff& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3ff& t1, Vec3fa& n1, Vec3fa& dn1, size_t i, float time) const + { + if (hasMotionBlur()) gather_hermite(p0,t0,n0,dn0,p1,t1,n1,dn1,i,time); + else gather_hermite(p0,t0,n0,dn0,p1,t1,n1,dn1,i); + } + template - __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const + __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const { Vec3ff v0,t0,v1,t1; Vec3fa n0,dn0,n1,dn1; unsigned int vertexID = curve(primID); @@ -315,7 +365,7 @@ namespace embree } template - __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const + __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const { float ftime; const size_t itime = timeSegment(time, ftime); @@ -324,6 +374,24 @@ namespace embree return clerp(curve0,curve1,ftime); } + template + __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurveSafe(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const + { + float ftime = 0.0f; + const size_t itime = hasMotionBlur() ? timeSegment(time, ftime) : 0; + const TensorLinearCubicBezierSurface3fa curve0 = getNormalOrientedHermiteCurve(context, ray_org, primID,itime+0); + if (hasMotionBlur()) { + const TensorLinearCubicBezierSurface3fa curve1 = getNormalOrientedHermiteCurve(context, ray_org, primID,itime+1); + return clerp(curve0,curve1,ftime); + } + return curve0; + } + + /* returns the projected area */ + __forceinline float projectedPrimitiveArea(const size_t i) const { + return 1.0f; + } + private: void resizeBuffers(unsigned int numSteps); @@ -333,12 +401,12 @@ namespace embree BufferView normals0; //!< fast access to first normal buffer BufferView tangents0; //!< fast access to first tangent buffer BufferView dnormals0; //!< fast access to first normal derivative buffer - vector> vertices; //!< vertex array for each timestep - vector> normals; //!< normal array for each timestep - vector> tangents; //!< tangent array for each timestep - vector> dnormals; //!< normal derivative array for each timestep + Device::vector> vertices = device; //!< vertex array for each timestep + Device::vector> normals = device; //!< normal array for each timestep + Device::vector> tangents = device; //!< tangent array for each timestep + Device::vector> dnormals = device; //!< normal derivative array for each timestep BufferView flags; //!< start, end flag per segment - vector> vertexAttribs; //!< user buffers + Device::vector> vertexAttribs = device; //!< user buffers int tessellationRate; //!< tessellation rate for flat curve float maxRadiusScale = 1.0; //!< maximal min-width scaling of curve radii }; @@ -486,7 +554,7 @@ namespace embree src = vertices[bufferSlot].getPtr(); stride = vertices[bufferSlot].getStride(); } - + for (unsigned int i=0; i> 1) * ((unsigned int)g.resY >> 1)); } @@ -174,6 +188,18 @@ namespace embree return vertices[itime][i]; } + /*! returns i'th vertex of for specified time */ + __forceinline const Vec3fa vertex(size_t i, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + const float t0 = 1.0f - ftime; + const float t1 = ftime; + Vec3fa v0 = vertex(i, itime+0); + Vec3fa v1 = vertex(i, itime+1); + return madd(Vec3fa(t0),v0,t1*v1); + } + /*! returns i'th vertex of itime'th timestep */ __forceinline const char* vertexPtr(size_t i, size_t itime) const { return vertices[itime].getPtr(i); @@ -198,6 +224,56 @@ namespace embree return vertex(index,itime); } + /*! returns i'th vertex of the itime'th timestep */ + __forceinline const Vec3fa grid_vertex(const Grid& g, size_t x, size_t y, float time) const { + const size_t index = grid_vertex_index(g,x,y); + return vertex(index,time); + } + + /*! gathers quad vertices */ + __forceinline void gather_quad_vertices(Vec3fa& v0, Vec3fa& v1, Vec3fa& v2, Vec3fa& v3, const Grid& g, size_t x, size_t y) const + { + v0 = grid_vertex(g,x+0,y+0); + v1 = grid_vertex(g,x+1,y+0); + v2 = grid_vertex(g,x+1,y+1); + v3 = grid_vertex(g,x+0,y+1); + } + + /*! gathers quad vertices for specified time */ + __forceinline void gather_quad_vertices(Vec3fa& v0, Vec3fa& v1, Vec3fa& v2, Vec3fa& v3, const Grid& g, size_t x, size_t y, float time) const + { + v0 = grid_vertex(g,x+0,y+0,time); + v1 = grid_vertex(g,x+1,y+0,time); + v2 = grid_vertex(g,x+1,y+1,time); + v3 = grid_vertex(g,x+0,y+1,time); + } + + /*! gathers quad vertices for mblur and non-mblur meshes */ + __forceinline void gather_quad_vertices_safe(Vec3fa& v0, Vec3fa& v1, Vec3fa& v2, Vec3fa& v3, const Grid& g, size_t x, size_t y, float time) const + { + if (hasMotionBlur()) gather_quad_vertices(v0,v1,v2,v3,g,x,y,time); + else gather_quad_vertices(v0,v1,v2,v3,g,x,y); + } + + /*! calculates the build bounds of the i'th quad, if it's valid */ + __forceinline bool buildBoundsQuad(const Grid& g, size_t sx, size_t sy, BBox3fa& bbox) const + { + BBox3fa b(empty); + for (size_t t=0; t grids; //!< array of triangles BufferView vertices0; //!< fast access to first vertex buffer - vector> vertices; //!< vertex array for each timestep - vector vertexAttribs; //!< vertex attributes + Device::vector> vertices = device; //!< vertex array for each timestep + Device::vector vertexAttribs = device; //!< vertex attributes + +#if defined(EMBREE_SYCL_SUPPORT) + + public: + struct PrimID_XY { uint32_t primID; uint16_t x,y; }; + Device::vector quadID_to_primID_xy = device; //!< maps a quad to the primitive ID and grid coordinates +#endif }; namespace isa @@ -287,6 +373,94 @@ namespace embree { GridMeshISA (Device* device) : GridMesh(device) {} + + LBBox3fa vlinearBounds(size_t buildID, const BBox1f& time_range, const SubGridBuildData * const sgrids) const override { + const SubGridBuildData &subgrid = sgrids[buildID]; + const unsigned int primID = subgrid.primID; + const size_t x = subgrid.x(); + const size_t y = subgrid.y(); + return linearBounds(grid(primID),x,y,time_range); + } + +#if defined(EMBREE_SYCL_SUPPORT) + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const override + { + PrimInfo pinfo(empty); + for (size_t j=r.begin(); j& prims, mvector& sgrids, const range& r, size_t k, unsigned int geomID) const override + { + PrimInfo pinfo(empty); + for (size_t j=r.begin(); j& r, size_t k, unsigned int geomID) const override + { + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + PrimInfo pinfo(empty); + for (size_t j=r.begin(); j& prims, mvector& sgrids, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const override + { + PrimInfoMB pinfoMB(empty); + for (size_t j=r.begin(); j 0) { + float ftime; const unsigned int itime = timeSegment(t, ftime); + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return slerp(local2world[itime+0],local2world[itime+1],ftime); + return lerp(local2world[itime+0],local2world[itime+1],ftime); + } + return getLocal2World(); } __forceinline AffineSpace3fa getWorld2Local() const { @@ -143,7 +147,9 @@ namespace embree } __forceinline AffineSpace3fa getWorld2Local(float t) const { - return rcp(getLocal2World(t)); + if (numTimeSegments() > 0) + return rcp(getLocal2World(t)); + return getWorld2Local(); } template @@ -154,6 +160,10 @@ namespace embree return getWorld2LocalLerp(valid, t); } + __forceinline float projectedPrimitiveArea(const size_t i) const { + return area(bounds(i)); + } + private: template @@ -220,7 +230,11 @@ namespace embree InstanceISA (Device* device) : Instance(device) {} - PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const + LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const { + return linearBounds(primID,time_range); + } + + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { assert(r.begin() == 0); assert(r.end() == 1); @@ -252,7 +266,23 @@ namespace embree prims[k++] = prim; return pinfo; } - + + PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range& r, size_t k, unsigned int geomID) const + { + assert(r.begin() == 0); + assert(r.end() == 1); + + PrimInfo pinfo(empty); + const BBox1f t0t1 = intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + const BBox3fa bounds = linearBounds(0, t0t1).bounds(); + const PrimRef prim(bounds, geomID, unsigned(0)); + pinfo.add_center2(prim); + prims[k++] = prim; + return pinfo; + } + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { assert(r.begin() == 0); diff --git a/thirdparty/embree/kernels/common/scene_instance_array.h b/thirdparty/embree/kernels/common/scene_instance_array.h new file mode 100644 index 00000000000..3cf4d68feb6 --- /dev/null +++ b/thirdparty/embree/kernels/common/scene_instance_array.h @@ -0,0 +1,385 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "geometry.h" +#include "accel.h" + +namespace embree +{ + struct MotionDerivativeCoefficients; + + /*! Instanced acceleration structure */ + struct InstanceArray : public Geometry + { + //ALIGNED_STRUCT_(16); + static const Geometry::GTypeMask geom_type = Geometry::MTY_INSTANCE_ARRAY; + + public: + InstanceArray (Device* device, unsigned int numTimeSteps = 1); + ~InstanceArray(); + + private: + InstanceArray (const InstanceArray& other) DELETED; // do not implement + InstanceArray& operator= (const InstanceArray& other) DELETED; // do not implement + + private: + LBBox3fa nonlinearBounds(size_t i, + const BBox1f& time_range_in, + const BBox1f& geom_time_range, + float geom_time_segments) const; + + BBox3fa boundSegment(size_t i, size_t itime, + BBox3fa const& obbox0, BBox3fa const& obbox1, + BBox3fa const& bbox0, BBox3fa const& bbox1, + float t_min, float t_max) const; + + /* calculates the (correct) interpolated bounds */ + __forceinline BBox3fa bounds(size_t i, size_t itime0, size_t itime1, float f) const + { + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return xfmBounds(slerp(l2w(i, itime0), l2w(i, itime1), f), + lerp(getObjectBounds(i, itime0), getObjectBounds(i, itime1), f)); + return xfmBounds(lerp(l2w(i, itime0), l2w(i, itime1), f), + lerp(getObjectBounds(i, itime0), getObjectBounds(i, itime1), f)); + } + + public: + + virtual void setBuffer(RTCBufferType type, unsigned int slot, RTCFormat format, const Ref& buffer, size_t offset, size_t stride, unsigned int num) override; + virtual void* getBuffer(RTCBufferType type, unsigned int slot) override; + virtual void updateBuffer(RTCBufferType type, unsigned int slot) override; + + virtual void setNumTimeSteps (unsigned int numTimeSteps) override; + virtual void setInstancedScene(const Ref& scene) override; + virtual void setInstancedScenes(const RTCScene* scenes, size_t numScenes) override; + virtual AffineSpace3fa getTransform(size_t, float time) override; + virtual void setMask (unsigned mask) override; + virtual void build() {} + virtual void addElementsToCount (GeometryCounts & counts) const override; + virtual void commit() override; + + public: + + /*! calculates the bounds of instance */ + __forceinline BBox3fa bounds(size_t i) const { + if (!valid(i)) + return BBox3fa(); + + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return xfmBounds(quaternionDecompositionToAffineSpace(l2w(i, 0)),getObject(i)->bounds.bounds()); + return xfmBounds(l2w(i, 0),getObject(i)->bounds.bounds()); + } + + /*! gets the bounds of the instanced scene */ + __forceinline BBox3fa getObjectBounds(size_t i, size_t itime) const { + if (!valid(i)) + return BBox3fa(); + + return getObject(i)->getBounds(timeStep(itime)); + } + + /*! calculates the bounds of instance */ + __forceinline BBox3fa bounds(size_t i, size_t itime) const { + if (!valid(i)) + return BBox3fa(); + + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return xfmBounds(quaternionDecompositionToAffineSpace(l2w(i, itime)),getObjectBounds(i, itime)); + return xfmBounds(l2w(i, itime),getObjectBounds(i, itime)); + } + + /*! calculates the linear bounds of the i'th primitive for the specified time range */ + __forceinline LBBox3fa linearBounds(size_t i, const BBox1f& dt) const { + if (!valid(i)) + return LBBox3fa(); + + LBBox3fa lbbox = nonlinearBounds(i, dt, time_range, fnumTimeSegments); + return lbbox; + } + + /*! calculates the build bounds of the i'th item, if it's valid */ + __forceinline bool buildBounds(size_t i, BBox3fa* bbox = nullptr) const + { + if (!valid(i)) + return false; + + const BBox3fa b = bounds(i); + if (bbox) *bbox = b; + return isvalid(b); + } + + /*! calculates the build bounds of the i'th item at the itime'th time segment, if it's valid */ + __forceinline bool buildBounds(size_t i, size_t itime, BBox3fa& bbox) const + { + if (!valid(i)) + return false; + + const LBBox3fa bounds = linearBounds(i,itime); + bbox = bounds.bounds (); + return isvalid(bounds); + } + + /* gets version info of topology */ + unsigned int getTopologyVersion() const { + return numPrimitives; + } + + /* returns true if topology changed */ + bool topologyChanged(unsigned int otherVersion) const { + return numPrimitives != otherVersion; + } + + /*! check if the i'th primitive is valid between the specified time range */ + __forceinline bool valid(size_t i) const + { + if (object) return true; + return (object_ids[i] != (unsigned int)(-1)); + } + + /*! check if the i'th primitive is valid between the specified time range */ + __forceinline bool valid(size_t i, const range& itime_range) const + { + for (size_t itime = itime_range.begin(); itime <= itime_range.end(); itime++) + if (!isvalid(bounds(i,itime))) return false; + + return true; + } + + __forceinline AffineSpace3fa getLocal2World(size_t i) const + { + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return quaternionDecompositionToAffineSpace(l2w(i,0)); + return l2w(i, 0); + } + + __forceinline AffineSpace3fa getLocal2World(size_t i, float t) const + { + if (numTimeSegments() > 0) { + float ftime; const unsigned int itime = timeSegment(t, ftime); + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return slerp(l2w(i, itime+0),l2w(i, itime+1),ftime); + return lerp(l2w(i, itime+0),l2w(i, itime+1),ftime); + } + return getLocal2World(i); + } + + __forceinline AffineSpace3fa getWorld2Local(size_t i) const { + return rcp(getLocal2World(i)); + } + + __forceinline AffineSpace3fa getWorld2Local(size_t i, float t) const { + return rcp(getLocal2World(i, t)); + } + + template + __forceinline AffineSpace3vf getWorld2Local(size_t i, const vbool& valid, const vfloat& t) const + { + if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION)) + return getWorld2LocalSlerp(i, valid, t); + return getWorld2LocalLerp(i, valid, t); + } + + __forceinline float projectedPrimitiveArea(const size_t i) const { + return area(bounds(i)); + } + + inline Accel* getObject(size_t i) const { + if (object) { + return object; + } + + assert(objects); + assert(i < numPrimitives); + if (object_ids[i] == (unsigned int)(-1)) + return nullptr; + + assert(object_ids[i] < numObjects); + return objects[object_ids[i]]; + } + + private: + + template + __forceinline AffineSpace3vf getWorld2LocalSlerp(size_t i, const vbool& valid, const vfloat& t) const + { + vfloat ftime; + const vint itime_k = timeSegment(t, ftime); + assert(any(valid)); + const size_t index = bsf(movemask(valid)); + const int itime = itime_k[index]; + if (likely(all(valid, itime_k == vint(itime)))) { + return rcp(slerp(AffineSpace3vff(l2w(i, itime+0)), + AffineSpace3vff(l2w(i, itime+1)), + ftime)); + } + else { + AffineSpace3vff space0,space1; + vbool valid1 = valid; + while (any(valid1)) { + vbool valid2; + const int itime = next_unique(valid1, itime_k, valid2); + space0 = select(valid2, AffineSpace3vff(l2w(i, itime+0)), space0); + space1 = select(valid2, AffineSpace3vff(l2w(i, itime+1)), space1); + } + return rcp(slerp(space0, space1, ftime)); + } + } + + template + __forceinline AffineSpace3vf getWorld2LocalLerp(size_t i, const vbool& valid, const vfloat& t) const + { + vfloat ftime; + const vint itime_k = timeSegment(t, ftime); + assert(any(valid)); + const size_t index = bsf(movemask(valid)); + const int itime = itime_k[index]; + if (likely(all(valid, itime_k == vint(itime)))) { + return rcp(lerp(AffineSpace3vf((AffineSpace3fa)l2w(i, itime+0)), + AffineSpace3vf((AffineSpace3fa)l2w(i, itime+1)), + ftime)); + } else { + AffineSpace3vf space0,space1; + vbool valid1 = valid; + while (any(valid1)) { + vbool valid2; + const int itime = next_unique(valid1, itime_k, valid2); + space0 = select(valid2, AffineSpace3vf((AffineSpace3fa)l2w(i, itime+0)), space0); + space1 = select(valid2, AffineSpace3vf((AffineSpace3fa)l2w(i, itime+1)), space1); + } + return rcp(lerp(space0, space1, ftime)); + } + } + + private: + + __forceinline AffineSpace3ff l2w(size_t i, size_t itime) const { + if (l2w_buf[itime].getFormat() == RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR) { + return *(AffineSpace3ff*)(l2w_buf[itime].getPtr(i)); + } + else if(l2w_buf[itime].getFormat() == RTC_FORMAT_QUATERNION_DECOMPOSITION) { + AffineSpace3ff transform; + QuaternionDecomposition* qd = (QuaternionDecomposition*)l2w_buf[itime].getPtr(i); + transform.l.vx.x = qd->scale_x; + transform.l.vy.y = qd->scale_y; + transform.l.vz.z = qd->scale_z; + transform.l.vy.x = qd->skew_xy; + transform.l.vz.x = qd->skew_xz; + transform.l.vz.y = qd->skew_yz; + transform.l.vx.y = qd->translation_x; + transform.l.vx.z = qd->translation_y; + transform.l.vy.z = qd->translation_z; + transform.p.x = qd->shift_x; + transform.p.y = qd->shift_y; + transform.p.z = qd->shift_z; + // normalize quaternion + Quaternion3f q(qd->quaternion_r, qd->quaternion_i, qd->quaternion_j, qd->quaternion_k); + q = normalize(q); + transform.l.vx.w = q.i; + transform.l.vy.w = q.j; + transform.l.vz.w = q.k; + transform.p.w = q.r; + return transform; + } + else if (l2w_buf[itime].getFormat() == RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR) { + AffineSpace3f* l2w = reinterpret_cast(l2w_buf[itime].getPtr(i)); + return AffineSpace3ff(*l2w); + } + else if (l2w_buf[itime].getFormat() == RTC_FORMAT_FLOAT3X4_ROW_MAJOR) { + float* data = reinterpret_cast(l2w_buf[itime].getPtr(i)); + AffineSpace3f l2w; + l2w.l.vx.x = data[0]; l2w.l.vy.x = data[1]; l2w.l.vz.x = data[2]; l2w.p.x = data[3]; + l2w.l.vx.y = data[4]; l2w.l.vy.y = data[5]; l2w.l.vz.y = data[6]; l2w.p.y = data[7]; + l2w.l.vx.z = data[8]; l2w.l.vy.z = data[9]; l2w.l.vz.z = data[10]; l2w.p.z = data[11]; + return l2w; + } + assert(false); + return AffineSpace3ff(); + } + + inline AffineSpace3ff l2w(size_t i) const { + return l2w(i, 0); + } + + private: + Accel* object; //!< fast path if only one scene is instanced + Accel** objects; + uint32_t numObjects; + Device::vector l2w_buf = device; //!< transformation from local space to world space for each timestep (either normal matrix or quaternion decomposition) + BufferView object_ids; //!< array of scene ids per instance array primitive + }; + + namespace isa + { + struct InstanceArrayISA : public InstanceArray + { + InstanceArrayISA (Device* device) + : InstanceArray(device) {} + + LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const { + return linearBounds(primID,time_range); + } + + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + for (size_t j = r.begin(); j < r.end(); j++) { + BBox3fa bounds = empty; + if (!buildBounds(j, &bounds) || !valid(j)) + continue; + const PrimRef prim(bounds, geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + + PrimInfo createPrimRefArrayMB(mvector& prims, size_t itime, const range& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + for (size_t j = r.begin(); j < r.end(); j++) { + BBox3fa bounds = empty; + if (!buildBounds(j, itime, bounds)) + continue; + const PrimRef prim(bounds, geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + + PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + for (size_t j = r.begin(); j < r.end(); j++) { + LBBox3fa lbounds = linearBounds(j, t0t1); + if (!isvalid(lbounds.bounds())) + continue; + const PrimRef prim(lbounds.bounds(), geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const + { + PrimInfoMB pinfo(empty); + for (size_t j = r.begin(); j < r.end(); j++) { + if (!valid(j, timeSegmentRange(t0t1))) + continue; + const PrimRefMB prim(linearBounds(j, t0t1), this->numTimeSegments(), this->time_range, this->numTimeSegments(), geomID, unsigned(j)); + pinfo.add_primref(prim); + prims[k++] = prim; + } + return pinfo; + } + }; + } + + DECLARE_ISA_FUNCTION(InstanceArray*, createInstanceArray, Device*); +} diff --git a/thirdparty/embree/kernels/common/scene_line_segments.h b/thirdparty/embree/kernels/common/scene_line_segments.h index 3c9fdb39dbf..e58fd1b7eb4 100644 --- a/thirdparty/embree/kernels/common/scene_line_segments.h +++ b/thirdparty/embree/kernels/common/scene_line_segments.h @@ -84,6 +84,14 @@ namespace embree return segments[i]; } +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + /*! returns the i'th segment */ + template + __forceinline const vuint vsegment(const vuint& i) const { + return segments[i.v]; + } +#endif + /*! returns the segment to the left of the i'th segment */ __forceinline bool segmentLeftExists(size_t i) const { assert (flags); @@ -136,6 +144,219 @@ namespace embree return vertices[itime][i].w; } + /*! gathers the curve starting with i'th vertex */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, unsigned int vid) const + { + p0 = vertex(vid+0); + p1 = vertex(vid+1); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, const vuint& vid) const + { + p0 = vertex(vid.v+0); + p1 = vertex(vid.v+1); + } +#endif + + /*! gathers the curve starting with i'th vertex of itime'th timestep */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, unsigned int vid, size_t itime) const + { + p0 = vertex(vid+0,itime); + p1 = vertex(vid+1,itime); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, const vuint& vid, const vint& itime) const + { + p0 = vertex(vid.v+0,itime.v); + p1 = vertex(vid.v+1,itime.v); + } +#endif + + /*! loads curve vertices for specified time */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, unsigned int vid, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + + const float t0 = 1.0f - ftime; + const float t1 = ftime; + Vec3ff a0,a1; gather(a0,a1,vid,itime); + Vec3ff b0,b1; gather(b0,b1,vid,itime+1); + p0 = madd(Vec3ff(t0),a0,t1*b0); + p1 = madd(Vec3ff(t0),a1,t1*b1); + } + + /*! loads curve vertices for specified time for mblur and non-mblur case */ + __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, unsigned int vid, float time) const + { + if (hasMotionBlur()) gather(p0,p1,vid,time); + else gather(p0,p1,vid); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, const vuint& vid, const vfloat& time) const + { + vfloat ftime; + const vint itime = timeSegment(time, ftime); + + const vfloat t0 = 1.0f - ftime; + const vfloat t1 = ftime; + Vec4vf a0,a1; vgather(a0,a1,vid,itime); + Vec4vf b0,b1; vgather(b0,b1,vid,itime+1); + p0 = madd(Vec4vf(t0),a0,t1*b0); + p1 = madd(Vec4vf(t0),a1,t1*b1); + } +#endif + + /*! gathers the cone curve starting with i'th vertex */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, unsigned int vid) const + { + gather(p0,p1,vid); + cL = !segmentLeftExists (primID); + cR = !segmentRightExists(primID); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, vbool& cL, vbool& cR, const vuint& primID, const vuint& vid) const + { + vgather(p0,p1,vid); + cL = !segmentLeftExists (primID.v); + cR = !segmentRightExists(primID.v); + } +#endif + + /*! gathers the cone curve starting with i'th vertex of itime'th timestep */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, size_t vid, size_t itime) const + { + gather(p0,p1,vid,itime); + cL = !segmentLeftExists (primID); + cR = !segmentRightExists(primID); + } + + /*! loads cone curve vertices for specified time */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, size_t vid, float time) const + { + gather(p0,p1,vid,time); + cL = !segmentLeftExists (primID); + cR = !segmentRightExists(primID); + } + + /*! loads cone curve vertices for specified time for mblur and non-mblur geometry */ + __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, size_t vid, float time) const + { + if (hasMotionBlur()) gather(p0,p1,cL,cR,primID,vid,time); + else gather(p0,p1,cL,cR,primID,vid); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, vbool& cL, vbool& cR, const vuint& primID, const vuint& vid, const vfloat& time) const + { + vgather(p0,p1,vid,time); + cL = !segmentLeftExists (primID.v); + cR = !segmentRightExists(primID.v); + } +#endif + + /*! gathers the curve starting with i'th vertex */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid) const + { + p0 = vertex(vid+0); + p1 = vertex(vid+1); + p2 = segmentLeftExists (primID) ? vertex(vid-1) : Vec3ff(inf); + p3 = segmentRightExists(primID) ? vertex(vid+2) : Vec3ff(inf); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, Vec4vf& p2, Vec4vf& p3, const vuint& primID, const vuint& vid) const + { + p0 = vertex(vid.v+0); + p1 = vertex(vid.v+1); + vbool left = segmentLeftExists (primID.v); + vbool right = segmentRightExists(primID.v); + vuint i2 = select(left, vid-1,vid+0); + vuint i3 = select(right,vid+2,vid+1); + p2 = vertex(i2.v); + p3 = vertex(i3.v); + p2 = select(left, p2,Vec4vf(inf)); + p3 = select(right,p3,Vec4vf(inf)); + } +#endif + + /*! gathers the curve starting with i'th vertex of itime'th timestep */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid, size_t itime) const + { + p0 = vertex(vid+0,itime); + p1 = vertex(vid+1,itime); + p2 = segmentLeftExists (primID) ? vertex(vid-1,itime) : Vec3ff(inf); + p3 = segmentRightExists(primID) ? vertex(vid+2,itime) : Vec3ff(inf); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, Vec4vf& p2, Vec4vf& p3, const vuint& primID, const vuint& vid, const vint& itime) const + { + p0 = vertex(vid.v+0, itime.v); + p1 = vertex(vid.v+1, itime.v); + vbool left = segmentLeftExists (primID.v); + vbool right = segmentRightExists(primID.v); + vuint i2 = select(left, vid-1,vid+0); + vuint i3 = select(right,vid+2,vid+1); + p2 = vertex(i2.v, itime.v); + p3 = vertex(i3.v, itime.v); + p2 = select(left, p2,Vec4vf(inf)); + p3 = select(right,p3,Vec4vf(inf)); + } +#endif + + /*! loads curve vertices for specified time */ + __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + + const float t0 = 1.0f - ftime; + const float t1 = ftime; + Vec3ff a0,a1,a2,a3; gather(a0,a1,a2,a3,primID,vid,itime); + Vec3ff b0,b1,b2,b3; gather(b0,b1,b2,b3,primID,vid,itime+1); + p0 = madd(Vec3ff(t0),a0,t1*b0); + p1 = madd(Vec3ff(t0),a1,t1*b1); + p2 = madd(Vec3ff(t0),a2,t1*b2); + p3 = madd(Vec3ff(t0),a3,t1*b3); + } + + /*! loads curve vertices for specified time for mblur and non-mblur geometry */ + __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid, float time) const + { + if (hasMotionBlur()) gather(p0,p1,p2,p3,primID,vid,time); + else gather(p0,p1,p2,p3,primID,vid); + } + +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + template + __forceinline void vgather(Vec4vf& p0, Vec4vf& p1, Vec4vf& p2, Vec4vf& p3, const vuint& primID, const vuint& vid, const vfloat& time) const + { + vfloat ftime; + const vint itime = timeSegment(time, ftime); + + const vfloat t0 = 1.0f - ftime; + const vfloat t1 = ftime; + Vec4vf a0,a1,a2,a3; vgather(a0,a1,a2,a3,primID,vid,itime); + Vec4vf b0,b1,b2,b3; vgather(b0,b1,b2,b3,primID,vid,itime+1); + p0 = madd(Vec4vf(t0),a0,t1*b0); + p1 = madd(Vec4vf(t0),a1,t1*b1); + p2 = madd(Vec4vf(t0),a2,t1*b2); + p3 = madd(Vec4vf(t0),a3,t1*b3); + } +#endif + /*! calculates bounding box of i'th line segment */ __forceinline BBox3fa bounds(const Vec3ff& v0, const Vec3ff& v1) const { @@ -183,6 +404,18 @@ namespace embree return bounds(w0,w1); } + /*! calculates bounding box of i'th segment */ + __forceinline BBox3fa bounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t i, size_t itime = 0) const + { + const float r_scale = r_scale0*scale; + const unsigned int index = segment(i); + const Vec3ff v0 = vertex(index+0,itime); + const Vec3ff v1 = vertex(index+1,itime); + const Vec3ff w0(xfmVector(space,(v0-ofs)*Vec3fa(scale)),maxRadiusScale*v0.w*r_scale); + const Vec3ff w1(xfmVector(space,(v1-ofs)*Vec3fa(scale)),maxRadiusScale*v1.w*r_scale); + return bounds(w0,w1); + } + /*! check if the i'th primitive is valid at the itime'th timestep */ __forceinline bool valid(size_t i, size_t itime) const { return valid(i, make_range(itime, itime)); @@ -193,13 +426,17 @@ namespace embree { const unsigned int index = segment(i); if (index+1 >= numVertices()) return false; - + +#if !defined(__SYCL_DEVICE_ONLY__) + for (size_t itime = itime_range.begin(); itime <= itime_range.end(); itime++) { const Vec3ff v0 = vertex(index+0,itime); if (unlikely(!isvalid4(v0))) return false; const Vec3ff v1 = vertex(index+1,itime); if (unlikely(!isvalid4(v1))) return false; if (min(v0.w,v1.w) < 0.0f) return false; } +#endif + return true; } @@ -234,6 +471,11 @@ namespace embree return LBBox3fa([&] (size_t itime) { return bounds(space, primID, itime); }, dt, time_range, fnumTimeSegments); } + /*! calculates the linear bounds of the i'th primitive for the specified time range */ + __forceinline LBBox3fa linearBounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t primID, const BBox1f& dt) const { + return LBBox3fa([&] (size_t itime) { return bounds(ofs, scale, r_scale0, space, primID, itime); }, dt, this->time_range, fnumTimeSegments); + } + /*! calculates the linear bounds of the i'th primitive for the specified time range */ __forceinline bool linearBounds(size_t i, const BBox1f& time_range, LBBox3fa& bbox) const { @@ -252,9 +494,9 @@ namespace embree BufferView vertices0; //!< fast access to first vertex buffer BufferView normals0; //!< fast access to first normal buffer BufferView flags; //!< start, end flag per segment - vector> vertices; //!< vertex array for each timestep - vector> normals; //!< normal array for each timestep - vector> vertexAttribs; //!< user buffers + Device::vector> vertices = device; //!< vertex array for each timestep + Device::vector> normals = device; //!< normal array for each timestep + Device::vector> vertexAttribs = device; //!< user buffers int tessellationRate; //!< tessellation rate for bezier curve float maxRadiusScale = 1.0; //!< maximal min-width scaling of curve radii }; @@ -266,6 +508,28 @@ namespace embree LineSegmentsISA (Device* device, Geometry::GType gtype) : LineSegments(device,gtype) {} + LinearSpace3fa computeAlignedSpace(const size_t primID) const + { + const Vec3fa dir = normalize(computeDirection(primID)); + if (is_finite(dir)) return frame(dir); + else return LinearSpace3fa(one); + } + + LinearSpace3fa computeAlignedSpaceMB(const size_t primID, const BBox1f time_range) const + { + Vec3fa axisz(0,0,1); + Vec3fa axisy(0,1,0); + + const range tbounds = this->timeSegmentRange(time_range); + if (tbounds.size() == 0) return frame(axisz); + + const size_t itime = (tbounds.begin()+tbounds.end())/2; + + const Vec3fa dir = normalize(computeDirection(primID,itime)); + if (is_finite(dir)) return frame(dir); + else return LinearSpace3fa(one); + } + Vec3fa computeDirection(unsigned int primID) const { const unsigned vtxID = segment(primID); @@ -282,7 +546,7 @@ namespace embree return v1-v0; } - PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { PrimInfo pinfo(empty); for (size_t j=r.begin(); j& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + for (size_t j = r.begin(); j < r.end(); j++) { + LBBox3fa lbounds = empty; + if (!linearBounds(j, t0t1, lbounds)) + continue; + const PrimRef prim(lbounds.bounds(), geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { PrimInfoMB pinfo(empty); @@ -331,6 +612,10 @@ namespace embree return bounds(space,i); } + BBox3fa vbounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t i, size_t itime = 0) const { + return bounds(ofs,scale,r_scale0,space,i,itime); + } + LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const { return linearBounds(primID,time_range); } @@ -338,6 +623,10 @@ namespace embree LBBox3fa vlinearBounds(const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const { return linearBounds(space,primID,time_range); } + + LBBox3fa vlinearBounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const { + return linearBounds(ofs,scale,r_scale0,space,primID,time_range); + } }; } diff --git a/thirdparty/embree/kernels/common/scene_points.h b/thirdparty/embree/kernels/common/scene_points.h index 017e098a510..937a8f1806f 100644 --- a/thirdparty/embree/kernels/common/scene_points.h +++ b/thirdparty/embree/kernels/common/scene_points.h @@ -68,6 +68,25 @@ namespace embree return vertices[itime][i]; } + /*! returns i'th vertex of for specified time */ + __forceinline Vec3ff vertex(size_t i, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + const float t0 = 1.0f - ftime; + const float t1 = ftime; + Vec3ff v0 = vertex(i, itime+0); + Vec3ff v1 = vertex(i, itime+1); + return madd(Vec3ff(t0),v0,t1*v1); + } + + /*! returns i'th vertex of for specified time */ + __forceinline Vec3ff vertex_safe(size_t i, float time) const + { + if (hasMotionBlur()) return vertex(i,time); + else return vertex(i); + } + /*! returns i'th vertex of itime'th timestep */ __forceinline const char* vertexPtr(size_t i, size_t itime) const { return vertices[itime].getPtr(i); @@ -78,11 +97,49 @@ namespace embree return normals[itime][i]; } + /*! returns i'th normal of for specified time */ + __forceinline Vec3fa normal(size_t i, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + const float t0 = 1.0f - ftime; + const float t1 = ftime; + Vec3fa n0 = normal(i, itime+0); + Vec3fa n1 = normal(i, itime+1); + return madd(Vec3fa(t0),n0,t1*n1); + } + + /*! returns i'th normal of for specified time */ + __forceinline Vec3fa normal_safe(size_t i, float time) const + { + if (hasMotionBlur()) return normal(i,time); + else return normal(i); + } + /*! returns i'th radius of itime'th timestep */ __forceinline float radius(size_t i, size_t itime) const { return vertices[itime][i].w; } + /*! returns i'th radius of for specified time */ + __forceinline float radius(size_t i, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + const float t0 = 1.0f - ftime; + const float t1 = ftime; + float r0 = radius(i, itime+0); + float r1 = radius(i, itime+1); + return madd(t0,r0,t1*r1); + } + + /*! returns i'th radius of for specified time */ + __forceinline float radius_safe(size_t i, float time) const + { + if (hasMotionBlur()) return radius(i,time); + else return radius(i); + } + /*! calculates bounding box of i'th line segment */ __forceinline BBox3fa bounds(const Vec3ff& v0) const { return enlarge(BBox3fa(v0), maxRadiusScale*Vec3fa(v0.w)); @@ -185,13 +242,18 @@ namespace embree __forceinline float * getCompactVertexArray () const { return (float*) vertices0.getPtr(); } + + __forceinline float projectedPrimitiveArea(const size_t i) const { + const float R = radius(i); + return 1 + 2*M_PI*R*R; + } public: BufferView vertices0; //!< fast access to first vertex buffer BufferView normals0; //!< fast access to first normal buffer - vector> vertices; //!< vertex array for each timestep - vector> normals; //!< normal array for each timestep - vector> vertexAttribs; //!< user buffers + Device::vector> vertices = device; //!< vertex array for each timestep + Device::vector> normals = device; //!< normal array for each timestep + Device::vector> vertexAttribs = device; //!< user buffers float maxRadiusScale = 1.0; //!< maximal min-width scaling of curve radii }; @@ -211,7 +273,7 @@ namespace embree return Vec3fa(1, 0, 0); } - PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { PrimInfo pinfo(empty); for (size_t j = r.begin(); j < r.end(); j++) { @@ -239,6 +301,23 @@ namespace embree return pinfo; } + PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + for (size_t j = r.begin(); j < r.end(); j++) { + LBBox3fa lbounds = empty; + if (!linearBounds(j, t0t1, lbounds)) + continue; + const PrimRef prim(lbounds.bounds(), geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, diff --git a/thirdparty/embree/kernels/common/scene_quad_mesh.h b/thirdparty/embree/kernels/common/scene_quad_mesh.h index bd8eeaaeb7a..09a8b8ddd95 100644 --- a/thirdparty/embree/kernels/common/scene_quad_mesh.h +++ b/thirdparty/embree/kernels/common/scene_quad_mesh.h @@ -17,12 +17,18 @@ namespace embree /*! triangle indices */ struct Quad { - uint32_t v[4]; + Quad() {} + + Quad (uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3) { + v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3; + } /*! outputs triangle indices */ __forceinline friend embree_ostream operator<<(embree_ostream cout, const Quad& q) { return cout << "Quad {" << q.v[0] << ", " << q.v[1] << ", " << q.v[2] << ", " << q.v[3] << " }"; } + + uint32_t v[4]; }; public: @@ -135,6 +141,18 @@ namespace embree return vertices[itime].getPtr(i); } + /*! returns i'th vertex of for specified time */ + __forceinline Vec3fa vertex(size_t i, float time) const + { + float ftime; + const size_t itime = timeSegment(time, ftime); + const float t0 = 1.0f - ftime; + const float t1 = ftime; + Vec3fa v0 = vertex(i, itime+0); + Vec3fa v1 = vertex(i, itime+1); + return madd(Vec3fa(t0),v0,t1*v1); + } + /*! calculates the bounds of the i'th quad */ __forceinline BBox3fa bounds(size_t i) const { @@ -196,7 +214,7 @@ namespace embree if (q.v[2] >= numVertices()) return false; if (q.v[3] >= numVertices()) return false; - for (unsigned int t=0; t quads; //!< array of quads BufferView vertices0; //!< fast access to first vertex buffer - vector> vertices; //!< vertex array for each timestep - vector> vertexAttribs; //!< vertex attribute buffers + Device::vector> vertices = device; //!< vertex array for each timestep + Device::vector vertexAttribs = device; //!< vertex attribute buffers }; namespace isa @@ -290,7 +308,11 @@ namespace embree QuadMeshISA (Device* device) : QuadMesh(device) {} - PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const + LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const { + return linearBounds(primID,time_range); + } + + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { PrimInfo pinfo(empty); for (size_t j=r.begin(); j& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + for (size_t j = r.begin(); j < r.end(); j++) { + LBBox3fa lbounds = empty; + if (!linearBounds(j, t0t1, lbounds)) + continue; + const PrimRef prim(lbounds.bounds(), geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { PrimInfoMB pinfo(empty); diff --git a/thirdparty/embree/kernels/common/scene_subdiv_mesh.h b/thirdparty/embree/kernels/common/scene_subdiv_mesh.h index 1db170196d0..b213a9b7baf 100644 --- a/thirdparty/embree/kernels/common/scene_subdiv_mesh.h +++ b/thirdparty/embree/kernels/common/scene_subdiv_mesh.h @@ -9,11 +9,13 @@ #include "../subdiv/tessellation_cache.h" #include "../subdiv/catmullclark_coefficients.h" #include "../subdiv/patch.h" -#include "../../common/algorithms/parallel_map.h" -#include "../../common/algorithms/parallel_set.h" namespace embree { + struct HoleSet; + struct VertexCreaseMap; + struct EdgeCreaseMap; + class SubdivMesh : public Geometry { ALIGNED_CLASS_(16); @@ -49,6 +51,7 @@ namespace embree /*! subdiv mesh construction */ SubdivMesh(Device* device); + ~SubdivMesh(); public: void setMask (unsigned mask); @@ -272,7 +275,7 @@ namespace embree mvector halfEdgeFace; /*! set with all holes */ - parallel_set holeSet; + std::unique_ptr holeSet; /*! fast lookup table to detect invalid faces */ mvector invalid_face; @@ -299,10 +302,10 @@ namespace embree private: /*! map with all vertex creases */ - parallel_map vertexCreaseMap; + std::unique_ptr vertexCreaseMap; /*! map with all edge creases */ - parallel_map edgeCreaseMap; + std::unique_ptr edgeCreaseMap; protected: diff --git a/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp b/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp index 3bbd7e51ae2..6cdd542a65d 100644 --- a/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp +++ b/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp @@ -134,7 +134,7 @@ namespace embree Geometry::update(); } - void TriangleMesh::commit() + void TriangleMesh::commit() { /* verify that stride of all time steps are identical */ for (unsigned int t=0; t triangles; //!< array of triangles BufferView vertices0; //!< fast access to first vertex buffer - vector> vertices; //!< vertex array for each timestep - vector vertexAttribs; //!< vertex attributes + Device::vector> vertices = device; //!< vertex array for each timestep + Device::vector vertexAttribs = device; //!< vertex attributes }; namespace isa @@ -271,7 +283,11 @@ namespace embree TriangleMeshISA (Device* device) : TriangleMesh(device) {} - PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const + LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const { + return linearBounds(primID,time_range); + } + + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { PrimInfo pinfo(empty); for (size_t j=r.begin(); j& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + for (size_t j = r.begin(); j < r.end(); j++) { + LBBox3fa lbounds = empty; + if (!linearBounds(j, t0t1, lbounds)) + continue; + const PrimRef prim(lbounds.bounds(), geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { PrimInfoMB pinfo(empty); diff --git a/thirdparty/embree/kernels/common/scene_user_geometry.h b/thirdparty/embree/kernels/common/scene_user_geometry.h index 2867b18b798..033476f658d 100644 --- a/thirdparty/embree/kernels/common/scene_user_geometry.h +++ b/thirdparty/embree/kernels/common/scene_user_geometry.h @@ -21,6 +21,8 @@ namespace embree virtual void setOccludedFunctionN (RTCOccludedFunctionN occluded); virtual void build() {} virtual void addElementsToCount (GeometryCounts & counts) const; + + __forceinline float projectedPrimitiveArea(const size_t i) const { return 0.0f; } }; namespace isa @@ -30,7 +32,7 @@ namespace embree UserGeometryISA (Device* device) : UserGeometry(device) {} - PrimInfo createPrimRefArray(mvector& prims, const range& r, size_t k, unsigned int geomID) const + PrimInfo createPrimRefArray(PrimRef* prims, const range& r, size_t k, unsigned int geomID) const { PrimInfo pinfo(empty); for (size_t j=r.begin(); j& r, size_t k, unsigned int geomID) const + { + PrimInfo pinfo(empty); + const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range); + if (t0t1.empty()) return pinfo; + + for (size_t j = r.begin(); j < r.end(); j++) { + LBBox3fa lbounds = empty; + if (!linearBounds(j, t0t1, lbounds)) + continue; + const PrimRef prim(lbounds.bounds(), geomID, unsigned(j)); + pinfo.add_center2(prim); + prims[k++] = prim; + } + return pinfo; + } + PrimInfoMB createPrimRefMBArray(mvector& prims, const BBox1f& t0t1, const range& r, size_t k, unsigned int geomID) const { PrimInfoMB pinfo(empty); diff --git a/thirdparty/embree/kernels/common/scene_verify.cpp b/thirdparty/embree/kernels/common/scene_verify.cpp new file mode 100644 index 00000000000..1db7844f4fe --- /dev/null +++ b/thirdparty/embree/kernels/common/scene_verify.cpp @@ -0,0 +1,24 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#include "scene.h" + +#include "../../common/algorithms/parallel_any_of.h" + +namespace embree +{ + +void Scene::checkIfModifiedAndSet () +{ + if (isModified ()) return; + + auto geometryIsModified = [this](size_t geomID)->bool { + return isGeometryModified(geomID); + }; + + if (parallel_any_of (size_t(0), geometries.size (), geometryIsModified)) { + setModified (); + } +} + +} \ No newline at end of file diff --git a/thirdparty/embree/kernels/common/stat.cpp b/thirdparty/embree/kernels/common/stat.cpp index ebb77cd534c..9a8c8fac4e1 100644 --- a/thirdparty/embree/kernels/common/stat.cpp +++ b/thirdparty/embree/kernels/common/stat.cpp @@ -17,7 +17,7 @@ namespace embree #endif } - void Stat::print(std::ostream& cout) + void Stat::print(embree_ostream cout) { Counters& cntrs = instance.cntrs; Counters::Data& data = instance.cntrs.code; diff --git a/thirdparty/embree/kernels/common/state.cpp b/thirdparty/embree/kernels/common/state.cpp index db6b8030418..1d73ae9629e 100644 --- a/thirdparty/embree/kernels/common/state.cpp +++ b/thirdparty/embree/kernels/common/state.cpp @@ -192,10 +192,17 @@ namespace embree const char* symbols[3] = { "=", ",", "|" }; bool State::parseFile(const FileName& fileName) - { - FILE* f = fopen(fileName.c_str(),"r"); - if (!f) return false; - Ref > file = new FileStream(f,fileName); + { + Ref > file; + // -- GODOT start -- + // try { + file = new FileStream(fileName); + // } + // catch (std::runtime_error& e) { + // (void) e; + // return false; + // } + // -- GODOT end -- std::vector syms; for (size_t i=0; iget().Identifier(); else if (tok == Token::Id("grid_accel_mb") && cin->trySymbol("=")) grid_accel_mb = cin->get().Identifier(); - + else if (tok == Token::Id("verbose") && cin->trySymbol("=")) verbose = cin->get().Int(); else if (tok == Token::Id("benchmark") && cin->trySymbol("=")) @@ -419,7 +426,7 @@ namespace embree } while (cin->trySymbol("|")); } } - + else if (tok == Token::Id("max_spatial_split_replications") && cin->trySymbol("=")) max_spatial_split_replications = cin->get().Float(); diff --git a/thirdparty/embree/kernels/common/state.h b/thirdparty/embree/kernels/common/state.h index 33bcc843b26..8c346141858 100644 --- a/thirdparty/embree/kernels/common/state.h +++ b/thirdparty/embree/kernels/common/state.h @@ -189,7 +189,7 @@ namespace embree memory_monitor_function = fptr; memory_monitor_userptr = uptr; } - + RTCMemoryMonitorFunction memory_monitor_function; void* memory_monitor_userptr; }; diff --git a/thirdparty/embree/kernels/config.h b/thirdparty/embree/kernels/config.h index 84ac27d1032..5979b543c9e 100644 --- a/thirdparty/embree/kernels/config.h +++ b/thirdparty/embree/kernels/config.h @@ -1,22 +1,26 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -/* #undef EMBREE_RAY_MASK */ -/* #undef EMBREE_STAT_COUNTERS */ -/* #undef EMBREE_BACKFACE_CULLING */ -/* #undef EMBREE_BACKFACE_CULLING_CURVES */ +#include "../include/embree4/rtcore_config.h" + +// #cmakedefine EMBREE_RAY_MASK +// #cmakedefine EMBREE_STAT_COUNTERS +// #cmakedefine EMBREE_BACKFACE_CULLING +// #cmakedefine EMBREE_BACKFACE_CULLING_CURVES +// #cmakedefine EMBREE_BACKFACE_CULLING_SPHERES #define EMBREE_FILTER_FUNCTION -/* #undef EMBREE_IGNORE_INVALID_RAYS */ +// #cmakedefine EMBREE_IGNORE_INVALID_RAYS #define EMBREE_GEOMETRY_TRIANGLE -/* #undef EMBREE_GEOMETRY_QUAD */ -/* #undef EMBREE_GEOMETRY_CURVE */ -/* #undef EMBREE_GEOMETRY_SUBDIVISION */ -/* #undef EMBREE_GEOMETRY_USER */ -/* #undef EMBREE_GEOMETRY_INSTANCE */ -/* #undef EMBREE_GEOMETRY_GRID */ -/* #undef EMBREE_GEOMETRY_POINT */ +// #cmakedefine EMBREE_GEOMETRY_QUAD +// #cmakedefine EMBREE_GEOMETRY_CURVE +// #cmakedefine EMBREE_GEOMETRY_SUBDIVISION +// #cmakedefine EMBREE_GEOMETRY_USER +// #cmakedefine EMBREE_GEOMETRY_INSTANCE +// EMBREE_GEOMETRY_INSTANCE_ARRAY is defined in rtcore_config.h +// #cmakedefine EMBREE_GEOMETRY_GRID +// #cmakedefine EMBREE_GEOMETRY_POINT #define EMBREE_RAY_PACKETS -/* #undef EMBREE_COMPACT_POLYS */ +// #cmakedefine EMBREE_COMPACT_POLYS #define EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR 2.0 #define EMBREE_DISC_POINT_SELF_INTERSECTION_AVOIDANCE @@ -69,8 +73,18 @@ #define IF_ENABLED_INSTANCE(x) #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + #define IF_ENABLED_INSTANCE_ARRAY(x) x +#else + #define IF_ENABLED_INSTANCE_ARRAY(x) +#endif + #if defined(EMBREE_GEOMETRY_GRID) #define IF_ENABLED_GRIDS(x) x #else #define IF_ENABLED_GRIDS(x) #endif + + + + diff --git a/thirdparty/embree/kernels/geometry/coneline_intersector.h b/thirdparty/embree/kernels/geometry/coneline_intersector.h index 90f3792eff4..696ea41ebc4 100644 --- a/thirdparty/embree/kernels/geometry/coneline_intersector.h +++ b/thirdparty/embree/kernels/geometry/coneline_intersector.h @@ -159,7 +159,7 @@ namespace embree template static __forceinline bool intersect(const vbool& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf& v0i, const Vec4vf& v1i, @@ -190,7 +190,7 @@ namespace embree template static __forceinline bool intersect(const vbool& valid_i, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf& v0i, const Vec4vf& v1i, diff --git a/thirdparty/embree/kernels/geometry/conelinei_intersector.h b/thirdparty/embree/kernels/geometry/conelinei_intersector.h index 6a985ebcad3..c919fe9f7bd 100644 --- a/thirdparty/embree/kernels/geometry/conelinei_intersector.h +++ b/thirdparty/embree/kernels/geometry/conelinei_intersector.h @@ -16,7 +16,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -27,7 +27,7 @@ namespace embree ConeCurveIntersector1::intersect(valid,ray,context,geom,pre,v0,v1,cL,cR,Intersect1EpilogM(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -51,7 +51,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -62,7 +62,7 @@ namespace embree ConeCurveIntersector1::intersect(valid,ray,context,geom,pre,v0,v1,cL,cR,Intersect1EpilogM(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -86,7 +86,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -97,7 +97,7 @@ namespace embree ConeCurveIntersectorK::intersect(valid,ray,k,context,geom,pre,v0,v1,cL,cR,Intersect1KEpilogM(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -115,7 +115,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -126,7 +126,7 @@ namespace embree ConeCurveIntersectorK::intersect(valid,ray,k,context,geom,pre,v0,v1,cL,cR,Intersect1KEpilogM(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); diff --git a/thirdparty/embree/kernels/geometry/curveNi_intersector.h b/thirdparty/embree/kernels/geometry/curveNi_intersector.h index c0b66515c18..137ec06d0c1 100644 --- a/thirdparty/embree/kernels/geometry/curveNi_intersector.h +++ b/thirdparty/embree/kernels/geometry/curveNi_intersector.h @@ -5,6 +5,12 @@ #include "curveNi.h" +#include "roundline_intersector.h" +#include "coneline_intersector.h" +#include "curve_intersector_ribbon.h" +#include "curve_intersector_oriented.h" +#include "curve_intersector_sweep.h" + namespace embree { namespace isa @@ -20,9 +26,14 @@ namespace embree static __forceinline vbool intersect(Ray& ray, const Primitive& prim, vfloat& tNear_o) { const size_t N = prim.N; +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + const Vec3fa offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); +#endif const Vec3fa org1 = (ray.org-offset)*scale; const Vec3fa dir1 = ray.dir*scale; @@ -50,7 +61,7 @@ namespace embree } template - static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -84,7 +95,7 @@ namespace embree } template - static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -121,7 +132,7 @@ namespace embree } template - static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -157,7 +168,7 @@ namespace embree } template - static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -196,7 +207,7 @@ namespace embree } template - static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -217,7 +228,7 @@ namespace embree } template - static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -241,7 +252,7 @@ namespace embree } template - static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -262,7 +273,7 @@ namespace embree } template - static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -297,10 +308,14 @@ namespace embree static __forceinline vbool intersect(RayK& ray, const size_t k, const Primitive& prim, vfloat& tNear_o) { const size_t N = prim.N; +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + const Vec3fa offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); - +#endif const Vec3fa ray_org(ray.org.x[k],ray.org.y[k],ray.org.z[k]); const Vec3fa ray_dir(ray.dir.x[k],ray.dir.y[k],ray.dir.z[k]); const Vec3fa org1 = (ray_org-offset)*scale; @@ -330,7 +345,7 @@ namespace embree } template - static __forceinline void intersect_t(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -364,7 +379,7 @@ namespace embree } template - static __forceinline bool occluded_t(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -401,7 +416,7 @@ namespace embree } template - static __forceinline void intersect_n(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -437,7 +452,7 @@ namespace embree } template - static __forceinline bool occluded_n(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -476,7 +491,7 @@ namespace embree } template - static __forceinline void intersect_h(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -497,7 +512,7 @@ namespace embree } template - static __forceinline bool occluded_h(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -521,7 +536,7 @@ namespace embree } template - static __forceinline void intersect_hn(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -542,7 +557,7 @@ namespace embree } template - static __forceinline bool occluded_hn(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -565,5 +580,69 @@ namespace embree return false; } }; + + __forceinline void convert_to_bezier(const Geometry::GType gtype, + Vec3ff& v0, Vec3ff& v1, Vec3ff& v2, Vec3ff& v3, + Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3) + { + const Geometry::GType basis = (Geometry::GType)(gtype & Geometry::GTY_BASIS_MASK); + const Geometry::GType stype = (Geometry::GType)(gtype & Geometry::GTY_SUBTYPE_MASK); + + if (basis == Geometry::GTY_BASIS_BSPLINE) { + BezierCurveT bezier; + convert(BSplineCurveT(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_HERMITE) { + BezierCurveT bezier; + convert(HermiteCurveT(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_CATMULL_ROM) { + BezierCurveT bezier; + convert(CatmullRomCurveT(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + + if (stype == Geometry::GTY_SUBTYPE_ORIENTED_CURVE) + { + if (basis == Geometry::GTY_BASIS_BSPLINE) { + BezierCurveT bezier; + convert(BSplineCurveT(n0,n1,n2,n3),bezier); + n0 = bezier.v0; n1 = bezier.v1; n2 = bezier.v2; n3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_HERMITE) { + BezierCurveT bezier; + convert(HermiteCurveT(n0,n1,n2,n3),bezier); + n0 = bezier.v0; n1 = bezier.v1; n2 = bezier.v2; n3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_CATMULL_ROM) { + BezierCurveT bezier; + convert(CatmullRomCurveT(n0,n1,n2,n3),bezier); + n0 = bezier.v0; n1 = bezier.v1; n2 = bezier.v2; n3 = bezier.v3; + } + } + } + + __forceinline void convert_to_bezier(const Geometry::GType gtype, Vec3ff& v0, Vec3ff& v1, Vec3ff& v2, Vec3ff& v3) + { + const Geometry::GType basis = (Geometry::GType)(gtype & Geometry::GTY_BASIS_MASK); + + if (basis == Geometry::GTY_BASIS_BSPLINE) { + BezierCurveT bezier; + convert(BSplineCurveT(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_HERMITE) { + BezierCurveT bezier; + convert(HermiteCurveT(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_CATMULL_ROM) { + BezierCurveT bezier; + convert(CatmullRomCurveT(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + } } } diff --git a/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h b/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h index bab796b33b1..4c14c2f0042 100644 --- a/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h +++ b/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h @@ -6,6 +6,12 @@ #include "curveNi_mb.h" #include "../subdiv/linear_bezier_patch.h" +#include "roundline_intersector.h" +#include "coneline_intersector.h" +#include "curve_intersector_ribbon.h" +#include "curve_intersector_oriented.h" +#include "curve_intersector_sweep.h" + namespace embree { namespace isa @@ -21,9 +27,14 @@ namespace embree static __forceinline vbool intersect(Ray& ray, const Primitive& prim, vfloat& tNear_o) { const size_t N = prim.N; +#if __SYCL_DEVICE_ONLY__ + const Vec3f offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); +#endif const Vec3fa org1 = (ray.org-offset)*scale; const Vec3fa dir1 = ray.dir*scale; @@ -73,7 +84,7 @@ namespace embree } template - static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -95,7 +106,7 @@ namespace embree } template - static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -120,7 +131,7 @@ namespace embree } template - static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -141,7 +152,7 @@ namespace embree } template - static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -166,7 +177,7 @@ namespace embree } template - static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -187,7 +198,7 @@ namespace embree } template - static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -211,7 +222,7 @@ namespace embree } template - static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -232,7 +243,7 @@ namespace embree } template - static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,prim,tNear); @@ -267,10 +278,14 @@ namespace embree static __forceinline vbool intersect(RayK& ray, const size_t k, const Primitive& prim, vfloat& tNear_o) { const size_t N = prim.N; +#if __SYCL_DEVICE_ONLY__ + const Vec3f offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); - +#endif const Vec3fa ray_org(ray.org.x[k],ray.org.y[k],ray.org.z[k]); const Vec3fa ray_dir(ray.dir.x[k],ray.dir.y[k],ray.dir.z[k]); const Vec3fa org1 = (ray_org-offset)*scale; @@ -322,7 +337,7 @@ namespace embree } template - static __forceinline void intersect_t(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; @@ -345,7 +360,7 @@ namespace embree } template - static __forceinline bool occluded_t(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -370,7 +385,7 @@ namespace embree } template - static __forceinline void intersect_n(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; @@ -393,7 +408,7 @@ namespace embree } template - static __forceinline bool occluded_n(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -419,7 +434,7 @@ namespace embree } template - static __forceinline void intersect_h(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; @@ -441,7 +456,7 @@ namespace embree } template - static __forceinline bool occluded_h(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); @@ -465,7 +480,7 @@ namespace embree } template - static __forceinline void intersect_hn(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; @@ -488,7 +503,7 @@ namespace embree } template - static __forceinline bool occluded_hn(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = intersect(ray,k,prim,tNear); diff --git a/thirdparty/embree/kernels/geometry/curveNv_intersector.h b/thirdparty/embree/kernels/geometry/curveNv_intersector.h index 2742725aeca..cfbd1a029cd 100644 --- a/thirdparty/embree/kernels/geometry/curveNv_intersector.h +++ b/thirdparty/embree/kernels/geometry/curveNv_intersector.h @@ -17,7 +17,7 @@ namespace embree typedef CurvePrecalculations1 Precalculations; template - static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = CurveNiIntersector1::intersect(ray,prim,tNear); @@ -54,7 +54,7 @@ namespace embree } template - static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = CurveNiIntersector1::intersect(ray,prim,tNear); @@ -101,7 +101,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; template - static __forceinline void intersect_t(Precalculations& pre, RayHitK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(Precalculations& pre, RayHitK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = CurveNiIntersectorK::intersect(ray,k,prim,tNear); @@ -138,7 +138,7 @@ namespace embree } template - static __forceinline bool occluded_t(Precalculations& pre, RayK& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(Precalculations& pre, RayK& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat tNear; vbool valid = CurveNiIntersectorK::intersect(ray,k,prim,tNear); diff --git a/thirdparty/embree/kernels/geometry/curve_intersector.h b/thirdparty/embree/kernels/geometry/curve_intersector.h index 1e8ac261257..a258befb5ec 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector.h @@ -24,7 +24,7 @@ namespace embree typedef CurvePrecalculations1 Precalculations; template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -34,7 +34,7 @@ namespace embree } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -50,7 +50,7 @@ namespace embree typedef unsigned char Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -60,7 +60,7 @@ namespace embree while (mask) leafIntersector.intersect(&pre,&ray,bscf(mask),context,prim); } - static __forceinline vbool occluded(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -76,7 +76,7 @@ namespace embree return valid_o; } - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -85,7 +85,7 @@ namespace embree leafIntersector.intersect(&pre,&ray,k,context,prim); } - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_distance.h b/thirdparty/embree/kernels/geometry/curve_intersector_distance.h index 748a9511a5b..80e17602890 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_distance.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_distance.h @@ -45,15 +45,56 @@ namespace embree vfloat vv; vfloat vt; }; - + template + struct DistanceCurveHit + { + enum { M = 1 }; + + __forceinline DistanceCurveHit() {} + + __forceinline DistanceCurveHit(const vbool& valid, const vfloat& U, const vfloat& V, const vfloat& T, const int i, const int N, + const NativeCurve3fa& curve3D) + : U(U), V(V), T(T), i(i), N(N), curve3D(curve3D), valid(valid) {} + + __forceinline void finalize() + { + vu = (vfloat(step)+U+vfloat(float(i)))*(1.0f/float(N)); + vv = V; + vt = T; + } + + __forceinline Vec2f uv () const { return Vec2f(vu,vv); } + __forceinline float t () const { return vt; } + __forceinline Vec3fa Ng() const { return curve3D.eval_du(vu); } + + public: + vfloat U; + vfloat V; + vfloat T; + int i, N; + NativeCurve3fa curve3D; + + public: + vbool valid; + vfloat vu; + vfloat vv; + vfloat vt; + }; + + template struct DistanceCurve1Intersector1 { + using vboolx = vbool; + using vintx = vint; + using vfloatx = vfloat; + using Vec4vfx = Vec4vf; + template - __forceinline bool intersect(const CurvePrecalculations1& pre,Ray& ray, - IntersectContext* context, + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, - const Vec3fa& v0, const Vec3fa& v1, const Vec3fa& v2, const Vec3fa& v3, + const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) { const int N = geom->tessellationRate; @@ -65,8 +106,8 @@ namespace embree /* evaluate the bezier curve */ vboolx valid = vfloatx(step) < vfloatx(float(N)); - const Vec4vfx p0 = curve2D.template eval0(0,N); - const Vec4vfx p1 = curve2D.template eval1(0,N); + const Vec4vfx p0 = curve2D.template eval0(0,N); + const Vec4vfx p1 = curve2D.template eval1(0,N); /* approximative intersection with cone */ const Vec4vfx v = p1-p0; @@ -86,19 +127,19 @@ namespace embree /* update hit information */ bool ishit = false; if (unlikely(any(valid))) { - DistanceCurveHit hit(valid,u,0.0f,t,0,N,curve3D); + DistanceCurveHit hit(valid,u,0.0f,t,0,N,curve3D); ishit = ishit | epilog(valid,hit); } - if (unlikely(VSIZEX < N)) + if (unlikely(W < N)) { /* process SIMD-size many segments per iteration */ - for (int i=VSIZEX; i(i,N); - const Vec4vfx p1 = curve2D.template eval1(i,N); + const Vec4vfx p0 = curve2D.template eval0(i,N); + const Vec4vfx p1 = curve2D.template eval1(i,N); /* approximative intersection with cone */ const Vec4vfx v = p1-p0; @@ -117,7 +158,7 @@ namespace embree /* update hit information */ if (unlikely(any(valid))) { - DistanceCurveHit hit(valid,u,0.0f,t,i,N,curve3D); + DistanceCurveHit hit(valid,u,0.0f,t,i,N,curve3D); ishit = ishit | epilog(valid,hit); } } diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h b/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h index 75532f5ae0a..cdab06ea5e4 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h @@ -14,7 +14,7 @@ namespace embree { namespace isa { - template + template struct TensorLinearCubicBezierSurfaceIntersector { const LinearSpace3fa& ray_space; @@ -235,7 +235,7 @@ namespace embree if (!clip_v(cu,cv)) return; return solve_newton_raphson(cu,cv); } - + __forceinline void solve_newton_raphson_recursion(BBox1f cu, BBox1f cv) { unsigned int sptr = 0; @@ -259,8 +259,8 @@ namespace embree if (mask) sptr++; // there are still items on the stack /* process next element recurse into each hit curve segment */ - const float u0 = float(i+0)*(1.0f/(VSIZEX-1)); - const float u1 = float(i+1)*(1.0f/(VSIZEX-1)); + const float u0 = float(i+0)*(1.0f/(N)); + const float u1 = float(i+1)*(1.0f/(N)); const BBox1f cui(lerp(cu.lower,cu.upper,u0),lerp(cu.lower,cu.upper,u1)); cu = cui; } @@ -280,28 +280,37 @@ namespace embree #endif entry: - - /* split the curve into VSIZEX-1 segments in u-direction */ - vboolx valid = true; - TensorLinearCubicBezierSurface subcurves = curve2d.clip_v(cv).vsplit_u(valid,cu); - - /* slabs test in u-direction */ - Vec2vfx ndv = cross(subcurves.axis_v()); - BBox boundsv = subcurves.vxfm(ndv).bounds(); - valid &= boundsv.lower <= eps; - valid &= boundsv.upper >= -eps; - if (none(valid)) continue; - /* slabs test in v-direction */ - Vec2vfx ndu = cross(subcurves.axis_u()); - BBox boundsu = subcurves.vxfm(ndu).bounds(); - valid &= boundsu.lower <= eps; - valid &= boundsu.upper >= -eps; - if (none(valid)) continue; + /* split the curve into N segments in u-direction */ + unsigned int mask = 0; + for (int i=0; i valid = true; + TensorLinearCubicBezierSurface> subcurves = curve2d.clip_v(cv).template vsplit_u(valid,cu,i,N); + + /* slabs test in u-direction */ + Vec2vf ndv = cross(subcurves.axis_v()); + BBox> boundsv = subcurves.template vxfm(ndv).bounds(); + valid &= boundsv.lower <= eps; + valid &= boundsv.upper >= -eps; + if (none(valid)) continue; + + /* slabs test in v-direction */ + Vec2vf ndu = cross(subcurves.axis_u()); + BBox> boundsu = subcurves.template vxfm(ndu).bounds(); + valid &= boundsu.lower <= eps; + valid &= boundsu.upper >= -eps; + if (none(valid)) continue; + + mask |= movemask(valid) << i0; + } + + if (!mask) continue; /* push valid segments to stack */ assert(sptr < stack_size); - mask_stack [sptr] = movemask(valid); + mask_stack [sptr] = mask; cu_stack [sptr] = cu; cv_stack [sptr] = cv; sptr++; @@ -318,7 +327,7 @@ namespace embree }; - template class SourceCurve> + template class SourceCurve, int N = VSIZEX-1, int V = VSIZEX> struct OrientedCurve1Intersector1 { //template using Curve = SourceCurve; @@ -329,33 +338,32 @@ namespace embree __forceinline OrientedCurve1Intersector1(const Ray& ray, const void* ptr) {} - template - __noinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + template + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0i, const Vec3ff& v1i, const Vec3ff& v2i, const Vec3ff& v3i, const Vec3fa& n0i, const Vec3fa& n1i, const Vec3fa& n2i, const Vec3fa& n3i, const Epilog& epilog) const { STAT3(normal.trav_prims,1,1,1); - SourceCurve3ff ccurve(v0i,v1i,v2i,v3i); SourceCurve3fa ncurve(n0i,n1i,n2i,n3i); ccurve = enlargeRadiusToMinWidth(context,geom,ray.org,ccurve); TensorLinearCubicBezierSurface3fa curve = TensorLinearCubicBezierSurface3fa::fromCenterAndNormalCurve(ccurve,ncurve); //return TensorLinearCubicBezierSurfaceIntersector(pre.ray_space,ray,curve,epilog).solve_bezier_clipping(); - return TensorLinearCubicBezierSurfaceIntersector(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); + return TensorLinearCubicBezierSurfaceIntersector(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); } - template - __noinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + template + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const TensorLinearCubicBezierSurface3fa& curve, const Epilog& epilog) const { STAT3(normal.trav_prims,1,1,1); //return TensorLinearCubicBezierSurfaceIntersector(pre.ray_space,ray,curve,epilog).solve_bezier_clipping(); - return TensorLinearCubicBezierSurfaceIntersector(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); + return TensorLinearCubicBezierSurfaceIntersector(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); } }; @@ -384,7 +392,7 @@ namespace embree template __forceinline bool intersect(const CurvePrecalculationsK& pre, RayK& vray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0i, const Vec3ff& v1i, const Vec3ff& v2i, const Vec3ff& v3i, const Vec3fa& n0i, const Vec3fa& n1i, const Vec3fa& n2i, const Vec3fa& n3i, @@ -402,7 +410,7 @@ namespace embree template __forceinline bool intersect(const CurvePrecalculationsK& pre, RayK& vray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const TensorLinearCubicBezierSurface3fa& curve, const Epilog& epilog) diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h b/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h index c3272e99fd2..423fd5b08d7 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h @@ -53,21 +53,23 @@ namespace embree }; /* calculate squared distance of point p0 to line p1->p2 */ - __forceinline std::pair sqr_point_line_distance(const Vec2vfx& p0, const Vec2vfx& p1, const Vec2vfx& p2) + template + __forceinline std::pair,vfloat> sqr_point_line_distance(const Vec2vf& p0, const Vec2vf& p1, const Vec2vf& p2) { - const vfloatx num = det(p2-p1,p1-p0); - const vfloatx den2 = dot(p2-p1,p2-p1); + const vfloat num = det(p2-p1,p1-p0); + const vfloat den2 = dot(p2-p1,p2-p1); return std::make_pair(num*num,den2); } /* performs culling against a cylinder */ - __forceinline vboolx cylinder_culling_test(const Vec2vfx& p0, const Vec2vfx& p1, const Vec2vfx& p2, const vfloatx& r) + template + __forceinline vbool cylinder_culling_test(const Vec2vf& p0, const Vec2vf& p1, const Vec2vf& p2, const vfloat& r) { - const std::pair d = sqr_point_line_distance(p0,p1,p2); + const std::pair,vfloat> d = sqr_point_line_distance(p0,p1,p2); return d.first <= r*r*d.second; } - template + template __forceinline bool intersect_ribbon(const Vec3fa& ray_org, const Vec3fa& ray_dir, const float ray_tnear, const float& ray_tfar, const LinearSpace3fa& ray_space, const float& depth_scale, const NativeCurve3ff& curve3D, const int N, @@ -76,89 +78,96 @@ namespace embree /* transform control points into ray space */ const NativeCurve3ff curve2D = curve3D.xfm_pr(ray_space,ray_org); float eps = 4.0f*float(ulp)*reduce_max(max(abs(curve2D.v0),abs(curve2D.v1),abs(curve2D.v2),abs(curve2D.v3))); - - /* evaluate the bezier curve */ + + int i=0; bool ishit = false; - vboolx valid = vfloatx(step) < vfloatx(float(N)); - const Vec4vfx p0 = curve2D.template eval0(0,N); - const Vec4vfx p1 = curve2D.template eval1(0,N); - valid &= cylinder_culling_test(zero,Vec2vfx(p0.x,p0.y),Vec2vfx(p1.x,p1.y),max(p0.w,p1.w)); - if (any(valid)) +#if !defined(__SYCL_DEVICE_ONLY__) { - Vec3vfx dp0dt = curve2D.template derivative0(0,N); - Vec3vfx dp1dt = curve2D.template derivative1(0,N); - dp0dt = select(reduce_max(abs(dp0dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp0dt); - dp1dt = select(reduce_max(abs(dp1dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp1dt); - const Vec3vfx n0(dp0dt.y,-dp0dt.x,0.0f); - const Vec3vfx n1(dp1dt.y,-dp1dt.x,0.0f); - const Vec3vfx nn0 = normalize(n0); - const Vec3vfx nn1 = normalize(n1); - const Vec3vfx lp0 = madd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx lp1 = madd(p1.w,nn1,Vec3vfx(p1)); - const Vec3vfx up0 = nmadd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx up1 = nmadd(p1.w,nn1,Vec3vfx(p1)); + /* evaluate the bezier curve */ + vbool valid = vfloat(step) < vfloat(float(N)); + const Vec4vf p0 = curve2D.template eval0(0,N); + const Vec4vf p1 = curve2D.template eval1(0,N); + valid &= cylinder_culling_test(zero,Vec2vf(p0.x,p0.y),Vec2vf(p1.x,p1.y),max(p0.w,p1.w)); - vfloatx vu,vv,vt; - vboolx valid0 = intersect_quad_backface_culling(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); - - if (any(valid0)) + if (any(valid)) { - /* ignore self intersections */ - if (EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR != 0.0f) { - vfloatx r = lerp(p0.w, p1.w, vu); - valid0 &= vt > float(EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR)*r*depth_scale; - } + Vec3vf dp0dt = curve2D.template derivative0(0,N); + Vec3vf dp1dt = curve2D.template derivative1(0,N); + dp0dt = select(reduce_max(abs(dp0dt)) < vfloat(eps),Vec3vf(p1-p0),dp0dt); + dp1dt = select(reduce_max(abs(dp1dt)) < vfloat(eps),Vec3vf(p1-p0),dp1dt); + const Vec3vf n0(dp0dt.y,-dp0dt.x,0.0f); + const Vec3vf n1(dp1dt.y,-dp1dt.x,0.0f); + const Vec3vf nn0 = normalize(n0); + const Vec3vf nn1 = normalize(n1); + const Vec3vf lp0 = madd(p0.w,nn0,Vec3vf(p0)); + const Vec3vf lp1 = madd(p1.w,nn1,Vec3vf(p1)); + const Vec3vf up0 = nmadd(p0.w,nn0,Vec3vf(p0)); + const Vec3vf up1 = nmadd(p1.w,nn1,Vec3vf(p1)); - if (any(valid0)) - { - vv = madd(2.0f,vv,vfloatx(-1.0f)); - RibbonHit bhit(valid0,vu,vv,vt,0,N,curve3D); - ishit |= epilog(bhit.valid,bhit); - } - } - } - - if (unlikely(VSIZEX < N)) - { - /* process SIMD-size many segments per iteration */ - for (int i=VSIZEX; i(i,N); - const Vec4vfx p1 = curve2D.template eval1(i,N); - valid &= cylinder_culling_test(zero,Vec2vfx(p0.x,p0.y),Vec2vfx(p1.x,p1.y),max(p0.w,p1.w)); - if (none(valid)) continue; + vfloat vu,vv,vt; + vbool valid0 = intersect_quad_backface_culling(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); - Vec3vfx dp0dt = curve2D.template derivative0(i,N); - Vec3vfx dp1dt = curve2D.template derivative1(i,N); - dp0dt = select(reduce_max(abs(dp0dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp0dt); - dp1dt = select(reduce_max(abs(dp1dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp1dt); - const Vec3vfx n0(dp0dt.y,-dp0dt.x,0.0f); - const Vec3vfx n1(dp1dt.y,-dp1dt.x,0.0f); - const Vec3vfx nn0 = normalize(n0); - const Vec3vfx nn1 = normalize(n1); - const Vec3vfx lp0 = madd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx lp1 = madd(p1.w,nn1,Vec3vfx(p1)); - const Vec3vfx up0 = nmadd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx up1 = nmadd(p1.w,nn1,Vec3vfx(p1)); - - vfloatx vu,vv,vt; - vboolx valid0 = intersect_quad_backface_culling(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); - if (any(valid0)) { /* ignore self intersections */ if (EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR != 0.0f) { - vfloatx r = lerp(p0.w, p1.w, vu); + vfloat r = lerp(p0.w, p1.w, vu); valid0 &= vt > float(EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR)*r*depth_scale; } if (any(valid0)) { - vv = madd(2.0f,vv,vfloatx(-1.0f)); - RibbonHit bhit(valid0,vu,vv,vt,i,N,curve3D); + vv = madd(2.0f,vv,vfloat(-1.0f)); + RibbonHit bhit(valid0,vu,vv,vt,0,N,curve3D); + ishit |= epilog(bhit.valid,bhit); + } + } + } + i += M; + } + + if (unlikely(i < N)) +#endif + { + /* process SIMD-size many segments per iteration */ + for (; i valid = vint(i)+vint(step) < vint(N); + const Vec4vf p0 = curve2D.template eval0(i,N); + const Vec4vf p1 = curve2D.template eval1(i,N); + valid &= cylinder_culling_test(zero,Vec2vf(p0.x,p0.y),Vec2vf(p1.x,p1.y),max(p0.w,p1.w)); + if (none(valid)) continue; + + Vec3vf dp0dt = curve2D.template derivative0(i,N); + Vec3vf dp1dt = curve2D.template derivative1(i,N); + dp0dt = select(reduce_max(abs(dp0dt)) < vfloat(eps),Vec3vf(p1-p0),dp0dt); + dp1dt = select(reduce_max(abs(dp1dt)) < vfloat(eps),Vec3vf(p1-p0),dp1dt); + const Vec3vf n0(dp0dt.y,-dp0dt.x,0.0f); + const Vec3vf n1(dp1dt.y,-dp1dt.x,0.0f); + const Vec3vf nn0 = normalize(n0); + const Vec3vf nn1 = normalize(n1); + const Vec3vf lp0 = madd(p0.w,nn0,Vec3vf(p0)); + const Vec3vf lp1 = madd(p1.w,nn1,Vec3vf(p1)); + const Vec3vf up0 = nmadd(p0.w,nn0,Vec3vf(p0)); + const Vec3vf up1 = nmadd(p1.w,nn1,Vec3vf(p1)); + + vfloat vu,vv,vt; + vbool valid0 = intersect_quad_backface_culling(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); + + if (any(valid0)) + { + /* ignore self intersections */ + if (EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR != 0.0f) { + vfloat r = lerp(p0.w, p1.w, vu); + valid0 &= vt > float(EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR)*r*depth_scale; + } + + if (any(valid0)) + { + vv = madd(2.0f,vv,vfloat(-1.0f)); + RibbonHit bhit(valid0,vu,vv,vt,i,N,curve3D); ishit |= epilog(bhit.valid,bhit); } } @@ -167,14 +176,14 @@ namespace embree return ishit; } - template class NativeCurve> + template class NativeCurve, int M = VSIZEX> struct RibbonCurve1Intersector1 { typedef NativeCurve NativeCurve3ff; - template + template __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -182,21 +191,21 @@ namespace embree const int N = geom->tessellationRate; NativeCurve3ff curve(v0,v1,v2,v3); curve = enlargeRadiusToMinWidth(context,geom,ray.org,curve); - return intersect_ribbon(ray.org,ray.dir,ray.tnear(),ray.tfar, + return intersect_ribbon(ray.org,ray.dir,ray.tnear(),ray.tfar, pre.ray_space,pre.depth_scale, curve,N, epilog); } }; - template class NativeCurve, int K> + template class NativeCurve, int K, int M = VSIZEX> struct RibbonCurve1IntersectorK { typedef NativeCurve NativeCurve3ff; template __forceinline bool intersect(const CurvePrecalculationsK& pre, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -206,7 +215,7 @@ namespace embree const Vec3fa ray_dir(ray.dir.x[k],ray.dir.y[k],ray.dir.z[k]); NativeCurve3ff curve(v0,v1,v2,v3); curve = enlargeRadiusToMinWidth(context,geom,ray_org,curve); - return intersect_ribbon(ray_org,ray_dir,ray.tnear()[k],ray.tfar[k], + return intersect_ribbon(ray_org,ray_dir,ray.tnear()[k],ray.tfar[k], pre.ray_space[k],pre.depth_scale[k], curve,N, epilog); diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h b/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h index ed827d583f9..5581822551b 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h @@ -14,7 +14,9 @@ namespace embree namespace isa { static const size_t numJacobianIterations = 5; -#if defined(__AVX__) +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + static const size_t numBezierSubdivisions = 2; +#elif defined(__AVX__) static const size_t numBezierSubdivisions = 2; #else static const size_t numBezierSubdivisions = 3; @@ -132,10 +134,15 @@ namespace embree return false; } +#if !defined(__SYCL_DEVICE_ONLY__) + template - bool intersect_bezier_recursive_jacobian(const Ray& ray, const float dt, const NativeCurve3ff& curve, - float u0, float u1, unsigned int depth, const Epilog& epilog) + __forceinline bool intersect_bezier_recursive_jacobian(const Ray& ray, const float dt, const NativeCurve3ff& curve, const Epilog& epilog) { + float u0 = 0.0f; + float u1 = 1.0f; + unsigned int depth = 1; + #if defined(__AVX__) enum { VSIZEX_ = 8 }; typedef vbool8 vboolx; // maximally 8-wide to work around KNL issues @@ -147,8 +154,6 @@ namespace embree typedef vint4 vintx; typedef vfloat4 vfloatx; #endif - typedef Vec3 Vec3vfx; - typedef Vec4 Vec4vfx; unsigned int maxDepth = numBezierSubdivisions; bool found = false; @@ -295,14 +300,156 @@ namespace embree return found; } +#else + + template + __forceinline bool intersect_bezier_recursive_jacobian(const Ray& ray, const float dt, const NativeCurve3ff& curve, const Epilog& epilog) + { + const Vec3fa org = zero; + const Vec3fa dir = ray.dir; + const unsigned int max_depth = 7; + + bool found = false; + + struct ShortStack + { + /* pushes both children */ + __forceinline void push() { + depth++; + } + + /* pops next node */ + __forceinline void pop() { + short_stack += (1<<(31-depth)); + depth = 31-bsf(short_stack); + } + + unsigned int depth = 0; + unsigned int short_stack = 0; + }; + + ShortStack stack; + + do + { + const float u0 = (stack.short_stack+0*(1<<(31-stack.depth)))/float(0x80000000); + const float u1 = (stack.short_stack+1*(1<<(31-stack.depth)))/float(0x80000000); + + /* subdivide bezier curve */ + Vec3ff P0, dP0du; curve.eval(u0,P0,dP0du); dP0du = dP0du * (u1-u0); + Vec3ff P3, dP3du; curve.eval(u1,P3,dP3du); dP3du = dP3du * (u1-u0); + const Vec3ff P1 = P0 + dP0du*(1.0f/3.0f); + const Vec3ff P2 = P3 - dP3du*(1.0f/3.0f); + + /* check if curve is well behaved, by checking deviation of tangents from straight line */ + const Vec3ff W = Vec3ff(P3-P0,0.0f); + const Vec3ff dQ0 = abs(3.0f*(P1-P0) - W); + const Vec3ff dQ1 = abs(3.0f*(P2-P1) - W); + const Vec3ff dQ2 = abs(3.0f*(P3-P2) - W); + const Vec3ff max_dQ = max(dQ0,dQ1,dQ2); + const float m = max(max_dQ.x,max_dQ.y,max_dQ.z); //,max_dQ.w); + const float l = length(Vec3f(W)); + const bool well_behaved = m < 0.2f*l; + + if (!well_behaved && stack.depth < max_depth) { + stack.push(); + continue; + } + + /* calculate bounding cylinders */ + const float rr1 = sqr_point_to_line_distance(Vec3f(dP0du),Vec3f(P3-P0)); + const float rr2 = sqr_point_to_line_distance(Vec3f(dP3du),Vec3f(P3-P0)); + const float maxr12 = sqrt(max(rr1,rr2)); + const float one_plus_ulp = 1.0f+2.0f*float(ulp); + const float one_minus_ulp = 1.0f-2.0f*float(ulp); + float r_outer = max(P0.w,P1.w,P2.w,P3.w)+maxr12; + float r_inner = min(P0.w,P1.w,P2.w,P3.w)-maxr12; + r_outer = one_plus_ulp*r_outer; + r_inner = max(0.0f,one_minus_ulp*r_inner); + const Cylinder cylinder_outer(Vec3f(P0),Vec3f(P3),r_outer); + const Cylinder cylinder_inner(Vec3f(P0),Vec3f(P3),r_inner); + + /* intersect with outer cylinder */ + BBox tc_outer; float u_outer0; Vec3fa Ng_outer0; float u_outer1; Vec3fa Ng_outer1; + if (!cylinder_outer.intersect(org,dir,tc_outer,u_outer0,Ng_outer0,u_outer1,Ng_outer1)) + { + stack.pop(); + continue; + } + + /* intersect with cap-planes */ + BBox tp(ray.tnear()-dt,ray.tfar-dt); + tp = embree::intersect(tp,tc_outer); + BBox h0 = HalfPlane(Vec3f(P0),+Vec3f(dP0du)).intersect(org,dir); + tp = embree::intersect(tp,h0); + BBox h1 = HalfPlane(Vec3f(P3),-Vec3f(dP3du)).intersect(org,dir); + tp = embree::intersect(tp,h1); + if (tp.lower > tp.upper) + { + stack.pop(); + continue; + } + + bool valid = true; + + /* clamp and correct u parameter */ + u_outer0 = clamp(u_outer0,float(0.0f),float(1.0f)); + u_outer1 = clamp(u_outer1,float(0.0f),float(1.0f)); + u_outer0 = lerp(u0,u1,u_outer0); + u_outer1 = lerp(u0,u1,u_outer1); + + /* intersect with inner cylinder */ + BBox tc_inner; + float u_inner0 = zero; Vec3fa Ng_inner0 = zero; float u_inner1 = zero; Vec3fa Ng_inner1 = zero; + const bool valid_inner = cylinder_inner.intersect(org,dir,tc_inner,u_inner0,Ng_inner0,u_inner1,Ng_inner1); + + /* subtract the inner interval from the current hit interval */ + BBox tp0, tp1; + subtract(tp,tc_inner,tp0,tp1); + bool valid0 = valid & (tp0.lower <= tp0.upper); + bool valid1 = valid & (tp1.lower <= tp1.upper); + if (!(valid0 | valid1)) + { + stack.pop(); + continue; + } + + /* at the unstable area we subdivide deeper */ + const bool unstable0 = valid0 && ((!valid_inner) | (abs(dot(Vec3fa(ray.dir),Ng_inner0)) < 0.3f)); + const bool unstable1 = valid1 && ((!valid_inner) | (abs(dot(Vec3fa(ray.dir),Ng_inner1)) < 0.3f)); + + if ((unstable0 | unstable1) && (stack.depth < max_depth)) { + stack.push(); + continue; + } + + if (valid0) + found |= intersect_bezier_iterative_jacobian(ray,dt,curve,u_outer0,tp0.lower,epilog); + + /* the far hit cannot be closer, thus skip if we hit entry already */ + valid1 &= tp1.lower+dt <= ray.tfar; + + /* iterate over second hit */ + if (valid1) + found |= intersect_bezier_iterative_jacobian(ray,dt,curve,u_outer1,tp1.upper,epilog); + + stack.pop(); + + } while (stack.short_stack != 0x80000000); + + return found; + } + +#endif + template class NativeCurve> struct SweepCurve1Intersector1 { typedef NativeCurve NativeCurve3ff; - template - __noinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + template + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -315,7 +462,7 @@ namespace embree const float dt = dot(curve0.center()-ray.org,ray.dir)*rcp(dot(ray.dir,ray.dir)); const Vec3ff ref(madd(Vec3fa(dt),ray.dir,ray.org),0.0f); const NativeCurve3ff curve1 = curve0-ref; - return intersect_bezier_recursive_jacobian(ray,dt,curve1,0.0f,1.0f,1,epilog); + return intersect_bezier_recursive_jacobian(ray,dt,curve1,epilog); } }; @@ -343,7 +490,7 @@ namespace embree template __forceinline bool intersect(const CurvePrecalculationsK& pre, RayK& vray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -357,7 +504,7 @@ namespace embree const float dt = dot(curve0.center()-ray.org,ray.dir)*rcp(dot(ray.dir,ray.dir)); const Vec3ff ref(madd(Vec3fa(dt),ray.dir,ray.org),0.0f); const NativeCurve3ff curve1 = curve0-ref; - return intersect_bezier_recursive_jacobian(ray,dt,curve1,0.0f,1.0f,1,epilog); + return intersect_bezier_recursive_jacobian(ray,dt,curve1,epilog); } }; } diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h b/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h index cffa8e46ad1..cbdcadac0c4 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h @@ -5,7 +5,7 @@ #include "primitive.h" #include "../subdiv/bezier_curve.h" -#include "../common/primref.h" +#include "../builders/primref.h" #include "curve_intersector_precalculations.h" #include "../bvh/node_intersector1.h" #include "../bvh/node_intersector_packet.h" @@ -37,28 +37,28 @@ namespace embree { struct VirtualCurveIntersector { - typedef void (*Intersect1Ty)(void* pre, void* ray, IntersectContext* context, const void* primitive); - typedef bool (*Occluded1Ty )(void* pre, void* ray, IntersectContext* context, const void* primitive); + typedef void (*Intersect1Ty)(void* pre, void* ray, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded1Ty )(void* pre, void* ray, RayQueryContext* context, const void* primitive); - typedef void (*Intersect4Ty)(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - typedef bool (*Occluded4Ty) (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + typedef void (*Intersect4Ty)(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded4Ty) (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); - typedef void (*Intersect8Ty)(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - typedef bool (*Occluded8Ty) (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + typedef void (*Intersect8Ty)(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded8Ty) (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); - typedef void (*Intersect16Ty)(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - typedef bool (*Occluded16Ty) (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + typedef void (*Intersect16Ty)(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded16Ty) (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); public: struct Intersectors { Intersectors() {} // WARNING: Do not zero initialize this, as we otherwise get problems with thread unsafe local static variable initialization (e.g. on VS2013) in curve_intersector_virtual.cpp. - template void intersect(void* pre, void* ray, IntersectContext* context, const void* primitive); - template bool occluded (void* pre, void* ray, IntersectContext* context, const void* primitive); + template void intersect(void* pre, void* ray, RayQueryContext* context, const void* primitive); + template bool occluded (void* pre, void* ray, RayQueryContext* context, const void* primitive); - template void intersect(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - template bool occluded (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + template void intersect(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + template bool occluded (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); public: Intersect1Ty intersect1; @@ -74,20 +74,20 @@ namespace embree Intersectors vtbl[Geometry::GTY_END]; }; - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<1> (void* pre, void* ray, IntersectContext* context, const void* primitive) { assert(intersect1); intersect1(pre,ray,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<1> (void* pre, void* ray, IntersectContext* context, const void* primitive) { assert(occluded1); return occluded1(pre,ray,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<1> (void* pre, void* ray, RayQueryContext* context, const void* primitive) { assert(intersect1); intersect1(pre,ray,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<1> (void* pre, void* ray, RayQueryContext* context, const void* primitive) { assert(occluded1); return occluded1(pre,ray,context,primitive); } - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<4>(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(intersect4); intersect4(pre,ray,k,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<4> (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(occluded4); return occluded4(pre,ray,k,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<4>(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(intersect4); intersect4(pre,ray,k,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<4> (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(occluded4); return occluded4(pre,ray,k,context,primitive); } #if defined(__AVX__) - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<8>(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(intersect8); intersect8(pre,ray,k,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<8> (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(occluded8); return occluded8(pre,ray,k,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<8>(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(intersect8); intersect8(pre,ray,k,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<8> (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(occluded8); return occluded8(pre,ray,k,context,primitive); } #endif #if defined(__AVX512F__) - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<16>(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(intersect16); intersect16(pre,ray,k,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<16> (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(occluded16); return occluded16(pre,ray,k,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<16>(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(intersect16); intersect16(pre,ray,k,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<16> (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(occluded16); return occluded16(pre,ray,k,context,primitive); } #endif namespace isa @@ -98,7 +98,7 @@ namespace embree typedef CurvePrecalculations1 Precalculations; template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -108,7 +108,7 @@ namespace embree } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -125,7 +125,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; template - static __forceinline void intersect(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -136,7 +136,7 @@ namespace embree } template - static __forceinline vbool occluded(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -153,7 +153,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -163,7 +163,7 @@ namespace embree } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); diff --git a/thirdparty/embree/kernels/geometry/disc_intersector.h b/thirdparty/embree/kernels/geometry/disc_intersector.h index ec6fa9c4f30..2997d362025 100644 --- a/thirdparty/embree/kernels/geometry/disc_intersector.h +++ b/thirdparty/embree/kernels/geometry/disc_intersector.h @@ -23,18 +23,24 @@ namespace embree __forceinline void finalize() {} - __forceinline Vec2f uv(const size_t i) const - { + __forceinline Vec2f uv(const size_t i) const { return Vec2f(vu[i], vv[i]); } - __forceinline float t(const size_t i) const - { + __forceinline Vec2vf uv() const { + return Vec2vf(vu, vv); + } + __forceinline float t(const size_t i) const { return vt[i]; } - __forceinline Vec3fa Ng(const size_t i) const - { + __forceinline vfloat t() const { + return vt; + } + __forceinline Vec3fa Ng(const size_t i) const { return Vec3fa(vNg.x[i], vNg.y[i], vNg.z[i]); } + __forceinline Vec3vf Ng() const { + return vNg; + } public: vfloat vu; @@ -43,16 +49,45 @@ namespace embree Vec3vf vNg; }; + template<> + struct DiscIntersectorHitM<1> + { + __forceinline DiscIntersectorHitM() {} + + __forceinline DiscIntersectorHitM(const float& u, const float& v, const float& t, const Vec3fa& Ng) + : vu(u), vv(v), vt(t), vNg(Ng) {} + + __forceinline void finalize() {} + + __forceinline Vec2f uv() const { + return Vec2f(vu, vv); + } + + __forceinline float t() const { + return vt; + } + + __forceinline Vec3fa Ng() const { + return vNg; + } + + public: + float vu; + float vv; + float vt; + Vec3fa vNg; + }; + template struct DiscIntersector1 { typedef CurvePrecalculations1 Precalculations; - template + template static __forceinline bool intersect( const vbool& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf& v0i, @@ -97,10 +132,10 @@ namespace embree return epilog(valid, hit); } - template + template static __forceinline bool intersect(const vbool& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf& v0i, @@ -145,7 +180,7 @@ namespace embree static __forceinline bool intersect(const vbool& valid_i, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf& v0i, @@ -194,7 +229,7 @@ namespace embree static __forceinline bool intersect(const vbool& valid_i, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf& v0i, diff --git a/thirdparty/embree/kernels/geometry/disci_intersector.h b/thirdparty/embree/kernels/geometry/disci_intersector.h index bb9d396f6ee..1ae4a663308 100644 --- a/thirdparty/embree/kernels/geometry/disci_intersector.h +++ b/thirdparty/embree/kernels/geometry/disci_intersector.h @@ -19,7 +19,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -32,7 +32,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -52,7 +52,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -65,7 +65,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -84,7 +84,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -96,7 +96,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -115,7 +115,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -127,7 +127,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -146,7 +146,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -160,7 +160,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -181,7 +181,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -195,7 +195,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -215,7 +215,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -228,7 +228,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -248,7 +248,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); @@ -261,7 +261,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(Disc.geomID()); diff --git a/thirdparty/embree/kernels/geometry/filter.h b/thirdparty/embree/kernels/geometry/filter.h index d64320bf78e..773c2bfeb85 100644 --- a/thirdparty/embree/kernels/geometry/filter.h +++ b/thirdparty/embree/kernels/geometry/filter.h @@ -12,20 +12,20 @@ namespace embree { namespace isa { - __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { if (geometry->intersectionFilterN) { - assert(context->scene->hasGeometryFilterFunction()); geometry->intersectionFilterN(args); if (args->valid[0] == 0) return false; } - - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + + if (context->getFilter()) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); if (args->valid[0] == 0) return false; @@ -35,7 +35,7 @@ namespace embree return true; } - __forceinline bool runIntersectionFilter1(const Geometry* const geometry, RayHit& ray, IntersectContext* context, Hit& hit) + __forceinline bool runIntersectionFilter1(const Geometry* const geometry, RayHit& ray, RayQueryContext* context, Hit& hit) { RTCFilterFunctionNArguments args; int mask = -1; @@ -48,39 +48,29 @@ namespace embree return runIntersectionFilter1Helper(&args,geometry,context); } - __forceinline void reportIntersection1(IntersectFunctionNArguments* args, const RTCFilterFunctionNArguments* filter_args) - { -#if defined(EMBREE_FILTER_FUNCTION) - if (args->geometry->intersectionFilterN) - args->geometry->intersectionFilterN(filter_args); - - if (args->context->filter) - args->context->filter(filter_args); -#endif - } - - __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { if (geometry->occlusionFilterN) { - assert(context->scene->hasGeometryFilterFunction()); geometry->occlusionFilterN(args); if (args->valid[0] == 0) return false; } - - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + + if (context->getFilter()) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); if (args->valid[0] == 0) return false; } + return true; } - __forceinline bool runOcclusionFilter1(const Geometry* const geometry, Ray& ray, IntersectContext* context, Hit& hit) + __forceinline bool runOcclusionFilter1(const Geometry* const geometry, Ray& ray, RayQueryContext* context, Hit& hit) { RTCFilterFunctionNArguments args; int mask = -1; @@ -93,33 +83,19 @@ namespace embree return runOcclusionFilter1Helper(&args,geometry,context); } - __forceinline void reportOcclusion1(OccludedFunctionNArguments* args, const RTCFilterFunctionNArguments* filter_args) - { -#if defined(EMBREE_FILTER_FUNCTION) - if (args->geometry->occlusionFilterN) - args->geometry->occlusionFilterN(filter_args); - - if (args->context->filter) - args->context->filter(filter_args); -#endif - } - template - __forceinline vbool runIntersectionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline vbool runIntersectionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { vint* mask = (vint*) args->valid; if (geometry->intersectionFilterN) - { - assert(context->scene->hasGeometryFilterFunction()); geometry->intersectionFilterN(args); - } - + vbool valid_o = *mask != vint(zero); if (none(valid_o)) return valid_o; - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + if (context->getFilter()) { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); } valid_o = *mask != vint(zero); @@ -130,7 +106,7 @@ namespace embree } template - __forceinline vbool runIntersectionFilter(const vbool& valid, const Geometry* const geometry, RayHitK& ray, IntersectContext* context, HitK& hit) + __forceinline vbool runIntersectionFilter(const vbool& valid, const Geometry* const geometry, RayHitK& ray, RayQueryContext* context, HitK& hit) { RTCFilterFunctionNArguments args; vint mask = valid.mask32(); @@ -144,24 +120,19 @@ namespace embree } template - __forceinline vbool runOcclusionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline vbool runOcclusionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { vint* mask = (vint*) args->valid; if (geometry->occlusionFilterN) - { - assert(context->scene->hasGeometryFilterFunction()); geometry->occlusionFilterN(args); - } - - vbool valid_o = *mask != vint(zero); + vbool valid_o = *mask != vint(zero); if (none(valid_o)) return valid_o; - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + if (context->getFilter()) { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); } - valid_o = *mask != vint(zero); RayK* ray = (RayK*) args->ray; @@ -170,7 +141,7 @@ namespace embree } template - __forceinline vbool runOcclusionFilter(const vbool& valid, const Geometry* const geometry, RayK& ray, IntersectContext* context, HitK& hit) + __forceinline vbool runOcclusionFilter(const vbool& valid, const Geometry* const geometry, RayK& ray, RayQueryContext* context, HitK& hit) { RTCFilterFunctionNArguments args; vint mask = valid.mask32(); diff --git a/thirdparty/embree/kernels/geometry/filter_sycl.h b/thirdparty/embree/kernels/geometry/filter_sycl.h new file mode 100644 index 00000000000..00f333134bd --- /dev/null +++ b/thirdparty/embree/kernels/geometry/filter_sycl.h @@ -0,0 +1,109 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../common/geometry.h" +#include "../common/ray.h" +#include "../common/hit.h" +#include "../common/context.h" + +namespace embree +{ + __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, int& mask, const Geometry* const geometry, RayQueryContext* context) + { + typedef void (*RTCFilterFunctionSYCL)(const void* args); + const RTCFeatureFlags feature_mask MAYBE_UNUSED = context->args->feature_mask; + +#if EMBREE_SYCL_GEOMETRY_CALLBACK + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY) + { + RTCFilterFunctionSYCL gfilter = (RTCFilterFunctionSYCL) geometry->intersectionFilterN; + if (gfilter) + { + gfilter(args); + + if (mask == 0) + return false; + } + } +#endif + + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS) + { + RTCFilterFunctionSYCL cfilter = (RTCFilterFunctionSYCL) context->args->filter; + if (cfilter) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + cfilter(args); + + if (mask == 0) + return false; + } + } + + return true; + } + + __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, int& mask, const Geometry* const geometry, RayQueryContext* context) + { + typedef void (*RTCFilterFunctionSYCL)(const void* args); + const RTCFeatureFlags feature_mask MAYBE_UNUSED = context->args->feature_mask; + +#if EMBREE_SYCL_GEOMETRY_CALLBACK + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY) + { + RTCFilterFunctionSYCL gfilter = (RTCFilterFunctionSYCL) geometry->occlusionFilterN; + if (gfilter) + { + gfilter(args); + + if (mask == 0) + return false; + } + } +#endif + + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS) + { + RTCFilterFunctionSYCL cfilter = (RTCFilterFunctionSYCL) context->args->filter; + if (cfilter) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + cfilter(args); + + if (mask == 0) + return false; + } + } + + return true; + } + + __forceinline bool runIntersectionFilter1SYCL(Geometry* geometry, RayHit& ray, sycl::private_ptr context, Hit& hit) + { + RTCFilterFunctionNArguments args; + int mask = -1; + args.valid = &mask; + args.geometryUserPtr = geometry->userPtr; + args.context = context->user; + args.ray = (RTCRayN*) &ray; + args.hit = (RTCHitN*) &hit; + args.N = 1; + return runIntersectionFilter1Helper(&args,mask,geometry,context); + } + + + __forceinline bool runIntersectionFilter1SYCL(Geometry* geometry, Ray& ray, sycl::private_ptr context, Hit& hit) + { + RTCFilterFunctionNArguments args; + int mask = -1; + args.valid = &mask; + args.geometryUserPtr = geometry->userPtr; + args.context = context->user; + args.ray = (RTCRayN*) &ray; + args.hit = (RTCHitN*) &hit; + args.N = 1; + return runOcclusionFilter1Helper(&args,mask,geometry,context); + } +} diff --git a/thirdparty/embree/kernels/geometry/grid_intersector.h b/thirdparty/embree/kernels/geometry/grid_intersector.h index 9c59cef119c..9837205445b 100644 --- a/thirdparty/embree/kernels/geometry/grid_intersector.h +++ b/thirdparty/embree/kernels/geometry/grid_intersector.h @@ -35,20 +35,20 @@ namespace embree typedef Grid1Precalculations Precalculations; /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersector1::intersect(pre,ray,context,prim,lazy_node); } - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { intersect(pre,ray,context,prim,ty,lazy_node); } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersector1::occluded(pre,ray,context,prim,lazy_node); } - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { return occluded(pre,ray,context,prim,ty,lazy_node); } @@ -70,22 +70,22 @@ namespace embree typedef SubdivPatch1PrecalculationsK::Precalculations> Precalculations; - static __forceinline void intersect(const vbool& valid, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK::intersect(valid,pre,ray,context,prim,lazy_node); } - static __forceinline vbool occluded(const vbool& valid, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK::occluded(valid,pre,ray,context,prim,lazy_node); } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK::intersect(pre,ray,k,context,prim,lazy_node); } - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK::occluded(pre,ray,k,context,prim,lazy_node); } diff --git a/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h b/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h index 8fbf0d4bdf2..6d56bd0404b 100644 --- a/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h +++ b/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h @@ -30,7 +30,7 @@ namespace embree template static __forceinline void intersect(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -50,7 +50,7 @@ namespace embree template static __forceinline bool occluded(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -71,7 +71,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -87,7 +87,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -112,7 +112,7 @@ namespace embree template static __forceinline void intersect(RayHit& ray, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -142,7 +142,7 @@ namespace embree template static __forceinline bool occluded(Ray& ray, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -171,7 +171,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -187,7 +187,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; diff --git a/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h b/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h index 14cacab5fea..5e5a24b7dd1 100644 --- a/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h +++ b/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h @@ -79,7 +79,7 @@ namespace embree }; /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t dim_offset = pre.grid->dim_offset; const size_t line_offset = pre.grid->width; @@ -110,7 +110,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t dim_offset = pre.grid->dim_offset; const size_t line_offset = pre.grid->width; @@ -146,7 +146,7 @@ namespace embree template static __forceinline void intersect(RayHitK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -163,7 +163,7 @@ namespace embree template static __forceinline bool occluded(RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -179,7 +179,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -194,7 +194,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -219,7 +219,7 @@ namespace embree typedef typename GridSOAIntersectorK::Precalculations Precalculations; /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { vfloat vftime; vint vitime = getTimeSegment(ray.time(), vfloat((float)(pre.grid->time_steps-1)), vftime); @@ -235,7 +235,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, const vfloat& ftime, int itime, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, const vfloat& ftime, int itime, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t grid_offset = pre.grid->gridBytes >> 2; const size_t dim_offset = pre.grid->dim_offset; @@ -279,7 +279,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { vfloat vftime; vint vitime = getTimeSegment(ray.time(), vfloat((float)(pre.grid->time_steps-1)), vftime); @@ -297,7 +297,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, const vfloat& ftime, int itime, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, const vfloat& ftime, int itime, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t grid_offset = pre.grid->gridBytes >> 2; const size_t dim_offset = pre.grid->dim_offset; @@ -347,7 +347,7 @@ namespace embree template static __forceinline void intersect(RayHitK& ray, size_t k, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -376,7 +376,7 @@ namespace embree template static __forceinline bool occluded(RayK& ray, size_t k, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -403,7 +403,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { float ftime; int itime = getTimeSegment(ray.time()[k], float(pre.grid->time_steps-1), ftime); @@ -422,7 +422,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { float ftime; int itime = getTimeSegment(ray.time()[k], float(pre.grid->time_steps-1), ftime); diff --git a/thirdparty/embree/kernels/geometry/instance_array.h b/thirdparty/embree/kernels/geometry/instance_array.h new file mode 100644 index 00000000000..fdbe79b3a89 --- /dev/null +++ b/thirdparty/embree/kernels/geometry/instance_array.h @@ -0,0 +1,85 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "primitive.h" +#include "../common/scene_instance_array.h" + +namespace embree +{ + //template + struct InstanceArrayPrimitive + { + struct Type : public PrimitiveType + { + const char* name() const; + size_t sizeActive(const char* This) const; + size_t sizeTotal(const char* This) const; + size_t getBytes(const char* This) const; + }; + static Type type; + + public: + + /* primitive supports multiple time segments */ + static const bool singleTimeSegment = false; + + /* Returns maximum number of stored primitives */ + static __forceinline size_t max_size() { return 1; } + + /* Returns required number of primitive blocks for N primitives */ + static __forceinline size_t blocks(size_t N) { return N; } + + public: + + InstanceArrayPrimitive (const uint32_t geomID, const uint32_t primID) + : primID_(primID) + , instID_(geomID) + {} + + __forceinline bool valid() const { + return primID_ != -1; + } + + void fill(const PrimRef* prims, size_t& i, size_t end, Scene* scene) + { + assert(end-i == 1); + const PrimRef& prim = prims[i]; i++; + const unsigned int geomID = prim.geomID(); + const unsigned int primID = prim.primID(); + new (this) InstanceArrayPrimitive(geomID, primID); + } + + __forceinline LBBox3fa fillMB(const PrimRef* prims, size_t& i, size_t end, Scene* scene, size_t itime) + { + assert(end-i == 1); + const PrimRef& prim = prims[i]; i++; + const unsigned int geomID = prim.geomID(); + const size_t primID = prim.primID(); + new (this) InstanceArrayPrimitive(geomID, primID); + const InstanceArray* instanceArray = scene->get(geomID); + return instanceArray->linearBounds(primID,itime); + } + + __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t& i, size_t end, Scene* scene, const BBox1f time_range) + { + assert(end-i == 1); + const PrimRefMB& prim = prims[i]; i++; + const unsigned int geomID = prim.geomID(); + const size_t primID = prim.primID(); + new (this) InstanceArrayPrimitive(geomID, primID); + const InstanceArray* instanceArray = scene->get(geomID); + return instanceArray->linearBounds(primID,time_range); + } + + /* Updates the primitive */ + __forceinline BBox3fa update(InstanceArray* instanceArray) { + return instanceArray->bounds(0); + } + + public: + unsigned int primID_; + unsigned int instID_; + }; +} diff --git a/thirdparty/embree/kernels/geometry/instance_array_intersector.h b/thirdparty/embree/kernels/geometry/instance_array_intersector.h new file mode 100644 index 00000000000..c32c8b4cdeb --- /dev/null +++ b/thirdparty/embree/kernels/geometry/instance_array_intersector.h @@ -0,0 +1,85 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "instance_array.h" +#include "../common/ray.h" +#include "../common/point_query.h" +#include "../common/scene.h" + +namespace embree +{ + namespace isa + { + struct InstanceArrayIntersector1 + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const Ray& ray, const void *ptr) {} + }; + + static void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim); + static bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim); + static bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim); + }; + + struct InstanceArrayIntersector1MB + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const Ray& ray, const void *ptr) {} + }; + + static void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim); + static bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim); + static bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim); + }; + + template + struct InstanceArrayIntersectorK + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const vbool& valid, const RayK& ray) {} + }; + + static void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& prim); + static vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& prim); + + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + intersect(vbool(1<& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + occluded(vbool(1< + struct InstanceArrayIntersectorKMB + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const vbool& valid, const RayK& ray) {} + }; + + static void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& prim); + static vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& prim); + + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + intersect(vbool(1<& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + occluded(vbool(1<& valid, const RayK& ray) {} }; - static void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& prim); - static vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& prim); + static void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& prim); + static vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& prim); - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { intersect(vbool(1<& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { occluded(vbool(1<& valid, const RayK& ray) {} }; - static void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& prim); - static vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& prim); + static void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& prim); + static vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& prim); - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { intersect(vbool(1<& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { occluded(vbool(1<user->instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user->instPrimID, ray.instPrimID); +#endif return true; } }; @@ -72,12 +75,12 @@ namespace embree struct Occluded1Epilog1 { Ray& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1Epilog1(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -117,12 +120,12 @@ namespace embree { RayHitK& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1KEpilog1(RayHitK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} @@ -163,6 +166,9 @@ namespace embree ray.primID[k] = primID; ray.geomID[k] = geomID; instance_id_stack::copy_UV(context->user->instID, ray.instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(context->user->instPrimID, ray.instPrimID, k); +#endif return true; } }; @@ -172,12 +178,12 @@ namespace embree { RayK& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1KEpilog1(RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} @@ -215,12 +221,12 @@ namespace embree struct Intersect1EpilogM { RayHit& ray; - IntersectContext* context; + RayQueryContext* context; const vuint& geomIDs; const vuint& primIDs; __forceinline Intersect1EpilogM(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const vuint& geomIDs, const vuint& primIDs) : ray(ray), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -287,6 +293,9 @@ namespace embree ray.primID = primIDs[i]; ray.geomID = geomID; instance_id_stack::copy_UU(context->user->instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user->instPrimID, ray.instPrimID); +#endif return true; } @@ -296,12 +305,12 @@ namespace embree struct Occluded1EpilogM { Ray& ray; - IntersectContext* context; + RayQueryContext* context; const vuint& geomIDs; const vuint& primIDs; __forceinline Occluded1EpilogM(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const vuint& geomIDs, const vuint& primIDs) : ray(ray), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -363,12 +372,12 @@ namespace embree struct Intersect1EpilogMU { RayHit& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1EpilogMU(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -424,6 +433,9 @@ namespace embree ray.primID = primID; ray.geomID = geomID; instance_id_stack::copy_UU(context->user->instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user->instPrimID, ray.instPrimID); +#endif return true; } }; @@ -432,12 +444,12 @@ namespace embree struct Occluded1EpilogMU { Ray& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1EpilogMU(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -477,13 +489,13 @@ namespace embree struct IntersectKEpilogM { RayHitK& ray; - IntersectContext* context; + RayQueryContext* context; const vuint& geomIDs; const vuint& primIDs; const size_t i; __forceinline IntersectKEpilogM(RayHitK& ray, - IntersectContext* context, + RayQueryContext* context, const vuint& geomIDs, const vuint& primIDs, size_t i) @@ -534,6 +546,9 @@ namespace embree vuint::store(valid,&ray.primID,primID); vuint::store(valid,&ray.geomID,geomID); instance_id_stack::copy_UV(context->user->instID, ray.instID, valid); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(context->user->instPrimID, ray.instPrimID, valid); +#endif return valid; } }; @@ -543,14 +558,14 @@ namespace embree { vbool& valid0; RayK& ray; - IntersectContext* context; + RayQueryContext* context; const vuint& geomIDs; const vuint& primIDs; const size_t i; __forceinline OccludedKEpilogM(vbool& valid0, RayK& ray, - IntersectContext* context, + RayQueryContext* context, const vuint& geomIDs, const vuint& primIDs, size_t i) @@ -598,12 +613,12 @@ namespace embree struct IntersectKEpilogMU { RayHitK& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline IntersectKEpilogMU(RayHitK& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -649,6 +664,9 @@ namespace embree vuint::store(valid,&ray.primID,primID); vuint::store(valid,&ray.geomID,geomID); instance_id_stack::copy_UV(context->user->instID, ray.instID, valid); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(context->user->instPrimID, ray.instPrimID, valid); +#endif return valid; } }; @@ -658,13 +676,13 @@ namespace embree { vbool& valid0; RayK& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline OccludedKEpilogMU(vbool& valid0, RayK& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : valid0(valid0), ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -709,12 +727,12 @@ namespace embree { RayHitK& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const vuint& geomIDs; const vuint& primIDs; __forceinline Intersect1KEpilogM(RayHitK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const vuint& geomIDs, const vuint& primIDs) : ray(ray), k(k), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -783,6 +801,9 @@ namespace embree ray.primID[k] = primIDs[i]; ray.geomID[k] = geomID; instance_id_stack::copy_UV(context->user->instID, ray.instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(context->user->instPrimID, ray.instPrimID, k); +#endif return true; } }; @@ -792,12 +813,12 @@ namespace embree { RayK& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const vuint& geomIDs; const vuint& primIDs; __forceinline Occluded1KEpilogM(RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const vuint& geomIDs, const vuint& primIDs) : ray(ray), k(k), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -860,12 +881,12 @@ namespace embree { RayHitK& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1KEpilogMU(RayHitK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} @@ -923,6 +944,9 @@ namespace embree ray.primID[k] = primID; ray.geomID[k] = geomID; instance_id_stack::copy_UV(context->user->instID, ray.instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV(context->user->instPrimID, ray.instPrimID, k); +#endif return true; } }; @@ -932,12 +956,12 @@ namespace embree { RayK& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1KEpilogMU(RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} diff --git a/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h b/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h new file mode 100644 index 00000000000..95650067387 --- /dev/null +++ b/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h @@ -0,0 +1,207 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../common/ray.h" +#include "../common/context.h" +#include "filter_sycl.h" + +namespace embree +{ + template + struct Intersect1Epilog1_HWIF; + + template<> + struct Intersect1Epilog1_HWIF + { + RayHit& ray; + sycl::private_ptr context; + const unsigned int geomID; + const unsigned int primID; + const bool filter; + + __forceinline Intersect1Epilog1_HWIF(RayHit& ray, + sycl::private_ptr context, + const unsigned int geomID, + const unsigned int primID, + const bool filter) + : ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {} + + template + __forceinline bool operator() (Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter()))) + { + Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t; + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = hit_i.t; + ray.u = hit_i.u; + ray.v = hit_i.v; + ray.Ng.x = hit_i.Ng.x; + ray.Ng.y = hit_i.Ng.y; + ray.Ng.z = hit_i.Ng.z; + ray.geomID = geomID; + ray.primID = primID; + instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID); +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID); +#endif + return true; + } + + template + __forceinline bool operator() (bool, Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + const Vec3fa Ng = hit_i.Ng(); + const Vec2f uv = hit_i.uv(); + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter()))) + { + Hit h(context->user,geomID,primID,uv,Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t(); + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = hit_i.t(); + ray.u = uv.x; + ray.v = uv.y; + ray.Ng.x = Ng.x; + ray.Ng.y = Ng.y; + ray.Ng.z = Ng.z; + ray.geomID = geomID; + ray.primID = primID; + instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID); +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID); +#endif + return true; + } + }; + + template<> + struct Intersect1Epilog1_HWIF + { + Ray& ray; + sycl::private_ptr context; + const unsigned int geomID; + const unsigned int primID; + const bool filter; + + __forceinline Intersect1Epilog1_HWIF(Ray& ray, + sycl::private_ptr context, + const unsigned int geomID, + const unsigned int primID, + const bool filter) + : ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {} + + template + __forceinline bool operator() (Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter()))) + { + Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t; + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = neg_inf; + return true; + } + + template + __forceinline bool operator() (bool, Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter()))) + { + const Vec3fa Ng = hit_i.Ng(); + const Vec2f uv = hit_i.uv(); + Hit h(context->user,geomID,primID,uv,Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t(); + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = neg_inf; + return true; + } + }; +} diff --git a/thirdparty/embree/kernels/geometry/intersector_iterators.h b/thirdparty/embree/kernels/geometry/intersector_iterators.h index 9cac1cd25ca..5c6a6a7bb03 100644 --- a/thirdparty/embree/kernels/geometry/intersector_iterators.h +++ b/thirdparty/embree/kernels/geometry/intersector_iterators.h @@ -20,14 +20,15 @@ namespace embree typedef typename Intersector::Precalculations Precalculations; template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { - for (size_t i=0; i - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { for (size_t i=0; i static __forceinline bool pointQuery(const Accel::Intersectors* This, PointQuery* query, PointQueryContext* context, const Primitive* prim, size_t num, const TravPointQuery &tquery, size_t& lazy_node) { @@ -46,12 +47,12 @@ namespace embree } template - static __forceinline void intersectK(const vbool& valid, /* PrecalculationsK& pre, */ RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersectK(const vbool& valid, /* PrecalculationsK& pre, */ RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { } template - static __forceinline vbool occludedK(const vbool& valid, /* PrecalculationsK& pre, */ RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline vbool occludedK(const vbool& valid, /* PrecalculationsK& pre, */ RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { return valid; } @@ -64,7 +65,7 @@ namespace embree typedef typename Intersector::Precalculations Precalculations; template - static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { for (size_t i=0; i - static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { vbool valid0 = valid; for (size_t i=0; i - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { for (size_t i=0; i - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { for (size_t i=0; i& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayHitK& ray, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline void intersectK(const vbool& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayHitK& ray, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(valid,ray); // FIXME: might cause trouble @@ -118,7 +119,7 @@ namespace embree } } - static __forceinline vbool occludedK(const vbool& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayK& ray, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline vbool occludedK(const vbool& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayK& ray, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(valid,ray); // FIXME: might cause trouble vbool valid0 = valid; @@ -129,7 +130,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(const Accel::Intersectors* This, RayHitK& ray, size_t k, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, RayHitK& ray, size_t k, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(ray.tnear() <= ray.tfar,ray); // FIXME: might cause trouble for (size_t i=0; i& ray, size_t k, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, RayK& ray, size_t k, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(ray.tnear() <= ray.tfar,ray); // FIXME: might cause trouble for (size_t i=0; i** __restrict__ inputPackets, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline size_t occluded(const Accel::Intersectors* This, size_t cur_mask, RayK** __restrict__ inputPackets, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { size_t m_occluded = 0; for (size_t i=0; i static __forceinline bool intersect(const vbool& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf& v0i, const Vec4vf& v1i, @@ -96,7 +96,7 @@ namespace embree template static __forceinline bool intersect(const vbool& valid_i, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf& v0i, const Vec4vf& v1i, diff --git a/thirdparty/embree/kernels/geometry/linei.h b/thirdparty/embree/kernels/geometry/linei.h index 3ee70ac0128..3305025fc91 100644 --- a/thirdparty/embree/kernels/geometry/linei.h +++ b/thirdparty/embree/kernels/geometry/linei.h @@ -457,6 +457,9 @@ namespace embree p1 = lerp(a1,b1,vfloat4(ftime)); pL = lerp(aL,bL,vfloat4(ftime)); pR = lerp(aR,bR,vfloat4(ftime)); + + pL = select(vboolf4(leftExists), pL, Vec4vf4(inf)); + pR = select(vboolf4(rightExists), pR, Vec4vf4(inf)); } #if defined(__AVX__) @@ -647,6 +650,9 @@ namespace embree p1 = lerp(a1,b1,vfloat8(ftime)); pL = lerp(aL,bL,vfloat8(ftime)); pR = lerp(aR,bR,vfloat8(ftime)); + + pL = select(vboolf4(leftExists), pL, Vec4vf8(inf)); + pR = select(vboolf4(rightExists), pR, Vec4vf8(inf)); } template<> diff --git a/thirdparty/embree/kernels/geometry/linei_intersector.h b/thirdparty/embree/kernels/geometry/linei_intersector.h index 5992827f5b5..d754cc12695 100644 --- a/thirdparty/embree/kernels/geometry/linei_intersector.h +++ b/thirdparty/embree/kernels/geometry/linei_intersector.h @@ -17,7 +17,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -26,7 +26,7 @@ namespace embree FlatLinearCurveIntersector1::intersect(valid,ray,context,geom,pre,v0,v1,Intersect1EpilogM(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -47,7 +47,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -56,7 +56,7 @@ namespace embree FlatLinearCurveIntersector1::intersect(valid,ray,context,geom,pre,v0,v1,Intersect1EpilogM(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -77,7 +77,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -86,7 +86,7 @@ namespace embree FlatLinearCurveIntersectorK::intersect(valid,ray,k,context,geom,pre,v0,v1,Intersect1KEpilogM(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -102,7 +102,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -111,7 +111,7 @@ namespace embree FlatLinearCurveIntersectorK::intersect(valid,ray,k,context,geom,pre,v0,v1,Intersect1KEpilogM(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); diff --git a/thirdparty/embree/kernels/geometry/object.h b/thirdparty/embree/kernels/geometry/object.h index 2a61829ffd2..9525b978809 100644 --- a/thirdparty/embree/kernels/geometry/object.h +++ b/thirdparty/embree/kernels/geometry/object.h @@ -62,6 +62,17 @@ namespace embree } /*! fill triangle from triangle list */ + __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t i, Scene* scene, const BBox1f time_range) + { + const PrimRefMB& prim = prims[i]; i++; + const unsigned geomID = prim.geomID(); + const unsigned primID = prim.primID(); + new (this) Object(geomID, primID); + AccelSet* accel = (AccelSet*) scene->get(geomID); + return accel->linearBounds(primID,time_range); + } + + /*! fill triangle from triangle list */ __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t& i, size_t end, Scene* scene, const BBox1f time_range) { const PrimRefMB& prim = prims[i]; i++; diff --git a/thirdparty/embree/kernels/geometry/object_intersector.h b/thirdparty/embree/kernels/geometry/object_intersector.h index e4ad01852f6..b89bc1837d4 100644 --- a/thirdparty/embree/kernels/geometry/object_intersector.h +++ b/thirdparty/embree/kernels/geometry/object_intersector.h @@ -22,7 +22,7 @@ namespace embree __forceinline Precalculations (const Ray& ray, const void *ptr) {} }; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); @@ -35,7 +35,7 @@ namespace embree accel->intersect(ray,prim.geomID(),prim.primID(),context); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); /* perform ray mask test */ @@ -47,6 +47,40 @@ namespace embree accel->occluded(ray,prim.geomID(),prim.primID(),context); return ray.tfar < 0.0f; } + + static __forceinline bool intersect(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { + return occluded(pre,ray,context,prim); + } + + static __forceinline void intersect(unsigned int k, const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) + { + AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); + + /* perform ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((ray.mask & accel->mask) == 0) + return; +#endif + + accel->intersect(k,ray,prim.geomID(),prim.primID(),context); + } + + static __forceinline bool occluded(unsigned int k, const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) + { + AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); + /* perform ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((ray.mask & accel->mask) == 0) + return false; +#endif + + accel->occluded(k, ray,prim.geomID(),prim.primID(),context); + return ray.tfar < 0.0f; + } + + static __forceinline bool intersect(unsigned int k, const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { + return occluded(k,pre,ray,context,prim); + } static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim) { @@ -57,13 +91,13 @@ namespace embree } template - static __forceinline void intersectK(const vbool& valid, /* PrecalculationsK& pre, */ RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersectK(const vbool& valid, /* PrecalculationsK& pre, */ RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(false); } template - static __forceinline vbool occludedK(const vbool& valid, /* PrecalculationsK& pre, */ RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline vbool occludedK(const vbool& valid, /* PrecalculationsK& pre, */ RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(false); return valid; @@ -79,7 +113,7 @@ namespace embree __forceinline Precalculations (const vbool& valid, const RayK& ray) {} }; - static __forceinline void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect(const vbool& valid_i, const Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& prim) { vbool valid = valid_i; AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); @@ -92,7 +126,7 @@ namespace embree accel->intersect(valid,ray,prim.geomID(),prim.primID(),context); } - static __forceinline vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& prim) + static __forceinline vbool occluded(const vbool& valid_i, const Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& prim) { vbool valid = valid_i; AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); @@ -106,11 +140,11 @@ namespace embree return ray.tfar < 0.0f; } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { intersect(vbool(1<& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& prim) { occluded(vbool(1<vertexPtr(primID(2), itime)); const vfloat4 a3 = vfloat4::loadu(geom->vertexPtr(primID(3), itime)); transpose(a0, a1, a2, a3, p0.x, p0.y, p0.z, p0.w); - const vfloat4 b0 = vfloat4(geom->normal(primID(0), itime)); - const vfloat4 b1 = vfloat4(geom->normal(primID(1), itime)); - const vfloat4 b2 = vfloat4(geom->normal(primID(2), itime)); - const vfloat4 b3 = vfloat4(geom->normal(primID(3), itime)); + const vfloat4 b0 = vfloat4(geom->normal((size_t)primID(0), (size_t)itime)); + const vfloat4 b1 = vfloat4(geom->normal((size_t)primID(1), (size_t)itime)); + const vfloat4 b2 = vfloat4(geom->normal((size_t)primID(2), (size_t)itime)); + const vfloat4 b3 = vfloat4(geom->normal((size_t)primID(3), (size_t)itime)); transpose(b0, b1, b2, b3, n0.x, n0.y, n0.z); } @@ -364,14 +364,14 @@ namespace embree const vfloat4 a6 = vfloat4::loadu(geom->vertexPtr(primID(6), itime)); const vfloat4 a7 = vfloat4::loadu(geom->vertexPtr(primID(7), itime)); transpose(a0, a1, a2, a3, a4, a5, a6, a7, p0.x, p0.y, p0.z, p0.w); - const vfloat4 b0 = vfloat4(geom->normal(primID(0), itime)); - const vfloat4 b1 = vfloat4(geom->normal(primID(1), itime)); - const vfloat4 b2 = vfloat4(geom->normal(primID(2), itime)); - const vfloat4 b3 = vfloat4(geom->normal(primID(3), itime)); - const vfloat4 b4 = vfloat4(geom->normal(primID(4), itime)); - const vfloat4 b5 = vfloat4(geom->normal(primID(5), itime)); - const vfloat4 b6 = vfloat4(geom->normal(primID(6), itime)); - const vfloat4 b7 = vfloat4(geom->normal(primID(7), itime)); + const vfloat4 b0 = vfloat4(geom->normal((size_t)primID(0), (size_t)itime)); + const vfloat4 b1 = vfloat4(geom->normal((size_t)primID(1), (size_t)itime)); + const vfloat4 b2 = vfloat4(geom->normal((size_t)primID(2), (size_t)itime)); + const vfloat4 b3 = vfloat4(geom->normal((size_t)primID(3), (size_t)itime)); + const vfloat4 b4 = vfloat4(geom->normal((size_t)primID(4), (size_t)itime)); + const vfloat4 b5 = vfloat4(geom->normal((size_t)primID(5), (size_t)itime)); + const vfloat4 b6 = vfloat4(geom->normal((size_t)primID(6), (size_t)itime)); + const vfloat4 b7 = vfloat4(geom->normal((size_t)primID(7), (size_t)itime)); transpose(b0, b1, b2, b3, b4, b5, b6, b7, n0.x, n0.y, n0.z); } diff --git a/thirdparty/embree/kernels/geometry/primitive.h b/thirdparty/embree/kernels/geometry/primitive.h index 608d981dd7a..de25ab87ef7 100644 --- a/thirdparty/embree/kernels/geometry/primitive.h +++ b/thirdparty/embree/kernels/geometry/primitive.h @@ -6,8 +6,8 @@ #include "../common/default.h" #include "../common/scene.h" #include "../../common/simd/simd.h" -#include "../common/primref.h" -#include "../common/primref_mb.h" +#include "../builders/primref.h" +#include "../builders/primref_mb.h" namespace embree { diff --git a/thirdparty/embree/kernels/geometry/primitive4.cpp b/thirdparty/embree/kernels/geometry/primitive4.cpp index 9c953c5d354..924e78bbf1e 100644 --- a/thirdparty/embree/kernels/geometry/primitive4.cpp +++ b/thirdparty/embree/kernels/geometry/primitive4.cpp @@ -15,6 +15,7 @@ #include "subdivpatch1.h" #include "object.h" #include "instance.h" +#include "instance_array.h" #include "subgrid.h" namespace embree @@ -335,6 +336,26 @@ namespace embree InstancePrimitive::Type InstancePrimitive::type; + /********************** InstanceArray4 **************************/ + + const char* InstanceArrayPrimitive::Type::name () const { + return "instance_array"; + } + + size_t InstanceArrayPrimitive::Type::sizeActive(const char* This) const { + return 1; + } + + size_t InstanceArrayPrimitive::Type::sizeTotal(const char* This) const { + return 1; + } + + size_t InstanceArrayPrimitive::Type::getBytes(const char* This) const { + return sizeof(InstanceArrayPrimitive); + } + + InstanceArrayPrimitive::Type InstanceArrayPrimitive::type; + /********************** SubGrid **************************/ const char* SubGrid::Type::name () const { diff --git a/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h b/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h index 3abc9d6f70b..2c574e4e473 100644 --- a/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h +++ b/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h @@ -122,7 +122,7 @@ namespace embree __forceinline QuadMIntersector1MoellerTrumbore(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -144,7 +144,7 @@ namespace embree } } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -215,14 +215,14 @@ namespace embree return false; } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect(ray,v0,v1,v2,v3,Intersect1EpilogM<8,filter>(ray,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { @@ -394,7 +394,7 @@ namespace embree __forceinline QuadMIntersectorKMoellerTrumbore(const vbool& valid, const RayK& ray) : QuadMIntersectorKMoellerTrumboreBase(valid,ray) {} - __forceinline void intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -403,7 +403,7 @@ namespace embree MoellerTrumboreIntersector1KTriangleM::intersect1(ray,k,v2,v3,v1,vbool(true ),epilog); } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -440,14 +440,14 @@ namespace embree return MoellerTrumboreIntersector1KTriangleM::intersect1<8,K>(ray,k,vtx0,vtx1,vtx2,flags,epilog); } - __forceinline bool intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect1(ray,k,v0,v1,v2,v3,Intersect1KEpilogM<8,K,filter>(ray,k,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { diff --git a/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h b/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h index 9873ff76acc..69d6881080a 100644 --- a/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h +++ b/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h @@ -171,7 +171,7 @@ namespace embree __forceinline QuadMIntersector1Pluecker(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -180,7 +180,7 @@ namespace embree PlueckerIntersectorTriangle1::intersect(ray,v2,v3,v1,vbool(true),epilog); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -216,13 +216,13 @@ namespace embree return PlueckerIntersectorTriangle1::intersect<8>(ray,vtx0,vtx1,vtx2,flags,epilog); } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect(ray,v0,v1,v2,v3,Intersect1EpilogM<8,filter>(ray,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect(ray,v0,v1,v2,v3,Occluded1EpilogM<8,filter>(ray,context,vuint8(geomID),vuint8(primID))); @@ -374,7 +374,7 @@ namespace embree __forceinline QuadMIntersectorKPluecker(const vbool& valid, const RayK& ray) : QuadMIntersectorKPlueckerBase(valid,ray) {} - __forceinline void intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -383,7 +383,7 @@ namespace embree PlueckerIntersector1KTriangleM::intersect1(ray,k,v2,v3,v1,vbool(true ),epilog); } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomID, const vuint& primID) const { @@ -418,14 +418,14 @@ namespace embree return PlueckerIntersector1KTriangleM::intersect1<8,K>(ray,k,vtx0,vtx1,vtx2,flags,epilog); } - __forceinline bool intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect1(ray,k,v0,v1,v2,v3,Intersect1KEpilogM<8,K,filter>(ray,k,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { diff --git a/thirdparty/embree/kernels/geometry/quadi_intersector.h b/thirdparty/embree/kernels/geometry/quadi_intersector.h index 20a98c34064..96fc77b42d5 100644 --- a/thirdparty/embree/kernels/geometry/quadi_intersector.h +++ b/thirdparty/embree/kernels/geometry/quadi_intersector.h @@ -19,7 +19,7 @@ namespace embree typedef QuadMIntersector1MoellerTrumbore Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -27,7 +27,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -48,7 +48,7 @@ namespace embree typedef QuadMIntersectorKMoellerTrumbore Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const QuadMi& quad) { Scene* scene = context->scene; for (size_t i=0; i::max_size(); i++) @@ -64,7 +64,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const QuadMi& quad) { Scene* scene = context->scene; vbool valid0 = valid_i; @@ -83,7 +83,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -91,7 +91,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -107,7 +107,7 @@ namespace embree typedef QuadMIntersector1Pluecker Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -115,7 +115,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -136,7 +136,7 @@ namespace embree typedef QuadMIntersectorKPluecker Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const QuadMi& quad) { Scene* scene = context->scene; for (size_t i=0; i::max_size(); i++) @@ -152,7 +152,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const QuadMi& quad) { Scene* scene = context->scene; vbool valid0 = valid_i; @@ -171,7 +171,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -179,7 +179,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -195,7 +195,7 @@ namespace embree typedef QuadMIntersector1MoellerTrumbore Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -203,7 +203,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -224,7 +224,7 @@ namespace embree typedef QuadMIntersectorKMoellerTrumbore Precalculations; /*! Intersects K rays with M quads. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const QuadMi& quad) { for (size_t i=0; i::max_size(); i++) { @@ -236,7 +236,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M quads. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const QuadMi& quad) { vbool valid0 = valid_i; for (size_t i=0; i::max_size(); i++) @@ -251,7 +251,7 @@ namespace embree } /*! Intersect a ray with M quads and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); @@ -259,7 +259,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M quads. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); @@ -275,7 +275,7 @@ namespace embree typedef QuadMIntersector1Pluecker Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -283,7 +283,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -304,7 +304,7 @@ namespace embree typedef QuadMIntersectorKPluecker Precalculations; /*! Intersects K rays with M quads. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const QuadMi& quad) { for (size_t i=0; i::max_size(); i++) { @@ -316,7 +316,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M quads. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const QuadMi& quad) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const QuadMi& quad) { vbool valid0 = valid_i; for (size_t i=0; i::max_size(); i++) @@ -331,7 +331,7 @@ namespace embree } /*! Intersect a ray with M quads and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); @@ -339,7 +339,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M quads. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const QuadMi& quad) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const QuadMi& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); diff --git a/thirdparty/embree/kernels/geometry/quadv_intersector.h b/thirdparty/embree/kernels/geometry/quadv_intersector.h index 9b28e05614c..9eea8275f7f 100644 --- a/thirdparty/embree/kernels/geometry/quadv_intersector.h +++ b/thirdparty/embree/kernels/geometry/quadv_intersector.h @@ -19,14 +19,14 @@ namespace embree typedef QuadMIntersector1MoellerTrumbore Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded(ray,context, quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); @@ -46,7 +46,7 @@ namespace embree typedef QuadMIntersectorKMoellerTrumbore Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const QuadMv& quad) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const QuadMv& quad) { for (size_t i=0; i::max_size(); i++) { @@ -61,7 +61,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const QuadMv& quad) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const QuadMv& quad) { vbool valid0 = valid_i; @@ -80,14 +80,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const QuadMv& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const QuadMv& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const QuadMv& quad) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const QuadMv& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); @@ -102,14 +102,14 @@ namespace embree typedef QuadMIntersector1Pluecker Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded(ray,context, quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); @@ -129,7 +129,7 @@ namespace embree typedef QuadMIntersectorKPluecker Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const QuadMv& quad) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const QuadMv& quad) { for (size_t i=0; i::max_size(); i++) { @@ -144,7 +144,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const QuadMv& quad) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const QuadMv& quad) { vbool valid0 = valid_i; @@ -163,14 +163,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const QuadMv& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const QuadMv& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const QuadMv& quad) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const QuadMv& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); diff --git a/thirdparty/embree/kernels/geometry/roundline_intersector.h b/thirdparty/embree/kernels/geometry/roundline_intersector.h index 764ff93fec2..a83dd72a7fb 100644 --- a/thirdparty/embree/kernels/geometry/roundline_intersector.h +++ b/thirdparty/embree/kernels/geometry/roundline_intersector.h @@ -661,7 +661,7 @@ namespace embree template static __forceinline bool intersect(const vbool& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf& v0i, const Vec4vf& v1i, @@ -694,7 +694,7 @@ namespace embree template static __forceinline bool intersect(const vbool& valid_i, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf& v0i, const Vec4vf& v1i, diff --git a/thirdparty/embree/kernels/geometry/roundlinei_intersector.h b/thirdparty/embree/kernels/geometry/roundlinei_intersector.h index 29061d64755..02a5d63a3d5 100644 --- a/thirdparty/embree/kernels/geometry/roundlinei_intersector.h +++ b/thirdparty/embree/kernels/geometry/roundlinei_intersector.h @@ -16,7 +16,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -25,7 +25,7 @@ namespace embree RoundLinearCurveIntersector1::intersect(valid,ray,context,geom,pre,v0,v1,vL,vR,Intersect1EpilogM(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -46,7 +46,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -55,7 +55,7 @@ namespace embree RoundLinearCurveIntersector1::intersect(valid,ray,context,geom,pre,v0,v1,vL,vR,Intersect1EpilogM(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -76,7 +76,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -85,7 +85,7 @@ namespace embree RoundLinearCurveIntersectorK::intersect(valid,ray,k,context,geom,pre,v0,v1,vL,vR,Intersect1KEpilogM(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -101,7 +101,7 @@ namespace embree typedef LineMi Primitive; typedef CurvePrecalculationsK Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); @@ -110,7 +110,7 @@ namespace embree RoundLinearCurveIntersectorK::intersect(valid,ray,k,context,geom,pre,v0,v1,vL,vR,Intersect1KEpilogM(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get(line.geomID()); diff --git a/thirdparty/embree/kernels/geometry/sphere_intersector.h b/thirdparty/embree/kernels/geometry/sphere_intersector.h index 2670f9762df..ba242a88b65 100644 --- a/thirdparty/embree/kernels/geometry/sphere_intersector.h +++ b/thirdparty/embree/kernels/geometry/sphere_intersector.h @@ -24,24 +24,60 @@ namespace embree __forceinline Vec2f uv(const size_t i) const { return Vec2f(0.0f, 0.0f); } + __forceinline Vec2vf uv() const { + return Vec2vf(0.0f, 0.0f); + } __forceinline float t(const size_t i) const { return vt[i]; } + __forceinline vfloat t() const { + return vt; + } __forceinline Vec3fa Ng(const size_t i) const { return Vec3fa(vNg.x[i], vNg.y[i], vNg.z[i]); } + __forceinline Vec3vf Ng() const { + return vNg; + } public: vfloat vt; Vec3vf vNg; }; + template<> + struct SphereIntersectorHitM<1> + { + __forceinline SphereIntersectorHitM() {} + + __forceinline SphereIntersectorHitM(const float& t, const Vec3f& Ng) + : vt(t), vNg(Ng) {} + + __forceinline void finalize() {} + + __forceinline Vec2f uv() const { + return Vec2f(0.0f, 0.0f); + } + + __forceinline float t() const { + return vt; + } + + __forceinline Vec3f Ng() const { + return vNg; + } + + public: + float vt; + Vec3f vNg; + }; + template struct SphereIntersector1 { typedef CurvePrecalculations1 Precalculations; - template + template static __forceinline bool intersect( const vbool& valid_i, Ray& ray, const Precalculations& pre, const Vec4vf& v0, const Epilog& epilog) @@ -68,10 +104,15 @@ namespace embree const vfloat t_back = projC0 + td; const vbool valid_front = valid & (ray.tnear() <= t_front) & (t_front <= ray.tfar); - const vbool valid_back = valid & (ray.tnear() <= t_back ) & (t_back <= ray.tfar); /* check if there is a first hit */ +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + /* check if there is a first hit */ + const vbool valid_first = valid_front; +#else + const vbool valid_back = valid & (ray.tnear() <= t_back ) & (t_back <= ray.tfar); const vbool valid_first = valid_front | valid_back; +#endif if (unlikely(none(valid_first))) return false; @@ -84,7 +125,10 @@ namespace embree /* invoke intersection filter for first hit */ const bool is_hit_first = epilog(valid_first, hit); - + +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + return is_hit_first; +#else /* check for possible second hits before potentially accepted hit */ const vfloat t_second = t_back; const vbool valid_second = valid_front & valid_back & (t_second <= ray.tfar); @@ -95,13 +139,13 @@ namespace embree const Vec3vf Ng_second = td_back * ray_dir - perp; hit = SphereIntersectorHitM (t_second, Ng_second); const bool is_hit_second = epilog(valid_second, hit); - return is_hit_first | is_hit_second; +#endif } template static __forceinline bool intersect( - const vbool& valid_i, Ray& ray, IntersectContext* context, const Points* geom, + const vbool& valid_i, Ray& ray, RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf& v0i, const Epilog& epilog) { const Vec3vf ray_org(ray.org.x, ray.org.y, ray.org.z); @@ -118,7 +162,7 @@ namespace embree template static __forceinline bool intersect(const vbool& valid_i, RayK& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf& v0i, @@ -148,10 +192,14 @@ namespace embree const vfloat t_back = projC0 + td; const vbool valid_front = valid & (ray.tnear()[k] <= t_front) & (t_front <= ray.tfar[k]); - const vbool valid_back = valid & (ray.tnear()[k] <= t_back ) & (t_back <= ray.tfar[k]); /* check if there is a first hit */ +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + const vbool valid_first = valid_front; +#else + const vbool valid_back = valid & (ray.tnear()[k] <= t_back ) & (t_back <= ray.tfar[k]); const vbool valid_first = valid_front | valid_back; +#endif if (unlikely(none(valid_first))) return false; @@ -164,7 +212,10 @@ namespace embree /* invoke intersection filter for first hit */ const bool is_hit_first = epilog(valid_first, hit); - + +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + return is_hit_first; +#else /* check for possible second hits before potentially accepted hit */ const vfloat t_second = t_back; const vbool valid_second = valid_front & valid_back & (t_second <= ray.tfar[k]); @@ -177,6 +228,7 @@ namespace embree const bool is_hit_second = epilog(valid_second, hit); return is_hit_first | is_hit_second; +#endif } }; } // namespace isa diff --git a/thirdparty/embree/kernels/geometry/spherei_intersector.h b/thirdparty/embree/kernels/geometry/spherei_intersector.h index 7a0b428117c..7072ea81e8e 100644 --- a/thirdparty/embree/kernels/geometry/spherei_intersector.h +++ b/thirdparty/embree/kernels/geometry/spherei_intersector.h @@ -19,7 +19,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); @@ -32,7 +32,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -59,7 +59,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); @@ -72,7 +72,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -98,7 +98,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(sphere.geomID()); @@ -110,7 +110,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(sphere.geomID()); @@ -129,7 +129,7 @@ namespace embree typedef CurvePrecalculationsK Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(sphere.geomID()); @@ -141,7 +141,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get(sphere.geomID()); diff --git a/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h b/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h index b4b15a12102..cf171271692 100644 --- a/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h +++ b/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h @@ -35,7 +35,7 @@ namespace embree typedef GridSOA Primitive; typedef SubdivPatch1Precalculations Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { lazy_node = prim->root(0); pre.grid = (Primitive*)prim; @@ -44,27 +44,27 @@ namespace embree /*! Intersect a ray with the primitive. */ template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAIntersector1::intersect(pre,ray,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { intersect(This,pre,ray,context,prim,ty,tray,lazy_node); } /*! Test if the ray is occluded by the primitive */ template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAIntersector1::occluded(pre,ray,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { return occluded(This,pre,ray,context,prim,ty,tray,lazy_node); } @@ -88,7 +88,7 @@ namespace embree typedef SubdivPatch1 Primitive; typedef GridSOAMBIntersector1::Precalculations Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim_i, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim_i, size_t& lazy_node) { Primitive* prim = (Primitive*) prim_i; GridSOA* grid = nullptr; @@ -101,27 +101,27 @@ namespace embree /*! Intersect a ray with the primitive. */ template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAMBIntersector1::intersect(pre,ray,context,prim,lazy_node); else processLazyNode(pre,ray,context,prim,lazy_node); } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { intersect(This,pre,ray,context,prim,ty,tray,lazy_node); } /*! Test if the ray is occluded by the primitive */ template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAMBIntersector1::occluded(pre,ray,context,prim,lazy_node); else return processLazyNode(pre,ray,context,prim,lazy_node); } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { return occluded(This,pre,ray,context,prim,ty,tray,lazy_node); } @@ -145,7 +145,7 @@ namespace embree typedef GridSOA Primitive; typedef SubdivPatch1PrecalculationsK::Precalculations> Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { lazy_node = prim->root(0); pre.grid = (Primitive*)prim; @@ -153,28 +153,28 @@ namespace embree } template - static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAIntersectorK::intersect(valid,pre,ray,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAIntersectorK::occluded(valid,pre,ray,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAIntersectorK::intersect(pre,ray,k,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAIntersectorK::occluded(pre,ray,k,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); @@ -192,7 +192,7 @@ namespace embree //typedef GridSOAMBIntersectorK::Precalculations Precalculations; typedef SubdivPatch1PrecalculationsK::Precalculations> Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim_i, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, RayQueryContext* context, const Primitive* prim_i, size_t& lazy_node) { Primitive* prim = (Primitive*) prim_i; GridSOA* grid = (GridSOA*) prim->root_ref.get(); @@ -202,28 +202,28 @@ namespace embree } template - static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAMBIntersectorK::intersect(valid,pre,ray,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAMBIntersectorK::occluded(valid,pre,ray,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAMBIntersectorK::intersect(pre,ray,k,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAMBIntersectorK::occluded(pre,ray,k,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); diff --git a/thirdparty/embree/kernels/geometry/subgrid.h b/thirdparty/embree/kernels/geometry/subgrid.h index ce54421cab2..f57e55db781 100644 --- a/thirdparty/embree/kernels/geometry/subgrid.h +++ b/thirdparty/embree/kernels/geometry/subgrid.h @@ -283,7 +283,7 @@ namespace embree friend embree_ostream operator<<(embree_ostream cout, const SubGrid& sg) { - return cout << "SubGrid " << " ( x " << sg.x() << ", y = " << sg.y() << ", geomID = " << sg.geomID() << ", primID = " << sg.primID() << " )"; + return cout << "SubGrid " << " ( x = " << sg.x() << ", y = " << sg.y() << ", geomID = " << sg.geomID() << ", primID = " << sg.primID() << ", invalid3x3X() " << (int)sg.invalid3x3X() << ", invalid3x3Y() " << (int)sg.invalid3x3Y(); } __forceinline unsigned int geomID() const { return _geomID; } @@ -305,9 +305,10 @@ namespace embree __forceinline SubGridID() {} __forceinline SubGridID(const unsigned int x, const unsigned int y, const unsigned int primID) : - x(x), y(y), primID(primID) {} + x(x), y(y), primID(primID) {} + }; - + /* QuantizedBaseNode as large subgrid leaf */ template struct SubGridQBVHN @@ -403,6 +404,9 @@ namespace embree typedef SubGridQBVHN<8> SubGridQBVH8; + + + /* QuantizedBaseNode as large subgrid leaf */ template struct SubGridMBQBVHN @@ -513,5 +517,4 @@ namespace embree } }; - } diff --git a/thirdparty/embree/kernels/geometry/subgrid_intersector.h b/thirdparty/embree/kernels/geometry/subgrid_intersector.h index e2410738120..561d3d43f2a 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_intersector.h +++ b/thirdparty/embree/kernels/geometry/subgrid_intersector.h @@ -23,7 +23,7 @@ namespace embree typedef SubGridQBVHN Primitive; typedef SubGridQuadMIntersector1MoellerTrumbore<4,filter> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -33,7 +33,7 @@ namespace embree pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -54,7 +54,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -76,7 +76,7 @@ namespace embree } } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -126,7 +126,7 @@ namespace embree typedef SubGridQBVHN Primitive; typedef SubGridQuadMIntersector1Pluecker<4,filter> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -136,7 +136,7 @@ namespace embree pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -156,7 +156,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -179,7 +179,7 @@ namespace embree } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -231,7 +231,7 @@ namespace embree typedef SubGridQBVHN Primitive; typedef SubGridQuadMIntersectorKMoellerTrumbore<4,K,filter> Precalculations; - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const SubGrid& subgrid) { Vec3fa vtx[16]; const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -249,7 +249,7 @@ namespace embree } } - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const SubGrid& subgrid) { vbool valid0 = valid_i; Vec3fa vtx[16]; @@ -270,7 +270,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -280,7 +280,7 @@ namespace embree pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -290,7 +290,7 @@ namespace embree } template - static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK isecK; for (size_t j=0;j - static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK isecK; vbool valid0 = valid; @@ -327,7 +327,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -347,7 +347,7 @@ namespace embree } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -375,7 +375,7 @@ namespace embree typedef SubGridQBVHN Primitive; typedef SubGridQuadMIntersectorKPluecker<4,K,filter> Precalculations; - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const SubGrid& subgrid) { Vec3fa vtx[16]; const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -393,7 +393,7 @@ namespace embree } } - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const SubGrid& subgrid) { vbool valid0 = valid_i; Vec3fa vtx[16]; @@ -414,7 +414,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -424,7 +424,7 @@ namespace embree pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -434,7 +434,7 @@ namespace embree } template - static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK isecK; for (size_t j=0;j - static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK isecK; vbool valid0 = valid; @@ -471,7 +471,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; @@ -491,7 +491,7 @@ namespace embree } template - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; diff --git a/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h b/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h index 64937d34fe6..2666847333c 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h +++ b/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h @@ -39,7 +39,7 @@ namespace embree __forceinline SubGridQuadMIntersector1MoellerTrumbore(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -65,7 +65,7 @@ namespace embree } } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -135,14 +135,14 @@ namespace embree return false; } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { return intersect(ray,v0,v1,v2,v3,g,subgrid,Intersect1EpilogMU<8,filter>(ray,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -270,7 +270,7 @@ namespace embree __forceinline SubGridQuadMIntersectorKMoellerTrumbore(const vbool& valid, const RayK& ray) : SubGridQuadMIntersectorKMoellerTrumboreBase(valid,ray) {} - __forceinline void intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity mapUV; @@ -294,7 +294,7 @@ namespace embree } } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity mapUV; @@ -361,13 +361,13 @@ namespace embree return false; } - __forceinline bool intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Intersect1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Occluded1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); diff --git a/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h b/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h index 5ded56e1f72..4919f927aec 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h +++ b/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h @@ -36,7 +36,7 @@ namespace embree __forceinline SubGridQuadMIntersector1Pluecker(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -63,7 +63,7 @@ namespace embree } } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -134,14 +134,14 @@ namespace embree return false; } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { return intersect(ray,v0,v1,v2,v3,g,subgrid,Intersect1EpilogMU<8,filter>(ray,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -255,7 +255,7 @@ namespace embree __forceinline SubGridQuadMIntersectorKPluecker(const vbool& valid, const RayK& ray) : SubGridQuadMIntersectorKPlueckerBase(valid,ray) {} - __forceinline void intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity mapUV; @@ -280,7 +280,7 @@ namespace embree } } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity mapUV; @@ -348,13 +348,13 @@ namespace embree return false; } - __forceinline bool intersect1(RayHitK& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Intersect1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded1(RayK& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Occluded1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); diff --git a/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h b/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h index 473d656e247..0986eea1349 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h +++ b/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h @@ -15,7 +15,7 @@ namespace embree typedef SubGridMBQBVHN Primitive; typedef SubGridQuadMIntersector1Pluecker<4,filter> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -27,7 +27,7 @@ namespace embree pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -46,7 +46,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; for (size_t i=0;i - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; for (size_t i=0;i Primitive; typedef SubGridQuadMIntersectorKPluecker<4,K,filter> Precalculations; - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const SubGrid& subgrid) { size_t m_valid = movemask(valid_i); while(m_valid) @@ -112,7 +112,7 @@ namespace embree } } - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const SubGrid& subgrid) { vbool valid0 = valid_i; size_t m_valid = movemask(valid_i); @@ -125,7 +125,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -137,7 +137,7 @@ namespace embree pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get(subgrid.geomID()); @@ -150,7 +150,7 @@ namespace embree } template - static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK isecK; for (size_t j=0;j - static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) + static __forceinline vbool occluded(const vbool& valid, const Accel::Intersectors* This, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK isecK; @@ -191,7 +191,7 @@ namespace embree } template - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; for (size_t i=0;i - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1 isec1; diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector.h b/thirdparty/embree/kernels/geometry/triangle_intersector.h index 2cdff78ec8a..9d9ddc7cadc 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector.h @@ -18,14 +18,14 @@ namespace embree typedef MoellerTrumboreIntersector1 Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleM& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const TriangleM& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersectEdge(ray,tri.v0,tri.e1,tri.e2,UVIdentity(),Intersect1EpilogM(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleM& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const TriangleM& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersectEdge(ray,tri.v0,tri.e1,tri.e2,UVIdentity(),Occluded1EpilogM(ray,context,tri.geomID(),tri.primID())); @@ -46,7 +46,7 @@ namespace embree typedef MoellerTrumboreIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const TriangleM& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const TriangleM& tri) { STAT_USER(0,TriangleM::max_size()); for (size_t i=0; i::max_size(); i++) @@ -61,7 +61,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const TriangleM& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const TriangleM& tri) { vbool valid0 = valid_i; @@ -79,14 +79,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const TriangleM& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const TriangleM& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersectEdge(ray,k,tri.v0,tri.e1,tri.e2,UVIdentity(),Intersect1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const TriangleM& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const TriangleM& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersectEdge(ray,k,tri.v0,tri.e1,tri.e2,UVIdentity(),Occluded1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h b/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h index 0a42d8f08b7..87bf0cd0699 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h @@ -77,18 +77,18 @@ namespace embree { /* calculate denominator */ vbool valid = valid0; + const Vec3vf O = Vec3vf((Vec3fa)ray.org); const Vec3vf D = Vec3vf((Vec3fa)ray.dir); const Vec3vf C = Vec3vf(tri_v0) - O; const Vec3vf R = cross(C,D); const vfloat den = dot(Vec3vf(tri_Ng),D); - const vfloat absDen = abs(den); const vfloat sgnDen = signmsk(den); - + /* perform edge tests */ - const vfloat U = dot(R,Vec3vf(tri_e2)) ^ sgnDen; - const vfloat V = dot(R,Vec3vf(tri_e1)) ^ sgnDen; + const vfloat U = asFloat(asInt(dot(R,Vec3vf(tri_e2))) ^ asInt(sgnDen)); + const vfloat V = asFloat(asInt(dot(R,Vec3vf(tri_e1))) ^ asInt(sgnDen)); /* perform backface culling */ #if defined(EMBREE_BACKFACE_CULLING) @@ -99,14 +99,15 @@ namespace embree if (likely(early_out && none(valid))) return false; /* perform depth test */ - const vfloat T = dot(Vec3vf(tri_Ng),C) ^ sgnDen; + const vfloat T = asFloat(asInt(dot(Vec3vf(tri_Ng),C)) ^ asInt(sgnDen)); + valid &= (absDen*vfloat(ray.tnear()) < T) & (T <= absDen*vfloat(ray.tfar)); if (likely(early_out && none(valid))) return false; /* update hit information */ new (&hit) MoellerTrumboreHitM(valid,U,V,T,absDen,tri_Ng,mapUV); - return true; + return early_out || any(valid); } template @@ -320,8 +321,7 @@ namespace embree const Vec3vf Ng = cross(e2,e1); return intersectK(valid0,ray.org,ray.dir,ray.tnear(),ray.tfar,tri_v0,e1,e2,Ng,mapUV,hit); } - - + /*! Intersects K rays with one of M triangles. */ template __forceinline vbool intersectK(const vbool& valid0, diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h b/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h index 8fbefcea88e..e21f1fa4c84 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h @@ -78,7 +78,7 @@ namespace embree /* calculate vertices relative to ray origin */ const Vec3vf O = Vec3vf((Vec3fa)ray.org); - const Vec3vf D = Vec3vf((Vec3fa)ray.dir); + const Vec3vf D = Vec3vf((Vec3fa)ray.dir); const Vec3vf v0 = tri_v0-O; const Vec3vf v1 = tri_v1-O; const Vec3vf v2 = tri_v2-O; @@ -114,7 +114,7 @@ namespace embree /* update hit information */ new (&hit) PlueckerHitM(valid,U,V,UVW,t,Ng,mapUV); - return true; + return early_out || any(valid); } template diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h b/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h index f05dcc4537e..03d23adc3d6 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h @@ -64,7 +64,7 @@ namespace embree kx = (kz+1) % 3; ky = (kx+1) % 3; const float inv_dir_kz = rcp(ray.dir[kz]); - if (ray.dir[kz]) std::swap(kx,ky); + if (ray.dir[kz] < 0.0f) std::swap(kx,ky); S.x = ray.dir[kx] * inv_dir_kz; S.y = ray.dir[ky] * inv_dir_kz; S.z = inv_dir_kz; diff --git a/thirdparty/embree/kernels/geometry/trianglei_intersector.h b/thirdparty/embree/kernels/geometry/trianglei_intersector.h index f7deb9e72d5..fa7f3ae43dd 100644 --- a/thirdparty/embree/kernels/geometry/trianglei_intersector.h +++ b/thirdparty/embree/kernels/geometry/trianglei_intersector.h @@ -18,14 +18,14 @@ namespace embree typedef TriangleMi Primitive; typedef MoellerTrumboreIntersector1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,v0,v1,v2,Intersect1EpilogM(ray,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -45,7 +45,7 @@ namespace embree typedef TriangleMi Primitive; typedef MoellerTrumboreIntersectorK Precalculations; - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& tri) { const Scene* scene = context->scene; for (size_t i=0; i occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& tri) { vbool valid0 = valid_i; const Scene* scene = context->scene; @@ -77,14 +77,14 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,k,v0,v1,v2,Intersect1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -99,14 +99,14 @@ namespace embree typedef TriangleMi Primitive; typedef PlueckerIntersector1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,v0,v1,v2,Intersect1EpilogM(ray,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -126,7 +126,7 @@ namespace embree typedef TriangleMi Primitive; typedef PlueckerIntersectorK Precalculations; - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& tri) { const Scene* scene = context->scene; for (size_t i=0; i occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& tri) { vbool valid0 = valid_i; const Scene* scene = context->scene; @@ -158,14 +158,14 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,k,v0,v1,v2,Intersect1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -181,7 +181,7 @@ namespace embree typedef MoellerTrumboreIntersector1 Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -189,7 +189,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -210,7 +210,7 @@ namespace embree typedef MoellerTrumboreIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const TriangleMi& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const TriangleMi& tri) { for (size_t i=0; i::max_size(); i++) { @@ -222,7 +222,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const TriangleMi& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const TriangleMi& tri) { vbool valid0 = valid_i; for (size_t i=0; i::max_size(); i++) @@ -237,7 +237,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const TriangleMi& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const TriangleMi& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); @@ -245,7 +245,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const TriangleMi& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const TriangleMi& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); @@ -261,7 +261,7 @@ namespace embree typedef PlueckerIntersector1 Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -269,7 +269,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -290,7 +290,7 @@ namespace embree typedef PlueckerIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const TriangleMi& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const TriangleMi& tri) { for (size_t i=0; i::max_size(); i++) { @@ -302,7 +302,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const TriangleMi& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const TriangleMi& tri) { vbool valid0 = valid_i; for (size_t i=0; i::max_size(); i++) @@ -317,7 +317,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const TriangleMi& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const TriangleMi& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); @@ -325,7 +325,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const TriangleMi& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const TriangleMi& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); diff --git a/thirdparty/embree/kernels/geometry/trianglev_intersector.h b/thirdparty/embree/kernels/geometry/trianglev_intersector.h index 3abb7f8e324..0575bad388e 100644 --- a/thirdparty/embree/kernels/geometry/trianglev_intersector.h +++ b/thirdparty/embree/kernels/geometry/trianglev_intersector.h @@ -20,14 +20,14 @@ namespace embree typedef MoellerTrumboreIntersector1 Precalculations; /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,tri.v0,tri.v1,tri.v2,/*UVIdentity(),*/Intersect1EpilogM(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,tri.v0,tri.v1,tri.v2,/*UVIdentity(),*/Occluded1EpilogM(ray,context,tri.geomID(),tri.primID())); @@ -48,14 +48,14 @@ namespace embree typedef WoopPrecalculations1 Precalculations; /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); intersec::intersect(ray,pre,tri.v0,tri.v1,tri.v2,Intersect1EpilogM(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return intersec::intersect(ray,pre,tri.v0,tri.v1,tri.v2,Occluded1EpilogM(ray,context,tri.geomID(),tri.primID())); @@ -76,7 +76,7 @@ namespace embree typedef MoellerTrumboreIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& tri) { for (size_t i=0; i occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& tri) { vbool valid0 = valid_i; @@ -108,14 +108,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,/*UVIdentity(),*/Intersect1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); //FIXME: M } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,/*UVIdentity(),*/Occluded1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); //FIXME: M @@ -130,14 +130,14 @@ namespace embree typedef PlueckerIntersector1 Precalculations; /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,tri.v0,tri.v1,tri.v2,UVIdentity(),Intersect1EpilogM(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,tri.v0,tri.v1,tri.v2,UVIdentity(),Occluded1EpilogM(ray,context,tri.geomID(),tri.primID())); @@ -157,7 +157,7 @@ namespace embree typedef PlueckerIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const Primitive& tri) { for (size_t i=0; i occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const Primitive& tri) { vbool valid0 = valid_i; @@ -189,14 +189,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,UVIdentity(),Intersect1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,UVIdentity(),Occluded1KEpilogM(ray,k,context,tri.geomID(),tri.primID())); diff --git a/thirdparty/embree/kernels/geometry/trianglev_mb.h b/thirdparty/embree/kernels/geometry/trianglev_mb.h index b550a29fd5b..c15313f209c 100644 --- a/thirdparty/embree/kernels/geometry/trianglev_mb.h +++ b/thirdparty/embree/kernels/geometry/trianglev_mb.h @@ -113,7 +113,6 @@ namespace embree BBox3fa bounds0 = empty; BBox3fa bounds1 = empty; - for (size_t i=0; iget(geomID); const TriangleMesh::Triangle& tri = mesh->triangle(primID); - const Vec3fa& a0 = mesh->vertex(tri.v[0],itime+0); bounds0.extend(a0); - const Vec3fa& a1 = mesh->vertex(tri.v[0],itime+1); bounds1.extend(a1); - const Vec3fa& b0 = mesh->vertex(tri.v[1],itime+0); bounds0.extend(b0); - const Vec3fa& b1 = mesh->vertex(tri.v[1],itime+1); bounds1.extend(b1); - const Vec3fa& c0 = mesh->vertex(tri.v[2],itime+0); bounds0.extend(c0); - const Vec3fa& c1 = mesh->vertex(tri.v[2],itime+1); bounds1.extend(c1); + const Vec3fa& a0 = mesh->vertex(tri.v[0],size_t(itime+0)); bounds0.extend(a0); + const Vec3fa& a1 = mesh->vertex(tri.v[0],size_t(itime+1)); bounds1.extend(a1); + const Vec3fa& b0 = mesh->vertex(tri.v[1],size_t(itime+0)); bounds0.extend(b0); + const Vec3fa& b1 = mesh->vertex(tri.v[1],size_t(itime+1)); bounds1.extend(b1); + const Vec3fa& c0 = mesh->vertex(tri.v[2],size_t(itime+0)); bounds0.extend(c0); + const Vec3fa& c1 = mesh->vertex(tri.v[2],size_t(itime+1)); bounds1.extend(c1); vgeomID [i] = geomID; vprimID [i] = primID; va0.x[i] = a0.x; va0.y[i] = a0.y; va0.z[i] = a0.z; @@ -159,12 +158,12 @@ namespace embree const int ilower = itime_range.begin(); const TriangleMesh::Triangle& tri = mesh->triangle(primID); allBounds.extend(mesh->linearBounds(primID, time_range)); - const Vec3fa& a0 = mesh->vertex(tri.v[0],ilower+0); - const Vec3fa& a1 = mesh->vertex(tri.v[0],ilower+1); - const Vec3fa& b0 = mesh->vertex(tri.v[1],ilower+0); - const Vec3fa& b1 = mesh->vertex(tri.v[1],ilower+1); - const Vec3fa& c0 = mesh->vertex(tri.v[2],ilower+0); - const Vec3fa& c1 = mesh->vertex(tri.v[2],ilower+1); + const Vec3fa& a0 = mesh->vertex(tri.v[0],size_t(ilower+0)); + const Vec3fa& a1 = mesh->vertex(tri.v[0],size_t(ilower+1)); + const Vec3fa& b0 = mesh->vertex(tri.v[1],size_t(ilower+0)); + const Vec3fa& b1 = mesh->vertex(tri.v[1],size_t(ilower+1)); + const Vec3fa& c0 = mesh->vertex(tri.v[2],size_t(ilower+0)); + const Vec3fa& c1 = mesh->vertex(tri.v[2],size_t(ilower+1)); const BBox1f time_range_v(mesh->timeStep(ilower+0),mesh->timeStep(ilower+1)); auto a01 = globalLinear(std::make_pair(a0,a1),time_range_v); auto b01 = globalLinear(std::make_pair(b0,b1),time_range_v); diff --git a/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h b/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h index 38cd52e85d7..c9042ba323e 100644 --- a/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h +++ b/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h @@ -18,7 +18,7 @@ namespace embree typedef MoellerTrumboreIntersector1 Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf time(ray.time()); @@ -29,7 +29,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf time(ray.time()); @@ -53,7 +53,7 @@ namespace embree typedef MoellerTrumboreIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const TriangleMvMB& tri) { for (size_t i=0; i::max_size(); i++) { @@ -68,7 +68,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const TriangleMvMB& tri) { vbool valid0 = valid_i; @@ -87,7 +87,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf time(ray.time()[k]); @@ -98,7 +98,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf time(ray.time()[k]); @@ -117,7 +117,7 @@ namespace embree typedef PlueckerIntersector1 Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf time(ray.time()); @@ -128,7 +128,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf time(ray.time()); @@ -152,7 +152,7 @@ namespace embree typedef PlueckerIntersectorK Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline void intersect(const vbool& valid_i, Precalculations& pre, RayHitK& ray, RayQueryContext* context, const TriangleMvMB& tri) { for (size_t i=0; i::max_size(); i++) { @@ -167,7 +167,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline vbool occluded(const vbool& valid_i, Precalculations& pre, RayK& ray, RayQueryContext* context, const TriangleMvMB& tri) { vbool valid0 = valid_i; @@ -186,7 +186,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK& ray, size_t k, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf time(ray.time()[k]); @@ -197,7 +197,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, IntersectContext* context, const TriangleMvMB& tri) + static __forceinline bool occluded(Precalculations& pre, RayK& ray, size_t k, RayQueryContext* context, const TriangleMvMB& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf time(ray.time()[k]); diff --git a/thirdparty/embree/kernels/hash.h b/thirdparty/embree/kernels/hash.h index 39d50e2354b..ec9759ee352 100644 --- a/thirdparty/embree/kernels/hash.h +++ b/thirdparty/embree/kernels/hash.h @@ -1,4 +1,4 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#define RTC_HASH "698442324ccddd11725fb8875275dc1384f7fb40" +#define RTC_HASH "daa8de0e714e18ad5e5c9841b67c1950d9c91c51" diff --git a/thirdparty/embree/kernels/subdiv/bezier_curve.h b/thirdparty/embree/kernels/subdiv/bezier_curve.h index a5adad5cc90..257e0afd404 100644 --- a/thirdparty/embree/kernels/subdiv/bezier_curve.h +++ b/thirdparty/embree/kernels/subdiv/bezier_curve.h @@ -185,9 +185,10 @@ namespace embree __forceinline CubicBezierCurve xfm(const Vertex& dx) const { return CubicBezierCurve(dot(v0,dx),dot(v1,dx),dot(v2,dx),dot(v3,dx)); } - - __forceinline CubicBezierCurve vxfm(const Vertex& dx) const { - return CubicBezierCurve(dot(v0,dx),dot(v1,dx),dot(v2,dx),dot(v3,dx)); + + template + __forceinline CubicBezierCurve> vxfm(const Vertex& dx) const { + return CubicBezierCurve>(dot(v0,dx),dot(v1,dx),dot(v2,dx),dot(v3,dx)); } __forceinline CubicBezierCurve xfm(const Vertex& dx, const Vertex& p) const { @@ -286,7 +287,7 @@ namespace embree { const float u0 = 0.0f, u1 = 1.0f; const float dscale = (u1-u0)*(1.0f/(3.0f*(VSIZEX-1))); - const vfloatx vu0 = lerp(u0,u1,vfloatx(step)*(1.0f/(VSIZEX-1))); + const vfloatx vu0 = lerp(u0,u1,vfloatx(StepTy())*(1.0f/(VSIZEX-1))); Vec2vfx P0, dP0du; evalN(vu0,P0,dP0du); dP0du = dP0du * Vec2vfx(dscale); const Vec2vfx P3 = shift_right_1(P0); const Vec2vfx dP3du = shift_right_1(dP0du); @@ -299,7 +300,7 @@ namespace embree { const float u0 = u.lower, u1 = u.upper; const float dscale = (u1-u0)*(1.0f/(3.0f*(VSIZEX-1))); - const vfloatx vu0 = lerp(u0,u1,vfloatx(step)*(1.0f/(VSIZEX-1))); + const vfloatx vu0 = lerp(u0,u1,vfloatx(StepTy())*(1.0f/(VSIZEX-1))); Vec2vfx P0, dP0du; evalN(vu0,P0,dP0du); dP0du = dP0du * Vec2vfx(dscale); const Vec2vfx P3 = shift_right_1(P0); const Vec2vfx dP3du = shift_right_1(dP0du); @@ -307,6 +308,33 @@ namespace embree const Vec2vfx P2 = P3 - dP3du; return CubicBezierCurve(P0,P1,P2,P3); } + + template + __forceinline CubicBezierCurve> split(const BBox1f& u, int i, int N) const + { + const float u0 = u.lower, u1 = u.upper; + const float dscale = (u1-u0)*(1.0f/(3.0f*N)); + const vfloat vu0 = lerp(u0,u1,(vfloat(i)+vfloat(StepTy()))*(1.0f/N)); + Vec2vf P0, dP0du; evalN(vu0,P0,dP0du); dP0du = dP0du * Vec2vf(dscale); + const Vec2vf P3 = shift_right_1(P0); + const Vec2vf dP3du = shift_right_1(dP0du); + const Vec2vf P1 = P0 + dP0du; + const Vec2vf P2 = P3 - dP3du; + return CubicBezierCurve>(P0,P1,P2,P3); + } + + __forceinline CubicBezierCurve split1(const BBox1f& u, int i, int N) const + { + const float u0 = u.lower, u1 = u.upper; + const float dscale = (u1-u0)*(1.0f/(3.0f*N)); + const float vu0 = lerp(u0,u1,(float(i)+0)*(1.0f/N)); + const float vu1 = lerp(u0,u1,(float(i)+1)*(1.0f/N)); + Vec2fa P0, dP0du; eval(vu0,P0,dP0du); dP0du = dP0du * Vec2fa(dscale); + Vec2fa P3, dP3du; eval(vu1,P3,dP3du); dP3du = dP3du * Vec2fa(dscale); + const Vec2fa P1 = P0 + dP0du; + const Vec2fa P2 = P3 - dP3du; + return CubicBezierCurve(P0,P1,P2,P3); + } __forceinline void eval(float t, Vertex& p, Vertex& dp) const { @@ -461,20 +489,20 @@ namespace embree return madd(b.x, Vec4vf(v0), madd(b.y, Vec4vf(v1), madd(b.z, Vec4vf(v2), b.w * Vec4vf(v3)))); } - template - __forceinline void veval(const vfloat& t, Vec4vf& p, Vec4vf& dp) const + template + __forceinline void veval(const vfloat& t, Vec& p, Vec& dp) const { - const Vec4vf p00 = v0; - const Vec4vf p01 = v1; - const Vec4vf p02 = v2; - const Vec4vf p03 = v3; + const Vec p00 = v0; + const Vec p01 = v1; + const Vec p02 = v2; + const Vec p03 = v3; - const Vec4vf p10 = lerp(p00,p01,t); - const Vec4vf p11 = lerp(p01,p02,t); - const Vec4vf p12 = lerp(p02,p03,t); - const Vec4vf p20 = lerp(p10,p11,t); - const Vec4vf p21 = lerp(p11,p12,t); - const Vec4vf p30 = lerp(p20,p21,t); + const Vec p10 = lerp(p00,p01,t); + const Vec p11 = lerp(p01,p02,t); + const Vec p12 = lerp(p02,p03,t); + const Vec p20 = lerp(p10,p11,t); + const Vec p21 = lerp(p11,p12,t); + const Vec p30 = lerp(p20,p21,t); p = p30; dp = vfloat(3.0f)*(p21-p20); @@ -485,10 +513,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat t = (vfloat(step) + vfloat(ofs+0))*rcp(float(size)); + Vec p,dp; veval(t,p,dp); + return p; +#else return madd(vfloat::loadu(&bezier_basis0.c0[size][ofs]), Vec(v0), madd(vfloat::loadu(&bezier_basis0.c1[size][ofs]), Vec(v1), madd(vfloat::loadu(&bezier_basis0.c2[size][ofs]), Vec(v2), vfloat::loadu(&bezier_basis0.c3[size][ofs]) * Vec(v3)))); +#endif } template> @@ -496,10 +531,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat t = (vfloat(step) + vfloat(ofs+1))*rcp(float(size)); + Vec p,dp; veval(t,p,dp); + return p; +#else return madd(vfloat::loadu(&bezier_basis1.c0[size][ofs]), Vec(v0), madd(vfloat::loadu(&bezier_basis1.c1[size][ofs]), Vec(v1), madd(vfloat::loadu(&bezier_basis1.c2[size][ofs]), Vec(v2), vfloat::loadu(&bezier_basis1.c3[size][ofs]) * Vec(v3)))); +#endif } template> @@ -507,10 +549,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat t = (vfloat(step) + vfloat(ofs+0))*rcp(float(size)); + Vec p,dp; veval(t,p,dp); + return dp; +#else return madd(vfloat::loadu(&bezier_basis0.d0[size][ofs]), Vec(v0), madd(vfloat::loadu(&bezier_basis0.d1[size][ofs]), Vec(v1), madd(vfloat::loadu(&bezier_basis0.d2[size][ofs]), Vec(v2), vfloat::loadu(&bezier_basis0.d3[size][ofs]) * Vec(v3)))); +#endif } template> @@ -518,10 +567,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat t = (vfloat(step) + vfloat(ofs+1))*rcp(float(size)); + Vec p,dp; veval(t,p,dp); + return dp; +#else return madd(vfloat::loadu(&bezier_basis1.d0[size][ofs]), Vec(v0), madd(vfloat::loadu(&bezier_basis1.d1[size][ofs]), Vec(v1), madd(vfloat::loadu(&bezier_basis1.d2[size][ofs]), Vec(v2), vfloat::loadu(&bezier_basis1.d3[size][ofs]) * Vec(v3)))); +#endif } /* calculates bounds of bezier curve geometry */ @@ -532,7 +588,7 @@ namespace embree Vec3vfx pl(pos_inf), pu(neg_inf); for (int i=0; i<=N; i+=VSIZEX) { - vintx vi = vintx(i)+vintx(step); + vintx vi = vintx(i)+vintx(StepTy()); vboolx valid = vi <= vintx(N); const Vec3vfx p = eval0>(i,N); const Vec3vfx dp = derivative0>(i,N); @@ -554,7 +610,7 @@ namespace embree Vec4vfx pl(pos_inf), pu(neg_inf); for (int i=0; i<=N; i+=VSIZEX) { - vintx vi = vintx(i)+vintx(step); + vintx vi = vintx(i)+vintx(StepTy()); vboolx valid = vi <= vintx(N); const Vec4vfx p = eval0(i,N); const Vec4vfx dp = derivative0(i,N); @@ -587,7 +643,7 @@ namespace embree Vec3vfx pl(pos_inf), pu(neg_inf); vfloatx ru(0.0f); for (int i=0; i(i,N); pl.x = select(valid,min(pl.x,pi.x),pl.x); // FIXME: use masked min @@ -645,6 +701,7 @@ namespace embree typedef CubicBezierCurve CubicBezierCurve2fa; typedef CubicBezierCurve CubicBezierCurve3fa; typedef CubicBezierCurve BezierCurve3fa; + typedef CubicBezierCurve BezierCurve3ff; template<> __forceinline int CubicBezierCurve::maxRoots() const { @@ -660,8 +717,9 @@ namespace embree return numRoots(v0,v1) + numRoots(v1,v2) + numRoots(v2,v3); } + struct CurveGeometry; // FIXME: this code should move ! template - __forceinline CubicBezierCurve enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CubicBezierCurve& curve) + __forceinline CubicBezierCurve enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CubicBezierCurve& curve) { return CubicBezierCurve(enlargeRadiusToMinWidth(context,geom,ray_org,curve.v0), enlargeRadiusToMinWidth(context,geom,ray_org,curve.v1), diff --git a/thirdparty/embree/kernels/subdiv/bspline_curve.h b/thirdparty/embree/kernels/subdiv/bspline_curve.h index 51489ef37cf..5d25ebb8e41 100644 --- a/thirdparty/embree/kernels/subdiv/bspline_curve.h +++ b/thirdparty/embree/kernels/subdiv/bspline_curve.h @@ -129,6 +129,12 @@ namespace embree const Vec4 b = BSplineBasis::derivative2(t); return madd(b.x,v0,madd(b.y,v1,madd(b.z,v2,b.w*v3))); } + + __forceinline void eval(const float t, Vertex& p, Vertex& dp) const + { + p = eval(t); + dp = eval_du(t); + } __forceinline void eval(const float t, Vertex& p, Vertex& dp, Vertex& ddp) const { @@ -307,7 +313,7 @@ namespace embree } template - __forceinline BSplineCurveT enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const BSplineCurveT& curve) + __forceinline BSplineCurveT enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const BSplineCurveT& curve) { return BSplineCurveT(enlargeRadiusToMinWidth(context,geom,ray_org,curve.v0), enlargeRadiusToMinWidth(context,geom,ray_org,curve.v1), diff --git a/thirdparty/embree/kernels/subdiv/catmullrom_curve.h b/thirdparty/embree/kernels/subdiv/catmullrom_curve.h index 9532287d986..c42435b9d77 100644 --- a/thirdparty/embree/kernels/subdiv/catmullrom_curve.h +++ b/thirdparty/embree/kernels/subdiv/catmullrom_curve.h @@ -4,12 +4,13 @@ #pragma once #include "../common/default.h" +#include "bezier_curve.h" #include "../common/scene_curves.h" /* - Implements Catmull-Rom curves with control points p0, p1, p2, p3. At - t=0 the curve goes through p1, with tangent (p2-p0)/3, and for t=1 + Implements Catmul Rom curves with control points p0, p1, p2, p3. At + t=0 the curve goes through p1, with tangent (p2-p0)/2, and for t=1 the curve goes through p2 with tangent (p3-p2)/2. */ @@ -99,7 +100,7 @@ namespace embree } __forceinline Vertex center() const { - return 0.25f*(v0+v1+v2+v3); + return 0.5f*(v0+v1); } __forceinline BBox bounds() const { @@ -136,6 +137,12 @@ namespace embree const Vec4 b = CatmullRomBasis::derivative2(t); return madd(b.x,v0,madd(b.y,v1,madd(b.z,v2,b.w*v3))); } + + __forceinline void eval(const float t, Vertex& p, Vertex& dp) const + { + p = eval(t); + dp = eval_du(t); + } __forceinline void eval(const float t, Vertex& p, Vertex& dp, Vertex& ddp) const { @@ -283,8 +290,18 @@ namespace embree } }; + template + __forceinline void convert(const CatmullRomCurveT& icurve, BezierCurveT& ocurve) + { + const Vertex v0 = icurve.v1; + const Vertex v1 = icurve.v1+(icurve.v2-icurve.v0)*(1.0f/6.0f); + const Vertex v2 = icurve.v2+(icurve.v1-icurve.v3)*(1.0f/6.0f); + const Vertex v3 = icurve.v2; + ocurve = BezierCurveT(v0,v1,v2,v3); + } + template - __forceinline CatmullRomCurveT enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CatmullRomCurveT& curve) + __forceinline CatmullRomCurveT enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CatmullRomCurveT& curve) { return CatmullRomCurveT(enlargeRadiusToMinWidth(context,geom,ray_org,curve.v0), enlargeRadiusToMinWidth(context,geom,ray_org,curve.v1), diff --git a/thirdparty/embree/kernels/subdiv/hermite_curve.h b/thirdparty/embree/kernels/subdiv/hermite_curve.h index ffef5a4315f..09ad4cd8b44 100644 --- a/thirdparty/embree/kernels/subdiv/hermite_curve.h +++ b/thirdparty/embree/kernels/subdiv/hermite_curve.h @@ -29,8 +29,14 @@ namespace embree } }; + template + __forceinline void convert(const HermiteCurveT& icurve, BezierCurveT& ocurve) + { + ocurve = BezierCurveT(icurve.v0,icurve.v1,icurve.v2,icurve.v3); + } + template - __forceinline HermiteCurveT enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const HermiteCurveT& curve) { + __forceinline HermiteCurveT enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const HermiteCurveT& curve) { return HermiteCurveT(enlargeRadiusToMinWidth(context,geom,ray_org,BezierCurveT(curve))); } diff --git a/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h b/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h index dcdb101d7c0..e93a86d7a36 100644 --- a/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h +++ b/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h @@ -31,7 +31,8 @@ namespace embree return merge(L.bounds(),R.bounds()); } }; - + +#if !defined(__SYCL_DEVICE_ONLY__) template<> struct TensorLinearQuadraticBezierSurface { @@ -57,6 +58,7 @@ namespace embree return merge(bl,br); } }; +#endif template struct TensorLinearCubicBezierSurface @@ -148,9 +150,10 @@ namespace embree __forceinline TensorLinearCubicBezierSurface xfm(const V& dx) const { return TensorLinearCubicBezierSurface(L.xfm(dx),R.xfm(dx)); } - - __forceinline TensorLinearCubicBezierSurface vxfm(const V& dx) const { - return TensorLinearCubicBezierSurface(L.vxfm(dx),R.vxfm(dx)); + + template + __forceinline TensorLinearCubicBezierSurface> vxfm(const V& dx) const { + return TensorLinearCubicBezierSurface>(L.template vxfm(dx),R.template vxfm(dx)); } __forceinline TensorLinearCubicBezierSurface xfm(const V& dx, const V& p) const { @@ -188,11 +191,20 @@ namespace embree new (&left ) TensorLinearCubicBezierSurface(L0,R0); new (&right) TensorLinearCubicBezierSurface(L1,R1); } - + __forceinline TensorLinearCubicBezierSurface vsplit_u(vboolx& valid, const BBox1f& u) const { valid = true; clear(valid,VSIZEX-1); return TensorLinearCubicBezierSurface(L.split(u),R.split(u)); } + + template + __forceinline TensorLinearCubicBezierSurface> vsplit_u(vbool& valid, const BBox1f& u, int& i, int N) const + { + valid = true; clear(valid,W-1); + auto r = TensorLinearCubicBezierSurface>(L.template split(u,i,N),R.template split(u,i,N)); + i += W-1; + return r; + } __forceinline V eval(const float u, const float v) const { return clerp(L,R,V(v)).eval(u); @@ -244,6 +256,8 @@ namespace embree return TensorLinearCubicBezierSurface(clerp(a.L,b.L,V(t)), clerp(a.R,b.R,V(t))); } }; + +#if !defined(__SYCL_DEVICE_ONLY__) template<> struct TensorLinearCubicBezierSurface @@ -332,12 +346,20 @@ namespace embree new (&left ) TensorLinearCubicBezierSurface(LR0); new (&right) TensorLinearCubicBezierSurface(LR1); } - + __forceinline TensorLinearCubicBezierSurface vsplit_u(vboolx& valid, const BBox1f& u) const { valid = true; clear(valid,VSIZEX-1); return TensorLinearCubicBezierSurface(getL().split(u),getR().split(u)); } + template + __forceinline TensorLinearCubicBezierSurface> vsplit_u(vbool& valid, const BBox1f& u, int& i, int N) const { + valid = true; clear(valid,W-1); + auto r = TensorLinearCubicBezierSurface>(getL().split(u,i,N),getR().split(u,i,N)); + i += W-1; + return r; + } + __forceinline Vec2fa eval(const float u, const float v) const { const vfloat4 p = LR.eval(u); @@ -396,6 +418,24 @@ namespace embree } }; + template<> + __forceinline TensorLinearCubicBezierSurface TensorLinearCubicBezierSurface::vsplit_u<1>(bool& valid, const BBox1f& u, int& i, int N) const { + auto r = TensorLinearCubicBezierSurface(getL().split1(u,i,N),getR().split1(u,i,N)); + valid = true; i += 1; + return r; + } + +#else + + template<> template<> + __forceinline TensorLinearCubicBezierSurface TensorLinearCubicBezierSurface::vsplit_u<1>(bool& valid, const BBox1f& u, int& i, int N) const { + auto r = TensorLinearCubicBezierSurface(L.split1(u,i,N),R.split1(u,i,N)); + valid = true; i += 1; + return r; + } + +#endif + typedef TensorLinearCubicBezierSurface TensorLinearCubicBezierSurface1f; typedef TensorLinearCubicBezierSurface TensorLinearCubicBezierSurface2fa; typedef TensorLinearCubicBezierSurface TensorLinearCubicBezierSurface3fa; diff --git a/thirdparty/embree/patches/godot-changes-noexcept.patch b/thirdparty/embree/patches/godot-changes-noexcept.patch index 84169c36e47..bf9973a7645 100644 --- a/thirdparty/embree/patches/godot-changes-noexcept.patch +++ b/thirdparty/embree/patches/godot-changes-noexcept.patch @@ -1,121 +1,5 @@ -diff --git a/thirdparty/embree/common/algorithms/parallel_for.h b/thirdparty/embree/common/algorithms/parallel_for.h -index f2969a88f1..6d411e4852 100644 ---- a/thirdparty/embree/common/algorithms/parallel_for.h -+++ b/thirdparty/embree/common/algorithms/parallel_for.h -@@ -21,7 +21,10 @@ namespace embree - func(r.begin()); - }); - if (!TaskScheduler::wait()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - } - #elif defined(TASKING_TBB) - #if TBB_INTERFACE_VERSION >= 12002 -@@ -30,13 +33,19 @@ namespace embree - func(i); - },context); - if (context.is_group_execution_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #else - tbb::parallel_for(Index(0),N,Index(1),[&](Index i) { - func(i); - }); - if (tbb::task::self().is_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #endif - - #elif defined(TASKING_PPL) -@@ -56,7 +65,10 @@ namespace embree - #if defined(TASKING_INTERNAL) - TaskScheduler::spawn(first,last,minStepSize,func); - if (!TaskScheduler::wait()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - - #elif defined(TASKING_TBB) - #if TBB_INTERFACE_VERSION >= 12002 -@@ -65,13 +77,19 @@ namespace embree - func(range(r.begin(),r.end())); - },context); - if (context.is_group_execution_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #else - tbb::parallel_for(tbb::blocked_range(first,last,minStepSize),[&](const tbb::blocked_range& r) { - func(range(r.begin(),r.end())); - }); - if (tbb::task::self().is_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #endif - - #elif defined(TASKING_PPL) -@@ -103,13 +121,19 @@ namespace embree - func(i); - },tbb::simple_partitioner(),context); - if (context.is_group_execution_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #else - tbb::parallel_for(Index(0),N,Index(1),[&](Index i) { - func(i); - },tbb::simple_partitioner()); - if (tbb::task::self().is_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #endif - } - -@@ -124,13 +148,19 @@ namespace embree - func(i); - },ap,context); - if (context.is_group_execution_cancelled()) -- throw std::runtime_error("task cancelled"); -+ // -- 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()) -- throw std::runtime_error("task cancelled"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task cancelled"); -+ abort(); -+ // -- GODOT end -- - #endif - } - diff --git a/thirdparty/embree/common/algorithms/parallel_reduce.h b/thirdparty/embree/common/algorithms/parallel_reduce.h -index 1a94aad8c4..cd0078f2e6 100644 +index b52b1e2e13..51ec0a6405 100644 --- a/thirdparty/embree/common/algorithms/parallel_reduce.h +++ b/thirdparty/embree/common/algorithms/parallel_reduce.h @@ -58,15 +58,19 @@ namespace embree @@ -143,119 +27,233 @@ index 1a94aad8c4..cd0078f2e6 100644 #endif #else // TASKING_PPL diff --git a/thirdparty/embree/common/lexers/stringstream.cpp b/thirdparty/embree/common/lexers/stringstream.cpp -index 42ffb10176..a037869506 100644 +index 42ffb10176..c93da0b420 100644 --- a/thirdparty/embree/common/lexers/stringstream.cpp +++ b/thirdparty/embree/common/lexers/stringstream.cpp -@@ -39,7 +39,10 @@ namespace embree +@@ -39,7 +39,12 @@ namespace embree std::vector str; str.reserve(64); while (cin->peek() != EOF && !isSeparator(cin->peek())) { int c = cin->get(); - if (!isValidChar(c)) throw std::runtime_error("invalid character "+std::string(1,c)+" in input"); + // -- GODOT start -- + // if (!isValidChar(c)) throw std::runtime_error("invalid character "+std::string(1,c)+" in input"); -+ if (!isValidChar(c)) abort(); ++ if (!isValidChar(c)) { ++ abort(); ++ } + // -- GODOT end -- str.push_back((char)c); } str.push_back(0); diff --git a/thirdparty/embree/common/sys/alloc.cpp b/thirdparty/embree/common/sys/alloc.cpp -index 1bc30fe9a5..abdd269069 100644 +index de225fafc6..71616a3982 100644 --- a/thirdparty/embree/common/sys/alloc.cpp +++ b/thirdparty/embree/common/sys/alloc.cpp -@@ -21,7 +21,10 @@ namespace embree - void* ptr = _mm_malloc(size,align); - - if (size != 0 && ptr == nullptr) -- throw std::bad_alloc(); -+ // -- GODOT start -- -+ // throw std::bad_alloc(); +@@ -24,16 +24,32 @@ namespace embree + + void enableUSMAllocEmbree(sycl::context* context, sycl::device* device) + { +- if (tls_context_embree != nullptr) throw std::runtime_error("USM allocation already enabled"); +- if (tls_device_embree != nullptr) throw std::runtime_error("USM allocation already enabled"); ++ // -- GODOT start -- ++ // if (tls_context_embree != nullptr) throw std::runtime_error("USM allocation already enabled"); ++ // if (tls_device_embree != nullptr) throw std::runtime_error("USM allocation already enabled"); ++ if (tls_context_embree != nullptr) { + abort(); -+ // -- GODOT end -- ++ } ++ if (tls_device_embree != nullptr) { ++ abort(); ++ } ++ // -- GODOT end -- + tls_context_embree = context; + tls_device_embree = device; + } + + void disableUSMAllocEmbree() + { +- if (tls_context_embree == nullptr) throw std::runtime_error("USM allocation not enabled"); +- if (tls_device_embree == nullptr) throw std::runtime_error("USM allocation not enabled"); ++ // -- GODOT start -- ++ // if (tls_context_embree == nullptr) throw std::runtime_error("USM allocation not enabled"); ++ // if (tls_device_embree == nullptr) throw std::runtime_error("USM allocation not enabled"); ++ if (tls_context_embree == nullptr) { ++ abort(); ++ } ++ if (tls_device_embree == nullptr) { ++ abort(); ++ } ++ // -- GODOT end -- + tls_context_embree = nullptr; + tls_device_embree = nullptr; + } +@@ -48,8 +64,16 @@ namespace embree + + void disableUSMAllocTutorial() + { +- if (tls_context_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled"); +- if (tls_device_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled"); ++ // -- GODOT start -- ++ // if (tls_context_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled"); ++ // if (tls_device_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled"); ++ if (tls_context_tutorial == nullptr) { ++ abort(); ++ } ++ if (tls_device_tutorial == nullptr) { ++ abort(); ++ } ++ // -- GODOT end -- + tls_context_tutorial = nullptr; + tls_device_tutorial = nullptr; +@@ -64,8 +88,13 @@ namespace embree + + assert((align & (align-1)) == 0); + void* ptr = _mm_malloc(size,align); +- if (size != 0 && ptr == nullptr) +- throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (size != 0 && ptr == nullptr) ++ // throw std::bad_alloc(); ++ if (size != 0 && ptr == nullptr) { ++ abort(); ++ } ++ // -- GODOT end -- return ptr; } -@@ -128,7 +131,10 @@ namespace embree + +@@ -94,8 +123,13 @@ namespace embree + else + ptr = sycl::aligned_alloc_shared(align,size,*device,*context); + +- if (size != 0 && ptr == nullptr) +- throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (size != 0 && ptr == nullptr) ++ // throw std::bad_alloc(); ++ if (size != 0 && ptr == nullptr) { ++ abort(); ++ } ++ // -- GODOT end -- + + return ptr; + } +@@ -241,7 +275,12 @@ namespace embree /* fall back to 4k pages */ int flags = MEM_COMMIT | MEM_RESERVE; char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE); - if (ptr == nullptr) throw std::bad_alloc(); + // -- GODOT start -- + // if (ptr == nullptr) throw std::bad_alloc(); -+ if (ptr == nullptr) abort(); ++ if (ptr == nullptr) { ++ abort(); ++ } + // -- GODOT end -- hugepages = false; return ptr; } -@@ -145,7 +151,10 @@ namespace embree +@@ -257,8 +296,13 @@ namespace embree + if (bytesNew >= bytesOld) return bytesOld; - if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) +- if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) - throw std::bad_alloc(); -+ // -- GODOT start -- -+ // throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) ++ // throw std::bad_alloc(); ++ if (!VirtualFree((char*)ptr+bytesNew,bytesOld-bytesNew,MEM_DECOMMIT)) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- return bytesNew; } -@@ -156,7 +165,10 @@ namespace embree +@@ -268,8 +312,13 @@ namespace embree + if (bytes == 0) return; - if (!VirtualFree(ptr,0,MEM_RELEASE)) +- if (!VirtualFree(ptr,0,MEM_RELEASE)) - throw std::bad_alloc(); -+ // -- GODOT start -- -+ // throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (!VirtualFree(ptr,0,MEM_RELEASE)) ++ // throw std::bad_alloc(); ++ if (!VirtualFree(ptr,0,MEM_RELEASE)) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- } void os_advise(void *ptr, size_t bytes) -@@ -260,7 +272,10 @@ namespace embree +@@ -373,7 +422,12 @@ namespace embree /* fallback to 4k pages */ void* ptr = (char*) mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (ptr == MAP_FAILED) throw std::bad_alloc(); + // -- GODOT start -- + // if (ptr == MAP_FAILED) throw std::bad_alloc(); -+ if (ptr == MAP_FAILED) abort(); ++ if (ptr == MAP_FAILED) { ++ abort(); ++ } + // -- GODOT end -- hugepages = false; /* advise huge page hint for THP */ -@@ -277,7 +292,10 @@ namespace embree +@@ -389,8 +443,13 @@ namespace embree + if (bytesNew >= bytesOld) return bytesOld; - if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) +- if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) - throw std::bad_alloc(); -+ // -- GODOT start -- -+ // throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) ++ // throw std::bad_alloc(); ++ if (munmap((char*)ptr+bytesNew,bytesOld-bytesNew) == -1) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- return bytesNew; } -@@ -291,7 +309,10 @@ namespace embree +@@ -403,8 +462,13 @@ namespace embree + /* for hugepages we need to also align the size */ const size_t pageSize = hugepages ? PAGE_SIZE_2M : PAGE_SIZE_4K; bytes = (bytes+pageSize-1) & ~(pageSize-1); - if (munmap(ptr,bytes) == -1) +- if (munmap(ptr,bytes) == -1) - throw std::bad_alloc(); -+ // -- GODOT start -- -+ // throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (munmap(ptr,bytes) == -1) ++ // throw std::bad_alloc(); ++ if (munmap(ptr,bytes) == -1) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- } /* hint for transparent huge pages (THP) */ +diff --git a/thirdparty/embree/common/sys/alloc.h b/thirdparty/embree/common/sys/alloc.h +index e19c2c221a..28b17f988d 100644 +--- a/thirdparty/embree/common/sys/alloc.h ++++ b/thirdparty/embree/common/sys/alloc.h +@@ -160,7 +160,10 @@ namespace embree + typedef std::ptrdiff_t difference_type; + + __forceinline pointer allocate( size_type n ) { +- throw std::runtime_error("no allocation supported"); ++ // -- GODOT start -- ++ // throw std::runtime_error("no allocation supported"); ++ abort(); ++ // -- GODOT end -- + } + + __forceinline void deallocate( pointer p, size_type n ) { diff --git a/thirdparty/embree/common/sys/platform.h b/thirdparty/embree/common/sys/platform.h -index be3ec36436..728bf6ed7d 100644 +index 6dc0cf3318..d4a9b9e119 100644 --- a/thirdparty/embree/common/sys/platform.h +++ b/thirdparty/embree/common/sys/platform.h -@@ -178,11 +178,19 @@ - #define PRINT4(x,y,z,w) embree_cout << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << ", " << STRING(w) << " = " << (w) << embree_endl +@@ -213,11 +213,19 @@ + #define UPRINT4(x,y,z,w) embree_cout_uniform << STRING(x) << " = " << (x) << ", " << STRING(y) << " = " << (y) << ", " << STRING(z) << " = " << (z) << ", " << STRING(w) << " = " << (w) << embree_endl #if defined(DEBUG) // only report file and line in debug mode + // -- GODOT start -- -+ // #define THROW_RUNTIME_ERROR(str) ++ // #define THROW_RUNTIME_ERROR(str) \ + // throw std::runtime_error(std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str)); #define THROW_RUNTIME_ERROR(str) \ - throw std::runtime_error(std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str)); @@ -263,7 +261,7 @@ index be3ec36436..728bf6ed7d 100644 + // -- GODOT end -- #else + // -- GODOT start -- -+ // #define THROW_RUNTIME_ERROR(str) ++ // #define THROW_RUNTIME_ERROR(str) \ + // throw std::runtime_error(str); #define THROW_RUNTIME_ERROR(str) \ - throw std::runtime_error(str); @@ -273,7 +271,7 @@ index be3ec36436..728bf6ed7d 100644 #define FATAL(x) THROW_RUNTIME_ERROR(x) diff --git a/thirdparty/embree/common/tasking/taskschedulerinternal.cpp b/thirdparty/embree/common/tasking/taskschedulerinternal.cpp -index dca835a716..ad438588a3 100644 +index 83ead95122..88b88a30ec 100644 --- a/thirdparty/embree/common/tasking/taskschedulerinternal.cpp +++ b/thirdparty/embree/common/tasking/taskschedulerinternal.cpp @@ -48,13 +48,15 @@ namespace embree @@ -281,115 +279,59 @@ index dca835a716..ad438588a3 100644 Task* prevTask = thread.task; thread.task = this; - try { -- if (thread.scheduler->cancellingException == nullptr) +- if (context->cancellingException == nullptr) + // -- GODOT start -- + // try { -+ // if (thread.scheduler->cancellingException == nullptr) ++ // if (context->cancellingException == nullptr) closure->execute(); - } catch (...) { -- if (thread.scheduler->cancellingException == nullptr) -- thread.scheduler->cancellingException = std::current_exception(); +- if (context->cancellingException == nullptr) +- context->cancellingException = std::current_exception(); - } + // } catch (...) { -+ // if (thread.scheduler->cancellingException == nullptr) -+ // thread.scheduler->cancellingException = std::current_exception(); ++ // if (context->cancellingException == nullptr) ++ // context->cancellingException = std::current_exception(); + // } + // -- GODOT end -- thread.task = prevTask; add_dependencies(-1); } -@@ -291,8 +293,11 @@ namespace embree - size_t threadIndex = allocThreadIndex(); - condition.wait(mutex, [&] () { return hasRootTask.load(); }); - mutex.unlock(); -- std::exception_ptr except = thread_loop(threadIndex); -- if (except != nullptr) std::rethrow_exception(except); -+ // -- GODOT start -- -+ // std::exception_ptr except = thread_loop(threadIndex); -+ // if (except != nullptr) std::rethrow_exception(except); -+ thread_loop(threadIndex); -+ // -- GODOT end -- - } - - void TaskScheduler::reset() { -@@ -324,7 +329,10 @@ namespace embree - return thread->scheduler->cancellingException == nullptr; - } - -- std::exception_ptr TaskScheduler::thread_loop(size_t threadIndex) -+// -- GODOT start -- -+// std::exception_ptr TaskScheduler::thread_loop(size_t threadIndex) -+ void TaskScheduler::thread_loop(size_t threadIndex) -+// -- GODOT end -- - { - /* allocate thread structure */ - std::unique_ptr mthread(new Thread(threadIndex,this)); // too large for stack allocation -@@ -347,9 +355,10 @@ namespace embree - swapThread(oldThread); - - /* remember exception to throw */ -- std::exception_ptr except = nullptr; -- if (cancellingException != nullptr) except = cancellingException; -- -+ // -- GODOT start -- -+ // std::exception_ptr except = nullptr; -+ // if (cancellingException != nullptr) except = cancellingException; -+ // -- GODOT end -- - /* wait for all threads to terminate */ - threadCounter--; - #if defined(__WIN32__) -@@ -367,7 +376,10 @@ namespace embree - yield(); - #endif - } -- return except; -+ // -- GODOT start -- -+ // return except; -+ return; -+ // -- GODOT end -- - } - - bool TaskScheduler::steal_from_other_threads(Thread& thread) diff --git a/thirdparty/embree/common/tasking/taskschedulerinternal.h b/thirdparty/embree/common/tasking/taskschedulerinternal.h -index 61a0e57c5b..6cc2495195 100644 +index 355648b3f8..e72d3b72ba 100644 --- a/thirdparty/embree/common/tasking/taskschedulerinternal.h +++ b/thirdparty/embree/common/tasking/taskschedulerinternal.h -@@ -123,7 +123,10 @@ namespace embree +@@ -130,8 +130,13 @@ namespace embree + __forceinline void* alloc(size_t bytes, size_t align = 64) { size_t ofs = bytes + ((align - stackPtr) & (align-1)); - if (stackPtr + ofs > CLOSURE_STACK_SIZE) +- if (stackPtr + ofs > CLOSURE_STACK_SIZE) - throw std::runtime_error("closure stack overflow"); -+ // -- GODOT start -- -+ // throw std::runtime_error("closure stack overflow"); ++ // -- GODOT start -- ++ // if (stackPtr + ofs > CLOSURE_STACK_SIZE) ++ // throw std::runtime_error("closure stack overflow"); ++ if (stackPtr + ofs > CLOSURE_STACK_SIZE) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- stackPtr += ofs; return &stack[stackPtr-bytes]; } -@@ -132,7 +135,10 @@ namespace embree - __forceinline void push_right(Thread& thread, const size_t size, const Closure& closure) +@@ -139,8 +144,13 @@ namespace embree + template + __forceinline void push_right(Thread& thread, const size_t size, const Closure& closure, TaskGroupContext* context) { - if (right >= TASK_STACK_SIZE) +- if (right >= TASK_STACK_SIZE) - throw std::runtime_error("task stack overflow"); -+ // -- GODOT start -- -+ // throw std::runtime_error("task stack overflow"); -+ abort(); -+ // -- GODOT end -- ++ // -- GODOT start -- ++ // if (right >= TASK_STACK_SIZE) ++ // throw std::runtime_error("task stack overflow"); ++ if (right >= TASK_STACK_SIZE) { ++ abort(); ++ } ++ // -- GODOT end -- /* allocate new task on right side of stack */ size_t oldStackPtr = stackPtr; -@@ -238,7 +244,10 @@ namespace embree - void wait_for_threads(size_t threadCount); - - /*! thread loop for all worker threads */ -- std::exception_ptr thread_loop(size_t threadIndex); -+ // -- GODOT start -- -+ // std::exception_ptr thread_loop(size_t threadIndex); -+ void thread_loop(size_t threadIndex); -+ // -- GODOT end -- - - /*! steals a task from a different thread */ - bool steal_from_other_threads(Thread& thread); diff --git a/thirdparty/embree/kernels/bvh/bvh_statistics.cpp b/thirdparty/embree/kernels/bvh/bvh_statistics.cpp index 40f9043736..57f75bfd7e 100644 --- a/thirdparty/embree/kernels/bvh/bvh_statistics.cpp @@ -406,40 +348,94 @@ index 40f9043736..57f75bfd7e 100644 } return s; } +diff --git a/thirdparty/embree/kernels/common/alloc.h b/thirdparty/embree/kernels/common/alloc.h +index 2bd292de4d..840d48c327 100644 +--- a/thirdparty/embree/kernels/common/alloc.h ++++ b/thirdparty/embree/kernels/common/alloc.h +@@ -189,8 +189,13 @@ namespace embree + , atype(osAllocation ? EMBREE_OS_MALLOC : ALIGNED_MALLOC) + , primrefarray(device,0) + { +- if (osAllocation && useUSM) +- throw std::runtime_error("USM allocation cannot be combined with OS allocation."); ++ // -- GODOT start -- ++ // if (osAllocation && useUSM) ++ // throw std::runtime_error("USM allocation cannot be combined with OS allocation."); ++ if (osAllocation && useUSM) { ++ abort(); ++ } ++ // -- GODOT end -- + + for (size_t i=0; imalloc(device,bytes,align,partial); +- if (ptr == nullptr && !blockAllocation) +- throw std::bad_alloc(); ++ // -- GODOT start -- ++ // if (ptr == nullptr && !blockAllocation) ++ // throw std::bad_alloc(); ++ if (ptr == nullptr && !blockAllocation) { ++ abort(); ++ } ++ // -- GODOT end -- + if (ptr) return ptr; + } + diff --git a/thirdparty/embree/kernels/common/rtcore.cpp b/thirdparty/embree/kernels/common/rtcore.cpp -index 95a94319ec..a6ea55bfc4 100644 +index 8dc5d7045b..eb8d2c0a58 100644 --- a/thirdparty/embree/kernels/common/rtcore.cpp +++ b/thirdparty/embree/kernels/common/rtcore.cpp -@@ -198,7 +198,10 @@ RTC_NAMESPACE_BEGIN; +@@ -257,10 +257,17 @@ RTC_NAMESPACE_BEGIN; + RTC_TRACE(rtcSetSceneBuildQuality); + RTC_VERIFY_HANDLE(hscene); + RTC_ENTER_DEVICE(hscene); ++ // -- GODOT start -- ++ // if (quality != RTC_BUILD_QUALITY_LOW && ++ // quality != RTC_BUILD_QUALITY_MEDIUM && ++ // quality != RTC_BUILD_QUALITY_HIGH) ++ // throw std::runtime_error("invalid build quality"); if (quality != RTC_BUILD_QUALITY_LOW && quality != RTC_BUILD_QUALITY_MEDIUM && - quality != RTC_BUILD_QUALITY_HIGH) +- quality != RTC_BUILD_QUALITY_HIGH) - throw std::runtime_error("invalid build quality"); -+ // -- GODOT start -- -+ // throw std::runtime_error("invalid build quality"); ++ quality != RTC_BUILD_QUALITY_HIGH) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- scene->setBuildQuality(quality); RTC_CATCH_END2(scene); } -@@ -1351,7 +1354,10 @@ RTC_NAMESPACE_BEGIN; +@@ -1563,11 +1570,19 @@ RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeSte + RTC_TRACE(rtcSetGeometryBuildQuality); + RTC_VERIFY_HANDLE(hgeometry); + RTC_ENTER_DEVICE(hgeometry); ++ // -- GODOT start -- ++ // if (quality != RTC_BUILD_QUALITY_LOW && ++ // quality != RTC_BUILD_QUALITY_MEDIUM && ++ // quality != RTC_BUILD_QUALITY_HIGH && ++ // quality != RTC_BUILD_QUALITY_REFIT) ++ // throw std::runtime_error("invalid build quality"); + if (quality != RTC_BUILD_QUALITY_LOW && quality != RTC_BUILD_QUALITY_MEDIUM && quality != RTC_BUILD_QUALITY_HIGH && - quality != RTC_BUILD_QUALITY_REFIT) +- quality != RTC_BUILD_QUALITY_REFIT) - throw std::runtime_error("invalid build quality"); -+ // -- GODOT start -- -+ // throw std::runtime_error("invalid build quality"); ++ quality != RTC_BUILD_QUALITY_REFIT) { + abort(); -+ // -- GODOT end -- ++ } ++ // -- GODOT end -- geometry->setBuildQuality(quality); RTC_CATCH_END2(geometry); } diff --git a/thirdparty/embree/kernels/common/rtcore.h b/thirdparty/embree/kernels/common/rtcore.h -index 4e4b24e9c2..ac58a84d6f 100644 +index 73a061de11..47526482c1 100644 --- a/thirdparty/embree/kernels/common/rtcore.h +++ b/thirdparty/embree/kernels/common/rtcore.h -@@ -25,6 +25,13 @@ namespace embree - #endif +@@ -13,13 +13,13 @@ namespace embree + __forceinline bool isIncoherent(RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_INCOHERENT; } /*! Macros used in the rtcore API implementation */ +// -- GODOT start -- @@ -447,21 +443,18 @@ index 4e4b24e9c2..ac58a84d6f 100644 +#define RTC_CATCH_END(device) +#define RTC_CATCH_END2(scene) +#define RTC_CATCH_END2_FALSE(scene) return false; -+ -+#if 0 + #if 0 +-# define RTC_CATCH_BEGIN +-# define RTC_CATCH_END(device) +-# define RTC_CATCH_END2(scene) +-# define RTC_CATCH_END2_FALSE(scene) return false; +-#else +- ++// -- GODOT end -- #define RTC_CATCH_BEGIN try { #define RTC_CATCH_END(device) \ -@@ -71,6 +78,8 @@ namespace embree - Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \ - return false; \ - } -+#endif -+// -- GODOT end -- - - #define RTC_VERIFY_HANDLE(handle) \ - if (handle == nullptr) { \ -@@ -97,6 +106,8 @@ namespace embree +@@ -94,6 +94,8 @@ namespace embree #define RTC_TRACE(x) #endif @@ -470,7 +463,7 @@ index 4e4b24e9c2..ac58a84d6f 100644 /*! used to throw embree API errors */ struct rtcore_error : public std::exception { -@@ -112,14 +123,18 @@ namespace embree +@@ -109,14 +111,18 @@ namespace embree RTCError error; std::string str; }; @@ -490,36 +483,61 @@ index 4e4b24e9c2..ac58a84d6f 100644 +// -- GODOT end -- #define RTC_BUILD_ARGUMENTS_HAS(settings,member) \ - (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member))) + (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member))) diff --git a/thirdparty/embree/kernels/common/scene.cpp b/thirdparty/embree/kernels/common/scene.cpp -index ad1916c54e..65d31d0f81 100644 +index fda8dd938a..10cb3c4bec 100644 --- a/thirdparty/embree/kernels/common/scene.cpp +++ b/thirdparty/embree/kernels/common/scene.cpp -@@ -790,16 +790,18 @@ namespace embree +@@ -894,16 +894,18 @@ namespace embree } /* initiate build */ - try { + // -- GODOT start -- + // try { - scheduler->spawn_root([&]() { commit_task(); Lock lock(schedulerMutex); this->scheduler = nullptr; }, 1, !join); + TaskScheduler::TaskGroupContext context; + scheduler->spawn_root([&]() { commit_task(); Lock lock(taskGroup->schedulerMutex); taskGroup->scheduler = nullptr; }, &context, 1, !join); - } - catch (...) { - accels_clear(); -- updateInterface(); -- Lock lock(schedulerMutex); -- this->scheduler = nullptr; +- Lock lock(taskGroup->schedulerMutex); +- taskGroup->scheduler = nullptr; - throw; - } + // } + // catch (...) { + // accels_clear(); -+ // updateInterface(); -+ // Lock lock(schedulerMutex); -+ // this->scheduler = nullptr; ++ // Lock lock(taskGroup->schedulerMutex); ++ // taskGroup->scheduler = nullptr; + // throw; + // } + // -- GODOT end -- } #endif +diff --git a/thirdparty/embree/kernels/common/state.cpp b/thirdparty/embree/kernels/common/state.cpp +index 4e3ab6ddfb..1d73ae9629 100644 +--- a/thirdparty/embree/kernels/common/state.cpp ++++ b/thirdparty/embree/kernels/common/state.cpp +@@ -194,13 +194,15 @@ namespace embree + bool State::parseFile(const FileName& fileName) + { + Ref > file; +- try { ++ // -- GODOT start -- ++ // try { + file = new FileStream(fileName); +- } +- catch (std::runtime_error& e) { +- (void) e; +- return false; +- } ++ // } ++ // catch (std::runtime_error& e) { ++ // (void) e; ++ // return false; ++ // } ++ // -- GODOT end -- + + std::vector syms; + for (size_t i=0; i