LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

Indirect draw/dispatch commands #12

Closed LukasBanana closed 5 years ago

LukasBanana commented 6 years ago

Indirect draw and dispatch commands as well as their respective buffer types should be added.

Concept:

enum class BufferType {
    Vertex,
    Index,
    Constant,
    Storage,
    StreamOutput,
    DrawIndirect,     // New buffer type for indirect draw commands
    DispatchIndirect, // New buffer type for indirect dispatch commands
};

For the case the rendering APIs have slightly different buffer formats for these commands, individual structures for each backend must be provided. Otherwise, a uniform structure can be used:

struct DrawIndirectFormat {
    std::uint32_t numVertices;
    std::uint32_t numInstances;
    std::uint32_t firstVertex;
    std::uint32_t firstInstance;
};
struct DrawIndexedIndirectFormat {
    std::uint32_t numIndices;
    std::uint32_t numInstances;
    std::uint32_t firstIndex;
    std::int32_t  vertexOffset;
    std::uint32_t firstInstance;
};
struct DispatchIndirectFormat {
    std::uint32_t groupSizeX;
    std::uint32_t groupSizeY;
    std::uint32_t groupSizeZ;
};

The functions in the CommandBuffer interface may look like this:

void DrawIndirect(Buffer& buffer, std::uint64_t offset);
void DrawIndexedIndirect(Buffer& buffer, std::uint64_t offset);
void DispatchIndirect(Buffer& buffer, std::uint64_t offset);

The parameter buffer specifies a buffer that contains the draw/dispatch command arguments and the parameter offset specifies an aligned byte offset within the buffer for command arguments.

Progress overview:

LukasBanana commented 5 years ago

Done with 87795a3. Buffer types are not changed, though. Instead, the BufferFlags::IndirectArgumentBinding flag has been added.