|
| 1 | +// RUN: %dxc -T lib_6_6 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=.256;512;1024. | %FileCheck %s |
| 2 | + |
| 3 | +// This file is checking for the correct access tracking for a descriptor-heap-indexed TLAS for TraceRay. |
| 4 | + |
| 5 | +// First advance through the output text to where the handle for heap index 7 is created: |
| 6 | +// CHECK: call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 7 |
| 7 | + |
| 8 | +// The next buffer store should be for this resource. |
| 9 | +// See DxilShaderAccessTracking::EmitResourceAccess for how this index is calculated. |
| 10 | +// It's the descriptor heap index (7, as seen in the HLSL below) plus 1 (to skip |
| 11 | +// over the "out-of-bounds" entry in the output UAV) times 8 DWORDs per record |
| 12 | +// (the first DWORD for write, the second for read), plus 4 to offset to the "read" record. |
| 13 | +// Read access for descriptor 7 is therefore at (7+1)*8+4 = 68. |
| 14 | +// This is then added to the base address for dynamic writes, which is 256 |
| 15 | +// (from the config=.256 in the command-line above), for a total of 324. |
| 16 | + |
| 17 | +// CHECK: call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %[[UAV:[0-9+]]], i32 324, |
| 18 | + |
| 19 | +RWTexture2D<float4> RTOutput : register(u0); |
| 20 | + |
| 21 | +struct PayloadData |
| 22 | +{ |
| 23 | + uint index : INDEX; |
| 24 | +}; |
| 25 | + |
| 26 | +struct AttributeData |
| 27 | +{ |
| 28 | + float2 barycentrics; |
| 29 | +}; |
| 30 | + |
| 31 | +struct ColorConstant |
| 32 | +{ |
| 33 | + uint3 color; |
| 34 | +}; |
| 35 | + |
| 36 | +struct AlphaConstant |
| 37 | +{ |
| 38 | + uint alpha; |
| 39 | +}; |
| 40 | + |
| 41 | + |
| 42 | +ConstantBuffer<ColorConstant> color : register(b0); |
| 43 | +ConstantBuffer<AlphaConstant> alpha : register(b1); |
| 44 | + |
| 45 | +[shader("raygeneration")] |
| 46 | +void RayGenMain() |
| 47 | +{ |
| 48 | + uint2 index = DispatchRaysIndex().xy; |
| 49 | + uint2 dim = DispatchRaysDimensions().xy; |
| 50 | + |
| 51 | + PayloadData payload; |
| 52 | + payload.index = index.y * dim.x + index.x; |
| 53 | + |
| 54 | + RayDesc ray; |
| 55 | + ray.Origin.x = 2.0 * (index.x + 0.5) / dim.x - 1.0; |
| 56 | + ray.Origin.y = 1.0 - 2.0 * (index.y + 0.5) / dim.y; |
| 57 | + ray.Origin.z = 0.0; |
| 58 | + ray.Direction = float3(0, 0, -1); |
| 59 | + ray.TMin = 0.01; |
| 60 | + ray.TMax = 100.0; |
| 61 | + |
| 62 | + RaytracingAccelerationStructure scene = ResourceDescriptorHeap[7]; |
| 63 | + |
| 64 | + TraceRay( |
| 65 | + scene, // Acceleration structure |
| 66 | + 0, // Ray flags |
| 67 | + 0xFF, // Instance inclusion mask |
| 68 | + 0, // RayContributionToHitGroupIndex |
| 69 | + 1, // MultiplierForGeometryContributionToHitGroupIndex |
| 70 | + 0, // MissShaderIndex |
| 71 | + ray, |
| 72 | + payload); |
| 73 | + |
| 74 | + RTOutput[index] = float4(color.color.r / 255.0f, color.color.g / 255.0f, color.color.b / 255.0f, alpha.alpha / 255.0f); |
| 75 | +} |
| 76 | + |
0 commit comments