Skip to content

Commit a1a661f

Browse files
MarijnS95claude
andcommitted
Bind acceleration structures and enable the InlineRT tests
Wire up acceleration-structure descriptor binding end-to-end across all three backends so shaders can actually consume the TLAS that buildPipelineAccelerationStructures produced — completing the stack and promoting the three InlineRT tests from XFAIL to passing. Vulkan: createDescriptorPool counts AS descriptors in a separate scalar (the KHR enum value 1000150000 doesn't fit in the indexed array used for the core types) and emits one VkDescriptorPoolSize for them. createDescriptorSets resolves each AS resource via Resource::TLASPtr, locates the matching VulkanAccelerationStructure in InvocationState::AccelStructs (BLASes-then-TLASes layout, matching the helper's documented declaration order), and writes the handle through a VkWriteDescriptorSetAccelerationStructureKHR chained on the descriptor write's pNext. The dispatch's pre-barrier dst access now includes VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR so the prior AS-build's writes are made visible to the shader's RayQuery reads. Device creation also enables VK_KHR_ray_query when supported so the RayQuery shader instructions actually function. DX12: writes a D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE SRV with the AS GPU virtual address as Location into the heap slot that createBuffers reserved (CreateShaderResourceView with a null resource — the AS data lives in the buffer pointed to by Location). Metal: the Metal shader converter doesn't bind the AS directly; the shader reads a buffer containing an IRRaytracingAccelerationStructure- GPUHeader that holds the AS's gpuResourceID plus a pointer to an instance-contributions array. createBuffers allocates and fills both buffers per AS-descriptor entry, then points the descriptor at the header buffer's GPU address. The TLAS itself is built with the UserID instance-descriptor variant so HLSL CommittedInstanceID() returns the YAML-specified per-instance ID instead of the array index. The three InlineRT tests now actually exercise the AS end-to-end: TraceRayInline issues a RayQuery against `Scene` and writes a hit-dependent value into `Output` (the instance ID for multi-instance, 1/0 otherwise). The catch-all `XFAIL: *` is dropped; `XFAIL: Clang` remains. The test shaders gain explicit `[[vk::binding]]` annotations since their `t0`/`u0` registers would otherwise collide under the default dxc HLSL→SPIR-V mapping. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a3b5e99 commit a1a661f

6 files changed

Lines changed: 235 additions & 27 deletions

File tree

lib/API/DX/Device.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,12 @@ class DXDevice : public offloadtest::Device {
21692169
[&IS,
21702170
this](Resource &R,
21712171
llvm::SmallVectorImpl<ResourcePair> &Resources) -> llvm::Error {
2172+
// Acceleration structures are created separately; descriptor binding for
2173+
// AS resources is wired up in the per-table binding loop below.
2174+
if (R.isAccelerationStructure()) {
2175+
Resources.push_back(std::make_pair(&R, ResourceBundle{}));
2176+
return llvm::Error::success();
2177+
}
21722178
switch (getDescriptorKind(R.Kind)) {
21732179
case DescriptorKind::SRV: {
21742180
auto ExRes = createSRV(R, IS);
@@ -2209,8 +2215,36 @@ class DXDevice : public offloadtest::Device {
22092215

22102216
// Bind descriptors in descriptor tables.
22112217
uint32_t HeapIndex = 0;
2218+
const uint32_t DescIncSize = Device->GetDescriptorHandleIncrementSize(
2219+
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
22122220
for (auto &T : IS.DescTables) {
22132221
for (auto &R : T.Resources) {
2222+
if (R.first->isAccelerationStructure()) {
2223+
assert(R.first->TLASPtr && "AS resource must be resolved to a TLAS");
2224+
assert(R.first->getArraySize() == 1 && "AS arrays not yet supported");
2225+
// OutAS layout from buildPipelineAccelerationStructures: BLASes
2226+
// first, then TLASes — both in P.AccelStructs declaration order.
2227+
const size_t TLASIdx = R.first->TLASPtr - &P.AccelStructs.TLAS[0];
2228+
const size_t ASIdx = P.AccelStructs.BLAS.size() + TLASIdx;
2229+
auto *DXAS =
2230+
llvm::cast<DXAccelerationStructure>(IS.AccelStructs[ASIdx].get());
2231+
D3D12_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
2232+
SRVDesc.Format = DXGI_FORMAT_UNKNOWN;
2233+
SRVDesc.ViewDimension =
2234+
D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE;
2235+
SRVDesc.Shader4ComponentMapping =
2236+
D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
2237+
SRVDesc.RaytracingAccelerationStructure.Location =
2238+
DXAS->getGPUVirtualAddress();
2239+
D3D12_CPU_DESCRIPTOR_HANDLE Handle =
2240+
IS.DescHeap->GetCPUDescriptorHandleForHeapStart();
2241+
Handle.ptr += HeapIndex * DescIncSize;
2242+
// AS SRVs are created with a null resource; the AS lives in the
2243+
// buffer referenced by Location.
2244+
Device->CreateShaderResourceView(nullptr, &SRVDesc, Handle);
2245+
HeapIndex += R.first->getArraySize();
2246+
continue;
2247+
}
22142248
switch (getDescriptorKind(R.first->Kind)) {
22152249
case DescriptorKind::SRV:
22162250
HeapIndex = bindSRV(*(R.first), IS, HeapIndex, R.second);

lib/API/MTL/MTLDevice.cpp

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#define IR_PRIVATE_IMPLEMENTATION
1818
#include "metal_irconverter.h"
1919
#include "metal_irconverter_runtime.h"
20+
// ir_raytracing.h depends on types defined in metal_irconverter_runtime.h —
21+
// keep this include in its own block so clang-format won't sort it above.
22+
#include "ir_raytracing.h"
2023

2124
#include "API/Device.h"
2225
#include "API/Encoder.h"
@@ -962,6 +965,10 @@ class MTLDevice : public offloadtest::Device {
962965
AccelStructs;
963966
// Vertex/index buffers consumed during AS builds; must outlive submission.
964967
llvm::SmallVector<std::unique_ptr<offloadtest::Buffer>> ASInputBuffers;
968+
// Per-AS-descriptor header + instance-contribution buffers backing inline
969+
// RT bindings; must be resident on the dispatch encoder so the shader can
970+
// read the header.
971+
llvm::SmallVector<MTL::Buffer *> ASDescriptorBuffers;
965972
};
966973

967974
llvm::Error createRootSignature(
@@ -1301,6 +1308,12 @@ class MTLDevice : public offloadtest::Device {
13011308
[&IS,
13021309
this](Resource &R,
13031310
llvm::SmallVectorImpl<ResourcePair> &Resources) -> llvm::Error {
1311+
// Acceleration structures are created separately; descriptor binding for
1312+
// AS resources is wired up in the per-table binding loop below.
1313+
if (R.isAccelerationStructure()) {
1314+
Resources.emplace_back(&R, ResourceBundle{});
1315+
return llvm::Error::success();
1316+
}
13041317
switch (getDescriptorKind(R.Kind)) {
13051318
case DescriptorKind::SRV: {
13061319
auto ExRes = createSRV(R, IS);
@@ -1343,6 +1356,51 @@ class MTLDevice : public offloadtest::Device {
13431356
uint32_t HeapIndex = 0;
13441357
for (auto &T : IS.DescTables) {
13451358
for (auto &R : T.Resources) {
1359+
if (R.first->isAccelerationStructure()) {
1360+
assert(R.first->TLASPtr && "AS resource must be resolved to a TLAS");
1361+
assert(R.first->getArraySize() == 1 && "AS arrays not yet supported");
1362+
// OutAS layout from buildPipelineAccelerationStructures:
1363+
// BLASes first, then TLASes — both in declaration order.
1364+
const size_t TLASIdx = R.first->TLASPtr - &P.AccelStructs.TLAS[0];
1365+
const size_t ASIdx = P.AccelStructs.BLAS.size() + TLASIdx;
1366+
auto *MTLAS = llvm::cast<MetalAccelerationStructure>(
1367+
IS.AccelStructs[ASIdx].get());
1368+
1369+
// Metal shader converter doesn't bind the AS directly; the shader
1370+
// reads a buffer containing an IRRaytracingAccelerationStructureGPU-
1371+
// Header that holds the AS's gpuResourceID plus a pointer to an
1372+
// instance-contributions array (one uint32 per instance, supplying
1373+
// the equivalent of D3D12's InstanceContributionToHitGroupIndex).
1374+
// Build both buffers here and point the descriptor entry at the
1375+
// header buffer's GPU address.
1376+
const uint32_t InstCount =
1377+
static_cast<uint32_t>(R.first->TLASPtr->Instances.size());
1378+
llvm::SmallVector<uint32_t> Contributions(InstCount, 0);
1379+
MTL::Buffer *ContribBuf = Device->newBuffer(
1380+
Contributions.data(), InstCount * sizeof(uint32_t),
1381+
MTL::ResourceStorageModeShared);
1382+
MTL::Buffer *HeaderBuf = Device->newBuffer(
1383+
sizeof(IRRaytracingAccelerationStructureGPUHeader),
1384+
MTL::ResourceStorageModeShared);
1385+
IRRaytracingSetAccelerationStructure(
1386+
static_cast<uint8_t *>(HeaderBuf->contents()),
1387+
MTLAS->AccelStruct->gpuResourceID(),
1388+
static_cast<uint8_t *>(ContribBuf->contents()),
1389+
ContribBuf->gpuAddress(), Contributions.data(), InstCount);
1390+
IS.CB->KeepAliveMTLBuffers.push_back(HeaderBuf);
1391+
IS.CB->KeepAliveMTLBuffers.push_back(ContribBuf);
1392+
// Only the header is read by the shader (via the descriptor's gpuVA).
1393+
// The contribution buffer is read indirectly via the header's
1394+
// addressOfInstanceContributions pointer, so both must be resident
1395+
// during dispatch.
1396+
IS.ASDescriptorBuffers.push_back(HeaderBuf);
1397+
IS.ASDescriptorBuffers.push_back(ContribBuf);
1398+
1399+
IRDescriptorTableSetAccelerationStructure(
1400+
IS.DescHeap->getEntryHandle(HeapIndex), HeaderBuf->gpuAddress());
1401+
HeapIndex += R.first->getArraySize();
1402+
continue;
1403+
}
13461404
switch (getDescriptorKind(R.first->Kind)) {
13471405
case DescriptorKind::SRV:
13481406
HeapIndex = bindSRV(*(R.first), IS, HeapIndex, R.second);
@@ -1402,6 +1460,12 @@ class MTLDevice : public offloadtest::Device {
14021460
NativeEncoder->useResource(ResSet.Resource.get(),
14031461
MTL::ResourceUsageRead |
14041462
MTL::ResourceUsageWrite);
1463+
for (auto &AS : IS.AccelStructs) {
1464+
auto *MTLAS = llvm::cast<MetalAccelerationStructure>(AS.get());
1465+
NativeEncoder->useResource(MTLAS->AccelStruct, MTL::ResourceUsageRead);
1466+
}
1467+
for (MTL::Buffer *B : IS.ASDescriptorBuffers)
1468+
NativeEncoder->useResource(B, MTL::ResourceUsageRead);
14051469

14061470
if (auto Err = Encoder.dispatch(*IS.Pipeline.get(),
14071471
P.DispatchParameters.DispatchGroupCount[0],
@@ -1534,6 +1598,9 @@ class MTLDevice : public offloadtest::Device {
15341598
llvm::Error copyBack(Pipeline &P, InvocationState &IS) {
15351599
auto MemCpyBack = [](ResourcePair &Pair) -> llvm::Error {
15361600
const Resource &R = *Pair.first;
1601+
// AS resources don't have CPU-side readback data.
1602+
if (R.isAccelerationStructure())
1603+
return llvm::Error::success();
15371604
if (!R.isReadWrite())
15381605
return llvm::Error::success();
15391606

@@ -2122,6 +2189,11 @@ class MTLDevice : public offloadtest::Device {
21222189
auto *Descriptor =
21232190
MTL::InstanceAccelerationStructureDescriptor::alloc()->init();
21242191
Descriptor->setInstanceCount(Instances.size());
2192+
// UserID descriptor type so per-instance InstanceID survives the
2193+
// build and is returned by HLSL CommittedInstanceID()/InstanceIndex()
2194+
// semantics on the shader side.
2195+
Descriptor->setInstanceDescriptorType(
2196+
MTL::AccelerationStructureInstanceDescriptorTypeUserID);
21252197

21262198
MTL::AccelerationStructureSizes Sizes =
21272199
Device->accelerationStructureSizes(Descriptor);
@@ -2436,19 +2508,20 @@ llvm::Error MTLComputeEncoder::batchBuildAS(llvm::ArrayRef<ASBuildItem> Items) {
24362508
InstanceASIdx.push_back(Idx);
24372509
}
24382510

2439-
// Pack instance descriptors. Layout differs from VK/DX12: 32-byte
2440-
// entries with an index instead of a GPU address.
2511+
// Pack instance descriptors. Layout differs from VK/DX12: indexed
2512+
// BLAS references with an extra userID slot so HLSL InstanceID()
2513+
// survives across the build.
24412514
const size_t InstByteSize =
24422515
TLAS->Instances.size() *
2443-
sizeof(MTL::AccelerationStructureInstanceDescriptor);
2516+
sizeof(MTL::AccelerationStructureUserIDInstanceDescriptor);
24442517
MTL::Buffer *InstBuf =
24452518
MTLDev->newBuffer(InstByteSize, MTL::ResourceStorageModeShared);
24462519
if (!InstBuf)
24472520
return llvm::createStringError(
24482521
std::errc::not_enough_memory,
24492522
"Failed to allocate TLAS instance buffer.");
24502523
auto *InstPtr =
2451-
static_cast<MTL::AccelerationStructureInstanceDescriptor *>(
2524+
static_cast<MTL::AccelerationStructureUserIDInstanceDescriptor *>(
24522525
InstBuf->contents());
24532526
for (size_t I = 0; I < TLAS->Instances.size(); ++I) {
24542527
const auto &Src = TLAS->Instances[I];
@@ -2462,12 +2535,15 @@ llvm::Error MTLComputeEncoder::batchBuildAS(llvm::ArrayRef<ASBuildItem> Items) {
24622535
D.mask = Src.InstanceMask;
24632536
D.intersectionFunctionTableOffset = 0;
24642537
D.accelerationStructureIndex = InstanceASIdx[I];
2538+
D.userID = Src.InstanceID;
24652539
}
24662540
CB->KeepAliveMTLBuffers.push_back(InstBuf);
24672541

24682542
auto *ID = MTL::InstanceAccelerationStructureDescriptor::alloc()->init();
24692543
ID->setInstanceDescriptorBuffer(InstBuf);
24702544
ID->setInstanceCount(TLAS->Instances.size());
2545+
ID->setInstanceDescriptorType(
2546+
MTL::AccelerationStructureInstanceDescriptorTypeUserID);
24712547
NS::Array *BLASArr = NS::Array::array(
24722548
reinterpret_cast<NS::Object *const *>(UniqueBLASes.data()),
24732549
UniqueBLASes.size());

lib/API/VK/Device.cpp

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,11 @@ class VKComputeEncoder : public offloadtest::ComputeEncoder {
837837
uint32_t GroupCountX, uint32_t GroupCountY,
838838
uint32_t GroupCountZ) override {
839839
const auto &VKPSO = llvm::cast<VulkanPipelineState>(PSO);
840+
// Include AS_READ so dispatches that issue RayQuery against a TLAS get a
841+
// proper hand-off from the prior AS-build's AS_WRITE.
840842
addDstBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
841-
VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT);
843+
VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT |
844+
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR);
842845
insertDebugSignpost(llvm::formatv("Dispatch [{0},{1},{2}]", GroupCountX,
843846
GroupCountY, GroupCountZ)
844847
.str());
@@ -1390,12 +1393,16 @@ class VulkanDevice : public offloadtest::Device {
13901393
(HasVulkan12 ||
13911394
isExtensionSupported(AvailableDeviceExtensions,
13921395
VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME));
1396+
const bool HasRayQueryExt =
1397+
HasASExts && isExtensionSupported(AvailableDeviceExtensions,
1398+
VK_KHR_RAY_QUERY_EXTENSION_NAME);
13931399

13941400
VkPhysicalDeviceAccelerationStructureFeaturesKHR ASFeatures{};
13951401
// On Vulkan 1.1 we need a separate BDA features struct; on 1.2+
13961402
// bufferDeviceAddress lives in VkPhysicalDeviceVulkan12Features which is
13971403
// already in the chain, and adding a duplicate is a validation error.
13981404
VkPhysicalDeviceBufferDeviceAddressFeatures BDAFeatures{};
1405+
VkPhysicalDeviceRayQueryFeaturesKHR RayQueryFeatures{};
13991406
if (HasASExts) {
14001407
ASFeatures.sType =
14011408
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR;
@@ -1407,6 +1414,12 @@ class VulkanDevice : public offloadtest::Device {
14071414
BDAFeatures.pNext = Features.pNext;
14081415
Features.pNext = &BDAFeatures;
14091416
}
1417+
if (HasRayQueryExt) {
1418+
RayQueryFeatures.sType =
1419+
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR;
1420+
RayQueryFeatures.pNext = Features.pNext;
1421+
Features.pNext = &RayQueryFeatures;
1422+
}
14101423
}
14111424

14121425
vkGetPhysicalDeviceFeatures2(PhysicalDevice, &Features);
@@ -1479,6 +1492,14 @@ class VulkanDevice : public offloadtest::Device {
14791492
if (!HasVulkan12)
14801493
EnabledDeviceExtensions.push_back(
14811494
VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
1495+
if (HasRayQueryExt) {
1496+
if (!RayQueryFeatures.rayQuery)
1497+
return llvm::createStringError(
1498+
std::errc::not_supported,
1499+
"Device advertises %s but reports rayQuery=0",
1500+
VK_KHR_RAY_QUERY_EXTENSION_NAME);
1501+
EnabledDeviceExtensions.push_back(VK_KHR_RAY_QUERY_EXTENSION_NAME);
1502+
}
14821503
}
14831504

14841505
DeviceInfo.enabledExtensionCount =
@@ -3009,6 +3030,14 @@ class VulkanDevice : public offloadtest::Device {
30093030
}
30103031

30113032
llvm::Error createResource(Resource &R, InvocationState &IS) {
3033+
// Acceleration structures are created separately; push a placeholder so
3034+
// the resource index stays in sync with the descriptor set layout.
3035+
if (R.isAccelerationStructure()) {
3036+
const ResourceBundle Bundle{getDescriptorType(R.Kind), 0, nullptr};
3037+
IS.Resources.push_back(Bundle);
3038+
return llvm::Error::success();
3039+
}
3040+
30123041
// Samplers don't have backing data buffers, so handle them separately
30133042
if (R.isSampler()) {
30143043
ResourceBundle Bundle{getDescriptorType(R.Kind), 0, nullptr};
@@ -3170,8 +3199,15 @@ class VulkanDevice : public offloadtest::Device {
31703199
constexpr size_t DescriptorTypesSize =
31713200
sizeof(DescriptorTypes) / sizeof(VkDescriptorType);
31723201
uint32_t DescriptorCounts[DescriptorTypesSize] = {0};
3202+
// VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR has an out-of-range enum
3203+
// value (1000150000), so it can't share the indexed array above.
3204+
uint32_t ASDescriptorCount = 0;
31733205
for (const auto &S : P.Sets) {
31743206
for (const auto &R : S.Resources) {
3207+
if (R.isAccelerationStructure()) {
3208+
ASDescriptorCount += R.getArraySize();
3209+
continue;
3210+
}
31753211
DescriptorCounts[getDescriptorType(R.Kind)] += R.getArraySize();
31763212
if (R.HasCounter)
31773213
DescriptorCounts[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER] +=
@@ -3189,6 +3225,12 @@ class VulkanDevice : public offloadtest::Device {
31893225
PoolSizes.push_back(PoolSize);
31903226
}
31913227
}
3228+
if (ASDescriptorCount > 0) {
3229+
llvm::outs() << "Descriptors: { type = ACCELERATION_STRUCTURE_KHR"
3230+
<< ", count = " << ASDescriptorCount << " }\n";
3231+
PoolSizes.push_back(
3232+
{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, ASDescriptorCount});
3233+
}
31923234

31933235
if (P.Sets.size() > 0) {
31943236
VkDescriptorPoolCreateInfo PoolCreateInfo = {};
@@ -3232,8 +3274,15 @@ class VulkanDevice : public offloadtest::Device {
32323274
uint32_t ImageInfoCount = 0;
32333275
uint32_t BufferInfoCount = 0;
32343276
uint32_t BufferViewCount = 0;
3277+
uint32_t ASInfoCount = 0;
3278+
uint32_t ASHandleCount = 0;
32353279
for (auto &D : P.Sets) {
32363280
for (auto &R : D.Resources) {
3281+
if (R.isAccelerationStructure()) {
3282+
ASInfoCount += 1;
3283+
ASHandleCount += R.getArraySize();
3284+
continue;
3285+
}
32373286
if (R.isSampler()) {
32383287
ImageInfoCount += 1;
32393288
continue;
@@ -3255,20 +3304,54 @@ class VulkanDevice : public offloadtest::Device {
32553304
llvm::SmallVector<VkDescriptorImageInfo> ImageInfos;
32563305
llvm::SmallVector<VkDescriptorBufferInfo> BufferInfos;
32573306
llvm::SmallVector<VkBufferView> BufferViews;
3307+
llvm::SmallVector<VkWriteDescriptorSetAccelerationStructureKHR> ASInfos;
3308+
llvm::SmallVector<VkAccelerationStructureKHR> ASHandles;
32583309
ImageInfos.reserve(ImageInfoCount);
32593310
BufferInfos.reserve(BufferInfoCount);
32603311
BufferViews.reserve(BufferViewCount);
3312+
ASInfos.reserve(ASInfoCount);
3313+
ASHandles.reserve(ASHandleCount);
32613314

32623315
llvm::SmallVector<VkWriteDescriptorSet> WriteDescriptors;
32633316
WriteDescriptors.reserve(ImageInfoCount + BufferInfoCount +
3264-
BufferViewCount);
3317+
BufferViewCount + ASInfoCount);
32653318
assert(IS.BufferViews.empty());
32663319

32673320
uint32_t OverallResIdx = 0;
32683321
for (uint32_t SetIdx = 0; SetIdx < P.Sets.size(); ++SetIdx) {
32693322
for (uint32_t RIdx = 0; RIdx < P.Sets[SetIdx].Resources.size();
32703323
++RIdx, ++OverallResIdx) {
32713324
const Resource &R = P.Sets[SetIdx].Resources[RIdx];
3325+
if (R.isAccelerationStructure()) {
3326+
assert(R.TLASPtr && "AS resource must be resolved to a TLAS");
3327+
assert(R.getArraySize() == 1 && "AS arrays not yet supported");
3328+
// OutAS layout from buildPipelineAccelerationStructures: BLASes
3329+
// first, then TLASes — both in P.AccelStructs declaration order.
3330+
const size_t TLASIdx = R.TLASPtr - &P.AccelStructs.TLAS[0];
3331+
const size_t ASIdx = P.AccelStructs.BLAS.size() + TLASIdx;
3332+
auto *VkAS = llvm::cast<VulkanAccelerationStructure>(
3333+
IS.AccelStructs[ASIdx].get());
3334+
const size_t HandleStart = ASHandles.size();
3335+
ASHandles.push_back(VkAS->AccelStruct);
3336+
VkWriteDescriptorSetAccelerationStructureKHR ASWrite = {};
3337+
ASWrite.sType =
3338+
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR;
3339+
ASWrite.accelerationStructureCount = 1;
3340+
ASWrite.pAccelerationStructures = &ASHandles[HandleStart];
3341+
ASInfos.push_back(ASWrite);
3342+
3343+
VkWriteDescriptorSet WDS = {};
3344+
WDS.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3345+
WDS.pNext = &ASInfos.back();
3346+
WDS.dstSet = IS.DescriptorSets[SetIdx];
3347+
WDS.dstBinding = R.VKBinding->Binding;
3348+
WDS.descriptorCount = 1;
3349+
WDS.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
3350+
llvm::outs() << "Updating AS Descriptor [" << OverallResIdx << "] { "
3351+
<< SetIdx << ", " << RIdx << " }\n";
3352+
WriteDescriptors.push_back(WDS);
3353+
continue;
3354+
}
32723355
uint32_t IndexOfFirstBufferDataInArray;
32733356
if (R.isSampler()) {
32743357
IndexOfFirstBufferDataInArray = ImageInfos.size();

0 commit comments

Comments
 (0)