为什么OpenGL简单循环比Vulkan循环更快?

问题描述

我有2个用于OpenGL和Vulkan的图形应用程序。

OpenGL循环如下所示:

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

static int test = 0;

// "if" statement here is to ensure that there is no any caching or optimizations
// made by OpenGL driver (if such things exist),// and commands are re-recorded to the buffer every frame

if ((test = 1 - test) == 0) {

    glBindBuffer(GL_ARRAY_BUFFER,vertex_buffer1);
    gluseProgram(program1);
    glDrawArrays(GL_TRIANGLES,vertices_size);
    gluseProgram(0);
}
else {

    glBindBuffer(GL_ARRAY_BUFFER,vertex_buffer2);
    gluseProgram(program2);
    glDrawArrays(GL_LInes,vertices_size);
    gluseProgram(0);
}

glfwSwapBuffers(window);

还有Vulkan:

static uint32_t image_index = 0;

vkAcquireNextimageKHR(device,swapchain,0xFFFFFFFF,image_available_semaphores[image_index],VK_NULL_HANDLE,&image_indices[image_index]);

vkWaitForFences(device,1,&submission_completed_fences[image_index],VK_TRUE,0xFFFFFFFF);

// VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
vkBeginCommandBuffer(cmd_buffers[image_index],&command_buffer_bi);
vkCmdBeginRenderPass(cmd_buffers[image_index],&render_pass_bi[image_index],VK_SUBPASS_CONTENTS_INLINE);
vkCmdEndRenderPass(cmd_buffers[image_index]);
vkEndCommandBuffer(cmd_buffers[image_index]);

vkResetFences(device,&submission_completed_fences[image_index]);

vkQueueSubmit(graphics_queue,&submit_info[image_index],submission_completed_fences[image_index]);

present_info[image_index].pImageIndices = &image_indices[image_index];

vkQueuePresentKHR(present_queue,&present_info[image_index]);

const static int max_swapchain_image_index = swapchain_image_count - 1;

if (++image_index > max_swapchain_image_index) {

  image_index = 0;
}

在Vulkan循环中,甚至没有渲染命令,只是空的渲染通道。验证层已禁用。

OpenGL FPS大约为10500,Vulkan FPS大约为7500(VK_PRESENT_MODE_IMMEDIATE_KHR使用8个交换链图像,较少的图像会使FPS降低)。

代码在具有Ubuntu 18.04,离散GPU Nvidia RTX 2060,Nvidia驱动程序450.66,Vulkan API版本1.2.133的笔记本电脑上运行。

我知道OpenGL驱动程序已经过高度优化,但是我无法想象Vulkan循环中还有哪些要优化的事情才能使其更快。

是否存在一些底层Linux驱动程序问题?也许Vulkan的性能提升只能在复杂得多的应用程序中实现(例如使用多线程)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)