Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layer observer based on raw-window-metal #7026

Merged
merged 6 commits into from
Feb 20, 2025

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Jan 29, 2025

After #6107, resizing is still broken, and the right way to fix it is to create a sublayer that resizes itself based on the superlayer using key-value observing (see this for an introduction).

I have written a crate for this already, called raw-window-metal and filed #6210, but that crate depends on objc2, which is still under review by Firefox/Mozilla. So in the meantime, let's fix this directly in Wgpu.

Fixes #7011 and a few other issues, and should be fairly cleanly backport-able to v23 or v24 if desired.

I didn't write all that much documentation and safety comments here, and was kinda sloppy in some places, because the hope is that this fix will be temporary.

Testing
Tested by cherry-picking onto v23.1.0, and running Bevy's mobile example in the iOS simulator.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy.
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@madsmtm madsmtm requested a review from a team as a code owner January 29, 2025 21:09
@teoxoy
Copy link
Member

teoxoy commented Feb 11, 2025

The changes look fine to me but it would be nice to get some confirmation from original reporters that this indeed fixes their issues.

cc @polina4096 & I will leave a comment in bevyengine/bevy#16604 as well.

@extrawurst
Copy link

extrawurst commented Feb 11, 2025

I would love to test this but just a normal bevy example (sprite) now fails using that branch:

cargo r --example sprite

...

thread 'main' panicked at /Users/stephan/.cargo/git/checkouts/wgpu-be909407e42442b4/41b4b0f/wgpu/src/backend/wgpu_core.rs:1082:26:
wgpu error: Validation Error

Caused by:
  In Device::create_bind_group_layout, label = 'mesh_view_layout'
    Bind groups may not contain both a binding array and a dynamically offset buffer

just to make sure i have not missed a crate, these are the ones i patched:

[patch.crates-io]
wgpu = { git = "https://github.com/madsmtm/wgpu.git", branch = "metal-layer-observer" }
wgpu-types = { git = "https://github.com/madsmtm/wgpu.git", branch = "metal-layer-observer" }
naga = { git = "https://github.com/madsmtm/wgpu.git", branch = "metal-layer-observer" }

@teoxoy
Copy link
Member

teoxoy commented Feb 12, 2025

That is a new restriction for binding arrays added in #6811.

You could try an example that doesn't use binding arrays or find a way to turn off binding array usage.

@cwfitzgerald - I doubt the new restriction will be a blocker for bevy - but putting it on your radar just in case.

@cwfitzgerald
Copy link
Member

Yeah I'll let them know about it

@cwfitzgerald
Copy link
Member

If no one has tested this by next maintainers meeting, we'll merge it.

@HackerFoo
Copy link

I've tested that this PR works by cherry picking on top of wgpu-v24.0.1, and trying both my app on a device, and the Bevy example in the iOS simulator.

@cwfitzgerald
Copy link
Member

Amazing! Thank you!

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) February 20, 2025 21:20
@cwfitzgerald cwfitzgerald merged commit 7b00140 into gfx-rs:trunk Feb 20, 2025
34 checks passed
@madsmtm madsmtm deleted the metal-layer-observer branch February 20, 2025 21:38
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.

Resizing in iOS doesn't work correctly after #6107
6 participants