|
| 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(3,1,1)] |
| 7 | +void main(uint3 tid : SV_DispatchThreadID) { |
| 8 | + // Three instances of the same triangle BLAS tiled along x at x = -4, 0, +4 |
| 9 | + // with distinct InstanceContributionToHitGroupIndex values. Each lane fires |
| 10 | + // straight down at its own instance, so CommittedInstanceContributionToHit- |
| 11 | + // GroupIndex() must equal the per-instance value. |
| 12 | + RayDesc Ray; |
| 13 | + Ray.Origin = float3((float(tid.x) - 1.0) * 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 | + ? Q.CommittedInstanceContributionToHitGroupIndex() |
| 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: 12 |
| 38 | + - Name: Expected |
| 39 | + Format: UInt32 |
| 40 | + Stride: 4 |
| 41 | + # 24-bit field: highest legal value is 0xFFFFFF. Pick three distinct |
| 42 | + # values across the range, including one that exercises the top bits. |
| 43 | + Data: [ 7, 99, 16777215 ] |
| 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, -4, 0, 1, 0, 0, 0, 0, 1, 0] |
| 57 | + InstanceContributionToHitGroupIndex: 7 |
| 58 | + - BLAS: TriangleBLAS |
| 59 | + Transform: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] |
| 60 | + InstanceContributionToHitGroupIndex: 99 |
| 61 | + - BLAS: TriangleBLAS |
| 62 | + Transform: [1, 0, 0, 4, 0, 1, 0, 0, 0, 0, 1, 0] |
| 63 | + InstanceContributionToHitGroupIndex: 16777215 |
| 64 | +DescriptorSets: |
| 65 | + - Resources: |
| 66 | + - Name: Scene |
| 67 | + Kind: AccelerationStructure |
| 68 | + DirectXBinding: |
| 69 | + Register: 0 |
| 70 | + Space: 0 |
| 71 | + VulkanBinding: |
| 72 | + Binding: 0 |
| 73 | + - Name: Output |
| 74 | + Kind: RWStructuredBuffer |
| 75 | + DirectXBinding: |
| 76 | + Register: 0 |
| 77 | + Space: 0 |
| 78 | + VulkanBinding: |
| 79 | + Binding: 1 |
| 80 | +Results: |
| 81 | + - Result: InstanceContribution |
| 82 | + Rule: BufferExact |
| 83 | + Actual: Output |
| 84 | + Expected: Expected |
| 85 | +... |
| 86 | +#--- end |
| 87 | + |
| 88 | +# REQUIRES: acceleration-structure |
| 89 | +# XFAIL: Clang |
| 90 | + |
| 91 | +# RUN: split-file %s %t |
| 92 | +# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl |
| 93 | +# RUN: %offloader %t/pipeline.yaml %t.o |
0 commit comments