Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h
9905 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "../common/ray.h"
7
#include "../common/context.h"
8
#include "filter_sycl.h"
9
10
namespace embree
11
{
12
template<typename Ray>
13
struct Intersect1Epilog1_HWIF;
14
15
template<>
16
struct Intersect1Epilog1_HWIF<RayHit>
17
{
18
RayHit& ray;
19
sycl::private_ptr<RayQueryContext> context;
20
const unsigned int geomID;
21
const unsigned int primID;
22
const bool filter;
23
24
__forceinline Intersect1Epilog1_HWIF(RayHit& ray,
25
sycl::private_ptr<RayQueryContext> context,
26
const unsigned int geomID,
27
const unsigned int primID,
28
const bool filter)
29
: ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {}
30
31
template<typename Hit_i>
32
__forceinline bool operator() (Hit_i& hit_i) const
33
{
34
hit_i.finalize();
35
36
Scene* scene MAYBE_UNUSED = context->scene;
37
Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
38
39
/* ray mask test */
40
#if defined(EMBREE_RAY_MASK)
41
if ((geometry->mask & ray.mask) == 0)
42
return false;
43
#endif
44
45
/* call intersection filter function */
46
#if defined(EMBREE_FILTER_FUNCTION)
47
if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter())))
48
{
49
Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng);
50
float old_t = ray.tfar;
51
ray.tfar = hit_i.t;
52
bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
53
if (!found) {
54
ray.tfar = old_t;
55
return false;
56
}
57
}
58
#endif
59
60
ray.tfar = hit_i.t;
61
ray.u = hit_i.u;
62
ray.v = hit_i.v;
63
ray.Ng.x = hit_i.Ng.x;
64
ray.Ng.y = hit_i.Ng.y;
65
ray.Ng.z = hit_i.Ng.z;
66
ray.geomID = geomID;
67
ray.primID = primID;
68
instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID);
69
#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
70
instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID);
71
#endif
72
return true;
73
}
74
75
template<typename Hit_i>
76
__forceinline bool operator() (bool, Hit_i& hit_i) const
77
{
78
hit_i.finalize();
79
80
Scene* scene MAYBE_UNUSED = context->scene;
81
Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
82
83
/* ray mask test */
84
#if defined(EMBREE_RAY_MASK)
85
if ((geometry->mask & ray.mask) == 0)
86
return false;
87
#endif
88
89
const Vec3fa Ng = hit_i.Ng();
90
const Vec2f uv = hit_i.uv();
91
92
/* call intersection filter function */
93
#if defined(EMBREE_FILTER_FUNCTION)
94
if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter())))
95
{
96
Hit h(context->user,geomID,primID,uv,Ng);
97
float old_t = ray.tfar;
98
ray.tfar = hit_i.t();
99
bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
100
if (!found) {
101
ray.tfar = old_t;
102
return false;
103
}
104
}
105
#endif
106
107
ray.tfar = hit_i.t();
108
ray.u = uv.x;
109
ray.v = uv.y;
110
ray.Ng.x = Ng.x;
111
ray.Ng.y = Ng.y;
112
ray.Ng.z = Ng.z;
113
ray.geomID = geomID;
114
ray.primID = primID;
115
instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID);
116
#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
117
instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID);
118
#endif
119
return true;
120
}
121
};
122
123
template<>
124
struct Intersect1Epilog1_HWIF<Ray>
125
{
126
Ray& ray;
127
sycl::private_ptr<RayQueryContext> context;
128
const unsigned int geomID;
129
const unsigned int primID;
130
const bool filter;
131
132
__forceinline Intersect1Epilog1_HWIF(Ray& ray,
133
sycl::private_ptr<RayQueryContext> context,
134
const unsigned int geomID,
135
const unsigned int primID,
136
const bool filter)
137
: ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {}
138
139
template<typename Hit_i>
140
__forceinline bool operator() (Hit_i& hit_i) const
141
{
142
hit_i.finalize();
143
144
Scene* scene MAYBE_UNUSED = context->scene;
145
Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
146
147
/* ray mask test */
148
#if defined(EMBREE_RAY_MASK)
149
if ((geometry->mask & ray.mask) == 0)
150
return false;
151
#endif
152
153
/* call intersection filter function */
154
#if defined(EMBREE_FILTER_FUNCTION)
155
if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter())))
156
{
157
Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng);
158
float old_t = ray.tfar;
159
ray.tfar = hit_i.t;
160
bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
161
if (!found) {
162
ray.tfar = old_t;
163
return false;
164
}
165
}
166
#endif
167
168
ray.tfar = neg_inf;
169
return true;
170
}
171
172
template<typename Hit_i>
173
__forceinline bool operator() (bool, Hit_i& hit_i) const
174
{
175
hit_i.finalize();
176
177
Scene* scene MAYBE_UNUSED = context->scene;
178
Geometry* geometry MAYBE_UNUSED = scene->get(geomID);
179
180
/* ray mask test */
181
#if defined(EMBREE_RAY_MASK)
182
if ((geometry->mask & ray.mask) == 0)
183
return false;
184
#endif
185
186
/* call intersection filter function */
187
#if defined(EMBREE_FILTER_FUNCTION)
188
if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter())))
189
{
190
const Vec3fa Ng = hit_i.Ng();
191
const Vec2f uv = hit_i.uv();
192
Hit h(context->user,geomID,primID,uv,Ng);
193
float old_t = ray.tfar;
194
ray.tfar = hit_i.t();
195
bool found = runIntersectionFilter1SYCL(geometry,ray,context,h);
196
if (!found) {
197
ray.tfar = old_t;
198
return false;
199
}
200
}
201
#endif
202
203
ray.tfar = neg_inf;
204
return true;
205
}
206
};
207
}
208
209