How to update VkAccelerationStructureKHR properly?

Started by
0 comments, last by nartoh 2 years, 5 months ago

I've set the the flag VkAccelerationStructureBuildGeometryInfoKHR::flags to VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR in my intial TLAS build. Then i try to update the 3x4 matrix so i can rotate my triangle every frame. Here's the TLAS update code

VkAccelerationStructureGeometryKHR accelerationStructureGeometry = {};
	accelerationStructureGeometry.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR;
	accelerationStructureGeometry.geometryType = VK_GEOMETRY_TYPE_INSTANCES_KHR;
	accelerationStructureGeometry.geometry.instances.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR;
	accelerationStructureGeometry.geometry.instances.data.deviceAddress = instanceBuffer->GetDeviceAddress();

	VkAccelerationStructureBuildGeometryInfoKHR accelerationStructureBuildGeometryInfo = {};
	accelerationStructureBuildGeometryInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR;
	accelerationStructureBuildGeometryInfo.geometryCount = 1;
	accelerationStructureBuildGeometryInfo.pGeometries = &accelerationStructureGeometry;
	accelerationStructureBuildGeometryInfo.mode = VK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHR;
	accelerationStructureBuildGeometryInfo.dstAccelerationStructure = mVkAccelerationStructure;
	accelerationStructureBuildGeometryInfo.srcAccelerationStructure = mVkAccelerationStructure;
	accelerationStructureBuildGeometryInfo.flags = VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR;

	VkAccelerationStructureBuildRangeInfoKHR buildRangeInfo = {};
	buildRangeInfo.primitiveCount = (uint32_t)accelerationStructureInstances.size();

	std::vector<VkAccelerationStructureBuildRangeInfoKHR*> pBuildRangeInfo;
	pBuildRangeInfo.push_back(&buildRangeInfo);

	vkCmdBuildAccelerationStructuresKHR(commandBuffer, 1, &accelerationStructureBuildGeometryInfo, pBuildRangeInfo.data());                                      

but the app crash with validation layer complaining I'vent begin the VkCommandBuffer which is I've called vkBegin CommandBuffer before trying to update the TLAS. I can't find the corect way on Google, i figured above code based on vulkan documentation.

This topic is closed to new replies.

Advertisement