Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions test/Feature/RT/closest-hit-barycentrics.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#--- source.hlsl

struct Payload {
float2 Bary;
};

[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
[[vk::binding(1, 0)]] RWStructuredBuffer<float> Output : register(u0);

[shader("raygeneration")]
void RayGen() {
// Each lane fires straight down at a clearly-interior point of the single
// triangle (vertices v0=(0,1,0), v1=(-1,-1,0), v2=(1,-1,0)). HLSL's
// closest-hit `barycentrics` attribute holds (u, v) with u + v + w == 1
// and w being vertex-0's weight, so a hit point at
// P = w * v0 + u * v1 + v * v2
// reports bary = (u, v).
// Lane 0 -> bary (0.25, 0.25), hit at 0.5*v0 + 0.25*v1 + 0.25*v2 = (0, 0, 0)
// Lane 1 -> bary (0.5, 0.25), hit at 0.25*v0 + 0.5*v1 + 0.25*v2 = (-0.25,-0.5, 0)
// Lane 2 -> bary (0.25, 0.5), hit at 0.25*v0 + 0.25*v1 + 0.5*v2 = (0.25, -0.5, 0)
// All three points sit well inside the triangle so the watertight-
// traversal edge rules are not in play and the hits are deterministic
// across rasterizers. Each lane writes 2 floats (u, v) at output offsets
// [2*Index .. 2*Index+1].
const uint Idx = DispatchRaysIndex().x;
const float2 Targets[3] = {float2(0, 0), float2(-0.25, -0.5),
float2(0.25, -0.5)};

Payload P;
P.Bary = float2(0, 0);
RayDesc Ray;
Ray.Origin = float3(Targets[Idx], 1);
Ray.Direction = float3(0, 0, -1);
Ray.TMin = 0.0;
Ray.TMax = 100.0;
TraceRay(Scene, RAY_FLAG_NONE, 0xFF, 0, 1, 0, Ray, P);

Output[2 * Idx + 0] = P.Bary.x;
Output[2 * Idx + 1] = P.Bary.y;
}

[shader("miss")]
void MissMain(inout Payload P) {
// Sentinel β€” every ray hits the triangle in this test.
P.Bary = float2(-1, -1);
}

[shader("closesthit")]
void ClosestHitMain(inout Payload P,
in BuiltInTriangleIntersectionAttributes Attr) {
P.Bary = Attr.barycentrics;
}
//--- pipeline.yaml
---
Shaders:
- Stage: RayGeneration
Entry: RayGen
- Stage: Miss
Entry: MissMain
- Stage: ClosestHit
Entry: ClosestHitMain
Buffers:
- Name: Vertices
Format: Float32
Stride: 12
Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ]
- Name: Output
Format: Float32
Stride: 4
FillSize: 24
- Name: Expected
Format: Float32
Stride: 4
Data: [ 0.25, 0.25, 0.5, 0.25, 0.25, 0.5 ]
AccelerationStructures:
BLAS:
- Name: TriangleBLAS
Triangles:
- VertexBuffer: Vertices
VertexFormat: RGB32Float
VertexStride: 12
VertexCount: 3
TLAS:
- Name: Scene
Instances:
- BLAS: TriangleBLAS
RayTracingPipelineConfig:
MaxTraceRecursionDepth: 1
MaxPayloadSizeInBytes: 8
HitGroups:
- Name: TriangleHitGroup
Type: Triangles
ClosestHit: ClosestHitMain
ShaderBindingTable:
RayGen:
ShaderName: RayGen
Miss:
- ShaderName: MissMain
HitGroup:
- ShaderName: TriangleHitGroup
DescriptorSets:
- Resources:
- Name: Scene
Kind: AccelerationStructure
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Output
Kind: RWStructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 1
DispatchParameters:
DispatchGroupCount: [ 3, 1, 1 ]
Results:
- Result: ClosestHitBarycentrics
Rule: BufferExact
Actual: Output
Expected: Expected
...
#--- end

# REQUIRES: raytracing-pipeline
# Unimplemented https://github.com/llvm/offload-test-suite/issues/1268
# XFAIL: Clang

# RUN: split-file %s %t
# RUN: %dxc_target_lib -T lib_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
124 changes: 124 additions & 0 deletions test/Feature/RT/closest-hit-primitive-index.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#--- source.hlsl

struct Payload {
uint Prim;
};

[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
[[vk::binding(1, 0)]] RWStructuredBuffer<uint> Output : register(u0);

[shader("raygeneration")]
void RayGen() {
// Three triangles tiled along x at x = -3, 0, +3 in a single BLAS. Each
// lane shoots straight down at its own triangle's centroid; the closest-
// hit shader reports its `PrimitiveIndex()` and must match the lane index.
const float Centers[3] = {-3.0, 0.0, 3.0};
const uint Idx = DispatchRaysIndex().x;

Payload P;
P.Prim = 0xFFFFFFFF;
RayDesc Ray;
Ray.Origin = float3(Centers[Idx], 0, 1);
Ray.Direction = float3(0, 0, -1);
Ray.TMin = 0.0;
Ray.TMax = 100.0;
TraceRay(Scene, RAY_FLAG_NONE, 0xFF, 0, 1, 0, Ray, P);
Output[Idx] = P.Prim;
}

[shader("miss")]
void MissMain(inout Payload P) {
P.Prim = 0xDEAD;
}

[shader("closesthit")]
void ClosestHitMain(inout Payload P,
in BuiltInTriangleIntersectionAttributes Attr) {
P.Prim = PrimitiveIndex();
}
//--- pipeline.yaml
---
Shaders:
- Stage: RayGeneration
Entry: RayGen
- Stage: Miss
Entry: MissMain
- Stage: ClosestHit
Entry: ClosestHitMain
Buffers:
- Name: Vertices
Format: Float32
Stride: 12
# Three triangles in one BLAS, each ~1 unit wide, centroid x at -3 / 0 / +3.
Data: [
-3.0, 1.0, 0.0, -4.0, -1.0, 0.0, -2.0, -1.0, 0.0,
0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0,
3.0, 1.0, 0.0, 2.0, -1.0, 0.0, 4.0, -1.0, 0.0,
]
- Name: Output
Format: UInt32
Stride: 4
FillSize: 12
- Name: Expected
Format: UInt32
Stride: 4
Data: [ 0, 1, 2 ]
AccelerationStructures:
BLAS:
- Name: ThreeTrianglesBLAS
Triangles:
- VertexBuffer: Vertices
VertexFormat: RGB32Float
VertexStride: 12
VertexCount: 9
TLAS:
- Name: Scene
Instances:
- BLAS: ThreeTrianglesBLAS
RayTracingPipelineConfig:
MaxTraceRecursionDepth: 1
MaxPayloadSizeInBytes: 4
HitGroups:
- Name: TriangleHitGroup
Type: Triangles
ClosestHit: ClosestHitMain
ShaderBindingTable:
RayGen:
ShaderName: RayGen
Miss:
- ShaderName: MissMain
HitGroup:
- ShaderName: TriangleHitGroup
DescriptorSets:
- Resources:
- Name: Scene
Kind: AccelerationStructure
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Output
Kind: RWStructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 1
DispatchParameters:
DispatchGroupCount: [ 3, 1, 1 ]
Results:
- Result: ClosestHitPrimitiveIndex
Rule: BufferExact
Actual: Output
Expected: Expected
...
#--- end

# REQUIRES: raytracing-pipeline
# Unimplemented https://github.com/llvm/offload-test-suite/issues/1268
# XFAIL: Clang

# RUN: split-file %s %t
# RUN: %dxc_target_lib -T lib_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
128 changes: 128 additions & 0 deletions test/Feature/RT/closest-hit-world-ray.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#--- source.hlsl

struct Payload {
// Packed: (OriginZ, DirectionZ, RayTCurrent) per lane.
float3 Reading;
};

[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0);
[[vk::binding(1, 0)]] RWStructuredBuffer<float> Output : register(u0);

[shader("raygeneration")]
void RayGen() {
// Two lanes fire from different z heights at the single triangle (z=0).
// Lane 0: Origin.z = 1 -> ClosestHit sees Origin.z=1, Dir.z=-1, T=1.
// Lane 1: Origin.z = 2 -> ClosestHit sees Origin.z=2, Dir.z=-1, T=2.
// The ClosestHit reports WorldRayOrigin().z, WorldRayDirection().z, and
// RayTCurrent() through the payload.
const uint Idx = DispatchRaysIndex().x;
const float Origins[2] = {1.0, 2.0};

Payload P;
P.Reading = float3(0, 0, 0);
RayDesc Ray;
Ray.Origin = float3(0, 0, Origins[Idx]);
Ray.Direction = float3(0, 0, -1);
Ray.TMin = 0.0;
Ray.TMax = 100.0;
TraceRay(Scene, RAY_FLAG_NONE, 0xFF, 0, 1, 0, Ray, P);

Output[3 * Idx + 0] = P.Reading.x;
Output[3 * Idx + 1] = P.Reading.y;
Output[3 * Idx + 2] = P.Reading.z;
}

[shader("miss")]
void MissMain(inout Payload P) {
// Sentinel β€” every ray hits the triangle.
P.Reading = float3(-1, -1, -1);
}

[shader("closesthit")]
void ClosestHitMain(inout Payload P,
in BuiltInTriangleIntersectionAttributes Attr) {
P.Reading.x = WorldRayOrigin().z;
P.Reading.y = WorldRayDirection().z;
P.Reading.z = RayTCurrent();
}
//--- pipeline.yaml
---
Shaders:
- Stage: RayGeneration
Entry: RayGen
- Stage: Miss
Entry: MissMain
- Stage: ClosestHit
Entry: ClosestHitMain
Buffers:
- Name: Vertices
Format: Float32
Stride: 12
Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ]
- Name: Output
Format: Float32
Stride: 4
FillSize: 24
- Name: Expected
Format: Float32
Stride: 4
Data: [ 1.0, -1.0, 1.0, 2.0, -1.0, 2.0 ]
AccelerationStructures:
BLAS:
- Name: TriangleBLAS
Triangles:
- VertexBuffer: Vertices
VertexFormat: RGB32Float
VertexStride: 12
VertexCount: 3
TLAS:
- Name: Scene
Instances:
- BLAS: TriangleBLAS
RayTracingPipelineConfig:
MaxTraceRecursionDepth: 1
MaxPayloadSizeInBytes: 12
HitGroups:
- Name: TriangleHitGroup
Type: Triangles
ClosestHit: ClosestHitMain
ShaderBindingTable:
RayGen:
ShaderName: RayGen
Miss:
- ShaderName: MissMain
HitGroup:
- ShaderName: TriangleHitGroup
DescriptorSets:
- Resources:
- Name: Scene
Kind: AccelerationStructure
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Output
Kind: RWStructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 1
DispatchParameters:
DispatchGroupCount: [ 2, 1, 1 ]
Results:
- Result: ClosestHitWorldRay
Rule: BufferExact
Actual: Output
Expected: Expected
...
#--- end

# REQUIRES: raytracing-pipeline
# Unimplemented https://github.com/llvm/offload-test-suite/issues/1268
# XFAIL: Clang

# RUN: split-file %s %t
# RUN: %dxc_target_lib -T lib_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
Loading