Hymn to Beauty
C++ 3D Engine
Video::VulkanRenderer Class Reference

Low-level renderer implementing Vulkan. More...

#include <VulkanRenderer.hpp>

Inheritance diagram for Video::VulkanRenderer:
Video::LowLevelRenderer

Public Member Functions

 VulkanRenderer (::Utility::Window *window)
 Create new Vulkan renderer. More...
 
 ~VulkanRenderer () final
 Destructor. More...
 
CommandBufferCreateCommandBuffer () final
 Create a command buffer. More...
 
void BeginFrame () final
 Begin a new frame. More...
 
void Submit (CommandBuffer *commandBuffer) final
 Submit a command buffer for execution. More...
 
void Present () final
 Present the rendered image to the swap chain. More...
 
BufferCreateBuffer (Buffer::BufferUsage bufferUsage, uint32_t size, const void *data=nullptr) final
 
BufferCreateTemporaryBuffer (Buffer::BufferUsage bufferUsage, uint32_t size, const void *data=nullptr) final
 
VertexDescriptionCreateVertexDescription (unsigned int attributeCount, const VertexDescription::Attribute *attributes, bool indexBuffer=false) final
 Create a vertex description. More...
 
GeometryBindingCreateGeometryBinding (const VertexDescription *vertexDescription, Buffer *vertexBuffer, GeometryBinding::IndexType indexType=GeometryBinding::IndexType::NONE, const Buffer *indexBuffer=nullptr) final
 Create a geometry binding. More...
 
ShaderCreateShader (const ShaderSource &shaderSource, Shader::Type type) final
 Create a shader. More...
 
ShaderProgramCreateShaderProgram (std::initializer_list< const Shader * > shaders) final
 Create a shader program. More...
 
TextureCreateTexture (const glm::uvec2 size, Texture::Format format, int components, unsigned char *data) final
 Create a texture. More...
 
const SamplerGetSampler (Sampler::Filter filter, Sampler::Clamping clamping) const final
 Get a sampler. More...
 
TextureCreateRenderTarget (const glm::uvec2 &size, Texture::Format format) final
 Create a render target. More...
 
void FreeRenderTarget (Texture *renderTarget) final
 Free a render target. More...
 
GraphicsPipelineCreateGraphicsPipeline (const ShaderProgram *shaderProgram, const GraphicsPipeline::Configuration &configuration, const VertexDescription *vertexDescription=nullptr) final
 Create a graphics pipeline. More...
 
ComputePipelineCreateComputePipeline (const ShaderProgram *shaderProgram) final
 Create a compute pipeline. More...
 
void Wait () final
 Wait for all rendering to finish. More...
 
unsigned char * ReadImage (Texture *texture) final
 Read a render texture color image. More...
 
const std::vector< Profiling::Event > & GetTimeline () const final
 Get profiling timeline. More...
 
const OptionalFeaturesGetOptionalFeatures () const final
 Get which optional features are supported. More...
 
VkImage GetCurrentSwapChainImage () const
 Get current swap chain image. More...
 
uint32_t GetSwapChainImageCount () const
 Get the number of swap chain images. More...
 
VkDescriptorSetLayout GetEmptyDescriptorSetLayout () const
 Get the empty descriptor set layout. More...
 
VkDescriptorSetLayout GetBufferDescriptorSetLayout (ShaderProgram::BindingType bindingType) const
 Get the descriptor set layout for a buffer binding. More...
 
VkDescriptorSetLayout GetStorageBufferDescriptorSetLayout (unsigned int buffers) const
 Get the descriptor set layout for a storage buffer binding. More...
 
VkDescriptorSetLayout GetMaterialDescriptorSetLayout (unsigned int textures) const
 Get the descriptor set layout for a material binding. More...
 
VkDescriptorSet GetDescriptorSet (ShaderProgram::BindingType bindingType, VulkanBuffer *buffer)
 Get a descriptor set for a given binding type and buffer. More...
 
VkDescriptorSet GetStorageBufferDescriptorSet (std::initializer_list< Buffer * > buffers)
 Get a descriptor set for a given binding of storage buffers. More...
 
VkDescriptorSet GetDescriptorSet (std::initializer_list< std::pair< Texture *, const Sampler * > > textures)
 Get a descriptor set for a given binding of textures. More...
 
VkQueryPool GetQueryPool ()
 Get the current frame's query pool. More...
 
uint32_t GetFreeQuery ()
 Get a free query from the current frame's pool. More...
 
- Public Member Functions inherited from Video::LowLevelRenderer
 LowLevelRenderer ()
 Create a new low-level renderer. More...
 
virtual ~LowLevelRenderer ()
 Destructor. More...
 
virtual BufferCreateBuffer (Buffer::BufferUsage bufferUsage, unsigned int size, const void *data=nullptr)=0
 Create a GPU buffer. More...
 
virtual BufferCreateTemporaryBuffer (Buffer::BufferUsage bufferUsage, unsigned int size, const void *data=nullptr)=0
 Create a temporary GPU buffer. More...
 
void SetProfiling (bool profiling)
 Set whether to profile. More...
 
bool IsProfiling () const
 Get whether profiling is active. More...
 

Detailed Description

Low-level renderer implementing Vulkan.

Constructor & Destructor Documentation

◆ VulkanRenderer()

Video::VulkanRenderer::VulkanRenderer ( ::Utility::Window window)
explicit

Create new Vulkan renderer.

Parameters
windowThe window to render to.

◆ ~VulkanRenderer()

Video::VulkanRenderer::~VulkanRenderer ( )
final

Destructor.

Member Function Documentation

◆ BeginFrame()

void Video::VulkanRenderer::BeginFrame ( )
finalvirtual

Begin a new frame.

Implements Video::LowLevelRenderer.

◆ CreateBuffer()

Buffer * Video::VulkanRenderer::CreateBuffer ( Buffer::BufferUsage  bufferUsage,
uint32_t  size,
const void *  data = nullptr 
)
final

◆ CreateCommandBuffer()

CommandBuffer * Video::VulkanRenderer::CreateCommandBuffer ( )
finalvirtual

Create a command buffer.

Returns
The created command buffer.

Implements Video::LowLevelRenderer.

◆ CreateComputePipeline()

ComputePipeline * Video::VulkanRenderer::CreateComputePipeline ( const ShaderProgram shaderProgram)
finalvirtual

Create a compute pipeline.

Parameters
shaderProgramThe shader program to use.
Returns
The created compute pipeline.

Implements Video::LowLevelRenderer.

◆ CreateGeometryBinding()

GeometryBinding * Video::VulkanRenderer::CreateGeometryBinding ( const VertexDescription vertexDescription,
Buffer vertexBuffer,
GeometryBinding::IndexType  indexType = GeometryBinding::IndexType::NONE,
const Buffer indexBuffer = nullptr 
)
finalvirtual

Create a geometry binding.

Parameters
vertexDescriptionDescription of the attributes in the vertex buffer.
vertexBufferBuffer containing the vertex data.
indexTypeThe type of values in the index buffer.
indexBufferIndex buffer.
Returns
The created geometry binding.

Implements Video::LowLevelRenderer.

◆ CreateGraphicsPipeline()

GraphicsPipeline * Video::VulkanRenderer::CreateGraphicsPipeline ( const ShaderProgram shaderProgram,
const GraphicsPipeline::Configuration configuration,
const VertexDescription vertexDescription = nullptr 
)
finalvirtual

Create a graphics pipeline.

Parameters
shaderProgramThe shader program to use.
configurationThe configuration of the pipeline.
vertexDescriptionThe description of the vertex input to the pipeline.
Returns
The created graphics pipeline.

Implements Video::LowLevelRenderer.

◆ CreateRenderTarget()

Texture * Video::VulkanRenderer::CreateRenderTarget ( const glm::uvec2 &  size,
Texture::Format  format 
)
finalvirtual

Create a render target.

Parameters
sizeThe size of the texture, in pixels.
formatThe format of the texture.
Returns
The created texture.

Implements Video::LowLevelRenderer.

◆ CreateShader()

Shader * Video::VulkanRenderer::CreateShader ( const ShaderSource &  shaderSource,
Shader::Type  type 
)
finalvirtual

Create a shader.

Parameters
shaderSourceThe source of the shader, generated by the shader processor.
typeThe type of shader to create.
Returns
The created shader.

Implements Video::LowLevelRenderer.

◆ CreateShaderProgram()

ShaderProgram * Video::VulkanRenderer::CreateShaderProgram ( std::initializer_list< const Shader * >  shaders)
finalvirtual

Create a shader program.

Link together shaders into a shader program that can be run on the GPU.

Sample:

Shader* vertexShader = lowLevelRenderer->CreateShader(vertexSource, Shader::Type::VERTEX_SHADER);
Shader* fragmentShader = lowLevelRenderer->CreateShader(fragmentSource, Shader::Type::FRAGMENT_SHADER);
ShaderProgram* shaderProgram = lowLevelRenderer->CreateShaderProgram({ vertexShader, fragmentShader });
@ VERTEX_SHADER
Vertex shader.
@ FRAGMENT_SHADER
Fragment shader.
Parameters
shadersList of shaders to link together.
Returns
The created shader program.

Implements Video::LowLevelRenderer.

◆ CreateTemporaryBuffer()

Buffer * Video::VulkanRenderer::CreateTemporaryBuffer ( Buffer::BufferUsage  bufferUsage,
uint32_t  size,
const void *  data = nullptr 
)
final

◆ CreateTexture()

Texture * Video::VulkanRenderer::CreateTexture ( const glm::uvec2  size,
Texture::Format  format,
int  components,
unsigned char *  data 
)
finalvirtual

Create a texture.

Parameters
sizeThe size of the texture, in pixels.
formatThe format of the texture.
componentsThe number of components in the texture, 0 if no texture data is supplied.
dataThe texture data to upload, or nullptr.
Returns
The created texture.

Implements Video::LowLevelRenderer.

◆ CreateVertexDescription()

VertexDescription * Video::VulkanRenderer::CreateVertexDescription ( unsigned int  attributeCount,
const VertexDescription::Attribute attributes,
bool  indexBuffer = false 
)
finalvirtual

Create a vertex description.

Parameters
attributeCountThe number of vertex attributes.
attributesThe array of attributes.
indexBufferWhether to use an index buffer.
Returns
The created vertex description.

Implements Video::LowLevelRenderer.

◆ FreeRenderTarget()

void Video::VulkanRenderer::FreeRenderTarget ( Texture renderTarget)
finalvirtual

Free a render target.

Parameters
renderTargetThe render target to free.

Implements Video::LowLevelRenderer.

◆ GetBufferDescriptorSetLayout()

VkDescriptorSetLayout Video::VulkanRenderer::GetBufferDescriptorSetLayout ( ShaderProgram::BindingType  bindingType) const

Get the descriptor set layout for a buffer binding.

Parameters
bindingTypeThe binding type.
Returns
The descriptor set layout.

◆ GetCurrentSwapChainImage()

VkImage Video::VulkanRenderer::GetCurrentSwapChainImage ( ) const

Get current swap chain image.

Returns
The current swap chain image.

◆ GetDescriptorSet() [1/2]

VkDescriptorSet Video::VulkanRenderer::GetDescriptorSet ( ShaderProgram::BindingType  bindingType,
VulkanBuffer buffer 
)

Get a descriptor set for a given binding type and buffer.

Parameters
bindingTypeThe binding type to bind the buffer to.
bufferThe buffer to bind.
Returns
The descriptor set.

◆ GetDescriptorSet() [2/2]

VkDescriptorSet Video::VulkanRenderer::GetDescriptorSet ( std::initializer_list< std::pair< Texture *, const Sampler * > >  textures)

Get a descriptor set for a given binding of textures.

Parameters
texturesThe textures to bind.
Returns
The descriptor set.
Todo:
Have some material object keep track of this instead of treating textures individually.

◆ GetEmptyDescriptorSetLayout()

VkDescriptorSetLayout Video::VulkanRenderer::GetEmptyDescriptorSetLayout ( ) const

Get the empty descriptor set layout.

◆ GetFreeQuery()

uint32_t Video::VulkanRenderer::GetFreeQuery ( )

Get a free query from the current frame's pool.

Returns
The query.

◆ GetMaterialDescriptorSetLayout()

VkDescriptorSetLayout Video::VulkanRenderer::GetMaterialDescriptorSetLayout ( unsigned int  textures) const

Get the descriptor set layout for a material binding.

Parameters
texturesThe number of textures to bind.
Returns
The descriptor set layout.

◆ GetOptionalFeatures()

const VulkanRenderer::OptionalFeatures & Video::VulkanRenderer::GetOptionalFeatures ( ) const
finalvirtual

Get which optional features are supported.

Returns
Which optional features are supported.

Implements Video::LowLevelRenderer.

◆ GetQueryPool()

VkQueryPool Video::VulkanRenderer::GetQueryPool ( )

Get the current frame's query pool.

Returns
The current frame's query pool.

◆ GetSampler()

const Sampler * Video::VulkanRenderer::GetSampler ( Sampler::Filter  filter,
Sampler::Clamping  clamping 
) const
finalvirtual

Get a sampler.

Parameters
filterThe interpolation to apply.
clampingHow to handle sampling outside the texture dimensions.
Returns
The requested sampler.

Implements Video::LowLevelRenderer.

◆ GetStorageBufferDescriptorSet()

VkDescriptorSet Video::VulkanRenderer::GetStorageBufferDescriptorSet ( std::initializer_list< Buffer * >  buffers)

Get a descriptor set for a given binding of storage buffers.

Parameters
buffersThe buffers to bind.
Returns
The descriptor set.

◆ GetStorageBufferDescriptorSetLayout()

VkDescriptorSetLayout Video::VulkanRenderer::GetStorageBufferDescriptorSetLayout ( unsigned int  buffers) const

Get the descriptor set layout for a storage buffer binding.

Parameters
buffersThe number of buffers to bind.
Returns
The descriptor set layout.

◆ GetSwapChainImageCount()

uint32_t Video::VulkanRenderer::GetSwapChainImageCount ( ) const

Get the number of swap chain images.

Returns
The number of swap chain images.

◆ GetTimeline()

const std::vector< Profiling::Event > & Video::VulkanRenderer::GetTimeline ( ) const
finalvirtual

Get profiling timeline.

Returns
A list of events that have occurred since the last time fetching the timeline.

Implements Video::LowLevelRenderer.

◆ Present()

void Video::VulkanRenderer::Present ( )
finalvirtual

Present the rendered image to the swap chain.

Implements Video::LowLevelRenderer.

◆ ReadImage()

unsigned char * Video::VulkanRenderer::ReadImage ( Texture texture)
finalvirtual

Read a render texture color image.

Parameters
textureThe texture to read.
Returns
The color image as a char-array.

Implements Video::LowLevelRenderer.

◆ Submit()

void Video::VulkanRenderer::Submit ( CommandBuffer commandBuffer)
finalvirtual

Submit a command buffer for execution.

Parameters
commandBufferThe command buffer to submit.

Implements Video::LowLevelRenderer.

◆ Wait()

void Video::VulkanRenderer::Wait ( )
finalvirtual

Wait for all rendering to finish.

Implements Video::LowLevelRenderer.


The documentation for this class was generated from the following files: