A Vulkan renderer for egui using Ash.

Related tags

GUI rust vulkan ash egui
Overview

egui-ash-renderer

Version Docs.rs Build Status Publish Status

A Vulkan renderer for egui using Ash.

This is meant to add support for egui in your existing Vulkan/ash applications. Not a full eframe integration for Vulkan/ash.

screenshot

Compatibility

crate egui ash gpu-allocator (feature) vk-mem (feature)
0.2.0 [0.26, 0.27] [0.34, 0.37] 0.25 0.3.0

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.

  • Managed textures

Textures managed by egui must be kept in sync with the renderer. To do so, the user should call Renderer::set_textures and Renderer::free_textures. The former must be call before submitting the command buffer for rendering and the latter must be called after rendering is complete. Example:

let output = egui_ctx.run(raw_input, |ui| {
    // ui code ..
});

// before rendering the ui
renderer.set_textures(queue, command_pool, output.textures_delta.set.as_slice()).unwrap();

// rendering code goes here .. (calling cmd_draw, submitting the command buffer, waiting for rendering to be finished...)

// after the rendering is done 
renderer.free_textures(output.textures_delta.free.as_slice()).unwrap();

If you have multiple frames in flight you might want to hold a set of textures to free for each frame and call Renderer::free_textures after waiting for the fence of the previous frame.

  • Custom textures

You can also render used managed textures in egui. You just need to call Renderer::add_user_texture and pass a vk::DescriptorSet compatible with the layout used in the renderer's graphics pipeline (see create_vulkan_descriptor_set_layout). This will return a egui::TextureId that you can use in your ui code. Example:

let user_texture_set: vk::DescriptorSet = ...;
let texture_id = renderer.add_user_texture(user_texture_set);

let output = egui_ctx.run(raw_input, |ui| {
    let egui_texture = SizedTexture {
        id: texture_id,
        size: Vec2 {
            x: 128.0,
            y: 128.0,
        },
    };

    egui::Image::new(egui_texture).ui(ui);
});

// When the texture won't be used anymore you can remove it from the renderer
renderer.remove_user_texture(texture_id);

You can find a example using egui managed and user managed textures here.

Features

gpu-allocator

This feature adds support for gpu-allocator. It adds Renderer::with_gpu_allocator which takes a Arc<Mutex<gpu_allocator::vulkan::Allocator>>. All internal allocator are then done using the allocator.

vk-mem

This feature adds support for vk-mem-rs. It adds Renderer::with_vk_mem_allocator which takes a Arc<Mutex<vk_mem::Allocator>>. All internal allocator are then done using the allocator.

dynamic-rendering

This feature is useful if you want to integrate the library in an app making use of Vulkan's dynamic rendering. When enabled, functions that usually takes a vk::RenderPass as argument will now take a DynamicRendering which contains the format of the color attachment the UI will be drawn to and an optional depth attachment format.

Integration

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

// Example with default allocator
let renderer = Renderer::with_default_allocator(
    &vk_instance,
    vk_physical_device,
    vk_device.clone(),
    vk_render_pass,
    Options::default(),
).unwrap();

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

# Or with Powershell
$env:VK_LAYER_PATH = "$env:VULKAN_SDK\Bin"
$env: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)
./scripts/compile_shaders.sh

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

# Example can be one of the following value:
# - demo_windows
# - textures
You might also like...
Egui bindings for macroquad

egui bindings for macroquad This is the easiest way to use egui. Just two functions! Web demo. Usage You need to call ui when you need to get informat

Egui bindings for miniquad

egui bindings for miniquad native On Linux you first must run apt install libx11-dev libxi-dev libgl1-mesa-dev (miniquad dependencies). cargo run --re

Render egui with skia!

Skia backend for egui This is a drawing backend for egui that uses skia-safe. Usage Have a look at the metal or cpu examples to get started. Run the e

a day-planner/calendar app based on egui
a day-planner/calendar app based on egui

Malakal Malakal is a day planner application. I crafted it because I was not able to find a comfortable calendar application for Linux. I myself have

Example showing how to use tokio and egui together.

Example using tokio with egui This example uses reqwest to send an HTTP request to httpbin. The parsed response contains an increment value (as provid

A render-backend independant egui backend for sdl2

A Sdl2 + Egui Backend An egui backend for sdl2 unbound to any renderer-backend. You can include it like so: [dependencies] egui_sdl2_platform = "0.1.0

egui backend for D3D9.

egui-d3d9 egui backend for D3D9. Primarily intended for source games like CS:GO and GMod. It's not perfect by far, but it'll do. This is a rewrite of

A tool for creating egui Visuals (themes).

egui-visuals-utility A tool for creating egui Visuals (themes). The code is rather messy and might crash but it seems to work. To load the theme use s

egui port to Car Thing (and maybe an alternative Car Thing UI?)
egui port to Car Thing (and maybe an alternative Car Thing UI?)

tt This project contains a port of egui to the Spotify Car Thing although in the future I also plan for it to contain a custom Car Thing UI. Technical

Comments
  • bump ash to 0.38

    bump ash to 0.38

    • [x] bump ash to 0.38
    • [ ] bump vk-mem (https://github.com/gwihlidal/vk-mem-rs/pull/67)
    • [ ] bump gpu-allocator (https://github.com/Traverse-Research/gpu-allocator/pull/218)
    opened by adrien-ben 0
Releases(0.2.0)
Owner
Adrien Bennadji
Backend web developper based in France. I like programming game related stuff on my spare time.
Adrien Bennadji
Egui node graph is a featureful, customizable library to create node graph applications using egui

Egui node graph is a featureful, customizable library to create node graph applications using egui. The library takes care of presenting a node graph to your users, and allows customizing many aspects of the interaction, creating the semantics you want for your specific application.

null 367 Jan 8, 2023
A presentation about egui, implemented in egui

egui presentation A presentation about egui, implemented in egui. You can view the presentation at https://emilk.github.io/egui_presentation/. TODO Li

Emil Ernerfeldt 9 Aug 24, 2023
A react-inspired UI library for building multimedia desktop apps with rust and vulkan.

narui A react-inspired UI library for building multimedia desktop apps with rust and vulkan. declarative UI with Ergonomics similar to React with hook

apertus° - open source cinema 42 Jan 1, 2023
💡 Experimental real-time global illumination renderer 🦀

?? kajiya Experimental real-time global illumination renderer made with Rust and Vulkan Its general goal is to get as close as possible to path-traced

Embark 3.8k Jan 3, 2023
♾️ A multithreaded fractal renderer in Rust

fractal.rs A multithreaded fractal renderer in Rust Online release The live wasm-compiled release is accessible here. Due to some rust wasm compiler l

Bertrand 16 Aug 26, 2022
This project attempts to allow the creation of reusable egui-themes

egui stylist Note this project is considered to be experimental and -- while used in personal projects -- may have API breaking changes without warnin

Jacobsky 22 Dec 1, 2022
A simple GUI version of the pH calibration tool written in egui, based on the eframe template.

caliphui A simple GUI version of the pH calibration tool written in egui, based on the eframe template. Usage Native binaries are provided under relea

Peter Dunne 0 Dec 29, 2021
FLTK frontend for Egui WGPU backend.

Egui FLTK Frontend FLTK Frontend for Egui WGPU Backend On linux Debian/Ubuntu, make sure to install the latest main requirements: sudo apt-get update

Adia Robbie 5 Oct 25, 2022
egui: an easy-to-use immediate mode GUI in pure Rust

?? egui: an easy-to-use GUI in pure Rust egui is a simple, fast, and highly portable immediate mode GUI library for Rust. egui runs on the web, native

Emil Ernerfeldt 12.6k Jan 3, 2023
D3D11 backend for egui library. Presumably for mods/cheats development

D3D11 backend for egui library. Presumably for mods/cheats development. Currently few features from egui are missing. WIP.

sy1ntexx 24 Jan 4, 2023