Why is OpenGL simple loop faster than Vulkan one?

1

I have 2 graphics applications for OpenGL and Vulkan.

OpenGL loop looks something like this:

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, 0, vertices_size);
    glUseProgram(0);
}
else {

    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer2);
    glUseProgram(program2);
    glDrawArrays(GL_LINES, 0, vertices_size);
    glUseProgram(0);
}

glfwSwapBuffers(window);

And 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, 1, &submission_completed_fences[image_index]);

vkQueueSubmit(graphics_queue, 1, &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;
}

In the Vulkan loop there are no even rendering commands, just empty render pass. Validation layers are disabled.

OpenGL FPS is about 10500, and Vulkan FPS is about 7500 (with 8 swapchain images in use with VK_PRESENT_MODE_IMMEDIATE_KHR, less images make FPS lower).

Code is running on laptop with Ubuntu 18.04, discrete GPU Nvidia RTX 2060, Nvidia driver 450.66, Vulkan API version 1.2.133.

I know that OpenGL driver is highly optimized, but i can't imagine what else is to be optimized in Vulkan loop to make it faster than it is.

Are there some low-level linux driver issues? Or maybe Vulkan performance increase is accomplished only in much more complex applications (using multithreading e.g.)?

opengl
vulkan
asked on Stack Overflow Oct 4, 2020 by Denis Belov • edited Oct 5, 2020 by Denis Belov

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0