Skip to content

Surface API#203

Merged
kvark merged 10 commits into
mainfrom
surface
Nov 17, 2024
Merged

Surface API#203
kvark merged 10 commits into
mainfrom
surface

Conversation

@kvark

@kvark kvark commented Nov 15, 2024

Copy link
Copy Markdown
Owner

Closes #82
TODO:

Begone the init_windowed method. There is only one init now. The other one is replaced by create_surface.

@kvark kvark marked this pull request as ready for review November 15, 2024 08:34
@kvark kvark changed the title Surface API, implementation in Vulkan Surface API Nov 15, 2024
@kvark kvark enabled auto-merge (rebase) November 17, 2024 08:54
@kvark kvark merged commit 2a22fc6 into main Nov 17, 2024
@kvark kvark deleted the surface branch November 17, 2024 09:01
ConradIrwin added a commit to zed-industries/zed that referenced this pull request Dec 18, 2024
Closes #17005

Release Notes:

- Improved GPU context management: share a single context with multiple
surfaces.

### High Level

Blade got a proper support for Surface objects in
kvark/blade#203.
That was mainly motivated by Zed needing to draw multiple windows. With
the Surface API, Zed is now able to have the GPU context tied to the
"Platform" instead of "Window". Practically speaking, this means:
  - architecture more sound
  - faster to open/close windows
  - less surprises, more robust

### Concerns

1. Zed has been using a temporary workaround for the platform bug on
some Intel+Nvidia machines that makes us unable to present -
kvark/blade#144 . This workaround is no longer
available with the new architecture. I'm looking for ideas on how to
approach this better.
- we are now picking up the change in
kvark/blade#210, which allows forcing a specific
Device ID. This should allow Zed users to work around the issue. We
could help them to automate it, too.
2. ~~Metal-rs dependency is switched to
https://github.com/kvark/metal-rs/tree/blade, since upstream isn't
responsive in merging changes that are required for Blade. Hopefully,
temporary.~~
- ~~we can also hack around it by just transmuting the texture
references, since we know those are unchanged in the branch. That would
allow Blade to use it's own version of Metal, temporarily, if switching
metal-rs in the workspace is a concern.~~
- merged my metal-rs changes and updated Zed to use the upstream github
reference

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
@someone13574

someone13574 commented Jan 13, 2025

Copy link
Copy Markdown

I bisected the BadNativeWindow issue on gles wayland to this PR using bunnymark. Haven't tested X11 or or my nvidia system yet.

Edit: X11 fails as well

@kvark

kvark commented Jan 19, 2025

Copy link
Copy Markdown
Owner Author

Yes, GLES support is a bit more difficult with this new API

const EGL_PLATFORM_XCB_EXT: u32 = 0x31DC;
const _EGL_PLATFORM_WAYLAND_KHR: u32 = 0x31D8;
const _EGL_PLATFORM_X11_KHR: u32 = 0x31D5;
const _EGL_PLATFORM_XCB_EXT: u32 = 0x31DC;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is the removal of Wayland / X11 accidental or intentional?

@Vanuan

Vanuan commented Nov 29, 2025

Copy link
Copy Markdown

Is the removal of Wayland / X11 from GLES accidental or intentional?

A bunch of unused variabled in gles/egl:

const _EGL_PLATFORM_WAYLAND_KHR: u32 = 0x31D8;
const _EGL_PLATFORM_X11_KHR: u32 = 0x31D5;
const _EGL_PLATFORM_XCB_EXT: u32 = 0x31DC;

const _EGL_PLATFORM_WAYLAND_KHR: u32 = 0x31D8;
const _EGL_PLATFORM_X11_KHR: u32 = 0x31D5;
const _EGL_PLATFORM_XCB_EXT: u32 = 0x31DC;

@Vanuan

Vanuan commented Nov 30, 2025

Copy link
Copy Markdown

Some investigation on GLES issue:

The engine initialization starts in Engine::new(), which creates a GPU context with presentation: true to indicate windowed rendering. This context description flows to the EGL backend's init() function, where the system queries available EGL extensions to determine what platforms are supported.

The critical issue is that EGL display selection happens here, before any window is created. The code only checks what EGL extensions are available (like ANGLE or surfaceless) but has no information about whether the application will use Wayland, X11, or another window system. This lack of window handle awareness during context initialization leads to selecting an incompatible EGL display, which later fails when trying to create actual window surfaces.

When the surfaceless platform is available, the code unconditionally selects it, creating a display optimized for offscreen rendering that cannot support window surfaces. This mismatch only manifests later when create_surface() is called, causing the BadNativeWindow panic when trying to present to an actual window.

@kvark

kvark commented Apr 13, 2026

Copy link
Copy Markdown
Owner Author

Implementation for EGL has changed a lot in #310. Also related to #331

jasonsmithio pushed a commit to paddleboarddev/paddleboard that referenced this pull request May 31, 2026
Closes #17005

Release Notes:

- Improved GPU context management: share a single context with multiple
surfaces.

### High Level

Blade got a proper support for Surface objects in
kvark/blade#203.
That was mainly motivated by Zed needing to draw multiple windows. With
the Surface API, Zed is now able to have the GPU context tied to the
"Platform" instead of "Window". Practically speaking, this means:
  - architecture more sound
  - faster to open/close windows
  - less surprises, more robust

### Concerns

1. Zed has been using a temporary workaround for the platform bug on
some Intel+Nvidia machines that makes us unable to present -
kvark/blade#144 . This workaround is no longer
available with the new architecture. I'm looking for ideas on how to
approach this better.
- we are now picking up the change in
kvark/blade#210, which allows forcing a specific
Device ID. This should allow Zed users to work around the issue. We
could help them to automate it, too.
2. ~~Metal-rs dependency is switched to
https://github.com/kvark/metal-rs/tree/blade, since upstream isn't
responsive in merging changes that are required for Blade. Hopefully,
temporary.~~
- ~~we can also hack around it by just transmuting the texture
references, since we know those are unchanged in the branch. That would
allow Blade to use it's own version of Metal, temporarily, if switching
metal-rs in the workspace is a concern.~~
- merged my metal-rs changes and updated Zed to use the upstream github
reference

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple windows

3 participants