mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
webgpu: Update wgpu and revamp computepass (#32575)
* Do not wait on drop, but rather wake poller thread * Update wgpu and render stuff * Set some good expectations * Update wgpu again * handle IPC error as warning * More good expectations * Some more expectations CTS does not match the spec: https://github.com/gpuweb/cts/issues/3806 * This expectations are due to other changes in servo also happening on main * Explain error_command_encoders and remove RefCell around it * fixup * store validness of passes * More good expectations * More docs * this assert is wrong * This is even more right per CTS/spec Only Command encoder state errors are allowed here, but wgpu does not exposes them. * More good expectations * One bad expectation * Fix my english
This commit is contained in:
parent
fced0b4940
commit
e9cf4d4971
16 changed files with 372 additions and 1870 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -214,11 +214,11 @@ checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ash"
|
name = "ash"
|
||||||
version = "0.37.3+1.3.251"
|
version = "0.38.0+1.3.281"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a"
|
checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libloading 0.7.4",
|
"libloading 0.8.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1176,10 +1176,10 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "d3d12"
|
name = "d3d12"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu?rev=d0a5e48aa7e84683114c3870051cc414ae92ac03#d0a5e48aa7e84683114c3870051cc414ae92ac03"
|
source = "git+https://github.com/gfx-rs/wgpu?rev=1e784c9c0af7a785b62e3b6840ed012a7477520f#1e784c9c0af7a785b62e3b6840ed012a7477520f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"libloading 0.8.4",
|
"libloading 0.7.4",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2261,9 +2261,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glutin_wgl_sys"
|
name = "glutin_wgl_sys"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6c8098adac955faa2d31079b65dc48841251f69efd3ac25477903fc424362ead"
|
checksum = "0a4e1951bbd9434a81aa496fe59ccc2235af3820d27b85f9314e279609211e2c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gl_generator",
|
"gl_generator",
|
||||||
]
|
]
|
||||||
|
@ -4003,7 +4003,7 @@ checksum = "956787520e75e9bd233246045d19f42fb73242759cc57fba9611d940ae96d4b0"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "naga"
|
name = "naga"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu?rev=d0a5e48aa7e84683114c3870051cc414ae92ac03#d0a5e48aa7e84683114c3870051cc414ae92ac03"
|
source = "git+https://github.com/gfx-rs/wgpu?rev=1e784c9c0af7a785b62e3b6840ed012a7477520f#1e784c9c0af7a785b62e3b6840ed012a7477520f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"bit-set",
|
"bit-set",
|
||||||
|
@ -4012,7 +4012,6 @@ dependencies = [
|
||||||
"hexf-parse",
|
"hexf-parse",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"log",
|
"log",
|
||||||
"num-traits",
|
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
"spirv",
|
"spirv",
|
||||||
|
@ -7295,7 +7294,7 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wgpu-core"
|
name = "wgpu-core"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu?rev=d0a5e48aa7e84683114c3870051cc414ae92ac03#d0a5e48aa7e84683114c3870051cc414ae92ac03"
|
source = "git+https://github.com/gfx-rs/wgpu?rev=1e784c9c0af7a785b62e3b6840ed012a7477520f#1e784c9c0af7a785b62e3b6840ed012a7477520f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"bit-vec",
|
"bit-vec",
|
||||||
|
@ -7313,7 +7312,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"web-sys",
|
|
||||||
"wgpu-hal",
|
"wgpu-hal",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
]
|
]
|
||||||
|
@ -7321,7 +7319,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wgpu-hal"
|
name = "wgpu-hal"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu?rev=d0a5e48aa7e84683114c3870051cc414ae92ac03#d0a5e48aa7e84683114c3870051cc414ae92ac03"
|
source = "git+https://github.com/gfx-rs/wgpu?rev=1e784c9c0af7a785b62e3b6840ed012a7477520f#1e784c9c0af7a785b62e3b6840ed012a7477520f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android_system_properties",
|
"android_system_properties",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
|
@ -7339,7 +7337,7 @@ dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"khronos-egl",
|
"khronos-egl",
|
||||||
"libc",
|
"libc",
|
||||||
"libloading 0.8.4",
|
"libloading 0.7.4",
|
||||||
"log",
|
"log",
|
||||||
"metal 0.28.0",
|
"metal 0.28.0",
|
||||||
"naga",
|
"naga",
|
||||||
|
@ -7362,7 +7360,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wgpu-types"
|
name = "wgpu-types"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu?rev=d0a5e48aa7e84683114c3870051cc414ae92ac03#d0a5e48aa7e84683114c3870051cc414ae92ac03"
|
source = "git+https://github.com/gfx-rs/wgpu?rev=1e784c9c0af7a785b62e3b6840ed012a7477520f#1e784c9c0af7a785b62e3b6840ed012a7477520f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
|
|
@ -136,8 +136,8 @@ webpki-roots = "0.25"
|
||||||
webrender = { git = "https://github.com/servo/webrender", branch = "0.64", features = ["capture"] }
|
webrender = { git = "https://github.com/servo/webrender", branch = "0.64", features = ["capture"] }
|
||||||
webrender_api = { git = "https://github.com/servo/webrender", branch = "0.64" }
|
webrender_api = { git = "https://github.com/servo/webrender", branch = "0.64" }
|
||||||
webrender_traits = { path = "components/shared/webrender" }
|
webrender_traits = { path = "components/shared/webrender" }
|
||||||
wgpu-core = { git = "https://github.com/gfx-rs/wgpu", rev = "d0a5e48aa7e84683114c3870051cc414ae92ac03" }
|
wgpu-core = { git = "https://github.com/gfx-rs/wgpu", rev = "1e784c9c0af7a785b62e3b6840ed012a7477520f" }
|
||||||
wgpu-types = { git = "https://github.com/gfx-rs/wgpu", rev = "d0a5e48aa7e84683114c3870051cc414ae92ac03" }
|
wgpu-types = { git = "https://github.com/gfx-rs/wgpu", rev = "1e784c9c0af7a785b62e3b6840ed012a7477520f" }
|
||||||
windows-sys = "0.52"
|
windows-sys = "0.52"
|
||||||
xi-unicode = "0.1.0"
|
xi-unicode = "0.1.0"
|
||||||
xml5ever = "0.18"
|
xml5ever = "0.18"
|
||||||
|
|
|
@ -64,7 +64,6 @@ use crate::dom::bindings::str::{DOMString, USVString};
|
||||||
use crate::dom::bindings::utils::WindowProxyHandler;
|
use crate::dom::bindings::utils::WindowProxyHandler;
|
||||||
use crate::dom::gpubuffer::GPUBufferState;
|
use crate::dom::gpubuffer::GPUBufferState;
|
||||||
use crate::dom::gpucanvascontext::WebGPUContextId;
|
use crate::dom::gpucanvascontext::WebGPUContextId;
|
||||||
use crate::dom::gpucommandencoder::GPUCommandEncoderState;
|
|
||||||
use crate::dom::htmlimageelement::SourceSet;
|
use crate::dom::htmlimageelement::SourceSet;
|
||||||
use crate::dom::htmlmediaelement::HTMLMediaElementFetchContext;
|
use crate::dom::htmlmediaelement::HTMLMediaElementFetchContext;
|
||||||
use crate::script_runtime::{ContextForRequestInterrupt, StreamConsumer};
|
use crate::script_runtime::{ContextForRequestInterrupt, StreamConsumer};
|
||||||
|
@ -371,7 +370,6 @@ unsafe_no_jsmanaged_fields!(DOMString);
|
||||||
unsafe_no_jsmanaged_fields!(USVString);
|
unsafe_no_jsmanaged_fields!(USVString);
|
||||||
unsafe_no_jsmanaged_fields!(WebGPUContextId);
|
unsafe_no_jsmanaged_fields!(WebGPUContextId);
|
||||||
unsafe_no_jsmanaged_fields!(GPUBufferState);
|
unsafe_no_jsmanaged_fields!(GPUBufferState);
|
||||||
unsafe_no_jsmanaged_fields!(GPUCommandEncoderState);
|
|
||||||
unsafe_no_jsmanaged_fields!(SourceSet);
|
unsafe_no_jsmanaged_fields!(SourceSet);
|
||||||
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
|
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
|
||||||
unsafe_no_jsmanaged_fields!(StreamConsumer);
|
unsafe_no_jsmanaged_fields!(StreamConsumer);
|
||||||
|
|
|
@ -8,8 +8,9 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use webgpu::wgc::command as wgpu_com;
|
use webgpu::wgc::command as wgpu_com;
|
||||||
use webgpu::{self, wgt, WebGPU, WebGPURequest};
|
use webgpu::{self, wgt, WebGPU, WebGPUComputePass, WebGPURequest};
|
||||||
|
|
||||||
|
use super::gpuconvert::convert_label;
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||||
GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, GPUExtent3D,
|
GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, GPUExtent3D,
|
||||||
|
@ -31,16 +32,6 @@ use crate::dom::gpuconvert::{
|
||||||
use crate::dom::gpudevice::GPUDevice;
|
use crate::dom::gpudevice::GPUDevice;
|
||||||
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
|
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
|
||||||
|
|
||||||
// TODO(sagudev): this is different now
|
|
||||||
// https://gpuweb.github.io/gpuweb/#enumdef-encoder-state
|
|
||||||
#[derive(MallocSizeOf, PartialEq)]
|
|
||||||
pub enum GPUCommandEncoderState {
|
|
||||||
Open,
|
|
||||||
EncodingRenderPass,
|
|
||||||
EncodingComputePass,
|
|
||||||
Closed,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct GPUCommandEncoder {
|
pub struct GPUCommandEncoder {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -51,7 +42,6 @@ pub struct GPUCommandEncoder {
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
encoder: webgpu::WebGPUCommandEncoder,
|
encoder: webgpu::WebGPUCommandEncoder,
|
||||||
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
|
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
|
||||||
state: DomRefCell<GPUCommandEncoderState>,
|
|
||||||
device: Dom<GPUDevice>,
|
device: Dom<GPUDevice>,
|
||||||
valid: Cell<bool>,
|
valid: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
@ -70,7 +60,6 @@ impl GPUCommandEncoder {
|
||||||
device: Dom::from_ref(device),
|
device: Dom::from_ref(device),
|
||||||
encoder,
|
encoder,
|
||||||
buffers: DomRefCell::new(HashSet::new()),
|
buffers: DomRefCell::new(HashSet::new()),
|
||||||
state: DomRefCell::new(GPUCommandEncoderState::Open),
|
|
||||||
valid: Cell::new(true),
|
valid: Cell::new(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,13 +85,8 @@ impl GPUCommandEncoder {
|
||||||
self.encoder
|
self.encoder
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_state(&self, set: GPUCommandEncoderState, expect: GPUCommandEncoderState) {
|
pub fn device_id(&self) -> webgpu::WebGPUDevice {
|
||||||
if *self.state.borrow() == expect {
|
self.device.id()
|
||||||
*self.state.borrow_mut() = set;
|
|
||||||
} else {
|
|
||||||
self.valid.set(false);
|
|
||||||
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,32 +106,26 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
&self,
|
&self,
|
||||||
descriptor: &GPUComputePassDescriptor,
|
descriptor: &GPUComputePassDescriptor,
|
||||||
) -> DomRoot<GPUComputePassEncoder> {
|
) -> DomRoot<GPUComputePassEncoder> {
|
||||||
self.set_state(
|
let compute_pass_id = self
|
||||||
GPUCommandEncoderState::EncodingComputePass,
|
.global()
|
||||||
GPUCommandEncoderState::Open,
|
.wgpu_id_hub()
|
||||||
);
|
.lock()
|
||||||
|
.create_compute_pass_id(self.device.id().0.backend());
|
||||||
|
|
||||||
let compute_pass = if !self.valid.get() {
|
if let Err(e) = self.channel.0.send(WebGPURequest::BeginComputePass {
|
||||||
None
|
command_encoder_id: self.id().0,
|
||||||
} else {
|
compute_pass_id,
|
||||||
Some(wgpu_com::ComputePass::new(
|
label: convert_label(&descriptor.parent),
|
||||||
self.encoder.0,
|
device_id: self.device.id().0,
|
||||||
&wgpu_com::ComputePassDescriptor {
|
}) {
|
||||||
label: descriptor
|
warn!("Failed to send WebGPURequest::BeginComputePass {e:?}");
|
||||||
.parent
|
}
|
||||||
.label
|
|
||||||
.as_ref()
|
|
||||||
.map(|l| Cow::Borrowed(&**l)),
|
|
||||||
timestamp_writes: None,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
};
|
|
||||||
|
|
||||||
GPUComputePassEncoder::new(
|
GPUComputePassEncoder::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
self.channel.clone(),
|
self.channel.clone(),
|
||||||
self,
|
self,
|
||||||
compute_pass,
|
WebGPUComputePass(compute_pass_id),
|
||||||
descriptor.parent.label.clone().unwrap_or_default(),
|
descriptor.parent.label.clone().unwrap_or_default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -157,11 +135,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
&self,
|
&self,
|
||||||
descriptor: &GPURenderPassDescriptor,
|
descriptor: &GPURenderPassDescriptor,
|
||||||
) -> DomRoot<GPURenderPassEncoder> {
|
) -> DomRoot<GPURenderPassEncoder> {
|
||||||
self.set_state(
|
|
||||||
GPUCommandEncoderState::EncodingRenderPass,
|
|
||||||
GPUCommandEncoderState::Open,
|
|
||||||
);
|
|
||||||
|
|
||||||
let render_pass = if !self.valid.get() {
|
let render_pass = if !self.valid.get() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -259,11 +232,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
destination_offset: GPUSize64,
|
destination_offset: GPUSize64,
|
||||||
size: GPUSize64,
|
size: GPUSize64,
|
||||||
) {
|
) {
|
||||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
|
||||||
self.valid.set(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.buffers.borrow_mut().insert(DomRoot::from_ref(source));
|
self.buffers.borrow_mut().insert(DomRoot::from_ref(source));
|
||||||
self.buffers
|
self.buffers
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -288,11 +256,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
destination: &GPUImageCopyTexture,
|
destination: &GPUImageCopyTexture,
|
||||||
copy_size: GPUExtent3D,
|
copy_size: GPUExtent3D,
|
||||||
) {
|
) {
|
||||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
|
||||||
self.valid.set(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.buffers
|
self.buffers
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(DomRoot::from_ref(&*source.buffer));
|
.insert(DomRoot::from_ref(&*source.buffer));
|
||||||
|
@ -315,11 +278,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
destination: &GPUImageCopyBuffer,
|
destination: &GPUImageCopyBuffer,
|
||||||
copy_size: GPUExtent3D,
|
copy_size: GPUExtent3D,
|
||||||
) {
|
) {
|
||||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
|
||||||
self.valid.set(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.buffers
|
self.buffers
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(DomRoot::from_ref(&*destination.buffer));
|
.insert(DomRoot::from_ref(&*destination.buffer));
|
||||||
|
@ -342,11 +300,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
destination: &GPUImageCopyTexture,
|
destination: &GPUImageCopyTexture,
|
||||||
copy_size: GPUExtent3D,
|
copy_size: GPUExtent3D,
|
||||||
) {
|
) {
|
||||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
|
||||||
self.valid.set(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.channel
|
self.channel
|
||||||
.0
|
.0
|
||||||
.send(WebGPURequest::CopyTextureToTexture {
|
.send(WebGPURequest::CopyTextureToTexture {
|
||||||
|
@ -371,7 +324,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
})
|
})
|
||||||
.expect("Failed to send Finish");
|
.expect("Failed to send Finish");
|
||||||
|
|
||||||
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
|
|
||||||
let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.into_command_buffer_id());
|
let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.into_command_buffer_id());
|
||||||
GPUCommandBuffer::new(
|
GPUCommandBuffer::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use webgpu::wgc::command::{compute_commands as wgpu_comp, ComputePass};
|
use webgpu::{WebGPU, WebGPUComputePass, WebGPURequest};
|
||||||
use webgpu::{WebGPU, WebGPURequest};
|
|
||||||
|
|
||||||
use super::bindings::error::Fallible;
|
use super::bindings::error::Fallible;
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
|
@ -15,7 +14,7 @@ use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpubindgroup::GPUBindGroup;
|
use crate::dom::gpubindgroup::GPUBindGroup;
|
||||||
use crate::dom::gpubuffer::GPUBuffer;
|
use crate::dom::gpubuffer::GPUBuffer;
|
||||||
use crate::dom::gpucommandencoder::{GPUCommandEncoder, GPUCommandEncoderState};
|
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
||||||
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -25,9 +24,8 @@ pub struct GPUComputePassEncoder {
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
label: DomRefCell<USVString>,
|
label: DomRefCell<USVString>,
|
||||||
#[ignore_malloc_size_of = "defined in wgpu-core"]
|
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
compute_pass: DomRefCell<Option<ComputePass>>,
|
compute_pass: WebGPUComputePass,
|
||||||
command_encoder: Dom<GPUCommandEncoder>,
|
command_encoder: Dom<GPUCommandEncoder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +33,14 @@ impl GPUComputePassEncoder {
|
||||||
fn new_inherited(
|
fn new_inherited(
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
parent: &GPUCommandEncoder,
|
parent: &GPUCommandEncoder,
|
||||||
compute_pass: Option<ComputePass>,
|
compute_pass: WebGPUComputePass,
|
||||||
label: USVString,
|
label: USVString,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
channel,
|
channel,
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
label: DomRefCell::new(label),
|
label: DomRefCell::new(label),
|
||||||
compute_pass: DomRefCell::new(compute_pass),
|
compute_pass,
|
||||||
command_encoder: Dom::from_ref(parent),
|
command_encoder: Dom::from_ref(parent),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +49,7 @@ impl GPUComputePassEncoder {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
parent: &GPUCommandEncoder,
|
parent: &GPUCommandEncoder,
|
||||||
compute_pass: Option<ComputePass>,
|
compute_pass: WebGPUComputePass,
|
||||||
label: USVString,
|
label: USVString,
|
||||||
) -> DomRoot<Self> {
|
) -> DomRoot<Self> {
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
|
@ -79,57 +77,83 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-dispatchworkgroups>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-dispatchworkgroups>
|
||||||
fn DispatchWorkgroups(&self, x: u32, y: u32, z: u32) {
|
fn DispatchWorkgroups(&self, x: u32, y: u32, z: u32) {
|
||||||
if let Some(compute_pass) = self.compute_pass.borrow_mut().as_mut() {
|
if let Err(e) = self
|
||||||
wgpu_comp::wgpu_compute_pass_dispatch_workgroups(compute_pass, x, y, z);
|
.channel
|
||||||
|
.0
|
||||||
|
.send(WebGPURequest::ComputePassDispatchWorkgroups {
|
||||||
|
compute_pass_id: self.compute_pass.0,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
device_id: self.command_encoder.device_id().0,
|
||||||
|
})
|
||||||
|
{
|
||||||
|
warn!("Error sending WebGPURequest::ComputePassDispatchWorkgroups: {e:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-dispatchworkgroupsindirect>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-dispatchworkgroupsindirect>
|
||||||
fn DispatchWorkgroupsIndirect(&self, indirect_buffer: &GPUBuffer, indirect_offset: u64) {
|
fn DispatchWorkgroupsIndirect(&self, buffer: &GPUBuffer, offset: u64) {
|
||||||
if let Some(compute_pass) = self.compute_pass.borrow_mut().as_mut() {
|
if let Err(e) = self
|
||||||
wgpu_comp::wgpu_compute_pass_dispatch_workgroups_indirect(
|
.channel
|
||||||
compute_pass,
|
.0
|
||||||
indirect_buffer.id().0,
|
.send(WebGPURequest::ComputePassDispatchWorkgroupsIndirect {
|
||||||
indirect_offset,
|
compute_pass_id: self.compute_pass.0,
|
||||||
);
|
buffer_id: buffer.id().0,
|
||||||
|
offset,
|
||||||
|
device_id: self.command_encoder.device_id().0,
|
||||||
|
})
|
||||||
|
{
|
||||||
|
warn!("Error sending WebGPURequest::ComputePassDispatchWorkgroupsIndirect: {e:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-endpass>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-endpass>
|
||||||
fn End(&self) -> Fallible<()> {
|
fn End(&self) -> Fallible<()> {
|
||||||
let compute_pass = self.compute_pass.borrow_mut().take();
|
if let Err(e) = self.channel.0.send(WebGPURequest::EndComputePass {
|
||||||
self.channel
|
compute_pass_id: self.compute_pass.0,
|
||||||
.0
|
device_id: self.command_encoder.device_id().0,
|
||||||
.send(WebGPURequest::RunComputePass {
|
command_encoder_id: self.command_encoder.id().0,
|
||||||
command_encoder_id: self.command_encoder.id().0,
|
}) {
|
||||||
compute_pass,
|
warn!("Failed to send WebGPURequest::EndComputePass: {e:?}");
|
||||||
})
|
}
|
||||||
.expect("Failed to send RunComputePass"); //TODO: handle error
|
|
||||||
|
|
||||||
self.command_encoder.set_state(
|
|
||||||
GPUCommandEncoderState::Open,
|
|
||||||
GPUCommandEncoderState::EncodingComputePass,
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpuprogrammablepassencoder-setbindgroup>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpuprogrammablepassencoder-setbindgroup>
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec<u32>) {
|
fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, offsets: Vec<u32>) {
|
||||||
if let Some(compute_pass) = self.compute_pass.borrow_mut().as_mut() {
|
if let Err(e) = self.channel.0.send(WebGPURequest::ComputePassSetBindGroup {
|
||||||
wgpu_comp::wgpu_compute_pass_set_bind_group(
|
compute_pass_id: self.compute_pass.0,
|
||||||
compute_pass,
|
index,
|
||||||
index,
|
bind_group_id: bind_group.id().0,
|
||||||
bind_group.id().0,
|
offsets,
|
||||||
&dynamic_offsets,
|
device_id: self.command_encoder.device_id().0,
|
||||||
)
|
}) {
|
||||||
|
warn!("Error sending WebGPURequest::ComputePassSetBindGroup: {e:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-setpipeline>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-setpipeline>
|
||||||
fn SetPipeline(&self, pipeline: &GPUComputePipeline) {
|
fn SetPipeline(&self, pipeline: &GPUComputePipeline) {
|
||||||
if let Some(compute_pass) = self.compute_pass.borrow_mut().as_mut() {
|
if let Err(e) = self.channel.0.send(WebGPURequest::ComputePassSetPipeline {
|
||||||
wgpu_comp::wgpu_compute_pass_set_pipeline(compute_pass, pipeline.id().0);
|
compute_pass_id: self.compute_pass.0,
|
||||||
|
pipeline_id: pipeline.id().0,
|
||||||
|
device_id: self.command_encoder.device_id().0,
|
||||||
|
}) {
|
||||||
|
warn!("Error sending WebGPURequest::ComputePassSetPipeline: {e:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for GPUComputePassEncoder {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if let Err(e) = self
|
||||||
|
.channel
|
||||||
|
.0
|
||||||
|
.send(WebGPURequest::DropComputePass(self.compute_pass.0))
|
||||||
|
{
|
||||||
|
warn!("Failed to send WebGPURequest::DropComputePass with {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -586,7 +586,9 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
entry_point: Some(Cow::Owned(descriptor.compute.entryPoint.to_string())),
|
entry_point: Some(Cow::Owned(descriptor.compute.entryPoint.to_string())),
|
||||||
constants: Cow::Owned(HashMap::new()),
|
constants: Cow::Owned(HashMap::new()),
|
||||||
zero_initialize_workgroup_memory: true,
|
zero_initialize_workgroup_memory: true,
|
||||||
|
vertex_pulling_transform: false,
|
||||||
},
|
},
|
||||||
|
cache: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.channel
|
self.channel
|
||||||
|
@ -769,6 +771,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
Some(wgpu_pipe::RenderPipelineDescriptor {
|
Some(wgpu_pipe::RenderPipelineDescriptor {
|
||||||
label: convert_label(&descriptor.parent.parent),
|
label: convert_label(&descriptor.parent.parent),
|
||||||
layout,
|
layout,
|
||||||
|
cache: None,
|
||||||
vertex: wgpu_pipe::VertexState {
|
vertex: wgpu_pipe::VertexState {
|
||||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
||||||
module: descriptor.vertex.parent.module.id().0,
|
module: descriptor.vertex.parent.module.id().0,
|
||||||
|
@ -777,6 +780,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
)),
|
)),
|
||||||
constants: Cow::Owned(HashMap::new()),
|
constants: Cow::Owned(HashMap::new()),
|
||||||
zero_initialize_workgroup_memory: true,
|
zero_initialize_workgroup_memory: true,
|
||||||
|
vertex_pulling_transform: false,
|
||||||
},
|
},
|
||||||
buffers: Cow::Owned(
|
buffers: Cow::Owned(
|
||||||
descriptor
|
descriptor
|
||||||
|
@ -813,6 +817,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
entry_point: Some(Cow::Owned(stage.parent.entryPoint.to_string())),
|
entry_point: Some(Cow::Owned(stage.parent.entryPoint.to_string())),
|
||||||
constants: Cow::Owned(HashMap::new()),
|
constants: Cow::Owned(HashMap::new()),
|
||||||
zero_initialize_workgroup_memory: true,
|
zero_initialize_workgroup_memory: true,
|
||||||
|
vertex_pulling_transform: false,
|
||||||
},
|
},
|
||||||
targets: Cow::Owned(
|
targets: Cow::Owned(
|
||||||
stage
|
stage
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpubindgroup::GPUBindGroup;
|
use crate::dom::gpubindgroup::GPUBindGroup;
|
||||||
use crate::dom::gpubuffer::GPUBuffer;
|
use crate::dom::gpubuffer::GPUBuffer;
|
||||||
use crate::dom::gpucommandencoder::{GPUCommandEncoder, GPUCommandEncoderState};
|
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
||||||
use crate::dom::gpurenderbundle::GPURenderBundle;
|
use crate::dom::gpurenderbundle::GPURenderBundle;
|
||||||
use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
||||||
|
|
||||||
|
@ -164,16 +164,12 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
|
||||||
let render_pass = self.render_pass.borrow_mut().take();
|
let render_pass = self.render_pass.borrow_mut().take();
|
||||||
self.channel
|
self.channel
|
||||||
.0
|
.0
|
||||||
.send(WebGPURequest::RunRenderPass {
|
.send(WebGPURequest::EndRenderPass {
|
||||||
command_encoder_id: self.command_encoder.id().0,
|
|
||||||
render_pass,
|
render_pass,
|
||||||
|
device_id: self.command_encoder.device_id().0,
|
||||||
})
|
})
|
||||||
.expect("Failed to send RunRenderPass");
|
.expect("Failed to send RunRenderPass");
|
||||||
|
|
||||||
self.command_encoder.set_state(
|
|
||||||
GPUCommandEncoderState::Open,
|
|
||||||
GPUCommandEncoderState::EncodingRenderPass,
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use webgpu::identity::{ComputePass, ComputePassId};
|
||||||
use webgpu::wgc::id::markers::{
|
use webgpu::wgc::id::markers::{
|
||||||
Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device,
|
Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device,
|
||||||
PipelineLayout, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture, TextureView,
|
PipelineLayout, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture, TextureView,
|
||||||
|
@ -31,6 +32,7 @@ pub struct IdentityHub {
|
||||||
samplers: IdentityManager<Sampler>,
|
samplers: IdentityManager<Sampler>,
|
||||||
render_pipelines: IdentityManager<RenderPipeline>,
|
render_pipelines: IdentityManager<RenderPipeline>,
|
||||||
render_bundles: IdentityManager<RenderBundle>,
|
render_bundles: IdentityManager<RenderBundle>,
|
||||||
|
compute_passes: IdentityManager<ComputePass>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdentityHub {
|
impl IdentityHub {
|
||||||
|
@ -50,6 +52,7 @@ impl IdentityHub {
|
||||||
samplers: IdentityManager::new(),
|
samplers: IdentityManager::new(),
|
||||||
render_pipelines: IdentityManager::new(),
|
render_pipelines: IdentityManager::new(),
|
||||||
render_bundles: IdentityManager::new(),
|
render_bundles: IdentityManager::new(),
|
||||||
|
compute_passes: IdentityManager::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,6 +228,14 @@ impl Identities {
|
||||||
pub fn kill_render_bundle_id(&mut self, id: RenderBundleId) {
|
pub fn kill_render_bundle_id(&mut self, id: RenderBundleId) {
|
||||||
self.select(id.backend()).render_bundles.free(id);
|
self.select(id.backend()).render_bundles.free(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_compute_pass_id(&mut self, backend: Backend) -> ComputePassId {
|
||||||
|
self.select(backend).compute_passes.process(backend)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn kill_compute_pass_id(&mut self, id: ComputePassId) {
|
||||||
|
self.select(id.backend()).compute_passes.free(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Identities {
|
impl Default for Identities {
|
||||||
|
|
|
@ -2450,6 +2450,7 @@ impl ScriptThread {
|
||||||
WebGPUMsg::FreeRenderPipeline(id) => self.gpu_id_hub.lock().kill_render_pipeline_id(id),
|
WebGPUMsg::FreeRenderPipeline(id) => self.gpu_id_hub.lock().kill_render_pipeline_id(id),
|
||||||
WebGPUMsg::FreeTexture(id) => self.gpu_id_hub.lock().kill_texture_id(id),
|
WebGPUMsg::FreeTexture(id) => self.gpu_id_hub.lock().kill_texture_id(id),
|
||||||
WebGPUMsg::FreeTextureView(id) => self.gpu_id_hub.lock().kill_texture_view_id(id),
|
WebGPUMsg::FreeTextureView(id) => self.gpu_id_hub.lock().kill_texture_view_id(id),
|
||||||
|
WebGPUMsg::FreeComputePass(id) => self.gpu_id_hub.lock().kill_compute_pass_id(id),
|
||||||
WebGPUMsg::Exit => *self.webgpu_port.borrow_mut() = None,
|
WebGPUMsg::Exit => *self.webgpu_port.borrow_mut() = None,
|
||||||
WebGPUMsg::DeviceLost {
|
WebGPUMsg::DeviceLost {
|
||||||
pipeline_id,
|
pipeline_id,
|
||||||
|
|
|
@ -16,8 +16,7 @@ use wgc::binding_model::{
|
||||||
BindGroupDescriptor, BindGroupLayoutDescriptor, PipelineLayoutDescriptor,
|
BindGroupDescriptor, BindGroupLayoutDescriptor, PipelineLayoutDescriptor,
|
||||||
};
|
};
|
||||||
use wgc::command::{
|
use wgc::command::{
|
||||||
ComputePass, ImageCopyBuffer, ImageCopyTexture, RenderBundleDescriptor, RenderBundleEncoder,
|
ImageCopyBuffer, ImageCopyTexture, RenderBundleDescriptor, RenderBundleEncoder, RenderPass,
|
||||||
RenderPass,
|
|
||||||
};
|
};
|
||||||
use wgc::device::HostMap;
|
use wgc::device::HostMap;
|
||||||
use wgc::id;
|
use wgc::id;
|
||||||
|
@ -191,6 +190,7 @@ pub enum WebGPURequest {
|
||||||
DropShaderModule(id::ShaderModuleId),
|
DropShaderModule(id::ShaderModuleId),
|
||||||
DropRenderBundle(id::RenderBundleId),
|
DropRenderBundle(id::RenderBundleId),
|
||||||
DropQuerySet(id::QuerySetId),
|
DropQuerySet(id::QuerySetId),
|
||||||
|
DropComputePass(id::ComputePassEncoderId),
|
||||||
Exit(IpcSender<()>),
|
Exit(IpcSender<()>),
|
||||||
RenderBundleEncoderFinish {
|
RenderBundleEncoderFinish {
|
||||||
render_bundle_encoder: RenderBundleEncoder,
|
render_bundle_encoder: RenderBundleEncoder,
|
||||||
|
@ -210,13 +210,45 @@ pub enum WebGPURequest {
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
},
|
},
|
||||||
RunComputePass {
|
BeginComputePass {
|
||||||
command_encoder_id: id::CommandEncoderId,
|
command_encoder_id: id::CommandEncoderId,
|
||||||
compute_pass: Option<ComputePass>,
|
compute_pass_id: ComputePassId,
|
||||||
|
label: Option<Cow<'static, str>>,
|
||||||
|
device_id: id::DeviceId,
|
||||||
},
|
},
|
||||||
RunRenderPass {
|
ComputePassSetPipeline {
|
||||||
|
compute_pass_id: ComputePassId,
|
||||||
|
pipeline_id: id::ComputePipelineId,
|
||||||
|
device_id: id::DeviceId,
|
||||||
|
},
|
||||||
|
ComputePassSetBindGroup {
|
||||||
|
compute_pass_id: ComputePassId,
|
||||||
|
index: u32,
|
||||||
|
bind_group_id: id::BindGroupId,
|
||||||
|
offsets: Vec<u32>,
|
||||||
|
device_id: id::DeviceId,
|
||||||
|
},
|
||||||
|
ComputePassDispatchWorkgroups {
|
||||||
|
compute_pass_id: ComputePassId,
|
||||||
|
x: u32,
|
||||||
|
y: u32,
|
||||||
|
z: u32,
|
||||||
|
device_id: id::DeviceId,
|
||||||
|
},
|
||||||
|
ComputePassDispatchWorkgroupsIndirect {
|
||||||
|
compute_pass_id: ComputePassId,
|
||||||
|
buffer_id: id::BufferId,
|
||||||
|
offset: u64,
|
||||||
|
device_id: id::DeviceId,
|
||||||
|
},
|
||||||
|
EndComputePass {
|
||||||
|
compute_pass_id: ComputePassId,
|
||||||
|
device_id: id::DeviceId,
|
||||||
command_encoder_id: id::CommandEncoderId,
|
command_encoder_id: id::CommandEncoderId,
|
||||||
|
},
|
||||||
|
EndRenderPass {
|
||||||
render_pass: Option<RenderPass>,
|
render_pass: Option<RenderPass>,
|
||||||
|
device_id: id::DeviceId,
|
||||||
},
|
},
|
||||||
Submit {
|
Submit {
|
||||||
queue_id: id::QueueId,
|
queue_id: id::QueueId,
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub use crate::wgc::id::markers::ComputePassEncoder as ComputePass;
|
||||||
|
pub use crate::wgc::id::ComputePassEncoderId as ComputePassId;
|
||||||
use crate::wgc::id::{
|
use crate::wgc::id::{
|
||||||
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
|
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
|
||||||
ComputePipelineId, DeviceId, PipelineLayoutId, QueueId, RenderBundleId, RenderPipelineId,
|
ComputePipelineId, DeviceId, PipelineLayoutId, QueueId, RenderBundleId, RenderPipelineId,
|
||||||
|
@ -43,3 +45,4 @@ webgpu_resource!(WebGPUShaderModule, ShaderModuleId);
|
||||||
webgpu_resource!(WebGPUSurface, SurfaceId);
|
webgpu_resource!(WebGPUSurface, SurfaceId);
|
||||||
webgpu_resource!(WebGPUTexture, TextureId);
|
webgpu_resource!(WebGPUTexture, TextureId);
|
||||||
webgpu_resource!(WebGPUTextureView, TextureViewId);
|
webgpu_resource!(WebGPUTextureView, TextureViewId);
|
||||||
|
webgpu_resource!(WebGPUComputePass, ComputePassId);
|
||||||
|
|
|
@ -10,9 +10,9 @@ use serde::{Deserialize, Serialize};
|
||||||
use crate::gpu_error::Error;
|
use crate::gpu_error::Error;
|
||||||
use crate::identity::WebGPUDevice;
|
use crate::identity::WebGPUDevice;
|
||||||
use crate::wgc::id::{
|
use crate::wgc::id::{
|
||||||
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, ComputePipelineId,
|
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, ComputePassEncoderId,
|
||||||
DeviceId, PipelineLayoutId, QuerySetId, RenderBundleId, RenderPipelineId, SamplerId,
|
ComputePipelineId, DeviceId, PipelineLayoutId, QuerySetId, RenderBundleId, RenderPipelineId,
|
||||||
ShaderModuleId, StagingBufferId, SurfaceId, TextureId, TextureViewId,
|
SamplerId, ShaderModuleId, StagingBufferId, SurfaceId, TextureId, TextureViewId,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#enumdef-gpudevicelostreason>
|
/// <https://gpuweb.github.io/gpuweb/#enumdef-gpudevicelostreason>
|
||||||
|
@ -44,6 +44,7 @@ pub enum WebGPUMsg {
|
||||||
FreeRenderBundle(RenderBundleId),
|
FreeRenderBundle(RenderBundleId),
|
||||||
FreeStagingBuffer(StagingBufferId),
|
FreeStagingBuffer(StagingBufferId),
|
||||||
FreeQuerySet(QuerySetId),
|
FreeQuerySet(QuerySetId),
|
||||||
|
FreeComputePass(ComputePassEncoderId),
|
||||||
UncapturedError {
|
UncapturedError {
|
||||||
device: WebGPUDevice,
|
device: WebGPUDevice,
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
//! Data and main loop of WebGPU thread.
|
//! Data and main loop of WebGPU thread.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
@ -26,14 +25,15 @@ use wgc::instance::parse_backends_from_comma_list;
|
||||||
use wgc::pipeline::ShaderModuleDescriptor;
|
use wgc::pipeline::ShaderModuleDescriptor;
|
||||||
use wgc::resource::{BufferMapCallback, BufferMapOperation};
|
use wgc::resource::{BufferMapCallback, BufferMapOperation};
|
||||||
use wgc::{gfx_select, id};
|
use wgc::{gfx_select, id};
|
||||||
|
use wgpu_core::command::{ComputePassDescriptor, DynComputePass};
|
||||||
use wgt::InstanceDescriptor;
|
use wgt::InstanceDescriptor;
|
||||||
pub use {wgpu_core as wgc, wgpu_types as wgt};
|
pub use {wgpu_core as wgc, wgpu_types as wgt};
|
||||||
|
|
||||||
use crate::gpu_error::ErrorScope;
|
use crate::gpu_error::ErrorScope;
|
||||||
use crate::poll_thread::Poller;
|
use crate::poll_thread::Poller;
|
||||||
use crate::{
|
use crate::{
|
||||||
Error, PopError, PresentationData, Transmute, WebGPU, WebGPUAdapter, WebGPUDevice, WebGPUMsg,
|
ComputePassId, Error, PopError, PresentationData, Transmute, WebGPU, WebGPUAdapter,
|
||||||
WebGPUQueue, WebGPURequest, WebGPUResponse,
|
WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const PRESENTATION_BUFFER_COUNT: usize = 10;
|
pub const PRESENTATION_BUFFER_COUNT: usize = 10;
|
||||||
|
@ -73,13 +73,20 @@ pub(crate) struct WGPU {
|
||||||
devices: Arc<Mutex<HashMap<DeviceId, DeviceScope>>>,
|
devices: Arc<Mutex<HashMap<DeviceId, DeviceScope>>>,
|
||||||
// Track invalid adapters https://gpuweb.github.io/gpuweb/#invalid
|
// Track invalid adapters https://gpuweb.github.io/gpuweb/#invalid
|
||||||
_invalid_adapters: Vec<WebGPUAdapter>,
|
_invalid_adapters: Vec<WebGPUAdapter>,
|
||||||
//TODO: Remove this (https://github.com/gfx-rs/wgpu/issues/867)
|
// TODO: Remove this (https://github.com/gfx-rs/wgpu/issues/867)
|
||||||
error_command_encoders: RefCell<HashMap<id::CommandEncoderId, String>>,
|
/// This stores first error on command encoder,
|
||||||
|
/// because wgpu does not invalidate command encoder object
|
||||||
|
/// (this is also reused for invalidation of command buffers)
|
||||||
|
error_command_encoders: HashMap<id::CommandEncoderId, String>,
|
||||||
webrender_api: Arc<Mutex<RenderApi>>,
|
webrender_api: Arc<Mutex<RenderApi>>,
|
||||||
webrender_document: DocumentId,
|
webrender_document: DocumentId,
|
||||||
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
|
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
|
||||||
wgpu_image_map: Arc<Mutex<HashMap<u64, PresentationData>>>,
|
wgpu_image_map: Arc<Mutex<HashMap<u64, PresentationData>>>,
|
||||||
|
/// Provides access to poller thread
|
||||||
poller: Poller,
|
poller: Poller,
|
||||||
|
/// Store compute passes (that have not ended yet) and their validity
|
||||||
|
compute_passes: HashMap<ComputePassId, (Box<dyn DynComputePass>, bool)>,
|
||||||
|
//render_passes: HashMap<RenderPassId, Box<dyn DynRenderPass>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WGPU {
|
impl WGPU {
|
||||||
|
@ -118,11 +125,12 @@ impl WGPU {
|
||||||
adapters: Vec::new(),
|
adapters: Vec::new(),
|
||||||
devices: Arc::new(Mutex::new(HashMap::new())),
|
devices: Arc::new(Mutex::new(HashMap::new())),
|
||||||
_invalid_adapters: Vec::new(),
|
_invalid_adapters: Vec::new(),
|
||||||
error_command_encoders: RefCell::new(HashMap::new()),
|
error_command_encoders: HashMap::new(),
|
||||||
webrender_api: Arc::new(Mutex::new(webrender_api_sender.create_api())),
|
webrender_api: Arc::new(Mutex::new(webrender_api_sender.create_api())),
|
||||||
webrender_document,
|
webrender_document,
|
||||||
external_images,
|
external_images,
|
||||||
wgpu_image_map,
|
wgpu_image_map,
|
||||||
|
compute_passes: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,13 +207,11 @@ impl WGPU {
|
||||||
} => {
|
} => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
let result = if is_error {
|
let result = if is_error {
|
||||||
Err(Error::Internal(String::from("Invalid GPUCommandEncoder")))
|
Err(Error::Validation(String::from("Invalid GPUCommandEncoder")))
|
||||||
} else if let Some(err) = self
|
} else if let Some(err) =
|
||||||
.error_command_encoders
|
self.error_command_encoders.get(&command_encoder_id)
|
||||||
.borrow()
|
|
||||||
.get(&command_encoder_id)
|
|
||||||
{
|
{
|
||||||
Err(Error::Internal(err.clone()))
|
Err(Error::Validation(err.clone()))
|
||||||
} else if let Some(error) =
|
} else if let Some(error) =
|
||||||
gfx_select!(command_encoder_id => global.command_encoder_finish(
|
gfx_select!(command_encoder_id => global.command_encoder_finish(
|
||||||
command_encoder_id,
|
command_encoder_id,
|
||||||
|
@ -218,7 +224,9 @@ impl WGPU {
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// invalidate command buffer too
|
||||||
self.encoder_record_error(command_encoder_id, &result);
|
self.encoder_record_error(command_encoder_id, &result);
|
||||||
|
// dispatch validation error
|
||||||
self.maybe_dispatch_error(device_id, result.err());
|
self.maybe_dispatch_error(device_id, result.err());
|
||||||
},
|
},
|
||||||
WebGPURequest::CopyBufferToBuffer {
|
WebGPURequest::CopyBufferToBuffer {
|
||||||
|
@ -575,7 +583,6 @@ impl WGPU {
|
||||||
},
|
},
|
||||||
WebGPURequest::DropCommandBuffer(id) => {
|
WebGPURequest::DropCommandBuffer(id) => {
|
||||||
self.error_command_encoders
|
self.error_command_encoders
|
||||||
.borrow_mut()
|
|
||||||
.remove(&id.into_command_encoder_id());
|
.remove(&id.into_command_encoder_id());
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
gfx_select!(id => global.command_buffer_drop(id));
|
gfx_select!(id => global.command_buffer_drop(id));
|
||||||
|
@ -745,35 +752,129 @@ impl WGPU {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
WebGPURequest::RunComputePass {
|
WebGPURequest::BeginComputePass {
|
||||||
command_encoder_id,
|
command_encoder_id,
|
||||||
compute_pass,
|
compute_pass_id,
|
||||||
|
label,
|
||||||
|
device_id: _device_id,
|
||||||
} => {
|
} => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
let result = if let Some(pass) = compute_pass {
|
let (pass, error) = gfx_select!(
|
||||||
gfx_select!(command_encoder_id => global.command_encoder_run_compute_pass(
|
command_encoder_id => global.command_encoder_create_compute_pass_dyn(
|
||||||
command_encoder_id,
|
command_encoder_id,
|
||||||
&pass
|
&ComputePassDescriptor { label, timestamp_writes: None }
|
||||||
)).map_err(|e| format!("{:?}", e))
|
));
|
||||||
} else {
|
assert!(
|
||||||
Err(String::from("Invalid ComputePass"))
|
self.compute_passes
|
||||||
};
|
.insert(compute_pass_id, (pass, error.is_none()))
|
||||||
self.encoder_record_error(command_encoder_id, &result);
|
.is_none(),
|
||||||
|
"ComputePass should not exist yet."
|
||||||
|
);
|
||||||
|
// TODO: Command encoder state errors
|
||||||
|
// self.maybe_dispatch_wgpu_error(device_id, error);
|
||||||
},
|
},
|
||||||
WebGPURequest::RunRenderPass {
|
WebGPURequest::ComputePassSetPipeline {
|
||||||
command_encoder_id,
|
compute_pass_id,
|
||||||
render_pass,
|
pipeline_id,
|
||||||
|
device_id,
|
||||||
} => {
|
} => {
|
||||||
let global = &self.global;
|
if let Some((pass, valid)) = self.compute_passes.get_mut(&compute_pass_id) {
|
||||||
let result = if let Some(pass) = render_pass {
|
*valid &= pass.set_pipeline(&self.global, pipeline_id).is_ok();
|
||||||
gfx_select!(command_encoder_id => global.command_encoder_run_render_pass(
|
|
||||||
command_encoder_id,
|
|
||||||
&pass
|
|
||||||
)).map_err(|e| format!("{:?}", e))
|
|
||||||
} else {
|
} else {
|
||||||
Err(String::from("Invalid RenderPass"))
|
self.maybe_dispatch_error(
|
||||||
|
device_id,
|
||||||
|
Some(Error::Validation("pass already ended".to_string())),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
self.encoder_record_error(command_encoder_id, &result);
|
},
|
||||||
|
WebGPURequest::ComputePassSetBindGroup {
|
||||||
|
compute_pass_id,
|
||||||
|
index,
|
||||||
|
bind_group_id,
|
||||||
|
offsets,
|
||||||
|
device_id,
|
||||||
|
} => {
|
||||||
|
if let Some((pass, valid)) = self.compute_passes.get_mut(&compute_pass_id) {
|
||||||
|
*valid &= pass
|
||||||
|
.set_bind_group(&self.global, index, bind_group_id, &offsets)
|
||||||
|
.is_ok();
|
||||||
|
} else {
|
||||||
|
self.maybe_dispatch_error(
|
||||||
|
device_id,
|
||||||
|
Some(Error::Validation("pass already ended".to_string())),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
WebGPURequest::ComputePassDispatchWorkgroups {
|
||||||
|
compute_pass_id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
device_id,
|
||||||
|
} => {
|
||||||
|
if let Some((pass, valid)) = self.compute_passes.get_mut(&compute_pass_id) {
|
||||||
|
*valid &= pass.dispatch_workgroups(&self.global, x, y, z).is_ok();
|
||||||
|
} else {
|
||||||
|
self.maybe_dispatch_error(
|
||||||
|
device_id,
|
||||||
|
Some(Error::Validation("pass already ended".to_string())),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
WebGPURequest::ComputePassDispatchWorkgroupsIndirect {
|
||||||
|
compute_pass_id,
|
||||||
|
buffer_id,
|
||||||
|
offset,
|
||||||
|
device_id,
|
||||||
|
} => {
|
||||||
|
if let Some((pass, valid)) = self.compute_passes.get_mut(&compute_pass_id) {
|
||||||
|
*valid &= pass
|
||||||
|
.dispatch_workgroups_indirect(&self.global, buffer_id, offset)
|
||||||
|
.is_ok();
|
||||||
|
} else {
|
||||||
|
self.maybe_dispatch_error(
|
||||||
|
device_id,
|
||||||
|
Some(Error::Validation("pass already ended".to_string())),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
WebGPURequest::EndComputePass {
|
||||||
|
compute_pass_id,
|
||||||
|
device_id,
|
||||||
|
command_encoder_id,
|
||||||
|
} => {
|
||||||
|
// TODO: Command encoder state error
|
||||||
|
if let Some((mut pass, valid)) =
|
||||||
|
self.compute_passes.remove(&compute_pass_id)
|
||||||
|
{
|
||||||
|
if pass.end(&self.global).is_ok() && !valid {
|
||||||
|
self.encoder_record_error(
|
||||||
|
command_encoder_id,
|
||||||
|
&Err::<(), _>("Pass is invalid".to_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.dispatch_error(
|
||||||
|
device_id,
|
||||||
|
Error::Validation("pass already ended".to_string()),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
WebGPURequest::EndRenderPass {
|
||||||
|
render_pass,
|
||||||
|
device_id,
|
||||||
|
} => {
|
||||||
|
if let Some(render_pass) = render_pass {
|
||||||
|
let command_encoder_id = render_pass.parent_id();
|
||||||
|
let global = &self.global;
|
||||||
|
let result = gfx_select!(command_encoder_id => global.render_pass_end(&render_pass));
|
||||||
|
self.maybe_dispatch_wgpu_error(device_id, result.err())
|
||||||
|
} else {
|
||||||
|
self.dispatch_error(
|
||||||
|
device_id,
|
||||||
|
Error::Validation("Render pass already ended".to_string()),
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
WebGPURequest::Submit {
|
WebGPURequest::Submit {
|
||||||
queue_id,
|
queue_id,
|
||||||
|
@ -782,11 +883,10 @@ impl WGPU {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
let cmd_id = command_buffers.iter().find(|id| {
|
let cmd_id = command_buffers.iter().find(|id| {
|
||||||
self.error_command_encoders
|
self.error_command_encoders
|
||||||
.borrow()
|
|
||||||
.contains_key(&id.into_command_encoder_id())
|
.contains_key(&id.into_command_encoder_id())
|
||||||
});
|
});
|
||||||
let result = if cmd_id.is_some() {
|
let result = if cmd_id.is_some() {
|
||||||
Err(Error::Internal(String::from(
|
Err(Error::Validation(String::from(
|
||||||
"Invalid command buffer submitted",
|
"Invalid command buffer submitted",
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -1026,7 +1126,8 @@ impl WGPU {
|
||||||
},
|
},
|
||||||
WebGPURequest::DropTexture(id) => {
|
WebGPURequest::DropTexture(id) => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
gfx_select!(id => global.texture_drop(id, true));
|
gfx_select!(id => global.texture_drop(id, false));
|
||||||
|
self.poller.wake();
|
||||||
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeTexture(id)) {
|
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeTexture(id)) {
|
||||||
warn!("Unable to send FreeTexture({:?}) ({:?})", id, e);
|
warn!("Unable to send FreeTexture({:?}) ({:?})", id, e);
|
||||||
};
|
};
|
||||||
|
@ -1040,7 +1141,8 @@ impl WGPU {
|
||||||
},
|
},
|
||||||
WebGPURequest::DropBuffer(id) => {
|
WebGPURequest::DropBuffer(id) => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
gfx_select!(id => global.buffer_drop(id, true));
|
gfx_select!(id => global.buffer_drop(id, false));
|
||||||
|
self.poller.wake();
|
||||||
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeBuffer(id)) {
|
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeBuffer(id)) {
|
||||||
warn!("Unable to send FreeBuffer({:?}) ({:?})", id, e);
|
warn!("Unable to send FreeBuffer({:?}) ({:?})", id, e);
|
||||||
};
|
};
|
||||||
|
@ -1060,6 +1162,13 @@ impl WGPU {
|
||||||
warn!("Unable to send FreeComputePipeline({:?}) ({:?})", id, e);
|
warn!("Unable to send FreeComputePipeline({:?}) ({:?})", id, e);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
WebGPURequest::DropComputePass(id) => {
|
||||||
|
// Compute pass might have already ended
|
||||||
|
self.compute_passes.remove(&id);
|
||||||
|
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeComputePass(id)) {
|
||||||
|
warn!("Unable to send FreeComputePass({:?}) ({:?})", id, e);
|
||||||
|
};
|
||||||
|
},
|
||||||
WebGPURequest::DropRenderPipeline(id) => {
|
WebGPURequest::DropRenderPipeline(id) => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
gfx_select!(id => global.render_pipeline_drop(id));
|
gfx_select!(id => global.render_pipeline_drop(id));
|
||||||
|
@ -1084,7 +1193,8 @@ impl WGPU {
|
||||||
},
|
},
|
||||||
WebGPURequest::DropTextureView(id) => {
|
WebGPURequest::DropTextureView(id) => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
let _result = gfx_select!(id => global.texture_view_drop(id, true));
|
let _result = gfx_select!(id => global.texture_view_drop(id, false));
|
||||||
|
self.poller.wake();
|
||||||
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeTextureView(id)) {
|
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeTextureView(id)) {
|
||||||
warn!("Unable to send FreeTextureView({:?}) ({:?})", id, e);
|
warn!("Unable to send FreeTextureView({:?}) ({:?})", id, e);
|
||||||
};
|
};
|
||||||
|
@ -1214,13 +1324,12 @@ impl WGPU {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encoder_record_error<U, T: std::fmt::Debug>(
|
fn encoder_record_error<U, T: std::fmt::Debug>(
|
||||||
&self,
|
&mut self,
|
||||||
encoder_id: id::CommandEncoderId,
|
encoder_id: id::CommandEncoderId,
|
||||||
result: &Result<U, T>,
|
result: &Result<U, T>,
|
||||||
) {
|
) {
|
||||||
if let Err(ref e) = result {
|
if let Err(ref e) = result {
|
||||||
self.error_command_encoders
|
self.error_command_encoders
|
||||||
.borrow_mut()
|
|
||||||
.entry(encoder_id)
|
.entry(encoder_id)
|
||||||
.or_insert_with(|| format!("{:?}", e));
|
.or_insert_with(|| format!("{:?}", e));
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,2 +1,3 @@
|
||||||
[canvas_complex_rgba8unorm_store.https.html]
|
[canvas_complex_rgba8unorm_store.https.html]
|
||||||
expected: FAIL
|
expected:
|
||||||
|
if os == "linux" and not debug: PASS
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
[canvas_image_rendering.https.html]
|
[canvas_image_rendering.https.html]
|
||||||
expected: TIMEOUT
|
expected:
|
||||||
|
if os == "linux" and not debug: PASS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue