Skip to content

ash-window: Keep loaded fns around via new SurfaceFactory object#1019

Merged
MarijnS95 merged 1 commit into
masterfrom
ash-window-store-loaded-extension
Nov 26, 2025
Merged

ash-window: Keep loaded fns around via new SurfaceFactory object#1019
MarijnS95 merged 1 commit into
masterfrom
ash-window-store-loaded-extension

Conversation

@MarijnS95

@MarijnS95 MarijnS95 commented Nov 21, 2025

Copy link
Copy Markdown
Collaborator

Fixes #974

Even though create_surface() is typically off the hot path, we're repeatedly loading all platform-specific surface function pointers each time a new surface has to be created (sometimes for multiple windows, and on Android after every suspend-resume cycle when the app becomes invisible). In a subsequent patch these loaded extensions can be used to call their respective get_present_support() without reloading the entire function-pointer struct too.

Additionally some users seem to be confused about object lifetimes when seeing this Instance::new() being dropped inside the implementation. This patch only marginally addresses that and users are more than free to just drop their SurfaceFactory object if no longer used (or recreate it later) without having any impact on the "parent/child relationship" mentioned in the fn create_surface() documentation.

For now the choice has been made to store the passed DisplayHandle field with the enum variant when used in create_surface() to reduce ambiguity by not requiring it to be passed again. The user might still pass an incompatible WindowHandle in which case this returns ERROR_EXTENSION_NOT_PRESENT.

StarLederer

This comment was marked as off-topic.

@Ralith Ralith left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice design!

Comment thread ash-window/src/lib.rs Outdated
Comment thread ash-window/examples/winit.rs Outdated
Comment thread ash-window/src/lib.rs Outdated
@MarijnS95 MarijnS95 force-pushed the ash-window-store-loaded-extension branch from 9b92e12 to 1d26882 Compare November 23, 2025 22:01
@MarijnS95 MarijnS95 changed the title ash-window: Keep loaded fns around via new SurfaceExtension object ash-window: Keep loaded fns around via new SurfaceFactory object Nov 23, 2025
@MarijnS95 MarijnS95 force-pushed the ash-window-store-loaded-extension branch from 1d26882 to 989eb03 Compare November 25, 2025 09:33
Comment thread ash-window/src/lib.rs Outdated
Comment thread ash-window/src/lib.rs Outdated
@MarijnS95 MarijnS95 force-pushed the ash-window-store-loaded-extension branch from 989eb03 to 62c59d0 Compare November 26, 2025 17:09
Even though `create_surface()` is typically off the hot path, we're
repeatedly loading all platform-specific surface function pointers each
time a new surface has to be created (sometimes for multiple windows,
and on Android after every suspend-resume cycle when the app becomes
invisible).  In a subsequent patch these loaded extensions can be used
to call their respective `get_present_support()` without reloading the
entire function-pointer struct too.

Additionally some users seem to be confused about object lifetimes when
seeing this `Instance::new()` being dropped inside the implementation.
This patch only marginally addresses that and users are more than
free to just drop their `SurfaceFactory` object if no longer used
(or recreate it later) without having any impact on the "parent/child
relationship" mentioned in the `fn create_surface()` documentation.

For now the choice has been made to store the passed `DisplayHandle`
field with the enum variant when used in `create_surface()` to reduce
ambiguity by not requiring it to be passed again.  The user might
still pass an incompatible `WindowHandle` in which case this returns
`ERROR_EXTENSION_NOT_PRESENT`.
@MarijnS95 MarijnS95 force-pushed the ash-window-store-loaded-extension branch from 62c59d0 to 0d2b61d Compare November 26, 2025 17:11
@MarijnS95 MarijnS95 merged commit c9292cf into master Nov 26, 2025
20 checks passed
@MarijnS95 MarijnS95 deleted the ash-window-store-loaded-extension branch November 26, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ash_window loses access to Surface Instance

3 participants