Hi.
I have this strange situation, My scene loader is not capable of load the entire mesh array.
When I try to reduce the loop that call the draw command to something close to 70% of total mesh.size() it work’s fine.
I’ve tried different meshes and the same thing happens…
commandBuffers.resize(swapChainFramebuffers.size());
VkCommandBufferAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = commandPool;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = (uint32_t)commandBuffers.size();
if (vkAllocateCommandBuffers(device, &allocInfo, commandBuffers.data()) != VK_SUCCESS) {
throw std::runtime_error("failed to allocate command buffers!");
}
for (size_t i = 0; i < commandBuffers.size(); i++) {
VkCommandBufferBeginInfo beginInfo = {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) {
throw std::runtime_error("failed to begin recording command buffer!");
}
VkRenderPassBeginInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = renderPass;
renderPassInfo.framebuffer = swapChainFramebuffers[i];
renderPassInfo.renderArea.offset = { 0, 0 };
renderPassInfo.renderArea.extent = swapChainExtent;
std::array<VkClearValue, 2> clearValues = {};
clearValues[0].color = { .0f, 0.0f, 0.0f, 1.0f };
clearValues[1].depthStencil = { 1.0f, 0 };
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
renderPassInfo.pClearValues = clearValues.data();
vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
VkBuffer vertexBuffers[] = { vertexBuffer };
VkDeviceSize offsets[1] = { 0 };
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);
vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT32);
If I change the meshes.size in this loop, for something close to 70% of the meshes size it works fine…
In other words, I can render the latest meshes.
I’ve tried to render just the last meshe and the same thing happens
for (size_t x = 0; x <meshes.size(); x++) {
std::cout << "\n X : " << x << std::endl;
VkPipelineLayout pipeline;
if (meshes[x].material->hasTexture) {
pipeline = pipelineWithTexturelayout;
std::array<VkDescriptorSet, 3> descriptorSets;
descriptorSets[0] = descriptorSetScene;
descriptorSets[1] = meshes[x].material->descriptorSet;
descriptorSets[2] = LightdescriptorSetScene;
vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineWithTexture);
vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineWithTexturelayout, 0, static_cast<uint32_t>(descriptorSets.size()), descriptorSets.data(), 0, NULL);
}
else {
pipeline = pipelineTextureLessLayout;
std::array<VkDescriptorSet, 2> descriptorSets;
// Set 0: Scene descriptor set containing global matrices
descriptorSets[0] = descriptorSetScene;
descriptorSets[1] = LightdescriptorSetScene;
// Set 1: Per-Material descriptor set containing bound images
//descriptorSets[1] = meshes[x].material->descriptorSet;
vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineTextureLess);
vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineTextureLessLayout, 0, static_cast<uint32_t>(descriptorSets.size()), descriptorSets.data(), 0, NULL);
}
vkCmdPushConstants(
commandBuffers[i],
pipeline,
VK_SHADER_STAGE_FRAGMENT_BIT,
0,
sizeof(Materials),
&meshes[x].material->properties);
//vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(meshes[x].indexCount), 1, 0, static_cast<uint32_t>(meshes[x].indexBase), 0);
vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(meshes[x].indexCount), 1, 0, static_cast<uint32_t>(meshes[x].indexBase), 0);
}
vkCmdEndRenderPass(commandBuffers[i]);
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
throw std::runtime_error("failed to record command buffer!");
}
}
When I try to load the entire scene i get an error in vkQueueSubmit it returns -4, wich I believe it’s VK_DEVICE_LOST