

[OpenGL and Vulkan Interoperability on Linux] Part 8: Using a Vulkan vertex buff...
source link: https://eleni.mutantstargoat.com/hikiko/vk-gl-interop-8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[OpenGL and Vulkan Interoperability on Linux] Part 8: Using a Vulkan vertex buffer from OpenGL and then from Vulkan
This is the 8th post on OpenGL and Vulkan Interoperability with EXT_external_objects and EXT_external_objects_fd where I explain some example use cases of the extensions I’ve implemented for Piglit as part of my work for Igalia. In this example, a Vulkan vertex buffer is created and filled with vertices and then it’s used to render the same chess board pattern once with OpenGL and once with Vulkan.
The Piglit test where I’ve implemented this use case is named vk-vert-buf-reuse and it’s source code can be found in piglit/tests/spec/ext_external_objects/vk_vert_buf_reuse.c
(you must clone the Piglit master branch).
The vk-vert-buf-reuse
test:
- Allocates a Vulkan vertex buffer and fills it with vertices that could form the white quads of a chess board like the ones we’ve seen in Part 7.
- Imports and uses the vertex buffer from OpenGL to draw the pattern on screen (like in Part 7).
- Reuses the vertex buffer to draw the same image with Vulkan.
- Copies the Vulkan render target image to a buffer to take a pointer to data and displays them with OpenGL
The expected result is the same red-blue chessboard pattern we’ve seen in Part 7:
Step 1: Allocating and filling the Vulkan vertex buffer
This step is similar to the one we’ve seen in Part 7. In vk_init
of piglit_init
we create an external vertex buffer and we fill it vertices that could be used to draw the white quads of a chess board using gen_checkerboard_quads
.
all the functions of the snippet above have already been explained in the previous post.
Step 2: Using the Vulkan vertex buffer in OpenGL rendering
We use the vertex buffer in piglit_display
to render the geometry in blue after we clear the framebuffer to red using a pair of shaders that we’ve also explained in Part 7. Then we validate that what is displayed on the screen is indeed a red-blue chessboard by calling check_red_blue_chess_pattern
:
The function check_red_blue_chess_pattern
only probes the middle pixel’s color for each red or blue quad using built-in piglit testing functions:
Step 3: The vertex buffer is used from Vulkan to draw the same chess board pattern
To draw with Vulkan we’ve first initialized some required Vulkan structs in vk_init
that is called inside piglit_init
. We used vk_init_vulkan_drawing
for that:
This function creates a Vulkan “renderer” (an abstract struct I use to render different scenes with the Piglit Vulkan framework). It also creates the color and depth attachments, the shaders and the vertex buffer that will be used at drawing. The shaders do more or less the same thing the OpenGL ones did in Part 7 and their code can be found in tests/spec/ext_external_objects/vk_blue.vert
and tests/spec/ext_external_objects/vk_blue.frag
files of the piglit master branch (the test is upstream).
After this required step, the rendering can be performed by calling vk_draw_checkerboard
in piglit_display
. This function renders the checkerboard pattern to the Vulkan renderer’s render target. After it’s called we only need a pointer to its pixels and we can use it with a new OpenGL texture to display and validate that the pattern is the same.
[Note!] the reason we display the pixels with OpenGL is that this code is part of the piglit testing framework where we can only draw pixels using OpenGL. In a different application someone could simply visualize the renderer’s renderpass render target with Vulkan.
The Vulkan function that draws the chess board pattern is simply a call to vk_draw
we’ve seen in previous examples:
And that was it!
In this test we’ve allocated a Vulkan vertex buffer, we’ve used it to draw with OpenGL and then we reused it to draw with Vulkan. At the end, we displayed the pixels of the Vulkan render target with OpenGL to validate they form a blue and red chess board pattern.
Links:
What’s next:
Next post will be about reusing an external Vulkan depth buffer from OpenGL and there will be one more about reusing the stencil buffer. Stay tuned!
and see you next time!
Recommend
-
22
[OpenGL and Vulkan Interoperability on Linux] Part 10: Reusing a Vulkan stencil buffer from OpenGL This is 10th post on
-
16
[OpenGL and Vulkan Interoperability on Linux] Part 9: Reusing a Vulkan z buffer from OpenGL In this 9th post on Op...
-
14
[OpenGL and Vulkan Interoperability on Linux] Part 7: Reusing a Vulkan vertex buffer from OpenGL This is the 7th post on
-
13
[OpenGL and Vulkan Interoperability on Linux] Part 6: We should be able to reuse a Vulkan pixel buffer from OpenGL but not to overwrite it! This is another blog post on
-
20
[OpenGL and Vulkan Interoperability on Linux] Part 5: A Vulkan pixel buffer is reused by OpenGL This is the 5th post of the
-
26
[OpenGL and Vulkan Interoperability on Linux] Part 4: Using OpenGL to overwrite Vulkan allocated textures. This is the 4th post on
-
13
[OpenGL and Vulkan Interoperability on Linux] Part 3: Using OpenGL to display Vulkan allocated textures. This is the third post of the
-
9
[OpenGL and Vulkan Interoperability on Linux]: The XDC 2020 presentation In this year’s XDC I’ve given a talk about OpenGL and Vulkan interoperability and our work to support
-
15
[OpenGL and Vulkan Interoperability on Linux] Part 2: Using OpenGL to draw on Vulkan textures. This is the second post of the
-
10
摩尔线程MTT S80 Linux驱动 v2.1.0:支持OpenGL 4.0和Vulkan 1.3
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK