#imgui #vulkan #ash

imgui-rs-vulkan-renderer

A Vulkan renderer for imgui-rs using Ash

10 releases (4 breaking)

0.6.0 Nov 15, 2020
0.5.0 Oct 7, 2020
0.4.2 Aug 17, 2020
0.4.1 Jun 19, 2020
0.1.1 Jan 30, 2020

#37 in Graphics APIs

Download history 2/week @ 2020-08-03 24/week @ 2020-08-10 36/week @ 2020-08-17 58/week @ 2020-08-24 14/week @ 2020-08-31 19/week @ 2020-09-07 9/week @ 2020-09-14 31/week @ 2020-09-21 13/week @ 2020-09-28 27/week @ 2020-10-05 4/week @ 2020-10-12 19/week @ 2020-10-19 7/week @ 2020-10-26 15/week @ 2020-11-02 70/week @ 2020-11-09 15/week @ 2020-11-16

98 downloads per month

MIT license

62KB
1K SLoC

imgui-rs-vulkan-renderer

Version Docs.rs Build Status Publish Status

A Vulkan renderer for imgui-rs using Ash.

screenshot

How it works

The renderer records drawing command to a command buffer supplied by the application. Here is a little breakdown of the features of this crate and how they work.

  • Vertex/Index buffers

The renderer creates a vertex buffer and a index buffer that will be updated every time Renderer::cmd_draw is called. If the vertex/index count is more than what the buffers can actually hold then the buffers are resized (actually destroyed then re-created).

  • Frames in flight

The renderer support having multiple frames in flight. You need to specify the number of frames during initialization of the renderer. The renderer manages one vertex and index buffer per frame.

  • No draw call execution

The Renderer::cmd_draw only record commands to a command buffer supplied by the application. It does not submit anything to the gpu.

  • Custom textures

The renderer supports custom textures. See Renderer::textures for details.

  • Custom Vulkan allocators

Custom Vulkan allocators are not supported for the moment.

Integration

You can find an example of integration in the common module of the examples.

The RendererVkContext trait

You need to implement that trait that will be used to access Vulkan resources such as the instance and device.

The Renderer struct

This is the main struct of the renderer. It has 3 function:

  • Renderer::new create and initialize the renderer. It takes:

    • A reference to a struct implementing RendererVkContext
    • The number of frames in flight of the application
    • The RenderPass use during rendering
  • Renderer::cmd_draw records commands required to render the ui. It takes:

    • A reference to a struct implementing RendererVkContext
    • A CommandBuffer to record commands to
    • A reference to the DrawData generated by imgui-rs
  • Renderer::destroy release all gpu resources allocated by the renderer. It takes:

    • A reference to a struct implementing RendererVkContext

Renderer::new and Renderer::cmd_draw return a RendererResult which is defined as follows:

type RendererResult<T> = Result<T, RendererError>;

Examples

You can run a set of examples by running the following command:

# If you want to enable validation layers
export VK_LAYER_PATH=$VULKAN_SDK/Bin
export VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation

# If you changed the shader code (you'll need glslangValidator on you PATH)
# There is also a PowerShell version (compile_shaders.ps1)
./compile_shaders.sh

# Run an example
cargo run --example <example>

# Example can be one of the following value:
# - collapsing_header
# - color_button
# - custom_textures
# - hello_world
# - progress_bar
# - radio_button
# - test_drawing_channels_split
# - test_window_impl
# - test_window

Dependencies

~10MB
~211K SLoC