Skip to content

Commit 6f306c4

Browse files
author
Deano
committed
Unit test fixes
All conformance tests now pass except hlbvh now pass on OpenCL and Vulkan Uses a fixed random seed, to ensure if passes on local test will pass on future tests (float point errors can otherwise cause passing tests to fail randomly)
1 parent 657cb96 commit 6f306c4

File tree

7 files changed

+114
-108
lines changed

7 files changed

+114
-108
lines changed

RadeonRays/src/strategy/bvh2lstrategy.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ namespace RadeonRays
5959

6060
struct Bvh2lStrategy::Face
6161
{
62-
// Up to 4 indices
63-
int idx[4];
62+
int idx[3];
63+
int shadeidx;
6464
// Primitive ID within the mesh
6565
int id;
6666
// Idx count
6767
int cnt;
68+
int2 padding;
6869
};
6970

7071
struct Bvh2lStrategy::GpuData

RadeonRays/src/strategy/fatbvhstrategy.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ namespace RadeonRays
350350
int id;
351351
// Idx count
352352
int cnt;
353+
354+
int2 padding;
353355
};
354356

355357
// Create face buffer

Resources/kernels/CL/bvh2l.cl

+5-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ TYPE DEFINITIONS
4949
typedef struct
5050
{
5151
// BVH structure
52-
__global BvhNode* nodes;
52+
__global BvhNode* const nodes;
5353
// Scene positional data
54-
__global float3* vertices;
54+
__global float3* const vertices;
5555
// Scene indices
56-
__global Face* faces;
56+
__global Face* const faces;
5757
// Transforms
58-
__global ShapeData* shapes;
58+
__global ShapeData* const shapes;
59+
5960
// Root BVH idx
6061
int rootidx;
6162
} SceneData;

Resources/kernels/CL/fatbvh.cl

+34-37
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ typedef struct
4747
typedef struct
4848
{
4949
// BVH structure
50-
__global FatBvhNode const* nodes;
50+
__global FatBvhNode const* nodes;
5151
// Scene positional data
52-
__global float3 const* vertices;
52+
__global float3 const* vertices;
5353
// Scene indices
54-
__global Face const* faces;
54+
__global Face const* faces;
5555
// Shape IDs
56-
__global ShapeData const* shapes;
56+
__global ShapeData const* shapes;
5757
// Extra data
58-
__global int const* extra;
58+
__global int const* extra;
5959
} SceneData;
6060

6161
/*************************************************************************
@@ -68,7 +68,7 @@ HELPER FUNCTIONS
6868
BVH FUNCTIONS
6969
**************************************************************************/
7070
// intersect a ray with leaf BVH node
71-
bool IntersectLeafClosest(
71+
void IntersectLeafClosest(
7272
SceneData const* scenedata,
7373
int faceidx,
7474
ray const* r, // ray to instersect
@@ -91,11 +91,8 @@ bool IntersectLeafClosest(
9191
{
9292
isect->primid = face.id;
9393
isect->shapeid = scenedata->shapes[face.shapeidx].id;
94-
return true;
9594
}
9695
}
97-
98-
return false;
9996
}
10097

10198
// intersect a ray with leaf BVH node
@@ -250,10 +247,10 @@ bool IntersectSceneClosest(SceneData const* scenedata, ray const* r, Intersectio
250247
if (r->o.w < 0.f)
251248
return false;
252249

253-
int stack[32];
250+
int stack[32];
254251

255-
int* sptr = stack;
256-
*sptr++ = -1;
252+
int* sptr = stack;
253+
*sptr++ = -1;
257254

258255
int idx = 0;
259256
FatBvhNode node;
@@ -278,8 +275,8 @@ bool IntersectSceneClosest(SceneData const* scenedata, ray const* r, Intersectio
278275
{
279276
IntersectLeafClosest(scenedata, STARTIDX(node.lbound), r, isect);
280277
}
281-
282-
if (rightleaf)
278+
279+
if (rightleaf)
283280
{
284281
IntersectLeafClosest(scenedata, STARTIDX(node.rbound), r, isect);
285282
}
@@ -298,7 +295,7 @@ bool IntersectSceneClosest(SceneData const* scenedata, ray const* r, Intersectio
298295
deferred = (int)node.rbound.pmax.w;
299296
}
300297

301-
*sptr++ = deferred;
298+
*sptr++ = deferred;
302299
continue;
303300
}
304301
else if (lefthit > 0)
@@ -312,7 +309,7 @@ bool IntersectSceneClosest(SceneData const* scenedata, ray const* r, Intersectio
312309
continue;
313310
}
314311

315-
idx = *--sptr;
312+
idx = *--sptr;
316313
}
317314

318315
return isect->shapeid >= 0;
@@ -357,13 +354,13 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r, __global int* s
357354
if (leftleaf)
358355
{
359356
if (IntersectLeafAny(scenedata, STARTIDX(node.lbound), r))
360-
return true;
357+
return true;
361358
}
362359

363360
if (rightleaf)
364361
{
365362
if (IntersectLeafAny(scenedata, STARTIDX(node.rbound), r))
366-
return true;
363+
return true;
367364
}
368365

369366
if (lefthit > 0.f && righthit > 0.f)
@@ -394,17 +391,17 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r, __global int* s
394391

395392
*lsptr = deferred;
396393
lsptr += 64;
397-
continue;
394+
continue;
398395
}
399396
else if (lefthit > 0)
400397
{
401398
idx = (int)node.lbound.pmax.w;
402-
continue;
399+
continue;
403400
}
404401
else if (righthit > 0)
405402
{
406403
idx = (int)node.rbound.pmax.w;
407-
continue;
404+
continue;
408405
}
409406

410407
lsptr -= 64;
@@ -436,10 +433,10 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r)
436433
if (r->o.w < 0.f)
437434
return false;
438435

439-
int stack[32];
436+
int stack[32];
440437

441-
int* sptr = stack;
442-
*sptr++ = -1;
438+
int* sptr = stack;
439+
*sptr++ = -1;
443440

444441
int idx = 0;
445442
FatBvhNode node;
@@ -450,7 +447,7 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r)
450447
float righthit = 0.f;
451448
int step = 0;
452449

453-
bool found = false;
450+
bool found = false;
454451

455452
while (idx > -1)
456453
{
@@ -465,19 +462,19 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r)
465462
if (leftleaf)
466463
{
467464
if (IntersectLeafAny(scenedata, STARTIDX(node.lbound), r))
468-
{
469-
found = true;
470-
break;
471-
}
465+
{
466+
found = true;
467+
break;
468+
}
472469
}
473470

474-
if (rightleaf)
471+
if (rightleaf)
475472
{
476473
if (IntersectLeafAny(scenedata, STARTIDX(node.rbound), r))
477-
{
478-
found = true;
479-
break;
480-
}
474+
{
475+
found = true;
476+
break;
477+
}
481478
}
482479

483480
if (lefthit > 0.f && righthit > 0.f)
@@ -494,7 +491,7 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r)
494491
deferred = (int)node.rbound.pmax.w;
495492
}
496493

497-
*sptr++ = deferred;
494+
*sptr++ = deferred;
498495
}
499496
else if (lefthit > 0)
500497
{
@@ -505,8 +502,8 @@ bool IntersectSceneAny(SceneData const* scenedata, ray const* r)
505502
idx = (int)node.rbound.pmax.w;
506503
}
507504

508-
if (lefthit <= 0.f && righthit <= 0.f)
509-
idx = *--sptr;
505+
if (lefthit <= 0.f && righthit <= 0.f)
506+
idx = *--sptr;
510507
}
511508

512509
return found;

Resources/kernels/GLSL/fatbvh.comp

+50-53
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 430
1+
#version 430
22

33
// Note Anvil define system assumes first line is alway a #version so don't rearrange
44

@@ -471,73 +471,70 @@ void IntersectSceneClosest(in ray r, inout Intersection isect, in int stack, in
471471

472472
while (idx > -1)
473473
{
474-
while (idx > -1)
475-
{
476-
node = Nodes[idx];
474+
node = Nodes[idx];
477475

478-
leftleaf = LEAFNODE(node.lbound);
479-
rightleaf = LEAFNODE(node.rbound);
476+
leftleaf = LEAFNODE(node.lbound);
477+
rightleaf = LEAFNODE(node.rbound);
480478

481-
lefthit = leftleaf ? -1.f : IntersectBoxF(r, invdir, node.lbound, isect.uvwt.w);
482-
righthit = rightleaf ? -1.f : IntersectBoxF(r, invdir, node.rbound, isect.uvwt.w);
479+
lefthit = leftleaf ? -1.f : IntersectBoxF(r, invdir, node.lbound, isect.uvwt.w);
480+
righthit = rightleaf ? -1.f : IntersectBoxF(r, invdir, node.rbound, isect.uvwt.w);
483481

484-
if (leftleaf)
482+
if (leftleaf)
483+
{
484+
IntersectLeafClosest(STARTIDX(node.lbound), r, isect);
485+
}
486+
487+
if (rightleaf)
488+
{
489+
IntersectLeafClosest(STARTIDX(node.rbound), r, isect);
490+
}
491+
492+
if (lefthit > 0.f && righthit > 0.f)
493+
{
494+
int deferred = -1;
495+
if (lefthit > righthit)
485496
{
486-
IntersectLeafClosest(STARTIDX(node.lbound), r, isect);
497+
idx = int(node.rbound.pmax.w);
498+
deferred = int(node.lbound.pmax.w);
487499
}
488-
489-
if (rightleaf)
500+
else
490501
{
491-
IntersectLeafClosest(STARTIDX(node.rbound), r, isect);
502+
idx = int(node.lbound.pmax.w);
503+
deferred = int(node.rbound.pmax.w);
492504
}
493505

494-
if (lefthit > 0.f && righthit > 0.f)
506+
if (lsptr - ldsstack >= SHORT_STACK_SIZE * 64)
495507
{
496-
int deferred = -1;
497-
if (lefthit > righthit)
498-
{
499-
idx = int(node.rbound.pmax.w);
500-
deferred = int(node.lbound.pmax.w);
501-
}
502-
else
508+
for (int i = 1; i < SHORT_STACK_SIZE; ++i)
503509
{
504-
idx = int(node.lbound.pmax.w);
505-
deferred = int(node.rbound.pmax.w);
510+
//gsptr[i] = ldsstack[i * 64];
511+
GlobalStack[ gsptr + i ] = LDSStack[ ldsstack + i * 64 ];
506512
}
507513

508-
if (lsptr - ldsstack >= SHORT_STACK_SIZE * 64)
509-
{
510-
for (int i = 1; i < SHORT_STACK_SIZE; ++i)
511-
{
512-
//gsptr[i] = ldsstack[i * 64];
513-
GlobalStack[ gsptr + i ] = LDSStack[ ldsstack + i * 64 ];
514-
}
515-
516-
gsptr += SHORT_STACK_SIZE;
517-
lsptr = ldsstack + 64;
518-
}
519-
520-
//*lsptr = deferred;
521-
LDSStack[ lsptr ] = deferred;
522-
lsptr += 64;
523-
524-
continue;
525-
}
526-
else if (lefthit > 0)
527-
{
528-
idx = int(node.lbound.pmax.w);
529-
continue;
530-
}
531-
else if (righthit > 0)
532-
{
533-
idx = int(node.rbound.pmax.w);
534-
continue;
514+
gsptr += SHORT_STACK_SIZE;
515+
lsptr = ldsstack + 64;
535516
}
536517

537-
lsptr -= 64;
538-
//idx = *(lsptr);
539-
idx = LDSStack[ lsptr ];
518+
//*lsptr = deferred;
519+
LDSStack[ lsptr ] = deferred;
520+
lsptr += 64;
521+
522+
continue;
523+
}
524+
else if (lefthit > 0)
525+
{
526+
idx = int(node.lbound.pmax.w);
527+
continue;
540528
}
529+
else if (righthit > 0)
530+
{
531+
idx = int(node.rbound.pmax.w);
532+
continue;
533+
}
534+
535+
lsptr -= 64;
536+
//idx = *(lsptr);
537+
idx = LDSStack[ lsptr ];
541538

542539
if (gsptr > stack)
543540
{

0 commit comments

Comments
 (0)