requested changes

This commit is contained in:
alexander-g 2021-03-07 11:35:20 +01:00
parent eb47d52047
commit 6da6bca339
5 changed files with 123 additions and 62 deletions

View file

@ -7,7 +7,7 @@ Sequence::Sequence(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::Queue> computeQueue,
uint32_t queueIndex,
uint32_t nrOfTimestamps)
uint32_t totalTimestamps)
{
KP_LOG_DEBUG("Kompute Sequence Constructor with existing device & queue");
@ -18,8 +18,8 @@ Sequence::Sequence(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
this->createCommandPool();
this->createCommandBuffer();
if(nrOfTimestamps>0)
this->createTimestampQueryPool(nrOfTimestamps+1); //+1 for the first one
if(totalTimestamps>0)
this->createTimestampQueryPool(totalTimestamps+1); //+1 for the first one
}
Sequence::~Sequence()
@ -246,6 +246,16 @@ Sequence::destroy()
this->mOperations.clear();
}
if(this->timestampQueryPool){
KP_LOG_INFO("Destroying QueryPool");
this->mDevice->destroy(
*this->timestampQueryPool,
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
this->timestampQueryPool = nullptr;
KP_LOG_DEBUG("Kompute Sequence Destroyed QueryPool");
}
if (this->mDevice) {
this->mDevice = nullptr;
}
@ -325,11 +335,11 @@ Sequence::createCommandBuffer()
}
void
Sequence::createTimestampQueryPool(uint32_t query_size)
Sequence::createTimestampQueryPool(uint32_t totalTimestamps)
{
KP_LOG_DEBUG("Kompute Sequence creating query pool");
if (!this->mDevice) {
throw std::runtime_error("Kompute Sequence device is null");
if (!this->isInit()) {
throw std::runtime_error("createTimestampQueryPool() called on uninitialized Sequence");
}
if (!this->mPhysicalDevice) {
throw std::runtime_error("Kompute Sequence physical device is null");
@ -339,32 +349,29 @@ Sequence::createTimestampQueryPool(uint32_t query_size)
this->mPhysicalDevice->getProperties();
if(physicalDeviceProperties.limits.timestampComputeAndGraphics){
vk::QueryPoolCreateInfo queryPoolInfo;
queryPoolInfo.setQueryCount(query_size);
queryPoolInfo.setQueryType(vk::QueryType::eTimestamp);
this->timestampQueryPool = std::make_shared<vk::QueryPool>(this->mDevice->createQueryPool(queryPoolInfo));
vk::QueryPoolCreateInfo queryPoolInfo;
queryPoolInfo.setQueryCount(totalTimestamps);
queryPoolInfo.setQueryType(vk::QueryType::eTimestamp);
this->timestampQueryPool = std::make_shared<vk::QueryPool>(this->mDevice->createQueryPool(queryPoolInfo));
KP_LOG_DEBUG("Query pool for timestamps created");
KP_LOG_DEBUG("Query pool for timestamps created");
}
else{
KP_LOG_DEBUG("Device does not support timestamps");
throw std::runtime_error("Device does not support timestamps");
}
}
std::vector<std::uint64_t>
Sequence::getTimestamps(){
Sequence::getTimestamps()
{
if(!this->timestampQueryPool)
throw std::runtime_error("Timestamp latching not enabled");
const auto n = this->mOperations.size()+1;
std::vector<std::uint64_t> timestamps(n, 0);
//XXX: the C++ method this->mDevice->getQueryPoolResults does not compile for me
const VkResult result =
vkGetQueryPoolResults(*this->mDevice, *this->timestampQueryPool,
0, n, timestamps.size()*sizeof(std::uint64_t), timestamps.data(),
sizeof(uint64_t), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
if(result!=VK_SUCCESS)
throw std::runtime_error("vkGetQueryPoolResults failed");
this->mDevice->getQueryPoolResults(*this->timestampQueryPool,
0, n, timestamps.size()*sizeof(std::uint64_t), timestamps.data(),
sizeof(uint64_t), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait);
return timestamps;
}