20.6. Window — surface, swapchain, frame sync, and the present loop
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.
20.6.1. Constants
- UINT64_MAX = 0xffffffffffffffff
UINT64_MAX:uint64 const
20.6.2. Structures
- Swapchain
- Fields:
handle : SwapchainKHR - < the VkSwapchainKHR
format : VkFormat - < color format of the swapchain images
color_space : VkColorSpaceKHR - < color space the surface presents in
width : int - < current extent width, in pixels
height : int - < current extent height, in pixels
images : array< VkImage> - < owned by the swapchain object itself; not destroyed here
views : array< ImageView> - < created + owned here
framebuffers : array< Framebuffer> - < created + owned here (after build_swapchain_framebuffers)
readback_supported : bool - < true if the images carry TRANSFER_SRC (host readback is possible)
- FrameSync
struct FrameSync
20.6.3. Surfaces
- 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 : Instance
native_window : void?
native_display : void?
- 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 : VkPhysicalDevice
queue_family : uint
surface : SurfaceKHR
20.6.4. Swapchain
- build_swapchain_framebuffers(device: Device; sc: Swapchain; render_pass: RenderPass )
def build_swapchain_framebuffers (device: Device; var sc: Swapchain; render_pass: RenderPass)
- Arguments:
device : Device
sc : Swapchain
render_pass : RenderPass
- 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 : Device
phys : VkPhysicalDevice
surface : SurfaceKHR
width : int
height : int
preferred_format : VkFormat
- 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 : Swapchain
device : Device
phys : VkPhysicalDevice
surface : SurfaceKHR
render_pass : RenderPass
width : int
height : int
20.6.5. Frame sync
- create_frame_sync(device: Device ): FrameSync
def create_frame_sync (device: Device) : FrameSync
- Arguments:
device : Device
20.6.6. Frame loop
- 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 : Device
queue : VkQueue
sc : Swapchain
render_pass : RenderPass
pool : CommandPool
sync : FrameSync
clear : VkClearValue
dynamic_viewport : bool
blk : block<(cmd: CommandBuffer):void>
- 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 : Device
queue : VkQueue
sc : Swapchain
pool : CommandPool
sync : FrameSync
blk : block<(cmd: CommandBuffer;target: VkImage;image_index:uint):void>