Skip to content

Commit 15140b1

Browse files
committed
Fix GetAttributesTest: procedural not contained in AABB / use integer arith for hitKind computation
1 parent c3c399f commit 15140b1

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

tools/clang/unittests/HLSLExec/ExecutionTest_SER.h

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ void raygen()
15091509
}
15101510
else
15111511
{
1512-
// Use 255 to keep outside the HitKind range [0, 127] we passthru for hits.
1512+
// Use 255 to keep outside the HitKind range [0,15] we passthru for hits.
15131513
testVal = 255;
15141514
}
15151515
int id = launchIndex.x + launchIndex.y * launchDim.x;
@@ -1537,28 +1537,35 @@ void closesthit(inout PerRayData payload, in CustomAttrs attrs)
15371537
[shader("intersection")]
15381538
void intersection()
15391539
{
1540+
// Intersection with circle on a plane (base, n, radius)
15401541
// hitPos is intersection point with plane (base, n)
15411542
float3 base = {0.0f,0.0f,0.5f};
15421543
float3 n = normalize(float3(0.0f,0.5f,0.5f));
1544+
float radius = 500.f;
1545+
// Plane hit
15431546
float t = dot(n, base - ObjectRayOrigin()) / dot(n, ObjectRayDirection());
1544-
if (t > RayTCurrent() || t < RayTMin()) {
1547+
if (t > RayTCurrent() || t < RayTMin())
15451548
return;
1546-
}
15471549
float3 hitPos = ObjectRayOrigin() + t * ObjectRayDirection();
15481550
float3 relHitPos = hitPos - base;
1549-
// Encode some hit information in hitKind
1550-
int hitKind = 0;
1551-
if (relHitPos.y >= 0.0f)
1552-
hitKind = 1;
1553-
hitKind *= 2;
1554-
if (relHitPos.x >= 0.0f)
1555-
hitKind += 1;
1556-
hitKind *= 2;
1557-
if (relHitPos.z >= 0.0f)
1558-
hitKind += 1;
1551+
// Circle hit
1552+
float hitDist = length(relHitPos);
1553+
if (hitDist > radius)
1554+
return;
15591555
15601556
CustomAttrs attrs;
1561-
attrs.dist = length(relHitPos);
1557+
attrs.dist = hitDist;
1558+
1559+
// Generate wave-incoherent hitKind
1560+
uint2 launchIndex = DispatchRaysIndex().xy;
1561+
uint hitKind = 1U;
1562+
if (launchIndex.x >= 32)
1563+
hitKind |= 2U;
1564+
if (launchIndex.y >= 32)
1565+
hitKind |= 4U;
1566+
if ((launchIndex.x + launchIndex.y) % 2 == 0)
1567+
hitKind |= 8U;
1568+
15621569
ReportHit(t, hitKind, attrs);
15631570
}
15641571
@@ -1580,12 +1587,18 @@ void intersection()
15801587
std::map<int, int> Histo;
15811588
for (int Val : TestData)
15821589
++Histo[Val];
1583-
VERIFY_ARE_EQUAL(Histo.size(), 5);
1584-
VERIFY_ARE_EQUAL(Histo[0], 2009);
1585-
VERIFY_ARE_EQUAL(Histo[1], 561);
1586-
VERIFY_ARE_EQUAL(Histo[3], 587);
1587-
VERIFY_ARE_EQUAL(Histo[4], 454);
1588-
VERIFY_ARE_EQUAL(Histo[6], 485);
1590+
1591+
VERIFY_ARE_EQUAL(Histo.size(), 10);
1592+
VERIFY_ARE_EQUAL(Histo[0], 1587);
1593+
VERIFY_ARE_EQUAL(Histo[1], 277);
1594+
VERIFY_ARE_EQUAL(Histo[3], 256);
1595+
VERIFY_ARE_EQUAL(Histo[5], 167);
1596+
VERIFY_ARE_EQUAL(Histo[7], 153);
1597+
VERIFY_ARE_EQUAL(Histo[9], 249);
1598+
VERIFY_ARE_EQUAL(Histo[11], 260);
1599+
VERIFY_ARE_EQUAL(Histo[13], 158);
1600+
VERIFY_ARE_EQUAL(Histo[15], 142);
1601+
VERIFY_ARE_EQUAL(Histo[255], 847);
15891602
}
15901603

15911604
TEST_F(ExecutionTest, SERTraceHitMissNopTest) {

0 commit comments

Comments
 (0)