Skip to content

Commit d0e3d9c

Browse files
cmannett85-armbaldurk
authored andcommitted
Vulkan AS descriptor and SPIR-V changes
Also has change where the AS is tracked in command buffers so that we know when it has been built - unbuilt ASes are skipped before serialisation.
1 parent 6de4204 commit d0e3d9c

19 files changed

+453
-55
lines changed

renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,8 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *api, const ShaderStage s
12931293
innerName = "sampledImage";
12941294
else if(innertype->type == DataType::ImageType)
12951295
innerName = "image";
1296+
else if(innertype->type == DataType::AccelerationStructureType)
1297+
innerName = "accelerationStructure";
12961298
sourceName = StringFormat::Fmt("_%s_set%u_bind%u", innerName.c_str(), decorations[v.id].set,
12971299
decorations[v.id].binding);
12981300
}
@@ -1377,6 +1379,14 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *api, const ShaderStage s
13771379
pointerIDs.push_back(GLOBAL_POINTER(v.id, readOnlyResources));
13781380
}
13791381
}
1382+
else if(innertype->type == DataType::AccelerationStructureType)
1383+
{
1384+
var.type = VarType::ReadOnlyResource;
1385+
debugType = DebugVariableType::ReadOnlyResource;
1386+
1387+
global.readOnlyResources.push_back(var);
1388+
pointerIDs.push_back(GLOBAL_POINTER(v.id, readOnlyResources));
1389+
}
13801390
else
13811391
{
13821392
RDCERR("Unhandled type of uniform: %u", innertype->type);
@@ -3500,6 +3510,8 @@ uint32_t Debugger::WalkVariable(
35003510
case DataType::ImageType:
35013511
case DataType::SamplerType:
35023512
case DataType::SampledImageType:
3513+
case DataType::RayQueryType:
3514+
case DataType::AccelerationStructureType:
35033515
case DataType::UnknownType:
35043516
{
35053517
RDCERR("Unexpected variable type %d", type.type);

renderdoc/driver/shaders/spirv/spirv_disassemble.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ rdcstr Reflector::Disassemble(const rdcstr &entryPoint,
361361
case Op::TypeSampler:
362362
case Op::TypeSampledImage:
363363
case Op::TypeFunction:
364-
case Op::TypeRuntimeArray: continue;
364+
case Op::TypeRuntimeArray:
365+
case Op::TypeRayQueryKHR: continue;
365366

366367
case Op::TypeForwardPointer:
367368
{

renderdoc/driver/shaders/spirv/spirv_processor.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,16 @@ void Processor::RegisterOp(Iter it)
799799

800800
functionTypes[decoded.result] = FunctionType(decoded.returnType, decoded.parameters);
801801
}
802+
else if(opdata.op == Op::TypeRayQueryKHR)
803+
{
804+
OpTypeRayQueryKHR decoded(it);
805+
dataTypes[opdata.result] = DataType(decoded.result, DataType::RayQueryType);
806+
}
807+
else if(opdata.op == Op::TypeAccelerationStructureKHR)
808+
{
809+
OpTypeAccelerationStructureKHR decoded(it);
810+
dataTypes[opdata.result] = DataType(decoded.result, DataType::AccelerationStructureType);
811+
}
802812
else if(opdata.op == Op::Decorate)
803813
{
804814
OpDecorate decoded(it);
@@ -926,7 +936,8 @@ void Processor::UnregisterOp(Iter it)
926936
else if(opdata.op == Op::TypeVoid || opdata.op == Op::TypeBool || opdata.op == Op::TypeInt ||
927937
opdata.op == Op::TypeFloat || opdata.op == Op::TypeVector ||
928938
opdata.op == Op::TypeMatrix || opdata.op == Op::TypeStruct || opdata.op == Op::TypeArray ||
929-
opdata.op == Op::TypePointer || opdata.op == Op::TypeRuntimeArray)
939+
opdata.op == Op::TypePointer || opdata.op == Op::TypeRuntimeArray ||
940+
opdata.op == Op::TypeRayQueryKHR || opdata.op == Op::TypeAccelerationStructureKHR)
930941
{
931942
dataTypes[opdata.result] = DataType();
932943
}

renderdoc/driver/shaders/spirv/spirv_processor.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ struct DataType
334334
ImageType,
335335
SamplerType,
336336
SampledImageType,
337+
RayQueryType,
338+
AccelerationStructureType,
337339
};
338340

339341
struct Child
@@ -372,7 +374,26 @@ struct DataType
372374
Id InnerType() const { return pointerType.baseId; }
373375
bool IsOpaqueType() const
374376
{
375-
return type == ImageType || type == SamplerType || type == SampledImageType;
377+
switch(type)
378+
{
379+
case Type::ScalarType:
380+
case Type::VectorType:
381+
case Type::MatrixType:
382+
case Type::StructType:
383+
case Type::PointerType:
384+
case Type::ArrayType: return false;
385+
case Type::ImageType:
386+
case Type::SamplerType:
387+
case Type::SampledImageType:
388+
case Type::RayQueryType:
389+
case Type::AccelerationStructureType: return true;
390+
default:
391+
{
392+
RDCWARN("Unknown SPIR-V type!");
393+
break;
394+
}
395+
}
396+
return false;
376397
}
377398
Id id;
378399
rdcstr name;

renderdoc/driver/shaders/spirv/spirv_reflect.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,14 @@ void Reflector::PostParse()
852852
type.name = StringFormat::Fmt("Sampled%s",
853853
dataTypes[sampledImageTypes[type.id].baseId].name.c_str());
854854
}
855+
else if(type.type == DataType::RayQueryType)
856+
{
857+
type.name = StringFormat::Fmt("rayQuery%u", type.id.value());
858+
}
859+
else if(type.type == DataType::AccelerationStructureType)
860+
{
861+
type.name = StringFormat::Fmt("accelerationStructure%u", type.id.value());
862+
}
855863
}
856864
}
857865

@@ -1447,6 +1455,15 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st
14471455

14481456
samplers.push_back(sortedsamp(global.id, samp));
14491457
}
1458+
else if(varType->type == DataType::AccelerationStructureType)
1459+
{
1460+
res.descriptorType = DescriptorType::AccelerationStructure;
1461+
res.variableType.baseType = VarType::ReadOnlyResource;
1462+
res.isTexture = false;
1463+
res.isReadOnly = true;
1464+
1465+
roresources.push_back(sortedres(global.id, res));
1466+
}
14501467
else
14511468
{
14521469
Id imageTypeId = varType->id;

renderdoc/driver/vulkan/vk_acceleration_structure.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void VulkanAccelerationStructureManager::Apply(ResourceId id, const VkInitialCon
355355
}
356356
}
357357

358-
VkDeviceSize VulkanAccelerationStructureManager::SerialisedASSize(VkAccelerationStructureKHR as)
358+
VkDeviceSize VulkanAccelerationStructureManager::SerialisedASSize(VkAccelerationStructureKHR unwrappedAs)
359359
{
360360
VkDevice d = m_pDriver->GetDev();
361361

@@ -374,15 +374,17 @@ VkDeviceSize VulkanAccelerationStructureManager::SerialisedASSize(VkAcceleration
374374

375375
// Get the size
376376
ObjDisp(d)->CmdWriteAccelerationStructuresPropertiesKHR(
377-
Unwrap(cmd), 1, &as, VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR, pool, 0);
377+
Unwrap(cmd), 1, &unwrappedAs, VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR,
378+
pool, 0);
378379

379380
m_pDriver->CloseInitStateCmd();
380381
m_pDriver->SubmitCmds();
381382
m_pDriver->FlushQ();
382383

383384
VkDeviceSize size = 0;
384385
vkr = ObjDisp(d)->GetQueryPoolResults(Unwrap(d), pool, 0, 1, sizeof(VkDeviceSize), &size,
385-
sizeof(VkDeviceSize), VK_QUERY_RESULT_WAIT_BIT);
386+
sizeof(VkDeviceSize),
387+
VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
386388
m_pDriver->CheckVkResult(vkr);
387389

388390
// Clean up

renderdoc/driver/vulkan/vk_acceleration_structure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class VulkanAccelerationStructureManager
5353
void Apply(ResourceId id, const VkInitialContents &initial);
5454

5555
private:
56-
VkDeviceSize SerialisedASSize(VkAccelerationStructureKHR as);
56+
VkDeviceSize SerialisedASSize(VkAccelerationStructureKHR unwrappedAs);
5757

5858
WrappedVulkan *m_pDriver;
5959
};

renderdoc/driver/vulkan/vk_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ constexpr DescriptorSlotType convert(VkDescriptorType type)
577577
? DescriptorSlotType::StorageBufferDynamic
578578
: type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT ? DescriptorSlotType::InputAttachment
579579
: type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK ? DescriptorSlotType::InlineBlock
580-
: DescriptorSlotType::Unwritten;
580+
: type == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR
581+
? DescriptorSlotType::AccelerationStructure
582+
: DescriptorSlotType::Unwritten;
581583
}
582584

583585
enum class DescriptorSlotImageLayout : EnumBaseType

renderdoc/driver/vulkan/vk_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,8 @@ class WrappedVulkan : public IFrameCapturer
10881088
rdcarray<VkResourceRecord *> &cmdsWithReferences,
10891089
std::unordered_set<ResourceId> &refdIDs);
10901090
void AddRecordsForSecondaries(VkResourceRecord *record);
1091-
void UpdateImageStatesForSecondaries(VkResourceRecord *record);
1091+
void UpdateImageStatesForSecondaries(VkResourceRecord *record,
1092+
rdcarray<VkResourceRecord *> &accelerationStructures);
10921093
void CaptureQueueSubmit(VkQueue queue, const rdcarray<VkCommandBuffer> &commandBuffers,
10931094
VkFence fence);
10941095

renderdoc/driver/vulkan/vk_info.cpp

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ void DescSetLayout::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo
318318
dynamicCount = 0;
319319
inlineCount = 0;
320320
inlineByteSize = 0;
321+
accelerationStructureCount = 0;
322+
accelerationStructureWriteCount = 0;
321323

322324
const VkMutableDescriptorTypeCreateInfoEXT *mutableInfo =
323325
(const VkMutableDescriptorTypeCreateInfoEXT *)FindNextStruct(
@@ -383,6 +385,11 @@ void DescSetLayout::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo
383385
inlineCount++;
384386
inlineByteSize = AlignUp4(inlineByteSize + bindings[b].descriptorCount);
385387
}
388+
else if(type == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
389+
{
390+
accelerationStructureWriteCount++;
391+
accelerationStructureCount += bindings[b].descriptorCount;
392+
}
386393

387394
if((type == VK_DESCRIPTOR_TYPE_SAMPLER || type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) &&
388395
pCreateInfo->pBindings[i].pImmutableSamplers)
@@ -510,50 +517,31 @@ void DescSetLayout::UpdateBindingsArray(const DescSetLayout &prevLayout,
510517
// resize to the new size, discarding any excess we don't need anymore
511518
bindingStorage.binds.resize(bindings.size());
512519

513-
if(inlineByteSize == 0)
520+
uint32_t inlineOffset = 0;
521+
for(size_t i = 0; i < bindings.size(); i++)
514522
{
515-
for(size_t i = 0; i < bindings.size(); i++)
516-
{
517-
DescriptorSetSlot *newSlots = newElems.data() + bindings[i].elemOffset;
523+
DescriptorSetSlot *newSlots = newElems.data() + bindings[i].elemOffset;
518524

525+
if(bindings[i].layoutDescType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK)
526+
{
527+
bindingStorage.binds[i]->type = DescriptorSlotType::InlineBlock;
528+
bindingStorage.binds[i]->offset = inlineOffset;
529+
bindingStorage.binds[i]->range = bindings[i].descriptorCount;
530+
inlineOffset = AlignUp4(inlineOffset + bindings[i].descriptorCount);
531+
}
532+
else
533+
{
519534
// copy over any previous bindings that overlapped
520535
if(i < prevLayout.bindings.size())
521536
memcpy(newSlots, bindingStorage.binds[i],
522537
sizeof(DescriptorSetSlot) *
523538
RDCMIN(prevLayout.bindings[i].descriptorCount, bindings[i].descriptorCount));
524-
525-
bindingStorage.binds[i] = newSlots;
526539
}
527-
}
528-
else
529-
{
530-
uint32_t inlineOffset = 0;
531-
for(size_t i = 0; i < bindings.size(); i++)
532-
{
533-
DescriptorSetSlot *newSlots = newElems.data() + bindings[i].elemOffset;
534540

535-
if(bindings[i].layoutDescType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK)
536-
{
537-
bindingStorage.binds[i]->type = DescriptorSlotType::InlineBlock;
538-
bindingStorage.binds[i]->offset = inlineOffset;
539-
bindingStorage.binds[i]->range = bindings[i].descriptorCount;
540-
inlineOffset = AlignUp4(inlineOffset + bindings[i].descriptorCount);
541-
}
542-
else
543-
{
544-
// copy over any previous bindings that overlapped
545-
if(i < prevLayout.bindings.size())
546-
memcpy(newSlots, bindingStorage.binds[i],
547-
sizeof(DescriptorSetSlot) *
548-
RDCMIN(prevLayout.bindings[i].descriptorCount, bindings[i].descriptorCount));
549-
}
550-
551-
bindingStorage.binds[i] = newSlots;
552-
}
553-
554-
bindingStorage.inlineBytes.resize(inlineByteSize);
541+
bindingStorage.binds[i] = newSlots;
555542
}
556543

544+
bindingStorage.inlineBytes.resize(inlineByteSize);
557545
bindingStorage.elems.swap(newElems);
558546
}
559547
}
@@ -633,6 +621,17 @@ bool IsValid(bool allowNULLDescriptors, const VkWriteDescriptorSet &write, uint3
633621
return true;
634622
}
635623

624+
if(write.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
625+
{
626+
if(allowNULLDescriptors)
627+
return true;
628+
629+
const VkWriteDescriptorSetAccelerationStructureKHR *asDesc =
630+
(const VkWriteDescriptorSetAccelerationStructureKHR *)FindNextStruct(
631+
&write, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR);
632+
return asDesc != VK_NULL_HANDLE;
633+
}
634+
636635
RDCERR("Encountered VkWriteDescriptorSet with no data!");
637636

638637
return false;
@@ -2622,6 +2621,9 @@ void DescUpdateTemplate::Init(VulkanResourceManager *resourceMan, VulkanCreation
26222621
texelBufferViewCount = 0;
26232622
bufferInfoCount = 0;
26242623
imageInfoCount = 0;
2624+
inlineInfoCount = 0;
2625+
inlineByteSize = 0;
2626+
accelerationStructureCount = 0;
26252627

26262628
for(const VkDescriptorUpdateTemplateEntry &entry : updates)
26272629
{
@@ -2659,6 +2661,13 @@ void DescUpdateTemplate::Init(VulkanResourceManager *resourceMan, VulkanCreation
26592661
inlineByteSize += entry.descriptorCount;
26602662
inlineByteSize = AlignUp4(inlineByteSize);
26612663
}
2664+
else if(entry.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
2665+
{
2666+
entrySize = sizeof(VkAccelerationStructureKHR);
2667+
2668+
accelerationStructureWriteCount++;
2669+
accelerationStructureCount += entry.descriptorCount;
2670+
}
26622671
else
26632672
{
26642673
entrySize = sizeof(VkDescriptorBufferInfo);
@@ -2704,6 +2713,8 @@ void DescUpdateTemplate::Apply(const void *pData, DescUpdateTemplateApplication
27042713
application.imgInfo.reserve(imageInfoCount);
27052714
application.inlineData.resize(inlineByteSize);
27062715
application.inlineUniform.reserve(inlineInfoCount);
2716+
application.accelerationStructureWrite.reserve(accelerationStructureWriteCount);
2717+
application.accelerationStructure.reserve(accelerationStructureCount);
27072718

27082719
uint32_t inlineOffset = 0;
27092720
for(const VkDescriptorUpdateTemplateEntry &entry : updates)
@@ -2768,6 +2779,28 @@ void DescUpdateTemplate::Apply(const void *pData, DescUpdateTemplateApplication
27682779
write.pNext = &inlineWrite;
27692780
write.descriptorCount = entry.descriptorCount;
27702781
}
2782+
else if(entry.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
2783+
{
2784+
application.accelerationStructureWrite.push_back({});
2785+
2786+
VkWriteDescriptorSetAccelerationStructureKHR &asWrite =
2787+
application.accelerationStructureWrite.back();
2788+
asWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR;
2789+
asWrite.pNext = NULL;
2790+
asWrite.accelerationStructureCount = entry.descriptorCount;
2791+
2792+
const size_t idx = application.accelerationStructure.size();
2793+
application.accelerationStructure.resize(idx + entry.descriptorCount);
2794+
for(uint32_t d = 0; d < entry.descriptorCount; d++)
2795+
{
2796+
memcpy(&application.accelerationStructure[idx + d], src, sizeof(VkAccelerationStructureKHR));
2797+
src += entry.stride;
2798+
}
2799+
asWrite.pAccelerationStructures = &application.accelerationStructure[idx];
2800+
2801+
write.pNext = &asWrite;
2802+
write.descriptorCount = entry.descriptorCount;
2803+
}
27712804
else
27722805
{
27732806
size_t idx = application.bufInfo.size();

0 commit comments

Comments
 (0)