Skip to content

Latest commit

 

History

History
138 lines (99 loc) · 5.48 KB

README.md

File metadata and controls

138 lines (99 loc) · 5.48 KB

KDGpu

KDGpu is a thin wrapper around Vulkan to make modern graphics easier to learn and use.

Introduction

Is KDGpu for me?

Have you ever wanted to be productive with Vulkan but can't get your head around the verbose syntax, managing object lifetimes, and the intricacies of just getting something working without drowning in synchronization and memory handling?

If the answer is yes, then KDGpu is the library for you!

KDGpu is a thin wrapper around Vulkan (and perhaps later other modern graphics APIs) with the aim of making modern graphics available to mortals and to massively reduce the amount of verbosity involved.

KDGpu also aims to make it easy to teach the concepts of modern graphics programming without having to be bogged down in the intricacies.

KDGpu is independent of any particular windowing system. You can use it purely with platform native APIs or you can checkout the included KDGpuExample library which makes it trivial to use KDGpu with KDGui::Window. Check out the handy KDBindings repository too for some more syntactic sugar.

In addition to being an enabler for Vulkan, the KDGpu project now also includes a new library, KDXr, which aims to be an enabler for OpenXR. Using the combination of KDGpu and KDXr allows application developers to very easily create AR and VR application experiences.

More information can be found in the documentation.

What does KDGpu provide?

  • The KDGpu library
  • The KDXr library to make OpenXR easier to use
  • An example framework called KDGpuExample that provides integration with KDGui to make it easy to experiment. Let us take care of the boring bits so you can make pretty pictures.
  • A set of illustrative examples showing how to use KDGpu for common rendering tasks.

How do I get up and running with KDGpu?

  • Install the Vulkan SDK, setup the runtime environment and verify the SDK as described in the Vulkan documentation
  • Clone this repository
  • Open up the directory in VS Code with the CMakeTools extension loaded
  • Configure and Build - all of the dependencies will be pulled down via CMake's FetchContent feature (see cmake/dependencies.cmake)
  • Try running the examples

What does KDGpu code look like?

A typical render function for KDGPu looks something like this:

auto opaquePass = commandRecorder.beginRenderPass(m_opaquePassOptions);
opaquePass.setPipeline(m_pipeline);
opaquePass.setVertexBuffer(0, m_buffer);
opaquePass.setBindGroup(0, m_textureBindGroup);
opaquePass.draw(DrawCommand{ .vertexCount = 4 });
renderImGuiOverlay(&opaquePass);
opaquePass.end();
m_commandBuffer = commandRecorder.finish();

Creating GPU resources is just as easy and intuitive. Creating a Buffer that resides on the GPU and can be uploaded to and used as a vertex buffer is as simple as:

const DeviceSize dataByteSize = vertexData.size() * sizeof(Vertex);
BufferOptions bufferOptions = {
    .size = dataByteSize,
    .usage = BufferUsageFlagBits::VertexBufferBit | BufferUsageFlagBits::TransferDstBit,
    .memoryUsage = MemoryUsage::GpuOnly
};
m_buffer = m_device.createBuffer(bufferOptions);

This pattern of using options structs and initializing them with C++20 designated initializers permeates through the API. It makes it easily discoverable, extensible and trivial to queue up for deferred invocations.

Uploading data to the above buffer is just as easy:

const BufferUploadOptions uploadOptions = {
    .destinationBuffer = m_buffer,
    .dstStages = PipelineStageFlagBit::VertexAttributeInputBit,
    .dstMask = AccessFlagBit::VertexAttributeReadBit,
    .data = vertexData.data(),
    .byteSize = dataByteSize
};
m_queue.uploadBufferData(uploadOptions);

Contact

Stay up-to-date with KDAB product announcements:

Licensing

KDGpu is © Klarälvdalens Datakonsult AB and is available under the terms of the MIT license.

Contact KDAB at [email protected] if you need different licensing options.

KDGpu includes these source files, also available under the terms of the MIT license:

doctest.h - the lightest feature-rich C++ single-header testing framework for unit tests and TDD (C) 2016-2021 Viktor Kirilov [email protected]

Get Involved

Please submit your contributions or issue reports from our GitHub space at https://github.com/KDAB/KDGpu.

Contact [email protected] for more information.

About KDAB

KDGpu is supported and maintained by Klarälvdalens Datakonsult AB (KDAB).

The KDAB Group is the global No.1 software consultancy for Qt, C++ and OpenGL applications across desktop, embedded and mobile platforms.

The KDAB Group provides consulting and mentoring for developing Qt applications from scratch and in porting from all popular and legacy frameworks to Qt. We continue to help develop parts of Qt and are one of the major contributors to the Qt Project. We can give advanced or standard trainings anywhere around the globe on Qt as well as C++, OpenGL, 3D and more.

Please visit https://www.kdab.com to meet the people who write code like this.