Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/kernels/common/rtcore.h
9905 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "../../include/embree4/rtcore.h"
7
RTC_NAMESPACE_USE
8
9
namespace embree
10
{
11
/*! decoding of intersection flags */
12
__forceinline bool isCoherent (RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_COHERENT; }
13
__forceinline bool isIncoherent(RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_INCOHERENT; }
14
15
/*! Macros used in the rtcore API implementation */
16
#if 1
17
# define RTC_CATCH_BEGIN
18
# define RTC_CATCH_END(device)
19
# define RTC_CATCH_END2(scene)
20
# define RTC_CATCH_END2_FALSE(scene) return false;
21
#else
22
23
#define RTC_CATCH_BEGIN try {
24
25
#define RTC_CATCH_END(device) \
26
} catch (std::bad_alloc&) { \
27
Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \
28
} catch (rtcore_error& e) { \
29
Device::process_error(device,e.error,e.what()); \
30
} catch (std::exception& e) { \
31
Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \
32
} catch (...) { \
33
Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \
34
}
35
36
#define RTC_CATCH_END2(scene) \
37
} catch (std::bad_alloc&) { \
38
Device* device = scene ? scene->device : nullptr; \
39
Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \
40
} catch (rtcore_error& e) { \
41
Device* device = scene ? scene->device : nullptr; \
42
Device::process_error(device,e.error,e.what()); \
43
} catch (std::exception& e) { \
44
Device* device = scene ? scene->device : nullptr; \
45
Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \
46
} catch (...) { \
47
Device* device = scene ? scene->device : nullptr; \
48
Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \
49
}
50
51
#define RTC_CATCH_END2_FALSE(scene) \
52
} catch (std::bad_alloc&) { \
53
Device* device = scene ? scene->device : nullptr; \
54
Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \
55
return false; \
56
} catch (rtcore_error& e) { \
57
Device* device = scene ? scene->device : nullptr; \
58
Device::process_error(device,e.error,e.what()); \
59
return false; \
60
} catch (std::exception& e) { \
61
Device* device = scene ? scene->device : nullptr; \
62
Device::process_error(device,RTC_ERROR_UNKNOWN,e.what()); \
63
return false; \
64
} catch (...) { \
65
Device* device = scene ? scene->device : nullptr; \
66
Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \
67
return false; \
68
}
69
70
#endif
71
72
#define RTC_VERIFY_HANDLE(handle) \
73
if (handle == nullptr) { \
74
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \
75
}
76
77
#define RTC_VERIFY_GEOMID(id) \
78
if (id == RTC_INVALID_GEOMETRY_ID) { \
79
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \
80
}
81
82
#define RTC_VERIFY_UPPER(id,upper) \
83
if (id > upper) { \
84
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \
85
}
86
87
#define RTC_VERIFY_RANGE(id,lower,upper) \
88
if (id < lower || id > upper) \
89
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"argument out of bounds");
90
91
#if 0 // enable to debug print all API calls
92
#define RTC_TRACE(x) std::cout << #x << std::endl;
93
#else
94
#define RTC_TRACE(x)
95
#endif
96
97
#if 0
98
/*! used to throw embree API errors */
99
struct rtcore_error : public std::exception
100
{
101
__forceinline rtcore_error(RTCError error, const std::string& str)
102
: error(error), str(str) {}
103
104
~rtcore_error() throw() {}
105
106
const char* what () const throw () {
107
return str.c_str();
108
}
109
110
RTCError error;
111
std::string str;
112
};
113
#endif
114
115
#if defined(DEBUG) // only report file and line in debug mode
116
#define throw_RTCError(error,str) \
117
printf("%s (%d): %s", __FILE__, __LINE__, std::string(str).c_str()), abort();
118
//throw rtcore_error(error,std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str));
119
#else
120
#define throw_RTCError(error,str) \
121
abort();
122
//throw rtcore_error(error,str);
123
#endif
124
125
#define RTC_BUILD_ARGUMENTS_HAS(settings,member) \
126
(settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member)))
127
128
129
inline void storeTransform(const AffineSpace3fa& space, RTCFormat format, float* xfm)
130
{
131
switch (format)
132
{
133
case RTC_FORMAT_FLOAT3X4_ROW_MAJOR:
134
xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vy.x; xfm[ 2] = space.l.vz.x; xfm[ 3] = space.p.x;
135
xfm[ 4] = space.l.vx.y; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vz.y; xfm[ 7] = space.p.y;
136
xfm[ 8] = space.l.vx.z; xfm[ 9] = space.l.vy.z; xfm[10] = space.l.vz.z; xfm[11] = space.p.z;
137
break;
138
139
case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR:
140
xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z;
141
xfm[ 3] = space.l.vy.x; xfm[ 4] = space.l.vy.y; xfm[ 5] = space.l.vy.z;
142
xfm[ 6] = space.l.vz.x; xfm[ 7] = space.l.vz.y; xfm[ 8] = space.l.vz.z;
143
xfm[ 9] = space.p.x; xfm[10] = space.p.y; xfm[11] = space.p.z;
144
break;
145
146
case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR:
147
xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; xfm[ 3] = 0.f;
148
xfm[ 4] = space.l.vy.x; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vy.z; xfm[ 7] = 0.f;
149
xfm[ 8] = space.l.vz.x; xfm[ 9] = space.l.vz.y; xfm[10] = space.l.vz.z; xfm[11] = 0.f;
150
xfm[12] = space.p.x; xfm[13] = space.p.y; xfm[14] = space.p.z; xfm[15] = 1.f;
151
break;
152
153
default:
154
#if !defined(__SYCL_DEVICE_ONLY__)
155
throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format");
156
#endif
157
break;
158
}
159
}
160
}
161
162