編輯創建命令緩衝區時: 這裏是Valgrind的輸出:段錯誤在vkCmdDrawIndexed了第二次
==6785==
==6785== Process terminating with default action of signal 11 (SIGSEGV)
==6785== Access not within mapped region at address 0xE0
==6785== at 0xA138542: cvdescriptorset::DescriptorSet::ValidateDrawState(std::map<unsigned int, descriptor_req, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, descriptor_req> > > const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::string*) const (in /home/user/VulkanSDK/1.0.37.0/x86_64/lib/libVkLayer_core_validation.so)
==6785== by 0xA0D9A06: core_validation::validate_and_update_draw_state(core_validation::layer_data*, GLOBAL_CB_NODE*, bool, VkPipelineBindPoint, char const*) (in /home/user/VulkanSDK/1.0.37.0/x86_64/lib/libVkLayer_core_validation.so)
==6785== by 0xA0EE4F3: core_validation::CmdDrawIndexed(VkCommandBuffer_T*, unsigned int, unsigned int, unsigned int, int, unsigned int) (in /home/user/VulkanSDK/1.0.37.0/x86_64/lib/libVkLayer_core_validation.so)
==6785== by 0xA8B6F23: object_tracker::CmdDrawIndexed(VkCommandBuffer_T*, unsigned int, unsigned int, unsigned int, int, unsigned int) (in /home/user/VulkanSDK/1.0.37.0/x86_64/lib/libVkLayer_object_tracker.so)
==6785== by 0xB3AD421: threading::CmdDrawIndexed(VkCommandBuffer_T*, unsigned int, unsigned int, unsigned int, int, unsigned int) (in /home/user/VulkanSDK/1.0.37.0/x86_64/lib/libVkLayer_threading.so)
==6785== by 0x13B147: VulkanRenderer::createCommandBuffers(ObjectInRAM*, ObjectInRAM*) (in /home/wobbi/git/Code/Implementierungen/Vulkan/VulkanTest)
==6785== by 0x13F1FF: VulkanRenderer::mainLoop() (in /home/wobbi/git/Code/Implementierungen/Vulkan/VulkanTest)
==6785== by 0x110716: main (in /home/wobbi/git/Code/Implementierungen/Vulkan/VulkanTest)
我總算得到vkCmdDrawIndexed期間段錯誤在我福爾康應用。 我想要做的是我想繪製兩個對象。第一個只有一次,第二個對象在不同位置可變的次數(沒有實例化)。我通過pushConstants得到不同的位置,一切正常。
當按下按鈕時,我想增加第二個對象的繪製次數,所以我等到設備空閒,然後用新的繪製調用數重新創建命令緩衝區。
但是在命令緩衝區的重新創建過程中,我得到一個段錯誤: vkCmdDrawIndexed(commandBuffers [i],obj2-> indices.size(),1,0,0,0);
我的代碼基於Vulkan-Tutorial.com,所以我只是再次調用createCommandBuffers()函數。
我爲我的池分配了: poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
爲什麼我得到段錯誤任何幫助,將不勝感激
代碼:
void VulkanRenderer::mainLoop()
{
float lastTextureChange = glfwGetTime();
float lastFPSUpdate = glfwGetTime();
int numFrames = 0;
int lastGPULoad = 1;
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
//adjust camera values
//if frames are further apart then movement between frames has to be faster
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
do_movement();
updateUniformBuffer(glm::vec3(0.0f), 0.1f);
if(lastGPULoad != GPULoad)
{
lastGPULoad = GPULoad;
recreateSwapChain();
}
drawFrame();
}
vkDeviceWaitIdle(device);
glfwDestroyWindow(window);
}
void VulkanRenderer::recreateSwapChain()
{
vkDeviceWaitIdle(device);
createSwapChain();
createImageViews();
createRenderPass();
createGraphicsPipeline();
createDepthResources();
createFramebuffers();
createCommandBuffers(&male, &cube);
}
void VulkanRenderer::createCommandBuffers(ObjectInRAM* obj, ObjectInRAM* obj2)
{
//check if old command buffers are still around and free them
if (commandBuffers.size() > 0)
{
vkFreeCommandBuffers(device, commandPool, commandBuffers.size(), commandBuffers.data());
}
commandBuffers.resize(swapChainFramebuffers.size());
std::cout <<"creating new command buffers:" <<commandBuffers.size() <<std::endl;
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;
beginInfo.pInheritanceInfo = nullptr; // Optional
vkBeginCommandBuffer(commandBuffers[i], &beginInfo);
VkRenderPassBeginInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = renderPass;
renderPassInfo.framebuffer = swapChainFramebuffers[i];
renderPassInfo.renderArea.offset = {0};
renderPassInfo.renderArea.extent = swapChainExtent;
std::array<VkClearValue, 2> clearValues = {};
clearValues[0].color = {0.0f, 0.0f, 0.0f, 1.0f};
clearValues[1].depthStencil = {1.0f, 0};
renderPassInfo.clearValueCount = clearValues.size();
renderPassInfo.pClearValues = clearValues.data();
updateUniformBuffer(glm::vec3(80.0f, 80.0f, 80.0f), 10.0f);
vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
pushUBO.model = glm::mat4();
pushUBO.model = glm::scale(pushUBO.model, glm::vec3(1.0f));
// Submit via push constant (rather than a UBO)
vkCmdPushConstants(
commandBuffers[i],
pipelineLayout,
VK_SHADER_STAGE_VERTEX_BIT,
0,
sizeof(pushUBO),
&pushUBO
);
vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
//Binding vertex buffers
VkBuffer vertexBuffers[] = {obj2->vertexBuffer};
VkDeviceSize offsets[] = {0};
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);
vkCmdBindIndexBuffer(commandBuffers[i], obj2->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
std::cout <<"bound index: " <<obj2->indices.size() <<std::endl;
vkCmdDrawIndexed(commandBuffers[i], obj2->indices.size(), 1,0,0,0);
std::cout <<"before crowd cmd recording " <<std::endl;
//render crowd
vertexBuffers[0] = obj->vertexBuffer;
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);
vkCmdBindIndexBuffer(commandBuffers[i], obj->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
int drawCmdCounter = 0;
while(drawCmdCounter < GPULoad)
{
pushUBO.model = glm::mat4();
pushUBO.model = glm::translate(pushUBO.model, glm::vec3(drawCmdCounter*5.0f, 0.0f,0.0f));
// Submit via push constant (rather than a UBO)
vkCmdPushConstants(
commandBuffers[i],
pipelineLayout,
VK_SHADER_STAGE_VERTEX_BIT,
0,
sizeof(pushUBO),
&pushUBO
);
vkCmdDrawIndexed(commandBuffers[i], obj->indices.size(), 1,0,0,0);
drawCmdCounter++;
}
vkCmdEndRenderPass(commandBuffers[i]);
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
throw std::runtime_error("failed to record command buffer!");
}
}
}
歡迎來到StackOverflow。請參閱[如何創建一個最小,完整和可驗證的示例](https://stackoverflow.com/help/mcve)以明確問題。 – lnman
您是否有適當的同步以確保您在覆蓋命令緩衝區的同時仍在進行中?還啓用驗證圖層並檢查其輸出是否有任何錯誤。如果你有適當的同步和驗證是乾淨的,發佈一個調用棧, –
'void VulkanRenderer :: recreateSwapChain() { vkDeviceWaitIdle(device); //重建交換鏈 createCommandBuffers(); }' 當我注意到我需要更多/更少的繪製調用時,我在主循環中調用了這個函數。是否正在等待設備足夠空閒以確保沒有更多命令緩衝區正在運行? – wobbi