All Projects → tuxalin → Commandbuffer

tuxalin / Commandbuffer

A lock-free CommandBuffer implementation designed for multi-threaded rendering applications.

Programming Languages

c
50402 projects - #5 most used programming language
cpp11
221 projects

Projects that are alternatives of or similar to Commandbuffer

3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+7647.02%)
Mutual labels:  opengl, vulkan, graphics-programming
Xrtl
Cross-platform Real-Time Rendering Library
Stars: ✭ 108 (-28.48%)
Mutual labels:  opengl, vulkan, graphics-programming
Diligentengine
A modern cross-platform low-level graphics library and rendering framework
Stars: ✭ 2,142 (+1318.54%)
Mutual labels:  opengl, vulkan, graphics-programming
Renderdoc
RenderDoc is a stand-alone graphics debugging tool.
Stars: ✭ 5,969 (+3852.98%)
Mutual labels:  opengl, vulkan, graphics-programming
Diligentsamples
Sample projects demonstrating the usage of Diligent Engine
Stars: ✭ 138 (-8.61%)
Mutual labels:  opengl, vulkan, graphics-programming
Gl vk threaded cadscene
OpenGL and Vulkan comparison on rendering a CAD scene using various techniques
Stars: ✭ 143 (-5.3%)
Mutual labels:  opengl, vulkan
Fna3d
FNA3D - 3D Graphics Library for FNA
Stars: ✭ 111 (-26.49%)
Mutual labels:  opengl, vulkan
Duckstation
Fast PlayStation 1 emulator for x86-64/AArch32/AArch64
Stars: ✭ 2,888 (+1812.58%)
Mutual labels:  opengl, vulkan
Serpent
Cross-platform gaming kit in the D programming language
Stars: ✭ 140 (-7.28%)
Mutual labels:  opengl, vulkan
Nova Rs
Nova Renderer, but in Rust
Stars: ✭ 98 (-35.1%)
Mutual labels:  vulkan, graphics-programming
Veldrid
A low-level, portable graphics library for .NET.
Stars: ✭ 1,784 (+1081.46%)
Mutual labels:  opengl, vulkan
Innocenceengine
Cross-platform modern game engine.
Stars: ✭ 149 (-1.32%)
Mutual labels:  opengl, vulkan
Vulkan Samples
One stop solution for all Vulkan samples
Stars: ✭ 2,009 (+1230.46%)
Mutual labels:  vulkan, graphics-programming
Crossshader
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
Stars: ✭ 113 (-25.17%)
Mutual labels:  opengl, vulkan
Vkgl
Core OpenGL over Vulkan
Stars: ✭ 105 (-30.46%)
Mutual labels:  opengl, vulkan
Herebedragons
A basic 3D scene implemented with various engines, frameworks or APIs.
Stars: ✭ 1,616 (+970.2%)
Mutual labels:  opengl, graphics-programming
Gpu Viewer
A front-end to glxinfo, vulkaninfo, clinfo and es2_info - Linux
Stars: ✭ 129 (-14.57%)
Mutual labels:  opengl, vulkan
Gl vk meshlet cadscene
This OpenGL/Vulkan sample illustrates the use of "mesh shaders" for rendering CAD models.
Stars: ✭ 127 (-15.89%)
Mutual labels:  opengl, vulkan
Vulkantutorial
Tutorial for the Vulkan graphics and compute API
Stars: ✭ 1,962 (+1199.34%)
Mutual labels:  vulkan, graphics-programming
Bgfx
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
Stars: ✭ 10,252 (+6689.4%)
Mutual labels:  opengl, vulkan

Lock-free CommandBuffer

Windows status Language License

A lock-free CommandBuffer implementation designed for multi-threaded rendering applications. Useful to reduce state switches(i.e. materials, shaders), depth sorting(for transparency or hardware early-z rejection) and also for dispatching commands from multiple threads.

Features

  • lock-free, designed for high-congestion
  • graphics API agnostic(see cb::RenderContext)
  • fast and configurable allocation via a linear allocator
  • optional material binder with multiple material passes support
  • chainable/appendable commands
  • configurable key type for sorting of commands(opaque, transparent, depth sorting)
  • easy to use and configurable draw key via bitfields
  • debug utilities, tag commands
  • basic GL commands implementation(see GLCommands.h)
  • lightweight, header only

Installation

The implementation is header only, except GL commands, requires at least C++11 support.

Usage

Creating a command:

    struct DrawArrays {
        static const cb::RenderContext::function_t kDispatchFunction;
        GLuint          vao;
        uint32_t        base;
        uint32_t        count;
        GLenum          primitive;
    };
    //in cpp
    void drawArrays(const void* data, cb::RenderContext*) {
        auto& cmd = *reinterpret_cast<const DrawGroundCommand*>(data);
        glBindVertexArray(cmd.vao);
        glDrawArrays(cmd.primitive, cmd.base, cmd.count);
    }
    const cb::RenderContext::function_t DrawArrays::kDispatchFunction = &drawArrays;

Dispatching a command:

    //create the command key first
    cb::DrawKey key(0);
    key.setViewLayer(cb::ViewLayerType::e3D, cb::TranslucencyType::eOpaque);
    key.setDepth(depth);
    key.setMaterial(materialId);
    
    //then create command which will dispatch it
    cmds::DrawArrays& cmd = *commandBuffer.addCommand<cmds::DrawArrays>(key);
    cmd.vao = vaoId;
    cmd.base = 0;
    cmd.count = 4;
    cmd.primitive = GL_TRIANGLE_STRIP;

Tagging a command for debug purposes, use CB_DEBUG_TAG_COMMANDS in config.h to enable/disable tagging:

void testFunction() {
    cb::DrawKey key = cb::DrawKey::makeDefault(viewportId, cb::ViewLayerType::e3D);
    cmds::DrawArrays& cmd = *commandBuffer.addCommand<cmds::DrawArrays>(key);
    ...
    // will name tag: 'testFunction : <cpp_line_number> : struct cmds::DrawArrays * __ptr64'
    CB_DEBUG_COMMAND_TAG(cmd);
    // will name tag: 'testFunction : <cpp_line_number> : struct cmds::DrawArrays * __ptr64 : draw quad'
    CB_DEBUG_COMMAND_TAG_MSG(cmd, "draw quad");
    // will name tag: 'draw quad'
    CB_DEBUG_COMMAND_SET_MSG(cmd, "draw quad");
}

NOTE. Can enable/disable logging of the commands via CB_DEBUG_COMMANDS_PRINT in config.h which is enabled by default.

Appending/chaining commands(useful to reduce overhead of redundant material bindings):

    cb::DrawKey key = cb::DrawKey::makeDefault(viewportId, cb::ViewLayerType::e3D);
    //setup key
    cmds::DrawArrays* cmd = commandBuffer.addCommand<cmds::DrawArrays>(key);
    //fill command data
    CB_DEBUG_COMMAND_SET_MSG(cmd, "draw first quad");
    
    //append multiple draw calls
    for(int i = 1; i < 10; ++i) {
        cmd = commandBuffer.appendCommand<cmds::DrawArrays>(cmd);
        //fill command data
        CB_DEBUG_COMMAND_SET_MSG(cmd, FORMAT_STR("draw quad %d", i));
    ...

Sometimes you may want to share/reference a command so you don't copy it's data multiple times:

    //create the first the shared command
    CommandPacket* headerPacket = buffer.createCommandPacketData<cmds:SetMatrixCommand>(matrices);

    //reference/share the command
     key = cb::DrawKey::makeDefault(viewportId, cb::ViewLayerType::e3D);
    CommandPacket* cmd = buffer.addCommandFrom(key, headerPacket);
    //append a new command to the shared one
    cmds::DrawArrays* draw = buffer.appendCommand<cmds::DrawArrays>(cmd);
    //fill command data

    //reference it again
    key = cb::DrawKey::makeDefault(otherViewportId, cb::ViewLayerType::e3D);
    cmd = buffer.addCommandFrom(key, headerPacket);
    draw = buffer.appendCommand<cmds::DrawArrays>(cmd);
    //fill command data
    ...

NOTE. Since matrices are PODs you can use data copy commands which will automatically allocate auxiliary memory and copy it.

Example

Check the example folder which shows how to use the CommandBuffer in a real use case scenario with more advanced usage, it was done by adapting NVIDIA's Gameworks GL Threading example to a deferred renderer.

Contributing

The implementation is mainly based on Stefan Reinalter's blog post at Molecular Matters, about a 'Stateless, layered, multi-threaded rendering' which I highly recommend reading.

References:

Bug reports and pull requests are welcome on GitHub at https://github.com/tuxalin/CommandBuffer.

License

The code is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].