Calculating delta time accurately

Hi, I’m trying to calculate delta time with timestamp queries but when I multiply my camera movement code with delta time it causes jittering. Also I’m not sure which flags should i use.

std::array<uint64_t, 2> timestamps{};
vkGetQueryPoolResults(device->device, queryPool->queryPool, currentFrame * 2, 2, sizeof(uint64_t) * 2, timestamps.data(), sizeof(uint64_t), VK_QUERY_RESULT_WAIT_BIT | VK_QUERY_RESULT_64_BIT);
double deltaTimeInNanoseconds = (timestamps[1] - timestamps[0]) * device->timestampPeriod;
float deltaTime = deltaTimeInNanoseconds / 1000000000.0f;

Also I tried VK_QUERY_RESULT_WITH_AVAILABILITY_BIT but i got deltatime 0

std::array<uint64_t, 4> timestamps{};
vkGetQueryPoolResults(device->device, queryPool->queryPool, currentFrame * 2, 2, sizeof(uint64_t) * 4, timestamps.data(), sizeof(uint64_t) * 2, VK_QUERY_RESULT_WITH_AVAILABILITY_BIT | VK_QUERY_RESULT_64_BIT);
double deltaTimeInNanoseconds = (timestamps[2] - timestamps[0]) * device->timestampPeriod;
float deltaTime = deltaTimeInNanoseconds / 1000000000.0f;

Delta time between what and what? And why would it multiply camera?

Anyway. VK_QUERY_RESULT_WAIT_BIT means the vkGetQueryPoolResults blocks. Which means whatever is supposed to be submitted after it likely gets delayed, hence jitter.

No VK_QUERY_RESULT_WAIT_BIT means the result is probably not in yet when you ask, therefore you get 0.