Skip to content

Add COPY_SRC to surface usages if supported#3341

Open
maxbergmark wants to merge 1 commit into
iced-rs:masterfrom
maxbergmark:master
Open

Add COPY_SRC to surface usages if supported#3341
maxbergmark wants to merge 1 commit into
iced-rs:masterfrom
maxbergmark:master

Conversation

@maxbergmark
Copy link
Copy Markdown

This mimics the exact changes of #3316, adding COPY_SRC to the surface usage if it is supported. Per the discussion in the other PR, this doesn't work for WASM due to an oversight in wgpu. Possible workarounds to enable support for WASM:

Force COPY_SRC when targeting WebGPU

let capabilities = surface.get_capabilities(&self.adapter);
let has_copy_src = capabilities.usages.contains(wgpu::TextureUsages::COPY_SRC);
let is_webgpu = cfg!(target_arch = "wasm32") && !cfg!(feature = "webgl");
let usage = if has_copy_src || is_webgpu {
    wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC
} else {
    wgpu::TextureUsages::RENDER_ATTACHMENT
};

From my testing, this is supported on most browsers. The only exception so far has been Safari, but that's not related to the COPY_SRC flag.

Add new feature flag to iced to force COPY_SRC

let capabilities = surface.get_capabilities(&self.adapter);
let has_copy_src = capabilities.usages.contains(wgpu::TextureUsages::COPY_SRC);
let usage = if has_copy_src || cfg!(feature = "force_copy_src") {
    wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC
} else {
    wgpu::TextureUsages::RENDER_ATTACHMENT
};

This would be a more prudent solution, making the usage explicit for WASM targets. However, adding a new feature flag for this single use case might not be the cleanest solution.

Completely skip WASM support

As is, this PR will not enable COPY_SRC for WASM targets. This would unfortunately not enable WASM support for crates like iced_glass. However, if the solutions above aren't acceptable this could be an alternative.

I would love to get some input regarding the choices above, or any other potential problems or solutions that I haven't considered.

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.

1 participant