|
| 1 | +#--- source.hlsl |
| 2 | + |
| 3 | +[[vk::binding(0, 0)]] RaytracingAccelerationStructure Scene : register(t0); |
| 4 | +[[vk::binding(1, 0)]] RWStructuredBuffer<uint> Output : register(u0); |
| 5 | + |
| 6 | +[numthreads(2,1,1)] |
| 7 | +void main(uint3 tid : SV_DispatchThreadID) { |
| 8 | + // The triangle vertices wind CW from +z under the DX / VK / MTL ray- |
| 9 | + // traversal convention. Two instances tiled along x: instance 0 has no |
| 10 | + // flags (front-facing), instance 1 has TriangleFrontCounterclockwise |
| 11 | + // (winding interpretation flips → back-facing). |
| 12 | + RayDesc Ray; |
| 13 | + Ray.Origin = float3((float(tid.x) - 0.5) * 4.0, 0, 1); |
| 14 | + Ray.Direction = float3(0, 0, -1); |
| 15 | + Ray.TMin = 0.0; |
| 16 | + Ray.TMax = 100.0; |
| 17 | + RayQuery<RAY_FLAG_NONE> Q; |
| 18 | + Q.TraceRayInline(Scene, RAY_FLAG_NONE, 0xFF, Ray); |
| 19 | + Q.Proceed(); |
| 20 | + Output[tid.x] = Q.CommittedStatus() == COMMITTED_TRIANGLE_HIT |
| 21 | + ? (uint)Q.CommittedTriangleFrontFace() |
| 22 | + : 0xFFFFFFFF; |
| 23 | +} |
| 24 | +//--- pipeline.yaml |
| 25 | +--- |
| 26 | +Shaders: |
| 27 | + - Stage: Compute |
| 28 | + Entry: main |
| 29 | +Buffers: |
| 30 | + - Name: Vertices |
| 31 | + Format: Float32 |
| 32 | + Stride: 12 |
| 33 | + Data: [ 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0 ] |
| 34 | + - Name: Output |
| 35 | + Format: UInt32 |
| 36 | + Stride: 4 |
| 37 | + FillSize: 8 |
| 38 | + - Name: Expected |
| 39 | + Format: UInt32 |
| 40 | + Stride: 4 |
| 41 | + # Instance 0: default winding → front face (1) |
| 42 | + # Instance 1: TriangleFrontCounterclockwise flips → back face (0) |
| 43 | + Data: [ 1, 0 ] |
| 44 | +AccelerationStructures: |
| 45 | + BLAS: |
| 46 | + - Name: TriangleBLAS |
| 47 | + Triangles: |
| 48 | + - VertexBuffer: Vertices |
| 49 | + VertexFormat: RGB32Float |
| 50 | + VertexStride: 12 |
| 51 | + VertexCount: 3 |
| 52 | + TLAS: |
| 53 | + - Name: Scene |
| 54 | + Instances: |
| 55 | + - BLAS: TriangleBLAS |
| 56 | + Transform: [1, 0, 0, -2, 0, 1, 0, 0, 0, 0, 1, 0] |
| 57 | + - BLAS: TriangleBLAS |
| 58 | + Transform: [1, 0, 0, 2, 0, 1, 0, 0, 0, 0, 1, 0] |
| 59 | + InstanceFlags: [TriangleFrontCounterclockwise] |
| 60 | +DescriptorSets: |
| 61 | + - Resources: |
| 62 | + - Name: Scene |
| 63 | + Kind: AccelerationStructure |
| 64 | + DirectXBinding: |
| 65 | + Register: 0 |
| 66 | + Space: 0 |
| 67 | + VulkanBinding: |
| 68 | + Binding: 0 |
| 69 | + - Name: Output |
| 70 | + Kind: RWStructuredBuffer |
| 71 | + DirectXBinding: |
| 72 | + Register: 0 |
| 73 | + Space: 0 |
| 74 | + VulkanBinding: |
| 75 | + Binding: 1 |
| 76 | +Results: |
| 77 | + - Result: InstanceFlags |
| 78 | + Rule: BufferExact |
| 79 | + Actual: Output |
| 80 | + Expected: Expected |
| 81 | +... |
| 82 | +#--- end |
| 83 | + |
| 84 | +# REQUIRES: acceleration-structure |
| 85 | +# XFAIL: Clang |
| 86 | + |
| 87 | +# RUN: split-file %s %t |
| 88 | +# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl |
| 89 | +# RUN: %offloader %t/pipeline.yaml %t.o |
0 commit comments