Code Monkey home page Code Monkey logo

vuk's Introduction

vuk logo

vuk - A rendergraph-based abstraction for Vulkan

Discord Server Documentation CI

Quick Start

  1. Grab the vuk repository
  2. Compile the examples
  3. Run the example browser and get a feel for the library
git clone http://github.com/martty/vuk
cd vuk
git submodule init
git submodule update --recursive
mkdir build
cd build
mkdir debug
cd debug
cmake ../.. -G Ninja -DVUK_BUILD_EXAMPLES=ON -DVUK_USE_DXC=OFF
cmake --build .
./vuk_all_examples

(if building with a multi-config generator, do not make the debug folder)

Overview of using vuk

  1. Initialize your window(s) and Vulkan device
  2. Create a vuk::Context object
  3. Each frame:
  4. Each frame, prepare high level description of your rendering, in the form of vuk::Pass
  5. Bind concrete resources as inputs and outputs
  6. Bind managed resources (temporary resources used by the rendergraph)
  7. Record the execution your rendergraph into a command buffer
  8. Submit and present

What does vuk do

  • Automatically deduces renderpasses, subpasses and framebuffers
    • with all the synchronization handled for you
    • including buffers
    • images
    • and rendertargets.
    • for multiple queues
    • using fine grained synchronization when possible (events)
  • Automatically transitions images into proper layouts
    • for renderpasses
    • and commands outside of renderpasses (eg. blitting).
  • Automates pipeline creation with
    • optionally compiling your shaders at runtime using shaderc
    • pipeline layouts and
    • descriptor set layouts
    • by reflecting your shaders
    • and deducing parameters based on renderpass and framebuffer.
  • Automates resource binding with hashmaps, reducing descriptor set allocations and updates.
  • Handles temporary allocations for a frame
  • Handles long-term allocations with RAII handles
  • Comes with lots of sugar to simplify common operations, but still exposing the full Vulkan interface:
    • Matching viewport/scissor dimensions to attachment sizes
    • Simplified vertex format specification
    • Blend presets
    • Directly writable mapped UBOs
    • Automatic management of multisampling
  • Helps debugging by naming the internal resources
  • dear imgui integration code

vuk's People

Contributors

aleokdev avatar anonn10 avatar cajallen avatar hatrickek avatar jazzfool avatar kociap avatar martty avatar nanokatze avatar tearnote avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vuk's Issues

Memory leaks when allocating large buffers via frame resource

When a few specific requirements are met, memory is not freed as expected:

  • A buffer is allocated via an allocator made from DeviceFrameResource,
  • The buffer memory usage is eGPUonly,
  • The allocation is large enough that it would fail with an out of memory error if it had memory usage type eCPUtoGPU.

This leaks all allocated memory (it's not freed after the "frames in flight" number of frames), which leads to VRAM exhaustion within about a second.

The issue is not related to the recent large allocation support (997ad59), behavior is the same even before that commit.

Viability of VUK on Android?

I'm looking into using VUK on Android and I've hit a couple problems

The biggest one is that VUK seems to rely on extensions that aren't available on Android, such as VK_KHR_synchronization2 and VK_KHR_timeline_semaphore. How much does VUK actually rely on these? Would I have to change some core parts of the library to remove them?

std::span overloads for PipelineBaseCreateInfo

PipelineBaseCreateInfo functions like add_spirv() currently take the source as std::vector. This makes sense for sources loaded at runtime, but requires a needless copy if the sources are embedded in the executable. These functions could have variants that accept a std::span, with the requirement that the underlying buffer will live as long as the vuk context. This is low priority but would reduce API friction a little in this scenario.

This would probably need a change to ShaderSource so that it owns a span and optionally a vector of data.

Polling Futures

Currently, there is no way to poll if a Future has completed - this can be useful to avoid needing to spawn threads just to wait.

Do not load debug utils function pointers

Currently, Vuk loads the function pointers for the debug utils functions itself. This fails on my system. My Android phone does not provide the debug utils extension itself, so trying to load the function pointers from the system fails

Volk is able to load the function pointers for the debug utils functions just fine, however. The Vulkan validation layers provide the debug utils extension for systems such as mine, and Volk is able to load the debug utils functions from those layers. I'm not entirely sure how Volk does it

I've gotten unblocked locally by changing the places where Vuk uses debug utils functions to use the function pointers from Volk

Memory management on iGPUs

When allocating eGPUonly buffers, vuk uses the device-local memory. This limits usage on integrated GPUs, which usually have very little dedicated memory, and a large amount of shared memory. As an example, the Ryzen 5900HX has 512MB device-local memory and 8GB shared memory.

A workaround is to always use eCPUtoGPU when running on an integrated GPU. It would be nice though if the vuk user didn't have to care about whether the host device is integrated or dedicated.

Missing CommandBuffer overloads

Most CommandBuffer member functions, like bind_buffer, can take either a Buffer or a Name. Some of them though, like bind_index_buffer or draw_indexed_indirect, take only a Buffer, and that needs to be worked around with the verbose *cmd.get_resource_buffer("bufferName"). Would be nice to have full feature parity for names here.

Enhancement: Name composition

I propose adding operator+ for vuk::Name, which returns a new concatenated Name with an optional joiner string in between (underscore sounds like a sensible default.) It could also be an alternate constructor taking two Name arguments.

The purpose is to support basic scoping of rendergraph identifiers. Currently, it is difficult to create rendergraph components that can be appended to a rendergraph more than once, because of resource name collisions. Concatenation would allow for an interface where the component itself is passed a Name on creation, and it uses that name as a prefix for all the resources it creates.

Example validation crash

Steps to reproduce:

  1. Run the vuk_all_examples example
  2. Click "All"
  3. Change any of the buffers being rendered by clicking on the D/C buttons
  4. Wait ~1 second

Result (This one happens after pressing the 05_position button in the deferred example):

$ ../../../../build/vuk_all_examples 
[WARNING: General](user defined)
terminator_CreateInstance: Failed to CreateInstance in ICD 1.  Skipping ICD.
[WARNING: Performance](user defined)
Validation Performance Warning: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x5625759b1f40, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | vkCmdBlitImage: For optimal performance VkImage 0x5ef3070000000063[] layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.
[WARNING: Performance](user defined)
Validation Performance Warning: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x562576106730, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | vkCmdBlitImage: For optimal performance VkImage 0x33f7660000000075[] layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.
[ERROR: Validation](user defined)
Validation Error: [ UNASSIGNED-CoreValidation-DrawState-DescriptorSetNotBound ] Object 0: handle = 0x562575b6c940, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xcde11083 | vkCmdDispatch(): VkPipeline 0x4e6ce70000004c37[Pipeline:stupidsort.comp] uses set #4 but that set is not bound.
/usr/include/c++/11.2.0/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = LAST_BOUND_STATE::PER_SET; _Alloc = std::allocator<LAST_BOUND_STATE::PER_SET>; std::vector<_Tp, _Alloc>::reference = LAST_BOUND_STATE::PER_SET&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted (core dumped)

Happens on my Linux Manjaro system using an AMD card.

Building examples failed : error C2039: 'add_glsl': is not a member of 'vuk::PipelineBaseCreateInfo'

D:\workspace\graphics_dev\vuk\examples\build>cmake --build .
[41/148] Building CXX object CMakeFiles\vuk_all_examples.dir\01_triangle.cpp.obj
FAILED: CMakeFiles/vuk_all_examples.dir/01_triangle.cpp.obj
"D:\Program_Filesx86\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe"  /nologo /TP -DGLM_ENABLE_EXPERIMENTAL -DGLM_FORCE_DEPTH_ZERO_TO_ONE -DGLM_FORCE_EXPLICIT_CTOR -DGLM_FORCE_RADIANS -DGLM_FORCE_SIZE_FUNC -ID:\workspace\graphics_dev\vuk\examples\build\_deps\vk-bootstrap-src\src -ID:\SDKs\VulkanSDK\1.3.204.0\Include -ID:\workspace\graphics_dev\vuk\examples\build\_deps\glfw-src\include -ID:\workspace\graphics_dev\vuk\examples\build\_deps\glm-src\glm\.. -ID:\workspace\graphics_dev\vuk\examples\..\ext\stb -ID:\workspace\graphics_dev\vuk\examples\..\ext\imgui -ID:\workspace\graphics_dev\vuk\examples\..\ext\plf_colony -ID:\workspace\graphics_dev\vuk\examples\..\include /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /std:c++latest /permissive- /Zc:char8_t- /showIncludes /FoCMakeFiles\vuk_all_examples.dir\01_triangle.cpp.obj /FdCMakeFiles\vuk_all_examples.dir\ /FS -c D:\workspace\graphics_dev\vuk\examples\01_triangle.cpp
D:\workspace\graphics_dev\vuk\examples\build\_deps\vk-bootstrap-src\src\VkBootstrap.h(1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
D:\workspace\graphics_dev\vuk\examples\01_triangle.cpp(21): error C2039: 'add_glsl': is not a member of 'vuk::PipelineBaseCreateInfo'
D:\workspace\graphics_dev\vuk\include\vuk\Pipeline.hpp(62): note: see declaration of 'vuk::PipelineBaseCreateInfo'
D:\workspace\graphics_dev\vuk\examples\01_triangle.cpp(22): error C2039: 'add_glsl': is not a member of 'vuk::PipelineBaseCreateInfo'
D:\workspace\graphics_dev\vuk\include\vuk\Pipeline.hpp(62): note: see declaration of 'vuk::PipelineBaseCreateInfo'
[42/148] Building CXX object CMakeFiles\vuk_example_01_triangle.dir\01_triangle.cpp.obj

Adding structs to VkRenderPassCreateInfo::pNext

Hello, I'm currently using this library to help with the vulkan work in a OpenXR renderer, I'd like to be able to use this vulkan extension, but requires that I pass extra info into the VkRenderPassCreateInfo::pNext. Is this possible with vuk, right now?

vuk-side validation tracking issue

  • descriptor binding
  • push constants
  • persistent descriptors
  • attaching to resources
  • attachment size inference
  • attachment sample count inference

Conditionally disable buffer-device-address

Adreno devices do not support VkPhysicalDeviceBufferDeviceAddressFeaturesKHR.bufferDeviceAddressCaptureReplay. If we could conditionally disable BDA, we could use RenderDoc to debug code running on Adreno devices

Relates to #65

[Feature] Disable Descriptor Binding Validation

I am currently trying to use vuk in conjunction with the VK_EXT_descriptor_buffer. Currently, I have shader code that resembles this:

layout (set = 0, binding = 0) buffer model_payload_buffer
{
    model_payload models[OBJECT_COUNT];
};

layout (set = 0, binding = 1) uniform scene_payload_buffer
{
    mat4 projection;
    mat4 view;
};

layout (set = 0, binding = 2) uniform texture2D texture_buffer[IMAGE_COUNT];
layout (set = 0, binding = 3) uniform sampler sampler_buffer[SAMPLER_COUNT];

When I go to draw with vuk, it tries to validate descriptor bindings and fails. I would like to have a mechanism to:

  1. Turn off descriptor binding for the command buffer
  2. Turn off descriptor binding validation for the command buffer
  3. Add descriptor strategy for user-defined descriptor buffer (discussed in discord)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.