Skip to content

danilw/nanovg_vulkan

 
 

Repository files navigation

added vulkan build, and cmake files, removed premake4.lua

Why I made this - I made it as a "test task for Vulkan related job" a year ago, for me this project has no real use. I would recommend for everyone use imgui if you look for production-ready Vulkan UI, also look on egui. I will not support or update this project at all, the last update was just to fix bugs and Validation errors.

Description - nanovg in C, no external dependencies. GLFW used only by one example (look examples description, there is example without using GLFW).


To launch - copy builded binary to example folder(or launch when this folder is current as on build example commands below). Because required fonts and images/shaders to load.


Known bugs-related info:


Build:

(use cmake to build on Windows, Windows/Linux supported and tested)

git clone --recursive https://github.com/danilw/nanovg_vulkan
cd nanovg_vulkan/example
mkdir build
cd build
cmake ../
make
cd ../
./build/example-vk
./build/example-vk_min_no_glfw

Look Examples description below there link to repository with C only minimal example without dependencies not using any library.

MoltenVK note - after TOPOLOGY_TRIANGLE_LIST update(look below) this Vulkan port does work on MoltenVK(Mac/etc) but I dont have it to test so you should make cmake config to build it and launch by yourself.


Examples description:

Multiple frames in flight - example_vulkan.c is multiple frames in flight example, example_vulkan_min_no_glfw.c is single frame in flight. Clearly visible on FPS - with multiple frames about 3x better FPS.


example_vulkan.c - minimal NanoVG example that use GLFW.

example_vulkan_min_no_glfw.c - same as above but not using GLFW, supported Linux and Windows.


2023 update - huge performance improvement thanks to @SubiyaCryolite

SubiyaCryolite pull request Optimizations > Cached Descriptor Sets, Implied Multiple Frames in Flight, Fencing for faster perf

  • Support for multiple command buffers, specifically one per swap-chain image / buffer
  • Caching of descriptor sets, removing the need to create new ones per draw func or to call vkResetDescriptorPool per frame.
  • Under example_vulkan, using vkWaitForFences to control rendering as opposed to vkQueueWaitIdle (seems to be the biggest perf booster). This change also has implied "multiple frames in flight" as dictated by the swap-chain image count.
  • Using persisted mapped buffers via VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT instead of VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT , allows to skip calls to vkMap/UnmapMemory per frame

Link to version before this change 5ba9d31, this change 10d5211.



2022 update - thanks to @nidefawl pull request with lots of changes:

In this PR:

  1. Merge latest nanovg

  2. Fix Stencil Strokes: I added a new enum to handle the 3 different pipelines used for stencil strokes.
    I wanted to also use enums for the fill-path (nvgFill) to make the code cleaner, but haven't done that yet.

  3. I combined the 2 CMakeLists.txt into example/CMakeLists.txt and added some bits to make it easier to build and debug in MSVC/VSCode.

  4. I added GLAD as default gl-loader for the GL3 example. It can be switched back to GLEW (I kept glew to allow easier merge with main nanovg)

  5. I Increased the number of swapchain images to minimum 3 and updated the swapchain barrier to gain some extra performance.

  6. Spacebar renders the demo multiple times to add some 'load' when comparing performance


2021 update - fixed all errors, this code has no Validation errors and work correctly everywhere.

Thanks to @fzwoch commits by default used TOPOLOGY_TRIANGLE_LIST, because TOPOLOGY_TRIANGLE_FAN is optional in Vulkan.

To enable TOPOLOGY_TRIANGLE_FAN edit src/nanovg_vk.h and set there #define USE_TOPOLOGY_TRIANGLE_FAN

Depth order bug on AMD fix by @leranger 6ee1009.


Screenshot of Vulkan version from Linux:

nvgvk


Read original readme for more info about NanoVG API https://github.com/memononen/nanovg

About

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations. (added Vulkan support)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 99.0%
  • Other 1.0%