Hi!
I don’t have problems when I do tests in the main function but when I want to implement this in a class, when I draw more things, the second call to VkQueueSubmit cause the VK_ERROR_DEVICE_LOST.
The indirect draw call command is quite long here :
void PerPixelLinkedListRenderComponent::createCommandBuffersIndirect(unsigned int p, unsigned int nbIndirectCommands, RenderStates currentStates) {
commandBuffers.resize(frameBuffer.getSwapchainFrameBuffers().size());
VkCommandBufferAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = vkDevice.getCommandPool();
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = (uint32_t) commandBuffers.size();
if (vkAllocateCommandBuffers(vkDevice.getDevice(), &allocInfo, commandBuffers.data()) != VK_SUCCESS) {
throw core::Erreur(0, "failed to allocate command buffers!", 1);
}
for (size_t i = 0; i < commandBuffers.size(); i++) {
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) {
throw core::Erreur(0, "failed to begin recording command buffer!", 1);
}
vkCmdPushConstants(commandBuffers[i], frameBuffer.getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(IndirectDrawPushConsts), &indirectDrawPushConsts);
frameBuffer.drawIndirect(commandBuffers[i], i, nbIndirectCommands, sizeof(DrawArraysIndirectCommand), vbBindlessTex[p], vboIndirect, currentStates);
vkCmdPipelineBarrier(commandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 0, nullptr);
VkMemoryBarrier memoryBarrier;
memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
memoryBarrier.pNext = VK_NULL_HANDLE;
memoryBarrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
memoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
vkCmdPipelineBarrier(commandBuffers[i], VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr);
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
throw core::Erreur(0, "failed to record command buffer!", 1);
}
}
frameBuffer.updateCommandBuffers(commandBuffers);
frameBuffer.display();
}
So it seems the render command are not finished when I draw the second pass :
void PerPixelLinkedListRenderComponent::createCommandBufferVertexBuffer(RenderStates currentStates) {
commandBuffers.resize(frameBuffer.getSwapchainFrameBuffers().size());
VkCommandBufferAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = vkDevice.getCommandPool();
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = (uint32_t) commandBuffers.size();
if (vkAllocateCommandBuffers(vkDevice.getDevice(), &allocInfo, commandBuffers.data()) != VK_SUCCESS) {
throw core::Erreur(0, "failed to allocate command buffers!", 1);
}
for (size_t i = 0; i < commandBuffers.size(); i++) {
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) {
throw core::Erreur(0, "failed to begin recording command buffer!", 1);
}
vkCmdPushConstants(commandBuffers[i], frameBuffer.getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(Ppll2PushConsts), &ppll2PushConsts);
frameBuffer.drawVertexBuffer(commandBuffers[i], i, vb, currentStates);
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
throw core::Erreur(0, "failed to record command buffer!", 1);
}
}
frameBuffer.updateCommandBuffers(commandBuffers);
frameBuffer.display();
}
I tried to add a fence but it doesn’t solve the issue :
void RenderTexture::display() {
if (getCommandBuffers().size() > 0) {
vkWaitForFences(vkDevice.getDevice(), 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
VkSubmitInfo submitInfo{};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &getCommandBuffers()[getCurrentFrame()];
vkResetFences(vkDevice.getDevice(), 1, &inFlightFences[currentFrame]);
VkResult result = vkQueueSubmit(vkDevice.getGraphicsQueue(), 1, &submitInfo, inFlightFences[currentFrame]);
std::cout<<"render texture result : "<<result<<std::endl;
/*if (vkQueueSubmit(vkDevice.getGraphicsQueue(), 1, &submitInfo, inFlightFences[currentFrame])) {
throw core::Erreur(0, "échec de l'envoi d'un command buffer!", 1);
}*/
vkDeviceWaitIdle(vkDevice.getDevice());
}
}
I don’t know what should I do…
Thanks.