Skip to content
Snippets Groups Projects
Commit 2ae7174c authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch '123-refactor-core-api' into 'develop'

Resolve "Refactor Core API"

Closes #123

See merge request !105
parents bb406e71 3157121f
No related branches found
No related tags found
1 merge request!105Resolve "Refactor Core API"
Showing
with 981 additions and 648 deletions
......@@ -874,8 +874,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
INPUT = src \
include \
INPUT = include \
modules
# This tag can be used to specify the character encoding of the source files
......
......@@ -15,23 +15,31 @@ set(vkcv_sources
${vkcv_include}/vkcv/File.hpp
${vkcv_source}/vkcv/File.cpp
${vkcv_include}/vkcv/Pass.hpp
${vkcv_source}/vkcv/Pass.cpp
${vkcv_include}/vkcv/PassConfig.hpp
${vkcv_source}/vkcv/PassConfig.cpp
${vkcv_source}/vkcv/PassManager.hpp
${vkcv_source}/vkcv/PassManager.cpp
${vkcv_include}/vkcv/Handles.hpp
${vkcv_source}/vkcv/Handles.cpp
${vkcv_source}/vkcv/HandleManager.hpp
${vkcv_include}/vkcv/Window.hpp
${vkcv_source}/vkcv/Window.cpp
${vkcv_include}/vkcv/BufferTypes.hpp
${vkcv_include}/vkcv/Buffer.hpp
${vkcv_include}/vkcv/PushConstants.hpp
${vkcv_source}/vkcv/PushConstants.cpp
${vkcv_include}/vkcv/BufferManager.hpp
${vkcv_source}/vkcv/BufferManager.hpp
${vkcv_source}/vkcv/BufferManager.cpp
${vkcv_include}/vkcv/Image.hpp
......@@ -40,13 +48,10 @@ set(vkcv_sources
${vkcv_source}/vkcv/ImageManager.hpp
${vkcv_source}/vkcv/ImageManager.cpp
${vkcv_include}/vkcv/Logger.hpp
${vkcv_include}/vkcv/PipelineConfig.hpp
${vkcv_source}/vkcv/PipelineConfig.cpp
${vkcv_include}/vkcv/Surface.hpp
${vkcv_source}/vkcv/Surface.cpp
${vkcv_include}/vkcv/Swapchain.hpp
${vkcv_source}/vkcv/Swapchain.cpp
${vkcv_include}/vkcv/Logger.hpp
${vkcv_include}/vkcv/ShaderStage.hpp
......@@ -54,6 +59,8 @@ set(vkcv_sources
${vkcv_source}/vkcv/ShaderProgram.cpp
${vkcv_include}/vkcv/GraphicsPipelineConfig.hpp
${vkcv_source}/vkcv/GraphicsPipelineConfig.cpp
${vkcv_include}/vkcv/ComputePipelineConfig.hpp
${vkcv_source}/vkcv/ComputePipelineManager.hpp
......@@ -61,30 +68,35 @@ set(vkcv_sources
${vkcv_source}/vkcv/GraphicsPipelineManager.hpp
${vkcv_source}/vkcv/GraphicsPipelineManager.cpp
${vkcv_include}/vkcv/CommandResources.hpp
${vkcv_source}/vkcv/CommandResources.cpp
${vkcv_include}/vkcv/SyncResources.hpp
${vkcv_source}/vkcv/SyncResources.cpp
${vkcv_include}/vkcv/QueueManager.hpp
${vkcv_source}/vkcv/QueueManager.cpp
${vkcv_include}/vkcv/VertexLayout.hpp
${vkcv_source}/vkcv/VertexLayout.cpp
${vkcv_include}/vkcv/DispatchSize.hpp
${vkcv_source}/vkcv/DispatchSize.cpp
${vkcv_include}/vkcv/Event.hpp
${vkcv_include}/vkcv/TypeGuard.hpp
${vkcv_source}/vkcv/TypeGuard.cpp
${vkcv_include}/vkcv/DescriptorTypes.hpp
${vkcv_source}/vkcv/DescriptorManager.hpp
${vkcv_source}/vkcv/DescriptorManager.cpp
${vkcv_include}/vkcv/DescriptorConfig.hpp
${vkcv_source}/vkcv/DescriptorConfig.cpp
${vkcv_include}/vkcv/DescriptorBinding.hpp
${vkcv_source}/vkcv/DescriptorBinding.cpp
${vkcv_include}/vkcv/DescriptorWrites.hpp
${vkcv_source}/vkcv/DescriptorWrites.cpp
${vkcv_source}/vkcv/DescriptorSetLayoutManager.hpp
${vkcv_source}/vkcv/DescriptorSetLayoutManager.cpp
${vkcv_source}/vkcv/DescriptorSetManager.hpp
${vkcv_source}/vkcv/DescriptorSetManager.cpp
${vkcv_source}/vkcv/SamplerManager.hpp
${vkcv_source}/vkcv/SamplerManager.cpp
......@@ -94,18 +106,13 @@ set(vkcv_sources
${vkcv_source}/vkcv/SwapchainManager.hpp
${vkcv_source}/vkcv/SwapchainManager.cpp
${vkcv_include}/vkcv/DescriptorWrites.hpp
${vkcv_include}/vkcv/DrawcallRecording.hpp
${vkcv_source}/vkcv/DrawcallRecording.cpp
${vkcv_source}/vkcv/CommandStreamManager.hpp
${vkcv_source}/vkcv/CommandStreamManager.cpp
${vkcv_include}/vkcv/CommandRecordingFunctionTypes.hpp
${vkcv_include}/vkcv/EventFunctionTypes.hpp
${vkcv_include}/vkcv/ImageConfig.hpp
${vkcv_source}/vkcv/ImageConfig.cpp
${vkcv_include}/vkcv/Multisampling.hpp
${vkcv_source}/vkcv/Multisampling.cpp
${vkcv_include}/vkcv/Downsampler.hpp
${vkcv_source}/vkcv/Downsampler.cpp
......@@ -113,7 +120,19 @@ set(vkcv_sources
${vkcv_include}/vkcv/BlitDownsampler.hpp
${vkcv_source}/vkcv/BlitDownsampler.cpp
${vkcv_include}/vkcv/SamplerTypes.hpp
${vkcv_include}/vkcv/Sampler.hpp
${vkcv_source}/vkcv/Sampler.cpp
${vkcv_include}/vkcv/DescriptorSetUsage.hpp
${vkcv_source}/vkcv/DescriptorSetUsage.cpp
${vkcv_include}/vkcv/Drawcall.hpp
${vkcv_source}/vkcv/Drawcall.cpp
${vkcv_include}/vkcv/VertexData.hpp
${vkcv_source}/vkcv/VertexData.cpp
${vkcv_include}/vkcv/Result.hpp
)
......
......@@ -7,8 +7,9 @@
#include <vector>
#include "BufferTypes.hpp"
#include "Core.hpp"
#include "Handles.hpp"
#include "BufferManager.hpp"
namespace vkcv {
......@@ -19,10 +20,18 @@ namespace vkcv {
*/
template<typename T>
class Buffer {
friend class Core;
public:
// explicit destruction of default constructor
Buffer() = delete;
Buffer() : m_core(nullptr), m_handle() {}
Buffer(Core* core, const BufferHandle& handle) : m_core(core), m_handle(handle) {}
Buffer(const Buffer& other) = default;
Buffer(Buffer&& other) noexcept = default;
~Buffer() = default;
Buffer& operator=(const Buffer& other) = default;
Buffer& operator=(Buffer&& other) noexcept = default;
/**
* @brief Returns the buffers handle.
......@@ -41,9 +50,14 @@ namespace vkcv {
*/
[[nodiscard]]
BufferType getType() const {
return m_type;
return m_core->getBufferType(m_handle);
};
[[nodiscard]]
BufferMemoryType getMemoryType() const {
return m_core->getBufferMemoryType(m_handle);
}
/**
* @brief Returns the count of elements in the buffer.
*
......@@ -51,7 +65,7 @@ namespace vkcv {
*/
[[nodiscard]]
size_t getCount() const {
return m_count;
return m_core->getBufferSize(m_handle) / sizeof(T);
}
/**
......@@ -61,7 +75,7 @@ namespace vkcv {
*/
[[nodiscard]]
size_t getSize() const {
return m_count * sizeof(T);
return m_core->getBufferSize(m_handle);
}
/**
......@@ -71,7 +85,7 @@ namespace vkcv {
*/
[[nodiscard]]
vk::Buffer getVulkanHandle() const {
return m_manager->getBuffer(m_handle);
return m_core->getBuffer(m_handle);
}
/**
......@@ -84,7 +98,7 @@ namespace vkcv {
void fill(const T* data,
size_t count = 0,
size_t offset = 0) {
m_manager->fillBuffer(m_handle, data, count * sizeof(T), offset * sizeof(T));
m_core->fillBuffer(m_handle, data, count * sizeof(T), offset * sizeof(T));
}
/**
......@@ -108,7 +122,7 @@ namespace vkcv {
void read(T* data,
size_t count = 0,
size_t offset = 0) {
m_manager->readBuffer(m_handle, data, count * sizeof(T), offset * sizeof(T));
m_core->readBuffer(m_handle, data, count * sizeof(T), offset * sizeof(T));
}
/**
......@@ -132,77 +146,29 @@ namespace vkcv {
[[nodiscard]]
T* map(size_t offset = 0,
size_t count = 0) {
return reinterpret_cast<T*>(m_manager->mapBuffer(m_handle, offset * sizeof(T), count * sizeof(T)));
return reinterpret_cast<T*>(m_core->mapBuffer(m_handle, offset * sizeof(T), count * sizeof(T)));
}
/**
* @brief Unmaps the #Buffer, invalidates the pointer obtained by map().
*/
void unmap() {
m_manager->unmapBuffer(m_handle);
m_core->unmapBuffer(m_handle);
}
private:
BufferManager* const m_manager;
const BufferHandle m_handle;
const BufferType m_type;
const size_t m_count;
const BufferMemoryType m_memoryType;
/**
* @brief Constructor of the buffer object.
*
* @param[in,out] manager Buffer manager
* @param[in] handle Buffer handle
* @param[in] type Type of buffer
* @param[in] count Count of elements
* @param[in] memoryType Type of memory
*/
Buffer(BufferManager* manager,
BufferHandle handle,
BufferType type,
size_t count,
BufferMemoryType memoryType) :
m_manager(manager),
m_handle(handle),
m_type(type),
m_count(count),
m_memoryType(memoryType)
{}
/**
* @brief Creates a buffer object of type T with
* a selected type, count of elements, memory type
* and support of indirect usage.
*
* @param[in,out] manager Buffer manager
* @param[in] type Buffer type
* @param[in] count Count of elements
* @param[in] memoryType Type of memory
* @param[in] supportIndirect Support indirect usage
* @return New buffer object
*/
[[nodiscard]]
static Buffer<T> create(BufferManager* manager,
BufferType type,
size_t count,
BufferMemoryType memoryType,
bool supportIndirect,
bool readable) {
return Buffer<T>(
manager,
manager->createBuffer(
type,
count * sizeof(T),
memoryType,
supportIndirect,
readable
),
type,
count,
memoryType
);
}
Core* m_core;
BufferHandle m_handle;
};
template<typename T>
Buffer<T> buffer(Core& core,
BufferType type,
size_t count,
BufferMemoryType memoryType = BufferMemoryType::DEVICE_LOCAL,
bool readable = false) {
return Buffer<T>(&core, core.createBuffer(type, typeGuard<T>(), count, memoryType, readable));
}
}
#pragma once
/**
* @authors Tobias Frisch
* @file vkcv/BufferTypes.hpp
* @brief Enum classes to specify attributes of buffers.
*/
namespace vkcv {
/**
* @brief Enum class to specify types of buffers.
*/
enum class BufferType {
INDEX,
VERTEX,
UNIFORM,
STORAGE,
STAGING,
INDIRECT,
UNKNOWN
};
/**
* @brief Enum class to specify types of buffer memory.
*/
enum class BufferMemoryType {
DEVICE_LOCAL,
HOST_VISIBLE,
UNKNOWN
};
}
#pragma once
/**
* @authors Alexander Gauggel, Tobias Frisch
* @file vkcv/CommandResources.hpp
* @brief Support functions to deal with command resources.
*/
#include <vulkan/vulkan.hpp>
#include <unordered_set>
#include "QueueManager.hpp"
namespace vkcv {
/**
* @brief Structure to store command pools for given queue families
* of a device.
*/
struct CommandResources {
std::vector<vk::CommandPool> cmdPoolPerQueueFamily;
};
/**
* @brief Generates a set of the family indices for all different kinds of
* queues a given queue manager provides.
*
* @param[in] queueManager Queue manager
* @return Set of queue family indices
*/
std::unordered_set<int> generateQueueFamilyIndexSet(const QueueManager &queueManager);
/**
* @brief Creates and returns a new command resources instance containing
* a vector of newly allocated command pools for each different queue family
* index in a given set.
*
* @param[in,out] device Vulkan device
* @param[in] familyIndexSet Set of queue family indices
* @return New command resources
*/
CommandResources createCommandResources(const vk::Device &device,
const std::unordered_set<int> &familyIndexSet);
/**
* @brief Destroys a command resources instance and deallocates its command
* pools. The command resources will be invalid to use afterwards.
*
* @param[in,out] device Vulkan device
* @param[in,out] resources Command resources
*/
void destroyCommandResources(const vk::Device &device,
const CommandResources &resources);
/**
* @brief Allocates and returns a new primary command buffer of a given
* command pool.
*
* @param[in,out] device Vulkan device
* @param[in,out] cmdPool Vulkan command pool
* @return New vulkan command buffer
*/
vk::CommandBuffer allocateCommandBuffer(const vk::Device &device,
const vk::CommandPool &cmdPool);
/**
* @brief Returns the matching command pool of given command resources for
* a specific queue.
*
* @param[in] queue Queue
* @param[in] cmdResources Command resources
* @return Command pool for a given queue
*/
vk::CommandPool chooseCmdPool(const Queue &queue,
const CommandResources &cmdResources);
/**
* @brief Returns a queue of a given type from a queue manager.
*
* @param[in] type Type of queue
* @param[in] queueManager Queue manager
* @return Queue of a given type
*/
Queue getQueueForSubmit(QueueType type,
const QueueManager &queueManager);
/**
* @brief Begins the usage of a command buffer with given command buffer
* usage flags.
*
* @param[in] cmdBuffer Vulkan command buffer
* @param[in] flags Command buffer usage flags
*/
void beginCommandBuffer(const vk::CommandBuffer &cmdBuffer,
vk::CommandBufferUsageFlags flags);
/**
* @brief Submits a command buffer into a queue with given fence and
* semaphores to wait for or to signal after processing the command
* buffer.
*
* @param[in,out] queue Vulkan queue
* @param[in] cmdBuffer Vulkan command buffer
* @param[in] fence Vulkan fence to wait for
* @param[in] waitSemaphores Vector of semaphores to wait for
* @param[in] signalSemaphores Vector of semaphores to signal
*/
void submitCommandBufferToQueue(vk::Queue queue,
const vk::CommandBuffer &cmdBuffer,
const vk::Fence &fence,
const std::vector<vk::Semaphore>& waitSemaphores,
const std::vector<vk::Semaphore>& signalSemaphores);
}
\ No newline at end of file
......@@ -5,19 +5,15 @@
* @brief Compute pipeline config struct to hand over required information to pipeline creation.
*/
#include <vector>
#include "Handles.hpp"
#include "ShaderProgram.hpp"
#include "PipelineConfig.hpp"
namespace vkcv {
/**
* @brief Structure to configure a compute pipeline before its creation.
* @brief Class to configure a compute pipeline before its creation.
*/
struct ComputePipelineConfig {
ShaderProgram& m_ShaderProgram;
std::vector<DescriptorSetLayoutHandle> m_DescriptorSetLayouts;
};
class ComputePipelineConfig : public PipelineConfig {
using PipelineConfig::PipelineConfig;
};
}
\ No newline at end of file
......@@ -8,8 +8,8 @@
#include <vulkan/vulkan.hpp>
#include <vk_mem_alloc.hpp>
#include "Handles.hpp"
#include "QueueManager.hpp"
#include "DrawcallRecording.hpp"
#include "Features.hpp"
namespace vkcv
......
This diff is collapsed.
#pragma once
/**
* @authors Artur Wasmut, Tobias Frisch, Simeon Hermann, Alexander Gauggel, Vanessa Karolek
* @file vkcv/DescriptorConfig.hpp
* @brief Structures to handle descriptor bindings.
*/
#include <unordered_map>
#include "DescriptorTypes.hpp"
#include "ShaderStage.hpp"
namespace vkcv {
/**
* @brief Structure to store details from a descriptor binding.
*/
struct DescriptorBinding {
uint32_t bindingID;
DescriptorType descriptorType;
uint32_t descriptorCount;
ShaderStages shaderStages;
bool variableCount;
bool partialBinding;
bool operator ==(const DescriptorBinding &other) const;
};
typedef std::unordered_map<uint32_t, DescriptorBinding> DescriptorBindings;
}
#pragma once
/**
* @authors Artur Wasmut, Tobias Frisch, Simeon Hermann, Alexander Gauggel, Vanessa Karolek
* @file vkcv/DescriptorConfig.hpp
* @brief Structures to handle descriptor types and bindings.
*/
#include <unordered_map>
#include "Handles.hpp"
#include "ShaderStage.hpp"
#include "Logger.hpp"
namespace vkcv
{
/**
* @brief Enum class to specify the type of a descriptor set binding.
*/
enum class DescriptorType {
UNIFORM_BUFFER,
STORAGE_BUFFER,
SAMPLER,
IMAGE_SAMPLED,
IMAGE_STORAGE,
UNIFORM_BUFFER_DYNAMIC,
STORAGE_BUFFER_DYNAMIC,
ACCELERATION_STRUCTURE_KHR
};
/**
* @brief Converts the descriptor type from the frameworks enumeration
* to the Vulkan type specifier.
*
* @param[in] type Descriptor type
* @return Vulkan descriptor type
*/
constexpr vk::DescriptorType getVkDescriptorType(DescriptorType type) noexcept {
switch (type)
{
case DescriptorType::UNIFORM_BUFFER:
return vk::DescriptorType::eUniformBuffer;
case DescriptorType::UNIFORM_BUFFER_DYNAMIC:
return vk::DescriptorType::eUniformBufferDynamic;
case DescriptorType::STORAGE_BUFFER:
return vk::DescriptorType::eStorageBuffer;
case DescriptorType::STORAGE_BUFFER_DYNAMIC:
return vk::DescriptorType::eStorageBufferDynamic;
case DescriptorType::SAMPLER:
return vk::DescriptorType::eSampler;
case DescriptorType::IMAGE_SAMPLED:
return vk::DescriptorType::eSampledImage;
case DescriptorType::IMAGE_STORAGE:
return vk::DescriptorType::eStorageImage;
case DescriptorType::ACCELERATION_STRUCTURE_KHR:
return vk::DescriptorType::eAccelerationStructureKHR;
default:
return vk::DescriptorType::eMutableVALVE;
}
}
/**
* @brief Structure to store details from a descriptor binding.
*/
struct DescriptorBinding {
uint32_t bindingID;
DescriptorType descriptorType;
uint32_t descriptorCount;
ShaderStages shaderStages;
bool variableCount;
bool partialBinding;
bool operator ==(const DescriptorBinding &other) const;
};
typedef std::unordered_map<uint32_t, DescriptorBinding> DescriptorBindings;
/**
* @brief Structure to store details about a descriptor set layout.
*/
struct DescriptorSetLayout {
vk::DescriptorSetLayout vulkanHandle;
DescriptorBindings descriptorBindings;
size_t layoutUsageCount;
};
/**
* @brief Structure to store details about a descriptor set.
*/
struct DescriptorSet {
vk::DescriptorSet vulkanHandle;
DescriptorSetLayoutHandle setLayoutHandle;
size_t poolIndex;
};
}
#pragma once
/**
* @authors Tobias Frisch
* @file vkcv/DescriptorUsage.hpp
* @brief Structures to handle descriptor usages.
*/
#include <vector>
#include "Handles.hpp"
namespace vkcv {
/**
* @brief Structure to configure a descriptor set usage.
*/
struct DescriptorSetUsage {
uint32_t location;
DescriptorSetHandle descriptorSet;
std::vector<uint32_t> dynamicOffsets;
};
DescriptorSetUsage useDescriptorSet(uint32_t location,
const DescriptorSetHandle &descriptorSet,
const std::vector<uint32_t> &dynamicOffsets = {});
}
#pragma once
/**
* @authors Artur Wasmut, Tobias Frisch, Simeon Hermann, Alexander Gauggel, Vanessa Karolek
* @file vkcv/DescriptorConfig.hpp
* @brief Enum classes to handle descriptor types.
*/
#include <vulkan/vulkan.hpp>
namespace vkcv {
/**
* @brief Enum class to specify the type of a descriptor set binding.
*/
enum class DescriptorType {
UNIFORM_BUFFER,
STORAGE_BUFFER,
SAMPLER,
IMAGE_SAMPLED,
IMAGE_STORAGE,
UNIFORM_BUFFER_DYNAMIC,
STORAGE_BUFFER_DYNAMIC,
ACCELERATION_STRUCTURE_KHR
};
/**
* @brief Converts the descriptor type from the frameworks enumeration
* to the Vulkan type specifier.
*
* @param[in] type Descriptor type
* @return Vulkan descriptor type
*/
constexpr vk::DescriptorType getVkDescriptorType(DescriptorType type) noexcept {
switch (type)
{
case DescriptorType::UNIFORM_BUFFER:
return vk::DescriptorType::eUniformBuffer;
case DescriptorType::UNIFORM_BUFFER_DYNAMIC:
return vk::DescriptorType::eUniformBufferDynamic;
case DescriptorType::STORAGE_BUFFER:
return vk::DescriptorType::eStorageBuffer;
case DescriptorType::STORAGE_BUFFER_DYNAMIC:
return vk::DescriptorType::eStorageBufferDynamic;
case DescriptorType::SAMPLER:
return vk::DescriptorType::eSampler;
case DescriptorType::IMAGE_SAMPLED:
return vk::DescriptorType::eSampledImage;
case DescriptorType::IMAGE_STORAGE:
return vk::DescriptorType::eStorageImage;
case DescriptorType::ACCELERATION_STRUCTURE_KHR:
return vk::DescriptorType::eAccelerationStructureKHR;
default:
return vk::DescriptorType::eMutableVALVE;
}
}
}
......@@ -6,6 +6,7 @@
*/
#include <vector>
#include <vulkan/vulkan.hpp>
#include "Handles.hpp"
......@@ -60,6 +61,7 @@ namespace vkcv {
*/
struct AccelerationDescriptorWrite {
uint32_t binding;
std::vector<vk::AccelerationStructureKHR> structures;
};
/**
......@@ -162,9 +164,11 @@ namespace vkcv {
* of a descriptor set.
*
* @param[in] binding Binding index
* @param[in] structures Acceleration structures
* @return Instance of descriptor writes
*/
DescriptorWrites& writeAcceleration(uint32_t binding);
DescriptorWrites& writeAcceleration(uint32_t binding,
const std::vector<vk::AccelerationStructureKHR> &structures);
/**
* @brief Returns the list of stored write entries for sampled images.
......
#pragma once
/**
* @authors Tobias Frisch
* @file vkcv/DispatchSize.hpp
* @brief Class to handle dispatch sizes.
*/
#include <array>
#include <vulkan/vulkan.hpp>
namespace vkcv {
/**
* @brief Class representing a dispatch size to invoke a compute pipeline with.
*/
class DispatchSize final {
private:
std::array<uint32_t, 3> m_Dispatch;
public:
/**
* Implicit constructor to convert an unsigned integer to a
* one dimensional dispatch size.
*
* @param[in] count Count of invocations
*/
DispatchSize(uint32_t count);
/**
* Explicit constructor to create a dispatch size with two or
* three dimensions setting each value specifically.
*
* @param[in] dimensionX Size of X dimension
* @param[in] dimentionY Size of Y dimension
* @param[in] dimensionZ Size of Z dimension (optional)
*/
DispatchSize(uint32_t dimensionX, uint32_t dimentionY, uint32_t dimensionZ = 1);
DispatchSize(const DispatchSize& other) = default;
DispatchSize(DispatchSize&& other) = default;
~DispatchSize() = default;
DispatchSize& operator=(const DispatchSize& other) = default;
DispatchSize& operator=(DispatchSize&& other) = default;
/**
* Returns the raw data of the dispatch size as readonly unsigned
* integer pointer.
*
* @return Pointer to data
*/
[[nodiscard]]
const uint32_t* data() const;
/**
* Returns the size value of the dispatch size by a given index.
*
* @param[in] index Size index
* @return Size value by index
*/
[[nodiscard]]
uint32_t operator[](size_t index) const;
/**
* Returns the value for the X dimension of the dispatch size.
*
* @return Size of X dimension
*/
[[nodiscard]]
uint32_t x() const;
/**
* Returns the value for the Y dimension of the dispatch size.
*
* @return Size of Y dimension
*/
[[nodiscard]]
uint32_t y() const;
/**
* Returns the value for the Z dimension of the dispatch size.
*
* @return Size of Z dimension
*/
[[nodiscard]]
uint32_t z() const;
/**
* Checks whether the dispatch size is valid for compute shader
* invocations and returns the result as boolean value.
*
* @return True if the dispatch size is valid, otherwise false.
*/
bool check() const;
};
/**
* Returns the proper dispatch size by dividing a global amount of invocations
* as three dimensional dispatch size into invocations of a fixed group size
* for the used work groups of the compute shader.
*
* This function will generate over fitted results to make sure all global
* invocations get computed. So make sure the used compute shader handles those
* additional invocations out of bounds from the original global invocations.
*
* @param[in] globalInvocations Size of planned global invocations
* @param[in] groupSize Size of work group in compute stage
* @return Dispatch size respecting the actual work group size
*/
[[nodiscard]]
DispatchSize dispatchInvocations(DispatchSize globalInvocations, DispatchSize groupSize);
}
#pragma once
/**
* @authors Tobias Frisch
* @file vkcv/Drawcall.hpp
* @brief Classes to define different drawcalls.
*/
#include <vector>
#include "DescriptorSetUsage.hpp"
#include "Handles.hpp"
#include "VertexData.hpp"
namespace vkcv {
/**
* @brief Base class to store details for a general drawcall.
*/
class Drawcall {
private:
std::vector<DescriptorSetUsage> m_usages;
public:
Drawcall() = default;
Drawcall(const Drawcall& other) = default;
Drawcall(Drawcall&& other) noexcept = default;
~Drawcall() = default;
Drawcall& operator=(const Drawcall& other) = default;
Drawcall& operator=(Drawcall&& other) noexcept = default;
[[nodiscard]]
const std::vector<DescriptorSetUsage>& getDescriptorSetUsages() const;
void useDescriptorSet(uint32_t location,
const DescriptorSetHandle &descriptorSet,
const std::vector<uint32_t> &dynamicOffsets = {});
};
/**
* @brief Class to store details for an instance drawcall.
*/
class InstanceDrawcall : public Drawcall {
private:
VertexData m_vertexData;
uint32_t m_instanceCount;
public:
explicit InstanceDrawcall(const VertexData& vertexData,
uint32_t instanceCount = 1);
[[nodiscard]]
const VertexData& getVertexData() const;
[[nodiscard]]
uint32_t getInstanceCount() const;
};
/**
* @brief Class to store details for an indirect drawcall.
*/
class IndirectDrawcall : public Drawcall {
private:
BufferHandle m_indirectDrawBuffer;
VertexData m_vertexData;
uint32_t m_drawCount;
public:
explicit IndirectDrawcall(const BufferHandle &indirectDrawBuffer,
const VertexData& vertexData,
uint32_t drawCount = 1);
[[nodiscard]]
BufferHandle getIndirectDrawBuffer() const;
[[nodiscard]]
const VertexData& getVertexData() const;
[[nodiscard]]
uint32_t getDrawCount() const;
};
/**
* @brief Class to store details for a task drawcall.
*/
class TaskDrawcall : public Drawcall {
private:
uint32_t m_taskCount;
public:
explicit TaskDrawcall(uint32_t taskCount = 1);
[[nodiscard]]
uint32_t getTaskCount() const;
};
}
#pragma once
/**
* @authors Sebastian Gaida, Alexander Gauggel, Artur Wasmut, Tobias Frisch
* @file vkcv/DrawcallRecording.hpp
* @brief Structures and functions to record drawcalls.
*/
#include <vulkan/vulkan.hpp>
#include "Handles.hpp"
#include "DescriptorConfig.hpp"
#include "PushConstants.hpp"
#include "Buffer.hpp"
namespace vkcv {
/**
* @brief Structure to store details about a vertex buffer binding.
*/
struct VertexBufferBinding {
vk::DeviceSize offset;
vk::Buffer buffer;
};
/**
* @brief Enum class to specify the size of indexes.
*/
enum class IndexBitCount {
Bit8,
Bit16,
Bit32
};
/**
* @brief Structure to configure a descriptor set usage.
*/
struct DescriptorSetUsage {
inline DescriptorSetUsage(uint32_t setLocation, DescriptorSetHandle descriptorSet,
const std::vector<uint32_t>& dynamicOffsets = {}) noexcept :
setLocation(setLocation),
descriptorSet(descriptorSet),
dynamicOffsets(dynamicOffsets) {}
const uint32_t setLocation;
const DescriptorSetHandle descriptorSet;
const std::vector<uint32_t> dynamicOffsets;
};
/**
* @brief Structure to store details of a mesh to draw.
*/
struct Mesh {
inline Mesh() {}
inline Mesh(std::vector<VertexBufferBinding> vertexBufferBindings,
vk::Buffer indexBuffer,
size_t indexCount,
IndexBitCount indexBitCount = IndexBitCount::Bit16) noexcept :
vertexBufferBindings(vertexBufferBindings),
indexBuffer(indexBuffer),
indexCount(indexCount),
indexBitCount(indexBitCount) {}
std::vector<VertexBufferBinding> vertexBufferBindings;
vk::Buffer indexBuffer;
size_t indexCount;
IndexBitCount indexBitCount;
};
/**
* @brief Structure to store details for a drawcall.
*/
struct DrawcallInfo {
inline DrawcallInfo(const Mesh& mesh,
const std::vector<DescriptorSetUsage>& descriptorSets,
const uint32_t instanceCount = 1) :
mesh(mesh),
descriptorSets(descriptorSets),
instanceCount(instanceCount){}
Mesh mesh;
std::vector<DescriptorSetUsage> descriptorSets;
uint32_t instanceCount;
};
/**
* @brief Structure to store details for a mesh shader drawcall.
*/
struct MeshShaderDrawcall {
std::vector<DescriptorSetUsage> descriptorSets;
uint32_t taskCount;
};
void recordMeshShaderDrawcall(const Core& core,
vk::CommandBuffer cmdBuffer,
vk::PipelineLayout pipelineLayout,
const PushConstants& pushConstantData,
uint32_t pushConstantOffset,
const MeshShaderDrawcall& drawcall,
uint32_t firstTask);
}
......@@ -2,12 +2,13 @@
/**
* @authors Alexander Gauggel, Tobias Frisch
* @file vkcv/CommandRecordingFunctionTypes.hpp
* @brief Abstract function types to handle command recording.
* @brief Abstract function types to handle command recording for example.
*/
#include <vulkan/vulkan.hpp>
#include "Event.hpp"
#include "Handles.hpp"
namespace vkcv {
......@@ -21,4 +22,10 @@ namespace vkcv {
*/
typedef typename event_function<>::type FinishCommandFunction;
/**
* @brief Function to be called each frame for every open window.
*/
typedef typename event_function<const WindowHandle&, double, double, uint32_t, uint32_t>::type
WindowFrameFunction;
}
\ No newline at end of file
......@@ -304,6 +304,16 @@ namespace vkcv {
[[nodiscard]]
bool checkSupport(const vk::PhysicalDeviceRayTracingPipelineFeaturesKHR& features, bool required) const;
/**
* @brief Checks support of the @p vk::PhysicalDeviceVulkan13Features.
*
* @param[in] features The features
* @param[in] required True, if the @p features are required, else false
* @return @p True, if the @p features are supported, else @p false
*/
[[nodiscard]]
bool checkSupport(const vk::PhysicalDeviceVulkan13Features& features, bool required) const;
/**
* @brief Searches for a base structure of a given structure type.
*
......@@ -411,7 +421,7 @@ namespace vkcv {
if (!checkSupport(features, required)) {
if (required) {
throw std::runtime_error("Required feature is not supported!");
vkcv_log_throw_error("Required feature is not supported!");
}
return false;
......
......@@ -2,16 +2,15 @@
/**
* @authors Mara Vogt, Mark Mints, Tobias Frisch
* @file vkcv/GraphicsPipelineConfig.hpp
* @brief Graphics Pipeline Config Struct to hand over required information to Pipeline Creation
* @brief Graphics pipeline config struct to hand over required information to pipeline creation.
*/
#include <vector>
#include <cstdint>
#include "Handles.hpp"
#include "ShaderProgram.hpp"
#include "PipelineConfig.hpp"
#include "VertexLayout.hpp"
#include "ImageConfig.hpp"
#include "Multisampling.hpp"
namespace vkcv {
......@@ -58,26 +57,104 @@ namespace vkcv {
};
/**
* @brief Structure to configure a graphics pipeline before its creation.
* @brief Class to configure a graphics pipeline before its creation.
*/
struct GraphicsPipelineConfig {
ShaderProgram m_ShaderProgram;
uint32_t m_Width;
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<DescriptorSetLayoutHandle> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
BlendMode m_blendMode = BlendMode::None;
bool m_EnableDepthClamping = false;
Multisampling m_multisampling = Multisampling::None;
CullMode m_culling = CullMode::None;
DepthTest m_depthTest = DepthTest::LessEqual;
bool m_depthWrite = true;
bool m_alphaToCoverage = false;
uint32_t m_tessellationControlPoints = 0;
class GraphicsPipelineConfig : public PipelineConfig {
private:
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
uint32_t m_Width;
uint32_t m_Height;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
BlendMode m_blendMode = BlendMode::None;
bool m_EnableDepthClamping = false;
CullMode m_Culling = CullMode::None;
DepthTest m_DepthTest = DepthTest::LessEqual;
bool m_DepthWrite = true;
bool m_AlphaToCoverage = false;
uint32_t m_TessellationControlPoints = 0;
public:
GraphicsPipelineConfig();
GraphicsPipelineConfig(const ShaderProgram& program,
const PassHandle& pass,
const VertexLayout& vertexLayout,
const std::vector<DescriptorSetLayoutHandle>& layouts);
GraphicsPipelineConfig(const GraphicsPipelineConfig &other) = default;
GraphicsPipelineConfig(GraphicsPipelineConfig &&other) = default;
~GraphicsPipelineConfig() = default;
GraphicsPipelineConfig& operator=(const GraphicsPipelineConfig &other) = default;
GraphicsPipelineConfig& operator=(GraphicsPipelineConfig &&other) = default;
[[nodiscard]]
const PassHandle& getPass() const;
[[nodiscard]]
const VertexLayout& getVertexLayout() const;
[[nodiscard]]
uint32_t getWidth() const;
[[nodiscard]]
uint32_t getHeight() const;
void setResolution(uint32_t width, uint32_t height);
[[nodiscard]]
bool isViewportDynamic() const;
[[nodiscard]]
bool isUsingConservativeRasterization() const;
void setUsingConservativeRasterization(bool conservativeRasterization);
[[nodiscard]]
PrimitiveTopology getPrimitiveTopology() const;
void setPrimitiveTopology(PrimitiveTopology primitiveTopology);
[[nodiscard]]
BlendMode getBlendMode() const;
void setBlendMode(BlendMode blendMode);
[[nodiscard]]
bool isDepthClampingEnabled() const;
void setDepthClampingEnabled(bool depthClamping);
[[nodiscard]]
CullMode getCulling() const;
void setCulling(CullMode cullMode);
[[nodiscard]]
DepthTest getDepthTest() const;
void setDepthTest(DepthTest depthTest);
[[nodiscard]]
bool isWritingDepth() const;
void setWritingDepth(bool writingDepth);
[[nodiscard]]
bool isWritingAlphaToCoverage() const;
void setWritingAlphaToCoverage(bool alphaToCoverage);
[[nodiscard]]
uint32_t getTesselationControlPoints() const;
void setTesselationControlPoints(uint32_t tessellationControlPoints);
};
}
\ No newline at end of file
......@@ -130,23 +130,23 @@ namespace vkcv
private:
using Handle::Handle;
};
/**
* @brief Handle class for descriptor sets.
/**
* @brief Handle class for descriptor set layouts.
*/
class DescriptorSetHandle : public Handle {
friend class DescriptorManager;
class DescriptorSetLayoutHandle : public Handle {
friend class DescriptorSetLayoutManager;
private:
using Handle::Handle;
};
/**
* @brief Handle class for descriptor set layouts.
* @brief Handle class for descriptor sets.
*/
class DescriptorSetLayoutHandle : public Handle {
friend class DescriptorManager;
class DescriptorSetHandle : public Handle {
friend class DescriptorSetManager;
private:
using Handle::Handle;
using Handle::Handle;
};
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment