Git Product home page Git Product logo

rvk's Introduction

rvk

Windows Ubuntu

Low-level rpp-based Vulkan 1.3 abstraction layer.

rvk does not seek to redefine the Vulkan API, nor expose all of its configurability. Instead, rvk provides a convenient interface for modern desktop GPUs. It includes the following features:

  • RAII wrappers for Vulkan objects
  • GPU heap allocators (host and device)
  • Multiple frames in flight and resource deletion queue
  • Awaitable GPU tasks for coroutines
  • Multithreaded command pool management for graphics, compute, and transfer queues
  • Swapchain management and compositor
  • Validation config and debug messaging
  • Compile-time descriptor set layout specifications
  • Shader hot reloading
  • Dear ImGui integration
  • NVIDIA Aftermath integration (optional)

rvk assumes your application uses dynamic rendering and bindless/BDA pipelines. It explicitly lacks the following features:

  • Fine-grained resource management: the user wrangles scene data by sub-allocating buffers and/or using BDA.
  • Shader source management: the user controls compilation to SPIR-V.
  • Windowing: the user creates a window, chooses a swapchain extension, and tracks input.
  • Scene graph / dependency tracking / barrier insertion
  • Pipeline caching

The minimal API of rvk may be found in rvk.h.

Integration

To use rvk in your project, run the following commands (or manually download the source):

git submodule add https://github.com/TheNumbat/rvk
git submodule update --init --recursive

Then add the following lines to your CMakeLists.txt:

add_subdirectory(rvk)
target_link_libraries($your_target PRIVATE rvk)
target_include_directories($your_target PRIVATE ${RVK_INCLUDE_DIRS})

If you're already using rpp, also set the following option:

set(RVK_HAS_RPP TRUE)

To enable NVIDIA Aftermath, set the following option:

set(RVK_NV_AFTERMATH TRUE)

Examples

Main Loop

#include <rpp/base.h>
#include <rvk/rvk.h>

using namespace rpp;

i32 main() {

    // Use your platform abstraction layer to create a window...

    // Initialize your imgui platform backend...

    Vec<String_View> swapchain_extensions = /* Find platform swapchain extensions */;

    rvk::startup(rvk::Config{
        .imgui = true,
        .swapchain_extensions = swapchain_extensions.slice(),
        .create_surface =
            [](VkInstance instance) {
                return /* Create platform surface */;
            },
    });

    {
        rvk::Drop<rvk::Image> target{move(*rvk::make_image({1280, 720, 1}, VK_FORMAT_R8G8B8A8_UNORM,
                                                            VK_IMAGE_USAGE_SAMPLED_BIT))};
        rvk::sync([&](rvk::Commands& cmds) {
            target->setup(cmds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
        });

        rvk::Drop<rvk::Image_View> target_view{target->view(VK_IMAGE_ASPECT_COLOR_BIT)};

        while(/* User hasn't quit */) {
            rvk::begin_frame();

            // Do your rendering...

            rvk::end_frame(target_view):
        }
    }

    rvk::shutdown();
}

Pipelines

#include <rpp/base.h>
#include <rvk/rvk.h>

using namespace rpp;

i32 main() {

    rvk::Shader_Loader loader = rvk::make_shader_loader();

    auto vertex = loader.compile("shader.vert.spv"_v);
    auto fragment = loader.compile("shader.frag.spv"_v);

    loader.on_reload(Slice{{vertex, fragment}}, [&](Shader_Loader&) {
        // Recreate your pipeline...
    });

    using Layout = List<rvk::Bind::Buffer_Storage<VK_SHADER_STAGE_VERTEX_BIT>,
                        rvk::Bind::Image_And_Sampler<VK_SHADER_STAGE_FRAGMENT_BIT>>;

    auto descriptor_set_layout = rvk::make_layout<Layout>();
    auto descriptor_set = rvk::make_set(descriptor_set_layout);

    VkGraphicsPipelineCreateInfo graphics = /* ... */;

    rvk::Pipeline pipeline = rvk::make_pipeline(rvk::Pipeline::Info{
        .push_constants = Slice{rvk::Push<VK_SHADER_STAGE_VERTEX_BIT, u64>::range},
        .descriptor_set_layouts = Slice{&descriptor_set_layout, 1},
        .info = graphics
    });
}

Build

To build rvk on its own, run the following commands:

Windows

Assure MSVC 19.37 and cmake 3.17 (or newer) are installed and in your PATH.

mkdir build
cd build
cmake ..
cmake --build .

For faster parallel builds, you can instead generate ninja build files with cmake -G Ninja ...

Linux

Assure clang-17 and cmake 3.17 (or newer) are installed.

mkdir build
cd build
CXX=clang++-17 cmake ..
make -j

For faster parallel builds, you can instead generate ninja build files with cmake -G Ninja ...

rvk's People

Contributors

thenumbat avatar

Stargazers

Hòa (Vladimir Scarlet) avatar Joshua Rowe avatar pknowles avatar  avatar Carolina Cuadra Pardo avatar Rafael Henrique Capati avatar Tim Gfrerer avatar Fabio Galuppo avatar rtj avatar Xu Cheng avatar Snowapril avatar Tim Arterbury avatar Lukas Hermann avatar Maximilian Olschewski avatar Larson T. avatar Dimitri Diakopoulos avatar Trevor Hedstrom avatar Tzu-Mao Li avatar bperris avatar Fan Pu Zeng avatar  avatar

Watchers

 avatar Rafael Henrique Capati avatar

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.