vk_struct.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Danil, 2021+ Vulkan shader launcher, self https://github.com/danilw/vulkan-shadertoy-launcher
  2. // The MIT License
  3. #ifndef vk_struct_H
  4. #define vk_struct_H
  5. #define VK_MAX_QUEUE_FAMILY 10
  6. struct vk_physical_device
  7. {
  8. VkPhysicalDevice physical_device;
  9. VkPhysicalDeviceProperties properties;
  10. VkPhysicalDeviceFeatures features;
  11. VkPhysicalDeviceMemoryProperties memories;
  12. VkQueueFamilyProperties queue_families[VK_MAX_QUEUE_FAMILY];
  13. uint32_t queue_family_count;
  14. bool queue_families_incomplete;
  15. };
  16. struct vk_commands
  17. {
  18. VkQueueFlags qflags;
  19. VkCommandPool pool;
  20. VkQueue *queues;
  21. uint32_t queue_count;
  22. VkCommandBuffer *buffers;
  23. uint32_t buffer_count;
  24. };
  25. struct vk_device
  26. {
  27. VkDevice device;
  28. struct vk_commands *command_pools;
  29. uint32_t command_pool_count;
  30. };
  31. #define VK_MAX_PRESENT_MODES 4
  32. struct vk_swapchain
  33. {
  34. VkSurfaceKHR surface;
  35. VkSwapchainKHR swapchain;
  36. VkSurfaceFormatKHR surface_format;
  37. VkSurfaceCapabilitiesKHR surface_caps;
  38. VkPresentModeKHR present_modes[VK_MAX_PRESENT_MODES];
  39. uint32_t present_modes_count;
  40. };
  41. struct vk_image
  42. {
  43. VkFormat format;
  44. VkExtent2D extent;
  45. VkImageUsageFlagBits usage;
  46. VkShaderStageFlagBits stage;
  47. bool make_view;
  48. bool will_be_initialized;
  49. bool host_visible;
  50. bool multisample;
  51. uint32_t *sharing_queues;
  52. uint32_t sharing_queue_count;
  53. VkImage image;
  54. VkDeviceMemory image_mem;
  55. VkImageView view;
  56. VkSampler sampler;
  57. bool anisotropyEnable;
  58. VkSamplerAddressMode repeat_mode;
  59. bool mipmaps;
  60. bool linear;
  61. };
  62. struct vk_buffer
  63. {
  64. VkFormat format;
  65. uint32_t size;
  66. VkBufferUsageFlagBits usage;
  67. VkShaderStageFlagBits stage;
  68. bool make_view;
  69. bool host_visible;
  70. uint32_t *sharing_queues;
  71. uint32_t sharing_queue_count;
  72. VkBuffer buffer;
  73. VkDeviceMemory buffer_mem;
  74. VkBufferView view;
  75. };
  76. struct vk_shader
  77. {
  78. const char *spirv_file;
  79. VkShaderStageFlagBits stage;
  80. VkShaderModule shader;
  81. };
  82. struct vk_graphics_buffers
  83. {
  84. VkExtent2D surface_size;
  85. VkImage swapchain_image;
  86. VkImageView color_view;
  87. struct vk_image depth;
  88. VkFramebuffer framebuffer;
  89. };
  90. struct vk_render_essentials
  91. {
  92. VkImage *images;
  93. uint32_t image_count;
  94. VkQueue present_queue;
  95. VkCommandBuffer cmd_buffer;
  96. VkSemaphore sem_post_acquire;
  97. VkSemaphore sem_pre_submit;
  98. VkFence exec_fence;
  99. bool first_render;
  100. };
  101. struct vk_resources
  102. {
  103. struct vk_image *images;
  104. uint32_t image_count;
  105. struct vk_buffer *buffers;
  106. uint32_t buffer_count;
  107. struct vk_shader *shaders;
  108. uint32_t shader_count;
  109. VkPushConstantRange *push_constants;
  110. uint32_t push_constant_count;
  111. VkRenderPass render_pass;
  112. };
  113. struct vk_layout
  114. {
  115. struct vk_resources *resources;
  116. VkDescriptorSetLayout set_layout;
  117. VkPipelineLayout pipeline_layout;
  118. };
  119. struct vk_pipeline
  120. {
  121. struct vk_layout *layout;
  122. VkPipelineVertexInputStateCreateInfo vertex_input_state;
  123. VkPipelineInputAssemblyStateCreateInfo input_assembly_state;
  124. VkPipelineTessellationStateCreateInfo tessellation_state;
  125. size_t thread_count;
  126. VkPipeline pipeline;
  127. VkDescriptorPool set_pool;
  128. };
  129. enum vk_render_pass_load_op
  130. {
  131. VK_C_CLEAR = 0,
  132. VK_KEEP = 1,
  133. };
  134. enum vk_make_depth_buffer
  135. {
  136. VK_WITHOUT_DEPTH = 0,
  137. VK_WITH_DEPTH = 1,
  138. };
  139. struct vk_offscreen_buffers
  140. {
  141. VkExtent2D surface_size;
  142. struct vk_image color;
  143. struct vk_image depth;
  144. VkFramebuffer framebuffer;
  145. };
  146. struct app_data_struct{
  147. int iResolution[2]; //resolution
  148. int iMouse[2]; //mouse in window, it always updated (not like iMouse on shadertoy)
  149. int iMouse_lclick[2]; //mouse left click pos (its -[last pos] when left mosue not clicked)
  150. int iMouse_rclick[2]; //mouse right click pos (its -[last pos] when right mosue not clicked)
  151. bool iMouse_click[2]; //is mouse button clicked(left/right)
  152. float iTime; //time
  153. float iTimeDelta; //time delta
  154. int iFrame; //frames
  155. bool pause; //pause clicked
  156. bool quit; //quit clicked/happend
  157. bool drawdebug; //draw debug info, key press
  158. };
  159. #define APP_NAME_STR_LEN 80
  160. struct app_os_window {
  161. #if defined(VK_USE_PLATFORM_WIN32_KHR)
  162. HINSTANCE connection;
  163. HWND window;
  164. POINT minsize;
  165. #elif defined(VK_USE_PLATFORM_XCB_KHR)
  166. Display *display;
  167. xcb_connection_t *connection;
  168. xcb_screen_t *screen;
  169. xcb_window_t xcb_window;
  170. xcb_intern_atom_reply_t *atom_wm_delete_window;
  171. #elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
  172. struct wl_display *display;
  173. struct wl_registry *registry;
  174. struct wl_compositor *compositor;
  175. struct wl_surface *surface;
  176. struct xdg_wm_base *shell;
  177. struct wl_seat *seat;
  178. struct wl_pointer *pointer;
  179. struct wl_keyboard *keyboard;
  180. struct xdg_surface *xdg_surface;
  181. struct xdg_toplevel *xdg_toplevel;
  182. bool configured;
  183. #endif
  184. char name[APP_NAME_STR_LEN];
  185. bool prepared; // is vk setup prepared
  186. bool is_minimized; //window controled events
  187. bool resize_event; //window controled events
  188. bool fps_lock; //key pressed event
  189. bool reload_shaders_on_resize; //launch option
  190. bool print_debug; //launch option
  191. bool pause_refresh; //used only in Windows, on pause when key pressed refresh
  192. VkPresentModeKHR present_mode;
  193. struct app_data_struct app_data;
  194. };
  195. #endif