Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Functions
VkUtils Namespace Reference

Utility functions for the Vulkan backend. More...

Functions

bool checkLayersSupport (const std::vector< const char * > &requestedLayers)
 
bool checkExtensionsSupport (const std::vector< const char * > &requestedExtensions)
 
std::vector< const char * > getRequiredInstanceExtensions (bool enableDebugMarkers, bool enablePortability)
 
bool checkDeviceExtensionsSupport (VkPhysicalDevice device, const std::vector< const char * > &requestedExtensions, bool &hasPortability)
 
bool getQueueFamilies (VkPhysicalDevice device, VkSurfaceKHR surface, int &graphicsFamily, int &presentFamily)
 
Layout convertFormat (const VkFormat &format)
 
Layout findSupportedFormat (const VkPhysicalDevice &physicalDevice, const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
 
void typesFromShape (const TextureShape &shape, VkImageType &imgType, VkImageViewType &viewType)
 
VkCommandBuffer beginSyncOperations (GPUContext &context)
 
void endSyncOperations (VkCommandBuffer &commandBuffer, GPUContext &context)
 
void imageLayoutBarrier (VkCommandBuffer &commandBuffer, GPUTexture &texture, VkImageLayout newLayout, uint mipStart, uint mipCount, uint layerStart, uint layerCount)
 
void mipLayoutBarrier (VkCommandBuffer &commandBuffer, const Texture &texture, VkImageLayout newLayout, uint mip)
 
void textureLayoutBarrier (VkCommandBuffer &commandBuffer, const Texture &texture, VkImageLayout newLayout)
 
void createCommandBuffers (GPUContext &context, uint count)
 
void checkResult (VkResult status)
 
VkSamplerAddressMode getGPUWrapping (Wrap mode)
 
void getGPUFilters (Filter filtering, VkFilter &imgFiltering, VkSamplerMipmapMode &mipFiltering)
 
unsigned int getGPULayout (Layout typedFormat, VkFormat &format)
 
glm::uvec2 copyTextureRegionToBuffer (VkCommandBuffer &commandBuffer, const Texture &srcTexture, std::shared_ptr< Buffer > &dstBuffer, uint mipStart, uint mipCount, uint layerStart, uint layerCount, const glm::uvec2 &offset, const glm::uvec2 &size)
 
void blitTexture (VkCommandBuffer &commandBuffer, const Texture &src, const Texture &dst, uint mipStartSrc, uint mipStartDst, uint mipCount, uint layerStartSrc, uint layerStartDst, uint layerCount, const glm::uvec2 &srcBaseOffset, const glm::uvec2 &srcBaseSize, const glm::uvec2 &dstBaseOffset, const glm::uvec2 &dstBaseSize, Filter filter)
 
void setDebugName (GPUContext &context, VkObjectType type, uint64_t handle, const char *format,...)
 

Detailed Description

Utility functions for the Vulkan backend.

Function Documentation

◆ beginSyncOperations()

VkCommandBuffer VkUtils::beginSyncOperations ( GPUContext context)

Start a one-shot command buffer.

Parameters
contextthe GPU internal context
Returns
the newly created command buffer

◆ blitTexture()

void VkUtils::blitTexture ( VkCommandBuffer &  commandBuffer,
const Texture src,
const Texture dst,
uint  mipStartSrc,
uint  mipStartDst,
uint  mipCount,
uint  layerStartSrc,
uint  layerStartDst,
uint  layerCount,
const glm::uvec2 &  srcBaseOffset,
const glm::uvec2 &  srcBaseSize,
const glm::uvec2 &  dstBaseOffset,
const glm::uvec2 &  dstBaseSize,
Filter  filter 
)

Blit a texture region to another texture region.

Parameters
commandBufferthe command buffer to record the operation on
srcthe source texture
dstthe destination texture
mipStartSrcfirst mip to copy from
mipStartDstfirst mip to copy to
mipCountnumber of mip levels to copy
layerStartSrcfirst layer to copy from
layerStartDstfirst layer to copy to
layerCountnumber of layers to copy
srcBaseOffsettop-left corner pixel coordinates of the region to copy from
srcBaseSizepixel dimensions of the region to copy from
dstBaseOffsettop-left corner pixel coordinates of the region to copy to
dstBaseSizepixel dimensions of the region to copy to
filterinterpolation filtering to apply if regions have different dimensions
Note
Offsets and sizes are expressed at mip 0 in all cases.

◆ checkDeviceExtensionsSupport()

bool VkUtils::checkDeviceExtensionsSupport ( VkPhysicalDevice  device,
const std::vector< const char * > &  requestedExtensions,
bool &  hasPortability 
)

Check if the Vulkan device supports some extensions and/or portability.

Parameters
devicethe physical device handle
requestedExtensionslist of extension names
hasPortabilitywill denote if the device support portability
Returns
true if all extensions are supported

◆ checkExtensionsSupport()

bool VkUtils::checkExtensionsSupport ( const std::vector< const char * > &  requestedExtensions)

Check if the Vulkan instance supports some extensions.

Parameters
requestedExtensionslist of extension names
Returns
true if all extensions are supported

◆ checkLayersSupport()

bool VkUtils::checkLayersSupport ( const std::vector< const char * > &  requestedLayers)

Check if the Vulkan instance supports some validation layers.

Parameters
requestedLayerslist of layer names
Returns
true if all layers are supported

◆ checkResult()

void VkUtils::checkResult ( VkResult  status)

Log a Vulkan return code as a human-readable string.

Parameters
statusthe status to check

◆ convertFormat()

Layout VkUtils::convertFormat ( const VkFormat &  format)

Convert Vulkan format to Rendu format

Parameters
formatVulkan format
Returns
the Rendu format

◆ copyTextureRegionToBuffer()

glm::uvec2 VkUtils::copyTextureRegionToBuffer ( VkCommandBuffer &  commandBuffer,
const Texture srcTexture,
std::shared_ptr< Buffer > &  dstBuffer,
uint  mipStart,
uint  mipCount,
uint  layerStart,
uint  layerCount,
const glm::uvec2 &  offset,
const glm::uvec2 &  size 
)

Copy a texture region to a transfer buffer allocated internally.

Parameters
commandBufferthe command buffer to record the operation on
srcTexturethe source texture
dstBufferwill point to the destination buffer
mipStartfirst mip to copy
mipCountnumber of mip levels to copy
layerStartfirst layer to copy
layerCountnumber of layers to copy
offsettop-left corner pixel coordinates of the region to copy
sizepixel dimensions of the region to copy
Note
Offsets and sizes are expressed at mip 0 in all cases.
Returns
the image index range in the source texture corresponding to the requested mip levels and layers.

◆ createCommandBuffers()

void VkUtils::createCommandBuffers ( GPUContext context,
uint  count 
)

Create per-frame command buffers on the context.

Parameters
contextthe GPU internal context
countnumber of command buffers to create

◆ endSyncOperations()

void VkUtils::endSyncOperations ( VkCommandBuffer &  commandBuffer,
GPUContext context 
)

Finish and submit a one-shot command buffer, waiting for queue completion.

Parameters
commandBufferthe command buffer to complete
contextthe GPU internal context

◆ findSupportedFormat()

Layout VkUtils::findSupportedFormat ( const VkPhysicalDevice &  physicalDevice,
const std::vector< VkFormat > &  candidates,
VkImageTiling  tiling,
VkFormatFeatureFlags  features 
)

Find the optimal image format from a list based on tiling and feature constraints

Parameters
physicalDevicethe physical device handle
candidateslist of possible formats to select from
tilingtype of tiling to support
featuresfeature flags to support
Returns
the selected format

◆ getGPUFilters()

void VkUtils::getGPUFilters ( Filter  filtering,
VkFilter &  imgFiltering,
VkSamplerMipmapMode &  mipFiltering 
)

Convert a Rendu texture filter to an interpolation and mip map Vulkan filterings.

Parameters
filteringthe texture filtering
imgFilteringwill contain the corresponding Vulkan image filtering
mipFilteringwill contain the corresponding Vulkan mipmap mode

◆ getGPULayout()

unsigned int VkUtils::getGPULayout ( Layout  typedFormat,
VkFormat &  format 
)

Convert a Rendu texture layout to a format and channel count.

Parameters
typedFormatthe texture layout
formatwill contain the corresponding Vulkan format
Returns
the format number of components

◆ getGPUWrapping()

VkSamplerAddressMode VkUtils::getGPUWrapping ( Wrap  mode)

Convert a Rendu texture wrapping to a Vulkan address mode.

Parameters
modethe texture wrapping
Returns
the corresponding Vulkan adressing mode

◆ getQueueFamilies()

bool VkUtils::getQueueFamilies ( VkPhysicalDevice  device,
VkSurfaceKHR  surface,
int &  graphicsFamily,
int &  presentFamily 
)

Query the graphics and present queue families indices.

Parameters
devicethe physical device handle
surfacethe display surface
graphicsFamilywill contain the graphics queue family index
presentFamilywill contain the present queue family index
Returns
true if query successful

◆ getRequiredInstanceExtensions()

std::vector< const char * > VkUtils::getRequiredInstanceExtensions ( bool  enableDebugMarkers,
bool  enablePortability 
)

Query the instance extensions required by the system (swapchain, debug layers,...)

Parameters
enableDebugMarkersshould debug marker extension be included
enablePortabilityshould portability extension be included
Returns
a list of extension names

◆ imageLayoutBarrier()

void VkUtils::imageLayoutBarrier ( VkCommandBuffer &  commandBuffer,
GPUTexture texture,
VkImageLayout  newLayout,
uint  mipStart,
uint  mipCount,
uint  layerStart,
uint  layerCount 
)

Apply a layout transition barrier to a texture region.

Parameters
commandBufferthe command buffer to record the operation on
texturethe texture to transition
newLayoutthe new layout to apply
mipStartfirst mip to apply the transition to
mipCountnumber of mip levels to transition
layerStartfirst layer to apply the transition to
layerCountnumber of layers to transition

◆ mipLayoutBarrier()

void VkUtils::mipLayoutBarrier ( VkCommandBuffer &  commandBuffer,
const Texture texture,
VkImageLayout  newLayout,
uint  mip 
)

Apply a layout transition barrier to a whole mip level.

Parameters
commandBufferthe command buffer to record the operation on
texturethe texture to transition
newLayoutthe new layout to apply
mipthe mip level to transition

◆ setDebugName()

void VkUtils::setDebugName ( GPUContext context,
VkObjectType  type,
uint64_t  handle,
const char *  format,
  ... 
)

Associate a debug name to a Vulkan object for validation layers and captures.

Parameters
contextthe GPU context
typethe type of the object
handlethe handle to the object, casted as a raw integer
formatname string format
...name string arguments

◆ textureLayoutBarrier()

void VkUtils::textureLayoutBarrier ( VkCommandBuffer &  commandBuffer,
const Texture texture,
VkImageLayout  newLayout 
)

Apply a layout transition barrier to a whole texture.

Parameters
commandBufferthe command buffer to record the operation on
texturethe texture to transition
newLayoutthe new layout to apply

◆ typesFromShape()

void VkUtils::typesFromShape ( const TextureShape shape,
VkImageType &  imgType,
VkImageViewType &  viewType 
)

Convert a Rendu texture shape to an image and image view types.

Parameters
shapethe texture shape
imgTypewill contain the corresponding image type
viewTypewill contain the corresponding image view type