The small3d framework
Functions | Variables
vkzos.h File Reference

vkzos header file More...

#include <vulkan/vulkan.h>

Go to the source code of this file.

Functions

int vkz_create_instance (const char *application_name, const char **enabled_extension_names, size_t enabled_extension_count)
 Create a vulkan instance. More...
 
int vkz_init (void)
 Initialise. Internally this means create physical device, select queue families and create logical device. More...
 
int vkz_set_width_height (const uint32_t width, const uint32_t height)
 Set width and height for all rendering calculations. More...
 
int vkz_create_swapchain (int with_image_sampler)
 Create the swapchain that will be used. This will also create the associated image views. More...
 
int vkz_destroy_swapchain (void)
 Destroy the swapchain.
 
int vkz_create_depth_image (void)
 Create the image used for depth testing. This function must be called right after vkz_create_swapchain(). This is not perfect but, for the time being it is what it is.
 
int vkz_destroy_depth_image (void)
 Destroy the image used for depth testing.
 
int vkz_create_pipeline (const char *vertex_shader_path, const char *fragment_shader_path, int(*set_input_state)(VkPipelineVertexInputStateCreateInfo *), int(*set_pipeline_layout)(VkPipelineLayoutCreateInfo *), uint32_t *index)
 Create a pipeline. This will also create associated Vulkan objects. More...
 
int vkz_begin_draw_command_buffer (VkCommandBuffer *command_buffer)
 Begin creating a drawing command buffer for a given pipeline not bound to a specific pipeline. More...
 
int vkz_bind_pipeline_to_command_buffer (uint32_t pipeline_index, const VkCommandBuffer *command_buffer)
 Bind a pipeline to a command buffer. More...
 
int vkz_end_draw_command_buffer (VkCommandBuffer *command_buffer)
 Finish recording a command buffer. More...
 
int vkz_destroy_draw_command_buffer (VkCommandBuffer *command_buffer)
 Destroy a command buffer. More...
 
int vkz_create_sync_objects (void)
 Create sync objects for a given pipeline. More...
 
int vkz_destroy_sync_objects (void)
 Destroy sync objects for a given pipeline. More...
 
int vkz_recreate_pipelines_and_swapchain (void)
 Recreate the swapchain and the pipelines. More...
 
int vkz_acquire_next_image (uint32_t pipeline_index, uint32_t *image_index)
 Acquire next swapchain image. More...
 
int vkz_present_next_image (void)
 Present next swapchain image (the one acquired by vkz_acquire_next_image()) More...
 
int vkz_draw (VkCommandBuffer *command_buffer)
 Send draw commands (will take effect on the current pipeline image acquired by vkz_acquire_next_image()) More...
 
int vkz_create_buffer (VkBuffer *buffer, VkBufferUsageFlags buffer_usage_flags, uint32_t buffer_size, VkDeviceMemory *memory, VkMemoryPropertyFlags memory_property_flags)
 Create a buffer. More...
 
int vkz_destroy_buffer (VkBuffer buffer, VkDeviceMemory memory)
 Destroy a buffer. More...
 
int vkz_copy_buffer (VkBuffer source, VkBuffer destination, VkDeviceSize size)
 Copy a buffer to another. More...
 
int vkz_create_image (VkImage *image, uint32_t image_width, uint32_t image_height, VkFormat image_format, VkImageTiling image_tiling, VkImageUsageFlags image_usage_flags, VkDeviceMemory *memory, VkMemoryPropertyFlags memory_property_flags)
 Create a Vulkan image. More...
 
int vkz_destroy_image (VkImage image, VkDeviceMemory image_memory)
 Destroy a Vulkan image. More...
 
int vkz_transition_image_layout (VkImage image, VkFormat format, VkImageLayout old_layout, VkImageLayout new_layout)
 Transition the layout of a Vulkan image. More...
 
int vkz_copy_buffer_to_image (VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
 Copy a buffer to an image. More...
 
int vkz_create_image_view (VkImageView *image_view, VkImage image, VkFormat format, VkImageAspectFlags aspect_flags)
 Create a Vulkan image view. More...
 
int vkz_create_sampler (VkSampler *sampler)
 Create a Vulkan sampler. More...
 
int vkz_shutdown (void)
 Cleanup the memory, destroy any debug callbacks, as well as the logical device and the Vulkan instance. More...
 

Variables

VkInstance vkz_instance
 The Vulkan instance.
 
VkSurfaceKHR vkz_surface
 The surface on which graphics will be presented.
 
VkPhysicalDevice vkz_physical_device
 The physical device that is selected vkz_init().
 
VkDevice vkz_logical_device
 The logical device that is created by vkz_init().
 
VkPipelineLayout * vkz_pipeline_layout
 The pipeline layouts, one for each pipeline created.
 
uint32_t vkz_swapchain_image_count
 Number of images in the swapchain, set by vkz_create_swapchain().
 
VkClearColorValue vkz_clear_colour
 The colour used to clear the screen.
 

Detailed Description

vkzos header file

Created on: 2018/05/01 Author: Dimitri Kourkoulis License: BSD 3-Clause License (see LICENSE file)

Function Documentation

◆ vkz_acquire_next_image()

int vkz_acquire_next_image ( uint32_t  pipeline_index,
uint32_t *  image_index 
)

Acquire next swapchain image.

Parameters
pipeline_indexThe index of the pipeline TODO: Independentise synchronisation from pipelines perhaps...
image_indexThe index of the acquired swapchain image
Returns
1 if successful, 0 otherwise

◆ vkz_begin_draw_command_buffer()

int vkz_begin_draw_command_buffer ( VkCommandBuffer *  command_buffer)

Begin creating a drawing command buffer for a given pipeline not bound to a specific pipeline.

Parameters
command_bufferPointer to the command buffer.
Returns
1 if successful, 0 otherwise

◆ vkz_bind_pipeline_to_command_buffer()

int vkz_bind_pipeline_to_command_buffer ( uint32_t  pipeline_index,
const VkCommandBuffer *  command_buffer 
)

Bind a pipeline to a command buffer.

Parameters
pipeline_indexThe index of the pipeline
command_bufferPointer to the command buffer.
Returns
1 if successful, 0 otherwise

◆ vkz_copy_buffer()

int vkz_copy_buffer ( VkBuffer  source,
VkBuffer  destination,
VkDeviceSize  size 
)

Copy a buffer to another.

Parameters
sourceThe source buffer
destinationThe destination buffer
sizeThe size of the buffer to be copied, in bytes
Returns
1 if successful, 0 otherwise

◆ vkz_copy_buffer_to_image()

int vkz_copy_buffer_to_image ( VkBuffer  buffer,
VkImage  image,
uint32_t  width,
uint32_t  height 
)

Copy a buffer to an image.

Parameters
bufferThe buffer
imageThe image
widthThe width of the image
heightThe height of the image
Returns
1 if successful, 0 otherwise

◆ vkz_create_buffer()

int vkz_create_buffer ( VkBuffer *  buffer,
VkBufferUsageFlags  buffer_usage_flags,
uint32_t  buffer_size,
VkDeviceMemory *  memory,
VkMemoryPropertyFlags  memory_property_flags 
)

Create a buffer.

Parameters
bufferVariable in which to store the buffer
buffer_usage_flagsVulkan usage flags for the buffer
buffer_sizeThe size of the buffer, in bytes
memoryThe GPU memory reserved for the buffer
memory_property_flagsVulkan properties of the reserved memory
Returns
1 if successful, 0 otherwise

◆ vkz_create_image()

int vkz_create_image ( VkImage *  image,
uint32_t  image_width,
uint32_t  image_height,
VkFormat  image_format,
VkImageTiling  image_tiling,
VkImageUsageFlags  image_usage_flags,
VkDeviceMemory *  memory,
VkMemoryPropertyFlags  memory_property_flags 
)

Create a Vulkan image.

Parameters
imageVariable in which to store the image
image_widthThe width of the image
image_heightThe height of the image
image_formatThe format of the image
image_tilingThe tiling of the image
image_usage_flagsThe usage flags of the image
memoryThe GPU memory reserved for the image
memory_property_flagsVulkan properties of the reserved memory
Returns
1 if successful, 0 otherwise

◆ vkz_create_image_view()

int vkz_create_image_view ( VkImageView *  image_view,
VkImage  image,
VkFormat  format,
VkImageAspectFlags  aspect_flags 
)

Create a Vulkan image view.

Parameters
image_viewThe image view to be created
imageThe image for which the image view will be created
formatThe image view format
aspect_flagsThe aspect flags (mask) e.g. VK_IMAGE_ASPECT_COLOR_BIT
Returns
1 if successful, 0 otherwise

◆ vkz_create_instance()

int vkz_create_instance ( const char *  application_name,
const char **  enabled_extension_names,
size_t  enabled_extension_count 
)

Create a vulkan instance.

Parameters
application_nameThe name of the application that will be using Vulkan
enabled_extension_namesNames of extensions used
enabled_extension_countNumber of extensions used
Returns
1 if successful, 0 otherwise

◆ vkz_create_pipeline()

int vkz_create_pipeline ( const char *  vertex_shader_path,
const char *  fragment_shader_path,
int(*)(VkPipelineVertexInputStateCreateInfo *)  set_input_state,
int(*)(VkPipelineLayoutCreateInfo *)  set_pipeline_layout,
uint32_t *  index 
)

Create a pipeline. This will also create associated Vulkan objects.

Parameters
vertex_shader_pathThe path to the SPV file for the vertex shader that will be used in the pipeline.
fragment_shader_pathThe path to the SPV file for the fragment shader that will be used in the pipeline.
set_input_stateCallback function, allowing e.g. the addition of information on buffers that will be used by the pipeline (vertex, uniform) before the pipeline is created. If there is no such information to be added, NULL should be passed here.
set_pipeline_layoutCallback function, allowing e.g. the addition of information on descriptors that will be used by the pipeline before the pipeline is created. If there is no such information to be added, NULL should be passed here.
indexIf 100 is passed here, a new "slot" will be used for the pipeline and returned via the same variable. If not, the pipeline will be created over a previously deleted pipeline at the index position of the internal array containing pipelines. In that case, the shader path parameters will be ignored, because the previously used shaders will be reused. Also in that case the callback functions parameters will be ignored.
Returns
1 if successful, 0 otherwise

◆ vkz_create_sampler()

int vkz_create_sampler ( VkSampler *  sampler)

Create a Vulkan sampler.

Parameters
samplerThe sampler to be created
Returns
1 if successful, 0 otherwise

◆ vkz_create_swapchain()

int vkz_create_swapchain ( int  with_image_sampler)

Create the swapchain that will be used. This will also create the associated image views.

Parameters
with_image_sampler1 If an image sampler will be used, 0 otherwise.
Returns
1 if successful, 0 otherwise

◆ vkz_create_sync_objects()

int vkz_create_sync_objects ( void  )

Create sync objects for a given pipeline.

Returns
1 if successful, 0 otherwise

◆ vkz_destroy_buffer()

int vkz_destroy_buffer ( VkBuffer  buffer,
VkDeviceMemory  memory 
)

Destroy a buffer.

Parameters
bufferThe buffer to be destroyed
memoryThe GPU memory previously reserved for the buffer, to be released
Returns
1 if successful, 0 otherwise

◆ vkz_destroy_draw_command_buffer()

int vkz_destroy_draw_command_buffer ( VkCommandBuffer *  command_buffer)

Destroy a command buffer.

Parameters
command_bufferPointer to the command buffer.
Returns
1 if successful, 0 otherwise

◆ vkz_destroy_image()

int vkz_destroy_image ( VkImage  image,
VkDeviceMemory  image_memory 
)

Destroy a Vulkan image.

Parameters
imageThe image to be destroyed
image_memoryThe GPU memory previously reserved for the image, to be released

◆ vkz_destroy_sync_objects()

int vkz_destroy_sync_objects ( void  )

Destroy sync objects for a given pipeline.

Returns
1 if successful, 0 otherwise

◆ vkz_draw()

int vkz_draw ( VkCommandBuffer *  command_buffer)

Send draw commands (will take effect on the current pipeline image acquired by vkz_acquire_next_image())

Parameters
command_bufferPointer to the command buffer containing the commands.
Returns
1 if successful, 0 otherwise

◆ vkz_end_draw_command_buffer()

int vkz_end_draw_command_buffer ( VkCommandBuffer *  command_buffer)

Finish recording a command buffer.

Parameters
command_bufferPointer to the command buffer.
Returns
1 if successful, 0 otherwise

◆ vkz_init()

int vkz_init ( void  )

Initialise. Internally this means create physical device, select queue families and create logical device.

Returns
1 if successful, 0 otherwise

◆ vkz_present_next_image()

int vkz_present_next_image ( void  )

Present next swapchain image (the one acquired by vkz_acquire_next_image())

Returns
1 if successful, 0 otherwise

◆ vkz_recreate_pipelines_and_swapchain()

int vkz_recreate_pipelines_and_swapchain ( void  )

Recreate the swapchain and the pipelines.

Returns
1 if successful, 0 otherwise

◆ vkz_set_width_height()

int vkz_set_width_height ( const uint32_t  width,
const uint32_t  height 
)

Set width and height for all rendering calculations.

Parameters
widthThe new width
heightThe new height
Returns
1 if successful, 0 otherwise

◆ vkz_shutdown()

int vkz_shutdown ( void  )

Cleanup the memory, destroy any debug callbacks, as well as the logical device and the Vulkan instance.

Returns
1 if successful, 0 otherwise

◆ vkz_transition_image_layout()

int vkz_transition_image_layout ( VkImage  image,
VkFormat  format,
VkImageLayout  old_layout,
VkImageLayout  new_layout 
)

Transition the layout of a Vulkan image.

Parameters
imageThe Vulkan image
formatThe image format
old_layoutThe old layout
new_layoutThe new layout
Returns
1 if successful, 0 otherwise