vk_render_helper.h 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Danil, 2021+ Vulkan shader launcher, self https://github.com/danilw/vulkan-shadertoy-launcher
  2. // The MIT License
  3. #ifndef vk_render_helper_H
  4. #define vk_render_helper_H
  5. #include "vk_utils.h"
  6. int vk_render_get_essentials(struct vk_render_essentials *essentials, struct vk_physical_device *phy_dev,
  7. struct vk_device *dev, struct vk_swapchain *swapchain);
  8. void vk_render_cleanup_essentials(struct vk_render_essentials *essentials, struct vk_device *dev);
  9. /*
  10. * Acquire an image from the swapchain, reset the command buffer, start recording, perform layout transition from
  11. * undefined to to_layout.
  12. */
  13. VkResult vk_render_start(struct vk_render_essentials *essentials, struct vk_device *dev,
  14. struct vk_swapchain *swapchain, VkImageLayout to_layout, uint32_t *image_index);
  15. /* Fill the contents of a host-visible buffer/image with arbitrary data */
  16. vk_error vk_render_fill_buffer(struct vk_device *dev, struct vk_buffer *to, void *from, size_t size, const char *name);
  17. vk_error vk_render_fill_image(struct vk_device *dev, struct vk_image *to, void *from, size_t size, const char *name);
  18. /*
  19. * Copy a buffer/image to another, for example from a host-visible one to a device-local one. This uses a command
  20. * buffer, submits it, and waits for it to finish, so it's not supposed to be used while recording a command buffer.
  21. */
  22. vk_error vk_render_copy_buffer(struct vk_device *dev, struct vk_render_essentials *essentials,
  23. struct vk_buffer *to, struct vk_buffer *from, size_t size, const char *name);
  24. vk_error vk_render_copy_image(struct vk_device *dev, struct vk_render_essentials *essentials,
  25. struct vk_image *to, VkImageLayout to_layout, struct vk_image *from, VkImageLayout from_layout,
  26. VkImageCopy *region, const char *name);
  27. vk_error vk_render_copy_buffer_to_image(struct vk_device *dev, struct vk_render_essentials *essentials,
  28. struct vk_image *to, VkImageLayout to_layout, struct vk_buffer *from,
  29. VkBufferImageCopy *region, const char *name);
  30. vk_error vk_render_copy_image_to_buffer(struct vk_device *dev, struct vk_render_essentials *essentials,
  31. struct vk_buffer *to, struct vk_image *from, VkImageLayout from_layout,
  32. VkBufferImageCopy *region, const char *name);
  33. vk_error create_staging_buffer(struct vk_physical_device *phy_dev, struct vk_device *dev, struct vk_render_essentials *essentials,
  34. struct vk_buffer *staging, uint8_t *contents, size_t size, const char *name);
  35. // use map and unmap memory every time, not optimized
  36. vk_error vk_render_update_texture(struct vk_physical_device *phy_dev, struct vk_device *dev, struct vk_render_essentials *essentials,
  37. struct vk_image *image, VkImageLayout base_layout, uint8_t *contents, const char *name);
  38. /*
  39. * Transition an image to a new layout. This uses a command buffer, submits it, and waits for it to finish, so it's
  40. * not supposed to be used while recording a command buffer.
  41. */
  42. vk_error vk_render_transition_images(struct vk_device *dev, struct vk_render_essentials *essentials,
  43. struct vk_image *images, uint32_t image_count,
  44. VkImageLayout from, VkImageLayout to, VkImageAspectFlags aspect, const char *name);
  45. vk_error vk_render_transition_images_mipmaps(struct vk_physical_device *phy_dev, struct vk_device *dev, struct vk_render_essentials *essentials,
  46. struct vk_image *image, VkImageAspectFlags aspect, const char *name);
  47. /*
  48. * Create a texture image. This uses a command buffer, submits it, and waits for it to finish,
  49. * so it's not supposed to be used while recording a command buffer. It creates and destroys a staging buffer in the
  50. * process. In the end, it transitions the image to the desired layout.
  51. */
  52. vk_error vk_render_init_texture(struct vk_physical_device *phy_dev, struct vk_device *dev, struct vk_render_essentials *essentials,
  53. struct vk_image *image, VkImageLayout layout, uint8_t *contents, const char *name);
  54. /*
  55. * Copy over arbitrary data to the buffer. This uses a command buffer, submits it, and waits for it to finish, so it's
  56. * not supposed to be used while recording a command buffer. It creates and destroys a staging buffer in the process.
  57. */
  58. vk_error vk_render_init_buffer(struct vk_physical_device *phy_dev, struct vk_device *dev, struct vk_render_essentials *essentials,
  59. struct vk_buffer *buffer, void *contents, const char *name);
  60. /*
  61. * allow additional wait and signal semaphores so the submission will be
  62. * synchronized with off-screen renders as well.
  63. */
  64. int vk_render_finish(struct vk_render_essentials *essentials, struct vk_device *dev,
  65. struct vk_swapchain *swapchain, VkImageLayout from_layout, uint32_t image_index,
  66. VkSemaphore wait_sem, VkSemaphore signal_sem);
  67. #endif