Add COPY_SRC to Metal's surface usage bits. #4852
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
On machines running Metal, we could not configure surfaces with the
COPY_SRC
usage flag. This flag is used a pretty often on platforms that do support it, and often you'll have macOS users submitting a bug to the root project, which requires them to implement a backbuffer or some other workaround.See "Discussion".
Testing
The simplest way to test is to add a wgpu::TextureUsages::COPY_SRC usage flag to hello_triangle example's surface configuration. Prior to this change (and given you're on macOS), you'll get a panic Error in Surface::configure: requested usage is not supported. This change fixes the panic.
Discussion
I can't find anything that says why this shouldn't be/isn't possible. I've tested the change on an M1 Pro Macbook which works without any issues, and I've even run it with Metal API validation enabled -- no errors. I found this pull request from Feb 2022, which added the
COPY_DST
flag with similar concerns, but no real answers.From reading the Metal documentation (I'm a novice, to be clear), it seems that the flag that really matters is
isFrameBufferOnly
, which we already set appropriately depending on whether the texture usage is onlyRENDER_ATTACHMENT
.So everything seems fine. We could probably allow more flags, but this at least brings things in line with DX12.