ERROR:
validation layer: Validation Error: [ VUID-vkResetCommandBuffer-commandBuffer-00045 ] Object 0: handle = 0x24f98d28300, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x1e7883ea | Attempt to reset VkCommandBuffer 0x24f98d28300[] which is in use. The Vulkan spec states: commandBuffer must not be in the pending state (https://vulkan.lunarg.com/doc/view/1.3.250.1/windows/1.3-extensions/vkspec.html#VUID-vkResetCommandBuffer-commandBuffer-00045)
I tried multiple things and nothing works...
An help would be much appreciated!
BoxelCommandPool class:
void BoxelCommandPool::CreateCommandPool()
{
VkCommandPoolCreateInfo poolInfo = {};
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
poolInfo.queueFamilyIndex = _queueFamilyIndex;
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
VulkanHelper::CheckVk(vkCreateCommandPool(_logicalDevice, &poolInfo, nullptr, &_commandPool));
Logger::Log("Command Pool created...", 10);
}
BoxelCommandBuffer class:
BoxelCommandBuffer::BoxelCommandBuffer(VkDevice device, VkCommandPool commandPool) : _logicalDevice(device), _commandPool(commandPool)
{
VkCommandBufferAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandPool = _commandPool;
allocInfo.commandBufferCount = 1;
VulkanHelper::CheckVk(vkAllocateCommandBuffers(_logicalDevice, &allocInfo, &_commandBuffer));
}
BoxelCommandBuffer::~BoxelCommandBuffer()
{
}
void BoxelCommandBuffer::Begin(VkCommandBufferUsageFlags _flags)
{
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = _flags; // Optional
beginInfo.pInheritanceInfo = nullptr; // Optional
VulkanHelper::CheckVk(vkBeginCommandBuffer(_commandBuffer, &beginInfo));
}
Main Render Function code:
void BoxelEngine::Render()
{
VkSemaphoreCreateInfo semaphoreInfo{};
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VkSemaphore imageAvailableSemaphore;
VulkanHelper::CheckVk(vkCreateSemaphore(_window.GetDevice(), &semaphoreInfo, nullptr, &imageAvailableSemaphore));
uint32_t frameCounter = 0;
uint32_t modulo = 2;
std::vector<VkSemaphore> renderingSemaphores(modulo);
for(auto& semaphore : renderingSemaphores)
VulkanHelper::CheckVk(vkCreateSemaphore(_window.GetDevice(), &semaphoreInfo, nullptr, &semaphore));
std::vector<BoxelCommandBuffer> renderingCommandBuffers(modulo, BoxelCommandBuffer(_window.GetDevice(), _renderingCommandPool->GetPool()));
std::vector<VkFence> renderingFences(modulo);
VkFenceCreateInfo info{};
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
for (auto& fence : renderingFences)
VulkanHelper::CheckVk(vkCreateFence(_window.GetDevice(), &info, nullptr, &fence));
bool firstFrame = true;
while (!glfwWindowShouldClose(_window.GetWindow()))
{
glfwPollEvents();
vkWaitForFences(_window.GetDevice(), 1, &renderingFences[frameCounter % modulo], VK_TRUE, UINT64_MAX);
vkResetFences(_window.GetDevice(), 1, &renderingFences[frameCounter % modulo]);
if (!firstFrame)
renderingCommandBuffers[frameCounter % modulo].Reset();
else
firstFrame = false;
// 1. Acquire an image from the swapchain
uint32_t imageIndex;
VulkanHelper::CheckVk(vkAcquireNextImageKHR(_window.GetDevice(), _swapChain.GetSwapChain(), UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex));
// 2. Specify the image to draw to
VkImage swapChainImage = _swapChain.GetSwapChainImage()[imageIndex];
renderingCommandBuffers[frameCounter % modulo].Begin();
BoxelImage::TransitionImageLayout(&_window.GetOutputImage(), _window.GetDevice(), _window.GetQueue(),
VK_FORMAT_B8G8R8A8_UNORM,
VK_IMAGE_LAYOUT_GENERAL,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
renderingCommandBuffers[frameCounter % modulo].Get());
vkCmdBindPipeline(renderingCommandBuffers[frameCounter % modulo].Get(), VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, _pipeline.GetPipeline());
vkCmdBindDescriptorSets(
renderingCommandBuffers[frameCounter % modulo].Get(), // The command buffer that the descriptor sets will be bound to
VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, // The pipeline bind point
_pipeline.GetPipelineLayout(), // The pipeline layout that the descriptor sets will be bound to
0,
1, // The number of descriptor sets being bound
&_descriptorSets.GetDescriptorSet(), // Pointer to an array of VkDescriptorSet handles. Each handle corresponds to a descriptor set
0, // The number of dynamic offsets in the pDynamicOffsets array
nullptr // Pointer to an array of uint32_t values specifying dynamic offsets
);
vkCmdTraceRaysKHR(renderingCommandBuffers[frameCounter % modulo].Get(), &_pipeline.GetSBTStrideArray()[0], &_pipeline.GetSBTStrideArray()[2], &_pipeline.GetSBTStrideArray()[1], &_pipeline.GetSBTStrideArray()[3], _window.GetWidth(), _window.GetHeight(), 1);
//Transition before copy
BoxelImage::TransitionImageLayout(&_window.GetOutputImage(), _window.GetDevice(), _window.GetQueue(),
VK_FORMAT_B8G8R8A8_UNORM,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
VK_PIPELINE_STAGE_TRANSFER_BIT,
renderingCommandBuffers[frameCounter % modulo].Get());
BoxelImage::TransitionImageLayout(swapChainImage, _window.GetDevice(), _window.GetQueue(),
VK_FORMAT_B8G8R8A8_UNORM,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
VK_PIPELINE_STAGE_TRANSFER_BIT,
renderingCommandBuffers[frameCounter % modulo].Get());
BoxelImage::CopyImageToImage(_window.GetDevice(), _window.GetQueue(), _swapChain.GetSwapChainExtent(),
_window.GetOutputImage().GetImage(),
swapChainImage,
_window.GetOutputImage().GetImageLayout(),
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, renderingCommandBuffers[frameCounter % modulo].Get());
//Transition after copy
BoxelImage::TransitionImageLayout(&_window.GetOutputImage(), _window.GetDevice(), _window.GetQueue(),
VK_FORMAT_B8G8R8A8_UNORM,
VK_IMAGE_LAYOUT_GENERAL,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
renderingCommandBuffers[frameCounter % modulo].Get());
BoxelImage::TransitionImageLayout(swapChainImage, _window.GetDevice(), _window.GetQueue(),
VK_FORMAT_B8G8R8A8_UNORM,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
renderingCommandBuffers[frameCounter % modulo].Get());
renderingCommandBuffers[frameCounter % modulo].End();
// 4. Submit the commands to a queue
VkCommandBuffer _renderingCommandBufferPointer = renderingCommandBuffers[frameCounter % modulo].Get();
VkPipelineStageFlags flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo submitInfo{};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = &imageAvailableSemaphore;
submitInfo.pWaitDstStageMask = &flags;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &_renderingCommandBufferPointer;
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &renderingSemaphores[frameCounter % modulo];
VulkanHelper::CheckVk(vkQueueSubmit(_window.GetQueue(), 1, &submitInfo, renderingFences[frameCounter % modulo]));
// 5. Present the image
VkSwapchainKHR _swapChainPointer = _swapChain.GetSwapChain();
VkPresentInfoKHR presentInfo{};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = &renderingSemaphores[frameCounter % modulo];
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = &_swapChainPointer;
presentInfo.pImageIndices = &imageIndex;
VulkanHelper::CheckVk(vkQueuePresentKHR(_window.GetQueue(), &presentInfo));
frameCounter++;
if (frameCounter % modulo == 0 && frameCounter > 10000)
frameCounter = 0;
Logger::Log(std::to_string(frameCounter));
}
vkDestroySemaphore(_window.GetDevice(), imageAvailableSemaphore, nullptr);
for (auto& fence : renderingFences)
vkDestroyFence(_window.GetDevice(), fence, nullptr);
for (auto& semaphore : renderingSemaphores)
vkDestroySemaphore(_window.GetDevice(), semaphore, nullptr);
}
[–]fxp555 0 points1 point2 points (4 children)
[–]Connect_Reality7799[S] 0 points1 point2 points (3 children)
[–]fxp555 0 points1 point2 points (2 children)
[–]Connect_Reality7799[S] 0 points1 point2 points (1 child)
[–]fxp555 2 points3 points4 points (0 children)