Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

VULKAN Staging buffer example



  • Hi,

    I would like to use staging buffer to get better performance. My intent is to render terrain. My issue is that I dont see rendered vertices using indices method.

    I use this hierarchy

    • MainWindow : QMainWindow
      • MapView : QVulkanWindow
        • MapViewRenderer : QVulkanWindowRenderer
          • World
            • MapTile (here I perform draw calls for terrain rendering)

    For now I use this code to create Vertex & Indices buffer via Staging buffers

            VK_CHECK_RESULT(vkManager.createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, vertexBufferSize, &vertexStaging.buffer, &vertexStaging.memory, verticesList.data()));
            VK_CHECK_RESULT(vkManager.createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, indexBufferSize, &indexStaging.buffer, &indexStaging.memory, indices.data()));
    	VK_CHECK_RESULT(vkManager.createBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, vertexBufferSize, &model.vertices.buffer, &model.vertices.memory));
    	VK_CHECK_RESULT(vkManager.createBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexBufferSize, &model.indices.buffer, &model.indices.memory));
    
    	// Copy from staging buffers
            VkCommandBuffer copyCommandBuffer = vkManager.createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
    
    	VkBufferCopy copyRegion = {};
    
    	copyRegion.size = vertexBufferSize;
    
    	vkManager.deviceFuncs->vkCmdCopyBuffer(copyCommandBuffer, vertexStaging.buffer, model.vertices.buffer, 1, &copyRegion);
    
    	copyRegion.size = indexBufferSize;
    
    	vkManager.deviceFuncs->vkCmdCopyBuffer(copyCommandBuffer, indexStaging.buffer, model.indices.buffer, 1, &copyRegion);
    
        vkManager.flushCommandBuffer(copyCommandBuffer, true);
    

    I am creating my own Command Buffer but I dont know if that's correct design for QVulkanWindowRenderer. In all examples I dont see own command buffer creation. Should I use QVulkanWindow currentCommandBuffer() ? I couldn't find any github project using Qt 5.11 with Vulkan :/

    Source code is available here



  • Now I am getting

    QVulkanWindow: Device lost
    qt.vulkan: Releasing all resources due to device lost
    qt.vulkan: Releasing swapchain
    

    What could lead to this? If I comment out this code it works.

    deviceFuncs->vkCmdDrawIndexed(commandBuffer, model.indexCount, 1, 0, 0, 0);
    

    Can I somehow enable logging? Or debug it, why it crash?



  • I found solution.. I was setting wrong
    VkPipelineMultisampleStateCreateInfo instead QVulkanWindow::getSampleCountFlagBits() I used VK_SAMPLE_COUNT_1_BIT


Log in to reply