Skip to content

Commit 7672d16

Browse files
committed
Implemented a new ray masking technique for all OpenCL intersection kernels.
The remnants of the deprecated ray masking implementation have been removed. The new ray masking implementation uses the mesh/shape id to distinguish whether a shape is masked or not on a per ray basis. With this new implementation, each ray can only ignore one specific mesh per call to the intersection kernel. However, the number of unique shapes that can be ignored is only limited by the positive range of a signed integer (MAX_INT - 1). When ray masking is disabled through the CMake config switch all ray masking checks in the intersection kernels are disabled at compile time to make sure that there is no performance impact when not using the feature.
1 parent d0d4a33 commit 7672d16

19 files changed

+756
-210
lines changed

Doc/RadeonRays.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,7 @@ virtual Id Shape::GetId() const = 0;
354354
```
355355
Work with shape id. This id will be used in results of QueryIntersection().
356356
* *id* - new shape id.
357-
```
358-
virtual void Shape::SetMask(int mask) = 0;
359-
virtual int Shape::GetMask() const = 0;
360-
```
361-
Geometry mask to mask out intersections.
362-
* *mask* - mask of shape.
357+
363358
#### Memory management
364359
```
365360
Buffer* IntersectionApi::CreateBuffer(size_t size, void* initdata) const override;

RadeonRays/include/math/ray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace RadeonRays
4040
{
4141
SetMaxT(maxt);
4242
SetTime(time);
43-
SetMask(0xFFFFFFFF);
43+
SetMask(-1);
4444
SetActive(true);
4545
}
4646

RadeonRays/include/radeon_rays.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ namespace RadeonRays
107107
// ID of a shape
108108
virtual void SetId(Id id) = 0;
109109
virtual Id GetId() const = 0;
110-
111-
// Geometry mask to mask out intersections
112-
virtual void SetMask(int mask) = 0;
113-
virtual int GetMask() const = 0;
114110
};
115111

116112
// Buffer represents a chunk of memory hosted inside the API

RadeonRays/src/intersector/intersector_2level.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace RadeonRays
4242
Id id;
4343
// Index of root bvh node
4444
int bvhidx;
45-
int mask;
45+
// Is the shape disabled?
46+
unsigned int shapeDisabled;
4647
int padding1;
4748
// Transform
4849
matrix minv;
@@ -56,8 +57,6 @@ namespace RadeonRays
5657
{
5758
// Up to 3 indices
5859
int idx[3];
59-
// Shape maks
60-
int shape_mask;
6160
// Shape ID
6261
int shape_id;
6362
// Primitive ID
@@ -455,11 +454,11 @@ namespace RadeonRays
455454
// and we need to skip them while doing traversal.
456455
if (shapes_disabled.find(shapeimpl) == shapes_disabled.cend())
457456
{
458-
m_cpudata->shapedata[i].mask = shapeimpl->GetMask();
457+
m_cpudata->shapedata[i].shapeDisabled = 0;
459458
}
460459
else
461460
{
462-
m_cpudata->shapedata[i].mask = 0x0;
461+
m_cpudata->shapedata[i].shapeDisabled = 1;
463462
}
464463

465464
shapeimpl->GetTransform(m, m_cpudata->shapedata[i].minv);
@@ -618,11 +617,11 @@ namespace RadeonRays
618617
// and we need to skip them while doing traversal.
619618
if (shapes_disabled.find(shapeimpl) == shapes_disabled.cend())
620619
{
621-
m_cpudata->shapedata[i].mask = shapeimpl->GetMask();
620+
m_cpudata->shapedata[i].shapeDisabled = 0;
622621
}
623622
else
624623
{
625-
m_cpudata->shapedata[i].mask = 0x0;
624+
m_cpudata->shapedata[i].shapeDisabled = 1;
626625
}
627626

628627
shapeimpl->GetTransform(m, m_cpudata->shapedata[i].minv);

RadeonRays/src/intersector/intersector_bittrail.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ namespace RadeonRays
372372
facedata[i].idx[2] = myfacedata[faceidx].idx[2] + mystartidx;
373373

374374
facedata[i].shapeidx = shapes[shapeidx]->GetId();
375-
facedata[i].shape_mask = shapes[shapeidx]->GetMask();
376375
facedata[i].id = faceidx;
377376
}
378377

RadeonRays/src/intersector/intersector_hlbvh.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ namespace RadeonRays
222222
{
223223
// Up to 3 indices
224224
int idx[3];
225-
// Shape maks
226-
int shape_mask;
227225
// Shape ID
228226
int shape_id;
229227
// Primitive ID
@@ -273,7 +271,6 @@ namespace RadeonRays
273271

274272
// Optimization: we are putting faceid here
275273
facedata[i].shape_id = mesh->GetId();
276-
facedata[i].shape_mask = mesh->GetMask();
277274
facedata[i].prim_id = faceidx;
278275
}
279276

RadeonRays/src/intersector/intersector_short_stack.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ namespace RadeonRays
385385
facedata[i].idx[2] = myfacedata[faceidx].idx[2] + mystartidx;
386386

387387
facedata[i].shapeidx = shapes[shapeidx]->GetId();
388-
facedata[i].shape_mask = shapes[shapeidx]->GetMask();
389388
facedata[i].id = faceidx;
390389
}
391390

RadeonRays/src/intersector/intersector_skip_links.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,6 @@ namespace RadeonRays
331331
{
332332
// Up to 3 indices
333333
int idx[3];
334-
// Shape maks
335-
int shape_mask;
336334
// Shape ID
337335
int shape_id;
338336
// Primitive ID
@@ -393,7 +391,6 @@ namespace RadeonRays
393391

394392
// Optimization: we are putting faceid here
395393
facedata[i].shape_id = shapes[shapeidx]->GetId();
396-
facedata[i].shape_mask = shapes[shapeidx]->GetMask();
397394
facedata[i].prim_id = faceidx;
398395
}
399396

RadeonRays/src/kernels/CL/intersect_bvh2_bittrail.cl

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ typedef struct
115115
int i0, i1, i2;
116116
// Address of a left child
117117
int child0;
118-
// Shape mask
119-
int shape_mask;
120118
// Shape ID
121119
int shape_id;
122120
// Primitive ID
@@ -183,19 +181,26 @@ occluded_main(
183181
// Check if it is a leaf
184182
if (LEAFNODE(node))
185183
{
186-
// Leafs directly store vertex indices
187-
// so we load vertices directly
188-
float3 const v1 = vertices[node.i0];
189-
float3 const v2 = vertices[node.i1];
190-
float3 const v3 = vertices[node.i2];
191-
// Intersect triangle
192-
float const f = fast_intersect_triangle(r, v1, v2, v3, t_max);
193-
// If hit store the result and bail out
194-
if (f < t_max)
184+
#ifdef RR_RAY_MASK
185+
if (ray_get_mask(&r) != node.shape_id)
195186
{
196-
hits[global_id] = HIT_MARKER;
197-
return;
187+
#endif
188+
// Leafs directly store vertex indices
189+
// so we load vertices directly
190+
float3 const v1 = vertices[node.i0];
191+
float3 const v2 = vertices[node.i1];
192+
float3 const v3 = vertices[node.i2];
193+
// Intersect triangle
194+
float const f = fast_intersect_triangle(r, v1, v2, v3, t_max);
195+
// If hit store the result and bail out
196+
if (f < t_max)
197+
{
198+
hits[global_id] = HIT_MARKER;
199+
return;
200+
}
201+
#ifdef RR_RAY_MASK
198202
}
203+
#endif
199204
}
200205
else
201206
{
@@ -327,19 +332,26 @@ KERNEL void intersect_main(
327332
// Check if it is a leaf
328333
if (LEAFNODE(node))
329334
{
330-
// Leafs directly store vertex indices
331-
// so we load vertices directly
332-
float3 const v1 = vertices[node.i0];
333-
float3 const v2 = vertices[node.i1];
334-
float3 const v3 = vertices[node.i2];
335-
// Intersect triangle
336-
float const f = fast_intersect_triangle(r, v1, v2, v3, t_max);
337-
// If hit update closest hit distance and index
338-
if (f < t_max)
335+
#ifdef RR_RAY_MASK
336+
if (ray_get_mask(&r) != node.shape_id)
339337
{
340-
t_max = f;
341-
isect_idx = addr;
338+
#endif
339+
// Leafs directly store vertex indices
340+
// so we load vertices directly
341+
float3 const v1 = vertices[node.i0];
342+
float3 const v2 = vertices[node.i1];
343+
float3 const v3 = vertices[node.i2];
344+
// Intersect triangle
345+
float const f = fast_intersect_triangle(r, v1, v2, v3, t_max);
346+
// If hit update closest hit distance and index
347+
if (f < t_max)
348+
{
349+
t_max = f;
350+
isect_idx = addr;
351+
}
352+
#ifdef RR_RAY_MASK
342353
}
354+
#endif
343355
}
344356
else
345357
{

RadeonRays/src/kernels/CL/intersect_bvh2_lds.cl

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,25 @@ KERNEL void intersect_main(
160160
}
161161
else
162162
{
163-
float t = fast_intersect_triangle(
164-
my_ray,
165-
node.aabb_left_min_or_v0_and_addr_left.xyz,
166-
node.aabb_left_max_or_v1_and_mesh_id.xyz,
167-
node.aabb_right_min_or_v2_and_addr_right.xyz,
168-
closest_t);
169-
170-
if (t < closest_t)
163+
#ifdef RR_RAY_MASK
164+
if (ray_get_mask(&my_ray) != convert_int(GetMeshId(node)))
171165
{
172-
closest_t = t;
173-
closest_addr = addr;
166+
#endif
167+
float t = fast_intersect_triangle(
168+
my_ray,
169+
node.aabb_left_min_or_v0_and_addr_left.xyz,
170+
node.aabb_left_max_or_v1_and_mesh_id.xyz,
171+
node.aabb_right_min_or_v2_and_addr_right.xyz,
172+
closest_t);
173+
174+
if (t < closest_t)
175+
{
176+
closest_t = t;
177+
closest_addr = addr;
178+
}
179+
#ifdef RR_RAY_MASK
174180
}
181+
#endif
175182
}
176183

177184
addr = lds_stack[--lds_sptr];
@@ -313,18 +320,25 @@ KERNEL void occluded_main(
313320
}
314321
else
315322
{
316-
float t = fast_intersect_triangle(
317-
my_ray,
318-
node.aabb_left_min_or_v0_and_addr_left.xyz,
319-
node.aabb_left_max_or_v1_and_mesh_id.xyz,
320-
node.aabb_right_min_or_v2_and_addr_right.xyz,
321-
closest_t);
322-
323-
if (t < closest_t)
323+
#ifdef RR_RAY_MASK
324+
if (ray_get_mask(&my_ray) != convert_int(GetMeshId(node)))
324325
{
325-
hits[index] = HIT_MARKER;
326-
return;
326+
#endif
327+
float t = fast_intersect_triangle(
328+
my_ray,
329+
node.aabb_left_min_or_v0_and_addr_left.xyz,
330+
node.aabb_left_max_or_v1_and_mesh_id.xyz,
331+
node.aabb_right_min_or_v2_and_addr_right.xyz,
332+
closest_t);
333+
334+
if (t < closest_t)
335+
{
336+
hits[index] = HIT_MARKER;
337+
return;
338+
}
339+
#ifdef RR_RAY_MASK
327340
}
341+
#endif
328342
}
329343

330344
addr = lds_stack[--lds_sptr];

0 commit comments

Comments
 (0)