wgpu: Bump to `0.13.0`

Based on the work in #6717, plus additional adaptions mentioned in
https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#wgpu-013-2022-06-30,
and more not-mentioned but required changes.

Also bump `wasm-bindgen` to `0.2.81` (along with its helper crates), as
required by the new `wgpu` version.

Note that I don't fully understand some of the required changes, notably:
* `wgpu::PresentMode::Mailbox` no longer works on my machine (Windows 11) -
The `wgpu` documentation says that `wgpu::PresentMode::Fifo` is the
only guaranteed to be supported, so I switched over to it instead.
* `self.staging_belt.recall()` doesn't return a `Future` anymore -
I assume it became synchronous so I simply removed the `executor`
from there.
This commit is contained in:
relrelb 2022-07-02 15:18:30 +03:00 committed by Mike Welsh
parent e219cb3b1c
commit 65be2adc63
22 changed files with 194 additions and 252 deletions

View File

@ -318,7 +318,7 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: install command: install
args: wasm-bindgen-cli --version 0.2.80 args: wasm-bindgen-cli --version 0.2.81
- name: Setup conda - name: Setup conda
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2

View File

@ -55,7 +55,7 @@ jobs:
# wasm-bindgen-cli version must match wasm-bindgen crate version. # wasm-bindgen-cli version must match wasm-bindgen crate version.
# Be sure to update in release_nightly.yml, web/Cargo.toml and web/README.md. # Be sure to update in release_nightly.yml, web/Cargo.toml and web/README.md.
- name: Install wasm-bindgen - name: Install wasm-bindgen
run: cargo install wasm-bindgen-cli --version 0.2.80 run: cargo install wasm-bindgen-cli --version 0.2.81
- name: Setup conda - name: Setup conda
uses: conda-incubator/setup-miniconda@v2 uses: conda-incubator/setup-miniconda@v2

88
Cargo.lock generated
View File

@ -56,6 +56,15 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "android_system_properties"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a20ae67ce26261f218e2b3f2f0d01887a9818283ca6fb260fa7c67e253d61c92"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "ansi_term" name = "ansi_term"
version = "0.12.1" version = "0.12.1"
@ -91,9 +100,9 @@ dependencies = [
[[package]] [[package]]
name = "ash" name = "ash"
version = "0.34.0+1.2.203" version = "0.37.0+1.3.209"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0f780da53d0063880d45554306489f09dd8d1bda47688b4a57bc579119356df" checksum = "006ca68e0f2b03f22d6fa9f2860f85aed430d257fec20f8879b2145e7c7ae1a6"
dependencies = [ dependencies = [
"libloading", "libloading",
] ]
@ -856,9 +865,9 @@ dependencies = [
[[package]] [[package]]
name = "d3d12" name = "d3d12"
version = "0.4.1" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" checksum = "827914e1f53b1e0e025ecd3d967a7836b7bcb54520f90e21ef8df7b4d88a2759"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"libloading", "libloading",
@ -1873,9 +1882,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.57" version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -1888,6 +1897,7 @@ checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3"
dependencies = [ dependencies = [
"libc", "libc",
"libloading", "libloading",
"pkg-config",
] ]
[[package]] [[package]]
@ -1923,9 +1933,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.120" version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]] [[package]]
name = "libflate" name = "libflate"
@ -2108,9 +2118,9 @@ dependencies = [
[[package]] [[package]]
name = "metal" name = "metal"
version = "0.23.1" version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0514f491f4cc03632ab399ee01e2c1c1b12d3e1cf2d667c1ff5f87d6dcd2084" checksum = "de11355d1f6781482d027a3b4d4de7825dcedb197bf573e0596d00008402d060"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"block", "block",
@ -2186,9 +2196,9 @@ dependencies = [
[[package]] [[package]]
name = "naga" name = "naga"
version = "0.8.5" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3012f2dbcc79e8e0b5825a4836a7106a75dd9b2fe42c528163be0f572538c705" checksum = "5f50357e1167a3ab92d6b3c7f4bf5f7fd13fde3f4b28bf0d5ea07b5100fdb6c0"
dependencies = [ dependencies = [
"bit-set", "bit-set",
"bitflags", "bitflags",
@ -2200,7 +2210,9 @@ dependencies = [
"rustc-hash", "rustc-hash",
"serde", "serde",
"spirv", "spirv",
"termcolor",
"thiserror", "thiserror",
"unicode-xid",
] ]
[[package]] [[package]]
@ -3135,7 +3147,6 @@ dependencies = [
"raw-window-handle", "raw-window-handle",
"ruffle_core", "ruffle_core",
"ruffle_render_common_tess", "ruffle_render_common_tess",
"wasm-bindgen-futures",
"web-sys", "web-sys",
"wgpu", "wgpu",
] ]
@ -3784,9 +3795,9 @@ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.2" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]] [[package]]
name = "url" name = "url"
@ -3863,9 +3874,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.80" version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"serde", "serde",
@ -3875,9 +3886,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.80" version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
@ -3890,9 +3901,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.30" version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"js-sys", "js-sys",
@ -3902,9 +3913,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.80" version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -3912,9 +3923,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.80" version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3925,9 +3936,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.80" version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
[[package]] [[package]]
name = "wayland-client" name = "wayland-client"
@ -4010,9 +4021,9 @@ checksum = "323f4da9523e9a669e1eaf9c6e763892769b1d38c623913647bfdc1532fe4549"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.57" version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -4049,9 +4060,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97cd781ff044d6d697b632a2e212032c2e957d1afaa21dbf58069cbb8f78567" checksum = "fd28e7c69ffd19c02e609322e4170738ac3340e699d8adfa16f5745625e4aa8c"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec 0.7.2",
"js-sys", "js-sys",
@ -4071,11 +4082,12 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-core" name = "wgpu-core"
version = "0.12.2" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4688c000eb841ca55f7b35db659b78d6e1cd77d7caf8fb929f4e181f754047d" checksum = "0bb155661d02bf104303589fbf9206fa971c80dbb6d4763e66879253bd0a072c"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec 0.7.2",
"bit-vec",
"bitflags", "bitflags",
"cfg_aliases", "cfg_aliases",
"codespan-reporting", "codespan-reporting",
@ -4090,16 +4102,18 @@ dependencies = [
"serde", "serde",
"smallvec", "smallvec",
"thiserror", "thiserror",
"web-sys",
"wgpu-hal", "wgpu-hal",
"wgpu-types", "wgpu-types",
] ]
[[package]] [[package]]
name = "wgpu-hal" name = "wgpu-hal"
version = "0.12.4" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93b1a9400e8d7f32dd4dd909bb9a391015d70633d639775ddd3f14d1104bc970" checksum = "a9f9cb367209e2ad214afa8d823348334994dc1579f4a521d53a3bc4d0848e73"
dependencies = [ dependencies = [
"android_system_properties",
"arrayvec 0.7.2", "arrayvec 0.7.2",
"ash", "ash",
"bit-set", "bit-set",
@ -4134,9 +4148,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "549533d9e1cdd4b4cda7718d33ff500fc4c34b5467b71d76b547ae0324f3b2a2" checksum = "f48d691b733b9d50ea8cb18f377fd1ed927c90c55ad1ec5b90f68885471977f7"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bitflags_serde_shim", "bitflags_serde_shim",

View File

@ -56,7 +56,7 @@ default-features = false # can't use rayon on web
version = "0.3.21" version = "0.3.21"
[target.'cfg(target_family = "wasm")'.dependencies.wasm-bindgen-futures] [target.'cfg(target_family = "wasm")'.dependencies.wasm-bindgen-futures]
version = "0.4.30" version = "0.4.31"
[dev-dependencies] [dev-dependencies]
approx = "0.5.1" approx = "0.5.1"

View File

@ -122,8 +122,7 @@ fn take_screenshot(
.renderer_mut() .renderer_mut()
.downcast_mut::<WgpuRenderBackend<TextureTarget>>() .downcast_mut::<WgpuRenderBackend<TextureTarget>>()
.unwrap(); .unwrap();
let target = renderer.target(); if let Some(image) = renderer.target().capture() {
if let Some(image) = target.capture(renderer.device()) {
result.push(image); result.push(image);
} else { } else {
return Err(format!("Unable to capture frame {} of {:?}", i, swf_path).into()); return Err(format!("Unable to capture frame {} of {:?}", i, swf_path).into());

View File

@ -6,10 +6,10 @@ edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
js-sys = "0.3.57" js-sys = "0.3.58"
log = "0.4" log = "0.4"
ruffle_web_common = { path = "../../web/common" } ruffle_web_common = { path = "../../web/common" }
wasm-bindgen = "=0.2.80" wasm-bindgen = "=0.2.81"
fnv = "1.0.7" fnv = "1.0.7"
[dependencies.ruffle_core] [dependencies.ruffle_core]
@ -17,7 +17,7 @@ path = "../../core"
default-features = false default-features = false
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3.57" version = "0.3.58"
features = [ features = [
"CanvasGradient", "CanvasPattern", "CanvasRenderingContext2d", "CanvasWindingRule", "CssStyleDeclaration", "CanvasGradient", "CanvasPattern", "CanvasRenderingContext2d", "CanvasWindingRule", "CssStyleDeclaration",
"Document", "DomMatrix", "Element", "HtmlCanvasElement", "ImageData", "Navigator", "Path2d", "SvgMatrix", "Document", "DomMatrix", "Element", "HtmlCanvasElement", "ImageData", "Navigator", "Path2d", "SvgMatrix",

View File

@ -6,11 +6,11 @@ edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
js-sys = "0.3.57" js-sys = "0.3.58"
log = "0.4" log = "0.4"
ruffle_render_common_tess = { path = "../common_tess" } ruffle_render_common_tess = { path = "../common_tess" }
ruffle_web_common = { path = "../../web/common" } ruffle_web_common = { path = "../../web/common" }
wasm-bindgen = "=0.2.80" wasm-bindgen = "=0.2.81"
bytemuck = { version = "1.9.1", features = ["derive"] } bytemuck = { version = "1.9.1", features = ["derive"] }
fnv = "1.0.7" fnv = "1.0.7"
@ -19,7 +19,7 @@ path = "../../core"
default-features = false default-features = false
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3.57" version = "0.3.58"
features = [ features = [
"HtmlCanvasElement", "OesVertexArrayObject", "WebGl2RenderingContext", "WebGlBuffer", "WebglDebugRendererInfo", "HtmlCanvasElement", "OesVertexArrayObject", "WebGl2RenderingContext", "WebGlBuffer", "WebglDebugRendererInfo",
"WebGlFramebuffer", "WebGlProgram", "WebGlRenderbuffer", "WebGlRenderingContext", "WebGlShader", "WebGlTexture", "WebGlFramebuffer", "WebGlProgram", "WebGlRenderbuffer", "WebGlRenderingContext", "WebGlShader", "WebGlTexture",

View File

@ -6,6 +6,7 @@ edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
wgpu = "0.13.0"
log = "0.4" log = "0.4"
ruffle_core = { path = "../../core", default-features = false } ruffle_core = { path = "../../core", default-features = false }
ruffle_render_common_tess = { path = "../common_tess" } ruffle_render_common_tess = { path = "../common_tess" }
@ -16,27 +17,18 @@ enum-map = "2.4.0"
fnv = "1.0.7" fnv = "1.0.7"
# desktop # desktop
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.futures] [target.'cfg(not(target_family = "wasm"))'.dependencies.futures]
version = "0.3.21" version = "0.3.21"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.image] [target.'cfg(not(target_family = "wasm"))'.dependencies.image]
version = "0.24.2" version = "0.24.2"
default-features = false default-features = false
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgpu]
version = "0.12"
# wasm # wasm
[target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen-futures] [target.'cfg(target_family = "wasm")'.dependencies.web-sys]
version = "0.4.30" version = "0.3.58"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.57"
features = ["HtmlCanvasElement"] features = ["HtmlCanvasElement"]
[target.'cfg(target_arch = "wasm32")'.dependencies.wgpu]
version = "0.12"
[features] [features]
render_debug_labels = [] render_debug_labels = []
render_trace = ["wgpu/trace"] render_trace = ["wgpu/trace"]

View File

@ -1,27 +1,24 @@
/// Shader used for drawing bitmap fills. /// Shader used for drawing bitmap fills.
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] uv: vec2<f32>; @location(0) uv: vec2<f32>,
}; };
[[group(2), binding(0)]] @group(2) @binding(0) var<uniform> textureTransforms: TextureTransforms;
var<uniform> textureTransforms: TextureTransforms; @group(2) @binding(1) var texture: texture_2d<f32>;
[[group(2), binding(1)]] @group(3) @binding(0) var texture_sampler: sampler;
var texture: texture_2d<f32>;
[[group(3), binding(0)]]
var texture_sampler: sampler;
[[stage(vertex)]] @vertex
fn main_vertex(in: VertexInput) -> VertexOutput { fn main_vertex(in: VertexInput) -> VertexOutput {
let matrix = textureTransforms.matrix; let matrix_ = textureTransforms.matrix_;
let uv = (mat3x3<f32>(matrix[0].xyz, matrix[1].xyz, matrix[2].xyz) * vec3<f32>(in.position, 1.0)).xy; let uv = (mat3x3<f32>(matrix_[0].xyz, matrix_[1].xyz, matrix_[2].xyz) * vec3<f32>(in.position, 1.0)).xy;
let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0); let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
return VertexOutput(pos, uv); return VertexOutput(pos, uv);
} }
[[stage(fragment)]] @fragment
fn main_fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> { fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
var color: vec4<f32> = textureSample(texture, texture_sampler, in.uv); var color: vec4<f32> = textureSample(texture, texture_sampler, in.uv);
// Texture is premultiplied by alpha. // Texture is premultiplied by alpha.
// Unmultiply alpha, apply color transform, remultiply alpha. // Unmultiply alpha, apply color transform, remultiply alpha.

View File

@ -1,11 +1,11 @@
/// Shader used for drawing solid color fills. /// Shader used for drawing solid color fills.
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] color: vec4<f32>; @location(0) color: vec4<f32>,
}; };
[[stage(vertex)]] @vertex
fn main_vertex(in: VertexInput) -> VertexOutput { fn main_vertex(in: VertexInput) -> VertexOutput {
let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0); let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
let color = in.color * transforms.mult_color + transforms.add_color; let color = in.color * transforms.mult_color + transforms.add_color;
@ -13,7 +13,7 @@ fn main_vertex(in: VertexInput) -> VertexOutput {
return VertexOutput(pos, vec4<f32>(color.rgb * alpha, alpha)); return VertexOutput(pos, vec4<f32>(color.rgb * alpha, alpha));
} }
[[stage(fragment)]] @fragment
fn main_fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> { fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color; return in.color;
} }

View File

@ -4,53 +4,51 @@
/// Global uniforms that are constant throughout a frame. /// Global uniforms that are constant throughout a frame.
struct Globals { struct Globals {
// The view matrix determined by the viewport and stage. // The view matrix determined by the viewport and stage.
view_matrix: mat4x4<f32>; view_matrix: mat4x4<f32>,
}; };
/// Transform uniforms that are changed per object. /// Transform uniforms that are changed per object.
struct Transforms { struct Transforms {
/// The world matrix that transforms this object into stage space. /// The world matrix that transforms this object into stage space.
world_matrix: mat4x4<f32>; world_matrix: mat4x4<f32>,
/// The multiplicative color transform of this object. /// The multiplicative color transform of this object.
mult_color: vec4<f32>; mult_color: vec4<f32>,
/// The additive color transform of this object. /// The additive color transform of this object.
add_color: vec4<f32>; add_color: vec4<f32>,
}; };
/// Uniforms used by texture draws (bitmaps and gradients). /// Uniforms used by texture draws (bitmaps and gradients).
struct TextureTransforms { struct TextureTransforms {
/// The transform matrix of the gradient or texture. /// The transform matrix of the gradient or texture.
/// Transforms from object space to UV space. /// Transforms from object space to UV space.
matrix: mat4x4<f32>; matrix_: mat4x4<f32>,
}; };
/// The vertex format shared among all shaders. /// The vertex format shared among all shaders.
struct VertexInput { struct VertexInput {
/// The position of the vertex in object space. /// The position of the vertex in object space.
[[location(0)]] position: vec2<f32>; @location(0) position: vec2<f32>,
/// The color of this vertex (only used by the color shader). /// The color of this vertex (only used by the color shader).
[[location(1)]] color: vec4<f32>; @location(1) color: vec4<f32>,
}; };
/// Common uniform layout shared by all shaders. /// Common uniform layout shared by all shaders.
[[group(0), binding(0)]] @group(0) @binding(0) var<uniform> globals: Globals;
var<uniform> globals: Globals; @group(1) @binding(0) var<uniform> transforms: Transforms;
[[group(1), binding(0)]]
var<uniform> transforms: Transforms;
/// Converts a color from linear to sRGB color space. /// Converts a color from linear to sRGB color space.
fn linear_to_srgb(linear: vec4<f32>) -> vec4<f32> { fn linear_to_srgb(linear_: vec4<f32>) -> vec4<f32> {
var rgb: vec3<f32> = linear.rgb; var rgb: vec3<f32> = linear_.rgb;
if( linear.a > 0.0 ) { if( linear_.a > 0.0 ) {
rgb = rgb / linear.a; rgb = rgb / linear_.a;
} }
let a = 12.92 * rgb; let a = 12.92 * rgb;
let b = 1.055 * pow(rgb, vec3<f32>(1.0 / 2.4)) - 0.055; let b = 1.055 * pow(rgb, vec3<f32>(1.0 / 2.4)) - 0.055;
let c = step(vec3<f32>(0.0031308), rgb); let c = step(vec3<f32>(0.0031308), rgb);
return vec4<f32>(mix(a, b, c) * linear.a, linear.a); return vec4<f32>(mix(a, b, c) * linear_.a, linear_.a);
} }
/// Converts a color from sRGB to linear color space. /// Converts a color from sRGB to linear color space.

View File

@ -1,26 +1,23 @@
/// Shader used for drawing bitmap fills. /// Shader used for drawing bitmap fills.
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] uv: vec2<f32>; @location(0) uv: vec2<f32>,
}; };
[[group(2), binding(0)]] @group(2) @binding(0) var<uniform> textureTransforms: TextureTransforms;
var<uniform> textureTransforms: TextureTransforms; @group(2) @binding(1) var texture: texture_2d<f32>;
[[group(2), binding(1)]] @group(3) @binding(0) var texture_sampler: sampler;
var texture: texture_2d<f32>;
[[group(3), binding(0)]]
var texture_sampler: sampler;
[[stage(vertex)]] @vertex
fn main_vertex(in: VertexInput) -> VertexOutput { fn main_vertex(in: VertexInput) -> VertexOutput {
let matrix = textureTransforms.matrix; let matrix_ = textureTransforms.matrix_;
let uv = (mat3x3<f32>(matrix[0].xyz, matrix[1].xyz, matrix[2].xyz) * vec3<f32>(in.position, 1.0)).xy; let uv = (mat3x3<f32>(matrix_[0].xyz, matrix_[1].xyz, matrix_[2].xyz) * vec3<f32>(in.position, 1.0)).xy;
let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0); let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
return VertexOutput(pos, uv); return VertexOutput(pos, uv);
} }
[[stage(fragment)]] @fragment
fn main_fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> { fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return srgb_to_linear(textureSample(texture, texture_sampler, in.uv)); return srgb_to_linear(textureSample(texture, texture_sampler, in.uv));
} }

View File

@ -1,35 +1,33 @@
/// Shader used for drawing all flavors of gradients. /// Shader used for drawing all flavors of gradients.
struct Gradient { struct Gradient {
colors: array<vec4<f32>,16u>; colors: array<vec4<f32>,16u>,
ratios: array<f32,16u>; ratios: array<f32,16u>,
gradient_type: i32; gradient_type: i32,
num_colors: u32; num_colors: u32,
repeat_mode: i32; repeat_mode: i32,
interpolation: i32; interpolation: i32,
focal_point: f32; focal_point: f32,
}; };
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] uv: vec2<f32>; @location(0) uv: vec2<f32>,
}; };
[[group(2), binding(0)]] @group(2) @binding(0) var<uniform> textureTransforms: TextureTransforms;
var<uniform> textureTransforms: TextureTransforms; @group(2) @binding(1) var<storage> gradient: Gradient;
[[group(2), binding(1)]]
var<storage> gradient: Gradient;
[[stage(vertex)]] @vertex
fn main_vertex(in: VertexInput) -> VertexOutput { fn main_vertex(in: VertexInput) -> VertexOutput {
let matrix = textureTransforms.matrix; let matrix_ = textureTransforms.matrix_;
let uv = (mat3x3<f32>(matrix[0].xyz, matrix[1].xyz, matrix[2].xyz) * vec3<f32>(in.position, 1.0)).xy; let uv = (mat3x3<f32>(matrix_[0].xyz, matrix_[1].xyz, matrix_[2].xyz) * vec3<f32>(in.position, 1.0)).xy;
let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0); let pos = globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
return VertexOutput(pos, uv); return VertexOutput(pos, uv);
} }
[[stage(fragment)]] @fragment
fn main_fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> { fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
let last = gradient.num_colors - 1u; let last = gradient.num_colors - 1u;
// Calculate normalized `t` position in gradient, [0.0, 1.0] being the bounds of the ratios. // Calculate normalized `t` position in gradient, [0.0, 1.0] being the bounds of the ratios.

View File

@ -1,5 +1,8 @@
use crate::bitmaps::BitmapSamplers;
use crate::globals::Globals;
use crate::pipelines::Pipelines; use crate::pipelines::Pipelines;
use crate::target::{RenderTarget, RenderTargetFrame, SwapChainTarget}; use crate::target::{RenderTarget, RenderTargetFrame, SwapChainTarget};
use crate::uniform_buffer::UniformBuffer;
use crate::utils::{create_buffer_with_data, format_list, get_backend_names}; use crate::utils::{create_buffer_with_data, format_list, get_backend_names};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use enum_map::Enum; use enum_map::Enum;
@ -15,6 +18,8 @@ use ruffle_render_common_tess::{
Vertex as TessVertex, Vertex as TessVertex,
}; };
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::path::Path;
pub use wgpu;
type Error = Box<dyn std::error::Error>; type Error = Box<dyn std::error::Error>;
@ -30,12 +35,6 @@ mod uniform_buffer;
#[cfg(feature = "clap")] #[cfg(feature = "clap")]
pub mod clap; pub mod clap;
use crate::bitmaps::BitmapSamplers;
use crate::globals::Globals;
use crate::uniform_buffer::UniformBuffer;
use std::path::Path;
pub use wgpu;
pub struct Descriptors { pub struct Descriptors {
pub device: wgpu::Device, pub device: wgpu::Device,
pub info: wgpu::AdapterInfo, pub info: wgpu::AdapterInfo,
@ -95,20 +94,13 @@ impl Descriptors {
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => wgpu::TextureFormat::Etc2Rgb8Unorm, wgpu::TextureFormat::Etc2Rgb8UnormSrgb => wgpu::TextureFormat::Etc2Rgb8Unorm,
wgpu::TextureFormat::Etc2Rgb8A1UnormSrgb => wgpu::TextureFormat::Etc2Rgb8A1Unorm, wgpu::TextureFormat::Etc2Rgb8A1UnormSrgb => wgpu::TextureFormat::Etc2Rgb8A1Unorm,
wgpu::TextureFormat::Etc2Rgba8UnormSrgb => wgpu::TextureFormat::Etc2Rgba8Unorm, wgpu::TextureFormat::Etc2Rgba8UnormSrgb => wgpu::TextureFormat::Etc2Rgba8Unorm,
wgpu::TextureFormat::Astc4x4RgbaUnormSrgb => wgpu::TextureFormat::Astc4x4RgbaUnorm, wgpu::TextureFormat::Astc {
wgpu::TextureFormat::Astc5x4RgbaUnormSrgb => wgpu::TextureFormat::Astc5x4RgbaUnorm, block,
wgpu::TextureFormat::Astc5x5RgbaUnormSrgb => wgpu::TextureFormat::Astc5x5RgbaUnorm, channel: wgpu::AstcChannel::UnormSrgb,
wgpu::TextureFormat::Astc6x5RgbaUnormSrgb => wgpu::TextureFormat::Astc6x5RgbaUnorm, } => wgpu::TextureFormat::Astc {
wgpu::TextureFormat::Astc6x6RgbaUnormSrgb => wgpu::TextureFormat::Astc6x6RgbaUnorm, block,
wgpu::TextureFormat::Astc8x5RgbaUnormSrgb => wgpu::TextureFormat::Astc8x5RgbaUnorm, channel: wgpu::AstcChannel::Unorm,
wgpu::TextureFormat::Astc8x6RgbaUnormSrgb => wgpu::TextureFormat::Astc8x6RgbaUnorm, },
wgpu::TextureFormat::Astc10x5RgbaUnormSrgb => wgpu::TextureFormat::Astc10x5RgbaUnorm,
wgpu::TextureFormat::Astc10x6RgbaUnormSrgb => wgpu::TextureFormat::Astc10x6RgbaUnorm,
wgpu::TextureFormat::Astc8x8RgbaUnormSrgb => wgpu::TextureFormat::Astc8x8RgbaUnorm,
wgpu::TextureFormat::Astc10x8RgbaUnormSrgb => wgpu::TextureFormat::Astc10x8RgbaUnorm,
wgpu::TextureFormat::Astc10x10RgbaUnormSrgb => wgpu::TextureFormat::Astc10x10RgbaUnorm,
wgpu::TextureFormat::Astc12x10RgbaUnormSrgb => wgpu::TextureFormat::Astc12x10RgbaUnorm,
wgpu::TextureFormat::Astc12x12RgbaUnormSrgb => wgpu::TextureFormat::Astc12x12RgbaUnorm,
_ => surface_format, _ => surface_format,
}; };
@ -316,7 +308,7 @@ impl WgpuRenderBackend<SwapChainTarget> {
#[cfg(target_family = "wasm")] #[cfg(target_family = "wasm")]
pub async fn for_canvas(canvas: &web_sys::HtmlCanvasElement) -> Result<Self, Error> { pub async fn for_canvas(canvas: &web_sys::HtmlCanvasElement) -> Result<Self, Error> {
let instance = wgpu::Instance::new(wgpu::Backends::BROWSER_WEBGPU); let instance = wgpu::Instance::new(wgpu::Backends::BROWSER_WEBGPU);
let surface = unsafe { instance.create_surface_from_canvas(canvas) }; let surface = instance.create_surface_from_canvas(canvas);
let descriptors = Self::build_descriptors( let descriptors = Self::build_descriptors(
wgpu::Backends::BROWSER_WEBGPU, wgpu::Backends::BROWSER_WEBGPU,
instance, instance,
@ -533,7 +525,7 @@ impl<T: RenderTarget> WgpuRenderBackend<T> {
.await?; .await?;
let info = adapter.get_info(); let info = adapter.get_info();
let surface_format = surface let surface_format = surface
.and_then(|surface| surface.get_preferred_format(&adapter)) .and_then(|surface| surface.get_supported_formats(&adapter).first().copied())
.unwrap_or(wgpu::TextureFormat::Rgba8Unorm); .unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
Descriptors::new(device, queue, info, surface_format) Descriptors::new(device, queue, info, surface_format)
} }
@ -741,10 +733,6 @@ impl<T: RenderTarget> WgpuRenderBackend<T> {
pub fn target(&self) -> &T { pub fn target(&self) -> &T {
&self.target &self.target
} }
pub fn device(&self) -> &wgpu::Device {
&self.descriptors.device
}
} }
impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> { impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
@ -921,7 +909,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
}; };
let render_pass = frame_data.0.begin_render_pass(&wgpu::RenderPassDescriptor { let render_pass = frame_data.0.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: color_view, view: color_view,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color { load: wgpu::LoadOp::Clear(wgpu::Color {
@ -933,7 +921,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
store: true, store: true,
}, },
resolve_target, resolve_target,
}], })],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture_view, view: &self.depth_texture_view,
depth_ops: Some(wgpu::Operations { depth_ops: Some(wgpu::Operations {
@ -1237,14 +1225,14 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
); );
let mut render_pass = copy_encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut render_pass = copy_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &frame.frame_data.1.view(), view: &frame.frame_data.1.view(),
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
store: true, store: true,
}, },
resolve_target: None, resolve_target: None,
}], })],
depth_stencil_attachment: None, depth_stencil_attachment: None,
label: None, label: None,
}); });

View File

@ -188,11 +188,11 @@ impl Pipelines {
&copy_srgb_shader, &copy_srgb_shader,
&copy_texture_pipeline_layout, &copy_texture_pipeline_layout,
None, None,
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format: surface_format, format: surface_format,
blend: Some(wgpu::BlendState::REPLACE), blend: Some(wgpu::BlendState::REPLACE),
write_mask: Default::default(), write_mask: Default::default(),
}], })],
&vertex_buffers_description, &vertex_buffers_description,
1, 1,
)); ));
@ -225,8 +225,7 @@ fn create_shader(
label: label.as_deref(), label: label.as_deref(),
source: wgpu::ShaderSource::Wgsl(src.into()), source: wgpu::ShaderSource::Wgsl(src.into()),
}; };
device.create_shader_module(desc)
device.create_shader_module(&desc)
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -236,7 +235,7 @@ fn create_pipeline_descriptor<'a>(
fragment_shader: &'a wgpu::ShaderModule, fragment_shader: &'a wgpu::ShaderModule,
pipeline_layout: &'a wgpu::PipelineLayout, pipeline_layout: &'a wgpu::PipelineLayout,
depth_stencil_state: Option<wgpu::DepthStencilState>, depth_stencil_state: Option<wgpu::DepthStencilState>,
color_target_state: &'a [wgpu::ColorTargetState], color_target_state: &'a [Option<wgpu::ColorTargetState>],
vertex_buffer_layout: &'a [wgpu::VertexBufferLayout<'a>], vertex_buffer_layout: &'a [wgpu::VertexBufferLayout<'a>],
msaa_sample_count: u32, msaa_sample_count: u32,
) -> wgpu::RenderPipelineDescriptor<'a> { ) -> wgpu::RenderPipelineDescriptor<'a> {
@ -304,11 +303,11 @@ fn create_color_pipelines(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_description, vertex_buffers_description,
msaa_sample_count, msaa_sample_count,
)) ))
@ -328,11 +327,11 @@ fn create_color_pipelines(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_description, vertex_buffers_description,
msaa_sample_count, msaa_sample_count,
)) ))
@ -352,11 +351,11 @@ fn create_color_pipelines(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_description, vertex_buffers_description,
msaa_sample_count, msaa_sample_count,
)) ))
@ -376,11 +375,11 @@ fn create_color_pipelines(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_description, vertex_buffers_description,
msaa_sample_count, msaa_sample_count,
)) ))
@ -429,11 +428,11 @@ fn create_bitmap_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -453,11 +452,11 @@ fn create_bitmap_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -477,11 +476,11 @@ fn create_bitmap_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -501,11 +500,11 @@ fn create_bitmap_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -552,11 +551,11 @@ fn create_gradient_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -576,11 +575,11 @@ fn create_gradient_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -601,11 +600,11 @@ fn create_gradient_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))
@ -625,11 +624,11 @@ fn create_gradient_pipeline(
stencil, stencil,
bias: Default::default(), bias: Default::default(),
}), }),
&[wgpu::ColorTargetState { &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING), blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
write_mask, write_mask,
}], })],
vertex_buffers_layout, vertex_buffers_layout,
msaa_sample_count, msaa_sample_count,
)) ))

View File

@ -58,7 +58,7 @@ impl SwapChainTarget {
format, format,
width: size.0, width: size.0,
height: size.1, height: size.1,
present_mode: wgpu::PresentMode::Mailbox, present_mode: wgpu::PresentMode::Fifo,
}; };
surface.configure(device, &surface_config); surface.configure(device, &surface_config);
Self { Self {
@ -165,10 +165,19 @@ impl TextureTarget {
} }
} }
pub fn capture(&self, device: &wgpu::Device) -> Option<image::RgbaImage> { pub fn capture(&self) -> Option<image::RgbaImage> {
let buffer_future = self.buffer.slice(..).map_async(wgpu::MapMode::Read); use std::sync::mpsc::channel;
device.poll(wgpu::Maintain::Wait);
match futures::executor::block_on(buffer_future) { let (sender, receiver) = channel();
self.buffer
.slice(..)
.map_async(wgpu::MapMode::Read, move |result| {
sender.send(result).unwrap()
});
let result = receiver.recv().unwrap();
match result {
Ok(()) => { Ok(()) => {
let map = self.buffer.slice(..).get_mapped_range(); let map = self.buffer.slice(..).get_mapped_range();
let mut buffer = Vec::with_capacity( let mut buffer = Vec::with_capacity(

View File

@ -9,7 +9,6 @@ pub struct UniformBuffer<T: Pod> {
blocks: Vec<Block>, blocks: Vec<Block>,
buffer_layout: wgpu::BindGroupLayout, buffer_layout: wgpu::BindGroupLayout,
staging_belt: StagingBelt, staging_belt: StagingBelt,
executor: Executor,
aligned_uniforms_size: u32, aligned_uniforms_size: u32,
cur_block: usize, cur_block: usize,
cur_offset: u32, cur_offset: u32,
@ -34,7 +33,6 @@ impl<T: Pod> UniformBuffer<T> {
Self { Self {
blocks: Vec::with_capacity(8), blocks: Vec::with_capacity(8),
buffer_layout, buffer_layout,
executor: Executor::new(),
staging_belt: StagingBelt::new(u64::from(Self::BLOCK_SIZE) / 2), staging_belt: StagingBelt::new(u64::from(Self::BLOCK_SIZE) / 2),
aligned_uniforms_size, aligned_uniforms_size,
cur_block: 0, cur_block: 0,
@ -53,8 +51,7 @@ impl<T: Pod> UniformBuffer<T> {
pub fn reset(&mut self) { pub fn reset(&mut self) {
self.cur_block = 0; self.cur_block = 0;
self.cur_offset = 0; self.cur_offset = 0;
self.executor.spawn_local(self.staging_belt.recall()); self.staging_belt.recall();
self.executor.run_until_stalled();
} }
/// Enqueue `data` for upload into the given command encoder, and set the bind group on `render_pass` /// Enqueue `data` for upload into the given command encoder, and set the bind group on `render_pass`
@ -136,49 +133,3 @@ struct Block {
buffer: wgpu::Buffer, buffer: wgpu::Buffer,
bind_group: wgpu::BindGroup, bind_group: wgpu::BindGroup,
} }
#[cfg(not(target_family = "wasm"))]
struct Executor {
executor: futures::executor::LocalPool,
spawner: futures::executor::LocalSpawner,
}
#[cfg(not(target_family = "wasm"))]
impl Executor {
fn new() -> Self {
let executor = futures::executor::LocalPool::new();
let spawner = executor.spawner();
Self { executor, spawner }
}
fn spawn_local<Fut>(&self, future: Fut)
where
Fut: std::future::Future<Output = ()> + 'static,
{
use futures::task::LocalSpawnExt;
let _ = self.spawner.spawn_local(future);
}
fn run_until_stalled(&mut self) {
self.executor.run_until_stalled();
}
}
#[cfg(target_family = "wasm")]
struct Executor;
#[cfg(target_family = "wasm")]
impl Executor {
fn new() -> Self {
Self
}
fn spawn_local<Fut>(&self, future: Fut)
where
Fut: std::future::Future<Output = ()> + 'static,
{
wasm_bindgen_futures::spawn_local(future);
}
fn run_until_stalled(&mut self) {}
}

View File

@ -1263,9 +1263,9 @@ fn run_swf(
.renderer_mut() .renderer_mut()
.downcast_mut::<WgpuRenderBackend<TextureTarget>>() .downcast_mut::<WgpuRenderBackend<TextureTarget>>()
.unwrap(); .unwrap();
let target = renderer.target(); let actual_image = renderer
let actual_image = target .target()
.capture(renderer.device()) .capture()
.expect("Failed to capture image"); .expect("Failed to capture image");
let expected_image_path = base_path.join("expected.png"); let expected_image_path = base_path.join("expected.png");

View File

@ -32,15 +32,15 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
console_log = { version = "0.2", optional = true } console_log = { version = "0.2", optional = true }
fnv = "1.0.7" fnv = "1.0.7"
generational-arena = "0.2.8" generational-arena = "0.2.8"
js-sys = "0.3.57" js-sys = "0.3.58"
log = { version = "0.4", features = ["serde"] } log = { version = "0.4", features = ["serde"] }
ruffle_render_canvas = { path = "../render/canvas", optional = true } ruffle_render_canvas = { path = "../render/canvas", optional = true }
ruffle_web_common = { path = "common" } ruffle_web_common = { path = "common" }
ruffle_render_webgl = { path = "../render/webgl", optional = true } ruffle_render_webgl = { path = "../render/webgl", optional = true }
ruffle_render_wgpu = { path = "../render/wgpu", optional = true } ruffle_render_wgpu = { path = "../render/wgpu", optional = true }
url = "2.2.2" url = "2.2.2"
wasm-bindgen = { version = "=0.2.80", features = ["serde-serialize"] } wasm-bindgen = { version = "=0.2.81", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.30" wasm-bindgen-futures = "0.4.31"
chrono = { version = "0.4", features = ["wasmbind"] } chrono = { version = "0.4", features = ["wasmbind"] }
getrandom = { version = "0.2", features = ["js"] } getrandom = { version = "0.2", features = ["js"] }
serde = { version = "1.0.137", features = ["derive"] } serde = { version = "1.0.137", features = ["derive"] }
@ -53,7 +53,7 @@ default-features = false
features = ["h263", "vp6", "screenvideo", "wasm-bindgen"] features = ["h263", "vp6", "screenvideo", "wasm-bindgen"]
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3.57" version = "0.3.58"
features = [ features = [
"AddEventListenerOptions", "AudioBuffer", "AudioBufferSourceNode", "AudioContext", "AudioDestinationNode", "AddEventListenerOptions", "AudioBuffer", "AudioBufferSourceNode", "AudioContext", "AudioDestinationNode",
"AudioNode", "AudioParam", "AudioProcessingEvent", "Blob", "BlobPropertyBag", "ChannelMergerNode", "AudioNode", "AudioParam", "AudioProcessingEvent", "Blob", "BlobPropertyBag", "ChannelMergerNode",

View File

@ -58,7 +58,7 @@ Note that npm 7 or newer is required. It should come bundled with Node.js 15 or
<!-- Be sure to also update the wasm-bindgen-cli version in `.github/workflows/*.yml` and `web/Cargo.toml`. --> <!-- Be sure to also update the wasm-bindgen-cli version in `.github/workflows/*.yml` and `web/Cargo.toml`. -->
This can be installed with `cargo install wasm-bindgen-cli --version 0.2.80`. Be sure to install this specific version of `wasm-bindgen-cli` to match the version used by Ruffle. This can be installed with `cargo install wasm-bindgen-cli --version 0.2.81`. Be sure to install this specific version of `wasm-bindgen-cli` to match the version used by Ruffle.
#### Binaryen #### Binaryen

View File

@ -6,10 +6,10 @@ edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
js-sys = "0.3.57" js-sys = "0.3.58"
log = "0.4" log = "0.4"
wasm-bindgen = "=0.2.80" wasm-bindgen = "=0.2.81"
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3.57" version = "0.3.58"
features = ["Window"] features = ["Window"]

View File

@ -1217,7 +1217,7 @@ async fn create_renderer(
// Try to create a backend, falling through to the next backend on failure. // Try to create a backend, falling through to the next backend on failure.
// We must recreate the canvas each attempt, as only a single context may be created per canvas // We must recreate the canvas each attempt, as only a single context may be created per canvas
// with `getContext`. // with `getContext`.
#[cfg(all(feature = "wgpu", target_arch = "wasm32"))] #[cfg(all(feature = "wgpu", target_family = "wasm"))]
{ {
// Check that we have access to WebGPU (navigator.gpu should exist). // Check that we have access to WebGPU (navigator.gpu should exist).
if web_sys::window() if web_sys::window()