.. _stdlib_vulkan_window: =============================================================== Window — surface, swapchain, frame sync, and the present loop =============================================================== .. das:module:: vulkan_window Windowing and presentation: create a ``SurfaceKHR`` from a native window, build and **recreate** a ``Swapchain`` (with its images, views, and framebuffers), set up per-frame ``FrameSync`` primitives, and run the acquire → record → submit → present loop via ``draw_frame``. Pair with ``create_graphics_pipeline_simple(..., dynamic_viewport = true)`` for resize-friendly pipelines. +++++++++ Constants +++++++++ .. _global-vulkan_window-UINT64_MAX: .. das:attribute:: UINT64_MAX = 0xffffffffffffffff UINT64_MAX:uint64 const ++++++++++ Structures ++++++++++ .. _struct-vulkan_window-Swapchain: .. das:attribute:: Swapchain :Fields: * **handle** : :ref:`SwapchainKHR ` - < the VkSwapchainKHR * **format** : :ref:`VkFormat ` - < color format of the swapchain images * **color_space** : :ref:`VkColorSpaceKHR ` - < color space the surface presents in * **width** : int - < current extent width, in pixels * **height** : int - < current extent height, in pixels * **images** : array< :ref:`VkImage `> - < owned by the swapchain object itself; not destroyed here * **views** : array< :ref:`ImageView `> - < created + owned here * **framebuffers** : array< :ref:`Framebuffer `> - < created + owned here (after build_swapchain_framebuffers) * **readback_supported** : bool - < true if the images carry TRANSFER_SRC (host readback is possible) .. _struct-vulkan_window-FrameSync: .. das:attribute:: FrameSync struct FrameSync ++++++++ Surfaces ++++++++ * :ref:`create_surface (instance: Instance; native_window: void?; native_display: void? = null) : SurfaceKHR ` * :ref:`queue_family_supports_present (phys: VkPhysicalDevice; queue_family: uint; surface: SurfaceKHR) : bool ` .. _function-vulkan_window_create_surface_Instance_void_q__void_q_: .. das:function:: create_surface(instance: Instance; native_window: void?; native_display: void? = null) : SurfaceKHR def create_surface (instance: Instance; native_window: void?; native_display: void? = null) : SurfaceKHR :Arguments: * **instance** : :ref:`Instance ` * **native_window** : void? * **native_display** : void? .. _function-vulkan_window_queue_family_supports_present_VkPhysicalDevice_uint_SurfaceKHR: .. das:function:: queue_family_supports_present(phys: VkPhysicalDevice; queue_family: uint; surface: SurfaceKHR) : bool def queue_family_supports_present (phys: VkPhysicalDevice; queue_family: uint; surface: SurfaceKHR) : bool :Arguments: * **phys** : :ref:`VkPhysicalDevice ` * **queue_family** : uint * **surface** : :ref:`SurfaceKHR ` +++++++++ Swapchain +++++++++ * :ref:`build_swapchain_framebuffers (device: Device; var sc: Swapchain; render_pass: RenderPass) ` * :ref:`create_swapchain (device: Device; phys: VkPhysicalDevice; surface: SurfaceKHR; width: int; height: int; preferred_format: VkFormat = vulkan::VkFormat.UNDEFINED) : Swapchain ` * :ref:`recreate_swapchain (var sc: Swapchain; device: Device; phys: VkPhysicalDevice; surface: SurfaceKHR; render_pass: RenderPass; width: int; height: int) ` .. _function-vulkan_window_build_swapchain_framebuffers_Device_Swapchain_RenderPass: .. das:function:: build_swapchain_framebuffers(device: Device; sc: Swapchain; render_pass: RenderPass) def build_swapchain_framebuffers (device: Device; var sc: Swapchain; render_pass: RenderPass) :Arguments: * **device** : :ref:`Device ` * **sc** : :ref:`Swapchain ` * **render_pass** : :ref:`RenderPass ` .. _function-vulkan_window_create_swapchain_Device_VkPhysicalDevice_SurfaceKHR_int_int_VkFormat: .. das:function:: create_swapchain(device: Device; phys: VkPhysicalDevice; surface: SurfaceKHR; width: int; height: int; preferred_format: VkFormat = vulkan::VkFormat.UNDEFINED) : Swapchain def create_swapchain (device: Device; phys: VkPhysicalDevice; surface: SurfaceKHR; width: int; height: int; preferred_format: VkFormat = vulkan::VkFormat.UNDEFINED) : Swapchain :Arguments: * **device** : :ref:`Device ` * **phys** : :ref:`VkPhysicalDevice ` * **surface** : :ref:`SurfaceKHR ` * **width** : int * **height** : int * **preferred_format** : :ref:`VkFormat ` .. _function-vulkan_window_recreate_swapchain_Swapchain_Device_VkPhysicalDevice_SurfaceKHR_RenderPass_int_int: .. das:function:: recreate_swapchain(sc: Swapchain; device: Device; phys: VkPhysicalDevice; surface: SurfaceKHR; render_pass: RenderPass; width: int; height: int) def recreate_swapchain (var sc: Swapchain; device: Device; phys: VkPhysicalDevice; surface: SurfaceKHR; render_pass: RenderPass; width: int; height: int) :Arguments: * **sc** : :ref:`Swapchain ` * **device** : :ref:`Device ` * **phys** : :ref:`VkPhysicalDevice ` * **surface** : :ref:`SurfaceKHR ` * **render_pass** : :ref:`RenderPass ` * **width** : int * **height** : int ++++++++++ Frame sync ++++++++++ * :ref:`create_frame_sync (device: Device) : FrameSync ` .. _function-vulkan_window_create_frame_sync_Device: .. das:function:: create_frame_sync(device: Device) : FrameSync def create_frame_sync (device: Device) : FrameSync :Arguments: * **device** : :ref:`Device ` ++++++++++ Frame loop ++++++++++ * :ref:`draw_frame (device: Device; queue: VkQueue; sc: Swapchain; render_pass: RenderPass; pool: CommandPool; sync: FrameSync; clear: VkClearValue; dynamic_viewport: bool = false; blk: block\<(cmd:CommandBuffer):void\>) : bool ` * :ref:`present_frame (device: Device; queue: VkQueue; sc: Swapchain; pool: CommandPool; sync: FrameSync; blk: block\<(cmd:CommandBuffer;target:VkImage;image_index:uint):void\>) : bool ` .. _function-vulkan_window_draw_frame_Device_VkQueue_Swapchain_RenderPass_CommandPool_FrameSync_VkClearValue_bool_block_ls_cmd_c_CommandBuffer_c_void_gr_: .. das:function:: draw_frame(device: Device; queue: VkQueue; sc: Swapchain; render_pass: RenderPass; pool: CommandPool; sync: FrameSync; clear: VkClearValue; dynamic_viewport: bool = false; blk: block<(cmd:CommandBuffer):void>) : bool def draw_frame (device: Device; queue: VkQueue; sc: Swapchain; render_pass: RenderPass; pool: CommandPool; sync: FrameSync; clear: VkClearValue; dynamic_viewport: bool = false; blk: block<(cmd:CommandBuffer):void>) : bool :Arguments: * **device** : :ref:`Device ` * **queue** : :ref:`VkQueue ` * **sc** : :ref:`Swapchain ` * **render_pass** : :ref:`RenderPass ` * **pool** : :ref:`CommandPool ` * **sync** : :ref:`FrameSync ` * **clear** : :ref:`VkClearValue ` * **dynamic_viewport** : bool * **blk** : block<(cmd: :ref:`CommandBuffer `):void> .. _function-vulkan_window_present_frame_Device_VkQueue_Swapchain_CommandPool_FrameSync_block_ls_cmd_c_CommandBuffer;target_c_VkImage;image_index_c_uint_c_void_gr_: .. das:function:: present_frame(device: Device; queue: VkQueue; sc: Swapchain; pool: CommandPool; sync: FrameSync; blk: block<(cmd:CommandBuffer;target:VkImage;image_index:uint):void>) : bool def present_frame (device: Device; queue: VkQueue; sc: Swapchain; pool: CommandPool; sync: FrameSync; blk: block<(cmd:CommandBuffer;target:VkImage;image_index:uint):void>) : bool :Arguments: * **device** : :ref:`Device ` * **queue** : :ref:`VkQueue ` * **sc** : :ref:`Swapchain ` * **pool** : :ref:`CommandPool ` * **sync** : :ref:`FrameSync ` * **blk** : block<(cmd: :ref:`CommandBuffer `;target: :ref:`VkImage `;image_index:uint):void>