const VkDeviceSize bufferSizeBytes = bottomLevelInstances.size() * sizeof(VkAccelerationStructureInstanceKHR);
const VkBufferCreateInfo bufferCreateInfo = makeBufferCreateInfo(bufferSizeBytes, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
- return new BufferWithMemory(vk, device, allocator, bufferCreateInfo, MemoryRequirement::HostVisible | MemoryRequirement::Coherent | MemoryRequirement::DeviceAddress);
+ try
+ {
+ return new BufferWithMemory(vk, device, allocator, bufferCreateInfo, MemoryRequirement::Cached | MemoryRequirement::HostVisible | MemoryRequirement::Coherent | MemoryRequirement::DeviceAddress);
+ }
+ catch (const tcu::NotSupportedError&)
+ {
+ // retry without Cached flag
+ return new BufferWithMemory(vk, device, allocator, bufferCreateInfo, MemoryRequirement::HostVisible | MemoryRequirement::Coherent | MemoryRequirement::DeviceAddress);
+ }
}
-void updateInstanceBuffer (const DeviceInterface& vk,
- const VkDevice device,
- std::vector<de::SharedPtr<BottomLevelAccelerationStructure> > bottomLevelInstances,
- std::vector<InstanceData> instanceData,
- BufferWithMemory* instanceBuffer,
- VkAccelerationStructureBuildTypeKHR buildType,
- bool inactiveInstances)
+void updateSingleInstance (const DeviceInterface& vk,
+ const VkDevice device,
+ const BottomLevelAccelerationStructure& bottomLevelAccelerationStructure,
+ const InstanceData& instanceData,
+ deUint8* bufferLocation,
+ VkAccelerationStructureBuildTypeKHR buildType,
+ bool inactiveInstances)
{
- DE_ASSERT(bottomLevelInstances.size() != 0);
- DE_ASSERT(bottomLevelInstances.size() == instanceData.size());
-
- const Allocation& instancesAlloc = instanceBuffer->getAllocation();
+ const VkAccelerationStructureKHR accelerationStructureKHR = *bottomLevelAccelerationStructure.getPtr();
- deUint8* bufferStart = static_cast<deUint8*>(instancesAlloc.getHostPtr());
- VkDeviceSize bufferOffset = 0;
+ // This part needs to be fixed once a new version of the VkAccelerationStructureInstanceKHR will be added to vkStructTypes.inl
+ VkDeviceAddress accelerationStructureAddress;
+ if (buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR)
+ {
+ VkAccelerationStructureDeviceAddressInfoKHR asDeviceAddressInfo =
+ {
+ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR, // VkStructureType sType;
+ DE_NULL, // const void* pNext;
+ accelerationStructureKHR // VkAccelerationStructureKHR accelerationStructure;
+ };
+ accelerationStructureAddress = vk.getAccelerationStructureDeviceAddressKHR(device, &asDeviceAddressInfo);
+ }
- for (size_t instanceNdx = 0; instanceNdx < bottomLevelInstances.size(); ++instanceNdx)
+ deUint64 structureReference;
+ if (inactiveInstances)
+ {
+ // Instances will be marked inactive by making their references VK_NULL_HANDLE or having address zero.
+ structureReference = 0ull;
+ }
+ else
{
- const BottomLevelAccelerationStructure& bottomLevelAccelerationStructure = *bottomLevelInstances[instanceNdx];
- const VkAccelerationStructureKHR accelerationStructureKHR = *bottomLevelAccelerationStructure.getPtr();
+ structureReference = (buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR)
+ ? deUint64(accelerationStructureAddress)
+ : deUint64(accelerationStructureKHR.getInternal());
+ }
- // This part needs to be fixed once a new version of the VkAccelerationStructureInstanceKHR will be added to vkStructTypes.inl
- VkDeviceAddress accelerationStructureAddress;
- if (buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR)
- {
- VkAccelerationStructureDeviceAddressInfoKHR asDeviceAddressInfo =
- {
- VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR, // VkStructureType sType;
- DE_NULL, // const void* pNext;
- accelerationStructureKHR // VkAccelerationStructureKHR accelerationStructure;
- };
- accelerationStructureAddress = vk.getAccelerationStructureDeviceAddressKHR(device, &asDeviceAddressInfo);
- }
+ VkAccelerationStructureInstanceKHR accelerationStructureInstanceKHR = makeVkAccelerationStructureInstanceKHR
+ (
+ instanceData.matrix, // VkTransformMatrixKHR transform;
+ instanceData.instanceCustomIndex, // deUint32 instanceCustomIndex:24;
+ instanceData.mask, // deUint32 mask:8;
+ instanceData.instanceShaderBindingTableRecordOffset, // deUint32 instanceShaderBindingTableRecordOffset:24;
+ instanceData.flags, // VkGeometryInstanceFlagsKHR flags:8;
+ structureReference // deUint64 accelerationStructureReference;
+ );
- deUint64 structureReference;
- if (inactiveInstances)
- {
- // Instances will be marked inactive by making their references VK_NULL_HANDLE or having address zero.
- structureReference = 0ull;
- }
- else
- {
- structureReference = (buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR)
- ? deUint64(accelerationStructureAddress)
- : deUint64(accelerationStructureKHR.getInternal());
- }
+ deMemcpy(bufferLocation, &accelerationStructureInstanceKHR, sizeof(VkAccelerationStructureInstanceKHR));
+}
- VkAccelerationStructureInstanceKHR accelerationStructureInstanceKHR = makeVkAccelerationStructureInstanceKHR
- (
- instanceData[instanceNdx].matrix, // VkTransformMatrixKHR transform;
- instanceData[instanceNdx].instanceCustomIndex, // deUint32 instanceCustomIndex:24;
- instanceData[instanceNdx].mask, // deUint32 mask:8;
- instanceData[instanceNdx].instanceShaderBindingTableRecordOffset, // deUint32 instanceShaderBindingTableRecordOffset:24;
- instanceData[instanceNdx].flags, // VkGeometryInstanceFlagsKHR flags:8;
- structureReference // deUint64 accelerationStructureReference;
- );
+void updateInstanceBuffer (const DeviceInterface& vk,
+ const VkDevice device,
+ const std::vector<de::SharedPtr<BottomLevelAccelerationStructure>>& bottomLevelInstances,
+ const std::vector<InstanceData>& instanceData,
+ const BufferWithMemory* instanceBuffer,
+ VkAccelerationStructureBuildTypeKHR buildType,
+ bool inactiveInstances)
+{
+ DE_ASSERT(bottomLevelInstances.size() != 0);
+ DE_ASSERT(bottomLevelInstances.size() == instanceData.size());
- deMemcpy(&bufferStart[bufferOffset], &accelerationStructureInstanceKHR, sizeof(VkAccelerationStructureInstanceKHR));
+ auto& instancesAlloc = instanceBuffer->getAllocation();
+ auto bufferStart = reinterpret_cast<deUint8*>(instancesAlloc.getHostPtr());
+ VkDeviceSize bufferOffset = 0ull;
+ for (size_t instanceNdx = 0; instanceNdx < bottomLevelInstances.size(); ++instanceNdx)
+ {
+ const auto& blas = *bottomLevelInstances[instanceNdx];
+ updateSingleInstance(vk, device, blas, instanceData[instanceNdx], bufferStart + bufferOffset, buildType, inactiveInstances);
bufferOffset += sizeof(VkAccelerationStructureInstanceKHR);
}